35require
'../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
39if (isModEnabled(
'project')) {
40 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
49$langs->loadLangs(array(
'bills',
'companies',
'compta',
'admin',
'other',
'products',
'banks'));
51$action =
GETPOST(
'action',
'alpha');
52$massaction =
GETPOST(
'massaction',
'alpha');
53$show_files =
GETPOST(
'show_files',
'int');
54$confirm =
GETPOST(
'confirm',
'alpha');
55$cancel =
GETPOST(
'cancel',
'alpha');
56$toselect =
GETPOST(
'toselect',
'array');
57$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'invoicetemplatelist';
61$lineid =
GETPOST(
'lineid',
'int');
64 $socid = $user->socid;
66$objecttype =
'facture_rec';
67if ($action ==
"create" || $action ==
"add") {
70$projectid =
GETPOST(
'projectid',
'int');
72$year_date_when =
GETPOST(
'year_date_when');
73$month_date_when =
GETPOST(
'month_date_when');
74$selectedLines =
GETPOST(
'toselect',
'array');
76$limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
77$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
78$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
79$page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
80if (empty($page) || $page == -1) {
83$offset = $limit * $page;
88 $sortfield =
'f.titre';
94if (($id > 0 || $ref) && $action !=
'create' && $action !=
'add') {
95 $ret = $object->fetch($id, $ref);
102$hookmanager->initHooks(array(
'invoicereccard',
'globalcard'));
106$extrafields->fetch_name_optionals_label($object->table_element);
108$search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
110$permissionnote = $user->hasRight(
'facture',
'creer');
111$permissiondellink = $user->hasRight(
'facture',
'creer');
112$permissiontoedit = $user->hasRight(
'facture',
'creer');
114$usercanread = $user->hasRight(
'facture',
'lire');
115$usercancreate = $user->hasRight(
'facture',
'creer');
116$usercanissuepayment = $user->hasRight(
'facture',
'paiement');
117$usercandelete = $user->hasRight(
'facture',
'supprimer');
118$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->facture->invoice_advance->validate)));
119$usercansend = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->rights->facture->invoice_advance->send);
120$usercanreopen = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->rights->facture->invoice_advance->reopen);
121$usercanunvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->facture->invoice_advance->unvalidate)));
123$usercanproductignorepricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && empty($user->rights->produit->ignore_price_min_advance)) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
124$usercancreatemargin = $user->hasRight(
"margins",
"creer");
125$usercanreadallmargin = $user->hasRight(
"margins",
"liretous");
126$usercancreatewithdrarequest = $user->hasRight(
"prelevement",
"bons",
"creer");
132$result =
restrictedArea($user,
'facture', $object->id, $objecttype);
139if (
GETPOST(
'cancel',
'alpha')) {
143if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
147$parameters = array();
148$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
153if (empty($reshook)) {
154 if (
GETPOST(
'cancel',
'alpha')) {
159 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
162 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
164 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
166 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
177 if ($action ==
'add') {
178 if (!
GETPOST(
'title',
'alphanohtml')) {
179 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->trans(
"Title")),
null,
'errors');
184 $frequency =
GETPOST(
'frequency',
'int');
185 $reyear =
GETPOST(
'reyear',
'int');
186 $remonth =
GETPOST(
'remonth',
'int');
187 $reday =
GETPOST(
'reday',
'int');
188 $rehour =
GETPOST(
'rehour',
'int');
189 $remin =
GETPOST(
'remin',
'int');
190 $nb_gen_max =
GETPOST(
'nb_gen_max',
'int');
193 if (
GETPOST(
'frequency',
'int')) {
194 if (empty($reyear) || empty($remonth) || empty($reday)) {
195 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->trans(
"Date")),
null,
'errors');
207 $object->subtype =
GETPOST(
'subtype');
208 $object->title =
GETPOST(
'title',
'alphanohtml');
209 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
210 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
211 $object->model_pdf =
GETPOST(
'modelpdf',
'alphanohtml');
212 $object->usenewprice =
GETPOST(
'usenewprice',
'alphanohtml');
214 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
215 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
217 $object->frequency = $frequency;
218 $object->unit_frequency =
GETPOST(
'unit_frequency',
'alpha');
219 $object->nb_gen_max = $nb_gen_max;
220 $object->auto_validate =
GETPOST(
'auto_validate',
'int');
221 $object->generate_pdf =
GETPOST(
'generate_pdf',
'int');
222 $object->fk_project = $projectid;
224 $date_next_execution =
dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear);
225 $object->date_when = $date_next_execution;
227 $ret = $extrafields->setOptionalsFromPost(
null, $object);
233 if (
GETPOST(
'facid',
'int') > 0) {
235 $srcObject->fetch(
GETPOST(
'facid',
'int'));
237 $srcObject->fetchObjectLinked();
239 if (!empty($srcObject->linkedObjectsIds[
'contrat'])) {
240 $contractidid = reset($srcObject->linkedObjectsIds[
'contrat']);
242 $object->origin =
'contrat';
243 $object->origin_id = $contractidid;
244 $object->linked_objects[$object->origin] = $object->origin_id;
250 $oldinvoice =
new Facture($db);
251 $oldinvoice->fetch(
GETPOST(
'facid',
'int'));
253 $onlylines =
GETPOST(
'toselect',
'array');
255 $result = $object->create($user, $oldinvoice->id, 0, $onlylines);
257 $result = $oldinvoice->delete($user, 1);
272 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?facid='.$object->id);
283 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->hasRight(
'facture',
'supprimer')) {
284 $object->delete($user);
286 header(
"Location: ".DOL_URL_ROOT.
'/compta/facture/invoicetemplate_list.php');
292 if ($action ==
'setconditions' && $user->hasRight(
'facture',
'creer')) {
294 $object->context[
'actionmsg'] = $langs->trans(
"FieldXModified", $langs->transnoentitiesnoconv(
"PaymentTerm"));
295 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
296 } elseif ($action ==
'setmode' && $user->hasRight(
'facture',
'creer')) {
298 $object->context[
'actionmsg'] = $langs->trans(
"FieldXModified", $langs->transnoentitiesnoconv(
"PaymentMode"));
299 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
300 } elseif ($action ==
'classin' && $user->hasRight(
'facture',
'creer')) {
302 $object->context[
'actionmsg'] = $langs->trans(
"FieldXModified", $langs->transnoentitiesnoconv(
"Project"));
303 $object->setProject(
GETPOST(
'projectid',
'int'));
304 } elseif ($action ==
'setref' && $user->hasRight(
'facture',
'creer')) {
306 $object->context[
'actionmsg'] = $langs->trans(
"FieldXModifiedFromYToZ", $langs->transnoentitiesnoconv(
"Title"), $object->title, $ref);
307 $result = $object->setValueFrom(
'titre', $ref,
'',
null,
'text',
'', $user,
'BILLREC_MODIFY');
309 $object->title = $ref;
310 $object->ref = $object->title;
313 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
314 $langs->load(
"errors");
315 setEventMessages($langs->trans(
'ErrorRefAlreadyExists', $ref),
null,
'errors');
320 } elseif ($action ==
'setbankaccount' && $user->hasRight(
'facture',
'creer')) {
322 $object->context[
'actionmsg'] = $langs->trans(
"FieldXModified", $langs->transnoentitiesnoconv(
"Bank"));
323 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
324 } elseif ($action ==
'setfrequency' && $user->hasRight(
'facture',
'creer')) {
326 $object->context[
'actionmsg'] = $langs->trans(
"FieldXModified", $langs->transnoentitiesnoconv(
"Frequency"));
327 $object->setFrequencyAndUnit(
GETPOST(
'frequency',
'int'),
GETPOST(
'unit_frequency',
'alpha'));
328 } elseif ($action ==
'setdate_when' && $user->hasRight(
'facture',
'creer')) {
332 $object->setNextDate($date);
334 } elseif ($action ==
'setnb_gen_max' && $user->hasRight(
'facture',
'creer')) {
336 $object->setMaxPeriod(
GETPOST(
'nb_gen_max',
'int'));
337 } elseif ($action ==
'setauto_validate' && $user->hasRight(
'facture',
'creer')) {
339 $object->setAutoValidate(
GETPOST(
'auto_validate',
'int'));
340 } elseif ($action ==
'setgenerate_pdf' && $user->hasRight(
'facture',
'creer')) {
342 $object->setGeneratepdf(
GETPOST(
'generate_pdf',
'int'));
343 } elseif ($action ==
'setmodelpdf' && $user->hasRight(
'facture',
'creer')) {
345 $object->setModelpdf(
GETPOST(
'modelpdf',
'alpha'));
346 } elseif ($action ==
'disable' && $user->hasRight(
'facture',
'creer')) {
350 $object->context[
'actionmsg'] = $langs->trans(
"RecordDisabled");
352 $res = $object->setValueFrom(
'suspended', 1,
'',
null,
'text',
'', $user,
'BILLREC_MODIFY');
363 } elseif ($action ==
'enable' && $user->hasRight(
'facture',
'creer')) {
367 $object->context[
'actionmsg'] = $langs->trans(
"RecordEnabled");
369 $res = $object->setValueFrom(
'suspended', 0,
'',
null,
'text',
'', $user,
'BILLREC_MODIFY');
380 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
382 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
383 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
385 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
389 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $user->hasRight(
'facture',
'creer')) {
391 $object->fetch_thirdparty();
400 if ($line->delete($user) > 0) {
401 $result = $object->update_price(1);
405 $object->fetch($object->id);
414 } elseif ($action ==
'update_extras') {
415 $object->oldcopy =
dol_clone($object, 2);
418 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
424 $result = $object->insertExtraFields(
'BILLREC_MODIFY');
433 if ($action ==
'addline' && $user->hasRight(
'facture',
'creer')) {
434 $langs->load(
'errors');
439 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
442 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'alpha');
443 if ($prod_entry_mode ==
'free') {
446 $idprod =
GETPOST(
'idprod',
'int');
449 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
454 $tva_tx = (
GETPOST(
'tva_tx',
'alpha') ?
GETPOST(
'tva_tx',
'alpha') : 0);
458 if (empty($remise_percent)) {
463 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
464 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
466 if (is_array($extralabelsline)) {
468 foreach ($extralabelsline as $key => $value) {
469 unset($_POST[
"options_".$key.$predef]);
473 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
474 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
477 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
478 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
481 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && (!($price_ht >= 0) || $price_ht ==
'')) {
482 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
486 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
489 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
490 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
494 $langs->load(
"errors");
495 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
499 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
500 $ret = $object->fetch($id);
505 $ret = $object->fetch_thirdparty();
510 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
521 if (!empty($idprod) && $idprod > 0) {
523 $prod->fetch($idprod);
525 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
537 $datapriceofproduct = $prod->getSellPrice($mysoc, $object->thirdparty, $pqp);
539 $pu_ht = $datapriceofproduct[
'pu_ht'];
540 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
541 $price_min = $datapriceofproduct[
'price_min'];
542 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
546 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
547 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
550 if (!empty($price_ht)) {
552 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
553 } elseif ($tmpvat != $tmpprodvat) {
556 if ($price_base_type !=
'HT') {
557 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
559 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
567 $outputlangs = $langs;
569 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
570 $newlang =
GETPOST(
'lang_id',
'aZ09');
572 if (empty($newlang)) {
573 $newlang = $object->thirdparty->default_lang;
575 if (!empty($newlang)) {
577 $outputlangs->setDefaultLang($newlang);
580 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->
description;
582 $desc = $prod->description;
588 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
592 $outputlangs = $langs;
594 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
595 $newlang =
GETPOST(
'lang_id',
'alpha');
597 if (empty($newlang)) {
598 $newlang = $object->thirdparty->default_lang;
600 if (!empty($newlang)) {
602 $outputlangs->setDefaultLang($newlang);
603 $outputlangs->load(
'products');
605 if (!empty($prod->customcode)) {
606 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
608 if (!empty($prod->customcode) && !empty($prod->country_code)) {
611 if (!empty($prod->country_code)) {
612 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
615 if (!empty($prod->customcode)) {
616 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
618 if (!empty($prod->customcode) && !empty($prod->country_code)) {
621 if (!empty($prod->country_code)) {
622 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
630 $fk_unit = $prod->fk_unit;
634 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
635 $tva_tx = str_replace(
'*',
'', $tva_tx);
636 if (empty($tva_tx)) {
639 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
640 $desc = $product_desc;
642 $fk_unit =
GETPOST(
'units',
'alpha');
645 $date_start_fill =
GETPOST(
'date_start_fill',
'int');
646 $date_end_fill =
GETPOST(
'date_end_fill',
'int');
653 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
654 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
661 $fk_parent_line =
GETPOST(
'fk_parent_line',
'int');
663 if ($usercanproductignorepricemin && (!empty($price_min) && (
price2num($pu_ht) * (1 -
price2num($remise_percent) / 100) <
price2num($price_min)))) {
664 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
668 $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, $fk_parent_line);
689 $object->fetch($object->id);
691 unset($_POST[
'prod_entry_mode']);
693 unset($_POST[
'qty']);
694 unset($_POST[
'type']);
695 unset($_POST[
'remise_percent']);
696 unset($_POST[
'price_ht']);
697 unset($_POST[
'multicurrency_price_ht']);
698 unset($_POST[
'price_ttc']);
699 unset($_POST[
'tva_tx']);
700 unset($_POST[
'product_ref']);
701 unset($_POST[
'product_label']);
702 unset($_POST[
'product_desc']);
703 unset($_POST[
'fournprice']);
704 unset($_POST[
'buying_price']);
705 unset($_POST[
'np_marginRate']);
706 unset($_POST[
'np_markRate']);
707 unset($_POST[
'dp_desc']);
708 unset($_POST[
'idprod']);
709 unset($_POST[
'units']);
711 unset($_POST[
'date_starthour']);
712 unset($_POST[
'date_startmin']);
713 unset($_POST[
'date_startsec']);
714 unset($_POST[
'date_startday']);
715 unset($_POST[
'date_startmonth']);
716 unset($_POST[
'date_startyear']);
717 unset($_POST[
'date_endhour']);
718 unset($_POST[
'date_endmin']);
719 unset($_POST[
'date_endsec']);
720 unset($_POST[
'date_endday']);
721 unset($_POST[
'date_endmonth']);
722 unset($_POST[
'date_endyear']);
724 unset($_POST[
'date_start_fill']);
725 unset($_POST[
'date_end_fill']);
727 unset($_POST[
'situations']);
728 unset($_POST[
'progress']);
736 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
737 if (!$object->fetch($id) > 0) {
740 $object->fetch_thirdparty();
755 if (preg_match(
'/\*/', $vat_rate)) {
760 $vat_rate = str_replace(
'*',
'', $vat_rate);
761 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty);
762 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty);
769 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
770 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
773 if ($objectline->fetch(
GETPOST(
'lineid',
'int'))) {
774 $objectline->array_options = $array_options;
775 $result = $objectline->insertExtraFields();
781 $position = ($objectline->rang >= 0 ? $objectline->rang : 0);
784 if (is_array($extralabelsline)) {
786 foreach ($extralabelsline as $key => $value) {
787 unset($_POST[
"options_".$key]);
792 $special_code =
GETPOST(
'special_code',
'int');
793 if ($special_code == 3) {
810 if (empty($remise_percent)) {
815 $productid =
GETPOST(
'productid',
'int');
816 if (!empty($productid)) {
818 $product->fetch($productid);
820 $type = $product->type;
822 $price_min = $product->price_min;
823 if (
getDolGlobalString(
'PRODUIT_MULTIPRICES') && !empty($object->thirdparty->price_level)) {
824 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
833 setEventMessages($langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency)),
null,
'errors');
837 $type =
GETPOST(
'type',
'int');
838 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
841 if (
GETPOST(
'type',
'int') < 0) {
842 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
847 $langs->load(
"errors");
848 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
852 $date_start_fill =
GETPOST(
'date_start_fill',
'int');
853 $date_end_fill =
GETPOST(
'date_end_fill',
'int');
854 $fk_parent_line =
GETPOST(
'fk_parent_line',
'int');
858 $result = $object->updateline(
904 $object->fetch($object->id);
906 unset($_POST[
'qty']);
907 unset($_POST[
'type']);
908 unset($_POST[
'productid']);
909 unset($_POST[
'remise_percent']);
910 unset($_POST[
'price_ht']);
911 unset($_POST[
'multicurrency_price_ht']);
912 unset($_POST[
'price_ttc']);
913 unset($_POST[
'tva_tx']);
914 unset($_POST[
'product_ref']);
915 unset($_POST[
'product_label']);
916 unset($_POST[
'product_desc']);
917 unset($_POST[
'fournprice']);
918 unset($_POST[
'buying_price']);
919 unset($_POST[
'np_marginRate']);
920 unset($_POST[
'np_markRate']);
922 unset($_POST[
'dp_desc']);
923 unset($_POST[
'idprod']);
924 unset($_POST[
'units']);
926 unset($_POST[
'date_starthour']);
927 unset($_POST[
'date_startmin']);
928 unset($_POST[
'date_startsec']);
929 unset($_POST[
'date_startday']);
930 unset($_POST[
'date_startmonth']);
931 unset($_POST[
'date_startyear']);
932 unset($_POST[
'date_endhour']);
933 unset($_POST[
'date_endmin']);
934 unset($_POST[
'date_endsec']);
935 unset($_POST[
'date_endday']);
936 unset($_POST[
'date_endmonth']);
937 unset($_POST[
'date_endyear']);
939 unset($_POST[
'situations']);
940 unset($_POST[
'progress']);
953$title = $object->ref.
" - ".$langs->trans(
'Card');
958$form =
new Form($db);
960if (isModEnabled(
'project')) {
963$companystatic =
new Societe($db);
973if ($action ==
'create') {
974 print
load_fiche_titre($langs->trans(
"CreateRepeatableInvoice"),
'',
'bill');
977 $product_static =
new Product($db);
979 if ($object->fetch($id, $ref) > 0) {
980 $result = $object->getLinesArray();
982 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
983 print
'<input type="hidden" name="token" value="'.newToken().
'">';
984 print
'<input type="hidden" name="action" value="add">';
985 print
'<input type="hidden" name="facid" value="'.$object->id.
'">';
990 if (isModEnabled(
'project')) {
993 if ($object->fk_account > 0) {
997 print
'<table class="border centpercent">';
999 $object->fetch_thirdparty();
1002 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
"Title").
'</td><td>';
1003 print
'<input class="flat quatrevingtpercent" type="text" name="title" value="'.dol_escape_htmltag(
GETPOST(
"title",
'alphanohtml')).
'" autofocus>';
1007 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Customer").
'</td><td>'.$object->thirdparty->getNomUrl(1,
'customer').
'</td>';
1012 print
"<tr><td>".$langs->trans(
"InvoiceSubtype").
"</td><td>";
1013 print $form->getSelectInvoiceSubtype(GETPOSTISSET(
'subtype') ?
GETPOST(
'subtype') : $object->subtype,
'subtype', 0, 0,
'');
1017 $note_public = GETPOSTISSET(
'note_public') ?
GETPOST(
'note_public',
'restricthtml') : $object->note_public;
1018 $note_private = GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') : $object->note_private;
1023 $substitutionarray[
'__INVOICE_PREVIOUS_MONTH__'] = $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, -1,
'm'),
'%m').
')';
1024 $substitutionarray[
'__INVOICE_MONTH__'] = $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($object->date,
'%m').
')';
1025 $substitutionarray[
'__INVOICE_NEXT_MONTH__'] = $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, 1,
'm'),
'%m').
')';
1026 $substitutionarray[
'__INVOICE_PREVIOUS_MONTH_TEXT__'] = $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, -1,
'm'),
'%B').
')';
1027 $substitutionarray[
'__INVOICE_MONTH_TEXT__'] = $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($object->date,
'%B').
')';
1028 $substitutionarray[
'__INVOICE_NEXT_MONTH_TEXT__'] = $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, 1,
'm'),
'%B').
')';
1029 $substitutionarray[
'__INVOICE_PREVIOUS_YEAR__'] = $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, -1,
'y'),
'%Y').
')';
1030 $substitutionarray[
'__INVOICE_YEAR__'] = $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($object->date,
'%Y').
')';
1031 $substitutionarray[
'__INVOICE_NEXT_YEAR__'] = $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, 1,
'y'),
'%Y').
')';
1033 $substitutionarray[
'__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = $langs->trans(
"DateNextInvoiceBeforeGen").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, 1,
'm'),
'dayhour').
')';
1034 $substitutionarray[
'__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] = $langs->trans(
"DateNextInvoiceAfterGen").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($object->date, 2,
'm'),
'dayhour').
')';
1035 $substitutionarray[
'__INVOICE_COUNTER_CURRENT__'] = $langs->trans(
"Count");
1036 $substitutionarray[
'__INVOICE_COUNTER_MAX__'] = $langs->trans(
"MaxPeriodNumber");
1038 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
1039 foreach ($substitutionarray as $key => $val) {
1040 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1042 $htmltext .=
'</i>';
1045 print
"<tr><td>".$langs->trans(
"Author").
"</td><td>".$user->getFullName($langs).
"</td></tr>";
1048 print
"<tr><td>".$langs->trans(
"PaymentConditions").
"</td><td>";
1049 print $form->getSelectConditionsPaiements(GETPOSTISSET(
'cond_reglement_id') ?
GETPOST(
'cond_reglement_id',
'int') : $object->cond_reglement_id,
'cond_reglement_id', -1, 0, 0,
'');
1054 print
"<tr><td>".$langs->trans(
"PaymentMode").
"</td><td>";
1055 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
1056 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);
1061 if ($object->fk_account > 0) {
1062 print
"<tr><td>".$langs->trans(
'BankAccount').
"</td><td>";
1063 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
1069 $draft->fetch(
GETPOST(
'facid',
'int'));
1072 $extralabels = $extrafields->fetch_name_optionals_label($draft->table_element);
1073 if ($draft->fetch_optionals() > 0) {
1074 $object->array_options = array_merge($object->array_options, $draft->array_options);
1077 print $object->showOptionals($extrafields,
'create', $parameters);
1080 if (isModEnabled(
'project') && is_object($object->thirdparty) && $object->thirdparty->id > 0) {
1081 $projectid =
GETPOST(
'projectid') ?
GETPOST(
'projectid') : $object->fk_project;
1082 $langs->load(
'projects');
1083 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
1084 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
1085 $numprojet = $formproject->select_projects($object->thirdparty->id, $projectid,
'projectid', 0, 0, 1, 0, 0, 0, 0,
'', 0, 0,
'');
1086 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>';
1091 print
"<tr><td>".$langs->trans(
'Model').
"</td><td>";
1092 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
1094 print
img_picto(
'',
'generic',
'class="pictofixedwidth"');
1095 print $form->selectarray(
'modelpdf', $list, $conf->global->FACTURE_ADDON_PDF);
1100 print
'<td class="tdtop">';
1101 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext, 1,
'help',
'', 0, 2,
'notepublic');
1104 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
1105 print $doleditor->Create(1);
1108 if (empty($user->socid)) {
1110 print
'<td class="tdtop">';
1111 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext, 1,
'help',
'', 0, 2,
'noteprivate');
1114 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
1115 print $doleditor->Create(1);
1125 $title = $langs->trans(
"Recurrence");
1128 print
'<span class="opacitymedium">'.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name')).
'</span><br><br>';
1132 print
'<table class="border centpercent">';
1135 print
'<tr><td class="titlefieldcreate">'.$form->textwithpicto($langs->trans(
"Frequency"), $langs->transnoentitiesnoconv(
'toolTipFrequency')).
"</td><td>";
1136 print
"<input type='text' name='frequency' value='".GETPOST(
'frequency',
'int').
"' size='4' /> ";
1137 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'));
1141 print
"<tr><td>".$langs->trans(
'NextDateToExecution').
"</td><td>";
1143 print $form->selectDate($date_next_execution,
'', 1, 1,
'',
"add", 1, 1);
1147 print
"<tr><td>".$langs->trans(
"MaxPeriodNumber").
"</td><td>";
1148 print
'<input type="text" name="nb_gen_max" value="'.GETPOST(
'nb_gen_max').
'" size="5" />';
1152 print
"<tr><td>".$langs->trans(
"StatusOfAutoGeneratedInvoices").
"</td><td>";
1153 $select = array(
'0'=>$langs->trans(
'BillStatusDraft'),
'1'=>$langs->trans(
'BillStatusValidated'));
1154 print $form->selectarray(
'auto_validate', $select,
GETPOST(
'auto_validate'));
1159 print
"<tr><td>".$langs->trans(
"StatusOfGeneratedDocuments").
"</td><td>";
1160 $select = array(
'0'=>$langs->trans(
'DoNotGenerateDoc'),
'1'=>$langs->trans(
'AutoGenerateDoc'));
1161 print $form->selectarray(
'generate_pdf', $select,
GETPOST(
'generate_pdf'));
1164 print
'<input type="hidden" name="generate_pdf" value="1">';
1172 $title = $langs->trans(
"ProductsAndServices");
1173 if (!isModEnabled(
'service')) {
1174 $title = $langs->trans(
"Products");
1175 } elseif (!isModEnabled(
'product')) {
1176 $title = $langs->trans(
"Services");
1184 print
'<div class="div-table-responsive-no-min">';
1185 print
'<table id="tablelines" class="noborder noshadow centpercent">';
1188 if (!empty($object->lines)) {
1189 $object->printOriginLinesList(
'', $selectedLines);
1197 if (!empty($flag_price_may_change)) {
1198 print
'<tr><td colspan="3" class="left">';
1199 print
'<select name="usenewprice" class="flat">';
1200 print
'<option value="0">'.$langs->trans(
"AlwaysUseFixedPrice").
'</option>';
1201 print
'<option value="1" disabled>'.$langs->trans(
"AlwaysUseNewPrice").
'</option>';
1207 print $form->buttonsSaveCancel(
"Create");
1217 if ($object->id > 0) {
1218 $object->fetch_thirdparty();
1222 if ($action ==
'ask_deleteline') {
1223 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
1226 if ($action ==
'delete') {
1227 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteRepeatableInvoice'), $langs->trans(
'ConfirmDeleteRepeatableInvoice'),
'confirm_delete',
'',
'no', 1);
1231 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
1232 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
1233 if (empty($reshook)) {
1234 $formconfirm .= $hookmanager->resPrint;
1235 } elseif ($reshook > 0) {
1236 $formconfirm = $hookmanager->resPrint;
1241 $author =
new User($db);
1242 $author->fetch($object->user_author);
1246 print
dol_get_fiche_head($head,
'card', $langs->trans(
"RepeatableInvoice"), -1,
'bill');
1250 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/invoicetemplate_list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1253 if ($action !=
'editref') {
1254 $morehtmlref .= $form->editfieldkey($object->ref,
'ref', $object->ref, $object, $user->hasRight(
'facture',
'creer'),
'',
'', 0, 2);
1256 $morehtmlref .= $form->editfieldval(
'',
'ref', $object->ref, $object, $user->hasRight(
'facture',
'creer'),
'string');
1259 $morehtmlref .=
'<div class="refidno">';
1264 $morehtmlref .= $object->thirdparty->getNomUrl(1,
'customer');
1266 if (isModEnabled(
'project')) {
1267 $langs->load(
"projects");
1268 $morehtmlref .=
'<br>';
1269 if ($user->hasRight(
'facture',
'creer')) {
1270 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
1271 if ($action !=
'classify') {
1272 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
1274 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
1276 if (!empty($object->fk_project)) {
1278 $proj->fetch($object->fk_project);
1279 $morehtmlref .=
' : '.$proj->getNomUrl(1);
1281 $morehtmlref .=
' - '.$proj->title;
1288 $morehtmlref .=
'</div>';
1290 $morehtmlright =
'';
1292 dol_banner_tab($object,
'ref', $linkback, 1,
'title',
'none', $morehtmlref,
'', 0,
'', $morehtmlright);
1294 print
'<div class="fichecenter">';
1295 print
'<div class="fichehalfleft">';
1296 print
'<div class="underbanner clearboth"></div>';
1298 print
'<table class="border centpercent tableforfield">';
1302 print
"<tr><td>".$langs->trans(
"InvoiceSubtype").
"</td><td>";
1303 if ($object->subtype > 0) {
1304 print $object->getSubtypeLabel(
'facture_rec');
1310 print
'<tr><td class="titlefield">'.$langs->trans(
"Author").
'</td><td>';
1311 print $author->getNomUrl(-1);
1315 print
'<tr><td>'.$langs->trans(
"AmountHT").
'</td>';
1316 print
'<td>'.price($object->total_ht,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
1320 print
'<tr><td>'.$langs->trans(
"AmountVAT").
'</td><td>'.
price($object->total_tva,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
1324 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) {
1325 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
1326 print
'<td class="nowrap">'.price($object->total_localtax1, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
1328 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) {
1329 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
1330 print
'<td class=nowrap">'.price($object->total_localtax2, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
1333 print
'<tr><td>'.$langs->trans(
"AmountTTC").
'</td><td colspan="3">'.
price($object->total_ttc,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
1339 print
'<table class="nobordernopadding centpercent"><tr><td>';
1340 print $langs->trans(
'PaymentConditionsShort');
1342 if ($action !=
'editconditions' && $user->hasRight(
'facture',
'creer')) {
1343 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>';
1345 print
'</tr></table>';
1348 if ($action ==
'editconditions') {
1349 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
1351 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'none');
1360 print
'<table class="nobordernopadding" width="100%"><tr><td>';
1361 print $langs->trans(
'PaymentMode');
1363 if ($action !=
'editmode' && $user->hasRight(
'facture',
'creer')) {
1364 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>';
1366 print
'</tr></table>';
1368 if ($action ==
'editmode') {
1369 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
1371 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'none');
1376 if (isModEnabled(
'multicurrency')) {
1380 print
'<table class="nobordernopadding" width="100%"><tr><td>';
1381 print $form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
1383 if ($usercancreate && $action !=
'editmulticurrencycode' && $object->suspended == $object::STATUS_SUSPENDED) {
1384 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>';
1386 print
'</tr></table>';
1388 $htmlname = (($usercancreate && $action ==
'editmulticurrencycode') ?
'multicurrency_code' :
'none');
1389 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code, $htmlname);
1393 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
1396 print
'<table class="nobordernopadding" width="100%"><tr><td>';
1397 print $form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
1399 if ($usercancreate && $action !=
'editmulticurrencyrate' && $object->suspended == $object::STATUS_SUSPENDED && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
1400 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>';
1402 print
'</tr></table>';
1404 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
1405 if ($action ==
'actualizemulticurrencyrate') {
1408 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx, ($usercancreate ?
'multicurrency_tx' :
'none'), $object->multicurrency_code);
1410 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
1411 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
1412 print
'<div class="inline-block"> ';
1413 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
1423 if (!empty($object->frequency) && !empty($object->date_when)) {
1424 $dateexample = $object->date_when;
1430 $substitutionarray[
'__INVOICE_PREVIOUS_MONTH__'] = $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')';
1431 $substitutionarray[
'__INVOICE_MONTH__'] = $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')';
1432 $substitutionarray[
'__INVOICE_NEXT_MONTH__'] = $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')';
1433 $substitutionarray[
'__INVOICE_PREVIOUS_MONTH_TEXT__'] = $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')';
1434 $substitutionarray[
'__INVOICE_MONTH_TEXT__'] = $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')';
1435 $substitutionarray[
'__INVOICE_NEXT_MONTH_TEXT__'] = $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')';
1436 $substitutionarray[
'__INVOICE_PREVIOUS_YEAR__'] = $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')';
1437 $substitutionarray[
'__INVOICE_YEAR__'] = $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')';
1438 $substitutionarray[
'__INVOICE_NEXT_YEAR__'] = $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')';
1440 $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').
')';
1441 $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').
')';
1442 $substitutionarray[
'__INVOICE_COUNTER_CURRENT__'] = $object->nb_gen_done;
1443 $substitutionarray[
'__INVOICE_COUNTER_MAX__'] = $object->nb_gen_max;
1445 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
1446 foreach ($substitutionarray as $key => $val) {
1447 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
1449 $htmltext .=
'</i>';
1452 print
'<tr><td class="nowrap">';
1453 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1454 print $langs->trans(
'BankAccount');
1456 if (($action !=
'editbankaccount') && $user->hasRight(
'facture',
'creer') && $object->statut ==
FactureRec::STATUS_DRAFT) {
1457 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>';
1459 print
'</tr></table>';
1461 if ($action ==
'editbankaccount') {
1462 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
1464 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
1470 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1475 print $form->editfieldkey($form->textwithpicto($langs->trans(
'NotePublic'), $htmltext, 1,
'help',
'', 0, 2,
'notepublic'),
'note_public', $object->note_public, $object, $user->hasRight(
'facture',
'creer'));
1476 print
'</td><td class="wordbreak">';
1477 print $form->editfieldval($langs->trans(
"NotePublic"),
'note_public', $object->note_public, $object, $user->hasRight(
'facture',
'creer'),
'textarea:'.ROWS_4.
':90%',
'',
null,
null,
'', 1);
1483 print $form->editfieldkey($form->textwithpicto($langs->trans(
"NotePrivate"), $htmltext, 1,
'help',
'', 0, 2,
'noteprivate'),
'note_private', $object->note_private, $object, $user->hasRight(
'facture',
'creer'));
1484 print
'</td><td class="wordbreak">';
1485 print $form->editfieldval($langs->trans(
"NotePrivate"),
'note_private', $object->note_private, $object, $user->hasRight(
'facture',
'creer'),
'textarea:'.ROWS_4.
':90%',
'',
null,
null,
'', 1);
1490 print
'<tr><td class="nowrap">';
1491 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1492 print $langs->trans(
'Model');
1494 if (($action !=
'editmodelpdf') && $user->hasRight(
'facture',
'creer') && $object->statut ==
FactureRec::STATUS_DRAFT) {
1495 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>';
1497 print
'</tr></table>';
1499 if ($action ==
'editmodelpdf') {
1500 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
1503 foreach ($models as $k => $model) {
1504 $list[] = str_replace(
':',
'|', $k).
':'.$model;
1506 $select =
'select;'.implode(
',', $list);
1507 print $form->editfieldval($langs->trans(
"Model"),
'modelpdf', $object->model_pdf, $object, $user->hasRight(
'facture',
'creer'), $select);
1509 print $object->model_pdf;
1521 print
'<div class="fichehalfright">';
1522 print
'<div class="underbanner clearboth"></div>';
1528 $title = $langs->trans(
"Recurrence");
1530 print
'<table class="border centpercent tableforfield">';
1532 print
'<tr><td colspan="2">'.img_picto(
'',
'recurring',
'class="pictofixedwidth"').$title.
'</td></tr>';
1535 print
'<tr><td style="width: 50%">';
1536 print
'<table class="nobordernopadding" width="100%"><tr><td>';
1537 print $langs->trans(
'Frequency');
1539 if ($action !=
'editfrequency' && $user->hasRight(
'facture',
'creer')) {
1540 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>';
1542 print
'</tr></table>';
1544 if ($action ==
'editfrequency') {
1545 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'">';
1546 print
'<input type="hidden" name="action" value="setfrequency">';
1547 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1548 print
'<table class="nobordernopadding">';
1550 print
"<input type='text' name='frequency' value='".$object->frequency.
"' size='5' /> ";
1551 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'));
1553 print
'<td class="left"><input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans(
"Modify").
'"></td>';
1554 print
'</tr></table></form>';
1556 if ($object->frequency > 0) {
1557 print $langs->trans(
'FrequencyPer_'.$object->unit_frequency, $object->frequency);
1559 print
'<span class="opacitymedium">'.$langs->trans(
"NotARecurringInvoiceTemplate").
'</span>';
1566 if ($action ==
'date_when' || $object->frequency > 0) {
1567 print $form->editfieldkey($langs->trans(
"NextDateToExecution"),
'date_when', $object->date_when, $object, $user->hasRight(
'facture',
'creer'),
'day');
1569 print $langs->trans(
"NextDateToExecution");
1572 if ($action ==
'date_when' || $object->frequency > 0) {
1573 print $form->editfieldval($langs->trans(
"NextDateToExecution"),
'date_when', $object->date_when, $object, $user->hasRight(
'facture',
'creer'),
'day', $object->date_when,
null,
'',
'', 0,
'strikeIfMaxNbGenReached');
1576 if (!$object->isMaxNbGenReached()) {
1577 if (!$object->suspended && $action !=
'editdate_when' && $object->frequency > 0 && $object->date_when && $object->date_when < $now) {
1581 print
img_info($langs->trans(
"MaxNumberOfGenerationReached"));
1588 if ($action ==
'nb_gen_max' || $object->frequency > 0) {
1589 print $form->editfieldkey($langs->trans(
"MaxPeriodNumber"),
'nb_gen_max', $object->nb_gen_max, $object, $user->hasRight(
'facture',
'creer'));
1591 print $langs->trans(
"MaxPeriodNumber");
1594 if ($action ==
'nb_gen_max' || $object->frequency > 0) {
1595 print $form->editfieldval($langs->trans(
"MaxPeriodNumber"),
'nb_gen_max', $object->nb_gen_max ? $object->nb_gen_max :
'', $object, $user->hasRight(
'facture',
'creer'));
1604 if ($action ==
'auto_validate' || $object->frequency > 0) {
1605 print $form->editfieldkey($langs->trans(
"StatusOfAutoGeneratedInvoices"),
'auto_validate', $object->auto_validate, $object, $user->hasRight(
'facture',
'creer'));
1607 print $langs->trans(
"StatusOfAutoGeneratedInvoices");
1610 $select =
'select;0:'.$langs->trans(
'BillStatusDraft').
',1:'.$langs->trans(
'BillStatusValidated');
1611 if ($action ==
'auto_validate' || $object->frequency > 0) {
1612 print $form->editfieldval($langs->trans(
"StatusOfAutoGeneratedInvoices"),
'auto_validate', $object->auto_validate, $object, $user->hasRight(
'facture',
'creer'), $select);
1619 if ($action ==
'generate_pdf' || $object->frequency > 0) {
1620 print $form->editfieldkey($langs->trans(
"StatusOfGeneratedDocuments"),
'generate_pdf', $object->generate_pdf, $object, $user->hasRight(
'facture',
'creer'));
1622 print $langs->trans(
"StatusOfGeneratedDocuments");
1626 $select =
'select;0:'.$langs->trans(
'DoNotGenerateDoc').
',1:'.$langs->trans(
'AutogenerateDoc');
1627 if ($action ==
'generate_pdf' || $object->frequency > 0) {
1628 print $form->editfieldval($langs->trans(
"StatusOfGeneratedDocuments"),
'generate_pdf', $object->generate_pdf, $object, $user->hasRight(
'facture',
'creer'), $select);
1633 print
'<input type="hidden" name="generate_pdf" value="1">';
1639 if ($object->frequency > 0) {
1642 if (!isModEnabled(
'cron')) {
1643 print
info_admin($langs->trans(
"EnableAndSetupModuleCron", $langs->transnoentitiesnoconv(
"Module2300Name")));
1646 print
'<div class="underbanner clearboth"></div>';
1647 print
'<table class="border centpercent tableforfield">';
1650 print
'<tr><td style="width: 50%">'.$langs->trans(
"NbOfGenerationDone").
'</td>';
1652 print $object->nb_gen_done ? $object->nb_gen_done :
'0';
1658 print $langs->trans(
"DateLastGeneration");
1672 print
'<div class="clearboth"></div><br>';
1676 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'#add' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">';
1677 print
'<input type="hidden" name="token" value="' . newToken().
'">';
1678 print
'<input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">';
1679 print
'<input type="hidden" name="mode" value="">';
1680 print
'<input type="hidden" name="id" value="' . $object->id.
'">';
1681 print
'<input type="hidden" name="page_y" value="">';
1683 if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
1684 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
1687 print
'<div class="div-table-responsive-no-min">';
1688 print
'<table id="tablelines" class="noborder noshadow centpercent">';
1690 if (!empty($object->lines)) {
1691 $canchangeproduct = 1;
1692 $object->printObjectLines($action, $mysoc, $object->thirdparty, $lineid, 0);
1696 if ($object->statut == $object::STATUS_DRAFT && $user->hasRight(
'facture',
'creer') && $action !=
'valid' && $action !=
'editline') {
1697 if ($action !=
'editline') {
1700 $parameters = array();
1701 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
1705 if (empty($reshook)) {
1706 $object->formAddObjectLine(0, $mysoc, $object->thirdparty);
1722 print
'<div class="tabsAction">';
1724 $parameters = array();
1725 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
1726 if (empty($reshook)) {
1729 'class' =>
'classfortooltip',
1732 if (empty($object->suspended)) {
1733 if ($user->hasRight(
'facture',
'creer')) {
1734 if (!empty($object->frequency) && $object->nb_gen_max > 0 && ($object->nb_gen_done >= $object->nb_gen_max)) {
1735 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' .
dol_escape_htmltag($langs->trans(
"MaxGenerationReached")) .
'">' . $langs->trans(
"CreateBill") .
'</a></div>';
1737 if (empty($object->frequency) || $object->date_when <= $nowlasthour) {
1738 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>';
1740 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' .
dol_escape_htmltag($langs->trans(
"DateIsNotEnough")) .
'">' . $langs->trans(
"CreateBill") .
'</a></div>';
1744 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">' . $langs->trans(
"CreateBill") .
'</a></div>';
1748 if ($user->hasRight(
'facture',
'creer')) {
1749 if (empty($object->suspended)) {
1750 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>';
1752 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>';
1757 print
dolGetButtonAction($langs->trans(
"Delete"),
'',
'delete', $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'&action=delete&token=' . newToken(),
'delete', $user->hasRight(
'facture',
'supprimer'));
1763 print
'<div class="fichecenter"><div class="fichehalfleft">';
1764 print
'<a name="builddoc"></a>';
1768 $linktoelem = $form->showLinkToObjectBlock($object,
null, array(
'invoice'));
1770 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1774 print
'<div class="fichehalfright">';
1779 $morehtmlcenter =
'';
1782 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
1784 $somethingshown =
$formactions->showactions($object, $object->element, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1,
'', $MAXEVENT,
'', $morehtmlcenter);
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif( $action=='specimen') elseif($action=='setmodel') elseif( $action=='del') elseif($action=='setdoc') $formactions
View.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
const STATUS_DRAFT
Draft status.
Class to manage a WYSIWYG editor.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_STANDARD
Standard invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage invoice lines of templates.
Class to manage invoice templates.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
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_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...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
img_info($titlealt='default')
Show info logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
invoice_rec_prepare_head($object)
Return array head with list of tabs to view object informations.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.