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;
1400 if (!empty($facture_source->tab_previous_situation_invoice)) {
1403 $tab_jumped_credit_notes = array();
1404 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1405 $searchPreviousInvoice =
true;
1406 while ($searchPreviousInvoice) {
1407 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1408 $searchPreviousInvoice =
false;
1412 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1418 $maxPrevSituationPercent = 0;
1419 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1420 if ($prevLine->id == $source_fk_prev_id) {
1421 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1424 $line->total_ht -= $prevLine->total_ht;
1425 $line->total_tva -= $prevLine->total_tva;
1426 $line->total_ttc -= $prevLine->total_ttc;
1427 $line->total_localtax1 -= $prevLine->total_localtax1;
1428 $line->total_localtax2 -= $prevLine->total_localtax2;
1430 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1431 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1432 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1433 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1438 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1443 $maxPrevSituationPercent = 0;
1444 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1445 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1446 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1447 $maxPrevSituationPercent = $prevLine->situation_percent;
1449 $line->total_ht -= $prevLine->total_ht;
1450 $line->total_tva -= $prevLine->total_tva;
1451 $line->total_ttc -= $prevLine->total_ttc;
1452 $line->total_localtax1 -= $prevLine->total_localtax1;
1453 $line->total_localtax2 -= $prevLine->total_localtax2;
1455 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1456 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1457 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1458 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1464 $line->situation_percent += $maxPrevSituationPercent;
1470 $line->fk_facture =
$object->id;
1471 $line->fk_parent_line = $fk_parent_line;
1473 $line->subprice = -$line->subprice;
1475 $line->total_ht = -$line->total_ht;
1476 $line->total_tva = -$line->total_tva;
1477 $line->total_ttc = -$line->total_ttc;
1478 $line->total_localtax1 = -$line->total_localtax1;
1479 $line->total_localtax2 = -$line->total_localtax2;
1481 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1482 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1483 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1484 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1486 $line->context[
'createcreditnotefrominvoice'] = 1;
1487 $result = $line->insert(0, 1);
1492 if ($result > 0 && $line->product_type == 9) {
1493 $fk_parent_line = $result;
1501 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1502 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1503 $totalpaid = $facture_source->getSommePaiement();
1504 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1505 $totaldeposits = $facture_source->getSumDepositsUsed();
1506 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1508 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1509 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1512 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1517 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1518 $tva_tx = (float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY');
1523 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), 0, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC', $remain_to_pay);
1528 if (!empty(
$object->fk_facture_source) &&
$id > 0) {
1529 $facture_source->fetch(
$object->fk_facture_source);
1530 $facture_source->fetchObjectLinked();
1532 if (!empty($facture_source->linkedObjectsIds)) {
1533 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1534 $object->add_object_linked($sourcetype, current($TIds));
1543 if (empty($dateinvoice)) {
1545 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1556 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1566 $object->date_pointoftax = $date_pointoftax;
1567 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1568 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1581 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1582 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1598 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1599 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1600 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1604 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1608 if (empty($dateinvoice)) {
1610 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1620 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1621 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1626 if ($typeamount && !empty($origin) && !empty($originid)) {
1627 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1628 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1632 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1633 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1637 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1638 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1648 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1658 $object->date_pointoftax = $date_pointoftax;
1659 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1660 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1672 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1673 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1677 $object->situation_counter = 1;
1682 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1684 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1686 $object->retained_warranty = 0;
1687 $object->retained_warranty_fk_cond_reglement = 0;
1690 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1691 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1694 $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);
1699 if (!empty($origin) && !empty($originid)) {
1702 $element = $subelement = $origin;
1703 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1704 $element = $regs[1];
1705 $subelement = $regs[2];
1709 if ($element ==
'order') {
1710 $element = $subelement =
'commande';
1712 if ($element ==
'propal') {
1713 $element =
'comm/propal';
1714 $subelement =
'propal';
1716 if ($element ==
'contract') {
1717 $element = $subelement =
'contrat';
1719 if ($element ==
'inter') {
1720 $element = $subelement =
'fichinter';
1722 if ($element ==
'shipping') {
1723 $element = $subelement =
'expedition';
1727 $object->origin_type = $origin;
1728 $object->origin_id = $originid;
1733 if (
$object->origin ==
'shipping') {
1734 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1736 $exp->fetch(
$object->origin_id);
1737 $exp->fetchObjectLinked();
1738 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1739 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1740 $object->linked_objects[
'commande'] = $value;
1746 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
1754 $classname = ucfirst($subelement);
1755 $srcobject =
new $classname($db);
1756 '@phan-var-force CommonObject $srcobject';
1758 dol_syslog(
"Try to find source object origin_type=".
$object->origin_type.
" origin_id=".
$object->origin_id.
" to add lines or deposit lines");
1759 $result = $srcobject->fetch(
$object->origin_id);
1765 $amountdeposit = array();
1768 if ($typeamount ==
'amount') {
1769 $amount = (float) $valuedeposit;
1771 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1774 $TTotalByTva = array();
1775 foreach ($srcobject->lines as &$line) {
1776 if (empty($line->qty)) {
1779 if (!empty($line->special_code)) {
1782 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1784 '@phan-var-force array<string,float> $TTotalByTva';
1786 $amount_ttc_diff = 0.;
1787 foreach ($TTotalByTva as $tva => &$total) {
1788 if (empty($amountdeposit[$tva])) {
1789 $amountdeposit[$tva] = 0;
1791 $coef = $total / $srcobject->total_ttc;
1792 $am = $amount * $coef;
1793 $amount_ttc_diff += $am;
1794 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1797 if ($typeamount ==
'amount') {
1798 $amountdeposit[0] = $valuedeposit;
1799 } elseif ($typeamount ==
'variable') {
1802 $lines = $srcobject->lines;
1803 $numlines = count($lines);
1804 for ($i = 0; $i < $numlines; $i++) {
1806 if (empty($lines[$i]->qty)) {
1809 if (!empty($lines[$i]->special_code)) {
1813 $totalamount += $lines[$i]->total_ht;
1814 $tva_tx = $lines[$i]->tva_tx;
1816 if (empty($amountdeposit[$tva_tx])) {
1817 $amountdeposit[$tva_tx] = 0;
1819 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1823 if ($totalamount == 0) {
1824 $amountdeposit[0] = 0;
1832 $amount_ttc_diff = $amountdeposit[0];
1835 foreach ($amountdeposit as $tva => $amount) {
1836 if (empty($amount)) {
1841 'amount' =>
'FixAmount',
1842 'variable' =>
'VarAmount'
1844 $descline =
'(DEPOSIT)';
1846 if ($typeamount ==
'amount') {
1847 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code : $conf->currency)).
')';
1848 } elseif ($typeamount ==
'variable') {
1849 $descline .=
' ('.$valuedeposit.
'%)';
1852 $descline .=
' - '.$srcobject->ref;
1865 $i >= 0 ? $lines[$i]->info_bits : 0,
1871 $i >= 0 ? $lines[$i]->special_code : 0,
1888 $diff =
$object->total_ttc - $amount_ttc_diff;
1892 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1893 $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);
1902 $lines = $srcobject->lines;
1903 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1904 $srcobject->fetch_lines();
1905 $lines = $srcobject->lines;
1910 if (is_array($lines)) {
1911 foreach ($lines as $line) {
1913 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuestandardinvoice / 100,
'MS');
1919 if (is_array($lines)) {
1920 foreach ($lines as $line) {
1922 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuedeposit / 100,
'MS');
1927 $fk_parent_line = 0;
1928 $num = count($lines);
1930 for ($i = 0; $i < $num; $i++) {
1931 if (!in_array($lines[$i]->
id, $selectedLines)) {
1936 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
1940 if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1941 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1943 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
1947 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1948 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1950 if (
$object->situation_counter == 1) {
1951 $lines[$i]->situation_percent = 0;
1954 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
1957 $desc = $label ? $label : $langs->trans(
'Discount');
1961 $discount->fk_soc =
$object->socid;
1962 $discount->socid =
$object->socid;
1963 $discount->amount_ht = abs($lines[$i]->total_ht);
1964 $discount->amount_tva = abs($lines[$i]->total_tva);
1965 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1966 $discount->total_ht = abs($lines[$i]->total_ht);
1967 $discount->total_tva = abs($lines[$i]->total_tva);
1968 $discount->total_ttc = abs($lines[$i]->total_ttc);
1969 $discount->tva_tx = $lines[$i]->tva_tx;
1970 $discount->fk_user = $user->id;
1971 $discount->description = $desc;
1972 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1973 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1974 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1975 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1976 $discount->multicurrency_total_ht = abs($lines[$i]->multicurrency_total_ht);
1977 $discount->multicurrency_total_tva = abs($lines[$i]->multicurrency_total_tva);
1978 $discount->multicurrency_total_ttc = abs($lines[$i]->multicurrency_total_ttc);
1980 $discountid = $discount->create($user);
1981 if ($discountid > 0) {
1982 $result =
$object->insert_discount($discountid);
1994 $date_start =
false;
1995 if (isset($lines[$i]->date_debut_prevue)) {
1996 $date_start = $lines[$i]->date_debut_prevue;
1998 if (isset($lines[$i]->date_debut_reel)) {
1999 $date_start = $lines[$i]->date_debut_reel;
2001 if (isset($lines[$i]->date_start)) {
2002 $date_start = $lines[$i]->date_start;
2007 if (isset($lines[$i]->date_fin_prevue)) {
2008 $date_end = $lines[$i]->date_fin_prevue;
2010 if (isset($lines[$i]->date_fin_reel)) {
2011 $date_end = $lines[$i]->date_fin_reel;
2013 if (isset($lines[$i]->date_end)) {
2014 $date_end = $lines[$i]->date_end;
2018 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
2019 $fk_parent_line = 0;
2022 $array_options = array();
2024 if (method_exists($lines[$i],
'fetch_optionals')) {
2025 $lines[$i]->fetch_optionals();
2026 $array_options = $lines[$i]->array_options;
2029 $tva_tx = $lines[$i]->tva_tx;
2030 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
2031 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
2041 $lines[$i]->subprice,
2046 $lines[$i]->fk_product,
2047 $lines[$i]->remise_percent,
2051 (
int) $lines[$i]->info_bits,
2052 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except : null,
2057 $lines[$i]->special_code,
2061 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice : null,
2065 $lines[$i]->situation_percent ?? 100,
2066 $lines[$i]->fk_prev_id ?? 0,
2067 $lines[$i]->fk_unit,
2074 foreach (
$object->lines as $line) {
2075 if ($line->id == $result) {
2076 $line->extraparams = $lines[$i]->extraparams;
2077 $line->setExtraParameters();
2089 if ($result > 0 && $lines[$i]->product_type == 9) {
2090 $fk_parent_line = $result;
2102 $object->line_order(
true,
'DESC');
2130 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id,
'objFrom' => $srcobject);
2131 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
2144 for ($i = 1; $i <= $NBLINES; $i++) {
2150 $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);
2161 if (empty($dateinvoice)) {
2163 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
2173 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
2183 if (!empty($origin) && !empty($originid)) {
2184 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2187 $object->origin_type = $origin;
2188 $object->origin_id = $originid;
2192 $retained_warranty =
GETPOSTINT(
'retained_warranty');
2193 if (
price2num($retained_warranty) > 0) {
2197 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
2198 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
2201 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
2202 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
2203 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
2205 $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);
2208 foreach (
$object->lines as $i => &$line) {
2209 $line->fk_prev_id = $line->id;
2210 $line->fetch_optionals();
2212 $line->situation_percent = 0;
2214 $line->situation_percent = $line->get_prev_progress(
$object->id);
2218 $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);
2219 $line->total_ht = (float) $tabprice[0];
2220 $line->total_tva = (float) $tabprice[1];
2221 $line->total_ttc = (float) $tabprice[2];
2222 $line->total_localtax1 = (float) $tabprice[9];
2223 $line->total_localtax2 = (float) $tabprice[10];
2224 $line->multicurrency_total_ht = (float) $tabprice[16];
2225 $line->multicurrency_total_tva = (float) $tabprice[17];
2226 $line->multicurrency_total_ttc = (float) $tabprice[18];
2229 if ($line->fk_remise_except) {
2231 $result = $discount->fetch($line->fk_remise_except);
2234 if ($discount->fk_facture_line > 0) {
2235 $line->fk_remise_except = 0;
2244 $object->date_pointoftax = $date_pointoftax;
2245 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2261 $object->situation_counter += 1;
2267 $nextSituationInvoice =
new Facture($db);
2268 $nextSituationInvoice->fetch($id);
2271 $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
2272 $ret = $extrafields->setOptionalsFromPost(
null, $nextSituationInvoice);
2274 $nextSituationInvoice->insertExtraFields();
2278 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id);
2279 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $nextSituationInvoice, $action);
2290 if ($id > 0 && !$error) {
2292 $categories =
GETPOST(
'categories',
'array');
2293 if (method_exists($object,
'setCategories')) {
2294 $object->setCategories($categories);
2302 $outputlangs = $langs;
2305 $newlang =
GETPOST(
'lang_id',
'aZ09');
2308 if (empty(
$object->thirdparty)) {
2311 $newlang =
$object->thirdparty->default_lang;
2313 if (!empty($newlang)) {
2314 $outputlangs =
new Translate(
"", $conf);
2315 $outputlangs->setDefaultLang($newlang);
2316 $outputlangs->load(
'products');
2321 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2327 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2332 $_GET[
"origin"] = $_POST[
"origin"];
2333 $_GET[
"originid"] = $_POST[
"originid"];
2336 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2340 foreach (
$object->lines as $line) {
2341 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2344 if ($line->product_type == 1) {
2345 $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);
2348 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2350 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2351 $vat_rate = str_replace(
'*',
'', $vat_rate);
2354 foreach (
$object->lines as $line) {
2355 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2358 $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);
2360 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2362 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2363 $remise_percent = str_replace(
'*',
'', $remise_percent);
2364 foreach (
$object->lines as $line) {
2365 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2368 $tvatx = $line->tva_tx;
2369 if (!empty($line->vat_src_code)) {
2370 $tvatx .=
' ('.$line->vat_src_code.
')';
2372 $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);
2374 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
2377 $langs->load(
'subtotals');
2379 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
2380 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
2382 $subtotal_options = array();
2384 foreach (Facture::$TITLE_OPTIONS as $option) {
2385 $value =
GETPOST($option,
'alphanohtml');
2387 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2392 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2403 $outputlangs = $langs;
2404 $newlang =
GETPOST(
'lang_id',
'alpha');
2406 $newlang =
$object->thirdparty->default_lang;
2408 if (!empty($newlang)) {
2409 $outputlangs =
new Translate(
"", $conf);
2410 $outputlangs->setDefaultLang($newlang);
2413 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2418 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2420 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
2423 $langs->load(
'subtotals');
2425 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
2426 foreach (
$object->lines as $line) {
2427 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
2428 $desc = $line->desc;
2429 $depth = -$line->qty;
2433 $subtotal_options = array();
2435 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
2436 $value =
GETPOST($option,
'alphanohtml');
2438 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2443 if (isset($desc) && isset($depth)) {
2444 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2446 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
2449 if (isset($result) && $result >= 0) {
2455 $outputlangs = $langs;
2456 $newlang =
GETPOST(
'lang_id',
'alpha');
2458 $newlang =
$object->thirdparty->default_lang;
2460 if (!empty($newlang)) {
2461 $outputlangs =
new Translate(
"", $conf);
2462 $outputlangs->setDefaultLang($newlang);
2465 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2470 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2472 } elseif ($action ==
'addline' &&
GETPOST(
'updateallvatlinesblock',
'alpha') &&
GETPOST(
'vatforblocklines',
'alpha') !==
'' && $usercancreate) {
2473 $tx_tva =
GETPOST(
'vatforblocklines') ?
GETPOST(
'vatforblocklines') : 0;
2474 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'tva', $tx_tva);
2475 } elseif ($action ==
'addline' &&
GETPOST(
'updatealldiscountlinesblock',
'alpha') &&
GETPOST(
'discountforblocklines',
'alpha') !==
'' && $usercancreate) {
2476 $discount =
GETPOST(
'discountforblocklines') ?
GETPOST(
'discountforblocklines') : 0;
2477 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'discount', $discount);
2478 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && !
GETPOST(
'submitforallmark',
'alpha') && $usercancreate) {
2479 $langs->load(
'errors');
2484 $line_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
2487 $price_ht_devise =
'';
2489 $price_ttc_devise =
'';
2492 $price_min_ttc =
'';
2494 if (
GETPOST(
'price_ht') !==
'') {
2497 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2500 if (
GETPOST(
'price_ttc') !==
'') {
2503 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2504 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2507 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2508 if ($prod_entry_mode ==
'free') {
2514 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2519 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2522 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
2523 if (empty($remise_percent)) {
2524 $remise_percent = 0;
2528 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2529 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2531 if (is_array($extralabelsline)) {
2533 foreach ($extralabelsline as $key => $value) {
2534 unset($_POST[
"options_".$key.$predef]);
2538 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2539 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2542 if (!$prod_entry_mode) {
2544 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2548 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2549 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2554 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0)
2555 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
2556 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
2557 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
2558 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
2559 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
2560 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2561 $langs->load(
"errors");
2562 if (
$object->type == $object::TYPE_DEPOSIT) {
2564 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2566 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2571 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
2572 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
2576 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
2577 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2581 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2585 $langs->load(
"errors");
2586 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2590 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2591 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
2595 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2596 $idprod = $res->fk_product_child;
2598 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2604 $price_base_type =
null;
2605 if (!$error && ($qty >= 0) && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
2611 $ret =
$object->fetch_thirdparty();
2616 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2627 if (!empty($idprod) && $idprod > 0) {
2629 $prod->fetch($idprod);
2631 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2636 $datapriceofproduct = $prod->getSellPrice(
$mysoc,
$object->thirdparty, $pqp);
2638 $pu_ht = $datapriceofproduct[
'pu_ht'];
2639 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2640 $price_min = $datapriceofproduct[
'price_min'];
2641 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2642 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2646 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2647 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $prod->tva_tx));
2651 if (!empty($price_ht) || $price_ht ===
'0') {
2653 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2654 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2655 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2656 $pu_ttc_devise = (float)
price2num((
float) $pu_ht_devise * (1 + ((float) $tmpvat / 100)),
'MU');
2659 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2661 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2662 } elseif (!empty($price_ttc_devise) || (
string) $price_ttc_devise ===
'0') {
2663 $pu_ttc_devise = (float)
price2num($price_ttc_devise,
'MU');
2664 $pu_ht_devise = (float)
price2num((
float) $pu_ttc_devise / (1 + ((float) $tmpvat / 100)),
'MU');
2667 } elseif ($tmpvat != $tmpprodvat) {
2669 if ($price_base_type !=
'HT') {
2670 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2672 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2676 $outputlangs = $langs;
2682 if (
GETPOST(
'lang_id',
'aZ09')) {
2683 $newlang =
GETPOST(
'lang_id',
'aZ09');
2685 if (empty($newlang)) {
2686 $newlang =
$object->thirdparty->default_lang;
2688 if (!empty($newlang)) {
2689 $outputlangs =
new Translate(
"", $conf);
2690 $outputlangs->setDefaultLang($newlang);
2691 $outputlangs->load(
'products');
2694 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->
description;
2696 $desc = $prod->description;
2708 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
2712 if (!empty($prod->customcode)) {
2713 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomsCode").
': '.$prod->customcode;
2715 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2718 if (!empty($prod->country_code)) {
2719 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $outputlangs, 0);
2722 if (!empty($prod->customcode)) {
2723 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomsCode").
': '.$prod->customcode;
2725 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2728 if (!empty($prod->country_code)) {
2729 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $langs, 0);
2736 $type = $prod->type;
2737 $fk_unit = $prod->fk_unit;
2739 if (!empty($price_ht)) {
2744 if (!empty($price_ttc)) {
2749 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2750 $tva_tx = str_replace(
'*',
'', $tva_tx);
2751 if (empty($tva_tx)) {
2754 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2757 $fk_unit =
GETPOST(
'units',
'alpha');
2759 if ($pu_ttc && !$pu_ht) {
2760 $price_base_type =
'TTC';
2774 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2775 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2778 $pu_equivalent = $pu_ht;
2779 $pu_equivalent_ttc = $pu_ttc;
2781 $currency_tx =
$object->multicurrency_tx;
2785 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
2786 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
2788 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
2789 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
2804 $fournprice = (int) (
GETPOST(
'fournprice'.$predef) ?
GETPOST(
'fournprice'.$predef) :
'');
2809 $price2num_remise_percent =
price2num($remise_percent);
2810 $price2num_price_min =
price2num($price_min);
2811 $price2num_price_min_ttc =
price2num($price_min_ttc);
2812 if (empty($price2num_pu_ht)) {
2813 $price2num_pu_ht = 0;
2815 if (empty($price2num_remise_percent)) {
2816 $price2num_remise_percent = 0;
2818 if (empty($price2num_price_min)) {
2819 $price2num_price_min = 0;
2821 if (empty($price2num_price_min_ttc)) {
2822 $price2num_price_min_ttc = 0;
2827 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2828 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2831 } 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') {
2832 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2839 '@phan-var-force CommonObjectLine[] $lines';
2841 if (
isModEnabled(
'productbatch') && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) &&
getDolGlobalString(
'INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS')) {
2842 $langs->load(
'productbatch');
2843 foreach ($lines[$i]->detail_batch as $batchline) {
2844 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2849 $situation_percent = (GETPOSTISSET(
'progress') ?
GETPOSTINT(
'progress') : 100);
2851 $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);
2856 $outputlangs = $langs;
2859 $newlang =
GETPOST(
'lang_id',
'aZ09');
2862 $newlang =
$object->thirdparty->default_lang;
2864 if (!empty($newlang)) {
2865 $outputlangs =
new Translate(
"", $conf);
2866 $outputlangs->setDefaultLang($newlang);
2867 $outputlangs->load(
'products');
2872 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2878 unset($_POST[
'prod_entry_mode']);
2879 unset($_POST[
'qty']);
2880 unset($_POST[
'type']);
2881 unset($_POST[
'remise_percent']);
2882 unset($_POST[
'price_ht']);
2883 unset($_POST[
'multicurrency_price_ht']);
2884 unset($_POST[
'price_ttc']);
2885 unset($_POST[
'tva_tx']);
2886 unset($_POST[
'product_ref']);
2887 unset($_POST[
'product_label']);
2888 unset($_POST[
'product_desc']);
2889 unset($_POST[
'fournprice']);
2890 unset($_POST[
'buying_price']);
2891 unset($_POST[
'np_marginRate']);
2892 unset($_POST[
'np_markRate']);
2893 unset($_POST[
'dp_desc']);
2894 unset($_POST[
'idprod']);
2895 unset($_POST[
'units']);
2896 unset($_POST[
'date_starthour']);
2897 unset($_POST[
'date_startmin']);
2898 unset($_POST[
'date_startsec']);
2899 unset($_POST[
'date_startday']);
2900 unset($_POST[
'date_startmonth']);
2901 unset($_POST[
'date_startyear']);
2902 unset($_POST[
'date_endhour']);
2903 unset($_POST[
'date_endmin']);
2904 unset($_POST[
'date_endsec']);
2905 unset($_POST[
'date_endday']);
2906 unset($_POST[
'date_endmonth']);
2907 unset($_POST[
'date_endyear']);
2908 unset($_POST[
'situations']);
2909 unset($_POST[
'progress']);
2917 } elseif ($action ==
'addline' && $usercancreate && (
2918 (
GETPOST(
'submitforallmargins',
'alpha') &&
GETPOST(
'marginforalllines',
'alpha') !==
'') ||
2919 (
GETPOST(
'submitforallmark',
'alpha') &&
GETPOST(
'markforalllines',
'alpha') !==
''))) {
2921 $margin_rate = GETPOSTISSET(
'marginforalllines') ?
GETPOST(
'marginforalllines',
'int') :
'';
2922 $mark_rate = GETPOSTISSET(
'markforalllines') ?
GETPOST(
'markforalllines',
'int') :
'';
2923 foreach (
$object->lines as &$line)
if ($line->subprice > 0) {
2924 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2927 $subprice_multicurrency = $line->subprice;
2928 if (is_numeric($margin_rate) && $margin_rate > 0) {
2929 $line->subprice = (float)
price2num((
float) $line->pa_ht * (1 + (float) $margin_rate / 100),
'MU');
2930 } elseif (is_numeric($mark_rate) && $mark_rate > 0) {
2931 $line->subprice = (float) ($line->pa_ht / (1 - ((
float) $mark_rate / 100)));
2933 $line->subprice = (float) $line->pa_ht;
2937 $res = $prod->fetch($line->fk_product);
2939 if ($prod->price_min > $line->subprice) {
2940 $price_subprice =
price($line->subprice, 0, $outlangs, 1, -1, -1,
'auto');
2941 $price_price_min =
price($prod->price_min, 0, $outlangs, 1, -1, -1,
'auto');
2942 setEventMessages($prod->ref .
' - ' . $prod->label .
' (' . $price_subprice .
' < ' . $price_price_min .
' ' . strtolower($langs->trans(
"MinPrice")) .
')' .
"\n",
null,
'warnings');
2950 $multicurrency_subprice = (float) $line->subprice * $line->multicurrency_subprice / $subprice_multicurrency;
2952 $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);
2955 if (is_numeric($margin_rate) && empty($mark_rate)) {
2956 $line->marge_tx = $margin_rate;
2957 } elseif (is_numeric($mark_rate) && empty($margin_rate)) {
2958 $line->marque_tx = $mark_rate;
2960 $line->total_ht = $line->qty * (float) $line->subprice;
2961 $line->total_tva = $line->tva_tx * $line->qty * (float) $line->subprice;
2962 $line->total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $line->subprice;
2964 $line->multicurrency_total_ht = $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
2965 $line->multicurrency_total_tva = $line->tva_tx * $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
2966 $line->multicurrency_total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
2968 $line->multicurrency_subprice = $multicurrency_subprice;
2973 } elseif ($action ==
'updatetitleline' && GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2976 $langs->load(
'subtotals');
2978 $desc =
GETPOST(
'line_desc',
'alphanohtml') ?? $langs->trans(
"Title");
2981 $subtotal_options = array();
2983 foreach (Facture::$TITLE_OPTIONS as $option) {
2984 $value =
GETPOST($option,
'alphanohtml');
2986 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2991 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3002 $outputlangs = $langs;
3003 $newlang =
GETPOST(
'lang_id',
'alpha');
3005 $newlang =
$object->thirdparty->default_lang;
3007 if (!empty($newlang)) {
3008 $outputlangs =
new Translate(
"", $conf);
3009 $outputlangs->setDefaultLang($newlang);
3012 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3017 } elseif ($action ==
'updatesubtotalline' && GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3020 $langs->load(
'subtotals');
3022 $desc =
GETPOST(
'line_desc',
'alphanohtml');
3025 $subtotal_options = array();
3027 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
3028 $value =
GETPOST($option,
'alphanohtml');
3030 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
3035 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3043 $outputlangs = $langs;
3044 $newlang =
GETPOST(
'lang_id',
'alpha');
3046 $newlang =
$object->thirdparty->default_lang;
3048 if (!empty($newlang)) {
3049 $outputlangs =
new Translate(
"", $conf);
3050 $outputlangs->setDefaultLang($newlang);
3053 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3058 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3059 if (!
$object->fetch($id) > 0) {
3082 if (preg_match(
'/\*/', $vat_rate)) {
3087 $vat_rate = str_replace(
'*',
'', $vat_rate);
3092 $fournprice = (int) (
GETPOST(
'fournprice') ?
GETPOST(
'fournprice') :
'');
3096 $pu_equivalent = $pu_ht;
3097 $pu_equivalent_ttc = $pu_ttc;
3099 $currency_tx =
$object->multicurrency_tx;
3103 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3104 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
3106 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3107 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
3122 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
3123 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
3125 if (is_array($extralabelsline)) {
3127 foreach ($extralabelsline as $key => $value) {
3128 unset($_POST[
"options_".$key]);
3134 if ($special_code == 3) {
3140 $percent = $line->get_prev_progress(
$object->id);
3145 if ($progress >= 0) {
3146 $mesg = $langs->trans(
"CantBeNullOrPositive");
3150 } elseif ($progress < $line->situation_percent) {
3151 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
3155 } elseif ($progress < $percent) {
3156 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
3164 if (empty($remise_percent)) {
3165 $remise_percent = 0;
3168 $price_base_type =
'HT';
3170 if (empty($pu) && !empty($pu_ttc)) {
3172 $price_base_type =
'TTC';
3177 if (!empty($productid)) {
3179 $product->fetch($productid);
3181 $type = $product->type;
3183 $price_min = $product->price_min;
3185 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
3187 $price_min_ttc = $product->price_min_ttc;
3189 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
3196 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
3197 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
3200 $action =
'editline';
3201 } 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') {
3202 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
3205 $action =
'editline';
3210 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
3214 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
3219 $langs->load(
"errors");
3220 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
3224 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
3225 $langs->load(
"errors");
3226 if (
$object->type == $object::TYPE_DEPOSIT) {
3228 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
3230 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
3234 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
3241 $previousprogress = $line->getAllPrevProgress($line->fk_facture);
3244 if ($fullprogress < $previousprogress) {
3246 setEventMessages($langs->trans(
'CantBeLessThanMinPercent'),
null,
'errors');
3250 if ($fullprogress > 100) {
3251 $fullprogress = 100;
3253 $addprogress = $fullprogress - $previousprogress;
3260 if (empty($usercancreatemargin)) {
3261 foreach (
$object->lines as &$line) {
3263 $fournprice = $line->fk_fournprice;
3264 $buyingprice = $line->pa_ht;
3270 $result =
$object->updateline(
3275 (
float) $remise_percent,
3293 (
float) $pu_ht_devise
3299 $outputlangs = $langs;
3302 $newlang =
GETPOST(
'lang_id',
'aZ09');
3305 $newlang =
$object->thirdparty->default_lang;
3307 if (!empty($newlang)) {
3308 $outputlangs =
new Translate(
"", $conf);
3309 $outputlangs->setDefaultLang($newlang);
3310 $outputlangs->load(
'products');
3314 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3317 unset($_POST[
'qty']);
3318 unset($_POST[
'type']);
3319 unset($_POST[
'productid']);
3320 unset($_POST[
'remise_percent']);
3321 unset($_POST[
'price_ht']);
3322 unset($_POST[
'multicurrency_price_ht']);
3323 unset($_POST[
'price_ttc']);
3324 unset($_POST[
'tva_tx']);
3325 unset($_POST[
'product_ref']);
3326 unset($_POST[
'product_label']);
3327 unset($_POST[
'product_desc']);
3328 unset($_POST[
'fournprice']);
3329 unset($_POST[
'buying_price']);
3330 unset($_POST[
'np_marginRate']);
3331 unset($_POST[
'np_markRate']);
3332 unset($_POST[
'dp_desc']);
3333 unset($_POST[
'idprod']);
3334 unset($_POST[
'units']);
3335 unset($_POST[
'date_starthour']);
3336 unset($_POST[
'date_startmin']);
3337 unset($_POST[
'date_startsec']);
3338 unset($_POST[
'date_startday']);
3339 unset($_POST[
'date_startmonth']);
3340 unset($_POST[
'date_startyear']);
3341 unset($_POST[
'date_endhour']);
3342 unset($_POST[
'date_endmin']);
3343 unset($_POST[
'date_endsec']);
3344 unset($_POST[
'date_endday']);
3345 unset($_POST[
'date_endmonth']);
3346 unset($_POST[
'date_endyear']);
3347 unset($_POST[
'situations']);
3348 unset($_POST[
'progress']);
3353 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modify')) {
3354 if (!
$object->fetch($id) > 0) {
3357 if (
GETPOST(
'all_progress') !=
"") {
3359 foreach (
$object->lines as $line) {
3361 $percent = $line->getAllPrevProgress(
$object->id);
3363 $percent = $line->get_prev_progress(
$object->id);
3365 if (
$object->type != $object::TYPE_CREDIT_NOTE && (
float) $all_progress < (
float) $percent) {
3366 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
3369 } elseif (
$object->type == $object::TYPE_CREDIT_NOTE && (
float) $all_progress > (
float) $percent) {
3370 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeMoreThanMinPercent");
3379 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
3380 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
3382 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
3384 $object->fetch($id,
'',
'', 0,
true);
3387 &&
$object->isSituationInvoice()
3390 &&
$object->is_last_in_cycle()
3391 && $usercanunvalidate
3394 $newCycle =
$object->newCycle();
3395 if ($newCycle > 1) {
3397 $lastCycle =
$object->situation_cycle_ref;
3398 $lastSituationCounter =
$object->situation_counter;
3399 $linkedCreditNotesList = array();
3401 if (count(
$object->tab_next_situation_invoice) > 0) {
3402 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
3404 && $next_invoice->situation_counter ==
$object->situation_counter
3405 && $next_invoice->fk_facture_source ==
$object->id
3407 $linkedCreditNotesList[] = $next_invoice->id;
3412 $object->situation_cycle_ref = $newCycle;
3413 $object->situation_counter = 1;
3415 if (
$object->update($user) > 0) {
3417 if (count($linkedCreditNotesList) > 0) {
3419 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
3420 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
3421 $sql .=
' , situation_final=0';
3422 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
3423 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
3425 $resql = $db->query($sql);
3431 foreach (
$object->lines as $line) {
3433 if ($line->product_type == 9) {
3438 if (!empty(
$object->tab_previous_situation_invoice)) {
3440 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
3441 $searchPreviousInvoice =
true;
3442 while ($searchPreviousInvoice) {
3443 if (
$object->tab_previous_situation_invoice[$lineIndex]->isSituationInvoice() || $lineIndex < 1) {
3444 $searchPreviousInvoice =
false;
3452 $maxPrevSituationPercent = 0;
3453 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
3454 if ($prevLine->id == $line->fk_prev_id) {
3455 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
3460 $line->situation_percent -= $maxPrevSituationPercent;
3462 if ($line->update() < 0) {
3471 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
3473 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
3476 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
3479 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
3485 $fromElement =
GETPOST(
'fromelement');
3486 $fromElementid =
GETPOST(
'fromelementid');
3487 $importLines =
GETPOST(
'line_checkbox');
3489 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
3490 $lineClassName =
'';
3491 if ($fromElement ==
'commande') {
3493 $lineClassName =
'OrderLine';
3494 } elseif ($fromElement ==
'propal') {
3495 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
3496 $lineClassName =
'PropaleLigne';
3498 $nextRang = count(
$object->lines) + 1;
3501 foreach ($importLines as $lineId) {
3502 if ($lineClassName ===
'') {
3506 dol_syslog(
'compta/facture/card - No lineClassName - skip import', LOG_ERR);
3513 $lineId = intval($lineId);
3514 $originLine =
new $lineClassName($db);
3515 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
3516 $originLine->fetch_optionals();
3517 $desc = $originLine->desc;
3518 $pu_ht = $originLine->subprice;
3519 $qty = $originLine->qty;
3520 $txtva = $originLine->tva_tx;
3521 $txlocaltax1 = $originLine->localtax1_tx;
3522 $txlocaltax2 = $originLine->localtax2_tx;
3523 $fk_product = $originLine->fk_product;
3524 $remise_percent = $originLine->remise_percent;
3525 $date_start = $originLine->date_start;
3526 $date_end = $originLine->date_end;
3527 $fk_code_ventilation = 0;
3528 $info_bits = $originLine->info_bits;
3529 $fk_remise_except = $originLine->fk_remise_except;
3530 $price_base_type =
'HT';
3532 $type = $originLine->product_type;
3533 $rang = $nextRang++;
3534 $special_code = $originLine->special_code;
3535 $origin = $originLine->element;
3536 $origin_id = $originLine->id;
3537 $fk_parent_line = 0;
3538 $fk_fournprice = $originLine->fk_fournprice;
3539 $pa_ht = $originLine->pa_ht;
3540 $label = $originLine->label;
3541 $array_options = $originLine->array_options;
3542 if (
$object->isSituationInvoice()) {
3543 $situation_percent = 0;
3545 $situation_percent = 100;
3548 $fk_unit = $originLine->fk_unit;
3549 $pu_ht_devise = $originLine->multicurrency_subprice;
3551 $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);
3571 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3577 if (!empty(
$object->id) && $action ==
'send') {
3579 $object->getSommePaiement(-1);
3580 $object->getSumCreditNotesUsed(-1);
3581 $object->getSumDepositsUsed(-1);
3583 $triggersendname =
'BILL_SENTBYMAIL';
3585 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3586 $trackid =
'inv'.$object->id;
3587 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3590 $upload_dir = $conf->invoice->multidir_output[!empty(
$object->entity) ?
$object->entity : $conf->entity];
3591 $permissiontoadd = $usercancreate;
3592 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3595 if ($action ==
'update_extras' && $permissiontoeditextra) {
3598 $attribute_name =
GETPOST(
'attribute',
'aZ09');
3601 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
3608 $result =
$object->updateExtraField($attribute_name,
'BILL_MODIFY');
3616 $action =
'edit_extras';
3621 if ($action ==
'addcontact' && $usercancreate) {
3622 $result =
$object->fetch($id);
3624 if ($result > 0 && $id > 0) {
3627 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3631 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3634 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3635 $langs->load(
"errors");
3636 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3641 } elseif ($action ==
'swapstatut' && $usercancreate) {
3648 } elseif ($action ==
'deletecontact' && $usercancreate) {
3651 $result =
$object->delete_contact($lineid);
3654 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3662 $action =
'edit_extras';
3672$form =
new Form($db);
3678$bankaccountstatic =
new Account($db);
3686$title =
$object->ref.
" - ".$langs->trans(
'Card');
3687if ($action ==
'create') {
3688 $title = $langs->trans(
"NewBill");
3690$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3696if ($action ==
'create') {
3697 $facturestatic =
new Facture($db);
3698 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3703 $res = $soc->fetch($socid);
3706 $currency_code = $conf->currency;
3708 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3709 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3713 if (empty($dateinvoice)) {
3720 if (!empty($origin) && !empty($originid)) {
3722 $element = $subelement = $origin;
3724 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3725 $element = $regs[1];
3726 $subelement = $regs[2];
3731 if ($element ==
'project') {
3732 $projectid = $originid;
3734 if (empty($cond_reglement_id)) {
3735 $cond_reglement_id = $soc->cond_reglement_id;
3737 if (empty($mode_reglement_id)) {
3738 $mode_reglement_id = $soc->mode_reglement_id;
3740 if (empty($fk_account)) {
3741 $fk_account = $soc->fk_account;
3745 if ($element ==
'order' || $element ==
'commande') {
3746 $element = $subelement =
'commande';
3748 if ($element ==
'propal') {
3749 $element =
'comm/propal';
3750 $subelement =
'propal';
3752 if ($element ==
'contract') {
3753 $element = $subelement =
'contrat';
3755 if ($element ==
'shipping') {
3756 $element = $subelement =
'expedition';
3761 $classname = ucfirst($subelement);
3762 $objectsrc =
new $classname($db);
3763 '@phan-var-force Commande|Propal|Contrat|Expedition $objectsrc';
3765 $objectsrc->fetch($originid);
3766 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3767 $objectsrc->fetch_lines();
3769 $objectsrc->fetch_thirdparty();
3771 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3777 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3781 if (empty($socid)) {
3782 $soc = $objectsrc->thirdparty;
3785 if ($element ==
'expedition') {
3786 $elem = $subelem = $objectsrc->origin_type;
3787 $expeoriginid = $objectsrc->origin_id;
3789 $classname = ucfirst($subelem);
3791 $expesrc =
new $classname($db);
3792 '@phan-var-force Expedition $expesrc';
3794 dol_syslog(
"Is type Facture|Commande or Expedition: $element...expesrc($classname)=".get_class($expesrc));
3795 $expesrc->fetch($expeoriginid);
3797 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3798 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3799 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3802 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3803 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3807 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3810 $expesrc->fetch_optionals();
3811 $object->array_options = $expesrc->array_options;
3813 $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)));
3814 $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)));
3815 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : (!empty($fk_account) ? $fk_account : 0)));
3818 if (!empty($objectsrc->multicurrency_code)) {
3819 $currency_code = $objectsrc->multicurrency_code;
3821 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
3822 $currency_tx = $objectsrc->multicurrency_tx;
3827 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3830 $objectsrc->fetch_optionals();
3831 $object->array_options = $objectsrc->array_options;
3835 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
3836 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
3837 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
3838 $inputReasonId = empty($soc->demand_reason_id) ? $inputReasonId : $soc->demand_reason_id;
3840 if (
isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3841 $currency_code = $soc->multicurrency_code;
3846 if (!
GETPOST(
'changecompany')) {
3847 if (GETPOSTISSET(
'cond_reglement_id')) {
3848 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3850 if (GETPOSTISSET(
'mode_reglement_id')) {
3851 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3853 if (GETPOSTISSET(
'cond_reglement_id')) {
3859 if (empty($cond_reglement_id)) {
3860 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
3864 if (empty($mode_reglement_id)) {
3865 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
3875 if (!empty($soc->id)) {
3876 $absolute_discount = $soc->getAvailableDiscounts();
3878 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
3879 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
3881 if (!empty($conf->use_javascript_ajax)) {
3882 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3888 if ($origin ==
'contrat') {
3889 $langs->load(
"admin");
3890 $text = $langs->trans(
"ToCreateARecurringInvoice");
3891 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3893 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3895 print
info_admin($text, 0, 0,
'info',
'').
'<br>';
3898 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3899 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3900 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3901 print
'<input type="hidden" name="changecompany" value="0">';
3903 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3905 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3906 print
'<input name="ref" type="hidden" value="provisoire">';
3907 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3908 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3909 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3910 print
'<input name="force_fk_account" type="hidden" value="0">';
3911 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3912 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3913 print
'<input type="hidden" name="originentity" value="'.GETPOSTINT(
'originentity').
'">';
3914 if (!empty($currency_tx)) {
3915 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3921 $parameters = array();
3923 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters, $object, $action);
3924 if (empty($reshook)) {
3925 print
'<table class="border centpercent">';
3927 $exampletemplateinvoice =
new FactureRec($db);
3929 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3930 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
3934 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
'Ref').
'</td>';
3935 print
'<td colspan="2">';
3936 print $langs->trans(
"Draft");
3941 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
3943 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
'Customer').
'</td>';
3944 print
'<td colspan="2">';
3945 print $soc->getNomUrl(1,
'customer');
3946 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3948 $arrayoutstandingbills = $soc->getOutstandingBills();
3949 $outstandingBills = $arrayoutstandingbills[
'opened'];
3950 print
' - <span class="opacitymedium valignmiddle">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3951 print
'<span class="amount valignmiddle">'.price($outstandingBills, 0, $langs, 0, 0, -1, $conf->currency).
'</span>';
3952 if ($soc->outstanding_limit !=
'') {
3953 if ($outstandingBills > $soc->outstanding_limit) {
3954 print
img_warning($langs->trans(
"OutstandingBillReached"));
3956 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1, $conf->currency);
3961 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3962 print
'<td colspan="2">';
3963 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
3964 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3968 $(document).ready(function() {
3969 $("#socid").change(function() {
3971 console.log("Submit page");
3972 $(\'input[name="action"]\').val(\'create\');
3973 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3974 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3975 $(\'input[name="force_fk_account"]\').val(\'1\');
3976 $("#formtocreate").submit(); */
3978 // For company change, we must submit page with action=create instead of action=add
3979 console.log("We have changed the company - Resubmit page");
3980 jQuery("input[name=changecompany]").val("1");
3981 jQuery("#formtocreateaction").val("create");
3982 jQuery("#formtocreate").submit();
3988 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>';
3995 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3997 foreach ($invoice_predefined->array_options as $key => $option) {
3998 if (!isset(
$object->array_options[$key])) {
3999 $object->array_options[$key] = $invoice_predefined->array_options[$key];
4003 $dateinvoice = $invoice_predefined->date_when;
4004 if (empty($projectid)) {
4005 $projectid = $invoice_predefined->fk_project;
4007 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
4008 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
4009 $fk_account = $invoice_predefined->fk_account;
4010 $note_public = $invoice_predefined->note_public;
4011 $note_private = $invoice_predefined->note_private;
4013 if (!empty($invoice_predefined->multicurrency_code)) {
4014 $currency_code = $invoice_predefined->multicurrency_code;
4016 if (!empty($invoice_predefined->multicurrency_tx)) {
4017 $currency_tx = $invoice_predefined->multicurrency_tx;
4020 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
4021 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
4022 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
4024 $resql = $db->query($sql);
4026 $num = $db->num_rows($resql);
4030 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
4032 print
'<select class="flat" id="fac_rec" name="fac_rec">';
4033 print
'<option value="0" selected></option>';
4035 $objp = $db->fetch_object($resql);
4036 print
'<option value="'.$objp->rowid.
'"';
4039 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
4041 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
4050 print
'<script type="text/javascript">
4051 $(document).ready(function() {
4052 $("#fac_rec").change(function() {
4053 console.log("We have changed the template invoice - Reload page");
4054 var fac_rec = $(this).val();
4055 var socid = $(\'#socid\').val();
4056 // 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.
4057 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
4070 print
'<tr><td class="tdtop fieldrequired titlefieldcreate">'.$langs->trans(
'Type').
'</td><td colspan="2">';
4071 print
'<div class="listofinvoicetypetable">'.
"\n";
4074 print
'<div class="listofinvoicetype"><div class="">';
4075 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
4076 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
4078 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'nowraponall', 0, 3,
'standardonsmartphone');
4080 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
4090 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%') .
'"/>';
4093 print
'</div></div>'.
"\n";
4095 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
4098 print
'<div class="listofinvoicetype"><div class="">';
4099 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
4100 print
'<script type="text/javascript">
4101 jQuery(document).ready(function() {
4102 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
4103 jQuery("#radio_standard").prop("checked", true);
4105 jQuery("#typedeposit, #valuedeposit").click(function() {
4106 jQuery("#radio_deposit").prop("checked", true);
4108 jQuery("#typedeposit").change(function() {
4109 console.log("We change type of down payment: "+jQuery("#typedeposit").val());
4111 if (jQuery("#typedeposit").val() == "amount") {
4112 jQuery("#valuedeposit").attr("placeholder", "'.$langs->getCurrencySymbol($conf->currency).
'");
4113 jQuery("#valuedeposit").val("");
4115 jQuery("#valuedeposit").attr("placeholder", "50%");
4116 jQuery("#valuedeposit").val("");
4119 jQuery("#radio_deposit").prop("checked", true);
4120 setRadioForTypeOfInvoice();
4122 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
4123 setRadioForTypeOfInvoice();
4126 function setRadioForTypeOfInvoice() {
4127 console.log("Change radio for type of invoice");
4128 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
4129 jQuery("#checkforselects").prop("disabled", true);
4130 jQuery("#checkforselects").prop("checked", false);
4131 jQuery(".checkforselect").prop("disabled", true);
4132 jQuery(".checkforselect").prop("checked", false);
4134 jQuery("#checkforselects").prop("disabled", false);
4135 jQuery("#checkforselects").prop("checked", true);
4136 jQuery(".checkforselect").prop("disabled", false);
4137 jQuery(".checkforselect").prop("checked", true);
4143 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
4145 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
4147 if (($origin ==
'propal') || ($origin ==
'commande')) {
4150 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
4151 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
4152 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4156 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4160 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
4162 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
4163 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
4164 if (!empty($origin_payment_conditions_deposit_percent)) {
4165 $typedeposit =
'variable';
4168 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
4169 $valuedeposit = $objectsrc->deposit_percent;
4171 print
'<span class="marginleftonly">'.$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1).
'</span>';
4173 print
'<input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.($valuedeposit ? $valuedeposit :
'').
'"'.($valuedeposit ?
'' :
'placeholder="'.$langs->getCurrencySymbol($conf->currency).
'"').
'>';
4176 print
'</div></div>'.
"\n";
4183 print
'<div class="listofinvoicetype"><div class="">';
4184 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
4185 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
4187 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
4191 $opt = $form->selectSituationInvoices((
string)
GETPOSTINT(
'originid'), $socid);
4194 print
'</div></div><div class="listofinvoicetype"><div>';
4196 $tmp =
'<input id="radio_situation_bis" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
4197 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4198 $tmp .=
' disabled';
4201 $text = $tmp.
'<label for="radio_situation_bis">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4203 $text .=
'<select class="flat minwidth125" id="situations" name="situations"';
4204 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4205 $text .=
' disabled';
4209 $text .=
'</select>';
4210 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
4212 print
'</div></div>'.
"\n";
4218 $facids = $facturestatic->list_replacable_invoices($soc->id);
4224 if (is_array($facids)) {
4225 foreach ($facids as $facparam) {
4226 $options .=
'<option value="'.$facparam [
'id'].
'"';
4227 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
4228 $options .=
' selected';
4230 $options .=
'>'.$facparam[
'ref'];
4231 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
4232 $options .=
'</option>';
4236 print
'<!-- replacement line -->';
4237 print
'<div class="listofinvoicetype"><div class="">';
4238 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
4239 if (!$options || $invoice_predefined->id > 0) {
4240 $tmp .=
' disabled';
4243 print
'<script type="text/javascript">
4244 jQuery(document).ready(function() {
4245 jQuery("#fac_replacement").change(function() {
4246 console.log("We change fac_replacement");
4247 jQuery("#radio_replacement").prop("checked", true);
4251 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
4252 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
4253 if (!$options || $invoice_predefined->id > 0) {
4254 $text .=
' disabled';
4258 $text .=
'<option value="-1"> </option>';
4261 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
4263 $text .=
'</select>';
4264 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
4266 print
'</div></div>'.
"\n";
4270 print
'<div class="listofinvoicetype"><div class="">';
4271 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
4272 $text = $tmp.
'<label class="opacitymedium">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4273 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'firstsituationonsmartphone');
4275 print
'</div></div>'.
"\n";
4278 print
'<div class="listofinvoicetype"><div class="">';
4279 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
4280 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
4281 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'replacementonsmartphone');
4283 print
'</div></div>'.
"\n";
4286 if (empty($origin)) {
4291 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
4297 $newinvoice_static =
new Facture($db);
4298 foreach ($facids as $key => $valarray) {
4299 $newinvoice_static->id = $key;
4300 $newinvoice_static->ref = $valarray [
'ref'];
4301 $newinvoice_static->statut = $valarray [
'status'];
4302 $newinvoice_static->status = $valarray [
'status'];
4303 $newinvoice_static->type = $valarray [
'type'];
4304 $newinvoice_static->paye = $valarray [
'paye'];
4305 $newinvoice_static->paid = $valarray [
'paye'];
4307 $optionsav .=
'<option value="'.$key.
'"';
4308 if ($key ==
GETPOST(
'fac_avoir')) {
4309 $optionsav .=
' selected';
4312 $newinvoice_static->fetch_optionals($key);
4313 $object->array_options = $newinvoice_static->array_options;
4316 $optionsav .= $newinvoice_static->ref;
4317 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
4318 $optionsav .=
'</option>';
4321 print
'<div class="listofinvoicetype"><div class="">';
4322 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
4323 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
4324 $tmp .=
' disabled';
4328 print
'<script type="text/javascript">
4329 jQuery(document).ready(function() {
4330 if (jQuery("#radio_creditnote").is(":checked"))
4332 jQuery("#radio_standard").prop("disabled", true);
4334 jQuery("#radio_standard").prop("disabled", false);
4336 if (! jQuery("#radio_creditnote").is(":checked"))
4338 jQuery("#credit_note_options").hide();
4340 jQuery("#radio_creditnote").click(function() {
4342 jQuery("#credit_note_options").show();
4344 jQuery("#radio_standard, #radio_replacement, #radio_deposit, #radio_situation, #radio_situation_bis").click(function() {
4345 console.log("We click on a radio to close credit not options");
4346 jQuery("#credit_note_options").hide();
4350 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
4351 $text .=
'<select class="flat valignmiddle minwidth200" name="fac_avoir" id="fac_avoir"';
4352 if (!$optionsav || $invoice_predefined->id > 0) {
4353 $text .=
' disabled';
4357 $text .=
'<option value="-1">'.$langs->trans(
"InvoiceAvoirAskCombo").
'</option>';
4358 $text .= $optionsav;
4360 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
4362 $text .=
'</select>';
4363 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
4366 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
4367 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>";
4368 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>";
4373 print
'</div></div>'.
"\n";
4376 print
'<div class="listofinvoicetype"><div class="">';
4378 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
4380 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
4382 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
4384 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
4386 print
'</div></div>'.
"\n";
4391 print
'<div class="listofinvoicetype"><div class="">';
4392 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
4393 $text = $tmp.
'<label class="opacitymedium" for="radio_template">'.$langs->trans(
"RepeatableInvoice").
'</label> ';
4394 $desc = $form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3,
'templateonsmartphone');
4396 print
'</div></div>'.
"\n";
4405 foreach ($listtType as $type) {
4406 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
4408 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
4411 print
'<script type="text/javascript">
4412 $(document).ready(function() {
4413 var listType = {'.$jsListType.
'};
4414 $("[name=\'type\'").change(function() {
4415 console.log("change name=type");
4416 if ($( this ).prop("checked"))
4418 if(($( this ).val() in listType))
4420 $("#model").val(listType[$( this ).val()]);
4437 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
4438 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
4444 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
4448 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
4451 $defaulttpldir =
'/core/tpl';
4452 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
4453 foreach ($dirtpls as $module => $reldir) {
4455 if (!empty($module)) {
4458 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
4460 if (file_exists($tpl)) {
4461 if (empty($conf->file->strict_mode)) {
4462 $res = @include $tpl;
4464 $res = include $tpl;
4467 if ($res) {
break; }
4477 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
4478 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4479 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
4484 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
4485 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4486 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
4491 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
4492 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
4493 print $form->getSelectConditionsPaiements((
int) $cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
4498 $rwStyle =
'display:none;';
4499 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
4503 $retained_warranty =
GETPOSTINT(
'retained_warranty');
4504 if (empty($retained_warranty)) {
4505 if ($objectsrc !==
null && property_exists($objectsrc,
'retained_warranty') && !empty($objectsrc->retained_warranty)) {
4507 $retained_warranty = $objectsrc->retained_warranty;
4510 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
4512 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
4513 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
4516 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
4517 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
4518 if (empty($retained_warranty_fk_cond_reglement)) {
4519 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4520 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
4521 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
4523 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4526 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4529 print
'<script type="text/javascript">
4530 $(document).ready(function() {
4531 $("[name=\'type\']").change(function() {
4532 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
4534 $(".retained-warranty-line").show();
4535 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
4538 $(".retained-warranty-line").hide();
4539 $("#new-situation-invoice-retained-warranty").val("");
4543 $("[name=\'type\']:checked").trigger("change");
4549 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
4550 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
4551 print $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth250 widthcentpercentminusx', 1);
4556 print
'<tr><td>'.$langs->trans(
'DefaultBankAccount').
'</td><td colspan="2">';
4557 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4558 print $form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth250 widthcentpercentminusx', 1);
4564 print
'<tr><td>'.$langs->trans(
'Source').
'</td><td>';
4565 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
4566 $form->selectInputReason((
string) $inputReasonId,
'input_reason_id',
'', 1,
'maxwidth250 widthcentpercentminusx');
4569 print
'<input type="hidden" name="input_reason_id" value="'.((string) $inputReasonId).
'">';
4573 if (
isModEnabled(
'project') && is_object($formproject)) {
4574 $langs->load(
'projects');
4575 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
4576 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
4578 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');
4579 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>';
4586 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
4587 print
'<td colspan="2" class="maxwidthonsmartphone">';
4588 $incoterm_id =
GETPOST(
'incoterm_id');
4589 $location_incoterms =
GETPOST(
'location_incoterms');
4590 if (empty($incoterm_id)) {
4591 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
4592 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
4594 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
4595 print $form->select_incoterms($incoterm_id, $location_incoterms);
4609 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
4610 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
4615 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
4616 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
4617 print $hookmanager->resPrint;
4618 if (empty($reshook)) {
4619 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
4622 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
4623 if ($soc->fetch_optionals() > 0) {
4624 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
4628 print
$object->showOptionals($extrafields,
'create', $parameters);
4632 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
4633 print
'<td colspan="2">';
4634 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
4635 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
4640 $paramkey =
'FACTURE_ADDON_PDF_'.$type;
4645 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
4651 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
4652 print
'<td colspan="2" class="maxwidthonsmartphone">';
4653 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
4654 print $form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth200 widthcentpercentminusx');
4661 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
4662 if (empty($dateexample)) {
4665 $substitutionarray = array(
4666 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
4667 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
4668 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
4669 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
4670 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
4671 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
4672 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
4673 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
4674 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
4675 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
4676 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
4679 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
4680 foreach ($substitutionarray as $key => $val) {
4681 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
4683 $htmltext .=
'</i>';
4688 print
'<td class="tdtop">';
4689 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
4691 print
'<td valign="top" colspan="2">';
4692 $doleditor =
new DolEditor(
'note_public', (
string) $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
4693 print $doleditor->Create(1);
4696 if (empty($user->socid)) {
4698 print
'<td class="tdtop">';
4699 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4701 print
'<td valign="top" colspan="2">';
4702 $doleditor =
new DolEditor(
'note_private', (
string) $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4703 print $doleditor->Create(1);
4709 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4710 $langs->loadLangs(array(
'orders',
'propal'));
4713 if ($origin ==
'contrat') {
4714 '@phan-var-force Contrat $objectsrc';
4716 $objectsrc->update_price(1,
'auto', 1);
4719 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4720 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4721 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4722 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4727 switch (get_class($objectsrc)) {
4729 $newclassname =
'CommercialProposal';
4732 $newclassname =
'Order';
4735 $newclassname =
'Sending';
4738 $newclassname =
'Contract';
4741 $newclassname =
'Intervention';
4744 $newclassname = get_class($objectsrc);
4748 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4749 print
'<td colspan="2">';
4750 print $objectsrc->getNomUrl(1);
4752 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
4753 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4755 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4759 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht, 1, $langs, 1, -1,
'', $conf->currency).
'</td></tr>';
4760 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva, 1, $langs, 1, -1,
'', $conf->currency).
"</td></tr>";
4761 if (
$mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4762 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>";
4765 if (
$mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4766 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>";
4768 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc, 1, $langs, 1, -1,
'', $conf->currency).
"</td></tr>";
4770 if (
isModEnabled(
'multicurrency') && $objectsrc->multicurrency_code != $conf->currency) {
4772 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
'</td></tr>';
4773 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4774 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4782 print $form->buttonsSaveCancel(
"CreateDraft");
4785 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4788 $title = $langs->trans(
'ProductsAndServices');
4791 print
'<div class="div-table-responsive-no-min">';
4792 print
'<table class="noborder centpercent">';
4794 $objectsrc->printOriginLinesList(
'', $selectedLines);
4801} elseif ($id > 0 || !empty($ref)) {
4803 $langs->load(
'errors');
4804 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4813 if ($user->socid > 0 && $user->socid !=
$object->socid) {
4817 $result =
$object->fetch_thirdparty();
4819 $result = $soc->fetch(
$object->socid);
4823 $selleruserevenustamp =
$mysoc->useRevenueStamp();
4825 $totalpaid =
$object->getSommePaiement();
4826 $totalcreditnotes =
$object->getSumCreditNotesUsed();
4827 $totaldeposits =
$object->getSumDepositsUsed();
4833 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4837 $multicurrency_totalpaid =
$object->getSommePaiement(1);
4838 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
4839 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
4840 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4844 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code != $conf->currency) {
4845 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
4849 if (
$object->paye ||
$object->status == $object::STATUS_CLOSED) {
4852 $resteapayeraffiche = $resteapayer;
4855 $filterabsolutediscount =
"fk_facture_source IS NULL";
4856 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4858 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4859 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4862 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
4863 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
4864 $absolute_discount =
price2num($absolute_discount,
'MT');
4865 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4867 $nb_creditnote_notyetavailable = $soc->getOpenCreditNotesNotYetConvertedIntoDiscount(0);
4869 $author =
new User($db);
4870 if (
$object->user_creation_id) {
4871 $author->fetch(
$object->user_creation_id);
4874 $objectidnext =
$object->getIdReplacingInvoice();
4883 if ($action ==
'converttoreduc') {
4885 $type_fac =
'ExcessReceived';
4887 $type_fac =
'CreditNote';
4889 $type_fac =
'Deposit';
4893 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4894 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4895 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4899 if ($action ==
'delete') {
4900 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
4901 $formquestion = array();
4904 $qualified_for_stock_change = 0;
4906 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4908 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4911 if ($qualified_for_stock_change) {
4912 $langs->load(
"stocks");
4913 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4917 if ($conf->browser->name ==
'ie') {
4920 $formquestion = array(
4924 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4926 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4928 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4931 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4936 if ($action ==
'situationout') {
4937 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
4938 $label = $langs->trans(
"ConfirmOuting");
4939 $formquestion = array();
4944 &&
$object->is_last_in_cycle()
4945 && $usercanunvalidate
4947 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4952 if ($action ==
'valid') {
4954 $objectref = substr(
$object->ref, 1, 4);
4955 if ($objectref ==
'PROV') {
4959 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
4961 $numref =
$object->getNextNumRef($soc);
4964 $numref = (string)
$object->ref;
4967 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4969 $text .=
'<br><br>';
4970 $text .=
img_picto(
'',
'warning',
'class="pictofixedwidth"').
' '.$langs->trans(
'WarningInvoiceCanNeverBeEdited');
4973 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4974 $notify =
new Notify($db);
4976 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid, $object);
4978 $formquestion = array();
4981 $qualified_for_stock_change = 0;
4983 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4985 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4988 if ($qualified_for_stock_change) {
4989 $langs->load(
"stocks");
4990 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4991 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4994 $warehouse_array = $warehouse->list_array();
4995 if (count($warehouse_array) == 1) {
4996 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4997 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5000 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5002 $formquestion = array(
5008 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5012 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
5017 foreach (
$object->lines as $line) {
5018 $res = $line->fetch_product();
5020 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
5026 if ($nbMandated > 0) {
5028 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
5031 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
5036 $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);
5041 if ($action ==
'modif') {
5044 $testvalue =
$object->isEditable();
5045 if ($testvalue < 0) {
5046 switch ($testvalue) {
5049 setEventMessages($langs->trans(
"DisabledBecauseDispatchedInBookkeeping"),
null,
'errors');
5053 setEventMessages($langs->trans(
"DisabledBecauseNotLastInvoice"),
null,
'errors');
5057 setEventMessages($langs->trans(
"DisabledBecauseNotLastSituationInvoice"),
null,
'errors');
5061 setEventMessages($langs->trans(
"DisabledBecauseThereIsAPayment"),
null,
'errors');
5065 setEventMessages($langs->trans(
"DisabledBecauseAlreadySentByEmail"),
null,
'errors');
5069 setEventMessages($langs->trans(
"DisabledBecauseAlreadyPrintedOnce"),
null,
'errors');
5085 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
5086 $formquestion = array();
5089 $qualified_for_stock_change = 0;
5091 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5093 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5096 if ($qualified_for_stock_change) {
5097 $langs->load(
"stocks");
5098 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5099 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
5102 $warehouse_array = $warehouse->list_array();
5103 if (count($warehouse_array) == 1) {
5104 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
5105 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5108 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5110 $formquestion = array(
5116 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5120 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
5125 if ($action ==
'canceled') {
5129 $statusreplacement = 0;
5131 if ($objectidnext) {
5132 $facturereplacement =
new Facture($db);
5133 $facturereplacement->fetch($objectidnext);
5134 $statusreplacement = $facturereplacement->status;
5136 if ($objectidnext && $statusreplacement == 0) {
5137 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
5141 $close[1][
'code'] =
'badcustomer';
5142 $close[2][
'code'] =
'abandon';
5144 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5145 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
5147 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
5148 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
5151 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
5152 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
5155 $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'));
5157 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 300);
5162 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
5163 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
5165 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
5169 $close[$i][
'code'] = $object::CLOSECODE_DISCOUNTVAT;
5171 $close[$i][
'code'] = $object::CLOSECODE_BADDEBT;
5173 $close[$i][
'code'] = $object::CLOSECODE_BANKCHARGE;
5175 $close[$i][
'code'] = $object::CLOSECODE_WITHHOLDINGTAX;
5177 $close[$i][
'code'] = $object::CLOSECODE_OTHER;
5181 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
5183 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5185 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
5187 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
5189 $close[$i][
'label'] = $langs->trans(
"Other");
5193 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5195 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5197 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5199 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
5201 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
5205 foreach ($close as $key => $val) {
5206 $arrayreasons[$close[$key][
'code']] =
'<span class="small">'.$close[$key][
'reason'].
'</span>';
5210 $formquestion = array(
5211 'text' => $langs->trans(
"ConfirmClassifyPaidPartiallyQuestion"),
5212 0 => array(
'type' =>
'radio',
'name' =>
'close_code',
'label' =>
'',
'values' => $arrayreasons),
5213 1 => array(
'type' =>
'text',
'name' =>
'close_note',
'moreattr' =>
'placeholder = "'.$langs->trans(
"Comment").
'"',
'value' =>
'',
'morecss' =>
'minwidth300'),
5214 2 => array(
'type' =>
'separator')
5217 $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);
5220 if ($action ==
'deletepayment') {
5221 $payment_id =
GETPOST(
'paiement_id');
5222 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
5226 if ($action ==
'ask_deleteline') {
5227 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
5231 if ($action ==
'ask_subtotal_deleteline') {
5232 $langs->load(
"subtotals");
5233 $title =
"DeleteSubtotalLine";
5234 $question =
"ConfirmDeleteSubtotalLine";
5235 if (
GETPOST(
'type') ==
'title') {
5236 $formconfirm = array(array(
'type' =>
'checkbox',
'name' =>
'deletecorrespondingsubtotalline',
'label' => $langs->trans(
"DeleteCorrespondingSubtotalLine"),
'value' => 0));
5237 $title =
"DeleteTitleLine";
5238 $question =
"ConfirmDeleteTitleLine";
5240 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans($title), $langs->trans($question),
'confirm_delete_subtotalline', $formconfirm,
'no', 1);
5244 if ($action ==
'clone') {
5245 $filter =
'(s.client:IN:1,2,3)';
5247 $formquestion = array(
5248 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
$object->socid,
'socid', $filter, 1)),
5249 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
5252 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
5256 if ($action ==
'add_title_line') {
5257 $langs->load(
'subtotals');
5259 $depth_array =
$object->getPossibleLevels($langs);
5261 } elseif ($action ==
'add_subtotal_line') {
5262 $langs->load(
'subtotals');
5264 $titles =
$object->getPossibleTitles();
5268 if ($action ==
"remove_file_comfirm") {
5269 $file =
GETPOST(
'file',
'alpha');
5271 $formconfirm = $form->formconfirm(
5272 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
5273 $langs->trans(
'DeleteFileHeader'),
5274 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
5283 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
5284 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
5285 if (empty($reshook)) {
5286 $formconfirm .= $hookmanager->resPrint;
5287 } elseif ($reshook > 0) {
5288 $formconfirm = $hookmanager->resPrint;
5296 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
5298 $morehtmlref =
'<div class="refidno">';
5301 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5302 $morehtmlref .= $form->editfieldval(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'',
null,
null,
'', 1);
5303 $morehtmlref .=
'<br>';
5306 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5307 $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);
5309 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
5311 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'&search_societe='.urlencode(
$object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
5315 $langs->load(
"projects");
5316 $morehtmlref .=
'<br>';
5317 if ($usercancreate) {
5318 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
5319 if ($action !=
'classify') {
5320 $morehtmlref .=
'<a class="editfielda" href="'.dolBuildUrl($_SERVER[
'PHP_SELF'], [
'action' =>
'classify',
'id' =>
$object->id],
true).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
5322 $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');
5324 if (!empty(
$object->fk_project)) {
5326 $proj->fetch(
$object->fk_project);
5327 $morehtmlref .= $proj->getNomUrl(1);
5329 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
5334 $morehtmlref .=
'</div>';
5336 $object->totalpaid = $totalpaid;
5337 $object->totalcreditnotes = $totalcreditnotes;
5338 $object->totaldeposits = $totaldeposits;
5341 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
5344 $parameters = array();
5346 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters, $object, $action);
5347 if (empty($reshook)) {
5348 print
'<div class="fichecenter">';
5349 print
'<div class="fichehalfleft">';
5350 print
'<div class="underbanner clearboth"></div>';
5352 print
'<table class="border centpercent tableforfield">';
5355 print
'<tr><td class="fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
5358 print
' '.$object->getSubtypeLabel(
'facture');
5361 $facreplaced =
new Facture($db);
5362 $facreplaced->fetch(
$object->fk_facture_source);
5363 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
5367 $facusing->fetch(
$object->fk_facture_source);
5368 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
5372 $object->getListIdAvoirFromInvoice();
5374 if (!empty(
$object->creditnote_ids)) {
5375 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
5377 foreach (
$object->creditnote_ids as $invoiceid) {
5383 $creditnote =
new Facture($db);
5384 $creditnote->fetch($invoiceid);
5385 print $creditnote->getNomUrl(1,
'', 32);
5389 if ($objectidnext > 0) {
5390 $facthatreplace =
new Facture($db);
5391 $facthatreplace->fetch($objectidnext);
5392 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
5397 $result = $discount->fetch(0,
$object->id);
5399 print
' <span class="opacitymediumbycolor paddingleft">';
5400 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
5401 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
5402 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
5404 print
'</span><br>';
5408 if (
$object->fk_fac_rec_source > 0) {
5410 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
5412 print
' <span class="opacitymediumbycolor paddingleft">';
5413 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
5414 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
5418 print
' <span class="opacitymediumbycolor paddingleft">';
5419 print $langs->transnoentities(
"GeneratedFromTemplate", $langs->trans(
"ObjectDeleted"));
5427 $langs->load(
"cashdesk");
5428 print
'<tr><td class="fieldname_type">';
5429 print
'<table class="nobordernopadding centpercent"><tr><td>';
5430 print $form->textwithpicto($langs->trans(
'PointOfSale'), $langs->trans(
'POSInfo'));
5432 if ($action !=
'editposinfo' && $usercancreate) {
5433 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>';
5435 print
'</tr></table>';
5436 print
'</td><td class="valuefield fieldname_type">';
5437 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" name="formposinfo">';
5438 print
'<input type="hidden" name="action" value="setposinfo">';
5439 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5440 if ($action ==
'editposinfo') {
5441 print
'<input type="text" class="maxwidth150" name="posmodule" placeholder="'.$langs->trans(
"POSModule").
'" value="'.
$object->module_source.
'"> ';
5442 print
'<input type="text" class="maxwidth100" name="posterminal" placeholder="'.$langs->trans(
"Terminal").
'" value="'.
$object->pos_source.
'">';
5443 print
'<input type="submit" class="button" name="submitposinfo" value="'.$langs->trans(
"Submit").
'">';
5446 print
'<span class="opacitymediumbycolor paddingleft">'.dolPrintHTML(ucfirst(
$object->module_source).
' - '.$langs->transnoentitiesnoconv(
"Terminal").
' '.
$object->pos_source).
'</span>';
5454 print
'<!-- Discounts -->'.
"\n";
5455 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
5459 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
5460 $defaulttpldir =
'/core/tpl';
5462 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5463 foreach ($dirtpls as $module => $reldir) {
5465 if (!empty($module)) {
5468 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
5470 if (file_exists($tpl)) {
5471 if (empty($conf->file->strict_mode)) {
5472 $res = @include $tpl;
5474 $res = include $tpl;
5477 if ($res) {
break; }
5484 print
'<table class="nobordernopadding centpercent"><tr><td>';
5485 print $langs->trans(
'DateInvoice');
5487 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
5488 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>';
5490 print
'</tr></table>';
5492 if ($action ==
'editinvoicedate') {
5493 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
5495 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
5510 print
'<table class="nobordernopadding centpercent"><tr><td>';
5511 print $langs->trans(
'DatePointOfTax');
5514 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>';
5516 print
'</tr></table>';
5518 if ($action ==
'editdate_pointoftax' && $editable) {
5519 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
5521 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
5529 print $form->editfieldkey(
'Source',
'input_reason',
'', $object, (
int) $usercancreate);
5530 print
'</td><td class="valuefield">';
5531 if ($action ==
'editinput_reason') {
5532 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'input_reason_id', 1,
'maxwidth250 widthcentpercentminusx');
5534 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'none');
5541 print
'<table class="nobordernopadding centpercent"><tr><td>';
5542 print $langs->trans(
'PaymentConditionsShort');
5545 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>';
5547 print
'</tr></table>';
5550 if ($action ==
'editconditions') {
5551 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
5553 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
5560 print
'<table class="nobordernopadding centpercent"><tr><td>';
5561 print $langs->trans(
'DateMaxPayment');
5564 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>';
5566 print
'</tr></table>';
5569 if ($action ==
'editpaymentterm') {
5570 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
5572 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
5582 print
'<table class="nobordernopadding centpercent"><tr><td>';
5583 print $langs->trans(
'PaymentMode');
5585 if ($action !=
'editmode' && $usercancreate) {
5586 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>';
5588 print
'</tr></table>';
5590 if ($action ==
'editmode') {
5591 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
5593 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'none',
'CRDT');
5599 print
'<tr><td class="nowrap">';
5600 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
5601 print $langs->trans(
'DefaultBankAccount');
5603 if (($action !=
'editbankaccount') && $usercancreate) {
5604 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>';
5606 print
'</tr></table>';
5608 if ($action ==
'editbankaccount') {
5609 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
5611 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
5620 print
'<table class="nobordernopadding centpercent"><tr><td>';
5621 print $langs->trans(
'IncotermLabel');
5622 print
'<td><td class="right">';
5623 if ($usercancreate) {
5624 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
5626 print
'</td></tr></table>';
5629 if ($action !=
'editincoterm') {
5630 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
5632 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
5639 print
'<table class="nobordernopadding centpercent"><tr><td>';
5640 print $langs->trans(
'Dispute');
5641 print
'<td><td class="right">';
5642 if ($usercancreate) {
5643 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editdispute_status&token='.
newToken().
'">'.
img_edit().
'</a>';
5645 print
'</td></tr></table>';
5647 $liststatus = array(
'0' =>
"None",
'1' =>
"DisputeOpen",
'8' =>
"DisputeLost",
'9' =>
"DisputeWon");
5648 if ($action !=
'editdispute_status') {
5649 if (
$object->dispute_status) {
5650 print $langs->trans($liststatus[
$object->dispute_status]);
5653 print
'<form enctype="multipart/form-data" action="'.DOL_URL_ROOT.
'/compta/facture/card.php" method="POST">';
5654 print
'<input type="hidden" name="action" value="set_dispute_status">';
5655 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5656 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
5657 print
'<input type="hidden" name="page_y" value="">';
5658 print $form->selectarray(
'dispute_status', $liststatus,
$object->dispute_status, 0, 0, 0,
'', 1);
5659 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Save").
'">';
5667 print
'<table class="nobordernopadding centpercent"><tr><td>';
5668 print $langs->trans(
"Categories");
5669 print
'<td><td class="right">';
5670 if ($usercancreate) {
5671 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
5675 print
'</td></tr></table>';
5678 if ($action ==
'edittags') {
5679 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5680 print
'<input type="hidden" name="action" value="settags">';
5681 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5682 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
5683 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5686 print $form->showCategories(
$object->id, Categorie::TYPE_INVOICE, 1);
5691 $displayWarranty =
false;
5694 $displayWarranty =
true;
5695 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
5696 $displayWarranty =
false;
5699 if ($displayWarranty) {
5701 print
'<tr class="retained-warranty-lines" ><td>';
5702 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
5703 print $langs->trans(
'RetainedWarranty');
5706 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>';
5709 print
'</tr></table>';
5712 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5713 print
'<input type="hidden" name="action" value="setretainedwarranty">';
5714 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5715 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5716 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
5717 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5725 print
'<tr class="retained-warranty-lines" ><td>';
5726 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
5727 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
5729 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
5730 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>';
5733 print
'</tr></table>';
5735 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5736 if (
$object->date > $defaultDate) {
5742 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5743 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
5744 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5745 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5746 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
5747 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
5748 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
5749 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
5750 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5753 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->retained_warranty_fk_cond_reglement,
'none');
5754 if (!$displayWarranty) {
5755 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning',
'class="pictowarning valignmiddle" ');
5761 print
'<tr class="retained-warranty-lines" ><td>';
5762 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
5763 print $langs->trans(
'RetainedWarrantyDateLimit');
5766 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>';
5769 print
'</tr></table>';
5771 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5772 if (
$object->date > $defaultDate) {
5777 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5778 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
5779 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5780 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5782 print $form->selectDate($defaultDate,
'retained_warranty_date_limit');
5783 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5795 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
5800 print
'<div class="fichehalfright">';
5802 print
'<!-- amounts -->'.
"\n";
5803 print
'<div class="underbanner clearboth"></div>'.
"\n";
5805 print
'<table class="border tableforfield centpercent">';
5807 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
5815 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
5816 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5819 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5825 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
5826 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5829 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5834 if ((
$mysoc->localtax1_assuj ==
"1" &&
$mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
5836 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1",
$mysoc->country_code) .
'</td>';
5837 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5841 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5846 if ((
$mysoc->localtax2_assuj ==
"1" &&
$mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
5848 print
'<td>' . $langs->transcountry(
"AmountLT2",
$mysoc->country_code) .
'</td>';
5849 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5853 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5859 if ($selleruserevenustamp) {
5860 print
'<tr><td class="titlefieldmiddle">';
5861 print
'<table class="nobordernopadding centpercent"><tr><td>';
5862 print $langs->trans(
'RevenueStamp');
5864 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
5865 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>';
5867 print
'</tr></table>';
5868 print
'</td><td class="nowrap amountcard right">';
5869 if ($action ==
'editrevenuestamp') {
5870 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
5871 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5872 print
'<input type="hidden" name="action" value="setrevenuestamp">';
5873 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
5874 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5875 print $formother->select_revenue_stamp(
'',
'revenuestamp_type',
$mysoc->country_code);
5876 print
' → <span id="revenuestamp_span"></span>';
5877 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
5880 $(document).ready(function(){
5881 js_recalculate_revenuestamp();
5882 $('select[name=revenuestamp_type]').on('change',function(){
5883 js_recalculate_revenuestamp();
5886 function js_recalculate_revenuestamp(){
5887 var valselected = $('select[name=revenuestamp_type]').val();
5888 console.log('Calculate revenue stamp from '+valselected);
5890 if (valselected.indexOf('%') == -1)
5892 revenue = valselected;
5896 var revenue_type = parseFloat(valselected);
5897 var amount_net = ".round(
$object->total_ht, 2).
";
5898 revenue = revenue_type * amount_net / 100;
5899 revenue = revenue.toFixed(2);
5901 $('#revenuestamp_val').val(revenue);
5902 $('#revenuestamp_span').html(revenue);
5906 print
price(
$object->revenuestamp, 1,
'', 1, -1, -1, $conf->currency);
5913 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
5914 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5917 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5932 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
5935 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
5938 if ($selleruserevenustamp) {
5948 $total_prev_ht = $total_prev_ttc = 0;
5949 $total_global_ht = $total_global_ttc = 0;
5953 print
'<!-- List of situation invoices -->';
5954 print
'<div class="div-table-responsive-no-min">';
5955 print
'<table class="noborder paymenttable centpercent situationstable">';
5957 print
'<tr class="liste_titre">';
5958 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
5960 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
5963 print
'<td class="right"></td>';
5965 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
5966 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
5967 print
'<td width="18"> </td>';
5970 if (count(
$object->tab_previous_situation_invoice) > 0) {
5973 $current_situation_counter = array();
5974 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
5975 $tmptotalallpayments = $prev_invoice->getSommePaiement(0);
5976 $tmptotalallpayments += $prev_invoice->getSumDepositsUsed(0);
5977 $tmptotalallpayments += $prev_invoice->getSumCreditNotesUsed(0);
5979 $total_prev_ht += $prev_invoice->total_ht;
5980 $total_prev_ttc += $prev_invoice->total_ttc;
5982 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
5983 print
'<tr class="oddeven">';
5984 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
5986 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
5988 print
'<td class="right"></td>';
5990 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
5991 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
5992 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalallpayments).
'</td>';
5997 $totalallpayments =
$object->getSommePaiement(0);
5998 $totalallpayments +=
$object->getSumCreditNotesUsed(0);
5999 $totalallpayments +=
$object->getSumDepositsUsed(0);
6001 $total_global_ht += $total_prev_ht;
6002 $total_global_ttc += $total_prev_ttc;
6003 $total_global_ht +=
$object->total_ht;
6004 $total_global_ttc +=
$object->total_ttc;
6008 print
'<tr class="oddeven">';
6009 print
'<td>'.$object->getNomUrl(1).
'</td>';
6011 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
6013 print
'<td class="right"></td>';
6015 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
6016 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
6017 print
'<td class="right">'.$object->getLibStatut(3, $totalallpayments).
'</td>';
6021 print
'<tr class="oddeven">';
6022 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'SituationTotalAfterInvoice').
'</b></td>';
6025 foreach ($current_situation_counter as $sit) {
6026 $curSign = $sit > 0 ?
'+' :
'-';
6027 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
6029 print
' '.$curSign.
' ';
6031 print $curType.abs($sit);
6038 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6039 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6040 print
'<td width="18"> </td>';
6044 if (count(
$object->tab_next_situation_invoice) > 0) {
6046 $total_next_ht = $total_next_ttc = 0;
6048 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
6049 $totalpaid = $next_invoice->getSommePaiement(0);
6050 $totalcreditnotes = $next_invoice->getSumCreditNotesUsed(0);
6051 $totaldeposits = $next_invoice->getSumDepositsUsed(0);
6052 $total_next_ht += $next_invoice->total_ht;
6053 $total_next_ttc += $next_invoice->total_ttc;
6055 print
'<tr class="oddeven">';
6056 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
6058 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
6060 print
'<td class="right"></td>';
6062 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
6063 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
6064 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid + $totalcreditnotes + $totaldeposits).
'</td>';
6068 $total_global_ht += $total_next_ht;
6069 $total_global_ttc += $total_next_ttc;
6071 print
'<tr class="oddeven">';
6072 print
'<td colspan="3" class="right"></td>';
6074 print
'<td class="right"></td>';
6076 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6077 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6078 print
'<td width="18"> </td>';
6087 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
6093 print
'<!-- List of payments already done -->';
6094 print
'<div class="div-table-responsive-no-min">';
6095 print
'<table class="noborder paymenttable centpercent">';
6097 print
'<tr class="liste_titre">';
6098 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
6099 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
6100 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
6102 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
6104 print
'<td class="liste_titre"></td>';
6105 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
6109 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
6110 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
6111 $sql .=
' pf.amount,';
6112 $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';
6113 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
6114 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
6115 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
6116 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
6117 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
6118 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
6119 $sql .=
' ORDER BY p.datep, p.tms';
6121 $result = $db->query($sql);
6123 $num = $db->num_rows($result);
6128 $objp = $db->fetch_object($result);
6130 $paymentstatic->id = $objp->rowid;
6131 $paymentstatic->datepaye = $db->jdate($objp->dp);
6132 $paymentstatic->ref = $objp->ref;
6133 $paymentstatic->num_payment = $objp->num_payment;
6134 $paymentstatic->paiementcode = $objp->payment_code;
6136 print
'<tr class="oddeven">';
6137 print
'<td class="nowraponall">';
6138 print $paymentstatic->getNomUrl(1);
6141 $dateofpayment = $db->jdate($objp->dp);
6143 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
6150 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
6151 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
6153 $bankaccountstatic->id = $objp->baid;
6154 $bankaccountstatic->ref = $objp->baref;
6155 $bankaccountstatic->label = $objp->baref;
6156 $bankaccountstatic->number = $objp->banumber;
6157 $bankaccountstatic->currency_code = $objp->bacurrency_code;
6160 $bankaccountstatic->account_number = $objp->account_number;
6163 $accountingjournal->fetch($objp->fk_accountancy_journal);
6164 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
6167 print
'<td class="nowraponall">';
6168 if ($bankaccountstatic->id) {
6169 print $bankaccountstatic->getNomUrl(1,
'transactions');
6175 print
'<td class="center">';
6177 $paiement->fetch($objp->rowid);
6179 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
6186 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
6201 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6202 print
'<span class="opacitymedium">';
6204 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
6206 print $langs->trans(
'AlreadyPaid');
6208 print
'</span></td>';
6210 print
'<td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td>';
6213 $resteapayeraffiche = $resteapayer;
6214 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
6215 $cssforamountpaymentcompletenoresize =
'amountpaymentcompletenoresize';
6218 $creditnoteamount = 0;
6220 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
6221 $sql .=
" re.description, re.fk_facture_source";
6222 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
6223 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
6224 $resql = $db->query($sql);
6226 $num = $db->num_rows($resql);
6230 $obj = $db->fetch_object($resql);
6231 $invoice->fetch($obj->fk_facture_source);
6233 print
'<td colspan="'.$nbcols.
'" class="right">';
6234 print
'<span class="opacitymedium">';
6236 print $langs->trans(
"CreditNote").
' ';
6239 print $langs->trans(
"Deposit").
' ';
6241 print $invoice->getNomUrl(0);
6245 print
'<td class="right">';
6246 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
6247 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
6251 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
6255 $creditnoteamount += $obj->amount_ttc;
6258 $depositamount += $obj->amount_ttc;
6268 print
'<td colspan="'.$nbcols.
'" class="nowrap right">';
6269 print
'<span class="opacitymedium">';
6270 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
6274 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6276 $resteapayeraffiche = 0;
6277 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6278 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6283 print
'<td colspan="'.($nbcols+1).
'" class="nowrap right">';
6284 print
'<span class="opacitymedium">';
6285 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
6289 print
'<td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td>';
6292 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6293 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6298 print
'<td colspan="'.($nbcols+1).
'" class="nowrap right">';
6299 print
'<span class="opacitymedium">';
6300 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
6304 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6306 $resteapayeraffiche = 0;
6307 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6308 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6313 print
'<td colspan="'.($nbcols+1).
'" class="nowrap right">';
6314 $text = $langs->trans(
"HelpAbandonOther");
6316 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
6318 print
'<span class="opacitymedium">';
6320 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
6324 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6326 $resteapayeraffiche = 0;
6327 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6328 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6333 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6334 print
'<span class="opacitymedium">';
6335 print $langs->trans(
"Billed");
6338 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
6343 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6344 print
'<span class="opacitymedium">';
6345 print $langs->trans(
'RemainderToPay');
6346 if ($resteapayeraffiche < 0) {
6347 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6352 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
6358 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6359 print
'<span class="opacitymedium">';
6360 print $langs->trans(
'RemainderToPayMulticurrency');
6361 if ($resteapayeraffiche < 0) {
6362 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6367 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcompletenoresize)).
'">';
6369 print
price(
price2num(
$object->multicurrency_tx * $resteapayeraffiche,
'MT'), 1, $langs, 1, -1, -1, (empty(
$object->multicurrency_code) ? $conf->currency :
$object->multicurrency_code)).
'</td>';
6374 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
6376 if (
$object->isSituationInvoice()) {
6377 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
6380 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
6383 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
6386 print
'<td colspan="'.($nbcols+1).
'" class="right">'.$langs->trans(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')).
' :</td>';
6388 print
'<td class="right">'.price($billedWithRetainedWarranty).
'</td>';
6393 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6394 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
6395 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
6398 print
'<td class="right">'.price($retainedWarranty).
'</td>';
6402 $resteapayeraffiche = $resteapayer;
6403 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6404 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6408 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6409 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
6412 print
'<td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td>';
6417 print
'<td colspan="'.($nbcols+1).
'" class="right"><span class="opacitymedium">'.$langs->trans(
"Billed").
'</span></td>';
6419 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
6423 print
'<tr><td colspan="'.($nbcols+1).
'" class="right">';
6424 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
6425 if ($resteapayeraffiche > 0) {
6426 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6428 print
'</span></td>';
6430 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche);
6439 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6440 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
6441 if ($resteapayeraffiche > 0) {
6442 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6447 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>';
6462 $formmargin->displayMarginInfos($object);
6468 print
'<div class="clearboth"></div><br>';
6471 $blocname =
'contacts';
6472 $title = $langs->trans(
'ContactsAddresses');
6473 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6477 $blocname =
'notes';
6478 $title = $langs->trans(
'Notes');
6479 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6483 $result =
$object->getLinesArray();
6487 global $inputalsopricewithtax;
6488 $inputalsopricewithtax = 1;
6493 print
'<!-- Area to change globally the situation percent -->'.
"\n";
6494 print
'<div class="div-table-responsive-no-min">';
6496 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'#updatealllines" method="POST">';
6497 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
6498 print
'<input type="hidden" name="action" value="updatealllines" />';
6499 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
6500 print
'<input type="hidden" name="page_y" value="" />';
6501 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
6503 print
'<table id="tablelines_all_progress" class="noborder noshadow centpercent">';
6505 print
'<tr class="liste_titre nodrag nodrop">';
6509 print
'<td align="center" width="5"> </td>';
6511 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
6512 print
'<td class="right">'.$langs->trans(
'CumulativeProgression').
'</td>';
6513 print
'<td> </td>';
6516 print
'<tr class="nodrag nodrop">';
6519 print
'<td align="center" width="5"> </td>';
6521 print
'<td> </td>';
6522 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
6523 print
'<td class="right"><input type="submit" class="button reposition small" name="all_percent" value="'.$langs->trans(
"Modify").
'" /></td>';
6534 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
6535 <input type="hidden" name="token" value="' .
newToken().
'">
6536 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
6537 <input type="hidden" name="mode" value="">
6538 <input type="hidden" name="page_y" value="">
6539 <input type="hidden" name="id" value="' .
$object->id.
'">
6540 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
6543 if (!empty($conf->use_javascript_ajax) &&
$object->status == 0) {
6545 include DOL_DOCUMENT_ROOT.
'/core/tpl/subtotal_ajaxrow.tpl.php';
6547 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
6551 print
'<div class="div-table-responsive-no-min">';
6552 print
'<table id="tablelines" class="noborder noshadow centpercent nomarginbottom">';
6556 $object->printObjectLines($action,
$mysoc, $soc, $lineid, 1);
6560 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
6561 if ($action !=
'editline' && $action !=
'selectlines') {
6564 $parameters = array();
6565 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
6569 if (empty($reshook)) {
6573 $parameters = array();
6574 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters, $object, $action);
6588 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
6589 print
'<div class="tabsAction">';
6591 $parameters = array();
6592 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
6593 if (empty($reshook)) {
6596 'class' =>
'classfortooltip',
6603 $ventilExportCompta =
$object->getVentilExportCompta();
6605 if ($ventilExportCompta == 0) {
6607 if (!$objectidnext &&
$object->is_last_in_cycle()) {
6608 if ($usercanunvalidate) {
6609 unset($params[
'attr'][
'title']);
6610 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
true, $params);
6612 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
6613 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
false, $params);
6615 } elseif (!
$object->is_last_in_cycle()) {
6616 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
6617 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6619 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
6620 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6624 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6625 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6630 $result = $discount->fetch(0,
$object->id);
6638 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
6639 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
6640 unset($params[
'attr'][
'title']);
6641 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
6643 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6644 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
6651 $langs->load(
"contracts");
6653 if ($usercancreatecontract) {
6654 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>';
6662 $langs->load(
"subtotals");
6664 $url_button = array();
6666 $url_button[] = array(
6667 'lang' =>
'subtotals',
6669 'perm' => (
bool) $usercancreate,
6670 'label' => $langs->trans(
'AddTitleLine'),
6671 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_title_line&token='.
newToken()
6674 $url_button[] = array(
6675 'lang' =>
'subtotals',
6677 'perm' => (
bool) $usercancreate,
6678 'label' => $langs->trans(
'AddSubtotalLine'),
6679 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_subtotal_line&token='.
newToken()
6681 print
dolGetButtonAction(
'', $langs->trans(
'Subtotal'),
'default', $url_button,
'',
true);
6688 if ($usercanvalidate) {
6689 unset($params[
'attr'][
'title']);
6690 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
6695 if (empty($user->socid)) {
6697 if ($objectidnext) {
6698 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6699 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
6702 unset($params[
'attr'][
'title']);
6703 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
6705 unset($params[
'attr'][
'title']);
6706 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
6714 if ($resteapayer > 0) {
6715 if ($usercancreatewithdrarequest) {
6716 if (!$objectidnext &&
$object->close_code !=
'replaced') {
6717 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>';
6719 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
6731 $langs->load(
"cashdesk");
6732 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
6733 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
6738 if ($objectidnext) {
6739 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
6743 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
6744 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
6748 unset($params[
'attr'][
'title']);
6749 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);
6754 $sumofpayment = $totalpaid;
6755 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
6761 if ($resteapayer == 0) {
6762 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
6764 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
6770 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
6774 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
6776 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>';
6783 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
6785 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
6799 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
6800 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
6802 unset($params[
'attr'][
'title']);
6803 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken(),
'',
true, $params);
6809 if ($totalpaid > 0 || $totalcreditnotes > 0) {
6811 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
6814 if ($objectidnext) {
6815 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
6817 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
6825 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
6826 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6827 } elseif (!
$object->is_last_in_cycle()) {
6828 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6830 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6836 if (!$objectidnext) {
6837 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>';
6843 &&
$object->isSituationInvoice()
6844 && (
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
6847 &&
$object->is_last_in_cycle()
6850 if ($usercanunvalidate) {
6851 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>';
6853 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
6859 if (!$objectidnext && count(
$object->lines) > 0) {
6860 unset($params[
'attr'][
'title']);
6861 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
6867 unset($params[
'attr'][
'title']);
6868 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'clone', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice&token='.
newToken(),
'',
true, $params);
6873 &&
$object->isSituationInvoice()
6876 &&
$object->situation_counter > 1
6877 &&
$object->is_last_in_cycle()
6878 && $usercanunvalidate
6880 if ((
$object->total_ttc - $totalcreditnotes) == 0) {
6881 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6883 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6888 $isErasable =
$object->is_erasable();
6891 if ($isErasable == -6) {
6892 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadySentByEmail');
6893 } elseif ($isErasable == -5) {
6894 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadyPrintedOnce');
6895 } elseif ($isErasable == -4) {
6896 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
6897 } elseif ($isErasable == -3) {
6898 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
6899 } elseif ($isErasable == -2) {
6900 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
6901 } elseif ($isErasable == -1) {
6902 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6903 } elseif ($isErasable <= 0) {
6904 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable').(empty(
$object->error) ?
': UnknownReason' :
': '.$object->error);
6905 } elseif ($objectidnext) {
6906 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
6908 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
6909 $enableDelete =
false;
6911 if ($isErasable > 0 && ! $objectidnext) {
6912 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
6913 $enableDelete =
true;
6915 unset($params[
'attr'][
'title']);
6916 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
6918 unset($params[
'attr'][
'title']);
6919 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
6926 if (
GETPOST(
'modelselected',
'alpha')) {
6927 $action =
'presend';
6929 if ($action !=
'prerelance' && $action !=
'presend') {
6930 print
'<div class="fichecenter"><div class="fichehalfleft">';
6931 print
'<a name="builddoc"></a>';
6936 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
6937 $genallowed = $usercanread;
6938 $delallowed = $usercancreate;
6939 $tooltipAfterComboOfModels =
'';
6941 $tooltipAfterComboOfModels = $langs->trans(
"AccordingToYourSetupTheFileWillBeConcatenated",
getDolGlobalString(
'MAIN_INFO_INVOICE_TERMSOFSALE'));
6944 print $formfile->showdocuments(
6964 'remove_file_comfirm',
6965 $tooltipAfterComboOfModels
6968 $somethingshown = $formfile->numoffiles;
6971 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice'), 1);
6972 $linktoelem = $tmparray[
'linktoelem'];
6973 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
6974 print $htmltoenteralink;
6976 $compatibleImportElementsList =
false;
6980 $compatibleImportElementsList = array(
'commande',
'propal',
'subscription');
6982 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
6986 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6987 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
6988 $useonlinepayment = count($validpaymentmethod);
6991 print
'<br><!-- Link to pay -->'.
"\n";
6992 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6993 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
6996 print
'</div><div class="fichehalfright">';
7000 $morehtmlcenter =
'<div class="nowraponall">';
7001 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullConversation'),
'',
'fa fa-comments imgforviewmode', DOL_URL_ROOT.
'/compta/facture/messaging.php?id='.
$object->id);
7002 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
7003 $morehtmlcenter .=
'</div>';
7006 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
7008 $somethingshown = $formactions->showactions($object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
7010 print
'</div></div>';
7015 $modelmail =
'facture_send';
7016 $defaulttopic =
'SendBillRef';
7017 $diroutput = $conf->invoice->multidir_output[
$object->entity ?? $conf->entity];
7018 $trackid =
'inv'.$object->id;
7020 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.