46require
'../../main.inc.php';
55require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
56require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
57require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
58require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
59require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
60require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
61require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
62require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
63require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
64require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
65require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
66require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
67require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
68require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
70 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
73 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
74 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
76require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
79 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
82 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
86$langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
88 $langs->load(
'incoterm');
91 $langs->load(
'margins');
95$action =
GETPOST(
'action',
'aZ09');
96$confirm =
GETPOST(
'confirm',
'alpha');
97$cancel =
GETPOST(
'cancel',
'alpha');
98$backtopage =
GETPOST(
'backtopage',
'alpha');
99$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
105$origin =
GETPOST(
'origin',
'alpha');
109$ref_client =
GETPOST(
'ref_client',
'alpha');
110$inputReasonId =
GETPOSTINT(
'input_reason_id');
113$selectedLines =
GETPOST(
'toselect',
'array:int');
127$extrafields->fetch_name_optionals_label(
$object->table_element);
130$total_global_ttc = 0;
131$displayWarranty =
false;
132$statusreplacement = 0;
134$price_base_type =
'';
135$array_options = array();
138if ($id > 0 || !empty($ref)) {
139 if ($action !=
'add') {
141 $fetch_situation =
false;
143 $fetch_situation =
true;
145 $ret =
$object->fetch($id, $ref,
'', 0, $fetch_situation);
146 if ($ret > 0 && isset(
$object->fk_project)) {
147 $ret =
$object->fetchProject();
153$hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
156$usercanread = $user->hasRight(
"facture",
"lire");
157$usercancreate = $user->hasRight(
"facture",
"creer");
158$usercanissuepayment = $user->hasRight(
"facture",
"paiement");
159$usercandelete = $user->hasRight(
"facture",
"supprimer") || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
160$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
163$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'validate')));
164$usercansend = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercanread) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'send')));
165$usercanreopen = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'reopen')));
167 $usercanreopen =
false;
169$usercanunvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'unvalidate')));
170$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
173$usercancreatemargin = $user->hasRight(
'margins',
'creer');
174$usercanreadallmargin = $user->hasRight(
'margins',
'liretous');
175$usercancreatewithdrarequest = $user->hasRight(
'prelevement',
'bons',
'creer');
177$permissionnote = $usercancreate;
178$permissiondellink = $usercancreate;
179$permissiontoedit = $usercancreate;
180$permissiontoadd = $usercancreate;
181$permissiontoeditextra = $usercancreate;
182if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
184 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
188$retainedWarrantyInvoiceAvailableType = array();
190 $retainedWarrantyInvoiceAvailableType = explode(
'+',
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY'));
195 $socid = $user->socid;
208$parameters = array(
'socid' => $socid);
209$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
214if (empty($reshook)) {
215 $backurlforlist = DOL_URL_ROOT.
'/compta/facture/list.php';
217 if (empty($backtopage) || ($cancel && empty($id))) {
218 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
219 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
220 $backtopage = $backurlforlist;
222 $backtopage = DOL_URL_ROOT.
'/compta/facture/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
228 if (!empty($backtopageforcancel)) {
229 header(
"Location: ".$backtopageforcancel);
231 } elseif (!empty($backtopage)) {
232 header(
"Location: ".$backtopage);
238 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
240 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
242 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
245 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
247 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'IdThirdParty')),
null,
'errors');
250 '@phan-var-force Facture $objectutil';
253 $objectutil->socid = $socid;
254 $result = $objectutil->createFromClone($user, $id, (GETPOSTISSET(
'entity') ?
GETPOSTINT(
'entity') : null));
256 $warningMsgLineList = array();
258 foreach ($objectutil->lines as $line) {
259 if (!is_object($line->product)) {
260 $line->fetch_product();
262 if (is_object($line->product) && $line->product->id > 0) {
263 if (empty($line->product->status)) {
264 $warningMsgLineList[$line->id] = $langs->trans(
'WarningLineProductNotToSell', $line->product->ref);
268 if (!empty($warningMsgLineList)) {
272 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?facid=' . $result);
275 $langs->load(
"errors");
280 } elseif ($action ==
'reopen' && $usercanreopen) {
284 $result =
$object->setUnpaid($user);
286 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
292 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
297 $idwarehouse =
GETPOST(
'idwarehouse');
299 $qualified_for_stock_change = 0;
301 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
303 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
306 $isErasable =
$object->is_erasable();
308 if (($isErasable > 0) || ($usercancreate && $isErasable == 1)) {
309 $result =
$object->delete($user, 0, (
int) $idwarehouse);
311 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
318 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
328 $outputlangs = $langs;
334 $newlang =
$object->thirdparty->default_lang;
336 if (!empty($newlang)) {
338 $outputlangs->setDefaultLang($newlang);
339 $outputlangs->load(
'products');
343 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
346 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
353 } elseif ($action ==
'confirm_delete_subtotalline' && $confirm ==
'yes' && $usercancreate) {
358 $result =
$object->deleteSubtotalLine($langs,
GETPOSTINT(
'lineid'), (
bool)
GETPOST(
'deletecorrespondingsubtotalline'));
363 $outputlangs = $langs;
369 $newlang =
$object->thirdparty->default_lang;
371 if (!empty($newlang)) {
373 $outputlangs->setDefaultLang($newlang);
374 $outputlangs->load(
'products');
378 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
381 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
388 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
391 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
392 $discount->unlink_invoice();
393 } elseif ($action ==
'valid' && $usercancreate) {
397 if ((preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) &&
404 $last_of_type =
$object->willBeLastOfSameType(
true);
405 if (empty(
$object->date_validation) && !$last_of_type[0]) {
415 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
424 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
433 $array_of_total_ht_per_vat_rate = array();
434 $array_of_total_ht_devise_per_vat_rate = array();
435 foreach (
$object->lines as $line) {
437 $vat_src_code_for_line =
'';
438 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
439 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
441 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
442 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
444 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
445 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
449 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
450 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
451 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
453 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
454 if (
$object->type == $object::TYPE_DEPOSIT) {
455 $langs->load(
"errors");
457 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
461 $tmpvatratetoshow = explode(
'_', $vatrate);
462 $tmpvatratetoshow[0] = round((
float) $tmpvatratetoshow[0], 2);
464 if ($tmpvatratetoshow[0] != 0) {
465 $langs->load(
"errors");
466 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", (
string) $tmpvatratetoshow[0]),
null,
'errors');
474 } elseif ($action ==
'classin' && $usercancreate) {
477 } elseif ($action ==
'setposinfo' && $usercancreate) {
481 $result =
$object->update($user);
485 } elseif ($action ==
'setmode' && $usercancreate) {
491 } elseif ($action ==
'setretainedwarrantyconditions' && $usercancreate) {
493 $object->retained_warranty_fk_cond_reglement = 0;
494 $result =
$object->setRetainedWarrantyPaymentTerms(
GETPOSTINT(
'retained_warranty_fk_cond_reglement'));
499 $old_rw_date_lim_reglement =
$object->retained_warranty_date_limit;
500 $new_rw_date_lim_reglement =
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
501 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
502 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
507 $result =
$object->update($user);
511 } elseif ($action ==
'setretainedwarranty' && $usercancreate) {
517 } elseif ($action ==
'setretainedwarrantydatelimit' && $usercancreate) {
519 $result =
$object->setRetainedWarrantyDateLimit(
GETPOSTDATE(
'retained_warranty_date_limit'));
523 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
524 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
525 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
527 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
529 $old_date_lim_reglement =
$object->date_lim_reglement;
531 if (empty($newdate)) {
532 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
533 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.
$id.
'&action=editinvoicedate&token='.
newToken());
538 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
540 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
545 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
546 if ($new_date_lim_reglement) {
547 $object->date_lim_reglement = $new_date_lim_reglement;
552 $result =
$object->update($user);
555 $action =
'editinvoicedate';
557 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
562 $object->date_pointoftax = $date_pointoftax;
563 $result =
$object->update($user);
567 } elseif ($action ==
'setconditions' && $usercancreate) {
569 $object->cond_reglement_code = 0;
570 $object->cond_reglement_id = 0;
583 $old_date_lim_reglement =
$object->date_lim_reglement;
584 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
585 if ($new_date_lim_reglement) {
586 $object->date_lim_reglement = $new_date_lim_reglement;
591 $result =
$object->update($user);
603 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
607 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
608 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
610 $result =
$object->update($user);
614 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
617 $result =
$object->update($user);
624 $outputlangs = $langs;
627 $newlang =
GETPOST(
'lang_id',
'aZ09');
630 $newlang =
$object->thirdparty->default_lang;
632 if (!empty($newlang)) {
634 $outputlangs->setDefaultLang($newlang);
635 $outputlangs->load(
'products');
640 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
646 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
648 } elseif ($action ==
'set_dispute_status' && $usercancreate) {
649 $result =
$object->setStatut(
GETPOSTINT(
'dispute_status'),
null,
'facture',
'FACTURE_MODIFY',
'dispute_status');
650 } elseif ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
652 } elseif ($action ==
'setbankaccount' && $usercancreate) {
654 } elseif ($action ==
'setremisepercent' && $usercancreate) {
657 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
676 $newremaintopay =
$object->getRemainToPay(0);
677 if ($newremaintopay == 0) {
684 if (
GETPOSTINT(
"remise_id_for_payment") > 0) {
685 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
687 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
691 $remaintopay =
$object->getRemainToPay(0);
695 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
699 $result = $discount->link_to_invoice(0, $id);
712 $newremaintopay =
$object->getRemainToPay(0);
713 if ($newremaintopay == 0) {
727 $outputlangs = $langs;
730 $newlang =
GETPOST(
'lang_id',
'aZ09');
734 $newlang =
$object->thirdparty->default_lang;
736 if (!empty($newlang)) {
738 $outputlangs->setDefaultLang($newlang);
742 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
747 } elseif ($action ==
'setref' && $usercancreate) {
749 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', 0,
'',
'', $user,
'BILL_MODIFY');
750 } elseif ($action ==
'setref_client' && $usercancreate) {
753 } elseif ($action ==
'setdemandreason' && $usercancreate) {
754 $result =
$object->setInputReason($inputReasonId);
758 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
767 $qualified_for_stock_change = 0;
769 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
771 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
774 if ($qualified_for_stock_change) {
775 if (!$idwarehouse || $idwarehouse == - 1) {
777 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
784 $result =
$object->validate($user,
'', $idwarehouse);
788 $outputlangs = $langs;
791 $newlang =
GETPOST(
'lang_id',
'aZ09');
794 $newlang =
$object->thirdparty->default_lang;
796 if (!empty($newlang)) {
798 $outputlangs->setDefaultLang($newlang);
799 $outputlangs->load(
'products');
805 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
818 } elseif ($action ==
'confirm_modif' && $usercanunvalidate && !
getDolGlobalString(
'INVOICE_CAN_NEVER_BE_EDITED')) {
827 $qualified_for_stock_change = 0;
829 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
831 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
834 if ($qualified_for_stock_change) {
835 if (!$idwarehouse || $idwarehouse == -1) {
837 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
846 $sql =
'SELECT pf.amount';
847 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'paiement_facture as pf';
848 $sql .=
' WHERE pf.fk_facture = ' . ((int)
$object->id);
850 $result = $db->query($sql);
853 $num = $db->num_rows($result);
856 $objp = $db->fetch_object($result);
857 $totalpaid += $objp->amount;
864 $resteapayer =
$object->total_ttc - $totalpaid;
867 $ventilExportCompta =
$object->getVentilExportCompta();
870 if ($ventilExportCompta == 0) {
872 $result =
$object->setDraft($user, $idwarehouse);
879 $outputlangs = $langs;
882 $newlang =
GETPOST(
'lang_id',
'aZ09');
885 $newlang =
$object->thirdparty->default_lang;
887 if (!empty($newlang)) {
889 $outputlangs->setDefaultLang($newlang);
890 $outputlangs->load(
'products');
895 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
900 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
903 $result =
$object->setPaid($user);
907 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
910 $close_code =
GETPOST(
"close_code",
'restricthtml');
911 $close_note =
GETPOST(
"close_note",
'restricthtml');
914 if (
isModEnabled(
'tax') && $close_code == $object::CLOSECODE_WITHHOLDINGTAX) {
915 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
917 $amount = (double) ($resteapayer > 0 ? $resteapayer * -1 : $resteapayer);
920 $tempTva =
new Tva($db);
921 $tempTva->datev =
$object->date;
922 $tempTva->datep =
$object->date;
923 $tempTva->amount = $amount;
924 $tempTva->label = $langs->trans(
'WithholdingTax') .
' - ' .
$object->ref;
926 $valid = $tempTva->getIdForLabel($tempTva->label);
928 $ret = $tempTva->create($user);
932 $tempTva->setPaid($user);
942 setEventMessages($langs->trans(
'LabelWithholdingExist'), $tempTva->errors,
'errors');
948 $result =
$object->setPaid($user, $close_code, $close_note);
956 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
958 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
961 $close_code =
GETPOST(
"close_code",
'restricthtml');
962 $close_note =
GETPOST(
"close_note",
'restricthtml');
964 $result =
$object->setCanceled($user, $close_code, $close_note);
971 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
973 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
981 $result = $discountcheck->fetch(0,
$object->id);
994 $amount_ht = $amount_tva = $amount_ttc = array();
995 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
999 foreach (
$object->lines as $line) {
1000 if ($line->product_type < 9 && $line->total_ht != 0) {
1001 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
1003 if (!isset($amount_ht[$keyforvatrate])) {
1004 $amount_ht[$keyforvatrate] = 0;
1006 $amount_ht[$keyforvatrate] += $line->total_ht;
1007 if (!isset($amount_tva[$keyforvatrate])) {
1008 $amount_tva[$keyforvatrate] = 0;
1010 $amount_tva[$keyforvatrate] += $line->total_tva;
1011 if (!isset($amount_ttc[$keyforvatrate])) {
1012 $amount_ttc[$keyforvatrate] = 0;
1014 $amount_ttc[$keyforvatrate] += $line->total_ttc;
1015 if (!isset($multicurrency_amount_ht[$keyforvatrate])) {
1016 $multicurrency_amount_ht[$keyforvatrate] = 0;
1018 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
1019 if (!isset($multicurrency_amount_tva[$keyforvatrate])) {
1020 $multicurrency_amount_tva[$keyforvatrate] = 0;
1022 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
1023 if (!isset($multicurrency_amount_ttc[$keyforvatrate])) {
1024 $multicurrency_amount_ttc[$keyforvatrate] = 0;
1026 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
1030 '@phan-var-force array<string,float> $amount_ht
1031 @phan-var-force array<string,float> $amount_tva
1032 @phan-var-force array<string,float> $amount_ttc
1033 @phan-var-force array<string,float> $multicurrency_amount_ht
1034 @phan-var-force array<string,float> $multicurrency_amount_tva
1035 @phan-var-force array<string,float> $multicurrency_amount_ttc';
1039 $alreadypaid =
$object->getSommePaiement();
1040 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
1041 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
1042 foreach ($amount_ht as $vatrate => $val) {
1043 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
1044 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
1045 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
1046 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
1047 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
1048 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
1057 $discount->description =
'(CREDIT_NOTE)';
1059 $discount->description =
'(DEPOSIT)';
1061 $discount->description =
'(EXCESS RECEIVED)';
1063 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
1065 $discount->fk_soc =
$object->socid;
1066 $discount->socid =
$object->socid;
1067 $discount->fk_facture_source =
$object->id;
1076 $discount->description =
'(EXCESS RECEIVED)';
1079 $sql =
'SELECT SUM(pf.amount) as total_paiements';
1080 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
1081 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
1082 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
1083 $sql .=
' AND pf.fk_paiement = p.rowid';
1084 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
1085 $resql = $db->query($sql);
1090 $res = $db->fetch_object($resql);
1091 $total_paiements = $res->total_paiements;
1094 $total_creditnote_and_deposit = 0;
1095 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1096 $sql .=
" re.description, re.fk_facture_source";
1097 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1098 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
1099 $resql = $db->query($sql);
1100 if (!empty($resql)) {
1101 while ($obj = $db->fetch_object($resql)) {
1102 $total_creditnote_and_deposit += $obj->amount_ttc;
1108 $discount->amount_ttc =
price2num($total_paiements + $total_creditnote_and_deposit -
$object->total_ttc,
'MT');
1109 $discount->amount_tva = 0;
1110 $discount->amount_ht = $discount->amount_ttc;
1111 $discount->tva_tx = 0;
1112 $discount->vat_src_code =
'';
1114 if ($discount->amount_ttc > 0) {
1115 $result = $discount->create($user);
1125 $discount->description =
'(CREDIT_NOTE)';
1127 $discount->description =
'(DEPOSIT)';
1130 foreach ($amount_ht as $tva_tx => $xxx) {
1132 $discount->amount_ht = -((float) $amount_ht[$tva_tx]);
1133 $discount->amount_tva = -((float) $amount_tva[$tva_tx]);
1134 $discount->amount_ttc = -((float) $amount_ttc[$tva_tx]);
1135 $discount->total_ht = -((float) $amount_ht[$tva_tx]);
1136 $discount->total_tva = -((float) $amount_tva[$tva_tx]);
1137 $discount->total_ttc = -((float) $amount_ttc[$tva_tx]);
1138 $discount->multicurrency_amount_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1139 $discount->multicurrency_amount_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1140 $discount->multicurrency_amount_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1141 $discount->multicurrency_total_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1142 $discount->multicurrency_total_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1143 $discount->multicurrency_total_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1146 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
1147 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
1148 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
1149 $discount->total_ht = abs((
float) $amount_ht[$tva_tx]);
1150 $discount->total_tva = abs((
float) $amount_tva[$tva_tx]);
1151 $discount->total_ttc = abs((
float) $amount_ttc[$tva_tx]);
1152 $discount->multicurrency_amount_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1153 $discount->multicurrency_amount_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1154 $discount->multicurrency_amount_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1155 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1156 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1157 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1163 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
1164 $vat_src_code = $reg[1];
1165 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
1168 $discount->tva_tx = abs((
float) $tva_tx);
1169 $discount->vat_src_code = $vat_src_code;
1171 $result = $discount->create($user);
1179 if (empty($error)) {
1189 $result =
$object->setPaid($user);
1203 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
1208 $result = $paiement->fetch(
GETPOSTINT(
'paiement_id'));
1210 $result = $paiement->delete($user);
1212 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1220 } elseif ($action ==
'add' && $usercancreate) {
1227 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1233 $object->demand_reason_id = $inputReasonId;
1235 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1245 if (empty($dateinvoice)) {
1247 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1257 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1267 $object->date_pointoftax = $date_pointoftax;
1268 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1269 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1280 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1281 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1298 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1300 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceAvoirAskCombo")),
null,
'errors');
1304 if (empty($dateinvoice)) {
1306 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1316 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1321 if (!empty($originentity)) {
1322 $object->entity = $originentity;
1328 $object->date_pointoftax = $date_pointoftax;
1329 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1330 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1335 $object->cond_reglement_id = 0;
1341 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1342 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1346 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1349 $facture_source =
new Facture($db);
1350 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1351 if ($facture_source->isSituationInvoice()) {
1352 $object->situation_counter = $facture_source->situation_counter;
1353 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1354 $facture_source->fetchPreviousNextSituationInvoice();
1364 if (
$object->copy_linked_contact($facture_source,
'internal') < 0) {
1366 } elseif ($facture_source->socid ==
$object->socid) {
1368 if (
$object->copy_linked_contact($facture_source,
'external') < 0) {
1379 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1380 if (!empty($facture_source->lines)) {
1381 $fk_parent_line = 0;
1383 foreach ($facture_source->lines as $line) {
1385 if (method_exists($line,
'fetch_optionals')) {
1387 $line->fetch_optionals();
1391 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1392 $fk_parent_line = 0;
1396 if ($facture_source->isSituationInvoice()) {
1397 $source_fk_prev_id = $line->fk_prev_id;
1398 $line->fk_prev_id = $line->id;
1403 if (
getDolGlobalInt(
'INVOICE_USE_SITUATION') != 2 && !empty($facture_source->tab_previous_situation_invoice)) {
1406 $tab_jumped_credit_notes = array();
1407 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1408 $searchPreviousInvoice =
true;
1409 while ($searchPreviousInvoice) {
1410 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1411 $searchPreviousInvoice =
false;
1415 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1421 $maxPrevSituationPercent = 0;
1422 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1423 if ($prevLine->id == $source_fk_prev_id) {
1424 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1427 $line->total_ht -= $prevLine->total_ht;
1428 $line->total_tva -= $prevLine->total_tva;
1429 $line->total_ttc -= $prevLine->total_ttc;
1430 $line->total_localtax1 -= $prevLine->total_localtax1;
1431 $line->total_localtax2 -= $prevLine->total_localtax2;
1433 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1434 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1435 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1436 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1441 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1446 $maxPrevSituationPercent = 0;
1447 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1448 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1449 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1450 $maxPrevSituationPercent = $prevLine->situation_percent;
1452 $line->total_ht -= $prevLine->total_ht;
1453 $line->total_tva -= $prevLine->total_tva;
1454 $line->total_ttc -= $prevLine->total_ttc;
1455 $line->total_localtax1 -= $prevLine->total_localtax1;
1456 $line->total_localtax2 -= $prevLine->total_localtax2;
1458 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1459 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1460 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1461 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1467 $line->situation_percent += $maxPrevSituationPercent;
1473 $line->fk_facture =
$object->id;
1474 $line->fk_parent_line = $fk_parent_line;
1476 $line->subprice = -$line->subprice;
1478 $line->total_ht = -$line->total_ht;
1479 $line->total_tva = -$line->total_tva;
1480 $line->total_ttc = -$line->total_ttc;
1481 $line->total_localtax1 = -$line->total_localtax1;
1482 $line->total_localtax2 = -$line->total_localtax2;
1484 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1485 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1486 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1487 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1489 $line->context[
'createcreditnotefrominvoice'] = 1;
1490 $result = $line->insert(0, 1);
1495 if ($result > 0 && $line->product_type == 9) {
1496 $fk_parent_line = $result;
1504 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1505 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1506 $totalpaid = $facture_source->getSommePaiement();
1507 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1508 $totaldeposits = $facture_source->getSumDepositsUsed();
1509 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1511 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1512 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1515 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1520 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1521 $tva_tx = (float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY');
1526 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), 0, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC', $remain_to_pay);
1531 if (!empty(
$object->fk_facture_source) &&
$id > 0) {
1532 $facture_source->fetch(
$object->fk_facture_source);
1533 $facture_source->fetchObjectLinked();
1535 if (!empty($facture_source->linkedObjectsIds)) {
1536 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1537 $object->add_object_linked($sourcetype, current($TIds));
1546 if (empty($dateinvoice)) {
1548 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1559 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1569 $object->date_pointoftax = $date_pointoftax;
1570 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1571 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1584 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1585 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1601 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1602 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1603 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1607 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1611 if (empty($dateinvoice)) {
1613 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1623 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1624 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1629 if ($typeamount && !empty($origin) && !empty($originid)) {
1630 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1631 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1635 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1636 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1640 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1641 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1651 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1661 $object->date_pointoftax = $date_pointoftax;
1662 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1663 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1675 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1676 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1680 $object->situation_counter = 1;
1685 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1687 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1689 $object->retained_warranty = 0;
1690 $object->retained_warranty_fk_cond_reglement = 0;
1693 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1694 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1697 $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);
1702 if (!empty($origin) && !empty($originid)) {
1705 $element = $subelement = $origin;
1706 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1707 $element = $regs[1];
1708 $subelement = $regs[2];
1712 if ($element ==
'order') {
1713 $element = $subelement =
'commande';
1715 if ($element ==
'propal') {
1716 $element =
'comm/propal';
1717 $subelement =
'propal';
1719 if ($element ==
'contract') {
1720 $element = $subelement =
'contrat';
1722 if ($element ==
'inter') {
1723 $element = $subelement =
'fichinter';
1725 if ($element ==
'shipping') {
1726 $element = $subelement =
'expedition';
1730 $object->origin_type = $origin;
1731 $object->origin_id = $originid;
1736 if (
$object->origin ==
'shipping') {
1737 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1739 $exp->fetch(
$object->origin_id);
1740 $exp->fetchObjectLinked();
1741 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1742 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1743 $object->linked_objects[
'commande'] = $value;
1749 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
1757 $classname = ucfirst($subelement);
1758 $srcobject =
new $classname($db);
1759 '@phan-var-force CommonObject $srcobject';
1761 dol_syslog(
"Try to find source object origin_type=".
$object->origin_type.
" origin_id=".
$object->origin_id.
" to add lines or deposit lines");
1762 $result = $srcobject->fetch(
$object->origin_id);
1768 $amountdeposit = array();
1771 if ($typeamount ==
'amount') {
1772 $amount = (float) $valuedeposit;
1774 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1777 $TTotalByTva = array();
1778 foreach ($srcobject->lines as &$line) {
1779 if (empty($line->qty)) {
1782 if (!empty($line->special_code)) {
1785 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1787 '@phan-var-force array<string,float> $TTotalByTva';
1789 $amount_ttc_diff = 0.;
1790 foreach ($TTotalByTva as $tva => &$total) {
1791 if (empty($amountdeposit[$tva])) {
1792 $amountdeposit[$tva] = 0;
1794 $coef = $total / $srcobject->total_ttc;
1795 $am = $amount * $coef;
1796 $amount_ttc_diff += $am;
1797 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1800 if ($typeamount ==
'amount') {
1801 $amountdeposit[0] = $valuedeposit;
1802 } elseif ($typeamount ==
'variable') {
1805 $lines = $srcobject->lines;
1806 $numlines = count($lines);
1807 for ($i = 0; $i < $numlines; $i++) {
1809 if (empty($lines[$i]->qty)) {
1812 if (!empty($lines[$i]->special_code)) {
1816 $totalamount += $lines[$i]->total_ht;
1817 $tva_tx = $lines[$i]->tva_tx;
1819 if (empty($amountdeposit[$tva_tx])) {
1820 $amountdeposit[$tva_tx] = 0;
1822 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1826 if ($totalamount == 0) {
1827 $amountdeposit[0] = 0;
1835 $amount_ttc_diff = $amountdeposit[0];
1838 foreach ($amountdeposit as $tva => $amount) {
1839 if (empty($amount)) {
1844 'amount' =>
'FixAmount',
1845 'variable' =>
'VarAmount'
1847 $descline =
'(DEPOSIT)';
1849 if ($typeamount ==
'amount') {
1850 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code : $conf->currency)).
')';
1851 } elseif ($typeamount ==
'variable') {
1852 $descline .=
' ('.$valuedeposit.
'%)';
1855 $descline .=
' - '.$srcobject->ref;
1868 $i >= 0 ? $lines[$i]->info_bits : 0,
1874 $i >= 0 ? $lines[$i]->special_code : 0,
1891 $diff =
$object->total_ttc - $amount_ttc_diff;
1895 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1896 $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);
1905 $lines = $srcobject->lines;
1906 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1907 $srcobject->fetch_lines();
1908 $lines = $srcobject->lines;
1913 if (is_array($lines)) {
1914 foreach ($lines as $line) {
1916 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuestandardinvoice / 100,
'MS');
1922 if (is_array($lines)) {
1923 foreach ($lines as $line) {
1925 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuedeposit / 100,
'MS');
1930 $fk_parent_line = 0;
1931 $num = count($lines);
1933 for ($i = 0; $i < $num; $i++) {
1934 if (!in_array($lines[$i]->
id, $selectedLines)) {
1939 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
1943 if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1944 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1946 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
1950 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1951 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1953 if (
$object->situation_counter == 1) {
1954 $lines[$i]->situation_percent = 0;
1957 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
1960 $desc = $label ? $label : $langs->trans(
'Discount');
1964 $discount->fk_soc =
$object->socid;
1965 $discount->socid =
$object->socid;
1966 $discount->amount_ht = abs($lines[$i]->total_ht);
1967 $discount->amount_tva = abs($lines[$i]->total_tva);
1968 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1969 $discount->total_ht = abs($lines[$i]->total_ht);
1970 $discount->total_tva = abs($lines[$i]->total_tva);
1971 $discount->total_ttc = abs($lines[$i]->total_ttc);
1972 $discount->tva_tx = $lines[$i]->tva_tx;
1973 $discount->fk_user = $user->id;
1974 $discount->description = $desc;
1975 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1976 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1977 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1978 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1979 $discount->multicurrency_total_ht = abs($lines[$i]->multicurrency_total_ht);
1980 $discount->multicurrency_total_tva = abs($lines[$i]->multicurrency_total_tva);
1981 $discount->multicurrency_total_ttc = abs($lines[$i]->multicurrency_total_ttc);
1983 $discountid = $discount->create($user);
1984 if ($discountid > 0) {
1985 $result =
$object->insert_discount($discountid);
1997 $date_start =
false;
1998 if (isset($lines[$i]->date_debut_prevue)) {
1999 $date_start = $lines[$i]->date_debut_prevue;
2001 if (isset($lines[$i]->date_debut_reel)) {
2002 $date_start = $lines[$i]->date_debut_reel;
2004 if (isset($lines[$i]->date_start)) {
2005 $date_start = $lines[$i]->date_start;
2010 if (isset($lines[$i]->date_fin_prevue)) {
2011 $date_end = $lines[$i]->date_fin_prevue;
2013 if (isset($lines[$i]->date_fin_reel)) {
2014 $date_end = $lines[$i]->date_fin_reel;
2016 if (isset($lines[$i]->date_end)) {
2017 $date_end = $lines[$i]->date_end;
2021 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
2022 $fk_parent_line = 0;
2025 $array_options = array();
2027 if (method_exists($lines[$i],
'fetch_optionals')) {
2028 $lines[$i]->fetch_optionals();
2029 $array_options = $lines[$i]->array_options;
2032 $tva_tx = $lines[$i]->tva_tx;
2033 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
2034 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
2044 $lines[$i]->subprice,
2049 $lines[$i]->fk_product,
2050 $lines[$i]->remise_percent,
2054 (
int) $lines[$i]->info_bits,
2055 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except : null,
2060 $lines[$i]->special_code,
2064 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice : null,
2068 $lines[$i]->situation_percent ?? 100,
2069 $lines[$i]->fk_prev_id ?? 0,
2070 $lines[$i]->fk_unit,
2077 foreach (
$object->lines as $line) {
2078 if ($line->id == $result) {
2079 $line->extraparams = $lines[$i]->extraparams;
2080 $line->setExtraParameters();
2092 if ($result > 0 && $lines[$i]->product_type == 9) {
2093 $fk_parent_line = $result;
2105 $object->line_order(
true,
'DESC');
2133 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id,
'objFrom' => $srcobject);
2134 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
2147 for ($i = 1; $i <= $NBLINES; $i++) {
2153 $result =
$object->addline($product->description, $product->price, (
float)
price2num(
GETPOST(
'qty'.$i),
'MS'), $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx,
GETPOSTINT(
'idprod'.$i), (
float)
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);
2164 if (empty($dateinvoice)) {
2166 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
2176 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
2186 if (!empty($origin) && !empty($originid)) {
2187 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2190 $object->origin_type = $origin;
2191 $object->origin_id = $originid;
2195 $retained_warranty =
GETPOSTINT(
'retained_warranty');
2196 if (
price2num($retained_warranty) > 0) {
2200 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
2201 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
2204 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
2205 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
2206 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
2208 $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);
2211 foreach (
$object->lines as $i => &$line) {
2212 $line->fk_prev_id = $line->id;
2213 $line->fetch_optionals();
2215 $line->situation_percent = 0;
2217 $line->situation_percent = $line->get_prev_progress(
$object->id);
2221 $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);
2222 $line->total_ht = (float) $tabprice[0];
2223 $line->total_tva = (float) $tabprice[1];
2224 $line->total_ttc = (float) $tabprice[2];
2225 $line->total_localtax1 = (float) $tabprice[9];
2226 $line->total_localtax2 = (float) $tabprice[10];
2227 $line->multicurrency_total_ht = (float) $tabprice[16];
2228 $line->multicurrency_total_tva = (float) $tabprice[17];
2229 $line->multicurrency_total_ttc = (float) $tabprice[18];
2232 if ($line->fk_remise_except) {
2234 $result = $discount->fetch($line->fk_remise_except);
2237 if ($discount->fk_facture_line > 0) {
2238 $line->fk_remise_except = 0;
2247 $object->date_pointoftax = $date_pointoftax;
2248 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2264 $object->situation_counter += 1;
2269 $extrafields->fetch_name_optionals_label(
$object->table_element);
2270 $extrafields->setOptionalsFromPost(
null, $object);
2276 $nextSituationInvoice =
new Facture($db);
2277 $nextSituationInvoice->fetch($id);
2280 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id);
2281 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $nextSituationInvoice, $action);
2292 if ($id > 0 && !$error) {
2294 $categories =
GETPOST(
'categories',
'array');
2295 if (method_exists($object,
'setCategories')) {
2296 $object->setCategories($categories);
2304 $outputlangs = $langs;
2307 $newlang =
GETPOST(
'lang_id',
'aZ09');
2310 if (empty(
$object->thirdparty)) {
2313 $newlang =
$object->thirdparty->default_lang;
2315 if (!empty($newlang)) {
2316 $outputlangs =
new Translate(
"", $conf);
2317 $outputlangs->setDefaultLang($newlang);
2318 $outputlangs->load(
'products');
2323 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2329 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2334 $_GET[
"origin"] = $_POST[
"origin"];
2335 $_GET[
"originid"] = $_POST[
"originid"];
2338 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2342 foreach (
$object->lines as $line) {
2343 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2346 if ($line->product_type == 1) {
2347 $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);
2350 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2352 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2353 $vat_rate = str_replace(
'*',
'', $vat_rate);
2356 foreach (
$object->lines as $line) {
2357 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2360 $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);
2362 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2364 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2365 $remise_percent = str_replace(
'*',
'', $remise_percent);
2366 foreach (
$object->lines as $line) {
2367 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2370 $tvatx = $line->tva_tx;
2371 if (!empty($line->vat_src_code)) {
2372 $tvatx .=
' ('.$line->vat_src_code.
')';
2374 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, (
float) $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);
2376 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
2379 $langs->load(
'subtotals');
2381 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
2382 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
2384 $subtotal_options = array();
2386 foreach (Facture::$TITLE_OPTIONS as $option) {
2387 $value =
GETPOST($option,
'alphanohtml');
2389 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2394 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2405 $outputlangs = $langs;
2406 $newlang =
GETPOST(
'lang_id',
'alpha');
2408 $newlang =
$object->thirdparty->default_lang;
2410 if (!empty($newlang)) {
2411 $outputlangs =
new Translate(
"", $conf);
2412 $outputlangs->setDefaultLang($newlang);
2415 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2420 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2422 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
2425 $langs->load(
'subtotals');
2427 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
2428 foreach (
$object->lines as $line) {
2429 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
2430 $desc = $line->desc;
2431 $depth = -$line->qty;
2435 $subtotal_options = array();
2437 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
2438 $value =
GETPOST($option,
'alphanohtml');
2440 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2445 if (isset($desc) && isset($depth)) {
2446 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2448 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
2451 if (isset($result) && $result >= 0) {
2457 $outputlangs = $langs;
2458 $newlang =
GETPOST(
'lang_id',
'alpha');
2460 $newlang =
$object->thirdparty->default_lang;
2462 if (!empty($newlang)) {
2463 $outputlangs =
new Translate(
"", $conf);
2464 $outputlangs->setDefaultLang($newlang);
2467 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2472 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2474 } elseif ($action ==
'addline' &&
GETPOST(
'updateallvatlinesblock',
'alpha') &&
GETPOST(
'vatforblocklines',
'alpha') !==
'' && $usercancreate) {
2475 $tx_tva =
GETPOST(
'vatforblocklines') ?
GETPOST(
'vatforblocklines') : 0;
2476 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'tva', $tx_tva);
2477 } elseif ($action ==
'addline' &&
GETPOST(
'updatealldiscountlinesblock',
'alpha') &&
GETPOST(
'discountforblocklines',
'alpha') !==
'' && $usercancreate) {
2478 $discount =
GETPOST(
'discountforblocklines') ?
GETPOST(
'discountforblocklines') : 0;
2479 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'discount', $discount);
2480 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && !
GETPOST(
'submitforallmark',
'alpha') && $usercancreate) {
2481 $langs->load(
'errors');
2486 $line_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
2489 $price_ht_devise =
'';
2491 $price_ttc_devise =
'';
2494 $price_min_ttc =
'';
2496 if (
GETPOST(
'price_ht') !==
'') {
2499 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2502 if (
GETPOST(
'price_ttc') !==
'') {
2505 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2506 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2509 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2510 if ($prod_entry_mode ==
'free') {
2516 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2521 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2524 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
2525 if (empty($remise_percent)) {
2526 $remise_percent = 0;
2530 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2531 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2533 if (is_array($extralabelsline)) {
2535 foreach ($extralabelsline as $key => $value) {
2536 unset($_POST[
"options_".$key.$predef]);
2540 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2541 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2544 if (!$prod_entry_mode) {
2546 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2550 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2551 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2556 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0)
2557 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
2558 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
2559 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
2560 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
2561 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
2562 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2563 $langs->load(
"errors");
2564 if (
$object->type == $object::TYPE_DEPOSIT) {
2566 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2568 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2573 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
2574 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
2578 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
2579 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2583 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2587 $langs->load(
"errors");
2588 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2592 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2593 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
2597 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2598 $idprod = $res->fk_product_child;
2600 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2606 $price_base_type =
null;
2607 if (!$error && ($qty >= 0) && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
2613 $ret =
$object->fetch_thirdparty();
2618 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2629 if (!empty($idprod) && $idprod > 0) {
2631 $prod->fetch($idprod);
2633 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2638 $datapriceofproduct = $prod->getSellPrice(
$mysoc,
$object->thirdparty, $pqp);
2640 $pu_ht = $datapriceofproduct[
'pu_ht'];
2641 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2642 $price_min = $datapriceofproduct[
'price_min'];
2643 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2644 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2648 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2649 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $prod->tva_tx));
2653 if (!empty($price_ht) || $price_ht ===
'0') {
2655 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2656 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2657 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2658 $pu_ttc_devise = (float)
price2num((
float) $pu_ht_devise * (1 + ((float) $tmpvat / 100)),
'MU');
2661 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2663 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2664 } elseif (!empty($price_ttc_devise) || (
string) $price_ttc_devise ===
'0') {
2665 $pu_ttc_devise = (float)
price2num($price_ttc_devise,
'MU');
2666 $pu_ht_devise = (float)
price2num((
float) $pu_ttc_devise / (1 + ((float) $tmpvat / 100)),
'MU');
2669 } elseif ($tmpvat != $tmpprodvat) {
2671 if ($price_base_type !=
'HT') {
2672 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2674 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2678 $outputlangs = $langs;
2684 if (
GETPOST(
'lang_id',
'aZ09')) {
2685 $newlang =
GETPOST(
'lang_id',
'aZ09');
2687 if (empty($newlang)) {
2688 $newlang =
$object->thirdparty->default_lang;
2690 if (!empty($newlang)) {
2691 $outputlangs =
new Translate(
"", $conf);
2692 $outputlangs->setDefaultLang($newlang);
2693 $outputlangs->load(
'products');
2696 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->
description;
2698 $desc = $prod->description;
2710 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
2714 if (!empty($prod->customcode)) {
2715 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomsCode").
': '.$prod->customcode;
2717 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2720 if (!empty($prod->country_code)) {
2721 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $outputlangs, 0);
2724 if (!empty($prod->customcode)) {
2725 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomsCode").
': '.$prod->customcode;
2727 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2730 if (!empty($prod->country_code)) {
2731 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $langs, 0);
2738 $type = $prod->type;
2739 $fk_unit = $prod->fk_unit;
2741 if (!empty($price_ht)) {
2746 if (!empty($price_ttc)) {
2751 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2752 $tva_tx = str_replace(
'*',
'', $tva_tx);
2753 if (empty($tva_tx)) {
2756 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2759 $fk_unit =
GETPOST(
'units',
'alpha');
2761 if ($pu_ttc && !$pu_ht) {
2762 $price_base_type =
'TTC';
2776 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2777 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2780 $pu_equivalent = $pu_ht;
2781 $pu_equivalent_ttc = $pu_ttc;
2783 $currency_tx =
$object->multicurrency_tx;
2787 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
2788 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
2790 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
2791 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
2806 $fournprice = (int) (
GETPOST(
'fournprice'.$predef) ?
GETPOST(
'fournprice'.$predef) :
'');
2811 $price2num_remise_percent =
price2num($remise_percent);
2812 $price2num_price_min =
price2num($price_min);
2813 $price2num_price_min_ttc =
price2num($price_min_ttc);
2814 if (empty($price2num_pu_ht)) {
2815 $price2num_pu_ht = 0;
2817 if (empty($price2num_remise_percent)) {
2818 $price2num_remise_percent = 0;
2820 if (empty($price2num_price_min)) {
2821 $price2num_price_min = 0;
2823 if (empty($price2num_price_min_ttc)) {
2824 $price2num_price_min_ttc = 0;
2829 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2830 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2833 } 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') {
2834 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2841 '@phan-var-force CommonObjectLine[] $lines';
2843 if (
isModEnabled(
'productbatch') && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) &&
getDolGlobalString(
'INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS')) {
2844 $langs->load(
'productbatch');
2845 foreach ($lines[$i]->detail_batch as $batchline) {
2846 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2851 $situation_percent = (GETPOSTISSET(
'progress') ?
GETPOSTINT(
'progress') : 100);
2853 $result =
$object->addline($desc, $pu_ht, (
float) $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,
GETPOSTINT(
'fk_parent_line'), (
int) $fournprice, $buyingprice, $label, $array_options, $situation_percent, 0, $fk_unit, (
float) $pu_ht_devise);
2858 $outputlangs = $langs;
2861 $newlang =
GETPOST(
'lang_id',
'aZ09');
2864 $newlang =
$object->thirdparty->default_lang;
2866 if (!empty($newlang)) {
2867 $outputlangs =
new Translate(
"", $conf);
2868 $outputlangs->setDefaultLang($newlang);
2869 $outputlangs->load(
'products');
2874 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2880 unset($_POST[
'prod_entry_mode']);
2881 unset($_POST[
'qty']);
2882 unset($_POST[
'type']);
2883 unset($_POST[
'remise_percent']);
2884 unset($_POST[
'price_ht']);
2885 unset($_POST[
'multicurrency_price_ht']);
2886 unset($_POST[
'price_ttc']);
2887 unset($_POST[
'tva_tx']);
2888 unset($_POST[
'product_ref']);
2889 unset($_POST[
'product_label']);
2890 unset($_POST[
'product_desc']);
2891 unset($_POST[
'fournprice']);
2892 unset($_POST[
'buying_price']);
2893 unset($_POST[
'np_marginRate']);
2894 unset($_POST[
'np_markRate']);
2895 unset($_POST[
'dp_desc']);
2896 unset($_POST[
'idprod']);
2897 unset($_POST[
'units']);
2898 unset($_POST[
'date_starthour']);
2899 unset($_POST[
'date_startmin']);
2900 unset($_POST[
'date_startsec']);
2901 unset($_POST[
'date_startday']);
2902 unset($_POST[
'date_startmonth']);
2903 unset($_POST[
'date_startyear']);
2904 unset($_POST[
'date_endhour']);
2905 unset($_POST[
'date_endmin']);
2906 unset($_POST[
'date_endsec']);
2907 unset($_POST[
'date_endday']);
2908 unset($_POST[
'date_endmonth']);
2909 unset($_POST[
'date_endyear']);
2910 unset($_POST[
'situations']);
2911 unset($_POST[
'progress']);
2919 } elseif ($action ==
'addline' && $usercancreate && (
2920 (
GETPOST(
'submitforallmargins',
'alpha') &&
GETPOST(
'marginforalllines',
'alpha') !==
'') ||
2921 (
GETPOST(
'submitforallmark',
'alpha') &&
GETPOST(
'markforalllines',
'alpha') !==
''))) {
2923 $margin_rate = GETPOSTISSET(
'marginforalllines') ?
GETPOST(
'marginforalllines',
'int') :
'';
2924 $mark_rate = GETPOSTISSET(
'markforalllines') ?
GETPOST(
'markforalllines',
'int') :
'';
2925 foreach (
$object->lines as &$line)
if ($line->subprice > 0) {
2926 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2929 $subprice_multicurrency = $line->subprice;
2930 if (is_numeric($margin_rate) && $margin_rate > 0) {
2931 $line->subprice = (float)
price2num((
float) $line->pa_ht * (1 + (float) $margin_rate / 100),
'MU');
2932 } elseif (is_numeric($mark_rate) && $mark_rate > 0) {
2933 $line->subprice = (float) ($line->pa_ht / (1 - ((
float) $mark_rate / 100)));
2935 $line->subprice = (float) $line->pa_ht;
2939 $res = $prod->fetch($line->fk_product);
2941 if ($prod->price_min > $line->subprice) {
2942 $price_subprice =
price($line->subprice, 0, $outlangs, 1, -1, -1,
'auto');
2943 $price_price_min =
price($prod->price_min, 0, $outlangs, 1, -1, -1,
'auto');
2944 setEventMessages($prod->ref .
' - ' . $prod->label .
' (' . $price_subprice .
' < ' . $price_price_min .
' ' . strtolower($langs->trans(
"MinPrice")) .
')' .
"\n",
null,
'warnings');
2948 } elseif ($line->fk_product) {
2952 $multicurrency_subprice = (float) $line->subprice * $line->multicurrency_subprice / $subprice_multicurrency;
2954 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->date_start, $line->date_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->product_ref, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $multicurrency_subprice);
2957 if (is_numeric($margin_rate) && empty($mark_rate)) {
2958 $line->marge_tx = $margin_rate;
2959 } elseif (is_numeric($mark_rate) && empty($margin_rate)) {
2960 $line->marque_tx = $mark_rate;
2962 $line->total_ht = $line->qty * (float) $line->subprice;
2963 $line->total_tva = $line->tva_tx * $line->qty * (float) $line->subprice;
2964 $line->total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $line->subprice;
2966 $line->multicurrency_total_ht = $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
2967 $line->multicurrency_total_tva = $line->tva_tx * $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
2968 $line->multicurrency_total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
2970 $line->multicurrency_subprice = $multicurrency_subprice;
2975 } elseif ($action ==
'updatetitleline' && GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2978 $langs->load(
'subtotals');
2980 $desc =
GETPOST(
'line_desc',
'alphanohtml') ?? $langs->trans(
"Title");
2983 $subtotal_options = array();
2985 foreach (Facture::$TITLE_OPTIONS as $option) {
2986 $value =
GETPOST($option,
'alphanohtml');
2988 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2993 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3004 $outputlangs = $langs;
3005 $newlang =
GETPOST(
'lang_id',
'alpha');
3007 $newlang =
$object->thirdparty->default_lang;
3009 if (!empty($newlang)) {
3010 $outputlangs =
new Translate(
"", $conf);
3011 $outputlangs->setDefaultLang($newlang);
3014 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3019 } elseif ($action ==
'updatesubtotalline' && GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3022 $langs->load(
'subtotals');
3024 $desc =
GETPOST(
'line_desc',
'alphanohtml');
3027 $subtotal_options = array();
3029 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
3030 $value =
GETPOST($option,
'alphanohtml');
3032 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
3037 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3045 $outputlangs = $langs;
3046 $newlang =
GETPOST(
'lang_id',
'alpha');
3048 $newlang =
$object->thirdparty->default_lang;
3050 if (!empty($newlang)) {
3051 $outputlangs =
new Translate(
"", $conf);
3052 $outputlangs->setDefaultLang($newlang);
3055 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3060 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3061 if (!
$object->fetch($id) > 0) {
3084 if (preg_match(
'/\*/', $vat_rate)) {
3089 $vat_rate = str_replace(
'*',
'', $vat_rate);
3094 $fournprice = (int) (
GETPOST(
'fournprice') ?
GETPOST(
'fournprice') :
'');
3098 $pu_equivalent = $pu_ht;
3099 $pu_equivalent_ttc = $pu_ttc;
3101 $currency_tx =
$object->multicurrency_tx;
3105 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3106 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
3108 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3109 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
3124 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
3125 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
3127 if (is_array($extralabelsline)) {
3129 foreach ($extralabelsline as $key => $value) {
3130 unset($_POST[
"options_".$key]);
3136 if ($special_code == 3) {
3142 $percent = $line->get_prev_progress(
$object->id);
3147 if ($progress >= 0) {
3148 $mesg = $langs->trans(
"CantBeNullOrPositive");
3152 } elseif ($progress < $line->situation_percent) {
3153 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
3157 } elseif ($progress < $percent) {
3158 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
3166 if (empty($remise_percent)) {
3167 $remise_percent = 0;
3170 $price_base_type =
'HT';
3172 if (empty($pu) && !empty($pu_ttc)) {
3174 $price_base_type =
'TTC';
3179 if (!empty($productid)) {
3181 $product->fetch($productid);
3183 $type = $product->type;
3185 $price_min = $product->price_min;
3187 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
3189 $price_min_ttc = $product->price_min_ttc;
3191 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
3198 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
3199 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
3202 $action =
'editline';
3203 } 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') {
3204 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
3207 $action =
'editline';
3212 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
3216 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
3221 $langs->load(
"errors");
3222 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
3226 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
3227 $langs->load(
"errors");
3228 if (
$object->type == $object::TYPE_DEPOSIT) {
3230 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
3232 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
3236 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
3243 $previousprogress = $line->getAllPrevProgress($line->fk_facture);
3246 if ($fullprogress < $previousprogress) {
3248 setEventMessages($langs->trans(
'CantBeLessThanMinPercent'),
null,
'errors');
3252 if ($fullprogress > 100) {
3253 $fullprogress = 100;
3255 $addprogress = $fullprogress - $previousprogress;
3262 if (empty($usercancreatemargin)) {
3263 foreach (
$object->lines as &$line) {
3265 $fournprice = $line->fk_fournprice;
3266 $buyingprice = $line->pa_ht;
3272 $result =
$object->updateline(
3277 (
float) $remise_percent,
3295 (
float) $pu_ht_devise
3301 $outputlangs = $langs;
3304 $newlang =
GETPOST(
'lang_id',
'aZ09');
3307 $newlang =
$object->thirdparty->default_lang;
3309 if (!empty($newlang)) {
3310 $outputlangs =
new Translate(
"", $conf);
3311 $outputlangs->setDefaultLang($newlang);
3312 $outputlangs->load(
'products');
3316 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3319 unset($_POST[
'qty']);
3320 unset($_POST[
'type']);
3321 unset($_POST[
'productid']);
3322 unset($_POST[
'remise_percent']);
3323 unset($_POST[
'price_ht']);
3324 unset($_POST[
'multicurrency_price_ht']);
3325 unset($_POST[
'price_ttc']);
3326 unset($_POST[
'tva_tx']);
3327 unset($_POST[
'product_ref']);
3328 unset($_POST[
'product_label']);
3329 unset($_POST[
'product_desc']);
3330 unset($_POST[
'fournprice']);
3331 unset($_POST[
'buying_price']);
3332 unset($_POST[
'np_marginRate']);
3333 unset($_POST[
'np_markRate']);
3334 unset($_POST[
'dp_desc']);
3335 unset($_POST[
'idprod']);
3336 unset($_POST[
'units']);
3337 unset($_POST[
'date_starthour']);
3338 unset($_POST[
'date_startmin']);
3339 unset($_POST[
'date_startsec']);
3340 unset($_POST[
'date_startday']);
3341 unset($_POST[
'date_startmonth']);
3342 unset($_POST[
'date_startyear']);
3343 unset($_POST[
'date_endhour']);
3344 unset($_POST[
'date_endmin']);
3345 unset($_POST[
'date_endsec']);
3346 unset($_POST[
'date_endday']);
3347 unset($_POST[
'date_endmonth']);
3348 unset($_POST[
'date_endyear']);
3349 unset($_POST[
'situations']);
3350 unset($_POST[
'progress']);
3355 } elseif ($action ==
'updatealllines' && $usercancreate && GETPOSTISSET(
'all_percent')) {
3356 if (!
$object->fetch($id) > 0) {
3359 if (
GETPOST(
'all_progress') !=
"") {
3361 foreach (
$object->lines as $line) {
3363 $percent = $line->getAllPrevProgress(
$object->id);
3365 $percent = $line->get_prev_progress(
$object->id);
3367 if (
$object->type != $object::TYPE_CREDIT_NOTE && (
float) $all_progress < (
float) $percent) {
3368 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
3371 } elseif (
$object->type == $object::TYPE_CREDIT_NOTE && (
float) $all_progress > (
float) $percent) {
3372 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeMoreThanMinPercent");
3381 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
3382 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
3384 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
3386 $object->fetch($id,
'',
'', 0,
true);
3389 &&
$object->isSituationInvoice()
3392 &&
$object->is_last_in_cycle()
3393 && $usercanunvalidate
3396 $newCycle =
$object->newCycle();
3397 if ($newCycle > 1) {
3399 $lastCycle =
$object->situation_cycle_ref;
3400 $lastSituationCounter =
$object->situation_counter;
3401 $linkedCreditNotesList = array();
3403 if (count(
$object->tab_next_situation_invoice) > 0) {
3404 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
3406 && $next_invoice->situation_counter ==
$object->situation_counter
3407 && $next_invoice->fk_facture_source ==
$object->id
3409 $linkedCreditNotesList[] = $next_invoice->id;
3414 $object->situation_cycle_ref = $newCycle;
3415 $object->situation_counter = 1;
3417 if (
$object->update($user) > 0) {
3419 if (count($linkedCreditNotesList) > 0) {
3421 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
3422 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
3423 $sql .=
' , situation_final=0';
3424 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
3425 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
3427 $resql = $db->query($sql);
3433 foreach (
$object->lines as $line) {
3435 if ($line->product_type == 9) {
3440 if (!empty(
$object->tab_previous_situation_invoice)) {
3442 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
3443 $searchPreviousInvoice =
true;
3444 while ($searchPreviousInvoice) {
3445 if (
$object->tab_previous_situation_invoice[$lineIndex]->isSituationInvoice() || $lineIndex < 1) {
3446 $searchPreviousInvoice =
false;
3454 $maxPrevSituationPercent = 0;
3455 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
3456 if ($prevLine->id == $line->fk_prev_id) {
3457 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
3462 $line->situation_percent -= $maxPrevSituationPercent;
3464 if ($line->update() < 0) {
3473 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
3475 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
3478 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
3481 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
3487 $fromElement =
GETPOST(
'fromelement');
3488 $fromElementid =
GETPOST(
'fromelementid');
3489 $importLines =
GETPOST(
'line_checkbox');
3491 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
3492 $lineClassName =
'';
3493 if ($fromElement ==
'commande') {
3495 $lineClassName =
'OrderLine';
3496 } elseif ($fromElement ==
'propal') {
3497 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
3498 $lineClassName =
'PropaleLigne';
3500 $nextRang = count(
$object->lines) + 1;
3503 foreach ($importLines as $lineId) {
3504 if ($lineClassName ===
'') {
3508 dol_syslog(
'compta/facture/card - No lineClassName - skip import', LOG_ERR);
3515 $lineId = intval($lineId);
3516 $originLine =
new $lineClassName($db);
3517 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
3518 $originLine->fetch_optionals();
3519 $desc = $originLine->desc;
3520 $pu_ht = $originLine->subprice;
3521 $qty = $originLine->qty;
3522 $txtva = $originLine->tva_tx;
3523 $txlocaltax1 = $originLine->localtax1_tx;
3524 $txlocaltax2 = $originLine->localtax2_tx;
3525 $fk_product = $originLine->fk_product;
3526 $remise_percent = $originLine->remise_percent;
3527 $date_start = $originLine->date_start;
3528 $date_end = $originLine->date_end;
3529 $fk_code_ventilation = 0;
3530 $info_bits = $originLine->info_bits;
3531 $fk_remise_except = $originLine->fk_remise_except;
3532 $price_base_type =
'HT';
3534 $type = $originLine->product_type;
3535 $rang = $nextRang++;
3536 $special_code = $originLine->special_code;
3537 $origin = $originLine->element;
3538 $origin_id = $originLine->id;
3539 $fk_parent_line = 0;
3540 $fk_fournprice = $originLine->fk_fournprice;
3541 $pa_ht = $originLine->pa_ht;
3542 $label = $originLine->label;
3543 $array_options = $originLine->array_options;
3544 if (
$object->isSituationInvoice()) {
3545 $situation_percent = 0;
3547 $situation_percent = 100;
3550 $fk_unit = $originLine->fk_unit;
3551 $pu_ht_devise = $originLine->multicurrency_subprice;
3553 $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);
3573 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3579 if (!empty(
$object->id) && $action ==
'send') {
3581 $object->getSommePaiement(-1);
3582 $object->getSumCreditNotesUsed(-1);
3583 $object->getSumDepositsUsed(-1);
3585 $triggersendname =
'BILL_SENTBYMAIL';
3587 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3588 $trackid =
'inv'.$object->id;
3589 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3592 $upload_dir = $conf->invoice->multidir_output[!empty(
$object->entity) ?
$object->entity : $conf->entity];
3593 $permissiontoadd = $usercancreate;
3594 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3597 if ($action ==
'update_extras' && $permissiontoeditextra) {
3600 $attribute_name =
GETPOST(
'attribute',
'aZ09');
3603 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
3610 $result =
$object->updateExtraField($attribute_name,
'BILL_MODIFY');
3618 $action =
'edit_extras';
3623 if ($action ==
'addcontact' && $usercancreate) {
3624 $result =
$object->fetch($id);
3626 if ($result > 0 && $id > 0) {
3629 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3633 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3636 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3637 $langs->load(
"errors");
3638 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3643 } elseif ($action ==
'swapstatut' && $usercancreate) {
3650 } elseif ($action ==
'deletecontact' && $usercancreate) {
3653 $result =
$object->delete_contact($lineid);
3656 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3664 $action =
'edit_extras';
3674$form =
new Form($db);
3680$bankaccountstatic =
new Account($db);
3688$title =
$object->ref.
" - ".$langs->trans(
'Card');
3689if ($action ==
'create') {
3690 $title = $langs->trans(
"NewBill");
3692$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3698if ($action ==
'create') {
3699 $facturestatic =
new Facture($db);
3700 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3705 $res = $soc->fetch($socid);
3708 $currency_code = $conf->currency;
3710 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3711 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3715 if (empty($dateinvoice)) {
3722 if (!empty($origin) && !empty($originid)) {
3724 $element = $subelement = $origin;
3726 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3727 $element = $regs[1];
3728 $subelement = $regs[2];
3733 if ($element ==
'project') {
3734 $projectid = $originid;
3736 if (empty($cond_reglement_id)) {
3737 $cond_reglement_id = $soc->cond_reglement_id;
3739 if (empty($mode_reglement_id)) {
3740 $mode_reglement_id = $soc->mode_reglement_id;
3742 if (empty($fk_account)) {
3743 $fk_account = $soc->fk_account;
3747 if ($element ==
'order' || $element ==
'commande') {
3748 $element = $subelement =
'commande';
3750 if ($element ==
'propal') {
3751 $element =
'comm/propal';
3752 $subelement =
'propal';
3754 if ($element ==
'contract') {
3755 $element = $subelement =
'contrat';
3757 if ($element ==
'shipping') {
3758 $element = $subelement =
'expedition';
3763 $classname = ucfirst($subelement);
3764 $objectsrc =
new $classname($db);
3765 '@phan-var-force Commande|Propal|Contrat|Expedition $objectsrc';
3767 $objectsrc->fetch($originid);
3768 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3769 $objectsrc->fetch_lines();
3771 $objectsrc->fetch_thirdparty();
3773 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3779 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3783 if (empty($socid)) {
3784 $soc = $objectsrc->thirdparty;
3787 if ($element ==
'expedition') {
3788 $elem = $subelem = $objectsrc->origin_type;
3789 $expeoriginid = $objectsrc->origin_id;
3791 $classname = ucfirst($subelem);
3793 $expesrc =
new $classname($db);
3794 '@phan-var-force Expedition $expesrc';
3796 dol_syslog(
"Is type Facture|Commande or Expedition: $element...expesrc($classname)=".get_class($expesrc));
3797 $expesrc->fetch($expeoriginid);
3799 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3800 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3801 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3804 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3805 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3809 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3812 $expesrc->fetch_optionals();
3813 $object->array_options = $expesrc->array_options;
3815 $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)));
3816 $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)));
3817 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : (!empty($fk_account) ? $fk_account : 0)));
3820 if (!empty($objectsrc->multicurrency_code)) {
3821 $currency_code = $objectsrc->multicurrency_code;
3823 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
3824 $currency_tx = $objectsrc->multicurrency_tx;
3829 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3832 $objectsrc->fetch_optionals();
3833 $object->array_options = $objectsrc->array_options;
3837 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
3838 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
3839 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
3840 $inputReasonId = empty($soc->demand_reason_id) ? $inputReasonId : $soc->demand_reason_id;
3842 if (
isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3843 $currency_code = $soc->multicurrency_code;
3848 if (!
GETPOST(
'changecompany')) {
3849 if (GETPOSTISSET(
'cond_reglement_id')) {
3850 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3852 if (GETPOSTISSET(
'mode_reglement_id')) {
3853 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3855 if (GETPOSTISSET(
'cond_reglement_id')) {
3861 if (empty($cond_reglement_id)) {
3862 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
3866 if (empty($mode_reglement_id)) {
3867 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
3877 if (!empty($soc->id)) {
3878 $absolute_discount = $soc->getAvailableDiscounts();
3880 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
3881 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
3883 if (!empty($conf->use_javascript_ajax)) {
3884 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3890 if ($origin ==
'contrat') {
3891 $langs->load(
"admin");
3892 $text = $langs->trans(
"ToCreateARecurringInvoice");
3893 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3895 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3897 print
info_admin($text, 0, 0,
'info',
'').
'<br>';
3900 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3901 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3902 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3903 print
'<input type="hidden" name="changecompany" value="0">';
3905 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3907 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3908 print
'<input name="ref" type="hidden" value="provisoire">';
3909 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3910 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3911 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3912 print
'<input name="force_fk_account" type="hidden" value="0">';
3913 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3914 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3915 print
'<input type="hidden" name="originentity" value="'.GETPOSTINT(
'originentity').
'">';
3916 if (!empty($currency_tx)) {
3917 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3923 $parameters = array();
3925 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters, $object, $action);
3926 if (empty($reshook)) {
3927 print
'<table class="border centpercent">';
3929 $exampletemplateinvoice =
new FactureRec($db);
3931 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3932 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
3936 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
'Ref').
'</td>';
3937 print
'<td colspan="2">';
3938 print $langs->trans(
"Draft");
3943 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
3945 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
'Customer').
'</td>';
3946 print
'<td colspan="2">';
3947 print $soc->getNomUrl(1,
'customer');
3948 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3950 $arrayoutstandingbills = $soc->getOutstandingBills();
3951 $outstandingBills = $arrayoutstandingbills[
'opened'];
3952 print
' - <span class="opacitymedium valignmiddle">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3953 print
'<span class="amount valignmiddle">'.price($outstandingBills, 0, $langs, 0, 0, -1, $conf->currency).
'</span>';
3954 if ($soc->outstanding_limit !=
'') {
3955 if ($outstandingBills > $soc->outstanding_limit) {
3956 print
img_warning($langs->trans(
"OutstandingBillReached"));
3958 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1, $conf->currency);
3963 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3964 print
'<td colspan="2">';
3965 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
3966 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3970 $(document).ready(function() {
3971 $("#socid").change(function() {
3973 console.log("Submit page");
3974 $(\'input[name="action"]\').val(\'create\');
3975 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3976 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3977 $(\'input[name="force_fk_account"]\').val(\'1\');
3978 $("#formtocreate").submit(); */
3980 // For company change, we must submit page with action=create instead of action=add
3981 console.log("We have changed the company - Resubmit page");
3982 jQuery("input[name=changecompany]").val("1");
3983 jQuery("#formtocreateaction").val("create");
3984 jQuery("#formtocreate").submit();
3990 print
' <a class="valignmiddle" 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>';
3997 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3999 foreach ($invoice_predefined->array_options as $key => $option) {
4000 if (!isset(
$object->array_options[$key])) {
4001 $object->array_options[$key] = $invoice_predefined->array_options[$key];
4005 $dateinvoice = $invoice_predefined->date_when;
4006 if (empty($projectid)) {
4007 $projectid = $invoice_predefined->fk_project;
4009 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
4010 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
4011 $fk_account = $invoice_predefined->fk_account;
4012 $note_public = $invoice_predefined->note_public;
4013 $note_private = $invoice_predefined->note_private;
4015 if (!empty($invoice_predefined->multicurrency_code)) {
4016 $currency_code = $invoice_predefined->multicurrency_code;
4018 if (!empty($invoice_predefined->multicurrency_tx)) {
4019 $currency_tx = $invoice_predefined->multicurrency_tx;
4022 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
4023 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
4024 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
4026 $resql = $db->query($sql);
4028 $num = $db->num_rows($resql);
4032 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
4034 print
'<select class="flat" id="fac_rec" name="fac_rec">';
4035 print
'<option value="0" selected></option>';
4037 $objp = $db->fetch_object($resql);
4038 print
'<option value="'.$objp->rowid.
'"';
4041 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
4043 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
4052 print
'<script type="text/javascript">
4053 $(document).ready(function() {
4054 $("#fac_rec").change(function() {
4055 console.log("We have changed the template invoice - Reload page");
4056 var fac_rec = $(this).val();
4057 var socid = $(\'#socid\').val();
4058 // 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.
4059 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
4072 print
'<tr><td class="tdtop fieldrequired titlefieldcreate">'.$langs->trans(
'Type').
'</td><td colspan="2">';
4073 print
'<div class="listofinvoicetypetable">'.
"\n";
4076 print
'<div class="listofinvoicetype"><div class="">';
4077 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
4078 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
4080 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'nowraponall', 0, 3,
'standardonsmartphone');
4082 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
4092 print
'<span class="opacitymedium marginleftonly">' . $langs->trans(
'PercentOfOriginalObject') .
'</span>:<input class="right" placeholder="100%" type="text" id="valuestandardinvoice" name="valuestandardinvoice" size="3" value="' . (GETPOSTISSET(
'valuestandardinvoice') ?
GETPOST(
'valuestandardinvoice',
'alpha') :
'100%') .
'"/>';
4095 print
'</div></div>'.
"\n";
4097 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
4100 print
'<div class="listofinvoicetype"><div class="">';
4101 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
4102 print
'<script type="text/javascript">
4103 jQuery(document).ready(function() {
4104 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
4105 jQuery("#radio_standard").prop("checked", true);
4107 jQuery("#typedeposit, #valuedeposit").click(function() {
4108 jQuery("#radio_deposit").prop("checked", true);
4110 jQuery("#typedeposit").change(function() {
4111 console.log("We change type of down payment: "+jQuery("#typedeposit").val());
4113 if (jQuery("#typedeposit").val() == "amount") {
4114 jQuery("#valuedeposit").attr("placeholder", "'.$langs->getCurrencySymbol($conf->currency).
'");
4115 jQuery("#valuedeposit").val("");
4117 jQuery("#valuedeposit").attr("placeholder", "50%");
4118 jQuery("#valuedeposit").val("");
4121 jQuery("#radio_deposit").prop("checked", true);
4122 setRadioForTypeOfInvoice();
4124 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
4125 setRadioForTypeOfInvoice();
4128 function setRadioForTypeOfInvoice() {
4129 console.log("Change radio for type of invoice");
4130 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
4131 jQuery("#checkforselects").prop("disabled", true);
4132 jQuery("#checkforselects").prop("checked", false);
4133 jQuery(".checkforselect").prop("disabled", true);
4134 jQuery(".checkforselect").prop("checked", false);
4136 jQuery("#checkforselects").prop("disabled", false);
4137 jQuery("#checkforselects").prop("checked", true);
4138 jQuery(".checkforselect").prop("disabled", false);
4139 jQuery(".checkforselect").prop("checked", true);
4145 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
4147 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
4149 if (($origin ==
'propal') || ($origin ==
'commande')) {
4152 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
4153 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
4154 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4158 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4162 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
4164 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
4165 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
4166 if (!empty($origin_payment_conditions_deposit_percent)) {
4167 $typedeposit =
'variable';
4170 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
4171 $valuedeposit = $objectsrc->deposit_percent;
4173 print
'<span class="marginleftonly">'.$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1).
'</span>';
4175 print
'<input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.($valuedeposit ? $valuedeposit :
'').
'"'.($valuedeposit ?
'' :
'placeholder="'.$langs->getCurrencySymbol($conf->currency).
'"').
'>';
4178 print
'</div></div>'.
"\n";
4185 print
'<div class="listofinvoicetype"><div class="">';
4186 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
4187 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
4189 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
4193 $opt = $form->selectSituationInvoices((
string)
GETPOSTINT(
'originid'), $socid);
4196 print
'</div></div><div class="listofinvoicetype"><div>';
4198 $tmp =
'<input id="radio_situation_bis" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
4199 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4200 $tmp .=
' disabled';
4203 $text = $tmp.
'<label for="radio_situation_bis">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4205 $text .=
'<select class="flat minwidth125" id="situations" name="situations"';
4206 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4207 $text .=
' disabled';
4211 $text .=
'</select>';
4212 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
4214 print
'</div></div>'.
"\n";
4220 $facids = $facturestatic->list_replacable_invoices($soc->id);
4226 if (is_array($facids)) {
4227 foreach ($facids as $facparam) {
4228 $options .=
'<option value="'.$facparam [
'id'].
'"';
4229 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
4230 $options .=
' selected';
4232 $options .=
'>'.$facparam[
'ref'];
4233 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
4234 $options .=
'</option>';
4238 print
'<!-- replacement line -->';
4239 print
'<div class="listofinvoicetype"><div class="">';
4240 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
4241 if (!$options || $invoice_predefined->id > 0) {
4242 $tmp .=
' disabled';
4245 print
'<script type="text/javascript">
4246 jQuery(document).ready(function() {
4247 jQuery("#fac_replacement").change(function() {
4248 console.log("We change fac_replacement");
4249 jQuery("#radio_replacement").prop("checked", true);
4253 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
4254 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
4255 if (!$options || $invoice_predefined->id > 0) {
4256 $text .=
' disabled';
4260 $text .=
'<option value="-1"> </option>';
4263 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
4265 $text .=
'</select>';
4266 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
4268 print
'</div></div>'.
"\n";
4272 print
'<div class="listofinvoicetype"><div class="">';
4273 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
4274 $text = $tmp.
'<label class="opacitymedium">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4275 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'firstsituationonsmartphone');
4277 print
'</div></div>'.
"\n";
4280 print
'<div class="listofinvoicetype"><div class="">';
4281 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
4282 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
4283 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'replacementonsmartphone');
4285 print
'</div></div>'.
"\n";
4288 if (empty($origin)) {
4293 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
4299 $newinvoice_static =
new Facture($db);
4300 foreach ($facids as $key => $valarray) {
4301 $newinvoice_static->id = $key;
4302 $newinvoice_static->ref = $valarray [
'ref'];
4303 $newinvoice_static->statut = $valarray [
'status'];
4304 $newinvoice_static->status = $valarray [
'status'];
4305 $newinvoice_static->type = $valarray [
'type'];
4306 $newinvoice_static->paye = $valarray [
'paye'];
4307 $newinvoice_static->paid = $valarray [
'paye'];
4309 $optionsav .=
'<option value="'.$key.
'"';
4310 if ($key ==
GETPOST(
'fac_avoir')) {
4311 $optionsav .=
' selected';
4314 $newinvoice_static->fetch_optionals($key);
4315 $object->array_options = $newinvoice_static->array_options;
4318 $optionsav .= $newinvoice_static->ref;
4319 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
4320 $optionsav .=
'</option>';
4323 print
'<div class="listofinvoicetype"><div class="">';
4324 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
4325 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
4326 $tmp .=
' disabled';
4330 print
'<script type="text/javascript">
4331 jQuery(document).ready(function() {
4332 if (jQuery("#radio_creditnote").is(":checked"))
4334 jQuery("#radio_standard").prop("disabled", true);
4336 jQuery("#radio_standard").prop("disabled", false);
4338 if (! jQuery("#radio_creditnote").is(":checked"))
4340 jQuery("#credit_note_options").hide();
4342 jQuery("#radio_creditnote").click(function() {
4344 jQuery("#credit_note_options").show();
4346 jQuery("#radio_standard, #radio_replacement, #radio_deposit, #radio_situation, #radio_situation_bis").click(function() {
4347 console.log("We click on a radio to close credit not options");
4348 jQuery("#credit_note_options").hide();
4352 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
4353 $text .=
'<select class="flat valignmiddle minwidth200" name="fac_avoir" id="fac_avoir"';
4354 if (!$optionsav || $invoice_predefined->id > 0) {
4355 $text .=
' disabled';
4359 $text .=
'<option value="-1">'.$langs->trans(
"InvoiceAvoirAskCombo").
'</option>';
4360 $text .= $optionsav;
4362 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
4364 $text .=
'</select>';
4365 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
4368 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
4369 print
'<div class="marginleftlargeondesktop"><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" class="small">'.$langs->trans(
'invoiceAvoirWithLines').
"</label></div>";
4370 print
'<div class="marginleftlargeondesktop"><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" class="small">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label></div>";
4375 print
'</div></div>'.
"\n";
4378 print
'<div class="listofinvoicetype"><div class="">';
4380 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
4382 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
4384 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
4386 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
4388 print
'</div></div>'.
"\n";
4393 print
'<div class="listofinvoicetype"><div class="">';
4394 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
4395 $text = $tmp.
'<label class="opacitymedium" for="radio_template">'.$langs->trans(
"RepeatableInvoice").
'</label> ';
4396 $desc = $form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3,
'templateonsmartphone');
4398 print
'</div></div>'.
"\n";
4407 foreach ($listtType as $type) {
4408 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
4410 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
4413 print
'<script type="text/javascript">
4414 $(document).ready(function() {
4415 var listType = {'.$jsListType.
'};
4416 $("[name=\'type\']").change(function() {
4417 console.log("change name=type");
4418 if ($( this ).prop("checked"))
4420 if(($( this ).val() in listType))
4422 $("#model").val(listType[$( this ).val()]).trigger("change");
4439 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
4440 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
4446 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
4450 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
4453 $defaulttpldir =
'/core/tpl';
4454 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
4455 foreach ($dirtpls as $module => $reldir) {
4457 if (!empty($module)) {
4460 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
4462 if (file_exists($tpl)) {
4463 if (empty($conf->file->strict_mode)) {
4464 $res = @include $tpl;
4466 $res = include $tpl;
4469 if ($res) {
break; }
4479 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
4480 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4481 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
4486 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
4487 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4488 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
4493 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
4494 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
4495 print $form->getSelectConditionsPaiements((
int) $cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
4500 $rwStyle =
'display:none;';
4501 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
4505 $retained_warranty =
GETPOSTINT(
'retained_warranty');
4506 if (empty($retained_warranty)) {
4507 if ($objectsrc !==
null && property_exists($objectsrc,
'retained_warranty') && !empty($objectsrc->retained_warranty)) {
4509 $retained_warranty = $objectsrc->retained_warranty;
4512 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
4514 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
4515 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
4518 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
4519 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
4520 if (empty($retained_warranty_fk_cond_reglement)) {
4521 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4522 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
4523 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
4525 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4528 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4531 print
'<script type="text/javascript">
4532 $(document).ready(function() {
4533 $("[name=\'type\']").change(function() {
4534 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
4536 $(".retained-warranty-line").show();
4537 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
4540 $(".retained-warranty-line").hide();
4541 $("#new-situation-invoice-retained-warranty").val("");
4545 $("[name=\'type\']:checked").trigger("change");
4551 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
4552 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
4553 print $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth250 widthcentpercentminusx', 1);
4558 print
'<tr><td>'.$langs->trans(
'DefaultBankAccount').
'</td><td colspan="2">';
4559 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4560 print $form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth250 widthcentpercentminusx', 1);
4566 print
'<tr><td>'.$langs->trans(
'Source').
'</td><td>';
4567 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
4568 $form->selectInputReason((
string) $inputReasonId,
'input_reason_id',
'', 1,
'maxwidth250 widthcentpercentminusx');
4571 print
'<input type="hidden" name="input_reason_id" value="'.((string) $inputReasonId).
'">';
4575 if (
isModEnabled(
'project') && is_object($formproject)) {
4576 $langs->load(
'projects');
4577 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
4578 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
4580 print $formproject->select_projects((($socid > 0 && !
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_CUSTOMERS')) ? $socid : -1), (string) $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
4581 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>';
4588 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
4589 print
'<td colspan="2" class="maxwidthonsmartphone">';
4590 $incoterm_id =
GETPOST(
'incoterm_id');
4591 $location_incoterms =
GETPOST(
'location_incoterms');
4592 if (empty($incoterm_id)) {
4593 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
4594 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
4596 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
4597 print $form->select_incoterms($incoterm_id, $location_incoterms);
4611 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
4612 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
4617 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
4618 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
4619 print $hookmanager->resPrint;
4620 if (empty($reshook)) {
4621 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
4624 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
4625 if ($soc->fetch_optionals() > 0) {
4626 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
4630 print
$object->showOptionals($extrafields,
'create', $parameters);
4634 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
4635 print
'<td colspan="2">';
4636 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
4637 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
4642 $paramkey =
'FACTURE_ADDON_PDF_'.$type;
4647 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
4653 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
4654 print
'<td colspan="2" class="maxwidthonsmartphone">';
4655 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
4656 print $form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth200 widthcentpercentminusx');
4663 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
4664 if (empty($dateexample)) {
4667 $substitutionarray = array(
4668 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
4669 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
4670 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
4671 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
4672 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
4673 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
4674 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
4675 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
4676 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
4677 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
4678 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
4681 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
4682 foreach ($substitutionarray as $key => $val) {
4683 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
4685 $htmltext .=
'</i>';
4690 print
'<td class="tdtop">';
4691 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
4693 print
'<td valign="top" colspan="2">';
4694 $doleditor =
new DolEditor(
'note_public', (
string) $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
4695 print $doleditor->Create(1);
4698 if (empty($user->socid)) {
4700 print
'<td class="tdtop">';
4701 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4703 print
'<td valign="top" colspan="2">';
4704 $doleditor =
new DolEditor(
'note_private', (
string) $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4705 print $doleditor->Create(1);
4711 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4712 $langs->loadLangs(array(
'orders',
'propal'));
4715 if ($origin ==
'contrat') {
4716 '@phan-var-force Contrat $objectsrc';
4718 $objectsrc->update_price(1,
'auto', 1);
4721 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4722 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4723 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4724 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4729 switch (get_class($objectsrc)) {
4731 $newclassname =
'CommercialProposal';
4734 $newclassname =
'Order';
4737 $newclassname =
'Sending';
4740 $newclassname =
'Contract';
4743 $newclassname =
'Intervention';
4746 $newclassname = get_class($objectsrc);
4750 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4751 print
'<td colspan="2">';
4752 print $objectsrc->getNomUrl(1);
4754 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
4755 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4757 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4761 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht, 1, $langs, 1, -1,
'', $conf->currency).
'</td></tr>';
4762 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva, 1, $langs, 1, -1,
'', $conf->currency).
"</td></tr>";
4763 if (
$mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4764 print
'<tr><td>'.$langs->transcountry(
"AmountLT1",
$mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax1, 1, $langs, 1, -1,
'', $conf->currency).
"</td></tr>";
4767 if (
$mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4768 print
'<tr><td>'.$langs->transcountry(
"AmountLT2",
$mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax2, 1, $langs, 1, -1,
'', $conf->currency).
"</td></tr>";
4770 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc, 1, $langs, 1, -1,
'', $conf->currency).
"</td></tr>";
4772 if (
isModEnabled(
'multicurrency') && $objectsrc->multicurrency_code != $conf->currency) {
4774 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
'</td></tr>';
4775 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4776 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4784 print $form->buttonsSaveCancel(
"CreateDraft");
4787 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4790 $title = $langs->trans(
'ProductsAndServices');
4793 print
'<div class="div-table-responsive-no-min">';
4794 print
'<table class="noborder centpercent">';
4796 $objectsrc->printOriginLinesList(
'', $selectedLines);
4803} elseif ($id > 0 || !empty($ref)) {
4805 $langs->load(
'errors');
4806 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4815 if ($user->socid > 0 && $user->socid !=
$object->socid) {
4819 $result =
$object->fetch_thirdparty();
4821 $result = $soc->fetch(
$object->socid);
4825 $selleruserevenustamp =
$mysoc->useRevenueStamp();
4827 $totalpaid =
$object->getSommePaiement();
4828 $totalcreditnotes =
$object->getSumCreditNotesUsed();
4829 $totaldeposits =
$object->getSumDepositsUsed();
4835 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4839 $multicurrency_totalpaid =
$object->getSommePaiement(1);
4840 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
4841 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
4842 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4846 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code != $conf->currency) {
4847 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
4851 if (
$object->paye ||
$object->status == $object::STATUS_CLOSED) {
4854 $resteapayeraffiche = $resteapayer;
4857 $filterabsolutediscount =
"fk_facture_source IS NULL";
4858 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4860 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4861 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4864 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
4865 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
4866 $absolute_discount =
price2num($absolute_discount,
'MT');
4867 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4869 $nb_creditnote_notyetavailable = $soc->getOpenCreditNotesNotYetConvertedIntoDiscount(0);
4871 $author =
new User($db);
4872 if (
$object->user_creation_id) {
4873 $author->fetch(
$object->user_creation_id);
4876 $objectidnext =
$object->getIdReplacingInvoice();
4885 if ($action ==
'converttoreduc') {
4887 $type_fac =
'ExcessReceived';
4889 $type_fac =
'CreditNote';
4891 $type_fac =
'Deposit';
4895 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4896 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4897 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4901 if ($action ==
'delete') {
4902 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
4903 $formquestion = array();
4906 $qualified_for_stock_change = 0;
4908 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4910 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4913 if ($qualified_for_stock_change) {
4914 $langs->load(
"stocks");
4915 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4919 if ($conf->browser->name ==
'ie') {
4922 $formquestion = array(
4926 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4928 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4930 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4933 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4938 if ($action ==
'situationout') {
4939 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
4940 $label = $langs->trans(
"ConfirmOuting");
4941 $formquestion = array();
4946 &&
$object->is_last_in_cycle()
4947 && $usercanunvalidate
4949 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4954 if ($action ==
'valid') {
4956 $objectref = substr(
$object->ref, 1, 4);
4957 if ($objectref ==
'PROV') {
4961 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
4963 $numref =
$object->getNextNumRef($soc);
4966 $numref = (string)
$object->ref;
4969 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4971 $text .=
'<br><br>';
4972 $text .=
img_picto(
'',
'warning',
'class="pictofixedwidth"').
' '.$langs->trans(
'WarningInvoiceCanNeverBeEdited');
4975 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4976 $notify =
new Notify($db);
4978 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid, $object);
4980 $formquestion = array();
4983 $qualified_for_stock_change = 0;
4985 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4987 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4990 if ($qualified_for_stock_change) {
4991 $langs->load(
"stocks");
4992 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4993 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4996 $warehouse_array = $warehouse->list_array();
4997 if (count($warehouse_array) == 1) {
4998 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4999 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5002 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5004 $formquestion = array(
5010 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5014 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
5019 foreach (
$object->lines as $line) {
5020 $res = $line->fetch_product();
5022 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
5028 if ($nbMandated > 0) {
5030 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
5033 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
5038 $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, 260);
5043 if ($action ==
'modif') {
5046 $testvalue =
$object->isEditable();
5047 if ($testvalue < 0) {
5048 switch ($testvalue) {
5051 setEventMessages($langs->trans(
"DisabledBecauseDispatchedInBookkeeping"),
null,
'errors');
5055 setEventMessages($langs->trans(
"DisabledBecauseNotLastInvoice"),
null,
'errors');
5059 setEventMessages($langs->trans(
"DisabledBecauseNotLastSituationInvoice"),
null,
'errors');
5063 setEventMessages($langs->trans(
"DisabledBecauseThereIsAPayment"),
null,
'errors');
5067 setEventMessages($langs->trans(
"DisabledBecauseAlreadySentByEmail"),
null,
'errors');
5071 setEventMessages($langs->trans(
"DisabledBecauseAlreadyPrintedOnce"),
null,
'errors');
5087 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
5088 $formquestion = array();
5091 $qualified_for_stock_change = 0;
5093 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5095 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5098 if ($qualified_for_stock_change) {
5099 $langs->load(
"stocks");
5100 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5101 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
5104 $warehouse_array = $warehouse->list_array();
5105 if (count($warehouse_array) == 1) {
5106 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
5107 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5110 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5112 $formquestion = array(
5118 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5122 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
5127 if ($action ==
'canceled') {
5131 $statusreplacement = 0;
5133 if ($objectidnext) {
5134 $facturereplacement =
new Facture($db);
5135 $facturereplacement->fetch($objectidnext);
5136 $statusreplacement = $facturereplacement->status;
5138 if ($objectidnext && $statusreplacement == 0) {
5139 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
5143 $close[1][
'code'] =
'badcustomer';
5144 $close[2][
'code'] =
'abandon';
5146 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5147 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
5149 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
5150 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
5153 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
5154 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
5157 $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'));
5159 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 300);
5164 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
5165 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
5167 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
5171 $close[$i][
'code'] = $object::CLOSECODE_DISCOUNTVAT;
5173 $close[$i][
'code'] = $object::CLOSECODE_BADDEBT;
5175 $close[$i][
'code'] = $object::CLOSECODE_BANKCHARGE;
5177 $close[$i][
'code'] = $object::CLOSECODE_WITHHOLDINGTAX;
5179 $close[$i][
'code'] = $object::CLOSECODE_OTHER;
5183 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
5185 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5187 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
5189 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
5191 $close[$i][
'label'] = $langs->trans(
"Other");
5195 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5197 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5199 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5201 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
5203 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
5207 foreach ($close as $key => $val) {
5208 $arrayreasons[$close[$key][
'code']] =
'<span class="small">'.$close[$key][
'reason'].
'</span>';
5212 $formquestion = array(
5213 'text' => $langs->trans(
"ConfirmClassifyPaidPartiallyQuestion"),
5214 0 => array(
'type' =>
'radio',
'name' =>
'close_code',
'label' =>
'',
'values' => $arrayreasons),
5215 1 => array(
'type' =>
'text',
'name' =>
'close_note',
'moreattr' =>
'placeholder = "'.$langs->trans(
"Comment").
'"',
'value' =>
'',
'morecss' =>
'minwidth300'),
5216 2 => array(
'type' =>
'separator')
5219 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&resteapayer='.((
float) $resteapayer), $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 420, 600);
5222 if ($action ==
'deletepayment') {
5223 $payment_id =
GETPOST(
'paiement_id');
5224 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
5228 if ($action ==
'ask_deleteline') {
5229 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
5233 if ($action ==
'ask_subtotal_deleteline') {
5234 $langs->load(
"subtotals");
5235 $title =
"DeleteSubtotalLine";
5236 $question =
"ConfirmDeleteSubtotalLine";
5237 if (
GETPOST(
'type') ==
'title') {
5238 $formconfirm = array(array(
'type' =>
'checkbox',
'name' =>
'deletecorrespondingsubtotalline',
'label' => $langs->trans(
"DeleteCorrespondingSubtotalLine"),
'value' => 0));
5239 $title =
"DeleteTitleLine";
5240 $question =
"ConfirmDeleteTitleLine";
5242 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans($title), $langs->trans($question),
'confirm_delete_subtotalline', $formconfirm,
'no', 1);
5246 if ($action ==
'clone') {
5247 $filter =
'(s.client:IN:1,2,3)';
5249 $formquestion = array(
5250 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
$object->socid,
'socid', $filter, 1)),
5251 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
5254 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
5258 if ($action ==
'add_title_line') {
5259 $langs->load(
'subtotals');
5261 $depth_array =
$object->getPossibleLevels($langs);
5263 } elseif ($action ==
'add_subtotal_line') {
5264 $langs->load(
'subtotals');
5266 $titles =
$object->getPossibleTitles();
5270 if ($action ==
"remove_file_comfirm") {
5271 $file =
GETPOST(
'file',
'alpha');
5273 $formconfirm = $form->formconfirm(
5274 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
5275 $langs->trans(
'DeleteFileHeader'),
5276 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
5285 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
5286 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
5287 if (empty($reshook)) {
5288 $formconfirm .= $hookmanager->resPrint;
5289 } elseif ($reshook > 0) {
5290 $formconfirm = $hookmanager->resPrint;
5298 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
5300 $morehtmlref =
'<div class="refidno">';
5303 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5304 $morehtmlref .= $form->editfieldval(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'',
null,
null,
'', 1);
5305 $morehtmlref .=
'<br>';
5308 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5309 $morehtmlref .= $form->editfieldval(
"RefCustomer",
'ref_client',
$object->ref_customer, $object, (
int) $usercancreate,
'string'.(getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') ?
':' .
getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') :
''),
'', null, null,
'', 1);
5311 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
5313 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'">'.$langs->trans(
"OtherBills").
'</a>)';
5317 $langs->load(
"projects");
5318 $morehtmlref .=
'<br>';
5319 if ($usercancreate) {
5320 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
5321 if ($action !=
'classify') {
5322 $morehtmlref .=
'<a class="editfielda" href="'.dolBuildUrl($_SERVER[
'PHP_SELF'], [
'action' =>
'classify',
'id' =>
$object->id],
true).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
5324 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->socid, (
string)
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
5326 if (!empty(
$object->fk_project)) {
5328 $proj->fetch(
$object->fk_project);
5329 $morehtmlref .= $proj->getNomUrl(1);
5331 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
5336 $morehtmlref .=
'</div>';
5338 $object->totalpaid = $totalpaid;
5339 $object->totalcreditnotes = $totalcreditnotes;
5340 $object->totaldeposits = $totaldeposits;
5343 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
5346 $parameters = array();
5348 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters, $object, $action);
5349 if (empty($reshook)) {
5350 print
'<div class="fichecenter">';
5351 print
'<div class="fichehalfleft">';
5352 print
'<div class="underbanner clearboth"></div>';
5354 print
'<table class="border centpercent tableforfield">';
5357 print
'<tr><td class="fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
5360 print
' '.$object->getSubtypeLabel(
'facture');
5363 $facreplaced =
new Facture($db);
5364 $facreplaced->fetch(
$object->fk_facture_source);
5365 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
5369 $facusing->fetch(
$object->fk_facture_source);
5370 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
5374 $object->getListIdAvoirFromInvoice();
5376 if (!empty(
$object->creditnote_ids)) {
5377 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
5379 foreach (
$object->creditnote_ids as $invoiceid) {
5385 $creditnote =
new Facture($db);
5386 $creditnote->fetch($invoiceid);
5387 print $creditnote->getNomUrl(1,
'', 32);
5391 if ($objectidnext > 0) {
5392 $facthatreplace =
new Facture($db);
5393 $facthatreplace->fetch($objectidnext);
5394 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
5399 $result = $discount->fetch(0,
$object->id);
5401 print
' <span class="opacitymediumbycolor paddingleft">';
5402 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
5403 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
5404 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
5406 print
'</span><br>';
5410 if (
$object->fk_fac_rec_source > 0) {
5412 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
5414 print
' <span class="opacitymediumbycolor paddingleft">';
5415 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
5416 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
5420 print
' <span class="opacitymediumbycolor paddingleft">';
5421 print $langs->transnoentities(
"GeneratedFromTemplate", $langs->trans(
"ObjectDeleted"));
5429 $langs->load(
"cashdesk");
5430 print
'<tr><td class="fieldname_type">';
5431 print
'<table class="nobordernopadding centpercent"><tr><td>';
5432 print $form->textwithpicto($langs->trans(
'PointOfSale'), $langs->trans(
'POSInfo'));
5434 if ($action !=
'editposinfo' && $usercancreate) {
5435 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editposinfo&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'SetPOSInfo'), 1).
'</a></td>';
5437 print
'</tr></table>';
5438 print
'</td><td class="valuefield fieldname_type">';
5439 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" name="formposinfo">';
5440 print
'<input type="hidden" name="action" value="setposinfo">';
5441 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5442 if ($action ==
'editposinfo') {
5443 print
'<input type="text" class="maxwidth150" name="posmodule" placeholder="'.$langs->trans(
"POSModule").
'" value="'.
$object->module_source.
'"> ';
5444 print
'<input type="text" class="maxwidth100" name="posterminal" placeholder="'.$langs->trans(
"Terminal").
'" value="'.
$object->pos_source.
'">';
5445 print
'<input type="submit" class="button" name="submitposinfo" value="'.$langs->trans(
"Submit").
'">';
5448 print
'<span class="opacitymediumbycolor paddingleft">'.dolPrintHTML(ucfirst(
$object->module_source).
' - '.$langs->transnoentitiesnoconv(
"Terminal").
' '.
$object->pos_source).
'</span>';
5456 print
'<!-- Discounts -->'.
"\n";
5457 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
5461 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
5462 $defaulttpldir =
'/core/tpl';
5464 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5465 foreach ($dirtpls as $module => $reldir) {
5467 if (!empty($module)) {
5470 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
5472 if (file_exists($tpl)) {
5473 if (empty($conf->file->strict_mode)) {
5474 $res = @include $tpl;
5476 $res = include $tpl;
5479 if ($res) {
break; }
5486 print
'<table class="nobordernopadding centpercent"><tr><td>';
5487 print $langs->trans(
'DateInvoice');
5489 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
5490 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>';
5492 print
'</tr></table>';
5494 if ($action ==
'editinvoicedate') {
5495 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
5497 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
5512 print
'<table class="nobordernopadding centpercent"><tr><td>';
5513 print $langs->trans(
'DatePointOfTax');
5516 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>';
5518 print
'</tr></table>';
5520 if ($action ==
'editdate_pointoftax' && $editable) {
5521 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
5523 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
5531 print $form->editfieldkey(
'Source',
'input_reason',
'', $object, (
int) $usercancreate);
5532 print
'</td><td class="valuefield">';
5533 if ($action ==
'editinput_reason') {
5534 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'input_reason_id', 1,
'maxwidth250 widthcentpercentminusx');
5536 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'none');
5543 print
'<table class="nobordernopadding centpercent"><tr><td>';
5544 print $langs->trans(
'PaymentConditionsShort');
5547 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>';
5549 print
'</tr></table>';
5552 if ($action ==
'editconditions') {
5553 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
5555 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
5562 print
'<table class="nobordernopadding centpercent"><tr><td>';
5563 print $langs->trans(
'DateMaxPayment');
5566 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>';
5568 print
'</tr></table>';
5571 if ($action ==
'editpaymentterm') {
5572 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
5574 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
5584 print
'<table class="nobordernopadding centpercent"><tr><td>';
5585 print $langs->trans(
'PaymentMode');
5587 if ($action !=
'editmode' && $usercancreate) {
5588 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>';
5590 print
'</tr></table>';
5592 if ($action ==
'editmode') {
5593 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
5595 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'none',
'CRDT');
5601 print
'<tr><td class="nowrap">';
5602 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
5603 print $langs->trans(
'DefaultBankAccount');
5605 if (($action !=
'editbankaccount') && $usercancreate) {
5606 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>';
5608 print
'</tr></table>';
5610 if ($action ==
'editbankaccount') {
5611 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
5613 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
5622 print
'<table class="nobordernopadding centpercent"><tr><td>';
5623 print $langs->trans(
'IncotermLabel');
5624 print
'<td><td class="right">';
5625 if ($usercancreate) {
5626 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
5628 print
'</td></tr></table>';
5631 if ($action !=
'editincoterm') {
5632 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
5634 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
5641 print
'<table class="nobordernopadding centpercent"><tr><td>';
5642 print $langs->trans(
'Dispute');
5643 print
'<td><td class="right">';
5644 if ($usercancreate) {
5645 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editdispute_status&token='.
newToken().
'">'.
img_edit().
'</a>';
5647 print
'</td></tr></table>';
5649 $liststatus = array(
'0' =>
"None",
'1' =>
"DisputeOpen",
'8' =>
"DisputeLost",
'9' =>
"DisputeWon");
5650 if ($action !=
'editdispute_status') {
5651 if (
$object->dispute_status) {
5652 print $langs->trans($liststatus[
$object->dispute_status]);
5655 print
'<form enctype="multipart/form-data" action="'.DOL_URL_ROOT.
'/compta/facture/card.php" method="POST">';
5656 print
'<input type="hidden" name="action" value="set_dispute_status">';
5657 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5658 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
5659 print
'<input type="hidden" name="page_y" value="">';
5660 print $form->selectarray(
'dispute_status', $liststatus,
$object->dispute_status, 0, 0, 0,
'', 1);
5661 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Save").
'">';
5669 print
'<table class="nobordernopadding centpercent"><tr><td>';
5670 print $langs->trans(
"Categories");
5671 print
'<td><td class="right">';
5672 if ($usercancreate) {
5673 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
5677 print
'</td></tr></table>';
5680 if ($action ==
'edittags') {
5681 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5682 print
'<input type="hidden" name="action" value="settags">';
5683 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5684 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
5685 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5688 print $form->showCategories(
$object->id, Categorie::TYPE_INVOICE, 1);
5693 $displayWarranty =
false;
5696 $displayWarranty =
true;
5697 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
5698 $displayWarranty =
false;
5701 if ($displayWarranty) {
5703 print
'<tr class="retained-warranty-lines" ><td>';
5704 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
5705 print $langs->trans(
'RetainedWarranty');
5708 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>';
5711 print
'</tr></table>';
5714 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5715 print
'<input type="hidden" name="action" value="setretainedwarranty">';
5716 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5717 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5718 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
5719 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5727 print
'<tr class="retained-warranty-lines" ><td>';
5728 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
5729 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
5731 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
5732 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>';
5735 print
'</tr></table>';
5737 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5738 if (
$object->date > $defaultDate) {
5744 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5745 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
5746 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5747 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5748 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
5749 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
5750 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
5751 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
5752 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5755 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->retained_warranty_fk_cond_reglement,
'none');
5756 if (!$displayWarranty) {
5757 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning',
'class="pictowarning valignmiddle" ');
5763 print
'<tr class="retained-warranty-lines" ><td>';
5764 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
5765 print $langs->trans(
'RetainedWarrantyDateLimit');
5768 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>';
5771 print
'</tr></table>';
5773 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5774 if (
$object->date > $defaultDate) {
5779 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5780 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
5781 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5782 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5784 print $form->selectDate($defaultDate,
'retained_warranty_date_limit');
5785 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5797 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
5802 print
'<div class="fichehalfright">';
5804 print
'<!-- amounts -->'.
"\n";
5805 print
'<div class="underbanner clearboth"></div>'.
"\n";
5807 print
'<table class="border tableforfield centpercent">';
5809 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
5817 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
5818 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5821 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5827 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
5828 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5831 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5836 if ((
$mysoc->localtax1_assuj ==
"1" &&
$mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
5838 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1",
$mysoc->country_code) .
'</td>';
5839 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5843 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5848 if ((
$mysoc->localtax2_assuj ==
"1" &&
$mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
5850 print
'<td>' . $langs->transcountry(
"AmountLT2",
$mysoc->country_code) .
'</td>';
5851 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5855 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5861 if ($selleruserevenustamp) {
5862 print
'<tr><td class="titlefieldmiddle">';
5863 print
'<table class="nobordernopadding centpercent"><tr><td>';
5864 print $langs->trans(
'RevenueStamp');
5866 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
5867 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>';
5869 print
'</tr></table>';
5870 print
'</td><td class="nowrap amountcard right">';
5871 if ($action ==
'editrevenuestamp') {
5872 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
5873 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5874 print
'<input type="hidden" name="action" value="setrevenuestamp">';
5875 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
5876 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5877 print $formother->select_revenue_stamp(
'',
'revenuestamp_type',
$mysoc->country_code);
5878 print
' → <span id="revenuestamp_span"></span>';
5879 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
5882 $(document).ready(function(){
5883 js_recalculate_revenuestamp();
5884 $('select[name=revenuestamp_type]').on('change',function(){
5885 js_recalculate_revenuestamp();
5888 function js_recalculate_revenuestamp(){
5889 var valselected = $('select[name=revenuestamp_type]').val();
5890 console.log('Calculate revenue stamp from '+valselected);
5892 if (valselected.indexOf('%') == -1)
5894 revenue = valselected;
5898 var revenue_type = parseFloat(valselected);
5899 var amount_net = ".round(
$object->total_ht, 2).
";
5900 revenue = revenue_type * amount_net / 100;
5901 revenue = revenue.toFixed(2);
5903 $('#revenuestamp_val').val(revenue);
5904 $('#revenuestamp_span').html(revenue);
5908 print
price(
$object->revenuestamp, 1,
'', 1, -1, -1, $conf->currency);
5915 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
5916 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5919 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5934 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
5937 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
5940 if ($selleruserevenustamp) {
5950 $total_prev_ht = $total_prev_ttc = 0;
5951 $total_global_ht = $total_global_ttc = 0;
5955 print
'<!-- List of situation invoices -->';
5956 print
'<div class="div-table-responsive-no-min">';
5957 print
'<table class="noborder paymenttable centpercent situationstable">';
5959 print
'<tr class="liste_titre">';
5960 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
5962 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
5965 print
'<td class="right"></td>';
5967 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
5968 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
5969 print
'<td width="18"> </td>';
5972 if (count(
$object->tab_previous_situation_invoice) > 0) {
5975 $current_situation_counter = array();
5976 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
5977 $tmptotalallpayments = $prev_invoice->getSommePaiement(0);
5978 $tmptotalallpayments += $prev_invoice->getSumDepositsUsed(0);
5979 $tmptotalallpayments += $prev_invoice->getSumCreditNotesUsed(0);
5981 $total_prev_ht += $prev_invoice->total_ht;
5982 $total_prev_ttc += $prev_invoice->total_ttc;
5984 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
5985 print
'<tr class="oddeven">';
5986 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
5988 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
5990 print
'<td class="right"></td>';
5992 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
5993 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
5994 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalallpayments).
'</td>';
5999 $totalallpayments =
$object->getSommePaiement(0);
6000 $totalallpayments +=
$object->getSumCreditNotesUsed(0);
6001 $totalallpayments +=
$object->getSumDepositsUsed(0);
6003 $total_global_ht += $total_prev_ht;
6004 $total_global_ttc += $total_prev_ttc;
6005 $total_global_ht +=
$object->total_ht;
6006 $total_global_ttc +=
$object->total_ttc;
6010 print
'<tr class="oddeven">';
6011 print
'<td>'.$object->getNomUrl(1).
'</td>';
6013 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
6015 print
'<td class="right"></td>';
6017 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
6018 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
6019 print
'<td class="right">'.$object->getLibStatut(3, $totalallpayments).
'</td>';
6023 print
'<tr class="oddeven">';
6024 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'SituationTotalAfterInvoice').
'</b></td>';
6027 foreach ($current_situation_counter as $sit) {
6028 $curSign = $sit > 0 ?
'+' :
'-';
6029 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
6031 print
' '.$curSign.
' ';
6033 print $curType.abs($sit);
6040 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6041 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6042 print
'<td width="18"> </td>';
6046 if (count(
$object->tab_next_situation_invoice) > 0) {
6048 $total_next_ht = $total_next_ttc = 0;
6050 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
6051 $next_totalpaid = $next_invoice->getSommePaiement(0);
6052 $next_totalcreditnotes = $next_invoice->getSumCreditNotesUsed(0);
6053 $next_totaldeposits = $next_invoice->getSumDepositsUsed(0);
6054 $total_next_ht += $next_invoice->total_ht;
6055 $total_next_ttc += $next_invoice->total_ttc;
6057 print
'<tr class="oddeven">';
6058 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
6060 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
6062 print
'<td class="right"></td>';
6064 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
6065 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
6066 print
'<td class="right">'.$next_invoice->getLibStatut(3, $next_totalpaid + $next_totalcreditnotes + $next_totaldeposits).
'</td>';
6070 $total_global_ht += $total_next_ht;
6071 $total_global_ttc += $total_next_ttc;
6073 print
'<tr class="oddeven">';
6074 print
'<td colspan="3" class="right"></td>';
6076 print
'<td class="right"></td>';
6078 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6079 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6080 print
'<td width="18"> </td>';
6089 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
6095 print
'<!-- List of payments already done -->';
6096 print
'<div class="div-table-responsive-no-min">';
6097 print
'<table class="noborder paymenttable centpercent">';
6099 print
'<tr class="liste_titre">';
6100 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
6101 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
6102 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
6104 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
6106 print
'<td class="liste_titre"></td>';
6107 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
6111 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
6112 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
6113 $sql .=
' pf.amount,';
6114 $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';
6115 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
6116 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
6117 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
6118 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
6119 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
6120 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
6121 $sql .=
' ORDER BY p.datep, p.tms';
6123 $result = $db->query($sql);
6125 $num = $db->num_rows($result);
6130 $objp = $db->fetch_object($result);
6132 $paymentstatic->id = $objp->rowid;
6133 $paymentstatic->datepaye = $db->jdate($objp->dp);
6134 $paymentstatic->ref = $objp->ref;
6135 $paymentstatic->num_payment = $objp->num_payment;
6136 $paymentstatic->paiementcode = $objp->payment_code;
6138 print
'<tr class="oddeven">';
6139 print
'<td class="nowraponall">';
6140 print $paymentstatic->getNomUrl(1);
6143 $dateofpayment = $db->jdate($objp->dp);
6145 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
6152 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
6153 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
6155 $bankaccountstatic->id = $objp->baid;
6156 $bankaccountstatic->ref = $objp->baref;
6157 $bankaccountstatic->label = $objp->baref;
6158 $bankaccountstatic->number = $objp->banumber;
6159 $bankaccountstatic->currency_code = $objp->bacurrency_code;
6162 $bankaccountstatic->account_number = $objp->account_number;
6165 $accountingjournal->fetch($objp->fk_accountancy_journal);
6166 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
6169 print
'<td class="nowraponall">';
6170 if ($bankaccountstatic->id) {
6171 print $bankaccountstatic->getNomUrl(1,
'transactions');
6177 print
'<td class="center">';
6179 $paiement->fetch($objp->rowid);
6181 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
6188 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
6203 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6204 print
'<span class="opacitymedium">';
6206 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
6208 print $langs->trans(
'AlreadyPaid');
6210 print
'</span></td>';
6212 print
'<td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td>';
6215 $resteapayeraffiche = $resteapayer;
6216 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
6217 $cssforamountpaymentcompletenoresize =
'amountpaymentcompletenoresize';
6220 $creditnoteamount = 0;
6222 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
6223 $sql .=
" re.description, re.fk_facture_source";
6224 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
6225 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
6226 $resql = $db->query($sql);
6228 $num = $db->num_rows($resql);
6232 $obj = $db->fetch_object($resql);
6233 $invoice->fetch($obj->fk_facture_source);
6235 print
'<td colspan="'.$nbcols.
'" class="right">';
6236 print
'<span class="opacitymedium">';
6238 print $langs->trans(
"CreditNote").
' ';
6241 print $langs->trans(
"Deposit").
' ';
6243 print $invoice->getNomUrl(0);
6247 print
'<td class="right">';
6248 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
6249 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
6253 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
6257 $creditnoteamount += $obj->amount_ttc;
6260 $depositamount += $obj->amount_ttc;
6270 print
'<td colspan="'.$nbcols.
'" class="nowrap right">';
6271 print
'<span class="opacitymedium">';
6272 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
6276 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6278 $resteapayeraffiche = 0;
6279 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6280 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6285 print
'<td colspan="'.($nbcols+1).
'" class="nowrap right">';
6286 print
'<span class="opacitymedium">';
6287 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
6291 print
'<td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td>';
6294 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6295 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6300 print
'<td colspan="'.($nbcols+1).
'" class="nowrap right">';
6301 print
'<span class="opacitymedium">';
6302 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
6306 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6308 $resteapayeraffiche = 0;
6309 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6310 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6315 print
'<td colspan="'.($nbcols+1).
'" class="nowrap right">';
6316 $text = $langs->trans(
"HelpAbandonOther");
6318 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
6320 print
'<span class="opacitymedium">';
6322 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
6326 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6328 $resteapayeraffiche = 0;
6329 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6330 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6335 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6336 print
'<span class="opacitymedium">';
6337 print $langs->trans(
"Billed");
6340 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
6345 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6346 print
'<span class="opacitymedium">';
6347 print $langs->trans(
'RemainderToPay');
6348 if ($resteapayeraffiche < 0) {
6349 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6354 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
6360 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6361 print
'<span class="opacitymedium">';
6362 print $langs->trans(
'RemainderToPayMulticurrency');
6363 if ($resteapayeraffiche < 0) {
6364 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6369 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcompletenoresize)).
'">';
6371 print
price(
price2num(
$object->multicurrency_tx * $resteapayeraffiche,
'MT'), 1, $langs, 1, -1, -1, (empty(
$object->multicurrency_code) ? $conf->currency :
$object->multicurrency_code)).
'</td>';
6376 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
6378 if (
$object->isSituationInvoice()) {
6379 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
6382 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
6385 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
6388 print
'<td colspan="'.($nbcols+1).
'" class="right">'.$langs->trans(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')).
' :</td>';
6390 print
'<td class="right">'.price($billedWithRetainedWarranty).
'</td>';
6395 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6396 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
6397 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
6400 print
'<td class="right">'.price($retainedWarranty).
'</td>';
6404 $resteapayeraffiche = $resteapayer;
6405 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6406 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6410 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6411 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
6414 print
'<td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td>';
6419 print
'<td colspan="'.($nbcols+1).
'" class="right"><span class="opacitymedium">'.$langs->trans(
"Billed").
'</span></td>';
6421 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
6425 print
'<tr><td colspan="'.($nbcols+1).
'" class="right">';
6426 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
6427 if ($resteapayeraffiche > 0) {
6428 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6430 print
'</span></td>';
6432 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche);
6441 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6442 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
6443 if ($resteapayeraffiche > 0) {
6444 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6449 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaybacknoresize' : (
' '.$cssforamountpaymentcompletenoresize)).
'">'.
price(
price2num($sign *
$object->multicurrency_tx * $resteapayeraffiche,
'MT'), 1, $langs, 1, -1, -1, (empty(
$object->multicurrency_code) ? $conf->currency :
$object->multicurrency_code)).
'</td>';
6464 $formmargin->displayMarginInfos($object);
6470 print
'<div class="clearboth"></div><br>';
6473 $blocname =
'contacts';
6474 $title = $langs->trans(
'ContactsAddresses');
6475 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6479 $blocname =
'notes';
6480 $title = $langs->trans(
'Notes');
6481 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6485 $result =
$object->getLinesArray();
6489 global $inputalsopricewithtax;
6490 $inputalsopricewithtax = 1;
6495 print
'<!-- Area to change globally the situation percent -->'.
"\n";
6496 print
'<div class="div-table-responsive-no-min">';
6498 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'#updatealllines" method="POST">';
6499 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
6500 print
'<input type="hidden" name="action" value="updatealllines" />';
6501 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
6502 print
'<input type="hidden" name="page_y" value="" />';
6503 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
6505 print
'<table id="tablelines_all_progress" class="noborder noshadow centpercent">';
6507 print
'<tr class="liste_titre nodrag nodrop">';
6511 print
'<td align="center" width="5"> </td>';
6513 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
6514 print
'<td class="right">'.$langs->trans(
'CumulativeProgression').
'</td>';
6515 print
'<td> </td>';
6518 print
'<tr class="nodrag nodrop">';
6521 print
'<td align="center" width="5"> </td>';
6523 print
'<td> </td>';
6524 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
6525 print
'<td class="right"><input type="submit" class="button reposition small" name="all_percent" value="'.$langs->trans(
"Modify").
'" /></td>';
6536 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
6537 <input type="hidden" name="token" value="' .
newToken().
'">
6538 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
6539 <input type="hidden" name="mode" value="">
6540 <input type="hidden" name="page_y" value="">
6541 <input type="hidden" name="id" value="' .
$object->id.
'">
6542 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
6545 if (!empty($conf->use_javascript_ajax) &&
$object->status == 0) {
6547 include DOL_DOCUMENT_ROOT.
'/core/tpl/subtotal_ajaxrow.tpl.php';
6549 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
6553 print
'<div class="div-table-responsive-no-min">';
6554 print
'<table id="tablelines" class="noborder noshadow centpercent nomarginbottom">';
6558 $object->printObjectLines($action,
$mysoc, $soc, $lineid, 1);
6562 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
6563 if ($action !=
'editline' && $action !=
'selectlines') {
6566 $parameters = array();
6567 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
6571 if (empty($reshook)) {
6575 $parameters = array();
6576 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters, $object, $action);
6590 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
6591 print
'<div class="tabsAction">';
6593 $parameters = array();
6594 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
6595 if (empty($reshook)) {
6598 'class' =>
'classfortooltip',
6605 $ventilExportCompta =
$object->getVentilExportCompta();
6607 if ($ventilExportCompta == 0) {
6609 if (!$objectidnext &&
$object->is_last_in_cycle()) {
6610 if ($usercanunvalidate) {
6611 unset($params[
'attr'][
'title']);
6612 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
true, $params);
6614 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
6615 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
false, $params);
6617 } elseif (!
$object->is_last_in_cycle()) {
6618 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
6619 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6621 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
6622 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6626 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6627 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6632 $result = $discount->fetch(0,
$object->id);
6640 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
6641 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
6642 unset($params[
'attr'][
'title']);
6643 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
6645 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6646 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
6653 $langs->load(
"contracts");
6655 if ($usercancreatecontract) {
6656 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>';
6664 $langs->load(
"subtotals");
6666 $url_button = array();
6668 $url_button[] = array(
6669 'lang' =>
'subtotals',
6671 'perm' => (
bool) $usercancreate,
6672 'label' => $langs->trans(
'AddTitleLine'),
6673 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_title_line&token='.
newToken()
6676 $url_button[] = array(
6677 'lang' =>
'subtotals',
6679 'perm' => (
bool) $usercancreate,
6680 'label' => $langs->trans(
'AddSubtotalLine'),
6681 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_subtotal_line&token='.
newToken()
6683 print
dolGetButtonAction(
'', $langs->trans(
'Subtotal'),
'default', $url_button,
'',
true);
6690 if ($usercanvalidate) {
6691 unset($params[
'attr'][
'title']);
6692 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
6697 if (empty($user->socid)) {
6699 if ($objectidnext) {
6700 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6701 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
6704 unset($params[
'attr'][
'title']);
6705 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
6707 unset($params[
'attr'][
'title']);
6708 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
6716 if ($resteapayer > 0) {
6717 if ($usercancreatewithdrarequest) {
6718 if (!$objectidnext &&
$object->close_code !=
'replaced') {
6719 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>';
6721 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
6733 $langs->load(
"cashdesk");
6734 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
6735 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
6740 if ($objectidnext) {
6741 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
6745 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
6746 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
6750 unset($params[
'attr'][
'title']);
6751 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);
6756 $sumofpayment = $totalpaid;
6757 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
6763 if ($resteapayer == 0) {
6764 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
6766 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
6772 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
6776 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
6778 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>';
6785 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
6787 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
6801 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
6802 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
6804 unset($params[
'attr'][
'title']);
6805 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken(),
'',
true, $params);
6811 if ($totalpaid > 0 || $totalcreditnotes > 0) {
6813 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
6816 if ($objectidnext) {
6817 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
6819 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
6827 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
6828 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6829 } elseif (!
$object->is_last_in_cycle()) {
6830 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6832 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6838 if (!$objectidnext) {
6839 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>';
6845 &&
$object->isSituationInvoice()
6846 && (
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
6849 &&
$object->is_last_in_cycle()
6852 if ($usercanunvalidate) {
6853 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>';
6855 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
6861 if (!$objectidnext && count(
$object->lines) > 0) {
6862 unset($params[
'attr'][
'title']);
6863 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
6869 unset($params[
'attr'][
'title']);
6870 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'clone', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice&token='.
newToken(),
'',
true, $params);
6875 &&
$object->isSituationInvoice()
6878 &&
$object->situation_counter > 1
6879 &&
$object->is_last_in_cycle()
6880 && $usercanunvalidate
6883 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6885 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6890 $isErasable =
$object->is_erasable();
6893 if ($isErasable == -6) {
6894 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadySentByEmail');
6895 } elseif ($isErasable == -5) {
6896 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadyPrintedOnce');
6897 } elseif ($isErasable == -4) {
6898 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
6899 } elseif ($isErasable == -3) {
6900 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
6901 } elseif ($isErasable == -2) {
6902 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
6903 } elseif ($isErasable == -1) {
6904 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6905 } elseif ($isErasable <= 0) {
6906 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable').(empty(
$object->error) ?
': UnknownReason' :
': '.$object->error);
6907 } elseif ($objectidnext) {
6908 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
6910 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
6911 $enableDelete =
false;
6913 if ($isErasable > 0 && ! $objectidnext) {
6914 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
6915 $enableDelete =
true;
6917 unset($params[
'attr'][
'title']);
6918 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
6920 unset($params[
'attr'][
'title']);
6921 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
6928 if (
GETPOST(
'modelselected',
'alpha')) {
6929 $action =
'presend';
6931 if ($action !=
'prerelance' && $action !=
'presend') {
6932 print
'<div class="fichecenter"><div class="fichehalfleft">';
6933 print
'<a name="builddoc"></a>';
6938 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
6939 $genallowed = $usercanread;
6940 $delallowed = $usercancreate;
6941 $tooltipAfterComboOfModels =
'';
6943 $tooltipAfterComboOfModels = $langs->trans(
"AccordingToYourSetupTheFileWillBeConcatenated",
getDolGlobalString(
'MAIN_INFO_INVOICE_TERMSOFSALE'));
6946 print $formfile->showdocuments(
6966 'remove_file_comfirm',
6967 $tooltipAfterComboOfModels
6970 $somethingshown = $formfile->numoffiles;
6973 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice'), 1);
6974 $linktoelem = $tmparray[
'linktoelem'];
6975 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
6976 print $htmltoenteralink;
6978 $compatibleImportElementsList =
false;
6982 $compatibleImportElementsList = array(
'commande',
'propal',
'subscription');
6984 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
6988 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6989 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
6990 $useonlinepayment = count($validpaymentmethod);
6993 print
'<br><!-- Link to pay -->'.
"\n";
6994 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6995 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
6998 print
'</div><div class="fichehalfright">';
7002 $morehtmlcenter =
'<div class="nowraponall">';
7003 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullConversation'),
'',
'fa fa-comments imgforviewmode', DOL_URL_ROOT.
'/compta/facture/messaging.php?id='.
$object->id);
7004 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
7005 $morehtmlcenter .=
'</div>';
7008 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
7010 $somethingshown = $formactions->showactions($object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
7012 print
'</div></div>';
7017 $modelmail =
'facture_send';
7018 $defaulttopic =
'SendBillRef';
7019 $diroutput = $conf->invoice->multidir_output[
$object->entity ?? $conf->entity];
7020 $trackid =
'inv'.$object->id;
7022 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $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 VAT - Value-added tax (also known in French as TVA - Taxe sur la valeur ajoutée)
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_now($mode='gmt')
Return date for now.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
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, $morecssdiv='')
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.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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'.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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 rate, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
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.