44require
'../../main.inc.php';
45require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
55require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
56require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
57require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
58if (isModEnabled(
'order')) {
59 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
61if (isModEnabled(
'project')) {
62 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
63 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
65require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
67if (isModEnabled(
'variants')) {
68 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
70if (isModEnabled(
'accounting')) {
71 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
84$langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
85if (isModEnabled(
'incoterm')) {
86 $langs->load(
'incoterm');
88if (isModEnabled(
'margin')) {
89 $langs->load(
'margins');
96$action =
GETPOST(
'action',
'aZ09');
97$confirm =
GETPOST(
'confirm',
'alpha');
98$cancel =
GETPOST(
'cancel',
'alpha');
99$backtopage =
GETPOST(
'backtopage',
'alpha');
100$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
103$search_ref =
GETPOST(
'sf_ref',
'alpha') ?
GETPOST(
'sf_ref',
'alpha') :
GETPOST(
'search_ref',
'alpha');
104$search_societe =
GETPOST(
'search_societe',
'alpha');
105$search_montant_ht =
GETPOST(
'search_montant_ht',
'alpha');
106$search_montant_ttc =
GETPOST(
'search_montant_ttc',
'alpha');
107$origin =
GETPOST(
'origin',
'alpha');
111$ref_client =
GETPOST(
'ref_client',
'alpha');
114$selectedLines =
GETPOST(
'toselect',
'array');
130$extrafields->fetch_name_optionals_label(
$object->table_element);
133$total_global_ttc = 0;
134$displayWarranty =
false;
135$statusreplacement = 0;
137$price_base_type =
'';
138$array_options = array();
141if ($id > 0 || !empty($ref)) {
142 if ($action !=
'add') {
144 $fetch_situation =
false;
146 $fetch_situation =
true;
148 $ret =
$object->fetch($id, $ref,
'', 0, $fetch_situation);
149 if ($ret > 0 && isset(
$object->fk_project)) {
150 $ret =
$object->fetchProject();
156$hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
159$usercanread = $user->hasRight(
"facture",
"lire");
160$usercancreate = $user->hasRight(
"facture",
"creer");
161$usercanissuepayment = $user->hasRight(
"facture",
"paiement");
162$usercandelete = $user->hasRight(
"facture",
"supprimer") || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
163$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
166$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'validate')));
168$usercanreopen = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'reopen')));
170 $usercanreopen =
false;
172$usercanunvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'unvalidate')));
173$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
176$usercancreatemargin = $user->hasRight(
'margins',
'creer');
177$usercanreadallmargin = $user->hasRight(
'margins',
'liretous');
178$usercancreatewithdrarequest = $user->hasRight(
'prelevement',
'bons',
'creer');
180$permissionnote = $usercancreate;
181$permissiondellink = $usercancreate;
182$permissiontoedit = $usercancreate;
183$permissiontoadd = $usercancreate;
186$retainedWarrantyInvoiceAvailableType = array();
188 $retainedWarrantyInvoiceAvailableType = explode(
'+',
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY'));
193 $socid = $user->socid;
205$parameters = array(
'socid' => $socid);
206$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
211if (empty($reshook)) {
212 $backurlforlist = DOL_URL_ROOT.
'/compta/facture/list.php';
214 if (empty($backtopage) || ($cancel && empty($id))) {
215 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
216 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
217 $backtopage = $backurlforlist;
219 $backtopage = DOL_URL_ROOT.
'/compta/facture/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
225 if (!empty($backtopageforcancel)) {
226 header(
"Location: ".$backtopageforcancel);
228 } elseif (!empty($backtopage)) {
229 header(
"Location: ".$backtopage);
235 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
237 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
239 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
242 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
244 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'IdThirdParty')),
null,
'errors');
247 '@phan-var-force Facture $objectutil';
250 $objectutil->socid = $socid;
251 $result = $objectutil->createFromClone($user, $id);
253 $warningMsgLineList = array();
255 foreach ($objectutil->lines as $line) {
256 if (!is_object($line->product)) {
257 $line->fetch_product();
259 if (is_object($line->product) && $line->product->id > 0) {
260 if (empty($line->product->status)) {
261 $warningMsgLineList[$line->id] = $langs->trans(
'WarningLineProductNotToSell', $line->product->ref);
265 if (!empty($warningMsgLineList)) {
269 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?facid=' . $result);
272 $langs->load(
"errors");
277 } elseif ($action ==
'reopen' && $usercanreopen) {
281 $result =
$object->setUnpaid($user);
283 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
289 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
294 $idwarehouse =
GETPOST(
'idwarehouse');
296 $qualified_for_stock_change = 0;
298 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
300 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
303 $isErasable =
$object->is_erasable();
305 if (($usercandelete && $isErasable > 0)
306 || ($usercancreate && $isErasable == 1)) {
307 $result =
$object->delete($user, 0, $idwarehouse);
309 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
316 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
326 $outputlangs = $langs;
332 $newlang =
$object->thirdparty->default_lang;
334 if (!empty($newlang)) {
336 $outputlangs->setDefaultLang($newlang);
337 $outputlangs->load(
'products');
341 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
344 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
351 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
354 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
355 $discount->unlink_invoice();
356 } elseif ($action ==
'valid' && $usercancreate) {
360 if ((preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) &&
367 $last_of_type =
$object->willBeLastOfSameType(
true);
368 if (empty(
$object->date_validation) && !$last_of_type[0]) {
378 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
387 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
396 $array_of_total_ht_per_vat_rate = array();
397 $array_of_total_ht_devise_per_vat_rate = array();
398 foreach (
$object->lines as $line) {
400 $vat_src_code_for_line =
'';
401 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
402 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
404 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
405 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
407 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
408 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
412 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
413 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
414 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
416 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
417 if (
$object->type == $object::TYPE_DEPOSIT) {
418 $langs->load(
"errors");
420 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
424 $tmpvatratetoshow = explode(
'_', $vatrate);
425 $tmpvatratetoshow[0] = round((
float) $tmpvatratetoshow[0], 2);
427 if ($tmpvatratetoshow[0] != 0) {
428 $langs->load(
"errors");
429 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", $tmpvatratetoshow[0]),
null,
'errors');
437 } elseif ($action ==
'classin' && $usercancreate) {
440 } elseif ($action ==
'setmode' && $usercancreate) {
446 } elseif ($action ==
'setretainedwarrantyconditions' && $usercancreate) {
448 $object->retained_warranty_fk_cond_reglement = 0;
449 $result =
$object->setRetainedWarrantyPaymentTerms(
GETPOSTINT(
'retained_warranty_fk_cond_reglement'));
454 $old_rw_date_lim_reglement =
$object->retained_warranty_date_limit;
455 $new_rw_date_lim_reglement =
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
456 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
457 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
462 $result =
$object->update($user);
466 } elseif ($action ==
'setretainedwarranty' && $usercancreate) {
472 } elseif ($action ==
'setretainedwarrantydatelimit' && $usercancreate) {
474 $result =
$object->setRetainedWarrantyDateLimit(
GETPOSTFLOAT(
'retained_warranty_date_limit'));
478 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
479 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
480 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
482 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
484 $old_date_lim_reglement =
$object->date_lim_reglement;
486 if (empty($newdate)) {
487 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
488 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.
$id.
'&action=editinvoicedate&token='.
newToken());
493 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
495 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
500 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
501 if ($new_date_lim_reglement) {
502 $object->date_lim_reglement = $new_date_lim_reglement;
507 $result =
$object->update($user);
510 $action =
'editinvoicedate';
512 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
517 $object->date_pointoftax = $date_pointoftax;
518 $result =
$object->update($user);
522 } elseif ($action ==
'setconditions' && $usercancreate) {
524 $object->cond_reglement_code = 0;
525 $object->cond_reglement_id = 0;
538 $old_date_lim_reglement =
$object->date_lim_reglement;
539 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
540 if ($new_date_lim_reglement) {
541 $object->date_lim_reglement = $new_date_lim_reglement;
546 $result =
$object->update($user);
558 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
562 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
563 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
565 $result =
$object->update($user);
569 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
572 $result =
$object->update($user);
579 $outputlangs = $langs;
582 $newlang =
GETPOST(
'lang_id',
'aZ09');
585 $newlang =
$object->thirdparty->default_lang;
587 if (!empty($newlang)) {
589 $outputlangs->setDefaultLang($newlang);
590 $outputlangs->load(
'products');
595 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
601 } elseif ($action ==
'set_incoterms' && isModEnabled(
'incoterm') && $usercancreate) {
603 } elseif ($action ==
'setbankaccount' && $usercancreate) {
605 } elseif ($action ==
'setremisepercent' && $usercancreate) {
608 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
626 if (
GETPOSTINT(
"remise_id_for_payment") > 0) {
627 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
629 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
633 $remaintopay =
$object->getRemainToPay(0);
637 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
641 $result = $discount->link_to_invoice(0, $id);
649 $newremaintopay =
$object->getRemainToPay(0);
650 if ($newremaintopay == 0) {
663 $outputlangs = $langs;
666 $newlang =
GETPOST(
'lang_id',
'aZ09');
670 $newlang =
$object->thirdparty->default_lang;
672 if (!empty($newlang)) {
674 $outputlangs->setDefaultLang($newlang);
678 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
683 } elseif ($action ==
'setref' && $usercancreate) {
685 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', 0,
'',
'', $user,
'BILL_MODIFY');
686 } elseif ($action ==
'setref_client' && $usercancreate) {
689 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
698 $qualified_for_stock_change = 0;
700 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
702 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
705 if ($qualified_for_stock_change) {
706 if (!$idwarehouse || $idwarehouse == - 1) {
708 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
715 $result =
$object->validate($user,
'', $idwarehouse);
719 $outputlangs = $langs;
722 $newlang =
GETPOST(
'lang_id',
'aZ09');
725 $newlang =
$object->thirdparty->default_lang;
727 if (!empty($newlang)) {
729 $outputlangs->setDefaultLang($newlang);
730 $outputlangs->load(
'products');
736 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
749 } elseif ($action ==
'confirm_modif' && $usercanunvalidate) {
758 $qualified_for_stock_change = 0;
760 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
762 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
765 if ($qualified_for_stock_change) {
766 if (!$idwarehouse || $idwarehouse == - 1) {
768 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
777 $sql =
'SELECT pf.amount';
778 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf';
779 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
781 $result = $db->query($sql);
784 $num = $db->num_rows($result);
787 $objp = $db->fetch_object($result);
788 $totalpaid += $objp->amount;
795 $resteapayer =
$object->total_ttc - $totalpaid;
798 $ventilExportCompta =
$object->getVentilExportCompta();
801 if ($ventilExportCompta == 0) {
803 $result =
$object->setDraft($user, $idwarehouse);
810 $outputlangs = $langs;
813 $newlang =
GETPOST(
'lang_id',
'aZ09');
816 $newlang =
$object->thirdparty->default_lang;
818 if (!empty($newlang)) {
820 $outputlangs->setDefaultLang($newlang);
821 $outputlangs->load(
'products');
826 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
831 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
834 $result =
$object->setPaid($user);
838 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
841 $close_code =
GETPOST(
"close_code",
'restricthtml');
842 $close_note =
GETPOST(
"close_note",
'restricthtml');
844 $result =
$object->setPaid($user, $close_code, $close_note);
849 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
851 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
854 $close_code =
GETPOST(
"close_code",
'restricthtml');
855 $close_note =
GETPOST(
"close_note",
'restricthtml');
857 $result =
$object->setCanceled($user, $close_code, $close_note);
862 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
864 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
872 $result = $discountcheck->fetch(0,
$object->id);
885 $amount_ht = $amount_tva = $amount_ttc = array();
886 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
890 foreach (
$object->lines as $line) {
891 if ($line->product_type < 9 && $line->total_ht != 0) {
892 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
894 if (!isset($amount_ht[$keyforvatrate])) {
895 $amount_ht[$keyforvatrate]=0;
897 $amount_ht[$keyforvatrate] += $line->total_ht;
898 if (!isset($amount_tva[$keyforvatrate])) {
899 $amount_tva[$keyforvatrate]=0;
901 $amount_tva[$keyforvatrate] += $line->total_tva;
902 if (!isset($amount_ttc[$keyforvatrate])) {
903 $amount_ttc[$keyforvatrate]=0;
905 $amount_ttc[$keyforvatrate] += $line->total_ttc;
906 if (!isset($multicurrency_amount_ht[$keyforvatrate])) {
907 $multicurrency_amount_ht[$keyforvatrate]=0;
909 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
910 if (!isset($multicurrency_amount_tva[$keyforvatrate])) {
911 $multicurrency_amount_tva[$keyforvatrate]=0;
913 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
914 if (!isset($multicurrency_amount_ttc[$keyforvatrate])) {
915 $multicurrency_amount_ttc[$keyforvatrate]=0;
917 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
921 '@phan-var-force array<string,float> $amount_ht
922 @phan-var-force array<string,float> $amount_tva
923 @phan-var-force array<string,float> $amount_ttc
924 @phan-var-force array<string,float> $multicurrency_amount_ht
925 @phan-var-force array<string,float> $multicurrency_amount_tva
926 @phan-var-force array<string,float> $multicurrency_amount_ttc';
930 $alreadypaid =
$object->getSommePaiement();
931 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
932 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
933 foreach ($amount_ht as $vatrate => $val) {
934 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
935 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
936 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
937 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
938 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
939 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
948 $discount->description =
'(CREDIT_NOTE)';
950 $discount->description =
'(DEPOSIT)';
952 $discount->description =
'(EXCESS RECEIVED)';
954 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
956 $discount->fk_soc =
$object->socid;
957 $discount->socid =
$object->socid;
958 $discount->fk_facture_source =
$object->id;
966 $sql =
'SELECT SUM(pf.amount) as total_paiements';
967 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
968 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
969 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
970 $sql .=
' AND pf.fk_paiement = p.rowid';
971 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
972 $resql = $db->query($sql);
977 $res = $db->fetch_object($resql);
978 $total_paiements = $res->total_paiements;
981 $total_creditnote_and_deposit = 0;
982 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
983 $sql .=
" re.description, re.fk_facture_source";
984 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
985 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
986 $resql = $db->query($sql);
987 if (!empty($resql)) {
988 while ($obj = $db->fetch_object($resql)) {
989 $total_creditnote_and_deposit += $obj->amount_ttc;
995 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
996 $discount->amount_tva = 0;
997 $discount->tva_tx = 0;
998 $discount->vat_src_code =
'';
1000 $result = $discount->create($user);
1006 foreach ($amount_ht as $tva_tx => $xxx) {
1007 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
1008 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
1009 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
1010 $discount->multicurrency_amount_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1011 $discount->multicurrency_amount_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1012 $discount->multicurrency_amount_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1017 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
1018 $vat_src_code = $reg[1];
1019 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
1022 $discount->tva_tx = abs((
float) $tva_tx);
1023 $discount->vat_src_code = $vat_src_code;
1025 $result = $discount->create($user);
1033 if (empty($error)) {
1036 $result =
$object->setPaid($user);
1051 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
1056 $result = $paiement->fetch(
GETPOSTINT(
'paiement_id'));
1058 $result = $paiement->delete($user);
1060 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1068 } elseif ($action ==
'add' && $usercancreate) {
1075 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1082 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
1092 if (empty($dateinvoice)) {
1094 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1104 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1114 $object->date_pointoftax = $date_pointoftax;
1115 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1116 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1127 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1128 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1145 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1147 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1151 if (empty($dateinvoice)) {
1153 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1163 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1168 if (!empty($originentity)) {
1169 $object->entity = $originentity;
1175 $object->date_pointoftax = $date_pointoftax;
1176 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1177 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1182 $object->cond_reglement_id = 0;
1188 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1189 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1193 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1196 $facture_source =
new Facture($db);
1197 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1198 if ($facture_source->isSituationInvoice()) {
1199 $object->situation_counter = $facture_source->situation_counter;
1200 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1201 $facture_source->fetchPreviousNextSituationInvoice();
1211 if (
$object->copy_linked_contact($facture_source,
'internal') < 0) {
1213 } elseif ($facture_source->socid ==
$object->socid) {
1215 if (
$object->copy_linked_contact($facture_source,
'external') < 0) {
1226 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1227 if (!empty($facture_source->lines)) {
1228 $fk_parent_line = 0;
1230 foreach ($facture_source->lines as $line) {
1232 if (method_exists($line,
'fetch_optionals')) {
1234 $line->fetch_optionals();
1238 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1239 $fk_parent_line = 0;
1243 if ($facture_source->isSituationInvoice()) {
1244 $source_fk_prev_id = $line->fk_prev_id;
1245 $line->fk_prev_id = $line->id;
1247 if (!empty($facture_source->tab_previous_situation_invoice)) {
1250 $tab_jumped_credit_notes = array();
1251 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1252 $searchPreviousInvoice =
true;
1253 while ($searchPreviousInvoice) {
1254 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1255 $searchPreviousInvoice =
false;
1259 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1265 $maxPrevSituationPercent = 0;
1266 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1267 if ($prevLine->id == $source_fk_prev_id) {
1268 $maxPrevSituationPercent = max($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;
1285 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1290 $maxPrevSituationPercent = 0;
1291 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1292 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1293 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1294 $maxPrevSituationPercent = $prevLine->situation_percent;
1296 $line->total_ht -= $prevLine->total_ht;
1297 $line->total_tva -= $prevLine->total_tva;
1298 $line->total_ttc -= $prevLine->total_ttc;
1299 $line->total_localtax1 -= $prevLine->total_localtax1;
1300 $line->total_localtax2 -= $prevLine->total_localtax2;
1302 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1303 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1304 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1305 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1311 $line->situation_percent += $maxPrevSituationPercent;
1317 $line->fk_facture =
$object->id;
1318 $line->fk_parent_line = $fk_parent_line;
1320 $line->subprice = -$line->subprice;
1322 $line->total_ht = -$line->total_ht;
1323 $line->total_tva = -$line->total_tva;
1324 $line->total_ttc = -$line->total_ttc;
1325 $line->total_localtax1 = -$line->total_localtax1;
1326 $line->total_localtax2 = -$line->total_localtax2;
1328 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1329 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1330 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1331 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1333 $line->context[
'createcreditnotefrominvoice'] = 1;
1334 $result = $line->insert(0, 1);
1339 if ($result > 0 && $line->product_type == 9) {
1340 $fk_parent_line = $result;
1348 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1349 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1350 $totalpaid = $facture_source->getSommePaiement();
1351 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1352 $totaldeposits = $facture_source->getSumDepositsUsed();
1353 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1355 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1356 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1359 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1364 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1365 $tva_tx = (float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY');
1370 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), 0, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC', $remain_to_pay);
1375 if (!empty(
$object->fk_facture_source) &&
$id > 0) {
1376 $facture_source->fetch(
$object->fk_facture_source);
1377 $facture_source->fetchObjectLinked();
1379 if (!empty($facture_source->linkedObjectsIds)) {
1380 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1381 $object->add_object_linked($sourcetype, current($TIds));
1390 if (empty($dateinvoice)) {
1392 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1403 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1413 $object->date_pointoftax = $date_pointoftax;
1414 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1415 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1427 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1428 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1440 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1441 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1442 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1446 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1450 if (empty($dateinvoice)) {
1452 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1462 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1463 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1468 if ($typeamount && !empty($origin) && !empty($originid)) {
1469 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1470 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1474 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1475 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1479 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1480 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1490 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1500 $object->date_pointoftax = $date_pointoftax;
1501 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1502 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1514 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1515 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1519 $object->situation_counter = 1;
1524 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1526 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1528 $object->retained_warranty = 0;
1529 $object->retained_warranty_fk_cond_reglement = 0;
1532 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1533 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1536 $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);
1541 if (!empty($origin) && !empty($originid)) {
1544 $element = $subelement = $origin;
1545 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1546 $element = $regs[1];
1547 $subelement = $regs[2];
1551 if ($element ==
'order') {
1552 $element = $subelement =
'commande';
1554 if ($element ==
'propal') {
1555 $element =
'comm/propal';
1556 $subelement =
'propal';
1558 if ($element ==
'contract') {
1559 $element = $subelement =
'contrat';
1561 if ($element ==
'inter') {
1562 $element = $subelement =
'fichinter';
1564 if ($element ==
'shipping') {
1565 $element = $subelement =
'expedition';
1569 $object->origin_type = $origin;
1570 $object->origin_id = $originid;
1575 if (
$object->origin ==
'shipping') {
1576 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1578 $exp->fetch(
$object->origin_id);
1579 $exp->fetchObjectLinked();
1580 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1581 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1582 $object->linked_objects[
'commande'] = $value;
1588 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
1596 $classname = ucfirst($subelement);
1597 $srcobject =
new $classname($db);
1598 '@phan-var-force CommonObject $srcobject';
1600 dol_syslog(
"Try to find source object origin=".
$object->origin.
" originid=".
$object->origin_id.
" to add lines or deposit lines");
1601 $result = $srcobject->fetch(
$object->origin_id);
1607 $amountdeposit = array();
1610 if ($typeamount ==
'amount') {
1611 $amount = (float) $valuedeposit;
1613 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1616 $TTotalByTva = array();
1617 foreach ($srcobject->lines as &$line) {
1618 if (empty($line->qty)) {
1621 if (!empty($line->special_code)) {
1624 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1626 '@phan-var-force array<string,float> $TTotalByTva';
1628 $amount_ttc_diff = 0.;
1629 foreach ($TTotalByTva as $tva => &$total) {
1630 if (empty($amountdeposit[$tva])) {
1631 $amountdeposit[$tva] = 0;
1633 $coef = $total / $srcobject->total_ttc;
1634 $am = $amount * $coef;
1635 $amount_ttc_diff += $am;
1636 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1639 if ($typeamount ==
'amount') {
1640 $amountdeposit[0] = $valuedeposit;
1641 } elseif ($typeamount ==
'variable') {
1644 $lines = $srcobject->lines;
1645 $numlines = count($lines);
1646 for ($i = 0; $i < $numlines; $i++) {
1648 if (empty($lines[$i]->qty)) {
1651 if (!empty($lines[$i]->special_code)) {
1655 $totalamount += $lines[$i]->total_ht;
1656 $tva_tx = $lines[$i]->tva_tx;
1658 if (empty($amountdeposit[$tva_tx])) {
1659 $amountdeposit[$tva_tx] = 0;
1661 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1665 if ($totalamount == 0) {
1666 $amountdeposit[0] = 0;
1674 $amount_ttc_diff = $amountdeposit[0];
1677 foreach ($amountdeposit as $tva => $amount) {
1678 if (empty($amount)) {
1683 'amount' =>
'FixAmount',
1684 'variable' =>
'VarAmount'
1686 $descline =
'(DEPOSIT)';
1688 if ($typeamount ==
'amount') {
1689 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1690 } elseif ($typeamount ==
'variable') {
1691 $descline .=
' ('.$valuedeposit.
'%)';
1694 $descline .=
' - '.$srcobject->ref;
1707 $i >= 0 ? $lines[$i]->info_bits : 0,
1713 $i >= 0 ? $lines[$i]->special_code : 0,
1726 (!empty(
$conf->global->MAIN_DEPOSIT_MULTI_TVA) ? 0 : 1)
1730 $diff =
$object->total_ttc - $amount_ttc_diff;
1734 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1735 $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);
1744 $lines = $srcobject->lines;
1745 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1746 $srcobject->fetch_lines();
1747 $lines = $srcobject->lines;
1752 if (is_array($lines)) {
1753 foreach ($lines as $line) {
1755 $line->qty =
price2num((
float) $line->qty * (
float) $valuestandardinvoice / 100,
'MS');
1761 if (is_array($lines)) {
1762 foreach ($lines as $line) {
1764 $line->qty =
price2num((
float) $line->qty * (
float) $valuedeposit / 100,
'MS');
1769 $fk_parent_line = 0;
1770 $num = count($lines);
1772 for ($i = 0; $i < $num; $i++) {
1773 if (!in_array($lines[$i]->
id, $selectedLines)) {
1778 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
1782 if (!isset(
$conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1783 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1785 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
1789 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1790 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1792 if (
$object->situation_counter == 1) {
1793 $lines[$i]->situation_percent = 0;
1796 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
1799 $desc = $label ? $label : $langs->trans(
'Discount');
1803 $discount->fk_soc =
$object->socid;
1804 $discount->socid =
$object->socid;
1805 $discount->amount_ht = abs($lines[$i]->total_ht);
1806 $discount->amount_tva = abs($lines[$i]->total_tva);
1807 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1808 $discount->tva_tx = $lines[$i]->tva_tx;
1809 $discount->fk_user = $user->id;
1810 $discount->description = $desc;
1811 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1812 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1813 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1814 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1816 $discountid = $discount->create($user);
1817 if ($discountid > 0) {
1818 $result =
$object->insert_discount($discountid);
1830 $date_start =
false;
1831 if (isset($lines[$i]->date_debut_prevue)) {
1832 $date_start = $lines[$i]->date_debut_prevue;
1834 if (isset($lines[$i]->date_debut_reel)) {
1835 $date_start = $lines[$i]->date_debut_reel;
1837 if (isset($lines[$i]->date_start)) {
1838 $date_start = $lines[$i]->date_start;
1843 if (isset($lines[$i]->date_fin_prevue)) {
1844 $date_end = $lines[$i]->date_fin_prevue;
1846 if (isset($lines[$i]->date_fin_reel)) {
1847 $date_end = $lines[$i]->date_fin_reel;
1849 if (isset($lines[$i]->date_end)) {
1850 $date_end = $lines[$i]->date_end;
1854 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1855 $fk_parent_line = 0;
1858 $array_options = array();
1860 if (method_exists($lines[$i],
'fetch_optionals')) {
1861 $lines[$i]->fetch_optionals();
1862 $array_options = $lines[$i]->array_options;
1865 $tva_tx = $lines[$i]->tva_tx;
1866 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
1867 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1877 $lines[$i]->subprice,
1882 $lines[$i]->fk_product,
1883 $lines[$i]->remise_percent,
1887 $lines[$i]->info_bits,
1888 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except : null,
1893 $lines[$i]->special_code,
1897 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice : null,
1901 $lines[$i]->situation_percent ?? 100,
1902 $lines[$i]->fk_prev_id ?? 0,
1903 $lines[$i]->fk_unit,
1918 if ($result > 0 && $lines[$i]->product_type == 9) {
1919 $fk_parent_line = $result;
1929 $object->update_price(1,
'auto', 0, $mysoc);
1957 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id,
'objFrom' => $srcobject);
1958 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
1971 for ($i = 1; $i <= $NBLINES; $i++) {
1977 $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);
1981 $object->update_price(1,
'auto', 0, $mysoc);
1988 if (empty($dateinvoice)) {
1990 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
2000 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
2010 if (!empty($origin) && !empty($originid)) {
2011 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2014 $object->origin_type = $origin;
2015 $object->origin_id = $originid;
2019 $retained_warranty =
GETPOSTINT(
'retained_warranty');
2020 if (
price2num($retained_warranty) > 0) {
2024 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
2025 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
2028 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
2029 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
2030 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
2032 $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);
2035 foreach (
$object->lines as $i => &$line) {
2036 $line->fk_prev_id = $line->id;
2037 $line->fetch_optionals();
2039 $line->situation_percent = 0;
2041 $line->situation_percent = $line->get_prev_progress(
$object->id);
2045 $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);
2046 $line->total_ht = (float) $tabprice[0];
2047 $line->total_tva = (float) $tabprice[1];
2048 $line->total_ttc = (float) $tabprice[2];
2049 $line->total_localtax1 = (float) $tabprice[9];
2050 $line->total_localtax2 = (float) $tabprice[10];
2051 $line->multicurrency_total_ht = (float) $tabprice[16];
2052 $line->multicurrency_total_tva = (float) $tabprice[17];
2053 $line->multicurrency_total_ttc = (float) $tabprice[18];
2056 if ($line->fk_remise_except) {
2058 $result = $discount->fetch($line->fk_remise_except);
2061 if ($discount->fk_facture_line > 0) {
2062 $line->fk_remise_except = 0;
2071 $object->date_pointoftax = $date_pointoftax;
2072 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2088 $object->situation_counter += 1;
2094 $nextSituationInvoice =
new Facture($db);
2095 $nextSituationInvoice->fetch($id);
2098 $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
2099 $ret = $extrafields->setOptionalsFromPost(
null, $nextSituationInvoice);
2101 $nextSituationInvoice->insertExtraFields();
2105 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id);
2106 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $nextSituationInvoice, $action);
2117 if ($id > 0 && !$error) {
2122 $outputlangs = $langs;
2125 $newlang =
GETPOST(
'lang_id',
'aZ09');
2128 if (empty(
$object->thirdparty)) {
2131 $newlang =
$object->thirdparty->default_lang;
2133 if (!empty($newlang)) {
2135 $outputlangs->setDefaultLang($newlang);
2136 $outputlangs->load(
'products');
2141 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2147 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2152 $_GET[
"origin"] = $_POST[
"origin"];
2153 $_GET[
"originid"] = $_POST[
"originid"];
2156 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2160 foreach (
$object->lines as $line) {
2161 if ($line->product_type == 1) {
2162 $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);
2165 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2167 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2168 $vat_rate = str_replace(
'*',
'', $vat_rate);
2171 foreach (
$object->lines as $line) {
2172 $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);
2174 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2176 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2177 $remise_percent = str_replace(
'*',
'', $remise_percent);
2178 foreach (
$object->lines as $line) {
2179 $tvatx = $line->tva_tx;
2180 if (!empty($line->vat_src_code)) {
2181 $tvatx .=
' ('.$line->vat_src_code.
')';
2183 $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);
2185 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && $usercancreate) {
2186 $langs->load(
'errors');
2191 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
2194 $price_ht_devise =
'';
2196 $price_ttc_devise =
'';
2199 $price_min_ttc =
'';
2201 if (
GETPOST(
'price_ht') !==
'') {
2204 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2207 if (
GETPOST(
'price_ttc') !==
'') {
2210 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2211 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2214 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2215 if ($prod_entry_mode ==
'free') {
2221 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2226 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2229 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
2230 if (empty($remise_percent)) {
2231 $remise_percent = 0;
2235 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2236 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2238 if (is_array($extralabelsline)) {
2240 foreach ($extralabelsline as $key => $value) {
2241 unset($_POST[
"options_".$key.$predef]);
2245 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2246 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2249 if (!$prod_entry_mode) {
2251 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2255 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2256 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2261 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0)
2262 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
2263 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
2264 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
2265 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
2266 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
2267 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2268 $langs->load(
"errors");
2269 if (
$object->type == $object::TYPE_DEPOSIT) {
2271 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2273 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2278 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
2279 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
2283 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
2284 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2288 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2292 $langs->load(
"errors");
2293 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2297 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2298 if ($combinations =
GETPOST(
'combinations',
'array')) {
2302 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2303 $idprod = $res->fk_product_child;
2305 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2311 $price_base_type =
null;
2312 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
2318 $ret =
$object->fetch_thirdparty();
2323 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2334 if (!empty($idprod) && $idprod > 0) {
2336 $prod->fetch($idprod);
2338 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2343 $datapriceofproduct = $prod->getSellPrice($mysoc,
$object->thirdparty, $pqp);
2345 $pu_ht = $datapriceofproduct[
'pu_ht'];
2346 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2347 $price_min = $datapriceofproduct[
'price_min'];
2348 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2349 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2353 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2354 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $prod->tva_tx));
2358 if (!empty($price_ht) || $price_ht ===
'0') {
2360 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2361 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2362 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2365 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2367 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2368 } elseif ($tmpvat != $tmpprodvat) {
2370 if ($price_base_type !=
'HT') {
2371 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2373 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2381 $outputlangs = $langs;
2383 if (
GETPOST(
'lang_id',
'aZ09')) {
2384 $newlang =
GETPOST(
'lang_id',
'aZ09');
2386 if (empty($newlang)) {
2387 $newlang =
$object->thirdparty->default_lang;
2389 if (!empty($newlang)) {
2391 $outputlangs->setDefaultLang($newlang);
2392 $outputlangs->load(
'products');
2395 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->
description;
2397 $desc = $prod->description;
2406 $desc = $product_desc;
2412 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
2416 $outputlangs = $langs;
2418 if (
GETPOST(
'lang_id',
'alpha')) {
2419 $newlang =
GETPOST(
'lang_id',
'alpha');
2421 if (empty($newlang)) {
2422 $newlang =
$object->thirdparty->default_lang;
2424 if (!empty($newlang)) {
2426 $outputlangs->setDefaultLang($newlang);
2427 $outputlangs->load(
'products');
2429 if (!empty($prod->customcode)) {
2430 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2432 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2435 if (!empty($prod->country_code)) {
2436 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $outputlangs, 0);
2439 if (!empty($prod->customcode)) {
2440 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2442 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2445 if (!empty($prod->country_code)) {
2446 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $langs, 0);
2453 $type = $prod->type;
2454 $fk_unit = $prod->fk_unit;
2456 if (!empty($price_ht)) {
2461 if (!empty($price_ttc)) {
2466 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2467 $tva_tx = str_replace(
'*',
'', $tva_tx);
2468 if (empty($tva_tx)) {
2471 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2472 $desc = $product_desc;
2474 $fk_unit =
GETPOST(
'units',
'alpha');
2476 if ($pu_ttc && !$pu_ht) {
2477 $price_base_type =
'TTC';
2491 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2492 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2495 $pu_equivalent = $pu_ht;
2496 $pu_equivalent_ttc = $pu_ttc;
2498 $currency_tx =
$object->multicurrency_tx;
2502 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2503 $pu_equivalent = (float) $pu_ht_devise * $currency_tx;
2505 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2506 $pu_equivalent_ttc = (float) $pu_ttc_devise * $currency_tx;
2526 $price2num_remise_percent =
price2num($remise_percent);
2527 $price2num_price_min =
price2num($price_min);
2528 $price2num_price_min_ttc =
price2num($price_min_ttc);
2529 if (empty($price2num_pu_ht)) {
2530 $price2num_pu_ht = 0;
2532 if (empty($price2num_remise_percent)) {
2533 $price2num_remise_percent = 0;
2535 if (empty($price2num_price_min)) {
2536 $price2num_price_min = 0;
2538 if (empty($price2num_price_min_ttc)) {
2539 $price2num_price_min_ttc = 0;
2544 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2545 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2548 } 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') {
2549 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2556 '@phan-var-force CommonObjectLine[] $lines';
2558 if (isModEnabled(
'productbatch') && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) &&
getDolGlobalString(
'INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS')) {
2559 $langs->load(
'productbatch');
2560 foreach ($lines[$i]->detail_batch as $batchline) {
2561 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2565 $situation_percent = GETPOSTISSET(
'progress') ?
GETPOSTINT(
'progress') : 100;
2568 $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, $situation_percent, 0, $fk_unit, $pu_ht_devise);
2573 $outputlangs = $langs;
2576 $newlang =
GETPOST(
'lang_id',
'aZ09');
2579 $newlang =
$object->thirdparty->default_lang;
2581 if (!empty($newlang)) {
2583 $outputlangs->setDefaultLang($newlang);
2584 $outputlangs->load(
'products');
2589 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2595 unset($_POST[
'prod_entry_mode']);
2596 unset($_POST[
'qty']);
2597 unset($_POST[
'type']);
2598 unset($_POST[
'remise_percent']);
2599 unset($_POST[
'price_ht']);
2600 unset($_POST[
'multicurrency_price_ht']);
2601 unset($_POST[
'price_ttc']);
2602 unset($_POST[
'tva_tx']);
2603 unset($_POST[
'product_ref']);
2604 unset($_POST[
'product_label']);
2605 unset($_POST[
'product_desc']);
2606 unset($_POST[
'fournprice']);
2607 unset($_POST[
'buying_price']);
2608 unset($_POST[
'np_marginRate']);
2609 unset($_POST[
'np_markRate']);
2610 unset($_POST[
'dp_desc']);
2611 unset($_POST[
'idprod']);
2612 unset($_POST[
'units']);
2613 unset($_POST[
'date_starthour']);
2614 unset($_POST[
'date_startmin']);
2615 unset($_POST[
'date_startsec']);
2616 unset($_POST[
'date_startday']);
2617 unset($_POST[
'date_startmonth']);
2618 unset($_POST[
'date_startyear']);
2619 unset($_POST[
'date_endhour']);
2620 unset($_POST[
'date_endmin']);
2621 unset($_POST[
'date_endsec']);
2622 unset($_POST[
'date_endday']);
2623 unset($_POST[
'date_endmonth']);
2624 unset($_POST[
'date_endyear']);
2625 unset($_POST[
'situations']);
2626 unset($_POST[
'progress']);
2634 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2635 if (!
$object->fetch($id) > 0) {
2647 $vat_rate = str_replace(
'*',
'', $vat_rate);
2659 if (preg_match(
'/\*/', $vat_rate)) {
2664 $vat_rate = str_replace(
'*',
'', $vat_rate);
2673 $pu_equivalent = $pu_ht;
2674 $pu_equivalent_ttc = $pu_ttc;
2676 $currency_tx =
$object->multicurrency_tx;
2680 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2681 $pu_equivalent = (float) $pu_ht_devise * (
float) $currency_tx;
2683 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2684 $pu_equivalent_ttc = (float) $pu_ttc_devise * (
float) $currency_tx;
2699 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2700 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
2702 if (is_array($extralabelsline)) {
2704 foreach ($extralabelsline as $key => $value) {
2705 unset($_POST[
"options_".$key]);
2711 if ($special_code == 3) {
2717 $percent = $line->get_prev_progress(
$object->id);
2722 if ($progress >= 0) {
2723 $mesg = $langs->trans(
"CantBeNullOrPositive");
2727 } elseif ($progress < $line->situation_percent) {
2728 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
2732 } elseif ($progress < $percent) {
2733 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
2744 if (!empty($productid)) {
2746 $product->fetch($productid);
2748 $type = $product->type;
2750 $price_min = $product->price_min;
2752 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
2754 $price_min_ttc = $product->price_min_ttc;
2756 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
2763 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
2764 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2767 $action =
'editline';
2768 } 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') {
2769 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2772 $action =
'editline';
2777 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2781 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
2786 $langs->load(
"errors");
2787 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2791 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2792 $langs->load(
"errors");
2793 if (
$object->type == $object::TYPE_DEPOSIT) {
2795 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2797 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2801 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2808 $previousprogress = $line->getAllPrevProgress($line->fk_facture);
2811 if ($fullprogress < $previousprogress) {
2813 setEventMessages($langs->trans(
'CantBeLessThanMinPercent'),
null,
'errors');
2817 if ($fullprogress > 100) {
2818 $fullprogress = 100;
2820 $addprogress = $fullprogress - $previousprogress;
2827 if (empty($usercancreatemargin)) {
2828 foreach (
$object->lines as &$line) {
2830 $fournprice = $line->fk_fournprice;
2831 $buyingprice = $line->pa_ht;
2837 $price_base_type =
'HT';
2839 if (empty($pu) && !empty($pu_ttc)) {
2841 $price_base_type =
'TTC';
2844 $result =
$object->updateline(
2873 $outputlangs = $langs;
2876 $newlang =
GETPOST(
'lang_id',
'aZ09');
2879 $newlang =
$object->thirdparty->default_lang;
2881 if (!empty($newlang)) {
2883 $outputlangs->setDefaultLang($newlang);
2884 $outputlangs->load(
'products');
2888 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2891 unset($_POST[
'qty']);
2892 unset($_POST[
'type']);
2893 unset($_POST[
'productid']);
2894 unset($_POST[
'remise_percent']);
2895 unset($_POST[
'price_ht']);
2896 unset($_POST[
'multicurrency_price_ht']);
2897 unset($_POST[
'price_ttc']);
2898 unset($_POST[
'tva_tx']);
2899 unset($_POST[
'product_ref']);
2900 unset($_POST[
'product_label']);
2901 unset($_POST[
'product_desc']);
2902 unset($_POST[
'fournprice']);
2903 unset($_POST[
'buying_price']);
2904 unset($_POST[
'np_marginRate']);
2905 unset($_POST[
'np_markRate']);
2906 unset($_POST[
'dp_desc']);
2907 unset($_POST[
'idprod']);
2908 unset($_POST[
'units']);
2909 unset($_POST[
'date_starthour']);
2910 unset($_POST[
'date_startmin']);
2911 unset($_POST[
'date_startsec']);
2912 unset($_POST[
'date_startday']);
2913 unset($_POST[
'date_startmonth']);
2914 unset($_POST[
'date_startyear']);
2915 unset($_POST[
'date_endhour']);
2916 unset($_POST[
'date_endmin']);
2917 unset($_POST[
'date_endsec']);
2918 unset($_POST[
'date_endday']);
2919 unset($_POST[
'date_endmonth']);
2920 unset($_POST[
'date_endyear']);
2921 unset($_POST[
'situations']);
2922 unset($_POST[
'progress']);
2927 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modify')) {
2928 if (!
$object->fetch($id) > 0) {
2931 if (
GETPOST(
'all_progress') !=
"") {
2933 foreach (
$object->lines as $line) {
2935 $percent = $line->getAllPrevProgress(
$object->id);
2937 $percent = $line->get_prev_progress(
$object->id);
2939 if ((
float) $all_progress < (
float) $percent) {
2940 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
2949 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
2950 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2952 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
2954 $object->fetch($id,
'',
'', 0,
true);
2957 &&
$object->isSituationInvoice()
2960 &&
$object->is_last_in_cycle()
2961 && $usercanunvalidate
2964 $newCycle =
$object->newCycle();
2965 if ($newCycle > 1) {
2967 $lastCycle =
$object->situation_cycle_ref;
2968 $lastSituationCounter =
$object->situation_counter;
2969 $linkedCreditNotesList = array();
2971 if (count(
$object->tab_next_situation_invoice) > 0) {
2972 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
2974 && $next_invoice->situation_counter ==
$object->situation_counter
2975 && $next_invoice->fk_facture_source ==
$object->id
2977 $linkedCreditNotesList[] = $next_invoice->id;
2982 $object->situation_cycle_ref = $newCycle;
2983 $object->situation_counter = 1;
2985 if (
$object->update($user) > 0) {
2987 if (count($linkedCreditNotesList) > 0) {
2989 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
2990 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
2991 $sql .=
' , situation_final=0';
2992 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
2993 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
2995 $resql = $db->query($sql);
3001 foreach (
$object->lines as $line) {
3003 if ($line->product_type == 9) {
3008 if (!empty(
$object->tab_previous_situation_invoice)) {
3010 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
3011 $searchPreviousInvoice =
true;
3012 while ($searchPreviousInvoice) {
3013 if (
$object->tab_previous_situation_invoice[$lineIndex]->isSituationInvoice() || $lineIndex < 1) {
3014 $searchPreviousInvoice =
false;
3022 $maxPrevSituationPercent = 0;
3023 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
3024 if ($prevLine->id == $line->fk_prev_id) {
3025 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
3030 $line->situation_percent -= $maxPrevSituationPercent;
3032 if ($line->update() < 0) {
3041 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
3043 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
3046 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
3049 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
3055 $fromElement =
GETPOST(
'fromelement');
3056 $fromElementid =
GETPOST(
'fromelementid');
3057 $importLines =
GETPOST(
'line_checkbox');
3059 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
3060 $lineClassName =
'';
3061 if ($fromElement ==
'commande') {
3063 $lineClassName =
'OrderLine';
3064 } elseif ($fromElement ==
'propal') {
3065 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
3066 $lineClassName =
'PropaleLigne';
3068 $nextRang = count(
$object->lines) + 1;
3071 foreach ($importLines as $lineId) {
3072 if ($lineClassName ===
'') {
3076 dol_syslog(
'compta/facture/card - No lineClassName - skip import', LOG_ERR);
3083 $lineId = intval($lineId);
3084 $originLine =
new $lineClassName($db);
3085 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
3086 $originLine->fetch_optionals();
3087 $desc = $originLine->desc;
3088 $pu_ht = $originLine->subprice;
3089 $qty = $originLine->qty;
3090 $txtva = $originLine->tva_tx;
3091 $txlocaltax1 = $originLine->localtax1_tx;
3092 $txlocaltax2 = $originLine->localtax2_tx;
3093 $fk_product = $originLine->fk_product;
3094 $remise_percent = $originLine->remise_percent;
3095 $date_start = $originLine->date_start;
3096 $date_end = $originLine->date_end;
3097 $fk_code_ventilation = 0;
3098 $info_bits = $originLine->info_bits;
3099 $fk_remise_except = $originLine->fk_remise_except;
3100 $price_base_type =
'HT';
3102 $type = $originLine->product_type;
3103 $rang = $nextRang++;
3104 $special_code = $originLine->special_code;
3105 $origin = $originLine->element;
3106 $origin_id = $originLine->id;
3107 $fk_parent_line = 0;
3108 $fk_fournprice = $originLine->fk_fournprice;
3109 $pa_ht = $originLine->pa_ht;
3110 $label = $originLine->label;
3111 $array_options = $originLine->array_options;
3112 if (
$object->isSituationInvoice()) {
3113 $situation_percent = 0;
3115 $situation_percent = 100;
3118 $fk_unit = $originLine->fk_unit;
3119 $pu_ht_devise = $originLine->multicurrency_subprice;
3121 $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);
3140 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3146 $triggersendname =
'BILL_SENTBYMAIL';
3148 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3149 $trackid =
'inv'.$object->id;
3150 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3154 $permissiontoadd = $usercancreate;
3155 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3158 if ($action ==
'update_extras' && $usercancreate) {
3160 $attribute_name =
GETPOST(
'attribute',
'restricthtml');
3163 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute_name);
3170 $result =
$object->updateExtraField($attribute_name,
'BILL_MODIFY');
3178 $action =
'edit_extras';
3183 if ($action ==
'addcontact' && $usercancreate) {
3184 $result =
$object->fetch($id);
3186 if ($result > 0 && $id > 0) {
3189 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3193 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3196 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3197 $langs->load(
"errors");
3198 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3203 } elseif ($action ==
'swapstatut' && $usercancreate) {
3210 } elseif ($action ==
'deletecontact' && $usercancreate) {
3213 $result =
$object->delete_contact($lineid);
3216 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3224 $action =
'edit_extras';
3235$form =
new Form($db);
3241$bankaccountstatic =
new Account($db);
3243if (isModEnabled(
'project')) {
3249$title =
$object->ref.
" - ".$langs->trans(
'Card');
3250if ($action ==
'create') {
3251 $title = $langs->trans(
"NewBill");
3253$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3259if ($action ==
'create') {
3260 $facturestatic =
new Facture($db);
3261 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3266 $res = $soc->fetch($socid);
3269 $currency_code =
$conf->currency;
3271 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3272 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3278 if (!empty($origin) && !empty($originid)) {
3280 $element = $subelement = $origin;
3282 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3283 $element = $regs[1];
3284 $subelement = $regs[2];
3290 if ($element ==
'project') {
3291 $projectid = $originid;
3293 if (empty($cond_reglement_id)) {
3294 $cond_reglement_id = $soc->cond_reglement_id;
3296 if (empty($mode_reglement_id)) {
3297 $mode_reglement_id = $soc->mode_reglement_id;
3299 if (empty($fk_account)) {
3300 $fk_account = $soc->fk_account;
3302 if (empty($dateinvoice)) {
3308 if ($element ==
'order' || $element ==
'commande') {
3309 $element = $subelement =
'commande';
3311 if ($element ==
'propal') {
3312 $element =
'comm/propal';
3313 $subelement =
'propal';
3315 if ($element ==
'contract') {
3316 $element = $subelement =
'contrat';
3318 if ($element ==
'shipping') {
3319 $element = $subelement =
'expedition';
3324 $classname = ucfirst($subelement);
3325 $objectsrc =
new $classname($db);
3326 '@phan-var-force Commande|Propal|Contrat|Expedition $objectsrc';
3327 $objectsrc->fetch($originid);
3328 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3329 $objectsrc->fetch_lines();
3331 $objectsrc->fetch_thirdparty();
3333 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3334 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3337 if (empty($socid)) {
3338 $soc = $objectsrc->thirdparty;
3341 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3343 if ($element ==
'expedition') {
3344 $ref_client = (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
'');
3346 $elem = $subelem = $objectsrc->origin;
3347 $expeoriginid = $objectsrc->origin_id;
3349 $classname = ucfirst($subelem);
3351 $expesrc =
new $classname($db);
3352 '@phan-var-force Expedition $expesrc';
3353 dol_syslog(
"Is type Facture|Commande or Expedition: $element...expesrc($classname)=".get_class($expesrc));
3354 $expesrc->fetch($expeoriginid);
3356 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3357 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3358 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3360 if (isModEnabled(
'multicurrency')) {
3361 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3362 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3366 $expesrc->fetch_optionals();
3367 $object->array_options = $expesrc->array_options;
3369 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : (!empty($cond_reglement_id) ? $cond_reglement_id : 0)));
3370 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : (!empty($mode_reglement_id) ? $mode_reglement_id : 0)));
3371 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : (!empty($fk_account) ? $fk_account : 0)));
3373 if (isModEnabled(
'multicurrency')) {
3374 if (!empty($objectsrc->multicurrency_code)) {
3375 $currency_code = $objectsrc->multicurrency_code;
3377 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
3378 $currency_tx = $objectsrc->multicurrency_tx;
3383 $objectsrc->fetch_optionals();
3384 $object->array_options = $objectsrc->array_options;
3388 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
3389 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
3390 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
3392 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3394 if (isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3395 $currency_code = $soc->multicurrency_code;
3400 if (!
GETPOST(
'changecompany')) {
3401 if (GETPOSTISSET(
'cond_reglement_id')) {
3402 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3404 if (GETPOSTISSET(
'mode_reglement_id')) {
3405 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3407 if (GETPOSTISSET(
'cond_reglement_id')) {
3413 if (empty($cond_reglement_id)) {
3414 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
3418 if (empty($mode_reglement_id)) {
3419 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
3429 if (!empty($soc->id)) {
3430 $absolute_discount = $soc->getAvailableDiscounts();
3432 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
3433 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
3435 if (!empty(
$conf->use_javascript_ajax)) {
3436 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3442 if ($origin ==
'contrat') {
3443 $langs->load(
"admin");
3444 $text = $langs->trans(
"ToCreateARecurringInvoice");
3445 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3447 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3449 print
info_admin($text, 0, 0,
'0',
'opacitymedium').
'<br>';
3452 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3453 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3454 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3455 print
'<input type="hidden" name="changecompany" value="0">';
3457 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3459 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3460 print
'<input name="ref" type="hidden" value="provisoire">';
3461 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3462 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3463 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3464 print
'<input name="force_fk_account" type="hidden" value="0">';
3465 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3466 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3467 print
'<input type="hidden" name="originentity" value="'.GETPOSTINT(
'originentity').
'">';
3468 if (!empty($currency_tx)) {
3469 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3475 $parameters = array();
3477 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters,
$object, $action);
3478 if (empty($reshook)) {
3479 print
'<table class="border centpercent">';
3481 $exampletemplateinvoice =
new FactureRec($db);
3483 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3484 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
3488 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
3490 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3491 print
'<td colspan="2">';
3492 print $soc->getNomUrl(1,
'customer');
3493 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3495 $arrayoutstandingbills = $soc->getOutstandingBills();
3496 $outstandingBills = $arrayoutstandingbills[
'opened'];
3497 print
' - <span class="opacitymedium">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3498 print
'<span class="amount">'.price($outstandingBills, 0, $langs, 0, 0, -1,
$conf->currency).
'</span>';
3499 if ($soc->outstanding_limit !=
'') {
3500 if ($outstandingBills > $soc->outstanding_limit) {
3501 print
img_warning($langs->trans(
"OutstandingBillReached"));
3503 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1,
$conf->currency);
3508 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3509 print
'<td colspan="2">';
3510 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
3511 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3515 $(document).ready(function() {
3516 $("#socid").change(function() {
3518 console.log("Submit page");
3519 $(\'input[name="action"]\').val(\'create\');
3520 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3521 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3522 $(\'input[name="force_fk_account"]\').val(\'1\');
3523 $("#formtocreate").submit(); */
3525 // For company change, we must submit page with action=create instead of action=add
3526 console.log("We have changed the company - Resubmit page");
3527 jQuery("input[name=changecompany]").val("1");
3528 jQuery("#formtocreateaction").val("create");
3529 jQuery("#formtocreate").submit();
3535 print
' <a href="'.DOL_URL_ROOT.
'/societe/card.php?action=create&customer=3&fournisseur=0&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create').
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddThirdParty").
'"></span></a>';
3542 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3544 foreach ($invoice_predefined->array_options as $key => $option) {
3545 if (!isset(
$object->array_options[$key])) {
3546 $object->array_options[$key] = $invoice_predefined->array_options[$key];
3550 $dateinvoice = $invoice_predefined->date_when;
3551 if (empty($projectid)) {
3552 $projectid = $invoice_predefined->fk_project;
3554 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
3555 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
3556 $fk_account = $invoice_predefined->fk_account;
3557 $note_public = $invoice_predefined->note_public;
3558 $note_private = $invoice_predefined->note_private;
3560 if (!empty($invoice_predefined->multicurrency_code)) {
3561 $currency_code = $invoice_predefined->multicurrency_code;
3563 if (!empty($invoice_predefined->multicurrency_tx)) {
3564 $currency_tx = $invoice_predefined->multicurrency_tx;
3567 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
3568 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
3569 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
3571 $resql = $db->query($sql);
3573 $num = $db->num_rows($resql);
3577 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
3579 print
'<select class="flat" id="fac_rec" name="fac_rec">';
3580 print
'<option value="0" selected></option>';
3582 $objp = $db->fetch_object($resql);
3583 print
'<option value="'.$objp->rowid.
'"';
3586 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
3588 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
3597 print
'<script type="text/javascript">
3598 $(document).ready(function() {
3599 $("#fac_rec").change(function() {
3600 console.log("We have changed the template invoice - Reload page");
3601 var fac_rec = $(this).val();
3602 var socid = $(\'#socid\').val();
3603 // 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.
3604 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3617 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td colspan="2">';
3618 print
'<div class="tagtable">'.
"\n";
3621 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3622 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
3623 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
3625 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'nowraponall', 0, 3,
'standardonsmartphone');
3626 print
'<table class="nobordernopadding"><tr>';
3630 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
3639 print
'<td class="nowrap" style="padding-left: 15px">';
3640 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%').
'"/>';
3643 print
'</tr></table>';
3644 print
'</div></div>';
3646 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
3649 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3650 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
3651 print
'<script type="text/javascript">
3652 jQuery(document).ready(function() {
3653 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
3654 jQuery("#radio_standard").prop("checked", true);
3656 jQuery("#typedeposit, #valuedeposit").click(function() {
3657 jQuery("#radio_deposit").prop("checked", true);
3659 jQuery("#typedeposit").change(function() {
3660 console.log("We change type of down payment");
3661 jQuery("#radio_deposit").prop("checked", true);
3662 setRadioForTypeOfInvoice();
3664 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
3665 setRadioForTypeOfInvoice();
3667 function setRadioForTypeOfInvoice() {
3668 console.log("Change radio for type of invoice");
3669 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
3670 jQuery("#checkforselects").prop("disabled", true);
3671 jQuery("#checkforselects").prop("checked", false);
3672 jQuery(".checkforselect").prop("disabled", true);
3673 jQuery(".checkforselect").prop("checked", false);
3675 jQuery("#checkforselects").prop("disabled", false);
3676 jQuery("#checkforselects").prop("checked", true);
3677 jQuery(".checkforselect").prop("disabled", false);
3678 jQuery(".checkforselect").prop("checked", true);
3684 print
'<table class="nobordernopadding"><tr>';
3686 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
3688 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
3691 if (($origin ==
'propal') || ($origin ==
'commande')) {
3692 print
'<td class="nowrap" style="padding-left: 15px">';
3694 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
3695 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
3696 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
3698 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
3700 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
3701 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
3702 if (!empty($origin_payment_conditions_deposit_percent)) {
3703 $typedeposit =
'variable';
3706 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
3707 $valuedeposit = $objectsrc->deposit_percent;
3709 print $form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
3711 print
'<td class="nowrap" style="padding-left: 5px">';
3712 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span>';
3713 print
'<input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.($valuedeposit ? $valuedeposit :
'').
'"/>';
3716 print
'</tr></table>';
3718 print
'</div></div>';
3725 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3726 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
3727 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
3729 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
3731 print
'</div></div>';
3734 $opt = $form->selectSituationInvoices(
GETPOSTINT(
'originid'), $socid);
3736 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3737 $tmp =
'<input id="radio_situation_bis" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
3738 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3739 $tmp .=
' disabled';
3742 $text = $tmp.
'<label for="radio_situation_bis">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3743 $text .=
'<select class="flat" id="situations" name="situations"';
3744 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3745 $text .=
' disabled';
3749 $text .=
'</select>';
3750 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
3752 print
'</div></div>';
3758 $facids = $facturestatic->list_replacable_invoices($soc->id);
3764 if (is_array($facids)) {
3765 foreach ($facids as $facparam) {
3766 $options .=
'<option value="'.$facparam [
'id'].
'"';
3767 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
3768 $options .=
' selected';
3770 $options .=
'>'.$facparam[
'ref'];
3771 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
3772 $options .=
'</option>';
3776 print
'<!-- replacement line -->';
3777 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3778 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
3779 if (!$options || $invoice_predefined->id > 0) {
3780 $tmp .=
' disabled';
3783 print
'<script type="text/javascript">
3784 jQuery(document).ready(function() {
3785 jQuery("#fac_replacement").change(function() {
3786 jQuery("#radio_replacement").prop("checked", true);
3790 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
3791 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
3792 if (!$options || $invoice_predefined->id > 0) {
3793 $text .=
' disabled';
3797 $text .=
'<option value="-1"> </option>';
3800 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
3802 $text .=
'</select>';
3803 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3805 print
'</div></div>';
3809 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3810 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3811 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3812 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'firstsituationonsmartphone');
3814 print
'</div></div>';
3817 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3818 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
3819 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
3821 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'replacementonsmartphone');
3823 print
'</div></div>';
3826 if (empty($origin)) {
3831 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
3837 $newinvoice_static =
new Facture($db);
3838 foreach ($facids as $key => $valarray) {
3839 $newinvoice_static->id = $key;
3840 $newinvoice_static->ref = $valarray [
'ref'];
3841 $newinvoice_static->statut = $valarray [
'status'];
3842 $newinvoice_static->status = $valarray [
'status'];
3843 $newinvoice_static->type = $valarray [
'type'];
3844 $newinvoice_static->paye = $valarray [
'paye'];
3846 $optionsav .=
'<option value="'.$key.
'"';
3847 if ($key ==
GETPOST(
'fac_avoir')) {
3848 $optionsav .=
' selected';
3851 $newinvoice_static->fetch_optionals($key);
3852 $object->array_options = $newinvoice_static->array_options;
3855 $optionsav .= $newinvoice_static->ref;
3856 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
3857 $optionsav .=
'</option>';
3860 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3861 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
3862 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
3863 $tmp .=
' disabled';
3867 print
'<script type="text/javascript">
3868 jQuery(document).ready(function() {
3869 if (jQuery("#radio_creditnote").is(":checked"))
3871 jQuery("#radio_standard").prop("disabled", true);
3873 jQuery("#radio_standard").prop("disabled", false);
3875 if (! jQuery("#radio_creditnote").is(":checked"))
3877 jQuery("#credit_note_options").hide();
3879 jQuery("#radio_creditnote").click(function() {
3880 jQuery("#credit_note_options").show();
3882 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
3883 jQuery("#credit_note_options").hide();
3887 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
3888 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3889 if (!$optionsav || $invoice_predefined->id > 0) {
3890 $text .=
' disabled';
3894 $text .=
'<option value="-1"></option>';
3895 $text .= $optionsav;
3897 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
3899 $text .=
'</select>';
3900 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3903 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
3904 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>";
3905 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>";
3908 print
'</div></div>';
3911 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3913 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3915 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
3917 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
3919 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
3921 print
'</div></div>'.
"\n";
3926 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3927 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
3928 $text = $tmp.
'<label class="opacitymedium" for="radio_template">'.$langs->trans(
"RepeatableInvoice").
'</label> ';
3929 $desc = $form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3,
'templateonsmartphone');
3931 print
'</div></div>';
3940 foreach ($listtType as $type) {
3941 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
3943 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
3946 print
'<script type="text/javascript">
3947 $(document).ready(function() {
3948 var listType = {'.$jsListType.
'};
3949 $("[name=\'type\'").change(function() {
3950 console.log("change name=type");
3951 if ($( this ).prop("checked"))
3953 if(($( this ).val() in listType))
3955 $("#model").val(listType[$( this ).val()]);
3972 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
3973 print $form->getSelectInvoiceSubtype(
GETPOST(
'subtype'),
'subtype', 1, 0,
'');
3979 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
3983 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
3984 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3993 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
3994 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3995 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
4000 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
4001 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4002 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
4007 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
4008 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
4009 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
4014 $rwStyle =
'display:none;';
4015 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
4019 $retained_warranty =
GETPOSTINT(
'retained_warranty');
4020 if (empty($retained_warranty)) {
4021 if ($objectsrc !==
null && property_exists($objectsrc,
'retained_warranty') && !empty($objectsrc->retained_warranty)) {
4023 $retained_warranty = $objectsrc->retained_warranty;
4026 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
4028 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
4029 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
4032 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
4033 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
4034 if (empty($retained_warranty_fk_cond_reglement)) {
4035 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4036 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
4037 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
4039 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4042 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4045 print
'<script type="text/javascript">
4046 $(document).ready(function() {
4047 $("[name=\'type\']").change(function() {
4048 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
4050 $(".retained-warranty-line").show();
4051 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
4054 $(".retained-warranty-line").hide();
4055 $("#new-situation-invoice-retained-warranty").val("");
4059 $("[name=\'type\']:checked").trigger("change");
4065 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
4066 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
4067 print $form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth250 widthcentpercentminusx', 1);
4071 if (isModEnabled(
"bank")) {
4072 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td colspan="2">';
4073 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4074 print $form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth250 widthcentpercentminusx', 1);
4080 if (isModEnabled(
'project') && is_object($formproject)) {
4081 $langs->load(
'projects');
4082 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
4083 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
4084 print $formproject->select_projects(($socid > 0 ? $socid : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
4085 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>';
4090 if (isModEnabled(
'incoterm')) {
4092 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
4093 print
'<td colspan="2" class="maxwidthonsmartphone">';
4094 $incoterm_id =
GETPOST(
'incoterm_id');
4095 $location_incoterms =
GETPOST(
'location_incoterms');
4096 if (empty($incoterm_id)) {
4097 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
4098 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
4100 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
4101 print $form->select_incoterms($incoterm_id, $location_incoterms);
4106 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
4107 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
4108 print $hookmanager->resPrint;
4109 if (empty($reshook)) {
4110 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
4113 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
4114 if ($soc->fetch_optionals() > 0) {
4115 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
4119 print
$object->showOptionals($extrafields,
'create', $parameters);
4123 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
4124 print
'<td colspan="2">';
4125 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
4126 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
4131 $paramkey =
'FACTURE_ADDON_PDF_'.$type;
4136 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
4140 if (isModEnabled(
'multicurrency')) {
4142 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0).
'</td>';
4143 print
'<td colspan="2" class="maxwidthonsmartphone">';
4144 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
4145 print $form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth100 widthcentpercentminusx');
4152 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
4153 if (empty($dateexample)) {
4156 $substitutionarray = array(
4157 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
4158 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
4159 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
4160 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
4161 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
4162 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
4163 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
4164 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
4165 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
4166 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
4167 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
4170 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
4171 foreach ($substitutionarray as $key => $val) {
4172 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
4174 $htmltext .=
'</i>';
4179 print
'<td class="tdtop">';
4180 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
4182 print
'<td valign="top" colspan="2">';
4183 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
4184 print $doleditor->Create(1);
4187 if (empty($user->socid)) {
4189 print
'<td class="tdtop">';
4190 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4192 print
'<td valign="top" colspan="2">';
4193 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4194 print $doleditor->Create(1);
4200 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4201 $langs->loadLangs(array(
'orders',
'propal'));
4204 if ($origin ==
'contrat') {
4205 '@phan-var-force Contrat $objectsrc';
4207 $objectsrc->update_price(1,
'auto', 1);
4210 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4211 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4212 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4213 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4218 switch (get_class($objectsrc)) {
4220 $newclassname =
'CommercialProposal';
4223 $newclassname =
'Order';
4226 $newclassname =
'Sending';
4229 $newclassname =
'Contract';
4232 $newclassname =
'Intervention';
4235 $newclassname = get_class($objectsrc);
4239 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4240 print
'<td colspan="2">';
4241 print $objectsrc->getNomUrl(1);
4243 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
4244 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4246 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4249 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht).
'</td></tr>';
4250 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva).
"</td></tr>";
4251 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4252 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax1).
"</td></tr>";
4255 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4256 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax2).
"</td></tr>";
4258 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc).
"</td></tr>";
4260 if (isModEnabled(
'multicurrency')) {
4261 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
4262 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
4263 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
4271 print $form->buttonsSaveCancel(
"CreateDraft");
4274 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4277 $title = $langs->trans(
'ProductsAndServices');
4280 print
'<div class="div-table-responsive-no-min">';
4281 print
'<table class="noborder centpercent">';
4283 $objectsrc->printOriginLinesList(
'', $selectedLines);
4290} elseif ($id > 0 || !empty($ref)) {
4292 $langs->load(
'errors');
4293 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4302 if ($user->socid > 0 && $user->socid !=
$object->socid) {
4306 $result =
$object->fetch_thirdparty();
4308 $result = $soc->fetch(
$object->socid);
4312 $selleruserevenustamp = $mysoc->useRevenueStamp();
4314 $totalpaid =
$object->getSommePaiement();
4315 $totalcreditnotes =
$object->getSumCreditNotesUsed();
4316 $totaldeposits =
$object->getSumDepositsUsed();
4322 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4325 if (isModEnabled(
'multicurrency')) {
4326 $multicurrency_totalpaid =
$object->getSommePaiement(1);
4327 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
4328 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
4329 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4333 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
4334 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
4341 $resteapayeraffiche = $resteapayer;
4344 $filterabsolutediscount =
"fk_facture_source IS NULL";
4345 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4347 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4348 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4351 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
4352 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
4353 $absolute_discount =
price2num($absolute_discount,
'MT');
4354 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4356 $author =
new User($db);
4357 if (
$object->user_creation_id) {
4358 $author->fetch(
$object->user_creation_id);
4361 $objectidnext =
$object->getIdReplacingInvoice();
4365 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
'bill');
4370 if ($action ==
'converttoreduc') {
4372 $type_fac =
'ExcessReceived';
4374 $type_fac =
'CreditNote';
4376 $type_fac =
'Deposit';
4380 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4381 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4382 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4386 if ($action ==
'delete') {
4387 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
4388 $formquestion = array();
4391 $qualified_for_stock_change = 0;
4393 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4395 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4398 if ($qualified_for_stock_change) {
4399 $langs->load(
"stocks");
4400 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4404 if (
$conf->browser->name ==
'ie') {
4407 $formquestion = array(
4411 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4413 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4415 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4418 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4423 if ($action ==
'situationout') {
4424 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
4425 $label = $langs->trans(
"ConfirmOuting");
4426 $formquestion = array();
4431 &&
$object->is_last_in_cycle()
4432 && $usercanunvalidate
4434 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4439 if ($action ==
'valid') {
4441 $objectref = substr(
$object->ref, 1, 4);
4442 if ($objectref ==
'PROV') {
4446 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
4448 $numref =
$object->getNextNumRef($soc);
4454 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4455 if (isModEnabled(
'notification')) {
4456 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4457 $notify =
new Notify($db);
4459 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid,
$object);
4461 $formquestion = array();
4464 $qualified_for_stock_change = 0;
4466 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4468 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4471 if ($qualified_for_stock_change) {
4472 $langs->load(
"stocks");
4473 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4474 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4477 $warehouse_array = $warehouse->list_array();
4478 if (count($warehouse_array) == 1) {
4479 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4480 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4483 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4485 $formquestion = array(
4491 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4495 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
4500 foreach (
$object->lines as $line) {
4501 $res = $line->fetch_product();
4503 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
4509 if ($nbMandated > 0) {
4511 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
4514 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
4519 $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);
4524 if ($action ==
'modif') {
4525 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
4526 $formquestion = array();
4529 $qualified_for_stock_change = 0;
4531 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4533 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4536 if ($qualified_for_stock_change) {
4537 $langs->load(
"stocks");
4538 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4539 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4542 $warehouse_array = $warehouse->list_array();
4543 if (count($warehouse_array) == 1) {
4544 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
4545 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4548 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4550 $formquestion = array(
4556 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4560 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
4564 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
4565 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
4567 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
4571 $close[$i][
'code'] =
'discount_vat';
4573 $close[$i][
'code'] =
'badcustomer';
4575 $close[$i][
'code'] =
'bankcharge';
4577 $close[$i][
'code'] =
'withholdingtax';
4579 $close[$i][
'code'] =
'other';
4583 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
4585 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4587 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
4589 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
4591 $close[$i][
'label'] = $langs->trans(
"Other");
4595 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4597 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4599 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4601 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
4603 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
4607 foreach ($close as $key => $val) {
4608 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
4612 $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'));
4614 $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);
4618 if ($action ==
'canceled') {
4622 $statusreplacement = 0;
4624 if ($objectidnext) {
4625 $facturereplacement =
new Facture($db);
4626 $facturereplacement->fetch($objectidnext);
4627 $statusreplacement = $facturereplacement->status;
4629 if ($objectidnext && $statusreplacement == 0) {
4630 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
4633 $close[1][
'code'] =
'badcustomer';
4634 $close[2][
'code'] =
'abandon';
4636 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4637 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
4639 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
4640 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
4643 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
4644 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
4647 $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'));
4649 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 270);
4653 if ($action ==
'deletepayment') {
4654 $payment_id =
GETPOST(
'paiement_id');
4655 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
4659 if ($action ==
'ask_deleteline') {
4660 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
4664 if ($action ==
'clone') {
4665 $filter =
'(s.client:IN:1,2,3)';
4667 $formquestion = array(
4668 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
$object->socid,
'socid', $filter, 1)),
4669 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
4672 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
4675 if ($action ==
"remove_file_comfirm") {
4676 $file =
GETPOST(
'file',
'alpha');
4678 $formconfirm = $form->formconfirm(
4679 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
4680 $langs->trans(
'DeleteFileHeader'),
4681 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
4690 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
4691 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
4692 if (empty($reshook)) {
4693 $formconfirm .= $hookmanager->resPrint;
4694 } elseif ($reshook > 0) {
4695 $formconfirm = $hookmanager->resPrint;
4703 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
4705 $morehtmlref =
'<div class="refidno">';
4708 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref',
$object->ref,
$object, $usercancreate,
'string',
'', 0, 1);
4709 $morehtmlref .= $form->editfieldval(
"Ref",
'ref',
$object->ref,
$object, $usercancreate,
'string',
'',
null,
null,
'', 1);
4710 $morehtmlref .=
'<br>';
4713 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer,
$object, $usercancreate,
'string',
'', 0, 1);
4714 $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);
4716 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
4718 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'&search_societe='.urlencode(
$object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
4721 if (isModEnabled(
'project')) {
4722 $langs->load(
"projects");
4723 $morehtmlref .=
'<br>';
4724 if ($usercancreate) {
4725 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
4726 if ($action !=
'classify') {
4727 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
4729 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->socid,
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
4731 if (!empty(
$object->fk_project)) {
4733 $proj->fetch(
$object->fk_project);
4734 $morehtmlref .= $proj->getNomUrl(1);
4736 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
4741 $morehtmlref .=
'</div>';
4743 $object->totalpaid = $totalpaid;
4744 $object->totalcreditnotes = $totalcreditnotes;
4745 $object->totaldeposits = $totaldeposits;
4748 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
4751 $parameters = array();
4753 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters,
$object, $action);
4754 if (empty($reshook)) {
4755 print
'<div class="fichecenter">';
4756 print
'<div class="fichehalfleft">';
4757 print
'<div class="underbanner clearboth"></div>';
4759 print
'<table class="border centpercent tableforfield">';
4762 print
'<tr><td class="fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
4765 print
' '.$object->getSubtypeLabel(
'facture');
4771 $facreplaced =
new Facture($db);
4772 $facreplaced->fetch(
$object->fk_facture_source);
4773 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
4777 $facusing->fetch(
$object->fk_facture_source);
4778 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
4781 $facidavoir =
$object->getListIdAvoirFromInvoice();
4782 if (count($facidavoir) > 0) {
4783 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
4785 foreach ($facidavoir as $id) {
4792 $facavoir->fetch($id);
4793 print $facavoir->getNomUrl(1,
'', 32);
4797 if ($objectidnext > 0) {
4798 $facthatreplace =
new Facture($db);
4799 $facthatreplace->fetch($objectidnext);
4800 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
4805 $result = $discount->fetch(0,
$object->id);
4807 print
' <span class="opacitymediumbycolor paddingleft">';
4808 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
4809 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
4810 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
4812 print
'</span><br>';
4816 if (
$object->fk_fac_rec_source > 0) {
4818 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
4820 print
' <span class="opacitymediumbycolor paddingleft">';
4821 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
4822 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
4830 print
'<!-- Discounts -->'.
"\n";
4831 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
4835 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
4836 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
4841 print
'<table class="nobordernopadding centpercent"><tr><td>';
4842 print $langs->trans(
'DateInvoice');
4844 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
4845 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>';
4847 print
'</tr></table>';
4850 if ($action ==
'editinvoicedate') {
4851 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
4853 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
4862 print
'<table class="nobordernopadding centpercent"><tr><td>';
4863 print $langs->trans(
'DatePointOfTax');
4865 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>';
4866 print
'</tr></table>';
4868 if ($action ==
'editdate_pointoftax') {
4869 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
4871 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
4878 print
'<table class="nobordernopadding centpercent"><tr><td>';
4879 print $langs->trans(
'PaymentConditionsShort');
4882 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>';
4884 print
'</tr></table>';
4887 if ($action ==
'editconditions') {
4888 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->cond_reglement_id,
'cond_reglement_id');
4890 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->cond_reglement_id,
'none');
4899 print
'<table class="nobordernopadding centpercent"><tr><td>';
4900 print $langs->trans(
'DateMaxPayment');
4903 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>';
4905 print
'</tr></table>';
4908 if ($action ==
'editpaymentterm') {
4909 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
4911 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
4923 print
'<table class="nobordernopadding centpercent"><tr><td>';
4924 print $langs->trans(
'PaymentMode');
4926 if ($action !=
'editmode' && $usercancreate) {
4927 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>';
4929 print
'</tr></table>';
4931 if ($action ==
'editmode') {
4932 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
4934 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->mode_reglement_id,
'none',
'CRDT');
4939 if (isModEnabled(
"bank")) {
4940 print
'<tr><td class="nowrap">';
4941 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
4942 print $langs->trans(
'BankAccount');
4944 if (($action !=
'editbankaccount') && $usercancreate) {
4945 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>';
4947 print
'</tr></table>';
4949 if ($action ==
'editbankaccount') {
4950 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'fk_account', 1);
4952 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'none');
4959 if (isModEnabled(
'incoterm')) {
4961 print
'<table class="nobordernopadding centpercent"><tr><td>';
4962 print $langs->trans(
'IncotermLabel');
4963 print
'<td><td class="right">';
4964 if ($usercancreate) {
4965 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
4969 print
'</td></tr></table>';
4972 if ($action !=
'editincoterm') {
4973 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
4975 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
4982 $displayWarranty =
false;
4985 $displayWarranty =
true;
4986 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
4987 $displayWarranty =
false;
4990 if ($displayWarranty) {
4992 print
'<tr class="retained-warranty-lines" ><td>';
4993 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
4994 print $langs->trans(
'RetainedWarranty');
4997 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>';
5000 print
'</tr></table>';
5003 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5004 print
'<input type="hidden" name="action" value="setretainedwarranty">';
5005 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5006 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5007 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
5008 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5016 print
'<tr class="retained-warranty-lines" ><td>';
5017 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
5018 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
5020 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
5021 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>';
5024 print
'</tr></table>';
5026 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5027 if (
$object->date > $defaultDate) {
5033 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5034 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
5035 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5036 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5037 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
5038 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
5039 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
5040 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
5041 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5044 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->retained_warranty_fk_cond_reglement,
'none');
5045 if (!$displayWarranty) {
5046 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning.png',
'class="pictowarning valignmiddle" ');
5052 print
'<tr class="retained-warranty-lines" ><td>';
5053 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
5054 print $langs->trans(
'RetainedWarrantyDateLimit');
5057 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>';
5060 print
'</tr></table>';
5062 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5063 if (
$object->date > $defaultDate) {
5069 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5070 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
5071 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5072 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5073 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').
'" >';
5074 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5086 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
5091 print
'<div class="fichehalfright">';
5093 print
'<!-- amounts -->'.
"\n";
5094 print
'<div class="underbanner clearboth"></div>'.
"\n";
5096 print
'<table class="border tableforfield centpercent">';
5098 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
5106 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
5107 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5108 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5110 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5116 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
5117 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5118 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5120 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5125 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
5127 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
5128 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5129 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5132 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5137 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
5139 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
5140 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5141 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5144 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5150 if ($selleruserevenustamp) {
5151 print
'<tr><td class="titlefieldmiddle">';
5152 print
'<table class="nobordernopadding centpercent"><tr><td>';
5153 print $langs->trans(
'RevenueStamp');
5155 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
5156 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>';
5158 print
'</tr></table>';
5159 print
'</td><td class="nowrap amountcard right">';
5160 if ($action ==
'editrevenuestamp') {
5161 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
5162 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5163 print
'<input type="hidden" name="action" value="setrevenuestamp">';
5164 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
5165 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5166 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
5167 print
' → <span id="revenuestamp_span"></span>';
5168 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
5171 $(document).ready(function(){
5172 js_recalculate_revenuestamp();
5173 $('select[name=revenuestamp_type]').on('change',function(){
5174 js_recalculate_revenuestamp();
5177 function js_recalculate_revenuestamp(){
5178 var valselected = $('select[name=revenuestamp_type]').val();
5179 console.log('Calculate revenue stamp from '+valselected);
5181 if (valselected.indexOf('%') == -1)
5183 revenue = valselected;
5187 var revenue_type = parseFloat(valselected);
5188 var amount_net = ".round(
$object->total_ht, 2).
";
5189 revenue = revenue_type * amount_net / 100;
5190 revenue = revenue.toFixed(2);
5192 $('#revenuestamp_val').val(revenue);
5193 $('#revenuestamp_span').html(revenue);
5204 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
5205 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5206 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5208 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5216 if (isModEnabled(
'project')) {
5219 if (isModEnabled(
"bank")) {
5223 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
5226 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
5229 if ($selleruserevenustamp) {
5232 if (isModEnabled(
'multicurrency')) {
5235 if (isModEnabled(
'incoterm')) {
5239 $total_prev_ht = $total_prev_ttc = 0;
5240 $total_global_ht = $total_global_ttc = 0;
5244 print
'<!-- List of situation invoices -->';
5245 print
'<div class="div-table-responsive-no-min">';
5246 print
'<table class="noborder paymenttable centpercent situationstable">';
5248 print
'<tr class="liste_titre">';
5249 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
5251 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
5253 if (isModEnabled(
"bank")) {
5254 print
'<td class="right"></td>';
5256 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
5257 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
5258 print
'<td width="18"> </td>';
5261 if (count(
$object->tab_previous_situation_invoice) > 0) {
5264 $current_situation_counter = array();
5265 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
5266 $tmptotalallpayments = $prev_invoice->getSommePaiement(0);
5267 $tmptotalallpayments += $prev_invoice->getSumDepositsUsed(0);
5268 $tmptotalallpayments += $prev_invoice->getSumCreditNotesUsed(0);
5270 $total_prev_ht += $prev_invoice->total_ht;
5271 $total_prev_ttc += $prev_invoice->total_ttc;
5273 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
5274 print
'<tr class="oddeven">';
5275 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
5277 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
5278 if (isModEnabled(
"bank")) {
5279 print
'<td class="right"></td>';
5281 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
5282 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
5283 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalallpayments).
'</td>';
5288 $totalallpayments =
$object->getSommePaiement(0);
5289 $totalallpayments +=
$object->getSumCreditNotesUsed(0);
5290 $totalallpayments +=
$object->getSumDepositsUsed(0);
5292 $total_global_ht += $total_prev_ht;
5293 $total_global_ttc += $total_prev_ttc;
5294 $total_global_ht +=
$object->total_ht;
5295 $total_global_ttc +=
$object->total_ttc;
5299 print
'<tr class="oddeven">';
5300 print
'<td>'.$object->getNomUrl(1).
'</td>';
5302 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
5303 if (isModEnabled(
"bank")) {
5304 print
'<td class="right"></td>';
5306 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
5307 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
5308 print
'<td class="right">'.$object->getLibStatut(3, $totalallpayments).
'</td>';
5312 print
'<tr class="oddeven">';
5313 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'CurrentSituationTotal').
'</b></td>';
5316 foreach ($current_situation_counter as $sit) {
5317 $curSign = $sit > 0 ?
'+' :
'-';
5318 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
5320 print
' '.$curSign.
' ';
5322 print $curType.abs($sit);
5326 if (isModEnabled(
"bank")) {
5329 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5330 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5331 print
'<td width="18"> </td>';
5335 if (count(
$object->tab_next_situation_invoice) > 0) {
5347 $total_next_ht = $total_next_ttc = 0;
5349 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
5350 $totalpaid = $next_invoice->getSommePaiement(0);
5351 $totalcreditnotes = $next_invoice->getSumCreditNotesUsed(0);
5352 $totaldeposits = $next_invoice->getSumDepositsUsed(0);
5353 $total_next_ht += $next_invoice->total_ht;
5354 $total_next_ttc += $next_invoice->total_ttc;
5356 print
'<tr class="oddeven">';
5357 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
5359 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
5360 if (isModEnabled(
"bank")) {
5361 print
'<td class="right"></td>';
5363 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
5364 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
5365 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid + $totalcreditnotes + $totaldeposits).
'</td>';
5369 $total_global_ht += $total_next_ht;
5370 $total_global_ttc += $total_next_ttc;
5372 print
'<tr class="oddeven">';
5373 print
'<td colspan="3" class="right"></td>';
5374 if (isModEnabled(
"bank")) {
5375 print
'<td class="right"></td>';
5377 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5378 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5379 print
'<td width="18"> </td>';
5388 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
5394 print
'<!-- List of payments already done -->';
5395 print
'<div class="div-table-responsive-no-min">';
5396 print
'<table class="noborder paymenttable centpercent">';
5398 print
'<tr class="liste_titre">';
5399 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
5400 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
5401 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
5402 if (isModEnabled(
"bank")) {
5403 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
5405 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
5406 print
'<td class="liste_titre" width="18"> </td>';
5410 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
5411 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
5412 $sql .=
' pf.amount,';
5413 $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';
5414 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
5415 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
5416 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
5417 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
5418 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
5419 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
5420 $sql .=
' ORDER BY p.datep, p.tms';
5422 $result = $db->query($sql);
5424 $num = $db->num_rows($result);
5429 $objp = $db->fetch_object($result);
5431 $paymentstatic->id = $objp->rowid;
5432 $paymentstatic->datepaye = $db->jdate($objp->dp);
5433 $paymentstatic->ref = $objp->ref;
5434 $paymentstatic->num_payment = $objp->num_payment;
5435 $paymentstatic->paiementcode = $objp->payment_code;
5437 print
'<tr class="oddeven"><td class="nowraponall">';
5438 print $paymentstatic->getNomUrl(1);
5441 $dateofpayment = $db->jdate($objp->dp);
5443 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
5450 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
5451 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
5452 if (isModEnabled(
"bank")) {
5453 $bankaccountstatic->id = $objp->baid;
5454 $bankaccountstatic->ref = $objp->baref;
5455 $bankaccountstatic->label = $objp->baref;
5456 $bankaccountstatic->number = $objp->banumber;
5457 $bankaccountstatic->currency_code = $objp->bacurrency_code;
5459 if (isModEnabled(
'accounting')) {
5460 $bankaccountstatic->account_number = $objp->account_number;
5463 $accountingjournal->fetch($objp->fk_accountancy_journal);
5464 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
5467 print
'<td class="nowraponall">';
5468 if ($bankaccountstatic->id) {
5469 print $bankaccountstatic->getNomUrl(1,
'transactions');
5473 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
5474 print
'<td class="center">';
5477 $paiement->fetch($objp->rowid);
5479 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
5496 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5497 print
'<span class="opacitymedium">';
5499 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
5501 print $langs->trans(
'AlreadyPaid');
5503 print
'</span></td><td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td><td> </td></tr>';
5505 $resteapayeraffiche = $resteapayer;
5506 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
5509 $creditnoteamount = 0;
5511 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
5512 $sql .=
" re.description, re.fk_facture_source";
5513 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
5514 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
5515 $resql = $db->query($sql);
5517 $num = $db->num_rows($resql);
5521 $obj = $db->fetch_object($resql);
5522 $invoice->fetch($obj->fk_facture_source);
5523 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5524 print
'<span class="opacitymedium">';
5526 print $langs->trans(
"CreditNote").
' ';
5529 print $langs->trans(
"Deposit").
' ';
5531 print $invoice->getNomUrl(0);
5534 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
5535 print
'<td class="right">';
5536 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
5537 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
5542 $creditnoteamount += $obj->amount_ttc;
5545 $depositamount += $obj->amount_ttc;
5554 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5555 print
'<span class="opacitymedium">';
5556 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
5558 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5559 $resteapayeraffiche = 0;
5560 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5564 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5565 print
'<span class="opacitymedium">';
5566 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
5568 print
'</td><td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td><td> </td></tr>';
5570 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5574 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5575 print
'<span class="opacitymedium">';
5576 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
5578 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5579 $resteapayeraffiche = 0;
5580 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5584 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5585 $text = $langs->trans(
"HelpAbandonOther");
5587 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
5589 print
'<span class="opacitymedium">';
5591 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
5593 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5594 $resteapayeraffiche = 0;
5595 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5599 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5600 print
'<span class="opacitymedium">';
5601 print $langs->trans(
"Billed");
5602 print
'</td><td class="right">'.price(
$object->total_ttc).
'</td><td> </td></tr>';
5604 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5605 print
'<span class="opacitymedium">';
5606 print $langs->trans(
'RemainderToPay');
5607 if ($resteapayeraffiche < 0) {
5608 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5612 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
5616 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5617 print
'<span class="opacitymedium">';
5618 print $langs->trans(
'RemainderToPayMulticurrency');
5619 if ($resteapayeraffiche < 0) {
5620 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5624 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">';
5626 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>';
5630 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
5632 if (
$object->isSituationInvoice()) {
5633 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
5636 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
5639 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
5641 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>';
5644 print
'<tr><td colspan="'.$nbcols.
'" align="right">';
5645 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
5646 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
5647 print
' :</td><td align="right">'.price($retainedWarranty).
'</td><td> </td></tr>';
5650 $resteapayeraffiche = $resteapayer;
5651 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5654 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5655 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
5656 print
'</td><td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td><td> </td></tr>';
5659 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>';
5662 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5663 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
5664 if ($resteapayeraffiche > 0) {
5665 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5667 print
'</span></td>';
5668 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
5669 print
'<td class="nowrap"> </td></tr>';
5673 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5674 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
5675 if ($resteapayeraffiche > 0) {
5676 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5680 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>';
5693 if (isModEnabled(
'margin')) {
5694 $formmargin->displayMarginInfos(
$object);
5700 print
'<div class="clearboth"></div><br>';
5703 $blocname =
'contacts';
5704 $title = $langs->trans(
'ContactsAddresses');
5705 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5709 $blocname =
'notes';
5710 $title = $langs->trans(
'Notes');
5711 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5715 $result =
$object->getLinesArray();
5719 global $inputalsopricewithtax;
5720 $inputalsopricewithtax = 1;
5725 print
'<!-- Area to change globally the situation percent -->'.
"\n";
5726 print
'<div class="div-table-responsive-no-min">';
5728 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'#updatealllines" method="POST">';
5729 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
5730 print
'<input type="hidden" name="action" value="updatealllines" />';
5731 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
5732 print
'<input type="hidden" name="page_y" value="" />';
5733 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5735 print
'<table id="tablelines_all_progress" class="noborder noshadow centpercent">';
5737 print
'<tr class="liste_titre nodrag nodrop">';
5741 print
'<td align="center" width="5"> </td>';
5743 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
5744 print
'<td class="right">'.$langs->trans(
'Progress').
'</td>';
5745 print
'<td> </td>';
5748 print
'<tr class="nodrag nodrop">';
5751 print
'<td align="center" width="5"> </td>';
5753 print
'<td> </td>';
5754 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
5755 print
'<td class="right"><input type="submit" class="button reposition small" name="all_percent" value="'.$langs->trans(
"Modify").
'" /></td>';
5766 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
5767 <input type="hidden" name="token" value="' .
newToken().
'">
5768 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
5769 <input type="hidden" name="mode" value="">
5770 <input type="hidden" name="page_y" value="">
5771 <input type="hidden" name="id" value="' .
$object->id.
'">
5772 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
5775 if (!empty(
$conf->use_javascript_ajax) &&
$object->status == 0) {
5776 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
5779 print
'<div class="div-table-responsive-no-min">';
5780 print
'<table id="tablelines" class="noborder noshadow centpercent">';
5784 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
5788 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
5789 if ($action !=
'editline' && $action !=
'selectlines') {
5792 $parameters = array();
5793 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
5797 if (empty($reshook)) {
5798 $object->formAddObjectLine(1, $mysoc, $soc);
5801 $parameters = array();
5802 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters,
$object, $action);
5816 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
5817 print
'<div class="tabsAction">';
5819 $parameters = array();
5820 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
5821 if (empty($reshook)) {
5824 'class' =>
'classfortooltip',
5831 $ventilExportCompta =
$object->getVentilExportCompta();
5833 if ($ventilExportCompta == 0) {
5835 if (!$objectidnext &&
$object->is_last_in_cycle()) {
5836 if ($usercanunvalidate) {
5837 unset($params[
'attr'][
'title']);
5838 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=modif&token='.
newToken(),
'',
true, $params);
5840 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
5841 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=modif&token='.
newToken(),
'',
false, $params);
5843 } elseif (!
$object->is_last_in_cycle()) {
5844 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
5845 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5847 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
5848 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5852 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5853 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5858 $result = $discount->fetch(0,
$object->id);
5866 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
5867 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
5868 unset($params[
'attr'][
'title']);
5869 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
5871 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
5872 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
5879 $langs->load(
"contracts");
5881 if ($usercancreatecontract) {
5882 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>';
5891 if ($usercanvalidate) {
5892 unset($params[
'attr'][
'title']);
5893 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
5898 if (empty($user->socid)) {
5900 if ($objectidnext) {
5901 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'SendMail').
'</span>';
5904 unset($params[
'attr'][
'title']);
5905 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
5907 unset($params[
'attr'][
'title']);
5908 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
5916 if ($resteapayer > 0) {
5917 if ($usercancreatewithdrarequest) {
5918 if (!$objectidnext &&
$object->close_code !=
'replaced') {
5919 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>';
5921 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
5932 if (isModEnabled(
'takepos') &&
$object->module_source ==
'takepos') {
5933 $langs->load(
"cashdesk");
5934 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
5935 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
5940 if ($objectidnext) {
5941 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
5945 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
5946 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
5950 unset($params[
'attr'][
'title']);
5951 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);
5956 $sumofpayment = $totalpaid;
5957 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
5963 if ($resteapayer == 0) {
5964 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
5966 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
5972 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
5976 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
5978 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>';
5985 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
5987 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
6001 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
6002 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
6004 unset($params[
'attr'][
'title']);
6005 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken(),
'',
true, $params);
6011 if ($totalpaid > 0 || $totalcreditnotes > 0) {
6013 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
6016 if ($objectidnext) {
6017 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
6019 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
6027 if (!$objectidnext) {
6028 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>';
6034 &&
$object->isSituationInvoice()
6035 && (
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
6038 &&
$object->is_last_in_cycle()
6041 if ($usercanunvalidate) {
6042 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>';
6044 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
6050 unset($params[
'attr'][
'title']);
6051 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice&token='.
newToken(),
'',
true, $params);
6056 if (!$objectidnext && count(
$object->lines) > 0) {
6057 unset($params[
'attr'][
'title']);
6058 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
6064 &&
$object->isSituationInvoice()
6067 &&
$object->situation_counter > 1
6068 &&
$object->is_last_in_cycle()
6069 && $usercanunvalidate
6071 if ((
$object->total_ttc - $totalcreditnotes) == 0) {
6072 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6074 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6080 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
6081 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6082 } elseif (!
$object->is_last_in_cycle()) {
6083 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6085 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6090 $isErasable =
$object->is_erasable();
6092 if ($isErasable == -4) {
6093 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
6094 } elseif ($isErasable == -3) {
6095 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
6096 } elseif ($isErasable == -2) {
6097 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
6098 } elseif ($isErasable == -1) {
6099 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6100 } elseif ($isErasable <= 0) {
6101 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable');
6102 } elseif ($objectidnext) {
6103 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
6105 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
6106 $enableDelete =
false;
6108 if ($isErasable > 0 && ! $objectidnext) {
6109 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
6110 $enableDelete =
true;
6112 unset($params[
'attr'][
'title']);
6113 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
6115 unset($params[
'attr'][
'title']);
6116 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
6123 if (
GETPOST(
'modelselected',
'alpha')) {
6124 $action =
'presend';
6126 if ($action !=
'prerelance' && $action !=
'presend') {
6127 print
'<div class="fichecenter"><div class="fichehalfleft">';
6128 print
'<a name="builddoc"></a>';
6133 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
6134 $genallowed = $usercanread;
6135 $delallowed = $usercancreate;
6137 print $formfile->showdocuments(
6157 'remove_file_comfirm'
6160 $somethingshown = $formfile->numoffiles;
6163 $tmparray = $form->showLinkToObjectBlock(
$object, array(), array(
'invoice'), 1);
6164 $linktoelem = $tmparray[
'linktoelem'];
6165 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
6166 print $htmltoenteralink;
6168 $compatibleImportElementsList =
false;
6172 $compatibleImportElementsList = array(
'commande',
'propal');
6174 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem, $compatibleImportElementsList);
6178 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6179 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
6180 $useonlinepayment = count($validpaymentmethod);
6183 print
'<br><!-- Link to pay -->'.
"\n";
6184 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6185 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
6188 print
'</div><div class="fichehalfright">';
6192 $morehtmlcenter =
'<div class="nowraponall">';
6193 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullConversation'),
'',
'fa fa-comments imgforviewmode', DOL_URL_ROOT.
'/compta/facture/messaging.php?id='.
$object->id);
6194 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
6195 $morehtmlcenter .=
'</div>';
6198 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
6200 $somethingshown = $formactions->showactions(
$object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
6202 print
'</div></div>';
6207 $modelmail =
'facture_send';
6208 $defaulttopic =
'SendBillRef';
6209 $diroutput =
$conf->invoice->multidir_output[
$object->entity];
6210 $trackid =
'inv'.$object->id;
6212 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.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.