dolibarr  7.0.0-beta
fiche-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@capnetworks.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.dolibarr@gmail.com>
10  * Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr>
11  * Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
25  */
26 
33 require '../../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
37 if (! empty($conf->projet->enabled)) {
38  require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
39  //require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.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 $langs->load('bills');
47 $langs->load('compta');
48 $langs->load('admin');
49 $langs->load('other');
50 
51 $action = GETPOST('action','alpha');
52 $massaction = GETPOST('massaction','alpha');
53 $show_files = GETPOST('show_files','int');
54 $confirm = GETPOST('confirm','alpha');
55 $cancel = GETPOST('cancel', 'alpha');
56 $toselect = GETPOST('toselect', 'array');
57 $contextpage= GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'invoicetemplatelist'; // To manage different context of search
58 
59 // Security check
60 $id=(GETPOST('facid','int')?GETPOST('facid','int'):GETPOST('id','int'));
61 $lineid=GETPOST('lineid','int');
62 $ref=GETPOST('ref','alpha');
63 if ($user->societe_id) $socid=$user->societe_id;
64 $objecttype = 'facture_rec';
65 if ($action == "create" || $action == "add") $objecttype = '';
66 $result = restrictedArea($user, 'facture', $id, $objecttype);
67 $projectid = GETPOST('projectid','int');
68 
69 $search_ref=GETPOST('search_ref');
70 $search_societe=GETPOST('search_societe');
71 $search_montant_ht=GETPOST('search_montant_ht');
72 $search_montant_vat=GETPOST('search_montant_vat');
73 $search_montant_ttc=GETPOST('search_montant_ttc');
74 $search_payment_mode=GETPOST('search_payment_mode');
75 $search_payment_term=GETPOST('search_payment_term');
76 $day=GETPOST('day');
77 $year=GETPOST('year');
78 $month=GETPOST('month');
79 $day_date_when=GETPOST('day_date_when');
80 $year_date_when=GETPOST('year_date_when');
81 $month_date_when=GETPOST('month_date_when');
82 $search_recurring=GETPOST('search_recurring','int');
83 $search_frequency=GETPOST('search_frequency','alpha');
84 $search_unit_frequency=GETPOST('search_unit_frequency','alpha');
85 
86 $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
87 $sortfield = GETPOST("sortfield",'alpha');
88 $sortorder = GETPOST("sortorder",'alpha');
89 $page = GETPOST("page",'int');
90 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
91 $offset = $limit * $page;
92 if (! $sortorder) $sortorder='DESC';
93 if (! $sortfield) $sortfield='f.titre';
94 $pageprev = $page - 1;
95 $pagenext = $page + 1;
96 
97 $object = new FactureRec($db);
98 if (($id > 0 || $ref) && $action != 'create' && $action != 'add')
99 {
100  $ret = $object->fetch($id, $ref);
101  if (!$ret)
102  {
103  setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
104  }
105 }
106 
107 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
108 $hookmanager->initHooks(array('invoicereccard','globalcard'));
109 $extrafields = new ExtraFields($db);
110 
111 // fetch optionals attributes and labels
112 $extralabels = $extrafields->fetch_name_optionals_label('facture_rec');
113 $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
114 
115 $permissionnote = $user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php
116 $permissiondellink=$user->rights->facture->creer; // Used by the include of actions_dellink.inc.php
117 $permissiontoedit = $user->rights->facture->creer; // Used by the include of actions_lineupdonw.inc.php
118 
119 
120 /*
121  * Actions
122  */
123 
124 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
125 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
126 
127 $parameters = array('socid' => $socid);
128 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
129 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
130 
131 if (empty($reshook))
132 {
133  if (GETPOST('cancel','alpha')) $action='';
134 
135  // Selection of new fields
136  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
137 
138  // Set note
139  include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
140 
141  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
142 
143  include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
144 
145  // Do we click on purge search criteria ?
146  if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers
147  {
148  $search_ref='';
149  $search_societe='';
150  $search_montant_ht='';
151  $search_montant_vat='';
152  $search_montant_ttc='';
153  $search_montant_mode='';
154  $search_montant_term='';
155  $day='';
156  $year='';
157  $month='';
158  $day_date_when='';
159  $year_date_when='';
160  $month_date_when='';
161  $search_recurring='';
162  $search_frequency='';
163  $search_unit_frequency='';
164  $search_array_options=array();
165  }
166 
167  // Mass actions
168  /*$objectclass='MyObject';
169  $objectlabel='MyObject';
170  $permtoread = $user->rights->mymodule->read;
171  $permtodelete = $user->rights->mymodule->delete;
172  $uploaddir = $conf->mymodule->dir_output;
173  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';*/
174 
175  // Create predefined invoice
176  if ($action == 'add')
177  {
178  if (! GETPOST('titre'))
179  {
180  setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("Title")), null, 'errors');
181  $action = "create";
182  $error++;
183  }
184 
185  $frequency=GETPOST('frequency', 'int');
186  $reyear=GETPOST('reyear');
187  $remonth=GETPOST('remonth');
188  $reday=GETPOST('reday');
189  $rehour=GETPOST('rehour');
190  $remin=GETPOST('remin');
191  $nb_gen_max=GETPOST('nb_gen_max', 'int');
192  //if (empty($nb_gen_max)) $nb_gen_max =0;
193 
194  if (GETPOST('frequency'))
195  {
196  if (empty($reyear) || empty($remonth) || empty($reday))
197  {
198  setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("Date")), null, 'errors');
199  $action = "create";
200  $error++;
201  }
202  if ($nb_gen_max === '')
203  {
204  setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("MaxPeriodNumber")), null, 'errors');
205  $action = "create";
206  $error++;
207  }
208  }
209 
210  if (! $error)
211  {
212  $object->titre = GETPOST('titre', 'alpha');
213  $object->note_private = GETPOST('note_private','none');
214  $object->note_public = GETPOST('note_public','none');
215  $object->modelpdf = GETPOST('modelpdf', 'alpha');
216  $object->usenewprice = GETPOST('usenewprice');
217 
218  $object->frequency = $frequency;
219  $object->unit_frequency = GETPOST('unit_frequency', 'alpha');
220  $object->nb_gen_max = $nb_gen_max;
221  $object->auto_validate = GETPOST('auto_validate', 'int');
222  $object->generate_pdf = GETPOST('generate_pdf', 'int');
223  $object->fk_project = $projectid;
224 
225  $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear);
226  $object->date_when = $date_next_execution;
227 
228  // Get first contract linked to invoice used to generate template (facid is id of source invoice)
229  if (GETPOST('facid','int') > 0)
230  {
231  $srcObject = new Facture($db);
232  $srcObject->fetch(GETPOST('facid','int'));
233 
234  $srcObject->fetchObjectLinked();
235 
236  if (! empty($srcObject->linkedObjectsIds['contrat']))
237  {
238  $contractidid = reset($srcObject->linkedObjectsIds['contrat']);
239 
240  $object->origin = 'contrat';
241  $object->origin_id = $contractidid;
242  $object->linked_objects[$object->origin] = $object->origin_id;
243  }
244  }
245 
246  $db->begin();
247 
248  $oldinvoice = new Facture($db);
249  $oldinvoice->fetch(GETPOST('facid','int'));
250 
251  $result = $object->create($user, $oldinvoice->id);
252  if ($result > 0)
253  {
254  $result=$oldinvoice->delete($user, 1);
255  if ($result < 0)
256  {
257  $error++;
258  setEventMessages($oldinvoice->error, $oldinvoice->errors, 'errors');
259  $action = "create";
260  }
261  }
262  else
263  {
264  $error++;
265  setEventMessages($object->error, $object->errors, 'errors');
266  $action = "create";
267  }
268 
269  if (! $error)
270  {
271  $db->commit();
272 
273  header("Location: " . $_SERVER['PHP_SELF'] . '?facid=' . $object->id);
274  exit;
275  }
276  else
277  {
278  $db->rollback();
279 
280  $error++;
281  setEventMessages($object->error, $object->errors, 'errors');
282  $action = "create";
283  }
284  }
285  }
286 
287  // Delete
288  if ($action == 'confirm_deleteinvoice' && $confirm == 'yes' && $user->rights->facture->supprimer)
289  {
290  $object->delete($user);
291 
292  header("Location: " . DOL_URL_ROOT.'/compta/facture/invoicetemplate_list.php');
293  exit;
294  }
295 
296 
297  // Update field
298  // Set condition
299  if ($action == 'setconditions' && $user->rights->facture->creer)
300  {
301  $result=$object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
302 
303  }
304  // Set mode
305  elseif ($action == 'setmode' && $user->rights->facture->creer)
306  {
307  $result=$object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
308  }
309  // Set project
310  elseif ($action == 'classin' && $user->rights->facture->creer)
311  {
312  $object->setProject(GETPOST('projectid', 'int'));
313  }
314  // Set bank account
315  elseif ($action == 'setref' && $user->rights->facture->creer)
316  {
317  //var_dump(GETPOST('ref', 'alpha'));exit;
318  $result=$object->setValueFrom('titre', GETPOST('ref', 'alpha'), '', null, 'text', '', $user, 'BILLREC_MODIFY');
319  if ($result > 0)
320  {
321  $object->titre = GETPOST('ref', 'alpha');
322  $object->ref = $object->titre;
323  }
324  else dol_print_error($db, $object->error, $object->errors);
325  }
326  // Set bank account
327  elseif ($action == 'setbankaccount' && $user->rights->facture->creer)
328  {
329  $result=$object->setBankAccount(GETPOST('fk_account', 'int'));
330  }
331  // Set frequency and unit frequency
332  elseif ($action == 'setfrequency' && $user->rights->facture->creer)
333  {
334  $object->setFrequencyAndUnit(GETPOST('frequency', 'int'), GETPOST('unit_frequency', 'alpha'));
335  }
336  // Set next date of execution
337  elseif ($action == 'setdate_when' && $user->rights->facture->creer)
338  {
339  $date = dol_mktime(GETPOST('date_whenhour'), GETPOST('date_whenmin'), 0, GETPOST('date_whenmonth'), GETPOST('date_whenday'), GETPOST('date_whenyear'));
340  if (!empty($date)) $object->setNextDate($date);
341  }
342  // Set max period
343  elseif ($action == 'setnb_gen_max' && $user->rights->facture->creer)
344  {
345  $object->setMaxPeriod(GETPOST('nb_gen_max', 'int'));
346  }
347  // Set auto validate
348  elseif ($action == 'setauto_validate' && $user->rights->facture->creer)
349  {
350  $object->setAutoValidate(GETPOST('auto_validate', 'int'));
351  }
352  // Set generate pdf
353  elseif ($action == 'setgenerate_pdf' && $user->rights->facture->creer)
354  {
355  $object->setGeneratepdf(GETPOST('generate_pdf', 'int'));
356  }
357  // Set model pdf
358  elseif ($action == 'setmodelpdf' && $user->rights->facture->creer)
359  {
360  $object->setModelpdf(GETPOST('modelpdf', 'alpha'));
361  }
362 
363  // Set status disabled
364  elseif ($action == 'disable' && $user->rights->facture->creer)
365  {
366  $db->begin();
367 
368  $object->fetch($id);
369 
370  $res = $object->setValueFrom('suspended', 1);
371  if ($res <= 0)
372  {
373  $error++;
374  }
375 
376  if (! $error)
377  {
378  $db->commit();
379  }
380  else
381  {
382  $db->rollback();
383  setEventMessages($object->error, $object->errors, 'errors');
384  }
385  }
386 
387  // Set status enabled
388  elseif ($action == 'enable' && $user->rights->facture->creer)
389  {
390  $db->begin();
391 
392  $object->fetch($id);
393 
394  $res = $object->setValueFrom('suspended', 0);
395  if ($res <= 0)
396  {
397  $error++;
398  }
399 
400  if (! $error)
401  {
402  $db->commit();
403  }
404  else
405  {
406  $db->rollback();
407  setEventMessages($object->error, $object->errors, 'errors');
408  }
409  }
410 
411  // Delete line
412  if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->facture->creer)
413  {
414  $object->fetch($id);
415  $object->fetch_thirdparty();
416 
417  $db->begin();
418 
419  $line=new FactureLigneRec($db);
420 
421  // For triggers
422  $line->id = $lineid;
423 
424  if ($line->delete($user) > 0)
425  {
426  $result=$object->update_price(1);
427 
428  if ($result > 0)
429  {
430  $db->commit();
431  $object->fetch($object->id); // Reload lines
432  }
433  else
434  {
435  $db->rollback();
436  setEventMessages($db->lasterror(), null, 'errors');
437  }
438  }
439  else
440  {
441  $db->rollback();
442  setEventMessages($line->error, $line->errors, 'errors');
443  }
444  }
445  else if ($action == 'update_extras')
446  {
447  // Fill array 'array_options' with data from update form
448  $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
449  $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
450  if ($ret < 0) $error++;
451 
452  if (! $error) {
453  $result = $object->insertExtraFields();
454  if ($result < 0)
455  {
456  setEventMessages($object->error, $object->errors, 'errors');
457  $error++;
458  }
459  }
460  }
461 
462  // Add a new line
463  if ($action == 'addline' && $user->rights->facture->creer)
464  {
465  $langs->load('errors');
466  $error = 0;
467 
468  // Set if we used free entry or predefined product
469  $predef='';
470  $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
471  $price_ht = GETPOST('price_ht');
472  if (GETPOST('prod_entry_mode') == 'free')
473  {
474  $idprod=0;
475  $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
476  }
477  else
478  {
479  $idprod=GETPOST('idprod', 'int');
480  $tva_tx = '';
481  }
482 
483  $qty = GETPOST('qty' . $predef);
484  $remise_percent = GETPOST('remise_percent' . $predef);
485 
486  // Extrafields
487  $extrafieldsline = new ExtraFields($db);
488  $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
489  $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
490  // Unset extrafield
491  if (is_array($extralabelsline))
492  {
493  // Get extra fields
494  foreach ($extralabelsline as $key => $value) {
495  unset($_POST["options_" . $key . $predef]);
496  }
497  }
498 
499  if (empty($idprod) && ($price_ht < 0) && ($qty < 0)) {
500  setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
501  $error ++;
502  }
503  if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && GETPOST('type') < 0) {
504  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors');
505  $error ++;
506  }
507  if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && (! ($price_ht >= 0) || $price_ht == '')) // Unit price can be 0 but not ''
508  {
509  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors');
510  $error ++;
511  }
512  if ($qty == '') {
513  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
514  $error ++;
515  }
516  if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && empty($product_desc)) {
517  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors');
518  $error ++;
519  }
520  if ($qty < 0) {
521  $langs->load("errors");
522  setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors');
523  $error ++;
524  }
525 
526  if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod)))
527  {
528  $ret = $object->fetch($id);
529  if ($ret < 0) {
530  dol_print_error($db, $object->error);
531  exit();
532  }
533  $ret = $object->fetch_thirdparty();
534 
535  // Clean parameters
536  $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'));
537  $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'));
538  $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
539 
540  // Define special_code for special lines
541  $special_code = 0;
542  // if (empty($_POST['qty'])) $special_code=3; // Options should not exists on invoices
543 
544  // Ecrase $pu par celui du produit
545  // Ecrase $desc par celui du produit
546  // Ecrase $tva_tx par celui du produit
547  // Ecrase $base_price_type par celui du produit
548  // Replaces $fk_unit with the product's
549  if (! empty($idprod))
550  {
551  $prod = new Product($db);
552  $prod->fetch($idprod);
553 
554  $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : '');
555 
556  // Update if prices fields are defined
557  $tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
558  $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
559  if (empty($tva_tx)) $tva_npr=0;
560 
561  $pu_ht = $prod->price;
562  $pu_ttc = $prod->price_ttc;
563  $price_min = $prod->price_min;
564  $price_base_type = $prod->price_base_type;
565 
566  // We define price for product
567  if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level))
568  {
569  $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
570  $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
571  $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
572  $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
573  if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility
574  {
575  if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) $tva_tx=$prod->multiprices_tva_tx[$object->thirdparty->price_level];
576  if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) $tva_npr=$prod->multiprices_recuperableonly[$object->thirdparty->price_level];
577  if (empty($tva_tx)) $tva_npr=0;
578  }
579  }
580  elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
581  {
582  require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
583 
584  $prodcustprice = new Productcustomerprice($db);
585 
586  $filter = array('t.fk_product' => $prod->id,'t.fk_soc' => $object->thirdparty->id);
587 
588  $result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
589  if ($result)
590  {
591  if (count($prodcustprice->lines) > 0)
592  {
593  $pu_ht = price($prodcustprice->lines[0]->price);
594  $pu_ttc = price($prodcustprice->lines[0]->price_ttc);
595  $price_base_type = $prodcustprice->lines[0]->price_base_type;
596  $tva_tx = $prodcustprice->lines[0]->tva_tx;
597  if ($prodcustprice->lines[0]->default_vat_code && ! preg_match('/\(.*\)/', $tva_tx)) $tva_tx.= ' ('.$prodcustprice->lines[0]->default_vat_code.')';
598  $tva_npr = $prodcustprice->lines[0]->recuperableonly;
599  if (empty($tva_tx)) $tva_npr=0;
600  }
601  }
602  }
603 
604  $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
605  $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx));
606 
607  // if price ht was forced (ie: from gui when calculated by margin rate and cost price). TODO Why this ?
608  if (! empty($price_ht))
609  {
610  $pu_ht = price2num($price_ht, 'MU');
611  $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
612  }
613  // On reevalue prix selon taux tva car taux tva transaction peut etre different
614  // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
615  elseif ($tmpvat != $tmpprodvat)
616  {
617  if ($price_base_type != 'HT')
618  {
619  $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');
620  }
621  else
622  {
623  $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
624  }
625  }
626 
627  $desc = '';
628 
629  // Define output language
630  if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
631  {
632  $outputlangs = $langs;
633  $newlang = '';
634  if (empty($newlang) && GETPOST('lang_id','aZ09'))
635  $newlang = GETPOST('lang_id','aZ09');
636  if (empty($newlang))
637  $newlang = $object->thirdparty->default_lang;
638  if (! empty($newlang))
639  {
640  $outputlangs = new Translate("", $conf);
641  $outputlangs->setDefaultLang($newlang);
642  }
643 
644  $desc = (! empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description;
645  }
646  else
647  {
648  $desc = $prod->description;
649  }
650 
651  $desc = dol_concatdesc($desc, $product_desc);
652 
653  // Add custom code and origin country into description
654  if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code)))
655  {
656  $tmptxt = '(';
657  if (! empty($prod->customcode))
658  $tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
659  if (! empty($prod->customcode) && ! empty($prod->country_code))
660  $tmptxt .= ' - ';
661  if (! empty($prod->country_code))
662  $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
663  $tmptxt .= ')';
664  $desc = dol_concatdesc($desc, $tmptxt);
665 
666  }
667 
668  $type = $prod->type;
669  $fk_unit = $prod->fk_unit;
670 
671  }
672  else
673  {
674  $pu_ht = price2num($price_ht, 'MU');
675  $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
676  $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
677  $tva_tx = str_replace('*', '', $tva_tx);
678  if (empty($tva_tx)) $tva_npr=0;
679  $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
680  $desc = $product_desc;
681  $type = GETPOST('type');
682  $fk_unit= GETPOST('units', 'alpha');
683  }
684 
685  // Margin
686  $fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : '');
687  $buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we must keep this value
688 
689  // Local Taxes
690  $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
691  $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
692 
693  $info_bits = 0;
694  if ($tva_npr)
695  $info_bits |= 0x01;
696 
697  if (! empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min)))
698  {
699  $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
700  setEventMessages($mesg, null, 'errors');
701  }
702  else
703  {
704  // Insert line
705  $result = $object->addline($desc, $pu_ht, $qty, $tva_tx,$localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $info_bits, '', $pu_ttc, $type, - 1, $special_code, $label, $fk_unit);
706 
707  if ($result > 0)
708  {
709  /*if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
710  {
711  // Define output language
712  $outputlangs = $langs;
713  $newlang = '';
714  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
715  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
716  if (! empty($newlang)) {
717  $outputlangs = new Translate("", $conf);
718  $outputlangs->setDefaultLang($newlang);
719  }
720  $model=$object->modelpdf;
721  $ret = $object->fetch($id); // Reload to get new records
722 
723  $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
724  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
725  }*/
726  $object->fetch($object->id); // Reload lines
727 
728  unset($_POST['prod_entry_mode']);
729 
730  unset($_POST['qty']);
731  unset($_POST['type']);
732  unset($_POST['remise_percent']);
733  unset($_POST['price_ht']);
734  unset($_POST['multicurrency_price_ht']);
735  unset($_POST['price_ttc']);
736  unset($_POST['tva_tx']);
737  unset($_POST['product_ref']);
738  unset($_POST['product_label']);
739  unset($_POST['product_desc']);
740  unset($_POST['fournprice']);
741  unset($_POST['buying_price']);
742  unset($_POST['np_marginRate']);
743  unset($_POST['np_markRate']);
744  unset($_POST['dp_desc']);
745  unset($_POST['idprod']);
746  unset($_POST['units']);
747 
748  unset($_POST['date_starthour']);
749  unset($_POST['date_startmin']);
750  unset($_POST['date_startsec']);
751  unset($_POST['date_startday']);
752  unset($_POST['date_startmonth']);
753  unset($_POST['date_startyear']);
754  unset($_POST['date_endhour']);
755  unset($_POST['date_endmin']);
756  unset($_POST['date_endsec']);
757  unset($_POST['date_endday']);
758  unset($_POST['date_endmonth']);
759  unset($_POST['date_endyear']);
760 
761  unset($_POST['situations']);
762  unset($_POST['progress']);
763  }
764  else
765  {
766  setEventMessages($object->error, $object->errors, 'errors');
767  }
768 
769  $action = '';
770  }
771  }
772  }
773 
774  elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST('cancel','alpha'))
775  {
776  if (! $object->fetch($id) > 0) dol_print_error($db);
777  $object->fetch_thirdparty();
778 
779  // Clean parameters
780  $date_start = '';
781  $date_end = '';
782  //$date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
783  //$date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
784  $description = dol_htmlcleanlastbr(GETPOST('product_desc','none') ? GETPOST('product_desc','none') : GETPOST('desc','none'));
785  $pu_ht = GETPOST('price_ht');
786  $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
787  $qty = GETPOST('qty');
788  $pu_ht_devise = GETPOST('multicurrency_subprice');
789 
790  // Define info_bits
791  $info_bits = 0;
792  if (preg_match('/\*/', $vat_rate))
793  $info_bits |= 0x01;
794 
795  // Define vat_rate
796  $vat_rate = str_replace('*', '', $vat_rate);
797  $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty);
798  $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty);
799 
800  // Add buying price
801  $fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
802  $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
803 
804  // Extrafields
805  $extrafieldsline = new ExtraFields($db);
806  $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
807  $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
808 
809  $objectline = new FactureLigneRec($db);
810  if ($objectline->fetch(GETPOST('lineid')))
811  {
812  $objectline->array_options=$array_options;
813  $result=$objectline->insertExtraFields();
814  if ($result < 0)
815  {
816  setEventMessages($langs->trans('Error').$result, null, 'errors');
817  }
818  }
819 
820  // Unset extrafield
821  if (is_array($extralabelsline))
822  {
823  // Get extra fields
824  foreach ($extralabelsline as $key => $value)
825  {
826  unset($_POST["options_" . $key]);
827  }
828  }
829 
830  // Define special_code for special lines
831  $special_code=GETPOST('special_code');
832  if (! GETPOST('qty')) $special_code=3;
833 
834  /*$line = new FactureLigne($db);
835  $line->fetch(GETPOST('lineid'));
836  $percent = $line->get_prev_progress($object->id);
837 
838  if (GETPOST('progress') < $percent)
839  {
840  $mesg = '<div class="warning">' . $langs->trans("CantBeLessThanMinPercent") . '</div>';
841  setEventMessages($mesg, null, 'warnings');
842  $error++;
843  $result = -1;
844  }*/
845 
846  // Check minimum price
847  $productid = GETPOST('productid', 'int');
848  if (! empty($productid))
849  {
850  $product = new Product($db);
851  $product->fetch($productid);
852 
853  $type = $product->type;
854 
855  $price_min = $product->price_min;
856  if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level))
857  $price_min = $product->multiprices_min [$object->thirdparty->price_level];
858 
859  $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
860 
861  // Check price is not lower than minimum (check is done only for standard or replacement invoices)
862  if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) && $price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) {
863  setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors');
864  $error ++;
865  }
866  } else {
867  $type = GETPOST('type');
868  $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
869 
870  // Check parameters
871  if (GETPOST('type') < 0) {
872  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
873  $error ++;
874  }
875  }
876  if ($qty < 0) {
877  $langs->load("errors");
878  setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors');
879  $error ++;
880  }
881 
882  // Update line
883  if (! $error)
884  {
885  $result = $object->updateline(
886  GETPOST('lineid'),
887  $description,
888  $pu_ht,
889  $qty,
890  $vat_rate,
891  $localtax1_rate,
892  $localtax1_rate,
893  GETPOST('productid'),
894  GETPOST('remise_percent'),
895  'HT',
896  $info_bits,
897  0,
898  0,
899  $type,
900  0,
901  $special_code,
902  $label,
903  GETPOST('units'),
904  $pu_ht_devise
905  );
906 
907  if ($result >= 0)
908  {
909  /*if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
910  // Define output language
911  $outputlangs = $langs;
912  $newlang = '';
913  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09'))
914  $newlang = GETPOST('lang_id','aZ09');
915  if ($conf->global->MAIN_MULTILANGS && empty($newlang))
916  $newlang = $object->thirdparty->default_lang;
917  if (! empty($newlang)) {
918  $outputlangs = new Translate("", $conf);
919  $outputlangs->setDefaultLang($newlang);
920  }
921 
922  $ret = $object->fetch($id); // Reload to get new records
923  $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
924  }*/
925 
926  $object->fetch($object->id); // Reload lines
927 
928  unset($_POST['qty']);
929  unset($_POST['type']);
930  unset($_POST['productid']);
931  unset($_POST['remise_percent']);
932  unset($_POST['price_ht']);
933  unset($_POST['multicurrency_price_ht']);
934  unset($_POST['price_ttc']);
935  unset($_POST['tva_tx']);
936  unset($_POST['product_ref']);
937  unset($_POST['product_label']);
938  unset($_POST['product_desc']);
939  unset($_POST['fournprice']);
940  unset($_POST['buying_price']);
941  unset($_POST['np_marginRate']);
942  unset($_POST['np_markRate']);
943 
944  unset($_POST['dp_desc']);
945  unset($_POST['idprod']);
946  unset($_POST['units']);
947 
948  unset($_POST['date_starthour']);
949  unset($_POST['date_startmin']);
950  unset($_POST['date_startsec']);
951  unset($_POST['date_startday']);
952  unset($_POST['date_startmonth']);
953  unset($_POST['date_startyear']);
954  unset($_POST['date_endhour']);
955  unset($_POST['date_endmin']);
956  unset($_POST['date_endsec']);
957  unset($_POST['date_endday']);
958  unset($_POST['date_endmonth']);
959  unset($_POST['date_endyear']);
960 
961  unset($_POST['situations']);
962  unset($_POST['progress']);
963  }
964  else
965  {
966  setEventMessages($object->error, $object->errors, 'errors');
967  }
968  }
969  }
970 }
971 
972 
973 /*
974  * View
975  */
976 
977 llxHeader('',$langs->trans("RepeatableInvoices"),'ch-facture.html#s-fac-facture-rec');
978 
979 $form = new Form($db);
980 $formother = new FormOther($db);
981 if (! empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
982 $companystatic = new Societe($db);
983 $invoicerectmp = new FactureRec($db);
984 
985 $now = dol_now();
986 $tmparray=dol_getdate($now);
987 $today = dol_mktime(23,59,59,$tmparray['mon'],$tmparray['mday'],$tmparray['year']); // Today is last second of current day
988 
989 
990 /*
991  * Create mode
992  */
993 if ($action == 'create')
994 {
995  print load_fiche_titre($langs->trans("CreateRepeatableInvoice"),'','title_accountancy.png');
996 
997  $object = new Facture($db); // Source invoice
998  $product_static = new Product($db);
999 
1000  if ($object->fetch($id, $ref) > 0)
1001  {
1002  $result = $object->getLinesArray();
1003 
1004  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1005  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1006  print '<input type="hidden" name="action" value="add">';
1007  print '<input type="hidden" name="facid" value="'.$object->id.'">';
1008 
1009  dol_fiche_head(null, '', '', 0);
1010 
1011  $rowspan=4;
1012  if (! empty($conf->projet->enabled)) $rowspan++;
1013  if ($object->fk_account > 0) $rowspan++;
1014 
1015  print '<table class="border" width="100%">';
1016 
1017  $object->fetch_thirdparty();
1018 
1019  // Title
1020  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Title").'</td><td>';
1021  print '<input class="flat quatrevingtpercent" type="text" name="titre" value="'.$_POST["titre"].'">';
1022  print '</td></tr>';
1023 
1024  // Third party
1025  print '<tr><td class="titlefieldcreate">'.$langs->trans("Customer").'</td><td>'.$object->thirdparty->getNomUrl(1,'customer').'</td>';
1026  print '</tr>';
1027 
1028  $note_public=GETPOST('note_public','none')?GETPOST('note_public','none'):$object->note_public;
1029  $note_private=GETPOST('note_private','none')?GETPOST('note_private','none'):$object->note_private;
1030 
1031  // Help of substitution key
1032  $substitutionarray = getCommonSubstitutionArray($langs, 2, null, $object);
1033 
1034  $substitutionarray['__INVOICE_PREVIOUS_MONTH__'] = $langs->trans("PreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($object->date, -1, 'm'),'%m').')';
1035  $substitutionarray['__INVOICE_MONTH__'] = $langs->trans("MonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($object->date,'%m').')';
1036  $substitutionarray['__INVOICE_NEXT_MONTH__'] = $langs->trans("NextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($object->date, 1, 'm'),'%m').')';
1037  $substitutionarray['__INVOICE_PREVIOUS_MONTH_TEXT__'] = $langs->trans("TextPreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($object->date, -1, 'm'),'%B').')';
1038  $substitutionarray['__INVOICE_MONTH_TEXT__'] = $langs->trans("TextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($object->date,'%B').')';
1039  $substitutionarray['__INVOICE_NEXT_MONTH_TEXT__'] = $langs->trans("TextNextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($object->date, 1, 'm'), '%B').')';
1040  $substitutionarray['__INVOICE_PREVIOUS_YEAR__'] = $langs->trans("YearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($object->date, -1, 'y'),'%Y').')';
1041  $substitutionarray['__INVOICE_YEAR__'] = $langs->trans("PreviousYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($object->date,'%Y').')';
1042  $substitutionarray['__INVOICE_NEXT_YEAR__'] = $langs->trans("NextYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($object->date, 1, 'y'),'%Y').')';
1043  // Only on template invoices
1044  $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = $langs->trans("DateNextInvoiceBeforeGen").' ('.$langs->trans("Example").': '.dol_print_date($object->date_when, 'dayhour').')';
1045  $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').')';
1046 
1047  $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
1048  foreach($substitutionarray as $key => $val)
1049  {
1050  $htmltext.=$key.' = '.$langs->trans($val).'<br>';
1051  }
1052  $htmltext.='</i>';
1053 
1054  // Public note
1055  print '<tr>';
1056  print '<td class="tdtop">';
1057  print $form->textwithpicto($langs->trans('NotePublic'), $htmltext, 1, 'help', '', 0, 2, 'notepublic');
1058  print '</td>';
1059  print '<td colspan="2">';
1060  $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
1061  print $doleditor->Create(1);
1062 
1063  // Private note
1064  if (empty($user->societe_id))
1065  {
1066  print '<tr>';
1067  print '<td class="tdtop">';
1068  print $form->textwithpicto($langs->trans('NotePrivate'), $htmltext, 1, 'help', '', 0, 2, 'noteprivate');
1069  print '</td>';
1070  print '<td valign="top" colspan="2">';
1071  $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
1072  print $doleditor->Create(1);
1073  // print '<textarea name="note_private" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_private.'.</textarea>
1074  print '</td></tr>';
1075  }
1076 
1077  // Author
1078  print "<tr><td>".$langs->trans("Author")."</td><td>".$user->getFullName($langs)."</td></tr>";
1079 
1080  // Payment term
1081  print "<tr><td>".$langs->trans("PaymentConditions")."</td><td>";
1082  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none');
1083  print "</td></tr>";
1084 
1085  // Payment mode
1086  print "<tr><td>".$langs->trans("PaymentMode")."</td><td>";
1087  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none', '', 1);
1088  print "</td></tr>";
1089 
1090  // Project
1091  if (! empty($conf->projet->enabled) && is_object($object->thirdparty) && $object->thirdparty->id > 0)
1092  {
1093  $projectid = GETPOST('projectid')?GETPOST('projectid'):$object->fk_project;
1094  $langs->load('projects');
1095  print '<tr><td>' . $langs->trans('Project') . '</td><td>';
1096  $numprojet = $formproject->select_projects($object->thirdparty->id, $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0, 0, '');
1097  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>';
1098  print '</td></tr>';
1099  }
1100 
1101  // Bank account
1102  if ($object->fk_account > 0)
1103  {
1104  print "<tr><td>".$langs->trans('BankAccount')."</td><td>";
1105  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
1106  print "</td></tr>";
1107  }
1108 
1109  // Model pdf
1110  print "<tr><td>".$langs->trans('Model')."</td><td>";
1111  include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php';
1112  $list = ModelePDFFactures::liste_modeles($db);
1113  print $form->selectarray('modelpdf', $list, $conf->global->FACTURE_ADDON_PDF);
1114  print "</td></tr>";
1115 
1116  print "</table>";
1117 
1118  dol_fiche_end();
1119 
1120 
1121  // Autogeneration
1122  $title = $langs->trans("Recurrence");
1123  print load_fiche_titre('<span class="fa fa-calendar"></span> '.$title, '', '');
1124 
1125  dol_fiche_head(null, '', '', 0);
1126 
1127  print '<table class="border" width="100%">';
1128 
1129  // Frequency + unit
1130  print '<tr><td class="titlefieldcreate">'.$form->textwithpicto($langs->trans("Frequency"), $langs->transnoentitiesnoconv('toolTipFrequency'))."</td><td>";
1131  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'));
1132  print "</td></tr>";
1133 
1134  // First date of execution for cron
1135  print "<tr><td>".$langs->trans('NextDateToExecution')."</td><td>";
1136  $date_next_execution = isset($date_next_execution) ? $date_next_execution : (GETPOST('remonth') ? dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')) : -1);
1137  print $form->select_date($date_next_execution, '', 1, 1, '', "add", 1, 1, 1);
1138  print "</td></tr>";
1139 
1140  // Number max of generation
1141  print "<tr><td>".$langs->trans("MaxPeriodNumber")."</td><td>";
1142  print '<input type="text" name="nb_gen_max" value="'.GETPOST('nb_gen_max').'" size="5" />';
1143  print "</td></tr>";
1144 
1145  // Auto validate the invoice
1146  print "<tr><td>".$langs->trans("StatusOfGeneratedInvoices")."</td><td>";
1147  $select = array('0'=>$langs->trans('BillStatusDraft'),'1'=>$langs->trans('BillStatusValidated'));
1148  print $form->selectarray('auto_validate', $select, GETPOST('auto_validate'));
1149  print "</td></tr>";
1150 
1151  // Auto generate document
1152  if (! empty($conf->global->INVOICE_REC_CAN_DISABLE_DOCUMENT_FILE_GENERATION))
1153  {
1154  print "<tr><td>".$langs->trans("StatusOfGeneratedDocuments")."</td><td>";
1155  $select = array('0'=>$langs->trans('DoNotGenerateDoc'),'1'=>$langs->trans('AutoGenerateDoc'));
1156  print $form->selectarray('generate_pdf', $select, GETPOST('generate_pdf'));
1157  print "</td></tr>";
1158  }
1159  else
1160  {
1161  print '<input type="hidden" name="generate_pdf" value="1">';
1162  }
1163 
1164  print "</table>";
1165 
1166  dol_fiche_end();
1167 
1168 
1169  $title = $langs->trans("ProductsAndServices");
1170  if (empty($conf->service->enabled))
1171  $title = $langs->trans("Products");
1172  else if (empty($conf->product->enabled))
1173  $title = $langs->trans("Services");
1174 
1175  print load_fiche_titre($title, '', '');
1176 
1177  /*
1178  * Invoice lines
1179  */
1180  print '<div class="div-table-responsive-no-min">';
1181  print '<table id="tablelines" class="noborder noshadow" width="100%">';
1182  // Show object lines
1183  if (! empty($object->lines))
1184  {
1185  $disableedit=1;
1186  $disablemove=1;
1187  $disableremove=1;
1188  $ret = $object->printObjectLines('', $mysoc, $object->thirdparty, $lineid, 0); // No date selector for template invoice
1189  }
1190 
1191  print "</table>\n";
1192  print '<div>';
1193 
1194  print '</td></tr>';
1195 
1196  if ($flag_price_may_change)
1197  {
1198  print '<tr><td colspan="3" align="left">';
1199  print '<select name="usenewprice" class="flat">';
1200  print '<option value="0">'.$langs->trans("AlwaysUseFixedPrice").'</option>';
1201  print '<option value="1" disabled>'.$langs->trans("AlwaysUseNewPrice").'</option>';
1202  print '</select>';
1203  print '</td></tr>';
1204  }
1205  print "</table>\n";
1206 
1207  print '<div align="center"><input type="submit" class="button" value="'.$langs->trans("Create").'">';
1208  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1209  print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
1210  print '</div>';
1211  print "</form>\n";
1212  }
1213  else
1214  {
1215  dol_print_error('',"Error, no invoice ".$object->id);
1216  }
1217 }
1218 else
1219 {
1220  /*
1221  * View mode
1222  */
1223  if ($object->id > 0)
1224  {
1225  $object->fetch_thirdparty();
1226 
1227  // Confirmation de la suppression d'une ligne produit
1228  if ($action == 'ask_deleteline') {
1229  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 'no', 1);
1230  }
1231 
1232  // Confirm delete of repeatable invoice
1233  if ($action == 'ask_deleteinvoice') {
1234  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteRepeatableInvoice'), $langs->trans('ConfirmDeleteRepeatableInvoice'), 'confirm_deleteinvoice', '', 'no', 1);
1235  }
1236 
1237  print $formconfirm;
1238 
1239  $author = new User($db);
1240  $author->fetch($object->user_author);
1241 
1242  $head=invoice_rec_prepare_head($object);
1243 
1244  dol_fiche_head($head, 'card', $langs->trans("RepeatableInvoice"), -1, 'bill'); // Add a div
1245 
1246  // Recurring invoice content
1247 
1248  $linkback = '<a href="' . DOL_URL_ROOT . '/compta/facture/invoicetemplate_list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
1249 
1250  $morehtmlref='';
1251  if ($action != 'editref') $morehtmlref.=$form->editfieldkey($object->ref, 'ref', $object->ref, $object, $user->rights->facture->creer, '', '', 0, 2);
1252  else $morehtmlref.= $form->editfieldval('', 'ref', $object->ref, $object, $user->rights->facture->creer, 'string');
1253 
1254  $morehtmlref.='<div class="refidno">';
1255  // Ref customer
1256  //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', 0, 1);
1257  //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', null, null, '', 1);
1258  // Thirdparty
1259  $morehtmlref.=$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
1260  // Project
1261  if (! empty($conf->projet->enabled))
1262  {
1263  $langs->load("projects");
1264  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
1265  if ($user->rights->facture->creer)
1266  {
1267  if ($action != 'classify')
1268  $morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
1269  if ($action == 'classify') {
1270  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
1271  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
1272  $morehtmlref.='<input type="hidden" name="action" value="classin">';
1273  $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1274  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
1275  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
1276  $morehtmlref.='</form>';
1277  } else {
1278  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
1279  }
1280  } else {
1281  if (! empty($object->fk_project)) {
1282  $proj = new Project($db);
1283  $proj->fetch($object->fk_project);
1284  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
1285  $morehtmlref.=$proj->ref;
1286  $morehtmlref.='</a>';
1287  } else {
1288  $morehtmlref.='';
1289  }
1290  }
1291  }
1292  $morehtmlref.='</div>';
1293 
1294  dol_banner_tab($object, 'ref', $linkback, 1, 'titre', 'none', $morehtmlref, '', 0, '', $morehtmlright);
1295 
1296  print '<div class="fichecenter">';
1297  print '<div class="fichehalfleft">';
1298  print '<div class="underbanner clearboth"></div>';
1299 
1300  print '<table class="border" width="100%">';
1301 
1302  print '<tr><td class="titlefield">'.$langs->trans("Author").'</td><td>'.$author->getFullName($langs)."</td></tr>";
1303 
1304  print '<tr><td>'.$langs->trans("AmountHT").'</td>';
1305  print '<td>'.price($object->total_ht,'',$langs,1,-1,-1,$conf->currency).'</td>';
1306  print '</tr>';
1307 
1308  print '<tr><td>'.$langs->trans("AmountVAT").'</td><td>'.price($object->total_tva,'',$langs,1,-1,-1,$conf->currency).'</td>';
1309  print '</tr>';
1310 
1311  // Amount Local Taxes
1312  if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) // Localtax1
1313  {
1314  print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
1315  print '<td class="nowrap">' . price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
1316  }
1317  if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) // Localtax2
1318  {
1319  print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
1320  print '<td class=nowrap">' . price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
1321  }
1322 
1323  print '<tr><td>'.$langs->trans("AmountTTC").'</td><td colspan="3">'.price($object->total_ttc,'',$langs,1,-1,-1,$conf->currency).'</td>';
1324  print '</tr>';
1325 
1326 
1327  // Payment term
1328  print '<tr><td>';
1329  print '<table class="nobordernopadding" width="100%"><tr><td>';
1330  print $langs->trans('PaymentConditionsShort');
1331  print '</td>';
1332  if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editconditions' && ! empty($object->brouillon) && $user->rights->facture->creer)
1333  print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editconditions&amp;facid=' . $object->id . '">' . img_edit($langs->trans('SetConditions'), 1) . '</a></td>';
1334  print '</tr></table>';
1335  print '</td><td>';
1336  if ($object->type != Facture::TYPE_CREDIT_NOTE)
1337  {
1338  if ($action == 'editconditions')
1339  {
1340  $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->cond_reglement_id, 'cond_reglement_id');
1341  }
1342  else
1343  {
1344  $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->cond_reglement_id, 'none');
1345  }
1346  } else {
1347  print '&nbsp;';
1348  }
1349  print '</td></tr>';
1350 
1351  // Payment mode
1352  print '<tr><td>';
1353  print '<table class="nobordernopadding" width="100%"><tr><td>';
1354  print $langs->trans('PaymentMode');
1355  print '</td>';
1356  if ($action != 'editmode' && ! empty($object->brouillon) && $user->rights->facture->creer)
1357  print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editmode&amp;facid=' . $object->id . '">' . img_edit($langs->trans('SetMode'), 1) . '</a></td>';
1358  print '</tr></table>';
1359  print '</td><td>';
1360  if ($action == 'editmode')
1361  {
1362  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT');
1363  }
1364  else
1365  {
1366  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->mode_reglement_id, 'none', 'CRDT');
1367  }
1368  print '</td></tr>';
1369 
1370  // Help of substitution key
1371  $dateexample=dol_now();
1372  if (! empty($object->frequency) && ! empty($object->date_when)) $dateexample=$object->date_when;
1373 
1374  $substitutionarray = getCommonSubstitutionArray($langs, 2, null, $object);
1375 
1376  $substitutionarray['__INVOICE_PREVIOUS_MONTH__'] = $langs->trans("PreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'),'%m').')';
1377  $substitutionarray['__INVOICE_MONTH__'] = $langs->trans("MonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample,'%m').')';
1378  $substitutionarray['__INVOICE_NEXT_MONTH__'] = $langs->trans("NextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'),'%m').')';
1379  $substitutionarray['__INVOICE_PREVIOUS_MONTH_TEXT__'] = $langs->trans("TextPreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'),'%B').')';
1380  $substitutionarray['__INVOICE_MONTH_TEXT__'] = $langs->trans("TextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample,'%B').')';
1381  $substitutionarray['__INVOICE_NEXT_MONTH_TEXT__'] = $langs->trans("TextNextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'), '%B').')';
1382  $substitutionarray['__INVOICE_PREVIOUS_YEAR__'] = $langs->trans("YearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'y'),'%Y').')';
1383  $substitutionarray['__INVOICE_YEAR__'] = $langs->trans("PreviousYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample,'%Y').')';
1384  $substitutionarray['__INVOICE_NEXT_YEAR__'] = $langs->trans("NextYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'y'),'%Y').')';
1385  // Only on template invoices
1386  $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').')';
1387  $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').')';
1388 
1389  $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
1390  foreach($substitutionarray as $key => $val)
1391  {
1392  $htmltext.=$key.' = '.$langs->trans($val).'<br>';
1393  }
1394  $htmltext.='</i>';
1395 
1396  // Note public
1397  print '<tr><td>';
1398  print $form->editfieldkey($form->textwithpicto($langs->trans('NotePublic'), $htmltext, 1, 'help', '', 0, 2, 'notepublic'), 'note_public', $object->note_public, $object, $user->rights->facture->creer);
1399  print '</td><td>';
1400  print $form->editfieldval($langs->trans("NotePublic"), 'note_public', $object->note_public, $object, $user->rights->facture->creer, 'textarea:'.ROWS_4.':90%', '', null, null, '', 1);
1401  print '</td>';
1402  print '</tr>';
1403 
1404  // Note private
1405  print '<tr><td>';
1406  print $form->editfieldkey($form->textwithpicto($langs->trans("NotePrivate"), $htmltext, 1, 'help', '', 0, 2, 'noteprivate'), 'note_private', $object->note_private, $object, $user->rights->facture->creer);
1407  print '</td><td>';
1408  print $form->editfieldval($langs->trans("NotePrivate"), 'note_private', $object->note_private, $object, $user->rights->facture->creer, 'textarea:'.ROWS_4.':90%', '', null, null, '', 1);
1409  print '</td>';
1410  print '</tr>';
1411 
1412  // Bank Account
1413  $langs->load('banks');
1414 
1415  print '<tr><td class="nowrap">';
1416  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1417  print $langs->trans('RIB');
1418  print '<td>';
1419  if (($action != 'editbankaccount') && $user->rights->facture->creer && ! empty($object->brouillon))
1420  print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'),1).'</a></td>';
1421  print '</tr></table>';
1422  print '</td><td>';
1423  if ($action == 'editbankaccount')
1424  {
1425  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
1426  }
1427  else
1428  {
1429  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
1430  }
1431  print "</td>";
1432  print '</tr>';
1433 
1434  // Model pdf
1435  $langs->load('banks');
1436 
1437  print '<tr><td class="nowrap">';
1438  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1439  print $langs->trans('Model');
1440  print '<td>';
1441  if (($action != 'editmodelpdf') && $user->rights->facture->creer && ! empty($object->brouillon))
1442  print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmodelpdf&amp;id='.$object->id.'">'.img_edit($langs->trans('SetModel'),1).'</a></td>';
1443  print '</tr></table>';
1444  print '</td><td>';
1445  if ($action == 'editmodelpdf')
1446  {
1447  include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php';
1448  $list = array();
1449  $models = ModelePDFFactures::liste_modeles($db);
1450  foreach ($models as $model) {
1451  $list[] = $model . ':' . $model;
1452  }
1453  $select = 'select;'.implode(',', $list);
1454  print $form->editfieldval($langs->trans("Model"), 'modelpdf', $object->modelpdf, $object, $user->rights->facture->creer, $select);
1455  }
1456  else
1457  {
1458  print $object->modelpdf;
1459  }
1460  print "</td>";
1461  print '</tr>';
1462 
1463  // Other attributes
1464  $cols = 2;
1465  include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
1466 
1467  print '</table>';
1468 
1469  print '</div>';
1470  print '<div class="fichehalfright">';
1471  print '<div class="ficheaddleft">';
1472  print '<div class="underbanner clearboth"></div>';
1473 
1474 
1475  /*
1476  * Recurrence
1477  */
1478  $title = $langs->trans("Recurrence");
1479  //print load_fiche_titre($title, '', 'calendar');
1480 
1481  print '<table class="border" width="100%">';
1482 
1483  print '<tr><td colspan="2"><span class="fa fa-calendar"></span> '.$title.'</td></tr>';
1484 
1485  // if "frequency" is empty or = 0, the reccurence is disabled
1486  print '<tr><td style="width: 50%">';
1487  print '<table class="nobordernopadding" width="100%"><tr><td>';
1488  print $langs->trans('Frequency');
1489  print '</td>';
1490  if ($action != 'editfrequency' && ! empty($object->brouillon) && $user->rights->facture->creer)
1491  print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editfrequency&amp;facid=' . $object->id . '">' . img_edit($langs->trans('Edit'), 1) . '</a></td>';
1492  print '</tr></table>';
1493  print '</td><td>';
1494  if ($action == 'editfrequency')
1495  {
1496  print '<form method="post" action="'.$_SERVER["PHP_SELF"] . '?facid=' . $object->id.'">';
1497  print '<input type="hidden" name="action" value="setfrequency">';
1498  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1499  print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
1500  print '<tr><td>';
1501  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'));
1502  print '</td>';
1503  print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
1504  print '</tr></table></form>';
1505  }
1506  else
1507  {
1508  if ($object->frequency > 0)
1509  {
1510  print $langs->trans('FrequencyPer_'.$object->unit_frequency, $object->frequency);
1511  }
1512  else
1513  {
1514  print $langs->trans("NotARecurringInvoiceTemplate");
1515  }
1516  }
1517  print '</td></tr>';
1518 
1519  // Date when
1520  print '<tr><td>';
1521  if ($action == 'date_when' || $object->frequency > 0)
1522  {
1523  print $form->editfieldkey($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day');
1524  }
1525  else
1526  {
1527  print $langs->trans("NextDateToExecution");
1528  }
1529  print '</td><td>';
1530  if ($action == 'date_when' || $object->frequency > 0)
1531  {
1532  print $form->editfieldval($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day', $object->date_when, null, '', '', 0, 'strikeIfMaxNbGenReached');
1533  }
1534  print '</td>';
1535  print '</tr>';
1536 
1537  // Max period / Rest period
1538  print '<tr><td>';
1539  if ($action == 'nb_gen_max' || $object->frequency > 0)
1540  {
1541  print $form->editfieldkey($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max, $object, $user->rights->facture->creer);
1542  }
1543  else
1544  {
1545  print $langs->trans("MaxPeriodNumber");
1546  }
1547  print '</td><td>';
1548  if ($action == 'nb_gen_max' || $object->frequency > 0)
1549  {
1550  print $form->editfieldval($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max?$object->nb_gen_max:'', $object, $user->rights->facture->creer);
1551  }
1552  else
1553  {
1554  print '';
1555  }
1556  print '</td>';
1557  print '</tr>';
1558 
1559  // Status of generated invoices
1560  print '<tr><td>';
1561  if ($action == 'auto_validate' || $object->frequency > 0)
1562  print $form->editfieldkey($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer);
1563  else
1564  print $langs->trans("StatusOfGeneratedInvoices");
1565  print '</td><td>';
1566  $select = 'select;0:'.$langs->trans('BillStatusDraft').',1:'.$langs->trans('BillStatusValidated');
1567  if ($action == 'auto_validate' || $object->frequency > 0)
1568  {
1569  print $form->editfieldval($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer, $select);
1570  }
1571  print '</td>';
1572  // Auto generate documents
1573  if (! empty($conf->global->INVOICE_REC_CAN_DISABLE_DOCUMENT_FILE_GENERATION))
1574  {
1575  print '<tr>';
1576  print '<td>';
1577  if ($action == 'generate_pdf' || $object->frequency > 0)
1578  print $form->editfieldkey($langs->trans("StatusOfGeneratedDocuments"), 'generate_pdf', $object->generate_pdf, $object, $user->rights->facture->creer);
1579  else
1580  print $langs->trans("StatusOfGeneratedDocuments");
1581  print '</td>';
1582  print '<td>';
1583  $select = 'select;0:'.$langs->trans('DoNotGenerateDoc').',1:'.$langs->trans('AutogenerateDoc');
1584  if ($action == 'generate_pdf' || $object->frequency > 0)
1585  {
1586  print $form->editfieldval($langs->trans("StatusOfGeneratedDocuments"), 'generate_pdf', $object->generate_pdf, $object, $user->rights->facture->creer, $select);
1587  }
1588  print '</td>';
1589  print '</tr>';
1590  }
1591  else
1592  {
1593  print '<input type="hidden" name="generate_pdf" value="1">';
1594  }
1595 
1596  print '</table>';
1597 
1598  // Frequencry/Recurring section
1599  if ($object->frequency > 0)
1600  {
1601  print '<br>';
1602 
1603  if (empty($conf->cron->enabled))
1604  {
1605  print info_admin($langs->trans("EnableAndSetupModuleCron", $langs->transnoentitiesnoconv("Module2300Name")));
1606  }
1607 
1608  print '<div class="underbanner clearboth"></div>';
1609  print '<table class="border centpercent">';
1610 
1611  // Nb of generation already done
1612  print '<tr><td style="width: 50%">'.$langs->trans("NbOfGenerationDone").'</td>';
1613  print '<td>';
1614  print $object->nb_gen_done?$object->nb_gen_done:'0';
1615  print '</td>';
1616  print '</tr>';
1617 
1618  // Date last
1619  print '<tr><td>';
1620  print $langs->trans("DateLastGeneration");
1621  print '</td><td>';
1622  print dol_print_date($object->date_last_gen, 'dayhour');
1623  print '</td>';
1624  print '</tr>';
1625 
1626  print '</table>';
1627 
1628  print '<br>';
1629  }
1630 
1631  print '</div>';
1632  print '</div>';
1633  print '</div>';
1634 
1635  print '<div class="clearboth"></div><br>';
1636 
1637 
1638  // Lines
1639  print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '#add' : '#line_' . GETPOST('lineid')) . '" method="POST">
1640  <input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">
1641  <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateligne') . '">
1642  <input type="hidden" name="mode" value="">
1643  <input type="hidden" name="id" value="' . $object->id . '">
1644  ';
1645 
1646  if (! empty($conf->use_javascript_ajax) && $object->statut == 0) {
1647  include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
1648  }
1649 
1650  print '<div class="div-table-responsive-no-min">';
1651  print '<table id="tablelines" class="noborder noshadow" width="100%">';
1652  // Show object lines
1653  if (! empty($object->lines))
1654  {
1655  //$disableedit=1;
1656  //$disablemove=1;
1657  $ret = $object->printObjectLines($action, $mysoc, $object->thirdparty, $lineid, 0); // No date selector for template invoice
1658  }
1659 
1660  // Form to add new line
1661  if ($object->statut == 0 && $user->rights->facture->creer && $action != 'valid' && $action != 'editline')
1662  {
1663  if ($action != 'editline')
1664  {
1665  // Add free products/services
1666  $object->formAddObjectLine(0, $mysoc, $object->thirdparty); // No date selector for template invoice
1667 
1668  $parameters = array();
1669  $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1670  }
1671  }
1672 
1673  print "</table>\n";
1674  print '</div>';
1675 
1676  print "</form>\n";
1677 
1678  dol_fiche_end();
1679 
1680 
1684  print '<div class="tabsAction">';
1685 
1686  if (empty($object->suspended))
1687  {
1688  if ($user->rights->facture->creer)
1689  {
1690  if (! empty($object->frequency) && $object->nb_gen_max > 0 && ($object->nb_gen_done >= $object->nb_gen_max))
1691  {
1692  print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("MaxGenerationReached")).'">'.$langs->trans("CreateBill").'</a></div>';
1693  }
1694  else
1695  {
1696  if (empty($object->frequency) || $object->date_when <= $today)
1697  {
1698  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&socid='.$object->thirdparty->id.'&fac_rec='.$object->id.'">'.$langs->trans("CreateBill").'</a></div>';
1699  }
1700  else
1701  {
1702  print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("DateIsNotEnough")).'">'.$langs->trans("CreateBill").'</a></div>';
1703  }
1704  }
1705  }
1706  else
1707  {
1708  print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans("CreateBill").'</a></div>';
1709  }
1710  }
1711 
1712  if ($user->rights->facture->creer)
1713  {
1714  if (empty($object->suspended))
1715  {
1716  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.DOL_URL_ROOT.'/compta/facture/fiche-rec.php?action=disable&id='.$object->id.'">'.$langs->trans("Disable").'</a></div>';
1717  }
1718  else
1719  {
1720  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/fiche-rec.php?action=enable&id='.$object->id.'">'.$langs->trans("Enable").'</a></div>';
1721  }
1722  }
1723 
1724  //if ($object->statut == Facture::STATUS_DRAFT && $user->rights->facture->supprimer)
1725  if ($user->rights->facture->supprimer)
1726  {
1727  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=ask_deleteinvoice&id='.$object->id.'">'.$langs->trans('Delete').'</a></div>';
1728  }
1729 
1730  print '</div>';
1731 
1732 
1733 
1734  print '<div class="fichecenter"><div class="fichehalfleft">';
1735  print '<a name="builddoc"></a>'; // ancre
1736 
1737 
1738  // Show links to link elements
1739  $linktoelem = $form->showLinkToObjectBlock($object, null, array('invoice'));
1740 
1741  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1742 
1743 
1744  print '</div></div>';
1745 
1746  }
1747 }
1748 
1749 llxFooter();
1750 
1751 $db->close();
File of class to manage predefined price products or services by customer.
llxFooter()
Empty footer.
Definition: wrapper.php:58
Class to manage invoice lines of templates.
const TYPE_STANDARD
Standard invoice.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
Class to manage products or services.
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.
Class to manage invoice templates.
Class to manage Dolibarr users.
Definition: user.class.php:39
const TYPE_REPLACEMENT
Replacement invoice.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_concatdesc($text1, $text2, $forxml=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
if(empty($reshook)) $form
View.
Definition: perms.php:103
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.
const TYPE_CREDIT_NOTE
Credit note invoice.
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1')
Show information for admin users or standard users.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage projects.
Class to manage building of HTML components.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
dol_fiche_end($notab=0)
Show tab footer of a card.
Classe permettant la generation de composants html autre Only common components are here...
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
Class to manage translations.
dol_now($mode='gmt')
Return date for now.
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...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print
Draft customers invoices.
Definition: index.php:91
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
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) Si ...
Class to manage a WYSIWYG editor.
Class to manage invoices.
dol_getdate($timestamp, $fast=false)
Return an array with locale date info.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:116
img_edit($titlealt= 'default', $float=0, $other= 'class="pictoedit"')
Show logo editer/modifier fiche.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.