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';
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',
'companies',
'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');
62 $socid = $user->socid;
64 $objecttype =
'facture_rec';
65 if ($action ==
"create" || $action ==
"add") {
68 $projectid =
GETPOST(
'projectid',
'int');
70 $year_date_when =
GETPOST(
'year_date_when');
71 $month_date_when =
GETPOST(
'month_date_when');
73 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
74 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
75 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
77 if (empty($page) || $page == -1) {
80 $offset = $limit * $page;
85 $sortfield =
'f.titre';
87 $pageprev = $page - 1;
88 $pagenext = $page + 1;
91 if (($id > 0 || $ref) && $action !=
'create' && $action !=
'add') {
92 $ret = $object->fetch($id, $ref);
99 $hookmanager->initHooks(array(
'invoicereccard',
'globalcard'));
103 $extrafields->fetch_name_optionals_label($object->table_element);
105 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
107 $permissionnote = $user->rights->facture->creer;
108 $permissiondellink = $user->rights->facture->creer;
109 $permissiontoedit = $user->rights->facture->creer;
111 $usercanread = $user->rights->facture->lire;
112 $usercancreate = $user->rights->facture->creer;
113 $usercanissuepayment = $user->rights->facture->paiement;
114 $usercandelete = $user->rights->facture->supprimer;
115 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->validate)));
116 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send);
117 $usercanreopen = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->reopen);
118 $usercanunvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->unvalidate)));
120 $usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
121 $usercancreatemargin = $user->rights->margins->creer;
122 $usercanreadallmargin = $user->rights->margins->liretous;
123 $usercancreatewithdrarequest = $user->rights->prelevement->bons->creer;
129 $result =
restrictedArea($user,
'facture', $object->id, $objecttype);
136 if (
GETPOST(
'cancel',
'alpha')) {
140 if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
144 $parameters = array(
'socid' => $socid);
145 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
150 if (empty($reshook)) {
151 if (
GETPOST(
'cancel',
'alpha')) {
156 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
159 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
161 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
163 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
174 if ($action ==
'add') {
175 if (!
GETPOST(
'title',
'alphanohtml')) {
176 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->trans(
"Title")),
null,
'errors');
181 $frequency =
GETPOST(
'frequency',
'int');
182 $reyear =
GETPOST(
'reyear',
'int');
183 $remonth =
GETPOST(
'remonth',
'int');
184 $reday =
GETPOST(
'reday',
'int');
185 $rehour =
GETPOST(
'rehour',
'int');
186 $remin =
GETPOST(
'remin',
'int');
187 $nb_gen_max =
GETPOST(
'nb_gen_max',
'int');
190 if (
GETPOST(
'frequency',
'int')) {
191 if (empty($reyear) || empty($remonth) || empty($reday)) {
192 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->trans(
"Date")),
null,
'errors');
204 $object->titre =
GETPOST(
'title',
'alphanohtml');
205 $object->title =
GETPOST(
'title',
'alphanohtml');
206 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
207 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
208 $object->model_pdf =
GETPOST(
'modelpdf',
'alphanohtml');
209 $object->usenewprice =
GETPOST(
'usenewprice',
'alphanohtml');
211 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
212 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
214 $object->frequency = $frequency;
215 $object->unit_frequency =
GETPOST(
'unit_frequency',
'alpha');
216 $object->nb_gen_max = $nb_gen_max;
217 $object->auto_validate =
GETPOST(
'auto_validate',
'int');
218 $object->generate_pdf =
GETPOST(
'generate_pdf',
'int');
219 $object->fk_project = $projectid;
221 $date_next_execution =
dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear);
222 $object->date_when = $date_next_execution;
225 if (
GETPOST(
'facid',
'int') > 0) {
227 $srcObject->fetch(
GETPOST(
'facid',
'int'));
229 $srcObject->fetchObjectLinked();
231 if (!empty($srcObject->linkedObjectsIds[
'contrat'])) {
232 $contractidid = reset($srcObject->linkedObjectsIds[
'contrat']);
234 $object->origin =
'contrat';
235 $object->origin_id = $contractidid;
236 $object->linked_objects[$object->origin] = $object->origin_id;
242 $oldinvoice =
new Facture($db);
243 $oldinvoice->fetch(
GETPOST(
'facid',
'int'));
245 $result = $object->create($user, $oldinvoice->id);
247 $result = $oldinvoice->delete($user, 1);
262 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?facid='.$object->id);
273 if ($action ==
'confirm_deleteinvoice' && $confirm ==
'yes' && $user->rights->facture->supprimer) {
274 $object->delete($user);
276 header(
"Location: ".DOL_URL_ROOT.
'/compta/facture/invoicetemplate_list.php');
283 if ($action ==
'setconditions' && $user->rights->facture->creer) {
284 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
285 } elseif ($action ==
'setmode' && $user->rights->facture->creer) {
287 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
288 } elseif ($action ==
'classin' && $user->rights->facture->creer) {
290 $object->setProject(
GETPOST(
'projectid',
'int'));
291 } elseif ($action ==
'setref' && $user->rights->facture->creer) {
294 $result = $object->setValueFrom(
'titre', $ref,
'',
null,
'text',
'', $user,
'BILLREC_MODIFY');
296 $object->titre = $ref;
297 $object->title = $ref;
298 $object->ref = $object->title;
301 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
302 $langs->load(
"errors");
303 setEventMessages($langs->trans(
'ErrorRefAlreadyExists', $ref),
null,
'errors');
308 } elseif ($action ==
'setbankaccount' && $user->rights->facture->creer) {
310 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
311 } elseif ($action ==
'setfrequency' && $user->rights->facture->creer) {
313 $object->setFrequencyAndUnit(
GETPOST(
'frequency',
'int'),
GETPOST(
'unit_frequency',
'alpha'));
314 } elseif ($action ==
'setdate_when' && $user->rights->facture->creer) {
318 $object->setNextDate($date);
320 } elseif ($action ==
'setnb_gen_max' && $user->rights->facture->creer) {
322 $object->setMaxPeriod(
GETPOST(
'nb_gen_max',
'int'));
323 } elseif ($action ==
'setauto_validate' && $user->rights->facture->creer) {
325 $object->setAutoValidate(
GETPOST(
'auto_validate',
'int'));
326 } elseif ($action ==
'setgenerate_pdf' && $user->rights->facture->creer) {
328 $object->setGeneratepdf(
GETPOST(
'generate_pdf',
'int'));
329 } elseif ($action ==
'setmodelpdf' && $user->rights->facture->creer) {
331 $object->setModelpdf(
GETPOST(
'modelpdf',
'alpha'));
332 } elseif ($action ==
'disable' && $user->rights->facture->creer) {
338 $res = $object->setValueFrom(
'suspended', 1);
349 } elseif ($action ==
'enable' && $user->rights->facture->creer) {
355 $res = $object->setValueFrom(
'suspended', 0);
366 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
368 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
369 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
371 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
375 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $user->rights->facture->creer) {
377 $object->fetch_thirdparty();
386 if ($line->delete($user) > 0) {
387 $result = $object->update_price(1);
391 $object->fetch($object->id);
400 } elseif ($action ==
'update_extras') {
404 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
410 $result = $object->insertExtraFields(
'BILLREC_MODIFY');
419 if ($action ==
'addline' && $user->rights->facture->creer) {
420 $langs->load(
'errors');
428 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'alpha');
429 if ($prod_entry_mode ==
'free') {
431 $tva_tx = (
GETPOST(
'tva_tx',
'alpha') ?
GETPOST(
'tva_tx',
'alpha') : 0);
433 $idprod =
GETPOST(
'idprod',
'int');
441 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
442 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
444 if (is_array($extralabelsline)) {
446 foreach ($extralabelsline as $key => $value) {
447 unset($_POST[
"options_".$key.$predef]);
451 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
452 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
455 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
456 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
459 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && (!($price_ht >= 0) || $price_ht ==
'')) {
460 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
464 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
467 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
468 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
472 $langs->load(
"errors");
473 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
477 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
478 $ret = $object->fetch($id);
483 $ret = $object->fetch_thirdparty();
488 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
499 if (!empty($idprod) && $idprod > 0) {
501 $prod->fetch($idprod);
503 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
508 if (empty($tva_tx)) {
515 $datapriceofproduct = $prod->getSellPrice($mysoc, $object->thirdparty, $pqp);
517 $pu_ht = $datapriceofproduct[
'pu_ht'];
518 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
519 $price_min = $datapriceofproduct[
'price_min'];
520 $price_base_type = $datapriceofproduct[
'price_base_type'];
521 $tva_tx = $datapriceofproduct[
'tva_tx'];
522 $tva_npr = $datapriceofproduct[
'tva_npr'];
524 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
525 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
528 if (!empty($price_ht)) {
530 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
531 } elseif ($tmpvat != $tmpprodvat) {
534 if ($price_base_type !=
'HT') {
535 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
537 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
544 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
545 $outputlangs = $langs;
547 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
548 $newlang =
GETPOST(
'lang_id',
'aZ09');
550 if (empty($newlang)) {
551 $newlang = $object->thirdparty->default_lang;
553 if (!empty($newlang)) {
555 $outputlangs->setDefaultLang($newlang);
558 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->description;
560 $desc = $prod->description;
566 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
569 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
570 $outputlangs = $langs;
572 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
573 $newlang =
GETPOST(
'lang_id',
'alpha');
575 if (empty($newlang)) {
576 $newlang = $object->thirdparty->default_lang;
578 if (!empty($newlang)) {
580 $outputlangs->setDefaultLang($newlang);
581 $outputlangs->load(
'products');
583 if (!empty($prod->customcode)) {
584 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
586 if (!empty($prod->customcode) && !empty($prod->country_code)) {
589 if (!empty($prod->country_code)) {
590 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
593 if (!empty($prod->customcode)) {
594 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
596 if (!empty($prod->customcode) && !empty($prod->country_code)) {
599 if (!empty($prod->country_code)) {
600 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
608 $fk_unit = $prod->fk_unit;
612 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
613 $tva_tx = str_replace(
'*',
'', $tva_tx);
614 if (empty($tva_tx)) {
617 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
618 $desc = $product_desc;
620 $fk_unit =
GETPOST(
'units',
'alpha');
623 $date_start_fill =
GETPOST(
'date_start_fill',
'int');
624 $date_end_fill =
GETPOST(
'date_end_fill',
'int');
631 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
632 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
639 if ($usercanproductignorepricemin && (!empty($price_min) && (
price2num($pu_ht) * (1 -
price2num($remise_percent) / 100) <
price2num($price_min)))) {
640 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
644 $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);
665 $object->fetch($object->id);
667 unset($_POST[
'prod_entry_mode']);
669 unset($_POST[
'qty']);
670 unset($_POST[
'type']);
671 unset($_POST[
'remise_percent']);
672 unset($_POST[
'price_ht']);
673 unset($_POST[
'multicurrency_price_ht']);
674 unset($_POST[
'price_ttc']);
675 unset($_POST[
'tva_tx']);
676 unset($_POST[
'product_ref']);
677 unset($_POST[
'product_label']);
678 unset($_POST[
'product_desc']);
679 unset($_POST[
'fournprice']);
680 unset($_POST[
'buying_price']);
681 unset($_POST[
'np_marginRate']);
682 unset($_POST[
'np_markRate']);
683 unset($_POST[
'dp_desc']);
684 unset($_POST[
'idprod']);
685 unset($_POST[
'units']);
687 unset($_POST[
'date_starthour']);
688 unset($_POST[
'date_startmin']);
689 unset($_POST[
'date_startsec']);
690 unset($_POST[
'date_startday']);
691 unset($_POST[
'date_startmonth']);
692 unset($_POST[
'date_startyear']);
693 unset($_POST[
'date_endhour']);
694 unset($_POST[
'date_endmin']);
695 unset($_POST[
'date_endsec']);
696 unset($_POST[
'date_endday']);
697 unset($_POST[
'date_endmonth']);
698 unset($_POST[
'date_endyear']);
700 unset($_POST[
'date_start_fill']);
701 unset($_POST[
'date_end_fill']);
703 unset($_POST[
'situations']);
704 unset($_POST[
'progress']);
712 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
713 if (!$object->fetch($id) > 0) {
716 $object->fetch_thirdparty();
731 if (preg_match(
'/\*/', $vat_rate)) {
736 $vat_rate = str_replace(
'*',
'', $vat_rate);
737 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty);
738 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty);
745 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
746 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
749 if ($objectline->fetch(
GETPOST(
'lineid',
'int'))) {
750 $objectline->array_options = $array_options;
751 $result = $objectline->insertExtraFields();
757 $position = ($objectline->rang >= 0 ? $objectline->rang : 0);
760 if (is_array($extralabelsline)) {
762 foreach ($extralabelsline as $key => $value) {
763 unset($_POST[
"options_".$key]);
768 $special_code =
GETPOST(
'special_code',
'int');
769 if ($special_code == 3) {
788 $productid =
GETPOST(
'productid',
'int');
789 if (!empty($productid)) {
791 $product->fetch($productid);
793 $type = $product->type;
795 $price_min = $product->price_min;
796 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
797 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
803 if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (($object->type ==
Facture::TYPE_STANDARD || $object->type ==
Facture::TYPE_REPLACEMENT) && $price_min && (
price2num($pu_ht) * (1 - $remise_percent / 100) <
price2num($price_min)))) {
804 setEventMessages($langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency)),
null,
'errors');
808 $type =
GETPOST(
'type',
'int');
809 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
812 if (
GETPOST(
'type',
'int') < 0) {
813 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
818 $langs->load(
"errors");
819 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
823 $date_start_fill =
GETPOST(
'date_start_fill',
'int');
824 $date_end_fill =
GETPOST(
'date_end_fill',
'int');
828 $result = $object->updateline(
873 $object->fetch($object->id);
875 unset($_POST[
'qty']);
876 unset($_POST[
'type']);
877 unset($_POST[
'productid']);
878 unset($_POST[
'remise_percent']);
879 unset($_POST[
'price_ht']);
880 unset($_POST[
'multicurrency_price_ht']);
881 unset($_POST[
'price_ttc']);
882 unset($_POST[
'tva_tx']);
883 unset($_POST[
'product_ref']);
884 unset($_POST[
'product_label']);
885 unset($_POST[
'product_desc']);
886 unset($_POST[
'fournprice']);
887 unset($_POST[
'buying_price']);
888 unset($_POST[
'np_marginRate']);
889 unset($_POST[
'np_markRate']);
891 unset($_POST[
'dp_desc']);
892 unset($_POST[
'idprod']);
893 unset($_POST[
'units']);
895 unset($_POST[
'date_starthour']);
896 unset($_POST[
'date_startmin']);
897 unset($_POST[
'date_startsec']);
898 unset($_POST[
'date_startday']);
899 unset($_POST[
'date_startmonth']);
900 unset($_POST[
'date_startyear']);
901 unset($_POST[
'date_endhour']);
902 unset($_POST[
'date_endmin']);
903 unset($_POST[
'date_endsec']);
904 unset($_POST[
'date_endday']);
905 unset($_POST[
'date_endmonth']);
906 unset($_POST[
'date_endyear']);
908 unset($_POST[
'situations']);
909 unset($_POST[
'progress']);
930 $companystatic =
new Societe($db);
940 if ($action ==
'create') {
941 print
load_fiche_titre($langs->trans(
"CreateRepeatableInvoice"),
'',
'bill');
944 $product_static =
new Product($db);
946 if ($object->fetch($id, $ref) > 0) {
947 $result = $object->getLinesArray();
949 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
950 print
'<input type="hidden" name="token" value="'.newToken().
'">';
951 print
'<input type="hidden" name="action" value="add">';
952 print
'<input type="hidden" name="facid" value="'.$object->id.
'">';
960 if ($object->fk_account > 0) {
964 print
'<table class="border centpercent">';
966 $object->fetch_thirdparty();
969 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
"Title").
'</td><td>';
970 print
'<input class="flat quatrevingtpercent" type="text" name="title" value="'.dol_escape_htmltag(
GETPOST(
"title",
'alphanohtml')).
'" autofocus>';
974 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Customer").
'</td><td>'.$object->thirdparty->getNomUrl(1,
'customer').
'</td>';
977 $note_public =
GETPOSTISSET(
'note_public') ?
GETPOST(
'note_public',
'restricthtml') : $object->note_public;
978 $note_private =
GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') : $object->note_private;
983 $substitutionarray[
'__INVOICE_PREVIOUS_MONTH__'] = $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, -1,
'm'),
'%m').
')';
984 $substitutionarray[
'__INVOICE_MONTH__'] = $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($object->date,
'%m').
')';
985 $substitutionarray[
'__INVOICE_NEXT_MONTH__'] = $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, 1,
'm'),
'%m').
')';
986 $substitutionarray[
'__INVOICE_PREVIOUS_MONTH_TEXT__'] = $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, -1,
'm'),
'%B').
')';
987 $substitutionarray[
'__INVOICE_MONTH_TEXT__'] = $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($object->date,
'%B').
')';
988 $substitutionarray[
'__INVOICE_NEXT_MONTH_TEXT__'] = $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, 1,
'm'),
'%B').
')';
989 $substitutionarray[
'__INVOICE_PREVIOUS_YEAR__'] = $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, -1,
'y'),
'%Y').
')';
990 $substitutionarray[
'__INVOICE_YEAR__'] = $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($object->date,
'%Y').
')';
991 $substitutionarray[
'__INVOICE_NEXT_YEAR__'] = $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, 1,
'y'),
'%Y').
')';
993 $substitutionarray[
'__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = $langs->trans(
"DateNextInvoiceBeforeGen").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($object->date_when,
'dayhour').
')';
994 $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').
')';
995 $substitutionarray[
'__INVOICE_COUNTER_CURRENT__'] = $langs->trans(
"Count");
996 $substitutionarray[
'__INVOICE_COUNTER_MAX__'] = $langs->trans(
"MaxPeriodNumber");
998 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
999 foreach ($substitutionarray as $key => $val) {
1000 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1002 $htmltext .=
'</i>';
1006 print
'<td class="tdtop">';
1007 print
$form->textwithpicto($langs->trans(
'NotePublic'), $htmltext, 1,
'help',
'', 0, 2,
'notepublic');
1010 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3,
'90%');
1011 print $doleditor->Create(1);
1014 if (empty($user->socid)) {
1016 print
'<td class="tdtop">';
1017 print
$form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext, 1,
'help',
'', 0, 2,
'noteprivate');
1020 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3,
'90%');
1021 print $doleditor->Create(1);
1027 print
"<tr><td>".$langs->trans(
"Author").
"</td><td>".$user->getFullName($langs).
"</td></tr>";
1030 print
"<tr><td>".$langs->trans(
"PaymentConditions").
"</td><td>";
1031 print
$form->getSelectConditionsPaiements(
GETPOSTISSET(
'cond_reglement_id') ?
GETPOST(
'cond_reglement_id',
'int') : $object->cond_reglement_id,
'cond_reglement_id', -1, 0, 0,
'');
1036 print
"<tr><td>".$langs->trans(
"PaymentMode").
"</td><td>";
1037 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
1038 print
$form->select_types_paiements(
GETPOSTISSET(
'mode_reglement_id') ?
GETPOST(
'mode_reglement_id',
'int') : $object->mode_reglement_id,
'mode_reglement_id',
'', 0, 1, 0, 0, 1,
'', 1);
1043 if ($object->fk_account > 0) {
1044 print
"<tr><td>".$langs->trans(
'BankAccount').
"</td><td>";
1045 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
1050 if (
isModEnabled(
'project') && is_object($object->thirdparty) && $object->thirdparty->id > 0) {
1051 $projectid =
GETPOST(
'projectid') ?
GETPOST(
'projectid') : $object->fk_project;
1052 $langs->load(
'projects');
1053 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
1054 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
1055 $numprojet = $formproject->select_projects($object->thirdparty->id, $projectid,
'projectid', 0, 0, 1, 0, 0, 0, 0,
'', 0, 0,
'');
1056 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 :
'')).
'">'.
img_object($langs->trans(
"AddProject"),
'add').
'</a>';
1061 print
"<tr><td>".$langs->trans(
'Model').
"</td><td>";
1062 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
1064 print
img_picto(
'',
'generic',
'class="pictofixedwidth"');
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' /> ";
1084 print
$form->selectarray(
'unit_frequency', array(
'd'=>$langs->trans(
'Day'),
'm'=>$langs->trans(
'Month'),
'y'=>$langs->trans(
'Year')), (
GETPOST(
'unit_frequency') ?
GETPOST(
'unit_frequency') :
'm'));
1088 print
"<tr><td>".$langs->trans(
'NextDateToExecution').
"</td><td>";
1090 print
$form->selectDate($date_next_execution,
'', 1, 1,
'',
"add", 1, 1);
1094 print
"<tr><td>".$langs->trans(
"MaxPeriodNumber").
"</td><td>";
1095 print
'<input type="text" name="nb_gen_max" value="'.GETPOST(
'nb_gen_max').
'" size="5" />';
1099 print
"<tr><td>".$langs->trans(
"StatusOfGeneratedInvoices").
"</td><td>";
1100 $select = array(
'0'=>$langs->trans(
'BillStatusDraft'),
'1'=>$langs->trans(
'BillStatusValidated'));
1101 print
$form->selectarray(
'auto_validate', $select,
GETPOST(
'auto_validate'));
1105 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");
1121 $title = $langs->trans(
"Products");
1123 $title = $langs->trans(
"Services");
1131 print
'<div class="div-table-responsive-no-min">';
1132 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
1134 if (!empty($object->lines)) {
1138 $object->printObjectLines(
'', $mysoc, $object->thirdparty, $lineid, 0);
1146 if ($flag_price_may_change) {
1147 print
'<tr><td colspan="3" class="left">';
1148 print
'<select name="usenewprice" class="flat">';
1149 print
'<option value="0">'.$langs->trans(
"AlwaysUseFixedPrice").
'</option>';
1150 print
'<option value="1" disabled>'.$langs->trans(
"AlwaysUseNewPrice").
'</option>';
1156 print
$form->buttonsSaveCancel(
"Create");
1166 if ($object->id > 0) {
1167 $object->fetch_thirdparty();
1170 if ($action ==
'ask_deleteline') {
1171 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
1175 if ($action ==
'ask_deleteinvoice') {
1176 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteRepeatableInvoice'), $langs->trans(
'ConfirmDeleteRepeatableInvoice'),
'confirm_deleteinvoice',
'',
'no', 1);
1181 $author =
new User($db);
1182 $author->fetch($object->user_author);
1186 print
dol_get_fiche_head($head,
'card', $langs->trans(
"RepeatableInvoice"), -1,
'bill');
1190 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/invoicetemplate_list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1193 if ($action !=
'editref') {
1194 $morehtmlref .=
$form->editfieldkey($object->ref,
'ref', $object->ref, $object, $user->rights->facture->creer,
'',
'', 0, 2);
1196 $morehtmlref .=
$form->editfieldval(
'',
'ref', $object->ref, $object, $user->rights->facture->creer,
'string');
1199 $morehtmlref .=
'<div class="refidno">';
1204 $morehtmlref .= $langs->trans(
'ThirdParty').
' : '.$object->thirdparty->getNomUrl(1);
1207 $langs->load(
"projects");
1208 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
1209 if ($user->rights->facture->creer) {
1210 if ($action !=
'classify') {
1211 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
1213 if ($action ==
'classify') {
1215 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
1216 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
1217 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
1218 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
1219 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
1220 $morehtmlref .=
'</form>';
1222 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
1225 if (!empty($object->fk_project)) {
1227 $proj->fetch($object->fk_project);
1228 $morehtmlref .=
' : '.$proj->getNomUrl(1);
1230 $morehtmlref .=
' - '.$proj->title;
1237 $morehtmlref .=
'</div>';
1239 $morehtmlright =
'';
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>';
1250 print $author->getNomUrl(-1);
1253 print
'<tr><td>'.$langs->trans(
"AmountHT").
'</td>';
1254 print
'<td>'.price($object->total_ht,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
1257 print
'<tr><td>'.$langs->trans(
"AmountVAT").
'</td><td>'.
price($object->total_tva,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
1261 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) {
1262 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
1263 print
'<td class="nowrap">'.price($object->total_localtax1, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
1265 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&token='.
newToken().
'&facid='.$object->id.
'">'.
img_edit($langs->trans(
'SetConditions'), 1).
'</a></td>';
1282 print
'</tr></table>';
1285 if ($action ==
'editconditions') {
1286 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
1288 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'none');
1297 print
'<table class="nobordernopadding" width="100%"><tr><td>';
1298 print $langs->trans(
'PaymentMode');
1300 if ($action !=
'editmode' && $user->rights->facture->creer) {
1301 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&token='.
newToken().
'&facid='.$object->id.
'">'.
img_edit($langs->trans(
'SetMode'), 1).
'</a></td>';
1303 print
'</tr></table>';
1305 if ($action ==
'editmode') {
1306 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
1308 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'none');
1317 print
'<table class="nobordernopadding" width="100%"><tr><td>';
1318 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
1320 if ($usercancreate && $action !=
'editmulticurrencycode' && !empty($object->brouillon)) {
1321 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencycode&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
1323 print
'</tr></table>';
1325 $htmlname = (($usercancreate && $action ==
'editmulticurrencycode') ?
'multicurrency_code' :
'none');
1326 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code, $htmlname);
1330 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
1333 print
'<table class="nobordernopadding" width="100%"><tr><td>';
1334 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
1336 if ($usercancreate && $action !=
'editmulticurrencyrate' && !empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
1337 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencyrate&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
1339 print
'</tr></table>';
1341 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
1342 if ($action ==
'actualizemulticurrencyrate') {
1345 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx, ($usercancreate ?
'multicurrency_tx' :
'none'), $object->multicurrency_code);
1347 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
1348 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
1349 print
'<div class="inline-block"> ';
1350 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
1360 if (!empty($object->frequency) && !empty($object->date_when)) {
1361 $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) {
1384 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1386 $htmltext .=
'</i>';
1390 print
$form->editfieldkey(
$form->textwithpicto($langs->trans(
'NotePublic'), $htmltext, 1,
'help',
'', 0, 2,
'notepublic'),
'note_public', $object->note_public, $object, $user->rights->facture->creer);
1391 print
'</td><td class="wordbreak">';
1392 print
$form->editfieldval($langs->trans(
"NotePublic"),
'note_public', $object->note_public, $object, $user->rights->facture->creer,
'textarea:'.ROWS_4.
':90%',
'',
null,
null,
'', 1);
1398 print
$form->editfieldkey(
$form->textwithpicto($langs->trans(
"NotePrivate"), $htmltext, 1,
'help',
'', 0, 2,
'noteprivate'),
'note_private', $object->note_private, $object, $user->rights->facture->creer);
1399 print
'</td><td class="wordbreak">';
1400 print
$form->editfieldval($langs->trans(
"NotePrivate"),
'note_private', $object->note_private, $object, $user->rights->facture->creer,
'textarea:'.ROWS_4.
':90%',
'',
null,
null,
'', 1);
1405 print
'<tr><td class="nowrap">';
1406 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1407 print $langs->trans(
'BankAccount');
1409 if (($action !=
'editbankaccount') && $user->rights->facture->creer && $object->statut ==
FactureRec::STATUS_DRAFT) {
1410 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editbankaccount&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetBankAccount'), 1).
'</a></td>';
1412 print
'</tr></table>';
1414 if ($action ==
'editbankaccount') {
1415 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
1417 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
1423 print
'<tr><td class="nowrap">';
1424 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1425 print $langs->trans(
'Model');
1428 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmodelpdf&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetModel'), 1).
'</a></td>';
1430 print
'</tr></table>';
1432 if ($action ==
'editmodelpdf') {
1433 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
1436 foreach ($models as $k => $model) {
1437 $list[] = str_replace(
':',
'|', $k).
':'.$model;
1439 $select =
'select;'.implode(
',', $list);
1440 print
$form->editfieldval($langs->trans(
"Model"),
'modelpdf', $object->model_pdf, $object, $user->rights->facture->creer, $select);
1442 print $object->model_pdf;
1449 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1454 print
'<div class="fichehalfright">';
1455 print
'<div class="underbanner clearboth"></div>';
1461 $title = $langs->trans(
"Recurrence");
1464 print
'<table class="border centpercent tableforfield">';
1466 print
'<tr><td colspan="2">'.img_picto(
'',
'recurring',
'class="pictofixedwidth"').$title.
'</td></tr>';
1469 print
'<tr><td style="width: 50%">';
1470 print
'<table class="nobordernopadding" width="100%"><tr><td>';
1471 print $langs->trans(
'Frequency');
1473 if ($action !=
'editfrequency' && $user->rights->facture->creer) {
1474 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editfrequency&token='.
newToken().
'&facid='.$object->id.
'">'.
img_edit($langs->trans(
'Edit'), 1).
'</a></td>';
1476 print
'</tr></table>';
1478 if ($action ==
'editfrequency') {
1479 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'">';
1480 print
'<input type="hidden" name="action" value="setfrequency">';
1481 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1482 print
'<table class="nobordernopadding">';
1484 print
"<input type='text' name='frequency' value='".$object->frequency.
"' size='5' /> ";
1485 print
$form->selectarray(
'unit_frequency', array(
'd'=>$langs->trans(
'Day'),
'm'=>$langs->trans(
'Month'),
'y'=>$langs->trans(
'Year')), ($object->unit_frequency ? $object->unit_frequency :
'm'));
1487 print
'<td class="left"><input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans(
"Modify").
'"></td>';
1488 print
'</tr></table></form>';
1490 if ($object->frequency > 0) {
1491 print $langs->trans(
'FrequencyPer_'.$object->unit_frequency, $object->frequency);
1493 print
'<span class="opacitymedium">'.$langs->trans(
"NotARecurringInvoiceTemplate").
'</span>';
1500 if ($action ==
'date_when' || $object->frequency > 0) {
1501 print
$form->editfieldkey($langs->trans(
"NextDateToExecution"),
'date_when', $object->date_when, $object, $user->rights->facture->creer,
'day');
1503 print $langs->trans(
"NextDateToExecution");
1506 if ($action ==
'date_when' || $object->frequency > 0) {
1507 print
$form->editfieldval($langs->trans(
"NextDateToExecution"),
'date_when', $object->date_when, $object, $user->rights->facture->creer,
'day', $object->date_when,
null,
'',
'', 0,
'strikeIfMaxNbGenReached');
1510 if (!$object->isMaxNbGenReached()) {
1511 if (!$object->suspended && $action !=
'editdate_when' && $object->frequency > 0 && $object->date_when && $object->date_when < $now) {
1515 print
img_info($langs->trans(
"MaxNumberOfGenerationReached"));
1522 if ($action ==
'nb_gen_max' || $object->frequency > 0) {
1523 print
$form->editfieldkey($langs->trans(
"MaxPeriodNumber"),
'nb_gen_max', $object->nb_gen_max, $object, $user->rights->facture->creer);
1525 print $langs->trans(
"MaxPeriodNumber");
1528 if ($action ==
'nb_gen_max' || $object->frequency > 0) {
1529 print
$form->editfieldval($langs->trans(
"MaxPeriodNumber"),
'nb_gen_max', $object->nb_gen_max ? $object->nb_gen_max :
'', $object, $user->rights->facture->creer);
1538 if ($action ==
'auto_validate' || $object->frequency > 0) {
1539 print
$form->editfieldkey($langs->trans(
"StatusOfGeneratedInvoices"),
'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer);
1541 print $langs->trans(
"StatusOfGeneratedInvoices");
1544 $select =
'select;0:'.$langs->trans(
'BillStatusDraft').
',1:'.$langs->trans(
'BillStatusValidated');
1545 if ($action ==
'auto_validate' || $object->frequency > 0) {
1546 print
$form->editfieldval($langs->trans(
"StatusOfGeneratedInvoices"),
'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer, $select);
1550 if (!empty($conf->global->INVOICE_REC_CAN_DISABLE_DOCUMENT_FILE_GENERATION)) {
1553 if ($action ==
'generate_pdf' || $object->frequency > 0) {
1554 print
$form->editfieldkey($langs->trans(
"StatusOfGeneratedDocuments"),
'generate_pdf', $object->generate_pdf, $object, $user->rights->facture->creer);
1556 print $langs->trans(
"StatusOfGeneratedDocuments");
1560 $select =
'select;0:'.$langs->trans(
'DoNotGenerateDoc').
',1:'.$langs->trans(
'AutogenerateDoc');
1561 if ($action ==
'generate_pdf' || $object->frequency > 0) {
1562 print
$form->editfieldval($langs->trans(
"StatusOfGeneratedDocuments"),
'generate_pdf', $object->generate_pdf, $object, $user->rights->facture->creer, $select);
1567 print
'<input type="hidden" name="generate_pdf" value="1">';
1573 if ($object->frequency > 0) {
1577 print
info_admin($langs->trans(
"EnableAndSetupModuleCron", $langs->transnoentitiesnoconv(
"Module2300Name")));
1580 print
'<div class="underbanner clearboth"></div>';
1581 print
'<table class="border centpercent tableforfield">';
1584 print
'<tr><td style="width: 50%">'.$langs->trans(
"NbOfGenerationDone").
'</td>';
1586 print $object->nb_gen_done ? $object->nb_gen_done :
'0';
1592 print $langs->trans(
"DateLastGeneration");
1606 print
'<div class="clearboth"></div><br>';
1610 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'#add' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">';
1611 print
'<input type="hidden" name="token" value="' .
newToken().
'">';
1612 print
'<input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">';
1613 print
'<input type="hidden" name="mode" value="">';
1614 print
'<input type="hidden" name="id" value="' . $object->id.
'">';
1615 print
'<input type="hidden" name="page_y" value="">';
1617 if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
1618 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
1621 print
'<div class="div-table-responsive-no-min">';
1622 print
'<table id="tablelines" class="noborder noshadow centpercent">';
1624 if (!empty($object->lines)) {
1625 $canchangeproduct = 1;
1626 $ret = $object->printObjectLines($action, $mysoc, $object->thirdparty, $lineid, 0);
1630 if ($object->statut == $object::STATUS_DRAFT && $user->rights->facture->creer && $action !=
'valid' && $action !=
'editline') {
1631 if ($action !=
'editline') {
1634 $parameters = array();
1635 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
1636 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
1637 if (empty($reshook))
1638 $object->formAddObjectLine(0, $mysoc, $object->thirdparty);
1653 print
'<div class="tabsAction">';
1655 if (empty($object->suspended)) {
1656 if ($user->rights->facture->creer) {
1657 if (!empty($object->frequency) && $object->nb_gen_max > 0 && ($object->nb_gen_done >= $object->nb_gen_max)) {
1658 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"MaxGenerationReached")).
'">'.$langs->trans(
"CreateBill").
'</a></div>';
1660 if (empty($object->frequency) || $object->date_when <= $nowlasthour) {
1661 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>';
1663 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"DateIsNotEnough")).
'">'.$langs->trans(
"CreateBill").
'</a></div>';
1667 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
"CreateBill").
'</a></div>';
1671 if ($user->rights->facture->creer) {
1672 if (empty($object->suspended)) {
1673 print
'<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?action=disable&id='.$object->id.
'&token='.
newToken().
'">'.$langs->trans(
"Disable").
'</a></div>';
1675 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=enable&id='.$object->id.
'&token='.
newToken().
'">'.$langs->trans(
"Enable").
'</a></div>';
1680 if ($user->rights->facture->supprimer) {
1681 print
'<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=ask_deleteinvoice&id='.$object->id.
'&token='.
newToken().
'">'.$langs->trans(
'Delete').
'</a></div>';
1688 print
'<div class="fichecenter"><div class="fichehalfleft">';
1689 print
'<a name="builddoc"></a>';
1693 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'invoice'));
1695 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
1699 print
'<div class="fichehalfright">';
1706 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
1708 $somethingshown =
$formactions->showactions($object, $object->element, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1,
'', $MAXEVENT,
'', $morehtmlcenter);