47require
'../../main.inc.php';
57require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
58require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
59require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
60require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
61require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
62require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
63require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
64require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
65require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
66require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
67require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
68require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
69require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
70require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
72 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
75 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
76 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
78require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
81 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
84 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
88$langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
90 $langs->load(
'incoterm');
93 $langs->load(
'margins');
97$action =
GETPOST(
'action',
'aZ09');
98$confirm =
GETPOST(
'confirm',
'alpha');
99$cancel =
GETPOST(
'cancel',
'alpha');
100$backtopage =
GETPOST(
'backtopage',
'alpha');
101$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
107$origin =
GETPOST(
'origin',
'alpha');
111$ref_client =
GETPOST(
'ref_client',
'alpha');
112$inputReasonId =
GETPOSTINT(
'input_reason_id');
115$selectedLines =
GETPOST(
'toselect',
'array:int');
128$extrafields->fetch_name_optionals_label(
$object->table_element);
131$total_global_ttc = 0;
132$displayWarranty =
false;
133$statusreplacement = 0;
135$price_base_type =
'';
136$array_options = array();
139if ($id > 0 || !empty($ref)) {
140 if ($action !=
'add') {
142 $fetch_situation =
false;
144 $fetch_situation =
true;
146 $ret =
$object->fetch($id, $ref,
'', 0, $fetch_situation);
147 if ($ret > 0 && isset(
$object->fk_project)) {
148 $ret =
$object->fetchProject();
154$hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
157$usercanread = $user->hasRight(
"facture",
"lire");
158$usercancreate = $user->hasRight(
"facture",
"creer");
159$usercanissuepayment = $user->hasRight(
"facture",
"paiement");
160$usercandelete = $user->hasRight(
"facture",
"supprimer") || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
161$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
164$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'validate')));
165$usercansend = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercanread) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'send')));
166$usercanreopen = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'reopen')));
168 $usercanreopen =
false;
170$usercanunvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'unvalidate')));
171$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
174$usercancreatemargin = $user->hasRight(
'margins',
'creer');
175$usercanreadallmargin = $user->hasRight(
'margins',
'liretous');
176$usercancreatewithdrarequest = $user->hasRight(
'prelevement',
'bons',
'creer');
178$permissionnote = $usercancreate;
179$permissiondellink = $usercancreate;
180$permissiontoedit = $usercancreate;
181$permissiontoadd = $usercancreate;
182$permissiontoeditextra = $usercancreate;
183if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
185 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
189$retainedWarrantyInvoiceAvailableType = array();
191 $retainedWarrantyInvoiceAvailableType = explode(
'+',
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY'));
196 $socid = $user->socid;
209$parameters = array(
'socid' => $socid);
210$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
215if (empty($reshook)) {
216 $backurlforlist =
dolBuildUrl(DOL_URL_ROOT.
'/compta/facture/list.php');
218 if (empty($backtopage) || ($cancel && empty($id))) {
219 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
220 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
221 $backtopage = $backurlforlist;
223 $backtopage =
dolBuildUrl(DOL_URL_ROOT.
'/compta/facture/card.php', [
'id' => ((!empty($id) && $id > 0) ? $id :
'__ID__')]);
229 if (!empty($backtopageforcancel)) {
230 header(
"Location: ".$backtopageforcancel);
232 } elseif (!empty($backtopage)) {
233 header(
"Location: ".$backtopage);
239 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
241 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
243 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
246 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
248 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'IdThirdParty')),
null,
'errors');
251 '@phan-var-force Facture $objectutil';
254 $objectutil->socid = $socid;
255 $result = $objectutil->createFromClone($user, $id, (
GETPOSTISSET(
'entity') ?
GETPOSTINT(
'entity') : null));
257 $warningMsgLineList = array();
259 foreach ($objectutil->lines as $line) {
260 if (!is_object($line->product)) {
261 $line->fetch_product();
263 if (is_object($line->product) && $line->product->id > 0) {
264 if (empty($line->product->status)) {
265 $warningMsgLineList[$line->id] = $langs->trans(
'WarningLineProductNotToSell', $line->product->ref);
269 if (!empty($warningMsgLineList)) {
273 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?facid=' . $result);
276 $langs->load(
"errors");
281 } elseif ($action ==
'reopen' && $usercanreopen) {
285 $result =
$object->setUnpaid($user);
287 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
293 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
298 $idwarehouse =
GETPOST(
'idwarehouse');
300 $qualified_for_stock_change = 0;
302 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
304 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
307 $isErasable =
$object->is_erasable();
309 if (($isErasable > 0) || ($usercancreate && $isErasable == 1)) {
310 $result =
$object->delete($user, 0, (
int) $idwarehouse);
312 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
319 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
329 $outputlangs = $langs;
335 $newlang =
$object->thirdparty->default_lang;
337 if (!empty($newlang)) {
339 $outputlangs->setDefaultLang($newlang);
340 $outputlangs->load(
'products');
344 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
347 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
354 } elseif ($action ==
'confirm_delete_subtotalline' && $confirm ==
'yes' && $usercancreate) {
359 $result =
$object->deleteSubtotalLine($langs,
GETPOSTINT(
'lineid'), (
bool)
GETPOST(
'deletecorrespondingsubtotalline'));
364 $outputlangs = $langs;
370 $newlang =
$object->thirdparty->default_lang;
372 if (!empty($newlang)) {
374 $outputlangs->setDefaultLang($newlang);
375 $outputlangs->load(
'products');
379 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
382 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
389 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
392 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
393 if ($result > 0 && $discount->fk_facture ==
$object->id) {
394 $discount->unlink_invoice();
398 } elseif ($action ==
'valid' && $usercancreate) {
402 if ((preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) &&
409 $last_of_type =
$object->willBeLastOfSameType(
true);
410 if (empty(
$object->date_validation) && !$last_of_type[0]) {
420 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
429 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
438 $array_of_total_ht_per_vat_rate = array();
439 $array_of_total_ht_devise_per_vat_rate = array();
440 foreach (
$object->lines as $line) {
442 $vat_src_code_for_line =
'';
443 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
444 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
446 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
447 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
449 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
450 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
454 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
455 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
456 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
458 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
459 if (
$object->type == $object::TYPE_DEPOSIT) {
460 $langs->load(
"errors");
462 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
466 $tmpvatratetoshow = explode(
'_', $vatrate);
467 $tmpvatratetoshow[0] = round((
float) $tmpvatratetoshow[0], 2);
469 if ($tmpvatratetoshow[0] != 0) {
470 $langs->load(
"errors");
471 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", (
string) $tmpvatratetoshow[0]),
null,
'errors');
479 } elseif ($action ==
'classin' && $usercancreate) {
485 } elseif ($action ==
'setposinfo' && $usercancreate) {
489 $result =
$object->update($user);
493 } elseif ($action ==
'setmode' && $usercancreate) {
499 } elseif ($action ==
'setretainedwarrantyconditions' && $usercancreate) {
502 $object->retained_warranty_fk_cond_reglement = 0;
503 $result =
$object->setRetainedWarrantyPaymentTerms(
GETPOSTINT(
'retained_warranty_fk_cond_reglement'));
508 $old_rw_date_lim_reglement =
$object->retained_warranty_date_limit;
509 $new_rw_date_lim_reglement =
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
510 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
511 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
516 $result =
$object->update($user);
520 } elseif ($action ==
'setretainedwarranty' && $usercancreate) {
526 } elseif ($action ==
'setretainedwarrantydatelimit' && $usercancreate) {
528 $result =
$object->setRetainedWarrantyDateLimit(
GETPOSTDATE(
'retained_warranty_date_limit'));
532 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
533 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
534 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
536 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
538 $old_date_lim_reglement =
$object->date_lim_reglement;
540 if (empty($newdate)) {
541 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
542 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.
$id.
'&action=editinvoicedate&token='.
newToken());
547 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
549 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
554 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
555 if ($new_date_lim_reglement) {
556 $object->date_lim_reglement = $new_date_lim_reglement;
561 $result =
$object->update($user);
564 $action =
'editinvoicedate';
566 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
571 $object->date_pointoftax = $date_pointoftax;
572 $result =
$object->update($user);
576 } elseif ($action ==
'setconditions' && $usercancreate) {
578 $object->cond_reglement_code = 0;
579 $object->cond_reglement_id = 0;
592 $old_date_lim_reglement =
$object->date_lim_reglement;
593 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
594 if ($new_date_lim_reglement) {
595 $object->date_lim_reglement = $new_date_lim_reglement;
600 $result =
$object->update($user);
612 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
616 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
617 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
619 $result =
$object->update($user);
623 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
626 $result =
$object->update($user);
633 $outputlangs = $langs;
636 $newlang =
GETPOST(
'lang_id',
'aZ09');
639 $newlang =
$object->thirdparty->default_lang;
641 if (!empty($newlang)) {
643 $outputlangs->setDefaultLang($newlang);
644 $outputlangs->load(
'products');
649 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
655 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
660 } elseif ($action ==
'set_dispute_status' && $usercancreate) {
661 $result =
$object->setStatut(
GETPOSTINT(
'dispute_status'),
null,
'facture',
'FACTURE_MODIFY',
'dispute_status');
665 } elseif ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
670 } elseif ($action ==
'setbankaccount' && $usercancreate) {
675 } elseif ($action ==
'setremisepercent' && $usercancreate) {
681 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
700 $newremaintopay =
$object->getRemainToPay(0);
701 if ($newremaintopay == 0) {
708 if (
GETPOSTINT(
"remise_id_for_payment") > 0) {
709 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
711 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
715 $remaintopay =
$object->getRemainToPay(0);
719 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
723 $result = $discount->link_to_invoice(0, $id);
736 $newremaintopay =
$object->getRemainToPay(0);
737 if ($newremaintopay == 0) {
751 $outputlangs = $langs;
754 $newlang =
GETPOST(
'lang_id',
'aZ09');
758 $newlang =
$object->thirdparty->default_lang;
760 if (!empty($newlang)) {
762 $outputlangs->setDefaultLang($newlang);
766 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
771 } elseif ($action ==
'setref' && $usercancreate) {
773 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', 0,
'',
'', $user,
'BILL_MODIFY');
777 } elseif ($action ==
'setref_client' && $usercancreate) {
783 } elseif ($action ==
'setdemandreason' && $usercancreate) {
784 $result =
$object->setInputReason($inputReasonId);
788 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
797 $qualified_for_stock_change = 0;
799 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
801 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
804 if ($qualified_for_stock_change) {
805 if (!$idwarehouse || $idwarehouse == - 1) {
807 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
814 $result =
$object->validate($user,
'', $idwarehouse);
818 $outputlangs = $langs;
821 $newlang =
GETPOST(
'lang_id',
'aZ09');
824 $newlang =
$object->thirdparty->default_lang;
826 if (!empty($newlang)) {
828 $outputlangs->setDefaultLang($newlang);
829 $outputlangs->load(
'products');
835 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
848 } elseif ($action ==
'confirm_modif' && $usercanunvalidate && !
getDolGlobalString(
'INVOICE_CAN_NEVER_BE_EDITED')) {
857 $qualified_for_stock_change = 0;
859 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
861 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
864 if ($qualified_for_stock_change) {
865 if (!$idwarehouse || $idwarehouse == -1) {
867 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
876 $sql =
'SELECT pf.amount';
877 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'paiement_facture as pf';
878 $sql .=
' WHERE pf.fk_facture = ' . ((int)
$object->id);
880 $result =
$db->query($sql);
883 $num =
$db->num_rows($result);
886 $objp =
$db->fetch_object($result);
887 $totalpaid += $objp->amount;
894 $resteapayer =
$object->total_ttc - $totalpaid;
897 $ventilExportCompta =
$object->getVentilExportCompta();
900 if ($ventilExportCompta == 0) {
903 $result =
$object->setDraft($user, $idwarehouse);
910 $outputlangs = $langs;
913 $newlang =
GETPOST(
'lang_id',
'aZ09');
916 $newlang =
$object->thirdparty->default_lang;
918 if (!empty($newlang)) {
920 $outputlangs->setDefaultLang($newlang);
921 $outputlangs->load(
'products');
926 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
932 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
935 $result =
$object->setPaid($user);
939 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
942 $close_code =
GETPOST(
"close_code",
'restricthtml');
943 $close_note =
GETPOST(
"close_note",
'restricthtml');
946 if (
isModEnabled(
'tax') && $close_code == $object::CLOSECODE_WITHHOLDINGTAX) {
947 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
949 $amount = (float) ($resteapayer > 0 ? $resteapayer * -1 : $resteapayer);
953 $tempTva->datev =
$object->date;
954 $tempTva->datep =
$object->date;
955 $tempTva->amount = $amount;
956 $tempTva->label = $langs->trans(
'WithholdingTax') .
' - ' .
$object->ref;
958 $valid = $tempTva->getIdForLabel($tempTva->label);
960 $ret = $tempTva->create($user);
964 $tempTva->setPaid($user);
974 setEventMessages($langs->trans(
'LabelWithholdingExist'), $tempTva->errors,
'errors');
980 $result =
$object->setPaid($user, $close_code, $close_note);
988 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
990 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
993 $close_code =
GETPOST(
"close_code",
'restricthtml');
994 $close_note =
GETPOST(
"close_note",
'restricthtml');
996 $result =
$object->setCanceled($user, $close_code, $close_note);
1003 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
1005 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
1013 $result = $discountcheck->fetch(0,
$object->id);
1026 $amount_ht = $amount_tva = $amount_ttc = $amount_localtax1 = $amount_localtax2 = array();
1027 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
1031 foreach (
$object->lines as $line) {
1032 if ($line->product_type < 9 && $line->total_ht != 0) {
1033 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
1035 if (!isset($amount_ht[$keyforvatrate])) {
1036 $amount_ht[$keyforvatrate] = 0;
1038 $amount_ht[$keyforvatrate] += $line->total_ht;
1039 if (!isset($amount_tva[$keyforvatrate])) {
1040 $amount_tva[$keyforvatrate] = 0;
1042 $amount_tva[$keyforvatrate] += $line->total_tva;
1043 if (!isset($amount_localtax1[$keyforvatrate])) {
1044 $amount_localtax1[$keyforvatrate] = 0;
1046 $amount_localtax1[$keyforvatrate] += $line->total_localtax1;
1047 if (!isset($amount_localtax2[$keyforvatrate])) {
1048 $amount_localtax2[$keyforvatrate] = 0;
1050 $amount_localtax2[$keyforvatrate] += $line->total_localtax2;
1051 if (!isset($amount_ttc[$keyforvatrate])) {
1052 $amount_ttc[$keyforvatrate] = 0;
1054 $amount_ttc[$keyforvatrate] += $line->total_ttc;
1055 if (!isset($multicurrency_amount_ht[$keyforvatrate])) {
1056 $multicurrency_amount_ht[$keyforvatrate] = 0;
1058 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
1059 if (!isset($multicurrency_amount_tva[$keyforvatrate])) {
1060 $multicurrency_amount_tva[$keyforvatrate] = 0;
1062 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
1063 if (!isset($multicurrency_amount_ttc[$keyforvatrate])) {
1064 $multicurrency_amount_ttc[$keyforvatrate] = 0;
1066 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
1070 '@phan-var-force array<string,float> $amount_ht
1071 @phan-var-force array<string,float> $amount_tva
1072 @phan-var-force array<string,float> $amount_ttc
1073 @phan-var-force array<string,float> $amount_localtax1
1074 @phan-var-force array<string,float> $amount_localtax2
1075 @phan-var-force array<string,float> $multicurrency_amount_ht
1076 @phan-var-force array<string,float> $multicurrency_amount_tva
1077 @phan-var-force array<string,float> $multicurrency_amount_ttc';
1081 $alreadypaid =
$object->getSommePaiement();
1082 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
1083 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
1084 foreach ($amount_ht as $vatrate => $val) {
1085 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
1086 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
1087 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
1088 $amount_localtax1[$vatrate] =
price2num($amount_localtax1[$vatrate] * $ratio,
'MU');
1089 $amount_localtax2[$vatrate] =
price2num($amount_localtax2[$vatrate] * $ratio,
'MU');
1090 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
1091 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
1092 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
1101 $discount->description =
'(CREDIT_NOTE)';
1103 $discount->description =
'(DEPOSIT)';
1105 $discount->description =
'(EXCESS RECEIVED)';
1107 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
1109 $discount->fk_soc =
$object->socid;
1110 $discount->socid =
$object->socid;
1111 $discount->fk_facture_source =
$object->id;
1120 $discount->description =
'(EXCESS RECEIVED)';
1123 $sql =
'SELECT SUM(pf.amount) as total_paiements';
1124 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
1125 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
1126 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
1127 $sql .=
' AND pf.fk_paiement = p.rowid';
1128 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
1129 $resql =
$db->query($sql);
1134 $res =
$db->fetch_object($resql);
1135 $total_paiements = $res->total_paiements;
1138 $total_creditnote_and_deposit = 0;
1139 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1140 $sql .=
" re.description, re.fk_facture_source";
1141 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1142 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
1143 $resql =
$db->query($sql);
1144 if (!empty($resql)) {
1145 while ($obj =
$db->fetch_object($resql)) {
1146 $total_creditnote_and_deposit += $obj->amount_ttc;
1152 $discount->amount_ttc =
price2num($total_paiements + $total_creditnote_and_deposit -
$object->total_ttc,
'MT');
1153 $discount->amount_tva = 0;
1154 $discount->amount_ht = $discount->amount_ttc;
1155 $discount->tva_tx = 0;
1156 $discount->localtax1_tx = 0;
1157 $discount->localtax1_type = 0;
1158 $discount->localtax2_tx = 0;
1159 $discount->localtax2_type = 0;
1160 $discount->vat_src_code =
'';
1162 if ($discount->amount_ttc > 0) {
1163 $result = $discount->create($user);
1173 $discount->description =
'(CREDIT_NOTE)';
1175 $discount->description =
'(DEPOSIT)';
1178 foreach ($amount_ht as $tva_tx => $xxx) {
1183 $discount->amount_ht = -((float) $amount_ht[$tva_tx]);
1184 $discount->amount_tva = -((float) $amount_tva[$tva_tx]);
1185 $discount->amount_ttc = -((float) $amount_ttc[$tva_tx]);
1186 $discount->total_ht = -((float) $amount_ht[$tva_tx]);
1187 $discount->total_tva = -((float) $amount_tva[$tva_tx]);
1188 $discount->total_localtax1 = -((float) $amount_localtax1[$tva_tx]);
1189 $discount->total_localtax2 = -((float) $amount_localtax2[$tva_tx]);
1190 $discount->total_ttc = -((float) $amount_ttc[$tva_tx]);
1191 $discount->multicurrency_amount_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1192 $discount->multicurrency_amount_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1193 $discount->multicurrency_amount_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1194 $discount->multicurrency_total_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1195 $discount->multicurrency_total_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1196 $discount->multicurrency_total_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1199 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
1200 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
1201 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
1202 $discount->total_ht = abs((
float) $amount_ht[$tva_tx]);
1203 $discount->total_tva = abs((
float) $amount_tva[$tva_tx]);
1204 $discount->total_localtax1 = abs((
float) $amount_localtax1[$tva_tx]);
1205 $discount->total_localtax2 = abs((
float) $amount_localtax2[$tva_tx]);
1206 $discount->total_ttc = abs((
float) $amount_ttc[$tva_tx]);
1207 $discount->multicurrency_amount_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1208 $discount->multicurrency_amount_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1209 $discount->multicurrency_amount_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1210 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1211 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1212 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1218 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
1219 $vat_src_code = $reg[1];
1220 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
1223 $discount->tva_tx = abs((
float) $tva_tx);
1224 $discount->localtax1_tx = $taxes[
'localtax1'];
1225 $discount->localtax1_type = $taxes[
'localtax1_type'];
1226 $discount->localtax2_tx = $taxes[
'localtax2'];
1227 $discount->localtax2_type = $taxes[
'localtax2_type'];
1228 $discount->vat_src_code = $vat_src_code;
1230 $result = $discount->create($user);
1238 if (empty($error)) {
1248 $result =
$object->setPaid($user);
1262 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
1267 $result = $paiement->fetch(
GETPOSTINT(
'paiement_id'));
1268 $paymentbills = ($result > 0) ? $paiement->getBillsArray() : array();
1269 if ($result > 0 && is_array($paymentbills) && in_array(
$object->id, $paymentbills)) {
1270 $result = $paiement->delete($user);
1272 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1282 } elseif ($action ==
'add' && $usercancreate) {
1289 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1295 $object->demand_reason_id = $inputReasonId;
1298 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1311 if (empty($dateinvoice)) {
1313 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1323 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1333 $object->date_pointoftax = $date_pointoftax;
1334 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1335 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1344 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1345 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1362 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1364 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceAvoirAskCombo")),
null,
'errors');
1368 if (empty($dateinvoice)) {
1370 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1380 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1385 if (!empty($originentity)) {
1386 $object->entity = $originentity;
1392 $object->date_pointoftax = $date_pointoftax;
1393 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1394 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1399 $object->cond_reglement_id = 0;
1403 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1404 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1408 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1412 if (
$object->fk_facture_source > 0 && $facture_source->fetch(
$object->fk_facture_source) > 0) {
1413 if ($facture_source->isSituationInvoice()) {
1414 $object->situation_counter = $facture_source->situation_counter;
1415 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1416 $facture_source->fetchPreviousNextSituationInvoice();
1419 $object->pos_source = $facture_source->pos_source;
1420 $object->module_source = $facture_source->module_source;
1428 if (
$object->copy_linked_contact($facture_source,
'internal') < 0) {
1430 } elseif ($facture_source->socid ==
$object->socid) {
1432 if (
$object->copy_linked_contact($facture_source,
'external') < 0) {
1443 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1444 if (!empty($facture_source->lines)) {
1445 $fk_parent_line = 0;
1447 foreach ($facture_source->lines as $line) {
1449 if (method_exists($line,
'fetch_optionals')) {
1451 $line->fetch_optionals();
1455 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1456 $fk_parent_line = 0;
1460 if ($facture_source->isSituationInvoice()) {
1461 $source_fk_prev_id = $line->fk_prev_id;
1462 $line->fk_prev_id = $line->id;
1467 if (
getDolGlobalInt(
'INVOICE_USE_SITUATION') == 1 && !empty($facture_source->tab_previous_situation_invoice)) {
1470 $tab_jumped_credit_notes = array();
1471 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1472 $searchPreviousInvoice =
true;
1473 while ($searchPreviousInvoice) {
1474 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1475 $searchPreviousInvoice =
false;
1479 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1485 $maxPrevSituationPercent = 0;
1486 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1487 if ($prevLine->id == $source_fk_prev_id) {
1488 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1491 $line->total_ht -= $prevLine->total_ht;
1492 $line->total_tva -= $prevLine->total_tva;
1493 $line->total_ttc -= $prevLine->total_ttc;
1494 $line->total_localtax1 -= $prevLine->total_localtax1;
1495 $line->total_localtax2 -= $prevLine->total_localtax2;
1497 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1498 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1499 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1500 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1505 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1510 $maxPrevSituationPercent = 0;
1511 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1512 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1513 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1514 $maxPrevSituationPercent = $prevLine->situation_percent;
1516 $line->total_ht -= $prevLine->total_ht;
1517 $line->total_tva -= $prevLine->total_tva;
1518 $line->total_ttc -= $prevLine->total_ttc;
1519 $line->total_localtax1 -= $prevLine->total_localtax1;
1520 $line->total_localtax2 -= $prevLine->total_localtax2;
1522 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1523 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1524 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1525 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1531 $line->situation_percent += $maxPrevSituationPercent;
1537 $line->fk_facture =
$object->id;
1538 $line->fk_parent_line = $fk_parent_line;
1540 $line->subprice = -$line->subprice;
1542 $line->total_ht = -$line->total_ht;
1543 $line->total_tva = -$line->total_tva;
1544 $line->total_ttc = -$line->total_ttc;
1545 $line->total_localtax1 = -$line->total_localtax1;
1546 $line->total_localtax2 = -$line->total_localtax2;
1548 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1549 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1550 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1551 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1553 $line->context[
'createcreditnotefrominvoice'] = 1;
1554 $result = $line->insert(0, 1);
1559 if ($result > 0 && $line->product_type == 9) {
1560 $fk_parent_line = $result;
1568 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1569 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1570 $totalpaid = $facture_source->getSommePaiement();
1571 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1572 $totaldeposits = $facture_source->getSumDepositsUsed();
1573 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1575 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1576 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1579 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1584 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1585 $tva_tx = (float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY');
1592 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), 0, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC', -$remain_to_pay);
1597 if (!empty(
$object->fk_facture_source) &&
$id > 0) {
1598 $facture_source->fetch(
$object->fk_facture_source);
1599 $facture_source->fetchObjectLinked();
1601 if (!empty($facture_source->linkedObjectsIds)) {
1602 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1603 $object->add_object_linked($sourcetype, current($TIds));
1612 if (empty($dateinvoice)) {
1614 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1625 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1635 $object->date_pointoftax = $date_pointoftax;
1636 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1637 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1648 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1649 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1665 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1666 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1667 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1671 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1675 if (empty($dateinvoice)) {
1677 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1687 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1688 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1693 if ($typeamount && !empty($origin) && !empty($originid)) {
1694 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1695 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1699 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1700 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1704 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1705 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1715 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1725 $object->date_pointoftax = $date_pointoftax;
1726 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1727 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1737 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1738 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1742 $object->situation_counter = 1;
1747 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1749 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1751 $object->retained_warranty = 0;
1752 $object->retained_warranty_fk_cond_reglement = 0;
1755 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1756 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1759 $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);
1764 if (!empty($origin) && !empty($originid)) {
1767 $element = $subelement = $origin;
1768 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1769 $element = $regs[1];
1770 $subelement = $regs[2];
1774 if ($element ==
'order') {
1775 $element = $subelement =
'commande';
1777 if ($element ==
'propal') {
1778 $element =
'comm/propal';
1779 $subelement =
'propal';
1781 if ($element ==
'contract') {
1782 $element = $subelement =
'contrat';
1784 if ($element ==
'inter') {
1785 $element = $subelement =
'fichinter';
1787 if ($element ==
'shipping') {
1788 $element = $subelement =
'expedition';
1792 $object->origin_type = $origin;
1793 $object->origin_id = $originid;
1798 if (
$object->origin ==
'shipping') {
1799 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1801 $exp->fetch(
$object->origin_id);
1802 $exp->fetchObjectLinked();
1803 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1804 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1805 $object->linked_objects[
'commande'] = $value;
1811 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
1819 $classname = ucfirst($subelement);
1820 $srcobject =
new $classname(
$db);
1821 '@phan-var-force CommonObject $srcobject';
1823 dol_syslog(
"Try to find source object origin_type=".
$object->origin_type.
" origin_id=".
$object->origin_id.
" to add lines or deposit lines");
1824 $result = $srcobject->fetch(
$object->origin_id);
1830 $amountdeposit = array();
1833 if ($typeamount ==
'amount') {
1834 $amount = (float) $valuedeposit;
1836 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1839 $TTotalByTva = array();
1840 foreach ($srcobject->lines as &$line) {
1841 if (empty($line->qty)) {
1844 if (!empty($line->special_code)) {
1847 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1849 '@phan-var-force array<string,float> $TTotalByTva';
1851 $amount_ttc_diff = 0.;
1852 foreach ($TTotalByTva as $tva => &$total) {
1853 if (empty($amountdeposit[$tva])) {
1854 $amountdeposit[$tva] = 0;
1856 $coef = $total / $srcobject->total_ttc;
1857 $am = $amount * $coef;
1858 $amount_ttc_diff += $am;
1859 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1862 if ($typeamount ==
'amount') {
1863 $amountdeposit[0] = $valuedeposit;
1864 } elseif ($typeamount ==
'variable') {
1867 $lines = $srcobject->lines;
1868 $numlines = count($lines);
1869 for ($i = 0; $i < $numlines; $i++) {
1871 if (empty($lines[$i]->qty)) {
1874 if (!empty($lines[$i]->special_code)) {
1878 $totalamount += $lines[$i]->total_ht;
1879 $tva_tx = $lines[$i]->tva_tx;
1881 if (empty($amountdeposit[$tva_tx])) {
1882 $amountdeposit[$tva_tx] = 0;
1884 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1888 if ($totalamount == 0) {
1889 $amountdeposit[0] = 0;
1897 $amount_ttc_diff = $amountdeposit[0];
1900 foreach ($amountdeposit as $tva => $amount) {
1901 if (empty($amount)) {
1906 'amount' =>
'FixAmount',
1907 'variable' =>
'VarAmount'
1909 $descline =
'(DEPOSIT)';
1911 if ($typeamount ==
'amount') {
1912 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1913 } elseif ($typeamount ==
'variable') {
1914 $descline .=
' ('.$valuedeposit.
'%)';
1917 $descline .=
' - '.$srcobject->ref;
1930 $i >= 0 ? $lines[$i]->info_bits : 0,
1936 $i >= 0 ? $lines[$i]->special_code : 0,
1953 $diff =
$object->total_ttc - $amount_ttc_diff;
1957 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1958 $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);
1967 $lines = $srcobject->lines;
1968 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1969 $srcobject->fetch_lines();
1970 $lines = $srcobject->lines;
1975 if (is_array($lines)) {
1976 foreach ($lines as $line) {
1978 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuestandardinvoice / 100,
'MS');
1984 if (is_array($lines)) {
1985 foreach ($lines as $line) {
1987 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuedeposit / 100,
'MS');
1992 $fk_parent_line = 0;
1993 $num = count($lines);
1995 for ($i = 0; $i < $num; $i++) {
1996 if (!in_array($lines[$i]->
id, $selectedLines)) {
2001 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
2005 if (!isset(
$conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
2006 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
2008 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
2012 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
2013 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
2015 if (
$object->situation_counter == 1) {
2016 $lines[$i]->situation_percent = 0;
2019 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
2022 $desc = $label ? $label : $langs->trans(
'Discount');
2026 $discount->fk_soc =
$object->socid;
2027 $discount->socid =
$object->socid;
2028 $discount->amount_ht = abs($lines[$i]->total_ht);
2029 $discount->amount_tva = abs($lines[$i]->total_tva);
2030 $discount->amount_ttc = abs($lines[$i]->total_ttc);
2031 $discount->total_ht = abs($lines[$i]->total_ht);
2032 $discount->total_tva = abs($lines[$i]->total_tva);
2033 $discount->total_ttc = abs($lines[$i]->total_ttc);
2034 $discount->tva_tx = $lines[$i]->tva_tx;
2035 $discount->localtax1_tx = $lines[$i]->localtax1_tx;
2036 $discount->localtax2_tx = $lines[$i]->localtax2_tx;
2037 $discount->localtax1_type = $lines[$i]->localtax1_type;
2038 $discount->localtax2_type = $lines[$i]->localtax2_type;
2039 $discount->total_localtax1 = abs($lines[$i]->total_localtax1);
2040 $discount->total_localtax2 = abs($lines[$i]->total_localtax2);
2041 $discount->fk_user = $user->id;
2042 $discount->description = $desc;
2043 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
2044 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
2045 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
2046 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
2047 $discount->multicurrency_total_ht = abs($lines[$i]->multicurrency_total_ht);
2048 $discount->multicurrency_total_tva = abs($lines[$i]->multicurrency_total_tva);
2049 $discount->multicurrency_total_ttc = abs($lines[$i]->multicurrency_total_ttc);
2051 $discountid = $discount->create($user);
2052 if ($discountid > 0) {
2053 $result =
$object->insert_discount($discountid);
2066 if (isset($lines[$i]->date_debut_prevue)) {
2069 if (isset($lines[$i]->date_debut_reel)) {
2072 if (isset($lines[$i]->date_start)) {
2078 if (isset($lines[$i]->date_fin_prevue)) {
2079 $date_end = $lines[$i]->date_fin_prevue;
2081 if (isset($lines[$i]->date_fin_reel)) {
2082 $date_end = $lines[$i]->date_fin_reel;
2084 if (isset($lines[$i]->date_end)) {
2085 $date_end = $lines[$i]->date_end;
2089 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
2090 $fk_parent_line = 0;
2093 $array_options = array();
2095 if (method_exists($lines[$i],
'fetch_optionals')) {
2096 $lines[$i]->fetch_optionals();
2097 $array_options = $lines[$i]->array_options;
2100 $tva_tx = $lines[$i]->tva_tx;
2101 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
2102 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
2112 $lines[$i]->subprice,
2117 $lines[$i]->fk_product,
2118 $lines[$i]->remise_percent,
2122 (
int) $lines[$i]->info_bits,
2123 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except : null,
2128 $lines[$i]->special_code,
2132 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice : null,
2136 $lines[$i]->situation_percent ?? 100,
2137 $lines[$i]->fk_prev_id ?? 0,
2138 $lines[$i]->fk_unit,
2145 foreach (
$object->lines as $line) {
2146 if ($line->id == $result) {
2147 $line->extraparams = $lines[$i]->extraparams;
2148 $line->setExtraParameters();
2160 if ($result > 0 && $lines[$i]->product_type == 9) {
2161 $fk_parent_line = $result;
2173 $object->line_order(
true,
'DESC');
2201 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id,
'objFrom' => $srcobject);
2202 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
2215 for ($i = 1; $i <= $NBLINES; $i++) {
2221 $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);
2232 if (empty($dateinvoice)) {
2234 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
2244 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
2254 if (!empty($origin) && !empty($originid)) {
2255 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2258 $object->origin_type = $origin;
2259 $object->origin_id = $originid;
2263 $retained_warranty =
GETPOSTINT(
'retained_warranty');
2264 if (
price2num($retained_warranty) > 0) {
2268 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
2269 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
2272 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
2273 if (!empty($retained_warranty_date_limit) &&
$db->jdate($retained_warranty_date_limit)) {
2274 $object->retained_warranty_date_limit =
$db->jdate($retained_warranty_date_limit);
2276 $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);
2279 foreach (
$object->lines as $i => &$line) {
2280 $line->fk_prev_id = $line->id;
2281 $line->fetch_optionals();
2283 $line->situation_percent = 0;
2285 $line->situation_percent = $line->get_prev_progress(
$object->id);
2289 $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);
2290 $line->total_ht = (float) $tabprice[0];
2291 $line->total_tva = (float) $tabprice[1];
2292 $line->total_ttc = (float) $tabprice[2];
2293 $line->total_localtax1 = (float) $tabprice[9];
2294 $line->total_localtax2 = (float) $tabprice[10];
2295 $line->multicurrency_total_ht = (float) $tabprice[16];
2296 $line->multicurrency_total_tva = (float) $tabprice[17];
2297 $line->multicurrency_total_ttc = (float) $tabprice[18];
2300 if ($line->fk_remise_except) {
2302 $result = $discount->fetch($line->fk_remise_except);
2305 if ($discount->fk_facture_line > 0) {
2306 $line->fk_remise_except = 0;
2315 $object->date_pointoftax = $date_pointoftax;
2316 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2330 $object->situation_counter += 1;
2335 $extrafields->fetch_name_optionals_label(
$object->table_element);
2336 $extrafields->setOptionalsFromPost(
null, $object);
2343 $nextSituationInvoice->fetch($id);
2346 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id);
2347 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $nextSituationInvoice, $action);
2358 if ($id > 0 && !$error) {
2360 $categories =
GETPOST(
'categories',
'array');
2361 if (method_exists($object,
'setCategories')) {
2362 $object->setCategories($categories);
2370 $outputlangs = $langs;
2373 $newlang =
GETPOST(
'lang_id',
'aZ09');
2376 if (empty(
$object->thirdparty)) {
2379 $newlang =
$object->thirdparty->default_lang;
2381 if (!empty($newlang)) {
2383 $outputlangs->setDefaultLang($newlang);
2384 $outputlangs->load(
'products');
2389 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2395 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2400 $_GET[
"origin"] =
GETPOST(
"origin",
'alpha');
2404 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2408 foreach (
$object->lines as $line) {
2409 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2412 if ($line->product_type == 1) {
2413 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $alldate_start, $alldate_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx,
'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice);
2416 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2418 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2419 $vat_rate = str_replace(
'*',
'', $vat_rate);
2422 foreach (
$object->lines as $line) {
2423 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2426 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $vat_rate, $localtax1_rate, $localtax2_rate,
'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice);
2428 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2430 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2431 $remise_percent = str_replace(
'*',
'', $remise_percent);
2432 foreach (
$object->lines as $line) {
2433 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2436 $tvatx = $line->tva_tx;
2437 if (!empty($line->vat_src_code)) {
2438 $tvatx .=
' ('.$line->vat_src_code.
')';
2440 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, (
float) $remise_percent, $line->date_start, $line->date_end, $tvatx, $line->localtax1_tx, $line->localtax2_tx,
'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice);
2442 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
2445 $langs->load(
'subtotals');
2447 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
2448 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
2450 $subtotal_options = array();
2452 foreach (Facture::$TITLE_OPTIONS as $option) {
2453 $value =
GETPOST($option,
'alphanohtml');
2455 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2460 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2471 $outputlangs = $langs;
2472 $newlang =
GETPOST(
'lang_id',
'alpha');
2474 $newlang =
$object->thirdparty->default_lang;
2476 if (!empty($newlang)) {
2478 $outputlangs->setDefaultLang($newlang);
2481 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2486 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2488 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
2491 $langs->load(
'subtotals');
2493 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
2494 foreach (
$object->lines as $line) {
2495 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
2496 $desc = $line->desc;
2497 $depth = -$line->qty;
2501 $subtotal_options = array();
2503 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
2504 $value =
GETPOST($option,
'alphanohtml');
2506 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2511 if (isset($desc) && isset($depth)) {
2512 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2515 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
2524 $outputlangs = $langs;
2525 $newlang =
GETPOST(
'lang_id',
'alpha');
2527 $newlang =
$object->thirdparty->default_lang;
2529 if (!empty($newlang)) {
2531 $outputlangs->setDefaultLang($newlang);
2534 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2539 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2541 } elseif ($action ==
'addline' &&
GETPOST(
'updateallvatlinesblock',
'alpha') &&
GETPOST(
'vatforblocklines',
'alpha') !==
'' && $usercancreate) {
2542 $tx_tva =
GETPOST(
'vatforblocklines') ?
GETPOST(
'vatforblocklines') : 0;
2543 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'tva', $tx_tva);
2544 } elseif ($action ==
'addline' &&
GETPOST(
'updatealldiscountlinesblock',
'alpha') &&
GETPOST(
'discountforblocklines',
'alpha') !==
'' && $usercancreate) {
2545 $discount =
GETPOST(
'discountforblocklines') ?
GETPOST(
'discountforblocklines') : 0;
2546 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'discount', $discount);
2547 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && !
GETPOST(
'submitforallmark',
'alpha') && $usercancreate) {
2548 $langs->load(
'errors');
2556 $price_ht_devise =
'';
2558 $price_ttc_devise =
'';
2561 $price_min_ttc =
'';
2563 if (
GETPOST(
'price_ht') !==
'') {
2566 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2569 if (
GETPOST(
'price_ttc') !==
'') {
2572 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2573 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2576 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2577 if ($prod_entry_mode ==
'free') {
2583 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2588 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2592 if (empty($remise_percent)) {
2593 $remise_percent = 0;
2597 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2598 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2600 if (is_array($extralabelsline)) {
2602 foreach ($extralabelsline as $key => $value) {
2603 unset($_POST[
"options_".$key.$predef]);
2607 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2608 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2611 if (!$prod_entry_mode) {
2613 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2617 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2618 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2623 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0)
2624 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
2625 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
2626 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
2627 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
2628 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
2629 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2630 $langs->load(
"errors");
2631 if (
$object->type == $object::TYPE_DEPOSIT) {
2633 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2635 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2640 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
2641 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
2645 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
2646 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2650 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2654 $langs->load(
"errors");
2655 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2659 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2660 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
2664 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2665 $idprod = $res->fk_product_child;
2667 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2673 $price_base_type =
null;
2674 if (!$error && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
2680 $ret =
$object->fetch_thirdparty();
2685 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2696 if (!empty($idprod) && $idprod > 0) {
2698 $prod->fetch($idprod);
2707 $pu_ht = $datapriceofproduct[
'pu_ht'];
2708 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2709 $price_min = $datapriceofproduct[
'price_min'];
2710 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2711 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2715 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2716 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string)
$prod->tva_tx));
2720 if (!empty($price_ht) || $price_ht ===
'0') {
2722 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2723 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2724 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2725 $pu_ttc_devise = (float)
price2num((
float) $pu_ht_devise * (1 + ((float) $tmpvat / 100)),
'MU');
2728 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2730 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2731 } elseif (!empty($price_ttc_devise) || (
string) $price_ttc_devise ===
'0') {
2732 $pu_ttc_devise = (float)
price2num($price_ttc_devise,
'MU');
2733 $pu_ht_devise = (float)
price2num((
float) $pu_ttc_devise / (1 + ((float) $tmpvat / 100)),
'MU');
2736 } elseif ($tmpvat != $tmpprodvat) {
2738 if ($price_base_type !=
'HT') {
2739 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2741 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2745 $outputlangs = $langs;
2751 if (
GETPOST(
'lang_id',
'aZ09')) {
2752 $newlang =
GETPOST(
'lang_id',
'aZ09');
2754 if (empty($newlang)) {
2755 $newlang =
$object->thirdparty->default_lang;
2757 if (!empty($newlang)) {
2759 $outputlangs->setDefaultLang($newlang);
2760 $outputlangs->load(
'products');
2763 $desc = (!empty(
$prod->multilangs [$outputlangs->defaultlang] [
"description"])) ?
$prod->multilangs [$outputlangs->defaultlang] [
"description"] :
$prod->
description;
2765 $desc =
$prod->description;
2781 if (!empty(
$prod->customcode)) {
2782 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomsCode").
': '.
$prod->customcode;
2784 if (!empty(
$prod->customcode) && !empty(
$prod->country_code)) {
2787 if (!empty(
$prod->country_code)) {
2788 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry(
$prod->country_code,
'',
$db, $outputlangs, 0);
2791 if (!empty(
$prod->customcode)) {
2792 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomsCode").
': '.
$prod->customcode;
2794 if (!empty(
$prod->customcode) && !empty(
$prod->country_code)) {
2797 if (!empty(
$prod->country_code)) {
2798 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry(
$prod->country_code,
'',
$db, $langs, 0);
2805 $type =
$prod->type;
2806 $fk_unit =
$prod->fk_unit;
2808 if (!empty($price_ht)) {
2813 if (!empty($price_ttc)) {
2818 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2819 $tva_tx = str_replace(
'*',
'', $tva_tx);
2820 if (empty($tva_tx)) {
2823 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2826 $fk_unit =
GETPOST(
'units',
'alpha');
2828 if ($pu_ttc && !$pu_ht) {
2829 $price_base_type =
'TTC';
2843 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2844 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2847 $pu_equivalent = $pu_ht;
2848 $pu_equivalent_ttc = $pu_ttc;
2850 $currency_tx =
$object->multicurrency_tx;
2854 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
2855 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
2857 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
2858 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
2873 $fournprice = (int) (
GETPOST(
'fournprice'.$predef) ?
GETPOST(
'fournprice'.$predef) :
'');
2878 $price2num_remise_percent =
price2num($remise_percent);
2879 $price2num_price_min =
price2num($price_min);
2880 $price2num_price_min_ttc =
price2num($price_min_ttc);
2881 if (empty($price2num_pu_ht)) {
2882 $price2num_pu_ht = 0;
2884 if (empty($price2num_remise_percent)) {
2885 $price2num_remise_percent = 0;
2887 if (empty($price2num_price_min)) {
2888 $price2num_price_min = 0;
2890 if (empty($price2num_price_min_ttc)) {
2891 $price2num_price_min_ttc = 0;
2896 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2897 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2900 } 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') {
2901 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2922 $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);
2928 $outputlangs = $langs;
2931 $newlang =
GETPOST(
'lang_id',
'aZ09');
2934 $newlang =
$object->thirdparty->default_lang;
2936 if (!empty($newlang)) {
2938 $outputlangs->setDefaultLang($newlang);
2939 $outputlangs->load(
'products');
2942 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2948 unset($_POST[
'prod_entry_mode']);
2949 unset($_POST[
'qty']);
2950 unset($_POST[
'type']);
2951 unset($_POST[
'remise_percent']);
2952 unset($_POST[
'price_ht']);
2953 unset($_POST[
'multicurrency_price_ht']);
2954 unset($_POST[
'price_ttc']);
2955 unset($_POST[
'tva_tx']);
2956 unset($_POST[
'product_ref']);
2957 unset($_POST[
'product_label']);
2958 unset($_POST[
'product_desc']);
2959 unset($_POST[
'fournprice']);
2960 unset($_POST[
'buying_price']);
2961 unset($_POST[
'np_marginRate']);
2962 unset($_POST[
'np_markRate']);
2963 unset($_POST[
'dp_desc']);
2964 unset($_POST[
'idprod']);
2965 unset($_POST[
'units']);
2966 unset($_POST[
'date_starthour']);
2967 unset($_POST[
'date_startmin']);
2968 unset($_POST[
'date_startsec']);
2969 unset($_POST[
'date_startday']);
2970 unset($_POST[
'date_startmonth']);
2971 unset($_POST[
'date_startyear']);
2972 unset($_POST[
'date_endhour']);
2973 unset($_POST[
'date_endmin']);
2974 unset($_POST[
'date_endsec']);
2975 unset($_POST[
'date_endday']);
2976 unset($_POST[
'date_endmonth']);
2977 unset($_POST[
'date_endyear']);
2978 unset($_POST[
'situations']);
2979 unset($_POST[
'progress']);
2987 } elseif ($action ==
'addline' && $usercancreate && (
2988 (
GETPOST(
'submitforallmargins',
'alpha') &&
GETPOST(
'marginforalllines',
'alpha') !==
'') ||
2989 (
GETPOST(
'submitforallmark',
'alpha') &&
GETPOST(
'markforalllines',
'alpha') !==
'')
2992 $margin_rate =
GETPOSTISSET(
'marginforalllines') ?
GETPOST(
'marginforalllines',
'int') :
'';
2994 foreach (
$object->lines as &$line) {
2995 if ($line->subprice > 0) {
2996 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2999 $subprice_multicurrency = $line->subprice;
3000 if (is_numeric($margin_rate) && $margin_rate > 0) {
3001 $line->subprice = (float)
price2num((
float) $line->pa_ht * (1 + (float) $margin_rate / 100),
'MU');
3002 } elseif (is_numeric($mark_rate) && $mark_rate > 0) {
3003 $line->subprice = (float) ($line->pa_ht / (1 - ((
float) $mark_rate / 100)));
3005 $line->subprice = (float) $line->pa_ht;
3008 if ($line->fk_product > 0) {
3010 $res =
$prod->fetch($line->fk_product);
3012 if (
$prod->price_min > $line->subprice) {
3013 $price_subprice =
price($line->subprice, 0, $outlangs, 1, -1, -1,
'auto');
3014 $price_price_min =
price(
$prod->price_min, 0, $outlangs, 1, -1, -1,
'auto');
3015 setEventMessages(
$prod->ref .
' - ' .
$prod->label .
' (' . $price_subprice .
' < ' . $price_price_min .
' ' . strtolower($langs->trans(
"MinPrice")) .
')' .
"\n",
null,
'warnings');
3024 $multicurrency_subprice = (float) $line->subprice * $line->multicurrency_subprice / $subprice_multicurrency;
3026 $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);
3029 if (is_numeric($margin_rate) && empty($mark_rate)) {
3030 $line->marge_tx = $margin_rate;
3031 } elseif (is_numeric($mark_rate) && empty($margin_rate)) {
3032 $line->marque_tx = $mark_rate;
3034 $line->total_ht = $line->qty * (float) $line->subprice;
3035 $line->total_tva = $line->tva_tx * $line->qty * (float) $line->subprice;
3036 $line->total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $line->subprice;
3038 $line->multicurrency_total_ht = $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
3039 $line->multicurrency_total_tva = $line->tva_tx * $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
3040 $line->multicurrency_total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
3042 $line->multicurrency_subprice = $multicurrency_subprice;
3048 } elseif ($action ==
'updatetitleline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3051 $langs->load(
'subtotals');
3053 $desc =
GETPOST(
'line_desc',
'alphanohtml') ?? $langs->trans(
"Title");
3056 $subtotal_options = array();
3058 foreach (Facture::$TITLE_OPTIONS as $option) {
3059 $value =
GETPOST($option,
'alphanohtml');
3061 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
3066 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3077 $outputlangs = $langs;
3078 $newlang =
GETPOST(
'lang_id',
'alpha');
3080 $newlang =
$object->thirdparty->default_lang;
3082 if (!empty($newlang)) {
3084 $outputlangs->setDefaultLang($newlang);
3087 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3092 } elseif ($action ==
'updatesubtotalline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3095 $langs->load(
'subtotals');
3097 $desc =
GETPOST(
'line_desc',
'alphanohtml');
3100 $subtotal_options = array();
3102 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
3103 $value =
GETPOST($option,
'alphanohtml');
3105 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
3110 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3118 $outputlangs = $langs;
3119 $newlang =
GETPOST(
'lang_id',
'alpha');
3121 $newlang =
$object->thirdparty->default_lang;
3123 if (!empty($newlang)) {
3125 $outputlangs->setDefaultLang($newlang);
3128 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3133 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3134 if (!
$object->fetch($id) > 0) {
3157 if (preg_match(
'/\*/', $vat_rate)) {
3162 $vat_rate = str_replace(
'*',
'', $vat_rate);
3167 $fournprice = (int) (
GETPOST(
'fournprice') ?
GETPOST(
'fournprice') :
'');
3171 $pu_equivalent = $pu_ht;
3172 $pu_equivalent_ttc = $pu_ttc;
3174 $currency_tx =
$object->multicurrency_tx;
3178 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3179 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
3181 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3182 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
3197 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
3198 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
3200 if (is_array($extralabelsline)) {
3202 foreach ($extralabelsline as $key => $value) {
3203 unset($_POST[
"options_".$key]);
3209 if ($special_code == 3) {
3215 $percent = $line->get_prev_progress(
$object->id);
3220 if ($progress >= 0) {
3221 $mesg = $langs->trans(
"CantBeNullOrPositive");
3225 } elseif ($progress < $line->situation_percent) {
3226 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
3230 } elseif ($progress < $percent) {
3231 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
3239 if (empty($remise_percent)) {
3240 $remise_percent = 0;
3243 $price_base_type =
'HT';
3245 if (empty($pu) && !empty($pu_ttc)) {
3247 $price_base_type =
'TTC';
3252 if (!empty($productid)) {
3254 $product->fetch($productid);
3256 $type = $product->type;
3258 $price_min = $product->price_min;
3260 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
3262 $price_min_ttc = $product->price_min_ttc;
3264 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
3271 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
3272 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3275 $action =
'editline';
3276 } 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') {
3277 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3280 $action =
'editline';
3285 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
3289 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
3294 $langs->load(
"errors");
3295 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
3299 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
3300 $langs->load(
"errors");
3301 if (
$object->type == $object::TYPE_DEPOSIT) {
3303 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
3305 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
3309 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
3316 $previousprogress = $line->getAllPrevProgress($line->fk_facture);
3319 if ($fullprogress < $previousprogress) {
3321 setEventMessages($langs->trans(
'CantBeLessThanMinPercent'),
null,
'errors');
3325 if ($fullprogress > 100) {
3326 $fullprogress = 100;
3328 $addprogress = $fullprogress - $previousprogress;
3335 if (empty($usercancreatemargin)) {
3336 foreach (
$object->lines as &$line) {
3338 $fournprice = $line->fk_fournprice;
3339 $buyingprice = $line->pa_ht;
3345 $result =
$object->updateline(
3350 (
float) $remise_percent,
3368 (
float) $pu_ht_devise
3375 $outputlangs = $langs;
3378 $newlang =
GETPOST(
'lang_id',
'aZ09');
3381 $newlang =
$object->thirdparty->default_lang;
3383 if (!empty($newlang)) {
3385 $outputlangs->setDefaultLang($newlang);
3386 $outputlangs->load(
'products');
3388 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3391 unset($_POST[
'qty']);
3392 unset($_POST[
'type']);
3393 unset($_POST[
'productid']);
3394 unset($_POST[
'remise_percent']);
3395 unset($_POST[
'price_ht']);
3396 unset($_POST[
'multicurrency_price_ht']);
3397 unset($_POST[
'price_ttc']);
3398 unset($_POST[
'tva_tx']);
3399 unset($_POST[
'product_ref']);
3400 unset($_POST[
'product_label']);
3401 unset($_POST[
'product_desc']);
3402 unset($_POST[
'fournprice']);
3403 unset($_POST[
'buying_price']);
3404 unset($_POST[
'np_marginRate']);
3405 unset($_POST[
'np_markRate']);
3406 unset($_POST[
'dp_desc']);
3407 unset($_POST[
'idprod']);
3408 unset($_POST[
'units']);
3409 unset($_POST[
'date_starthour']);
3410 unset($_POST[
'date_startmin']);
3411 unset($_POST[
'date_startsec']);
3412 unset($_POST[
'date_startday']);
3413 unset($_POST[
'date_startmonth']);
3414 unset($_POST[
'date_startyear']);
3415 unset($_POST[
'date_endhour']);
3416 unset($_POST[
'date_endmin']);
3417 unset($_POST[
'date_endsec']);
3418 unset($_POST[
'date_endday']);
3419 unset($_POST[
'date_endmonth']);
3420 unset($_POST[
'date_endyear']);
3421 unset($_POST[
'situations']);
3422 unset($_POST[
'progress']);
3427 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOSTISSET(
'all_percent')) {
3428 if (!
$object->fetch($id) > 0) {
3431 if (
GETPOST(
'all_progress') !=
"") {
3433 if ($all_progress > 100) {
3434 $all_progress = 100;
3437 foreach (
$object->lines as $line) {
3439 $percent = $line->getAllPrevProgress(
$object->id);
3441 $percent = $line->get_prev_progress(
$object->id);
3443 if (
$object->type != $object::TYPE_CREDIT_NOTE && (
float) $all_progress < (
float) $percent) {
3444 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
3447 } elseif (
$object->type == $object::TYPE_CREDIT_NOTE && (
float) $all_progress > (
float) $percent) {
3448 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeMoreThanMinPercent");
3452 $object->update_percent($line, $all_progress,
false);
3457 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
3458 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
3460 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
3462 $object->fetch($id,
'',
'', 0,
true);
3465 &&
$object->isSituationInvoice()
3468 &&
$object->is_last_in_cycle()
3469 && $usercanunvalidate
3472 $newCycle =
$object->newCycle();
3473 if ($newCycle > 1) {
3475 $lastCycle =
$object->situation_cycle_ref;
3476 $lastSituationCounter =
$object->situation_counter;
3477 $linkedCreditNotesList = array();
3479 if (count(
$object->tab_next_situation_invoice) > 0) {
3480 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
3482 && $next_invoice->situation_counter ==
$object->situation_counter
3483 && $next_invoice->fk_facture_source ==
$object->id
3485 $linkedCreditNotesList[] = $next_invoice->id;
3490 $object->situation_cycle_ref = $newCycle;
3491 $object->situation_counter = 1;
3493 if (
$object->update($user) > 0) {
3495 if (count($linkedCreditNotesList) > 0) {
3497 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
3498 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
3499 $sql .=
' , situation_final=0';
3500 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
3501 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
3503 $resql =
$db->query($sql);
3509 foreach (
$object->lines as $line) {
3511 if ($line->product_type == 9) {
3516 if (!empty(
$object->tab_previous_situation_invoice)) {
3518 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
3519 $searchPreviousInvoice =
true;
3520 while ($searchPreviousInvoice) {
3521 if (
$object->tab_previous_situation_invoice[$lineIndex]->isSituationInvoice() || $lineIndex < 1) {
3522 $searchPreviousInvoice =
false;
3530 $maxPrevSituationPercent = 0;
3531 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
3532 if ($prevLine->id == $line->fk_prev_id) {
3533 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
3538 $line->situation_percent -= $maxPrevSituationPercent;
3540 if ($line->update() < 0) {
3549 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
3551 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
3554 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
3557 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
3563 $fromElement =
GETPOST(
'fromelement');
3564 $fromElementid =
GETPOST(
'fromelementid');
3565 $importLines =
GETPOST(
'line_checkbox');
3567 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
3568 $lineClassName =
'';
3569 if ($fromElement ==
'commande') {
3571 $lineClassName =
'OrderLine';
3572 } elseif ($fromElement ==
'propal') {
3573 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
3574 $lineClassName =
'PropaleLigne';
3576 $nextRang = count(
$object->lines) + 1;
3579 foreach ($importLines as $lineId) {
3580 if ($lineClassName ===
'') {
3584 dol_syslog(
'compta/facture/card - No lineClassName - skip import', LOG_ERR);
3591 $lineId = intval($lineId);
3592 $originLine =
new $lineClassName(
$db);
3593 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
3594 $originLine->fetch_optionals();
3595 $desc = $originLine->desc;
3596 $pu_ht = $originLine->subprice;
3597 $qty = $originLine->qty;
3598 $txtva = $originLine->tva_tx;
3599 $txlocaltax1 = $originLine->localtax1_tx;
3600 $txlocaltax2 = $originLine->localtax2_tx;
3601 $fk_product = $originLine->fk_product;
3602 $remise_percent = $originLine->remise_percent;
3604 $date_end = $originLine->date_end;
3605 $fk_code_ventilation = 0;
3606 $info_bits = $originLine->info_bits;
3607 $fk_remise_except = $originLine->fk_remise_except;
3608 $price_base_type =
'HT';
3610 $type = $originLine->product_type;
3611 $rang = $nextRang++;
3612 $special_code = $originLine->special_code;
3613 $origin = $originLine->element;
3614 $origin_id = $originLine->id;
3615 $fk_parent_line = 0;
3616 $fk_fournprice = $originLine->fk_fournprice;
3617 $pa_ht = $originLine->pa_ht;
3618 $label = $originLine->label;
3619 $array_options = $originLine->array_options;
3620 if (
$object->isSituationInvoice()) {
3621 $situation_percent = 0;
3623 $situation_percent = 100;
3626 $fk_unit = $originLine->fk_unit;
3627 $pu_ht_devise = $originLine->multicurrency_subprice;
3629 $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);
3649 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3655 if (!empty(
$object->id) && $action ==
'send') {
3657 $object->getSommePaiement(-1);
3658 $object->getSumCreditNotesUsed(-1);
3659 $object->getSumDepositsUsed(-1);
3661 $triggersendname =
'BILL_SENTBYMAIL';
3663 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3664 $trackid =
'inv'.$object->id;
3665 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3669 $permissiontoadd = $usercancreate;
3670 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3673 if ($action ==
'update_extras' && $permissiontoeditextra) {
3676 $attribute_name =
GETPOST(
'attribute',
'aZ09');
3679 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
3686 $result =
$object->updateExtraField($attribute_name,
'BILL_MODIFY');
3694 $action =
'edit_extras';
3699 if ($action ==
'addcontact' && $usercancreate) {
3700 $result =
$object->fetch($id);
3702 if ($result > 0 && $id > 0) {
3705 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3709 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3712 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3713 $langs->load(
"errors");
3714 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3719 } elseif ($action ==
'swapstatut' && $usercancreate) {
3726 } elseif ($action ==
'deletecontact' && $usercancreate) {
3729 $result =
$object->delete_contact($lineid);
3732 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3740 $action =
'edit_extras';
3764$title =
$object->ref.
" - ".$langs->trans(
'Card');
3765if ($action ==
'create') {
3766 $title = $langs->trans(
"NewBill");
3768$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3774if ($action ==
'create') {
3776 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3781 $res = $soc->fetch($socid);
3784 $currency_code =
$conf->currency;
3786 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3787 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3791 if (empty($dateinvoice)) {
3797 if (!empty($origin) && !empty($originid)) {
3799 $element = $subelement = $origin;
3801 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3802 $element = $regs[1];
3803 $subelement = $regs[2];
3808 if ($element ==
'project') {
3809 $projectid = $originid;
3811 if (empty($cond_reglement_id)) {
3812 $cond_reglement_id = $soc->cond_reglement_id;
3814 if (empty($mode_reglement_id)) {
3815 $mode_reglement_id = $soc->mode_reglement_id;
3817 if (empty($fk_account)) {
3818 $fk_account = $soc->fk_account;
3822 if ($element ==
'order' || $element ==
'commande') {
3823 $element = $subelement =
'commande';
3825 if ($element ==
'propal') {
3826 $element =
'comm/propal';
3827 $subelement =
'propal';
3829 if ($element ==
'contract') {
3830 $element = $subelement =
'contrat';
3832 if ($element ==
'shipping') {
3833 $element = $subelement =
'expedition';
3838 $classname = ucfirst($subelement);
3839 $objectsrc =
new $classname(
$db);
3840 '@phan-var-force Commande|Propal|Contrat|Expedition|Facture $objectsrc';
3842 $objectsrc->fetch($originid);
3843 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3844 $objectsrc->fetch_lines();
3846 $objectsrc->fetch_thirdparty();
3848 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3854 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3858 if (empty($socid)) {
3859 $soc = $objectsrc->thirdparty;
3862 if ($element ==
'expedition') {
3863 $elem = $subelem = $objectsrc->origin_type;
3864 $expeoriginid = $objectsrc->origin_id;
3866 $classname = ucfirst($subelem);
3868 $expesrc =
new $classname(
$db);
3869 '@phan-var-force Expedition $expesrc';
3871 dol_syslog(
"Is type Facture|Commande or Expedition: $element...expesrc($classname)=".get_class($expesrc));
3872 $expesrc->fetch($expeoriginid);
3874 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3875 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3876 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3879 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3880 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3884 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3887 $expesrc->fetch_optionals();
3888 $object->array_options = $expesrc->array_options;
3890 $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)));
3891 $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)));
3892 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : (!empty($fk_account) ? $fk_account : 0)));
3895 if (!empty($objectsrc->multicurrency_code)) {
3896 $currency_code = $objectsrc->multicurrency_code;
3898 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
3899 $currency_tx = $objectsrc->multicurrency_tx;
3904 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3907 $objectsrc->fetch_optionals();
3908 $object->array_options = $objectsrc->array_options;
3912 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
3913 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
3914 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
3915 $inputReasonId = empty($soc->demand_reason_id) ? $inputReasonId : $soc->demand_reason_id;
3917 if (
isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3918 $currency_code = $soc->multicurrency_code;
3923 if (!
GETPOST(
'changecompany')) {
3925 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3928 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3936 if (empty($cond_reglement_id)) {
3937 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
3941 if (empty($mode_reglement_id)) {
3942 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
3952 if (!empty($soc->id)) {
3953 $absolute_discount = $soc->getAvailableDiscounts();
3955 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
3956 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
3958 if (!empty(
$conf->use_javascript_ajax)) {
3959 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3965 if ($origin ==
'contrat') {
3966 $langs->load(
"admin");
3967 $text = $langs->trans(
"ToCreateARecurringInvoice");
3968 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3970 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3972 print
info_admin($text, 0, 0,
'info',
'').
'<br>';
3975 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3976 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3977 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3978 print
'<input type="hidden" name="changecompany" value="0">';
3980 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3982 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3983 print
'<input name="ref" type="hidden" value="provisoire">';
3984 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3985 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3986 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3987 print
'<input name="force_fk_account" type="hidden" value="0">';
3988 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3989 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3990 print
'<input type="hidden" name="originentity" value="'.GETPOSTINT(
'originentity').
'">';
3991 if (!empty($currency_tx)) {
3992 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3998 $parameters = array();
4000 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters, $object, $action);
4001 if (empty($reshook)) {
4002 print
'<table class="border centpercent">';
4006 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
4007 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
4020 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
4022 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
'Customer').
'</td>';
4023 print
'<td colspan="2">';
4024 print $soc->getNomUrl(1,
'customer');
4025 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
4027 $arrayoutstandingbills = $soc->getOutstandingBills();
4028 $outstandingBills = $arrayoutstandingbills[
'opened'];
4029 print
' - <span class="opacitymedium valignmiddle">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
4030 print
'<span class="amount valignmiddle">'.price($outstandingBills, 0, $langs, 0, 0, -1,
$conf->currency).
'</span>';
4031 if ($soc->outstanding_limit !=
'') {
4032 if ($outstandingBills > $soc->outstanding_limit) {
4033 print
img_warning($langs->trans(
"OutstandingBillReached"));
4035 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1,
$conf->currency);
4040 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
4041 print
'<td colspan="2">';
4042 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
4043 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
4047 $(document).ready(function() {
4048 $("#socid").change(function() {
4050 console.log("Submit page");
4051 $(\'input[name="action"]\').val(\'create\');
4052 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
4053 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
4054 $(\'input[name="force_fk_account"]\').val(\'1\');
4055 $("#formtocreate").submit(); */
4057 // For company change, we must submit page with action=create instead of action=add
4058 console.log("We have changed the company - Resubmit page");
4059 jQuery("input[name=changecompany]").val("1");
4060 jQuery("#formtocreateaction").val("create");
4061 jQuery("#formtocreate").submit();
4067 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>';
4074 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
4076 foreach ($invoice_predefined->array_options as $key => $option) {
4077 if (!isset(
$object->array_options[$key])) {
4078 $object->array_options[$key] = $invoice_predefined->array_options[$key];
4082 $dateinvoice = $invoice_predefined->date_when;
4083 if (empty($projectid)) {
4084 $projectid = $invoice_predefined->fk_project;
4086 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
4087 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
4088 $fk_account = $invoice_predefined->fk_account;
4089 $note_public = $invoice_predefined->note_public;
4090 $note_private = $invoice_predefined->note_private;
4092 if (!empty($invoice_predefined->multicurrency_code)) {
4093 $currency_code = $invoice_predefined->multicurrency_code;
4095 if (!empty($invoice_predefined->multicurrency_tx)) {
4096 $currency_tx = $invoice_predefined->multicurrency_tx;
4099 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
4100 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
4101 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
4103 $resql =
$db->query($sql);
4105 $num =
$db->num_rows($resql);
4109 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
4111 print
'<select class="flat" id="fac_rec" name="fac_rec">';
4112 print
'<option value="0" selected></option>';
4114 $objp =
$db->fetch_object($resql);
4115 print
'<option value="'.$objp->rowid.
'"';
4118 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
4120 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
4129 print
'<script type="text/javascript">
4130 $(document).ready(function() {
4131 $("#fac_rec").change(function() {
4132 console.log("We have changed the template invoice - Reload page");
4133 var fac_rec = $(this).val();
4134 var socid = $(\'#socid\').val();
4135 // 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.
4136 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
4149 print
'<tr><td class="tdtop fieldrequired titlefieldcreate">'.$langs->trans(
'Type').
'</td><td colspan="2">';
4150 print
'<div class="listofinvoicetypetable">'.
"\n";
4153 print
'<div class="listofinvoicetype"><div class="">';
4154 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
4155 $tmp .=
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk");
4156 $tmp .=
' <span class="opacitymedium">'.$langs->trans(
"InvoiceStandardAsk2").
'</span>';
4159 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc").
'<br><br>'.$langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'nowraponall', 0, 3,
'standardonsmartphone');
4161 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
4171 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%') .
'"/>';
4174 print
'</div></div>'.
"\n";
4176 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
4179 print
'<div class="listofinvoicetype"><div class="">';
4180 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
4181 print
'<script type="text/javascript">
4182 jQuery(document).ready(function() {
4183 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
4184 jQuery("#radio_standard").prop("checked", true);
4186 jQuery("#typedeposit, #valuedeposit").click(function() {
4187 jQuery("#radio_deposit").prop("checked", true);
4189 jQuery("#typedeposit").change(function() {
4190 console.log("We change type of down payment: "+jQuery("#typedeposit").val());
4192 if (jQuery("#typedeposit").val() == "amount") {
4193 jQuery("#valuedeposit").attr("placeholder", "'.$langs->getCurrencySymbol(
$conf->currency).
'");
4194 jQuery("#valuedeposit").val("");
4196 jQuery("#valuedeposit").attr("placeholder", "50%");
4197 jQuery("#valuedeposit").val("");
4200 jQuery("#radio_deposit").prop("checked", true);
4201 setRadioForTypeOfInvoice();
4203 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
4204 setRadioForTypeOfInvoice();
4207 function setRadioForTypeOfInvoice() {
4208 console.log("Change radio for type of invoice");
4209 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
4210 jQuery("#checkforselects").prop("disabled", true);
4211 jQuery("#checkforselects").prop("checked", false);
4212 jQuery(".checkforselect").prop("disabled", true);
4213 jQuery(".checkforselect").prop("checked", false);
4215 jQuery("#checkforselects").prop("disabled", false);
4216 jQuery("#checkforselects").prop("checked", true);
4217 jQuery(".checkforselect").prop("disabled", false);
4218 jQuery(".checkforselect").prop("checked", true);
4224 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
4226 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
4228 if (($origin ==
'propal') || ($origin ==
'commande')) {
4231 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
4232 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
4233 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4237 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4241 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
4243 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
4244 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
4245 if (!empty($origin_payment_conditions_deposit_percent)) {
4246 $typedeposit =
'variable';
4249 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
4250 $valuedeposit = $objectsrc->deposit_percent;
4252 print
'<span class="marginleftonly">'.$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1).
'</span>';
4254 print
'<input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.($valuedeposit ? $valuedeposit :
'').
'"'.($valuedeposit ?
'' :
'placeholder="'.$langs->getCurrencySymbol(
$conf->currency).
'"').
'>';
4257 print
'</div></div>'.
"\n";
4264 print
'<div class="listofinvoicetype"><div class="">';
4265 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
4266 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
4268 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
4272 $opt = $form->selectSituationInvoices((
string)
GETPOSTINT(
'originid'), $socid);
4275 print
'</div></div><div class="listofinvoicetype"><div>';
4277 $tmp =
'<input id="radio_situation_bis" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
4278 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4279 $tmp .=
' disabled';
4282 $text = $tmp.
'<label for="radio_situation_bis">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4284 $text .=
'<select class="flat minwidth125" id="situations" name="situations"';
4285 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4286 $text .=
' disabled';
4290 $text .=
'</select>';
4291 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
4293 print
'</div></div>'.
"\n";
4299 $facids = $facturestatic->list_replacable_invoices($soc->id);
4305 if (is_array($facids)) {
4306 foreach ($facids as $facparam) {
4307 $options .=
'<option value="'.$facparam [
'id'].
'"';
4308 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
4309 $options .=
' selected';
4311 $options .=
'>'.$facparam[
'ref'];
4312 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
4313 $options .=
'</option>';
4317 print
'<!-- replacement line -->';
4318 print
'<div class="listofinvoicetype"><div class="">';
4319 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
4320 if (!$options || $invoice_predefined->id > 0) {
4321 $tmp .=
' disabled';
4324 print
'<script type="text/javascript">
4325 jQuery(document).ready(function() {
4326 jQuery("#fac_replacement").change(function() {
4327 console.log("We change fac_replacement");
4328 jQuery("#radio_replacement").prop("checked", true);
4332 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
4333 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
4334 if (!$options || $invoice_predefined->id > 0) {
4335 $text .=
' disabled';
4339 $text .=
'<option value="-1"> </option>';
4342 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
4344 $text .=
'</select>';
4345 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
4347 print
'</div></div>'.
"\n";
4351 print
'<div class="listofinvoicetype"><div class="">';
4352 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
4353 $text = $tmp.
'<label class="opacitymedium">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4354 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'firstsituationonsmartphone');
4356 print
'</div></div>'.
"\n";
4359 print
'<div class="listofinvoicetype"><div class="">';
4360 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
4361 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
4362 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'replacementonsmartphone');
4364 print
'</div></div>'.
"\n";
4367 if (empty($origin)) {
4372 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
4379 foreach ($facids as $key => $valarray) {
4380 $newinvoice_static->id = $key;
4381 $newinvoice_static->ref = $valarray [
'ref'];
4382 $newinvoice_static->statut = $valarray [
'status'];
4383 $newinvoice_static->status = $valarray [
'status'];
4384 $newinvoice_static->type = $valarray [
'type'];
4385 $newinvoice_static->paye = $valarray [
'paye'];
4386 $newinvoice_static->paid = $valarray [
'paye'];
4388 $optionsav .=
'<option value="'.$key.
'"';
4389 if ($key ==
GETPOST(
'fac_avoir')) {
4390 $optionsav .=
' selected';
4393 $newinvoice_static->fetch_optionals($key);
4394 $object->array_options = $newinvoice_static->array_options;
4397 $optionsav .= $newinvoice_static->ref;
4398 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
4399 $optionsav .=
'</option>';
4402 print
'<div class="listofinvoicetype"><div class="">';
4403 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
4404 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
4405 $tmp .=
' disabled';
4409 print
'<script type="text/javascript">
4410 jQuery(document).ready(function() {
4411 if (jQuery("#radio_creditnote").is(":checked")) {
4412 jQuery("#radio_standard").prop("disabled", true);
4413 jQuery("#radio_deposit").prop("disabled", true);
4415 jQuery("#radio_standard").prop("disabled", false);
4416 jQuery("#radio_deposit").prop("disabled", false);
4418 if (! jQuery("#radio_creditnote").is(":checked")) {
4419 jQuery("#credit_note_options").hide();
4421 jQuery("#radio_creditnote").click(function() {
4422 jQuery("#credit_note_options").show();
4424 jQuery("#radio_standard, #radio_replacement, #radio_deposit, #radio_situation, #radio_situation_bis").click(function() {
4425 console.log("We click on a radio to close credit not options");
4426 jQuery("#credit_note_options").hide();
4430 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
4431 $text .=
'<select class="flat valignmiddle minwidth200" name="fac_avoir" id="fac_avoir"';
4432 if (!$optionsav || $invoice_predefined->id > 0) {
4433 $text .=
' disabled';
4437 $text .=
'<option value="-1">'.$langs->trans(
"InvoiceAvoirAskCombo").
'</option>';
4438 $text .= $optionsav;
4440 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
4442 $text .=
'</select>';
4443 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
4446 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
4447 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>";
4448 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>";
4453 print
'</div></div>'.
"\n";
4456 print
'<div class="listofinvoicetype"><div class="">';
4458 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
4460 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
4462 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
4464 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
4466 print
'</div></div>'.
"\n";
4487 foreach ($listtType as $type) {
4488 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
4490 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
4493 print
'<script type="text/javascript">
4494 $(document).ready(function() {
4495 var listType = {'.$jsListType.
'};
4496 $("[name=\'type\']").change(function() {
4497 console.log("change name=type");
4498 if ($( this ).prop("checked"))
4500 if(($( this ).val() in listType))
4502 $("#model").val(listType[$( this ).val()]).trigger("change");
4519 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
4520 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
4526 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
4530 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
4533 $defaulttpldir =
'/core/tpl';
4534 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array($defaulttpldir));
4535 foreach ($dirtpls as $module => $reldir) {
4537 if (!empty($module)) {
4540 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
4542 if (file_exists($tpl)) {
4543 if (empty(
$conf->file->strict_mode)) {
4544 $res = @include $tpl;
4546 $res = include $tpl;
4561 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
4562 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4563 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
4568 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
4569 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4570 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
4575 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
4576 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
4577 print $form->getSelectConditionsPaiements((
int) $cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
4582 $rwStyle =
'display:none;';
4583 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
4587 $retained_warranty =
GETPOSTINT(
'retained_warranty');
4588 if (empty($retained_warranty)) {
4589 if ($objectsrc !==
null && property_exists($objectsrc,
'retained_warranty') && !empty($objectsrc->retained_warranty)) {
4591 $retained_warranty = $objectsrc->retained_warranty;
4594 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
4596 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
4597 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
4600 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
4601 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
4602 if (empty($retained_warranty_fk_cond_reglement)) {
4603 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4604 if ($objectsrc instanceOf
Facture && !empty($objectsrc->retained_warranty_fk_cond_reglement)) {
4606 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
4609 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4612 print
'<script type="text/javascript">
4613 $(document).ready(function() {
4614 $("[name=\'type\']").change(function() {
4615 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
4617 $(".retained-warranty-line").show();
4618 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
4621 $(".retained-warranty-line").hide();
4622 $("#new-situation-invoice-retained-warranty").val("");
4626 $("[name=\'type\']:checked").trigger("change");
4632 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
4633 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
4634 print $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth250 widthcentpercentminusx', 1);
4639 print
'<tr><td>'.$langs->trans(
'DefaultBankAccount').
'</td><td colspan="2">';
4640 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4641 print $form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth250 widthcentpercentminusx', 1);
4647 print
'<tr><td>'.$langs->trans(
'Source').
'</td><td>';
4648 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
4649 $form->selectInputReason((
string) $inputReasonId,
'input_reason_id',
'', 1,
'maxwidth250 widthcentpercentminusx');
4652 print
'<input type="hidden" name="input_reason_id" value="'.((string) $inputReasonId).
'">';
4656 if (
isModEnabled(
'project') && is_object($formproject)) {
4657 $langs->load(
'projects');
4658 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
4659 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
4661 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');
4662 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>';
4669 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
4670 print
'<td colspan="2" class="maxwidthonsmartphone">';
4671 $incoterm_id =
GETPOST(
'incoterm_id');
4672 $location_incoterms =
GETPOST(
'location_incoterms');
4673 if (empty($incoterm_id)) {
4674 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
4675 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
4677 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
4678 print $form->select_incoterms($incoterm_id, $location_incoterms);
4692 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
4693 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
4698 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
4699 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
4700 print $hookmanager->resPrint;
4701 if (empty($reshook)) {
4702 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
4705 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
4706 if ($soc->fetch_optionals() > 0) {
4707 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
4711 print
$object->showOptionals($extrafields,
'create', $parameters);
4715 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
4717 if (is_array($list) && count($list) > 0) {
4721 $paramkey =
'FACTURE_ADDON_PDF_'.$type;
4726 if (count($list) > 1) {
4727 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
4728 print
'<td colspan="2">';
4729 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
4730 print $form->selectarray(
'model', $list, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
4733 print
'<input type="hidden" name="model" value="'.$preselected.
'">';
4740 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
4741 print
'<td colspan="2" class="maxwidthonsmartphone">';
4742 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
4743 print $form->selectMultiCurrency(((
GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth200 widthcentpercentminusx');
4750 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
4751 if (empty($dateexample)) {
4754 $substitutionarray = array(
4755 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
4756 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
4757 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
4758 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
4759 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
4760 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
4761 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
4762 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
4763 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
4764 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
4765 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
4768 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
4769 foreach ($substitutionarray as $key => $val) {
4770 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
4772 $htmltext .=
'</i>';
4777 print
'<td class="tdtop">';
4778 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
4780 print
'<td valign="top" colspan="2">';
4781 $doleditor =
new DolEditor(
'note_public', (
string) $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
4782 print $doleditor->Create(1);
4785 if (empty($user->socid)) {
4787 print
'<td class="tdtop">';
4788 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4790 print
'<td valign="top" colspan="2">';
4791 $doleditor =
new DolEditor(
'note_private', (
string) $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4792 print $doleditor->Create(1);
4798 if (!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($classname)) {
4799 $langs->loadLangs(array(
'orders',
'propal'));
4802 if ($origin ==
'contrat') {
4803 '@phan-var-force Contrat $objectsrc';
4805 $objectsrc->update_price(1,
'auto', 1);
4808 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4809 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4810 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4811 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4816 switch (get_class($objectsrc)) {
4818 $newclassname =
'CommercialProposal';
4821 $newclassname =
'Order';
4824 $newclassname =
'Sending';
4827 $newclassname =
'Contract';
4830 $newclassname =
'Intervention';
4833 $newclassname = get_class($objectsrc);
4837 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4838 print
'<td colspan="2">';
4839 print $objectsrc->getNomUrl(1);
4841 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
4842 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4844 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4848 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht, 1, $langs, 1, -1,
'',
$conf->currency).
'</td></tr>';
4849 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
4850 if (
$mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4851 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>";
4854 if (
$mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4855 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>";
4857 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
4859 if (
isModEnabled(
'multicurrency') && $objectsrc->multicurrency_code !=
$conf->currency) {
4861 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
'</td></tr>';
4862 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4863 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4871 print $form->buttonsSaveCancel(
"CreateDraft");
4874 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4877 $title = $langs->trans(
'ProductsAndServices');
4880 print
'<div class="div-table-responsive-no-min">';
4881 print
'<table class="noborder centpercent">';
4883 $objectsrc->printOriginLinesList(
'', $selectedLines);
4890} elseif ($id > 0 || !empty($ref)) {
4892 $langs->load(
'errors');
4893 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4902 if ($user->socid > 0 && $user->socid !=
$object->socid) {
4906 $result =
$object->fetch_thirdparty();
4908 $result = $soc->fetch(
$object->socid);
4912 $selleruserevenustamp =
$mysoc->useRevenueStamp();
4914 $totalpaid =
$object->getSommePaiement();
4915 $totalcreditnotes =
$object->getSumCreditNotesUsed();
4916 $totaldeposits =
$object->getSumDepositsUsed();
4922 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4926 $multicurrency_totalpaid =
$object->getSommePaiement(1);
4927 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
4928 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
4929 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4933 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
4934 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
4938 if (
$object->paye ||
$object->status == $object::STATUS_CLOSED) {
4941 $resteapayeraffiche = $resteapayer;
4944 $filterabsolutediscount =
"fk_facture_source IS NULL";
4945 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4947 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4948 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4951 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
4952 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
4953 $absolute_discount =
price2num($absolute_discount,
'MT');
4954 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4956 $nb_creditnote_notyetavailable = $soc->getOpenCreditNotesNotYetConvertedIntoDiscount(0);
4959 if (
$object->user_creation_id) {
4960 $author->fetch(
$object->user_creation_id);
4963 $objectidnext =
$object->getIdReplacingInvoice();
4967 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
$object->picto, 0,
'',
'', 0,
'', 1);
4972 if ($action ==
'converttoreduc') {
4974 $type_fac =
'ExcessReceived';
4976 $type_fac =
'CreditNote';
4978 $type_fac =
'Deposit';
4982 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4983 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4984 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4988 if ($action ==
'delete') {
4989 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
4990 $formquestion = array();
4993 $qualified_for_stock_change = 0;
4995 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4997 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5000 if ($qualified_for_stock_change) {
5001 $langs->load(
"stocks");
5002 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5006 if (
$conf->browser->name ==
'ie') {
5009 $formquestion = array(
5013 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
5015 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
5017 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
5020 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
5025 if ($action ==
'situationout') {
5026 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
5027 $label = $langs->trans(
"ConfirmOuting");
5028 $formquestion = array();
5033 &&
$object->is_last_in_cycle()
5034 && $usercanunvalidate
5036 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
5041 if ($action ==
'valid') {
5043 $objectref = substr(
$object->ref, 1, 4);
5044 if ($objectref ==
'PROV') {
5048 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
5050 $numref =
$object->getNextNumRef($soc);
5056 $text = $langs->trans(
'ConfirmValidateBill', $numref);
5058 $text .=
'<br><br>';
5059 $text .=
img_picto(
'',
'warning',
'class="pictofixedwidth"').
' '.$langs->trans(
'WarningInvoiceCanNeverBeEdited');
5062 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
5065 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid, $object);
5067 $formquestion = array();
5070 $qualified_for_stock_change = 0;
5072 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5074 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5077 if ($qualified_for_stock_change) {
5078 $langs->load(
"stocks");
5079 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5080 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
5083 $warehouse_array = $warehouse->list_array();
5084 if (count($warehouse_array) == 1) {
5085 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
5086 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5089 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5091 $formquestion = array(
5097 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5101 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
5106 foreach (
$object->lines as $line) {
5107 $res = $line->fetch_product();
5109 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
5115 if ($nbMandated > 0) {
5117 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
5120 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
5125 $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);
5130 if ($action ==
'modif') {
5133 $testvalue =
$object->isEditable();
5134 if ($testvalue < 0) {
5135 switch ($testvalue) {
5138 setEventMessages($langs->trans(
"DisabledBecauseDispatchedInBookkeeping"),
null,
'errors');
5142 setEventMessages($langs->trans(
"DisabledBecauseNotLastInvoice"),
null,
'errors');
5146 setEventMessages($langs->trans(
"DisabledBecauseNotLastSituationInvoice"),
null,
'errors');
5150 setEventMessages($langs->trans(
"DisabledBecauseThereIsAPayment"),
null,
'errors');
5154 setEventMessages($langs->trans(
"DisabledBecauseAlreadySentByEmail"),
null,
'errors');
5158 setEventMessages($langs->trans(
"DisabledBecauseAlreadyPrintedOnce"),
null,
'errors');
5174 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
5175 $formquestion = array();
5178 $qualified_for_stock_change = 0;
5180 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5182 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5185 if ($qualified_for_stock_change) {
5186 $langs->load(
"stocks");
5187 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5188 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
5191 $warehouse_array = $warehouse->list_array();
5192 if (count($warehouse_array) == 1) {
5193 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
5194 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5197 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5199 $formquestion = array(
5205 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5209 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
5214 if ($action ==
'canceled') {
5218 $statusreplacement = 0;
5220 if ($objectidnext) {
5222 $facturereplacement->fetch($objectidnext);
5223 $statusreplacement = $facturereplacement->status;
5225 if ($objectidnext && $statusreplacement == 0) {
5226 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
5230 $close[1][
'code'] =
'badcustomer';
5231 $close[2][
'code'] =
'abandon';
5233 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5234 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
5236 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
5237 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
5240 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
5241 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
5244 $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'));
5246 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 300);
5251 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
5252 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
5254 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
5258 $close[$i][
'code'] = $object::CLOSECODE_DISCOUNTVAT;
5260 $close[$i][
'code'] = $object::CLOSECODE_BADDEBT;
5262 $close[$i][
'code'] = $object::CLOSECODE_BANKCHARGE;
5264 $close[$i][
'code'] = $object::CLOSECODE_WITHHOLDINGTAX;
5266 $close[$i][
'code'] = $object::CLOSECODE_OTHER;
5270 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
5272 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5274 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
5276 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
5278 $close[$i][
'label'] = $langs->trans(
"Other");
5282 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5284 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5286 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5288 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
5290 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
5294 foreach ($close as $key => $val) {
5295 $arrayreasons[$close[$key][
'code']] =
'<span class="small">'.$close[$key][
'reason'].
'</span>';
5299 $formquestion = array(
5300 'text' => $langs->trans(
"ConfirmClassifyPaidPartiallyQuestion"),
5301 0 => array(
'type' =>
'radio',
'name' =>
'close_code',
'label' =>
'',
'values' => $arrayreasons),
5302 1 => array(
'type' =>
'text',
'name' =>
'close_note',
'moreattr' =>
'placeholder = "'.$langs->trans(
"Comment").
'"',
'value' =>
'',
'morecss' =>
'minwidth300'),
5303 2 => array(
'type' =>
'separator')
5306 $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);
5309 if ($action ==
'deletepayment') {
5310 $payment_id =
GETPOST(
'paiement_id');
5311 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
5315 if ($action ==
'ask_deleteline') {
5316 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
5320 if ($action ==
'ask_subtotal_deleteline') {
5321 $langs->load(
"subtotals");
5322 $title =
"DeleteSubtotalLine";
5323 $question =
"ConfirmDeleteSubtotalLine";
5324 if (
GETPOST(
'type') ==
'title') {
5325 $formconfirm = array(array(
'type' =>
'checkbox',
'name' =>
'deletecorrespondingsubtotalline',
'label' => $langs->trans(
"DeleteCorrespondingSubtotalLine"),
'value' => 0));
5326 $title =
"DeleteTitleLine";
5327 $question =
"ConfirmDeleteTitleLine";
5329 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans($title), $langs->trans($question),
'confirm_delete_subtotalline', $formconfirm,
'no', 1);
5333 if ($action ==
'clone') {
5334 $filter =
'(s.client:IN:1,2,3)';
5336 $formquestion = array(
5337 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
$object->socid,
'socid', $filter, 1)),
5338 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
5341 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 0);
5345 if ($action ==
'add_title_line') {
5346 $langs->load(
'subtotals');
5348 $depth_array =
$object->getPossibleLevels($langs);
5350 } elseif ($action ==
'add_subtotal_line') {
5351 $langs->load(
'subtotals');
5353 $titles =
$object->getPossibleTitles();
5357 if ($action ==
"remove_file_comfirm") {
5358 $file =
GETPOST(
'file',
'alpha');
5360 $formconfirm = $form->formconfirm(
5361 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
5362 $langs->trans(
'DeleteFileHeader'),
5363 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
5372 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
5373 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
5374 if (empty($reshook)) {
5375 $formconfirm .= $hookmanager->resPrint;
5376 } elseif ($reshook > 0) {
5377 $formconfirm = $hookmanager->resPrint;
5385 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
5387 $morehtmlref =
'<div class="refidno">';
5390 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5391 $morehtmlref .= $form->editfieldval(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'',
null,
null,
'', 1);
5392 $morehtmlref .=
'<br>';
5395 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5396 $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);
5398 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
5400 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'">'.$langs->trans(
"OtherBills").
'</a>)';
5404 $langs->load(
"projects");
5405 $morehtmlref .=
'<br>';
5406 if ($usercancreate) {
5407 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
5408 if ($action !=
'classify') {
5409 $morehtmlref .=
'<a class="editfielda" href="'.dolBuildUrl($_SERVER[
'PHP_SELF'], [
'action' =>
'classify',
'id' =>
$object->id],
true).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
5411 $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');
5413 if (!empty(
$object->fk_project)) {
5415 $proj->fetch(
$object->fk_project);
5416 $morehtmlref .= $proj->getNomUrl(1);
5418 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
5423 $morehtmlref .=
'</div>';
5425 $object->totalpaid = $totalpaid;
5426 $object->totalcreditnotes = $totalcreditnotes;
5427 $object->totaldeposits = $totaldeposits;
5430 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
5433 $parameters = array();
5435 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters, $object, $action);
5436 if (empty($reshook)) {
5437 print
'<div class="fichecenter">';
5438 print
'<div class="fichehalfleft">';
5439 print
'<div class="underbanner clearboth"></div>';
5441 print
'<table class="border centpercent tableforfield">';
5444 print
'<tr><td class="fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
5447 print
' '.$object->getSubtypeLabel(
'facture');
5451 $facreplaced->fetch(
$object->fk_facture_source);
5452 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
5456 $facusing->fetch(
$object->fk_facture_source);
5457 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
5461 $object->getListIdAvoirFromInvoice();
5463 if (!empty(
$object->creditnote_ids)) {
5464 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
5466 foreach (
$object->creditnote_ids as $invoiceid) {
5473 $creditnote->fetch($invoiceid);
5474 print $creditnote->getNomUrl(1,
'', 32);
5478 if ($objectidnext > 0) {
5480 $facthatreplace->fetch($objectidnext);
5481 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
5486 $result = $discount->fetch(0,
$object->id);
5488 print
' <span class="opacitymediumbycolor paddingleft">';
5489 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
5490 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
5491 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
5493 print
'</span><br>';
5497 if (
$object->fk_fac_rec_source > 0) {
5499 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
5501 print
' <span class="opacitymediumbycolor paddingleft">';
5502 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
5503 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
5507 print
' <span class="opacitymediumbycolor paddingleft">';
5508 print $langs->transnoentities(
"GeneratedFromTemplate", $langs->trans(
"ObjectDeleted"));
5516 $langs->load(
"cashdesk");
5517 print
'<tr><td class="fieldname_type">';
5518 print
'<table class="nobordernopadding centpercent"><tr><td>';
5519 print $form->textwithpicto($langs->trans(
'PointOfSale'), $langs->trans(
'POSInfo'));
5521 if ($action !=
'editposinfo' && $usercancreate) {
5522 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>';
5524 print
'</tr></table>';
5525 print
'</td><td class="valuefield fieldname_type">';
5526 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" name="formposinfo">';
5527 print
'<input type="hidden" name="action" value="setposinfo">';
5528 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5529 if ($action ==
'editposinfo') {
5530 print
'<input type="text" class="maxwidth150" name="posmodule" placeholder="'.$langs->trans(
"POSModule").
'" value="'.
$object->module_source.
'"> ';
5531 print
'<input type="text" class="maxwidth100" name="posterminal" placeholder="'.$langs->trans(
"Terminal").
'" value="'.
$object->pos_source.
'">';
5532 print
'<input type="submit" class="button" name="submitposinfo" value="'.$langs->trans(
"Submit").
'">';
5535 print
'<span class="opacitymediumbycolor paddingleft">'.dolPrintHTML(ucfirst(
$object->module_source).
' - '.$langs->transnoentitiesnoconv(
"Terminal").
' '.
$object->pos_source).
'</span>';
5543 print
'<!-- Discounts -->'.
"\n";
5544 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
5548 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
5549 $defaulttpldir =
'/core/tpl';
5551 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array($defaulttpldir));
5552 foreach ($dirtpls as $module => $reldir) {
5554 if (!empty($module)) {
5557 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
5559 if (file_exists($tpl)) {
5560 if (empty(
$conf->file->strict_mode)) {
5561 $res = @include $tpl;
5563 $res = include $tpl;
5575 print
'<table class="nobordernopadding centpercent"><tr><td>';
5576 print $langs->trans(
'DateInvoice');
5578 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
5579 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>';
5581 print
'</tr></table>';
5583 if ($action ==
'editinvoicedate') {
5584 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
5586 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
5601 print
'<table class="nobordernopadding centpercent"><tr><td>';
5602 print $langs->trans(
'DatePointOfTax');
5605 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>';
5607 print
'</tr></table>';
5609 if ($action ==
'editdate_pointoftax' && $editable) {
5610 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
5612 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
5620 print $form->editfieldkey(
'Source',
'input_reason',
'', $object, (
int) $usercancreate);
5621 print
'</td><td class="valuefield">';
5622 if ($action ==
'editinput_reason') {
5623 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'input_reason_id', 1,
'maxwidth250 widthcentpercentminusx');
5625 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'none');
5632 print
'<table class="nobordernopadding centpercent"><tr><td>';
5633 print $langs->trans(
'PaymentConditionsShort');
5636 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>';
5638 print
'</tr></table>';
5641 if ($action ==
'editconditions') {
5642 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
5644 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
5651 print
'<table class="nobordernopadding centpercent"><tr><td>';
5652 print $langs->trans(
'DateMaxPayment');
5655 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>';
5657 print
'</tr></table>';
5660 if ($action ==
'editpaymentterm') {
5661 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
5663 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
5673 print
'<table class="nobordernopadding centpercent"><tr><td>';
5674 print $langs->trans(
'PaymentMode');
5676 if ($action !=
'editmode' && $usercancreate) {
5677 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>';
5679 print
'</tr></table>';
5681 if ($action ==
'editmode') {
5682 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
5684 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'none',
'CRDT');
5690 print
'<tr><td class="nowrap">';
5691 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
5692 print $langs->trans(
'DefaultBankAccount');
5694 if (($action !=
'editbankaccount') && $usercancreate) {
5695 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>';
5697 print
'</tr></table>';
5699 if ($action ==
'editbankaccount') {
5700 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
5702 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
5711 print
'<table class="nobordernopadding centpercent"><tr><td>';
5712 print $langs->trans(
'IncotermLabel');
5713 print
'<td><td class="right">';
5714 if ($usercancreate) {
5715 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
5717 print
'</td></tr></table>';
5720 if ($action !=
'editincoterm') {
5721 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
5723 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
5730 print
'<table class="nobordernopadding centpercent"><tr><td>';
5731 print $langs->trans(
'Dispute');
5732 print
'<td><td class="right">';
5733 if ($usercancreate) {
5734 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editdispute_status&token='.
newToken().
'">'.
img_edit().
'</a>';
5736 print
'</td></tr></table>';
5738 $liststatus = Facture::ARRAY_OF_DISPUTE_STATUS;
5739 if ($action !=
'editdispute_status') {
5740 if (
$object->dispute_status) {
5741 print $langs->trans($liststatus[
$object->dispute_status][
'label']);
5744 print
'<form enctype="multipart/form-data" action="'.DOL_URL_ROOT.
'/compta/facture/card.php" method="POST">';
5745 print
'<input type="hidden" name="action" value="set_dispute_status">';
5746 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5747 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
5748 print
'<input type="hidden" name="page_y" value="">';
5749 print $form->selectarray(
'dispute_status', $liststatus,
$object->dispute_status, 0, 0, 0,
'', 1);
5750 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Save").
'">';
5758 print
'<table class="nobordernopadding centpercent"><tr><td>';
5759 print $langs->trans(
"Categories");
5760 print
'<td><td class="right">';
5761 if ($usercancreate) {
5762 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
5766 print
'</td></tr></table>';
5769 if ($action ==
'edittags') {
5770 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5771 print
'<input type="hidden" name="action" value="settags">';
5772 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5773 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
5774 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5777 print $form->showCategories(
$object->id, Categorie::TYPE_INVOICE, 1);
5782 $displayWarranty =
false;
5785 $displayWarranty =
true;
5786 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
5787 $displayWarranty =
false;
5790 if ($displayWarranty) {
5792 print
'<tr class="retained-warranty-lines" ><td>';
5793 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
5794 print $langs->trans(
'RetainedWarranty');
5797 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>';
5800 print
'</tr></table>';
5803 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5804 print
'<input type="hidden" name="action" value="setretainedwarranty">';
5805 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5806 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5807 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
5808 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5816 print
'<tr class="retained-warranty-lines" ><td>';
5817 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
5818 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
5820 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
5821 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>';
5824 print
'</tr></table>';
5826 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5827 if (
$object->date > $defaultDate) {
5833 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5834 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
5835 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5836 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5837 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
5838 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
5839 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
5840 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
5841 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5844 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->retained_warranty_fk_cond_reglement,
'none');
5845 if (!$displayWarranty) {
5846 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning',
'class="pictowarning valignmiddle" ');
5852 print
'<tr class="retained-warranty-lines" ><td>';
5853 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
5854 print $langs->trans(
'RetainedWarrantyDateLimit');
5857 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>';
5860 print
'</tr></table>';
5862 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5863 if (
$object->date > $defaultDate) {
5868 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5869 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
5870 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5871 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5873 print $form->selectDate($defaultDate,
'retained_warranty_date_limit');
5874 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5886 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
5891 print
'<div class="fichehalfright">';
5893 print
'<!-- amounts -->'.
"\n";
5894 print
'<div class="underbanner clearboth"></div>'.
"\n";
5896 print
'<table class="border tableforfield centpercent">';
5898 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
5906 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
5907 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5910 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5916 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
5917 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5920 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5925 if ((
$mysoc->localtax1_assuj ==
"1" &&
$mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
5927 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1",
$mysoc->country_code) .
'</td>';
5928 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5932 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5937 if ((
$mysoc->localtax2_assuj ==
"1" &&
$mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
5939 print
'<td>' . $langs->transcountry(
"AmountLT2",
$mysoc->country_code) .
'</td>';
5940 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5944 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5950 if ($selleruserevenustamp) {
5951 print
'<tr><td class="titlefieldmiddle">';
5952 print
'<table class="nobordernopadding centpercent"><tr><td>';
5953 print $langs->trans(
'RevenueStamp');
5955 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
5956 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>';
5958 print
'</tr></table>';
5959 print
'</td><td class="nowrap amountcard right">';
5960 if ($action ==
'editrevenuestamp') {
5961 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
5962 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5963 print
'<input type="hidden" name="action" value="setrevenuestamp">';
5964 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
5965 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5966 print $formother->select_revenue_stamp(
'',
'revenuestamp_type',
$mysoc->country_code);
5967 print
' → <span id="revenuestamp_span"></span>';
5968 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
5971 $(document).ready(function(){
5972 js_recalculate_revenuestamp();
5973 $('select[name=revenuestamp_type]').on('change',function(){
5974 js_recalculate_revenuestamp();
5977 function js_recalculate_revenuestamp(){
5978 var valselected = $('select[name=revenuestamp_type]').val();
5979 console.log('Calculate revenue stamp from '+valselected);
5981 if (valselected.indexOf('%') == -1)
5983 revenue = valselected;
5987 var revenue_type = parseFloat(valselected);
5988 var amount_net = ".round(
$object->total_ht, 2).
";
5989 revenue = revenue_type * amount_net / 100;
5990 revenue = revenue.toFixed(2);
5992 $('#revenuestamp_val').val(revenue);
5993 $('#revenuestamp_span').html(revenue);
6004 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
6005 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
6008 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
6023 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
6026 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
6029 if ($selleruserevenustamp) {
6039 $total_prev_ht = $total_prev_ttc = 0;
6040 $total_global_ht = $total_global_ttc = 0;
6044 print
'<!-- List of situation invoices -->';
6045 print
'<div class="div-table-responsive-no-min">';
6046 print
'<table class="noborder paymenttable centpercent situationstable">';
6048 print
'<tr class="liste_titre">';
6049 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
6051 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
6054 print
'<td class="right"></td>';
6056 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
6057 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
6058 print
'<td width="18"> </td>';
6061 if (count(
$object->tab_previous_situation_invoice) > 0) {
6064 $current_situation_counter = array();
6065 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
6066 $tmptotalallpayments = $prev_invoice->getSommePaiement(0);
6067 $tmptotalallpayments += $prev_invoice->getSumDepositsUsed(0);
6068 $tmptotalallpayments += $prev_invoice->getSumCreditNotesUsed(0);
6070 $total_prev_ht += $prev_invoice->total_ht;
6071 $total_prev_ttc += $prev_invoice->total_ttc;
6073 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
6074 print
'<tr class="oddeven">';
6075 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
6077 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
6079 print
'<td class="right"></td>';
6081 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
6082 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
6083 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalallpayments).
'</td>';
6088 $totalallpayments =
$object->getSommePaiement(0);
6089 $totalallpayments +=
$object->getSumCreditNotesUsed(0);
6090 $totalallpayments +=
$object->getSumDepositsUsed(0);
6092 $total_global_ht += $total_prev_ht;
6093 $total_global_ttc += $total_prev_ttc;
6094 $total_global_ht +=
$object->total_ht;
6095 $total_global_ttc +=
$object->total_ttc;
6099 print
'<tr class="oddeven">';
6100 print
'<td>'.$object->getNomUrl(1).
'</td>';
6102 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
6104 print
'<td class="right"></td>';
6106 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
6107 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
6108 print
'<td class="right">'.$object->getLibStatut(3, $totalallpayments).
'</td>';
6112 print
'<tr class="oddeven">';
6113 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'SituationTotalAfterInvoice').
'</b></td>';
6116 foreach ($current_situation_counter as $sit) {
6117 $curSign = $sit > 0 ?
'+' :
'-';
6118 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
6120 print
' '.$curSign.
' ';
6122 print $curType.abs($sit);
6129 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6130 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6131 print
'<td width="18"> </td>';
6135 if (count(
$object->tab_next_situation_invoice) > 0) {
6137 $total_next_ht = $total_next_ttc = 0;
6139 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
6140 $next_totalpaid = $next_invoice->getSommePaiement(0);
6141 $next_totalcreditnotes = $next_invoice->getSumCreditNotesUsed(0);
6142 $next_totaldeposits = $next_invoice->getSumDepositsUsed(0);
6143 $total_next_ht += $next_invoice->total_ht;
6144 $total_next_ttc += $next_invoice->total_ttc;
6146 print
'<tr class="oddeven">';
6147 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
6149 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
6151 print
'<td class="right"></td>';
6153 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
6154 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
6155 print
'<td class="right">'.$next_invoice->getLibStatut(3, $next_totalpaid + $next_totalcreditnotes + $next_totaldeposits).
'</td>';
6159 $total_global_ht += $total_next_ht;
6160 $total_global_ttc += $total_next_ttc;
6162 print
'<tr class="oddeven">';
6163 print
'<td colspan="3" class="right"></td>';
6165 print
'<td class="right"></td>';
6167 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6168 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6169 print
'<td width="18"> </td>';
6178 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
6184 print
'<!-- List of payments already done -->';
6185 print
'<div class="div-table-responsive-no-min">';
6186 print
'<table class="noborder paymenttable centpercent">';
6188 print
'<tr class="liste_titre">';
6189 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
6190 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
6191 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
6193 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
6195 print
'<td class="liste_titre"></td>';
6196 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
6200 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
6201 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
6202 $sql .=
' pf.amount,';
6203 $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';
6204 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
6205 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
6206 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
6207 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
6208 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
6209 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
6210 $sql .=
' ORDER BY p.datep, p.tms';
6212 $result =
$db->query($sql);
6214 $num =
$db->num_rows($result);
6219 $objp =
$db->fetch_object($result);
6221 $paymentstatic->id = $objp->rowid;
6222 $paymentstatic->datepaye =
$db->jdate($objp->dp);
6223 $paymentstatic->ref = $objp->ref;
6224 $paymentstatic->num_payment = $objp->num_payment;
6225 $paymentstatic->paiementcode = $objp->payment_code;
6227 print
'<tr class="oddeven">';
6228 print
'<td class="nowraponall">';
6229 print $paymentstatic->getNomUrl(1);
6232 $dateofpayment =
$db->jdate($objp->dp);
6234 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
6241 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
6242 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
6244 $bankaccountstatic->id = $objp->baid;
6245 $bankaccountstatic->ref = $objp->baref;
6246 $bankaccountstatic->label = $objp->baref;
6247 $bankaccountstatic->number = $objp->banumber;
6248 $bankaccountstatic->currency_code = $objp->bacurrency_code;
6251 $bankaccountstatic->account_number = $objp->account_number;
6254 $accountingjournal->fetch($objp->fk_accountancy_journal);
6255 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
6258 print
'<td class="nowraponall">';
6259 if ($bankaccountstatic->id) {
6260 print $bankaccountstatic->getNomUrl(1,
'transactions');
6266 print
'<td class="center">';
6268 $paiement->fetch($objp->rowid);
6270 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
6277 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
6292 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6293 print
'<span class="opacitymedium">';
6295 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
6297 print $langs->trans(
'AlreadyPaid');
6299 print
'</span></td>';
6301 print
'<td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td>';
6304 $resteapayeraffiche = $resteapayer;
6305 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
6306 $cssforamountpaymentcompletenoresize =
'amountpaymentcompletenoresize';
6309 $creditnoteamount = 0;
6311 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
6312 $sql .=
" re.description, re.fk_facture_source";
6313 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
6314 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
6315 $resql =
$db->query($sql);
6317 $num =
$db->num_rows($resql);
6321 $obj =
$db->fetch_object($resql);
6322 $invoice->fetch($obj->fk_facture_source);
6324 print
'<td colspan="'.$nbcols.
'" class="right">';
6325 print
'<span class="opacitymedium">';
6327 print $langs->trans(
"CreditNote").
' ';
6330 print $langs->trans(
"Deposit").
' ';
6332 print $invoice->getNomUrl(0);
6336 print
'<td class="right">';
6337 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
6338 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
6342 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
6346 $creditnoteamount += $obj->amount_ttc;
6349 $depositamount += $obj->amount_ttc;
6359 print
'<td colspan="'.$nbcols.
'" class="nowrap right">';
6360 print
'<span class="opacitymedium">';
6361 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
6365 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6367 $resteapayeraffiche = 0;
6368 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6369 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6374 print
'<td colspan="'.($nbcols + 1).
'" class="nowrap right">';
6375 print
'<span class="opacitymedium">';
6376 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
6380 print
'<td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td>';
6383 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6384 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6389 print
'<td colspan="'.($nbcols + 1).
'" class="nowrap right">';
6390 print
'<span class="opacitymedium">';
6391 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
6395 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6397 $resteapayeraffiche = 0;
6398 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6399 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6404 print
'<td colspan="'.($nbcols + 1).
'" class="nowrap right">';
6405 $text = $langs->trans(
"HelpAbandonOther");
6407 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
6409 print
'<span class="opacitymedium">';
6411 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
6415 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6417 $resteapayeraffiche = 0;
6418 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6419 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6424 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6425 print
'<span class="opacitymedium">';
6426 print $langs->trans(
"Billed");
6429 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
6434 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6435 print
'<span class="opacitymedium">';
6436 print $langs->trans(
'RemainderToPay');
6437 if ($resteapayeraffiche < 0) {
6438 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6443 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
6449 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6450 print
'<span class="opacitymedium">';
6451 print $langs->trans(
'RemainderToPayMulticurrency');
6452 if ($resteapayeraffiche < 0) {
6453 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6458 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcompletenoresize)).
'">';
6465 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
6467 if (
$object->isSituationInvoice()) {
6468 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
6471 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
6474 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
6477 print
'<td colspan="'.($nbcols + 1).
'" class="right">'.$langs->trans(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')).
' :</td>';
6479 print
'<td class="right">'.price($billedWithRetainedWarranty).
'</td>';
6484 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6485 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
6486 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
6489 print
'<td class="right">'.price($retainedWarranty).
'</td>';
6493 $resteapayeraffiche = $resteapayer;
6494 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6495 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6499 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6500 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
6503 print
'<td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td>';
6508 print
'<td colspan="'.($nbcols + 1).
'" class="right"><span class="opacitymedium">'.$langs->trans(
"Billed").
'</span></td>';
6510 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
6514 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
6515 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
6516 if ($resteapayeraffiche > 0) {
6517 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6519 print
'</span></td>';
6521 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche);
6530 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6531 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
6532 if ($resteapayeraffiche > 0) {
6533 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6538 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>';
6553 $formmargin->displayMarginInfos($object);
6559 print
'<div class="clearboth"></div><br>';
6562 $blocname =
'contacts';
6563 $title = $langs->trans(
'ContactsAddresses');
6564 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6568 $blocname =
'notes';
6569 $title = $langs->trans(
'Notes');
6570 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6574 $result =
$object->getLinesArray();
6578 global $inputalsopricewithtax;
6579 $inputalsopricewithtax = 1;
6584 print
'<!-- Area to change globally the situation percent -->'.
"\n";
6585 print
'<div class="div-table-responsive-no-min">';
6587 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'#updatealllines" method="POST">';
6588 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
6589 print
'<input type="hidden" name="action" value="updatealllines" />';
6590 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
6591 print
'<input type="hidden" name="page_y" value="" />';
6592 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
6594 print
'<table id="tablelines_all_progress" class="noborder noshadow centpercent">';
6596 print
'<tr class="liste_titre nodrag nodrop">';
6600 print
'<td align="center" width="5"> </td>';
6602 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
6603 print
'<td class="right">'.$langs->trans(
'CumulativeProgression').
'</td>';
6604 print
'<td> </td>';
6607 print
'<tr class="nodrag nodrop">';
6610 print
'<td align="center" width="5"> </td>';
6612 print
'<td> </td>';
6613 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
6614 print
'<td class="right"><input type="submit" class="button reposition small" name="all_percent" value="'.$langs->trans(
"Modify").
'" /></td>';
6625 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
6626 <input type="hidden" name="token" value="' .
newToken().
'">
6627 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
6628 <input type="hidden" name="mode" value="">
6629 <input type="hidden" name="page_y" value="">
6630 <input type="hidden" name="id" value="' .
$object->id.
'">
6631 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
6634 if (!empty(
$conf->use_javascript_ajax) &&
$object->status == 0) {
6636 include DOL_DOCUMENT_ROOT.
'/core/tpl/subtotal_ajaxrow.tpl.php';
6638 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
6642 print
'<div class="div-table-responsive-no-min">';
6643 print
'<table id="tablelines" class="noborder noshadow centpercent nomarginbottom">';
6647 $object->printObjectLines($action,
$mysoc, $soc, $lineid, 1);
6651 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
6652 if ($action !=
'editline' && $action !=
'selectlines') {
6655 $parameters = array();
6656 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
6660 if (empty($reshook)) {
6664 $parameters = array();
6665 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters, $object, $action);
6679 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
6680 print
'<div class="tabsAction">';
6682 $parameters = array();
6683 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
6684 if (empty($reshook)) {
6687 'class' =>
'classfortooltip',
6694 $ventilExportCompta =
$object->getVentilExportCompta();
6696 if ($ventilExportCompta == 0) {
6698 if (!$objectidnext &&
$object->is_last_in_cycle()) {
6699 if ($usercanunvalidate) {
6700 unset($params[
'attr'][
'title']);
6701 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
true, $params);
6703 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
6704 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
false, $params);
6706 } elseif (!
$object->is_last_in_cycle()) {
6707 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
6708 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6710 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
6711 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6715 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6716 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6721 $result = $discount->fetch(0,
$object->id);
6729 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
6730 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
6731 unset($params[
'attr'][
'title']);
6732 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
6734 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6735 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
6742 $langs->load(
"contracts");
6744 if ($usercancreatecontract) {
6745 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>';
6753 $langs->load(
"subtotals");
6755 $url_button = array();
6757 $url_button[] = array(
6758 'lang' =>
'subtotals',
6760 'perm' => (
bool) $usercancreate,
6761 'label' => $langs->trans(
'AddTitleLine'),
6762 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_title_line&token='.
newToken()
6765 $url_button[] = array(
6766 'lang' =>
'subtotals',
6768 'perm' => (
bool) $usercancreate,
6769 'label' => $langs->trans(
'AddSubtotalLine'),
6770 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_subtotal_line&token='.
newToken()
6772 print
dolGetButtonAction(
'', $langs->trans(
'SubTotal'),
'default', $url_button,
'',
true);
6779 if ($usercanvalidate) {
6780 unset($params[
'attr'][
'title']);
6781 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
6786 if (empty($user->socid)) {
6788 if ($objectidnext) {
6789 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6790 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
6793 unset($params[
'attr'][
'title']);
6794 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
6796 unset($params[
'attr'][
'title']);
6797 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
6805 if ($resteapayer > 0) {
6806 if ($usercancreatewithdrarequest) {
6807 if (!$objectidnext &&
$object->close_code !=
'replaced') {
6808 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>';
6810 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
6822 $langs->load(
"cashdesk");
6823 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
6824 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
6829 if ($objectidnext) {
6830 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
6834 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
6835 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
6839 unset($params[
'attr'][
'title']);
6840 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);
6845 $sumofpayment = $totalpaid;
6846 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
6852 if ($resteapayer == 0) {
6853 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
6855 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
6861 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
6865 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
6867 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>';
6874 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
6876 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
6890 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
6891 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
6893 unset($params[
'attr'][
'title']);
6894 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken(),
'',
true, $params);
6900 if ($totalpaid > 0 || $totalcreditnotes > 0) {
6902 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
6905 if ($objectidnext) {
6906 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
6908 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled&token='.
newToken().
'">'.$langs->trans(
'ClassifyCanceled').
'</a>';
6916 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
6917 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6918 } elseif (!
$object->is_last_in_cycle()) {
6919 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6921 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6927 if (!$objectidnext) {
6928 print
'<!-- button create credit note -->';
6929 if (
$object->module_source ==
'takepos') {
6930 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseInvoiceGeneratedBy", $langs->transnoentitiesnoconv(
'TakePOS')).
'">'.$langs->trans(
"CreateCreditNote").
'</a>';
6932 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>';
6939 &&
$object->isSituationInvoice()
6942 &&
$object->is_last_in_cycle()
6945 if ($usercanunvalidate) {
6946 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>';
6948 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
6954 if (!$objectidnext && count(
$object->lines) > 0) {
6955 unset($params[
'attr'][
'title']);
6956 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
6962 unset($params[
'attr'][
'title']);
6963 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'clone', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice&token='.
newToken(),
'',
true, $params);
6968 &&
$object->isSituationInvoice()
6971 &&
$object->situation_counter > 1
6972 &&
$object->is_last_in_cycle()
6973 && $usercanunvalidate
6976 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout&token='.
newToken().
'">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6978 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6983 $isErasable =
$object->is_erasable();
6986 if ($isErasable == -6) {
6987 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadySentByEmail');
6988 } elseif ($isErasable == -5) {
6989 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadyPrintedOnce');
6990 } elseif ($isErasable == -4) {
6991 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
6992 } elseif ($isErasable == -3) {
6993 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
6994 } elseif ($isErasable == -2) {
6995 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
6996 } elseif ($isErasable == -1) {
6997 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6998 } elseif ($isErasable <= 0) {
6999 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable').(empty(
$object->error) ?
': UnknownReason' :
': '.$object->error);
7000 } elseif ($objectidnext) {
7001 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
7003 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
7004 $enableDelete =
false;
7006 if ($isErasable > 0 && ! $objectidnext) {
7007 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
7008 $enableDelete =
true;
7010 unset($params[
'attr'][
'title']);
7011 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
7013 unset($params[
'attr'][
'title']);
7014 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
7021 if (
GETPOST(
'modelselected',
'alpha')) {
7022 $action =
'presend';
7024 if ($action !=
'prerelance' && $action !=
'presend') {
7025 print
'<div class="fichecenter"><div class="fichehalfleft">';
7026 print
'<a name="builddoc"></a>';
7031 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
7032 $genallowed = $usercanread;
7033 $delallowed = $usercancreate;
7034 $tooltipAfterComboOfModels =
'';
7036 $tooltipAfterComboOfModels = $langs->trans(
"AccordingToYourSetupTheFileWillBeConcatenated",
getDolGlobalString(
'MAIN_INFO_INVOICE_TERMSOFSALE'));
7039 print $formfile->showdocuments(
7059 'remove_file_comfirm',
7060 $tooltipAfterComboOfModels
7063 $somethingshown = $formfile->numoffiles;
7066 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice'), 1);
7067 $linktoelem = $tmparray[
'linktoelem'];
7068 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
7069 print $htmltoenteralink;
7071 $compatibleImportElementsList =
false;
7075 $compatibleImportElementsList = array(
'commande',
'propal',
'subscription');
7077 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
7081 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
7082 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
7083 $useonlinepayment = count($validpaymentmethod);
7086 print
'<br><!-- Link to pay -->'.
"\n";
7087 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
7088 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
7091 print
'</div><div class="fichehalfright">';
7095 $morehtmlcenter =
'<div class="nowraponall">';
7096 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullConversation'),
'',
'fa fa-comments imgforviewmode', DOL_URL_ROOT.
'/compta/facture/messaging.php?id='.
$object->id);
7097 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
7098 $morehtmlcenter .=
'</div>';
7101 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
7103 $somethingshown = $formactions->showactions($object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
7105 print
'</div></div>';
7110 $modelmail =
'facture_send';
7111 $defaulttopic =
'SendBillRef';
7113 $trackid =
'inv'.$object->id;
7115 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage bank accounts.
Class to manage accounting journals.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_DRAFT
Draft status.
const TYPE_STANDARD
Standard invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_PROFORMA
Proforma invoice (should not be used.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_DEPOSIT
Deposit invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const TYPE_CREDIT_NOTE
Credit note invoice.
const STATUS_CLOSED
Classified paid.
Class to manage invoice lines.
Class to manage invoice templates.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage the table of subscription to notifications.
Class to manage payments of customer invoices.
Class ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage VAT - Value-added tax (also known in French as TVA)
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
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).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
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.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $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.