44require
'../../main.inc.php';
45require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
55require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
56require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
57require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
58if (isModEnabled(
'order')) {
59 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
61if (isModEnabled(
'project')) {
62 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
63 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
65require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
67if (isModEnabled(
'variants')) {
68 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
70if (isModEnabled(
'accounting')) {
71 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
84$langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
85if (isModEnabled(
'incoterm')) {
86 $langs->load(
'incoterm');
88if (isModEnabled(
'margin')) {
89 $langs->load(
'margins');
96$action =
GETPOST(
'action',
'aZ09');
97$confirm =
GETPOST(
'confirm',
'alpha');
98$cancel =
GETPOST(
'cancel',
'alpha');
99$backtopage =
GETPOST(
'backtopage',
'alpha');
100$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
103$search_ref =
GETPOST(
'sf_ref',
'alpha') ?
GETPOST(
'sf_ref',
'alpha') :
GETPOST(
'search_ref',
'alpha');
104$search_societe =
GETPOST(
'search_societe',
'alpha');
105$search_montant_ht =
GETPOST(
'search_montant_ht',
'alpha');
106$search_montant_ttc =
GETPOST(
'search_montant_ttc',
'alpha');
107$origin =
GETPOST(
'origin',
'alpha');
114$selectedLines =
GETPOST(
'toselect',
'array');
130$extrafields->fetch_name_optionals_label(
$object->table_element);
133$total_global_ttc = 0;
134$displayWarranty =
false;
135$statusreplacement = 0;
137$price_base_type =
'';
138$array_options = array();
141if ($id > 0 || !empty($ref)) {
142 if ($action !=
'add') {
144 $fetch_situation =
false;
146 $fetch_situation =
true;
148 $ret =
$object->fetch($id, $ref,
'', 0, $fetch_situation);
149 if ($ret > 0 && isset(
$object->fk_project)) {
150 $ret =
$object->fetchProject();
156$hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
159$usercanread = $user->hasRight(
"facture",
"lire");
160$usercancreate = $user->hasRight(
"facture",
"creer");
161$usercanissuepayment = $user->hasRight(
"facture",
"paiement");
162$usercandelete = $user->hasRight(
"facture",
"supprimer") || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
163$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
166$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'validate')));
168$usercanreopen = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'reopen')));
170 $usercanreopen =
false;
172$usercanunvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'unvalidate')));
173$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
176$usercancreatemargin = $user->hasRight(
'margins',
'creer');
177$usercanreadallmargin = $user->hasRight(
'margins',
'liretous');
178$usercancreatewithdrarequest = $user->hasRight(
'prelevement',
'bons',
'creer');
180$permissionnote = $usercancreate;
181$permissiondellink = $usercancreate;
182$permissiontoedit = $usercancreate;
183$permissiontoadd = $usercancreate;
186$retainedWarrantyInvoiceAvailableType = array();
188 $retainedWarrantyInvoiceAvailableType = explode(
'+',
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY'));
193 $socid = $user->socid;
205$parameters = array(
'socid' => $socid);
206$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
211if (empty($reshook)) {
212 $backurlforlist = DOL_URL_ROOT.
'/compta/facture/list.php';
214 if (empty($backtopage) || ($cancel && empty($id))) {
215 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
216 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
217 $backtopage = $backurlforlist;
219 $backtopage = DOL_URL_ROOT.
'/compta/facture/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
225 if (!empty($backtopageforcancel)) {
226 header(
"Location: ".$backtopageforcancel);
228 } elseif (!empty($backtopage)) {
229 header(
"Location: ".$backtopage);
235 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
237 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
239 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
242 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
244 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'IdThirdParty')),
null,
'errors');
247 '@phan-var-force Facture $objectutil';
250 $objectutil->socid = $socid;
251 $result = $objectutil->createFromClone($user, $id);
253 $warningMsgLineList = array();
255 foreach ($objectutil->lines as $line) {
256 if (!is_object($line->product)) {
257 $line->fetch_product();
259 if (is_object($line->product) && $line->product->id > 0) {
260 if (empty($line->product->status)) {
261 $warningMsgLineList[$line->id] = $langs->trans(
'WarningLineProductNotToSell', $line->product->ref);
265 if (!empty($warningMsgLineList)) {
269 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?facid=' . $result);
272 $langs->load(
"errors");
277 } elseif ($action ==
'reopen' && $usercanreopen) {
281 $result =
$object->setUnpaid($user);
283 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
289 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
294 $idwarehouse =
GETPOST(
'idwarehouse');
296 $qualified_for_stock_change = 0;
298 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
300 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
303 $isErasable =
$object->is_erasable();
305 if (($usercandelete && $isErasable > 0)
306 || ($usercancreate && $isErasable == 1)) {
307 $result =
$object->delete($user, 0, $idwarehouse);
309 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
316 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
326 $outputlangs = $langs;
332 $newlang =
$object->thirdparty->default_lang;
334 if (!empty($newlang)) {
336 $outputlangs->setDefaultLang($newlang);
337 $outputlangs->load(
'products');
341 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
344 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
351 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
354 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
355 $discount->unlink_invoice();
356 } elseif ($action ==
'valid' && $usercancreate) {
360 if ((preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) &&
367 $last_of_type =
$object->willBeLastOfSameType(
true);
368 if (empty(
$object->date_validation) && !$last_of_type[0]) {
378 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
387 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
396 $array_of_total_ht_per_vat_rate = array();
397 $array_of_total_ht_devise_per_vat_rate = array();
398 foreach (
$object->lines as $line) {
400 $vat_src_code_for_line =
'';
401 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
402 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
404 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
405 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
407 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
408 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
412 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
413 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
414 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
416 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
417 if (
$object->type == $object::TYPE_DEPOSIT) {
418 $langs->load(
"errors");
420 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
424 $tmpvatratetoshow = explode(
'_', $vatrate);
425 $tmpvatratetoshow[0] = round((
float) $tmpvatratetoshow[0], 2);
427 if ($tmpvatratetoshow[0] != 0) {
428 $langs->load(
"errors");
429 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", $tmpvatratetoshow[0]),
null,
'errors');
437 } elseif ($action ==
'classin' && $usercancreate) {
440 } elseif ($action ==
'setmode' && $usercancreate) {
446 } elseif ($action ==
'setretainedwarrantyconditions' && $usercancreate) {
448 $object->retained_warranty_fk_cond_reglement = 0;
449 $result =
$object->setRetainedWarrantyPaymentTerms(
GETPOSTINT(
'retained_warranty_fk_cond_reglement'));
454 $old_rw_date_lim_reglement =
$object->retained_warranty_date_limit;
455 $new_rw_date_lim_reglement =
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
456 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
457 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
462 $result =
$object->update($user);
466 } elseif ($action ==
'setretainedwarranty' && $usercancreate) {
472 } elseif ($action ==
'setretainedwarrantydatelimit' && $usercancreate) {
474 $result =
$object->setRetainedWarrantyDateLimit(
GETPOSTFLOAT(
'retained_warranty_date_limit'));
478 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
479 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
480 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
482 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
484 $old_date_lim_reglement =
$object->date_lim_reglement;
486 if (empty($newdate)) {
487 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
488 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.
$id.
'&action=editinvoicedate&token='.
newToken());
493 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
495 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
500 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
501 if ($new_date_lim_reglement) {
502 $object->date_lim_reglement = $new_date_lim_reglement;
507 $result =
$object->update($user);
510 $action =
'editinvoicedate';
512 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
517 $object->date_pointoftax = $date_pointoftax;
518 $result =
$object->update($user);
522 } elseif ($action ==
'setconditions' && $usercancreate) {
524 $object->cond_reglement_code = 0;
525 $object->cond_reglement_id = 0;
538 $old_date_lim_reglement =
$object->date_lim_reglement;
539 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
540 if ($new_date_lim_reglement) {
541 $object->date_lim_reglement = $new_date_lim_reglement;
546 $result =
$object->update($user);
558 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
562 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
563 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
565 $result =
$object->update($user);
569 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
572 $result =
$object->update($user);
579 $outputlangs = $langs;
582 $newlang =
GETPOST(
'lang_id',
'aZ09');
585 $newlang =
$object->thirdparty->default_lang;
587 if (!empty($newlang)) {
589 $outputlangs->setDefaultLang($newlang);
590 $outputlangs->load(
'products');
595 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
601 } elseif ($action ==
'set_incoterms' && isModEnabled(
'incoterm') && $usercancreate) {
603 } elseif ($action ==
'setbankaccount' && $usercancreate) {
605 } elseif ($action ==
'setremisepercent' && $usercancreate) {
608 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
626 if (
GETPOSTINT(
"remise_id_for_payment") > 0) {
627 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
629 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
633 $remaintopay =
$object->getRemainToPay(0);
637 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
641 $result = $discount->link_to_invoice(0, $id);
649 $newremaintopay =
$object->getRemainToPay(0);
650 if ($newremaintopay == 0) {
663 $outputlangs = $langs;
666 $newlang =
GETPOST(
'lang_id',
'aZ09');
670 $newlang =
$object->thirdparty->default_lang;
672 if (!empty($newlang)) {
674 $outputlangs->setDefaultLang($newlang);
678 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
683 } elseif ($action ==
'setref' && $usercancreate) {
685 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', 0,
'',
'', $user,
'BILL_MODIFY');
686 } elseif ($action ==
'setref_client' && $usercancreate) {
689 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
698 $qualified_for_stock_change = 0;
700 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
702 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
705 if ($qualified_for_stock_change) {
706 if (!$idwarehouse || $idwarehouse == - 1) {
708 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
715 $result =
$object->validate($user,
'', $idwarehouse);
719 $outputlangs = $langs;
722 $newlang =
GETPOST(
'lang_id',
'aZ09');
725 $newlang =
$object->thirdparty->default_lang;
727 if (!empty($newlang)) {
729 $outputlangs->setDefaultLang($newlang);
730 $outputlangs->load(
'products');
736 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
749 } elseif ($action ==
'confirm_modif' && $usercanunvalidate) {
758 $qualified_for_stock_change = 0;
760 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
762 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
765 if ($qualified_for_stock_change) {
766 if (!$idwarehouse || $idwarehouse == - 1) {
768 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
777 $sql =
'SELECT pf.amount';
778 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf';
779 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
781 $result = $db->query($sql);
784 $num = $db->num_rows($result);
787 $objp = $db->fetch_object($result);
788 $totalpaid += $objp->amount;
795 $resteapayer =
$object->total_ttc - $totalpaid;
798 $ventilExportCompta =
$object->getVentilExportCompta();
801 if ($ventilExportCompta == 0) {
803 $result =
$object->setDraft($user, $idwarehouse);
810 $outputlangs = $langs;
813 $newlang =
GETPOST(
'lang_id',
'aZ09');
816 $newlang =
$object->thirdparty->default_lang;
818 if (!empty($newlang)) {
820 $outputlangs->setDefaultLang($newlang);
821 $outputlangs->load(
'products');
826 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
831 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
834 $result =
$object->setPaid($user);
838 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
841 $close_code =
GETPOST(
"close_code",
'restricthtml');
842 $close_note =
GETPOST(
"close_note",
'restricthtml');
844 $result =
$object->setPaid($user, $close_code, $close_note);
849 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
851 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
854 $close_code =
GETPOST(
"close_code",
'restricthtml');
855 $close_note =
GETPOST(
"close_note",
'restricthtml');
857 $result =
$object->setCanceled($user, $close_code, $close_note);
862 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
864 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
872 $result = $discountcheck->fetch(0,
$object->id);
885 $amount_ht = $amount_tva = $amount_ttc = array();
886 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
890 foreach (
$object->lines as $line) {
891 if ($line->product_type < 9 && $line->total_ht != 0) {
892 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
894 $amount_ht[$keyforvatrate] += $line->total_ht;
895 $amount_tva[$keyforvatrate] += $line->total_tva;
896 $amount_ttc[$keyforvatrate] += $line->total_ttc;
897 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
898 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
899 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
903 '@phan-var-force array<string,float> $amount_ht
904 @phan-var-force array<string,float> $amount_tva
905 @phan-var-force array<string,float> $amount_ttc
906 @phan-var-force array<string,float> $multicurrency_amount_ht
907 @phan-var-force array<string,float> $multicurrency_amount_tva
908 @phan-var-force array<string,float> $multicurrency_amount_ttc';
912 $alreadypaid =
$object->getSommePaiement();
913 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
914 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
915 foreach ($amount_ht as $vatrate => $val) {
916 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
917 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
918 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
919 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
920 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
921 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
930 $discount->description =
'(CREDIT_NOTE)';
932 $discount->description =
'(DEPOSIT)';
934 $discount->description =
'(EXCESS RECEIVED)';
936 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
938 $discount->fk_soc =
$object->socid;
939 $discount->socid =
$object->socid;
940 $discount->fk_facture_source =
$object->id;
948 $sql =
'SELECT SUM(pf.amount) as total_paiements';
949 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
950 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
951 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
952 $sql .=
' AND pf.fk_paiement = p.rowid';
953 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
954 $resql = $db->query($sql);
959 $res = $db->fetch_object($resql);
960 $total_paiements = $res->total_paiements;
963 $total_creditnote_and_deposit = 0;
964 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
965 $sql .=
" re.description, re.fk_facture_source";
966 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
967 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
968 $resql = $db->query($sql);
969 if (!empty($resql)) {
970 while ($obj = $db->fetch_object($resql)) {
971 $total_creditnote_and_deposit += $obj->amount_ttc;
977 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
978 $discount->amount_tva = 0;
979 $discount->tva_tx = 0;
980 $discount->vat_src_code =
'';
982 $result = $discount->create($user);
988 foreach ($amount_ht as $tva_tx => $xxx) {
989 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
990 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
991 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
992 $discount->multicurrency_amount_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
993 $discount->multicurrency_amount_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
994 $discount->multicurrency_amount_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
999 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
1000 $vat_src_code = $reg[1];
1001 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
1004 $discount->tva_tx = abs((
float) $tva_tx);
1005 $discount->vat_src_code = $vat_src_code;
1007 $result = $discount->create($user);
1015 if (empty($error)) {
1018 $result =
$object->setPaid($user);
1033 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
1038 $result = $paiement->fetch(
GETPOSTINT(
'paiement_id'));
1040 $result = $paiement->delete($user);
1042 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1050 } elseif ($action ==
'add' && $usercancreate) {
1057 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1064 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
1074 if (empty($dateinvoice)) {
1076 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1086 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1096 $object->date_pointoftax = $date_pointoftax;
1097 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1098 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1109 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1110 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1127 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1129 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1133 if (empty($dateinvoice)) {
1135 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1145 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1150 if (!empty($originentity)) {
1151 $object->entity = $originentity;
1157 $object->date_pointoftax = $date_pointoftax;
1158 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1159 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1164 $object->cond_reglement_id = 0;
1170 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1171 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1175 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1178 $facture_source =
new Facture($db);
1179 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1181 $object->situation_counter = $facture_source->situation_counter;
1182 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1183 $facture_source->fetchPreviousNextSituationInvoice();
1193 if (
$object->copy_linked_contact($facture_source,
'internal') < 0) {
1195 } elseif ($facture_source->socid ==
$object->socid) {
1197 if (
$object->copy_linked_contact($facture_source,
'external') < 0) {
1208 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1209 if (!empty($facture_source->lines)) {
1210 $fk_parent_line = 0;
1212 foreach ($facture_source->lines as $line) {
1214 if (method_exists($line,
'fetch_optionals')) {
1216 $line->fetch_optionals();
1220 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1221 $fk_parent_line = 0;
1226 $source_fk_prev_id = $line->fk_prev_id;
1227 $line->fk_prev_id = $line->id;
1229 if (!empty($facture_source->tab_previous_situation_invoice)) {
1232 $tab_jumped_credit_notes = array();
1233 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1234 $searchPreviousInvoice =
true;
1235 while ($searchPreviousInvoice) {
1236 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1237 $searchPreviousInvoice =
false;
1241 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1247 $maxPrevSituationPercent = 0;
1248 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1249 if ($prevLine->id == $source_fk_prev_id) {
1250 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1253 $line->total_ht -= $prevLine->total_ht;
1254 $line->total_tva -= $prevLine->total_tva;
1255 $line->total_ttc -= $prevLine->total_ttc;
1256 $line->total_localtax1 -= $prevLine->total_localtax1;
1257 $line->total_localtax2 -= $prevLine->total_localtax2;
1259 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1260 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1261 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1262 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1267 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1272 $maxPrevSituationPercent = 0;
1273 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1274 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1275 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1276 $maxPrevSituationPercent = $prevLine->situation_percent;
1278 $line->total_ht -= $prevLine->total_ht;
1279 $line->total_tva -= $prevLine->total_tva;
1280 $line->total_ttc -= $prevLine->total_ttc;
1281 $line->total_localtax1 -= $prevLine->total_localtax1;
1282 $line->total_localtax2 -= $prevLine->total_localtax2;
1284 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1285 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1286 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1287 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1293 $line->situation_percent += $maxPrevSituationPercent;
1299 $line->fk_facture =
$object->id;
1300 $line->fk_parent_line = $fk_parent_line;
1302 $line->subprice = -$line->subprice;
1304 $line->total_ht = -$line->total_ht;
1305 $line->total_tva = -$line->total_tva;
1306 $line->total_ttc = -$line->total_ttc;
1307 $line->total_localtax1 = -$line->total_localtax1;
1308 $line->total_localtax2 = -$line->total_localtax2;
1310 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1311 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1312 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1313 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1315 $line->context[
'createcreditnotefrominvoice'] = 1;
1316 $result = $line->insert(0, 1);
1321 if ($result > 0 && $line->product_type == 9) {
1322 $fk_parent_line = $result;
1330 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1331 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1332 $totalpaid = $facture_source->getSommePaiement();
1333 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1334 $totaldeposits = $facture_source->getSumDepositsUsed();
1335 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1337 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1338 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1341 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1346 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1347 $tva_tx = (float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY');
1352 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC');
1357 if (!empty(
$object->fk_facture_source) &&
$id > 0) {
1358 $facture_source->fetch(
$object->fk_facture_source);
1359 $facture_source->fetchObjectLinked();
1361 if (!empty($facture_source->linkedObjectsIds)) {
1362 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1363 $object->add_object_linked($sourcetype, current($TIds));
1372 if (empty($dateinvoice)) {
1374 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1385 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1395 $object->date_pointoftax = $date_pointoftax;
1396 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1397 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1409 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1410 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1422 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1423 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1424 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1428 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1432 if (empty($dateinvoice)) {
1434 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1444 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1445 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1450 if ($typeamount && !empty($origin) && !empty($originid)) {
1451 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1452 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1456 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1457 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1461 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1462 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1472 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1482 $object->date_pointoftax = $date_pointoftax;
1483 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1484 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1496 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1497 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1501 $object->situation_counter = 1;
1506 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1508 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1510 $object->retained_warranty = 0;
1511 $object->retained_warranty_fk_cond_reglement = 0;
1514 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1515 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1518 $object->retained_warranty_date_limit = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit :
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
1523 if (!empty($origin) && !empty($originid)) {
1526 $element = $subelement = $origin;
1527 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1528 $element = $regs[1];
1529 $subelement = $regs[2];
1533 if ($element ==
'order') {
1534 $element = $subelement =
'commande';
1536 if ($element ==
'propal') {
1537 $element =
'comm/propal';
1538 $subelement =
'propal';
1540 if ($element ==
'contract') {
1541 $element = $subelement =
'contrat';
1543 if ($element ==
'inter') {
1544 $element = $subelement =
'fichinter';
1546 if ($element ==
'shipping') {
1547 $element = $subelement =
'expedition';
1551 $object->origin_type = $origin;
1552 $object->origin_id = $originid;
1557 if (
$object->origin ==
'shipping') {
1558 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1560 $exp->fetch(
$object->origin_id);
1561 $exp->fetchObjectLinked();
1562 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1563 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1564 $object->linked_objects[
'commande'] = $value;
1570 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
1578 $classname = ucfirst($subelement);
1579 $srcobject =
new $classname($db);
1580 '@phan-var-force CommonObject $srcobject';
1582 dol_syslog(
"Try to find source object origin=".
$object->origin.
" originid=".
$object->origin_id.
" to add lines or deposit lines");
1583 $result = $srcobject->fetch(
$object->origin_id);
1589 $amountdeposit = array();
1592 if ($typeamount ==
'amount') {
1593 $amount = (float) $valuedeposit;
1595 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1598 $TTotalByTva = array();
1599 foreach ($srcobject->lines as &$line) {
1600 if (empty($line->qty)) {
1603 if (!empty($line->special_code)) {
1606 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1608 '@phan-var-force array<string,float> $TTotalByTva';
1610 $amount_ttc_diff = 0.;
1611 foreach ($TTotalByTva as $tva => &$total) {
1612 $coef = $total / $srcobject->total_ttc;
1613 $am = $amount * $coef;
1614 $amount_ttc_diff += $am;
1615 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1618 if ($typeamount ==
'amount') {
1619 $amountdeposit[0] = $valuedeposit;
1620 } elseif ($typeamount ==
'variable') {
1623 $lines = $srcobject->lines;
1624 $numlines = count($lines);
1625 for ($i = 0; $i < $numlines; $i++) {
1627 if (empty($lines[$i]->qty)) {
1630 if (!empty($lines[$i]->special_code)) {
1634 $totalamount += $lines[$i]->total_ht;
1635 $tva_tx = $lines[$i]->tva_tx;
1636 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1640 if ($totalamount == 0) {
1641 $amountdeposit[0] = 0;
1649 $amount_ttc_diff = $amountdeposit[0];
1652 foreach ($amountdeposit as $tva => $amount) {
1653 if (empty($amount)) {
1658 'amount' =>
'FixAmount',
1659 'variable' =>
'VarAmount'
1661 $descline =
'(DEPOSIT)';
1663 if ($typeamount ==
'amount') {
1664 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1665 } elseif ($typeamount ==
'variable') {
1666 $descline .=
' ('.$valuedeposit.
'%)';
1669 $descline .=
' - '.$srcobject->ref;
1682 $i >= 0 ? $lines[$i]->info_bits : 0,
1688 $i >= 0 ? $lines[$i]->special_code : 0,
1701 (!empty(
$conf->global->MAIN_DEPOSIT_MULTI_TVA) ? 0 : 1)
1705 $diff =
$object->total_ttc - $amount_ttc_diff;
1709 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1710 $object->updateline(
$object->lines[0]->id,
$object->lines[0]->desc, $subprice_diff,
$object->lines[0]->qty,
$object->lines[0]->remise_percent,
$object->lines[0]->date_start,
$object->lines[0]->date_end,
$object->lines[0]->tva_tx, 0, 0,
'HT',
$object->lines[0]->info_bits,
$object->lines[0]->product_type, 0, 0, 0,
$object->lines[0]->pa_ht,
$object->lines[0]->label, 0, array(), 100);
1719 $lines = $srcobject->lines;
1720 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1721 $srcobject->fetch_lines();
1722 $lines = $srcobject->lines;
1727 if (is_array($lines)) {
1728 foreach ($lines as $line) {
1730 $line->qty =
price2num((
float) $line->qty * (
float) $valuestandardinvoice / 100,
'MS');
1736 if (is_array($lines)) {
1737 foreach ($lines as $line) {
1739 $line->qty =
price2num((
float) $line->qty * (
float) $valuedeposit / 100,
'MS');
1744 $fk_parent_line = 0;
1745 $num = count($lines);
1747 for ($i = 0; $i < $num; $i++) {
1748 if (!in_array($lines[$i]->
id, $selectedLines)) {
1753 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
1757 if (!isset(
$conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1758 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1760 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
1764 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1765 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1767 if (
$object->situation_counter == 1) {
1768 $lines[$i]->situation_percent = 0;
1771 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
1774 $desc = $label ? $label : $langs->trans(
'Discount');
1778 $discount->fk_soc =
$object->socid;
1779 $discount->socid =
$object->socid;
1780 $discount->amount_ht = abs($lines[$i]->total_ht);
1781 $discount->amount_tva = abs($lines[$i]->total_tva);
1782 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1783 $discount->tva_tx = $lines[$i]->tva_tx;
1784 $discount->fk_user = $user->id;
1785 $discount->description = $desc;
1786 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1787 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1788 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1789 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1791 $discountid = $discount->create($user);
1792 if ($discountid > 0) {
1793 $result =
$object->insert_discount($discountid);
1805 $date_start =
false;
1806 if (isset($lines[$i]->date_debut_prevue)) {
1807 $date_start = $lines[$i]->date_debut_prevue;
1809 if (isset($lines[$i]->date_debut_reel)) {
1810 $date_start = $lines[$i]->date_debut_reel;
1812 if (isset($lines[$i]->date_start)) {
1813 $date_start = $lines[$i]->date_start;
1818 if (isset($lines[$i]->date_fin_prevue)) {
1819 $date_end = $lines[$i]->date_fin_prevue;
1821 if (isset($lines[$i]->date_fin_reel)) {
1822 $date_end = $lines[$i]->date_fin_reel;
1824 if (isset($lines[$i]->date_end)) {
1825 $date_end = $lines[$i]->date_end;
1829 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1830 $fk_parent_line = 0;
1833 $array_options = array();
1835 if (method_exists($lines[$i],
'fetch_optionals')) {
1836 $lines[$i]->fetch_optionals();
1837 $array_options = $lines[$i]->array_options;
1840 $tva_tx = $lines[$i]->tva_tx;
1841 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
1842 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1852 $lines[$i]->subprice,
1857 $lines[$i]->fk_product,
1858 $lines[$i]->remise_percent,
1862 $lines[$i]->info_bits,
1863 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except : null,
1868 $lines[$i]->special_code,
1872 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice : null,
1876 $lines[$i]->situation_percent ?? 100,
1877 $lines[$i]->fk_prev_id ?? 0,
1878 $lines[$i]->fk_unit,
1893 if ($result > 0 && $lines[$i]->product_type == 9) {
1894 $fk_parent_line = $result;
1904 $object->update_price(1,
'auto', 0, $mysoc);
1932 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id,
'objFrom' => $srcobject);
1933 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
1946 for ($i = 1; $i <= $NBLINES; $i++) {
1952 $result =
$object->addline($product->description, $product->price,
price2num(
GETPOST(
'qty'.$i),
'MS'), $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx,
GETPOSTINT(
'idprod'.$i),
price2num(
GETPOST(
'remise_percent'.$i),
'', 2), $startday, $endday, 0, 0, 0, $product->price_base_type, $product->price_ttc, $product->type, -1, 0,
'', 0, 0, 0, 0,
'', array(), 100, 0, $product->fk_unit, 0,
'', 1);
1956 $object->update_price(1,
'auto', 0, $mysoc);
1963 if (empty($dateinvoice)) {
1965 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
1975 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
1985 if (!empty($origin) && !empty($originid)) {
1986 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1989 $object->origin_type = $origin;
1990 $object->origin_id = $originid;
1994 $retained_warranty =
GETPOSTINT(
'retained_warranty');
1995 if (
price2num($retained_warranty) > 0) {
1999 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
2000 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
2003 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
2004 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
2005 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
2007 $object->retained_warranty_date_limit = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit :
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
2010 foreach (
$object->lines as $i => &$line) {
2011 $line->fk_prev_id = $line->id;
2012 $line->fetch_optionals();
2014 $line->situation_percent = $line->getAllPrevProgress(
$object->id);
2016 $line->situation_percent = $line->get_prev_progress(
$object->id);
2020 $tabprice =
calcul_price_total($line->qty, $line->subprice, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 0,
'HT', 0, $line->product_type, $mysoc, array(), $line->situation_percent);
2021 $line->total_ht = (float) $tabprice[0];
2022 $line->total_tva = (float) $tabprice[1];
2023 $line->total_ttc = (float) $tabprice[2];
2024 $line->total_localtax1 = (float) $tabprice[9];
2025 $line->total_localtax2 = (float) $tabprice[10];
2026 $line->multicurrency_total_ht = (float) $tabprice[16];
2027 $line->multicurrency_total_tva = (float) $tabprice[17];
2028 $line->multicurrency_total_ttc = (float) $tabprice[18];
2031 if ($line->fk_remise_except) {
2033 $result = $discount->fetch($line->fk_remise_except);
2036 if ($discount->fk_facture_line > 0) {
2037 $line->fk_remise_except = 0;
2046 $object->date_pointoftax = $date_pointoftax;
2047 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2063 $object->situation_counter += 1;
2069 $nextSituationInvoice =
new Facture($db);
2070 $nextSituationInvoice->fetch($id);
2073 $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
2074 $ret = $extrafields->setOptionalsFromPost(
null, $nextSituationInvoice);
2076 $nextSituationInvoice->insertExtraFields();
2080 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id);
2081 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $nextSituationInvoice, $action);
2092 if ($id > 0 && !$error) {
2097 $outputlangs = $langs;
2100 $newlang =
GETPOST(
'lang_id',
'aZ09');
2103 $newlang =
$object->thirdparty->default_lang;
2105 if (!empty($newlang)) {
2107 $outputlangs->setDefaultLang($newlang);
2108 $outputlangs->load(
'products');
2113 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2119 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2124 $_GET[
"origin"] = $_POST[
"origin"];
2125 $_GET[
"originid"] = $_POST[
"originid"];
2128 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2132 foreach (
$object->lines as $line) {
2133 if ($line->product_type == 1) {
2134 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $alldate_start, $alldate_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx,
'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice);
2137 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2139 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2140 $vat_rate = str_replace(
'*',
'', $vat_rate);
2143 foreach (
$object->lines as $line) {
2144 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $vat_rate, $localtax1_rate, $localtax2_rate,
'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice);
2146 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2148 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2149 $remise_percent = str_replace(
'*',
'', $remise_percent);
2150 foreach (
$object->lines as $line) {
2151 $tvatx = $line->tva_tx;
2152 if (!empty($line->vat_src_code)) {
2153 $tvatx .=
' ('.$line->vat_src_code.
')';
2155 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $remise_percent, $line->date_start, $line->date_end, $tvatx, $line->localtax1_tx, $line->localtax2_tx,
'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice);
2157 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && $usercancreate) {
2158 $langs->load(
'errors');
2163 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
2166 $price_ht_devise =
'';
2168 $price_ttc_devise =
'';
2170 $price_min_ttc =
'';
2172 if (
GETPOST(
'price_ht') !==
'') {
2175 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2178 if (
GETPOST(
'price_ttc') !==
'') {
2181 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2182 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2185 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2186 if ($prod_entry_mode ==
'free') {
2192 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2197 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2200 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
2201 if (empty($remise_percent)) {
2202 $remise_percent = 0;
2206 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2207 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2209 if (is_array($extralabelsline)) {
2211 foreach ($extralabelsline as $key => $value) {
2212 unset($_POST[
"options_".$key.$predef]);
2216 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2217 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2220 if (!$prod_entry_mode) {
2222 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2226 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2227 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2230 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && (($price_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht ==
'') && (($price_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ==
'') && $price_ttc ===
'' && $price_ttc_devise ===
'' &&
$object->type !=
Facture::TYPE_CREDIT_NOTE) {
2231 if (($price_ht < 0 || $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2232 $langs->load(
"errors");
2233 if (
$object->type == $object::TYPE_DEPOSIT) {
2235 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2237 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2241 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2246 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2249 if ($prod_entry_mode ==
'free' && empty($idprod) && empty($product_desc)) {
2250 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2254 $langs->load(
"errors");
2255 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2259 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2260 if ($combinations =
GETPOST(
'combinations',
'array')) {
2264 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2265 $idprod = $res->fk_product_child;
2267 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2273 $price_base_type =
null;
2274 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
2280 $ret =
$object->fetch_thirdparty();
2285 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2296 if (!empty($idprod) && $idprod > 0) {
2298 $prod->fetch($idprod);
2300 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2305 $datapriceofproduct = $prod->getSellPrice($mysoc,
$object->thirdparty, $pqp);
2307 $pu_ht = $datapriceofproduct[
'pu_ht'];
2308 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2309 $price_min = $datapriceofproduct[
'price_min'];
2310 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2311 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2315 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2316 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $prod->tva_tx));
2320 if (!empty($price_ht) || $price_ht ===
'0') {
2322 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2323 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2324 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2327 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2329 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2330 } elseif ($tmpvat != $tmpprodvat) {
2332 if ($price_base_type !=
'HT') {
2333 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2335 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2343 $outputlangs = $langs;
2345 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
2346 $newlang =
GETPOST(
'lang_id',
'aZ09');
2348 if (empty($newlang)) {
2349 $newlang =
$object->thirdparty->default_lang;
2351 if (!empty($newlang)) {
2353 $outputlangs->setDefaultLang($newlang);
2354 $outputlangs->load(
'products');
2357 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->
description;
2359 $desc = $prod->description;
2368 $desc = $product_desc;
2374 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
2378 $outputlangs = $langs;
2380 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
2381 $newlang =
GETPOST(
'lang_id',
'alpha');
2383 if (empty($newlang)) {
2384 $newlang =
$object->thirdparty->default_lang;
2386 if (!empty($newlang)) {
2388 $outputlangs->setDefaultLang($newlang);
2389 $outputlangs->load(
'products');
2391 if (!empty($prod->customcode)) {
2392 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2394 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2397 if (!empty($prod->country_code)) {
2398 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $outputlangs, 0);
2401 if (!empty($prod->customcode)) {
2402 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2404 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2407 if (!empty($prod->country_code)) {
2408 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $langs, 0);
2415 $type = $prod->type;
2416 $fk_unit = $prod->fk_unit;
2418 if (!empty($price_ht)) {
2423 if (!empty($price_ttc)) {
2428 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2429 $tva_tx = str_replace(
'*',
'', $tva_tx);
2430 if (empty($tva_tx)) {
2433 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2434 $desc = $product_desc;
2436 $fk_unit =
GETPOST(
'units',
'alpha');
2438 if ($pu_ttc && !$pu_ht) {
2439 $price_base_type =
'TTC';
2453 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2454 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2457 $pu_equivalent = $pu_ht;
2458 $pu_equivalent_ttc = $pu_ttc;
2460 $currency_tx =
$object->multicurrency_tx;
2464 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2465 $pu_equivalent = (float) $pu_ht_devise * $currency_tx;
2467 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2468 $pu_equivalent_ttc = (float) $pu_ttc_devise * $currency_tx;
2488 $price2num_remise_percent =
price2num($remise_percent);
2489 $price2num_price_min =
price2num($price_min);
2490 $price2num_price_min_ttc =
price2num($price_min_ttc);
2491 if (empty($price2num_pu_ht)) {
2492 $price2num_pu_ht = 0;
2494 if (empty($price2num_remise_percent)) {
2495 $price2num_remise_percent = 0;
2497 if (empty($price2num_price_min)) {
2498 $price2num_price_min = 0;
2500 if (empty($price2num_price_min_ttc)) {
2501 $price2num_price_min_ttc = 0;
2506 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2507 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2510 } elseif ($pu_equivalent_ttc && $price_min_ttc && (((
float)
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
2511 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2518 '@phan-var-force CommonObjectLine[] $lines';
2520 if (isModEnabled(
'productbatch') && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) &&
getDolGlobalString(
'INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS')) {
2521 $langs->load(
'productbatch');
2522 foreach ($lines[$i]->detail_batch as $batchline) {
2523 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2528 $result =
$object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $date_start, $date_end, 0, $info_bits, 0, $price_base_type, $pu_ttc, $type, min($rank, count(
$object->lines) + 1), $special_code,
'', 0,
GETPOST(
'fk_parent_line'), $fournprice, $buyingprice, $label, $array_options,
GETPOST(
'progress'), 0, $fk_unit, $pu_ht_devise);
2533 $outputlangs = $langs;
2536 $newlang =
GETPOST(
'lang_id',
'aZ09');
2539 $newlang =
$object->thirdparty->default_lang;
2541 if (!empty($newlang)) {
2543 $outputlangs->setDefaultLang($newlang);
2544 $outputlangs->load(
'products');
2549 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2555 unset($_POST[
'prod_entry_mode']);
2556 unset($_POST[
'qty']);
2557 unset($_POST[
'type']);
2558 unset($_POST[
'remise_percent']);
2559 unset($_POST[
'price_ht']);
2560 unset($_POST[
'multicurrency_price_ht']);
2561 unset($_POST[
'price_ttc']);
2562 unset($_POST[
'tva_tx']);
2563 unset($_POST[
'product_ref']);
2564 unset($_POST[
'product_label']);
2565 unset($_POST[
'product_desc']);
2566 unset($_POST[
'fournprice']);
2567 unset($_POST[
'buying_price']);
2568 unset($_POST[
'np_marginRate']);
2569 unset($_POST[
'np_markRate']);
2570 unset($_POST[
'dp_desc']);
2571 unset($_POST[
'idprod']);
2572 unset($_POST[
'units']);
2573 unset($_POST[
'date_starthour']);
2574 unset($_POST[
'date_startmin']);
2575 unset($_POST[
'date_startsec']);
2576 unset($_POST[
'date_startday']);
2577 unset($_POST[
'date_startmonth']);
2578 unset($_POST[
'date_startyear']);
2579 unset($_POST[
'date_endhour']);
2580 unset($_POST[
'date_endmin']);
2581 unset($_POST[
'date_endsec']);
2582 unset($_POST[
'date_endday']);
2583 unset($_POST[
'date_endmonth']);
2584 unset($_POST[
'date_endyear']);
2585 unset($_POST[
'situations']);
2586 unset($_POST[
'progress']);
2594 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2595 if (!
$object->fetch($id) > 0) {
2607 $vat_rate = str_replace(
'*',
'', $vat_rate);
2619 if (preg_match(
'/\*/', $vat_rate)) {
2624 $vat_rate = str_replace(
'*',
'', $vat_rate);
2633 $pu_equivalent = $pu_ht;
2634 $pu_equivalent_ttc = $pu_ttc;
2636 $currency_tx =
$object->multicurrency_tx;
2640 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2641 $pu_equivalent = (float) $pu_ht_devise * (
float) $currency_tx;
2643 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2644 $pu_equivalent_ttc = (float) $pu_ttc_devise * (
float) $currency_tx;
2659 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2660 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
2662 if (is_array($extralabelsline)) {
2664 foreach ($extralabelsline as $key => $value) {
2665 unset($_POST[
"options_".$key]);
2671 if ($special_code == 3) {
2677 $percent = $line->get_prev_progress(
$object->id);
2682 if ($progress >= 0) {
2683 $mesg = $langs->trans(
"CantBeNullOrPositive");
2687 } elseif ($progress < $line->situation_percent) {
2688 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
2692 } elseif ($progress < $percent) {
2693 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
2704 if (!empty($productid)) {
2706 $product->fetch($productid);
2708 $type = $product->type;
2710 $price_min = $product->price_min;
2712 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
2714 $price_min_ttc = $product->price_min_ttc;
2716 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
2723 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
2724 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2727 $action =
'editline';
2728 } elseif ($pu_equivalent_ttc && $price_min_ttc && (((
float)
price2num($pu_equivalent_ttc) * (1 - (
float) $remise_percent / 100)) < (
float)
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
2729 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2732 $action =
'editline';
2737 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2741 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
2746 $langs->load(
"errors");
2747 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2751 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2752 $langs->load(
"errors");
2753 if (
$object->type == $object::TYPE_DEPOSIT) {
2755 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2757 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2761 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2768 $previousprogress = $line->getAllPrevProgress($line->fk_facture);
2771 if ($fullprogress < $previousprogress) {
2773 setEventMessages($langs->trans(
'CantBeLessThanMinPercent'),
null,
'errors');
2777 if ($fullprogress > 100) {
2778 $fullprogress = 100;
2780 $addprogress = $fullprogress - $previousprogress;
2787 if (empty($usercancreatemargin)) {
2788 foreach (
$object->lines as &$line) {
2790 $fournprice = $line->fk_fournprice;
2791 $buyingprice = $line->pa_ht;
2797 $price_base_type =
'HT';
2799 if (empty($pu) && !empty($pu_ttc)) {
2801 $price_base_type =
'TTC';
2804 $result =
$object->updateline(
2833 $outputlangs = $langs;
2836 $newlang =
GETPOST(
'lang_id',
'aZ09');
2839 $newlang =
$object->thirdparty->default_lang;
2841 if (!empty($newlang)) {
2843 $outputlangs->setDefaultLang($newlang);
2844 $outputlangs->load(
'products');
2848 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2851 unset($_POST[
'qty']);
2852 unset($_POST[
'type']);
2853 unset($_POST[
'productid']);
2854 unset($_POST[
'remise_percent']);
2855 unset($_POST[
'price_ht']);
2856 unset($_POST[
'multicurrency_price_ht']);
2857 unset($_POST[
'price_ttc']);
2858 unset($_POST[
'tva_tx']);
2859 unset($_POST[
'product_ref']);
2860 unset($_POST[
'product_label']);
2861 unset($_POST[
'product_desc']);
2862 unset($_POST[
'fournprice']);
2863 unset($_POST[
'buying_price']);
2864 unset($_POST[
'np_marginRate']);
2865 unset($_POST[
'np_markRate']);
2866 unset($_POST[
'dp_desc']);
2867 unset($_POST[
'idprod']);
2868 unset($_POST[
'units']);
2869 unset($_POST[
'date_starthour']);
2870 unset($_POST[
'date_startmin']);
2871 unset($_POST[
'date_startsec']);
2872 unset($_POST[
'date_startday']);
2873 unset($_POST[
'date_startmonth']);
2874 unset($_POST[
'date_startyear']);
2875 unset($_POST[
'date_endhour']);
2876 unset($_POST[
'date_endmin']);
2877 unset($_POST[
'date_endsec']);
2878 unset($_POST[
'date_endday']);
2879 unset($_POST[
'date_endmonth']);
2880 unset($_POST[
'date_endyear']);
2881 unset($_POST[
'situations']);
2882 unset($_POST[
'progress']);
2887 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modifier')) {
2888 if (!
$object->fetch($id) > 0) {
2891 if (
GETPOST(
'all_progress') !=
"") {
2893 foreach (
$object->lines as $line) {
2895 $percent = $line->getAllPrevProgress(
$object->id);
2897 $percent = $line->get_prev_progress(
$object->id);
2899 if ((
float) $all_progress < (
float) $percent) {
2900 $mesg = $langs->trans(
"Line").
' '.$i.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
2909 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
2910 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2912 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
2914 $object->fetch($id,
'',
'', 0,
true);
2920 &&
$object->is_last_in_cycle()
2921 && $usercanunvalidate
2924 $newCycle =
$object->newCycle();
2925 if ($newCycle > 1) {
2927 $lastCycle =
$object->situation_cycle_ref;
2928 $lastSituationCounter =
$object->situation_counter;
2929 $linkedCreditNotesList = array();
2931 if (count(
$object->tab_next_situation_invoice) > 0) {
2932 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
2934 && $next_invoice->situation_counter ==
$object->situation_counter
2935 && $next_invoice->fk_facture_source ==
$object->id
2937 $linkedCreditNotesList[] = $next_invoice->id;
2942 $object->situation_cycle_ref = $newCycle;
2943 $object->situation_counter = 1;
2945 if (
$object->update($user) > 0) {
2947 if (count($linkedCreditNotesList) > 0) {
2949 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
2950 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
2951 $sql .=
' , situation_final=0';
2952 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
2953 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
2955 $resql = $db->query($sql);
2961 foreach (
$object->lines as $line) {
2963 if ($line->product_type == 9) {
2968 if (!empty(
$object->tab_previous_situation_invoice)) {
2970 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
2971 $searchPreviousInvoice =
true;
2972 while ($searchPreviousInvoice) {
2974 $searchPreviousInvoice =
false;
2982 $maxPrevSituationPercent = 0;
2983 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
2984 if ($prevLine->id == $line->fk_prev_id) {
2985 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
2990 $line->situation_percent -= $maxPrevSituationPercent;
2992 if ($line->update() < 0) {
3001 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
3003 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
3006 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
3009 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
3015 $fromElement =
GETPOST(
'fromelement');
3016 $fromElementid =
GETPOST(
'fromelementid');
3017 $importLines =
GETPOST(
'line_checkbox');
3019 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
3020 $lineClassName =
'';
3021 if ($fromElement ==
'commande') {
3023 $lineClassName =
'OrderLine';
3024 } elseif ($fromElement ==
'propal') {
3025 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
3026 $lineClassName =
'PropaleLigne';
3028 $nextRang = count(
$object->lines) + 1;
3031 foreach ($importLines as $lineId) {
3032 if ($lineClassName ===
'') {
3036 dol_syslog(
'compta/facture/card - No lineClassName - skip import', LOG_ERR);
3043 $lineId = intval($lineId);
3044 $originLine =
new $lineClassName($db);
3045 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
3046 $originLine->fetch_optionals();
3047 $desc = $originLine->desc;
3048 $pu_ht = $originLine->subprice;
3049 $qty = $originLine->qty;
3050 $txtva = $originLine->tva_tx;
3051 $txlocaltax1 = $originLine->localtax1_tx;
3052 $txlocaltax2 = $originLine->localtax2_tx;
3053 $fk_product = $originLine->fk_product;
3054 $remise_percent = $originLine->remise_percent;
3055 $date_start = $originLine->date_start;
3056 $date_end = $originLine->date_end;
3057 $fk_code_ventilation = 0;
3058 $info_bits = $originLine->info_bits;
3059 $fk_remise_except = $originLine->fk_remise_except;
3060 $price_base_type =
'HT';
3062 $type = $originLine->product_type;
3063 $rang = $nextRang++;
3064 $special_code = $originLine->special_code;
3065 $origin = $originLine->element;
3066 $origin_id = $originLine->id;
3067 $fk_parent_line = 0;
3068 $fk_fournprice = $originLine->fk_fournprice;
3069 $pa_ht = $originLine->pa_ht;
3070 $label = $originLine->label;
3071 $array_options = $originLine->array_options;
3073 $situation_percent = 0;
3075 $situation_percent = 100;
3078 $fk_unit = $originLine->fk_unit;
3079 $pu_ht_devise = $originLine->multicurrency_subprice;
3081 $res =
$object->addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $fk_code_ventilation, $info_bits, $fk_remise_except, $price_base_type, $pu_ttc, $type, $rang, $special_code, $origin, $origin_id, $fk_parent_line, $fk_fournprice, $pa_ht, $label, $array_options, $situation_percent, $fk_prev_id, $fk_unit, $pu_ht_devise);
3100 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3106 $triggersendname =
'BILL_SENTBYMAIL';
3108 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3109 $trackid =
'inv'.$object->id;
3110 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3114 $permissiontoadd = $usercancreate;
3115 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3118 if ($action ==
'update_extras' && $usercancreate) {
3120 $attribute_name =
GETPOST(
'attribute',
'restricthtml');
3123 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute_name);
3130 $result =
$object->updateExtraField($attribute_name,
'BILL_MODIFY');
3138 $action =
'edit_extras';
3143 if ($action ==
'addcontact' && $usercancreate) {
3144 $result =
$object->fetch($id);
3146 if ($result > 0 && $id > 0) {
3149 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3153 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3156 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3157 $langs->load(
"errors");
3158 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3163 } elseif ($action ==
'swapstatut' && $usercancreate) {
3170 } elseif ($action ==
'deletecontact' && $usercancreate) {
3173 $result =
$object->delete_contact($lineid);
3176 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3184 $action =
'edit_extras';
3195$form =
new Form($db);
3201$bankaccountstatic =
new Account($db);
3203if (isModEnabled(
'project')) {
3209$title =
$object->ref.
" - ".$langs->trans(
'Card');
3210if ($action ==
'create') {
3211 $title = $langs->trans(
"NewBill");
3213$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3219if ($action ==
'create') {
3220 $facturestatic =
new Facture($db);
3221 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3226 $res = $soc->fetch($socid);
3229 $currency_code =
$conf->currency;
3231 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3232 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3238 if (!empty($origin) && !empty($originid)) {
3240 $element = $subelement = $origin;
3242 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3243 $element = $regs[1];
3244 $subelement = $regs[2];
3250 if ($element ==
'project') {
3251 $projectid = $originid;
3253 if (empty($cond_reglement_id)) {
3254 $cond_reglement_id = $soc->cond_reglement_id;
3256 if (empty($mode_reglement_id)) {
3257 $mode_reglement_id = $soc->mode_reglement_id;
3259 if (empty($fk_account)) {
3260 $fk_account = $soc->fk_account;
3262 if (empty($dateinvoice)) {
3268 if ($element ==
'order' || $element ==
'commande') {
3269 $element = $subelement =
'commande';
3271 if ($element ==
'propal') {
3272 $element =
'comm/propal';
3273 $subelement =
'propal';
3275 if ($element ==
'contract') {
3276 $element = $subelement =
'contrat';
3278 if ($element ==
'shipping') {
3279 $element = $subelement =
'expedition';
3284 $classname = ucfirst($subelement);
3285 $objectsrc =
new $classname($db);
3286 '@phan-var-force Commande|Propal|Contrat|Expedition $objectsrc';
3287 $objectsrc->fetch($originid);
3288 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3289 $objectsrc->fetch_lines();
3291 $objectsrc->fetch_thirdparty();
3293 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3294 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3297 if (empty($socid)) {
3298 $soc = $objectsrc->thirdparty;
3301 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3303 if ($element ==
'expedition') {
3304 $ref_client = (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
'');
3306 $elem = $subelem = $objectsrc->origin;
3307 $expeoriginid = $objectsrc->origin_id;
3309 $classname = ucfirst($subelem);
3311 $expesrc =
new $classname($db);
3312 '@phan-var-force Expedition $expesrc';
3313 dol_syslog(
"Is type Facture|Commande or Expedition: $element...expesrc($classname)=".get_class($expesrc));
3314 $expesrc->fetch($expeoriginid);
3316 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3317 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3318 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3320 if (isModEnabled(
'multicurrency')) {
3321 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3322 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3326 $expesrc->fetch_optionals();
3327 $object->array_options = $expesrc->array_options;
3329 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
3330 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3331 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3333 if (isModEnabled(
'multicurrency')) {
3334 if (!empty($objectsrc->multicurrency_code)) {
3335 $currency_code = $objectsrc->multicurrency_code;
3337 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
3338 $currency_tx = $objectsrc->multicurrency_tx;
3343 $objectsrc->fetch_optionals();
3344 $object->array_options = $objectsrc->array_options;
3348 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
3349 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
3350 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
3352 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3354 if (isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3355 $currency_code = $soc->multicurrency_code;
3360 if (!
GETPOST(
'changecompany')) {
3361 if (GETPOSTISSET(
'cond_reglement_id')) {
3362 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3364 if (GETPOSTISSET(
'mode_reglement_id')) {
3365 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3367 if (GETPOSTISSET(
'cond_reglement_id')) {
3373 if (empty($cond_reglement_id)) {
3374 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
3378 if (empty($mode_reglement_id)) {
3379 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
3389 if (!empty($soc->id)) {
3390 $absolute_discount = $soc->getAvailableDiscounts();
3392 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
3393 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
3395 if (!empty(
$conf->use_javascript_ajax)) {
3396 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3402 if ($origin ==
'contrat') {
3403 $langs->load(
"admin");
3404 $text = $langs->trans(
"ToCreateARecurringInvoice");
3405 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3407 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3409 print
info_admin($text, 0, 0,
'0',
'opacitymedium').
'<br>';
3412 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3413 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3414 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3415 print
'<input type="hidden" name="changecompany" value="0">';
3417 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3419 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3420 print
'<input name="ref" type="hidden" value="provisoire">';
3421 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3422 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3423 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3424 print
'<input name="force_fk_account" type="hidden" value="0">';
3425 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3426 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3427 print
'<input type="hidden" name="originentity" value="'.GETPOSTINT(
'originentity').
'">';
3428 if (!empty($currency_tx)) {
3429 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3435 $parameters = array();
3437 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters,
$object, $action);
3438 if (empty($reshook)) {
3439 print
'<table class="border centpercent">';
3441 $exampletemplateinvoice =
new FactureRec($db);
3443 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3444 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
3448 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
3450 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3451 print
'<td colspan="2">';
3452 print $soc->getNomUrl(1,
'customer');
3453 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3455 $arrayoutstandingbills = $soc->getOutstandingBills();
3456 $outstandingBills = $arrayoutstandingbills[
'opened'];
3457 print
' - <span class="opacitymedium">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3458 print
'<span class="amount">'.price($outstandingBills, 0, $langs, 0, 0, -1,
$conf->currency).
'</span>';
3459 if ($soc->outstanding_limit !=
'') {
3460 if ($outstandingBills > $soc->outstanding_limit) {
3461 print
img_warning($langs->trans(
"OutstandingBillReached"));
3463 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1,
$conf->currency);
3468 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3469 print
'<td colspan="2">';
3470 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
3471 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3475 $(document).ready(function() {
3476 $("#socid").change(function() {
3478 console.log("Submit page");
3479 $(\'input[name="action"]\').val(\'create\');
3480 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3481 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3482 $(\'input[name="force_fk_account"]\').val(\'1\');
3483 $("#formtocreate").submit(); */
3485 // For company change, we must submit page with action=create instead of action=add
3486 console.log("We have changed the company - Resubmit page");
3487 jQuery("input[name=changecompany]").val("1");
3488 jQuery("#formtocreateaction").val("create");
3489 jQuery("#formtocreate").submit();
3495 print
' <a href="'.DOL_URL_ROOT.
'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create').
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddThirdParty").
'"></span></a>';
3502 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3503 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
3505 $dateinvoice = $invoice_predefined->date_when;
3506 if (empty($projectid)) {
3507 $projectid = $invoice_predefined->fk_project;
3509 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
3510 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
3511 $fk_account = $invoice_predefined->fk_account;
3512 $note_public = $invoice_predefined->note_public;
3513 $note_private = $invoice_predefined->note_private;
3515 if (!empty($invoice_predefined->multicurrency_code)) {
3516 $currency_code = $invoice_predefined->multicurrency_code;
3518 if (!empty($invoice_predefined->multicurrency_tx)) {
3519 $currency_tx = $invoice_predefined->multicurrency_tx;
3522 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
3523 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
3524 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
3526 $resql = $db->query($sql);
3528 $num = $db->num_rows($resql);
3532 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
3534 print
'<select class="flat" id="fac_rec" name="fac_rec">';
3535 print
'<option value="0" selected></option>';
3537 $objp = $db->fetch_object($resql);
3538 print
'<option value="'.$objp->rowid.
'"';
3541 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
3543 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
3552 print
'<script type="text/javascript">
3553 $(document).ready(function() {
3554 $("#fac_rec").change(function() {
3555 console.log("We have changed the template invoice - Reload page");
3556 var fac_rec = $(this).val();
3557 var socid = $(\'#socid\').val();
3558 // For template invoice change, we must reuse data of template, not input already done, so we call a GET with action=create, not a POST submit.
3559 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3572 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td colspan="2">';
3573 print
'<div class="tagtable">'.
"\n";
3576 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3577 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
3578 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
3580 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'nowraponall', 0, 3,
'standardonsmartphone');
3581 print
'<table class="nobordernopadding"><tr>';
3585 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
3594 print
'<td class="nowrap" style="padding-left: 15px">';
3595 print
'<span class="opacitymedium">'.$langs->trans(
'PercentOfOriginalObject').
'</span>:<input class="right" placeholder="100%" type="text" id="valuestandardinvoice" name="valuestandardinvoice" size="3" value="'.(GETPOSTISSET(
'valuestandardinvoice') ?
GETPOST(
'valuestandardinvoice',
'alpha') :
'100%').
'"/>';
3598 print
'</tr></table>';
3599 print
'</div></div>';
3601 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
3604 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3605 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
3606 print
'<script type="text/javascript">
3607 jQuery(document).ready(function() {
3608 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
3609 jQuery("#radio_standard").prop("checked", true);
3611 jQuery("#typedeposit, #valuedeposit").click(function() {
3612 jQuery("#radio_deposit").prop("checked", true);
3614 jQuery("#typedeposit").change(function() {
3615 console.log("We change type of down payment");
3616 jQuery("#radio_deposit").prop("checked", true);
3617 setRadioForTypeOfInvoice();
3619 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
3620 setRadioForTypeOfInvoice();
3622 function setRadioForTypeOfInvoice() {
3623 console.log("Change radio for type of invoice");
3624 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
3625 jQuery("#checkforselects").prop("disabled", true);
3626 jQuery("#checkforselects").prop("checked", false);
3627 jQuery(".checkforselect").prop("disabled", true);
3628 jQuery(".checkforselect").prop("checked", false);
3630 jQuery("#checkforselects").prop("disabled", false);
3631 jQuery("#checkforselects").prop("checked", true);
3632 jQuery(".checkforselect").prop("disabled", false);
3633 jQuery(".checkforselect").prop("checked", true);
3639 print
'<table class="nobordernopadding"><tr>';
3641 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
3643 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
3646 if (($origin ==
'propal') || ($origin ==
'commande')) {
3647 print
'<td class="nowrap" style="padding-left: 15px">';
3649 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
3650 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
3651 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
3653 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
3655 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
3656 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
3657 if (!empty($origin_payment_conditions_deposit_percent)) {
3658 $typedeposit =
'variable';
3661 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
3662 $valuedeposit = $objectsrc->deposit_percent;
3664 print $form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
3666 print
'<td class="nowrap" style="padding-left: 5px">';
3667 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.$valuedeposit.
'"/>';
3670 print
'</tr></table>';
3672 print
'</div></div>';
3679 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3680 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
3681 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
3683 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
3685 print
'</div></div>';
3688 $opt = $form->selectSituationInvoices(
GETPOSTINT(
'originid'), $socid);
3690 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3691 $tmp =
'<input type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
3692 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3693 $tmp .=
' disabled';
3696 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3697 $text .=
'<select class="flat" id="situations" name="situations"';
3698 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3699 $text .=
' disabled';
3703 $text .=
'</select>';
3704 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
3706 print
'</div></div>';
3712 $facids = $facturestatic->list_replacable_invoices($soc->id);
3718 if (is_array($facids)) {
3719 foreach ($facids as $facparam) {
3720 $options .=
'<option value="'.$facparam [
'id'].
'"';
3721 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
3722 $options .=
' selected';
3724 $options .=
'>'.$facparam[
'ref'];
3725 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
3726 $options .=
'</option>';
3730 print
'<!-- replacement line -->';
3731 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3732 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
3733 if (!$options || $invoice_predefined->id > 0) {
3734 $tmp .=
' disabled';
3737 print
'<script type="text/javascript">
3738 jQuery(document).ready(function() {
3739 jQuery("#fac_replacement").change(function() {
3740 jQuery("#radio_replacement").prop("checked", true);
3744 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
3745 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
3746 if (!$options || $invoice_predefined->id > 0) {
3747 $text .=
' disabled';
3751 $text .=
'<option value="-1"> </option>';
3754 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
3756 $text .=
'</select>';
3757 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3759 print
'</div></div>';
3763 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3764 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3765 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3766 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3767 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'nowraponall', 0, 3,
'firstsituationonsmartphone');
3769 print
'</div></div>';
3772 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3773 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
3774 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
3776 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'replacementonsmartphone');
3778 print
'</div></div>';
3781 if (empty($origin)) {
3786 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
3792 $newinvoice_static =
new Facture($db);
3793 foreach ($facids as $key => $valarray) {
3794 $newinvoice_static->id = $key;
3795 $newinvoice_static->ref = $valarray [
'ref'];
3796 $newinvoice_static->statut = $valarray [
'status'];
3797 $newinvoice_static->status = $valarray [
'status'];
3798 $newinvoice_static->type = $valarray [
'type'];
3799 $newinvoice_static->paye = $valarray [
'paye'];
3801 $optionsav .=
'<option value="'.$key.
'"';
3802 if ($key ==
GETPOST(
'fac_avoir')) {
3803 $optionsav .=
' selected';
3806 $newinvoice_static->fetch_optionals($key);
3807 $object->array_options = $newinvoice_static->array_options;
3810 $optionsav .= $newinvoice_static->ref;
3811 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
3812 $optionsav .=
'</option>';
3815 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3816 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
3817 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
3818 $tmp .=
' disabled';
3822 print
'<script type="text/javascript">
3823 jQuery(document).ready(function() {
3824 if (jQuery("#radio_creditnote").is(":checked"))
3826 jQuery("#radio_standard").prop("disabled", true);
3828 jQuery("#radio_standard").prop("disabled", false);
3830 if (! jQuery("#radio_creditnote").is(":checked"))
3832 jQuery("#credit_note_options").hide();
3834 jQuery("#radio_creditnote").click(function() {
3835 jQuery("#credit_note_options").show();
3837 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
3838 jQuery("#credit_note_options").hide();
3842 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
3843 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3844 if (!$optionsav || $invoice_predefined->id > 0) {
3845 $text .=
' disabled';
3849 $text .=
'<option value="-1"></option>';
3850 $text .= $optionsav;
3852 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
3854 $text .=
'</select>';
3855 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3858 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
3859 print
' <input type="checkbox" name="invoiceAvoirWithLines" id="invoiceAvoirWithLines" value="1" onclick="$(\'#credit_note_options input[type=checkbox]\').not(this).prop(\'checked\', false);" '.(GETPOSTINT(
'invoiceAvoirWithLines') > 0 ?
'checked' :
'').
' /> <label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
3860 print
'<br> <input type="checkbox" name="invoiceAvoirWithPaymentRestAmount" id="invoiceAvoirWithPaymentRestAmount" value="1" onclick="$(\'#credit_note_options input[type=checkbox]\').not(this).prop(\'checked\', false);" '.(GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') > 0 ?
'checked' :
'').
' /> <label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
3863 print
'</div></div>';
3866 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3868 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3870 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
3872 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
3874 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
3876 print
'</div></div>'.
"\n";
3881 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3882 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
3883 $text = $tmp.
'<label class="opacitymedium" for="radio_template">'.$langs->trans(
"RepeatableInvoice").
'</label> ';
3884 $desc = $form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3,
'templateonsmartphone');
3886 print
'</div></div>';
3895 foreach ($listtType as $type) {
3896 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
3898 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
3901 print
'<script type="text/javascript">
3902 $(document).ready(function() {
3903 var listType = {'.$jsListType.
'};
3904 $("[name=\'type\'").change(function() {
3905 console.log("change name=type");
3906 if ($( this ).prop("checked"))
3908 if(($( this ).val() in listType))
3910 $("#model").val(listType[$( this ).val()]);
3927 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
3928 print $form->getSelectInvoiceSubtype(
GETPOST(
'subtype'),
'subtype', 1, 0,
'');
3934 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
3938 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
3939 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3948 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
3949 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3950 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
3955 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
3956 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3957 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
3962 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
3963 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
3964 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
3969 $rwStyle =
'display:none;';
3970 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
3974 $retained_warranty =
GETPOSTINT(
'retained_warranty');
3975 if (empty($retained_warranty)) {
3976 if ($objectsrc !==
null && property_exists($objectsrc,
'retained_warranty') && !empty($objectsrc->retained_warranty)) {
3978 $retained_warranty = $objectsrc->retained_warranty;
3981 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
3983 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
3984 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
3987 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
3988 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
3989 if (empty($retained_warranty_fk_cond_reglement)) {
3990 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
3991 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
3992 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
3994 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
3997 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4000 print
'<script type="text/javascript">
4001 $(document).ready(function() {
4002 $("[name=\'type\']").change(function() {
4003 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
4005 $(".retained-warranty-line").show();
4006 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
4009 $(".retained-warranty-line").hide();
4010 $("#new-situation-invoice-retained-warranty").val("");
4014 $("[name=\'type\']:checked").trigger("change");
4020 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
4021 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
4022 print $form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth250 widthcentpercentminusx', 1);
4026 if (isModEnabled(
"bank")) {
4027 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td colspan="2">';
4028 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4029 print $form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth250 widthcentpercentminusx', 1);
4035 if (isModEnabled(
'project') && is_object($formproject)) {
4036 $langs->load(
'projects');
4037 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
4038 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
4039 print $formproject->select_projects(($socid > 0 ? $socid : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
4040 print
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?socid='.$soc->id.
'&action=create&status=1&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create&socid='.$soc->id.($fac_rec ?
'&fac_rec='.$fac_rec :
'')).
'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans(
"AddProject").
'"></span></a>';
4045 if (isModEnabled(
'incoterm')) {
4047 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
4048 print
'<td colspan="2" class="maxwidthonsmartphone">';
4049 $incoterm_id =
GETPOST(
'incoterm_id');
4050 $location_incoterms =
GETPOST(
'location_incoterms');
4051 if (empty($incoterm_id)) {
4052 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
4053 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
4055 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
4056 print $form->select_incoterms($incoterm_id, $location_incoterms);
4061 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
4062 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
4063 print $hookmanager->resPrint;
4064 if (empty($reshook)) {
4065 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
4068 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
4069 if ($soc->fetch_optionals() > 0) {
4070 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
4074 print
$object->showOptionals($extrafields,
'create', $parameters);
4078 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
4079 print
'<td colspan="2">';
4080 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
4081 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
4086 $paramkey =
'FACTURE_ADDON_PDF_'.$type;
4091 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
4095 if (isModEnabled(
'multicurrency')) {
4097 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0).
'</td>';
4098 print
'<td colspan="2" class="maxwidthonsmartphone">';
4099 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
4100 print $form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth100 widthcentpercentminusx');
4107 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
4108 if (empty($dateexample)) {
4111 $substitutionarray = array(
4112 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
4113 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
4114 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
4115 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
4116 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
4117 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
4118 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
4119 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
4120 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
4121 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
4122 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
4125 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
4126 foreach ($substitutionarray as $key => $val) {
4127 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
4129 $htmltext .=
'</i>';
4134 print
'<td class="tdtop">';
4135 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
4137 print
'<td valign="top" colspan="2">';
4138 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
4139 print $doleditor->Create(1);
4142 if (empty($user->socid)) {
4144 print
'<td class="tdtop">';
4145 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4147 print
'<td valign="top" colspan="2">';
4148 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4149 print $doleditor->Create(1);
4155 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4156 $langs->loadLangs(array(
'orders',
'propal'));
4159 if ($origin ==
'contrat') {
4160 '@phan-var-force Contrat $objectsrc';
4162 $objectsrc->update_price(1,
'auto', 1);
4165 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4166 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4167 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4168 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4173 switch (get_class($objectsrc)) {
4175 $newclassname =
'CommercialProposal';
4178 $newclassname =
'Order';
4181 $newclassname =
'Sending';
4184 $newclassname =
'Contract';
4187 $newclassname =
'Intervention';
4190 $newclassname = get_class($objectsrc);
4194 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4195 print
'<td colspan="2">';
4196 print $objectsrc->getNomUrl(1);
4198 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
4199 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4201 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4204 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht).
'</td></tr>';
4205 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva).
"</td></tr>";
4206 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4207 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax1).
"</td></tr>";
4210 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4211 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax2).
"</td></tr>";
4213 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc).
"</td></tr>";
4215 if (isModEnabled(
'multicurrency')) {
4216 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
4217 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
4218 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
4226 print $form->buttonsSaveCancel(
"CreateDraft");
4229 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4232 $title = $langs->trans(
'ProductsAndServices');
4235 print
'<div class="div-table-responsive-no-min">';
4236 print
'<table class="noborder centpercent">';
4238 $objectsrc->printOriginLinesList(
'', $selectedLines);
4245} elseif ($id > 0 || !empty($ref)) {
4247 $langs->load(
'errors');
4248 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4257 if ($user->socid > 0 && $user->socid !=
$object->socid) {
4261 $result =
$object->fetch_thirdparty();
4263 $result = $soc->fetch(
$object->socid);
4267 $selleruserevenustamp = $mysoc->useRevenueStamp();
4269 $totalpaid =
$object->getSommePaiement();
4270 $totalcreditnotes =
$object->getSumCreditNotesUsed();
4271 $totaldeposits =
$object->getSumDepositsUsed();
4277 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4280 if (isModEnabled(
'multicurrency')) {
4281 $multicurrency_totalpaid =
$object->getSommePaiement(1);
4282 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
4283 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
4284 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4288 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
4289 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
4296 $resteapayeraffiche = $resteapayer;
4299 $filterabsolutediscount =
"fk_facture_source IS NULL";
4300 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4302 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4303 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4306 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
4307 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
4308 $absolute_discount =
price2num($absolute_discount,
'MT');
4309 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4311 $author =
new User($db);
4312 if (
$object->user_creation_id) {
4313 $author->fetch(
$object->user_creation_id);
4316 $objectidnext =
$object->getIdReplacingInvoice();
4320 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
'bill');
4325 if ($action ==
'converttoreduc') {
4327 $type_fac =
'ExcessReceived';
4329 $type_fac =
'CreditNote';
4331 $type_fac =
'Deposit';
4335 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4336 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4337 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4341 if ($action ==
'delete') {
4342 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
4343 $formquestion = array();
4346 $qualified_for_stock_change = 0;
4348 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4350 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4353 if ($qualified_for_stock_change) {
4354 $langs->load(
"stocks");
4355 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4359 if (
$conf->browser->name ==
'ie') {
4362 $formquestion = array(
4366 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4368 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4370 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4373 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4378 if ($action ==
'situationout') {
4379 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
4380 $label = $langs->trans(
"ConfirmOuting");
4381 $formquestion = array();
4386 &&
$object->is_last_in_cycle()
4387 && $usercanunvalidate
4389 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4394 if ($action ==
'valid') {
4396 $objectref = substr(
$object->ref, 1, 4);
4397 if ($objectref ==
'PROV') {
4401 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
4403 $numref =
$object->getNextNumRef($soc);
4409 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4410 if (isModEnabled(
'notification')) {
4411 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4412 $notify =
new Notify($db);
4414 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid,
$object);
4416 $formquestion = array();
4419 $qualified_for_stock_change = 0;
4421 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4423 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4426 if ($qualified_for_stock_change) {
4427 $langs->load(
"stocks");
4428 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4429 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4432 $warehouse_array = $warehouse->list_array();
4433 if (count($warehouse_array) == 1) {
4434 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4435 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4438 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4440 $formquestion = array(
4446 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4450 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
4455 foreach (
$object->lines as $line) {
4456 $res = $line->fetch_product();
4458 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
4464 if ($nbMandated > 0) {
4466 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
4469 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
4474 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, ((
$object->type !=
Facture::TYPE_CREDIT_NOTE &&
$object->total_ttc < 0) ?
"no" :
"yes"), 2, 240);
4479 if ($action ==
'modif') {
4480 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
4481 $formquestion = array();
4484 $qualified_for_stock_change = 0;
4486 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4488 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4491 if ($qualified_for_stock_change) {
4492 $langs->load(
"stocks");
4493 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4494 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4497 $warehouse_array = $warehouse->list_array();
4498 if (count($warehouse_array) == 1) {
4499 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
4500 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4503 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4505 $formquestion = array(
4511 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4515 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
4519 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
4520 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
4522 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
4526 $close[$i][
'code'] =
'discount_vat';
4528 $close[$i][
'code'] =
'badcustomer';
4530 $close[$i][
'code'] =
'bankcharge';
4532 $close[$i][
'code'] =
'withholdingtax';
4534 $close[$i][
'code'] =
'other';
4538 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
4540 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4542 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
4544 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
4546 $close[$i][
'label'] = $langs->trans(
"Other");
4550 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4552 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4554 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4556 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
4558 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
4562 foreach ($close as $key => $val) {
4563 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
4567 $formquestion = array(
'text' => $langs->trans(
"ConfirmClassifyPaidPartiallyQuestion"), 0 => array(
'type' =>
'radio',
'name' =>
'close_code',
'label' => $langs->trans(
"Reason"),
'values' => $arrayreasons), 1 => array(
'type' =>
'text',
'name' =>
'close_note',
'label' => $langs->trans(
"Comment"),
'value' =>
'',
'morecss' =>
'minwidth300'));
4569 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 380, 600);
4573 if ($action ==
'canceled') {
4577 $statusreplacement = 0;
4579 if ($objectidnext) {
4580 $facturereplacement =
new Facture($db);
4581 $facturereplacement->fetch($objectidnext);
4582 $statusreplacement = $facturereplacement->status;
4584 if ($objectidnext && $statusreplacement == 0) {
4585 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
4588 $close[1][
'code'] =
'badcustomer';
4589 $close[2][
'code'] =
'abandon';
4591 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4592 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
4594 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
4595 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
4598 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
4599 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
4602 $formquestion = array(
'text' => $langs->trans(
"ConfirmCancelBillQuestion"), 0 => array(
'type' =>
'radio',
'name' =>
'close_code',
'label' => $langs->trans(
"Reason"),
'values' => $arrayreasons), 1 => array(
'type' =>
'text',
'name' =>
'close_note',
'label' => $langs->trans(
"Comment"),
'value' =>
'',
'morecss' =>
'minwidth300'));
4604 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 270);
4608 if ($action ==
'deletepayment') {
4609 $payment_id =
GETPOST(
'paiement_id');
4610 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
4614 if ($action ==
'ask_deleteline') {
4615 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
4619 if ($action ==
'clone') {
4620 $filter =
'(s.client:IN:1,2,3)';
4622 $formquestion = array(
4623 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
$object->socid,
'socid', $filter, 1)),
4624 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
4627 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
4630 if ($action ==
"remove_file_comfirm") {
4631 $file =
GETPOST(
'file',
'alpha');
4633 $formconfirm = $form->formconfirm(
4634 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
4635 $langs->trans(
'DeleteFileHeader'),
4636 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
4645 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
4646 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
4647 if (empty($reshook)) {
4648 $formconfirm .= $hookmanager->resPrint;
4649 } elseif ($reshook > 0) {
4650 $formconfirm = $hookmanager->resPrint;
4658 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
4660 $morehtmlref =
'<div class="refidno">';
4663 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref',
$object->ref,
$object, $usercancreate,
'string',
'', 0, 1);
4664 $morehtmlref .= $form->editfieldval(
"Ref",
'ref',
$object->ref,
$object, $usercancreate,
'string',
'',
null,
null,
'', 1);
4665 $morehtmlref .=
'<br>';
4668 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer,
$object, $usercancreate,
'string',
'', 0, 1);
4669 $morehtmlref .= $form->editfieldval(
"RefCustomer",
'ref_client',
$object->ref_customer,
$object, $usercancreate,
'string'.(getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') ?
':' .
getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') :
''),
'', null, null,
'', 1);
4671 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
4673 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'&search_societe='.urlencode(
$object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
4676 if (isModEnabled(
'project')) {
4677 $langs->load(
"projects");
4678 $morehtmlref .=
'<br>';
4679 if ($usercancreate) {
4680 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
4681 if ($action !=
'classify') {
4682 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
4684 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->socid,
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
4686 if (!empty(
$object->fk_project)) {
4688 $proj->fetch(
$object->fk_project);
4689 $morehtmlref .= $proj->getNomUrl(1);
4691 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
4696 $morehtmlref .=
'</div>';
4698 $object->totalpaid = $totalpaid;
4699 $object->totalcreditnotes = $totalcreditnotes;
4700 $object->totaldeposits = $totaldeposits;
4703 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
4706 $parameters = array();
4708 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters,
$object, $action);
4709 if (empty($reshook)) {
4710 print
'<div class="fichecenter">';
4711 print
'<div class="fichehalfleft">';
4712 print
'<div class="underbanner clearboth"></div>';
4714 print
'<table class="border centpercent tableforfield">';
4717 print
'<tr><td class="fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
4720 print
' '.$object->getSubtypeLabel(
'facture');
4726 $facreplaced =
new Facture($db);
4727 $facreplaced->fetch(
$object->fk_facture_source);
4728 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
4732 $facusing->fetch(
$object->fk_facture_source);
4733 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
4736 $facidavoir =
$object->getListIdAvoirFromInvoice();
4737 if (count($facidavoir) > 0) {
4738 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
4740 foreach ($facidavoir as $id) {
4747 $facavoir->fetch($id);
4748 print $facavoir->getNomUrl(1,
'', 32);
4752 if ($objectidnext > 0) {
4753 $facthatreplace =
new Facture($db);
4754 $facthatreplace->fetch($objectidnext);
4755 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
4760 $result = $discount->fetch(0,
$object->id);
4762 print
' <span class="opacitymediumbycolor paddingleft">';
4763 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
4764 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
4765 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
4767 print
'</span><br>';
4771 if (
$object->fk_fac_rec_source > 0) {
4773 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
4775 print
' <span class="opacitymediumbycolor paddingleft">';
4776 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
4777 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
4785 print
'<!-- Discounts -->'.
"\n";
4786 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
4790 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
4791 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
4796 print
'<table class="nobordernopadding centpercent"><tr><td>';
4797 print $langs->trans(
'DateInvoice');
4799 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
4800 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editinvoicedate&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'SetDate'), 1).
'</a></td>';
4802 print
'</tr></table>';
4805 if ($action ==
'editinvoicedate') {
4806 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
4808 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
4817 print
'<table class="nobordernopadding centpercent"><tr><td>';
4818 print $langs->trans(
'DatePointOfTax');
4820 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editdate_pointoftax&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'SetDate'), 1).
'</a></td>';
4821 print
'</tr></table>';
4823 if ($action ==
'editdate_pointoftax') {
4824 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
4826 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
4833 print
'<table class="nobordernopadding centpercent"><tr><td>';
4834 print $langs->trans(
'PaymentConditionsShort');
4837 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>';
4839 print
'</tr></table>';
4842 if ($action ==
'editconditions') {
4843 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->cond_reglement_id,
'cond_reglement_id');
4845 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->cond_reglement_id,
'none');
4854 print
'<table class="nobordernopadding centpercent"><tr><td>';
4855 print $langs->trans(
'DateMaxPayment');
4858 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editpaymentterm&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'SetDate'), 1).
'</a></td>';
4860 print
'</tr></table>';
4863 if ($action ==
'editpaymentterm') {
4864 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
4866 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
4878 print
'<table class="nobordernopadding centpercent"><tr><td>';
4879 print $langs->trans(
'PaymentMode');
4881 if ($action !=
'editmode' && $usercancreate) {
4882 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>';
4884 print
'</tr></table>';
4886 if ($action ==
'editmode') {
4887 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
4889 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->mode_reglement_id,
'none',
'CRDT');
4894 if (isModEnabled(
"bank")) {
4895 print
'<tr><td class="nowrap">';
4896 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
4897 print $langs->trans(
'BankAccount');
4899 if (($action !=
'editbankaccount') && $usercancreate) {
4900 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>';
4902 print
'</tr></table>';
4904 if ($action ==
'editbankaccount') {
4905 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'fk_account', 1);
4907 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'none');
4914 if (isModEnabled(
'incoterm')) {
4916 print
'<table class="nobordernopadding centpercent"><tr><td>';
4917 print $langs->trans(
'IncotermLabel');
4918 print
'<td><td class="right">';
4919 if ($usercancreate) {
4920 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
4924 print
'</td></tr></table>';
4927 if ($action !=
'editincoterm') {
4928 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
4930 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
4937 $displayWarranty =
false;
4940 $displayWarranty =
true;
4941 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
4942 $displayWarranty =
false;
4945 if ($displayWarranty) {
4947 print
'<tr class="retained-warranty-lines" ><td>';
4948 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
4949 print $langs->trans(
'RetainedWarranty');
4952 print
'<td align="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editretainedwarranty&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'setRetainedWarranty'), 1).
'</a></td>';
4955 print
'</tr></table>';
4958 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
4959 print
'<input type="hidden" name="action" value="setretainedwarranty">';
4960 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4961 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4962 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
4963 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
4971 print
'<tr class="retained-warranty-lines" ><td>';
4972 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
4973 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
4975 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
4976 print
'<td align="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editretainedwarrantypaymentterms&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'setPaymentConditionsShortRetainedWarranty'), 1).
'</a></td>';
4979 print
'</tr></table>';
4981 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
4982 if (
$object->date > $defaultDate) {
4988 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
4989 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
4990 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4991 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4992 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
4993 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
4994 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4995 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4996 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4999 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->retained_warranty_fk_cond_reglement,
'none');
5000 if (!$displayWarranty) {
5001 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning.png',
'class="pictowarning valignmiddle" ');
5007 print
'<tr class="retained-warranty-lines" ><td>';
5008 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
5009 print $langs->trans(
'RetainedWarrantyDateLimit');
5012 print
'<td align="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editretainedwarrantydatelimit&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'setRetainedWarrantyDateLimit'), 1).
'</a></td>';
5015 print
'</tr></table>';
5017 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5018 if (
$object->date > $defaultDate) {
5024 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5025 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
5026 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5027 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5028 print
'<input name="retained_warranty_date_limit" type="date" step="1" min="'.dol_print_date(
$object->date,
'%Y-%m-%d').
'" value="'.
dol_print_date($defaultDate,
'%Y-%m-%d').
'" >';
5029 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5041 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
5046 print
'<div class="fichehalfright">';
5048 print
'<!-- amounts -->'.
"\n";
5049 print
'<div class="underbanner clearboth"></div>'.
"\n";
5051 print
'<table class="border tableforfield centpercent">';
5053 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
5061 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
5062 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5063 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5065 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5071 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
5072 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5073 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5075 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5080 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
5082 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
5083 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5084 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5087 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5092 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
5094 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
5095 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5096 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5099 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5105 if ($selleruserevenustamp) {
5106 print
'<tr><td class="titlefieldmiddle">';
5107 print
'<table class="nobordernopadding centpercent"><tr><td>';
5108 print $langs->trans(
'RevenueStamp');
5110 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
5111 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editrevenuestamp&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'SetRevenuStamp'), 1).
'</a></td>';
5113 print
'</tr></table>';
5114 print
'</td><td class="nowrap amountcard right">';
5115 if ($action ==
'editrevenuestamp') {
5116 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
5117 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5118 print
'<input type="hidden" name="action" value="setrevenuestamp">';
5119 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
5120 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5121 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
5122 print
' → <span id="revenuestamp_span"></span>';
5123 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
5126 $(document).ready(function(){
5127 js_recalculate_revenuestamp();
5128 $('select[name=revenuestamp_type]').on('change',function(){
5129 js_recalculate_revenuestamp();
5132 function js_recalculate_revenuestamp(){
5133 var valselected = $('select[name=revenuestamp_type]').val();
5134 console.log('Calculate revenue stamp from '+valselected);
5136 if (valselected.indexOf('%') == -1)
5138 revenue = valselected;
5142 var revenue_type = parseFloat(valselected);
5143 var amount_net = ".round(
$object->total_ht, 2).
";
5144 revenue = revenue_type * amount_net / 100;
5145 revenue = revenue.toFixed(2);
5147 $('#revenuestamp_val').val(revenue);
5148 $('#revenuestamp_span').html(revenue);
5159 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
5160 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5161 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5163 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5171 if (isModEnabled(
'project')) {
5174 if (isModEnabled(
"bank")) {
5178 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
5181 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
5184 if ($selleruserevenustamp) {
5187 if (isModEnabled(
'multicurrency')) {
5190 if (isModEnabled(
'incoterm')) {
5194 $total_prev_ht = $total_prev_ttc = 0;
5195 $total_global_ht = $total_global_ttc = 0;
5199 print
'<!-- List of situation invoices -->';
5200 print
'<table class="noborder situationstable" width="100%">';
5202 print
'<tr class="liste_titre">';
5203 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
5205 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
5206 if (isModEnabled(
"bank")) {
5207 print
'<td class="right"></td>';
5209 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
5210 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
5211 print
'<td width="18"> </td>';
5214 if (count(
$object->tab_previous_situation_invoice) > 0) {
5217 $current_situation_counter = array();
5218 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
5219 $tmptotalallpayments = $prev_invoice->getSommePaiement(0);
5220 $tmptotalallpayments += $prev_invoice->getSumDepositsUsed(0);
5221 $tmptotalallpayments += $prev_invoice->getSumCreditNotesUsed(0);
5223 $total_prev_ht += $prev_invoice->total_ht;
5224 $total_prev_ttc += $prev_invoice->total_ttc;
5226 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
5227 print
'<tr class="oddeven">';
5228 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
5230 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
5231 if (isModEnabled(
"bank")) {
5232 print
'<td class="right"></td>';
5234 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
5235 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
5236 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalallpayments).
'</td>';
5241 $totalallpayments =
$object->getSommePaiement(0);
5242 $totalallpayments +=
$object->getSumCreditNotesUsed(0);
5243 $totalallpayments +=
$object->getSumDepositsUsed(0);
5245 $total_global_ht += $total_prev_ht;
5246 $total_global_ttc += $total_prev_ttc;
5247 $total_global_ht +=
$object->total_ht;
5248 $total_global_ttc +=
$object->total_ttc;
5252 print
'<tr class="oddeven">';
5253 print
'<td>'.$object->getNomUrl(1).
'</td>';
5255 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
5256 if (isModEnabled(
"bank")) {
5257 print
'<td class="right"></td>';
5259 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
5260 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
5261 print
'<td class="right">'.$object->getLibStatut(3, $totalallpayments).
'</td>';
5265 print
'<tr class="oddeven">';
5266 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'CurrentSituationTotal').
'</b></td>';
5269 foreach ($current_situation_counter as $sit) {
5270 $curSign = $sit > 0 ?
'+' :
'-';
5271 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
5273 print
' '.$curSign.
' ';
5275 print $curType.abs($sit);
5279 if (isModEnabled(
"bank")) {
5282 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5283 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5284 print
'<td width="18"> </td>';
5288 if (count(
$object->tab_next_situation_invoice) > 0) {
5300 $total_next_ht = $total_next_ttc = 0;
5302 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
5303 $totalpaid = $next_invoice->getSommePaiement(0);
5304 $totalcreditnotes = $next_invoice->getSumCreditNotesUsed(0);
5305 $totaldeposits = $next_invoice->getSumDepositsUsed(0);
5307 $total_next_ht += $next_invoice->total_ht;
5308 $total_next_ttc += $next_invoice->total_ttc;
5310 print
'<tr class="oddeven">';
5311 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
5313 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
5314 if (isModEnabled(
"bank")) {
5315 print
'<td class="right"></td>';
5317 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
5318 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
5319 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid + $totalcreditnotes + $totaldeposits).
'</td>';
5323 $total_global_ht += $total_next_ht;
5324 $total_global_ttc += $total_next_ttc;
5326 print
'<tr class="oddeven">';
5327 print
'<td colspan="3" class="right"></td>';
5328 if (isModEnabled(
"bank")) {
5329 print
'<td class="right"></td>';
5331 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5332 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5333 print
'<td width="18"> </td>';
5341 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
5347 print
'<!-- List of payments already done -->';
5348 print
'<div class="div-table-responsive-no-min">';
5349 print
'<table class="noborder paymenttable centpercent">';
5351 print
'<tr class="liste_titre">';
5352 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
5353 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
5354 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
5355 if (isModEnabled(
"bank")) {
5356 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
5358 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
5359 print
'<td class="liste_titre" width="18"> </td>';
5363 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
5364 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
5365 $sql .=
' pf.amount,';
5366 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal, ba.currency_code as bacurrency_code';
5367 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
5368 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
5369 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
5370 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
5371 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
5372 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
5373 $sql .=
' ORDER BY p.datep, p.tms';
5375 $result = $db->query($sql);
5377 $num = $db->num_rows($result);
5382 $objp = $db->fetch_object($result);
5384 $paymentstatic->id = $objp->rowid;
5385 $paymentstatic->datepaye = $db->jdate($objp->dp);
5386 $paymentstatic->ref = $objp->ref;
5387 $paymentstatic->num_payment = $objp->num_payment;
5388 $paymentstatic->paiementcode = $objp->payment_code;
5390 print
'<tr class="oddeven"><td class="nowraponall">';
5391 print $paymentstatic->getNomUrl(1);
5394 $dateofpayment = $db->jdate($objp->dp);
5396 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
5403 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
5404 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
5405 if (isModEnabled(
"bank")) {
5406 $bankaccountstatic->id = $objp->baid;
5407 $bankaccountstatic->ref = $objp->baref;
5408 $bankaccountstatic->label = $objp->baref;
5409 $bankaccountstatic->number = $objp->banumber;
5410 $bankaccountstatic->currency_code = $objp->bacurrency_code;
5412 if (isModEnabled(
'accounting')) {
5413 $bankaccountstatic->account_number = $objp->account_number;
5416 $accountingjournal->fetch($objp->fk_accountancy_journal);
5417 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
5420 print
'<td class="nowraponall">';
5421 if ($bankaccountstatic->id) {
5422 print $bankaccountstatic->getNomUrl(1,
'transactions');
5426 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
5427 print
'<td class="center">';
5430 $paiement->fetch($objp->rowid);
5432 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
5449 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5450 print
'<span class="opacitymedium">';
5452 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
5454 print $langs->trans(
'AlreadyPaid');
5456 print
'</span></td><td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td><td> </td></tr>';
5458 $resteapayeraffiche = $resteapayer;
5459 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
5462 $creditnoteamount = 0;
5464 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
5465 $sql .=
" re.description, re.fk_facture_source";
5466 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
5467 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
5468 $resql = $db->query($sql);
5470 $num = $db->num_rows($resql);
5474 $obj = $db->fetch_object($resql);
5475 $invoice->fetch($obj->fk_facture_source);
5476 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5477 print
'<span class="opacitymedium">';
5479 print $langs->trans(
"CreditNote").
' ';
5482 print $langs->trans(
"Deposit").
' ';
5484 print $invoice->getNomUrl(0);
5487 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
5488 print
'<td class="right">';
5489 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
5490 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
5495 $creditnoteamount += $obj->amount_ttc;
5498 $depositamount += $obj->amount_ttc;
5507 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5508 print
'<span class="opacitymedium">';
5509 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
5511 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5512 $resteapayeraffiche = 0;
5513 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5517 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5518 print
'<span class="opacitymedium">';
5519 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
5521 print
'</td><td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td><td> </td></tr>';
5523 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5527 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5528 print
'<span class="opacitymedium">';
5529 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
5531 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5532 $resteapayeraffiche = 0;
5533 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5537 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5538 $text = $langs->trans(
"HelpAbandonOther");
5540 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
5542 print
'<span class="opacitymedium">';
5544 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
5546 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5547 $resteapayeraffiche = 0;
5548 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5552 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5553 print
'<span class="opacitymedium">';
5554 print $langs->trans(
"Billed");
5555 print
'</td><td class="right">'.price(
$object->total_ttc).
'</td><td> </td></tr>';
5557 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5558 print
'<span class="opacitymedium">';
5559 print $langs->trans(
'RemainderToPay');
5560 if ($resteapayeraffiche < 0) {
5561 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5565 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
5569 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5570 print
'<span class="opacitymedium">';
5571 print $langs->trans(
'RemainderToPayMulticurrency');
5572 if ($resteapayeraffiche < 0) {
5573 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5577 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">';
5579 print
price(
price2num(
$object->multicurrency_tx * $resteapayeraffiche,
'MT'), 1, $langs, 1, -1, -1, (empty(
$object->multicurrency_code) ?
$conf->currency :
$object->multicurrency_code)).
'</td><td> </td></tr>';
5583 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
5586 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
5589 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
5592 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
5594 print
'<tr><td colspan="'.$nbcols.
'" align="right">'.$langs->trans(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')).
' :</td><td align="right">'.
price($billedWithRetainedWarranty).
'</td><td> </td></tr>';
5597 print
'<tr><td colspan="'.$nbcols.
'" align="right">';
5598 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
5599 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
5600 print
' :</td><td align="right">'.price($retainedWarranty).
'</td><td> </td></tr>';
5603 $resteapayeraffiche = $resteapayer;
5604 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5607 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5608 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
5609 print
'</td><td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td><td> </td></tr>';
5612 print
'<tr><td colspan="'.$nbcols.
'" class="right"><span class="opacitymedium">'.$langs->trans(
"Billed").
'</span></td><td class="right">'.
price($sign *
$object->total_ttc).
'</td><td> </td></tr>';
5615 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5616 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
5617 if ($resteapayeraffiche > 0) {
5618 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5620 print
'</span></td>';
5621 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
5622 print
'<td class="nowrap"> </td></tr>';
5626 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5627 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
5628 if ($resteapayeraffiche > 0) {
5629 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5633 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.(!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency).
' '.
price(
price2num($sign *
$object->multicurrency_tx * $resteapayeraffiche,
'MT')).
'</td><td> </td></tr>';
5646 if (isModEnabled(
'margin')) {
5647 $formmargin->displayMarginInfos(
$object);
5653 print
'<div class="clearboth"></div><br><br>';
5656 $blocname =
'contacts';
5657 $title = $langs->trans(
'ContactsAddresses');
5658 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5662 $blocname =
'notes';
5663 $title = $langs->trans(
'Notes');
5664 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5668 $result =
$object->getLinesArray();
5672 global $inputalsopricewithtax;
5673 $inputalsopricewithtax = 1;
5678 print
'<!-- Area to change globally the situation percent -->'.
"\n";
5679 print
'<div class="div-table-responsive">';
5681 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'#updatealllines" method="POST">';
5682 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
5683 print
'<input type="hidden" name="action" value="updatealllines" />';
5684 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
5685 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5687 print
'<table id="tablelines_all_progress" class="noborder noshadow" width="100%">';
5689 print
'<tr class="liste_titre nodrag nodrop">';
5693 print
'<td align="center" width="5"> </td>';
5695 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
5696 print
'<td class="right">'.$langs->trans(
'Progress').
'</td>';
5697 print
'<td> </td>';
5700 print
'<tr class="nodrag nodrop">';
5703 print
'<td align="center" width="5"> </td>';
5705 print
'<td> </td>';
5706 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
5707 print
'<td class="right"><input type="submit" class="button" name="all_percent" value="Modifier" /></td>';
5718 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
5719 <input type="hidden" name="token" value="' .
newToken().
'">
5720 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
5721 <input type="hidden" name="mode" value="">
5722 <input type="hidden" name="page_y" value="">
5723 <input type="hidden" name="id" value="' .
$object->id.
'">
5724 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
5727 if (!empty(
$conf->use_javascript_ajax) &&
$object->status == 0) {
5728 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
5731 print
'<div class="div-table-responsive-no-min">';
5732 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
5736 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
5740 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
5741 if ($action !=
'editline' && $action !=
'selectlines') {
5744 $parameters = array();
5745 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
5749 if (empty($reshook)) {
5750 $object->formAddObjectLine(1, $mysoc, $soc);
5753 $parameters = array();
5754 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters,
$object, $action);
5768 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
5769 print
'<div class="tabsAction">';
5771 $parameters = array();
5772 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
5773 if (empty($reshook)) {
5776 'class' =>
'classfortooltip',
5783 $ventilExportCompta =
$object->getVentilExportCompta();
5785 if ($ventilExportCompta == 0) {
5787 if (!$objectidnext &&
$object->is_last_in_cycle()) {
5788 if ($usercanunvalidate) {
5789 unset($params[
'attr'][
'title']);
5790 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=modif&token='.
newToken(),
'',
true, $params);
5792 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
5793 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=modif&token='.
newToken(),
'',
false, $params);
5795 } elseif (!
$object->is_last_in_cycle()) {
5796 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
5797 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5799 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
5800 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5804 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5805 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5810 $result = $discount->fetch(0,
$object->id);
5818 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
5819 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
5820 unset($params[
'attr'][
'title']);
5821 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
5823 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
5824 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
5831 $langs->load(
"contracts");
5833 if ($usercancreatecontract) {
5834 print
'<a class="butAction" href="' . DOL_URL_ROOT .
'/contrat/card.php?action=create&origin=' .
$object->element .
'&originid=' .
$object->id .
'&socid=' .
$object->socid .
'">' . $langs->trans(
'AddContract') .
'</a>';
5841 if ($usercanvalidate) {
5842 unset($params[
'attr'][
'title']);
5843 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
5848 if (empty($user->socid)) {
5850 if ($objectidnext) {
5851 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'SendMail').
'</span>';
5854 unset($params[
'attr'][
'title']);
5855 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
5857 unset($params[
'attr'][
'title']);
5858 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
5866 if ($resteapayer > 0) {
5867 if ($usercancreatewithdrarequest) {
5868 if (!$objectidnext &&
$object->close_code !=
'replaced') {
5869 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/facture/prelevement.php?facid='.
$object->id.
'" title="'.
dol_escape_htmltag($langs->trans(
"MakeWithdrawRequest")).
'">'.$langs->trans(
"MakeWithdrawRequest").
'</a>';
5871 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
5882 if (isModEnabled(
'takepos') &&
$object->module_source ==
'takepos') {
5883 $langs->load(
"cashdesk");
5884 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
5885 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
5890 if ($objectidnext) {
5891 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
5895 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
5896 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
5900 unset($params[
'attr'][
'title']);
5901 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default', DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create'.(
$object->fk_account > 0 ?
'&accountid='.$object->fk_account :
''),
'', true, $params);
5906 $sumofpayment = $totalpaid;
5907 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
5913 if ($resteapayer == 0) {
5914 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
5916 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
5922 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
5926 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
5928 print
'<a class="butAction classfortooltip'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'" title="'.
dol_escape_htmltag($langs->trans(
"ConfirmConvertToReduc2")).
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
5935 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
5937 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
5951 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
5952 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
5954 unset($params[
'attr'][
'title']);
5955 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken(),
'',
true, $params);
5961 if ($totalpaid > 0 || $totalcreditnotes > 0) {
5963 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
5966 if ($objectidnext) {
5967 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
5969 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
5977 if (!$objectidnext) {
5978 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?socid='.
$object->socid.
'&fac_avoir='.
$object->id.
'&action=create&type=2'.(
$object->fk_project > 0 ?
'&projectid='.$object->fk_project :
'').(
$object->entity > 0 ?
'&originentity='.$object->entity :
'').
'">'.$langs->trans(
"CreateCreditNote").
'</a>';
5985 && (
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
5988 &&
$object->is_last_in_cycle()
5991 if ($usercanunvalidate) {
5992 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?socid='.
$object->socid.
'&fac_avoir='.
$object->id.
'&invoiceAvoirWithLines=1&action=create&type=2'.(
$object->fk_project > 0 ?
'&projectid='.$object->fk_project :
'').
'">'.$langs->trans(
"CreateCreditNote").
'</a>';
5994 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
6000 unset($params[
'attr'][
'title']);
6001 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice&token='.
newToken(),
'',
true, $params);
6006 if (!$objectidnext && count(
$object->lines) > 0) {
6007 unset($params[
'attr'][
'title']);
6008 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
6017 &&
$object->situation_counter > 1
6018 &&
$object->is_last_in_cycle()
6019 && $usercanunvalidate
6021 if ((
$object->total_ttc - $totalcreditnotes) == 0) {
6022 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6024 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6030 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
6031 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6032 } elseif (!
$object->is_last_in_cycle()) {
6033 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6035 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6040 $isErasable =
$object->is_erasable();
6042 if ($isErasable == -4) {
6043 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
6044 } elseif ($isErasable == -3) {
6045 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
6046 } elseif ($isErasable == -2) {
6047 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
6048 } elseif ($isErasable == -1) {
6049 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6050 } elseif ($isErasable <= 0) {
6051 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable');
6052 } elseif ($objectidnext) {
6053 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
6055 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
6056 $enableDelete =
false;
6058 if ($isErasable > 0 && ! $objectidnext) {
6059 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
6060 $enableDelete =
true;
6062 unset($params[
'attr'][
'title']);
6063 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
6065 unset($params[
'attr'][
'title']);
6066 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
6073 if (
GETPOST(
'modelselected',
'alpha')) {
6074 $action =
'presend';
6076 if ($action !=
'prerelance' && $action !=
'presend') {
6077 print
'<div class="fichecenter"><div class="fichehalfleft">';
6078 print
'<a name="builddoc"></a>';
6083 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
6084 $genallowed = $usercanread;
6085 $delallowed = $usercancreate;
6087 print $formfile->showdocuments(
6107 'remove_file_comfirm'
6110 $somethingshown = $formfile->numoffiles;
6113 $tmparray = $form->showLinkToObjectBlock(
$object, array(), array(
'invoice'), 1);
6114 $linktoelem = $tmparray[
'linktoelem'];
6115 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
6116 print $htmltoenteralink;
6118 $compatibleImportElementsList =
false;
6122 $compatibleImportElementsList = array(
'commande',
'propal');
6124 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem, $compatibleImportElementsList);
6128 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6129 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
6130 $useonlinepayment = count($validpaymentmethod);
6133 print
'<br><!-- Link to pay -->'.
"\n";
6134 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6135 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
6138 print
'</div><div class="fichehalfright">';
6142 $morehtmlcenter =
'<div class="nowraponall">';
6143 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullConversation'),
'',
'fa fa-comments imgforviewmode', DOL_URL_ROOT.
'/compta/facture/messaging.php?id='.
$object->id);
6144 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
6145 $morehtmlcenter .=
'</div>';
6148 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
6150 $somethingshown = $formactions->showactions(
$object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
6152 print
'</div></div>';
6157 $modelmail =
'facture_send';
6158 $defaulttopic =
'SendBillRef';
6159 $diroutput =
$conf->invoice->multidir_output[
$object->entity];
6160 $trackid =
'inv'.$object->id;
6162 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage bank accounts.
Class to manage accounting journals.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_DRAFT
Draft status.
const TYPE_STANDARD
Standard invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_PROFORMA
Proforma invoice (should not be used.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_DEPOSIT
Deposit invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const TYPE_CREDIT_NOTE
Credit note invoice.
const STATUS_CLOSED
Classified paid.
Class to manage invoice lines.
Class to manage invoice templates.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage the table of subscription to notifications.
Class to manage payments of customer invoices.
Class ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
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=null, $outputlangs=null, $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.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
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_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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 '.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
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.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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...
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.