49require
'../../main.inc.php';
59require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
60require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
61require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
62require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
63require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
64require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
65require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
66require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
67require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
68require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
69require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
70require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
71require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
72require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
74 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
77 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
78 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
80require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
83 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
86 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
90$langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
92 $langs->load(
'incoterm');
95 $langs->load(
'margins');
99$action =
GETPOST(
'action',
'aZ09');
100$confirm =
GETPOST(
'confirm',
'alpha');
101$cancel =
GETPOST(
'cancel',
'alpha');
102$backtopage =
GETPOST(
'backtopage',
'alpha');
103$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
109$origin =
GETPOST(
'origin',
'alpha');
113$ref_client =
GETPOST(
'ref_client',
'alpha');
114$inputReasonId =
GETPOSTINT(
'input_reason_id');
117$selectedLines =
GETPOST(
'toselect',
'array:int');
130$extrafields->fetch_name_optionals_label(
$object->table_element);
133$total_global_ttc = 0;
134$displayWarranty =
false;
135$statusreplacement = 0;
137$price_base_type =
'';
138$array_options = array();
141if ($id > 0 || !empty($ref)) {
142 if ($action !=
'add') {
144 $fetch_situation =
false;
146 $fetch_situation =
true;
148 $ret =
$object->fetch($id, $ref,
'', 0, $fetch_situation);
149 if ($ret > 0 && isset(
$object->fk_project)) {
150 $ret =
$object->fetchProject();
156$hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
159$usercanread = $user->hasRight(
"facture",
"lire");
160$usercancreate = $user->hasRight(
"facture",
"creer");
161$usercanissuepayment = $user->hasRight(
"facture",
"paiement");
162$usercandelete = $user->hasRight(
"facture",
"supprimer") || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
163$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
166$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'validate')));
167$usercansend = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercanread) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'send')));
168$usercanreopen = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'reopen')));
170 $usercanreopen =
false;
172$usercanunvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'unvalidate')));
173$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
176$usercancreatemargin = $user->hasRight(
'margins',
'creer');
177$usercanreadallmargin = $user->hasRight(
'margins',
'liretous');
178$usercancreatewithdrarequest = $user->hasRight(
'prelevement',
'bons',
'creer');
180$permissionnote = $usercancreate;
181$permissiondellink = $usercancreate;
182$permissiontoedit = $usercancreate;
183$permissiontoadd = $usercancreate;
184$permissiontoeditextra = $usercancreate;
185if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
187 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
191$retainedWarrantyInvoiceAvailableType = array();
193 $retainedWarrantyInvoiceAvailableType = explode(
'+',
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY'));
198 $socid = $user->socid;
211$parameters = array(
'socid' => $socid);
212$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
214 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
217if (empty($reshook)) {
218 $backurlforlist =
dolBuildUrl(DOL_URL_ROOT.
'/compta/facture/list.php');
220 if (empty($backtopage) || ($cancel && empty($id))) {
221 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
222 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
223 $backtopage = $backurlforlist;
225 $backtopage =
dolBuildUrl(DOL_URL_ROOT.
'/compta/facture/card.php', [
'id' => ((!empty($id) && $id > 0) ? $id :
'__ID__')]);
231 if (!empty($backtopageforcancel)) {
232 header(
"Location: ".$backtopageforcancel);
234 } elseif (!empty($backtopage)) {
235 header(
"Location: ".$backtopage);
241 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
243 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
245 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
248 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
250 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'IdThirdParty')),
null,
'errors');
253 '@phan-var-force Facture $objectutil';
256 $objectutil->socid = $socid;
257 $result = $objectutil->createFromClone($user, $id, (
GETPOSTISSET(
'entity') ?
GETPOSTINT(
'entity') : null));
259 $warningMsgLineList = array();
261 foreach ($objectutil->lines as $line) {
262 if (!is_object($line->product)) {
263 $line->fetch_product();
265 if (is_object($line->product) && $line->product->id > 0) {
266 if (empty($line->product->status)) {
267 $warningMsgLineList[$line->id] = $langs->trans(
'WarningLineProductNotToSell', $line->product->ref);
271 if (!empty($warningMsgLineList)) {
272 setEventMessages(
'', $warningMsgLineList,
'warnings');
275 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?facid=' . $result);
278 $langs->load(
"errors");
279 setEventMessages($objectutil->error, $objectutil->errors,
'errors');
283 } elseif ($action ==
'reopen' && $usercanreopen) {
287 $result =
$object->setUnpaid($user);
289 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
295 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
300 $idwarehouse =
GETPOST(
'idwarehouse');
302 $qualified_for_stock_change = 0;
304 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
306 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
309 $isErasable =
$object->is_erasable();
311 if (($isErasable > 0) || ($usercancreate && $isErasable == 1)) {
313 $result =
$object->delete($user, 0, (
int) $idwarehouse);
315 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
322 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
332 $outputlangs = $langs;
338 $newlang =
$object->thirdparty->default_lang;
340 if (!empty($newlang)) {
342 $outputlangs->setDefaultLang($newlang);
343 $outputlangs->load(
'products');
347 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
350 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
357 } elseif ($action ==
'confirm_delete_subtotalline' && $confirm ==
'yes' && $usercancreate) {
362 $result =
$object->deleteSubtotalLine($langs,
GETPOSTINT(
'lineid'), (
bool)
GETPOST(
'deletecorrespondingsubtotalline'));
367 $outputlangs = $langs;
373 $newlang =
$object->thirdparty->default_lang;
375 if (!empty($newlang)) {
377 $outputlangs->setDefaultLang($newlang);
378 $outputlangs->load(
'products');
382 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
385 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
392 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
395 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
397 if ($result > 0 && $discount->fk_facture ==
$object->id) {
398 $discount->unlink_invoice();
400 if (
$object->paye == 1 && (
float)
$object->getRemainToPay() > 0) {
404 setEventMessages($langs->trans(
"ErrorRecordNotFound"),
null,
'errors');
406 } elseif ($action ==
'valid' && $usercancreate) {
410 if ((preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) &&
417 $last_of_type =
$object->willBeLastOfSameType(
true);
418 if (empty(
$object->date_validation) && !$last_of_type[0]) {
428 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
437 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
446 $array_of_total_ht_per_vat_rate = array();
447 $array_of_total_ht_devise_per_vat_rate = array();
448 foreach (
$object->lines as $line) {
450 $vat_src_code_for_line =
'';
451 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
452 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
454 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
455 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
457 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
458 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
462 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
463 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
464 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
466 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
467 if (
$object->type == $object::TYPE_DEPOSIT) {
468 $langs->load(
"errors");
470 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
474 $tmpvatratetoshow = explode(
'_', $vatrate);
475 $tmpvatratetoshow[0] = round((
float) $tmpvatratetoshow[0], 2);
477 if ($tmpvatratetoshow[0] != 0) {
478 $langs->load(
"errors");
479 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", (
string) $tmpvatratetoshow[0]),
null,
'errors');
487 } elseif ($action ==
'classin' && $usercancreate) {
493 } elseif ($action ==
'setposinfo' && $usercancreate) {
497 $result =
$object->update($user);
501 } elseif ($action ==
'setmode' && $usercancreate) {
507 } elseif ($action ==
'setretainedwarrantyconditions' && $usercancreate) {
510 $object->retained_warranty_fk_cond_reglement = 0;
511 $result =
$object->setRetainedWarrantyPaymentTerms(
GETPOSTINT(
'retained_warranty_fk_cond_reglement'));
516 $old_rw_date_lim_reglement =
$object->retained_warranty_date_limit;
517 $new_rw_date_lim_reglement =
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
518 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
519 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
524 $result =
$object->update($user);
528 } elseif ($action ==
'setretainedwarranty' && $usercancreate) {
534 } elseif ($action ==
'setretainedwarrantydatelimit' && $usercancreate) {
536 $result =
$object->setRetainedWarrantyDateLimit(
GETPOSTDATE(
'retained_warranty_date_limit'));
540 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
541 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
542 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
544 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
546 $old_date_lim_reglement =
$object->date_lim_reglement;
548 if (empty($newdate)) {
549 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
550 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.
$id.
'&action=editinvoicedate&token='.
newToken());
555 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
557 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
562 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
563 if ($new_date_lim_reglement) {
564 $object->date_lim_reglement = $new_date_lim_reglement;
569 $result =
$object->update($user);
572 $action =
'editinvoicedate';
574 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
579 $object->date_pointoftax = $date_pointoftax;
580 $result =
$object->update($user);
584 } elseif ($action ==
'setconditions' && $usercancreate) {
586 $object->cond_reglement_code = 0;
587 $object->cond_reglement_id = 0;
600 $old_date_lim_reglement =
$object->date_lim_reglement;
601 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
602 if ($new_date_lim_reglement) {
603 $object->date_lim_reglement = $new_date_lim_reglement;
608 $result =
$object->update($user);
620 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
624 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
625 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
627 $result =
$object->update($user);
631 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
634 $result =
$object->update($user);
641 $outputlangs = $langs;
644 $newlang =
GETPOST(
'lang_id',
'aZ09');
647 $newlang =
$object->thirdparty->default_lang;
649 if (!empty($newlang)) {
651 $outputlangs->setDefaultLang($newlang);
652 $outputlangs->load(
'products');
657 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
663 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
668 } elseif ($action ==
'set_dispute_status' && $usercancreate) {
669 $result =
$object->setStatut(
GETPOSTINT(
'dispute_status'),
null,
'facture',
'FACTURE_MODIFY',
'dispute_status');
673 } elseif ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
678 } elseif ($action ==
'setbankaccount' && $usercancreate) {
683 } elseif ($action ==
'setremisepercent' && $usercancreate) {
689 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
701 $usemccompare =
false;
703 if ($discount->fetch($idremise) > 0) {
707 && !empty($discount->multicurrency_code) && !empty(
$object->multicurrency_code)
708 && $discount->multicurrency_code ==
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency);
709 $maxtoabsorb = (float)
price2num($usemccompare ?
$object->getRemainToPay(1) :
$object->getRemainToPay(0),
'MT');
710 $discountamountforcompare = (float)
price2num($usemccompare ? $discount->multicurrency_amount_ttc : $discount->amount_ttc,
'MT');
711 if ($discountamountforcompare > $maxtoabsorb) {
712 if ($maxtoabsorb <= 0) {
715 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
718 $depositeur = (float) $discount->amount_ttc;
719 $depositdev = (float) $discount->multicurrency_amount_ttc;
720 if ($usemccompare && $depositdev != 0) {
721 $applydev = $maxtoabsorb;
725 $creditrate = !empty($discount->multicurrency_tx) ? (float) $discount->multicurrency_tx : 0;
726 if ($creditrate > 0) {
727 $applyeur = (float)
price2num($applydev / $creditrate,
'MT');
729 $applyeur = (float)
price2num($applydev / $depositdev * $depositeur,
'MT');
732 $applyeur = $maxtoabsorb;
733 $applydev = ($depositeur != 0 ? (float)
price2num($applyeur / $depositeur * $depositdev,
'MT') : 0);
735 $splitparts = $discount->splitAmount($applyeur, (
float)
price2num($depositeur - $applyeur,
'MT'));
736 $applypart = $splitparts[0];
737 $remainpart = $splitparts[1];
739 if (!empty($discount->multicurrency_code) && $depositdev != 0) {
741 $remaindev = (float)
price2num($depositdev - $applydev,
'MT');
742 $applypart->multicurrency_amount_ttc = $applydev;
743 $applypart->multicurrency_amount_ht =
price2num($applydev / (1 + (
float) $applypart->tva_tx / 100),
'MT');
744 $applypart->multicurrency_amount_tva =
price2num($applydev - (
float) $applypart->multicurrency_amount_ht);
745 $remainpart->multicurrency_amount_ttc = $remaindev;
746 $remainpart->multicurrency_amount_ht =
price2num($remaindev / (1 + (
float) $remainpart->tva_tx / 100),
'MT');
747 $remainpart->multicurrency_amount_tva =
price2num($remaindev - (
float) $remainpart->multicurrency_amount_ht);
749 $discount->fk_facture_source = 0;
750 $discount->fk_invoice_supplier_source = 0;
751 $resdelete = $discount->delete($user);
752 $newidapply = $applypart->create($user);
753 $newidremain = $remainpart->create($user);
754 if ($resdelete > 0 && $newidapply > 0 && $newidremain > 0) {
755 $idremise = $newidapply;
756 $splitappliedmsg =
price($applyeur, 0, $langs, 1, -1, -1,
$conf->currency);
757 $splitremainmsg =
price((
float)
price2num($depositeur - $applyeur,
'MT'), 0, $langs, 1, -1, -1,
$conf->currency);
758 if (!empty($discount->multicurrency_code) && $depositdev != 0) {
759 $splitappliedmsg .=
' / '.price($applydev, 0, $langs, 1, -1, -1, $discount->multicurrency_code);
760 $splitremainmsg .=
' / '.price($remaindev, 0, $langs, 1, -1, -1, $discount->multicurrency_code);
762 setEventMessages($langs->trans(
'DepositSplitAutomaticallyApplied', $splitappliedmsg, $splitremainmsg),
null,
'warnings');
765 setEventMessages($langs->trans(
"Error"),
null,
'errors');
772 $result =
$object->insert_discount($idremise);
776 if ($result > 0 && $usemccompare) {
783 $foreigncredits = 0.0;
784 $companycredits = 0.0;
785 foreach (
$object->lines as $creditline) {
786 if (empty($creditline->fk_remise_except)) {
787 $foreigngoods += (float) $creditline->multicurrency_total_ttc;
789 $foreigncredits -= (float) $creditline->multicurrency_total_ttc;
790 $companycredits -= (float) $creditline->total_ttc;
793 $targetcompany = ((float)
$object->multicurrency_tx > 0 ? ($foreigngoods - $foreigncredits) / (float)
$object->multicurrency_tx : 0) + $companycredits;
794 if ($foreigngoods > 0 && $targetcompany > 0) {
795 $neweffectivetx = (float)
price2num($foreigngoods / $targetcompany,
'CR');
796 if (abs($neweffectivetx - (
float)
$object->multicurrency_tx) >= 0.00000001) {
797 $resrate =
$object->setMulticurrencyRate($neweffectivetx, 1);
802 setEventMessages($langs->trans(
'InvoiceRateRealigned',
price2num($neweffectivetx,
'CR')),
null,
'mesgs');
815 $newremaintopay =
$object->getRemainToPay(0);
816 if ($newremaintopay == 0) {
823 if (
GETPOSTINT(
"remise_id_for_payment") > 0) {
824 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
826 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
833 && !empty($discount->multicurrency_code) && !empty(
$object->multicurrency_code)
834 && $discount->multicurrency_code ==
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency);
835 $remaintopay = $usemccompare ?
$object->getRemainToPay(1) :
$object->getRemainToPay(0);
836 $discountamountforcompare = $usemccompare ? $discount->multicurrency_amount_ttc : $discount->amount_ttc;
837 $discounttolink = $discount;
838 $depositwassplit =
false;
839 $splitappliedmsg =
'';
840 $splitremainmsg =
'';
842 if ((
float) $remaintopay <= 0) {
844 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
847 $depositeur = (float) $discount->amount_ttc;
848 $depositdev = (float) $discount->multicurrency_amount_ttc;
849 if ($usemccompare && $depositdev != 0) {
850 $applydev = (float) $remaintopay;
854 $creditrate = !empty($discount->multicurrency_tx) ? (float) $discount->multicurrency_tx : 0;
855 if ($creditrate > 0) {
856 $applyeur = (float)
price2num($applydev / $creditrate,
'MT');
858 $applyeur = (float)
price2num($applydev / $depositdev * $depositeur,
'MT');
861 $applyeur = (float) $remaintopay;
862 $applydev = ($depositeur != 0 ? (float)
price2num($applyeur / $depositeur * $depositdev,
'MT') : 0);
864 $splitparts = $discount->splitAmount($applyeur, (
float)
price2num($depositeur - $applyeur,
'MT'));
865 $applypart = $splitparts[0];
866 $remainpart = $splitparts[1];
868 if (!empty($discount->multicurrency_code) && $depositdev != 0) {
869 $remaindev = (float)
price2num($depositdev - $applydev,
'MT');
870 $applypart->multicurrency_amount_ttc = $applydev;
871 $applypart->multicurrency_amount_ht =
price2num($applydev / (1 + (
float) $applypart->tva_tx / 100),
'MT');
872 $applypart->multicurrency_amount_tva =
price2num($applydev - (
float) $applypart->multicurrency_amount_ht);
873 $remainpart->multicurrency_amount_ttc = $remaindev;
874 $remainpart->multicurrency_amount_ht =
price2num($remaindev / (1 + (
float) $remainpart->tva_tx / 100),
'MT');
875 $remainpart->multicurrency_amount_tva =
price2num($remaindev - (
float) $remainpart->multicurrency_amount_ht);
877 $discount->fk_facture_source = 0;
878 $discount->fk_invoice_supplier_source = 0;
879 $resdelete = $discount->delete($user);
880 $newidapply = $applypart->create($user);
881 $newidremain = $remainpart->create($user);
882 if ($resdelete > 0 && $newidapply > 0 && $newidremain > 0) {
884 $discounttolink->fetch($newidapply);
886 $depositwassplit =
true;
887 $splitappliedmsg =
price($applyeur, 0, $langs, 1, -1, -1,
$conf->currency);
888 $splitremainmsg =
price((
float)
price2num($depositeur - $applyeur,
'MT'), 0, $langs, 1, -1, -1,
$conf->currency);
889 if (!empty($discount->multicurrency_code) && $depositdev != 0) {
890 $splitappliedmsg .=
' / '.price($applydev, 0, $langs, 1, -1, -1, $discount->multicurrency_code);
891 $splitremainmsg .=
' / '.price($remaindev, 0, $langs, 1, -1, -1, $discount->multicurrency_code);
895 setEventMessages($langs->trans(
"Error"),
null,
'errors');
901 $result = $discounttolink->link_to_invoice(0, $id);
904 setEventMessages($discounttolink->error, $discounttolink->errors,
'errors');
914 $newremaintopay = $usemccompare ?
$object->getRemainToPay(1) :
$object->getRemainToPay(0);
915 if ($newremaintopay == 0) {
919 if ($depositwassplit) {
920 setEventMessages($langs->trans(
'DepositSplitAutomaticallyApplied', $splitappliedmsg, $splitremainmsg),
null,
'warnings');
932 $outputlangs = $langs;
935 $newlang =
GETPOST(
'lang_id',
'aZ09');
939 $newlang =
$object->thirdparty->default_lang;
941 if (!empty($newlang)) {
943 $outputlangs->setDefaultLang($newlang);
947 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
952 } elseif ($action ==
'setref' && $usercancreate) {
954 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', 0,
'',
'', $user,
'BILL_MODIFY');
958 } elseif ($action ==
'setref_client' && $usercancreate) {
964 } elseif ($action ==
'setdemandreason' && $usercancreate) {
965 $result =
$object->setInputReason($inputReasonId);
969 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
978 $qualified_for_stock_change = 0;
980 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
982 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
985 if ($qualified_for_stock_change) {
986 if (!$idwarehouse || $idwarehouse == - 1) {
988 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
995 $result =
$object->validate($user,
'', $idwarehouse);
999 $outputlangs = $langs;
1002 $newlang =
GETPOST(
'lang_id',
'aZ09');
1005 $newlang =
$object->thirdparty->default_lang;
1007 if (!empty($newlang)) {
1009 $outputlangs->setDefaultLang($newlang);
1010 $outputlangs->load(
'products');
1016 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1023 setEventMessages(
null,
$object->errors,
'errors');
1029 } elseif ($action ==
'confirm_modif' && $usercanunvalidate && !
getDolGlobalString(
'INVOICE_CAN_NEVER_BE_EDITED')) {
1038 $qualified_for_stock_change = 0;
1040 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
1042 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1045 if ($qualified_for_stock_change) {
1046 if (!$idwarehouse || $idwarehouse == -1) {
1048 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1057 $sql =
'SELECT pf.amount';
1058 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'paiement_facture as pf';
1059 $sql .=
' WHERE pf.fk_facture = ' . ((int)
$object->id);
1061 $result = $db->query($sql);
1064 $num = $db->num_rows($result);
1067 $objp = $db->fetch_object($result);
1068 $totalpaid += $objp->amount;
1072 dol_print_error($db,
'');
1075 $resteapayer =
$object->total_ttc - $totalpaid;
1078 $ventilExportCompta =
$object->getVentilExportCompta();
1081 if ($ventilExportCompta == 0) {
1084 $result =
$object->setDraft($user, $idwarehouse);
1091 $outputlangs = $langs;
1094 $newlang =
GETPOST(
'lang_id',
'aZ09');
1097 $newlang =
$object->thirdparty->default_lang;
1099 if (!empty($newlang)) {
1101 $outputlangs->setDefaultLang($newlang);
1102 $outputlangs->load(
'products');
1107 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1113 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
1116 $result =
$object->setPaid($user);
1120 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
1123 $close_code =
GETPOST(
"close_code",
'restricthtml');
1124 $close_note =
GETPOST(
"close_note",
'restricthtml');
1127 if (
isModEnabled(
'tax') && $close_code == $object::CLOSECODE_WITHHOLDINGTAX) {
1128 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
1130 $amount = (float) ($resteapayer > 0 ? $resteapayer * -1 : $resteapayer);
1133 $tempTva =
new Tva($db);
1134 $tempTva->datev =
$object->date;
1135 $tempTva->datep =
$object->date;
1136 $tempTva->amount = $amount;
1137 $tempTva->label = $langs->trans(
'WithholdingTax') .
' - ' .
$object->ref;
1139 $valid = $tempTva->getIdForLabel($tempTva->label);
1141 $ret = $tempTva->create($user);
1145 $tempTva->setPaid($user);
1147 if (empty($error)) {
1150 setEventMessages($tempTva->error, $tempTva->errors,
'errors');
1155 setEventMessages($langs->trans(
'LabelWithholdingExist'), $tempTva->errors,
'errors');
1161 $result =
$object->setPaid($user, $close_code, $close_note);
1169 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
1171 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
1174 $close_code =
GETPOST(
"close_code",
'restricthtml');
1175 $close_note =
GETPOST(
"close_note",
'restricthtml');
1177 $result =
$object->setCanceled($user, $close_code, $close_note);
1184 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
1186 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
1194 $result = $discountcheck->fetch(0,
$object->id);
1207 $amount_ht = $amount_tva = $amount_ttc = $amount_localtax1 = $amount_localtax2 = array();
1208 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
1212 foreach (
$object->lines as $line) {
1213 if ($line->product_type < 9 && $line->total_ht != 0) {
1214 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
1216 if (!isset($amount_ht[$keyforvatrate])) {
1217 $amount_ht[$keyforvatrate] = 0;
1219 $amount_ht[$keyforvatrate] += $line->total_ht;
1220 if (!isset($amount_tva[$keyforvatrate])) {
1221 $amount_tva[$keyforvatrate] = 0;
1223 $amount_tva[$keyforvatrate] += $line->total_tva;
1224 if (!isset($amount_localtax1[$keyforvatrate])) {
1225 $amount_localtax1[$keyforvatrate] = 0;
1227 $amount_localtax1[$keyforvatrate] += $line->total_localtax1;
1228 if (!isset($amount_localtax2[$keyforvatrate])) {
1229 $amount_localtax2[$keyforvatrate] = 0;
1231 $amount_localtax2[$keyforvatrate] += $line->total_localtax2;
1232 if (!isset($amount_ttc[$keyforvatrate])) {
1233 $amount_ttc[$keyforvatrate] = 0;
1235 $amount_ttc[$keyforvatrate] += $line->total_ttc;
1236 if (!isset($multicurrency_amount_ht[$keyforvatrate])) {
1237 $multicurrency_amount_ht[$keyforvatrate] = 0;
1239 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
1240 if (!isset($multicurrency_amount_tva[$keyforvatrate])) {
1241 $multicurrency_amount_tva[$keyforvatrate] = 0;
1243 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
1244 if (!isset($multicurrency_amount_ttc[$keyforvatrate])) {
1245 $multicurrency_amount_ttc[$keyforvatrate] = 0;
1247 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
1251 '@phan-var-force array<string,float> $amount_ht
1252 @phan-var-force array<string,float> $amount_tva
1253 @phan-var-force array<string,float> $amount_ttc
1254 @phan-var-force array<string,float> $amount_localtax1
1255 @phan-var-force array<string,float> $amount_localtax2
1256 @phan-var-force array<string,float> $multicurrency_amount_ht
1257 @phan-var-force array<string,float> $multicurrency_amount_tva
1258 @phan-var-force array<string,float> $multicurrency_amount_ttc';
1262 $alreadypaid =
$object->getSommePaiement();
1263 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
1264 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
1265 foreach ($amount_ht as $vatrate => $val) {
1266 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
1267 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
1268 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
1269 $amount_localtax1[$vatrate] =
price2num($amount_localtax1[$vatrate] * $ratio,
'MU');
1270 $amount_localtax2[$vatrate] =
price2num($amount_localtax2[$vatrate] * $ratio,
'MU');
1271 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
1272 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
1273 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
1282 $discount->description =
'(CREDIT_NOTE)';
1284 $discount->description =
'(DEPOSIT)';
1286 $discount->description =
'(EXCESS RECEIVED)';
1288 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
1290 $discount->fk_soc =
$object->socid;
1291 $discount->socid =
$object->socid;
1292 $discount->fk_facture_source =
$object->id;
1301 $discount->description =
'(EXCESS RECEIVED)';
1304 $sql =
'SELECT SUM(pf.amount) as total_paiements';
1305 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
1306 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
1307 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
1308 $sql .=
' AND pf.fk_paiement = p.rowid';
1309 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
1310 $resql = $db->query($sql);
1312 dol_print_error($db);
1315 $res = $db->fetch_object($resql);
1316 $total_paiements = $res->total_paiements;
1319 $total_creditnote_and_deposit = 0;
1320 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1321 $sql .=
" re.description, re.fk_facture_source";
1322 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1323 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
1324 $resql = $db->query($sql);
1325 if (!empty($resql)) {
1326 while ($obj = $db->fetch_object($resql)) {
1327 $total_creditnote_and_deposit += $obj->amount_ttc;
1330 dol_print_error($db);
1333 $discount->amount_ttc =
price2num($total_paiements + $total_creditnote_and_deposit -
$object->total_ttc,
'MT');
1334 $discount->amount_tva = 0;
1335 $discount->amount_ht = $discount->amount_ttc;
1336 $discount->tva_tx = 0;
1337 $discount->localtax1_tx = 0;
1338 $discount->localtax1_type = 0;
1339 $discount->localtax2_tx = 0;
1340 $discount->localtax2_type = 0;
1341 $discount->vat_src_code =
'';
1343 if ($discount->amount_ttc > 0) {
1344 $result = $discount->create($user);
1354 $discount->description =
'(CREDIT_NOTE)';
1356 $discount->description =
'(DEPOSIT)';
1359 foreach ($amount_ht as $tva_tx => $xxx) {
1364 $discount->amount_ht = -((float) $amount_ht[$tva_tx]);
1365 $discount->amount_tva = -((float) $amount_tva[$tva_tx]);
1366 $discount->amount_ttc = -((float) $amount_ttc[$tva_tx]);
1367 $discount->total_ht = -((float) $amount_ht[$tva_tx]);
1368 $discount->total_tva = -((float) $amount_tva[$tva_tx]);
1369 $discount->total_localtax1 = -((float) $amount_localtax1[$tva_tx]);
1370 $discount->total_localtax2 = -((float) $amount_localtax2[$tva_tx]);
1371 $discount->total_ttc = -((float) $amount_ttc[$tva_tx]);
1372 $discount->multicurrency_amount_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1373 $discount->multicurrency_amount_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1374 $discount->multicurrency_amount_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1375 $discount->multicurrency_total_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1376 $discount->multicurrency_total_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1377 $discount->multicurrency_total_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1380 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
1381 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
1382 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
1383 $discount->total_ht = abs((
float) $amount_ht[$tva_tx]);
1384 $discount->total_tva = abs((
float) $amount_tva[$tva_tx]);
1385 $discount->total_localtax1 = abs((
float) $amount_localtax1[$tva_tx]);
1386 $discount->total_localtax2 = abs((
float) $amount_localtax2[$tva_tx]);
1387 $discount->total_ttc = abs((
float) $amount_ttc[$tva_tx]);
1388 $discount->multicurrency_amount_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1389 $discount->multicurrency_amount_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1390 $discount->multicurrency_amount_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1391 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1392 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1393 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1399 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
1400 $vat_src_code = $reg[1];
1401 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
1404 $discount->tva_tx = abs((
float) $tva_tx);
1405 $discount->localtax1_tx = $taxes[
'localtax1'];
1406 $discount->localtax1_type = $taxes[
'localtax1_type'];
1407 $discount->localtax2_tx = $taxes[
'localtax2'];
1408 $discount->localtax2_type = $taxes[
'localtax2_type'];
1409 $discount->vat_src_code = $vat_src_code;
1411 $result = $discount->create($user);
1419 if (empty($error)) {
1429 $result =
$object->setPaid($user);
1439 setEventMessages($discount->error, $discount->errors,
'errors');
1443 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
1448 $result = $paiement->fetch(
GETPOSTINT(
'paiement_id'));
1449 $paymentbills = ($result > 0) ? $paiement->getBillsArray() : array();
1450 if ($result > 0 && is_array($paymentbills) && in_array(
$object->id, $paymentbills)) {
1451 $result = $paiement->delete($user);
1453 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1457 setEventMessages($paiement->error, $paiement->errors,
'errors');
1460 setEventMessages($langs->trans(
"ErrorRecordNotFound"),
null,
'errors');
1463 } elseif ($action ==
'add' && $usercancreate) {
1470 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1476 $object->demand_reason_id = $inputReasonId;
1479 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1492 if (empty($dateinvoice)) {
1494 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1498 setEventMessages($langs->trans(
"ErrorDateIsInFuture"),
null,
'errors');
1504 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1514 $object->date_pointoftax = $date_pointoftax;
1515 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1516 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1525 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1526 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1543 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1545 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceAvoirAskCombo")),
null,
'errors');
1549 if (empty($dateinvoice)) {
1551 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1555 setEventMessages($langs->trans(
"ErrorDateIsInFuture"),
null,
'errors');
1561 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1566 if (!empty($originentity)) {
1567 $object->entity = $originentity;
1573 $object->date_pointoftax = $date_pointoftax;
1574 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1575 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1580 $object->cond_reglement_id = 0;
1584 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1585 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1589 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1592 $facture_source =
new Facture($db);
1593 if (
$object->fk_facture_source > 0 && $facture_source->fetch(
$object->fk_facture_source) > 0) {
1594 if ($facture_source->isSituationInvoice()) {
1595 $object->situation_counter = $facture_source->situation_counter;
1596 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1597 $facture_source->fetchPreviousNextSituationInvoice();
1600 $object->pos_source = $facture_source->pos_source;
1601 $object->module_source = $facture_source->module_source;
1609 if (
$object->copy_linked_contact($facture_source,
'internal') < 0) {
1611 } elseif ($facture_source->socid ==
$object->socid) {
1613 if (
$object->copy_linked_contact($facture_source,
'external') < 0) {
1624 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1625 if (!empty($facture_source->lines)) {
1626 $fk_parent_line = 0;
1628 foreach ($facture_source->lines as $line) {
1630 if (method_exists($line,
'fetch_optionals')) {
1632 $line->fetch_optionals();
1636 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1637 $fk_parent_line = 0;
1641 if ($facture_source->isSituationInvoice()) {
1642 $source_fk_prev_id = $line->fk_prev_id;
1643 $line->fk_prev_id = $line->id;
1648 if (
getDolGlobalInt(
'INVOICE_USE_SITUATION') == 1 && !empty($facture_source->tab_previous_situation_invoice)) {
1651 $tab_jumped_credit_notes = array();
1652 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1653 $searchPreviousInvoice =
true;
1654 while ($searchPreviousInvoice) {
1655 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1656 $searchPreviousInvoice =
false;
1660 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1666 $maxPrevSituationPercent = 0;
1667 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1668 if ($prevLine->id == $source_fk_prev_id) {
1669 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1672 $line->total_ht -= $prevLine->total_ht;
1673 $line->total_tva -= $prevLine->total_tva;
1674 $line->total_ttc -= $prevLine->total_ttc;
1675 $line->total_localtax1 -= $prevLine->total_localtax1;
1676 $line->total_localtax2 -= $prevLine->total_localtax2;
1678 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1679 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1680 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1681 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1686 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1691 $maxPrevSituationPercent = 0;
1692 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1693 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1694 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1695 $maxPrevSituationPercent = $prevLine->situation_percent;
1697 $line->total_ht -= $prevLine->total_ht;
1698 $line->total_tva -= $prevLine->total_tva;
1699 $line->total_ttc -= $prevLine->total_ttc;
1700 $line->total_localtax1 -= $prevLine->total_localtax1;
1701 $line->total_localtax2 -= $prevLine->total_localtax2;
1703 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1704 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1705 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1706 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1712 $line->situation_percent += $maxPrevSituationPercent;
1718 $line->fk_facture =
$object->id;
1719 $line->fk_parent_line = $fk_parent_line;
1721 $line->subprice = -$line->subprice;
1722 $line->subprice_ttc = -$line->subprice_ttc;
1724 $line->total_ht = -$line->total_ht;
1725 $line->total_tva = -$line->total_tva;
1726 $line->total_ttc = -$line->total_ttc;
1727 $line->total_localtax1 = -$line->total_localtax1;
1728 $line->total_localtax2 = -$line->total_localtax2;
1730 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1731 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1732 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1733 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1735 $line->context[
'createcreditnotefrominvoice'] = 1;
1736 $result = $line->insert(0, 1);
1741 if ($result > 0 && $line->product_type == 9) {
1742 $fk_parent_line = $result;
1750 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1751 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1752 $totalpaid = $facture_source->getSommePaiement();
1753 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1754 $totaldeposits = $facture_source->getSumDepositsUsed();
1755 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1757 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1758 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1761 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1766 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1767 $tva_tx = (float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY');
1774 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), 0, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC', -$remain_to_pay);
1779 if (!empty(
$object->fk_facture_source) &&
$id > 0) {
1780 $facture_source->fetch(
$object->fk_facture_source);
1781 $facture_source->fetchObjectLinked();
1783 if (!empty($facture_source->linkedObjectsIds)) {
1784 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1785 $object->add_object_linked($sourcetype, current($TIds));
1794 if (empty($dateinvoice)) {
1796 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1800 setEventMessages($langs->trans(
"ErrorDateIsInFuture"),
null,
'errors');
1807 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1817 $object->date_pointoftax = $date_pointoftax;
1818 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1819 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1830 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1831 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1847 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1848 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1849 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1853 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1857 if (empty($dateinvoice)) {
1859 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1863 setEventMessages($langs->trans(
"ErrorDateIsInFuture"),
null,
'errors');
1869 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1870 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1875 if ($typeamount && !empty($origin) && !empty($originid)) {
1876 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1877 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1881 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1882 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1886 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1887 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1897 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1907 $object->date_pointoftax = $date_pointoftax;
1908 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1909 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1919 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1920 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1924 $object->situation_counter = 1;
1929 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1931 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1933 $object->retained_warranty = 0;
1934 $object->retained_warranty_fk_cond_reglement = 0;
1937 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1938 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1941 $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);
1946 if (!empty($origin) && !empty($originid)) {
1949 $element = $subelement = $origin;
1950 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1951 $element = $regs[1];
1952 $subelement = $regs[2];
1956 if ($element ==
'order') {
1957 $element = $subelement =
'commande';
1959 if ($element ==
'propal') {
1960 $element =
'comm/propal';
1961 $subelement =
'propal';
1963 if ($element ==
'contract') {
1964 $element = $subelement =
'contrat';
1966 if ($element ==
'inter') {
1967 $element = $subelement =
'fichinter';
1969 if ($element ==
'shipping') {
1970 $element = $subelement =
'expedition';
1974 $object->origin_type = $origin;
1975 $object->origin_id = $originid;
1980 if (
$object->origin ==
'shipping') {
1981 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1983 $exp->fetch(
$object->origin_id);
1984 $exp->fetchObjectLinked();
1985 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1986 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1987 $object->linked_objects[
'commande'] = $value;
1993 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
2001 $classname = ucfirst($subelement);
2002 $srcobject =
new $classname($db);
2003 '@phan-var-force CommonObject $srcobject';
2005 dol_syslog(
"Try to find source object origin_type=".
$object->origin_type.
" origin_id=".
$object->origin_id.
" to add lines or deposit lines");
2006 $result = $srcobject->fetch(
$object->origin_id);
2012 $amountdeposit = array();
2015 if ($typeamount ==
'amount') {
2016 $amount = (float) $valuedeposit;
2018 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
2021 $TTotalByTva = array();
2022 foreach ($srcobject->lines as &$line) {
2023 if (empty($line->qty)) {
2026 if (!empty($line->special_code)) {
2029 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
2031 '@phan-var-force array<string,float> $TTotalByTva';
2033 $amount_ttc_diff = 0.;
2034 foreach ($TTotalByTva as $tva => &$total) {
2035 if (empty($amountdeposit[$tva])) {
2036 $amountdeposit[$tva] = 0;
2038 $coef = $total / $srcobject->total_ttc;
2039 $am = $amount * $coef;
2040 $amount_ttc_diff += $am;
2041 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
2044 if ($typeamount ==
'amount') {
2045 $amountdeposit[0] = $valuedeposit;
2046 } elseif ($typeamount ==
'variable') {
2049 $lines = $srcobject->lines;
2050 $numlines = count($lines);
2051 for ($i = 0; $i < $numlines; $i++) {
2053 if (empty($lines[$i]->qty)) {
2056 if (!empty($lines[$i]->special_code)) {
2060 $totalamount += $lines[$i]->total_ht;
2061 $tva_tx = $lines[$i]->tva_tx;
2063 if (empty($amountdeposit[$tva_tx])) {
2064 $amountdeposit[$tva_tx] = 0;
2066 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
2070 if ($totalamount == 0) {
2071 $amountdeposit[0] = 0;
2074 setEventMessages($srcobject->error, $srcobject->errors,
'errors');
2080 if ($typeamount ==
'variable') {
2081 $amount_ttc_diff = (float)
price2num($srcobject->total_ttc * ((
float) $valuedeposit / 100),
'MT');
2083 $amount_ttc_diff = $amountdeposit[0];
2087 foreach ($amountdeposit as $tva => $amount) {
2088 if (empty($amount)) {
2093 'amount' =>
'FixAmount',
2094 'variable' =>
'VarAmount'
2096 $descline =
'(DEPOSIT)';
2098 if ($typeamount ==
'amount') {
2099 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
2100 } elseif ($typeamount ==
'variable') {
2101 $descline .=
' ('.$valuedeposit.
'%)';
2104 $descline .=
' - '.$srcobject->ref;
2117 $i >= 0 ? $lines[$i]->info_bits : 0,
2123 $i >= 0 ? $lines[$i]->special_code : 0,
2142 $diff =
$object->total_ttc - $amount_ttc_diff;
2146 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
2147 $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);
2156 $lines = $srcobject->lines;
2157 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
2158 $srcobject->fetch_lines();
2159 $lines = $srcobject->lines;
2164 if (is_array($lines)) {
2165 foreach ($lines as $line) {
2167 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuestandardinvoice / 100,
'MS');
2173 if (is_array($lines)) {
2174 foreach ($lines as $line) {
2176 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuedeposit / 100,
'MS');
2181 $fk_parent_line = 0;
2182 $num = count($lines);
2184 for ($i = 0; $i < $num; $i++) {
2185 if (!in_array($lines[$i]->
id, $selectedLines)) {
2190 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
2194 if (!isset(
$conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
2195 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
2197 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
2201 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
2202 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
2204 if (
$object->situation_counter == 1) {
2205 $lines[$i]->situation_percent = 0;
2208 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
2211 $desc = $label ? $label : $langs->trans(
'Discount');
2215 $discount->fk_soc =
$object->socid;
2216 $discount->socid =
$object->socid;
2217 $discount->amount_ht = abs($lines[$i]->total_ht);
2218 $discount->amount_tva = abs($lines[$i]->total_tva);
2219 $discount->amount_ttc = abs($lines[$i]->total_ttc);
2220 $discount->total_ht = abs($lines[$i]->total_ht);
2221 $discount->total_tva = abs($lines[$i]->total_tva);
2222 $discount->total_ttc = abs($lines[$i]->total_ttc);
2223 $discount->tva_tx = $lines[$i]->tva_tx;
2224 $discount->localtax1_tx = $lines[$i]->localtax1_tx;
2225 $discount->localtax2_tx = $lines[$i]->localtax2_tx;
2226 $discount->localtax1_type = $lines[$i]->localtax1_type;
2227 $discount->localtax2_type = $lines[$i]->localtax2_type;
2228 $discount->total_localtax1 = abs($lines[$i]->total_localtax1);
2229 $discount->total_localtax2 = abs($lines[$i]->total_localtax2);
2230 $discount->fk_user = $user->id;
2231 $discount->description = $desc;
2232 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
2233 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
2234 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
2235 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
2236 $discount->multicurrency_total_ht = abs($lines[$i]->multicurrency_total_ht);
2237 $discount->multicurrency_total_tva = abs($lines[$i]->multicurrency_total_tva);
2238 $discount->multicurrency_total_ttc = abs($lines[$i]->multicurrency_total_ttc);
2240 $discountid = $discount->create($user);
2241 if ($discountid > 0) {
2242 $result =
$object->insert_discount($discountid);
2244 setEventMessages($discount->error, $discount->errors,
'errors');
2255 if (isset($lines[$i]->date_debut_prevue)) {
2258 if (isset($lines[$i]->date_debut_reel)) {
2261 if (isset($lines[$i]->date_start)) {
2267 if (isset($lines[$i]->date_fin_prevue)) {
2268 $date_end = $lines[$i]->date_fin_prevue;
2270 if (isset($lines[$i]->date_fin_reel)) {
2271 $date_end = $lines[$i]->date_fin_reel;
2273 if (isset($lines[$i]->date_end)) {
2274 $date_end = $lines[$i]->date_end;
2278 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
2279 $fk_parent_line = 0;
2282 $array_options = array();
2284 if (method_exists($lines[$i],
'fetch_optionals')) {
2285 $lines[$i]->fetch_optionals();
2286 $array_options = $lines[$i]->array_options;
2289 $tva_tx = $lines[$i]->tva_tx;
2290 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
2291 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
2300 $line_price_base_type = $lines[$i]->getPriceBaseType();
2303 $lines[$i]->subprice,
2308 $lines[$i]->fk_product,
2309 $lines[$i]->remise_percent,
2313 (
int) $lines[$i]->info_bits,
2314 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except : null,
2315 $line_price_base_type,
2316 (float) $lines[$i]->subprice_ttc,
2319 $lines[$i]->special_code,
2323 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice : null,
2327 $lines[$i]->situation_percent ?? 100,
2328 $lines[$i]->fk_prev_id ?? 0,
2329 $lines[$i]->fk_unit,
2336 foreach (
$object->lines as $line) {
2337 if ($line->id == $result) {
2338 $line->extraparams = $lines[$i]->extraparams;
2339 $line->setExtraParameters();
2351 if ($result > 0 && $lines[$i]->product_type == 9) {
2352 $fk_parent_line = $result;
2357 setEventMessages($srcobject->error, $srcobject->errors,
'errors');
2364 $object->line_order(
true,
'DESC');
2392 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id,
'objFrom' => $srcobject);
2393 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
2396 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2406 for ($i = 1; $i <= $NBLINES; $i++) {
2412 $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);
2423 if (empty($dateinvoice)) {
2425 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
2426 setEventMessages($mesg,
null,
'errors');
2429 setEventMessages($langs->trans(
"ErrorDateIsInFuture"),
null,
'errors');
2435 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
2436 setEventMessages($mesg,
null,
'errors');
2445 if (!empty($origin) && !empty($originid)) {
2446 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2449 $object->origin_type = $origin;
2450 $object->origin_id = $originid;
2454 $retained_warranty =
GETPOSTINT(
'retained_warranty');
2455 if (
price2num($retained_warranty) > 0) {
2459 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
2460 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
2463 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
2464 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
2465 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
2467 $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);
2470 foreach (
$object->lines as $i => &$line) {
2471 $line->fk_prev_id = $line->id;
2472 $line->fetch_optionals();
2474 $line->situation_percent = 0;
2476 $line->situation_percent = $line->get_prev_progress(
$object->id);
2480 $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);
2481 $line->total_ht = (float) $tabprice[0];
2482 $line->total_tva = (float) $tabprice[1];
2483 $line->total_ttc = (float) $tabprice[2];
2484 $line->total_localtax1 = (float) $tabprice[9];
2485 $line->total_localtax2 = (float) $tabprice[10];
2486 $line->multicurrency_total_ht = (float) $tabprice[16];
2487 $line->multicurrency_total_tva = (float) $tabprice[17];
2488 $line->multicurrency_total_ttc = (float) $tabprice[18];
2491 if ($line->fk_remise_except) {
2493 $result = $discount->fetch((
int) $line->fk_remise_except);
2496 if ($discount->fk_facture_line > 0) {
2497 $line->fk_remise_except = 0;
2506 $object->date_pointoftax = $date_pointoftax;
2507 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2521 $object->situation_counter += 1;
2526 $extrafields->fetch_name_optionals_label(
$object->table_element);
2527 $extrafields->setOptionalsFromPost(
null, $object);
2533 $nextSituationInvoice =
new Facture($db);
2534 $nextSituationInvoice->fetch($id);
2537 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id);
2538 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $nextSituationInvoice, $action);
2541 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2549 if ($id > 0 && !$error) {
2551 $categories =
GETPOST(
'categories',
'array');
2552 if (method_exists($object,
'setCategories')) {
2553 $object->setCategories($categories);
2561 $outputlangs = $langs;
2564 $newlang =
GETPOST(
'lang_id',
'aZ09');
2567 if (empty(
$object->thirdparty)) {
2570 $newlang =
$object->thirdparty->default_lang;
2572 if (!empty($newlang)) {
2574 $outputlangs->setDefaultLang($newlang);
2575 $outputlangs->load(
'products');
2580 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2586 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2591 $_GET[
"origin"] =
GETPOST(
"origin",
'alpha');
2595 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2599 foreach (
$object->lines as $line) {
2600 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2603 if ($line->product_type == 1) {
2605 $line_price_base_type = $line->getPriceBaseType();
2606 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
2607 $result =
$object->updateline($line->id, $line->desc, $line_pu, $line->qty, $line->remise_percent, $alldate_start, $alldate_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line_price_base_type, $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);
2610 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2612 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2613 $vat_rate = str_replace(
'*',
'', $vat_rate);
2616 foreach (
$object->lines as $line) {
2617 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2621 $line_price_base_type = $line->getPriceBaseType();
2622 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
2623 $result =
$object->updateline($line->id, $line->desc, $line_pu, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $vat_rate, $localtax1_rate, $localtax2_rate, $line_price_base_type, $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);
2625 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2627 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2628 $remise_percent = str_replace(
'*',
'', $remise_percent);
2629 foreach (
$object->lines as $line) {
2630 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2633 $tvatx = $line->tva_tx;
2634 if (!empty($line->vat_src_code)) {
2635 $tvatx .=
' ('.$line->vat_src_code.
')';
2638 $line_price_base_type = $line->getPriceBaseType();
2639 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
2640 $result =
$object->updateline($line->id, $line->desc, $line_pu, $line->qty, (
float) $remise_percent, $line->date_start, $line->date_end, $tvatx, $line->localtax1_tx, $line->localtax2_tx, $line_price_base_type, $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);
2642 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'progressforalllines',
'alpha') !==
'' && $usercancreate &&
$object->situation_cycle_ref) {
2645 if ($all_progress > 100) {
2646 $all_progress = 100;
2649 foreach (
$object->lines as $line) {
2650 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2654 $percent = $line->getAllPrevProgress(
$object->id);
2656 $percent = $line->get_prev_progress(
$object->id);
2658 if (
$object->type != $object::TYPE_CREDIT_NOTE && (
float) $all_progress < (
float) $percent) {
2659 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
2660 setEventMessages($mesg,
null,
'warnings');
2661 } elseif (
$object->type == $object::TYPE_CREDIT_NOTE && (
float) $all_progress > (
float) $percent) {
2662 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeMoreThanMinPercent");
2663 setEventMessages($mesg,
null,
'warnings');
2665 $object->update_percent($line, $all_progress,
false);
2669 } elseif ($action ==
'confirm_addtextline' && $usercancreate) {
2672 $langs->load(
'subtotals');
2674 $desc =
GETPOST(
'subtotaltextcontent',
'restricthtml');
2677 $result =
$object->addSubtotalLine($langs, $desc, 0, array());
2688 $outputlangs = $langs;
2689 $newlang =
GETPOST(
'lang_id',
'alpha');
2691 $newlang =
$object->thirdparty->default_lang;
2693 if (!empty($newlang)) {
2695 $outputlangs->setDefaultLang($newlang);
2698 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2703 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2705 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
2708 $langs->load(
'subtotals');
2710 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
2711 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
2713 $subtotal_options = array();
2715 foreach (Facture::$TITLE_OPTIONS as $option) {
2716 $value =
GETPOST($option,
'alphanohtml');
2718 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2723 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2734 $outputlangs = $langs;
2735 $newlang =
GETPOST(
'lang_id',
'alpha');
2737 $newlang =
$object->thirdparty->default_lang;
2739 if (!empty($newlang)) {
2741 $outputlangs->setDefaultLang($newlang);
2744 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2749 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2751 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
2754 $langs->load(
'subtotals');
2756 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
2757 foreach (
$object->lines as $line) {
2758 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
2759 $desc = $line->desc;
2760 $depth = -$line->qty;
2764 $subtotal_options = array();
2766 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
2767 $value =
GETPOST($option,
'alphanohtml');
2769 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2774 if (isset($desc) && isset($depth)) {
2775 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2778 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
2787 $outputlangs = $langs;
2788 $newlang =
GETPOST(
'lang_id',
'alpha');
2790 $newlang =
$object->thirdparty->default_lang;
2792 if (!empty($newlang)) {
2794 $outputlangs->setDefaultLang($newlang);
2797 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2802 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2804 } elseif ($action ==
'addline' &&
GETPOST(
'updateallvatlinesblock',
'alpha') &&
GETPOST(
'vatforblocklines',
'alpha') !==
'' && $usercancreate) {
2805 $tx_tva =
GETPOST(
'vatforblocklines') ?
GETPOST(
'vatforblocklines') : 0;
2806 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'tva', $tx_tva);
2807 } elseif ($action ==
'addline' &&
GETPOST(
'updatealldiscountlinesblock',
'alpha') &&
GETPOST(
'discountforblocklines',
'alpha') !==
'' && $usercancreate) {
2808 $discount =
GETPOST(
'discountforblocklines') ?
GETPOST(
'discountforblocklines') : 0;
2809 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'discount', $discount);
2810 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && !
GETPOST(
'submitforallmark',
'alpha') && $usercancreate) {
2811 $langs->load(
'errors');
2819 $price_ht_devise =
'';
2821 $price_ttc_devise =
'';
2824 $price_min_ttc =
'';
2826 if (
GETPOST(
'price_ht') !==
'') {
2829 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2832 if (
GETPOST(
'price_ttc') !==
'') {
2835 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2836 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2839 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2840 if ($prod_entry_mode ==
'free') {
2846 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2851 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2855 if (empty($remise_percent)) {
2856 $remise_percent = 0;
2860 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2861 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2863 if (is_array($extralabelsline)) {
2865 foreach ($extralabelsline as $key => $value) {
2866 unset($_POST[
"options_".$key.$predef]);
2870 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2871 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2874 if (!$prod_entry_mode) {
2876 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2880 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2881 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2886 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0)
2887 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
2888 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
2889 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
2890 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
2891 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
2892 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2893 $langs->load(
"errors");
2894 if (
$object->type == $object::TYPE_DEPOSIT) {
2896 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2898 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2903 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
2904 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
2908 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
2909 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2913 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2917 $langs->load(
"errors");
2918 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2922 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2923 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
2927 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2928 $idprod = $res->fk_product_child;
2930 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2936 $price_base_type =
null;
2937 if (!$error && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
2940 dol_print_error($db,
$object->error);
2943 $ret =
$object->fetch_thirdparty();
2948 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2959 if (!empty($idprod) && $idprod > 0) {
2961 $prod->fetch($idprod);
2970 $pu_ht = $datapriceofproduct[
'pu_ht'];
2971 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2972 $price_min = $datapriceofproduct[
'price_min'];
2973 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2974 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2978 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2979 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string)
$prod->tva_tx));
2984 if (!empty($price_ht) || $price_ht ===
'0') {
2986 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2987 $price_base_type =
'HT';
2988 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2989 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2990 $pu_ttc_devise = (float)
price2num((
float) $pu_ht_devise * (1 + ((float) $tmpvat / 100)),
'MU');
2993 $price_base_type =
'HT';
2994 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2996 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2997 $price_base_type =
'TTC';
2998 } elseif (!empty($price_ttc_devise) || (
string) $price_ttc_devise ===
'0') {
2999 $pu_ttc_devise = (float)
price2num($price_ttc_devise,
'MU');
3000 $pu_ht_devise = (float)
price2num((
float) $pu_ttc_devise / (1 + ((float) $tmpvat / 100)),
'MU');
3003 $price_base_type =
'TTC';
3004 } elseif ($tmpvat != $tmpprodvat) {
3006 if ($price_base_type !=
'HT') {
3007 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
3009 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
3013 $outputlangs = $langs;
3019 if (
GETPOST(
'lang_id',
'aZ09')) {
3020 $newlang =
GETPOST(
'lang_id',
'aZ09');
3022 if (empty($newlang)) {
3023 $newlang =
$object->thirdparty->default_lang;
3025 if (!empty($newlang)) {
3027 $outputlangs->setDefaultLang($newlang);
3028 $outputlangs->load(
'products');
3031 $desc = (!empty(
$prod->multilangs [$outputlangs->defaultlang] [
"description"])) ?
$prod->multilangs [$outputlangs->defaultlang] [
"description"] :
$prod->
description;
3033 $desc =
$prod->description;
3049 if (!empty(
$prod->customcode)) {
3050 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomsCode").
': '.
$prod->customcode;
3052 if (!empty(
$prod->customcode) && !empty(
$prod->country_code)) {
3055 if (!empty(
$prod->country_code)) {
3056 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry(
$prod->country_code,
'', $db, $outputlangs, 0);
3059 if (!empty(
$prod->customcode)) {
3060 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomsCode").
': '.
$prod->customcode;
3062 if (!empty(
$prod->customcode) && !empty(
$prod->country_code)) {
3065 if (!empty(
$prod->country_code)) {
3066 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry(
$prod->country_code,
'', $db, $langs, 0);
3073 $type =
$prod->type;
3074 $fk_unit =
$prod->fk_unit;
3076 if (!empty($price_ht)) {
3081 if (!empty($price_ttc)) {
3086 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
3087 $tva_tx = str_replace(
'*',
'', $tva_tx);
3088 if (empty($tva_tx)) {
3091 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
3094 $fk_unit =
GETPOST(
'units',
'alpha');
3096 if ($pu_ttc && !$pu_ht) {
3097 $price_base_type =
'TTC';
3111 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
3112 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
3115 $pu_equivalent = $pu_ht;
3116 $pu_equivalent_ttc = $pu_ttc;
3118 $currency_tx =
$object->multicurrency_tx;
3122 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3123 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
3125 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3126 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
3141 $fournprice = (int) (
GETPOST(
'fournprice'.$predef) ?
GETPOST(
'fournprice'.$predef) :
'');
3146 $price2num_remise_percent =
price2num($remise_percent);
3147 $price2num_price_min =
price2num($price_min);
3148 $price2num_price_min_ttc =
price2num($price_min_ttc);
3149 if (empty($price2num_pu_ht)) {
3150 $price2num_pu_ht = 0;
3152 if (empty($price2num_remise_percent)) {
3153 $price2num_remise_percent = 0;
3155 if (empty($price2num_price_min)) {
3156 $price2num_price_min = 0;
3158 if (empty($price2num_price_min_ttc)) {
3159 $price2num_price_min_ttc = 0;
3164 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
3165 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3166 setEventMessages($mesg,
null,
'errors');
3168 } 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') {
3169 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3170 setEventMessages($mesg,
null,
'errors');
3190 $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);
3196 $outputlangs = $langs;
3199 $newlang =
GETPOST(
'lang_id',
'aZ09');
3202 $newlang =
$object->thirdparty->default_lang;
3204 if (!empty($newlang)) {
3206 $outputlangs->setDefaultLang($newlang);
3207 $outputlangs->load(
'products');
3210 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
3216 unset($_POST[
'prod_entry_mode']);
3217 unset($_POST[
'qty']);
3218 unset($_POST[
'type']);
3219 unset($_POST[
'remise_percent']);
3220 unset($_POST[
'price_ht']);
3221 unset($_POST[
'multicurrency_price_ht']);
3222 unset($_POST[
'price_ttc']);
3223 unset($_POST[
'tva_tx']);
3224 unset($_POST[
'product_ref']);
3225 unset($_POST[
'product_label']);
3226 unset($_POST[
'product_desc']);
3227 unset($_POST[
'fournprice']);
3228 unset($_POST[
'buying_price']);
3229 unset($_POST[
'np_marginRate']);
3230 unset($_POST[
'np_markRate']);
3231 unset($_POST[
'dp_desc']);
3232 unset($_POST[
'idprod']);
3233 unset($_POST[
'units']);
3234 unset($_POST[
'date_starthour']);
3235 unset($_POST[
'date_startmin']);
3236 unset($_POST[
'date_startsec']);
3237 unset($_POST[
'date_startday']);
3238 unset($_POST[
'date_startmonth']);
3239 unset($_POST[
'date_startyear']);
3240 unset($_POST[
'date_endhour']);
3241 unset($_POST[
'date_endmin']);
3242 unset($_POST[
'date_endsec']);
3243 unset($_POST[
'date_endday']);
3244 unset($_POST[
'date_endmonth']);
3245 unset($_POST[
'date_endyear']);
3246 unset($_POST[
'situations']);
3247 unset($_POST[
'progress']);
3249 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
3258 } elseif ($action ==
'addline' && $usercancreate && (
3259 (
GETPOST(
'submitforallmargins',
'alpha') &&
GETPOST(
'marginforalllines',
'alpha') !==
'') ||
3260 (
GETPOST(
'submitforallmark',
'alpha') &&
GETPOST(
'markforalllines',
'alpha') !==
'')
3263 $margin_rate =
GETPOSTISSET(
'marginforalllines') ?
GETPOST(
'marginforalllines',
'int') :
'';
3265 foreach (
$object->lines as &$line) {
3266 if ($line->subprice > 0) {
3267 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
3270 $subprice_multicurrency = $line->subprice;
3271 if (is_numeric($margin_rate) && $margin_rate > 0) {
3272 $line->subprice = (float)
price2num((
float) $line->pa_ht * (1 + (float) $margin_rate / 100),
'MU');
3273 } elseif (is_numeric($mark_rate) && $mark_rate > 0) {
3274 $line->subprice = (float) ($line->pa_ht / (1 - ((
float) $mark_rate / 100)));
3276 $line->subprice = (float) $line->pa_ht;
3279 if ($line->fk_product > 0) {
3281 $res =
$prod->fetch($line->fk_product);
3283 if (
$prod->price_min > $line->subprice) {
3284 $price_subprice =
price($line->subprice, 0, $outlangs, 1, -1, -1,
'auto');
3285 $price_price_min =
price(
$prod->price_min, 0, $outlangs, 1, -1, -1,
'auto');
3286 setEventMessages(
$prod->ref .
' - ' .
$prod->label .
' (' . $price_subprice .
' < ' . $price_price_min .
' ' . strtolower($langs->trans(
"MinPrice")) .
')' .
"\n",
null,
'warnings');
3288 setEventMessages(
$prod->error,
$prod->errors,
'errors');
3291 setEventMessages(
$prod->error,
$prod->errors,
'errors');
3295 $multicurrency_subprice = (float) $line->subprice * $line->multicurrency_subprice / $subprice_multicurrency;
3297 $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);
3300 if (is_numeric($margin_rate) && empty($mark_rate)) {
3301 $line->marge_tx = $margin_rate;
3302 } elseif (is_numeric($mark_rate) && empty($margin_rate)) {
3303 $line->marque_tx = $mark_rate;
3305 $line->total_ht = $line->qty * (float) $line->subprice;
3306 $line->total_tva = $line->tva_tx * $line->qty * (float) $line->subprice;
3307 $line->total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $line->subprice;
3309 $line->multicurrency_total_ht = $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
3310 $line->multicurrency_total_tva = $line->tva_tx * $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
3311 $line->multicurrency_total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
3313 $line->multicurrency_subprice = $multicurrency_subprice;
3319 } elseif ($action ==
'updatetitleline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3322 $langs->load(
'subtotals');
3324 $desc =
GETPOST(
'line_desc',
'alphanohtml') ?? $langs->trans(
"Title");
3327 $subtotal_options = array();
3329 foreach (Facture::$TITLE_OPTIONS as $option) {
3330 $value =
GETPOST($option,
'alphanohtml');
3332 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
3337 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3348 $outputlangs = $langs;
3349 $newlang =
GETPOST(
'lang_id',
'alpha');
3351 $newlang =
$object->thirdparty->default_lang;
3353 if (!empty($newlang)) {
3355 $outputlangs->setDefaultLang($newlang);
3358 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3363 } elseif ($action ==
'updatetextline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3366 $langs->load(
'subtotals');
3368 $desc =
GETPOST(
'line_desc',
'restricthtml');
3371 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, 0, array());
3382 $outputlangs = $langs;
3383 $newlang =
GETPOST(
'lang_id',
'alpha');
3385 $newlang =
$object->thirdparty->default_lang;
3387 if (!empty($newlang)) {
3389 $outputlangs->setDefaultLang($newlang);
3392 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3397 } elseif ($action ==
'updatesubtotalline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3400 $langs->load(
'subtotals');
3402 $desc =
GETPOST(
'line_desc',
'alphanohtml');
3405 $subtotal_options = array();
3407 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
3408 $value =
GETPOST($option,
'alphanohtml');
3410 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
3415 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3423 $outputlangs = $langs;
3424 $newlang =
GETPOST(
'lang_id',
'alpha');
3426 $newlang =
$object->thirdparty->default_lang;
3428 if (!empty($newlang)) {
3430 $outputlangs->setDefaultLang($newlang);
3433 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3438 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3439 if (!
$object->fetch($id) > 0) {
3440 dol_print_error($db);
3462 if (preg_match(
'/\*/', $vat_rate)) {
3467 $vat_rate = str_replace(
'*',
'', $vat_rate);
3472 $fournprice = (int) (
GETPOST(
'fournprice') ?
GETPOST(
'fournprice') :
'');
3476 $pu_equivalent = $pu_ht;
3477 $pu_equivalent_ttc = $pu_ttc;
3479 $currency_tx =
$object->multicurrency_tx;
3483 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3484 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
3486 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3487 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
3502 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
3503 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
3505 if (is_array($extralabelsline)) {
3507 foreach ($extralabelsline as $key => $value) {
3508 unset($_POST[
"options_".$key]);
3514 if ($special_code == 3) {
3520 $percent = $line->get_prev_progress(
$object->id);
3525 if ($progress >= 0) {
3526 $mesg = $langs->trans(
"CantBeNullOrPositive");
3527 setEventMessages($mesg,
null,
'warnings');
3530 } elseif ($progress < $line->situation_percent) {
3531 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
3532 setEventMessages($mesg,
null,
'warnings');
3535 } elseif ($progress < $percent) {
3536 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
3537 setEventMessages($mesg,
null,
'warnings');
3544 if (empty($remise_percent)) {
3545 $remise_percent = 0;
3552 $price_base_type =
'HT';
3553 if (empty($pu_ht) && !empty($pu_ttc)) {
3555 $price_base_type =
'TTC';
3556 } elseif (!empty($pu_ht) && !empty($pu_ttc)) {
3557 foreach (
$object->lines as $line_obj) {
3560 if ($line_obj->wasEnteredIncludingTax()) {
3562 $price_base_type =
'TTC';
3571 if (!empty($productid)) {
3573 $product->fetch($productid);
3575 $type = $product->type;
3577 $price_min = $product->price_min;
3579 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
3581 $price_min_ttc = $product->price_min_ttc;
3583 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
3590 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
3591 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3592 setEventMessages($mesg,
null,
'errors');
3594 $action =
'editline';
3595 } 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') {
3596 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3597 setEventMessages($mesg,
null,
'errors');
3599 $action =
'editline';
3604 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
3608 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
3613 $langs->load(
"errors");
3614 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
3618 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
3619 $langs->load(
"errors");
3620 if (
$object->type == $object::TYPE_DEPOSIT) {
3622 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
3624 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
3628 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
3635 $previousprogress = $line->getAllPrevProgress($line->fk_facture);
3638 if ($fullprogress < $previousprogress) {
3640 setEventMessages($langs->trans(
'CantBeLessThanMinPercent'),
null,
'errors');
3644 if ($fullprogress > 100) {
3645 $fullprogress = 100;
3647 $addprogress = $fullprogress - $previousprogress;
3654 if (empty($usercancreatemargin)) {
3655 foreach (
$object->lines as &$line) {
3657 $fournprice = $line->fk_fournprice;
3658 $buyingprice = $line->pa_ht;
3664 $result =
$object->updateline(
3669 (
float) $remise_percent,
3687 (
float) $pu_ht_devise
3694 $outputlangs = $langs;
3697 $newlang =
GETPOST(
'lang_id',
'aZ09');
3700 $newlang =
$object->thirdparty->default_lang;
3702 if (!empty($newlang)) {
3704 $outputlangs->setDefaultLang($newlang);
3705 $outputlangs->load(
'products');
3707 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3710 unset($_POST[
'qty']);
3711 unset($_POST[
'type']);
3712 unset($_POST[
'productid']);
3713 unset($_POST[
'remise_percent']);
3714 unset($_POST[
'price_ht']);
3715 unset($_POST[
'multicurrency_price_ht']);
3716 unset($_POST[
'price_ttc']);
3717 unset($_POST[
'tva_tx']);
3718 unset($_POST[
'product_ref']);
3719 unset($_POST[
'product_label']);
3720 unset($_POST[
'product_desc']);
3721 unset($_POST[
'fournprice']);
3722 unset($_POST[
'buying_price']);
3723 unset($_POST[
'np_marginRate']);
3724 unset($_POST[
'np_markRate']);
3725 unset($_POST[
'dp_desc']);
3726 unset($_POST[
'idprod']);
3727 unset($_POST[
'units']);
3728 unset($_POST[
'date_starthour']);
3729 unset($_POST[
'date_startmin']);
3730 unset($_POST[
'date_startsec']);
3731 unset($_POST[
'date_startday']);
3732 unset($_POST[
'date_startmonth']);
3733 unset($_POST[
'date_startyear']);
3734 unset($_POST[
'date_endhour']);
3735 unset($_POST[
'date_endmin']);
3736 unset($_POST[
'date_endsec']);
3737 unset($_POST[
'date_endday']);
3738 unset($_POST[
'date_endmonth']);
3739 unset($_POST[
'date_endyear']);
3740 unset($_POST[
'situations']);
3741 unset($_POST[
'progress']);
3746 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
3747 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
3749 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
3751 $object->fetch($id,
'',
'', 0,
true);
3754 &&
$object->isSituationInvoice()
3757 &&
$object->is_last_in_cycle()
3758 && $usercanunvalidate
3761 $newCycle =
$object->newCycle();
3762 if ($newCycle > 1) {
3764 $lastCycle =
$object->situation_cycle_ref;
3765 $lastSituationCounter =
$object->situation_counter;
3766 $linkedCreditNotesList = array();
3768 if (count(
$object->tab_next_situation_invoice) > 0) {
3769 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
3771 && $next_invoice->situation_counter ==
$object->situation_counter
3772 && $next_invoice->fk_facture_source ==
$object->id
3774 $linkedCreditNotesList[] = $next_invoice->id;
3779 $object->situation_cycle_ref = $newCycle;
3780 $object->situation_counter = 1;
3782 if (
$object->update($user) > 0) {
3784 if (count($linkedCreditNotesList) > 0) {
3786 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
3787 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
3788 $sql .=
' , situation_final=0';
3789 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
3790 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
3792 $resql = $db->query($sql);
3798 foreach (
$object->lines as $line) {
3800 if ($line->product_type == 9) {
3805 if (!empty(
$object->tab_previous_situation_invoice)) {
3807 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
3808 $searchPreviousInvoice =
true;
3809 while ($searchPreviousInvoice) {
3810 if (
$object->tab_previous_situation_invoice[$lineIndex]->isSituationInvoice() || $lineIndex < 1) {
3811 $searchPreviousInvoice =
false;
3819 $maxPrevSituationPercent = 0;
3820 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
3821 if ($prevLine->id == $line->fk_prev_id) {
3822 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
3827 $line->situation_percent -= $maxPrevSituationPercent;
3829 if ($line->update() < 0) {
3837 setEventMessages($langs->trans(
'Updated'),
null,
'mesgs');
3838 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
3840 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
3843 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
3846 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
3852 $fromElement =
GETPOST(
'fromelement',
'aZ09');
3853 $fromElementid =
GETPOST(
'fromelementid');
3854 $importLines =
GETPOST(
'line_checkbox');
3856 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && !empty($fromElementid)) {
3857 $lineClassName =
'';
3858 if ($fromElement ==
'commande') {
3860 $lineClassName =
'OrderLine';
3861 } elseif ($fromElement ==
'propal') {
3862 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
3863 $lineClassName =
'PropaleLigne';
3865 $nextRang = count(
$object->lines) + 1;
3868 foreach ($importLines as $lineId) {
3869 if ($lineClassName ===
'') {
3873 dol_syslog(
'compta/facture/card - No lineClassName - skip import', LOG_ERR);
3880 $lineId = intval($lineId);
3881 $originLine =
new $lineClassName($db);
3882 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
3883 $originLine->fetch_optionals();
3884 $desc = $originLine->desc;
3885 $pu_ht = $originLine->subprice;
3886 $qty = $originLine->qty;
3887 $txtva = $originLine->tva_tx;
3888 $txlocaltax1 = $originLine->localtax1_tx;
3889 $txlocaltax2 = $originLine->localtax2_tx;
3890 $fk_product = $originLine->fk_product;
3891 $remise_percent = $originLine->remise_percent;
3893 $date_end = $originLine->date_end;
3894 $fk_code_ventilation = 0;
3895 $info_bits = $originLine->info_bits;
3896 $fk_remise_except = $originLine->fk_remise_except;
3897 $price_base_type =
'HT';
3899 $type = $originLine->product_type;
3900 $rang = $nextRang++;
3901 $special_code = $originLine->special_code;
3902 $origin = $originLine->element;
3903 $origin_id = $originLine->id;
3904 $fk_parent_line = 0;
3905 $fk_fournprice = $originLine->fk_fournprice;
3906 $pa_ht = $originLine->pa_ht;
3907 $label = $originLine->label;
3908 $array_options = $originLine->array_options;
3909 if (
$object->isSituationInvoice()) {
3910 $situation_percent = 0;
3912 $situation_percent = 100;
3915 $fk_unit = $originLine->fk_unit;
3916 $pu_ht_devise = $originLine->multicurrency_subprice;
3918 $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);
3931 setEventMessages($langs->trans(
'ErrorsOnXLines', $error),
null,
'errors');
3938 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3944 if (!empty(
$object->id) && $action ==
'send') {
3946 $object->getSommePaiement(-1);
3947 $object->getSumCreditNotesUsed(-1);
3948 $object->getSumDepositsUsed(-1);
3950 $triggersendname =
'BILL_SENTBYMAIL';
3952 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3953 $trackid =
'inv'.$object->id;
3954 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3958 $permissiontoadd = $usercancreate;
3959 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3962 if ($action ==
'update_extras' && $permissiontoeditextra) {
3965 $attribute_name =
GETPOST(
'attribute',
'aZ09');
3968 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
3975 $result =
$object->updateExtraField($attribute_name,
'BILL_MODIFY');
3983 $action =
'edit_extras';
3988 if ($action ==
'addcontact' && $usercancreate) {
3989 $result =
$object->fetch($id);
3991 if ($result > 0 && $id > 0) {
3994 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3998 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
4001 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
4002 $langs->load(
"errors");
4003 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
4008 } elseif ($action ==
'swapstatut' && $usercancreate) {
4013 dol_print_error($db);
4015 } elseif ($action ==
'deletecontact' && $usercancreate) {
4018 $result =
$object->delete_contact($lineid);
4021 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
4024 dol_print_error($db);
4029 $action =
'edit_extras';
4039$form =
new Form($db);
4045$bankaccountstatic =
new Account($db);
4053$title =
$object->ref.
" - ".$langs->trans(
'Card');
4054if ($action ==
'create') {
4055 $title = $langs->trans(
"NewBill");
4057$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
4063if ($action ==
'create') {
4064 $facturestatic =
new Facture($db);
4065 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
4070 $res = $soc->fetch($socid);
4073 $currency_code =
$conf->currency;
4075 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
4076 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
4080 if (empty($dateinvoice)) {
4086 if (!empty($origin) && !empty($originid)) {
4088 $element = $subelement = $origin;
4090 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
4091 $element = $regs[1];
4092 $subelement = $regs[2];
4097 if ($element ==
'project') {
4098 $projectid = $originid;
4100 if (empty($cond_reglement_id)) {
4101 $cond_reglement_id = $soc->cond_reglement_id;
4103 if (empty($mode_reglement_id)) {
4104 $mode_reglement_id = $soc->mode_reglement_id;
4106 if (empty($fk_account)) {
4107 $fk_account = $soc->fk_account;
4111 if ($element ==
'order' || $element ==
'commande') {
4112 $element = $subelement =
'commande';
4114 if ($element ==
'propal') {
4115 $element =
'comm/propal';
4116 $subelement =
'propal';
4118 if ($element ==
'contract') {
4119 $element = $subelement =
'contrat';
4121 if ($element ==
'shipping') {
4122 $element = $subelement =
'expedition';
4127 $classname = ucfirst($subelement);
4128 $objectsrc =
new $classname($db);
4129 '@phan-var-force Commande|Propal|Contrat|Expedition|Facture $objectsrc';
4131 $objectsrc->fetch($originid);
4132 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
4133 $objectsrc->fetch_lines();
4135 $objectsrc->fetch_thirdparty();
4137 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
4143 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
4147 if (empty($socid)) {
4148 $soc = $objectsrc->thirdparty;
4151 if ($element ==
'expedition') {
4152 $elem = $subelem = $objectsrc->origin_type;
4153 $expeoriginid = $objectsrc->origin_id;
4155 $classname = ucfirst($subelem);
4157 $expesrc =
new $classname($db);
4158 '@phan-var-force Expedition $expesrc';
4160 dol_syslog(
"Is type Facture|Commande or Expedition: $element...expesrc($classname)=".get_class($expesrc));
4161 $expesrc->fetch($expeoriginid);
4163 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
4164 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
4165 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
4168 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
4169 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
4173 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
4176 $expesrc->fetch_optionals();
4177 $object->array_options = $expesrc->array_options;
4179 $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)));
4180 $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)));
4181 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : (!empty($fk_account) ? $fk_account : 0)));
4184 if (!empty($objectsrc->multicurrency_code)) {
4185 $currency_code = $objectsrc->multicurrency_code;
4187 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
4188 $currency_tx = $objectsrc->multicurrency_tx;
4193 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
4196 $objectsrc->fetch_optionals();
4197 $object->array_options = $objectsrc->array_options;
4201 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
4202 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
4203 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
4204 $inputReasonId = empty($soc->demand_reason_id) ? $inputReasonId : $soc->demand_reason_id;
4206 if (
isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
4207 $currency_code = $soc->multicurrency_code;
4212 if (!
GETPOST(
'changecompany')) {
4214 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
4217 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
4225 if (empty($cond_reglement_id)) {
4226 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
4230 if (empty($mode_reglement_id)) {
4231 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
4241 if (!empty($soc->id)) {
4242 $absolute_discount = $soc->getAvailableDiscounts();
4244 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
4245 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
4247 if (!empty(
$conf->use_javascript_ajax)) {
4248 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
4254 if ($origin ==
'contrat') {
4255 $langs->load(
"admin");
4256 $text = $langs->trans(
"ToCreateARecurringInvoice");
4257 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
4259 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
4261 print
info_admin($text, 0, 0,
'info',
'').
'<br>';
4264 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
4265 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4266 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
4267 print
'<input type="hidden" name="changecompany" value="0">';
4269 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
4271 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4272 print
'<input name="ref" type="hidden" value="provisoire">';
4273 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
4274 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
4275 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
4276 print
'<input name="force_fk_account" type="hidden" value="0">';
4277 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
4278 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
4279 print
'<input type="hidden" name="originentity" value="'.GETPOSTINT(
'originentity').
'">';
4280 if (!empty($currency_tx)) {
4281 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
4287 $parameters = array();
4289 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters, $object, $action);
4290 if (empty($reshook)) {
4291 print
'<table class="border centpercent">';
4293 $exampletemplateinvoice =
new FactureRec($db);
4295 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
4296 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
4309 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
4311 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
'Customer').
'</td>';
4312 print
'<td colspan="2">';
4313 print $soc->getNomUrl(1,
'customer');
4314 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
4316 $arrayoutstandingbills = $soc->getOutstandingBills();
4317 $outstandingBills = $arrayoutstandingbills[
'opened'];
4318 print
' - <span class="opacitymedium valignmiddle">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
4319 print
'<span class="amount valignmiddle">'.price($outstandingBills, 0, $langs, 0, 0, -1,
$conf->currency).
'</span>';
4320 if ($soc->outstanding_limit !=
'') {
4321 if ($outstandingBills > $soc->outstanding_limit) {
4322 print img_warning($langs->trans(
"OutstandingBillReached"));
4324 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1,
$conf->currency);
4329 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
4330 print
'<td colspan="2">';
4331 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
4332 print img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
4336 $(document).ready(function() {
4337 $("#socid").change(function() {
4339 console.log("Submit page");
4340 $(\'input[name="action"]\').val(\'create\');
4341 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
4342 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
4343 $(\'input[name="force_fk_account"]\').val(\'1\');
4344 $("#formtocreate").submit(); */
4346 // For company change, we must submit page with action=create instead of action=add
4347 console.log("We have changed the company - Resubmit page");
4348 jQuery("input[name=changecompany]").val("1");
4349 jQuery("#formtocreateaction").val("create");
4350 jQuery("#formtocreate").submit();
4356 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>';
4363 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
4365 foreach ($invoice_predefined->array_options as $key => $option) {
4366 if (!isset(
$object->array_options[$key])) {
4367 $object->array_options[$key] = $invoice_predefined->array_options[$key];
4371 $dateinvoice = $invoice_predefined->date_when;
4372 if (empty($projectid)) {
4373 $projectid = $invoice_predefined->fk_project;
4375 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
4376 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
4377 $fk_account = $invoice_predefined->fk_account;
4378 $note_public = $invoice_predefined->note_public;
4379 $note_private = $invoice_predefined->note_private;
4381 if (!empty($invoice_predefined->multicurrency_code)) {
4382 $currency_code = $invoice_predefined->multicurrency_code;
4384 if (!empty($invoice_predefined->multicurrency_tx)) {
4385 $currency_tx = $invoice_predefined->multicurrency_tx;
4388 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
4389 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
4390 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
4392 $resql = $db->query($sql);
4394 $num = $db->num_rows($resql);
4398 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
4400 print
'<select class="flat" id="fac_rec" name="fac_rec">';
4401 print
'<option value="0" selected></option>';
4403 $objp = $db->fetch_object($resql);
4404 print
'<option value="'.$objp->rowid.
'"';
4407 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
4409 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
4418 print
'<script type="text/javascript">
4419 $(document).ready(function() {
4420 $("#fac_rec").change(function() {
4421 console.log("We have changed the template invoice - Reload page");
4422 var fac_rec = $(this).val();
4423 var socid = $(\'#socid\').val();
4424 // 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.
4425 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
4434 dol_print_error($db);
4438 print
'<tr><td class="tdtop fieldrequired titlefieldcreate">'.$langs->trans(
'Type').
'</td><td colspan="2">';
4439 print
'<div class="listofinvoicetypetable">'.
"\n";
4442 print
'<div class="listofinvoicetype"><div class="">';
4443 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
4444 $tmp .=
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk");
4445 $tmp .=
' <span class="opacitymedium">'.$langs->trans(
"InvoiceStandardAsk2").
'</span>';
4448 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc").
'<br><br>'.$langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'nowraponall', 0, 3,
'standardonsmartphone');
4450 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
4460 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%') .
'"/>';
4463 print
'</div></div>'.
"\n";
4465 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
4468 print
'<div class="listofinvoicetype"><div class="">';
4469 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
4470 print
'<script type="text/javascript">
4471 jQuery(document).ready(function() {
4472 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
4473 jQuery("#radio_standard").prop("checked", true);
4475 jQuery("#typedeposit, #valuedeposit").click(function() {
4476 jQuery("#radio_deposit").prop("checked", true);
4478 jQuery("#typedeposit").change(function() {
4479 console.log("We change type of down payment: "+jQuery("#typedeposit").val());
4481 if (jQuery("#typedeposit").val() == "amount") {
4482 jQuery("#valuedeposit").attr("placeholder", "'.$langs->getCurrencySymbol(
$conf->currency).
'");
4483 jQuery("#valuedeposit").val("");
4485 jQuery("#valuedeposit").attr("placeholder", "50%");
4486 jQuery("#valuedeposit").val("");
4489 jQuery("#radio_deposit").prop("checked", true);
4490 setRadioForTypeOfInvoice();
4492 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
4493 setRadioForTypeOfInvoice();
4496 function setRadioForTypeOfInvoice() {
4497 console.log("Change radio for type of invoice");
4498 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
4499 jQuery("#checkforselects").prop("disabled", true);
4500 jQuery("#checkforselects").prop("checked", false);
4501 jQuery(".checkforselect").prop("disabled", true);
4502 jQuery(".checkforselect").prop("checked", false);
4504 jQuery("#checkforselects").prop("disabled", false);
4505 jQuery("#checkforselects").prop("checked", true);
4506 jQuery(".checkforselect").prop("disabled", false);
4507 jQuery(".checkforselect").prop("checked", true);
4513 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
4515 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
4517 if (($origin ==
'propal') || ($origin ==
'commande')) {
4520 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
4521 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
4522 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4526 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4530 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
4532 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
4533 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
4534 if (!empty($origin_payment_conditions_deposit_percent)) {
4535 $typedeposit =
'variable';
4538 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
4539 $valuedeposit = $objectsrc->deposit_percent;
4541 print
'<span class="marginleftonly">'.$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1).
'</span>';
4543 print
'<input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.($valuedeposit ? $valuedeposit :
'').
'"'.($valuedeposit ?
'' :
'placeholder="'.$langs->getCurrencySymbol(
$conf->currency).
'"').
'>';
4546 print
'</div></div>'.
"\n";
4553 print
'<div class="listofinvoicetype"><div class="">';
4554 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
4555 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
4557 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
4561 $opt = $form->selectSituationInvoices((
string)
GETPOSTINT(
'originid'), $socid);
4564 print
'</div></div><div class="listofinvoicetype"><div>';
4566 $tmp =
'<input id="radio_situation_bis" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
4567 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4568 $tmp .=
' disabled';
4571 $text = $tmp.
'<label for="radio_situation_bis">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4573 $text .=
'<select class="flat minwidth125" id="situations" name="situations"';
4574 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4575 $text .=
' disabled';
4579 $text .=
'</select>';
4580 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
4582 print
'</div></div>'.
"\n";
4588 $facids = $facturestatic->list_replacable_invoices($soc->id);
4590 dol_print_error($db, $facturestatic->error, $facturestatic->errors);
4594 if (is_array($facids)) {
4595 foreach ($facids as $facparam) {
4596 $options .=
'<option value="'.$facparam [
'id'].
'"';
4597 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
4598 $options .=
' selected';
4600 $options .=
'>'.$facparam[
'ref'];
4601 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
4602 $options .=
'</option>';
4606 print
'<!-- replacement line -->';
4607 print
'<div class="listofinvoicetype"><div class="">';
4608 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
4609 if (!$options || $invoice_predefined->id > 0) {
4610 $tmp .=
' disabled';
4613 print
'<script type="text/javascript">
4614 jQuery(document).ready(function() {
4615 jQuery("#fac_replacement").change(function() {
4616 console.log("We change fac_replacement");
4617 jQuery("#radio_replacement").prop("checked", true);
4621 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
4622 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
4623 if (!$options || $invoice_predefined->id > 0) {
4624 $text .=
' disabled';
4628 $text .=
'<option value="-1"> </option>';
4631 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
4633 $text .=
'</select>';
4634 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
4636 print
'</div></div>'.
"\n";
4640 print
'<div class="listofinvoicetype"><div class="">';
4641 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
4642 $text = $tmp.
'<label class="opacitymedium">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4643 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'firstsituationonsmartphone');
4645 print
'</div></div>'.
"\n";
4648 print
'<div class="listofinvoicetype"><div class="">';
4649 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
4650 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
4651 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'replacementonsmartphone');
4653 print
'</div></div>'.
"\n";
4656 if (empty($origin)) {
4661 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
4663 dol_print_error($db, $facturestatic->error, $facturestatic->errors);
4667 $newinvoice_static =
new Facture($db);
4668 foreach ($facids as $key => $valarray) {
4669 $newinvoice_static->id = $key;
4670 $newinvoice_static->ref = $valarray [
'ref'];
4671 $newinvoice_static->statut = $valarray [
'status'];
4672 $newinvoice_static->status = $valarray [
'status'];
4673 $newinvoice_static->type = $valarray [
'type'];
4674 $newinvoice_static->paye = $valarray [
'paye'];
4675 $newinvoice_static->paid = $valarray [
'paye'];
4676 $newinvoice_static->multicurrency_code = (string) $valarray[
'multicurrency_code'];
4678 $optionsav .=
'<option value="'.$key.
'"';
4679 if ($key ==
GETPOST(
'fac_avoir')) {
4680 $optionsav .=
' selected';
4683 $newinvoice_static->fetch_optionals($key);
4684 $object->array_options = $newinvoice_static->array_options;
4687 $currency_code = $newinvoice_static->multicurrency_code;
4690 $optionsav .= $newinvoice_static->ref;
4691 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
4692 $optionsav .=
'</option>';
4695 print
'<div class="listofinvoicetype"><div class="">';
4696 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
4697 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
4698 $tmp .=
' disabled';
4702 print
'<script type="text/javascript">
4703 jQuery(document).ready(function() {
4704 if (jQuery("#radio_creditnote").is(":checked")) {
4705 jQuery("#radio_standard").prop("disabled", true);
4706 jQuery("#radio_deposit").prop("disabled", true);
4708 jQuery("#radio_standard").prop("disabled", false);
4709 jQuery("#radio_deposit").prop("disabled", false);
4711 if (! jQuery("#radio_creditnote").is(":checked")) {
4712 jQuery("#credit_note_options").hide();
4714 jQuery("#radio_creditnote").click(function() {
4715 jQuery("#credit_note_options").show();
4717 jQuery("#radio_standard, #radio_replacement, #radio_deposit, #radio_situation, #radio_situation_bis").click(function() {
4718 console.log("We click on a radio to close credit not options");
4719 jQuery("#credit_note_options").hide();
4723 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
4724 $text .=
'<select class="flat valignmiddle minwidth200" name="fac_avoir" id="fac_avoir"';
4725 if (!$optionsav || $invoice_predefined->id > 0) {
4726 $text .=
' disabled';
4730 $text .=
'<option value="-1">'.$langs->trans(
"InvoiceAvoirAskCombo").
'</option>';
4731 $text .= $optionsav;
4733 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
4735 $text .=
'</select>';
4736 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
4739 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
4740 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>";
4741 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>";
4746 print
'</div></div>'.
"\n";
4749 print
'<div class="listofinvoicetype"><div class="">';
4751 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
4753 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
4755 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
4757 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
4759 print
'</div></div>'.
"\n";
4780 foreach ($listtType as $type) {
4781 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
4783 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
4786 print
'<script type="text/javascript">
4787 $(document).ready(function() {
4788 var listType = {'.$jsListType.
'};
4789 $("[name=\'type\']").change(function() {
4790 console.log("change name=type");
4791 if ($( this ).prop("checked"))
4793 if(($( this ).val() in listType))
4795 $("#model").val(listType[$( this ).val()]).trigger("change");
4812 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
4813 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
4819 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
4823 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
4826 $defaulttpldir =
'/core/tpl';
4827 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array($defaulttpldir));
4828 foreach ($dirtpls as
$module => $reldir) {
4833 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
4835 if (file_exists($tpl)) {
4836 if (empty(
$conf->file->strict_mode)) {
4837 $res = @include $tpl;
4839 $res = include $tpl;
4854 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
4855 print img_picto(
'',
'action',
'class="pictofixedwidth"');
4856 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
4861 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
4862 print img_picto(
'',
'action',
'class="pictofixedwidth"');
4863 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
4868 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
4869 print img_picto(
'',
'payment',
'class="pictofixedwidth"');
4870 print $form->getSelectConditionsPaiements((
int) $cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
4875 $rwStyle =
'display:none;';
4876 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
4880 $retained_warranty =
GETPOSTINT(
'retained_warranty');
4881 if (empty($retained_warranty)) {
4882 if ($objectsrc !==
null && property_exists($objectsrc,
'retained_warranty') && !empty($objectsrc->retained_warranty)) {
4884 $retained_warranty = $objectsrc->retained_warranty;
4887 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
4889 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
4890 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
4893 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
4894 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
4895 if (empty($retained_warranty_fk_cond_reglement)) {
4896 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4897 if ($objectsrc instanceOf
Facture && !empty($objectsrc->retained_warranty_fk_cond_reglement)) {
4899 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
4902 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4905 print
'<script type="text/javascript">
4906 $(document).ready(function() {
4907 $("[name=\'type\']").change(function() {
4908 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
4910 $(".retained-warranty-line").show();
4911 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
4914 $(".retained-warranty-line").hide();
4915 $("#new-situation-invoice-retained-warranty").val("");
4919 $("[name=\'type\']:checked").trigger("change");
4925 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
4926 print img_picto(
'',
'bank',
'class="pictofixedwidth"');
4927 print $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth250 widthcentpercentminusx', 1);
4932 print
'<tr><td>'.$langs->trans(
'DefaultBankAccount').
'</td><td colspan="2">';
4933 print img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4934 print $form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth250 widthcentpercentminusx', 1);
4940 print
'<tr><td>'.$langs->trans(
'Source').
'</td><td>';
4941 print img_picto(
'',
'question',
'class="pictofixedwidth"');
4942 $form->selectInputReason((
string) $inputReasonId,
'input_reason_id',
'', 1,
'maxwidth250 widthcentpercentminusx');
4945 print
'<input type="hidden" name="input_reason_id" value="'.((string) $inputReasonId).
'">';
4949 if (
isModEnabled(
'project') && is_object($formproject)) {
4950 $langs->load(
'projects');
4951 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
4952 print img_picto(
'',
'project',
'class="pictofixedwidth"');
4954 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');
4955 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>';
4962 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
4963 print
'<td colspan="2" class="maxwidthonsmartphone">';
4964 $incoterm_id =
GETPOST(
'incoterm_id');
4965 $location_incoterms =
GETPOST(
'location_incoterms');
4966 if (empty($incoterm_id)) {
4967 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
4968 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
4970 print img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
4971 print $form->select_incoterms($incoterm_id, $location_incoterms);
4985 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
4986 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
4991 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
4992 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
4993 print $hookmanager->resPrint;
4994 if (empty($reshook)) {
4995 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
4998 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
4999 if ($soc->fetch_optionals() > 0) {
5000 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
5004 print
$object->showOptionals($extrafields,
'create', $parameters);
5008 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
5010 if (is_array($list) && count($list) > 0) {
5014 $paramkey =
'FACTURE_ADDON_PDF_'.$type;
5019 if (count($list) > 1) {
5020 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
5021 print
'<td colspan="2">';
5022 print img_picto(
'',
'pdf',
'class="pictofixedwidth"');
5023 print $form->selectarray(
'model', $list, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
5026 print
'<input type="hidden" name="model" value="'.$preselected.
'">';
5033 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
5034 print
'<td colspan="2" class="maxwidthonsmartphone">';
5035 print img_picto(
'',
'currency',
'class="pictofixedwidth"');
5036 print $form->selectMultiCurrency(((
GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth200 widthcentpercentminusx');
5043 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
5044 if (empty($dateexample)) {
5047 $substitutionarray = array(
5048 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
5049 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
5050 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
5051 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
5052 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
5053 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
5054 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
5055 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
5056 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
5057 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
5058 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
5061 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
5062 foreach ($substitutionarray as $key => $val) {
5063 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
5065 $htmltext .=
'</i>';
5070 print
'<td class="tdtop">';
5071 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
5073 print
'<td valign="top" colspan="2">';
5074 $doleditor =
new DolEditor(
'note_public', (
string) $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
5075 print $doleditor->Create(1);
5078 if (empty($user->socid)) {
5080 print
'<td class="tdtop">';
5081 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
5083 print
'<td valign="top" colspan="2">';
5084 $doleditor =
new DolEditor(
'note_private', (
string) $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
5085 print $doleditor->Create(1);
5091 if (!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($classname)) {
5092 $langs->loadLangs(array(
'orders',
'propal'));
5095 if ($origin ==
'contrat') {
5096 '@phan-var-force Contrat $objectsrc';
5098 $objectsrc->update_price(1,
'auto', 1);
5101 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
5102 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
5103 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
5104 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
5109 switch (get_class($objectsrc)) {
5111 $newclassname =
'CommercialProposal';
5114 $newclassname =
'Order';
5117 $newclassname =
'Sending';
5120 $newclassname =
'Contract';
5123 $newclassname =
'Intervention';
5126 $newclassname = get_class($objectsrc);
5130 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
5131 print
'<td colspan="2">';
5132 print $objectsrc->getNomUrl(1);
5134 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
5135 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
5136 setEventMessages(
'WarningBillExist',
null,
'warnings');
5137 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
5141 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht, 1, $langs, 1, -1,
'',
$conf->currency).
'</td></tr>';
5142 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
5143 if (
$mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
5144 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>";
5147 if (
$mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
5148 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>";
5150 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
5152 if (
isModEnabled(
'multicurrency') && $objectsrc->multicurrency_code !=
$conf->currency) {
5154 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
'</td></tr>';
5155 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
5156 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
5164 print $form->buttonsSaveCancel(
"CreateDraft");
5167 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
5170 $title = $langs->trans(
'ProductsAndServices');
5173 print
'<div class="div-table-responsive-no-min">';
5174 print
'<table class="noborder centpercent">';
5176 $objectsrc->printOriginLinesList(
'', $selectedLines);
5183} elseif ($id > 0 || !empty($ref)) {
5185 $langs->load(
'errors');
5186 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
5195 if ($user->socid > 0 && $user->socid !=
$object->socid) {
5199 $result =
$object->fetch_thirdparty();
5201 $result = $soc->fetch(
$object->socid);
5203 dol_print_error($db);
5205 $selleruserevenustamp =
$mysoc->useRevenueStamp();
5207 $totalpaid =
$object->getSommePaiement();
5208 $totalcreditnotes =
$object->getSumCreditNotesUsed();
5209 $totaldeposits =
$object->getSumDepositsUsed();
5215 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
5219 $multicurrency_totalpaid =
$object->getSommePaiement(1);
5220 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
5221 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
5222 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
5226 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
5227 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
5231 if (
$object->paye ||
$object->status == $object::STATUS_CLOSED) {
5234 $resteapayeraffiche = $resteapayer;
5237 $filterabsolutediscount =
"fk_facture_source IS NULL";
5238 $filtercreditnote =
"fk_facture_source IS NOT NULL";
5240 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
5241 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
5244 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
5245 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
5246 $absolute_discount =
price2num($absolute_discount,
'MT');
5247 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
5249 $nb_creditnote_notyetavailable = $soc->getOpenCreditNotesNotYetConvertedIntoDiscount(0);
5251 $author =
new User($db);
5252 if (
$object->user_creation_id) {
5253 $author->fetch(
$object->user_creation_id);
5256 $objectidnext =
$object->getIdReplacingInvoice();
5260 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
$object->picto, 0,
'',
'', 0,
'', 1);
5265 if ($action ==
'converttoreduc') {
5267 $type_fac =
'ExcessReceived';
5269 $type_fac =
'CreditNote';
5271 $type_fac =
'Deposit';
5275 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
5276 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
5277 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
5281 if ($action ==
'delete') {
5282 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
5283 $formquestion = array();
5286 $qualified_for_stock_change = 0;
5288 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5290 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5293 if ($qualified_for_stock_change) {
5294 $langs->load(
"stocks");
5295 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5299 if (
$conf->browser->name ==
'ie') {
5302 $formquestion = array(
5306 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
5308 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
5310 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
5313 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
5318 if ($action ==
'situationout') {
5319 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
5320 $label = $langs->trans(
"ConfirmOuting");
5321 $formquestion = array();
5326 &&
$object->is_last_in_cycle()
5327 && $usercanunvalidate
5329 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
5334 if ($action ==
'valid') {
5336 $objectref = substr(
$object->ref, 1, 4);
5337 if ($objectref ==
'PROV') {
5341 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
5343 $numref =
$object->getNextNumRef($soc);
5346 $numref = (string)
$object->ref;
5349 $text = $langs->trans(
'ConfirmValidateBill', $numref);
5351 $text .=
'<br><br>';
5352 $text .= img_picto(
'',
'warning',
'class="pictofixedwidth"').
' '.$langs->trans(
'WarningInvoiceCanNeverBeEdited');
5355 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
5356 $notify =
new Notify($db);
5358 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid, $object);
5360 $formquestion = array();
5363 $qualified_for_stock_change = 0;
5365 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5367 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5370 if ($qualified_for_stock_change) {
5371 $langs->load(
"stocks");
5372 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5373 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
5376 $warehouse_array = $warehouse->list_array();
5377 if (count($warehouse_array) == 1) {
5378 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
5379 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5382 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5384 $formquestion = array(
5390 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5394 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
5399 foreach (
$object->lines as $line) {
5400 $res = $line->fetch_product();
5402 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
5408 if ($nbMandated > 0) {
5410 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
5413 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
5418 $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, 0);
5423 if ($action ==
'modif') {
5426 $testvalue =
$object->isEditable();
5427 if ($testvalue < 0) {
5428 switch ($testvalue) {
5431 setEventMessages($langs->trans(
"DisabledBecauseDispatchedInBookkeeping"),
null,
'errors');
5435 setEventMessages($langs->trans(
"DisabledBecauseNotLastInvoice"),
null,
'errors');
5439 setEventMessages($langs->trans(
"DisabledBecauseNotLastSituationInvoice"),
null,
'errors');
5443 setEventMessages($langs->trans(
"DisabledBecauseThereIsAPayment"),
null,
'errors');
5447 setEventMessages($langs->trans(
"DisabledBecauseAlreadySentByEmail"),
null,
'errors');
5451 setEventMessages($langs->trans(
"DisabledBecauseAlreadyPrintedOnce"),
null,
'errors');
5455 setEventMessages($langs->trans(
"DisabledBecauseVersionProtected").(empty(
$object->error) ?
'' :
': '.
$object->error), null,
'errors');
5459 setEventMessages($langs->trans(
"DisabledBecauseNotEditable").(empty(
$object->error) ?
': UnknownReason' :
': '.
$object->error), null,
'errors');
5467 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
5468 $formquestion = array();
5471 $qualified_for_stock_change = 0;
5473 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5475 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5478 if ($qualified_for_stock_change) {
5479 $langs->load(
"stocks");
5480 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5481 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
5484 $warehouse_array = $warehouse->list_array();
5485 if (count($warehouse_array) == 1) {
5486 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
5487 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5490 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5492 $formquestion = array(
5498 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5502 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
5507 if ($action ==
'canceled') {
5511 $statusreplacement = 0;
5513 if ($objectidnext) {
5514 $facturereplacement =
new Facture($db);
5515 $facturereplacement->fetch($objectidnext);
5516 $statusreplacement = $facturereplacement->status;
5518 if ($objectidnext && $statusreplacement == 0) {
5519 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
5523 $close[1][
'code'] =
'badcustomer';
5524 $close[2][
'code'] =
'abandon';
5526 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5527 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
5529 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
5530 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
5533 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
5534 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
5537 $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'));
5539 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 300);
5544 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
5545 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
5547 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
5551 $close[$i][
'code'] = $object::CLOSECODE_DISCOUNTVAT;
5553 $close[$i][
'code'] = $object::CLOSECODE_BADDEBT;
5555 $close[$i][
'code'] = $object::CLOSECODE_BANKCHARGE;
5557 $close[$i][
'code'] = $object::CLOSECODE_WITHHOLDINGTAX;
5559 $close[$i][
'code'] = $object::CLOSECODE_OTHER;
5563 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
5565 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5567 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
5569 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
5571 $close[$i][
'label'] = $langs->trans(
"Other");
5575 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5577 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5579 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5581 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
5583 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
5587 foreach ($close as $key => $val) {
5588 $arrayreasons[$close[$key][
'code']] =
'<span class="small">'.$close[$key][
'reason'].
'</span>';
5592 $formquestion = array(
5593 'text' => $langs->trans(
"ConfirmClassifyPaidPartiallyQuestion"),
5594 0 => array(
'type' =>
'radio',
'name' =>
'close_code',
'label' =>
'',
'values' => $arrayreasons),
5595 1 => array(
'type' =>
'text',
'name' =>
'close_note',
'moreattr' =>
'placeholder = "'.$langs->trans(
"Comment").
'"',
'value' =>
'',
'morecss' =>
'minwidth300'),
5596 2 => array(
'type' =>
'separator')
5599 $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);
5602 if ($action ==
'deletepayment') {
5603 $payment_id =
GETPOST(
'paiement_id');
5604 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
5608 if ($action ==
'ask_deleteline') {
5609 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
5613 if ($action ==
'ask_subtotal_deleteline') {
5614 $langs->load(
"subtotals");
5615 $title =
"DeleteSubtotalLine";
5616 $question =
"ConfirmDeleteSubtotalLine";
5617 if (
GETPOST(
'type') ==
'title') {
5618 $formconfirm = array(array(
'type' =>
'checkbox',
'name' =>
'deletecorrespondingsubtotalline',
'label' => $langs->trans(
"DeleteCorrespondingSubtotalLine"),
'value' => 0));
5619 $title =
"DeleteTitleLine";
5620 $question =
"ConfirmDeleteTitleLine";
5622 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans($title), $langs->trans($question),
'confirm_delete_subtotalline', $formconfirm,
'no', 1);
5626 if ($action ==
'clone') {
5627 $filter =
'(s.client:IN:1,2,3)';
5629 $formquestion = array(
5630 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
$object->socid,
'socid', $filter, 1)),
5631 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
5634 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 0);
5638 if ($action ==
'add_title_line') {
5639 $langs->load(
'subtotals');
5641 $depth_array =
$object->getPossibleLevels($langs);
5643 } elseif ($action ==
'add_subtotal_line') {
5644 $langs->load(
'subtotals');
5646 $titles =
$object->getPossibleTitles();
5648 } elseif ($action ==
'add_text_line') {
5649 $langs->load(
'subtotals');
5654 if ($action ==
"remove_file_comfirm") {
5655 $file =
GETPOST(
'file',
'alpha');
5657 $formconfirm = $form->formconfirm(
5658 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
5659 $langs->trans(
'DeleteFileHeader'),
5660 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
5669 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
5670 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
5671 if (empty($reshook)) {
5672 $formconfirm .= $hookmanager->resPrint;
5673 } elseif ($reshook > 0) {
5674 $formconfirm = $hookmanager->resPrint;
5682 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
5684 $morehtmlref =
'<div class="refidno">';
5687 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5688 $morehtmlref .= $form->editfieldval(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'',
null,
null,
'', 1);
5689 $morehtmlref .=
'<br>';
5692 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5693 $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);
5695 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
5697 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'">'.$langs->trans(
"OtherBills").
'</a>)';
5701 $langs->load(
"projects");
5702 $morehtmlref .=
'<br>';
5703 if ($usercancreate) {
5704 $morehtmlref .= img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
5705 if ($action !=
'classify') {
5706 $morehtmlref .=
'<a class="editfielda" href="'.dolBuildUrl($_SERVER[
'PHP_SELF'], [
'action' =>
'classify',
'id' =>
$object->id],
true).
'">'.img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
5708 $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');
5710 if (!empty(
$object->fk_project)) {
5712 $proj->fetch(
$object->fk_project);
5713 $morehtmlref .= $proj->getNomUrl(1);
5715 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
5720 $morehtmlref .=
'</div>';
5722 $object->totalpaid = $totalpaid;
5723 $object->totalcreditnotes = $totalcreditnotes;
5724 $object->totaldeposits = $totaldeposits;
5727 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
5730 $parameters = array();
5732 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters, $object, $action);
5733 if (empty($reshook)) {
5734 print
'<div class="fichecenter">';
5735 print
'<div class="fichehalfleft">';
5736 print
'<div class="underbanner clearboth"></div>';
5738 print
'<table class="border centpercent tableforfield">';
5741 print
'<tr><td class="fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
5744 print
' '.$object->getSubtypeLabel(
'facture');
5747 $facreplaced =
new Facture($db);
5748 $facreplaced->fetch(
$object->fk_facture_source);
5749 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
5753 $facusing->fetch(
$object->fk_facture_source);
5754 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
5758 $object->getListIdAvoirFromInvoice();
5760 if (!empty(
$object->creditnote_ids)) {
5761 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
5763 foreach (
$object->creditnote_ids as $invoiceid) {
5769 $creditnote =
new Facture($db);
5770 $creditnote->fetch($invoiceid);
5771 print $creditnote->getNomUrl(1,
'', 32);
5775 if ($objectidnext > 0) {
5776 $facthatreplace =
new Facture($db);
5777 $facthatreplace->fetch($objectidnext);
5778 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
5783 $result = $discount->fetch(0,
$object->id);
5785 print
' <span class="opacitymediumbycolor paddingleft">';
5786 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
5787 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
5788 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
5790 print
'</span><br>';
5794 if (
$object->fk_fac_rec_source > 0) {
5796 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
5798 print
' <span class="opacitymediumbycolor paddingleft">';
5799 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
5800 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
5804 print
' <span class="opacitymediumbycolor paddingleft">';
5805 print $langs->transnoentities(
"GeneratedFromTemplate", $langs->trans(
"ObjectDeleted"));
5813 $langs->load(
"cashdesk");
5814 print
'<tr><td class="fieldname_type">';
5815 print
'<table class="nobordernopadding centpercent"><tr><td>';
5816 print $form->textwithpicto($langs->trans(
'PointOfSale'), $langs->trans(
'POSInfo'));
5818 if ($action !=
'editposinfo' && $usercancreate) {
5819 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>';
5821 print
'</tr></table>';
5822 print
'</td><td class="valuefield fieldname_type">';
5823 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" name="formposinfo">';
5824 print
'<input type="hidden" name="action" value="setposinfo">';
5825 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5826 if ($action ==
'editposinfo') {
5827 print
'<input type="text" class="maxwidth150" name="posmodule" placeholder="'.$langs->trans(
"POSModule").
'" value="'.
$object->module_source.
'"> ';
5828 print
'<input type="text" class="maxwidth100" name="posterminal" placeholder="'.$langs->trans(
"Terminal").
'" value="'.
$object->pos_source.
'">';
5829 print
'<input type="submit" class="button" name="submitposinfo" value="'.$langs->trans(
"Submit").
'">';
5832 print
'<span class="opacitymediumbycolor paddingleft">'.dolPrintHTML(ucfirst(
$object->module_source).
' - '.$langs->transnoentitiesnoconv(
"Terminal").
' '.
$object->pos_source).
'</span>';
5840 print
'<!-- Discounts -->'.
"\n";
5841 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
5845 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
5846 $defaulttpldir =
'/core/tpl';
5848 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array($defaulttpldir));
5849 foreach ($dirtpls as
$module => $reldir) {
5854 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
5856 if (file_exists($tpl)) {
5857 if (empty(
$conf->file->strict_mode)) {
5858 $res = @include $tpl;
5860 $res = include $tpl;
5872 print
'<table class="nobordernopadding centpercent"><tr><td>';
5873 print $langs->trans(
'DateInvoice');
5875 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
5876 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>';
5878 print
'</tr></table>';
5880 if ($action ==
'editinvoicedate') {
5881 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
5883 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
5898 print
'<table class="nobordernopadding centpercent"><tr><td>';
5899 print $langs->trans(
'DatePointOfTax');
5902 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>';
5904 print
'</tr></table>';
5906 if ($action ==
'editdate_pointoftax' && $editable) {
5907 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
5909 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
5917 print $form->editfieldkey(
'Source',
'input_reason',
'', $object, (
int) $usercancreate);
5918 print
'</td><td class="valuefield">';
5919 if ($action ==
'editinput_reason') {
5920 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'input_reason_id', 1,
'maxwidth250 widthcentpercentminusx');
5922 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'none');
5929 print
'<table class="nobordernopadding centpercent"><tr><td>';
5930 print $langs->trans(
'PaymentConditionsShort');
5933 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>';
5935 print
'</tr></table>';
5938 if ($action ==
'editconditions') {
5939 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
5941 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
5948 print
'<table class="nobordernopadding centpercent"><tr><td>';
5949 print $langs->trans(
'DateMaxPayment');
5952 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>';
5954 print
'</tr></table>';
5957 if ($action ==
'editpaymentterm') {
5958 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
5960 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
5962 print img_warning($langs->trans(
'Late'));
5970 print
'<table class="nobordernopadding centpercent"><tr><td>';
5971 print $langs->trans(
'PaymentMode');
5973 if ($action !=
'editmode' && $usercancreate) {
5974 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>';
5976 print
'</tr></table>';
5978 if ($action ==
'editmode') {
5979 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
5981 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'none',
'CRDT');
5987 print
'<tr><td class="nowrap">';
5988 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
5989 print $langs->trans(
'DefaultBankAccount');
5991 if (($action !=
'editbankaccount') && $usercancreate) {
5992 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>';
5994 print
'</tr></table>';
5996 if ($action ==
'editbankaccount') {
5997 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
5999 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
6008 print
'<table class="nobordernopadding centpercent"><tr><td>';
6009 print $langs->trans(
'IncotermLabel');
6010 print
'<td><td class="right">';
6011 if ($usercancreate) {
6012 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.img_edit().
'</a>';
6014 print
'</td></tr></table>';
6017 if ($action !=
'editincoterm') {
6018 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
6020 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
6027 print
'<table class="nobordernopadding centpercent"><tr><td>';
6028 print $langs->trans(
'Dispute');
6029 print
'<td><td class="right">';
6030 if ($usercancreate) {
6031 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editdispute_status&token='.
newToken().
'">'.img_edit().
'</a>';
6033 print
'</td></tr></table>';
6035 $liststatus = Facture::ARRAY_OF_DISPUTE_STATUS;
6036 if ($action !=
'editdispute_status') {
6037 if (
$object->dispute_status) {
6038 print $langs->trans($liststatus[
$object->dispute_status][
'label']);
6041 print
'<form enctype="multipart/form-data" action="'.DOL_URL_ROOT.
'/compta/facture/card.php" method="POST">';
6042 print
'<input type="hidden" name="action" value="set_dispute_status">';
6043 print
'<input type="hidden" name="token" value="'.newToken().
'">';
6044 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
6045 print
'<input type="hidden" name="page_y" value="">';
6046 print $form->selectarray(
'dispute_status', $liststatus,
$object->dispute_status, 0, 0, 0,
'', 1);
6047 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Save").
'">';
6055 print
'<table class="nobordernopadding centpercent"><tr><td>';
6056 print $langs->trans(
"Categories");
6057 print
'<td><td class="right">';
6058 if ($usercancreate) {
6059 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.img_edit().
'</a>';
6063 print
'</td></tr></table>';
6066 if ($action ==
'edittags') {
6067 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
6068 print
'<input type="hidden" name="action" value="settags">';
6069 print
'<input type="hidden" name="token" value="'.newToken().
'">';
6070 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
6071 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
6074 print $form->showCategories(
$object->id, Categorie::TYPE_INVOICE, 1);
6079 $displayWarranty =
false;
6082 $displayWarranty =
true;
6083 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
6084 $displayWarranty =
false;
6087 if ($displayWarranty) {
6089 print
'<tr class="retained-warranty-lines" ><td>';
6090 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
6091 print $langs->trans(
'RetainedWarranty');
6094 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>';
6097 print
'</tr></table>';
6100 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
6101 print
'<input type="hidden" name="action" value="setretainedwarranty">';
6102 print
'<input type="hidden" name="token" value="'.newToken().
'">';
6103 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
6104 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
6105 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
6113 print
'<tr class="retained-warranty-lines" ><td>';
6114 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
6115 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
6117 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
6118 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>';
6121 print
'</tr></table>';
6123 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
6124 if (
$object->date > $defaultDate) {
6130 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
6131 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
6132 print
'<input type="hidden" name="token" value="'.newToken().
'">';
6133 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
6134 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
6135 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
6136 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
6137 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
6138 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
6141 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->retained_warranty_fk_cond_reglement,
'none');
6142 if (!$displayWarranty) {
6143 print img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning',
'class="pictowarning valignmiddle" ');
6149 print
'<tr class="retained-warranty-lines" ><td>';
6150 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
6151 print $langs->trans(
'RetainedWarrantyDateLimit');
6154 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>';
6157 print
'</tr></table>';
6159 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
6160 if (
$object->date > $defaultDate) {
6165 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
6166 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
6167 print
'<input type="hidden" name="token" value="'.newToken().
'">';
6168 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
6170 print $form->selectDate($defaultDate,
'retained_warranty_date_limit');
6171 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
6183 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
6188 print
'<div class="fichehalfright">';
6190 print
'<!-- amounts -->'.
"\n";
6191 print
'<div class="underbanner clearboth"></div>'.
"\n";
6193 print
'<table class="border tableforfield centpercent">';
6195 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
6203 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
6204 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
6207 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
6213 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
6214 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
6217 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
6222 if ((
$mysoc->localtax1_assuj ==
"1" &&
$mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
6224 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1",
$mysoc->country_code) .
'</td>';
6225 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
6229 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
6234 if ((
$mysoc->localtax2_assuj ==
"1" &&
$mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
6236 print
'<td>' . $langs->transcountry(
"AmountLT2",
$mysoc->country_code) .
'</td>';
6237 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
6241 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
6247 if ($selleruserevenustamp) {
6248 print
'<tr><td class="titlefieldmiddle">';
6249 print
'<table class="nobordernopadding centpercent"><tr><td>';
6250 print $langs->trans(
'RevenueStamp');
6252 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
6253 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>';
6255 print
'</tr></table>';
6256 print
'</td><td class="nowrap amountcard right">';
6257 if ($action ==
'editrevenuestamp') {
6258 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
6259 print
'<input type="hidden" name="token" value="'.newToken().
'">';
6260 print
'<input type="hidden" name="action" value="setrevenuestamp">';
6261 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
6262 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
6263 print $formother->select_revenue_stamp(
'',
'revenuestamp_type',
$mysoc->country_code);
6264 print
' → <span id="revenuestamp_span"></span>';
6265 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
6268 $(document).ready(function(){
6269 js_recalculate_revenuestamp();
6270 $('select[name=revenuestamp_type]').on('change',function(){
6271 js_recalculate_revenuestamp();
6274 function js_recalculate_revenuestamp(){
6275 var valselected = $('select[name=revenuestamp_type]').val();
6276 console.log('Calculate revenue stamp from '+valselected);
6278 if (valselected.indexOf('%') == -1)
6280 revenue = valselected;
6284 var revenue_type = parseFloat(valselected);
6285 var amount_net = ".round(
$object->total_ht, 2).
";
6286 revenue = revenue_type * amount_net / 100;
6287 revenue = revenue.toFixed(2);
6289 $('#revenuestamp_val').val(revenue);
6290 $('#revenuestamp_span').html(revenue);
6301 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
6302 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
6305 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
6320 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
6323 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
6326 if ($selleruserevenustamp) {
6336 $total_prev_ht = $total_prev_ttc = 0;
6337 $total_global_ht = $total_global_ttc = 0;
6341 print
'<!-- List of situation invoices -->';
6342 print
'<div class="div-table-responsive-no-min">';
6343 print
'<table class="noborder paymenttable centpercent situationstable">';
6345 print
'<tr class="liste_titre">';
6346 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
6348 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
6351 print
'<td class="right"></td>';
6353 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
6354 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
6355 print
'<td width="18"> </td>';
6358 if (count(
$object->tab_previous_situation_invoice) > 0) {
6361 $current_situation_counter = array();
6362 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
6363 $tmptotalallpayments = $prev_invoice->getSommePaiement(0);
6364 $tmptotalallpayments += $prev_invoice->getSumDepositsUsed(0);
6365 $tmptotalallpayments += $prev_invoice->getSumCreditNotesUsed(0);
6367 $total_prev_ht += $prev_invoice->total_ht;
6368 $total_prev_ttc += $prev_invoice->total_ttc;
6370 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
6371 print
'<tr class="oddeven">';
6372 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
6374 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
6376 print
'<td class="right"></td>';
6378 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
6379 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
6380 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalallpayments).
'</td>';
6385 $totalallpayments =
$object->getSommePaiement(0);
6386 $totalallpayments +=
$object->getSumCreditNotesUsed(0);
6387 $totalallpayments +=
$object->getSumDepositsUsed(0);
6389 $total_global_ht += $total_prev_ht;
6390 $total_global_ttc += $total_prev_ttc;
6391 $total_global_ht +=
$object->total_ht;
6392 $total_global_ttc +=
$object->total_ttc;
6396 print
'<tr class="oddeven">';
6397 print
'<td>'.$object->getNomUrl(1).
'</td>';
6399 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
6401 print
'<td class="right"></td>';
6403 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
6404 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
6405 print
'<td class="right">'.$object->getLibStatut(3, $totalallpayments).
'</td>';
6409 print
'<tr class="oddeven">';
6410 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'SituationTotalAfterInvoice').
'</b></td>';
6413 foreach ($current_situation_counter as $sit) {
6414 $curSign = $sit > 0 ?
'+' :
'-';
6415 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
6417 print
' '.$curSign.
' ';
6419 print $curType.abs($sit);
6426 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6427 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6428 print
'<td width="18"> </td>';
6432 if (count(
$object->tab_next_situation_invoice) > 0) {
6434 $total_next_ht = $total_next_ttc = 0;
6436 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
6437 $next_totalpaid = $next_invoice->getSommePaiement(0);
6438 $next_totalcreditnotes = $next_invoice->getSumCreditNotesUsed(0);
6439 $next_totaldeposits = $next_invoice->getSumDepositsUsed(0);
6440 $total_next_ht += $next_invoice->total_ht;
6441 $total_next_ttc += $next_invoice->total_ttc;
6443 print
'<tr class="oddeven">';
6444 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
6446 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
6448 print
'<td class="right"></td>';
6450 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
6451 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
6452 print
'<td class="right">'.$next_invoice->getLibStatut(3, $next_totalpaid + $next_totalcreditnotes + $next_totaldeposits).
'</td>';
6456 $total_global_ht += $total_next_ht;
6457 $total_global_ttc += $total_next_ttc;
6459 print
'<tr class="oddeven">';
6460 print
'<td colspan="3" class="right"></td>';
6462 print
'<td class="right"></td>';
6464 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6465 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6466 print
'<td width="18"> </td>';
6475 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
6481 print
'<!-- List of payments already done -->';
6482 print
'<div class="div-table-responsive-no-min">';
6483 print
'<table class="noborder paymenttable centpercent">';
6485 print
'<tr class="liste_titre">';
6486 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
6487 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
6488 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
6490 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
6492 print
'<td class="liste_titre"></td>';
6493 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
6497 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
6498 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
6499 $sql .=
' pf.amount,';
6500 $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';
6501 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
6502 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
6503 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
6504 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
6505 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
6506 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
6507 $sql .=
' ORDER BY p.datep, p.tms';
6509 $result = $db->query($sql);
6511 $num = $db->num_rows($result);
6516 $objp = $db->fetch_object($result);
6518 $paymentstatic->id = $objp->rowid;
6519 $paymentstatic->datepaye = $db->jdate($objp->dp);
6520 $paymentstatic->ref = $objp->ref;
6521 $paymentstatic->num_payment = $objp->num_payment;
6522 $paymentstatic->paiementcode = $objp->payment_code;
6524 print
'<tr class="oddeven">';
6525 print
'<td class="nowraponall">';
6526 print $paymentstatic->getNomUrl(1);
6529 $dateofpayment = $db->jdate($objp->dp);
6531 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
6538 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
6539 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
6541 $bankaccountstatic->id = $objp->baid;
6542 $bankaccountstatic->ref = $objp->baref;
6543 $bankaccountstatic->label = $objp->baref;
6544 $bankaccountstatic->number = $objp->banumber;
6545 $bankaccountstatic->currency_code = $objp->bacurrency_code;
6548 $bankaccountstatic->account_number = $objp->account_number;
6551 $accountingjournal->fetch($objp->fk_accountancy_journal);
6552 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
6555 print
'<td class="nowraponall">';
6556 if ($bankaccountstatic->id) {
6557 print $bankaccountstatic->getNomUrl(1,
'transactions');
6563 print
'<td class="center">';
6565 $paiement->fetch($objp->rowid);
6567 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
6574 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
6583 dol_print_error($db);
6589 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6590 print
'<span class="opacitymedium">';
6592 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
6594 print $langs->trans(
'AlreadyPaid');
6596 print
'</span></td>';
6598 print
'<td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td>';
6601 $resteapayeraffiche = $resteapayer;
6602 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
6603 $cssforamountpaymentcompletenoresize =
'amountpaymentcompletenoresize';
6606 $creditnoteamount = 0;
6608 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
6609 $sql .=
" re.description, re.fk_facture_source";
6610 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
6611 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
6612 $resql = $db->query($sql);
6614 $num = $db->num_rows($resql);
6618 $obj = $db->fetch_object($resql);
6619 $invoice->fetch($obj->fk_facture_source);
6621 print
'<td colspan="'.$nbcols.
'" class="right">';
6622 print
'<span class="opacitymedium">';
6624 print $langs->trans(
"CreditNote").
' ';
6627 print $langs->trans(
"Deposit").
' ';
6629 print $invoice->getNomUrl(0);
6633 print
'<td class="right">';
6634 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
6635 print img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
6639 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
6643 $creditnoteamount += $obj->amount_ttc;
6646 $depositamount += $obj->amount_ttc;
6650 dol_print_error($db);
6656 print
'<td colspan="'.$nbcols.
'" class="nowrap right">';
6657 print
'<span class="opacitymedium">';
6658 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
6662 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6664 $resteapayeraffiche = 0;
6665 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6666 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6671 print
'<td colspan="'.($nbcols + 1).
'" class="nowrap right">';
6672 print
'<span class="opacitymedium">';
6673 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
6677 print
'<td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td>';
6680 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6681 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6686 print
'<td colspan="'.($nbcols + 1).
'" class="nowrap right">';
6687 print
'<span class="opacitymedium">';
6688 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
6692 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6694 $resteapayeraffiche = 0;
6695 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6696 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6701 print
'<td colspan="'.($nbcols + 1).
'" class="nowrap right">';
6702 $text = $langs->trans(
"HelpAbandonOther");
6704 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
6706 print
'<span class="opacitymedium">';
6708 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
6712 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6714 $resteapayeraffiche = 0;
6715 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6716 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6721 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6722 print
'<span class="opacitymedium">';
6723 print $langs->trans(
"Billed");
6726 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
6731 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6732 print
'<span class="opacitymedium">';
6733 print $langs->trans(
'RemainderToPay');
6734 if ($resteapayeraffiche < 0) {
6735 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6740 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
6746 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6747 print
'<span class="opacitymedium">';
6748 print $langs->trans(
'RemainderToPayMulticurrency');
6749 if ($resteapayeraffiche < 0) {
6750 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6755 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcompletenoresize)).
'">';
6762 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
6764 if (
$object->isSituationInvoice()) {
6765 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
6768 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
6771 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
6774 print
'<td colspan="'.($nbcols + 1).
'" class="right">'.$langs->trans(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')).
' :</td>';
6776 print
'<td class="right">'.price($billedWithRetainedWarranty).
'</td>';
6781 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6782 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
6783 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
6786 print
'<td class="right">'.price($retainedWarranty).
'</td>';
6790 $resteapayeraffiche = $resteapayer;
6791 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6792 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6796 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6797 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
6800 print
'<td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td>';
6805 print
'<td colspan="'.($nbcols + 1).
'" class="right"><span class="opacitymedium">'.$langs->trans(
"Billed").
'</span></td>';
6807 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
6811 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
6812 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
6813 if ($resteapayeraffiche > 0) {
6814 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6816 print
'</span></td>';
6818 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche);
6827 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6828 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
6829 if ($resteapayeraffiche > 0) {
6830 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6835 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>';
6850 $formmargin->displayMarginInfos($object);
6856 print
'<div class="clearboth"></div><br>';
6859 $blocname =
'contacts';
6860 $title = $langs->trans(
'ContactsAddresses');
6861 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6865 $blocname =
'notes';
6866 $title = $langs->trans(
'Notes');
6867 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6871 $result =
$object->getLinesArray();
6875 global $inputalsopricewithtax;
6876 $inputalsopricewithtax = 1;
6878 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
6879 <input type="hidden" name="token" value="' .
newToken().
'">
6880 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
6881 <input type="hidden" name="mode" value="">
6882 <input type="hidden" name="page_y" value="">
6883 <input type="hidden" name="id" value="' .
$object->id.
'">
6884 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
6887 if (!empty(
$conf->use_javascript_ajax) &&
$object->status == 0) {
6889 include DOL_DOCUMENT_ROOT.
'/core/tpl/subtotal_ajaxrow.tpl.php';
6891 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
6895 print
'<div class="div-table-responsive-no-min">';
6896 print
'<table id="tablelines" class="noborder noshadow centpercent nomarginbottom">';
6900 $object->printObjectLines($action,
$mysoc, $soc, $lineid, 1);
6904 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
6905 if ($action !=
'editline' && $action !=
'selectlines') {
6908 $parameters = array();
6909 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
6911 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
6913 if (empty($reshook)) {
6917 $parameters = array();
6918 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters, $object, $action);
6932 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
6933 print
'<div class="tabsAction">';
6935 $parameters = array();
6936 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
6937 if (empty($reshook)) {
6940 'class' =>
'classfortooltip',
6947 $ventilExportCompta =
$object->getVentilExportCompta();
6949 if ($ventilExportCompta == 0) {
6951 if (!$objectidnext &&
$object->is_last_in_cycle()) {
6952 if ($usercanunvalidate) {
6953 unset($params[
'attr'][
'title']);
6954 print dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
true, $params);
6956 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
6957 print dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
false, $params);
6959 } elseif (!
$object->is_last_in_cycle()) {
6960 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
6961 print dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6963 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
6964 print dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6968 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6969 print dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6974 $result = $discount->fetch(0,
$object->id);
6982 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
6983 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
6984 unset($params[
'attr'][
'title']);
6985 print dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
6987 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6988 print dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
6995 $langs->load(
"contracts");
6997 if ($usercancreatecontract) {
6998 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>';
7006 $langs->load(
"subtotals");
7008 $url_button = array();
7010 $url_button[] = array(
7011 'lang' =>
'subtotals',
7013 'perm' => (
bool) $usercancreate,
7014 'label' => $langs->trans(
'AddTitleLine'),
7015 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_title_line&token='.
newToken()
7018 $url_button[] = array(
7019 'lang' =>
'subtotals',
7021 'perm' => (
bool) $usercancreate,
7022 'label' => $langs->trans(
'AddSubtotalLine'),
7023 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_subtotal_line&token='.
newToken()
7026 $url_button[] = array(
7027 'lang' =>
'subtotals',
7029 'perm' => (
bool) $usercancreate,
7030 'label' => $langs->trans(
'AddTextLine'),
7031 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_text_line&token='.
newToken()
7033 print dolGetButtonAction(
'', $langs->trans(
'SubTotal'),
'default', $url_button,
'',
true);
7040 if ($usercanvalidate) {
7041 unset($params[
'attr'][
'title']);
7042 print dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
7047 if (empty($user->socid)) {
7049 if ($objectidnext) {
7050 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
7051 print dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
7054 unset($params[
'attr'][
'title']);
7055 print dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
7057 unset($params[
'attr'][
'title']);
7058 print dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
7066 if ($resteapayer > 0) {
7067 if ($usercancreatewithdrarequest) {
7068 if (!$objectidnext &&
$object->close_code !=
'replaced') {
7069 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>';
7071 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
7083 $langs->load(
"cashdesk");
7084 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
7085 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
7090 if ($objectidnext) {
7091 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
7095 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
7096 print dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
7100 unset($params[
'attr'][
'title']);
7101 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);
7106 $sumofpayment = $totalpaid;
7107 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
7113 if ($resteapayer == 0) {
7114 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
7116 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
7122 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
7126 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
7128 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>';
7135 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
7137 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
7151 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
7152 print dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
7154 unset($params[
'attr'][
'title']);
7155 print dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken(),
'',
true, $params);
7161 if ($totalpaid > 0 || $totalcreditnotes > 0) {
7163 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
7166 if ($objectidnext) {
7167 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
7169 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled&token='.
newToken().
'">'.$langs->trans(
'ClassifyCanceled').
'</a>';
7176 if ($usercancreate &&
$object->isSituationInvoice() && (
$object->status == 1 ||
$object->status == 2)) {
7177 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
7178 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
7179 } elseif (!
$object->is_last_in_cycle()) {
7180 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
7182 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
7188 if (!$objectidnext) {
7189 print
'<!-- button create credit note -->';
7190 if (
$object->module_source ==
'takepos') {
7191 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseInvoiceGeneratedBy", $langs->transnoentitiesnoconv(
'TakePOS')).
'">'.$langs->trans(
"CreateCreditNote").
'</a>';
7193 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>';
7200 &&
$object->isSituationInvoice()
7203 &&
$object->is_last_in_cycle()
7206 if ($usercanunvalidate) {
7207 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>';
7209 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
7215 if (!$objectidnext && count(
$object->lines) > 0) {
7216 unset($params[
'attr'][
'title']);
7217 print dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
7223 unset($params[
'attr'][
'title']);
7224 print dolGetButtonAction($langs->trans(
'ToClone'), $langs->trans(
'ToClone'),
'clone', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice&token='.
newToken(),
'',
true, array(
'attr' => array(
'class' =>
'reposition')));
7229 &&
$object->isSituationInvoice()
7232 &&
$object->situation_counter > 1
7233 &&
$object->is_last_in_cycle()
7234 && $usercanunvalidate
7237 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout&token='.
newToken().
'">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
7239 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
7244 $isErasable =
$object->is_erasable();
7247 if ($isErasable == -6) {
7248 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadySentByEmail');
7249 } elseif ($isErasable == -5) {
7250 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadyPrintedOnce');
7251 } elseif ($isErasable == -4) {
7252 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
7253 } elseif ($isErasable == -3) {
7254 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
7255 } elseif ($isErasable == -2) {
7256 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
7257 } elseif ($isErasable == -1) {
7258 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
7259 } elseif ($isErasable <= 0) {
7260 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable').(empty(
$object->error) ?
': UnknownReason' :
': '.$object->error);
7261 } elseif ($objectidnext) {
7262 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
7264 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
7265 $enableDelete =
false;
7267 if ($isErasable > 0 && ! $objectidnext) {
7268 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
7269 $enableDelete =
true;
7271 unset($params[
'attr'][
'title']);
7272 print dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, array(
'attr' => array(
'class' =>
'reposition')));
7274 unset($params[
'attr'][
'title']);
7275 print dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
7282 if (
GETPOST(
'modelselected',
'alpha')) {
7283 $action =
'presend';
7285 if ($action !=
'prerelance' && $action !=
'presend') {
7286 print
'<div class="fichecenter"><div class="fichehalfleft">';
7287 print
'<a name="builddoc"></a>';
7292 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
7293 $genallowed = $usercanread;
7294 $delallowed = $usercancreate;
7295 $tooltipAfterComboOfModels =
'';
7297 $tooltipAfterComboOfModels = $langs->trans(
"AccordingToYourSetupTheFileWillBeConcatenated",
getDolGlobalString(
'MAIN_INFO_INVOICE_TERMSOFSALE'));
7300 print $formfile->showdocuments(
7320 'remove_file_comfirm',
7321 $tooltipAfterComboOfModels
7324 $somethingshown = $formfile->numoffiles;
7327 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice'), 1);
7328 $linktoelem = $tmparray[
'linktoelem'];
7329 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
7330 print $htmltoenteralink;
7332 $compatibleImportElementsList =
false;
7336 $compatibleImportElementsList = array(
'commande',
'propal',
'subscription');
7338 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
7342 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
7343 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
7344 $useonlinepayment = count($validpaymentmethod);
7347 print
'<br><!-- Link to pay -->'.
"\n";
7348 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
7349 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
7352 print
'</div><div class="fichehalfright">';
7356 $morehtmlcenter =
'<div class="nowraponall">';
7357 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullConversation'),
'',
'fa fa-comments imgforviewmode', DOL_URL_ROOT.
'/compta/facture/messaging.php?id='.
$object->id);
7358 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
7359 $morehtmlcenter .=
'</div>';
7362 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
7364 $somethingshown = $formactions->showactions($object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
7366 print
'</div></div>';
7371 $modelmail =
'facture_send';
7372 $defaulttopic =
'SendBillRef';
7374 $trackid =
'inv'.$object->id;
7376 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
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='', $placeholder='')
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)
Class to manage Dolibarr users.
if(! $sortfield) if(! $sortorder) $module
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, $processnotimeasnoon=0)
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.
$date_start
Variables from include:
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...
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
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.
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
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'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
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...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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_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.
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
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, $notused, $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.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
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.