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';
75$langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
76if (isModEnabled(
'incoterm')) {
77 $langs->load(
'incoterm');
79if (isModEnabled(
'margin')) {
80 $langs->load(
'margins');
87$action =
GETPOST(
'action',
'aZ09');
88$confirm =
GETPOST(
'confirm',
'alpha');
89$cancel =
GETPOST(
'cancel',
'alpha');
90$backtopage =
GETPOST(
'backtopage',
'alpha');
91$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
94$search_ref =
GETPOST(
'sf_ref',
'alpha') ?
GETPOST(
'sf_ref',
'alpha') :
GETPOST(
'search_ref',
'alpha');
95$search_societe =
GETPOST(
'search_societe',
'alpha');
96$search_montant_ht =
GETPOST(
'search_montant_ht',
'alpha');
97$search_montant_ttc =
GETPOST(
'search_montant_ttc',
'alpha');
98$origin =
GETPOST(
'origin',
'alpha');
105$selectedLines =
GETPOST(
'toselect',
'array');
121$extrafields->fetch_name_optionals_label(
$object->table_element);
124$total_global_ttc = 0;
125$displayWarranty =
false;
126$statusreplacement = 0;
128$price_base_type =
'';
129$array_options = array();
132if ($id > 0 || !empty($ref)) {
133 if ($action !=
'add') {
135 $fetch_situation =
false;
137 $fetch_situation =
true;
139 $ret =
$object->fetch($id, $ref,
'', 0, $fetch_situation);
140 if ($ret > 0 && isset(
$object->fk_project)) {
141 $ret =
$object->fetch_project();
147$hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
150$usercanread = $user->hasRight(
"facture",
"lire");
151$usercancreate = $user->hasRight(
"facture",
"creer");
152$usercanissuepayment = $user->hasRight(
"facture",
"paiement");
153$usercandelete = $user->hasRight(
"facture",
"supprimer") || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
154$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
157$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'validate')));
159$usercanreopen = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'reopen')));
161 $usercanreopen =
false;
163$usercanunvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'unvalidate')));
164$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
167$usercancreatemargin = $user->hasRight(
'margins',
'creer');
168$usercanreadallmargin = $user->hasRight(
'margins',
'liretous');
169$usercancreatewithdrarequest = $user->hasRight(
'prelevement',
'bons',
'creer');
171$permissionnote = $usercancreate;
172$permissiondellink = $usercancreate;
173$permissiontoedit = $usercancreate;
174$permissiontoadd = $usercancreate;
177$retainedWarrantyInvoiceAvailableType = array();
179 $retainedWarrantyInvoiceAvailableType = explode(
'+',
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY'));
184 $socid = $user->socid;
195$parameters = array(
'socid' => $socid);
196$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
201if (empty($reshook)) {
202 $backurlforlist = DOL_URL_ROOT.
'/compta/facture/list.php';
204 if (empty($backtopage) || ($cancel && empty($id))) {
205 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
206 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
207 $backtopage = $backurlforlist;
209 $backtopage = DOL_URL_ROOT.
'/compta/facture/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
215 if (!empty($backtopageforcancel)) {
216 header(
"Location: ".$backtopageforcancel);
218 } elseif (!empty($backtopage)) {
219 header(
"Location: ".$backtopage);
225 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
227 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
229 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
232 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
234 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'IdThirdParty')),
null,
'errors');
237 '@phan-var-force Facture $objectutil';
240 $objectutil->socid = $socid;
241 $result = $objectutil->createFromClone($user, $id);
243 $warningMsgLineList = array();
245 foreach ($objectutil->lines as $line) {
246 if (!is_object($line->product)) {
247 $line->fetch_product();
249 if (is_object($line->product) && $line->product->id > 0) {
250 if (empty($line->product->status)) {
251 $warningMsgLineList[$line->id] = $langs->trans(
'WarningLineProductNotToSell', $line->product->ref);
255 if (!empty($warningMsgLineList)) {
259 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?facid=' . $result);
262 $langs->load(
"errors");
267 } elseif ($action ==
'reopen' && $usercanreopen) {
271 $result =
$object->setUnpaid($user);
273 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
279 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
284 $idwarehouse =
GETPOST(
'idwarehouse');
286 $qualified_for_stock_change = 0;
288 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
290 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
293 $isErasable =
$object->is_erasable();
295 if (($usercandelete && $isErasable > 0)
296 || ($usercancreate && $isErasable == 1)) {
297 $result =
$object->delete($user, 0, $idwarehouse);
299 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
306 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
316 $outputlangs = $langs;
322 $newlang =
$object->thirdparty->default_lang;
324 if (!empty($newlang)) {
326 $outputlangs->setDefaultLang($newlang);
327 $outputlangs->load(
'products');
331 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
334 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
341 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
344 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
345 $discount->unlink_invoice();
346 } elseif ($action ==
'valid' && $usercancreate) {
350 if ((preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) &&
357 $last_of_type =
$object->willBeLastOfSameType(
true);
358 if (empty(
$object->date_validation) && !$last_of_type[0]) {
368 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
377 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
386 $array_of_total_ht_per_vat_rate = array();
387 $array_of_total_ht_devise_per_vat_rate = array();
388 foreach (
$object->lines as $line) {
390 $vat_src_code_for_line =
'';
391 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
392 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
394 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
395 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
397 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
398 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
402 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
403 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
404 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
406 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
407 if (
$object->type == $object::TYPE_DEPOSIT) {
408 $langs->load(
"errors");
410 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
414 $tmpvatratetoshow = explode(
'_', $vatrate);
415 $tmpvatratetoshow[0] = round((
float) $tmpvatratetoshow[0], 2);
417 if ($tmpvatratetoshow[0] != 0) {
418 $langs->load(
"errors");
419 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", $tmpvatratetoshow[0]),
null,
'errors');
427 } elseif ($action ==
'classin' && $usercancreate) {
430 } elseif ($action ==
'setmode' && $usercancreate) {
436 } elseif ($action ==
'setretainedwarrantyconditions' && $usercancreate) {
438 $object->retained_warranty_fk_cond_reglement = 0;
439 $result =
$object->setRetainedWarrantyPaymentTerms(
GETPOSTINT(
'retained_warranty_fk_cond_reglement'));
444 $old_rw_date_lim_reglement =
$object->retained_warranty_date_limit;
445 $new_rw_date_lim_reglement =
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
446 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
447 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
452 $result =
$object->update($user);
456 } elseif ($action ==
'setretainedwarranty' && $usercancreate) {
462 } elseif ($action ==
'setretainedwarrantydatelimit' && $usercancreate) {
464 $result =
$object->setRetainedWarrantyDateLimit(
GETPOSTFLOAT(
'retained_warranty_date_limit'));
468 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
469 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
470 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
472 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
474 $old_date_lim_reglement =
$object->date_lim_reglement;
476 if (empty($newdate)) {
477 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
478 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.
$id.
'&action=editinvoicedate&token='.
newToken());
483 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
485 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
490 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
491 if ($new_date_lim_reglement) {
492 $object->date_lim_reglement = $new_date_lim_reglement;
497 $result =
$object->update($user);
500 $action =
'editinvoicedate';
502 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
507 $object->date_pointoftax = $date_pointoftax;
508 $result =
$object->update($user);
512 } elseif ($action ==
'setconditions' && $usercancreate) {
514 $object->cond_reglement_code = 0;
515 $object->cond_reglement_id = 0;
530 $old_date_lim_reglement =
$object->date_lim_reglement;
531 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
532 if ($new_date_lim_reglement) {
533 $object->date_lim_reglement = $new_date_lim_reglement;
538 $result =
$object->update($user);
550 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
554 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
555 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
557 $result =
$object->update($user);
561 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
564 $result =
$object->update($user);
571 $outputlangs = $langs;
574 $newlang =
GETPOST(
'lang_id',
'aZ09');
577 $newlang =
$object->thirdparty->default_lang;
579 if (!empty($newlang)) {
581 $outputlangs->setDefaultLang($newlang);
582 $outputlangs->load(
'products');
587 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
593 } elseif ($action ==
'set_incoterms' && isModEnabled(
'incoterm') && $usercancreate) {
595 } elseif ($action ==
'setbankaccount' && $usercancreate) {
597 } elseif ($action ==
'setremisepercent' && $usercancreate) {
600 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
618 if (
GETPOSTINT(
"remise_id_for_payment") > 0) {
619 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
621 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
625 $remaintopay =
$object->getRemainToPay(0);
629 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
633 $result = $discount->link_to_invoice(0, $id);
641 $newremaintopay =
$object->getRemainToPay(0);
642 if ($newremaintopay == 0) {
655 $outputlangs = $langs;
658 $newlang =
GETPOST(
'lang_id',
'aZ09');
662 $newlang =
$object->thirdparty->default_lang;
664 if (!empty($newlang)) {
666 $outputlangs->setDefaultLang($newlang);
670 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
675 } elseif ($action ==
'setref' && $usercancreate) {
677 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', 0,
'',
'', $user,
'BILL_MODIFY');
678 } elseif ($action ==
'setref_client' && $usercancreate) {
681 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
690 $qualified_for_stock_change = 0;
692 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
694 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
697 if ($qualified_for_stock_change) {
698 if (!$idwarehouse || $idwarehouse == - 1) {
700 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
707 $result =
$object->validate($user,
'', $idwarehouse);
711 $outputlangs = $langs;
714 $newlang =
GETPOST(
'lang_id',
'aZ09');
717 $newlang =
$object->thirdparty->default_lang;
719 if (!empty($newlang)) {
721 $outputlangs->setDefaultLang($newlang);
722 $outputlangs->load(
'products');
728 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
741 } elseif ($action ==
'confirm_modif' && $usercanunvalidate) {
750 $qualified_for_stock_change = 0;
752 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
754 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
757 if ($qualified_for_stock_change) {
758 if (!$idwarehouse || $idwarehouse == - 1) {
760 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
769 $sql =
'SELECT pf.amount';
770 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf';
771 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
773 $result = $db->query($sql);
776 $num = $db->num_rows($result);
779 $objp = $db->fetch_object($result);
780 $totalpaid += $objp->amount;
787 $resteapayer =
$object->total_ttc - $totalpaid;
790 $ventilExportCompta =
$object->getVentilExportCompta();
793 if ($ventilExportCompta == 0) {
795 $result =
$object->setDraft($user, $idwarehouse);
802 $outputlangs = $langs;
805 $newlang =
GETPOST(
'lang_id',
'aZ09');
808 $newlang =
$object->thirdparty->default_lang;
810 if (!empty($newlang)) {
812 $outputlangs->setDefaultLang($newlang);
813 $outputlangs->load(
'products');
818 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
823 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
826 $result =
$object->setPaid($user);
830 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
833 $close_code =
GETPOST(
"close_code",
'restricthtml');
834 $close_note =
GETPOST(
"close_note",
'restricthtml');
836 $result =
$object->setPaid($user, $close_code, $close_note);
841 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
843 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
846 $close_code =
GETPOST(
"close_code",
'restricthtml');
847 $close_note =
GETPOST(
"close_note",
'restricthtml');
849 $result =
$object->setCanceled($user, $close_code, $close_note);
854 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
856 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
864 $result = $discountcheck->fetch(0,
$object->id);
877 $amount_ht = $amount_tva = $amount_ttc = array();
878 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
882 foreach (
$object->lines as $line) {
883 if ($line->product_type < 9 && $line->total_ht != 0) {
884 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
886 $amount_ht[$keyforvatrate] += $line->total_ht;
887 $amount_tva[$keyforvatrate] += $line->total_tva;
888 $amount_ttc[$keyforvatrate] += $line->total_ttc;
889 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
890 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
891 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
895 '@phan-var-force array<string,float> $amount_ht
896 @phan-var-force array<string,float> $amount_tva
897 @phan-var-force array<string,float> $amount_ttc
898 @phan-var-force array<string,float> $multicurrency_amount_ht
899 @phan-var-force array<string,float> $multicurrency_amount_tva
900 @phan-var-force array<string,float> $multicurrency_amount_ttc';
904 $alreadypaid =
$object->getSommePaiement();
905 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
906 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
907 foreach ($amount_ht as $vatrate => $val) {
908 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
909 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
910 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
911 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
912 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
913 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
922 $discount->description =
'(CREDIT_NOTE)';
924 $discount->description =
'(DEPOSIT)';
926 $discount->description =
'(EXCESS RECEIVED)';
928 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
930 $discount->fk_soc =
$object->socid;
931 $discount->socid =
$object->socid;
932 $discount->fk_facture_source =
$object->id;
940 $sql =
'SELECT SUM(pf.amount) as total_paiements';
941 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
942 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
943 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
944 $sql .=
' AND pf.fk_paiement = p.rowid';
945 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
946 $resql = $db->query($sql);
951 $res = $db->fetch_object($resql);
952 $total_paiements = $res->total_paiements;
955 $total_creditnote_and_deposit = 0;
956 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
957 $sql .=
" re.description, re.fk_facture_source";
958 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
959 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
960 $resql = $db->query($sql);
961 if (!empty($resql)) {
962 while ($obj = $db->fetch_object($resql)) {
963 $total_creditnote_and_deposit += $obj->amount_ttc;
969 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
970 $discount->amount_tva = 0;
971 $discount->tva_tx = 0;
972 $discount->vat_src_code =
'';
974 $result = $discount->create($user);
980 foreach ($amount_ht as $tva_tx => $xxx) {
981 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
982 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
983 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
984 $discount->multicurrency_amount_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
985 $discount->multicurrency_amount_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
986 $discount->multicurrency_amount_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
991 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
992 $vat_src_code = $reg[1];
993 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
996 $discount->tva_tx = abs((
float) $tva_tx);
997 $discount->vat_src_code = $vat_src_code;
999 $result = $discount->create($user);
1007 if (empty($error)) {
1010 $result =
$object->setPaid($user);
1025 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
1030 $result = $paiement->fetch(
GETPOSTINT(
'paiement_id'));
1032 $result = $paiement->delete($user);
1034 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1042 } elseif ($action ==
'add' && $usercancreate) {
1049 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1057 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
1067 if (empty($dateinvoice)) {
1069 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1079 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1089 $object->date_pointoftax = $date_pointoftax;
1090 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1091 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1102 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1103 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1120 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1122 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1126 if (empty($dateinvoice)) {
1128 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1138 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1143 if (!empty($originentity)) {
1144 $object->entity = $originentity;
1150 $object->date_pointoftax = $date_pointoftax;
1151 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1152 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1157 $object->cond_reglement_id = 0;
1163 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1164 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1168 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1171 $facture_source =
new Facture($db);
1172 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1174 $object->situation_counter = $facture_source->situation_counter;
1175 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1176 $facture_source->fetchPreviousNextSituationInvoice();
1186 if (
$object->copy_linked_contact($facture_source,
'internal') < 0) {
1188 } elseif ($facture_source->socid ==
$object->socid) {
1190 if (
$object->copy_linked_contact($facture_source,
'external') < 0) {
1201 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1202 if (!empty($facture_source->lines)) {
1203 $fk_parent_line = 0;
1205 foreach ($facture_source->lines as $line) {
1207 if (method_exists($line,
'fetch_optionals')) {
1209 $line->fetch_optionals();
1213 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1214 $fk_parent_line = 0;
1219 $source_fk_prev_id = $line->fk_prev_id;
1220 $line->fk_prev_id = $line->id;
1222 if (!empty($facture_source->tab_previous_situation_invoice)) {
1225 $tab_jumped_credit_notes = array();
1226 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1227 $searchPreviousInvoice =
true;
1228 while ($searchPreviousInvoice) {
1229 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1230 $searchPreviousInvoice =
false;
1234 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1240 $maxPrevSituationPercent = 0;
1241 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1242 if ($prevLine->id == $source_fk_prev_id) {
1243 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1246 $line->total_ht -= $prevLine->total_ht;
1247 $line->total_tva -= $prevLine->total_tva;
1248 $line->total_ttc -= $prevLine->total_ttc;
1249 $line->total_localtax1 -= $prevLine->total_localtax1;
1250 $line->total_localtax2 -= $prevLine->total_localtax2;
1252 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1253 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1254 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1255 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1260 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1265 $maxPrevSituationPercent = 0;
1266 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1267 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1268 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1269 $maxPrevSituationPercent = $prevLine->situation_percent;
1271 $line->total_ht -= $prevLine->total_ht;
1272 $line->total_tva -= $prevLine->total_tva;
1273 $line->total_ttc -= $prevLine->total_ttc;
1274 $line->total_localtax1 -= $prevLine->total_localtax1;
1275 $line->total_localtax2 -= $prevLine->total_localtax2;
1277 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1278 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1279 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1280 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1286 $line->situation_percent += $maxPrevSituationPercent;
1292 $line->fk_facture =
$object->id;
1293 $line->fk_parent_line = $fk_parent_line;
1295 $line->subprice = -$line->subprice;
1297 $line->total_ht = -$line->total_ht;
1298 $line->total_tva = -$line->total_tva;
1299 $line->total_ttc = -$line->total_ttc;
1300 $line->total_localtax1 = -$line->total_localtax1;
1301 $line->total_localtax2 = -$line->total_localtax2;
1303 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1304 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1305 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1306 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1308 $line->context[
'createcreditnotefrominvoice'] = 1;
1309 $result = $line->insert(0, 1);
1314 if ($result > 0 && $line->product_type == 9) {
1315 $fk_parent_line = $result;
1323 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1324 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1325 $totalpaid = $facture_source->getSommePaiement();
1326 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1327 $totaldeposits = $facture_source->getSumDepositsUsed();
1328 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1330 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1331 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1334 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1339 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1340 $tva_tx = (float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY');
1345 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC');
1350 if (!empty(
$object->fk_facture_source) &&
$id > 0) {
1351 $facture_source->fetch(
$object->fk_facture_source);
1352 $facture_source->fetchObjectLinked();
1354 if (!empty($facture_source->linkedObjectsIds)) {
1355 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1356 $object->add_object_linked($sourcetype, current($TIds));
1365 if (empty($dateinvoice)) {
1367 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1378 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1388 $object->date_pointoftax = $date_pointoftax;
1389 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1390 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1402 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1403 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1415 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1416 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1417 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1421 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1425 if (empty($dateinvoice)) {
1427 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1437 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1438 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1443 if ($typeamount && !empty($origin) && !empty($originid)) {
1444 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1445 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1449 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1450 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1454 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1455 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1465 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1475 $object->date_pointoftax = $date_pointoftax;
1476 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1477 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1489 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1490 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1494 $object->situation_counter = 1;
1499 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1501 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1503 $object->retained_warranty = 0;
1504 $object->retained_warranty_fk_cond_reglement = 0;
1507 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1508 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1511 $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);
1516 if (!empty($origin) && !empty($originid)) {
1519 $element = $subelement = $origin;
1520 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1521 $element = $regs[1];
1522 $subelement = $regs[2];
1526 if ($element ==
'order') {
1527 $element = $subelement =
'commande';
1529 if ($element ==
'propal') {
1530 $element =
'comm/propal';
1531 $subelement =
'propal';
1533 if ($element ==
'contract') {
1534 $element = $subelement =
'contrat';
1536 if ($element ==
'inter') {
1537 $element = $subelement =
'fichinter';
1539 if ($element ==
'shipping') {
1540 $element = $subelement =
'expedition';
1544 $object->origin_type = $origin;
1545 $object->origin_id = $originid;
1550 if (
$object->origin ==
'shipping') {
1551 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1553 $exp->fetch(
$object->origin_id);
1554 $exp->fetchObjectLinked();
1555 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1556 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1557 $object->linked_objects[
'commande'] = $value;
1563 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
1571 $classname = ucfirst($subelement);
1572 $srcobject =
new $classname($db);
1573 '@phan-var-force CommonObject $srcobject';
1575 dol_syslog(
"Try to find source object origin=".
$object->origin.
" originid=".
$object->origin_id.
" to add lines or deposit lines");
1576 $result = $srcobject->fetch(
$object->origin_id);
1581 $amountdeposit = array();
1583 if ($typeamount ==
'amount') {
1584 $amount = (float) $valuedeposit;
1586 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1589 $TTotalByTva = array();
1590 foreach ($srcobject->lines as &$line) {
1591 if (empty($line->qty)) {
1594 if (!empty($line->special_code)) {
1597 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1599 '@phan-var-force array<string,float> $TTotalByTva';
1601 $amount_ttc_diff = 0.;
1602 foreach ($TTotalByTva as $tva => &$total) {
1603 $coef = $total / $srcobject->total_ttc;
1604 $am = $amount * $coef;
1605 $amount_ttc_diff += $am;
1606 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1609 if ($typeamount ==
'amount') {
1610 $amountdeposit[0] = $valuedeposit;
1611 } elseif ($typeamount ==
'variable') {
1614 $lines = $srcobject->lines;
1615 $numlines = count($lines);
1616 for ($i = 0; $i < $numlines; $i++) {
1618 if (empty($lines[$i]->qty)) {
1621 if (!empty($lines[$i]->special_code)) {
1625 $totalamount += $lines[$i]->total_ht;
1626 $tva_tx = $lines[$i]->tva_tx;
1627 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1631 if ($totalamount == 0) {
1632 $amountdeposit[0] = 0;
1640 $amount_ttc_diff = $amountdeposit[0];
1643 foreach ($amountdeposit as $tva => $amount) {
1644 if (empty($amount)) {
1649 'amount' =>
'FixAmount',
1650 'variable' =>
'VarAmount'
1652 $descline =
'(DEPOSIT)';
1654 if ($typeamount ==
'amount') {
1655 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code : $conf->currency)).
')';
1656 } elseif ($typeamount ==
'variable') {
1657 $descline .=
' ('.$valuedeposit.
'%)';
1660 $descline .=
' - '.$srcobject->ref;
1673 $lines[$i]->info_bits,
1679 $lines[$i]->special_code,
1692 (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) ? 0 : 1)
1696 $diff =
$object->total_ttc - $amount_ttc_diff;
1700 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1701 $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);
1708 $lines = $srcobject->lines;
1709 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1710 $srcobject->fetch_lines();
1711 $lines = $srcobject->lines;
1716 if (is_array($lines)) {
1717 foreach ($lines as $line) {
1719 $line->qty =
price2num((
float) $line->qty * (
float) $valuestandardinvoice / 100,
'MS');
1725 if (is_array($lines)) {
1726 foreach ($lines as $line) {
1728 $line->qty =
price2num((
float) $line->qty * (
float) $valuedeposit / 100,
'MS');
1733 $fk_parent_line = 0;
1734 $num = count($lines);
1736 for ($i = 0; $i < $num; $i++) {
1737 if (!in_array($lines[$i]->
id, $selectedLines)) {
1742 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
1746 if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1747 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1749 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
1753 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1754 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1756 if (
$object->situation_counter == 1) {
1757 $lines[$i]->situation_percent = 0;
1760 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
1763 $desc = $label ? $label : $langs->trans(
'Discount');
1767 $discount->fk_soc =
$object->socid;
1768 $discount->socid =
$object->socid;
1769 $discount->amount_ht = abs($lines[$i]->total_ht);
1770 $discount->amount_tva = abs($lines[$i]->total_tva);
1771 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1772 $discount->tva_tx = $lines[$i]->tva_tx;
1773 $discount->fk_user = $user->id;
1774 $discount->description = $desc;
1775 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1776 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1777 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1778 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1780 $discountid = $discount->create($user);
1781 if ($discountid > 0) {
1782 $result =
$object->insert_discount($discountid);
1794 $date_start =
false;
1795 if (isset($lines[$i]->date_debut_prevue)) {
1796 $date_start = $lines[$i]->date_debut_prevue;
1798 if (isset($lines[$i]->date_debut_reel)) {
1799 $date_start = $lines[$i]->date_debut_reel;
1801 if (isset($lines[$i]->date_start)) {
1802 $date_start = $lines[$i]->date_start;
1807 if (isset($lines[$i]->date_fin_prevue)) {
1808 $date_end = $lines[$i]->date_fin_prevue;
1810 if (isset($lines[$i]->date_fin_reel)) {
1811 $date_end = $lines[$i]->date_fin_reel;
1813 if (isset($lines[$i]->date_end)) {
1814 $date_end = $lines[$i]->date_end;
1818 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1819 $fk_parent_line = 0;
1823 if (method_exists($lines[$i],
'fetch_optionals')) {
1824 $lines[$i]->fetch_optionals();
1825 $array_options = $lines[$i]->array_options;
1828 $tva_tx = $lines[$i]->tva_tx;
1829 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
1830 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1840 $lines[$i]->subprice,
1845 $lines[$i]->fk_product,
1846 $lines[$i]->remise_percent,
1850 $lines[$i]->info_bits,
1851 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except : null,
1856 $lines[$i]->special_code,
1860 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice : null,
1864 $lines[$i]->situation_percent ?? 100,
1865 $lines[$i]->fk_prev_id ?? 0,
1866 $lines[$i]->fk_unit,
1881 if ($result > 0 && $lines[$i]->product_type == 9) {
1882 $fk_parent_line = $result;
1892 $object->update_price(1,
'auto', 0, $mysoc);
1920 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id,
'objFrom' => $srcobject);
1921 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
1934 for ($i = 1; $i <= $NBLINES; $i++) {
1940 $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);
1944 $object->update_price(1,
'auto', 0, $mysoc);
1951 if (empty($dateinvoice)) {
1953 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
1963 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
1973 if (!empty($origin) && !empty($originid)) {
1974 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1977 $object->origin_type = $origin;
1978 $object->origin_id = $originid;
1982 $retained_warranty =
GETPOSTINT(
'retained_warranty');
1983 if (
price2num($retained_warranty) > 0) {
1987 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
1988 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1991 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1992 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
1993 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
1995 $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);
1998 foreach (
$object->lines as $i => &$line) {
1999 $line->fk_prev_id = $line->id;
2000 $line->fetch_optionals();
2002 $line->situation_percent = $line->getAllPrevProgress(
$object->id);
2004 $line->situation_percent = $line->get_prev_progress(
$object->id);
2008 $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);
2009 $line->total_ht = $tabprice[0];
2010 $line->total_tva = $tabprice[1];
2011 $line->total_ttc = $tabprice[2];
2012 $line->total_localtax1 = $tabprice[9];
2013 $line->total_localtax2 = $tabprice[10];
2014 $line->multicurrency_total_ht = $tabprice[16];
2015 $line->multicurrency_total_tva = $tabprice[17];
2016 $line->multicurrency_total_ttc = $tabprice[18];
2019 if ($line->fk_remise_except) {
2021 $result = $discount->fetch($line->fk_remise_except);
2024 if ($discount->fk_facture_line > 0) {
2025 $line->fk_remise_except = 0;
2034 $object->date_pointoftax = $date_pointoftax;
2035 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2051 $object->situation_counter += 1;
2057 $nextSituationInvoice =
new Facture($db);
2058 $nextSituationInvoice->fetch($id);
2061 $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
2062 $ret = $extrafields->setOptionalsFromPost(
null, $nextSituationInvoice);
2064 $nextSituationInvoice->insertExtraFields();
2068 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id);
2069 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $nextSituationInvoice, $action);
2080 if ($id > 0 && !$error) {
2085 $outputlangs = $langs;
2088 $newlang =
GETPOST(
'lang_id',
'aZ09');
2091 $newlang =
$object->thirdparty->default_lang;
2093 if (!empty($newlang)) {
2094 $outputlangs =
new Translate(
"", $conf);
2095 $outputlangs->setDefaultLang($newlang);
2096 $outputlangs->load(
'products');
2101 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2107 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2112 $_GET[
"origin"] = $_POST[
"origin"];
2113 $_GET[
"originid"] = $_POST[
"originid"];
2116 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2120 foreach (
$object->lines as $line) {
2121 if ($line->product_type == 1) {
2122 $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);
2125 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2127 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2128 $vat_rate = str_replace(
'*',
'', $vat_rate);
2131 foreach (
$object->lines as $line) {
2132 $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);
2134 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2136 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2137 $remise_percent = str_replace(
'*',
'', $remise_percent);
2138 foreach (
$object->lines as $line) {
2139 $tvatx = $line->tva_tx;
2140 if (!empty($line->vat_src_code)) {
2141 $tvatx .=
' ('.$line->vat_src_code.
')';
2143 $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);
2145 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && $usercancreate) {
2146 $langs->load(
'errors');
2151 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
2154 $price_ht_devise =
'';
2156 $price_ttc_devise =
'';
2158 $price_min_ttc =
'';
2160 if (
GETPOST(
'price_ht') !==
'') {
2163 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2166 if (
GETPOST(
'price_ttc') !==
'') {
2169 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2170 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2173 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2174 if ($prod_entry_mode ==
'free') {
2180 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2185 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2188 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
2189 if (empty($remise_percent)) {
2190 $remise_percent = 0;
2194 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2195 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2197 if (is_array($extralabelsline)) {
2199 foreach ($extralabelsline as $key => $value) {
2200 unset($_POST[
"options_".$key.$predef]);
2204 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2205 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2208 if (!$prod_entry_mode) {
2210 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2214 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2215 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2218 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) {
2219 if (($price_ht < 0 || $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2220 $langs->load(
"errors");
2221 if (
$object->type == $object::TYPE_DEPOSIT) {
2223 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2225 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2229 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2234 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2237 if ($prod_entry_mode ==
'free' && empty($idprod) && empty($product_desc)) {
2238 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2242 $langs->load(
"errors");
2243 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2247 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2248 if ($combinations =
GETPOST(
'combinations',
'array')) {
2252 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2253 $idprod = $res->fk_product_child;
2255 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2261 $price_base_type =
null;
2262 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
2268 $ret =
$object->fetch_thirdparty();
2273 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2284 if (!empty($idprod) && $idprod > 0) {
2286 $prod->fetch($idprod);
2288 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2293 $datapriceofproduct = $prod->getSellPrice($mysoc,
$object->thirdparty, $pqp);
2295 $pu_ht = $datapriceofproduct[
'pu_ht'];
2296 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2297 $price_min = $datapriceofproduct[
'price_min'];
2298 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2299 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2303 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2304 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $prod->tva_tx));
2308 if (!empty($price_ht) || $price_ht ===
'0') {
2310 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2311 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2312 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2315 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2317 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2318 } elseif ($tmpvat != $tmpprodvat) {
2320 if ($price_base_type !=
'HT') {
2321 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2323 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2331 $outputlangs = $langs;
2333 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
2334 $newlang =
GETPOST(
'lang_id',
'aZ09');
2336 if (empty($newlang)) {
2337 $newlang =
$object->thirdparty->default_lang;
2339 if (!empty($newlang)) {
2340 $outputlangs =
new Translate(
"", $conf);
2341 $outputlangs->setDefaultLang($newlang);
2342 $outputlangs->load(
'products');
2345 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->
description;
2347 $desc = $prod->description;
2356 $desc = $product_desc;
2362 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
2366 $outputlangs = $langs;
2368 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
2369 $newlang =
GETPOST(
'lang_id',
'alpha');
2371 if (empty($newlang)) {
2372 $newlang =
$object->thirdparty->default_lang;
2374 if (!empty($newlang)) {
2375 $outputlangs =
new Translate(
"", $conf);
2376 $outputlangs->setDefaultLang($newlang);
2377 $outputlangs->load(
'products');
2379 if (!empty($prod->customcode)) {
2380 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2382 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2385 if (!empty($prod->country_code)) {
2386 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $outputlangs, 0);
2389 if (!empty($prod->customcode)) {
2390 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2392 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2395 if (!empty($prod->country_code)) {
2396 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $langs, 0);
2403 $type = $prod->type;
2404 $fk_unit = $prod->fk_unit;
2406 if (!empty($price_ht)) {
2411 if (!empty($price_ttc)) {
2416 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2417 $tva_tx = str_replace(
'*',
'', $tva_tx);
2418 if (empty($tva_tx)) {
2421 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2422 $desc = $product_desc;
2424 $fk_unit =
GETPOST(
'units',
'alpha');
2426 if ($pu_ttc && !$pu_ht) {
2427 $price_base_type =
'TTC';
2441 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2442 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2445 $pu_equivalent = $pu_ht;
2446 $pu_equivalent_ttc = $pu_ttc;
2448 $currency_tx =
$object->multicurrency_tx;
2452 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2453 $pu_equivalent = (float) $pu_ht_devise * $currency_tx;
2455 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2456 $pu_equivalent_ttc = (float) $pu_ttc_devise * $currency_tx;
2476 $price2num_remise_percent =
price2num($remise_percent);
2477 $price2num_price_min =
price2num($price_min);
2478 $price2num_price_min_ttc =
price2num($price_min_ttc);
2479 if (empty($price2num_pu_ht)) {
2480 $price2num_pu_ht = 0;
2482 if (empty($price2num_remise_percent)) {
2483 $price2num_remise_percent = 0;
2485 if (empty($price2num_price_min)) {
2486 $price2num_price_min = 0;
2488 if (empty($price2num_price_min_ttc)) {
2489 $price2num_price_min_ttc = 0;
2494 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2495 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2498 } 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') {
2499 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2506 '@phan-var-force CommonObjectLine[] $lines';
2508 if (isModEnabled(
'productbatch') && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) &&
getDolGlobalString(
'INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS')) {
2509 $langs->load(
'productbatch');
2510 foreach ($lines[$i]->detail_batch as $batchline) {
2511 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2516 $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);
2521 $outputlangs = $langs;
2524 $newlang =
GETPOST(
'lang_id',
'aZ09');
2527 $newlang =
$object->thirdparty->default_lang;
2529 if (!empty($newlang)) {
2530 $outputlangs =
new Translate(
"", $conf);
2531 $outputlangs->setDefaultLang($newlang);
2532 $outputlangs->load(
'products');
2537 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2543 unset($_POST[
'prod_entry_mode']);
2544 unset($_POST[
'qty']);
2545 unset($_POST[
'type']);
2546 unset($_POST[
'remise_percent']);
2547 unset($_POST[
'price_ht']);
2548 unset($_POST[
'multicurrency_price_ht']);
2549 unset($_POST[
'price_ttc']);
2550 unset($_POST[
'tva_tx']);
2551 unset($_POST[
'product_ref']);
2552 unset($_POST[
'product_label']);
2553 unset($_POST[
'product_desc']);
2554 unset($_POST[
'fournprice']);
2555 unset($_POST[
'buying_price']);
2556 unset($_POST[
'np_marginRate']);
2557 unset($_POST[
'np_markRate']);
2558 unset($_POST[
'dp_desc']);
2559 unset($_POST[
'idprod']);
2560 unset($_POST[
'units']);
2561 unset($_POST[
'date_starthour']);
2562 unset($_POST[
'date_startmin']);
2563 unset($_POST[
'date_startsec']);
2564 unset($_POST[
'date_startday']);
2565 unset($_POST[
'date_startmonth']);
2566 unset($_POST[
'date_startyear']);
2567 unset($_POST[
'date_endhour']);
2568 unset($_POST[
'date_endmin']);
2569 unset($_POST[
'date_endsec']);
2570 unset($_POST[
'date_endday']);
2571 unset($_POST[
'date_endmonth']);
2572 unset($_POST[
'date_endyear']);
2573 unset($_POST[
'situations']);
2574 unset($_POST[
'progress']);
2582 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2583 if (!
$object->fetch($id) > 0) {
2595 $vat_rate = str_replace(
'*',
'', $vat_rate);
2607 if (preg_match(
'/\*/', $vat_rate)) {
2612 $vat_rate = str_replace(
'*',
'', $vat_rate);
2621 $pu_equivalent = $pu_ht;
2622 $pu_equivalent_ttc = $pu_ttc;
2624 $currency_tx =
$object->multicurrency_tx;
2628 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2629 $pu_equivalent = (float) $pu_ht_devise * (
float) $currency_tx;
2631 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2632 $pu_equivalent_ttc = (float) $pu_ttc_devise * (
float) $currency_tx;
2647 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2648 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
2650 if (is_array($extralabelsline)) {
2652 foreach ($extralabelsline as $key => $value) {
2653 unset($_POST[
"options_".$key]);
2659 if ($special_code == 3) {
2665 $percent = $line->get_prev_progress(
$object->id);
2670 if ($progress >= 0) {
2671 $mesg = $langs->trans(
"CantBeNullOrPositive");
2675 } elseif ($progress < $line->situation_percent) {
2676 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
2680 } elseif ($progress < $percent) {
2681 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
2692 if (!empty($productid)) {
2694 $product->fetch($productid);
2696 $type = $product->type;
2698 $price_min = $product->price_min;
2700 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
2702 $price_min_ttc = $product->price_min_ttc;
2704 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
2711 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
2712 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2715 $action =
'editline';
2716 } 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') {
2717 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2720 $action =
'editline';
2725 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2729 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
2734 $langs->load(
"errors");
2735 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2739 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2740 $langs->load(
"errors");
2741 if (
$object->type == $object::TYPE_DEPOSIT) {
2743 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2745 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2749 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2756 $previousprogress = $line->getAllPrevProgress($line->fk_facture);
2759 if ($fullprogress < $previousprogress) {
2761 setEventMessages($langs->trans(
'CantBeLessThanMinPercent'),
null,
'errors');
2765 if ($fullprogress > 100) {
2766 $fullprogress = 100;
2768 $addprogress = $fullprogress - $previousprogress;
2775 if (empty($usercancreatemargin)) {
2776 foreach (
$object->lines as &$line) {
2778 $fournprice = $line->fk_fournprice;
2779 $buyingprice = $line->pa_ht;
2785 $price_base_type =
'HT';
2787 if (empty($pu) && !empty($pu_ttc)) {
2789 $price_base_type =
'TTC';
2792 $result =
$object->updateline(
2821 $outputlangs = $langs;
2824 $newlang =
GETPOST(
'lang_id',
'aZ09');
2827 $newlang =
$object->thirdparty->default_lang;
2829 if (!empty($newlang)) {
2830 $outputlangs =
new Translate(
"", $conf);
2831 $outputlangs->setDefaultLang($newlang);
2832 $outputlangs->load(
'products');
2836 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2839 unset($_POST[
'qty']);
2840 unset($_POST[
'type']);
2841 unset($_POST[
'productid']);
2842 unset($_POST[
'remise_percent']);
2843 unset($_POST[
'price_ht']);
2844 unset($_POST[
'multicurrency_price_ht']);
2845 unset($_POST[
'price_ttc']);
2846 unset($_POST[
'tva_tx']);
2847 unset($_POST[
'product_ref']);
2848 unset($_POST[
'product_label']);
2849 unset($_POST[
'product_desc']);
2850 unset($_POST[
'fournprice']);
2851 unset($_POST[
'buying_price']);
2852 unset($_POST[
'np_marginRate']);
2853 unset($_POST[
'np_markRate']);
2854 unset($_POST[
'dp_desc']);
2855 unset($_POST[
'idprod']);
2856 unset($_POST[
'units']);
2857 unset($_POST[
'date_starthour']);
2858 unset($_POST[
'date_startmin']);
2859 unset($_POST[
'date_startsec']);
2860 unset($_POST[
'date_startday']);
2861 unset($_POST[
'date_startmonth']);
2862 unset($_POST[
'date_startyear']);
2863 unset($_POST[
'date_endhour']);
2864 unset($_POST[
'date_endmin']);
2865 unset($_POST[
'date_endsec']);
2866 unset($_POST[
'date_endday']);
2867 unset($_POST[
'date_endmonth']);
2868 unset($_POST[
'date_endyear']);
2869 unset($_POST[
'situations']);
2870 unset($_POST[
'progress']);
2875 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modifier')) {
2876 if (!
$object->fetch($id) > 0) {
2879 if (
GETPOST(
'all_progress') !=
"") {
2881 foreach (
$object->lines as $line) {
2883 $percent = $line->getAllPrevProgress(
$object->id);
2885 $percent = $line->get_prev_progress(
$object->id);
2887 if ((
float) $all_progress < (
float) $percent) {
2888 $mesg = $langs->trans(
"Line").
' '.$i.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
2897 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
2898 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2900 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
2902 $object->fetch($id,
'',
'', 0,
true);
2908 &&
$object->is_last_in_cycle()
2909 && $usercanunvalidate
2912 $newCycle =
$object->newCycle();
2913 if ($newCycle > 1) {
2915 $lastCycle =
$object->situation_cycle_ref;
2916 $lastSituationCounter =
$object->situation_counter;
2917 $linkedCreditNotesList = array();
2919 if (count(
$object->tab_next_situation_invoice) > 0) {
2920 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
2922 && $next_invoice->situation_counter ==
$object->situation_counter
2923 && $next_invoice->fk_facture_source ==
$object->id
2925 $linkedCreditNotesList[] = $next_invoice->id;
2930 $object->situation_cycle_ref = $newCycle;
2931 $object->situation_counter = 1;
2933 if (
$object->update($user) > 0) {
2935 if (count($linkedCreditNotesList) > 0) {
2937 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
2938 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
2939 $sql .=
' , situation_final=0';
2940 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
2941 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
2943 $resql = $db->query($sql);
2949 foreach (
$object->lines as $line) {
2951 if ($line->product_type == 9) {
2956 if (!empty(
$object->tab_previous_situation_invoice)) {
2958 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
2959 $searchPreviousInvoice =
true;
2960 while ($searchPreviousInvoice) {
2962 $searchPreviousInvoice =
false;
2970 $maxPrevSituationPercent = 0;
2971 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
2972 if ($prevLine->id == $line->fk_prev_id) {
2973 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
2978 $line->situation_percent -= $maxPrevSituationPercent;
2980 if ($line->update() < 0) {
2989 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
2991 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
2994 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
2997 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
3003 $fromElement =
GETPOST(
'fromelement');
3004 $fromElementid =
GETPOST(
'fromelementid');
3005 $importLines =
GETPOST(
'line_checkbox');
3007 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
3008 $lineClassName =
'';
3009 if ($fromElement ==
'commande') {
3011 $lineClassName =
'OrderLine';
3012 } elseif ($fromElement ==
'propal') {
3013 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
3014 $lineClassName =
'PropaleLigne';
3016 $nextRang = count(
$object->lines) + 1;
3019 foreach ($importLines as $lineId) {
3020 if ($lineClassName ===
'') {
3024 dol_syslog(
'compta/facture/card - No lineClassName - skip import', LOG_ERR);
3031 $lineId = intval($lineId);
3032 $originLine =
new $lineClassName($db);
3033 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
3034 $originLine->fetch_optionals();
3035 $desc = $originLine->desc;
3036 $pu_ht = $originLine->subprice;
3037 $qty = $originLine->qty;
3038 $txtva = $originLine->tva_tx;
3039 $txlocaltax1 = $originLine->localtax1_tx;
3040 $txlocaltax2 = $originLine->localtax2_tx;
3041 $fk_product = $originLine->fk_product;
3042 $remise_percent = $originLine->remise_percent;
3043 $date_start = $originLine->date_start;
3044 $date_end = $originLine->date_end;
3045 $fk_code_ventilation = 0;
3046 $info_bits = $originLine->info_bits;
3047 $fk_remise_except = $originLine->fk_remise_except;
3048 $price_base_type =
'HT';
3050 $type = $originLine->product_type;
3051 $rang = $nextRang++;
3052 $special_code = $originLine->special_code;
3053 $origin = $originLine->element;
3054 $origin_id = $originLine->id;
3055 $fk_parent_line = 0;
3056 $fk_fournprice = $originLine->fk_fournprice;
3057 $pa_ht = $originLine->pa_ht;
3058 $label = $originLine->label;
3059 $array_options = $originLine->array_options;
3061 $situation_percent = 0;
3063 $situation_percent = 100;
3066 $fk_unit = $originLine->fk_unit;
3067 $pu_ht_devise = $originLine->multicurrency_subprice;
3069 $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);
3088 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3094 $triggersendname =
'BILL_SENTBYMAIL';
3096 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3097 $trackid =
'inv'.$object->id;
3098 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3101 $upload_dir = $conf->invoice->multidir_output[!empty(
$object->entity) ?
$object->entity : $conf->entity];
3102 $permissiontoadd = $usercancreate;
3103 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3106 if ($action ==
'update_extras' && $usercancreate) {
3108 $attribute_name =
GETPOST(
'attribute',
'restricthtml');
3111 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute_name);
3118 $result =
$object->updateExtraField($attribute_name,
'BILL_MODIFY');
3126 $action =
'edit_extras';
3131 if ($action ==
'addcontact' && $usercancreate) {
3132 $result =
$object->fetch($id);
3134 if ($result > 0 && $id > 0) {
3137 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3141 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3144 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3145 $langs->load(
"errors");
3146 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3151 } elseif ($action ==
'swapstatut' && $usercancreate) {
3158 } elseif ($action ==
'deletecontact' && $usercancreate) {
3161 $result =
$object->delete_contact($lineid);
3164 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3172 $action =
'edit_extras';
3183$form =
new Form($db);
3189$bankaccountstatic =
new Account($db);
3191if (isModEnabled(
'project')) {
3197$title =
$object->ref.
" - ".$langs->trans(
'Card');
3198if ($action ==
'create') {
3199 $title = $langs->trans(
"NewBill");
3201$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3207if ($action ==
'create') {
3208 $facturestatic =
new Facture($db);
3209 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3214 $res = $soc->fetch($socid);
3217 $currency_code = $conf->currency;
3219 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3220 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3226 if (!empty($origin) && !empty($originid)) {
3228 $element = $subelement = $origin;
3230 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3231 $element = $regs[1];
3232 $subelement = $regs[2];
3238 if ($element ==
'project') {
3239 $projectid = $originid;
3241 if (empty($cond_reglement_id)) {
3242 $cond_reglement_id = $soc->cond_reglement_id;
3244 if (empty($mode_reglement_id)) {
3245 $mode_reglement_id = $soc->mode_reglement_id;
3247 if (empty($fk_account)) {
3248 $fk_account = $soc->fk_account;
3250 if (empty($dateinvoice)) {
3256 if ($element ==
'order' || $element ==
'commande') {
3257 $element = $subelement =
'commande';
3259 if ($element ==
'propal') {
3260 $element =
'comm/propal';
3261 $subelement =
'propal';
3263 if ($element ==
'contract') {
3264 $element = $subelement =
'contrat';
3266 if ($element ==
'shipping') {
3267 $element = $subelement =
'expedition';
3272 $classname = ucfirst($subelement);
3273 $objectsrc =
new $classname($db);
3274 '@phan-var-force Commande|Propal|Contrat|Expedition $objectsrc';
3275 $objectsrc->fetch($originid);
3276 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3277 $objectsrc->fetch_lines();
3279 $objectsrc->fetch_thirdparty();
3281 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3282 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3285 if (empty($socid)) {
3286 $soc = $objectsrc->thirdparty;
3289 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3291 if ($element ==
'expedition') {
3292 $ref_client = (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
'');
3294 $elem = $subelem = $objectsrc->origin;
3295 $expeoriginid = $objectsrc->origin_id;
3297 $classname = ucfirst($subelem);
3299 $expesrc =
new $classname($db);
3300 '@phan-var-force CommonObject $expesrc';
3301 $expesrc->fetch($expeoriginid);
3303 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3304 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3305 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3307 if (isModEnabled(
'multicurrency')) {
3308 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3309 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3313 $expesrc->fetch_optionals();
3314 $object->array_options = $expesrc->array_options;
3316 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
3317 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3318 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3320 if (isModEnabled(
'multicurrency')) {
3321 if (!empty($objectsrc->multicurrency_code)) {
3322 $currency_code = $objectsrc->multicurrency_code;
3324 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
3325 $currency_tx = $objectsrc->multicurrency_tx;
3330 $objectsrc->fetch_optionals();
3331 $object->array_options = $objectsrc->array_options;
3335 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
3336 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
3337 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
3339 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3341 if (isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3342 $currency_code = $soc->multicurrency_code;
3347 if (!
GETPOST(
'changecompany')) {
3348 if (GETPOSTISSET(
'cond_reglement_id')) {
3349 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3351 if (GETPOSTISSET(
'mode_reglement_id')) {
3352 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3354 if (GETPOSTISSET(
'cond_reglement_id')) {
3360 if (empty($cond_reglement_id)) {
3361 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
3365 if (empty($mode_reglement_id)) {
3366 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
3376 if (!empty($soc->id)) {
3377 $absolute_discount = $soc->getAvailableDiscounts();
3379 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
3380 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
3382 if (!empty($conf->use_javascript_ajax)) {
3383 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3389 if ($origin ==
'contrat') {
3390 $langs->load(
"admin");
3391 $text = $langs->trans(
"ToCreateARecurringInvoice");
3392 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3394 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3396 print
info_admin($text, 0, 0,
'0',
'opacitymedium').
'<br>';
3399 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3400 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3401 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3402 print
'<input type="hidden" name="changecompany" value="0">';
3404 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3406 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3407 print
'<input name="ref" type="hidden" value="provisoire">';
3408 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3409 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3410 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3411 print
'<input name="force_fk_account" type="hidden" value="0">';
3412 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3413 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3414 print
'<input type="hidden" name="originentity" value="'.GETPOSTINT(
'originentity').
'">';
3415 if (!empty($currency_tx)) {
3416 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3422 $parameters = array();
3424 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters,
$object, $action);
3425 if (empty($reshook)) {
3426 print
'<table class="border centpercent">';
3428 $exampletemplateinvoice =
new FactureRec($db);
3430 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3431 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
3435 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
3437 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3438 print
'<td colspan="2">';
3439 print $soc->getNomUrl(1,
'customer');
3440 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3442 $arrayoutstandingbills = $soc->getOutstandingBills();
3443 $outstandingBills = $arrayoutstandingbills[
'opened'];
3444 print
' - <span class="opacitymedium">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3445 print
'<span class="amount">'.price($outstandingBills, 0, $langs, 0, 0, -1, $conf->currency).
'</span>';
3446 if ($soc->outstanding_limit !=
'') {
3447 if ($outstandingBills > $soc->outstanding_limit) {
3448 print
img_warning($langs->trans(
"OutstandingBillReached"));
3450 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1, $conf->currency);
3455 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3456 print
'<td colspan="2">';
3457 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
3458 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3462 $(document).ready(function() {
3463 $("#socid").change(function() {
3465 console.log("Submit page");
3466 $(\'input[name="action"]\').val(\'create\');
3467 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3468 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3469 $(\'input[name="force_fk_account"]\').val(\'1\');
3470 $("#formtocreate").submit(); */
3472 // For company change, we must submit page with action=create instead of action=add
3473 console.log("We have changed the company - Resubmit page");
3474 jQuery("input[name=changecompany]").val("1");
3475 jQuery("#formtocreateaction").val("create");
3476 jQuery("#formtocreate").submit();
3482 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>';
3489 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3490 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
3492 $dateinvoice = $invoice_predefined->date_when;
3493 if (empty($projectid)) {
3494 $projectid = $invoice_predefined->fk_project;
3496 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
3497 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
3498 $fk_account = $invoice_predefined->fk_account;
3499 $note_public = $invoice_predefined->note_public;
3500 $note_private = $invoice_predefined->note_private;
3502 if (!empty($invoice_predefined->multicurrency_code)) {
3503 $currency_code = $invoice_predefined->multicurrency_code;
3505 if (!empty($invoice_predefined->multicurrency_tx)) {
3506 $currency_tx = $invoice_predefined->multicurrency_tx;
3509 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
3510 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
3511 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
3513 $resql = $db->query($sql);
3515 $num = $db->num_rows($resql);
3519 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
3521 print
'<select class="flat" id="fac_rec" name="fac_rec">';
3522 print
'<option value="0" selected></option>';
3524 $objp = $db->fetch_object($resql);
3525 print
'<option value="'.$objp->rowid.
'"';
3528 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
3530 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
3539 print
'<script type="text/javascript">
3540 $(document).ready(function() {
3541 $("#fac_rec").change(function() {
3542 console.log("We have changed the template invoice - Reload page");
3543 var fac_rec = $(this).val();
3544 var socid = $(\'#socid\').val();
3545 // 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.
3546 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3559 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td colspan="2">';
3560 print
'<div class="tagtable">'.
"\n";
3563 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3564 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
3565 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
3567 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'nowraponall', 0, 3,
'standardonsmartphone');
3568 print
'<table class="nobordernopadding"><tr>';
3572 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
3581 print
'<td class="nowrap" style="padding-left: 15px">';
3582 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%').
'"/>';
3585 print
'</tr></table>';
3586 print
'</div></div>';
3588 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
3591 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3592 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
3593 print
'<script type="text/javascript">
3594 jQuery(document).ready(function() {
3595 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
3596 jQuery("#radio_standard").prop("checked", true);
3598 jQuery("#typedeposit, #valuedeposit").click(function() {
3599 jQuery("#radio_deposit").prop("checked", true);
3601 jQuery("#typedeposit").change(function() {
3602 console.log("We change type of down payment");
3603 jQuery("#radio_deposit").prop("checked", true);
3604 setRadioForTypeOfInvoice();
3606 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
3607 setRadioForTypeOfInvoice();
3609 function setRadioForTypeOfInvoice() {
3610 console.log("Change radio for type of invoice");
3611 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
3612 jQuery("#checkforselects").prop("disabled", true);
3613 jQuery("#checkforselects").prop("checked", false);
3614 jQuery(".checkforselect").prop("disabled", true);
3615 jQuery(".checkforselect").prop("checked", false);
3617 jQuery("#checkforselects").prop("disabled", false);
3618 jQuery("#checkforselects").prop("checked", true);
3619 jQuery(".checkforselect").prop("disabled", false);
3620 jQuery(".checkforselect").prop("checked", true);
3626 print
'<table class="nobordernopadding"><tr>';
3628 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
3630 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
3633 if (($origin ==
'propal') || ($origin ==
'commande')) {
3634 print
'<td class="nowrap" style="padding-left: 15px">';
3636 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
3637 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
3638 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
3640 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
3642 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
3643 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
3644 if (!empty($origin_payment_conditions_deposit_percent)) {
3645 $typedeposit =
'variable';
3648 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
3649 $valuedeposit = $objectsrc->deposit_percent;
3651 print $form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
3653 print
'<td class="nowrap" style="padding-left: 5px">';
3654 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.$valuedeposit.
'"/>';
3657 print
'</tr></table>';
3659 print
'</div></div>';
3666 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3667 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
3668 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
3670 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
3672 print
'</div></div>';
3675 $opt = $form->selectSituationInvoices(
GETPOSTINT(
'originid'), $socid);
3677 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3678 $tmp =
'<input type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
3679 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3680 $tmp .=
' disabled';
3683 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3684 $text .=
'<select class="flat" id="situations" name="situations"';
3685 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3686 $text .=
' disabled';
3690 $text .=
'</select>';
3691 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
3693 print
'</div></div>';
3699 $facids = $facturestatic->list_replacable_invoices($soc->id);
3705 if (is_array($facids)) {
3706 foreach ($facids as $facparam) {
3707 $options .=
'<option value="'.$facparam [
'id'].
'"';
3708 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
3709 $options .=
' selected';
3711 $options .=
'>'.$facparam[
'ref'];
3712 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
3713 $options .=
'</option>';
3717 print
'<!-- replacement line -->';
3718 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3719 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
3720 if (!$options || $invoice_predefined->id > 0) {
3721 $tmp .=
' disabled';
3724 print
'<script type="text/javascript">
3725 jQuery(document).ready(function() {
3726 jQuery("#fac_replacement").change(function() {
3727 jQuery("#radio_replacement").prop("checked", true);
3731 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
3732 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
3733 if (!$options || $invoice_predefined->id > 0) {
3734 $text .=
' disabled';
3738 $text .=
'<option value="-1"> </option>';
3741 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
3743 $text .=
'</select>';
3744 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3746 print
'</div></div>';
3750 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3751 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3752 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3753 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3754 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'nowraponall', 0, 3,
'firstsituationonsmartphone');
3756 print
'</div></div>';
3759 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3760 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
3761 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
3763 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'replacementonsmartphone');
3765 print
'</div></div>';
3768 if (empty($origin)) {
3773 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
3779 $newinvoice_static =
new Facture($db);
3780 foreach ($facids as $key => $valarray) {
3781 $newinvoice_static->id = $key;
3782 $newinvoice_static->ref = $valarray [
'ref'];
3783 $newinvoice_static->statut = $valarray [
'status'];
3784 $newinvoice_static->status = $valarray [
'status'];
3785 $newinvoice_static->type = $valarray [
'type'];
3786 $newinvoice_static->paye = $valarray [
'paye'];
3788 $optionsav .=
'<option value="'.$key.
'"';
3789 if ($key ==
GETPOST(
'fac_avoir')) {
3790 $optionsav .=
' selected';
3793 $newinvoice_static->fetch_optionals($key);
3794 $object->array_options = $newinvoice_static->array_options;
3797 $optionsav .= $newinvoice_static->ref;
3798 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
3799 $optionsav .=
'</option>';
3802 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3803 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
3804 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
3805 $tmp .=
' disabled';
3809 print
'<script type="text/javascript">
3810 jQuery(document).ready(function() {
3811 if (jQuery("#radio_creditnote").is(":checked"))
3813 jQuery("#radio_standard").prop("disabled", true);
3815 jQuery("#radio_standard").prop("disabled", false);
3817 if (! jQuery("#radio_creditnote").is(":checked"))
3819 jQuery("#credit_note_options").hide();
3821 jQuery("#radio_creditnote").click(function() {
3822 jQuery("#credit_note_options").show();
3824 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
3825 jQuery("#credit_note_options").hide();
3829 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
3830 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3831 if (!$optionsav || $invoice_predefined->id > 0) {
3832 $text .=
' disabled';
3836 $text .=
'<option value="-1"></option>';
3837 $text .= $optionsav;
3839 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
3841 $text .=
'</select>';
3842 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3845 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
3846 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>";
3847 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>";
3850 print
'</div></div>';
3853 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3855 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3857 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
3859 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
3861 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
3863 print
'</div></div>'.
"\n";
3868 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3869 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
3870 $text = $tmp.
'<label class="opacitymedium" for="radio_template">'.$langs->trans(
"RepeatableInvoice").
'</label> ';
3871 $desc = $form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3,
'templateonsmartphone');
3873 print
'</div></div>';
3882 foreach ($listtType as $type) {
3883 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
3885 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
3888 print
'<script type="text/javascript">
3889 $(document).ready(function() {
3890 var listType = {'.$jsListType.
'};
3891 $("[name=\'type\'").change(function() {
3892 console.log("change name=type");
3893 if ($( this ).prop("checked"))
3895 if(($( this ).val() in listType))
3897 $("#model").val(listType[$( this ).val()]);
3914 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
3915 print $form->getSelectInvoiceSubtype(
GETPOST(
'subtype'),
'subtype', 1, 0,
'');
3921 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
3925 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
3926 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3935 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
3936 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3937 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
3942 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
3943 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3944 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
3949 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
3950 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
3951 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
3956 $rwStyle =
'display:none;';
3957 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
3961 $retained_warranty =
GETPOSTINT(
'retained_warranty');
3962 if (empty($retained_warranty)) {
3963 if (!empty($objectsrc->retained_warranty)) {
3964 $retained_warranty = $objectsrc->retained_warranty;
3967 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
3969 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
3970 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
3973 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
3974 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
3975 if (empty($retained_warranty_fk_cond_reglement)) {
3976 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
3977 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
3978 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
3980 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
3983 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
3986 print
'<script type="text/javascript">
3987 $(document).ready(function() {
3988 $("[name=\'type\']").change(function() {
3989 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
3991 $(".retained-warranty-line").show();
3992 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
3995 $(".retained-warranty-line").hide();
3996 $("#new-situation-invoice-retained-warranty").val("");
4000 $("[name=\'type\']:checked").trigger("change");
4006 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
4007 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
4008 print $form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
4012 if (isModEnabled(
"bank")) {
4013 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td colspan="2">';
4014 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4015 print $form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
4020 if (isModEnabled(
'project') && is_object($formproject)) {
4021 $langs->load(
'projects');
4022 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
4023 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
4024 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>';
4029 if (isModEnabled(
'incoterm')) {
4031 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
4032 print
'<td colspan="2" class="maxwidthonsmartphone">';
4033 $incoterm_id =
GETPOST(
'incoterm_id');
4034 $location_incoterms =
GETPOST(
'location_incoterms');
4035 if (empty($incoterm_id)) {
4036 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
4037 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
4039 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
4040 print $form->select_incoterms($incoterm_id, $location_incoterms);
4045 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
4046 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
4047 print $hookmanager->resPrint;
4048 if (empty($reshook)) {
4049 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
4052 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
4053 if ($soc->fetch_optionals() > 0) {
4054 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
4058 print
$object->showOptionals($extrafields,
'create', $parameters);
4062 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
4063 print
'<td colspan="2">';
4064 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
4065 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
4070 $paramkey =
'FACTURE_ADDON_PDF_'.$type;
4075 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
4079 if (isModEnabled(
'multicurrency')) {
4081 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0).
'</td>';
4082 print
'<td colspan="2" class="maxwidthonsmartphone">';
4083 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
4084 print $form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth100 widthcentpercentminusx');
4091 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
4092 if (empty($dateexample)) {
4095 $substitutionarray = array(
4096 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
4097 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
4098 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
4099 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
4100 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
4101 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
4102 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
4103 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
4104 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
4105 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
4106 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
4109 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
4110 foreach ($substitutionarray as $key => $val) {
4111 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
4113 $htmltext .=
'</i>';
4118 print
'<td class="tdtop">';
4119 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
4121 print
'<td valign="top" colspan="2">';
4122 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
4123 print $doleditor->Create(1);
4126 if (empty($user->socid)) {
4128 print
'<td class="tdtop">';
4129 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4131 print
'<td valign="top" colspan="2">';
4132 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4133 print $doleditor->Create(1);
4139 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4140 $langs->loadLangs(array(
'orders',
'propal'));
4143 if ($origin ==
'contrat') {
4144 '@phan-var-force Contrat $objectsrc';
4146 $objectsrc->update_price(1,
'auto', 1);
4149 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4150 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4151 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4152 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4157 switch (get_class($objectsrc)) {
4159 $newclassname =
'CommercialProposal';
4162 $newclassname =
'Order';
4165 $newclassname =
'Sending';
4168 $newclassname =
'Contract';
4171 $newclassname =
'Intervention';
4174 $newclassname = get_class($objectsrc);
4178 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4179 print
'<td colspan="2">';
4180 print $objectsrc->getNomUrl(1);
4182 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
4183 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4185 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4188 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht).
'</td></tr>';
4189 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva).
"</td></tr>";
4190 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4191 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax1).
"</td></tr>";
4194 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4195 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax2).
"</td></tr>";
4197 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc).
"</td></tr>";
4199 if (isModEnabled(
'multicurrency')) {
4200 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
4201 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
4202 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
4210 print $form->buttonsSaveCancel(
"CreateDraft");
4213 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4216 $title = $langs->trans(
'ProductsAndServices');
4219 print
'<div class="div-table-responsive-no-min">';
4220 print
'<table class="noborder centpercent">';
4222 $objectsrc->printOriginLinesList(
'', $selectedLines);
4229} elseif ($id > 0 || !empty($ref)) {
4231 $langs->load(
'errors');
4232 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4241 $result =
$object->fetch($id, $ref);
4248 $extrafields->fetch_name_optionals_label(
$object->table_element);
4250 if ($user->socid > 0 && $user->socid !=
$object->socid) {
4254 $result =
$object->fetch_thirdparty();
4256 $result = $soc->fetch(
$object->socid);
4260 $selleruserevenustamp = $mysoc->useRevenueStamp();
4262 $totalpaid =
$object->getSommePaiement();
4263 $totalcreditnotes =
$object->getSumCreditNotesUsed();
4264 $totaldeposits =
$object->getSumDepositsUsed();
4270 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4273 if (isModEnabled(
'multicurrency')) {
4274 $multicurrency_totalpaid =
$object->getSommePaiement(1);
4275 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
4276 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
4277 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4281 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code != $conf->currency) {
4282 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
4289 $resteapayeraffiche = $resteapayer;
4292 $filterabsolutediscount =
"fk_facture_source IS NULL";
4293 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4295 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4296 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4299 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
4300 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
4301 $absolute_discount =
price2num($absolute_discount,
'MT');
4302 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4304 $author =
new User($db);
4305 if (
$object->user_creation_id) {
4306 $author->fetch(
$object->user_creation_id);
4309 $objectidnext =
$object->getIdReplacingInvoice();
4313 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
'bill');
4318 if ($action ==
'converttoreduc') {
4320 $type_fac =
'ExcessReceived';
4322 $type_fac =
'CreditNote';
4324 $type_fac =
'Deposit';
4326 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4327 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4328 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4332 if ($action ==
'delete') {
4333 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
4334 $formquestion = array();
4337 $qualified_for_stock_change = 0;
4339 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4341 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4344 if ($qualified_for_stock_change) {
4345 $langs->load(
"stocks");
4346 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4350 if ($conf->browser->name ==
'ie') {
4353 $formquestion = array(
4357 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4359 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4361 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4364 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4369 if ($action ==
'situationout') {
4370 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
4371 $label = $langs->trans(
"ConfirmOuting");
4372 $formquestion = array();
4377 &&
$object->is_last_in_cycle()
4378 && $usercanunvalidate
4380 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4385 if ($action ==
'valid') {
4387 $objectref = substr(
$object->ref, 1, 4);
4388 if ($objectref ==
'PROV') {
4392 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
4394 $numref =
$object->getNextNumRef($soc);
4400 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4401 if (isModEnabled(
'notification')) {
4402 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4403 $notify =
new Notify($db);
4405 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid,
$object);
4407 $formquestion = array();
4410 $qualified_for_stock_change = 0;
4412 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4414 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4417 if ($qualified_for_stock_change) {
4418 $langs->load(
"stocks");
4419 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4420 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4423 $warehouse_array = $warehouse->list_array();
4424 if (count($warehouse_array) == 1) {
4425 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4426 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4429 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4431 $formquestion = array(
4437 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4441 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
4446 foreach (
$object->lines as $line) {
4447 $res = $line->fetch_product();
4449 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
4455 if ($nbMandated > 0) {
4457 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
4460 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
4465 $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);
4470 if ($action ==
'modif') {
4471 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
4472 $formquestion = array();
4475 $qualified_for_stock_change = 0;
4477 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4479 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4482 if ($qualified_for_stock_change) {
4483 $langs->load(
"stocks");
4484 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4485 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4488 $warehouse_array = $warehouse->list_array();
4489 if (count($warehouse_array) == 1) {
4490 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
4491 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4494 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4496 $formquestion = array(
4502 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4506 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
4510 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
4511 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
4513 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
4517 $close[$i][
'code'] =
'discount_vat';
4519 $close[$i][
'code'] =
'badcustomer';
4521 $close[$i][
'code'] =
'bankcharge';
4523 $close[$i][
'code'] =
'withholdingtax';
4525 $close[$i][
'code'] =
'other';
4529 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
4531 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4533 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
4535 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
4537 $close[$i][
'label'] = $langs->trans(
"Other");
4541 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4543 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4545 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4547 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
4549 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
4553 foreach ($close as $key => $val) {
4554 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
4558 $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'));
4560 $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);
4564 if ($action ==
'canceled') {
4567 if ($objectidnext) {
4568 $facturereplacement =
new Facture($db);
4569 $facturereplacement->fetch($objectidnext);
4570 $statusreplacement = $facturereplacement->status;
4572 if ($objectidnext && $statusreplacement == 0) {
4573 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
4576 $close[1][
'code'] =
'badcustomer';
4577 $close[2][
'code'] =
'abandon';
4579 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4580 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
4582 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
4583 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
4586 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
4587 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
4590 $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'));
4592 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 270);
4596 if ($action ==
'deletepayment') {
4597 $payment_id =
GETPOST(
'paiement_id');
4598 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
4602 if ($action ==
'ask_deleteline') {
4603 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
4607 if ($action ==
'clone') {
4608 $filter =
'(s.client:IN:1,2,3)';
4610 $formquestion = array(
4611 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
$object->socid,
'socid', $filter, 1)),
4612 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
4615 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
4618 if ($action ==
"remove_file_comfirm") {
4619 $file =
GETPOST(
'file',
'alpha');
4621 $formconfirm = $form->formconfirm(
4622 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
4623 $langs->trans(
'DeleteFileHeader'),
4624 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
4633 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
4634 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
4635 if (empty($reshook)) {
4636 $formconfirm .= $hookmanager->resPrint;
4637 } elseif ($reshook > 0) {
4638 $formconfirm = $hookmanager->resPrint;
4646 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
4648 $morehtmlref =
'<div class="refidno">';
4651 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref',
$object->ref,
$object, $usercancreate,
'string',
'', 0, 1);
4652 $morehtmlref .= $form->editfieldval(
"Ref",
'ref',
$object->ref,
$object, $usercancreate,
'string',
'',
null,
null,
'', 1);
4653 $morehtmlref .=
'<br>';
4656 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer,
$object, $usercancreate,
'string',
'', 0, 1);
4657 $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);
4659 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
4661 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'&search_societe='.urlencode(
$object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
4664 if (isModEnabled(
'project')) {
4665 $langs->load(
"projects");
4666 $morehtmlref .=
'<br>';
4667 if ($usercancreate) {
4668 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
4669 if ($action !=
'classify') {
4670 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
4672 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->socid,
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
4674 if (!empty(
$object->fk_project)) {
4676 $proj->fetch(
$object->fk_project);
4677 $morehtmlref .= $proj->getNomUrl(1);
4679 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
4684 $morehtmlref .=
'</div>';
4686 $object->totalpaid = $totalpaid;
4687 $object->totalcreditnotes = $totalcreditnotes;
4688 $object->totaldeposits = $totaldeposits;
4691 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
4694 $parameters = array();
4696 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters,
$object, $action);
4697 if (empty($reshook)) {
4698 print
'<div class="fichecenter">';
4699 print
'<div class="fichehalfleft">';
4700 print
'<div class="underbanner clearboth"></div>';
4702 print
'<table class="border centpercent tableforfield">';
4705 print
'<tr><td class="fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
4708 print
' '.$object->getSubtypeLabel(
'facture');
4714 $facreplaced =
new Facture($db);
4715 $facreplaced->fetch(
$object->fk_facture_source);
4716 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
4720 $facusing->fetch(
$object->fk_facture_source);
4721 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
4724 $facidavoir =
$object->getListIdAvoirFromInvoice();
4725 if (count($facidavoir) > 0) {
4726 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
4728 foreach ($facidavoir as $id) {
4735 $facavoir->fetch($id);
4736 print $facavoir->getNomUrl(1,
'', 32);
4740 if ($objectidnext > 0) {
4741 $facthatreplace =
new Facture($db);
4742 $facthatreplace->fetch($objectidnext);
4743 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
4748 $result = $discount->fetch(0,
$object->id);
4750 print
' <span class="opacitymediumbycolor paddingleft">';
4751 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
4752 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
4753 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
4755 print
'</span><br>';
4759 if (
$object->fk_fac_rec_source > 0) {
4761 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
4763 print
' <span class="opacitymediumbycolor paddingleft">';
4764 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
4765 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
4773 print
'<!-- Discounts -->'.
"\n";
4774 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
4778 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
4779 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
4784 print
'<table class="nobordernopadding centpercent"><tr><td>';
4785 print $langs->trans(
'DateInvoice');
4787 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
4788 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>';
4790 print
'</tr></table>';
4793 if ($action ==
'editinvoicedate') {
4794 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
4796 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
4805 print
'<table class="nobordernopadding centpercent"><tr><td>';
4806 print $langs->trans(
'DatePointOfTax');
4808 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>';
4809 print
'</tr></table>';
4811 if ($action ==
'editdate_pointoftax') {
4812 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
4814 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
4821 print
'<table class="nobordernopadding centpercent"><tr><td>';
4822 print $langs->trans(
'PaymentConditionsShort');
4825 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>';
4827 print
'</tr></table>';
4830 if ($action ==
'editconditions') {
4831 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->cond_reglement_id,
'cond_reglement_id');
4833 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->cond_reglement_id,
'none');
4842 print
'<table class="nobordernopadding centpercent"><tr><td>';
4843 print $langs->trans(
'DateMaxPayment');
4846 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>';
4848 print
'</tr></table>';
4851 if ($action ==
'editpaymentterm') {
4852 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
4854 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
4866 print
'<table class="nobordernopadding centpercent"><tr><td>';
4867 print $langs->trans(
'PaymentMode');
4869 if ($action !=
'editmode' && $usercancreate) {
4870 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>';
4872 print
'</tr></table>';
4874 if ($action ==
'editmode') {
4875 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
4877 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->mode_reglement_id,
'none',
'CRDT');
4882 if (isModEnabled(
"bank")) {
4883 print
'<tr><td class="nowrap">';
4884 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
4885 print $langs->trans(
'BankAccount');
4887 if (($action !=
'editbankaccount') && $usercancreate) {
4888 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>';
4890 print
'</tr></table>';
4892 if ($action ==
'editbankaccount') {
4893 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'fk_account', 1);
4895 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'none');
4902 if (isModEnabled(
'incoterm')) {
4904 print
'<table class="nobordernopadding centpercent"><tr><td>';
4905 print $langs->trans(
'IncotermLabel');
4906 print
'<td><td class="right">';
4907 if ($usercancreate) {
4908 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
4912 print
'</td></tr></table>';
4915 if ($action !=
'editincoterm') {
4916 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
4918 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
4926 $displayWarranty =
true;
4927 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
4928 $displayWarranty =
false;
4931 if ($displayWarranty) {
4933 print
'<tr class="retained-warranty-lines" ><td>';
4934 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
4935 print $langs->trans(
'RetainedWarranty');
4938 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>';
4941 print
'</tr></table>';
4944 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
4945 print
'<input type="hidden" name="action" value="setretainedwarranty">';
4946 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4947 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4948 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
4949 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
4957 print
'<tr class="retained-warranty-lines" ><td>';
4958 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
4959 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
4961 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
4962 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>';
4965 print
'</tr></table>';
4967 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
4968 if (
$object->date > $defaultDate) {
4974 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
4975 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
4976 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4977 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4978 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
4979 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
4980 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4981 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4982 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4985 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->retained_warranty_fk_cond_reglement,
'none');
4986 if (!$displayWarranty) {
4987 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning.png',
'class="pictowarning valignmiddle" ');
4993 print
'<tr class="retained-warranty-lines" ><td>';
4994 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
4995 print $langs->trans(
'RetainedWarrantyDateLimit');
4998 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>';
5001 print
'</tr></table>';
5003 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5004 if (
$object->date > $defaultDate) {
5010 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5011 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
5012 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5013 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5014 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').
'" >';
5015 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5027 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
5032 print
'<div class="fichehalfright">';
5034 print
'<!-- amounts -->'.
"\n";
5035 print
'<div class="underbanner clearboth"></div>'.
"\n";
5037 print
'<table class="border tableforfield centpercent">';
5039 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
5047 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
5048 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5049 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
5051 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5057 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
5058 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5059 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
5061 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5066 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
5068 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
5069 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5070 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
5073 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5078 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
5080 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
5081 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5082 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
5085 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5091 if ($selleruserevenustamp) {
5092 print
'<tr><td class="titlefieldmiddle">';
5093 print
'<table class="nobordernopadding centpercent"><tr><td>';
5094 print $langs->trans(
'RevenueStamp');
5096 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
5097 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>';
5099 print
'</tr></table>';
5100 print
'</td><td class="nowrap amountcard right">';
5101 if ($action ==
'editrevenuestamp') {
5102 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
5103 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5104 print
'<input type="hidden" name="action" value="setrevenuestamp">';
5105 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
5106 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5107 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
5108 print
' → <span id="revenuestamp_span"></span>';
5109 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
5112 $(document).ready(function(){
5113 js_recalculate_revenuestamp();
5114 $('select[name=revenuestamp_type]').on('change',function(){
5115 js_recalculate_revenuestamp();
5118 function js_recalculate_revenuestamp(){
5119 var valselected = $('select[name=revenuestamp_type]').val();
5120 console.log('Calculate revenue stamp from '+valselected);
5122 if (valselected.indexOf('%') == -1)
5124 revenue = valselected;
5128 var revenue_type = parseFloat(valselected);
5129 var amount_net = ".round(
$object->total_ht, 2).
";
5130 revenue = revenue_type * amount_net / 100;
5131 revenue = revenue.toFixed(2);
5133 $('#revenuestamp_val').val(revenue);
5134 $('#revenuestamp_span').html(revenue);
5138 print
price(
$object->revenuestamp, 1,
'', 1, -1, -1, $conf->currency);
5145 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
5146 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5147 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
5149 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5157 if (isModEnabled(
'project')) {
5160 if (isModEnabled(
"bank")) {
5164 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
5167 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
5170 if ($selleruserevenustamp) {
5173 if (isModEnabled(
'multicurrency')) {
5176 if (isModEnabled(
'incoterm')) {
5182 print
'<!-- List of situation invoices -->';
5183 print
'<table class="noborder situationstable" width="100%">';
5185 print
'<tr class="liste_titre">';
5186 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
5188 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
5189 if (isModEnabled(
"bank")) {
5190 print
'<td class="right"></td>';
5192 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
5193 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
5194 print
'<td width="18"> </td>';
5197 $total_prev_ht = $total_prev_ttc = 0;
5198 $total_global_ht = $total_global_ttc = 0;
5200 if (count(
$object->tab_previous_situation_invoice) > 0) {
5203 $current_situation_counter = array();
5204 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
5205 $tmptotalallpayments = $prev_invoice->getSommePaiement(0);
5206 $tmptotalallpayments += $prev_invoice->getSumDepositsUsed(0);
5207 $tmptotalallpayments += $prev_invoice->getSumCreditNotesUsed(0);
5209 $total_prev_ht += $prev_invoice->total_ht;
5210 $total_prev_ttc += $prev_invoice->total_ttc;
5212 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
5213 print
'<tr class="oddeven">';
5214 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
5216 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
5217 if (isModEnabled(
"bank")) {
5218 print
'<td class="right"></td>';
5220 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
5221 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
5222 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalallpayments).
'</td>';
5227 $totalallpayments =
$object->getSommePaiement(0);
5228 $totalallpayments +=
$object->getSumCreditNotesUsed(0);
5229 $totalallpayments +=
$object->getSumDepositsUsed(0);
5231 $total_global_ht += $total_prev_ht;
5232 $total_global_ttc += $total_prev_ttc;
5233 $total_global_ht +=
$object->total_ht;
5234 $total_global_ttc +=
$object->total_ttc;
5238 print
'<tr class="oddeven">';
5239 print
'<td>'.$object->getNomUrl(1).
'</td>';
5241 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
5242 if (isModEnabled(
"bank")) {
5243 print
'<td class="right"></td>';
5245 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
5246 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
5247 print
'<td class="right">'.$object->getLibStatut(3, $totalallpayments).
'</td>';
5251 print
'<tr class="oddeven">';
5252 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'CurrentSituationTotal').
'</b></td>';
5255 foreach ($current_situation_counter as $sit) {
5256 $curSign = $sit > 0 ?
'+' :
'-';
5257 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
5259 print
' '.$curSign.
' ';
5261 print $curType.abs($sit);
5265 if (isModEnabled(
"bank")) {
5268 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5269 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5270 print
'<td width="18"> </td>';
5274 if (count(
$object->tab_next_situation_invoice) > 0) {
5286 $total_next_ht = $total_next_ttc = 0;
5288 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
5289 $totalpaid = $next_invoice->getSommePaiement(0);
5290 $totalcreditnotes = $next_invoice->getSumCreditNotesUsed(0);
5291 $totaldeposits = $next_invoice->getSumDepositsUsed(0);
5293 $total_next_ht += $next_invoice->total_ht;
5294 $total_next_ttc += $next_invoice->total_ttc;
5296 print
'<tr class="oddeven">';
5297 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
5299 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
5300 if (isModEnabled(
"bank")) {
5301 print
'<td class="right"></td>';
5303 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
5304 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
5305 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid + $totalcreditnotes + $totaldeposits).
'</td>';
5309 $total_global_ht += $total_next_ht;
5310 $total_global_ttc += $total_next_ttc;
5312 print
'<tr class="oddeven">';
5313 print
'<td colspan="3" class="right"></td>';
5314 if (isModEnabled(
"bank")) {
5315 print
'<td class="right"></td>';
5317 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5318 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5319 print
'<td width="18"> </td>';
5327 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
5333 print
'<!-- List of payments already done -->';
5334 print
'<div class="div-table-responsive-no-min">';
5335 print
'<table class="noborder paymenttable centpercent">';
5337 print
'<tr class="liste_titre">';
5338 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
5339 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
5340 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
5341 if (isModEnabled(
"bank")) {
5342 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
5344 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
5345 print
'<td class="liste_titre" width="18"> </td>';
5349 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
5350 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
5351 $sql .=
' pf.amount,';
5352 $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';
5353 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
5354 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
5355 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
5356 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
5357 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
5358 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
5359 $sql .=
' ORDER BY p.datep, p.tms';
5361 $result = $db->query($sql);
5363 $num = $db->num_rows($result);
5368 $objp = $db->fetch_object($result);
5370 $paymentstatic->id = $objp->rowid;
5371 $paymentstatic->datepaye = $db->jdate($objp->dp);
5372 $paymentstatic->ref = $objp->ref;
5373 $paymentstatic->num_payment = $objp->num_payment;
5374 $paymentstatic->paiementcode = $objp->payment_code;
5376 print
'<tr class="oddeven"><td class="nowraponall">';
5377 print $paymentstatic->getNomUrl(1);
5380 $dateofpayment = $db->jdate($objp->dp);
5382 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
5389 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
5390 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
5391 if (isModEnabled(
"bank")) {
5392 $bankaccountstatic->id = $objp->baid;
5393 $bankaccountstatic->ref = $objp->baref;
5394 $bankaccountstatic->label = $objp->baref;
5395 $bankaccountstatic->number = $objp->banumber;
5396 $bankaccountstatic->currency_code = $objp->bacurrency_code;
5398 if (isModEnabled(
'accounting')) {
5399 $bankaccountstatic->account_number = $objp->account_number;
5402 $accountingjournal->fetch($objp->fk_accountancy_journal);
5403 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
5406 print
'<td class="nowraponall">';
5407 if ($bankaccountstatic->id) {
5408 print $bankaccountstatic->getNomUrl(1,
'transactions');
5412 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
5413 print
'<td class="center">';
5416 $paiement->fetch($objp->rowid);
5418 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
5435 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5436 print
'<span class="opacitymedium">';
5438 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
5440 print $langs->trans(
'AlreadyPaid');
5442 print
'</span></td><td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td><td> </td></tr>';
5444 $resteapayeraffiche = $resteapayer;
5445 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
5448 $creditnoteamount = 0;
5450 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
5451 $sql .=
" re.description, re.fk_facture_source";
5452 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
5453 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
5454 $resql = $db->query($sql);
5456 $num = $db->num_rows($resql);
5460 $obj = $db->fetch_object($resql);
5461 $invoice->fetch($obj->fk_facture_source);
5462 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5463 print
'<span class="opacitymedium">';
5465 print $langs->trans(
"CreditNote").
' ';
5468 print $langs->trans(
"Deposit").
' ';
5470 print $invoice->getNomUrl(0);
5473 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
5474 print
'<td class="right">';
5475 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
5476 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
5481 $creditnoteamount += $obj->amount_ttc;
5484 $depositamount += $obj->amount_ttc;
5493 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5494 print
'<span class="opacitymedium">';
5495 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
5497 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5498 $resteapayeraffiche = 0;
5499 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5503 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5504 print
'<span class="opacitymedium">';
5505 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
5507 print
'</td><td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td><td> </td></tr>';
5509 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5513 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5514 print
'<span class="opacitymedium">';
5515 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
5517 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5518 $resteapayeraffiche = 0;
5519 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5523 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5524 $text = $langs->trans(
"HelpAbandonOther");
5526 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
5528 print
'<span class="opacitymedium">';
5530 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
5532 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5533 $resteapayeraffiche = 0;
5534 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5538 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5539 print
'<span class="opacitymedium">';
5540 print $langs->trans(
"Billed");
5541 print
'</td><td class="right">'.price(
$object->total_ttc).
'</td><td> </td></tr>';
5543 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5544 print
'<span class="opacitymedium">';
5545 print $langs->trans(
'RemainderToPay');
5546 if ($resteapayeraffiche < 0) {
5547 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5551 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
5554 if (
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
5555 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5556 print
'<span class="opacitymedium">';
5557 print $langs->trans(
'RemainderToPayMulticurrency');
5558 if ($resteapayeraffiche < 0) {
5559 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5563 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">';
5565 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>';
5569 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
5572 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
5575 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
5578 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
5580 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>';
5583 print
'<tr><td colspan="'.$nbcols.
'" align="right">';
5584 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
5585 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
5586 print
' :</td><td align="right">'.price($retainedWarranty).
'</td><td> </td></tr>';
5589 $resteapayeraffiche = $resteapayer;
5590 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5593 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5594 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
5595 print
'</td><td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td><td> </td></tr>';
5598 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>';
5601 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5602 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
5603 if ($resteapayeraffiche > 0) {
5604 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5606 print
'</span></td>';
5607 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
5608 print
'<td class="nowrap"> </td></tr>';
5611 if (
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
5612 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5613 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
5614 if ($resteapayeraffiche > 0) {
5615 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5619 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>';
5632 if (isModEnabled(
'margin')) {
5633 $formmargin->displayMarginInfos(
$object);
5639 print
'<div class="clearboth"></div><br><br>';
5642 $blocname =
'contacts';
5643 $title = $langs->trans(
'ContactsAddresses');
5644 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5648 $blocname =
'notes';
5649 $title = $langs->trans(
'Notes');
5650 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5654 $result =
$object->getLinesArray();
5658 global $inputalsopricewithtax;
5659 $inputalsopricewithtax = 1;
5664 print
'<!-- Area to change globally the situation percent -->'.
"\n";
5665 print
'<div class="div-table-responsive">';
5667 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'#updatealllines" method="POST">';
5668 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
5669 print
'<input type="hidden" name="action" value="updatealllines" />';
5670 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
5671 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5673 print
'<table id="tablelines_all_progress" class="noborder noshadow" width="100%">';
5675 print
'<tr class="liste_titre nodrag nodrop">';
5679 print
'<td align="center" width="5"> </td>';
5681 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
5682 print
'<td class="right">'.$langs->trans(
'Progress').
'</td>';
5683 print
'<td> </td>';
5686 print
'<tr class="nodrag nodrop">';
5689 print
'<td align="center" width="5"> </td>';
5691 print
'<td> </td>';
5692 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
5693 print
'<td class="right"><input type="submit" class="button" name="all_percent" value="Modifier" /></td>';
5704 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
5705 <input type="hidden" name="token" value="' .
newToken().
'">
5706 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
5707 <input type="hidden" name="mode" value="">
5708 <input type="hidden" name="page_y" value="">
5709 <input type="hidden" name="id" value="' .
$object->id.
'">
5710 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
5713 if (!empty($conf->use_javascript_ajax) &&
$object->status == 0) {
5714 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
5717 print
'<div class="div-table-responsive-no-min">';
5718 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
5722 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
5726 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
5727 if ($action !=
'editline' && $action !=
'selectlines') {
5730 $parameters = array();
5731 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
5735 if (empty($reshook)) {
5736 $object->formAddObjectLine(1, $mysoc, $soc);
5739 $parameters = array();
5740 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters,
$object, $action);
5754 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
5755 print
'<div class="tabsAction">';
5757 $parameters = array();
5758 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
5759 if (empty($reshook)) {
5762 'class' =>
'classfortooltip',
5769 $ventilExportCompta =
$object->getVentilExportCompta();
5771 if ($ventilExportCompta == 0) {
5773 if (!$objectidnext &&
$object->is_last_in_cycle()) {
5774 if ($usercanunvalidate) {
5775 unset($params[
'attr'][
'title']);
5776 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=modif&token='.
newToken(),
'',
true, $params);
5778 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
5779 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=modif&token='.
newToken(),
'',
false, $params);
5781 } elseif (!
$object->is_last_in_cycle()) {
5782 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
5783 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5785 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
5786 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5790 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5791 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5796 $result = $discount->fetch(0,
$object->id);
5804 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
5805 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
5806 unset($params[
'attr'][
'title']);
5807 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
5809 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
5810 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
5817 $langs->load(
"contracts");
5819 if ($usercancreatecontract) {
5820 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>';
5827 if ($usercanvalidate) {
5828 unset($params[
'attr'][
'title']);
5829 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
5834 if (empty($user->socid)) {
5836 if ($objectidnext) {
5837 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'SendMail').
'</span>';
5840 unset($params[
'attr'][
'title']);
5841 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
5843 unset($params[
'attr'][
'title']);
5844 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
5852 if ($resteapayer > 0) {
5853 if ($usercancreatewithdrarequest) {
5854 if (!$objectidnext &&
$object->close_code !=
'replaced') {
5855 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>';
5857 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
5868 if (isModEnabled(
'takepos') &&
$object->module_source ==
'takepos') {
5869 $langs->load(
"cashdesk");
5870 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
5871 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
5876 if ($objectidnext) {
5877 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
5881 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
5882 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
5886 unset($params[
'attr'][
'title']);
5887 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);
5892 $sumofpayment = $totalpaid;
5893 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
5899 if ($resteapayer == 0) {
5900 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
5902 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
5908 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
5912 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
5914 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>';
5921 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
5923 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
5937 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
5938 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
5940 unset($params[
'attr'][
'title']);
5941 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken(),
'',
true, $params);
5947 if ($totalpaid > 0 || $totalcreditnotes > 0) {
5949 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
5952 if ($objectidnext) {
5953 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
5955 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
5963 if (!$objectidnext) {
5964 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>';
5971 && (
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
5974 &&
$object->is_last_in_cycle()
5977 if ($usercanunvalidate) {
5978 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>';
5980 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
5986 unset($params[
'attr'][
'title']);
5987 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice&token='.
newToken(),
'',
true, $params);
5992 if (!$objectidnext && count(
$object->lines) > 0) {
5993 unset($params[
'attr'][
'title']);
5994 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
6003 &&
$object->situation_counter > 1
6004 &&
$object->is_last_in_cycle()
6005 && $usercanunvalidate
6007 if ((
$object->total_ttc - $totalcreditnotes) == 0) {
6008 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6010 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6016 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
6017 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6018 } elseif (!
$object->is_last_in_cycle()) {
6019 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6021 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6026 $isErasable =
$object->is_erasable();
6028 if ($isErasable == -4) {
6029 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
6030 } elseif ($isErasable == -3) {
6031 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
6032 } elseif ($isErasable == -2) {
6033 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
6034 } elseif ($isErasable == -1) {
6035 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6036 } elseif ($isErasable <= 0) {
6037 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable');
6038 } elseif ($objectidnext) {
6039 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
6041 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
6042 $enableDelete =
false;
6044 if ($isErasable > 0 && ! $objectidnext) {
6045 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
6046 $enableDelete =
true;
6048 unset($params[
'attr'][
'title']);
6049 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
6051 unset($params[
'attr'][
'title']);
6052 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
6059 if (
GETPOST(
'modelselected',
'alpha')) {
6060 $action =
'presend';
6062 if ($action !=
'prerelance' && $action !=
'presend') {
6063 print
'<div class="fichecenter"><div class="fichehalfleft">';
6064 print
'<a name="builddoc"></a>';
6069 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
6070 $genallowed = $usercanread;
6071 $delallowed = $usercancreate;
6073 print $formfile->showdocuments(
6093 'remove_file_comfirm'
6096 $somethingshown = $formfile->numoffiles;
6099 $linktoelem = $form->showLinkToObjectBlock(
$object, array(), array(
'invoice'));
6101 $compatibleImportElementsList =
false;
6105 $compatibleImportElementsList = array(
'commande',
'propal');
6107 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem, $compatibleImportElementsList);
6111 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6112 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
6113 $useonlinepayment = count($validpaymentmethod);
6116 print
'<br><!-- Link to pay -->'.
"\n";
6117 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6118 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
6121 print
'</div><div class="fichehalfright">';
6125 $morehtmlcenter =
'<div class="nowraponall">';
6126 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullConversation'),
'',
'fa fa-comments imgforviewmode', DOL_URL_ROOT.
'/compta/facture/messaging.php?id='.
$object->id);
6127 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
6128 $morehtmlcenter .=
'</div>';
6131 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
6133 $somethingshown = $formactions->showactions(
$object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
6135 print
'</div></div>';
6140 $modelmail =
'facture_send';
6141 $defaulttopic =
'SendBillRef';
6142 $diroutput = $conf->invoice->multidir_output[
$object->entity];
6143 $trackid =
'inv'.$object->id;
6145 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'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
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.
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.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid