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 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
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';
47 $langs->loadLangs(array(
'bills',
'compta',
'admin',
'other',
'products',
'banks'));
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') :
'invoicetemplatelist';
59 $lineid =
GETPOST(
'lineid',
'int');
61 if ($user->socid) $socid = $user->socid;
62 $objecttype =
'facture_rec';
63 if ($action ==
"create" || $action ==
"add") $objecttype =
'';
65 $projectid =
GETPOST(
'projectid',
'int');
67 $year_date_when =
GETPOST(
'year_date_when');
68 $month_date_when =
GETPOST(
'month_date_when');
70 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
71 $sortfield =
GETPOST(
"sortfield",
'alpha');
72 $sortorder =
GETPOST(
"sortorder",
'alpha');
74 if (empty($page) || $page == -1) { $page = 0; }
75 $offset = $limit * $page;
76 if (!$sortorder) $sortorder =
'DESC';
77 if (!$sortfield) $sortfield =
'f.titre';
78 $pageprev = $page - 1;
79 $pagenext = $page + 1;
82 if (($id > 0 || $ref) && $action !=
'create' && $action !=
'add')
84 $ret = $object->fetch($id, $ref);
92 $hookmanager->initHooks(array(
'invoicereccard',
'globalcard'));
96 $extrafields->fetch_name_optionals_label($object->table_element);
98 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
100 $permissionnote = $user->rights->facture->creer;
101 $permissiondellink = $user->rights->facture->creer;
102 $permissiontoedit = $user->rights->facture->creer;
104 $usercanread = $user->rights->facture->lire;
105 $usercancreate = $user->rights->facture->creer;
106 $usercanissuepayment = $user->rights->facture->paiement;
107 $usercandelete = $user->rights->facture->supprimer;
108 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->validate)));
109 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send);
110 $usercanreopen = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->reopen);
111 $usercanunvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->unvalidate)));
113 $usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
114 $usercancreatemargin = $user->rights->margins->creer;
115 $usercanreadallmargin = $user->rights->margins->liretous;
116 $usercancreatewithdrarequest = $user->rights->prelevement->bons->creer;
127 if (
GETPOST(
'cancel',
'alpha')) { $action =
'list'; $massaction =
''; }
128 if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') { $massaction =
''; }
130 $parameters = array(
'socid' => $socid);
131 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
132 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
136 if (
GETPOST(
'cancel',
'alpha')) $action =
'';
139 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
142 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
144 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
146 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
157 if ($action ==
'add')
159 if (!
GETPOST(
'title',
'alphanohtml'))
161 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->trans(
"Title")), null,
'errors');
166 $frequency =
GETPOST(
'frequency',
'int');
167 $reyear =
GETPOST(
'reyear',
'int');
168 $remonth =
GETPOST(
'remonth',
'int');
169 $reday =
GETPOST(
'reday',
'int');
170 $rehour =
GETPOST(
'rehour',
'int');
171 $remin =
GETPOST(
'remin',
'int');
172 $nb_gen_max =
GETPOST(
'nb_gen_max',
'int');
175 if (
GETPOST(
'frequency',
'int'))
177 if (empty($reyear) || empty($remonth) || empty($reday))
179 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->trans(
"Date")), null,
'errors');
183 if ($nb_gen_max ===
'')
185 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->trans(
"MaxPeriodNumber")), null,
'errors');
193 $object->titre =
GETPOST(
'title',
'nohtml');
194 $object->title =
GETPOST(
'title',
'nohtml');
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');
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 $object->fk_project = $projectid;
207 $date_next_execution =
dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear);
208 $object->date_when = $date_next_execution;
211 if (
GETPOST(
'facid',
'int') > 0)
214 $srcObject->fetch(
GETPOST(
'facid',
'int'));
216 $srcObject->fetchObjectLinked();
218 if (!empty($srcObject->linkedObjectsIds[
'contrat']))
220 $contractidid = reset($srcObject->linkedObjectsIds[
'contrat']);
222 $object->origin =
'contrat';
223 $object->origin_id = $contractidid;
224 $object->linked_objects[$object->origin] = $object->origin_id;
230 $oldinvoice =
new Facture($db);
231 $oldinvoice->fetch(
GETPOST(
'facid',
'int'));
233 $result = $object->create($user, $oldinvoice->id);
236 $result = $oldinvoice->delete($user, 1);
253 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id);
266 if ($action ==
'confirm_deleteinvoice' && $confirm ==
'yes' && $user->rights->facture->supprimer)
268 $object->delete($user);
270 header(
"Location: ".DOL_URL_ROOT.
'/compta/facture/invoicetemplate_list.php');
277 if ($action ==
'setconditions' && $user->rights->facture->creer)
279 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
281 elseif ($action ==
'setmode' && $user->rights->facture->creer)
283 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
285 elseif ($action ==
'classin' && $user->rights->facture->creer)
287 $object->setProject(
GETPOST(
'projectid',
'int'));
289 elseif ($action ==
'setref' && $user->rights->facture->creer)
292 $result = $object->setValueFrom(
'titre', $ref,
'', null,
'text',
'', $user,
'BILLREC_MODIFY');
295 $object->titre = $ref;
296 $object->title = $ref;
297 $object->ref = $object->title;
300 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
301 $langs->load(
"errors");
302 setEventMessages($langs->trans(
'ErrorRefAlreadyExists', $ref), null,
'errors');
308 elseif ($action ==
'setbankaccount' && $user->rights->facture->creer)
310 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
312 elseif ($action ==
'setfrequency' && $user->rights->facture->creer)
314 $object->setFrequencyAndUnit(
GETPOST(
'frequency',
'int'),
GETPOST(
'unit_frequency',
'alpha'));
316 elseif ($action ==
'setdate_when' && $user->rights->facture->creer)
319 if (!empty($date)) $object->setNextDate($date);
321 elseif ($action ==
'setnb_gen_max' && $user->rights->facture->creer)
323 $object->setMaxPeriod(
GETPOST(
'nb_gen_max',
'int'));
325 elseif ($action ==
'setauto_validate' && $user->rights->facture->creer)
327 $object->setAutoValidate(
GETPOST(
'auto_validate',
'int'));
329 elseif ($action ==
'setgenerate_pdf' && $user->rights->facture->creer)
331 $object->setGeneratepdf(
GETPOST(
'generate_pdf',
'int'));
333 elseif ($action ==
'setmodelpdf' && $user->rights->facture->creer)
335 $object->setModelpdf(
GETPOST(
'modelpdf',
'alpha'));
337 elseif ($action ==
'disable' && $user->rights->facture->creer)
343 $res = $object->setValueFrom(
'suspended', 1);
357 elseif ($action ==
'enable' && $user->rights->facture->creer)
363 $res = $object->setValueFrom(
'suspended', 0);
377 elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
378 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
380 elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
381 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
385 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $user->rights->facture->creer)
388 $object->fetch_thirdparty();
397 if ($line->delete($user) > 0)
399 $result = $object->update_price(1);
404 $object->fetch($object->id);
413 } elseif ($action ==
'update_extras')
418 $ret = $extrafields->setOptionalsFromPost(null, $object,
GETPOST(
'attribute',
'restricthtml'));
419 if ($ret < 0) $error++;
423 $result = $object->insertExtraFields(
'BILLREC_MODIFY');
433 if ($action ==
'addline' && $user->rights->facture->creer)
435 $langs->load(
'errors');
443 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'alpha');
444 if ($prod_entry_mode ==
'free')
447 $tva_tx = (
GETPOST(
'tva_tx',
'alpha') ?
GETPOST(
'tva_tx',
'alpha') : 0);
449 $idprod =
GETPOST(
'idprod',
'int');
454 $remise_percent =
GETPOST(
'remise_percent'.$predef);
457 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
458 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
460 if (is_array($extralabelsline))
463 foreach ($extralabelsline as $key => $value) {
464 unset($_POST[
"options_".$key.$predef]);
468 if (empty($idprod) && ($price_ht < 0) && ($qty < 0)) {
469 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
472 if ($prod_entry_mode ==
'free' && empty($idprod) &&
GETPOST(
'type') < 0) {
473 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')), null,
'errors');
476 if ($prod_entry_mode ==
'free' && empty($idprod) && (!($price_ht >= 0) || $price_ht ==
''))
478 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")), null,
'errors');
482 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
485 if ($prod_entry_mode ==
'free' && empty($idprod) && empty($product_desc)) {
486 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')), null,
'errors');
490 $langs->load(
"errors");
491 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'), null,
'errors');
495 if (!$error && ($qty >= 0) && (!empty($product_desc) || !empty($idprod)))
497 $ret = $object->fetch($id);
502 $ret = $object->fetch_thirdparty();
507 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
521 $prod->fetch($idprod);
523 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
528 if (empty($tva_tx)) $tva_npr = 0;
533 $datapriceofproduct = $prod->getSellPrice($mysoc, $object->thirdparty, $pqp);
535 $pu_ht = $datapriceofproduct[
'pu_ht'];
536 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
537 $price_min = $datapriceofproduct[
'price_min'];
538 $price_base_type = $datapriceofproduct[
'price_base_type'];
539 $tva_tx = $datapriceofproduct[
'tva_tx'];
540 $tva_npr = $datapriceofproduct[
'tva_npr'];
542 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
543 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
546 if (!empty($price_ht))
549 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
552 elseif ($tmpvat != $tmpprodvat)
554 if ($price_base_type !=
'HT')
556 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
558 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
565 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
567 $outputlangs = $langs;
569 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09'))
570 $newlang =
GETPOST(
'lang_id',
'aZ09');
572 $newlang = $object->thirdparty->default_lang;
573 if (!empty($newlang))
576 $outputlangs->setDefaultLang($newlang);
579 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->description;
581 $desc = $prod->description;
587 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code)))
591 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
592 $outputlangs = $langs;
594 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) $newlang =
GETPOST(
'lang_id',
'alpha');
595 if (empty($newlang)) $newlang = $object->thirdparty->default_lang;
596 if (!empty($newlang)) {
598 $outputlangs->setDefaultLang($newlang);
599 $outputlangs->load(
'products');
601 if (!empty($prod->customcode)) $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
602 if (!empty($prod->customcode) && !empty($prod->country_code)) $tmptxt .=
' - ';
603 if (!empty($prod->country_code)) $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
605 if (!empty($prod->customcode)) $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
606 if (!empty($prod->customcode) && !empty($prod->country_code)) $tmptxt .=
' - ';
607 if (!empty($prod->country_code)) $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
614 $fk_unit = $prod->fk_unit;
618 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
619 $tva_tx = str_replace(
'*',
'', $tva_tx);
620 if (empty($tva_tx)) $tva_npr = 0;
621 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
622 $desc = $product_desc;
624 $fk_unit =
GETPOST(
'units',
'alpha');
627 $date_start_fill =
GETPOST(
'date_start_fill',
'int');
628 $date_end_fill =
GETPOST(
'date_end_fill',
'int');
635 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
636 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
642 if ($usercanproductignorepricemin && (!empty($price_min) && (
price2num($pu_ht) * (1 -
price2num($remise_percent) / 100) <
price2num($price_min)))) {
643 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
647 $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, 0, $date_start_fill, $date_end_fill, $fournprice, $buyingprice);
669 $object->fetch($object->id);
671 unset($_POST[
'prod_entry_mode']);
673 unset($_POST[
'qty']);
674 unset($_POST[
'type']);
675 unset($_POST[
'remise_percent']);
676 unset($_POST[
'price_ht']);
677 unset($_POST[
'multicurrency_price_ht']);
678 unset($_POST[
'price_ttc']);
679 unset($_POST[
'tva_tx']);
680 unset($_POST[
'product_ref']);
681 unset($_POST[
'product_label']);
682 unset($_POST[
'product_desc']);
683 unset($_POST[
'fournprice']);
684 unset($_POST[
'buying_price']);
685 unset($_POST[
'np_marginRate']);
686 unset($_POST[
'np_markRate']);
687 unset($_POST[
'dp_desc']);
688 unset($_POST[
'idprod']);
689 unset($_POST[
'units']);
691 unset($_POST[
'date_starthour']);
692 unset($_POST[
'date_startmin']);
693 unset($_POST[
'date_startsec']);
694 unset($_POST[
'date_startday']);
695 unset($_POST[
'date_startmonth']);
696 unset($_POST[
'date_startyear']);
697 unset($_POST[
'date_endhour']);
698 unset($_POST[
'date_endmin']);
699 unset($_POST[
'date_endsec']);
700 unset($_POST[
'date_endday']);
701 unset($_POST[
'date_endmonth']);
702 unset($_POST[
'date_endyear']);
704 unset($_POST[
'date_start_fill']);
705 unset($_POST[
'date_end_fill']);
707 unset($_POST[
'situations']);
708 unset($_POST[
'progress']);
716 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha'))
719 $object->fetch_thirdparty();
734 if (preg_match(
'/\*/', $vat_rate)) $info_bits |= 0x01;
737 $vat_rate = str_replace(
'*',
'', $vat_rate);
738 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty);
739 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty);
746 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
747 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
750 if ($objectline->fetch(
GETPOST(
'lineid',
'int')))
752 $objectline->array_options = $array_options;
753 $result = $objectline->insertExtraFields();
760 $position = ($objectline->rang >= 0 ? $objectline->rang : 0);
763 if (is_array($extralabelsline))
766 foreach ($extralabelsline as $key => $value)
768 unset($_POST[
"options_".$key]);
773 $special_code =
GETPOST(
'special_code',
'int');
774 if (!
GETPOST(
'qty',
'alpha')) $special_code = 3;
789 $productid =
GETPOST(
'productid',
'int');
790 if (!empty($productid))
793 $product->fetch($productid);
795 $type = $product->type;
797 $price_min = $product->price_min;
798 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level))
799 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
806 setEventMessages($langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null,
'errors');
810 $type =
GETPOST(
'type',
'int');
811 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
814 if (
GETPOST(
'type',
'int') < 0) {
815 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")), null,
'errors');
820 $langs->load(
"errors");
821 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'), null,
'errors');
825 $date_start_fill =
GETPOST(
'date_start_fill',
'int');
826 $date_end_fill =
GETPOST(
'date_end_fill',
'int');
831 $result = $object->updateline(
877 $object->fetch($object->id);
879 unset($_POST[
'qty']);
880 unset($_POST[
'type']);
881 unset($_POST[
'productid']);
882 unset($_POST[
'remise_percent']);
883 unset($_POST[
'price_ht']);
884 unset($_POST[
'multicurrency_price_ht']);
885 unset($_POST[
'price_ttc']);
886 unset($_POST[
'tva_tx']);
887 unset($_POST[
'product_ref']);
888 unset($_POST[
'product_label']);
889 unset($_POST[
'product_desc']);
890 unset($_POST[
'fournprice']);
891 unset($_POST[
'buying_price']);
892 unset($_POST[
'np_marginRate']);
893 unset($_POST[
'np_markRate']);
895 unset($_POST[
'dp_desc']);
896 unset($_POST[
'idprod']);
897 unset($_POST[
'units']);
899 unset($_POST[
'date_starthour']);
900 unset($_POST[
'date_startmin']);
901 unset($_POST[
'date_startsec']);
902 unset($_POST[
'date_startday']);
903 unset($_POST[
'date_startmonth']);
904 unset($_POST[
'date_startyear']);
905 unset($_POST[
'date_endhour']);
906 unset($_POST[
'date_endmin']);
907 unset($_POST[
'date_endsec']);
908 unset($_POST[
'date_endday']);
909 unset($_POST[
'date_endmonth']);
910 unset($_POST[
'date_endyear']);
912 unset($_POST[
'situations']);
913 unset($_POST[
'progress']);
927 llxHeader(
'', $langs->trans(
"RepeatableInvoices"), $help_url);
929 $form =
new Form($db);
931 if (!empty($conf->projet->enabled)) { $formproject =
new FormProjets($db); }
932 $companystatic =
new Societe($db);
937 $today =
dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
943 if ($action ==
'create')
948 $product_static =
new Product($db);
950 if ($object->fetch($id, $ref) > 0)
952 $result = $object->getLinesArray();
954 print '<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
955 print '<input type="hidden" name="token" value="'.newToken().
'">';
956 print '<input type="hidden" name="action" value="add">';
957 print '<input type="hidden" name="facid" value="'.$object->id.
'">';
962 if (!empty($conf->projet->enabled)) $rowspan++;
963 if ($object->fk_account > 0) $rowspan++;
965 print '<table class="border centpercent">';
967 $object->fetch_thirdparty();
970 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
"Title").
'</td><td>';
971 print '<input class="flat quatrevingtpercent" type="text" name="title" value="'.dol_escape_htmltag(
GETPOST(
"titre",
'alphanohtml')).
'">';
975 print '<tr><td class="titlefieldcreate">'.$langs->trans(
"Customer").
'</td><td>'.$object->thirdparty->getNomUrl(1,
'customer').
'</td>';
978 $note_public =
GETPOSTISSET(
'note_public') ?
GETPOST(
'note_public',
'restricthtml') : $object->note_public;
979 $note_private =
GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') : $object->note_private;
984 $substitutionarray[
'__INVOICE_PREVIOUS_MONTH__'] = $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, -1,
'm'),
'%m').
')';
985 $substitutionarray[
'__INVOICE_MONTH__'] = $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($object->date,
'%m').
')';
986 $substitutionarray[
'__INVOICE_NEXT_MONTH__'] = $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, 1,
'm'),
'%m').
')';
987 $substitutionarray[
'__INVOICE_PREVIOUS_MONTH_TEXT__'] = $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, -1,
'm'),
'%B').
')';
988 $substitutionarray[
'__INVOICE_MONTH_TEXT__'] = $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($object->date,
'%B').
')';
989 $substitutionarray[
'__INVOICE_NEXT_MONTH_TEXT__'] = $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, 1,
'm'),
'%B').
')';
990 $substitutionarray[
'__INVOICE_PREVIOUS_YEAR__'] = $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, -1,
'y'),
'%Y').
')';
991 $substitutionarray[
'__INVOICE_YEAR__'] = $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($object->date,
'%Y').
')';
992 $substitutionarray[
'__INVOICE_NEXT_YEAR__'] = $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, 1,
'y'),
'%Y').
')';
994 $substitutionarray[
'__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = $langs->trans(
"DateNextInvoiceBeforeGen").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($object->date_when,
'dayhour').
')';
995 $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').
')';
996 $substitutionarray[
'__INVOICE_COUNTER_CURRENT__'] = $langs->trans(
"Count");
997 $substitutionarray[
'__INVOICE_COUNTER_MAX__'] = $langs->trans(
"MaxPeriodNumber");
999 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
1000 foreach ($substitutionarray as $key => $val)
1002 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1004 $htmltext .=
'</i>';
1008 print '<td class="tdtop">';
1009 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext, 1,
'help',
'', 0, 2,
'notepublic');
1012 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false,
true, ROWS_3,
'90%');
1013 print $doleditor->Create(1);
1016 if (empty($user->socid))
1019 print '<td class="tdtop">';
1020 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext, 1,
'help',
'', 0, 2,
'noteprivate');
1023 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false,
true, ROWS_3,
'90%');
1024 print $doleditor->Create(1);
1030 print "<tr><td>".$langs->trans(
"Author").
"</td><td>".$user->getFullName($langs).
"</td></tr>";
1033 print "<tr><td>".$langs->trans(
"PaymentConditions").
"</td><td>";
1034 $form->form_conditions_reglement(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none');
1038 print "<tr><td>".$langs->trans(
"PaymentMode").
"</td><td>";
1039 $form->form_modes_reglement(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none',
'', 1);
1043 if (!empty($conf->projet->enabled) && is_object($object->thirdparty) && $object->thirdparty->id > 0)
1045 $projectid =
GETPOST(
'projectid') ?
GETPOST(
'projectid') : $object->fk_project;
1046 $langs->load(
'projects');
1047 print '<tr><td>'.$langs->trans(
'Project').
'</td><td>';
1048 $numprojet = $formproject->select_projects($object->thirdparty->id, $projectid,
'projectid', 0, 0, 1, 0, 0, 0, 0,
'', 0, 0,
'');
1049 print ' <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>';
1054 if ($object->fk_account > 0)
1056 print "<tr><td>".$langs->trans(
'BankAccount').
"</td><td>";
1057 $form->formSelectAccount(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
1062 print "<tr><td>".$langs->trans(
'Model').
"</td><td>";
1063 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
1065 print $form->selectarray(
'modelpdf', $list, $conf->global->FACTURE_ADDON_PDF);
1074 $title = $langs->trans(
"Recurrence");
1079 print '<table class="border centpercent">';
1082 print '<tr><td class="titlefieldcreate">'.$form->textwithpicto($langs->trans(
"Frequency"), $langs->transnoentitiesnoconv(
'toolTipFrequency')).
"</td><td>";
1083 print "<input type='text' name='frequency' value='".GETPOST(
'frequency',
'int').
"' size='4' /> ".$form->selectarray(
'unit_frequency', array(
'd'=>$langs->trans(
'Day'),
'm'=>$langs->trans(
'Month'),
'y'=>$langs->trans(
'Year')), (
GETPOST(
'unit_frequency') ?
GETPOST(
'unit_frequency') :
'm'));
1087 print "<tr><td>".$langs->trans(
'NextDateToExecution').
"</td><td>";
1089 print $form->selectDate($date_next_execution,
'', 1, 1,
'',
"add", 1, 1);
1093 print "<tr><td>".$langs->trans(
"MaxPeriodNumber").
"</td><td>";
1094 print '<input type="text" name="nb_gen_max" value="'.GETPOST(
'nb_gen_max').
'" size="5" />';
1098 print "<tr><td>".$langs->trans(
"StatusOfGeneratedInvoices").
"</td><td>";
1099 $select = array(
'0'=>$langs->trans(
'BillStatusDraft'),
'1'=>$langs->trans(
'BillStatusValidated'));
1100 print $form->selectarray(
'auto_validate', $select,
GETPOST(
'auto_validate'));
1104 if (!empty($conf->global->INVOICE_REC_CAN_DISABLE_DOCUMENT_FILE_GENERATION))
1106 print "<tr><td>".$langs->trans(
"StatusOfGeneratedDocuments").
"</td><td>";
1107 $select = array(
'0'=>$langs->trans(
'DoNotGenerateDoc'),
'1'=>$langs->trans(
'AutoGenerateDoc'));
1108 print $form->selectarray(
'generate_pdf', $select,
GETPOST(
'generate_pdf'));
1111 print '<input type="hidden" name="generate_pdf" value="1">';
1119 $title = $langs->trans(
"ProductsAndServices");
1120 if (empty($conf->service->enabled))
1121 $title = $langs->trans(
"Products");
1122 elseif (empty($conf->product->enabled))
1123 $title = $langs->trans("Services");
1130 print '<div class="div-table-responsive-no-min">';
1131 print '<table
id="tablelines" class="noborder noshadow" width="100%">';
1133 if (!empty($object->lines))
1138 $object->printObjectLines(
'', $mysoc, $object->thirdparty, $lineid, 0);
1146 if ($flag_price_may_change)
1148 print '<tr><td colspan="3" class="left">';
1149 print '<select name="usenewprice" class="flat">';
1150 print '<option value="0">'.$langs->trans(
"AlwaysUseFixedPrice").
'</option>';
1151 print '<option value="1" disabled>'.$langs->trans(
"AlwaysUseNewPrice").
'</option>';
1157 print '<div align="center"><input type="submit" class="button" value="'.$langs->trans(
"Create").
'">';
1158 print ' ';
1159 print '<input type="button" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'" onClick="javascript:history.go(-1)">';
1169 if ($object->id > 0)
1171 $object->fetch_thirdparty();
1174 if ($action ==
'ask_deleteline') {
1175 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
1179 if ($action ==
'ask_deleteinvoice') {
1180 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteRepeatableInvoice'), $langs->trans(
'ConfirmDeleteRepeatableInvoice'),
'confirm_deleteinvoice',
'',
'no', 1);
1185 $author =
new User($db);
1186 $author->fetch($object->user_author);
1194 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/invoicetemplate_list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1197 if ($action !=
'editref') $morehtmlref .= $form->editfieldkey($object->ref,
'ref', $object->ref, $object, $user->rights->facture->creer,
'',
'', 0, 2);
1198 else $morehtmlref .= $form->editfieldval(
'',
'ref', $object->ref, $object, $user->rights->facture->creer,
'string');
1200 $morehtmlref .=
'<div class="refidno">';
1205 $morehtmlref .= $langs->trans(
'ThirdParty').
' : '.$object->thirdparty->getNomUrl(1);
1207 if (!empty($conf->projet->enabled))
1209 $langs->load(
"projects");
1210 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
1211 if ($user->rights->facture->creer)
1213 if ($action !=
'classify') {
1214 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
1216 if ($action ==
'classify') {
1218 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
1219 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
1220 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
1221 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
1222 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
1223 $morehtmlref .=
'</form>';
1225 $morehtmlref .= $form->form_project(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
1228 if (!empty($object->fk_project)) {
1230 $proj->fetch($object->fk_project);
1231 $morehtmlref .=
'<a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$object->fk_project.
'" title="'.$langs->trans(
'ShowProject').
'">';
1232 $morehtmlref .= $proj->ref;
1233 $morehtmlref .=
'</a>';
1239 $morehtmlref .=
'</div>';
1241 dol_banner_tab($object,
'ref', $linkback, 1,
'title',
'none', $morehtmlref,
'', 0,
'', $morehtmlright);
1243 print '<div class="fichecenter">';
1244 print '<div class="fichehalfleft">';
1245 print '<div class="underbanner clearboth"></div>';
1247 print '<table class="border centpercent tableforfield">';
1249 print '<tr><td class="titlefield">'.$langs->trans(
"Author").
'</td><td>'.$author->getFullName($langs).
"</td></tr>";
1251 print '<tr><td>'.$langs->trans(
"AmountHT").
'</td>';
1252 print '<td>'.price($object->total_ht,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
1255 print '<tr><td>'.$langs->trans(
"AmountVAT").
'</td><td>'.
price($object->total_tva,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
1259 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0)
1261 print '<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
1262 print '<td class="nowrap">'.price($object->total_localtax1, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
1264 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0)
1266 print '<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
1267 print '<td class=nowrap">'.price($object->total_localtax2, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
1270 print '<tr><td>'.$langs->trans(
"AmountTTC").
'</td><td colspan="3">'.
price($object->total_ttc,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
1276 print '<table class="nobordernopadding centpercent"><tr><td>';
1277 print $langs->trans(
'PaymentConditionsShort');
1279 if ($action !=
'editconditions' && $user->rights->facture->creer)
1280 print '<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editconditions&facid='.$object->id.
'">'.
img_edit($langs->trans(
'SetConditions'), 1).
'</a></td>';
1281 print '</tr></table>';
1285 if ($action ==
'editconditions')
1287 $form->form_conditions_reglement(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
1289 $form->form_conditions_reglement(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'none');
1298 print
'<table class="nobordernopadding" width="100%"><tr><td>';
1299 print $langs->trans(
'PaymentMode');
1301 if ($action !=
'editmode' && $user->rights->facture->creer)
1302 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&facid='.$object->id.
'">'.
img_edit($langs->trans(
'SetMode'), 1).
'</a></td>';
1303 print
'</tr></table>';
1305 if ($action ==
'editmode')
1307 $form->form_modes_reglement(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
1309 $form->form_modes_reglement(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'none');
1314 if (!empty($conf->multicurrency->enabled))
1319 print
'<table class="nobordernopadding" width="100%"><tr><td>';
1320 print $form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
1322 if ($usercancreate && $action !=
'editmulticurrencycode' && !empty($object->brouillon)) {
1323 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencycode&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
1325 print
'</tr></table>';
1327 $htmlname = (($usercancreate && $action ==
'editmulticurrencycode') ?
'multicurrency_code' :
'none');
1328 $form->form_multicurrency_code(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code, $htmlname);
1332 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1)
1336 print
'<table class="nobordernopadding" width="100%"><tr><td>';
1337 print $form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
1339 if ($usercancreate && $action !=
'editmulticurrencyrate' && !empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
1340 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencyrate&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
1342 print
'</tr></table>';
1344 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
1345 if ($action ==
'actualizemulticurrencyrate') {
1348 $form->form_multicurrency_rate(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx, ($usercancreate ?
'multicurrency_tx' :
'none'), $object->multicurrency_code);
1350 $form->form_multicurrency_rate(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
1351 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
1352 print
'<div class="inline-block"> ';
1353 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
1363 if (!empty($object->frequency) && !empty($object->date_when)) $dateexample = $object->date_when;
1367 $substitutionarray[
'__INVOICE_PREVIOUS_MONTH__'] = $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')';
1368 $substitutionarray[
'__INVOICE_MONTH__'] = $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')';
1369 $substitutionarray[
'__INVOICE_NEXT_MONTH__'] = $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')';
1370 $substitutionarray[
'__INVOICE_PREVIOUS_MONTH_TEXT__'] = $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')';
1371 $substitutionarray[
'__INVOICE_MONTH_TEXT__'] = $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')';
1372 $substitutionarray[
'__INVOICE_NEXT_MONTH_TEXT__'] = $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')';
1373 $substitutionarray[
'__INVOICE_PREVIOUS_YEAR__'] = $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')';
1374 $substitutionarray[
'__INVOICE_YEAR__'] = $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')';
1375 $substitutionarray[
'__INVOICE_NEXT_YEAR__'] = $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')';
1377 $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').
')';
1378 $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').
')';
1379 $substitutionarray[
'__INVOICE_COUNTER_CURRENT__'] = $object->nb_gen_done;
1380 $substitutionarray[
'__INVOICE_COUNTER_MAX__'] = $object->nb_gen_max;
1382 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
1383 foreach ($substitutionarray as $key => $val)
1385 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1387 $htmltext .=
'</i>';
1391 print $form->editfieldkey($form->textwithpicto($langs->trans(
'NotePublic'), $htmltext, 1,
'help',
'', 0, 2,
'notepublic'),
'note_public', $object->note_public, $object, $user->rights->facture->creer);
1392 print
'</td><td class="wordbreak">';
1393 print $form->editfieldval($langs->trans(
"NotePublic"),
'note_public', $object->note_public, $object, $user->rights->facture->creer,
'textarea:'.ROWS_4.
':90%',
'', null, null,
'', 1);
1399 print $form->editfieldkey($form->textwithpicto($langs->trans(
"NotePrivate"), $htmltext, 1,
'help',
'', 0, 2,
'noteprivate'),
'note_private', $object->note_private, $object, $user->rights->facture->creer);
1400 print
'</td><td class="wordbreak">';
1401 print $form->editfieldval($langs->trans(
"NotePrivate"),
'note_private', $object->note_private, $object, $user->rights->facture->creer,
'textarea:'.ROWS_4.
':90%',
'', null, null,
'', 1);
1406 print
'<tr><td class="nowrap">';
1407 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1408 print $langs->trans(
'BankAccount');
1410 if (($action !=
'editbankaccount') && $user->rights->facture->creer && $object->statut ==
FactureRec::STATUS_DRAFT)
1411 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editbankaccount&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetBankAccount'), 1).
'</a></td>';
1412 print
'</tr></table>';
1414 if ($action ==
'editbankaccount')
1416 $form->formSelectAccount(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
1418 $form->formSelectAccount(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
1424 print
'<tr><td class="nowrap">';
1425 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1426 print $langs->trans(
'Model');
1429 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmodelpdf&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetModel'), 1).
'</a></td>';
1430 print
'</tr></table>';
1432 if ($action ==
'editmodelpdf')
1434 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
1437 foreach ($models as $k => $model) {
1438 $list[] = str_replace(
':',
'|', $k).
':'.$model;
1440 $select =
'select;'.implode(
',', $list);
1441 print $form->editfieldval($langs->trans(
"Model"),
'modelpdf', $object->model_pdf, $object, $user->rights->facture->creer, $select);
1443 print $object->model_pdf;
1450 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1455 print
'<div class="fichehalfright">';
1456 print
'<div class="ficheaddleft">';
1457 print
'<div class="underbanner clearboth"></div>';
1463 $title = $langs->trans(
"Recurrence");
1466 print
'<table class="border centpercent tableforfield">';
1468 print
'<tr><td colspan="2"><span class="fa fa-calendar"></span> '.$title.
'</td></tr>';
1471 print
'<tr><td style="width: 50%">';
1472 print
'<table class="nobordernopadding" width="100%"><tr><td>';
1473 print $langs->trans(
'Frequency');
1475 if ($action !=
'editfrequency' && $user->rights->facture->creer)
1476 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editfrequency&facid='.$object->id.
'">'.
img_edit($langs->trans(
'Edit'), 1).
'</a></td>';
1477 print
'</tr></table>';
1479 if ($action ==
'editfrequency')
1481 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'">';
1482 print
'<input type="hidden" name="action" value="setfrequency">';
1483 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1484 print
'<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
1486 print
"<input type='text' name='frequency' value='".$object->frequency.
"' size='5' /> ".$form->selectarray(
'unit_frequency', array(
'd'=>$langs->trans(
'Day'),
'm'=>$langs->trans(
'Month'),
'y'=>$langs->trans(
'Year')), ($object->unit_frequency ? $object->unit_frequency :
'm'));
1488 print
'<td class="left"><input type="submit" class="button" value="'.$langs->trans(
"Modify").
'"></td>';
1489 print
'</tr></table></form>';
1491 if ($object->frequency > 0)
1493 print $langs->trans(
'FrequencyPer_'.$object->unit_frequency, $object->frequency);
1495 print $langs->trans(
"NotARecurringInvoiceTemplate");
1502 if ($action ==
'date_when' || $object->frequency > 0)
1504 print $form->editfieldkey($langs->trans(
"NextDateToExecution"),
'date_when', $object->date_when, $object, $user->rights->facture->creer,
'day');
1506 print $langs->trans(
"NextDateToExecution");
1509 if ($action ==
'date_when' || $object->frequency > 0)
1511 print $form->editfieldval($langs->trans(
"NextDateToExecution"),
'date_when', $object->date_when, $object, $user->rights->facture->creer,
'day', $object->date_when, null,
'',
'', 0,
'strikeIfMaxNbGenReached');
1514 if (!$object->isMaxNbGenReached())
1516 if (!$object->suspended && $action !=
'editdate_when' && $object->frequency > 0 && $object->date_when && $object->date_when < $now) print
img_warning($langs->trans(
"Late"));
1518 print
img_info($langs->trans(
"MaxNumberOfGenerationReached"));
1525 if ($action ==
'nb_gen_max' || $object->frequency > 0)
1527 print $form->editfieldkey($langs->trans(
"MaxPeriodNumber"),
'nb_gen_max', $object->nb_gen_max, $object, $user->rights->facture->creer);
1529 print $langs->trans(
"MaxPeriodNumber");
1532 if ($action ==
'nb_gen_max' || $object->frequency > 0)
1534 print $form->editfieldval($langs->trans(
"MaxPeriodNumber"),
'nb_gen_max', $object->nb_gen_max ? $object->nb_gen_max :
'', $object, $user->rights->facture->creer);
1543 if ($action ==
'auto_validate' || $object->frequency > 0)
1544 print $form->editfieldkey($langs->trans(
"StatusOfGeneratedInvoices"),
'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer);
1545 else print $langs->trans(
"StatusOfGeneratedInvoices");
1547 $select =
'select;0:'.$langs->trans(
'BillStatusDraft').
',1:'.$langs->trans(
'BillStatusValidated');
1548 if ($action ==
'auto_validate' || $object->frequency > 0)
1550 print $form->editfieldval($langs->trans(
"StatusOfGeneratedInvoices"),
'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer, $select);
1554 if (!empty($conf->global->INVOICE_REC_CAN_DISABLE_DOCUMENT_FILE_GENERATION))
1558 if ($action ==
'generate_pdf' || $object->frequency > 0)
1559 print $form->editfieldkey($langs->trans(
"StatusOfGeneratedDocuments"),
'generate_pdf', $object->generate_pdf, $object, $user->rights->facture->creer);
1560 else print $langs->trans(
"StatusOfGeneratedDocuments");
1563 $select =
'select;0:'.$langs->trans(
'DoNotGenerateDoc').
',1:'.$langs->trans(
'AutogenerateDoc');
1564 if ($action ==
'generate_pdf' || $object->frequency > 0)
1566 print $form->editfieldval($langs->trans(
"StatusOfGeneratedDocuments"),
'generate_pdf', $object->generate_pdf, $object, $user->rights->facture->creer, $select);
1571 print
'<input type="hidden" name="generate_pdf" value="1">';
1577 if ($object->frequency > 0)
1581 if (empty($conf->cron->enabled))
1583 print
info_admin($langs->trans(
"EnableAndSetupModuleCron", $langs->transnoentitiesnoconv(
"Module2300Name")));
1586 print
'<div class="underbanner clearboth"></div>';
1587 print
'<table class="border centpercent tableforfield">';
1590 print
'<tr><td style="width: 50%">'.$langs->trans(
"NbOfGenerationDone").
'</td>';
1592 print $object->nb_gen_done ? $object->nb_gen_done :
'0';
1598 print $langs->trans(
"DateLastGeneration");
1613 print
'<div class="clearboth"></div><br>';
1617 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'#add' :
'#line_'.
GETPOST(
'lineid')).
'" method="POST">
1618 <input type="hidden" name="token" value="' .
newToken().
'">
1619 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
1620 <input type="hidden" name="mode" value="">
1621 <input type="hidden" name="id" value="' . $object->id.
'">
1624 if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
1625 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
1628 print
'<div class="div-table-responsive-no-min">';
1629 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
1631 if (!empty($object->lines))
1633 $canchangeproduct = 1;
1634 $ret = $object->printObjectLines($action, $mysoc, $object->thirdparty, $lineid, 0);
1638 if ($object->statut == $object::STATUS_DRAFT && $user->rights->facture->creer && $action !=
'valid' && $action !=
'editline')
1640 if ($action !=
'editline')
1643 $object->formAddObjectLine(0, $mysoc, $object->thirdparty);
1645 $parameters = array();
1646 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
1661 print
'<div class="tabsAction">';
1663 if (empty($object->suspended))
1665 if ($user->rights->facture->creer)
1667 if (!empty($object->frequency) && $object->nb_gen_max > 0 && ($object->nb_gen_done >= $object->nb_gen_max))
1669 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"MaxGenerationReached")).
'">'.$langs->trans(
"CreateBill").
'</a></div>';
1671 if (empty($object->frequency) || $object->date_when <= $today)
1673 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>';
1675 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"DateIsNotEnough")).
'">'.$langs->trans(
"CreateBill").
'</a></div>';
1679 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
"CreateBill").
'</a></div>';
1683 if ($user->rights->facture->creer)
1685 if (empty($object->suspended))
1687 print
'<div class="inline-block divButAction"><a class="butActionDelete" href="'.DOL_URL_ROOT.
'/compta/facture/card-rec.php?action=disable&id='.$object->id.
'">'.$langs->trans(
"Disable").
'</a></div>';
1689 print
'<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.
'/compta/facture/card-rec.php?action=enable&id='.$object->id.
'">'.$langs->trans(
"Enable").
'</a></div>';
1694 if ($user->rights->facture->supprimer)
1696 print
'<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=ask_deleteinvoice&id='.$object->id.
'">'.$langs->trans(
'Delete').
'</a></div>';
1703 print
'<div class="fichecenter"><div class="fichehalfleft">';
1704 print
'<a name="builddoc"></a>';
1708 $linktoelem = $form->showLinkToObjectBlock($object, null, array(
'invoice'));
1710 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1713 print
'</div></div>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage invoice lines of templates.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
const TYPE_STANDARD
Standard invoice.
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...
static getIdAndTxFromCode($db, $code, $date_document= '')
Get id and rate of currency from code.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
Class to manage invoice templates.
Class to manage Dolibarr users.
const TYPE_REPLACEMENT
Replacement invoice.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate, from a $thirdparty_buyer to a $thirdparty_seller Note: This function applies same rules than get_default_tva.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
const TYPE_CREDIT_NOTE
Credit note invoice.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
const STATUS_DRAFT
Draft status.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage translations.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) Si ...
img_info($titlealt= 'default')
Show info logo.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
Class to manage invoices.
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.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.
invoice_rec_prepare_head($object)
Return array head with list of tabs to view object informations.