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 $discount->unlink_invoice();
394 } elseif ($action ==
'valid' && $usercancreate) {
398 if ((preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) &&
405 $last_of_type =
$object->willBeLastOfSameType(
true);
406 if (empty(
$object->date_validation) && !$last_of_type[0]) {
416 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
425 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
434 $array_of_total_ht_per_vat_rate = array();
435 $array_of_total_ht_devise_per_vat_rate = array();
436 foreach (
$object->lines as $line) {
438 $vat_src_code_for_line =
'';
439 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
440 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
442 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
443 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
445 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
446 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
450 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
451 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
452 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
454 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
455 if (
$object->type == $object::TYPE_DEPOSIT) {
456 $langs->load(
"errors");
458 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
462 $tmpvatratetoshow = explode(
'_', $vatrate);
463 $tmpvatratetoshow[0] = round((
float) $tmpvatratetoshow[0], 2);
465 if ($tmpvatratetoshow[0] != 0) {
466 $langs->load(
"errors");
467 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", (
string) $tmpvatratetoshow[0]),
null,
'errors');
475 } elseif ($action ==
'classin' && $usercancreate) {
481 } elseif ($action ==
'setposinfo' && $usercancreate) {
485 $result =
$object->update($user);
489 } elseif ($action ==
'setmode' && $usercancreate) {
495 } elseif ($action ==
'setretainedwarrantyconditions' && $usercancreate) {
498 $object->retained_warranty_fk_cond_reglement = 0;
499 $result =
$object->setRetainedWarrantyPaymentTerms(
GETPOSTINT(
'retained_warranty_fk_cond_reglement'));
504 $old_rw_date_lim_reglement =
$object->retained_warranty_date_limit;
505 $new_rw_date_lim_reglement =
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
506 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
507 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
512 $result =
$object->update($user);
516 } elseif ($action ==
'setretainedwarranty' && $usercancreate) {
522 } elseif ($action ==
'setretainedwarrantydatelimit' && $usercancreate) {
524 $result =
$object->setRetainedWarrantyDateLimit(
GETPOSTDATE(
'retained_warranty_date_limit'));
528 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
529 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
530 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
532 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
534 $old_date_lim_reglement =
$object->date_lim_reglement;
536 if (empty($newdate)) {
537 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
538 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.
$id.
'&action=editinvoicedate&token='.
newToken());
543 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
545 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
550 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
551 if ($new_date_lim_reglement) {
552 $object->date_lim_reglement = $new_date_lim_reglement;
557 $result =
$object->update($user);
560 $action =
'editinvoicedate';
562 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
567 $object->date_pointoftax = $date_pointoftax;
568 $result =
$object->update($user);
572 } elseif ($action ==
'setconditions' && $usercancreate) {
574 $object->cond_reglement_code = 0;
575 $object->cond_reglement_id = 0;
588 $old_date_lim_reglement =
$object->date_lim_reglement;
589 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
590 if ($new_date_lim_reglement) {
591 $object->date_lim_reglement = $new_date_lim_reglement;
596 $result =
$object->update($user);
608 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
612 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
613 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
615 $result =
$object->update($user);
619 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
622 $result =
$object->update($user);
629 $outputlangs = $langs;
632 $newlang =
GETPOST(
'lang_id',
'aZ09');
635 $newlang =
$object->thirdparty->default_lang;
637 if (!empty($newlang)) {
639 $outputlangs->setDefaultLang($newlang);
640 $outputlangs->load(
'products');
645 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
651 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
656 } elseif ($action ==
'set_dispute_status' && $usercancreate) {
657 $result =
$object->setStatut(
GETPOSTINT(
'dispute_status'),
null,
'facture',
'FACTURE_MODIFY',
'dispute_status');
661 } elseif ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
666 } elseif ($action ==
'setbankaccount' && $usercancreate) {
671 } elseif ($action ==
'setremisepercent' && $usercancreate) {
677 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
696 $newremaintopay =
$object->getRemainToPay(0);
697 if ($newremaintopay == 0) {
704 if (
GETPOSTINT(
"remise_id_for_payment") > 0) {
705 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
707 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
711 $remaintopay =
$object->getRemainToPay(0);
715 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
719 $result = $discount->link_to_invoice(0, $id);
732 $newremaintopay =
$object->getRemainToPay(0);
733 if ($newremaintopay == 0) {
747 $outputlangs = $langs;
750 $newlang =
GETPOST(
'lang_id',
'aZ09');
754 $newlang =
$object->thirdparty->default_lang;
756 if (!empty($newlang)) {
758 $outputlangs->setDefaultLang($newlang);
762 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
767 } elseif ($action ==
'setref' && $usercancreate) {
769 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', 0,
'',
'', $user,
'BILL_MODIFY');
773 } elseif ($action ==
'setref_client' && $usercancreate) {
779 } elseif ($action ==
'setdemandreason' && $usercancreate) {
780 $result =
$object->setInputReason($inputReasonId);
784 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
793 $qualified_for_stock_change = 0;
795 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
797 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
800 if ($qualified_for_stock_change) {
801 if (!$idwarehouse || $idwarehouse == - 1) {
803 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
810 $result =
$object->validate($user,
'', $idwarehouse);
814 $outputlangs = $langs;
817 $newlang =
GETPOST(
'lang_id',
'aZ09');
820 $newlang =
$object->thirdparty->default_lang;
822 if (!empty($newlang)) {
824 $outputlangs->setDefaultLang($newlang);
825 $outputlangs->load(
'products');
831 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
844 } elseif ($action ==
'confirm_modif' && $usercanunvalidate && !
getDolGlobalString(
'INVOICE_CAN_NEVER_BE_EDITED')) {
853 $qualified_for_stock_change = 0;
855 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
857 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
860 if ($qualified_for_stock_change) {
861 if (!$idwarehouse || $idwarehouse == -1) {
863 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
872 $sql =
'SELECT pf.amount';
873 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'paiement_facture as pf';
874 $sql .=
' WHERE pf.fk_facture = ' . ((int)
$object->id);
876 $result =
$db->query($sql);
879 $num =
$db->num_rows($result);
882 $objp =
$db->fetch_object($result);
883 $totalpaid += $objp->amount;
890 $resteapayer =
$object->total_ttc - $totalpaid;
893 $ventilExportCompta =
$object->getVentilExportCompta();
896 if ($ventilExportCompta == 0) {
899 $result =
$object->setDraft($user, $idwarehouse);
906 $outputlangs = $langs;
909 $newlang =
GETPOST(
'lang_id',
'aZ09');
912 $newlang =
$object->thirdparty->default_lang;
914 if (!empty($newlang)) {
916 $outputlangs->setDefaultLang($newlang);
917 $outputlangs->load(
'products');
922 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
928 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
931 $result =
$object->setPaid($user);
935 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
938 $close_code =
GETPOST(
"close_code",
'restricthtml');
939 $close_note =
GETPOST(
"close_note",
'restricthtml');
942 if (
isModEnabled(
'tax') && $close_code == $object::CLOSECODE_WITHHOLDINGTAX) {
943 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
945 $amount = (float) ($resteapayer > 0 ? $resteapayer * -1 : $resteapayer);
949 $tempTva->datev =
$object->date;
950 $tempTva->datep =
$object->date;
951 $tempTva->amount = $amount;
952 $tempTva->label = $langs->trans(
'WithholdingTax') .
' - ' .
$object->ref;
954 $valid = $tempTva->getIdForLabel($tempTva->label);
956 $ret = $tempTva->create($user);
960 $tempTva->setPaid($user);
970 setEventMessages($langs->trans(
'LabelWithholdingExist'), $tempTva->errors,
'errors');
976 $result =
$object->setPaid($user, $close_code, $close_note);
984 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
986 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
989 $close_code =
GETPOST(
"close_code",
'restricthtml');
990 $close_note =
GETPOST(
"close_note",
'restricthtml');
992 $result =
$object->setCanceled($user, $close_code, $close_note);
999 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
1001 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
1009 $result = $discountcheck->fetch(0,
$object->id);
1022 $amount_ht = $amount_tva = $amount_ttc = $amount_localtax1 = $amount_localtax2 = array();
1023 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
1027 foreach (
$object->lines as $line) {
1028 if ($line->product_type < 9 && $line->total_ht != 0) {
1029 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
1031 if (!isset($amount_ht[$keyforvatrate])) {
1032 $amount_ht[$keyforvatrate] = 0;
1034 $amount_ht[$keyforvatrate] += $line->total_ht;
1035 if (!isset($amount_tva[$keyforvatrate])) {
1036 $amount_tva[$keyforvatrate] = 0;
1038 $amount_tva[$keyforvatrate] += $line->total_tva;
1039 if (!isset($amount_localtax1[$keyforvatrate])) {
1040 $amount_localtax1[$keyforvatrate] = 0;
1042 $amount_localtax1[$keyforvatrate] += $line->total_localtax1;
1043 if (!isset($amount_localtax2[$keyforvatrate])) {
1044 $amount_localtax2[$keyforvatrate] = 0;
1046 $amount_localtax2[$keyforvatrate] += $line->total_localtax2;
1047 if (!isset($amount_ttc[$keyforvatrate])) {
1048 $amount_ttc[$keyforvatrate] = 0;
1050 $amount_ttc[$keyforvatrate] += $line->total_ttc;
1051 if (!isset($multicurrency_amount_ht[$keyforvatrate])) {
1052 $multicurrency_amount_ht[$keyforvatrate] = 0;
1054 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
1055 if (!isset($multicurrency_amount_tva[$keyforvatrate])) {
1056 $multicurrency_amount_tva[$keyforvatrate] = 0;
1058 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
1059 if (!isset($multicurrency_amount_ttc[$keyforvatrate])) {
1060 $multicurrency_amount_ttc[$keyforvatrate] = 0;
1062 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
1066 '@phan-var-force array<string,float> $amount_ht
1067 @phan-var-force array<string,float> $amount_tva
1068 @phan-var-force array<string,float> $amount_ttc
1069 @phan-var-force array<string,float> $amount_localtax1
1070 @phan-var-force array<string,float> $amount_localtax2
1071 @phan-var-force array<string,float> $multicurrency_amount_ht
1072 @phan-var-force array<string,float> $multicurrency_amount_tva
1073 @phan-var-force array<string,float> $multicurrency_amount_ttc';
1077 $alreadypaid =
$object->getSommePaiement();
1078 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
1079 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
1080 foreach ($amount_ht as $vatrate => $val) {
1081 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
1082 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
1083 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
1084 $amount_localtax1[$vatrate] =
price2num($amount_localtax1[$vatrate] * $ratio,
'MU');
1085 $amount_localtax2[$vatrate] =
price2num($amount_localtax2[$vatrate] * $ratio,
'MU');
1086 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
1087 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
1088 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
1097 $discount->description =
'(CREDIT_NOTE)';
1099 $discount->description =
'(DEPOSIT)';
1101 $discount->description =
'(EXCESS RECEIVED)';
1103 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
1105 $discount->fk_soc =
$object->socid;
1106 $discount->socid =
$object->socid;
1107 $discount->fk_facture_source =
$object->id;
1116 $discount->description =
'(EXCESS RECEIVED)';
1119 $sql =
'SELECT SUM(pf.amount) as total_paiements';
1120 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
1121 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
1122 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
1123 $sql .=
' AND pf.fk_paiement = p.rowid';
1124 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
1125 $resql =
$db->query($sql);
1130 $res =
$db->fetch_object($resql);
1131 $total_paiements = $res->total_paiements;
1134 $total_creditnote_and_deposit = 0;
1135 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1136 $sql .=
" re.description, re.fk_facture_source";
1137 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1138 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
1139 $resql =
$db->query($sql);
1140 if (!empty($resql)) {
1141 while ($obj =
$db->fetch_object($resql)) {
1142 $total_creditnote_and_deposit += $obj->amount_ttc;
1148 $discount->amount_ttc =
price2num($total_paiements + $total_creditnote_and_deposit -
$object->total_ttc,
'MT');
1149 $discount->amount_tva = 0;
1150 $discount->amount_ht = $discount->amount_ttc;
1151 $discount->tva_tx = 0;
1152 $discount->localtax1_tx = 0;
1153 $discount->localtax1_type = 0;
1154 $discount->localtax2_tx = 0;
1155 $discount->localtax2_type = 0;
1156 $discount->vat_src_code =
'';
1158 if ($discount->amount_ttc > 0) {
1159 $result = $discount->create($user);
1169 $discount->description =
'(CREDIT_NOTE)';
1171 $discount->description =
'(DEPOSIT)';
1174 foreach ($amount_ht as $tva_tx => $xxx) {
1179 $discount->amount_ht = -((float) $amount_ht[$tva_tx]);
1180 $discount->amount_tva = -((float) $amount_tva[$tva_tx]);
1181 $discount->amount_ttc = -((float) $amount_ttc[$tva_tx]);
1182 $discount->total_ht = -((float) $amount_ht[$tva_tx]);
1183 $discount->total_tva = -((float) $amount_tva[$tva_tx]);
1184 $discount->total_localtax1 = -((float) $amount_localtax1[$tva_tx]);
1185 $discount->total_localtax2 = -((float) $amount_localtax2[$tva_tx]);
1186 $discount->total_ttc = -((float) $amount_ttc[$tva_tx]);
1187 $discount->multicurrency_amount_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1188 $discount->multicurrency_amount_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1189 $discount->multicurrency_amount_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1190 $discount->multicurrency_total_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1191 $discount->multicurrency_total_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1192 $discount->multicurrency_total_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1195 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
1196 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
1197 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
1198 $discount->total_ht = abs((
float) $amount_ht[$tva_tx]);
1199 $discount->total_tva = abs((
float) $amount_tva[$tva_tx]);
1200 $discount->total_localtax1 = abs((
float) $amount_localtax1[$tva_tx]);
1201 $discount->total_localtax2 = abs((
float) $amount_localtax2[$tva_tx]);
1202 $discount->total_ttc = abs((
float) $amount_ttc[$tva_tx]);
1203 $discount->multicurrency_amount_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1204 $discount->multicurrency_amount_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1205 $discount->multicurrency_amount_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1206 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1207 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1208 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1214 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
1215 $vat_src_code = $reg[1];
1216 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
1219 $discount->tva_tx = abs((
float) $tva_tx);
1220 $discount->localtax1_tx = $taxes[
'localtax1'];
1221 $discount->localtax1_type = $taxes[
'localtax1_type'];
1222 $discount->localtax2_tx = $taxes[
'localtax2'];
1223 $discount->localtax2_type = $taxes[
'localtax2_type'];
1224 $discount->vat_src_code = $vat_src_code;
1226 $result = $discount->create($user);
1234 if (empty($error)) {
1244 $result =
$object->setPaid($user);
1258 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
1263 $result = $paiement->fetch(
GETPOSTINT(
'paiement_id'));
1265 $result = $paiement->delete($user);
1267 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1275 } elseif ($action ==
'add' && $usercancreate) {
1282 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1288 $object->demand_reason_id = $inputReasonId;
1291 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1304 if (empty($dateinvoice)) {
1306 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1316 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1326 $object->date_pointoftax = $date_pointoftax;
1327 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1328 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1337 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1338 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1355 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1357 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceAvoirAskCombo")),
null,
'errors');
1361 if (empty($dateinvoice)) {
1363 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1373 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1378 if (!empty($originentity)) {
1379 $object->entity = $originentity;
1385 $object->date_pointoftax = $date_pointoftax;
1386 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1387 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1392 $object->cond_reglement_id = 0;
1396 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1397 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1401 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1405 if (
$object->fk_facture_source > 0 && $facture_source->fetch(
$object->fk_facture_source) > 0) {
1406 if ($facture_source->isSituationInvoice()) {
1407 $object->situation_counter = $facture_source->situation_counter;
1408 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1409 $facture_source->fetchPreviousNextSituationInvoice();
1412 $object->pos_source = $facture_source->pos_source;
1413 $object->module_source = $facture_source->module_source;
1421 if (
$object->copy_linked_contact($facture_source,
'internal') < 0) {
1423 } elseif ($facture_source->socid ==
$object->socid) {
1425 if (
$object->copy_linked_contact($facture_source,
'external') < 0) {
1436 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1437 if (!empty($facture_source->lines)) {
1438 $fk_parent_line = 0;
1440 foreach ($facture_source->lines as $line) {
1442 if (method_exists($line,
'fetch_optionals')) {
1444 $line->fetch_optionals();
1448 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1449 $fk_parent_line = 0;
1453 if ($facture_source->isSituationInvoice()) {
1454 $source_fk_prev_id = $line->fk_prev_id;
1455 $line->fk_prev_id = $line->id;
1460 if (
getDolGlobalInt(
'INVOICE_USE_SITUATION') != 2 && !empty($facture_source->tab_previous_situation_invoice)) {
1463 $tab_jumped_credit_notes = array();
1464 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1465 $searchPreviousInvoice =
true;
1466 while ($searchPreviousInvoice) {
1467 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1468 $searchPreviousInvoice =
false;
1472 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1478 $maxPrevSituationPercent = 0;
1479 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1480 if ($prevLine->id == $source_fk_prev_id) {
1481 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1484 $line->total_ht -= $prevLine->total_ht;
1485 $line->total_tva -= $prevLine->total_tva;
1486 $line->total_ttc -= $prevLine->total_ttc;
1487 $line->total_localtax1 -= $prevLine->total_localtax1;
1488 $line->total_localtax2 -= $prevLine->total_localtax2;
1490 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1491 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1492 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1493 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1498 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1503 $maxPrevSituationPercent = 0;
1504 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1505 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1506 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1507 $maxPrevSituationPercent = $prevLine->situation_percent;
1509 $line->total_ht -= $prevLine->total_ht;
1510 $line->total_tva -= $prevLine->total_tva;
1511 $line->total_ttc -= $prevLine->total_ttc;
1512 $line->total_localtax1 -= $prevLine->total_localtax1;
1513 $line->total_localtax2 -= $prevLine->total_localtax2;
1515 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1516 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1517 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1518 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1524 $line->situation_percent += $maxPrevSituationPercent;
1530 $line->fk_facture =
$object->id;
1531 $line->fk_parent_line = $fk_parent_line;
1533 $line->subprice = -$line->subprice;
1535 $line->total_ht = -$line->total_ht;
1536 $line->total_tva = -$line->total_tva;
1537 $line->total_ttc = -$line->total_ttc;
1538 $line->total_localtax1 = -$line->total_localtax1;
1539 $line->total_localtax2 = -$line->total_localtax2;
1541 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1542 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1543 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1544 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1546 $line->context[
'createcreditnotefrominvoice'] = 1;
1547 $result = $line->insert(0, 1);
1552 if ($result > 0 && $line->product_type == 9) {
1553 $fk_parent_line = $result;
1561 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1562 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1563 $totalpaid = $facture_source->getSommePaiement();
1564 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1565 $totaldeposits = $facture_source->getSumDepositsUsed();
1566 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1568 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1569 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1572 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1577 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1578 $tva_tx = (float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY');
1583 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), 0, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC', $remain_to_pay);
1588 if (!empty(
$object->fk_facture_source) &&
$id > 0) {
1589 $facture_source->fetch(
$object->fk_facture_source);
1590 $facture_source->fetchObjectLinked();
1592 if (!empty($facture_source->linkedObjectsIds)) {
1593 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1594 $object->add_object_linked($sourcetype, current($TIds));
1603 if (empty($dateinvoice)) {
1605 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1616 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1626 $object->date_pointoftax = $date_pointoftax;
1627 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1628 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1639 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1640 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1656 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1657 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1658 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1662 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1666 if (empty($dateinvoice)) {
1668 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1678 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1679 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1684 if ($typeamount && !empty($origin) && !empty($originid)) {
1685 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1686 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1690 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1691 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1695 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1696 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1706 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1716 $object->date_pointoftax = $date_pointoftax;
1717 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1718 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1728 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1729 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1733 $object->situation_counter = 1;
1738 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1740 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1742 $object->retained_warranty = 0;
1743 $object->retained_warranty_fk_cond_reglement = 0;
1746 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1747 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1750 $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);
1755 if (!empty($origin) && !empty($originid)) {
1758 $element = $subelement = $origin;
1759 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1760 $element = $regs[1];
1761 $subelement = $regs[2];
1765 if ($element ==
'order') {
1766 $element = $subelement =
'commande';
1768 if ($element ==
'propal') {
1769 $element =
'comm/propal';
1770 $subelement =
'propal';
1772 if ($element ==
'contract') {
1773 $element = $subelement =
'contrat';
1775 if ($element ==
'inter') {
1776 $element = $subelement =
'fichinter';
1778 if ($element ==
'shipping') {
1779 $element = $subelement =
'expedition';
1783 $object->origin_type = $origin;
1784 $object->origin_id = $originid;
1789 if (
$object->origin ==
'shipping') {
1790 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1792 $exp->fetch(
$object->origin_id);
1793 $exp->fetchObjectLinked();
1794 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1795 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1796 $object->linked_objects[
'commande'] = $value;
1802 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
1810 $classname = ucfirst($subelement);
1811 $srcobject =
new $classname(
$db);
1812 '@phan-var-force CommonObject $srcobject';
1814 dol_syslog(
"Try to find source object origin_type=".
$object->origin_type.
" origin_id=".
$object->origin_id.
" to add lines or deposit lines");
1815 $result = $srcobject->fetch(
$object->origin_id);
1821 $amountdeposit = array();
1824 if ($typeamount ==
'amount') {
1825 $amount = (float) $valuedeposit;
1827 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1830 $TTotalByTva = array();
1831 foreach ($srcobject->lines as &$line) {
1832 if (empty($line->qty)) {
1835 if (!empty($line->special_code)) {
1838 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1840 '@phan-var-force array<string,float> $TTotalByTva';
1842 $amount_ttc_diff = 0.;
1843 foreach ($TTotalByTva as $tva => &$total) {
1844 if (empty($amountdeposit[$tva])) {
1845 $amountdeposit[$tva] = 0;
1847 $coef = $total / $srcobject->total_ttc;
1848 $am = $amount * $coef;
1849 $amount_ttc_diff += $am;
1850 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1853 if ($typeamount ==
'amount') {
1854 $amountdeposit[0] = $valuedeposit;
1855 } elseif ($typeamount ==
'variable') {
1858 $lines = $srcobject->lines;
1859 $numlines = count($lines);
1860 for ($i = 0; $i < $numlines; $i++) {
1862 if (empty($lines[$i]->qty)) {
1865 if (!empty($lines[$i]->special_code)) {
1869 $totalamount += $lines[$i]->total_ht;
1870 $tva_tx = $lines[$i]->tva_tx;
1872 if (empty($amountdeposit[$tva_tx])) {
1873 $amountdeposit[$tva_tx] = 0;
1875 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1879 if ($totalamount == 0) {
1880 $amountdeposit[0] = 0;
1888 $amount_ttc_diff = $amountdeposit[0];
1891 foreach ($amountdeposit as $tva => $amount) {
1892 if (empty($amount)) {
1897 'amount' =>
'FixAmount',
1898 'variable' =>
'VarAmount'
1900 $descline =
'(DEPOSIT)';
1902 if ($typeamount ==
'amount') {
1903 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1904 } elseif ($typeamount ==
'variable') {
1905 $descline .=
' ('.$valuedeposit.
'%)';
1908 $descline .=
' - '.$srcobject->ref;
1921 $i >= 0 ? $lines[$i]->info_bits : 0,
1927 $i >= 0 ? $lines[$i]->special_code : 0,
1944 $diff =
$object->total_ttc - $amount_ttc_diff;
1948 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1949 $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);
1958 $lines = $srcobject->lines;
1959 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1960 $srcobject->fetch_lines();
1961 $lines = $srcobject->lines;
1966 if (is_array($lines)) {
1967 foreach ($lines as $line) {
1969 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuestandardinvoice / 100,
'MS');
1975 if (is_array($lines)) {
1976 foreach ($lines as $line) {
1978 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuedeposit / 100,
'MS');
1983 $fk_parent_line = 0;
1984 $num = count($lines);
1986 for ($i = 0; $i < $num; $i++) {
1987 if (!in_array($lines[$i]->
id, $selectedLines)) {
1992 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
1996 if (!isset(
$conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1997 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1999 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
2003 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
2004 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
2006 if (
$object->situation_counter == 1) {
2007 $lines[$i]->situation_percent = 0;
2010 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
2013 $desc = $label ? $label : $langs->trans(
'Discount');
2017 $discount->fk_soc =
$object->socid;
2018 $discount->socid =
$object->socid;
2019 $discount->amount_ht = abs($lines[$i]->total_ht);
2020 $discount->amount_tva = abs($lines[$i]->total_tva);
2021 $discount->amount_ttc = abs($lines[$i]->total_ttc);
2022 $discount->total_ht = abs($lines[$i]->total_ht);
2023 $discount->total_tva = abs($lines[$i]->total_tva);
2024 $discount->total_ttc = abs($lines[$i]->total_ttc);
2025 $discount->tva_tx = $lines[$i]->tva_tx;
2026 $discount->localtax1_tx = $lines[$i]->localtax1_tx;
2027 $discount->localtax2_tx = $lines[$i]->localtax2_tx;
2028 $discount->localtax1_type = $lines[$i]->localtax1_type;
2029 $discount->localtax2_type = $lines[$i]->localtax2_type;
2030 $discount->total_localtax1 = abs($lines[$i]->total_localtax1);
2031 $discount->total_localtax2 = abs($lines[$i]->total_localtax2);
2032 $discount->fk_user = $user->id;
2033 $discount->description = $desc;
2034 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
2035 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
2036 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
2037 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
2038 $discount->multicurrency_total_ht = abs($lines[$i]->multicurrency_total_ht);
2039 $discount->multicurrency_total_tva = abs($lines[$i]->multicurrency_total_tva);
2040 $discount->multicurrency_total_ttc = abs($lines[$i]->multicurrency_total_ttc);
2042 $discountid = $discount->create($user);
2043 if ($discountid > 0) {
2044 $result =
$object->insert_discount($discountid);
2057 if (isset($lines[$i]->date_debut_prevue)) {
2060 if (isset($lines[$i]->date_debut_reel)) {
2063 if (isset($lines[$i]->date_start)) {
2069 if (isset($lines[$i]->date_fin_prevue)) {
2070 $date_end = $lines[$i]->date_fin_prevue;
2072 if (isset($lines[$i]->date_fin_reel)) {
2073 $date_end = $lines[$i]->date_fin_reel;
2075 if (isset($lines[$i]->date_end)) {
2076 $date_end = $lines[$i]->date_end;
2080 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
2081 $fk_parent_line = 0;
2084 $array_options = array();
2086 if (method_exists($lines[$i],
'fetch_optionals')) {
2087 $lines[$i]->fetch_optionals();
2088 $array_options = $lines[$i]->array_options;
2091 $tva_tx = $lines[$i]->tva_tx;
2092 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
2093 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
2103 $lines[$i]->subprice,
2108 $lines[$i]->fk_product,
2109 $lines[$i]->remise_percent,
2113 (
int) $lines[$i]->info_bits,
2114 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except : null,
2119 $lines[$i]->special_code,
2123 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice : null,
2127 $lines[$i]->situation_percent ?? 100,
2128 $lines[$i]->fk_prev_id ?? 0,
2129 $lines[$i]->fk_unit,
2136 foreach (
$object->lines as $line) {
2137 if ($line->id == $result) {
2138 $line->extraparams = $lines[$i]->extraparams;
2139 $line->setExtraParameters();
2151 if ($result > 0 && $lines[$i]->product_type == 9) {
2152 $fk_parent_line = $result;
2164 $object->line_order(
true,
'DESC');
2192 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id,
'objFrom' => $srcobject);
2193 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
2206 for ($i = 1; $i <= $NBLINES; $i++) {
2212 $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);
2223 if (empty($dateinvoice)) {
2225 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
2235 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
2245 if (!empty($origin) && !empty($originid)) {
2246 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2249 $object->origin_type = $origin;
2250 $object->origin_id = $originid;
2254 $retained_warranty =
GETPOSTINT(
'retained_warranty');
2255 if (
price2num($retained_warranty) > 0) {
2259 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
2260 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
2263 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
2264 if (!empty($retained_warranty_date_limit) &&
$db->jdate($retained_warranty_date_limit)) {
2265 $object->retained_warranty_date_limit =
$db->jdate($retained_warranty_date_limit);
2267 $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);
2270 foreach (
$object->lines as $i => &$line) {
2271 $line->fk_prev_id = $line->id;
2272 $line->fetch_optionals();
2274 $line->situation_percent = 0;
2276 $line->situation_percent = $line->get_prev_progress(
$object->id);
2280 $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);
2281 $line->total_ht = (float) $tabprice[0];
2282 $line->total_tva = (float) $tabprice[1];
2283 $line->total_ttc = (float) $tabprice[2];
2284 $line->total_localtax1 = (float) $tabprice[9];
2285 $line->total_localtax2 = (float) $tabprice[10];
2286 $line->multicurrency_total_ht = (float) $tabprice[16];
2287 $line->multicurrency_total_tva = (float) $tabprice[17];
2288 $line->multicurrency_total_ttc = (float) $tabprice[18];
2291 if ($line->fk_remise_except) {
2293 $result = $discount->fetch($line->fk_remise_except);
2296 if ($discount->fk_facture_line > 0) {
2297 $line->fk_remise_except = 0;
2306 $object->date_pointoftax = $date_pointoftax;
2307 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2321 $object->situation_counter += 1;
2326 $extrafields->fetch_name_optionals_label(
$object->table_element);
2327 $extrafields->setOptionalsFromPost(
null, $object);
2334 $nextSituationInvoice->fetch($id);
2337 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id);
2338 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $nextSituationInvoice, $action);
2349 if ($id > 0 && !$error) {
2351 $categories =
GETPOST(
'categories',
'array');
2352 if (method_exists($object,
'setCategories')) {
2353 $object->setCategories($categories);
2361 $outputlangs = $langs;
2364 $newlang =
GETPOST(
'lang_id',
'aZ09');
2367 if (empty(
$object->thirdparty)) {
2370 $newlang =
$object->thirdparty->default_lang;
2372 if (!empty($newlang)) {
2374 $outputlangs->setDefaultLang($newlang);
2375 $outputlangs->load(
'products');
2380 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2386 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2391 $_GET[
"origin"] =
GETPOST(
"origin",
'alpha');
2395 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2399 foreach (
$object->lines as $line) {
2400 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2403 if ($line->product_type == 1) {
2404 $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);
2407 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2409 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2410 $vat_rate = str_replace(
'*',
'', $vat_rate);
2413 foreach (
$object->lines as $line) {
2414 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2417 $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);
2419 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2421 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2422 $remise_percent = str_replace(
'*',
'', $remise_percent);
2423 foreach (
$object->lines as $line) {
2424 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2427 $tvatx = $line->tva_tx;
2428 if (!empty($line->vat_src_code)) {
2429 $tvatx .=
' ('.$line->vat_src_code.
')';
2431 $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);
2433 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
2436 $langs->load(
'subtotals');
2438 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
2439 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
2441 $subtotal_options = array();
2443 foreach (Facture::$TITLE_OPTIONS as $option) {
2444 $value =
GETPOST($option,
'alphanohtml');
2446 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2451 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2462 $outputlangs = $langs;
2463 $newlang =
GETPOST(
'lang_id',
'alpha');
2465 $newlang =
$object->thirdparty->default_lang;
2467 if (!empty($newlang)) {
2469 $outputlangs->setDefaultLang($newlang);
2472 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2477 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2479 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
2482 $langs->load(
'subtotals');
2484 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
2485 foreach (
$object->lines as $line) {
2486 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
2487 $desc = $line->desc;
2488 $depth = -$line->qty;
2492 $subtotal_options = array();
2494 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
2495 $value =
GETPOST($option,
'alphanohtml');
2497 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2502 if (isset($desc) && isset($depth)) {
2503 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2506 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
2515 $outputlangs = $langs;
2516 $newlang =
GETPOST(
'lang_id',
'alpha');
2518 $newlang =
$object->thirdparty->default_lang;
2520 if (!empty($newlang)) {
2522 $outputlangs->setDefaultLang($newlang);
2525 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2530 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2532 } elseif ($action ==
'addline' &&
GETPOST(
'updateallvatlinesblock',
'alpha') &&
GETPOST(
'vatforblocklines',
'alpha') !==
'' && $usercancreate) {
2533 $tx_tva =
GETPOST(
'vatforblocklines') ?
GETPOST(
'vatforblocklines') : 0;
2534 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'tva', $tx_tva);
2535 } elseif ($action ==
'addline' &&
GETPOST(
'updatealldiscountlinesblock',
'alpha') &&
GETPOST(
'discountforblocklines',
'alpha') !==
'' && $usercancreate) {
2536 $discount =
GETPOST(
'discountforblocklines') ?
GETPOST(
'discountforblocklines') : 0;
2537 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'discount', $discount);
2538 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && !
GETPOST(
'submitforallmark',
'alpha') && $usercancreate) {
2539 $langs->load(
'errors');
2547 $price_ht_devise =
'';
2549 $price_ttc_devise =
'';
2552 $price_min_ttc =
'';
2554 if (
GETPOST(
'price_ht') !==
'') {
2557 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2560 if (
GETPOST(
'price_ttc') !==
'') {
2563 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2564 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2567 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2568 if ($prod_entry_mode ==
'free') {
2574 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2579 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2583 if (empty($remise_percent)) {
2584 $remise_percent = 0;
2588 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2589 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2591 if (is_array($extralabelsline)) {
2593 foreach ($extralabelsline as $key => $value) {
2594 unset($_POST[
"options_".$key.$predef]);
2598 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2599 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2602 if (!$prod_entry_mode) {
2604 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2608 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2609 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2614 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0)
2615 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
2616 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
2617 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
2618 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
2619 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
2620 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2621 $langs->load(
"errors");
2622 if (
$object->type == $object::TYPE_DEPOSIT) {
2624 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2626 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2631 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
2632 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
2636 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
2637 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2641 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2645 $langs->load(
"errors");
2646 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2650 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2651 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
2655 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2656 $idprod = $res->fk_product_child;
2658 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2664 $price_base_type =
null;
2665 if (!$error && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
2671 $ret =
$object->fetch_thirdparty();
2676 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2687 if (!empty($idprod) && $idprod > 0) {
2689 $prod->fetch($idprod);
2698 $pu_ht = $datapriceofproduct[
'pu_ht'];
2699 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2700 $price_min = $datapriceofproduct[
'price_min'];
2701 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2702 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2706 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2707 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string)
$prod->tva_tx));
2711 if (!empty($price_ht) || $price_ht ===
'0') {
2713 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2714 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2715 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2716 $pu_ttc_devise = (float)
price2num((
float) $pu_ht_devise * (1 + ((float) $tmpvat / 100)),
'MU');
2719 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2721 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2722 } elseif (!empty($price_ttc_devise) || (
string) $price_ttc_devise ===
'0') {
2723 $pu_ttc_devise = (float)
price2num($price_ttc_devise,
'MU');
2724 $pu_ht_devise = (float)
price2num((
float) $pu_ttc_devise / (1 + ((float) $tmpvat / 100)),
'MU');
2727 } elseif ($tmpvat != $tmpprodvat) {
2729 if ($price_base_type !=
'HT') {
2730 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2732 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2736 $outputlangs = $langs;
2742 if (
GETPOST(
'lang_id',
'aZ09')) {
2743 $newlang =
GETPOST(
'lang_id',
'aZ09');
2745 if (empty($newlang)) {
2746 $newlang =
$object->thirdparty->default_lang;
2748 if (!empty($newlang)) {
2750 $outputlangs->setDefaultLang($newlang);
2751 $outputlangs->load(
'products');
2754 $desc = (!empty(
$prod->multilangs [$outputlangs->defaultlang] [
"description"])) ?
$prod->multilangs [$outputlangs->defaultlang] [
"description"] :
$prod->
description;
2756 $desc =
$prod->description;
2772 if (!empty(
$prod->customcode)) {
2773 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomsCode").
': '.
$prod->customcode;
2775 if (!empty(
$prod->customcode) && !empty(
$prod->country_code)) {
2778 if (!empty(
$prod->country_code)) {
2779 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry(
$prod->country_code,
'',
$db, $outputlangs, 0);
2782 if (!empty(
$prod->customcode)) {
2783 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomsCode").
': '.
$prod->customcode;
2785 if (!empty(
$prod->customcode) && !empty(
$prod->country_code)) {
2788 if (!empty(
$prod->country_code)) {
2789 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry(
$prod->country_code,
'',
$db, $langs, 0);
2796 $type =
$prod->type;
2797 $fk_unit =
$prod->fk_unit;
2799 if (!empty($price_ht)) {
2804 if (!empty($price_ttc)) {
2809 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2810 $tva_tx = str_replace(
'*',
'', $tva_tx);
2811 if (empty($tva_tx)) {
2814 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2817 $fk_unit =
GETPOST(
'units',
'alpha');
2819 if ($pu_ttc && !$pu_ht) {
2820 $price_base_type =
'TTC';
2834 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2835 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2838 $pu_equivalent = $pu_ht;
2839 $pu_equivalent_ttc = $pu_ttc;
2841 $currency_tx =
$object->multicurrency_tx;
2845 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
2846 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
2848 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
2849 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
2864 $fournprice = (int) (
GETPOST(
'fournprice'.$predef) ?
GETPOST(
'fournprice'.$predef) :
'');
2869 $price2num_remise_percent =
price2num($remise_percent);
2870 $price2num_price_min =
price2num($price_min);
2871 $price2num_price_min_ttc =
price2num($price_min_ttc);
2872 if (empty($price2num_pu_ht)) {
2873 $price2num_pu_ht = 0;
2875 if (empty($price2num_remise_percent)) {
2876 $price2num_remise_percent = 0;
2878 if (empty($price2num_price_min)) {
2879 $price2num_price_min = 0;
2881 if (empty($price2num_price_min_ttc)) {
2882 $price2num_price_min_ttc = 0;
2887 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2888 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2891 } 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') {
2892 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2913 $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);
2919 $outputlangs = $langs;
2922 $newlang =
GETPOST(
'lang_id',
'aZ09');
2925 $newlang =
$object->thirdparty->default_lang;
2927 if (!empty($newlang)) {
2929 $outputlangs->setDefaultLang($newlang);
2930 $outputlangs->load(
'products');
2933 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2939 unset($_POST[
'prod_entry_mode']);
2940 unset($_POST[
'qty']);
2941 unset($_POST[
'type']);
2942 unset($_POST[
'remise_percent']);
2943 unset($_POST[
'price_ht']);
2944 unset($_POST[
'multicurrency_price_ht']);
2945 unset($_POST[
'price_ttc']);
2946 unset($_POST[
'tva_tx']);
2947 unset($_POST[
'product_ref']);
2948 unset($_POST[
'product_label']);
2949 unset($_POST[
'product_desc']);
2950 unset($_POST[
'fournprice']);
2951 unset($_POST[
'buying_price']);
2952 unset($_POST[
'np_marginRate']);
2953 unset($_POST[
'np_markRate']);
2954 unset($_POST[
'dp_desc']);
2955 unset($_POST[
'idprod']);
2956 unset($_POST[
'units']);
2957 unset($_POST[
'date_starthour']);
2958 unset($_POST[
'date_startmin']);
2959 unset($_POST[
'date_startsec']);
2960 unset($_POST[
'date_startday']);
2961 unset($_POST[
'date_startmonth']);
2962 unset($_POST[
'date_startyear']);
2963 unset($_POST[
'date_endhour']);
2964 unset($_POST[
'date_endmin']);
2965 unset($_POST[
'date_endsec']);
2966 unset($_POST[
'date_endday']);
2967 unset($_POST[
'date_endmonth']);
2968 unset($_POST[
'date_endyear']);
2969 unset($_POST[
'situations']);
2970 unset($_POST[
'progress']);
2978 } elseif ($action ==
'addline' && $usercancreate && (
2979 (
GETPOST(
'submitforallmargins',
'alpha') &&
GETPOST(
'marginforalllines',
'alpha') !==
'') ||
2980 (
GETPOST(
'submitforallmark',
'alpha') &&
GETPOST(
'markforalllines',
'alpha') !==
'')
2983 $margin_rate =
GETPOSTISSET(
'marginforalllines') ?
GETPOST(
'marginforalllines',
'int') :
'';
2985 foreach (
$object->lines as &$line) {
2986 if ($line->subprice > 0) {
2987 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2990 $subprice_multicurrency = $line->subprice;
2991 if (is_numeric($margin_rate) && $margin_rate > 0) {
2992 $line->subprice = (float)
price2num((
float) $line->pa_ht * (1 + (float) $margin_rate / 100),
'MU');
2993 } elseif (is_numeric($mark_rate) && $mark_rate > 0) {
2994 $line->subprice = (float) ($line->pa_ht / (1 - ((
float) $mark_rate / 100)));
2996 $line->subprice = (float) $line->pa_ht;
3000 $res =
$prod->fetch($line->fk_product);
3002 if (
$prod->price_min > $line->subprice) {
3003 $price_subprice =
price($line->subprice, 0, $outlangs, 1, -1, -1,
'auto');
3004 $price_price_min =
price(
$prod->price_min, 0, $outlangs, 1, -1, -1,
'auto');
3005 setEventMessages(
$prod->ref .
' - ' .
$prod->label .
' (' . $price_subprice .
' < ' . $price_price_min .
' ' . strtolower($langs->trans(
"MinPrice")) .
')' .
"\n",
null,
'warnings');
3013 $multicurrency_subprice = (float) $line->subprice * $line->multicurrency_subprice / $subprice_multicurrency;
3015 $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);
3018 if (is_numeric($margin_rate) && empty($mark_rate)) {
3019 $line->marge_tx = $margin_rate;
3020 } elseif (is_numeric($mark_rate) && empty($margin_rate)) {
3021 $line->marque_tx = $mark_rate;
3023 $line->total_ht = $line->qty * (float) $line->subprice;
3024 $line->total_tva = $line->tva_tx * $line->qty * (float) $line->subprice;
3025 $line->total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $line->subprice;
3027 $line->multicurrency_total_ht = $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
3028 $line->multicurrency_total_tva = $line->tva_tx * $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
3029 $line->multicurrency_total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
3031 $line->multicurrency_subprice = $multicurrency_subprice;
3037 } elseif ($action ==
'updatetitleline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3040 $langs->load(
'subtotals');
3042 $desc =
GETPOST(
'line_desc',
'alphanohtml') ?? $langs->trans(
"Title");
3045 $subtotal_options = array();
3047 foreach (Facture::$TITLE_OPTIONS as $option) {
3048 $value =
GETPOST($option,
'alphanohtml');
3050 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
3055 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3066 $outputlangs = $langs;
3067 $newlang =
GETPOST(
'lang_id',
'alpha');
3069 $newlang =
$object->thirdparty->default_lang;
3071 if (!empty($newlang)) {
3073 $outputlangs->setDefaultLang($newlang);
3076 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3081 } elseif ($action ==
'updatesubtotalline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3084 $langs->load(
'subtotals');
3086 $desc =
GETPOST(
'line_desc',
'alphanohtml');
3089 $subtotal_options = array();
3091 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
3092 $value =
GETPOST($option,
'alphanohtml');
3094 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
3099 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3107 $outputlangs = $langs;
3108 $newlang =
GETPOST(
'lang_id',
'alpha');
3110 $newlang =
$object->thirdparty->default_lang;
3112 if (!empty($newlang)) {
3114 $outputlangs->setDefaultLang($newlang);
3117 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3122 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3123 if (!
$object->fetch($id) > 0) {
3146 if (preg_match(
'/\*/', $vat_rate)) {
3151 $vat_rate = str_replace(
'*',
'', $vat_rate);
3156 $fournprice = (int) (
GETPOST(
'fournprice') ?
GETPOST(
'fournprice') :
'');
3160 $pu_equivalent = $pu_ht;
3161 $pu_equivalent_ttc = $pu_ttc;
3163 $currency_tx =
$object->multicurrency_tx;
3167 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3168 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
3170 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3171 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
3186 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
3187 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
3189 if (is_array($extralabelsline)) {
3191 foreach ($extralabelsline as $key => $value) {
3192 unset($_POST[
"options_".$key]);
3198 if ($special_code == 3) {
3204 $percent = $line->get_prev_progress(
$object->id);
3209 if ($progress >= 0) {
3210 $mesg = $langs->trans(
"CantBeNullOrPositive");
3214 } elseif ($progress < $line->situation_percent) {
3215 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
3219 } elseif ($progress < $percent) {
3220 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
3228 if (empty($remise_percent)) {
3229 $remise_percent = 0;
3232 $price_base_type =
'HT';
3234 if (empty($pu) && !empty($pu_ttc)) {
3236 $price_base_type =
'TTC';
3241 if (!empty($productid)) {
3243 $product->fetch($productid);
3245 $type = $product->type;
3247 $price_min = $product->price_min;
3249 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
3251 $price_min_ttc = $product->price_min_ttc;
3253 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
3260 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
3261 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3264 $action =
'editline';
3265 } 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') {
3266 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3269 $action =
'editline';
3274 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
3278 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
3283 $langs->load(
"errors");
3284 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
3288 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
3289 $langs->load(
"errors");
3290 if (
$object->type == $object::TYPE_DEPOSIT) {
3292 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
3294 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
3298 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
3305 $previousprogress = $line->getAllPrevProgress($line->fk_facture);
3308 if ($fullprogress < $previousprogress) {
3310 setEventMessages($langs->trans(
'CantBeLessThanMinPercent'),
null,
'errors');
3314 if ($fullprogress > 100) {
3315 $fullprogress = 100;
3317 $addprogress = $fullprogress - $previousprogress;
3324 if (empty($usercancreatemargin)) {
3325 foreach (
$object->lines as &$line) {
3327 $fournprice = $line->fk_fournprice;
3328 $buyingprice = $line->pa_ht;
3334 $result =
$object->updateline(
3339 (
float) $remise_percent,
3357 (
float) $pu_ht_devise
3364 $outputlangs = $langs;
3367 $newlang =
GETPOST(
'lang_id',
'aZ09');
3370 $newlang =
$object->thirdparty->default_lang;
3372 if (!empty($newlang)) {
3374 $outputlangs->setDefaultLang($newlang);
3375 $outputlangs->load(
'products');
3377 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3380 unset($_POST[
'qty']);
3381 unset($_POST[
'type']);
3382 unset($_POST[
'productid']);
3383 unset($_POST[
'remise_percent']);
3384 unset($_POST[
'price_ht']);
3385 unset($_POST[
'multicurrency_price_ht']);
3386 unset($_POST[
'price_ttc']);
3387 unset($_POST[
'tva_tx']);
3388 unset($_POST[
'product_ref']);
3389 unset($_POST[
'product_label']);
3390 unset($_POST[
'product_desc']);
3391 unset($_POST[
'fournprice']);
3392 unset($_POST[
'buying_price']);
3393 unset($_POST[
'np_marginRate']);
3394 unset($_POST[
'np_markRate']);
3395 unset($_POST[
'dp_desc']);
3396 unset($_POST[
'idprod']);
3397 unset($_POST[
'units']);
3398 unset($_POST[
'date_starthour']);
3399 unset($_POST[
'date_startmin']);
3400 unset($_POST[
'date_startsec']);
3401 unset($_POST[
'date_startday']);
3402 unset($_POST[
'date_startmonth']);
3403 unset($_POST[
'date_startyear']);
3404 unset($_POST[
'date_endhour']);
3405 unset($_POST[
'date_endmin']);
3406 unset($_POST[
'date_endsec']);
3407 unset($_POST[
'date_endday']);
3408 unset($_POST[
'date_endmonth']);
3409 unset($_POST[
'date_endyear']);
3410 unset($_POST[
'situations']);
3411 unset($_POST[
'progress']);
3416 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modify')) {
3417 if (!
$object->fetch($id) > 0) {
3420 if (
GETPOST(
'all_progress') !=
"") {
3422 if ($all_progress > 100) {
3423 $all_progress = 100;
3426 foreach (
$object->lines as $line) {
3428 $percent = $line->getAllPrevProgress(
$object->id);
3430 $percent = $line->get_prev_progress(
$object->id);
3432 if (
$object->type != $object::TYPE_CREDIT_NOTE && (
float) $all_progress < (
float) $percent) {
3433 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
3436 } elseif (
$object->type == $object::TYPE_CREDIT_NOTE && (
float) $all_progress > (
float) $percent) {
3437 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeMoreThanMinPercent");
3441 $object->update_percent($line, $all_progress,
false);
3446 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
3447 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
3449 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
3451 $object->fetch($id,
'',
'', 0,
true);
3454 &&
$object->isSituationInvoice()
3457 &&
$object->is_last_in_cycle()
3458 && $usercanunvalidate
3461 $newCycle =
$object->newCycle();
3462 if ($newCycle > 1) {
3464 $lastCycle =
$object->situation_cycle_ref;
3465 $lastSituationCounter =
$object->situation_counter;
3466 $linkedCreditNotesList = array();
3468 if (count(
$object->tab_next_situation_invoice) > 0) {
3469 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
3471 && $next_invoice->situation_counter ==
$object->situation_counter
3472 && $next_invoice->fk_facture_source ==
$object->id
3474 $linkedCreditNotesList[] = $next_invoice->id;
3479 $object->situation_cycle_ref = $newCycle;
3480 $object->situation_counter = 1;
3482 if (
$object->update($user) > 0) {
3484 if (count($linkedCreditNotesList) > 0) {
3486 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
3487 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
3488 $sql .=
' , situation_final=0';
3489 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
3490 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
3492 $resql =
$db->query($sql);
3498 foreach (
$object->lines as $line) {
3500 if ($line->product_type == 9) {
3505 if (!empty(
$object->tab_previous_situation_invoice)) {
3507 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
3508 $searchPreviousInvoice =
true;
3509 while ($searchPreviousInvoice) {
3510 if (
$object->tab_previous_situation_invoice[$lineIndex]->isSituationInvoice() || $lineIndex < 1) {
3511 $searchPreviousInvoice =
false;
3519 $maxPrevSituationPercent = 0;
3520 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
3521 if ($prevLine->id == $line->fk_prev_id) {
3522 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
3527 $line->situation_percent -= $maxPrevSituationPercent;
3529 if ($line->update() < 0) {
3538 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
3540 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
3543 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
3546 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
3552 $fromElement =
GETPOST(
'fromelement');
3553 $fromElementid =
GETPOST(
'fromelementid');
3554 $importLines =
GETPOST(
'line_checkbox');
3556 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
3557 $lineClassName =
'';
3558 if ($fromElement ==
'commande') {
3560 $lineClassName =
'OrderLine';
3561 } elseif ($fromElement ==
'propal') {
3562 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
3563 $lineClassName =
'PropaleLigne';
3565 $nextRang = count(
$object->lines) + 1;
3568 foreach ($importLines as $lineId) {
3569 if ($lineClassName ===
'') {
3573 dol_syslog(
'compta/facture/card - No lineClassName - skip import', LOG_ERR);
3580 $lineId = intval($lineId);
3581 $originLine =
new $lineClassName(
$db);
3582 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
3583 $originLine->fetch_optionals();
3584 $desc = $originLine->desc;
3585 $pu_ht = $originLine->subprice;
3586 $qty = $originLine->qty;
3587 $txtva = $originLine->tva_tx;
3588 $txlocaltax1 = $originLine->localtax1_tx;
3589 $txlocaltax2 = $originLine->localtax2_tx;
3590 $fk_product = $originLine->fk_product;
3591 $remise_percent = $originLine->remise_percent;
3593 $date_end = $originLine->date_end;
3594 $fk_code_ventilation = 0;
3595 $info_bits = $originLine->info_bits;
3596 $fk_remise_except = $originLine->fk_remise_except;
3597 $price_base_type =
'HT';
3599 $type = $originLine->product_type;
3600 $rang = $nextRang++;
3601 $special_code = $originLine->special_code;
3602 $origin = $originLine->element;
3603 $origin_id = $originLine->id;
3604 $fk_parent_line = 0;
3605 $fk_fournprice = $originLine->fk_fournprice;
3606 $pa_ht = $originLine->pa_ht;
3607 $label = $originLine->label;
3608 $array_options = $originLine->array_options;
3609 if (
$object->isSituationInvoice()) {
3610 $situation_percent = 0;
3612 $situation_percent = 100;
3615 $fk_unit = $originLine->fk_unit;
3616 $pu_ht_devise = $originLine->multicurrency_subprice;
3618 $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);
3638 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3644 if (!empty(
$object->id) && $action ==
'send') {
3646 $object->getSommePaiement(-1);
3647 $object->getSumCreditNotesUsed(-1);
3648 $object->getSumDepositsUsed(-1);
3650 $triggersendname =
'BILL_SENTBYMAIL';
3652 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3653 $trackid =
'inv'.$object->id;
3654 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3658 $permissiontoadd = $usercancreate;
3659 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3662 if ($action ==
'update_extras' && $permissiontoeditextra) {
3665 $attribute_name =
GETPOST(
'attribute',
'aZ09');
3668 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
3675 $result =
$object->updateExtraField($attribute_name,
'BILL_MODIFY');
3683 $action =
'edit_extras';
3688 if ($action ==
'addcontact' && $usercancreate) {
3689 $result =
$object->fetch($id);
3691 if ($result > 0 && $id > 0) {
3694 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3698 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3701 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3702 $langs->load(
"errors");
3703 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3708 } elseif ($action ==
'swapstatut' && $usercancreate) {
3715 } elseif ($action ==
'deletecontact' && $usercancreate) {
3718 $result =
$object->delete_contact($lineid);
3721 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3729 $action =
'edit_extras';
3753$title =
$object->ref.
" - ".$langs->trans(
'Card');
3754if ($action ==
'create') {
3755 $title = $langs->trans(
"NewBill");
3757$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3763if ($action ==
'create') {
3765 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3770 $res = $soc->fetch($socid);
3773 $currency_code =
$conf->currency;
3775 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3776 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3780 if (empty($dateinvoice)) {
3786 if (!empty($origin) && !empty($originid)) {
3788 $element = $subelement = $origin;
3790 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3791 $element = $regs[1];
3792 $subelement = $regs[2];
3797 if ($element ==
'project') {
3798 $projectid = $originid;
3800 if (empty($cond_reglement_id)) {
3801 $cond_reglement_id = $soc->cond_reglement_id;
3803 if (empty($mode_reglement_id)) {
3804 $mode_reglement_id = $soc->mode_reglement_id;
3806 if (empty($fk_account)) {
3807 $fk_account = $soc->fk_account;
3811 if ($element ==
'order' || $element ==
'commande') {
3812 $element = $subelement =
'commande';
3814 if ($element ==
'propal') {
3815 $element =
'comm/propal';
3816 $subelement =
'propal';
3818 if ($element ==
'contract') {
3819 $element = $subelement =
'contrat';
3821 if ($element ==
'shipping') {
3822 $element = $subelement =
'expedition';
3827 $classname = ucfirst($subelement);
3828 $objectsrc =
new $classname(
$db);
3829 '@phan-var-force Commande|Propal|Contrat|Expedition|Facture $objectsrc';
3831 $objectsrc->fetch($originid);
3832 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3833 $objectsrc->fetch_lines();
3835 $objectsrc->fetch_thirdparty();
3837 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3843 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3847 if (empty($socid)) {
3848 $soc = $objectsrc->thirdparty;
3851 if ($element ==
'expedition') {
3852 $elem = $subelem = $objectsrc->origin_type;
3853 $expeoriginid = $objectsrc->origin_id;
3855 $classname = ucfirst($subelem);
3857 $expesrc =
new $classname(
$db);
3858 '@phan-var-force Expedition $expesrc';
3860 dol_syslog(
"Is type Facture|Commande or Expedition: $element...expesrc($classname)=".get_class($expesrc));
3861 $expesrc->fetch($expeoriginid);
3863 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3864 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3865 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3868 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3869 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3873 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3876 $expesrc->fetch_optionals();
3877 $object->array_options = $expesrc->array_options;
3879 $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)));
3880 $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)));
3881 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : (!empty($fk_account) ? $fk_account : 0)));
3884 if (!empty($objectsrc->multicurrency_code)) {
3885 $currency_code = $objectsrc->multicurrency_code;
3887 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
3888 $currency_tx = $objectsrc->multicurrency_tx;
3893 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3896 $objectsrc->fetch_optionals();
3897 $object->array_options = $objectsrc->array_options;
3901 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
3902 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
3903 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
3904 $inputReasonId = empty($soc->demand_reason_id) ? $inputReasonId : $soc->demand_reason_id;
3906 if (
isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3907 $currency_code = $soc->multicurrency_code;
3912 if (!
GETPOST(
'changecompany')) {
3914 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3917 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3925 if (empty($cond_reglement_id)) {
3926 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
3930 if (empty($mode_reglement_id)) {
3931 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
3941 if (!empty($soc->id)) {
3942 $absolute_discount = $soc->getAvailableDiscounts();
3944 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
3945 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
3947 if (!empty(
$conf->use_javascript_ajax)) {
3948 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3954 if ($origin ==
'contrat') {
3955 $langs->load(
"admin");
3956 $text = $langs->trans(
"ToCreateARecurringInvoice");
3957 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3959 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3961 print
info_admin($text, 0, 0,
'info',
'').
'<br>';
3964 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3965 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3966 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3967 print
'<input type="hidden" name="changecompany" value="0">';
3969 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3971 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3972 print
'<input name="ref" type="hidden" value="provisoire">';
3973 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3974 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3975 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3976 print
'<input name="force_fk_account" type="hidden" value="0">';
3977 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3978 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3979 print
'<input type="hidden" name="originentity" value="'.GETPOSTINT(
'originentity').
'">';
3980 if (!empty($currency_tx)) {
3981 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3987 $parameters = array();
3989 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters, $object, $action);
3990 if (empty($reshook)) {
3991 print
'<table class="border centpercent">';
3995 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3996 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
4009 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
4011 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
'Customer').
'</td>';
4012 print
'<td colspan="2">';
4013 print $soc->getNomUrl(1,
'customer');
4014 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
4016 $arrayoutstandingbills = $soc->getOutstandingBills();
4017 $outstandingBills = $arrayoutstandingbills[
'opened'];
4018 print
' - <span class="opacitymedium valignmiddle">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
4019 print
'<span class="amount valignmiddle">'.price($outstandingBills, 0, $langs, 0, 0, -1,
$conf->currency).
'</span>';
4020 if ($soc->outstanding_limit !=
'') {
4021 if ($outstandingBills > $soc->outstanding_limit) {
4022 print
img_warning($langs->trans(
"OutstandingBillReached"));
4024 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1,
$conf->currency);
4029 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
4030 print
'<td colspan="2">';
4031 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
4032 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
4036 $(document).ready(function() {
4037 $("#socid").change(function() {
4039 console.log("Submit page");
4040 $(\'input[name="action"]\').val(\'create\');
4041 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
4042 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
4043 $(\'input[name="force_fk_account"]\').val(\'1\');
4044 $("#formtocreate").submit(); */
4046 // For company change, we must submit page with action=create instead of action=add
4047 console.log("We have changed the company - Resubmit page");
4048 jQuery("input[name=changecompany]").val("1");
4049 jQuery("#formtocreateaction").val("create");
4050 jQuery("#formtocreate").submit();
4056 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>';
4063 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
4065 foreach ($invoice_predefined->array_options as $key => $option) {
4066 if (!isset(
$object->array_options[$key])) {
4067 $object->array_options[$key] = $invoice_predefined->array_options[$key];
4071 $dateinvoice = $invoice_predefined->date_when;
4072 if (empty($projectid)) {
4073 $projectid = $invoice_predefined->fk_project;
4075 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
4076 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
4077 $fk_account = $invoice_predefined->fk_account;
4078 $note_public = $invoice_predefined->note_public;
4079 $note_private = $invoice_predefined->note_private;
4081 if (!empty($invoice_predefined->multicurrency_code)) {
4082 $currency_code = $invoice_predefined->multicurrency_code;
4084 if (!empty($invoice_predefined->multicurrency_tx)) {
4085 $currency_tx = $invoice_predefined->multicurrency_tx;
4088 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
4089 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
4090 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
4092 $resql =
$db->query($sql);
4094 $num =
$db->num_rows($resql);
4098 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
4100 print
'<select class="flat" id="fac_rec" name="fac_rec">';
4101 print
'<option value="0" selected></option>';
4103 $objp =
$db->fetch_object($resql);
4104 print
'<option value="'.$objp->rowid.
'"';
4107 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
4109 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
4118 print
'<script type="text/javascript">
4119 $(document).ready(function() {
4120 $("#fac_rec").change(function() {
4121 console.log("We have changed the template invoice - Reload page");
4122 var fac_rec = $(this).val();
4123 var socid = $(\'#socid\').val();
4124 // 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.
4125 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
4138 print
'<tr><td class="tdtop fieldrequired titlefieldcreate">'.$langs->trans(
'Type').
'</td><td colspan="2">';
4139 print
'<div class="listofinvoicetypetable">'.
"\n";
4142 print
'<div class="listofinvoicetype"><div class="">';
4143 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
4144 $tmp .=
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk");
4145 $tmp .=
' <span class="opacitymedium">'.$langs->trans(
"InvoiceStandardAsk2").
'</span>';
4148 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc").
'<br><br>'.$langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'nowraponall', 0, 3,
'standardonsmartphone');
4150 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
4160 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%') .
'"/>';
4163 print
'</div></div>'.
"\n";
4165 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
4168 print
'<div class="listofinvoicetype"><div class="">';
4169 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
4170 print
'<script type="text/javascript">
4171 jQuery(document).ready(function() {
4172 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
4173 jQuery("#radio_standard").prop("checked", true);
4175 jQuery("#typedeposit, #valuedeposit").click(function() {
4176 jQuery("#radio_deposit").prop("checked", true);
4178 jQuery("#typedeposit").change(function() {
4179 console.log("We change type of down payment: "+jQuery("#typedeposit").val());
4181 if (jQuery("#typedeposit").val() == "amount") {
4182 jQuery("#valuedeposit").attr("placeholder", "'.$langs->getCurrencySymbol(
$conf->currency).
'");
4183 jQuery("#valuedeposit").val("");
4185 jQuery("#valuedeposit").attr("placeholder", "50%");
4186 jQuery("#valuedeposit").val("");
4189 jQuery("#radio_deposit").prop("checked", true);
4190 setRadioForTypeOfInvoice();
4192 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
4193 setRadioForTypeOfInvoice();
4196 function setRadioForTypeOfInvoice() {
4197 console.log("Change radio for type of invoice");
4198 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
4199 jQuery("#checkforselects").prop("disabled", true);
4200 jQuery("#checkforselects").prop("checked", false);
4201 jQuery(".checkforselect").prop("disabled", true);
4202 jQuery(".checkforselect").prop("checked", false);
4204 jQuery("#checkforselects").prop("disabled", false);
4205 jQuery("#checkforselects").prop("checked", true);
4206 jQuery(".checkforselect").prop("disabled", false);
4207 jQuery(".checkforselect").prop("checked", true);
4213 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
4215 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
4217 if (($origin ==
'propal') || ($origin ==
'commande')) {
4220 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
4221 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
4222 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4226 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4230 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
4232 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
4233 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
4234 if (!empty($origin_payment_conditions_deposit_percent)) {
4235 $typedeposit =
'variable';
4238 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
4239 $valuedeposit = $objectsrc->deposit_percent;
4241 print
'<span class="marginleftonly">'.$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1).
'</span>';
4243 print
'<input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.($valuedeposit ? $valuedeposit :
'').
'"'.($valuedeposit ?
'' :
'placeholder="'.$langs->getCurrencySymbol(
$conf->currency).
'"').
'>';
4246 print
'</div></div>'.
"\n";
4253 print
'<div class="listofinvoicetype"><div class="">';
4254 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
4255 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
4257 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
4261 $opt = $form->selectSituationInvoices((
string)
GETPOSTINT(
'originid'), $socid);
4264 print
'</div></div><div class="listofinvoicetype"><div>';
4266 $tmp =
'<input id="radio_situation_bis" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
4267 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4268 $tmp .=
' disabled';
4271 $text = $tmp.
'<label for="radio_situation_bis">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4273 $text .=
'<select class="flat minwidth125" id="situations" name="situations"';
4274 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4275 $text .=
' disabled';
4279 $text .=
'</select>';
4280 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
4282 print
'</div></div>'.
"\n";
4288 $facids = $facturestatic->list_replacable_invoices($soc->id);
4294 if (is_array($facids)) {
4295 foreach ($facids as $facparam) {
4296 $options .=
'<option value="'.$facparam [
'id'].
'"';
4297 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
4298 $options .=
' selected';
4300 $options .=
'>'.$facparam[
'ref'];
4301 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
4302 $options .=
'</option>';
4306 print
'<!-- replacement line -->';
4307 print
'<div class="listofinvoicetype"><div class="">';
4308 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
4309 if (!$options || $invoice_predefined->id > 0) {
4310 $tmp .=
' disabled';
4313 print
'<script type="text/javascript">
4314 jQuery(document).ready(function() {
4315 jQuery("#fac_replacement").change(function() {
4316 console.log("We change fac_replacement");
4317 jQuery("#radio_replacement").prop("checked", true);
4321 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
4322 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
4323 if (!$options || $invoice_predefined->id > 0) {
4324 $text .=
' disabled';
4328 $text .=
'<option value="-1"> </option>';
4331 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
4333 $text .=
'</select>';
4334 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
4336 print
'</div></div>'.
"\n";
4340 print
'<div class="listofinvoicetype"><div class="">';
4341 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
4342 $text = $tmp.
'<label class="opacitymedium">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4343 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'firstsituationonsmartphone');
4345 print
'</div></div>'.
"\n";
4348 print
'<div class="listofinvoicetype"><div class="">';
4349 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
4350 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
4351 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'replacementonsmartphone');
4353 print
'</div></div>'.
"\n";
4356 if (empty($origin)) {
4361 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
4368 foreach ($facids as $key => $valarray) {
4369 $newinvoice_static->id = $key;
4370 $newinvoice_static->ref = $valarray [
'ref'];
4371 $newinvoice_static->statut = $valarray [
'status'];
4372 $newinvoice_static->status = $valarray [
'status'];
4373 $newinvoice_static->type = $valarray [
'type'];
4374 $newinvoice_static->paye = $valarray [
'paye'];
4375 $newinvoice_static->paid = $valarray [
'paye'];
4377 $optionsav .=
'<option value="'.$key.
'"';
4378 if ($key ==
GETPOST(
'fac_avoir')) {
4379 $optionsav .=
' selected';
4382 $newinvoice_static->fetch_optionals($key);
4383 $object->array_options = $newinvoice_static->array_options;
4386 $optionsav .= $newinvoice_static->ref;
4387 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
4388 $optionsav .=
'</option>';
4391 print
'<div class="listofinvoicetype"><div class="">';
4392 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
4393 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
4394 $tmp .=
' disabled';
4398 print
'<script type="text/javascript">
4399 jQuery(document).ready(function() {
4400 if (jQuery("#radio_creditnote").is(":checked")) {
4401 jQuery("#radio_standard").prop("disabled", true);
4402 jQuery("#radio_deposit").prop("disabled", true);
4404 jQuery("#radio_standard").prop("disabled", false);
4405 jQuery("#radio_deposit").prop("disabled", false);
4407 if (! jQuery("#radio_creditnote").is(":checked")) {
4408 jQuery("#credit_note_options").hide();
4410 jQuery("#radio_creditnote").click(function() {
4411 jQuery("#credit_note_options").show();
4413 jQuery("#radio_standard, #radio_replacement, #radio_deposit, #radio_situation, #radio_situation_bis").click(function() {
4414 console.log("We click on a radio to close credit not options");
4415 jQuery("#credit_note_options").hide();
4419 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
4420 $text .=
'<select class="flat valignmiddle minwidth200" name="fac_avoir" id="fac_avoir"';
4421 if (!$optionsav || $invoice_predefined->id > 0) {
4422 $text .=
' disabled';
4426 $text .=
'<option value="-1">'.$langs->trans(
"InvoiceAvoirAskCombo").
'</option>';
4427 $text .= $optionsav;
4429 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
4431 $text .=
'</select>';
4432 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
4435 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
4436 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>";
4437 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>";
4442 print
'</div></div>'.
"\n";
4445 print
'<div class="listofinvoicetype"><div class="">';
4447 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
4449 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
4451 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
4453 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
4455 print
'</div></div>'.
"\n";
4476 foreach ($listtType as $type) {
4477 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
4479 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
4482 print
'<script type="text/javascript">
4483 $(document).ready(function() {
4484 var listType = {'.$jsListType.
'};
4485 $("[name=\'type\']").change(function() {
4486 console.log("change name=type");
4487 if ($( this ).prop("checked"))
4489 if(($( this ).val() in listType))
4491 $("#model").val(listType[$( this ).val()]).trigger("change");
4508 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
4509 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
4515 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
4519 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
4522 $defaulttpldir =
'/core/tpl';
4523 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array($defaulttpldir));
4524 foreach ($dirtpls as $module => $reldir) {
4526 if (!empty($module)) {
4529 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
4531 if (file_exists($tpl)) {
4532 if (empty(
$conf->file->strict_mode)) {
4533 $res = @include $tpl;
4535 $res = include $tpl;
4550 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
4551 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4552 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
4557 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
4558 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4559 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
4564 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
4565 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
4566 print $form->getSelectConditionsPaiements((
int) $cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
4571 $rwStyle =
'display:none;';
4572 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
4576 $retained_warranty =
GETPOSTINT(
'retained_warranty');
4577 if (empty($retained_warranty)) {
4578 if ($objectsrc !==
null && property_exists($objectsrc,
'retained_warranty') && !empty($objectsrc->retained_warranty)) {
4580 $retained_warranty = $objectsrc->retained_warranty;
4583 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
4585 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
4586 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
4589 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
4590 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
4591 if (empty($retained_warranty_fk_cond_reglement)) {
4592 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4593 if ($objectsrc instanceOf
Facture && !empty($objectsrc->retained_warranty_fk_cond_reglement)) {
4595 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
4598 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4601 print
'<script type="text/javascript">
4602 $(document).ready(function() {
4603 $("[name=\'type\']").change(function() {
4604 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
4606 $(".retained-warranty-line").show();
4607 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
4610 $(".retained-warranty-line").hide();
4611 $("#new-situation-invoice-retained-warranty").val("");
4615 $("[name=\'type\']:checked").trigger("change");
4621 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
4622 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
4623 print $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth250 widthcentpercentminusx', 1);
4628 print
'<tr><td>'.$langs->trans(
'DefaultBankAccount').
'</td><td colspan="2">';
4629 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4630 print $form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth250 widthcentpercentminusx', 1);
4636 print
'<tr><td>'.$langs->trans(
'Source').
'</td><td>';
4637 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
4638 $form->selectInputReason((
string) $inputReasonId,
'input_reason_id',
'', 1,
'maxwidth250 widthcentpercentminusx');
4641 print
'<input type="hidden" name="input_reason_id" value="'.((string) $inputReasonId).
'">';
4645 if (
isModEnabled(
'project') && is_object($formproject)) {
4646 $langs->load(
'projects');
4647 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
4648 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
4650 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');
4651 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>';
4658 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
4659 print
'<td colspan="2" class="maxwidthonsmartphone">';
4660 $incoterm_id =
GETPOST(
'incoterm_id');
4661 $location_incoterms =
GETPOST(
'location_incoterms');
4662 if (empty($incoterm_id)) {
4663 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
4664 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
4666 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
4667 print $form->select_incoterms($incoterm_id, $location_incoterms);
4681 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
4682 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
4687 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
4688 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
4689 print $hookmanager->resPrint;
4690 if (empty($reshook)) {
4691 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
4694 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
4695 if ($soc->fetch_optionals() > 0) {
4696 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
4700 print
$object->showOptionals($extrafields,
'create', $parameters);
4704 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
4706 if (is_array($list) && count($list) > 0) {
4710 $paramkey =
'FACTURE_ADDON_PDF_'.$type;
4715 if (count($list) > 1) {
4716 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
4717 print
'<td colspan="2">';
4718 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
4719 print $form->selectarray(
'model', $list, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
4722 print
'<input type="hidden" name="model" value="'.$preselected.
'">';
4729 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
4730 print
'<td colspan="2" class="maxwidthonsmartphone">';
4731 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
4732 print $form->selectMultiCurrency(((
GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth200 widthcentpercentminusx');
4739 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
4740 if (empty($dateexample)) {
4743 $substitutionarray = array(
4744 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
4745 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
4746 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
4747 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
4748 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
4749 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
4750 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
4751 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
4752 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
4753 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
4754 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
4757 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
4758 foreach ($substitutionarray as $key => $val) {
4759 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
4761 $htmltext .=
'</i>';
4766 print
'<td class="tdtop">';
4767 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
4769 print
'<td valign="top" colspan="2">';
4770 $doleditor =
new DolEditor(
'note_public', (
string) $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
4771 print $doleditor->Create(1);
4774 if (empty($user->socid)) {
4776 print
'<td class="tdtop">';
4777 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4779 print
'<td valign="top" colspan="2">';
4780 $doleditor =
new DolEditor(
'note_private', (
string) $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4781 print $doleditor->Create(1);
4787 if (!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($classname)) {
4788 $langs->loadLangs(array(
'orders',
'propal'));
4791 if ($origin ==
'contrat') {
4792 '@phan-var-force Contrat $objectsrc';
4794 $objectsrc->update_price(1,
'auto', 1);
4797 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4798 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4799 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4800 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4805 switch (get_class($objectsrc)) {
4807 $newclassname =
'CommercialProposal';
4810 $newclassname =
'Order';
4813 $newclassname =
'Sending';
4816 $newclassname =
'Contract';
4819 $newclassname =
'Intervention';
4822 $newclassname = get_class($objectsrc);
4826 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4827 print
'<td colspan="2">';
4828 print $objectsrc->getNomUrl(1);
4830 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
4831 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4833 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4837 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht, 1, $langs, 1, -1,
'',
$conf->currency).
'</td></tr>';
4838 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
4839 if (
$mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4840 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>";
4843 if (
$mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4844 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>";
4846 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
4848 if (
isModEnabled(
'multicurrency') && $objectsrc->multicurrency_code !=
$conf->currency) {
4850 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
'</td></tr>';
4851 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4852 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4860 print $form->buttonsSaveCancel(
"CreateDraft");
4863 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4866 $title = $langs->trans(
'ProductsAndServices');
4869 print
'<div class="div-table-responsive-no-min">';
4870 print
'<table class="noborder centpercent">';
4872 $objectsrc->printOriginLinesList(
'', $selectedLines);
4879} elseif ($id > 0 || !empty($ref)) {
4881 $langs->load(
'errors');
4882 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4891 if ($user->socid > 0 && $user->socid !=
$object->socid) {
4895 $result =
$object->fetch_thirdparty();
4897 $result = $soc->fetch(
$object->socid);
4901 $selleruserevenustamp =
$mysoc->useRevenueStamp();
4903 $totalpaid =
$object->getSommePaiement();
4904 $totalcreditnotes =
$object->getSumCreditNotesUsed();
4905 $totaldeposits =
$object->getSumDepositsUsed();
4911 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4915 $multicurrency_totalpaid =
$object->getSommePaiement(1);
4916 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
4917 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
4918 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4922 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
4923 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
4927 if (
$object->paye ||
$object->status == $object::STATUS_CLOSED) {
4930 $resteapayeraffiche = $resteapayer;
4933 $filterabsolutediscount =
"fk_facture_source IS NULL";
4934 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4936 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4937 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4940 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
4941 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
4942 $absolute_discount =
price2num($absolute_discount,
'MT');
4943 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4945 $nb_creditnote_notyetavailable = $soc->getOpenCreditNotesNotYetConvertedIntoDiscount(0);
4948 if (
$object->user_creation_id) {
4949 $author->fetch(
$object->user_creation_id);
4952 $objectidnext =
$object->getIdReplacingInvoice();
4956 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
$object->picto, 0,
'',
'', 0,
'', 1);
4961 if ($action ==
'converttoreduc') {
4963 $type_fac =
'ExcessReceived';
4965 $type_fac =
'CreditNote';
4967 $type_fac =
'Deposit';
4971 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4972 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4973 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4977 if ($action ==
'delete') {
4978 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
4979 $formquestion = array();
4982 $qualified_for_stock_change = 0;
4984 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4986 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4989 if ($qualified_for_stock_change) {
4990 $langs->load(
"stocks");
4991 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4995 if (
$conf->browser->name ==
'ie') {
4998 $formquestion = array(
5002 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
5004 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
5006 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
5009 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
5014 if ($action ==
'situationout') {
5015 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
5016 $label = $langs->trans(
"ConfirmOuting");
5017 $formquestion = array();
5022 &&
$object->is_last_in_cycle()
5023 && $usercanunvalidate
5025 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
5030 if ($action ==
'valid') {
5032 $objectref = substr(
$object->ref, 1, 4);
5033 if ($objectref ==
'PROV') {
5037 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
5039 $numref =
$object->getNextNumRef($soc);
5045 $text = $langs->trans(
'ConfirmValidateBill', $numref);
5047 $text .=
'<br><br>';
5048 $text .=
img_picto(
'',
'warning',
'class="pictofixedwidth"').
' '.$langs->trans(
'WarningInvoiceCanNeverBeEdited');
5051 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
5054 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid, $object);
5056 $formquestion = array();
5059 $qualified_for_stock_change = 0;
5061 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5063 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5066 if ($qualified_for_stock_change) {
5067 $langs->load(
"stocks");
5068 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5069 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
5072 $warehouse_array = $warehouse->list_array();
5073 if (count($warehouse_array) == 1) {
5074 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
5075 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5078 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5080 $formquestion = array(
5086 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5090 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
5095 foreach (
$object->lines as $line) {
5096 $res = $line->fetch_product();
5098 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
5104 if ($nbMandated > 0) {
5106 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
5109 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
5114 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, ((
$object->type !=
Facture::TYPE_CREDIT_NOTE &&
$object->total_ttc < 0) ?
"no" :
"yes"), 2, 260);
5119 if ($action ==
'modif') {
5122 $testvalue =
$object->isEditable();
5123 if ($testvalue < 0) {
5124 switch ($testvalue) {
5127 setEventMessages($langs->trans(
"DisabledBecauseDispatchedInBookkeeping"),
null,
'errors');
5131 setEventMessages($langs->trans(
"DisabledBecauseNotLastInvoice"),
null,
'errors');
5135 setEventMessages($langs->trans(
"DisabledBecauseNotLastSituationInvoice"),
null,
'errors');
5139 setEventMessages($langs->trans(
"DisabledBecauseThereIsAPayment"),
null,
'errors');
5143 setEventMessages($langs->trans(
"DisabledBecauseAlreadySentByEmail"),
null,
'errors');
5147 setEventMessages($langs->trans(
"DisabledBecauseAlreadyPrintedOnce"),
null,
'errors');
5163 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
5164 $formquestion = array();
5167 $qualified_for_stock_change = 0;
5169 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5171 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5174 if ($qualified_for_stock_change) {
5175 $langs->load(
"stocks");
5176 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5177 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
5180 $warehouse_array = $warehouse->list_array();
5181 if (count($warehouse_array) == 1) {
5182 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
5183 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5186 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5188 $formquestion = array(
5194 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5198 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
5203 if ($action ==
'canceled') {
5207 $statusreplacement = 0;
5209 if ($objectidnext) {
5211 $facturereplacement->fetch($objectidnext);
5212 $statusreplacement = $facturereplacement->status;
5214 if ($objectidnext && $statusreplacement == 0) {
5215 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
5219 $close[1][
'code'] =
'badcustomer';
5220 $close[2][
'code'] =
'abandon';
5222 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5223 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
5225 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
5226 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
5229 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
5230 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
5233 $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'));
5235 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 300);
5240 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
5241 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
5243 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
5247 $close[$i][
'code'] = $object::CLOSECODE_DISCOUNTVAT;
5249 $close[$i][
'code'] = $object::CLOSECODE_BADDEBT;
5251 $close[$i][
'code'] = $object::CLOSECODE_BANKCHARGE;
5253 $close[$i][
'code'] = $object::CLOSECODE_WITHHOLDINGTAX;
5255 $close[$i][
'code'] = $object::CLOSECODE_OTHER;
5259 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
5261 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5263 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
5265 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
5267 $close[$i][
'label'] = $langs->trans(
"Other");
5271 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5273 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5275 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5277 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
5279 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
5283 foreach ($close as $key => $val) {
5284 $arrayreasons[$close[$key][
'code']] =
'<span class="small">'.$close[$key][
'reason'].
'</span>';
5288 $formquestion = array(
5289 'text' => $langs->trans(
"ConfirmClassifyPaidPartiallyQuestion"),
5290 0 => array(
'type' =>
'radio',
'name' =>
'close_code',
'label' =>
'',
'values' => $arrayreasons),
5291 1 => array(
'type' =>
'text',
'name' =>
'close_note',
'moreattr' =>
'placeholder = "'.$langs->trans(
"Comment").
'"',
'value' =>
'',
'morecss' =>
'minwidth300'),
5292 2 => array(
'type' =>
'separator')
5295 $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);
5298 if ($action ==
'deletepayment') {
5299 $payment_id =
GETPOST(
'paiement_id');
5300 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
5304 if ($action ==
'ask_deleteline') {
5305 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
5309 if ($action ==
'ask_subtotal_deleteline') {
5310 $langs->load(
"subtotals");
5311 $title =
"DeleteSubtotalLine";
5312 $question =
"ConfirmDeleteSubtotalLine";
5313 if (
GETPOST(
'type') ==
'title') {
5314 $formconfirm = array(array(
'type' =>
'checkbox',
'name' =>
'deletecorrespondingsubtotalline',
'label' => $langs->trans(
"DeleteCorrespondingSubtotalLine"),
'value' => 0));
5315 $title =
"DeleteTitleLine";
5316 $question =
"ConfirmDeleteTitleLine";
5318 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans($title), $langs->trans($question),
'confirm_delete_subtotalline', $formconfirm,
'no', 1);
5322 if ($action ==
'clone') {
5323 $filter =
'(s.client:IN:1,2,3)';
5325 $formquestion = array(
5326 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
$object->socid,
'socid', $filter, 1)),
5327 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
5330 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
5334 if ($action ==
'add_title_line') {
5335 $langs->load(
'subtotals');
5337 $depth_array =
$object->getPossibleLevels($langs);
5339 } elseif ($action ==
'add_subtotal_line') {
5340 $langs->load(
'subtotals');
5342 $titles =
$object->getPossibleTitles();
5346 if ($action ==
"remove_file_comfirm") {
5347 $file =
GETPOST(
'file',
'alpha');
5349 $formconfirm = $form->formconfirm(
5350 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
5351 $langs->trans(
'DeleteFileHeader'),
5352 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
5361 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
5362 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
5363 if (empty($reshook)) {
5364 $formconfirm .= $hookmanager->resPrint;
5365 } elseif ($reshook > 0) {
5366 $formconfirm = $hookmanager->resPrint;
5374 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
5376 $morehtmlref =
'<div class="refidno">';
5379 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5380 $morehtmlref .= $form->editfieldval(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'',
null,
null,
'', 1);
5381 $morehtmlref .=
'<br>';
5384 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5385 $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);
5387 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
5389 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'">'.$langs->trans(
"OtherBills").
'</a>)';
5393 $langs->load(
"projects");
5394 $morehtmlref .=
'<br>';
5395 if ($usercancreate) {
5396 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
5397 if ($action !=
'classify') {
5398 $morehtmlref .=
'<a class="editfielda" href="'.dolBuildUrl($_SERVER[
'PHP_SELF'], [
'action' =>
'classify',
'id' =>
$object->id],
true).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
5400 $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');
5402 if (!empty(
$object->fk_project)) {
5404 $proj->fetch(
$object->fk_project);
5405 $morehtmlref .= $proj->getNomUrl(1);
5407 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
5412 $morehtmlref .=
'</div>';
5414 $object->totalpaid = $totalpaid;
5415 $object->totalcreditnotes = $totalcreditnotes;
5416 $object->totaldeposits = $totaldeposits;
5419 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
5422 $parameters = array();
5424 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters, $object, $action);
5425 if (empty($reshook)) {
5426 print
'<div class="fichecenter">';
5427 print
'<div class="fichehalfleft">';
5428 print
'<div class="underbanner clearboth"></div>';
5430 print
'<table class="border centpercent tableforfield">';
5433 print
'<tr><td class="fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
5436 print
' '.$object->getSubtypeLabel(
'facture');
5440 $facreplaced->fetch(
$object->fk_facture_source);
5441 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
5445 $facusing->fetch(
$object->fk_facture_source);
5446 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
5450 $object->getListIdAvoirFromInvoice();
5452 if (!empty(
$object->creditnote_ids)) {
5453 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
5455 foreach (
$object->creditnote_ids as $invoiceid) {
5462 $creditnote->fetch($invoiceid);
5463 print $creditnote->getNomUrl(1,
'', 32);
5467 if ($objectidnext > 0) {
5469 $facthatreplace->fetch($objectidnext);
5470 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
5475 $result = $discount->fetch(0,
$object->id);
5477 print
' <span class="opacitymediumbycolor paddingleft">';
5478 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
5479 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
5480 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
5482 print
'</span><br>';
5486 if (
$object->fk_fac_rec_source > 0) {
5488 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
5490 print
' <span class="opacitymediumbycolor paddingleft">';
5491 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
5492 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
5496 print
' <span class="opacitymediumbycolor paddingleft">';
5497 print $langs->transnoentities(
"GeneratedFromTemplate", $langs->trans(
"ObjectDeleted"));
5505 $langs->load(
"cashdesk");
5506 print
'<tr><td class="fieldname_type">';
5507 print
'<table class="nobordernopadding centpercent"><tr><td>';
5508 print $form->textwithpicto($langs->trans(
'PointOfSale'), $langs->trans(
'POSInfo'));
5510 if ($action !=
'editposinfo' && $usercancreate) {
5511 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>';
5513 print
'</tr></table>';
5514 print
'</td><td class="valuefield fieldname_type">';
5515 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" name="formposinfo">';
5516 print
'<input type="hidden" name="action" value="setposinfo">';
5517 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5518 if ($action ==
'editposinfo') {
5519 print
'<input type="text" class="maxwidth150" name="posmodule" placeholder="'.$langs->trans(
"POSModule").
'" value="'.
$object->module_source.
'"> ';
5520 print
'<input type="text" class="maxwidth100" name="posterminal" placeholder="'.$langs->trans(
"Terminal").
'" value="'.
$object->pos_source.
'">';
5521 print
'<input type="submit" class="button" name="submitposinfo" value="'.$langs->trans(
"Submit").
'">';
5524 print
'<span class="opacitymediumbycolor paddingleft">'.dolPrintHTML(ucfirst(
$object->module_source).
' - '.$langs->transnoentitiesnoconv(
"Terminal").
' '.
$object->pos_source).
'</span>';
5532 print
'<!-- Discounts -->'.
"\n";
5533 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
5537 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
5538 $defaulttpldir =
'/core/tpl';
5540 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array($defaulttpldir));
5541 foreach ($dirtpls as $module => $reldir) {
5543 if (!empty($module)) {
5546 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
5548 if (file_exists($tpl)) {
5549 if (empty(
$conf->file->strict_mode)) {
5550 $res = @include $tpl;
5552 $res = include $tpl;
5564 print
'<table class="nobordernopadding centpercent"><tr><td>';
5565 print $langs->trans(
'DateInvoice');
5567 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
5568 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>';
5570 print
'</tr></table>';
5572 if ($action ==
'editinvoicedate') {
5573 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
5575 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
5590 print
'<table class="nobordernopadding centpercent"><tr><td>';
5591 print $langs->trans(
'DatePointOfTax');
5594 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>';
5596 print
'</tr></table>';
5598 if ($action ==
'editdate_pointoftax' && $editable) {
5599 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
5601 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
5609 print $form->editfieldkey(
'Source',
'input_reason',
'', $object, (
int) $usercancreate);
5610 print
'</td><td class="valuefield">';
5611 if ($action ==
'editinput_reason') {
5612 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'input_reason_id', 1,
'maxwidth250 widthcentpercentminusx');
5614 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'none');
5621 print
'<table class="nobordernopadding centpercent"><tr><td>';
5622 print $langs->trans(
'PaymentConditionsShort');
5625 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>';
5627 print
'</tr></table>';
5630 if ($action ==
'editconditions') {
5631 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
5633 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
5640 print
'<table class="nobordernopadding centpercent"><tr><td>';
5641 print $langs->trans(
'DateMaxPayment');
5644 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>';
5646 print
'</tr></table>';
5649 if ($action ==
'editpaymentterm') {
5650 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
5652 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
5662 print
'<table class="nobordernopadding centpercent"><tr><td>';
5663 print $langs->trans(
'PaymentMode');
5665 if ($action !=
'editmode' && $usercancreate) {
5666 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>';
5668 print
'</tr></table>';
5670 if ($action ==
'editmode') {
5671 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
5673 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'none',
'CRDT');
5679 print
'<tr><td class="nowrap">';
5680 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
5681 print $langs->trans(
'DefaultBankAccount');
5683 if (($action !=
'editbankaccount') && $usercancreate) {
5684 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>';
5686 print
'</tr></table>';
5688 if ($action ==
'editbankaccount') {
5689 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
5691 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
5700 print
'<table class="nobordernopadding centpercent"><tr><td>';
5701 print $langs->trans(
'IncotermLabel');
5702 print
'<td><td class="right">';
5703 if ($usercancreate) {
5704 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
5706 print
'</td></tr></table>';
5709 if ($action !=
'editincoterm') {
5710 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
5712 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
5719 print
'<table class="nobordernopadding centpercent"><tr><td>';
5720 print $langs->trans(
'Dispute');
5721 print
'<td><td class="right">';
5722 if ($usercancreate) {
5723 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editdispute_status&token='.
newToken().
'">'.
img_edit().
'</a>';
5725 print
'</td></tr></table>';
5727 $liststatus = Facture::ARRAY_OF_DISPUTE_STATUS;
5728 if ($action !=
'editdispute_status') {
5729 if (
$object->dispute_status) {
5730 print $langs->trans($liststatus[
$object->dispute_status][
'label']);
5733 print
'<form enctype="multipart/form-data" action="'.DOL_URL_ROOT.
'/compta/facture/card.php" method="POST">';
5734 print
'<input type="hidden" name="action" value="set_dispute_status">';
5735 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5736 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
5737 print
'<input type="hidden" name="page_y" value="">';
5738 print $form->selectarray(
'dispute_status', $liststatus,
$object->dispute_status, 0, 0, 0,
'', 1);
5739 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Save").
'">';
5747 print
'<table class="nobordernopadding centpercent"><tr><td>';
5748 print $langs->trans(
"Categories");
5749 print
'<td><td class="right">';
5750 if ($usercancreate) {
5751 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
5755 print
'</td></tr></table>';
5758 if ($action ==
'edittags') {
5759 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5760 print
'<input type="hidden" name="action" value="settags">';
5761 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5762 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
5763 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5766 print $form->showCategories(
$object->id, Categorie::TYPE_INVOICE, 1);
5771 $displayWarranty =
false;
5774 $displayWarranty =
true;
5775 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
5776 $displayWarranty =
false;
5779 if ($displayWarranty) {
5781 print
'<tr class="retained-warranty-lines" ><td>';
5782 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
5783 print $langs->trans(
'RetainedWarranty');
5786 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>';
5789 print
'</tr></table>';
5792 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5793 print
'<input type="hidden" name="action" value="setretainedwarranty">';
5794 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5795 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5796 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
5797 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5805 print
'<tr class="retained-warranty-lines" ><td>';
5806 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
5807 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
5809 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
5810 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>';
5813 print
'</tr></table>';
5815 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5816 if (
$object->date > $defaultDate) {
5822 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5823 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
5824 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5825 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5826 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
5827 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
5828 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
5829 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
5830 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5833 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->retained_warranty_fk_cond_reglement,
'none');
5834 if (!$displayWarranty) {
5835 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning',
'class="pictowarning valignmiddle" ');
5841 print
'<tr class="retained-warranty-lines" ><td>';
5842 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
5843 print $langs->trans(
'RetainedWarrantyDateLimit');
5846 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>';
5849 print
'</tr></table>';
5851 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5852 if (
$object->date > $defaultDate) {
5857 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5858 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
5859 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5860 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5862 print $form->selectDate($defaultDate,
'retained_warranty_date_limit');
5863 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5875 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
5880 print
'<div class="fichehalfright">';
5882 print
'<!-- amounts -->'.
"\n";
5883 print
'<div class="underbanner clearboth"></div>'.
"\n";
5885 print
'<table class="border tableforfield centpercent">';
5887 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
5895 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
5896 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5899 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5905 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
5906 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5909 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5914 if ((
$mysoc->localtax1_assuj ==
"1" &&
$mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
5916 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1",
$mysoc->country_code) .
'</td>';
5917 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5921 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5926 if ((
$mysoc->localtax2_assuj ==
"1" &&
$mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
5928 print
'<td>' . $langs->transcountry(
"AmountLT2",
$mysoc->country_code) .
'</td>';
5929 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5933 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5939 if ($selleruserevenustamp) {
5940 print
'<tr><td class="titlefieldmiddle">';
5941 print
'<table class="nobordernopadding centpercent"><tr><td>';
5942 print $langs->trans(
'RevenueStamp');
5944 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
5945 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>';
5947 print
'</tr></table>';
5948 print
'</td><td class="nowrap amountcard right">';
5949 if ($action ==
'editrevenuestamp') {
5950 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
5951 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5952 print
'<input type="hidden" name="action" value="setrevenuestamp">';
5953 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
5954 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5955 print $formother->select_revenue_stamp(
'',
'revenuestamp_type',
$mysoc->country_code);
5956 print
' → <span id="revenuestamp_span"></span>';
5957 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
5960 $(document).ready(function(){
5961 js_recalculate_revenuestamp();
5962 $('select[name=revenuestamp_type]').on('change',function(){
5963 js_recalculate_revenuestamp();
5966 function js_recalculate_revenuestamp(){
5967 var valselected = $('select[name=revenuestamp_type]').val();
5968 console.log('Calculate revenue stamp from '+valselected);
5970 if (valselected.indexOf('%') == -1)
5972 revenue = valselected;
5976 var revenue_type = parseFloat(valselected);
5977 var amount_net = ".round(
$object->total_ht, 2).
";
5978 revenue = revenue_type * amount_net / 100;
5979 revenue = revenue.toFixed(2);
5981 $('#revenuestamp_val').val(revenue);
5982 $('#revenuestamp_span').html(revenue);
5993 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
5994 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5997 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
6012 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
6015 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
6018 if ($selleruserevenustamp) {
6028 $total_prev_ht = $total_prev_ttc = 0;
6029 $total_global_ht = $total_global_ttc = 0;
6033 print
'<!-- List of situation invoices -->';
6034 print
'<div class="div-table-responsive-no-min">';
6035 print
'<table class="noborder paymenttable centpercent situationstable">';
6037 print
'<tr class="liste_titre">';
6038 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
6040 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
6043 print
'<td class="right"></td>';
6045 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
6046 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
6047 print
'<td width="18"> </td>';
6050 if (count(
$object->tab_previous_situation_invoice) > 0) {
6053 $current_situation_counter = array();
6054 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
6055 $tmptotalallpayments = $prev_invoice->getSommePaiement(0);
6056 $tmptotalallpayments += $prev_invoice->getSumDepositsUsed(0);
6057 $tmptotalallpayments += $prev_invoice->getSumCreditNotesUsed(0);
6059 $total_prev_ht += $prev_invoice->total_ht;
6060 $total_prev_ttc += $prev_invoice->total_ttc;
6062 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
6063 print
'<tr class="oddeven">';
6064 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
6066 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
6068 print
'<td class="right"></td>';
6070 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
6071 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
6072 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalallpayments).
'</td>';
6077 $totalallpayments =
$object->getSommePaiement(0);
6078 $totalallpayments +=
$object->getSumCreditNotesUsed(0);
6079 $totalallpayments +=
$object->getSumDepositsUsed(0);
6081 $total_global_ht += $total_prev_ht;
6082 $total_global_ttc += $total_prev_ttc;
6083 $total_global_ht +=
$object->total_ht;
6084 $total_global_ttc +=
$object->total_ttc;
6088 print
'<tr class="oddeven">';
6089 print
'<td>'.$object->getNomUrl(1).
'</td>';
6091 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
6093 print
'<td class="right"></td>';
6095 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
6096 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
6097 print
'<td class="right">'.$object->getLibStatut(3, $totalallpayments).
'</td>';
6101 print
'<tr class="oddeven">';
6102 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'SituationTotalAfterInvoice').
'</b></td>';
6105 foreach ($current_situation_counter as $sit) {
6106 $curSign = $sit > 0 ?
'+' :
'-';
6107 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
6109 print
' '.$curSign.
' ';
6111 print $curType.abs($sit);
6118 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6119 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6120 print
'<td width="18"> </td>';
6124 if (count(
$object->tab_next_situation_invoice) > 0) {
6126 $total_next_ht = $total_next_ttc = 0;
6128 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
6129 $totalpaid = $next_invoice->getSommePaiement(0);
6130 $totalcreditnotes = $next_invoice->getSumCreditNotesUsed(0);
6131 $totaldeposits = $next_invoice->getSumDepositsUsed(0);
6132 $total_next_ht += $next_invoice->total_ht;
6133 $total_next_ttc += $next_invoice->total_ttc;
6135 print
'<tr class="oddeven">';
6136 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
6138 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
6140 print
'<td class="right"></td>';
6142 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
6143 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
6144 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid + $totalcreditnotes + $totaldeposits).
'</td>';
6148 $total_global_ht += $total_next_ht;
6149 $total_global_ttc += $total_next_ttc;
6151 print
'<tr class="oddeven">';
6152 print
'<td colspan="3" class="right"></td>';
6154 print
'<td class="right"></td>';
6156 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6157 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6158 print
'<td width="18"> </td>';
6167 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
6173 print
'<!-- List of payments already done -->';
6174 print
'<div class="div-table-responsive-no-min">';
6175 print
'<table class="noborder paymenttable centpercent">';
6177 print
'<tr class="liste_titre">';
6178 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
6179 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
6180 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
6182 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
6184 print
'<td class="liste_titre"></td>';
6185 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
6189 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
6190 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
6191 $sql .=
' pf.amount,';
6192 $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';
6193 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
6194 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
6195 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
6196 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
6197 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
6198 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
6199 $sql .=
' ORDER BY p.datep, p.tms';
6201 $result =
$db->query($sql);
6203 $num =
$db->num_rows($result);
6208 $objp =
$db->fetch_object($result);
6210 $paymentstatic->id = $objp->rowid;
6211 $paymentstatic->datepaye =
$db->jdate($objp->dp);
6212 $paymentstatic->ref = $objp->ref;
6213 $paymentstatic->num_payment = $objp->num_payment;
6214 $paymentstatic->paiementcode = $objp->payment_code;
6216 print
'<tr class="oddeven">';
6217 print
'<td class="nowraponall">';
6218 print $paymentstatic->getNomUrl(1);
6221 $dateofpayment =
$db->jdate($objp->dp);
6223 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
6230 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
6231 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
6233 $bankaccountstatic->id = $objp->baid;
6234 $bankaccountstatic->ref = $objp->baref;
6235 $bankaccountstatic->label = $objp->baref;
6236 $bankaccountstatic->number = $objp->banumber;
6237 $bankaccountstatic->currency_code = $objp->bacurrency_code;
6240 $bankaccountstatic->account_number = $objp->account_number;
6243 $accountingjournal->fetch($objp->fk_accountancy_journal);
6244 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
6247 print
'<td class="nowraponall">';
6248 if ($bankaccountstatic->id) {
6249 print $bankaccountstatic->getNomUrl(1,
'transactions');
6255 print
'<td class="center">';
6257 $paiement->fetch($objp->rowid);
6259 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
6266 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
6281 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6282 print
'<span class="opacitymedium">';
6284 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
6286 print $langs->trans(
'AlreadyPaid');
6288 print
'</span></td>';
6290 print
'<td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td>';
6293 $resteapayeraffiche = $resteapayer;
6294 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
6295 $cssforamountpaymentcompletenoresize =
'amountpaymentcompletenoresize';
6298 $creditnoteamount = 0;
6300 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
6301 $sql .=
" re.description, re.fk_facture_source";
6302 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
6303 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
6304 $resql =
$db->query($sql);
6306 $num =
$db->num_rows($resql);
6310 $obj =
$db->fetch_object($resql);
6311 $invoice->fetch($obj->fk_facture_source);
6313 print
'<td colspan="'.$nbcols.
'" class="right">';
6314 print
'<span class="opacitymedium">';
6316 print $langs->trans(
"CreditNote").
' ';
6319 print $langs->trans(
"Deposit").
' ';
6321 print $invoice->getNomUrl(0);
6325 print
'<td class="right">';
6326 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
6327 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
6331 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
6335 $creditnoteamount += $obj->amount_ttc;
6338 $depositamount += $obj->amount_ttc;
6348 print
'<td colspan="'.$nbcols.
'" class="nowrap right">';
6349 print
'<span class="opacitymedium">';
6350 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
6354 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6356 $resteapayeraffiche = 0;
6357 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6358 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6363 print
'<td colspan="'.($nbcols + 1).
'" class="nowrap right">';
6364 print
'<span class="opacitymedium">';
6365 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
6369 print
'<td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td>';
6372 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6373 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6378 print
'<td colspan="'.($nbcols + 1).
'" class="nowrap right">';
6379 print
'<span class="opacitymedium">';
6380 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
6384 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6386 $resteapayeraffiche = 0;
6387 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6388 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6393 print
'<td colspan="'.($nbcols + 1).
'" class="nowrap right">';
6394 $text = $langs->trans(
"HelpAbandonOther");
6396 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
6398 print
'<span class="opacitymedium">';
6400 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
6404 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6406 $resteapayeraffiche = 0;
6407 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6408 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6413 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6414 print
'<span class="opacitymedium">';
6415 print $langs->trans(
"Billed");
6418 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
6423 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6424 print
'<span class="opacitymedium">';
6425 print $langs->trans(
'RemainderToPay');
6426 if ($resteapayeraffiche < 0) {
6427 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6432 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
6438 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6439 print
'<span class="opacitymedium">';
6440 print $langs->trans(
'RemainderToPayMulticurrency');
6441 if ($resteapayeraffiche < 0) {
6442 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6447 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcompletenoresize)).
'">';
6454 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
6456 if (
$object->isSituationInvoice()) {
6457 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
6460 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
6463 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
6466 print
'<td colspan="'.($nbcols + 1).
'" class="right">'.$langs->trans(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')).
' :</td>';
6468 print
'<td class="right">'.price($billedWithRetainedWarranty).
'</td>';
6473 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6474 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
6475 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
6478 print
'<td class="right">'.price($retainedWarranty).
'</td>';
6482 $resteapayeraffiche = $resteapayer;
6483 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6484 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6488 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6489 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
6492 print
'<td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td>';
6497 print
'<td colspan="'.($nbcols + 1).
'" class="right"><span class="opacitymedium">'.$langs->trans(
"Billed").
'</span></td>';
6499 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
6503 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
6504 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
6505 if ($resteapayeraffiche > 0) {
6506 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6508 print
'</span></td>';
6510 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche);
6519 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6520 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
6521 if ($resteapayeraffiche > 0) {
6522 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6527 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>';
6542 $formmargin->displayMarginInfos($object);
6548 print
'<div class="clearboth"></div><br>';
6551 $blocname =
'contacts';
6552 $title = $langs->trans(
'ContactsAddresses');
6553 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6557 $blocname =
'notes';
6558 $title = $langs->trans(
'Notes');
6559 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6563 $result =
$object->getLinesArray();
6567 global $inputalsopricewithtax;
6568 $inputalsopricewithtax = 1;
6573 print
'<!-- Area to change globally the situation percent -->'.
"\n";
6574 print
'<div class="div-table-responsive-no-min">';
6576 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'#updatealllines" method="POST">';
6577 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
6578 print
'<input type="hidden" name="action" value="updatealllines" />';
6579 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
6580 print
'<input type="hidden" name="page_y" value="" />';
6581 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
6583 print
'<table id="tablelines_all_progress" class="noborder noshadow centpercent">';
6585 print
'<tr class="liste_titre nodrag nodrop">';
6589 print
'<td align="center" width="5"> </td>';
6591 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
6592 print
'<td class="right">'.$langs->trans(
'CumulativeProgression').
'</td>';
6593 print
'<td> </td>';
6596 print
'<tr class="nodrag nodrop">';
6599 print
'<td align="center" width="5"> </td>';
6601 print
'<td> </td>';
6602 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
6603 print
'<td class="right"><input type="submit" class="button reposition small" name="all_percent" value="'.$langs->trans(
"Modify").
'" /></td>';
6614 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
6615 <input type="hidden" name="token" value="' .
newToken().
'">
6616 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
6617 <input type="hidden" name="mode" value="">
6618 <input type="hidden" name="page_y" value="">
6619 <input type="hidden" name="id" value="' .
$object->id.
'">
6620 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
6623 if (!empty(
$conf->use_javascript_ajax) &&
$object->status == 0) {
6625 include DOL_DOCUMENT_ROOT.
'/core/tpl/subtotal_ajaxrow.tpl.php';
6627 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
6631 print
'<div class="div-table-responsive-no-min">';
6632 print
'<table id="tablelines" class="noborder noshadow centpercent nomarginbottom">';
6636 $object->printObjectLines($action,
$mysoc, $soc, $lineid, 1);
6640 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
6641 if ($action !=
'editline' && $action !=
'selectlines') {
6644 $parameters = array();
6645 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
6649 if (empty($reshook)) {
6653 $parameters = array();
6654 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters, $object, $action);
6668 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
6669 print
'<div class="tabsAction">';
6671 $parameters = array();
6672 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
6673 if (empty($reshook)) {
6676 'class' =>
'classfortooltip',
6683 $ventilExportCompta =
$object->getVentilExportCompta();
6685 if ($ventilExportCompta == 0) {
6687 if (!$objectidnext &&
$object->is_last_in_cycle()) {
6688 if ($usercanunvalidate) {
6689 unset($params[
'attr'][
'title']);
6690 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
true, $params);
6692 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
6693 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
false, $params);
6695 } elseif (!
$object->is_last_in_cycle()) {
6696 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
6697 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6699 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
6700 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6704 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6705 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6710 $result = $discount->fetch(0,
$object->id);
6718 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
6719 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
6720 unset($params[
'attr'][
'title']);
6721 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
6723 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6724 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
6731 $langs->load(
"contracts");
6733 if ($usercancreatecontract) {
6734 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>';
6742 $langs->load(
"subtotals");
6744 $url_button = array();
6746 $url_button[] = array(
6747 'lang' =>
'subtotals',
6749 'perm' => (
bool) $usercancreate,
6750 'label' => $langs->trans(
'AddTitleLine'),
6751 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_title_line&token='.
newToken()
6754 $url_button[] = array(
6755 'lang' =>
'subtotals',
6757 'perm' => (
bool) $usercancreate,
6758 'label' => $langs->trans(
'AddSubtotalLine'),
6759 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_subtotal_line&token='.
newToken()
6761 print
dolGetButtonAction(
'', $langs->trans(
'Subtotal'),
'default', $url_button,
'',
true);
6768 if ($usercanvalidate) {
6769 unset($params[
'attr'][
'title']);
6770 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
6775 if (empty($user->socid)) {
6777 if ($objectidnext) {
6778 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6779 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
6782 unset($params[
'attr'][
'title']);
6783 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
6785 unset($params[
'attr'][
'title']);
6786 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
6794 if ($resteapayer > 0) {
6795 if ($usercancreatewithdrarequest) {
6796 if (!$objectidnext &&
$object->close_code !=
'replaced') {
6797 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>';
6799 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
6811 $langs->load(
"cashdesk");
6812 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
6813 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
6818 if ($objectidnext) {
6819 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
6823 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
6824 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
6828 unset($params[
'attr'][
'title']);
6829 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);
6834 $sumofpayment = $totalpaid;
6835 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
6841 if ($resteapayer == 0) {
6842 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
6844 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
6850 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
6854 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
6856 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>';
6863 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
6865 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
6879 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
6880 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
6882 unset($params[
'attr'][
'title']);
6883 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken(),
'',
true, $params);
6889 if ($totalpaid > 0 || $totalcreditnotes > 0) {
6891 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
6894 if ($objectidnext) {
6895 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
6897 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
6904 if ($usercancreate &&
$object->isSituationInvoice() && (
$object->status == 1 ||
$object->status == 2)) {
6905 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
6906 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6907 } elseif (!
$object->is_last_in_cycle()) {
6908 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6910 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6916 if (!$objectidnext) {
6917 print
'<!-- button create credit note -->';
6918 if (
$object->module_source ==
'takepos') {
6919 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseInvoiceGeneratedBy", $langs->transnoentitiesnoconv(
'TakePOS')).
'">'.$langs->trans(
"CreateCreditNote").
'</a>';
6921 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>';
6928 &&
$object->isSituationInvoice()
6931 &&
$object->is_last_in_cycle()
6934 if ($usercanunvalidate) {
6935 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>';
6937 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
6943 if (!$objectidnext && count(
$object->lines) > 0) {
6944 unset($params[
'attr'][
'title']);
6945 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
6951 unset($params[
'attr'][
'title']);
6952 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'clone', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice&token='.
newToken(),
'',
true, $params);
6957 &&
$object->isSituationInvoice()
6960 &&
$object->situation_counter > 1
6961 &&
$object->is_last_in_cycle()
6962 && $usercanunvalidate
6964 if ((
$object->total_ttc - $totalcreditnotes) == 0) {
6965 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6967 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6972 $isErasable =
$object->is_erasable();
6975 if ($isErasable == -6) {
6976 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadySentByEmail');
6977 } elseif ($isErasable == -5) {
6978 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadyPrintedOnce');
6979 } elseif ($isErasable == -4) {
6980 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
6981 } elseif ($isErasable == -3) {
6982 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
6983 } elseif ($isErasable == -2) {
6984 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
6985 } elseif ($isErasable == -1) {
6986 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6987 } elseif ($isErasable <= 0) {
6988 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable').(empty(
$object->error) ?
': UnknownReason' :
': '.$object->error);
6989 } elseif ($objectidnext) {
6990 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
6992 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
6993 $enableDelete =
false;
6995 if ($isErasable > 0 && ! $objectidnext) {
6996 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
6997 $enableDelete =
true;
6999 unset($params[
'attr'][
'title']);
7000 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
7002 unset($params[
'attr'][
'title']);
7003 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
7010 if (
GETPOST(
'modelselected',
'alpha')) {
7011 $action =
'presend';
7013 if ($action !=
'prerelance' && $action !=
'presend') {
7014 print
'<div class="fichecenter"><div class="fichehalfleft">';
7015 print
'<a name="builddoc"></a>';
7020 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
7021 $genallowed = $usercanread;
7022 $delallowed = $usercancreate;
7023 $tooltipAfterComboOfModels =
'';
7025 $tooltipAfterComboOfModels = $langs->trans(
"AccordingToYourSetupTheFileWillBeConcatenated",
getDolGlobalString(
'MAIN_INFO_INVOICE_TERMSOFSALE'));
7028 print $formfile->showdocuments(
7048 'remove_file_comfirm',
7049 $tooltipAfterComboOfModels
7052 $somethingshown = $formfile->numoffiles;
7055 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice'), 1);
7056 $linktoelem = $tmparray[
'linktoelem'];
7057 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
7058 print $htmltoenteralink;
7060 $compatibleImportElementsList =
false;
7064 $compatibleImportElementsList = array(
'commande',
'propal',
'subscription');
7066 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
7070 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
7071 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
7072 $useonlinepayment = count($validpaymentmethod);
7075 print
'<br><!-- Link to pay -->'.
"\n";
7076 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
7077 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
7080 print
'</div><div class="fichehalfright">';
7084 $morehtmlcenter =
'<div class="nowraponall">';
7085 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullConversation'),
'',
'fa fa-comments imgforviewmode', DOL_URL_ROOT.
'/compta/facture/messaging.php?id='.
$object->id);
7086 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
7087 $morehtmlcenter .=
'</div>';
7090 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
7092 $somethingshown = $formactions->showactions($object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
7094 print
'</div></div>';
7099 $modelmail =
'facture_send';
7100 $defaulttopic =
'SendBillRef';
7102 $trackid =
'inv'.$object->id;
7104 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_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
$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, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.