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