dolibarr  16.0.1
card-rec.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
6  * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
8  * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
9  * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
10  * Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr>
11  * Copyright (C) 2017-2018 Frédéric France <frederic.france@netlogic.fr>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <https://www.gnu.org/licenses/>.
25  */
26 
33 require '../../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture-rec.class.php';
35 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
36 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
37 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
38 if (! empty($conf->project->enabled)) {
39  include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
40 }
41 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
42 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
43 require_once DOL_DOCUMENT_ROOT . '/core/lib/invoice.lib.php';
44 require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
45 
46 // Load translation files required by the page
47 $langs->loadLangs(array('bills', 'companies', 'compta', 'admin', 'other', 'products', 'banks', 'suppliers'));
48 
49 $action = GETPOST('action', 'alpha');
50 $massaction = GETPOST('massaction', 'alpha');
51 $show_files = GETPOST('show_files', 'int');
52 $confirm = GETPOST('confirm', 'alpha');
53 $cancel = GETPOST('cancel', 'alpha');
54 $toselect = GETPOST('toselect', 'array');
55 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'supplierinvoicetemplatelist'; // To manage different context of search
56 
57 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
58 $sortfield = GETPOST("sortfield", 'alpha');
59 $sortorder = GETPOST("sortorder", 'alpha');
60 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
61 
62 // Security check
63 $id = (GETPOST('facid', 'int') ? GETPOST('facid', 'int') : GETPOST('id', 'int'));
64 $lineid = GETPOST('lineid', 'int');
65 $title = GETPOST('title', 'alpha');
66 $ref_supplier = GETPOST('ref_supplier', 'alpha');
67 $projectid = GETPOST('projectid', 'int');
68 $year_date_when = GETPOST('year_date_when');
69 $month_date_when = GETPOST('month_date_when');
70 if ($user->socid) {
71  $socid = $user->socid;
72 }
73 $objecttype = 'facturefournisseur_rec';
74 if ($action == "create" || $action == "add") {
75  $objecttype = '';
76 }
77 
78 if (empty($page) || $page == -1) {
79  $page = 0;
80 } // If $page is not defined, or '' or -1
81 $offset = $limit * $page;
82 if (! $sortorder) {
83  $sortorder = 'DESC';
84 }
85 if (! $sortfield) {
86  $sortfield = 'f.titre';
87 }
88 $pageprev = $page - 1;
89 $pagenext = $page + 1;
90 
91 $object = new FactureFournisseurRec($db);
92 if (($id > 0 || $title) && $action != 'create' && $action != 'add') {
93  $ret = $object->fetch($id, $title);
94  if (! $ret) {
95  setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
96  }
97 }
98 
99 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
100 $hookmanager->initHooks(array('supplierinvoicereccard', 'globalcard'));
101 $extrafields = new ExtraFields($db);
102 
103 // fetch optionals attributes and labels
104 $extrafields->fetch_name_optionals_label($object->table_element);
105 
106 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
107 
108 $permissionnote = $user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer; // Used by the include of actions_setnotes.inc.php
109 $permissiondellink = $user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer;; // Used by the include of actions_dellink.inc.php
110 $permissiontoedit = $user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer;; // Used by the include of actions_lineupdonw.inc.php
111 
112 $usercanread = $user->rights->fournisseur->facture->lire || $user->rights->supplier_invoice->lire;
113 $usercancreate = $user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer;
114 $usercandelete = $user->rights->fournisseur->facture->supprimer || $user->rights->supplier_invoice->supprimer;
115 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($usercancreate)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->supplier_invoice_advance->validate)));
116 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->fournisseur->supplier_invoice_advance->send);
117 
118 $usercanproductignorepricemin = ((! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
119 $usercancreatemargin = $user->rights->margins->creer;
120 $usercanreadallmargin = $user->rights->margins->liretous;
121 $usercancreatewithdrarequest = $user->rights->prelevement->bons->creer;
122 
123 $now = dol_now();
124 
125 $error = 0;
126 
127 $result = restrictedArea($user, 'facture', $object->id, $objecttype);
128 
129 /*
130  * Actions
131  */
132 
133 if (GETPOST('cancel', 'alpha')) {
134  $action = 'list';
135  $massaction = '';
136 }
137 if (! GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
138  $massaction = '';
139 }
140 
141 $parameters = array('socid' => $socid);
142 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
143 if ($reshook < 0) {
144  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
145 }
146 
147 if (empty($reshook)) {
148  if (GETPOST('cancel', 'alpha')) {
149  $action = '';
150  }
151 
152  // Selection of new fields
153  include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php';
154 
155  // Set note
156  include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not include_once
157 
158  include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php'; // Must be include, not include_once
159 
160  include DOL_DOCUMENT_ROOT . '/core/actions_lineupdown.inc.php'; // Must be include, not include_once
161 
162  // Create predefined invoice
163  if ($action == 'add') {
164  if (! GETPOST('title', 'alphanohtml')) {
165  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Title")), null, 'errors');
166  $action = "create";
167  $error++;
168  }
169 
170  $frequency = GETPOST('frequency', 'int');
171  $reyear = GETPOST('reyear', 'int');
172  $remonth = GETPOST('remonth', 'int');
173  $reday = GETPOST('reday', 'int');
174  $rehour = GETPOST('rehour', 'int');
175  $remin = GETPOST('remin', 'int');
176  $nb_gen_max = GETPOST('nb_gen_max', 'int');
177  //if (empty($nb_gen_max)) $nb_gen_max =0;
178 
179  if (GETPOST('frequency', 'int')) {
180  if (empty($reyear) || empty($remonth) || empty($reday)) {
181  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Date")), null, 'errors');
182  $action = "create";
183  $error++;
184  }
185  }
186 
187  if (! $error) {
188  $object->titre = GETPOST('title', 'alphanohtml'); // deprecated
189  $object->title = GETPOST('title', 'alphanohtml');
190  $object->fk_project = GETPOST('projectid', 'int');
191  $object->ref_supplier = GETPOST('ref_supplier', 'alphanohtml');
192 
193  $object->note_private = GETPOST('note_private', 'restricthtml');
194  $object->note_public = GETPOST('note_public', 'restricthtml');
195  $object->model_pdf = GETPOST('modelpdf', 'alpha');
196  $object->usenewprice = GETPOST('usenewprice', 'alpha');
197 
198  $object->frequency = $frequency;
199  $object->unit_frequency = GETPOST('unit_frequency', 'alpha');
200  $object->nb_gen_max = $nb_gen_max;
201  $object->auto_validate = GETPOST('auto_validate', 'int');
202  $object->generate_pdf = GETPOST('generate_pdf', 'int');
203 
204  $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear);
205  $object->date_when = $date_next_execution;
206 
207  $db->begin();
208 
209  $oldinvoice = new FactureFournisseur($db);
210  $oldinvoice->fetch(GETPOST('facid', 'int'));
211 
212  $object->cond_reglement_id = $oldinvoice->cond_reglement_id;
213  $object->cond_reglement_code = $oldinvoice->cond_reglement_code;
214  $object->cond_reglement_label = $oldinvoice->cond_reglement_label;
215  $object->cond_reglement_doc = $oldinvoice->cond_reglement_doc;
216  $object->mode_reglement_id = $oldinvoice->mode_reglement_id;
217  $object->mode_reglement_code = $oldinvoice->mode_reglement_code;
218 
219  $result = $object->create($user, $oldinvoice->id);
220  if ($result > 0) {
221  $result = $oldinvoice->delete($user, 1);
222  if ($result < 0) {
223  $error++;
224  setEventMessages($oldinvoice->error, $oldinvoice->errors, 'errors');
225  $action = "create";
226  }
227  } else {
228  $error++;
229  setEventMessages($object->error, $object->errors, 'errors');
230  $action = "create";
231  }
232 
233  if (! $error) {
234  $db->commit();
235 
236  header("Location: " . $_SERVER['PHP_SELF'] . '?facid=' . $object->id);
237  exit;
238  } else {
239  $db->rollback();
240 
241  $error++;
242  setEventMessages($object->error, $object->errors, 'errors');
243  $action = "create";
244  }
245  }
246  }
247 
248  // Delete
249  //TODO : Droits
250  if ($action == 'confirm_deleteinvoice' && $confirm == 'yes' && ($user->rights->fournisseur->facture->supprimer || $user->rights->supplier_invoice->supprimer)) {
251  $object->delete($user);
252 
253  header('Location: ' . DOL_URL_ROOT . '/fourn/facture/list-rec.php');
254  exit;
255  }
256 
257  // Update field
258  // Set condition
259  if ($action == 'setconditions' && $usercancreate) {
260  $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
261  } elseif ($action == 'setmode' && $usercancreate) {
262  // Set mode
263  $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
264  } elseif ($action == 'classin' && $usercancreate) {
265  // Set project
266  $object->setProject(GETPOST('projectid', 'int'));
267  } elseif ($action == 'setref_supplier' && $usercancreate) {
268  $result = $object->setValueFrom('ref_supplier', $ref_supplier, '', null, 'text', '', $user);
269 
270  if ($result <= 0) {
271  $error++;
272  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
273  $langs->load("errors");
274  setEventMessages($langs->trans('ErrorRefAlreadyExists', $ref_supplier), null, 'errors');
275  } else {
276  setEventMessages($object->error, $object->errors, 'errors');
277  }
278  }
279  } elseif ($action == 'settitle' && $usercancreate) {
280  $result = $object->setValueFrom('titre', $title, '', null, 'text', '', $user);
281 
282  if ($result > 0) {
283  $object->titre = $title;
284  $object->title = $title;
285  $object->ref = $object->title;
286  } else {
287  $error++;
288  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
289  $langs->load("errors");
290  setEventMessages($langs->trans('ErrorTitreAlreadyExists', $title), null, 'errors');
291  } else {
292  setEventMessages($object->error, $object->errors, 'errors');
293  }
294  }
295  } elseif ($action == 'setbankaccount' && $usercancreate) {
296  // Set bank account
297  $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
298  } elseif ($action == 'setfrequency' && $usercancreate) {
299  // Set frequency and unit frequency
300  $object->setFrequencyAndUnit(GETPOST('frequency', 'int'), GETPOST('unit_frequency', 'alpha'));
301  } elseif ($action == 'setdate_when' && $usercancreate) {
302  // Set next date of execution
303  $date = dol_mktime(GETPOST('date_whenhour'), GETPOST('date_whenmin'), 0, GETPOST('date_whenmonth'), GETPOST('date_whenday'), GETPOST('date_whenyear'));
304  if (! empty($date)) {
305  $object->setNextDate($date);
306  }
307  } elseif ($action == 'setnb_gen_max' && $usercancreate) {
308  // Set max period
309  $object->setMaxPeriod(GETPOST('nb_gen_max', 'int'));
310  } elseif ($action == 'setauto_validate' && $usercancreate) {
311  // Set auto validate
312  $object->setAutoValidate(GETPOST('auto_validate', 'int'));
313  } elseif ($action == 'setgenerate_pdf' && $usercancreate) {
314  // Set generate pdf
315  $object->setGeneratepdf(GETPOST('generate_pdf', 'int'));
316  } elseif ($action == 'setmodelpdf' && $usercancreate) {
317  // Set model pdf
318  $object->setModelpdf(GETPOST('modelpdf', 'alpha'));
319  } elseif ($action == 'disable' && $usercancreate) {
320  // Set status disabled
321  $db->begin();
322 
323  $object->fetch($id);
324 
325  $res = $object->setValueFrom('suspended', 1);
326  if ($res <= 0) {
327  $error++;
328  }
329 
330  if (! $error) {
331  $db->commit();
332  } else {
333  $db->rollback();
334  setEventMessages($object->error, $object->errors, 'errors');
335  }
336  } elseif ($action == 'enable' && $usercancreate) {
337  // Set status enabled
338  $db->begin();
339 
340  $object->fetch($id);
341 
342  $res = $object->setValueFrom('suspended', 0);
343  if ($res <= 0) {
344  $error++;
345  }
346 
347  if (! $error) {
348  $db->commit();
349  } else {
350  $db->rollback();
351  setEventMessages($object->error, $object->errors, 'errors');
352  }
353  } elseif ($action == 'setmulticurrencycode' && $usercancreate) {
354  // Multicurrency Code
355  $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
356  } elseif ($action == 'setmulticurrencyrate' && $usercancreate) {
357  // Multicurrency rate
358  $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int'));
359  } elseif ($action == 'setlibelle' && $usercancreate) {
360  // Set label
361  $object->fetch($id);
362  $object->libelle = GETPOST('libelle');
363  $result = $object->update($user);
364 
365  if ($result < 0) {
366  dol_print_error($db);
367  }
368  }
369 
370  // Delete line
371  if ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) {
372  $object->fetch($id);
373  $object->fetch_thirdparty();
374 
375  $db->begin();
376 
377  $line = new FactureFournisseurLigneRec($db);
378 
379  // For triggers
380  $line->id = $lineid;
381 
382  if ($line->delete($user) > 0) {
383  $result = $object->update_price(1);
384 
385  if ($result > 0) {
386  $db->commit();
387  $object->fetch($object->id); // Reload lines
388  } else {
389  $db->rollback();
390  setEventMessages($db->lasterror(), null, 'errors');
391  }
392  } else {
393  $db->rollback();
394  setEventMessages($line->error, $line->errors, 'errors');
395  }
396  } elseif ($action == 'update_extras') {
397  $object->oldcopy = dol_clone($object);
398 
399  // Fill array 'array_options' with data from update form
400  $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
401  if ($ret < 0) {
402  $error++;
403  }
404 
405  if (! $error) {
406  $result = $object->insertExtraFields('BILLREC_MODIFY');
407  if ($result < 0) {
408  setEventMessages($object->error, $object->errors, 'errors');
409  $error++;
410  }
411  }
412  }
413 
414  // Add a new line
415  if ($action == 'addline' && $usercancreate) {
416  $langs->load('errors');
417  $error = 0;
418 
419  // Set if we used free entry or predefined product
420 
421  $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
422  $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
423  $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
424  $prod_entry_mode = GETPOST('prod_entry_mode', 'alpha');
425  if ($prod_entry_mode == 'free') {
426  $idprod = 0;
427  $tva_tx = (GETPOST('tva_tx', 'alpha') ? GETPOST('tva_tx', 'alpha') : 0);
428  $ref_fournisseur = (GETPOSTISSET('fourn_ref') ? GETPOST('fourn_ref', 'restricthtml') : '');
429  } else {
430  $idprod = GETPOST('idprod', 'int');
431  $tva_tx = '';
432  }
433 
434  $qty = price2num(GETPOST('qty' . $predef, 'alpha'), 'MS', 2);
435  $remise_percent = price2num(GETPOST('remise_percent' . $predef), '', 2);
436 
437  // Extrafields
438  $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
439  $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
440  // Unset extrafield
441  if (is_array($extralabelsline)) {
442  // Get extra fields
443  foreach ($extralabelsline as $key => $value) {
444  unset($_POST["options_" . $key . $predef]);
445  }
446  }
447 
448  if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
449  setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
450  $error++;
451  }
452  if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) {
453  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors');
454  $error++;
455  }
456  if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && (! ($price_ht >= 0) || $price_ht == '')) { // Unit price can be 0 but not ''
457  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors');
458  $error++;
459  }
460  if ($qty == '') {
461  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
462  $error++;
463  }
464  if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
465  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors');
466  $error++;
467  }
468  if ($qty < 0) {
469  $langs->load("errors");
470  setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors');
471  $error++;
472  }
473 
474  if ($prod_entry_mode != 'free' && empty($error)) { // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
475  $productsupplier = new ProductFournisseur($db);
476 
477  $idprod = 0;
478  if (GETPOST('idprodfournprice', 'alpha') == -1 || GETPOST('idprodfournprice', 'alpha') == '') {
479  $idprod = -99; // Same behaviour than with combolist. When not select idprodfournprice is now -99 (to avoid conflict with next action that may return -1, -2, ...)
480  }
481  $reg = array();
482  if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg)) {
483  $idprod = (int) $reg[1];
484  $res = $productsupplier->fetch($idprod); // Load product from its id
485  // Call to init some price properties of $productsupplier
486  // So if a supplier price already exists for another thirdparty (first one found), we use it as reference price
487  if (! empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) {
488  $fksoctosearch = 0;
489  $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
490  if ($productsupplier->fourn_socid != $socid) { // The price we found is for another supplier, so we clear supplier price
491  $productsupplier->ref_supplier = '';
492  }
493  } else {
494  $fksoctosearch = $object->thirdparty->id;
495  $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
496  }
497  } elseif (GETPOST('idprodfournprice', 'alpha') > 0) {
498  $qtytosearch = $qty; // Just to see if a price exists for the quantity. Not used to found vat.
499  $idprod = $productsupplier->get_buyprice(GETPOST('idprodfournprice', 'alpha'), $qtytosearch);
500  $res = $productsupplier->fetch($idprod);
501  $ref_fournisseur = $productsupplier->ref_supplier;
502  }
503  }
504 
505  if (! $error && ($qty >= 0) && (! empty($product_desc) || (! empty($idprod) && $idprod > 0))) {
506  $ret = $object->fetch($id);
507  if ($ret < 0) {
508  dol_print_error($db, $object->error);
509  exit();
510  }
511  $ret = $object->fetch_thirdparty();
512 
513  // Clean parameters
514  $date_start = dol_mktime(GETPOST('date_start' . $predef . 'hour'), GETPOST('date_start' . $predef . 'min'), GETPOST('date_start' . $predef . 'sec'), GETPOST('date_start' . $predef . 'month'), GETPOST('date_start' . $predef . 'day'), GETPOST('date_start' . $predef . 'year'));
515  $date_end = dol_mktime(GETPOST('date_end' . $predef . 'hour'), GETPOST('date_end' . $predef . 'min'), GETPOST('date_end' . $predef . 'sec'), GETPOST('date_end' . $predef . 'month'), GETPOST('date_end' . $predef . 'day'), GETPOST('date_end' . $predef . 'year'));
516  $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
517 
518  // Define special_code for special lines
519  $special_code = 0;
520  // if (empty($_POST['qty'])) $special_code=3; // Options should not exists on invoices
521 
522  // Ecrase $pu par celui du produit
523  // Ecrase $desc par celui du produit
524  // Ecrase $tva_tx par celui du produit
525  // Ecrase $base_price_type par celui du produit
526  // Replaces $fk_unit with the product's
527  if (! empty($idprod) && $idprod > 0) {
528  $prod = new Product($db);
529  $prod->fetch($idprod);
530 
531  $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : '');
532 
533  // Update if prices fields are defined
534  $tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
535  $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
536  if (empty($tva_tx)) {
537  $tva_npr = 0;
538  }
539 
540  // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
541  $pqp = (GETPOST('pbq', 'int') ? GETPOST('pbq', 'int') : 0);
542 
543  $datapriceofproduct = $prod->getSellPrice($mysoc, $object->thirdparty, $pqp);
544 
545  $pu_ht = $datapriceofproduct['pu_ht'];
546  $pu_ttc = $datapriceofproduct['pu_ttc'];
547  $price_min = $datapriceofproduct['price_min'];
548  $price_base_type = $datapriceofproduct['price_base_type'];
549  $tva_tx = $datapriceofproduct['tva_tx'];
550  $tva_npr = $datapriceofproduct['tva_npr'];
551 
552  $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
553  $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx));
554 
555  // if price ht was forced (ie: from gui when calculated by margin rate and cost price). TODO Why this ?
556  if (! empty($price_ht)) {
557  $pu_ht = price2num($price_ht, 'MU');
558  $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
559  } elseif ($tmpvat != $tmpprodvat) {
560  // On reevalue prix selon taux tva car taux tva transaction peut etre different
561  // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
562  if ($price_base_type != 'HT') {
563  $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');
564  } else {
565  $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
566  }
567  }
568 
569  $desc = '';
570 
571  // Define output language
572  if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
573  $outputlangs = $langs;
574  $newlang = '';
575  if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
576  $newlang = GETPOST('lang_id', 'aZ09');
577  }
578  if (empty($newlang)) {
579  $newlang = $object->thirdparty->default_lang;
580  }
581  if (! empty($newlang)) {
582  $outputlangs = new Translate("", $conf);
583  $outputlangs->setDefaultLang($newlang);
584  }
585 
586  $desc = (! empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description;
587  } else {
588  $desc = $prod->description;
589  }
590 
591  $desc = dol_concatdesc($desc, $product_desc);
592 
593  // Add custom code and origin country into description
594  if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) {
595  $tmptxt = '(';
596  // Define output language
597  if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
598  $outputlangs = $langs;
599  $newlang = '';
600  if (empty($newlang) && GETPOST('lang_id', 'alpha')) {
601  $newlang = GETPOST('lang_id', 'alpha');
602  }
603  if (empty($newlang)) {
604  $newlang = $object->thirdparty->default_lang;
605  }
606  if (! empty($newlang)) {
607  $outputlangs = new Translate("", $conf);
608  $outputlangs->setDefaultLang($newlang);
609  $outputlangs->load('products');
610  }
611  if (! empty($prod->customcode)) {
612  $tmptxt .= $outputlangs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
613  }
614  if (! empty($prod->customcode) && ! empty($prod->country_code)) {
615  $tmptxt .= ' - ';
616  }
617  if (! empty($prod->country_code)) {
618  $tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $outputlangs, 0);
619  }
620  } else {
621  if (! empty($prod->customcode)) {
622  $tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
623  }
624  if (! empty($prod->customcode) && ! empty($prod->country_code)) {
625  $tmptxt .= ' - ';
626  }
627  if (! empty($prod->country_code)) {
628  $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
629  }
630  }
631  $tmptxt .= ')';
632  $desc = dol_concatdesc($desc, $tmptxt);
633  }
634 
635  $type = $prod->type;
636  $fk_unit = $prod->fk_unit;
637  } else {
638  $pu_ht = price2num($price_ht, 'MU');
639  $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
640  $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
641  $tva_tx = str_replace('*', '', $tva_tx);
642  if (empty($tva_tx)) {
643  $tva_npr = 0;
644  }
645  $desc = $product_desc;
646  $type = GETPOST('type');
647  $fk_unit = GETPOST('units', 'alpha');
648  }
649 
650  $date_start_fill = ! empty(GETPOST('date_start_fill', 'int')) ? GETPOST('date_start_fill', 'int') : null;
651  $date_end_fill = ! empty(GETPOST('date_end_fill', 'int')) ? GETPOST('date_end_fill', 'int') : null;
652 
653  // Margin
654  $fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : '');
655  $buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we must keep this value
656 
657  // Local Taxes
658  $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
659  $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
660  $info_bits = 0;
661  if ($tva_npr) {
662  $info_bits |= 0x01;
663  }
664 
665  //To set vars in float type to avoid non-numeric warnings
666  $pu_ht = (float) price2num($pu_ht);
667  $remise_percent = (float) price2num($remise_percent);
668 
669  $price_min = (float) price2num($price_min);
670  if ($usercanproductignorepricemin && (! empty($price_min) && ($pu_ht * (1 - $remise_percent / 100) < $price_min))) {
671  $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
672  setEventMessages($mesg, null, 'errors');
673  } else {
674  // Insert line
675  $result = $object->addline($idprod, $ref_fournisseur, $label, $desc, $pu_ht, $pu_ttc, $qty, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $price_base_type, $type, $date_start_fill, $date_end_fill, $info_bits, $special_code, -1, $fk_unit);
676 
677  if ($result > 0) {
678  $object->fetch($object->id); // Reload lines
679 
680  unset($_POST['prod_entry_mode']);
681  unset($_POST['qty']);
682  unset($_POST['type']);
683  unset($_POST['remise_percent']);
684  unset($_POST['price_ht']);
685  unset($_POST['multicurrency_price_ht']);
686  unset($_POST['price_ttc']);
687  unset($_POST['tva_tx']);
688  unset($_POST['product_ref']);
689  unset($_POST['product_label']);
690  unset($_POST['product_desc']);
691  unset($_POST['fournprice']);
692  unset($_POST['buying_price']);
693  unset($_POST['np_marginRate']);
694  unset($_POST['np_markRate']);
695  unset($_POST['dp_desc']);
696  unset($_POST['idprod']);
697  unset($_POST['units']);
698  unset($_POST['date_starthour']);
699  unset($_POST['date_startmin']);
700  unset($_POST['date_startsec']);
701  unset($_POST['date_startday']);
702  unset($_POST['date_startmonth']);
703  unset($_POST['date_startyear']);
704  unset($_POST['date_endhour']);
705  unset($_POST['date_endmin']);
706  unset($_POST['date_endsec']);
707  unset($_POST['date_endday']);
708  unset($_POST['date_endmonth']);
709  unset($_POST['date_endyear']);
710  unset($_POST['date_start_fill']);
711  unset($_POST['date_end_fill']);
712  unset($_POST['situations']);
713  unset($_POST['progress']);
714  } else {
715  setEventMessages($object->error, $object->errors, 'errors');
716  }
717 
718  $action = '';
719  }
720  }
721  } elseif ($action == 'updateline' && $usercancreate && ! GETPOST('cancel', 'alpha')) {
722  if (! $object->fetch($id) > 0) {
723  dol_print_error($db);
724  }
725  $object->fetch_thirdparty();
726 
727  // Clean parameters
728  $date_start = '';
729  $date_end = '';
730  $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml') ? GETPOST('product_desc', 'restricthtml') : GETPOST('desc', 'restricthtml'));
731  $ref_fourn = GETPOST('fourn_ref', 'alpha');
732  $pu_ht = price2num(GETPOST('price_ht'), '', 2);
733  $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
734  $qty = GETPOST('qty');
735  $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
736 
737  // Define info_bits
738  $info_bits = 0;
739  if (preg_match('/\*/', $vat_rate)) {
740  $info_bits |= 0x01;
741  }
742 
743  // Define vat_rate
744  $vat_rate = str_replace('*', '', $vat_rate);
745  $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty);
746  $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty);
747 
748  // Extrafields
749  $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
750  $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
751 
752  $objectline = new FactureFournisseurLigneRec($db);
753  if ($objectline->fetch(GETPOST('lineid', 'int'))) {
754  $objectline->array_options = $array_options;
755  $result = $objectline->insertExtraFields();
756  if ($result < 0) {
757  setEventMessages($langs->trans('Error') . $result, null, 'errors');
758  }
759  }
760 
761  $position = ($objectline->rang >= 0 ? $objectline->rang : 0);
762 
763  // Unset extrafield
764  if (is_array($extralabelsline)) {
765  // Get extra fields
766  foreach ($extralabelsline as $key => $value) {
767  unset($_POST["options_" . $key]);
768  }
769  }
770 
771  // Define special_code for special lines
772  $special_code = GETPOST('special_code', 'int');
773  if (! GETPOST('qty', 'alpha')) {
774  $special_code = 3;
775  }
776 
777  $remise_percent = price2num(GETPOST('remise_percent'), '', 2);
778 
779  // Check minimum price
780  $productid = GETPOST('productid', 'int');
781  if (! empty($productid)) {
782  $product = new Product($db);
783  $product->fetch($productid);
784 
785  $type = $product->type;
786 
787  $price_min = $product->price_min;
788  if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level)) {
789  $price_min = $product->multiprices_min[$object->thirdparty->price_level];
790  }
791 
792  $label = $product->label;
793 
794  // Check price is not lower than minimum (check is done only for standard or replacement invoices)
795  if (((! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && $price_min && (price2num($pu_ht) * (1 - $remise_percent / 100) < price2num($price_min))) {
796  setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)), null, 'errors');
797  $error++;
798  }
799  } else {
800  $type = GETPOST('type', 'int');
801  $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
802 
803  // Check parameters
804  if (GETPOST('type', 'int') < 0) {
805  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
806  $error++;
807  }
808  }
809  if ($qty < 0) {
810  $langs->load("errors");
811  setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors');
812  $error++;
813  }
814 
815  $date_start_fill = ! empty(GETPOST('date_start_fill', 'int')) ? GETPOST('date_start_fill', 'int') : 'NULL';
816  $date_end_fill = ! empty(GETPOST('date_end_fill', 'int')) ? GETPOST('date_end_fill', 'int') : 'NULL';
817 
818  // Update line
819  if (! $error) {
820  $result = $object->updateline(GETPOST('lineid', 'int'), GETPOST('productid', 'int'), $ref_fourn, $label, $description, $pu_ht, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax1_rate, 'HT', $type, $date_start_fill, $date_end_fill, $info_bits, $special_code, -1);
821  if ($result >= 0) {
822  $object->fetch($object->id); // Reload lines
823 
824  unset($_POST['qty']);
825  unset($_POST['type']);
826  unset($_POST['productid']);
827  unset($_POST['remise_percent']);
828  unset($_POST['price_ht']);
829  unset($_POST['multicurrency_price_ht']);
830  unset($_POST['price_ttc']);
831  unset($_POST['tva_tx']);
832  unset($_POST['product_ref']);
833  unset($_POST['product_label']);
834  unset($_POST['product_desc']);
835  unset($_POST['fournprice']);
836  unset($_POST['buying_price']);
837  unset($_POST['np_marginRate']);
838  unset($_POST['np_markRate']);
839  unset($_POST['dp_desc']);
840  unset($_POST['idprod']);
841  unset($_POST['units']);
842  unset($_POST['date_starthour']);
843  unset($_POST['date_startmin']);
844  unset($_POST['date_startsec']);
845  unset($_POST['date_startday']);
846  unset($_POST['date_startmonth']);
847  unset($_POST['date_startyear']);
848  unset($_POST['date_endhour']);
849  unset($_POST['date_endmin']);
850  unset($_POST['date_endsec']);
851  unset($_POST['date_endday']);
852  unset($_POST['date_endmonth']);
853  unset($_POST['date_endyear']);
854  unset($_POST['situations']);
855  unset($_POST['progress']);
856  } else {
857  setEventMessages($object->error, $object->errors, 'errors');
858  }
859  }
860  }
861 }
862 
863 /*
864  * View
865  */
866 
867 $help_url = '';
868 llxHeader('', $langs->trans("RepeatableSupplierInvoice"), $help_url);
869 
870 $form = new Form($db);
871 $formother = new FormOther($db);
872 if (! empty($conf->project->enabled)) {
873  $formproject = new FormProjets($db);
874 }
875 $companystatic = new Societe($db);
876 $invoicerectmp = new FactureFournisseurRec($db);
877 
878 $now = dol_now();
879 $nowlasthour = dol_get_last_hour($now);
880 
881 /*
882  * Create mode
883  */
884 if ($action == 'create') {
885  print load_fiche_titre($langs->trans("CreateRepeatableInvoice"), '', 'bill');
886 
887  $object = new FactureFournisseur($db); // Source invoice
888  $product_static = new Product($db);
889 
890  if ($object->fetch($id) > 0) {
891  $result = $object->fetch_lines();
892 
893  print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
894  print '<input type="hidden" name="token" value="' . newToken() . '">';
895  print '<input type="hidden" name="action" value="add">';
896  print '<input type="hidden" name="facid" value="' . $object->id . '">';
897 
898  print dol_get_fiche_head(null, '', '', 0);
899 
900  $rowspan = 4;
901  if (! empty($conf->project->enabled)) $rowspan++;
902  if ($object->fk_account > 0) $rowspan++;
903 
904  print '<table class="border centpercent">';
905 
906  $object->fetch_thirdparty();
907 
908  // Title
909  print '<tr><td class="titlefieldcreate fieldrequired">' . $langs->trans("Title") . '</td><td>';
910  print '<input class="flat quatrevingtpercent" type="text" name="title" value="' . dol_escape_htmltag(GETPOST("title", 'alphanohtml')) . '">';
911  print '</td></tr>';
912 
913  // Ref supplier
914  print '<tr><td class="titlefieldcreate fieldrequired">' . $langs->trans("SupplierRef") . '</td><td>';
915  print '<input class="flat quatrevingtpercent" type="text" name="ref_supplier" value="' . $object->ref_supplier . '">';
916  print '</td></tr>';
917 
918  // Third party
919  print '<tr><td class="titlefieldcreate">' . $langs->trans("Customer") . '</td><td>' . $object->thirdparty->getNomUrl(1, 'customer') . '</td>';
920  print '</tr>';
921 
922  $note_public = GETPOSTISSET('note_public') ? GETPOST('note_public', 'restricthtml') : $object->note_public;
923  $note_private = GETPOSTISSET('note_private') ? GETPOST('note_private', 'restricthtml') : $object->note_private;
924 
925  // Help of substitution key
926  $substitutionarray = getCommonSubstitutionArray($langs, 2, null, $object);
927 
928  $substitutionarray['__INVOICE_PREVIOUS_MONTH__'] = $langs->trans("PreviousMonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($object->date, -1, 'm'), '%m') . ')';
929  $substitutionarray['__INVOICE_MONTH__'] = $langs->trans("MonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date($object->date, '%m') . ')';
930  $substitutionarray['__INVOICE_NEXT_MONTH__'] = $langs->trans("NextMonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($object->date, 1, 'm'), '%m') . ')';
931  $substitutionarray['__INVOICE_PREVIOUS_MONTH_TEXT__'] = $langs->trans("TextPreviousMonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($object->date, -1, 'm'), '%B') . ')';
932  $substitutionarray['__INVOICE_MONTH_TEXT__'] = $langs->trans("TextMonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date($object->date, '%B') . ')';
933  $substitutionarray['__INVOICE_NEXT_MONTH_TEXT__'] = $langs->trans("TextNextMonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($object->date, 1, 'm'), '%B') . ')';
934  $substitutionarray['__INVOICE_PREVIOUS_YEAR__'] = $langs->trans("PreviousYearOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($object->date, -1, 'y'), '%Y') . ')';
935  $substitutionarray['__INVOICE_YEAR__'] = $langs->trans("YearOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date($object->date, '%Y') . ')';
936  $substitutionarray['__INVOICE_NEXT_YEAR__'] = $langs->trans("NextYearOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($object->date, 1, 'y'), '%Y') . ')';
937  // Only on template invoices
938  $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = $langs->trans("DateNextInvoiceBeforeGen") . ' (' . $langs->trans("Example") . ': ' . dol_print_date($object->date_when, 'dayhour') . ')';
939  $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] = $langs->trans("DateNextInvoiceAfterGen") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($object->date_when, $object->frequency, $object->unit_frequency), 'dayhour') . ')';
940  $substitutionarray['__INVOICE_COUNTER_CURRENT__'] = $langs->trans("Count");
941  $substitutionarray['__INVOICE_COUNTER_MAX__'] = $langs->trans("MaxPeriodNumber");
942 
943  $htmltext = '<i>' . $langs->trans("FollowingConstantsWillBeSubstituted") . ':<br>';
944  foreach ($substitutionarray as $key => $val) {
945  $htmltext .= $key . ' = ' . $langs->trans($val) . '<br>';
946  }
947  $htmltext .= '</i>';
948 
949  // Libelle
950  print '<tr><td class="titlefieldcreate">' . $langs->trans("Label") . '</td><td>';
951  print '<input class="flat quatrevingtpercent" type="text" name="libelle" value="' . $object->label . '">';
952  print '</td></tr>';
953 
954  // Public note
955  print '<tr>';
956  print '<td class="tdtop">';
957  print $form->textwithpicto($langs->trans('NotePublic'), $htmltext, 1, 'help', '', 0, 2, 'notepublic');
958  print '</td>';
959  print '<td>';
960  $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%');
961  print $doleditor->Create(1);
962 
963  // Private note
964  if (empty($user->socid)) {
965  print '<tr>';
966  print '<td class="tdtop">';
967  print $form->textwithpicto($langs->trans('NotePrivate'), $htmltext, 1, 'help', '', 0, 2, 'noteprivate');
968  print '</td>';
969  print '<td>';
970  $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%');
971  print $doleditor->Create(1);
972  print '</td></tr>';
973  }
974 
975  // Author
976  print "<tr><td>" . $langs->trans("Author") . "</td><td>" . $user->getFullName($langs) . "</td></tr>";
977 
978  // Payment term
979  print "<tr><td>" . $langs->trans("PaymentConditions") . "</td><td>";
980  $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->cond_reglement_id, 'none');
981  print "</td></tr>";
982 
983  // Payment mode
984  print "<tr><td>" . $langs->trans("PaymentMode") . "</td><td>";
985  $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'none', '', 1);
986  print "</td></tr>";
987 
988  // Project
989  if (! empty($conf->project->enabled) && is_object($object->thirdparty) && $object->thirdparty->id > 0) {
990  $projectid = GETPOST('projectid') ? GETPOST('projectid') : $object->fk_project;
991  $langs->load('projects');
992  print '<tr><td>' . $langs->trans('Project') . '</td><td>';
993  $numprojet = $formproject->select_projects($object->thirdparty->id, $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0, 0, '');
994  print ' &nbsp; <a href="' . DOL_URL_ROOT . '/projet/card.php?socid=' . $object->thirdparty->id . '&action=create&status=1&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create&socid=' . $object->thirdparty->id . (! empty($id) ? '&id=' . $id : '')) . '">' . $langs->trans("AddProject") . '</a>';
995  print '</td></tr>';
996  }
997 
998  // Bank account
999  if ($object->fk_account > 0) {
1000  print "<tr><td>" . $langs->trans('BankAccount') . "</td><td>";
1001  $form->formSelectAccount($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->fk_account, 'none');
1002  print "</td></tr>";
1003  }
1004 
1005  // Model pdf
1006  print "<tr><td>" . $langs->trans('Model') . "</td><td>";
1007  include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_invoice/modules_facturefournisseur.php';
1009  print $form->selectarray('modelpdf', $list, $conf->global->INVOICE_SUPPLIER_ADDON_PDF);
1010  print "</td></tr>";
1011 
1012  print "</table>";
1013 
1014  print dol_get_fiche_end();
1015 
1016  // Autogeneration
1017  $title = $langs->trans("Recurrence");
1018  print load_fiche_titre(img_picto('', 'recurring', 'class="pictofixedwidth"') . $title, '', '');
1019 
1020  print dol_get_fiche_head(null, '', '', 0);
1021 
1022  print '<table class="border centpercent">';
1023 
1024  // Frequency + unit
1025  print '<tr><td class="titlefieldcreate">' . $form->textwithpicto($langs->trans("Frequency"), $langs->transnoentitiesnoconv('toolTipFrequency')) . "</td><td>";
1026  print "<input type='text' name='frequency' value='" . GETPOST('frequency', 'int') . "' size='4' />&nbsp;" . $form->selectarray('unit_frequency', array('d' => $langs->trans('Day'), 'm' => $langs->trans('Month'), 'y' => $langs->trans('Year')), (GETPOST('unit_frequency') ? GETPOST('unit_frequency') : 'm'));
1027  print "</td></tr>";
1028 
1029  // Date next run
1030  print "<tr><td>" . $langs->trans('NextDateToExecution') . "</td><td>";
1031  $date_next_execution = isset($date_next_execution) ? $date_next_execution : (GETPOST('remonth') ? dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')) : -1);
1032  print $form->selectDate($date_next_execution, '', 1, 1, '', "add", 1, 1);
1033  print "</td></tr>";
1034 
1035  // Number max of generation
1036  print "<tr><td>" . $langs->trans("MaxPeriodNumber") . "</td><td>";
1037  print '<input type="text" name="nb_gen_max" value="' . GETPOST('nb_gen_max') . '" size="5" />';
1038  print "</td></tr>";
1039 
1040  // Auto validate the invoice
1041  print "<tr><td>" . $langs->trans("StatusOfGeneratedInvoices") . "</td><td>";
1042  $select = array('0' => $langs->trans('BillStatusDraft'), '1' => $langs->trans('BillStatusValidated'));
1043  print $form->selectarray('auto_validate', $select, GETPOST('auto_validate'));
1044  print "</td></tr>";
1045 
1046  // Auto generate document
1047  if (! empty($conf->global->INVOICE_REC_CAN_DISABLE_DOCUMENT_FILE_GENERATION)) {
1048  print "<tr><td>" . $langs->trans("StatusOfGeneratedDocuments") . "</td><td>";
1049  $select = array('0' => $langs->trans('DoNotGenerateDoc'), '1' => $langs->trans('AutoGenerateDoc'));
1050  print $form->selectarray('generate_pdf', $select, GETPOST('generate_pdf'));
1051  print "</td></tr>";
1052  } else {
1053  print '<input type="hidden" name="generate_pdf" value="1">';
1054  }
1055 
1056  print "</table>";
1057 
1058  print dol_get_fiche_end();
1059 
1060  $title = $langs->trans("ProductsAndServices");
1061  if (empty($conf->service->enabled)) {
1062  $title = $langs->trans("Products");
1063  } elseif (empty($conf->product->enabled)) {
1064  $title = $langs->trans("Services");
1065  }
1066 
1067  print load_fiche_titre($title, '', '');
1068 
1069  /*
1070  * Invoice lines
1071  */
1072  print '<div class="div-table-responsive-no-min">';
1073  print '<table id="tablelines" class="noborder noshadow" width="100%">';
1074  // Show object lines
1075  if (! empty($object->lines)) {
1076  $disableedit = 1;
1077  $disablemove = 1;
1078  $disableremove = 1;
1079  $object->printObjectLines('', $mysoc, $object->thirdparty, $lineid, 0); // No date selector for template invoice
1080  }
1081 
1082  print "</table>\n";
1083  print '<div>';
1084  print '</td></tr>';
1085  print "</table>\n";
1086 
1087  print $form->buttonsSaveCancel("Create");
1088 
1089  print "</form>\n";
1090  } else {
1091  dol_print_error('', "Error, no invoice " . $object->id);
1092  }
1093 } else {
1094  /*
1095  * View mode
1096  */
1097  if ($object->id > 0) {
1098  $object->fetch($object->id);
1099  $object->fetch_thirdparty();
1100 
1101  // Confirmation de la suppression d'une ligne produit
1102  if ($action == 'ask_deleteline') {
1103  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 'no', 1);
1104  }
1105 
1106  // Confirm delete of repeatable invoice
1107  if ($action == 'ask_deleteinvoice') {
1108  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteRepeatableInvoice'), $langs->trans('ConfirmDeleteRepeatableInvoice'), 'confirm_deleteinvoice', '', 'no', 1);
1109  }
1110 
1111  print $formconfirm;
1112 
1113  $author = new User($db);
1114  $author->fetch($object->user_author);
1115 
1116  $head = supplier_invoice_rec_prepare_head($object);
1117 
1118  print dol_get_fiche_head($head, 'card', $langs->trans('RepeatableInvoice'), -1, 'bill'); // Add a div
1119 
1120  // Recurring invoice content
1121 
1122  $linkback = '<a href="' . DOL_URL_ROOT . '/fourn/facture/list-rec.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans('BackToList') . '</a>';
1123 
1124  $morehtmlref = '';
1125  if ($action != 'edittitle') {
1126  $morehtmlref .= $form->editfieldkey($object->titre, 'title', $object->titre, $object, $usercancreate, '', '', 0, 2);
1127  } else {
1128  $morehtmlref .= $form->editfieldval('', 'title', $object->titre, $object, $usercancreate, 'string');
1129  }
1130  $morehtmlref .= '<div class="refidno">';
1131  //Ref supplier
1132  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreate, 'string', '', 0, 1);
1133  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreate, 'string', '', null, null, '', 1);
1134  // Thirdparty
1135  $morehtmlref .= '<br>' . $langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
1136 
1137  // Project
1138  if (! empty($conf->project->enabled)) {
1139  $langs->load('projects');
1140  $morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
1141  if ($usercancreate) {
1142  if ($action != 'classify') {
1143  $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
1144  }
1145  if ($action == 'classify') {
1146  $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
1147  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
1148  $morehtmlref .= '<input type="hidden" name="token" value="' . newToken() . '">';
1149  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
1150  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
1151  $morehtmlref .= '</form>';
1152  } else {
1153  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
1154  }
1155  } else {
1156  if (! empty($object->fk_project)) {
1157  $project = new Project($db);
1158  $project->fetch($object->fk_project);
1159  $morehtmlref .= ' : ' . $project->getNomUrl(1);
1160  if ($project->title) {
1161  $morehtmlref .= ' - ' . $project->title;
1162  }
1163  } else {
1164  $morehtmlref .= '';
1165  }
1166  }
1167  }
1168  $morehtmlref .= '</div>';
1169 
1170  $morehtmlright = '';
1171 
1172  dol_banner_tab($object, 'ref', $linkback, 1, 'title', 'none', $morehtmlref, '', 0, '', $morehtmlright);
1173 
1174  print '<div class="fichecenter">';
1175  print '<div class="fichehalfleft">';
1176  print '<div class="underbanner clearboth"></div>';
1177 
1178  print '<table class="border centpercent tableforfield">';
1179 
1180  print '<tr><td class="titlefield">' . $langs->trans('Author') . '</td><td>';
1181  print $author->getNomUrl(-1);
1182  print "</td></tr>";
1183 
1184  // Label
1185  print '<tr>';
1186  print '<td>' . $form->editfieldkey("Label", 'libelle', $object->libelle, $object, $usercancreate) . '</td>';
1187  print '<td>' . $form->editfieldval("Label", 'libelle', $object->libelle, $object, $usercancreate) . '</td>';
1188  print '</tr>';
1189 
1190  print '<tr><td>' . $langs->trans('AmountHT') . '</td>';
1191  print '<td>' . price($object->total_ht, '', $langs, 1, -1, -1, $conf->currency) . '</td>';
1192  print '</tr>';
1193 
1194  print '<tr><td>' . $langs->trans("AmountVAT") . '</td><td>' . price($object->total_tva, '', $langs, 1, -1, -1, $conf->currency) . '</td>';
1195  print '</tr>';
1196 
1197  // Amount Local Taxes
1198  if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) { // Localtax1
1199  print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
1200  print '<td class="nowrap">' . price($object->total_localtax1, 1, '', 1, -1, -1, $conf->currency) . '</td></tr>';
1201  }
1202  if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) { // Localtax2
1203  print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
1204  print '<td class=nowrap">' . price($object->total_localtax2, 1, '', 1, -1, -1, $conf->currency) . '</td></tr>';
1205  }
1206 
1207  print '<tr><td>' . $langs->trans("AmountTTC") . '</td><td colspan="3">' . price($object->total_ttc, '', $langs, 1, -1, -1, $conf->currency) . '</td>';
1208  print '</tr>';
1209 
1210  // Payment term
1211  print '<tr><td>';
1212  print '<table class="nobordernopadding centpercent"><tr><td>';
1213  print $langs->trans('PaymentConditionsShort');
1214  print '</td>';
1215  if ($action != 'editconditions' && $usercancreate) {
1216  print '<td class="right"><a class="editfielda" href="' . $_SERVER["PHP_SELF"] . '?action=editconditions&token=' . newToken() . '&facid=' . $object->id . '">' . img_edit($langs->trans('SetConditions'), 1) . '</a></td>';
1217  }
1218  print '</tr></table>';
1219  print '</td><td>';
1220  if ($action == 'editconditions') {
1221  $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->cond_reglement_id, 'cond_reglement_id');
1222  } else {
1223  $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->cond_reglement_id, 'none');
1224  }
1225 
1226  print '</td></tr>';
1227 
1228  // Payment mode
1229  print '<tr><td>';
1230  print '<table class="nobordernopadding" width="100%"><tr><td>';
1231  print $langs->trans('PaymentMode');
1232  print '</td>';
1233  if ($action != 'editmode' && $usercancreate) {
1234  print '<td class="right"><a class="editfielda" href="' . $_SERVER["PHP_SELF"] . '?action=editmode&token=' . newToken() . '&facid=' . $object->id . '">' . img_edit($langs->trans('SetMode'), 1) . '</a></td>';
1235  }
1236  print '</tr></table>';
1237  print '</td><td>';
1238  if ($action == 'editmode') {
1239  $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1);
1240  } else {
1241  $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->mode_reglement_id, 'none');
1242  }
1243  print '</td></tr>';
1244 
1245  // Multicurrency
1246  if (! empty($conf->multicurrency->enabled)) {
1247  // Multicurrency code
1248  print '<tr>';
1249  print '<td>';
1250  print '<table class="nobordernopadding" width="100%"><tr><td>';
1251  print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0);
1252  print '</td>';
1253  if ($usercancreate && $action != 'editmulticurrencycode' && ! empty($object->brouillon)) {
1254  print '<td class="right"><a class="editfielda" href="' . $_SERVER["PHP_SELF"] . '?action=editmulticurrencycode&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '</a></td>';
1255  }
1256  print '</tr></table>';
1257  print '</td><td>';
1258  $htmlname = (($usercancreate && $action == 'editmulticurrencycode') ? 'multicurrency_code' : 'none');
1259  $form->form_multicurrency_code($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_code, $htmlname);
1260  print '</td></tr>';
1261 
1262  // Multicurrency rate
1263  if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
1264  print '<tr>';
1265  print '<td>';
1266  print '<table class="nobordernopadding" width="100%"><tr><td>';
1267  print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0);
1268  print '</td>';
1269  if ($usercancreate && $action != 'editmulticurrencyrate' && ! empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
1270  print '<td class="right"><a class="editfielda" href="' . $_SERVER["PHP_SELF"] . '?action=editmulticurrencyrate&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '</a></td>';
1271  }
1272  print '</tr></table>';
1273  print '</td><td>';
1274  if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') {
1275  if ($action == 'actualizemulticurrencyrate') {
1276  list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code);
1277  }
1278  $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, ($usercancreate ? 'multicurrency_tx' : 'none'), $object->multicurrency_code);
1279  } else {
1280  $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code);
1281  if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
1282  print '<div class="inline-block"> &nbsp; &nbsp; &nbsp; &nbsp; ';
1283  print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=actualizemulticurrencyrate">' . $langs->trans("ActualizeCurrency") . '</a>';
1284  print '</div>';
1285  }
1286  }
1287  print '</td></tr>';
1288  }
1289  }
1290 
1291  // Help of substitution key
1292  $dateexample = dol_now();
1293  if (! empty($object->frequency) && ! empty($object->date_when)) {
1294  $dateexample = $object->date_when;
1295  }
1296 
1297  $substitutionarray = getCommonSubstitutionArray($langs, 2, null, $object);
1298 
1299  $substitutionarray['__INVOICE_PREVIOUS_MONTH__'] = $langs->trans("PreviousMonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'), '%m') . ')';
1300  $substitutionarray['__INVOICE_MONTH__'] = $langs->trans("MonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date($dateexample, '%m') . ')';
1301  $substitutionarray['__INVOICE_NEXT_MONTH__'] = $langs->trans("NextMonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'), '%m') . ')';
1302  $substitutionarray['__INVOICE_PREVIOUS_MONTH_TEXT__'] = $langs->trans("TextPreviousMonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'), '%B') . ')';
1303  $substitutionarray['__INVOICE_MONTH_TEXT__'] = $langs->trans("TextMonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date($dateexample, '%B') . ')';
1304  $substitutionarray['__INVOICE_NEXT_MONTH_TEXT__'] = $langs->trans("TextNextMonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'), '%B') . ')';
1305  $substitutionarray['__INVOICE_PREVIOUS_YEAR__'] = $langs->trans("PreviousYearOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($dateexample, -1, 'y'), '%Y') . ')';
1306  $substitutionarray['__INVOICE_YEAR__'] = $langs->trans("YearOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date($dateexample, '%Y') . ')';
1307  $substitutionarray['__INVOICE_NEXT_YEAR__'] = $langs->trans("NextYearOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($dateexample, 1, 'y'), '%Y') . ')';
1308  // Only on template invoices
1309  $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = $langs->trans("DateNextInvoiceBeforeGen") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(($object->date_when ? $object->date_when : dol_now()), 'dayhour') . ')';
1310  $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] = $langs->trans("DateNextInvoiceAfterGen") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree(($object->date_when ? $object->date_when : dol_now()), $object->frequency, $object->unit_frequency), 'dayhour') . ')';
1311  $substitutionarray['__INVOICE_COUNTER_CURRENT__'] = $object->nb_gen_done;
1312  $substitutionarray['__INVOICE_COUNTER_MAX__'] = $object->nb_gen_max;
1313 
1314  $htmltext = '<i>' . $langs->trans("FollowingConstantsWillBeSubstituted") . ':<br>';
1315  foreach ($substitutionarray as $key => $val) {
1316  $htmltext .= $key . ' = ' . $langs->trans($val) . '<br>';
1317  }
1318  $htmltext .= '</i>';
1319 
1320  // Note public
1321  print '<tr><td>';
1322  print $form->editfieldkey($form->textwithpicto($langs->trans('NotePublic'), $htmltext, 1, 'help', '', 0, 2, 'notepublic'), 'note_public', $object->note_public, $object, $usercancreate);
1323  print '</td><td class="wordbreak">';
1324  print $form->editfieldval($langs->trans("NotePublic"), 'note_public', $object->note_public, $object, $usercancreate, 'textarea:' . ROWS_4 . ':90%', '', null, null, '', 1);
1325  print '</td>';
1326  print '</tr>';
1327 
1328  // Note private
1329  print '<tr><td>';
1330  print $form->editfieldkey($form->textwithpicto($langs->trans("NotePrivate"), $htmltext, 1, 'help', '', 0, 2, 'noteprivate'), 'note_private', $object->note_private, $object, $usercancreate);
1331  print '</td><td class="wordbreak">';
1332  print $form->editfieldval($langs->trans("NotePrivate"), 'note_private', $object->note_private, $object, $usercancreate, 'textarea:' . ROWS_4 . ':90%', '', null, null, '', 1);
1333  print '</td>';
1334  print '</tr>';
1335 
1336  // Bank Account
1337  print '<tr><td class="nowrap">';
1338  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1339  print $langs->trans('BankAccount');
1340  print '<td>';
1341  if ($action != 'editbankaccount' && $usercancreate && $object->statut == FactureFournisseurRec::STATUS_NOTSUSPENDED) {
1342  print '<td class="right"><a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=editbankaccount&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->trans('SetBankAccount'), 1) . '</a></td>';
1343  }
1344  print '</tr></table>';
1345  print '</td><td>';
1346  if ($action == 'editbankaccount') {
1347  $form->formSelectAccount($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->fk_account, 'fk_account', 1);
1348  } else {
1349  $form->formSelectAccount($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->fk_account, 'none');
1350  }
1351  print "</td>";
1352  print '</tr>';
1353 
1354  // Model pdf
1355  print '<tr><td class="nowrap">';
1356  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1357  print $langs->trans('Model');
1358  print '<td>';
1359  if ($action != 'editmodelpdf' && $usercancreate && $object->statut == FactureFournisseurRec::STATUS_NOTSUSPENDED) {
1360  print '<td class="right"><a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=editmodelpdf&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->trans('SetModel'), 1) . '</a></td>';
1361  }
1362  print '</tr></table>';
1363  print '</td><td>';
1364  if ($action == 'editmodelpdf') {
1365  include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_invoice/modules_facturefournisseur.php';
1366  $list = array();
1368  foreach ($models as $k => $model) {
1369  $list[] = str_replace(':', '|', $k) . ':' . $model;
1370  }
1371  $select = 'select;' . implode(',', $list);
1372  //TODO : Droits
1373  print $form->editfieldval($langs->trans('Model'), 'modelpdf', $object->model_pdf, $object, $usercancreate, $select);
1374  } else {
1375  print $object->model_pdf;
1376  }
1377  print "</td>";
1378  print '</tr>';
1379 
1380  // Other attributes
1381  $cols = 2;
1382  include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
1383 
1384  print '</table>';
1385 
1386  print '</div>';
1387  print '<div class="fichehalfright">';
1388  print '<div class="underbanner clearboth"></div>';
1389 
1390  /*
1391  * Recurrence
1392  */
1393  $title = $langs->trans("Recurrence");
1394  //print load_fiche_titre($title, '', 'calendar');
1395 
1396  print '<table class="border centpercent tableforfield">';
1397 
1398  print '<tr><td colspan="2">' . img_picto('', 'recurring', 'class="pictofixedwidth"') . $title . '</td></tr>';
1399 
1400  // if "frequency" is empty or = 0, the reccurence is disabled
1401  print '<tr><td style="width: 50%">';
1402  print '<table class="nobordernopadding" width="100%"><tr><td>';
1403  print $langs->trans('Frequency');
1404  print '</td>';
1405  if ($action != 'editfrequency' && $usercancreate) {
1406  print '<td class="right"><a class="editfielda" href="' . $_SERVER["PHP_SELF"] . '?action=editfrequency&token=' . newToken() . '&facid=' . $object->id . '">' . img_edit($langs->trans('Edit'), 1) . '</a></td>';
1407  }
1408  print '</tr></table>';
1409  print '</td><td>';
1410  if ($action == 'editfrequency') {
1411  print '<form method="post" action="' . $_SERVER["PHP_SELF"] . '?facid=' . $object->id . '">';
1412  print '<input type="hidden" name="action" value="setfrequency">';
1413  print '<input type="hidden" name="token" value="' . newToken() . '">';
1414  print '<table class="nobordernopadding">';
1415  print '<tr><td>';
1416  print "<input type='text' name='frequency' value='" . $object->frequency . "' size='5' />&nbsp;" . $form->selectarray('unit_frequency', array('d' => $langs->trans('Day'), 'm' => $langs->trans('Month'), 'y' => $langs->trans('Year')), ($object->unit_frequency ? $object->unit_frequency : 'm'));
1417  print '</td>';
1418  print '<td class="left"><input type="submit" class="button button-edit" value="' . $langs->trans("Modify") . '"></td>';
1419  print '</tr></table></form>';
1420  } else {
1421  if ($object->frequency > 0) {
1422  print $langs->trans('FrequencyPer_' . $object->unit_frequency, $object->frequency);
1423  } else {
1424  print $langs->trans("NotARecurringInvoiceTemplate");
1425  }
1426  }
1427  print '</td></tr>';
1428 
1429  // Date when (next invoice generation)
1430  print '<tr><td>';
1431  if ($action == 'date_when' || $object->frequency > 0) {
1432  print $form->editfieldkey($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $usercancreate, 'day');
1433  } else {
1434  print $langs->trans("NextDateToExecution");
1435  }
1436  print '</td><td>';
1437  if ($action == 'date_when' || $object->frequency > 0) {
1438  print $form->editfieldval($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $usercancreate, 'day', $object->date_when, null, '', '', 0, 'strikeIfMaxNbGenReached');
1439  }
1440  //var_dump(dol_print_date($object->date_when+60, 'dayhour').' - '.dol_print_date($now, 'dayhour'));
1441  if (! $object->isMaxNbGenReached()) {
1442  if (! $object->suspended && $action != 'editdate_when' && $object->frequency > 0 && $object->date_when && $object->date_when < $now) {
1443  print img_warning($langs->trans("Late"));
1444  }
1445  } else {
1446  print img_info($langs->trans("MaxNumberOfGenerationReached"));
1447  }
1448  print '</td>';
1449  print '</tr>';
1450 
1451  // Max period / Rest period
1452  print '<tr><td>';
1453  if ($action == 'nb_gen_max' || $object->frequency > 0) {
1454  print $form->editfieldkey($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max, $object, $usercancreate);
1455  } else {
1456  print $langs->trans("MaxPeriodNumber");
1457  }
1458  print '</td><td>';
1459  if ($action == 'nb_gen_max' || $object->frequency > 0) {
1460  print $form->editfieldval($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max ? $object->nb_gen_max : '', $object, $usercancreate);
1461  } else {
1462  print '';
1463  }
1464  print '</td>';
1465  print '</tr>';
1466 
1467  // Status of generated invoices
1468  print '<tr><td>';
1469  if ($action == 'auto_validate' || $object->frequency > 0) {
1470  print $form->editfieldkey($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $usercancreate);
1471  } else {
1472  print $langs->trans("StatusOfGeneratedInvoices");
1473  }
1474  print '</td><td>';
1475  $select = 'select;0:' . $langs->trans('BillStatusDraft') . ',1:' . $langs->trans('BillStatusValidated');
1476  if ($action == 'auto_validate' || $object->frequency > 0) {
1477  print $form->editfieldval($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $usercancreate, $select);
1478  }
1479  print '</td>';
1480  // Auto generate documents
1481  if (! empty($conf->global->INVOICE_REC_CAN_DISABLE_DOCUMENT_FILE_GENERATION)) {
1482  print '<tr>';
1483  print '<td>';
1484  if ($action == 'generate_pdf' || $object->frequency > 0) {
1485  print $form->editfieldkey($langs->trans("StatusOfGeneratedDocuments"), 'generate_pdf', $object->generate_pdf, $object, $usercancreate);
1486  } else {
1487  print $langs->trans("StatusOfGeneratedDocuments");
1488  }
1489  print '</td>';
1490  print '<td>';
1491  $select = 'select;0:' . $langs->trans('DoNotGenerateDoc') . ',1:' . $langs->trans('AutogenerateDoc');
1492  if ($action == 'generate_pdf' || $object->frequency > 0) {
1493  print $form->editfieldval($langs->trans("StatusOfGeneratedDocuments"), 'generate_pdf', $object->generate_pdf, $object, $usercancreate, $select);
1494  }
1495  print '</td>';
1496  print '</tr>';
1497  } else {
1498  print '<input type="hidden" name="generate_pdf" value="1">';
1499  }
1500 
1501  print '</table>';
1502 
1503  // Frequencry/Recurring section
1504  if ($object->frequency > 0) {
1505  print '<br>';
1506 
1507  if (empty($conf->cron->enabled)) {
1508  print info_admin($langs->trans("EnableAndSetupModuleCron", $langs->transnoentitiesnoconv("Module2300Name")));
1509  }
1510 
1511  print '<div class="underbanner clearboth"></div>';
1512  print '<table class="border centpercent tableforfield">';
1513 
1514  // Nb of generation already done
1515  print '<tr><td style="width: 50%">' . $langs->trans("NbOfGenerationDone") . '</td>';
1516  print '<td>';
1517  print $object->nb_gen_done ? $object->nb_gen_done : '0';
1518  print '</td>';
1519  print '</tr>';
1520 
1521  // Date last
1522  print '<tr><td>';
1523  print $langs->trans("DateLastGeneration");
1524  print '</td><td>';
1525  print dol_print_date($object->date_last_gen, 'dayhour');
1526  print '</td>';
1527  print '</tr>';
1528 
1529  print '</table>';
1530 
1531  print '<br>';
1532  }
1533 
1534  print '</div>';
1535  print '</div>';
1536 
1537  print '<div class="clearboth"></div><br>';
1538 
1539  // Lines
1540  print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '#add' : '#line_' . GETPOST('lineid', 'int')) . '" method="POST">
1541  <input type="hidden" name="token" value="' . newToken() . '">
1542  <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline') . '">
1543  <input type="hidden" name="mode" value="">
1544  <input type="hidden" name="id" value="' . $object->id . '">
1545  ';
1546 
1547  if (! empty($conf->use_javascript_ajax) && $object->statut == 0) {
1548  include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
1549  }
1550 
1551  print '<div class="div-table-responsive-no-min">';
1552  print '<table id="tablelines" class="noborder noshadow" width="100%">';
1553  $object->fetch_lines();
1554  // Show object lines
1555  if (! empty($object->lines)) {
1556  $canchangeproduct = 1;
1557  // To set ref for getNomURL function
1558  foreach ($object->lines as $line) {
1559  $line->ref = $line->label;
1560  $line->product_label = $line->label;
1561  $line->subprice = $line->pu_ht;
1562  }
1563 
1564  global $canchangeproduct;
1565  $canchangeproduct = 0;
1566 
1567  $object->statut = $object->suspended;
1568  $object->printObjectLines($action, $mysoc, $object->thirdparty, $lineid, 0); // No date selector for template invoice
1569  }
1570 
1571  // Form to add new line
1572  //TODO : Droits
1573  if ($object->statut == $object::STATUS_DRAFT && $usercancreate && $action != 'valid' && $action != 'editline') {
1574  if ($action != 'editline') {
1575  // Add free products/services
1576 
1577  $parameters = array();
1578  $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1579  if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1580  if (empty($reshook))
1581  global $senderissupplier;
1582  $senderissupplier = 2;
1583  $object->formAddObjectLine(0, $object->thirdparty, $mysoc); // No date selector for template invoice
1584  }
1585  }
1586 
1587  print "</table>\n";
1588  print '</div>';
1589 
1590  print "</form>\n";
1591 
1592  print dol_get_fiche_end();
1593 
1594  /*
1595  * Action bar
1596  */
1597  print '<div class="tabsAction">';
1598 
1599  if (empty($object->suspended)) {
1600  if ($usercancreate) {
1601  if (! empty($object->frequency) && $object->nb_gen_max > 0 && ($object->nb_gen_done >= $object->nb_gen_max)) {
1602  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag($langs->trans("MaxGenerationReached")) . '">' . $langs->trans("CreateBill") . '</a></div>';
1603  } else {
1604  if (empty($object->frequency) || $object->date_when <= $nowlasthour) {
1605  print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/fourn/facture/card.php?action=create&socid=' . $object->thirdparty->id . '&fac_rec=' . $object->id . '">' . $langs->trans("CreateBill") . '</a></div>';
1606  } else {
1607  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag($langs->trans("DateIsNotEnough")) . '">' . $langs->trans("CreateBill") . '</a></div>';
1608  }
1609  }
1610  } else {
1611  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">' . $langs->trans("CreateBill") . '</a></div>';
1612  }
1613  }
1614 
1615  if ($usercancreate) {
1616  if (empty($object->suspended)) {
1617  print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?action=disable&id=' . $object->id . '&token=' . newToken() . '">' . $langs->trans("Disable") . '</a></div>';
1618  } else {
1619  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=enable&id=' . $object->id . '&token=' . newToken() . '">' . $langs->trans("Enable") . '</a></div>';
1620  }
1621  }
1622 
1623  //if ($object->statut == Facture::STATUS_DRAFT && ($user->rights->fournisseur->facture->supprimer || $user->rights->supplier_invoice->supprimer))
1624  if (($user->rights->fournisseur->facture->supprimer || $user->rights->supplier_invoice->supprimer)) {
1625  print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER['PHP_SELF'] . '?action=ask_deleteinvoice&id=' . $object->id . '&token=' . newToken() . '">' . $langs->trans('Delete') . '</a></div>';
1626  }
1627 
1628  print '</div>';
1629 
1630  print '<div class="fichecenter"><div class="fichehalfleft">';
1631  print '<a name="builddoc"></a>'; // ancre
1632 
1633  // Show links to link elements
1634  $linktoelem = $form->showLinkToObjectBlock($object, null, array('invoice'));
1635 
1636  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1637 
1638  print '</div></div>';
1639  }
1640 }
1641 
1642 // End of page
1643 llxFooter();
1644 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
Class to manage suppliers invoices.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate, from a $thirdparty_buyer to a $thirdparty_seller Note: This function applies same rules than get_default_tva.
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save"&&empty($cancel)) $help_url
View.
Definition: agenda.php:116
Class to manage supplier invoice lines of templates.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:121
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
static getIdAndTxFromCode($dbs, $code, $date_document= '')
Get id and rate of currency from code.
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form...
dol_get_last_hour($date, $gm= 'tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
Definition: date.lib.php:597
Class to manage third parties objects (customers, suppliers, prospects...)
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= 'hideonsmartphone', $textfordropdown= '')
Show information for admin users or standard users.
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Class to manage building of HTML components.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
Classe permettant la generation de composants html autre Only common components are here...
Class to manage invoice templates.
Class to manage translations.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation models.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
div float
Buy price without taxes.
Definition: style.css.php:809
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
supplier_invoice_rec_prepare_head($object)
Return array head with list of tabs to view object informations.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
img_info($titlealt= 'default')
Show info logo.
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:73
$formconfirm
if ($action == &#39;delbookkeepingyear&#39;) {
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.
Class to manage predefined suppliers products.