44require
'../../main.inc.php';
45require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
55require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
56require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
57require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
58if (isModEnabled(
'order')) {
59 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
61if (isModEnabled(
'project')) {
62 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
63 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
65require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
67if (isModEnabled(
'variants')) {
68 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
70if (isModEnabled(
'accounting')) {
71 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
75$langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
76if (isModEnabled(
'incoterm')) {
77 $langs->load(
'incoterm');
79if (isModEnabled(
'margin')) {
80 $langs->load(
'margins');
87$action =
GETPOST(
'action',
'aZ09');
88$confirm =
GETPOST(
'confirm',
'alpha');
89$cancel =
GETPOST(
'cancel',
'alpha');
90$backtopage =
GETPOST(
'backtopage',
'alpha');
91$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
94$search_ref =
GETPOST(
'sf_ref',
'alpha') ?
GETPOST(
'sf_ref',
'alpha') :
GETPOST(
'search_ref',
'alpha');
95$search_societe =
GETPOST(
'search_societe',
'alpha');
96$search_montant_ht =
GETPOST(
'search_montant_ht',
'alpha');
97$search_montant_ttc =
GETPOST(
'search_montant_ttc',
'alpha');
98$origin =
GETPOST(
'origin',
'alpha');
105$selectedLines =
GETPOST(
'toselect',
'array');
121$extrafields->fetch_name_optionals_label(
$object->table_element);
124if ($id > 0 || !empty($ref)) {
125 if ($action !=
'add') {
127 $fetch_situation =
false;
129 $fetch_situation =
true;
131 $ret =
$object->fetch($id, $ref,
'', 0, $fetch_situation);
132 if ($ret > 0 && isset(
$object->fk_project)) {
133 $ret =
$object->fetch_project();
139$hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
142$usercanread = $user->hasRight(
"facture",
"lire");
143$usercancreate = $user->hasRight(
"facture",
"creer");
144$usercanissuepayment = $user->hasRight(
"facture",
"paiement");
145$usercandelete = $user->hasRight(
"facture",
"supprimer") || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
146$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
149$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'validate')));
151$usercanreopen = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'reopen')));
153 $usercanreopen =
false;
155$usercanunvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'unvalidate')));
156$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
159$usercancreatemargin = $user->hasRight(
'margins',
'creer');
160$usercanreadallmargin = $user->hasRight(
'margins',
'liretous');
161$usercancreatewithdrarequest = $user->hasRight(
'prelevement',
'bons',
'creer');
163$permissionnote = $usercancreate;
164$permissiondellink = $usercancreate;
165$permissiontoedit = $usercancreate;
166$permissiontoadd = $usercancreate;
169$retainedWarrantyInvoiceAvailableType = array();
171 $retainedWarrantyInvoiceAvailableType = explode(
'+',
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY'));
176 $socid = $user->socid;
187$parameters = array(
'socid' => $socid);
188$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
193if (empty($reshook)) {
194 $backurlforlist = DOL_URL_ROOT.
'/compta/facture/list.php';
196 if (empty($backtopage) || ($cancel && empty($id))) {
197 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
198 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
199 $backtopage = $backurlforlist;
201 $backtopage = DOL_URL_ROOT.
'/compta/facture/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
207 if (!empty($backtopageforcancel)) {
208 header(
"Location: ".$backtopageforcancel);
210 } elseif (!empty($backtopage)) {
211 header(
"Location: ".$backtopage);
217 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
219 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
221 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
224 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
226 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'IdThirdParty')),
null,
'errors');
229 '@phan-var-force Facture $objectutil';
232 $objectutil->socid = $socid;
233 $result = $objectutil->createFromClone($user, $id);
235 $warningMsgLineList = array();
237 foreach ($objectutil->lines as $line) {
238 if (!is_object($line->product)) {
239 $line->fetch_product();
241 if (is_object($line->product) && $line->product->id > 0) {
242 if (empty($line->product->status)) {
243 $warningMsgLineList[$line->id] = $langs->trans(
'WarningLineProductNotToSell', $line->product->ref);
247 if (!empty($warningMsgLineList)) {
251 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?facid=' . $result);
254 $langs->load(
"errors");
259 } elseif ($action ==
'reopen' && $usercanreopen) {
263 $result =
$object->setUnpaid($user);
265 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
271 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
276 $idwarehouse =
GETPOST(
'idwarehouse');
278 $qualified_for_stock_change = 0;
280 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
282 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
285 $isErasable =
$object->is_erasable();
287 if (($usercandelete && $isErasable > 0)
288 || ($usercancreate && $isErasable == 1)) {
289 $result =
$object->delete($user, 0, $idwarehouse);
291 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
298 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
308 $outputlangs = $langs;
314 $newlang =
$object->thirdparty->default_lang;
316 if (!empty($newlang)) {
318 $outputlangs->setDefaultLang($newlang);
319 $outputlangs->load(
'products');
323 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
326 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
333 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
336 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
337 $discount->unlink_invoice();
338 } elseif ($action ==
'valid' && $usercancreate) {
342 if ((preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) &&
349 $last_of_type =
$object->willBeLastOfSameType(
true);
350 if (empty(
$object->date_validation) && !$last_of_type[0]) {
360 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
369 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
378 $array_of_total_ht_per_vat_rate = array();
379 $array_of_total_ht_devise_per_vat_rate = array();
380 foreach (
$object->lines as $line) {
382 $vat_src_code_for_line =
'';
383 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
384 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
386 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
387 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
389 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
390 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
394 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
395 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
396 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
398 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
399 if (
$object->type == $object::TYPE_DEPOSIT) {
400 $langs->load(
"errors");
402 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
406 $tmpvatratetoshow = explode(
'_', $vatrate);
407 $tmpvatratetoshow[0] = round((
float) $tmpvatratetoshow[0], 2);
409 if ($tmpvatratetoshow[0] != 0) {
410 $langs->load(
"errors");
411 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", $tmpvatratetoshow[0]),
null,
'errors');
419 } elseif ($action ==
'classin' && $usercancreate) {
422 } elseif ($action ==
'setmode' && $usercancreate) {
428 } elseif ($action ==
'setretainedwarrantyconditions' && $usercancreate) {
430 $object->retained_warranty_fk_cond_reglement = 0;
431 $result =
$object->setRetainedWarrantyPaymentTerms(
GETPOSTINT(
'retained_warranty_fk_cond_reglement'));
436 $old_rw_date_lim_reglement =
$object->retained_warranty_date_limit;
437 $new_rw_date_lim_reglement =
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
438 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
439 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
444 $result =
$object->update($user);
448 } elseif ($action ==
'setretainedwarranty' && $usercancreate) {
454 } elseif ($action ==
'setretainedwarrantydatelimit' && $usercancreate) {
456 $result =
$object->setRetainedWarrantyDateLimit(
GETPOSTFLOAT(
'retained_warranty_date_limit'));
460 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
461 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
462 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
464 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
466 $old_date_lim_reglement =
$object->date_lim_reglement;
468 if (empty($newdate)) {
469 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
470 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id.
'&action=editinvoicedate&token='.
newToken());
475 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
477 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
482 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
483 if ($new_date_lim_reglement) {
484 $object->date_lim_reglement = $new_date_lim_reglement;
489 $result =
$object->update($user);
492 $action =
'editinvoicedate';
494 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
499 $object->date_pointoftax = $date_pointoftax;
500 $result =
$object->update($user);
504 } elseif ($action ==
'setconditions' && $usercancreate) {
506 $object->cond_reglement_code = 0;
507 $object->cond_reglement_id = 0;
522 $old_date_lim_reglement =
$object->date_lim_reglement;
523 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
524 if ($new_date_lim_reglement) {
525 $object->date_lim_reglement = $new_date_lim_reglement;
530 $result =
$object->update($user);
542 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
546 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
547 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
549 $result =
$object->update($user);
553 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
556 $result =
$object->update($user);
563 $outputlangs = $langs;
566 $newlang =
GETPOST(
'lang_id',
'aZ09');
569 $newlang =
$object->thirdparty->default_lang;
571 if (!empty($newlang)) {
573 $outputlangs->setDefaultLang($newlang);
574 $outputlangs->load(
'products');
579 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
585 } elseif ($action ==
'set_incoterms' && isModEnabled(
'incoterm') && $usercancreate) {
587 } elseif ($action ==
'setbankaccount' && $usercancreate) {
589 } elseif ($action ==
'setremisepercent' && $usercancreate) {
592 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
610 if (
GETPOSTINT(
"remise_id_for_payment") > 0) {
611 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
613 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
617 $remaintopay =
$object->getRemainToPay(0);
621 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
625 $result = $discount->link_to_invoice(0, $id);
633 $newremaintopay =
$object->getRemainToPay(0);
634 if ($newremaintopay == 0) {
647 $outputlangs = $langs;
650 $newlang =
GETPOST(
'lang_id',
'aZ09');
654 $newlang =
$object->thirdparty->default_lang;
656 if (!empty($newlang)) {
658 $outputlangs->setDefaultLang($newlang);
662 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
667 } elseif ($action ==
'setref' && $usercancreate) {
669 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', 0,
'',
'', $user,
'BILL_MODIFY');
670 } elseif ($action ==
'setref_client' && $usercancreate) {
673 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
682 $qualified_for_stock_change = 0;
684 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
686 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
689 if ($qualified_for_stock_change) {
690 if (!$idwarehouse || $idwarehouse == - 1) {
692 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
699 $result =
$object->validate($user,
'', $idwarehouse);
703 $outputlangs = $langs;
706 $newlang =
GETPOST(
'lang_id',
'aZ09');
709 $newlang =
$object->thirdparty->default_lang;
711 if (!empty($newlang)) {
713 $outputlangs->setDefaultLang($newlang);
714 $outputlangs->load(
'products');
720 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
733 } elseif ($action ==
'confirm_modif' && $usercanunvalidate) {
742 $qualified_for_stock_change = 0;
744 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
746 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
749 if ($qualified_for_stock_change) {
750 if (!$idwarehouse || $idwarehouse == - 1) {
752 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
761 $sql =
'SELECT pf.amount';
762 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf';
763 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
765 $result = $db->query($sql);
768 $num = $db->num_rows($result);
771 $objp = $db->fetch_object($result);
772 $totalpaid += $objp->amount;
779 $resteapayer =
$object->total_ttc - $totalpaid;
782 $ventilExportCompta =
$object->getVentilExportCompta();
785 if ($ventilExportCompta == 0) {
787 $result =
$object->setDraft($user, $idwarehouse);
794 $outputlangs = $langs;
797 $newlang =
GETPOST(
'lang_id',
'aZ09');
800 $newlang =
$object->thirdparty->default_lang;
802 if (!empty($newlang)) {
804 $outputlangs->setDefaultLang($newlang);
805 $outputlangs->load(
'products');
810 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
815 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
818 $result =
$object->setPaid($user);
822 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
825 $close_code =
GETPOST(
"close_code",
'restricthtml');
826 $close_note =
GETPOST(
"close_note",
'restricthtml');
828 $result =
$object->setPaid($user, $close_code, $close_note);
833 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
835 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
838 $close_code =
GETPOST(
"close_code",
'restricthtml');
839 $close_note =
GETPOST(
"close_note",
'restricthtml');
841 $result =
$object->setCanceled($user, $close_code, $close_note);
846 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
848 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
856 $result = $discountcheck->fetch(0,
$object->id);
869 $amount_ht = $amount_tva = $amount_ttc = array();
870 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
874 foreach (
$object->lines as $line) {
875 if ($line->product_type < 9 && $line->total_ht != 0) {
876 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
878 $amount_ht[$keyforvatrate] += $line->total_ht;
879 $amount_tva[$keyforvatrate] += $line->total_tva;
880 $amount_ttc[$keyforvatrate] += $line->total_ttc;
881 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
882 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
883 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
887 '@phan-var-force array<string,float> $amount_ht
888 @phan-var-force array<string,float> $amount_tva
889 @phan-var-force array<string,float> $amount_ttc
890 @phan-var-force array<string,float> $multicurrency_amount_ht
891 @phan-var-force array<string,float> $multicurrency_amount_tva
892 @phan-var-force array<string,float> $multicurrency_amount_ttc';
896 $alreadypaid =
$object->getSommePaiement();
897 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
898 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
899 foreach ($amount_ht as $vatrate => $val) {
900 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
901 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
902 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
903 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
904 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
905 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
914 $discount->description =
'(CREDIT_NOTE)';
916 $discount->description =
'(DEPOSIT)';
918 $discount->description =
'(EXCESS RECEIVED)';
920 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
922 $discount->fk_soc =
$object->socid;
923 $discount->socid =
$object->socid;
924 $discount->fk_facture_source =
$object->id;
932 $sql =
'SELECT SUM(pf.amount) as total_paiements';
933 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
934 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
935 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
936 $sql .=
' AND pf.fk_paiement = p.rowid';
937 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
938 $resql = $db->query($sql);
943 $res = $db->fetch_object($resql);
944 $total_paiements = $res->total_paiements;
947 $total_creditnote_and_deposit = 0;
948 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
949 $sql .=
" re.description, re.fk_facture_source";
950 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
951 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
952 $resql = $db->query($sql);
953 if (!empty($resql)) {
954 while ($obj = $db->fetch_object($resql)) {
955 $total_creditnote_and_deposit += $obj->amount_ttc;
961 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
962 $discount->amount_tva = 0;
963 $discount->tva_tx = 0;
964 $discount->vat_src_code =
'';
966 $result = $discount->create($user);
972 foreach ($amount_ht as $tva_tx => $xxx) {
973 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
974 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
975 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
976 $discount->multicurrency_amount_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
977 $discount->multicurrency_amount_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
978 $discount->multicurrency_amount_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
983 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
984 $vat_src_code = $reg[1];
985 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
988 $discount->tva_tx = abs((
float) $tva_tx);
989 $discount->vat_src_code = $vat_src_code;
991 $result = $discount->create($user);
1002 $result =
$object->setPaid($user);
1017 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
1022 $result = $paiement->fetch(
GETPOSTINT(
'paiement_id'));
1024 $result = $paiement->delete($user);
1026 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1034 } elseif ($action ==
'add' && $usercancreate) {
1041 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1047 $originentity =
GETPOST(
'originentity');
1049 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
1059 if (empty($dateinvoice)) {
1061 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1071 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1081 $object->date_pointoftax = $date_pointoftax;
1082 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1083 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1094 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1095 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1102 $id =
$object->createFromCurrent($user);
1112 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1114 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1118 if (empty($dateinvoice)) {
1120 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1130 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1135 if (!empty($originentity)) {
1136 $object->entity = $originentity;
1142 $object->date_pointoftax = $date_pointoftax;
1143 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1144 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1149 $object->cond_reglement_id = 0;
1155 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1156 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1160 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1163 $facture_source =
new Facture($db);
1164 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1166 $object->situation_counter = $facture_source->situation_counter;
1167 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1168 $facture_source->fetchPreviousNextSituationInvoice();
1178 if (
$object->copy_linked_contact($facture_source,
'internal') < 0) {
1180 } elseif ($facture_source->socid ==
$object->socid) {
1182 if (
$object->copy_linked_contact($facture_source,
'external') < 0) {
1193 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1194 if (!empty($facture_source->lines)) {
1195 $fk_parent_line = 0;
1197 foreach ($facture_source->lines as $line) {
1199 if (method_exists($line,
'fetch_optionals')) {
1201 $line->fetch_optionals();
1205 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1206 $fk_parent_line = 0;
1211 $source_fk_prev_id = $line->fk_prev_id;
1212 $line->fk_prev_id = $line->id;
1214 if (!empty($facture_source->tab_previous_situation_invoice)) {
1217 $tab_jumped_credit_notes = array();
1218 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1219 $searchPreviousInvoice =
true;
1220 while ($searchPreviousInvoice) {
1221 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1222 $searchPreviousInvoice =
false;
1226 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1232 $maxPrevSituationPercent = 0;
1233 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1234 if ($prevLine->id == $source_fk_prev_id) {
1235 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1238 $line->total_ht -= $prevLine->total_ht;
1239 $line->total_tva -= $prevLine->total_tva;
1240 $line->total_ttc -= $prevLine->total_ttc;
1241 $line->total_localtax1 -= $prevLine->total_localtax1;
1242 $line->total_localtax2 -= $prevLine->total_localtax2;
1244 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1245 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1246 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1247 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1252 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1257 $maxPrevSituationPercent = 0;
1258 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1259 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1260 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1261 $maxPrevSituationPercent = $prevLine->situation_percent;
1263 $line->total_ht -= $prevLine->total_ht;
1264 $line->total_tva -= $prevLine->total_tva;
1265 $line->total_ttc -= $prevLine->total_ttc;
1266 $line->total_localtax1 -= $prevLine->total_localtax1;
1267 $line->total_localtax2 -= $prevLine->total_localtax2;
1269 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1270 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1271 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1272 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1278 $line->situation_percent += $maxPrevSituationPercent;
1284 $line->fk_facture =
$object->id;
1285 $line->fk_parent_line = $fk_parent_line;
1287 $line->subprice = -$line->subprice;
1289 $line->total_ht = -$line->total_ht;
1290 $line->total_tva = -$line->total_tva;
1291 $line->total_ttc = -$line->total_ttc;
1292 $line->total_localtax1 = -$line->total_localtax1;
1293 $line->total_localtax2 = -$line->total_localtax2;
1295 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1296 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1297 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1298 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1300 $line->context[
'createcreditnotefrominvoice'] = 1;
1301 $result = $line->insert(0, 1);
1306 if ($result > 0 && $line->product_type == 9) {
1307 $fk_parent_line = $result;
1315 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1316 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1317 $totalpaid = $facture_source->getSommePaiement();
1318 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1319 $totaldeposits = $facture_source->getSumDepositsUsed();
1320 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1322 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1323 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1326 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1331 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1332 $tva_tx = (float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY');
1337 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC');
1342 if (!empty(
$object->fk_facture_source) && $id > 0) {
1343 $facture_source->fetch(
$object->fk_facture_source);
1344 $facture_source->fetchObjectLinked();
1346 if (!empty($facture_source->linkedObjectsIds)) {
1347 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1348 $object->add_object_linked($sourcetype, current($TIds));
1357 if (empty($dateinvoice)) {
1359 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1370 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1380 $object->date_pointoftax = $date_pointoftax;
1381 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1382 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1394 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1395 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1407 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1408 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1409 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1413 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1417 if (empty($dateinvoice)) {
1419 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1429 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1430 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1435 if ($typeamount && !empty($origin) && !empty($originid)) {
1436 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1437 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1441 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1442 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1446 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1447 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1457 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1467 $object->date_pointoftax = $date_pointoftax;
1468 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1469 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1481 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1482 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1486 $object->situation_counter = 1;
1491 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1493 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1495 $object->retained_warranty = 0;
1496 $object->retained_warranty_fk_cond_reglement = 0;
1499 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1500 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1503 $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);
1508 if (!empty($origin) && !empty($originid)) {
1511 $element = $subelement = $origin;
1512 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1513 $element = $regs[1];
1514 $subelement = $regs[2];
1518 if ($element ==
'order') {
1519 $element = $subelement =
'commande';
1521 if ($element ==
'propal') {
1522 $element =
'comm/propal';
1523 $subelement =
'propal';
1525 if ($element ==
'contract') {
1526 $element = $subelement =
'contrat';
1528 if ($element ==
'inter') {
1529 $element = $subelement =
'ficheinter';
1531 if ($element ==
'shipping') {
1532 $element = $subelement =
'expedition';
1536 $object->origin_type = $origin;
1537 $object->origin_id = $originid;
1542 if (
$object->origin ==
'shipping') {
1543 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1545 $exp->fetch(
$object->origin_id);
1546 $exp->fetchObjectLinked();
1547 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1548 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1549 $object->linked_objects[
'commande'] = $value;
1555 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
1563 $classname = ucfirst($subelement);
1564 $srcobject =
new $classname($db);
1565 '@phan-var-force CommonObject $srcobject';
1567 dol_syslog(
"Try to find source object origin=".
$object->origin.
" originid=".
$object->origin_id.
" to add lines or deposit lines");
1568 $result = $srcobject->fetch(
$object->origin_id);
1573 $amountdeposit = array();
1575 if ($typeamount ==
'amount') {
1576 $amount = (float) $valuedeposit;
1578 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1581 $TTotalByTva = array();
1582 foreach ($srcobject->lines as &$line) {
1583 if (!empty($line->special_code)) {
1586 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1588 '@phan-var-force array<string,float> $TTotalByTva';
1590 $amount_ttc_diff = 0.;
1591 foreach ($TTotalByTva as $tva => &$total) {
1592 $coef = $total / $srcobject->total_ttc;
1593 $am = $amount * $coef;
1594 $amount_ttc_diff += $am;
1595 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1598 if ($typeamount ==
'amount') {
1599 $amountdeposit[0] = $valuedeposit;
1600 } elseif ($typeamount ==
'variable') {
1603 $lines = $srcobject->lines;
1604 $numlines = count($lines);
1605 for ($i = 0; $i < $numlines; $i++) {
1607 if (empty($lines[$i]->qty)) {
1610 if (!empty($lines[$i]->special_code)) {
1614 $totalamount += $lines[$i]->total_ht;
1615 $tva_tx = $lines[$i]->tva_tx;
1616 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1620 if ($totalamount == 0) {
1621 $amountdeposit[0] = 0;
1629 $amount_ttc_diff = $amountdeposit[0];
1632 foreach ($amountdeposit as $tva => $amount) {
1633 if (empty($amount)) {
1638 'amount' =>
'FixAmount',
1639 'variable' =>
'VarAmount'
1641 $descline =
'(DEPOSIT)';
1643 if ($typeamount ==
'amount') {
1644 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code : $conf->currency)).
')';
1645 } elseif ($typeamount ==
'variable') {
1646 $descline .=
' ('.$valuedeposit.
'%)';
1649 $descline .=
' - '.$srcobject->ref;
1662 $lines[$i]->info_bits,
1668 $lines[$i]->special_code,
1681 (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) ? 0 : 1)
1685 $diff =
$object->total_ttc - $amount_ttc_diff;
1689 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1690 $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);
1697 $lines = $srcobject->lines;
1698 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1699 $srcobject->fetch_lines();
1700 $lines = $srcobject->lines;
1705 if (is_array($lines)) {
1706 foreach ($lines as $line) {
1708 $line->qty =
price2num((
float) $line->qty * (
float) $valuestandardinvoice / 100,
'MS');
1714 if (is_array($lines)) {
1715 foreach ($lines as $line) {
1717 $line->qty =
price2num((
float) $line->qty * (
float) $valuedeposit / 100,
'MS');
1722 $fk_parent_line = 0;
1723 $num = count($lines);
1725 for ($i = 0; $i < $num; $i++) {
1726 if (!in_array($lines[$i]->
id, $selectedLines)) {
1731 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
1735 if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1736 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1738 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->
statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
1742 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1743 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1745 if (
$object->situation_counter == 1) {
1746 $lines[$i]->situation_percent = 0;
1749 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
1752 $desc = $label ? $label : $langs->trans(
'Discount');
1756 $discount->fk_soc =
$object->socid;
1757 $discount->socid =
$object->socid;
1758 $discount->amount_ht = abs($lines[$i]->total_ht);
1759 $discount->amount_tva = abs($lines[$i]->total_tva);
1760 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1761 $discount->tva_tx = $lines[$i]->tva_tx;
1762 $discount->fk_user = $user->id;
1763 $discount->description = $desc;
1764 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1765 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1766 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1767 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1769 $discountid = $discount->create($user);
1770 if ($discountid > 0) {
1771 $result =
$object->insert_discount($discountid);
1783 $date_start =
false;
1784 if (isset($lines[$i]->date_debut_prevue)) {
1785 $date_start = $lines[$i]->date_debut_prevue;
1787 if (isset($lines[$i]->date_debut_reel)) {
1788 $date_start = $lines[$i]->date_debut_reel;
1790 if (isset($lines[$i]->date_start)) {
1791 $date_start = $lines[$i]->date_start;
1796 if (isset($lines[$i]->date_fin_prevue)) {
1797 $date_end = $lines[$i]->date_fin_prevue;
1799 if (isset($lines[$i]->date_fin_reel)) {
1800 $date_end = $lines[$i]->date_fin_reel;
1802 if (isset($lines[$i]->date_end)) {
1803 $date_end = $lines[$i]->date_end;
1807 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1808 $fk_parent_line = 0;
1812 if (method_exists($lines[$i],
'fetch_optionals')) {
1813 $lines[$i]->fetch_optionals();
1814 $array_options = $lines[$i]->array_options;
1817 $tva_tx = $lines[$i]->tva_tx;
1818 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
1819 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1829 $lines[$i]->subprice,
1834 $lines[$i]->fk_product,
1835 $lines[$i]->remise_percent,
1839 $lines[$i]->info_bits,
1840 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except : null,
1845 $lines[$i]->special_code,
1849 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice : null,
1853 $lines[$i]->situation_percent ?? 100,
1854 $lines[$i]->fk_prev_id ?? 0,
1855 $lines[$i]->fk_unit,
1870 if ($result > 0 && $lines[$i]->product_type == 9) {
1871 $fk_parent_line = $result;
1881 $object->update_price(1,
'auto', 0, $mysoc);
1909 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id,
'objFrom' => $srcobject);
1910 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
1923 for ($i = 1; $i <= $NBLINES; $i++) {
1929 $result =
$object->addline($product->description, $product->price,
price2num(
GETPOST(
'qty'.$i),
'MS'), $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx,
GETPOSTINT(
'idprod'.$i),
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);
1933 $object->update_price(1,
'auto', 0, $mysoc);
1940 if (empty($dateinvoice)) {
1942 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
1952 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
1962 if (!empty($origin) && !empty($originid)) {
1963 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1966 $object->origin_type = $origin;
1967 $object->origin_id = $originid;
1971 $retained_warranty =
GETPOSTINT(
'retained_warranty');
1972 if (
price2num($retained_warranty) > 0) {
1976 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
1977 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1980 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1981 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
1982 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
1984 $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);
1987 foreach (
$object->lines as $i => &$line) {
1988 $line->fk_prev_id = $line->id;
1989 $line->fetch_optionals();
1991 $line->situation_percent = $line->get_allprev_progress(
$object->id);;
1993 $line->situation_percent = $line->get_prev_progress(
$object->id);
1997 $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);
1998 $line->total_ht = $tabprice[0];
1999 $line->total_tva = $tabprice[1];
2000 $line->total_ttc = $tabprice[2];
2001 $line->total_localtax1 = $tabprice[9];
2002 $line->total_localtax2 = $tabprice[10];
2003 $line->multicurrency_total_ht = $tabprice[16];
2004 $line->multicurrency_total_tva = $tabprice[17];
2005 $line->multicurrency_total_ttc = $tabprice[18];
2008 if ($line->fk_remise_except) {
2010 $result = $discount->fetch($line->fk_remise_except);
2013 if ($discount->fk_facture_line > 0) {
2014 $line->fk_remise_except = 0;
2023 $object->date_pointoftax = $date_pointoftax;
2024 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2040 $object->situation_counter += 1;
2042 $id =
$object->createFromCurrent($user);
2046 $nextSituationInvoice =
new Facture($db);
2047 $nextSituationInvoice->fetch($id);
2050 $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
2051 $ret = $extrafields->setOptionalsFromPost(
null, $nextSituationInvoice);
2053 $nextSituationInvoice->insertExtraFields();
2057 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id);
2058 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $nextSituationInvoice, $action);
2069 if ($id > 0 && !$error) {
2074 $outputlangs = $langs;
2077 $newlang =
GETPOST(
'lang_id',
'aZ09');
2080 $newlang =
$object->thirdparty->default_lang;
2082 if (!empty($newlang)) {
2083 $outputlangs =
new Translate(
"", $conf);
2084 $outputlangs->setDefaultLang($newlang);
2085 $outputlangs->load(
'products');
2090 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2096 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2101 $_GET[
"origin"] = $_POST[
"origin"];
2102 $_GET[
"originid"] = $_POST[
"originid"];
2105 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2109 foreach (
$object->lines as $line) {
2110 if ($line->product_type == 1) {
2111 $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);
2114 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2116 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2117 $vat_rate = str_replace(
'*',
'', $vat_rate);
2120 foreach (
$object->lines as $line) {
2121 $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);
2123 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2125 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2126 $remise_percent = str_replace(
'*',
'', $remise_percent);
2127 foreach (
$object->lines as $line) {
2128 $tvatx= $line->tva_tx;
2129 if (!empty($line->vat_src_code)) {
2130 $tvatx .=
' ('.$line->vat_src_code.
')';
2132 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $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);
2134 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && $usercancreate) {
2135 $langs->load(
'errors');
2140 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
2143 $price_ht_devise =
'';
2145 $price_ttc_devise =
'';
2147 $price_min_ttc =
'';
2149 if (
GETPOST(
'price_ht') !==
'') {
2152 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2155 if (
GETPOST(
'price_ttc') !==
'') {
2158 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2159 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2162 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2163 if ($prod_entry_mode ==
'free') {
2169 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2174 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2177 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
2178 if (empty($remise_percent)) {
2179 $remise_percent = 0;
2183 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2184 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2186 if (is_array($extralabelsline)) {
2188 foreach ($extralabelsline as $key => $value) {
2189 unset($_POST[
"options_".$key.$predef]);
2193 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2194 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2197 if (!$prod_entry_mode) {
2199 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2203 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2204 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2207 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && (($price_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht ==
'') && (($price_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ==
'') && $price_ttc ===
'' && $price_ttc_devise ===
'' &&
$object->type !=
Facture::TYPE_CREDIT_NOTE) {
2208 if (($price_ht < 0 || $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2209 $langs->load(
"errors");
2210 if (
$object->type == $object::TYPE_DEPOSIT) {
2212 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2214 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2218 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2223 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2226 if ($prod_entry_mode ==
'free' && empty($idprod) && empty($product_desc)) {
2227 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2231 $langs->load(
"errors");
2232 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2236 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2237 if ($combinations =
GETPOST(
'combinations',
'array')) {
2241 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2242 $idprod = $res->fk_product_child;
2244 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2250 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
2256 $ret =
$object->fetch_thirdparty();
2261 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2272 if (!empty($idprod) && $idprod > 0) {
2274 $prod->fetch($idprod);
2276 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2281 $datapriceofproduct = $prod->getSellPrice($mysoc,
$object->thirdparty, $pqp);
2283 $pu_ht = $datapriceofproduct[
'pu_ht'];
2284 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2285 $price_min = $datapriceofproduct[
'price_min'];
2286 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2287 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2291 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2292 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $prod->tva_tx));
2296 if (!empty($price_ht) || $price_ht ===
'0') {
2298 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2299 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2300 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2303 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2305 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2306 } elseif ($tmpvat != $tmpprodvat) {
2308 if ($price_base_type !=
'HT') {
2309 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2311 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2319 $outputlangs = $langs;
2321 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
2322 $newlang =
GETPOST(
'lang_id',
'aZ09');
2324 if (empty($newlang)) {
2325 $newlang =
$object->thirdparty->default_lang;
2327 if (!empty($newlang)) {
2328 $outputlangs =
new Translate(
"", $conf);
2329 $outputlangs->setDefaultLang($newlang);
2330 $outputlangs->load(
'products');
2333 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->
description;
2335 $desc = $prod->description;
2344 $desc = $product_desc;
2350 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
2354 $outputlangs = $langs;
2356 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
2357 $newlang =
GETPOST(
'lang_id',
'alpha');
2359 if (empty($newlang)) {
2360 $newlang =
$object->thirdparty->default_lang;
2362 if (!empty($newlang)) {
2363 $outputlangs =
new Translate(
"", $conf);
2364 $outputlangs->setDefaultLang($newlang);
2365 $outputlangs->load(
'products');
2367 if (!empty($prod->customcode)) {
2368 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2370 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2373 if (!empty($prod->country_code)) {
2374 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
2377 if (!empty($prod->customcode)) {
2378 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2380 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2383 if (!empty($prod->country_code)) {
2384 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
2391 $type = $prod->type;
2392 $fk_unit = $prod->fk_unit;
2394 if (!empty($price_ht)) {
2399 if (!empty($price_ttc)) {
2404 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2405 $tva_tx = str_replace(
'*',
'', $tva_tx);
2406 if (empty($tva_tx)) {
2409 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2410 $desc = $product_desc;
2412 $fk_unit =
GETPOST(
'units',
'alpha');
2414 if ($pu_ttc && !$pu_ht) {
2415 $price_base_type =
'TTC';
2429 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2430 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2433 $pu_equivalent = $pu_ht;
2434 $pu_equivalent_ttc = $pu_ttc;
2436 $currency_tx =
$object->multicurrency_tx;
2440 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2441 $pu_equivalent = (float) $pu_ht_devise * $currency_tx;
2443 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2444 $pu_equivalent_ttc = (float) $pu_ttc_devise * $currency_tx;
2464 $price2num_remise_percent =
price2num($remise_percent);
2465 $price2num_price_min =
price2num($price_min);
2466 $price2num_price_min_ttc =
price2num($price_min_ttc);
2467 if (empty($price2num_pu_ht)) {
2468 $price2num_pu_ht = 0;
2470 if (empty($price2num_remise_percent)) {
2471 $price2num_remise_percent = 0;
2473 if (empty($price2num_price_min)) {
2474 $price2num_price_min = 0;
2476 if (empty($price2num_price_min_ttc)) {
2477 $price2num_price_min_ttc = 0;
2482 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2483 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2486 } 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') {
2487 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2494 '@phan-var-force array<string,mixed> $lines';
2496 if (isModEnabled(
'productbatch') && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) &&
getDolGlobalString(
'INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS')) {
2497 $langs->load(
'productbatch');
2498 foreach ($lines[$i]->detail_batch as $batchline) {
2499 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2504 $result =
$object->addline($desc, $pu_ht, $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,
GETPOST(
'fk_parent_line'), $fournprice, $buyingprice, $label, $array_options,
GETPOST(
'progress'), 0, $fk_unit, $pu_ht_devise);
2509 $outputlangs = $langs;
2512 $newlang =
GETPOST(
'lang_id',
'aZ09');
2515 $newlang =
$object->thirdparty->default_lang;
2517 if (!empty($newlang)) {
2518 $outputlangs =
new Translate(
"", $conf);
2519 $outputlangs->setDefaultLang($newlang);
2520 $outputlangs->load(
'products');
2525 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2531 unset($_POST[
'prod_entry_mode']);
2532 unset($_POST[
'qty']);
2533 unset($_POST[
'type']);
2534 unset($_POST[
'remise_percent']);
2535 unset($_POST[
'price_ht']);
2536 unset($_POST[
'multicurrency_price_ht']);
2537 unset($_POST[
'price_ttc']);
2538 unset($_POST[
'tva_tx']);
2539 unset($_POST[
'product_ref']);
2540 unset($_POST[
'product_label']);
2541 unset($_POST[
'product_desc']);
2542 unset($_POST[
'fournprice']);
2543 unset($_POST[
'buying_price']);
2544 unset($_POST[
'np_marginRate']);
2545 unset($_POST[
'np_markRate']);
2546 unset($_POST[
'dp_desc']);
2547 unset($_POST[
'idprod']);
2548 unset($_POST[
'units']);
2549 unset($_POST[
'date_starthour']);
2550 unset($_POST[
'date_startmin']);
2551 unset($_POST[
'date_startsec']);
2552 unset($_POST[
'date_startday']);
2553 unset($_POST[
'date_startmonth']);
2554 unset($_POST[
'date_startyear']);
2555 unset($_POST[
'date_endhour']);
2556 unset($_POST[
'date_endmin']);
2557 unset($_POST[
'date_endsec']);
2558 unset($_POST[
'date_endday']);
2559 unset($_POST[
'date_endmonth']);
2560 unset($_POST[
'date_endyear']);
2561 unset($_POST[
'situations']);
2562 unset($_POST[
'progress']);
2570 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2571 if (!
$object->fetch($id) > 0) {
2583 $vat_rate = str_replace(
'*',
'', $vat_rate);
2595 if (preg_match(
'/\*/', $vat_rate)) {
2600 $vat_rate = str_replace(
'*',
'', $vat_rate);
2609 $pu_equivalent = $pu_ht;
2610 $pu_equivalent_ttc = $pu_ttc;
2612 $currency_tx =
$object->multicurrency_tx;
2616 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2617 $pu_equivalent = (float) $pu_ht_devise * (
float) $currency_tx;
2619 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2620 $pu_equivalent_ttc = (float) $pu_ttc_devise * (
float) $currency_tx;
2635 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2636 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
2638 if (is_array($extralabelsline)) {
2640 foreach ($extralabelsline as $key => $value) {
2641 unset($_POST[
"options_".$key]);
2647 if ($special_code == 3) {
2653 $percent = $line->get_prev_progress(
$object->id);
2658 if ($progress >= 0) {
2659 $mesg = $langs->trans(
"CantBeNullOrPositive");
2663 } elseif ($progress < $line->situation_percent) {
2664 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
2668 } elseif ($progress < $percent) {
2669 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
2680 if (!empty($productid)) {
2682 $product->fetch($productid);
2684 $type = $product->type;
2686 $price_min = $product->price_min;
2688 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
2690 $price_min_ttc = $product->price_min_ttc;
2692 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
2699 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
2700 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2703 $action =
'editline';
2704 } 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') {
2705 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2708 $action =
'editline';
2713 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2717 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
2722 $langs->load(
"errors");
2723 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2727 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2728 $langs->load(
"errors");
2729 if (
$object->type == $object::TYPE_DEPOSIT) {
2731 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2733 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2737 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2744 $previousprogress = $line->get_allprev_progress($line->fk_facture);
2747 if ($fullprogress < $previousprogress) {
2749 setEventMessages($langs->trans(
'CantBeLessThanMinPercent'),
null,
'errors');
2753 if ($fullprogress > 100) {
2754 $fullprogress = 100;
2756 $addprogress = $fullprogress - $previousprogress;
2763 if (empty($usercancreatemargin)) {
2764 foreach (
$object->lines as &$line) {
2766 $fournprice = $line->fk_fournprice;
2767 $buyingprice = $line->pa_ht;
2773 $price_base_type =
'HT';
2775 if (empty($pu) && !empty($pu_ttc)) {
2777 $price_base_type =
'TTC';
2780 $result =
$object->updateline(
2809 $outputlangs = $langs;
2812 $newlang =
GETPOST(
'lang_id',
'aZ09');
2815 $newlang =
$object->thirdparty->default_lang;
2817 if (!empty($newlang)) {
2818 $outputlangs =
new Translate(
"", $conf);
2819 $outputlangs->setDefaultLang($newlang);
2820 $outputlangs->load(
'products');
2824 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2827 unset($_POST[
'qty']);
2828 unset($_POST[
'type']);
2829 unset($_POST[
'productid']);
2830 unset($_POST[
'remise_percent']);
2831 unset($_POST[
'price_ht']);
2832 unset($_POST[
'multicurrency_price_ht']);
2833 unset($_POST[
'price_ttc']);
2834 unset($_POST[
'tva_tx']);
2835 unset($_POST[
'product_ref']);
2836 unset($_POST[
'product_label']);
2837 unset($_POST[
'product_desc']);
2838 unset($_POST[
'fournprice']);
2839 unset($_POST[
'buying_price']);
2840 unset($_POST[
'np_marginRate']);
2841 unset($_POST[
'np_markRate']);
2842 unset($_POST[
'dp_desc']);
2843 unset($_POST[
'idprod']);
2844 unset($_POST[
'units']);
2845 unset($_POST[
'date_starthour']);
2846 unset($_POST[
'date_startmin']);
2847 unset($_POST[
'date_startsec']);
2848 unset($_POST[
'date_startday']);
2849 unset($_POST[
'date_startmonth']);
2850 unset($_POST[
'date_startyear']);
2851 unset($_POST[
'date_endhour']);
2852 unset($_POST[
'date_endmin']);
2853 unset($_POST[
'date_endsec']);
2854 unset($_POST[
'date_endday']);
2855 unset($_POST[
'date_endmonth']);
2856 unset($_POST[
'date_endyear']);
2857 unset($_POST[
'situations']);
2858 unset($_POST[
'progress']);
2863 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modifier')) {
2864 if (!
$object->fetch($id) > 0) {
2867 if (
GETPOST(
'all_progress') !=
"") {
2869 foreach (
$object->lines as $line) {
2871 $percent = $line->get_allprev_progress(
$object->id);
2873 $percent = $line->get_prev_progress(
$object->id);
2875 if ((
float) $all_progress < (
float) $percent) {
2876 $mesg = $langs->trans(
"Line").
' '.$i.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
2885 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
2886 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2888 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
2890 $object->fetch($id,
'',
'', 0,
true);
2896 &&
$object->is_last_in_cycle()
2897 && $usercanunvalidate
2900 $newCycle =
$object->newCycle();
2901 if ($newCycle > 1) {
2903 $lastCycle =
$object->situation_cycle_ref;
2904 $lastSituationCounter =
$object->situation_counter;
2905 $linkedCreditNotesList = array();
2907 if (count(
$object->tab_next_situation_invoice) > 0) {
2908 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
2910 && $next_invoice->situation_counter ==
$object->situation_counter
2911 && $next_invoice->fk_facture_source ==
$object->id
2913 $linkedCreditNotesList[] = $next_invoice->id;
2918 $object->situation_cycle_ref = $newCycle;
2919 $object->situation_counter = 1;
2921 if (
$object->update($user) > 0) {
2923 if (count($linkedCreditNotesList) > 0) {
2925 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
2926 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
2927 $sql .=
' , situation_final=0';
2928 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
2929 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
2931 $resql = $db->query($sql);
2937 foreach (
$object->lines as $line) {
2939 if ($line->product_type == 9) {
2944 if (!empty(
$object->tab_previous_situation_invoice)) {
2946 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
2947 $searchPreviousInvoice =
true;
2948 while ($searchPreviousInvoice) {
2950 $searchPreviousInvoice =
false;
2958 $maxPrevSituationPercent = 0;
2959 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
2960 if ($prevLine->id == $line->fk_prev_id) {
2961 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
2966 $line->situation_percent -= $maxPrevSituationPercent;
2968 if ($line->update() < 0) {
2977 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
2979 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
2982 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
2985 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
2991 $fromElement =
GETPOST(
'fromelement');
2992 $fromElementid =
GETPOST(
'fromelementid');
2993 $importLines =
GETPOST(
'line_checkbox');
2995 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
2996 if ($fromElement ==
'commande') {
2998 $lineClassName =
'OrderLine';
2999 } elseif ($fromElement ==
'propal') {
3000 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
3001 $lineClassName =
'PropaleLigne';
3003 $nextRang = count(
$object->lines) + 1;
3006 foreach ($importLines as $lineId) {
3007 $lineId = intval($lineId);
3008 $originLine =
new $lineClassName($db);
3009 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
3010 $originLine->fetch_optionals();
3011 $desc = $originLine->desc;
3012 $pu_ht = $originLine->subprice;
3013 $qty = $originLine->qty;
3014 $txtva = $originLine->tva_tx;
3015 $txlocaltax1 = $originLine->localtax1_tx;
3016 $txlocaltax2 = $originLine->localtax2_tx;
3017 $fk_product = $originLine->fk_product;
3018 $remise_percent = $originLine->remise_percent;
3019 $date_start = $originLine->date_start;
3020 $date_end = $originLine->date_end;
3021 $fk_code_ventilation = 0;
3022 $info_bits = $originLine->info_bits;
3023 $fk_remise_except = $originLine->fk_remise_except;
3024 $price_base_type =
'HT';
3026 $type = $originLine->product_type;
3027 $rang = $nextRang++;
3028 $special_code = $originLine->special_code;
3029 $origin = $originLine->element;
3030 $origin_id = $originLine->id;
3031 $fk_parent_line = 0;
3032 $fk_fournprice = $originLine->fk_fournprice;
3033 $pa_ht = $originLine->pa_ht;
3034 $label = $originLine->label;
3035 $array_options = $originLine->array_options;
3037 $situation_percent = 0;
3039 $situation_percent = 100;
3042 $fk_unit = $originLine->fk_unit;
3043 $pu_ht_devise = $originLine->multicurrency_subprice;
3045 $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);
3064 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3070 $triggersendname =
'BILL_SENTBYMAIL';
3072 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3073 $trackid =
'inv'.$object->id;
3074 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3077 $upload_dir = $conf->invoice->multidir_output[!empty(
$object->entity) ?
$object->entity : $conf->entity];
3078 $permissiontoadd = $usercancreate;
3079 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3082 if ($action ==
'update_extras' && $usercancreate) {
3086 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
GETPOST(
'attribute',
'restricthtml'));
3093 $result =
$object->insertExtraFields(
'BILL_MODIFY');
3101 $action =
'edit_extras';
3106 if ($action ==
'addcontact' && $usercancreate) {
3107 $result =
$object->fetch($id);
3109 if ($result > 0 && $id > 0) {
3112 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3116 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3119 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3120 $langs->load(
"errors");
3121 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3126 } elseif ($action ==
'swapstatut' && $usercancreate) {
3133 } elseif ($action ==
'deletecontact' && $usercancreate) {
3136 $result =
$object->delete_contact($lineid);
3139 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3147 $action =
'edit_extras';
3158$form =
new Form($db);
3164$bankaccountstatic =
new Account($db);
3165if (isModEnabled(
'project')) {
3171$title =
$object->ref.
" - ".$langs->trans(
'Card');
3172if ($action ==
'create') {
3173 $title = $langs->trans(
"NewBill");
3175$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3181if ($action ==
'create') {
3182 $facturestatic =
new Facture($db);
3183 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3188 $res = $soc->fetch($socid);
3191 $currency_code = $conf->currency;
3193 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3194 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3199 if (!empty($origin) && !empty($originid)) {
3201 $element = $subelement = $origin;
3203 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3204 $element = $regs[1];
3205 $subelement = $regs[2];
3211 if ($element ==
'project') {
3212 $projectid = $originid;
3214 if (empty($cond_reglement_id)) {
3215 $cond_reglement_id = $soc->cond_reglement_id;
3217 if (empty($mode_reglement_id)) {
3218 $mode_reglement_id = $soc->mode_reglement_id;
3220 if (empty($fk_account)) {
3221 $fk_account = $soc->fk_account;
3223 if (empty($dateinvoice)) {
3229 if ($element ==
'order' || $element ==
'commande') {
3230 $element = $subelement =
'commande';
3232 if ($element ==
'propal') {
3233 $element =
'comm/propal';
3234 $subelement =
'propal';
3236 if ($element ==
'contract') {
3237 $element = $subelement =
'contrat';
3239 if ($element ==
'shipping') {
3240 $element = $subelement =
'expedition';
3245 $classname = ucfirst($subelement);
3246 $objectsrc =
new $classname($db);
3247 $objectsrc->fetch($originid);
3248 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3249 $objectsrc->fetch_lines();
3251 $objectsrc->fetch_thirdparty();
3253 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3254 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3257 if (empty($socid)) {
3258 $soc = $objectsrc->thirdparty;
3261 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3263 if ($element ==
'expedition') {
3264 $ref_client = (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
'');
3266 $elem = $subelem = $objectsrc->origin;
3267 $expeoriginid = $objectsrc->origin_id;
3269 $classname = ucfirst($subelem);
3271 $expesrc =
new $classname($db);
3272 $expesrc->fetch($expeoriginid);
3274 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3275 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3276 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3278 if (isModEnabled(
'multicurrency')) {
3279 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3280 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3284 $expesrc->fetch_optionals();
3285 $object->array_options = $expesrc->array_options;
3287 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
3288 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3289 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3291 if (isModEnabled(
'multicurrency')) {
3292 if (!empty($objectsrc->multicurrency_code)) {
3293 $currency_code = $objectsrc->multicurrency_code;
3295 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
3296 $currency_tx = $objectsrc->multicurrency_tx;
3301 $objectsrc->fetch_optionals();
3302 $object->array_options = $objectsrc->array_options;
3306 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
3307 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
3308 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
3310 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3312 if (isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3313 $currency_code = $soc->multicurrency_code;
3318 if (!
GETPOST(
'changecompany')) {
3319 if (GETPOSTISSET(
'cond_reglement_id')) {
3320 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3322 if (GETPOSTISSET(
'mode_reglement_id')) {
3323 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3325 if (GETPOSTISSET(
'cond_reglement_id')) {
3331 if (empty($cond_reglement_id)) {
3332 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
3336 if (empty($mode_reglement_id)) {
3337 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
3347 if (!empty($soc->id)) {
3348 $absolute_discount = $soc->getAvailableDiscounts();
3350 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
3351 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
3353 if (!empty($conf->use_javascript_ajax)) {
3354 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3360 if ($origin ==
'contrat') {
3361 $langs->load(
"admin");
3362 $text = $langs->trans(
"ToCreateARecurringInvoice");
3363 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3365 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3367 print
info_admin($text, 0, 0, 0,
'opacitymedium').
'<br>';
3370 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3371 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3372 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3373 print
'<input type="hidden" name="changecompany" value="0">';
3375 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3377 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3378 print
'<input name="ref" type="hidden" value="provisoire">';
3379 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3380 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3381 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3382 print
'<input name="force_fk_account" type="hidden" value="0">';
3383 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3384 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3385 print
'<input type="hidden" name="originentity" value="'.GETPOST(
'originentity').
'">';
3386 if (!empty($currency_tx)) {
3387 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3393 $parameters = array();
3395 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters,
$object, $action);
3396 if (empty($reshook)) {
3397 print
'<table class="border centpercent">';
3399 $exampletemplateinvoice =
new FactureRec($db);
3401 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3402 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
3406 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
3408 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3409 print
'<td colspan="2">';
3410 print $soc->getNomUrl(1,
'customer');
3411 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3413 $arrayoutstandingbills = $soc->getOutstandingBills();
3414 $outstandingBills = $arrayoutstandingbills[
'opened'];
3415 print
' - <span class="opacitymedium">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3416 print
'<span class="amount">'.price($outstandingBills, 0, $langs, 0, 0, -1, $conf->currency).
'</span>';
3417 if ($soc->outstanding_limit !=
'') {
3418 if ($outstandingBills > $soc->outstanding_limit) {
3419 print
img_warning($langs->trans(
"OutstandingBillReached"));
3421 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1, $conf->currency);
3426 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3427 print
'<td colspan="2">';
3428 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
3429 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3433 $(document).ready(function() {
3434 $("#socid").change(function() {
3436 console.log("Submit page");
3437 $(\'input[name="action"]\').val(\'create\');
3438 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3439 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3440 $(\'input[name="force_fk_account"]\').val(\'1\');
3441 $("#formtocreate").submit(); */
3443 // For company change, we must submit page with action=create instead of action=add
3444 console.log("We have changed the company - Resubmit page");
3445 jQuery("input[name=changecompany]").val("1");
3446 jQuery("#formtocreateaction").val("create");
3447 jQuery("#formtocreate").submit();
3453 print
' <a href="'.DOL_URL_ROOT.
'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create').
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddThirdParty").
'"></span></a>';
3460 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3461 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
3463 $dateinvoice = $invoice_predefined->date_when;
3464 if (empty($projectid)) {
3465 $projectid = $invoice_predefined->fk_project;
3467 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
3468 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
3469 $fk_account = $invoice_predefined->fk_account;
3470 $note_public = $invoice_predefined->note_public;
3471 $note_private = $invoice_predefined->note_private;
3473 if (!empty($invoice_predefined->multicurrency_code)) {
3474 $currency_code = $invoice_predefined->multicurrency_code;
3476 if (!empty($invoice_predefined->multicurrency_tx)) {
3477 $currency_tx = $invoice_predefined->multicurrency_tx;
3480 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
3481 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
3482 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
3484 $resql = $db->query($sql);
3486 $num = $db->num_rows($resql);
3490 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
3492 print
'<select class="flat" id="fac_rec" name="fac_rec">';
3493 print
'<option value="0" selected></option>';
3495 $objp = $db->fetch_object($resql);
3496 print
'<option value="'.$objp->rowid.
'"';
3499 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
3501 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
3510 print
'<script type="text/javascript">
3511 $(document).ready(function() {
3512 $("#fac_rec").change(function() {
3513 console.log("We have changed the template invoice - Reload page");
3514 var fac_rec = $(this).val();
3515 var socid = $(\'#socid\').val();
3516 // 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.
3517 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3530 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td colspan="2">';
3531 print
'<div class="tagtable">'.
"\n";
3534 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3535 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
3536 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
3538 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'nowraponall', 0, 3,
'standardonsmartphone');
3539 print
'<table class="nobordernopadding"><tr>';
3543 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
3552 print
'<td class="nowrap" style="padding-left: 15px">';
3553 print
'<span class="opacitymedium">'.$langs->trans(
'PercentOfOriginalObject').
'</span>:<input class="right" placeholder="100%" type="text" id="valuestandardinvoice" name="valuestandardinvoice" size="3" value="'.(GETPOSTISSET(
'valuestandardinvoice') ?
GETPOST(
'valuestandardinvoice',
'alpha') :
'100%').
'"/>';
3556 print
'</tr></table>';
3557 print
'</div></div>';
3559 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
3562 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3563 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
3564 print
'<script type="text/javascript">
3565 jQuery(document).ready(function() {
3566 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
3567 jQuery("#radio_standard").prop("checked", true);
3569 jQuery("#typedeposit, #valuedeposit").click(function() {
3570 jQuery("#radio_deposit").prop("checked", true);
3572 jQuery("#typedeposit").change(function() {
3573 console.log("We change type of down payment");
3574 jQuery("#radio_deposit").prop("checked", true);
3575 setRadioForTypeOfInvoice();
3577 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
3578 setRadioForTypeOfInvoice();
3580 function setRadioForTypeOfInvoice() {
3581 console.log("Change radio for type of invoice");
3582 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
3583 jQuery("#checkforselects").prop("disabled", true);
3584 jQuery("#checkforselects").prop("checked", false);
3585 jQuery(".checkforselect").prop("disabled", true);
3586 jQuery(".checkforselect").prop("checked", false);
3588 jQuery("#checkforselects").prop("disabled", false);
3589 jQuery("#checkforselects").prop("checked", true);
3590 jQuery(".checkforselect").prop("disabled", false);
3591 jQuery(".checkforselect").prop("checked", true);
3597 print
'<table class="nobordernopadding"><tr>';
3599 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
3601 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
3604 if (($origin ==
'propal') || ($origin ==
'commande')) {
3605 print
'<td class="nowrap" style="padding-left: 15px">';
3607 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
3608 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
3609 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
3611 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
3613 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
3614 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
3615 if (!empty($origin_payment_conditions_deposit_percent)) {
3616 $typedeposit =
'variable';
3619 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
3620 $valuedeposit = $objectsrc->deposit_percent;
3622 print $form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
3624 print
'<td class="nowrap" style="padding-left: 5px">';
3625 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.$valuedeposit.
'"/>';
3628 print
'</tr></table>';
3630 print
'</div></div>';
3637 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3638 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
3639 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
3641 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
3643 print
'</div></div>';
3646 $opt = $form->selectSituationInvoices(
GETPOSTINT(
'originid'), $socid);
3648 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3649 $tmp =
'<input type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
3650 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3651 $tmp .=
' disabled';
3654 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3655 $text .=
'<select class="flat" id="situations" name="situations"';
3656 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3657 $text .=
' disabled';
3661 $text .=
'</select>';
3662 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
3664 print
'</div></div>';
3670 $facids = $facturestatic->list_replacable_invoices($soc->id);
3676 if (is_array($facids)) {
3677 foreach ($facids as $facparam) {
3678 $options .=
'<option value="'.$facparam [
'id'].
'"';
3679 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
3680 $options .=
' selected';
3682 $options .=
'>'.$facparam[
'ref'];
3683 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
3684 $options .=
'</option>';
3688 print
'<!-- replacement line -->';
3689 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3690 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
3691 if (!$options || $invoice_predefined->id > 0) {
3692 $tmp .=
' disabled';
3695 print
'<script type="text/javascript">
3696 jQuery(document).ready(function() {
3697 jQuery("#fac_replacement").change(function() {
3698 jQuery("#radio_replacement").prop("checked", true);
3702 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
3703 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
3704 if (!$options || $invoice_predefined->id > 0) {
3705 $text .=
' disabled';
3709 $text .=
'<option value="-1"> </option>';
3712 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
3714 $text .=
'</select>';
3715 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3717 print
'</div></div>';
3721 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3722 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3723 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3724 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3725 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'nowraponall', 0, 3,
'firstsituationonsmartphone');
3727 print
'</div></div>';
3730 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3731 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
3732 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
3734 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'replacementonsmartphone');
3736 print
'</div></div>';
3739 if (empty($origin)) {
3744 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
3750 $newinvoice_static =
new Facture($db);
3751 foreach ($facids as $key => $valarray) {
3752 $newinvoice_static->id = $key;
3753 $newinvoice_static->ref = $valarray [
'ref'];
3754 $newinvoice_static->statut = $valarray [
'status'];
3755 $newinvoice_static->status = $valarray [
'status'];
3756 $newinvoice_static->type = $valarray [
'type'];
3757 $newinvoice_static->paye = $valarray [
'paye'];
3759 $optionsav .=
'<option value="'.$key.
'"';
3760 if ($key ==
GETPOST(
'fac_avoir')) {
3761 $optionsav .=
' selected';
3764 $newinvoice_static->fetch_optionals($key);
3765 $object->array_options = $newinvoice_static->array_options;
3768 $optionsav .= $newinvoice_static->ref;
3769 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
3770 $optionsav .=
'</option>';
3773 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3774 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
3775 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
3776 $tmp .=
' disabled';
3780 print
'<script type="text/javascript">
3781 jQuery(document).ready(function() {
3782 if (jQuery("#radio_creditnote").is(":checked"))
3784 jQuery("#radio_standard").prop("disabled", true);
3786 jQuery("#radio_standard").prop("disabled", false);
3788 if (! jQuery("#radio_creditnote").is(":checked"))
3790 jQuery("#credit_note_options").hide();
3792 jQuery("#radio_creditnote").click(function() {
3793 jQuery("#credit_note_options").show();
3795 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
3796 jQuery("#credit_note_options").hide();
3800 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
3801 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3802 if (!$optionsav || $invoice_predefined->id > 0) {
3803 $text .=
' disabled';
3807 $text .=
'<option value="-1"></option>';
3808 $text .= $optionsav;
3810 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
3812 $text .=
'</select>';
3813 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3816 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
3817 print
' <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">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
3818 print
'<br> <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">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
3821 print
'</div></div>';
3824 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3826 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3828 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
3830 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
3832 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
3834 print
'</div></div>'.
"\n";
3839 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3840 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
3841 $text = $tmp.
'<label class="opacitymedium" for="radio_template">'.$langs->trans(
"RepeatableInvoice").
'</label> ';
3842 $desc = $form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3,
'templateonsmartphone');
3844 print
'</div></div>';
3853 foreach ($listtType as $type) {
3854 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
3856 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
3859 print
'<script type="text/javascript">
3860 $(document).ready(function() {
3861 var listType = {'.$jsListType.
'};
3862 $("[name=\'type\'").change(function() {
3863 console.log("change name=type");
3864 if ($( this ).prop("checked"))
3866 if(($( this ).val() in listType))
3868 $("#model").val(listType[$( this ).val()]);
3885 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
3886 print $form->getSelectInvoiceSubtype(
GETPOST(
'subtype'),
'subtype', 1, 0,
'');
3892 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
3896 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
3897 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3906 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
3907 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3908 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
3913 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
3914 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3915 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
3920 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
3921 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
3922 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
3927 $rwStyle =
'display:none;';
3928 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
3932 $retained_warranty =
GETPOSTINT(
'retained_warranty');
3933 if (empty($retained_warranty)) {
3934 if (!empty($objectsrc->retained_warranty)) {
3935 $retained_warranty = $objectsrc->retained_warranty;
3938 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
3940 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
3941 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
3944 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
3945 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
3946 if (empty($retained_warranty_fk_cond_reglement)) {
3947 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
3948 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
3949 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
3951 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
3954 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
3957 print
'<script type="text/javascript">
3958 $(document).ready(function() {
3959 $("[name=\'type\']").change(function() {
3960 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
3962 $(".retained-warranty-line").show();
3963 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
3966 $(".retained-warranty-line").hide();
3967 $("#new-situation-invoice-retained-warranty").val("");
3971 $("[name=\'type\']:checked").trigger("change");
3977 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
3978 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
3979 print $form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
3983 if (isModEnabled(
"bank")) {
3984 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td colspan="2">';
3985 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
3986 print $form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
3991 if (isModEnabled(
'project')) {
3992 $langs->load(
'projects');
3993 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
3994 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
3995 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>';
4000 if (isModEnabled(
'incoterm')) {
4002 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
4003 print
'<td colspan="2" class="maxwidthonsmartphone">';
4004 $incoterm_id =
GETPOST(
'incoterm_id');
4005 $location_incoterms =
GETPOST(
'location_incoterms');
4006 if (empty($incoterm_id)) {
4007 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
4008 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
4010 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
4011 print $form->select_incoterms($incoterm_id, $location_incoterms);
4016 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
4017 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
4018 print $hookmanager->resPrint;
4019 if (empty($reshook)) {
4020 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
4023 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
4024 if ($soc->fetch_optionals() > 0) {
4025 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
4029 print
$object->showOptionals($extrafields,
'create', $parameters);
4033 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
4034 print
'<td colspan="2">';
4035 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
4036 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
4040 $paramkey =
'FACTURE_ADDON_PDF_'.$object->type;
4045 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
4049 if (isModEnabled(
'multicurrency')) {
4051 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0).
'</td>';
4052 print
'<td colspan="2" class="maxwidthonsmartphone">';
4053 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
4054 print $form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth100 widthcentpercentminusx');
4061 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
4062 if (empty($dateexample)) {
4065 $substitutionarray = array(
4066 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
4067 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
4068 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
4069 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
4070 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
4071 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
4072 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
4073 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
4074 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
4075 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
4076 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
4079 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
4080 foreach ($substitutionarray as $key => $val) {
4081 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
4083 $htmltext .=
'</i>';
4088 print
'<td class="tdtop">';
4089 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
4091 print
'<td valign="top" colspan="2">';
4092 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
4093 print $doleditor->Create(1);
4096 if (empty($user->socid)) {
4098 print
'<td class="tdtop">';
4099 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4101 print
'<td valign="top" colspan="2">';
4102 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4103 print $doleditor->Create(1);
4109 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4110 $langs->loadLangs(array(
'orders',
'propal'));
4113 if ($origin ==
'contrat') {
4115 $objectsrc->update_price(1,
'auto', 1);
4118 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4119 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4120 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4121 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4126 switch (get_class($objectsrc)) {
4128 $newclassname =
'CommercialProposal';
4131 $newclassname =
'Order';
4134 $newclassname =
'Sending';
4137 $newclassname =
'Contract';
4140 $newclassname =
'Intervention';
4143 $newclassname = get_class($objectsrc);
4147 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4148 print
'<td colspan="2">';
4149 print $objectsrc->getNomUrl(1);
4151 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
4152 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4154 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4157 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht).
'</td></tr>';
4158 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva).
"</td></tr>";
4159 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4160 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax1).
"</td></tr>";
4163 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4164 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax2).
"</td></tr>";
4166 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc).
"</td></tr>";
4168 if (isModEnabled(
'multicurrency')) {
4169 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
4170 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
4171 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
4179 print $form->buttonsSaveCancel(
"CreateDraft");
4182 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4185 $title = $langs->trans(
'ProductsAndServices');
4188 print
'<div class="div-table-responsive-no-min">';
4189 print
'<table class="noborder centpercent">';
4191 $objectsrc->printOriginLinesList(
'', $selectedLines);
4198} elseif ($id > 0 || !empty($ref)) {
4200 $langs->load(
'errors');
4201 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4210 $result =
$object->fetch($id, $ref);
4217 $extrafields->fetch_name_optionals_label(
$object->table_element);
4219 if ($user->socid > 0 && $user->socid !=
$object->socid) {
4223 $result =
$object->fetch_thirdparty();
4225 $result = $soc->fetch(
$object->socid);
4229 $selleruserevenustamp = $mysoc->useRevenueStamp();
4231 $totalpaid =
$object->getSommePaiement();
4232 $totalcreditnotes =
$object->getSumCreditNotesUsed();
4233 $totaldeposits =
$object->getSumDepositsUsed();
4239 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4242 if (isModEnabled(
'multicurrency')) {
4243 $multicurrency_totalpaid =
$object->getSommePaiement(1);
4244 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
4245 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
4246 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4250 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code != $conf->currency) {
4251 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
4258 $resteapayeraffiche = $resteapayer;
4261 $filterabsolutediscount =
"fk_facture_source IS NULL";
4262 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4264 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4265 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4268 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
4269 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
4270 $absolute_discount =
price2num($absolute_discount,
'MT');
4271 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4273 $author =
new User($db);
4274 if (
$object->user_creation_id) {
4275 $author->fetch(
$object->user_creation_id);
4278 $objectidnext =
$object->getIdReplacingInvoice();
4282 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
'bill');
4287 if ($action ==
'converttoreduc') {
4289 $type_fac =
'ExcessReceived';
4291 $type_fac =
'CreditNote';
4293 $type_fac =
'Deposit';
4295 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4296 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4297 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4301 if ($action ==
'delete') {
4302 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
4303 $formquestion = array();
4306 $qualified_for_stock_change = 0;
4308 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4310 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4313 if ($qualified_for_stock_change) {
4314 $langs->load(
"stocks");
4315 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4319 if ($conf->browser->name ==
'ie') {
4322 $formquestion = array(
4326 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4328 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4330 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4333 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4338 if ($action ==
'situationout') {
4339 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
4340 $label = $langs->trans(
"ConfirmOuting");
4341 $formquestion = array();
4346 &&
$object->is_last_in_cycle()
4347 && $usercanunvalidate
4349 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4354 if ($action ==
'valid') {
4356 $objectref = substr(
$object->ref, 1, 4);
4357 if ($objectref ==
'PROV') {
4361 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
4363 $numref =
$object->getNextNumRef($soc);
4369 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4370 if (isModEnabled(
'notification')) {
4371 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4372 $notify =
new Notify($db);
4374 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid,
$object);
4376 $formquestion = array();
4379 $qualified_for_stock_change = 0;
4381 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4383 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4386 if ($qualified_for_stock_change) {
4387 $langs->load(
"stocks");
4388 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4389 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4392 $warehouse_array = $warehouse->list_array();
4393 if (count($warehouse_array) == 1) {
4394 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4395 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4398 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4400 $formquestion = array(
4406 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4410 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
4415 foreach (
$object->lines as $line) {
4416 $res = $line->fetch_product();
4418 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
4424 if ($nbMandated > 0) {
4426 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
4429 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
4434 $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, 240);
4439 if ($action ==
'modif') {
4440 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
4441 $formquestion = array();
4444 $qualified_for_stock_change = 0;
4446 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4448 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4451 if ($qualified_for_stock_change) {
4452 $langs->load(
"stocks");
4453 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4454 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4457 $warehouse_array = $warehouse->list_array();
4458 if (count($warehouse_array) == 1) {
4459 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
4460 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4463 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4465 $formquestion = array(
4471 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4475 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
4479 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
4480 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
4482 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
4486 $close[$i][
'code'] =
'discount_vat';
4488 $close[$i][
'code'] =
'badcustomer';
4490 $close[$i][
'code'] =
'bankcharge';
4492 $close[$i][
'code'] =
'withholdingtax';
4494 $close[$i][
'code'] =
'other';
4498 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
4500 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4502 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
4504 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
4506 $close[$i][
'label'] = $langs->trans(
"Other");
4510 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4512 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4514 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4516 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
4518 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
4522 foreach ($close as $key => $val) {
4523 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
4527 $formquestion = array(
'text' => $langs->trans(
"ConfirmClassifyPaidPartiallyQuestion"), 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'));
4529 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 380, 600);
4533 if ($action ==
'canceled') {
4536 if ($objectidnext) {
4537 $facturereplacement =
new Facture($db);
4538 $facturereplacement->fetch($objectidnext);
4539 $statusreplacement = $facturereplacement->status;
4541 if ($objectidnext && $statusreplacement == 0) {
4542 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
4545 $close[1][
'code'] =
'badcustomer';
4546 $close[2][
'code'] =
'abandon';
4548 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4549 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
4551 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
4552 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
4555 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
4556 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
4559 $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'));
4561 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 270);
4565 if ($action ==
'deletepayment') {
4566 $payment_id =
GETPOST(
'paiement_id');
4567 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
4571 if ($action ==
'ask_deleteline') {
4572 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
4576 if ($action ==
'clone') {
4577 $filter =
'(s.client:IN:1,2,3)';
4579 $formquestion = array(
4580 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
$object->socid,
'socid', $filter, 1)),
4581 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
4584 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
4587 if ($action ==
"remove_file_comfirm") {
4588 $file =
GETPOST(
'file',
'alpha');
4590 $formconfirm = $form->formconfirm(
4591 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
4592 $langs->trans(
'DeleteFileHeader'),
4593 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
4602 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
4603 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
4604 if (empty($reshook)) {
4605 $formconfirm .= $hookmanager->resPrint;
4606 } elseif ($reshook > 0) {
4607 $formconfirm = $hookmanager->resPrint;
4615 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
4617 $morehtmlref =
'<div class="refidno">';
4620 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref',
$object->ref,
$object, $usercancreate,
'string',
'', 0, 1);
4621 $morehtmlref .= $form->editfieldval(
"Ref",
'ref',
$object->ref,
$object, $usercancreate,
'string',
'',
null,
null,
'', 1);
4622 $morehtmlref .=
'<br>';
4625 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer,
$object, $usercancreate,
'string',
'', 0, 1);
4626 $morehtmlref .= $form->editfieldval(
"RefCustomer",
'ref_client',
$object->ref_customer,
$object, $usercancreate,
'string'.(getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') ?
':' .
getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') :
''),
'', null, null,
'', 1);
4628 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
4630 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'&search_societe='.urlencode(
$object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
4633 if (isModEnabled(
'project')) {
4634 $langs->load(
"projects");
4635 $morehtmlref .=
'<br>';
4636 if ($usercancreate) {
4637 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
4638 if ($action !=
'classify') {
4639 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
4641 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->socid,
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
4643 if (!empty(
$object->fk_project)) {
4645 $proj->fetch(
$object->fk_project);
4646 $morehtmlref .= $proj->getNomUrl(1);
4648 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
4653 $morehtmlref .=
'</div>';
4655 $object->totalpaid = $totalpaid;
4657 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
4660 $parameters = array();
4662 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters,
$object, $action);
4663 if (empty($reshook)) {
4664 print
'<div class="fichecenter">';
4665 print
'<div class="fichehalfleft">';
4666 print
'<div class="underbanner clearboth"></div>';
4668 print
'<table class="border centpercent tableforfield">';
4671 print
'<tr><td class="titlefield fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
4674 print
' '.$object->getSubtypeLabel(
'facture');
4680 $facreplaced =
new Facture($db);
4681 $facreplaced->fetch(
$object->fk_facture_source);
4682 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
4686 $facusing->fetch(
$object->fk_facture_source);
4687 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
4690 $facidavoir =
$object->getListIdAvoirFromInvoice();
4691 if (count($facidavoir) > 0) {
4692 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
4694 foreach ($facidavoir as $id) {
4701 $facavoir->fetch($id);
4702 print $facavoir->getNomUrl(1,
'', 32);
4706 if ($objectidnext > 0) {
4707 $facthatreplace =
new Facture($db);
4708 $facthatreplace->fetch($objectidnext);
4709 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
4714 $result = $discount->fetch(0,
$object->id);
4716 print
' <span class="opacitymediumbycolor paddingleft">';
4717 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
4718 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
4719 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
4721 print
'</span><br>';
4725 if (
$object->fk_fac_rec_source > 0) {
4727 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
4729 print
' <span class="opacitymediumbycolor paddingleft">';
4730 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
4731 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
4739 print
'<!-- Discounts -->'.
"\n";
4740 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
4744 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
4745 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
4750 print
'<table class="nobordernopadding centpercent"><tr><td>';
4751 print $langs->trans(
'DateInvoice');
4753 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
4754 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>';
4756 print
'</tr></table>';
4759 if ($action ==
'editinvoicedate') {
4760 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
4762 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
4771 print
'<table class="nobordernopadding centpercent"><tr><td>';
4772 print $langs->trans(
'DatePointOfTax');
4774 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>';
4775 print
'</tr></table>';
4777 if ($action ==
'editdate_pointoftax') {
4778 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
4780 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
4787 print
'<table class="nobordernopadding centpercent"><tr><td>';
4788 print $langs->trans(
'PaymentConditionsShort');
4791 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>';
4793 print
'</tr></table>';
4796 if ($action ==
'editconditions') {
4797 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->cond_reglement_id,
'cond_reglement_id');
4799 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->cond_reglement_id,
'none');
4808 print
'<table class="nobordernopadding centpercent"><tr><td>';
4809 print $langs->trans(
'DateMaxPayment');
4812 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>';
4814 print
'</tr></table>';
4817 if ($action ==
'editpaymentterm') {
4818 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
4820 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
4832 print
'<table class="nobordernopadding centpercent"><tr><td>';
4833 print $langs->trans(
'PaymentMode');
4835 if ($action !=
'editmode' && $usercancreate) {
4836 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>';
4838 print
'</tr></table>';
4840 if ($action ==
'editmode') {
4841 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
4843 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->mode_reglement_id,
'none',
'CRDT');
4848 if (isModEnabled(
'multicurrency')) {
4852 print
'<table class="nobordernopadding centpercent"><tr><td>';
4853 print $form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0);
4855 if ($usercancreate && $action !=
'editmulticurrencycode' &&
$object->status == $object::STATUS_DRAFT) {
4856 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencycode&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
4858 print
'</tr></table>';
4860 $htmlname = (($usercancreate && $action ==
'editmulticurrencycode') ?
'multicurrency_code' :
'none');
4861 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_code, $htmlname);
4865 if (
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
4868 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4869 print $form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'',
$object, 0);
4871 if ($usercancreate && $action !=
'editmulticurrencyrate' &&
$object->status == $object::STATUS_DRAFT &&
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency) {
4872 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencyrate&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
4874 print
'</tr></table>';
4876 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
4877 if ($action ==
'actualizemulticurrencyrate') {
4880 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_tx, ($usercancreate ?
'multicurrency_tx' :
'none'),
$object->multicurrency_code);
4882 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_tx,
'none',
$object->multicurrency_code);
4883 if (
$object->status == $object::STATUS_DRAFT &&
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency) {
4884 print
'<div class="inline-block"> ';
4885 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
4894 if (isModEnabled(
"bank")) {
4895 print
'<tr><td class="nowrap">';
4896 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
4897 print $langs->trans(
'BankAccount');
4899 if (($action !=
'editbankaccount') && $usercancreate) {
4900 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>';
4902 print
'</tr></table>';
4904 if ($action ==
'editbankaccount') {
4905 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'fk_account', 1);
4907 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'none');
4914 if (isModEnabled(
'incoterm')) {
4916 print
'<table class="nobordernopadding centpercent"><tr><td>';
4917 print $langs->trans(
'IncotermLabel');
4918 print
'<td><td class="right">';
4919 if ($usercancreate) {
4920 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
4924 print
'</td></tr></table>';
4927 if ($action !=
'editincoterm') {
4928 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
4930 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
4938 $displayWarranty =
true;
4939 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
4940 $displayWarranty =
false;
4943 if ($displayWarranty) {
4945 print
'<tr class="retained-warranty-lines" ><td>';
4946 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
4947 print $langs->trans(
'RetainedWarranty');
4950 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>';
4953 print
'</tr></table>';
4956 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
4957 print
'<input type="hidden" name="action" value="setretainedwarranty">';
4958 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4959 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4960 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
4961 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
4969 print
'<tr class="retained-warranty-lines" ><td>';
4970 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
4971 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
4973 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
4974 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>';
4977 print
'</tr></table>';
4979 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
4980 if (
$object->date > $defaultDate) {
4986 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
4987 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
4988 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4989 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4990 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
4991 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
4992 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4993 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4994 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4997 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->retained_warranty_fk_cond_reglement,
'none');
4998 if (!$displayWarranty) {
4999 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning.png',
'class="pictowarning valignmiddle" ');
5005 print
'<tr class="retained-warranty-lines" ><td>';
5006 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
5007 print $langs->trans(
'RetainedWarrantyDateLimit');
5010 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>';
5013 print
'</tr></table>';
5015 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5016 if (
$object->date > $defaultDate) {
5022 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5023 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
5024 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5025 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5026 print
'<input name="retained_warranty_date_limit" type="date" step="1" min="'.dol_print_date(
$object->date,
'%Y-%m-%d').
'" value="'.
dol_print_date($defaultDate,
'%Y-%m-%d').
'" >';
5027 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5039 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
5044 print
'<div class="fichehalfright">';
5046 print
'<!-- amounts -->'.
"\n";
5047 print
'<div class="underbanner clearboth"></div>'.
"\n";
5049 print
'<table class="border tableforfield centpercent">';
5057 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
5058 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5059 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
5061 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5067 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountVAT') .
'</td>';
5068 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5069 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
5071 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5076 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
5078 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
5079 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5080 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
5083 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5088 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
5090 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
5091 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5092 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
5095 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5101 if ($selleruserevenustamp) {
5102 print
'<tr><td class="titlefieldmiddle">';
5103 print
'<table class="nobordernopadding centpercent"><tr><td>';
5104 print $langs->trans(
'RevenueStamp');
5106 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
5107 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>';
5109 print
'</tr></table>';
5110 print
'</td><td class="nowrap amountcard right">';
5111 if ($action ==
'editrevenuestamp') {
5112 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
5113 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5114 print
'<input type="hidden" name="action" value="setrevenuestamp">';
5115 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
5116 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5117 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
5118 print
' → <span id="revenuestamp_span"></span>';
5119 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
5122 $(document).ready(function(){
5123 js_recalculate_revenuestamp();
5124 $('select[name=revenuestamp_type]').on('change',function(){
5125 js_recalculate_revenuestamp();
5128 function js_recalculate_revenuestamp(){
5129 var valselected = $('select[name=revenuestamp_type]').val();
5130 console.log('Calculate revenue stamp from '+valselected);
5132 if (valselected.indexOf('%') == -1)
5134 revenue = valselected;
5138 var revenue_type = parseFloat(valselected);
5139 var amount_net = ".round(
$object->total_ht, 2).
";
5140 revenue = revenue_type * amount_net / 100;
5141 revenue = revenue.toFixed(2);
5143 $('#revenuestamp_val').val(revenue);
5144 $('#revenuestamp_span').html(revenue);
5148 print
price(
$object->revenuestamp, 1,
'', 1, -1, -1, $conf->currency);
5155 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
5156 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5157 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
5159 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5167 if (isModEnabled(
'project')) {
5170 if (isModEnabled(
"bank")) {
5174 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
5177 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
5180 if ($selleruserevenustamp) {
5183 if (isModEnabled(
'multicurrency')) {
5186 if (isModEnabled(
'incoterm')) {
5192 print
'<!-- List of situation invoices -->';
5193 print
'<table class="noborder situationstable" width="100%">';
5195 print
'<tr class="liste_titre">';
5196 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
5198 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
5199 if (isModEnabled(
"bank")) {
5200 print
'<td class="right"></td>';
5202 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
5203 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
5204 print
'<td width="18"> </td>';
5207 $total_prev_ht = $total_prev_ttc = 0;
5208 $total_global_ht = $total_global_ttc = 0;
5210 if (count(
$object->tab_previous_situation_invoice) > 0) {
5213 $current_situation_counter = array();
5214 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
5215 $tmptotalpaidforthisinvoice = $prev_invoice->getSommePaiement();
5216 $total_prev_ht += $prev_invoice->total_ht;
5217 $total_prev_ttc += $prev_invoice->total_ttc;
5218 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
5219 print
'<tr class="oddeven">';
5220 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
5222 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
5223 if (isModEnabled(
"bank")) {
5224 print
'<td class="right"></td>';
5226 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
5227 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
5228 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).
'</td>';
5234 $total_global_ht += $total_prev_ht;
5235 $total_global_ttc += $total_prev_ttc;
5236 $total_global_ht +=
$object->total_ht;
5237 $total_global_ttc +=
$object->total_ttc;
5239 print
'<tr class="oddeven">';
5240 print
'<td>'.$object->getNomUrl(1).
'</td>';
5242 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
5243 if (isModEnabled(
"bank")) {
5244 print
'<td class="right"></td>';
5246 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
5247 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
5248 print
'<td class="right">'.$object->getLibStatut(3,
$object->getSommePaiement()).
'</td>';
5252 print
'<tr class="oddeven">';
5253 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'CurrentSituationTotal').
'</b></td>';
5256 foreach ($current_situation_counter as $sit) {
5257 $curSign = $sit > 0 ?
'+' :
'-';
5258 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
5260 print
' '.$curSign.
' ';
5262 print $curType.abs($sit);
5266 if (isModEnabled(
"bank")) {
5269 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5270 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5271 print
'<td width="18"> </td>';
5275 if (count(
$object->tab_next_situation_invoice) > 0) {
5287 $total_next_ht = $total_next_ttc = 0;
5289 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
5290 $totalpaid = $next_invoice->getSommePaiement();
5291 $total_next_ht += $next_invoice->total_ht;
5292 $total_next_ttc += $next_invoice->total_ttc;
5294 print
'<tr class="oddeven">';
5295 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
5297 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
5298 if (isModEnabled(
"bank")) {
5299 print
'<td class="right"></td>';
5301 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
5302 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
5303 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid).
'</td>';
5307 $total_global_ht += $total_next_ht;
5308 $total_global_ttc += $total_next_ttc;
5310 print
'<tr class="oddeven">';
5311 print
'<td colspan="3" class="right"></td>';
5312 if (isModEnabled(
"bank")) {
5313 print
'<td class="right"></td>';
5315 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5316 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5317 print
'<td width="18"> </td>';
5325 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
5331 print
'<!-- List of payments already done -->';
5332 print
'<div class="div-table-responsive-no-min">';
5333 print
'<table class="noborder paymenttable centpercent">';
5335 print
'<tr class="liste_titre">';
5336 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
5337 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
5338 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
5339 if (isModEnabled(
"bank")) {
5340 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
5342 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
5343 print
'<td class="liste_titre" width="18"> </td>';
5347 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
5348 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
5349 $sql .=
' pf.amount,';
5350 $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';
5351 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
5352 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
5353 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
5354 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
5355 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
5356 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
5357 $sql .=
' ORDER BY p.datep, p.tms';
5359 $result = $db->query($sql);
5361 $num = $db->num_rows($result);
5366 $objp = $db->fetch_object($result);
5368 $paymentstatic->id = $objp->rowid;
5369 $paymentstatic->datepaye = $db->jdate($objp->dp);
5370 $paymentstatic->ref = $objp->ref;
5371 $paymentstatic->num_payment = $objp->num_payment;
5372 $paymentstatic->paiementcode = $objp->payment_code;
5374 print
'<tr class="oddeven"><td class="nowraponall">';
5375 print $paymentstatic->getNomUrl(1);
5378 $dateofpayment = $db->jdate($objp->dp);
5380 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
5387 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
5388 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
5389 if (isModEnabled(
"bank")) {
5390 $bankaccountstatic->id = $objp->baid;
5391 $bankaccountstatic->ref = $objp->baref;
5392 $bankaccountstatic->label = $objp->baref;
5393 $bankaccountstatic->number = $objp->banumber;
5394 $bankaccountstatic->currency_code = $objp->bacurrency_code;
5396 if (isModEnabled(
'accounting')) {
5397 $bankaccountstatic->account_number = $objp->account_number;
5400 $accountingjournal->fetch($objp->fk_accountancy_journal);
5401 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
5404 print
'<td class="nowraponall">';
5405 if ($bankaccountstatic->id) {
5406 print $bankaccountstatic->getNomUrl(1,
'transactions');
5410 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
5411 print
'<td class="center">';
5414 $paiement->fetch($objp->rowid);
5416 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
5433 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5434 print
'<span class="opacitymedium">';
5436 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
5438 print $langs->trans(
'AlreadyPaid');
5440 print
'</span></td><td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td><td> </td></tr>';
5442 $resteapayeraffiche = $resteapayer;
5443 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
5446 $creditnoteamount = 0;
5448 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
5449 $sql .=
" re.description, re.fk_facture_source";
5450 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
5451 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
5452 $resql = $db->query($sql);
5454 $num = $db->num_rows($resql);
5458 $obj = $db->fetch_object($resql);
5459 $invoice->fetch($obj->fk_facture_source);
5460 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5461 print
'<span class="opacitymedium">';
5463 print $langs->trans(
"CreditNote").
' ';
5466 print $langs->trans(
"Deposit").
' ';
5468 print $invoice->getNomUrl(0);
5471 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
5472 print
'<td class="right">';
5473 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
5474 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
5479 $creditnoteamount += $obj->amount_ttc;
5482 $depositamount += $obj->amount_ttc;
5491 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5492 print
'<span class="opacitymedium">';
5493 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
5495 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5496 $resteapayeraffiche = 0;
5497 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5501 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5502 print
'<span class="opacitymedium">';
5503 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
5505 print
'</td><td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td><td> </td></tr>';
5507 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5511 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5512 print
'<span class="opacitymedium">';
5513 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
5515 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5516 $resteapayeraffiche = 0;
5517 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5521 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5522 $text = $langs->trans(
"HelpAbandonOther");
5524 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
5526 print
'<span class="opacitymedium">';
5528 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
5530 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5531 $resteapayeraffiche = 0;
5532 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5536 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5537 print
'<span class="opacitymedium">';
5538 print $langs->trans(
"Billed");
5539 print
'</td><td class="right">'.price(
$object->total_ttc).
'</td><td> </td></tr>';
5541 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5542 print
'<span class="opacitymedium">';
5543 print $langs->trans(
'RemainderToPay');
5544 if ($resteapayeraffiche < 0) {
5545 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5549 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
5552 if (
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
5553 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5554 print
'<span class="opacitymedium">';
5555 print $langs->trans(
'RemainderToPayMulticurrency');
5556 if ($resteapayeraffiche < 0) {
5557 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5561 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">';
5563 print
price(
price2num(
$object->multicurrency_tx * $resteapayeraffiche,
'MT'), 1, $langs, 1, -1, -1, (empty(
$object->multicurrency_code) ? $conf->currency :
$object->multicurrency_code)).
'</td><td> </td></tr>';
5567 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
5570 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
5573 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
5576 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
5578 print
'<tr><td colspan="'.$nbcols.
'" align="right">'.$langs->trans(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')).
' :</td><td align="right">'.
price($billedWithRetainedWarranty).
'</td><td> </td></tr>';
5581 print
'<tr><td colspan="'.$nbcols.
'" align="right">';
5582 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
5583 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
5584 print
' :</td><td align="right">'.price($retainedWarranty).
'</td><td> </td></tr>';
5587 $resteapayeraffiche = $resteapayer;
5588 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5591 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5592 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
5593 print
'</td><td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td><td> </td></tr>';
5596 print
'<tr><td colspan="'.$nbcols.
'" class="right"><span class="opacitymedium">'.$langs->trans(
"Billed").
'</span></td><td class="right">'.
price($sign *
$object->total_ttc).
'</td><td> </td></tr>';
5599 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5600 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
5601 if ($resteapayeraffiche > 0) {
5602 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5604 print
'</span></td>';
5605 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
5606 print
'<td class="nowrap"> </td></tr>';
5609 if (
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
5610 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5611 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
5612 if ($resteapayeraffiche > 0) {
5613 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5617 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.(!empty(
$object->multicurrency_code) ?
$object->multicurrency_code : $conf->currency).
' '.
price(
price2num($sign *
$object->multicurrency_tx * $resteapayeraffiche,
'MT')).
'</td><td> </td></tr>';
5630 if (isModEnabled(
'margin')) {
5631 $formmargin->displayMarginInfos(
$object);
5637 print
'<div class="clearboth"></div><br><br>';
5640 $blocname =
'contacts';
5641 $title = $langs->trans(
'ContactsAddresses');
5642 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5646 $blocname =
'notes';
5647 $title = $langs->trans(
'Notes');
5648 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5652 $result =
$object->getLinesArray();
5656 global $inputalsopricewithtax;
5657 $inputalsopricewithtax = 1;
5662 print
'<!-- Area to change globally the situation percent -->'.
"\n";
5663 print
'<div class="div-table-responsive">';
5665 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'#updatealllines" method="POST">';
5666 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
5667 print
'<input type="hidden" name="action" value="updatealllines" />';
5668 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
5669 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5671 print
'<table id="tablelines_all_progress" class="noborder noshadow" width="100%">';
5673 print
'<tr class="liste_titre nodrag nodrop">';
5677 print
'<td align="center" width="5"> </td>';
5679 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
5680 print
'<td class="right">'.$langs->trans(
'Progress').
'</td>';
5681 print
'<td> </td>';
5684 print
'<tr class="nodrag nodrop">';
5687 print
'<td align="center" width="5"> </td>';
5689 print
'<td> </td>';
5690 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
5691 print
'<td class="right"><input type="submit" class="button" name="all_percent" value="Modifier" /></td>';
5702 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
5703 <input type="hidden" name="token" value="' .
newToken().
'">
5704 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
5705 <input type="hidden" name="mode" value="">
5706 <input type="hidden" name="page_y" value="">
5707 <input type="hidden" name="id" value="' .
$object->id.
'">
5708 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
5711 if (!empty($conf->use_javascript_ajax) &&
$object->status == 0) {
5712 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
5715 print
'<div class="div-table-responsive-no-min">';
5716 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
5720 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
5724 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
5725 if ($action !=
'editline' && $action !=
'selectlines') {
5728 $parameters = array();
5729 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
5733 if (empty($reshook)) {
5734 $object->formAddObjectLine(1, $mysoc, $soc);
5737 $parameters = array();
5738 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters,
$object, $action);
5752 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
5753 print
'<div class="tabsAction">';
5755 $parameters = array();
5756 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
5757 if (empty($reshook)) {
5760 'class' =>
'classfortooltip',
5767 $ventilExportCompta =
$object->getVentilExportCompta();
5769 if ($ventilExportCompta == 0) {
5771 if (!$objectidnext &&
$object->is_last_in_cycle()) {
5772 if ($usercanunvalidate) {
5773 unset($params[
'attr'][
'title']);
5774 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=modif&token='.
newToken(),
'',
true, $params);
5776 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
5777 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=modif&token='.
newToken(),
'',
false, $params);
5779 } elseif (!
$object->is_last_in_cycle()) {
5780 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
5781 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5783 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
5784 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5788 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5789 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5794 $result = $discount->fetch(0,
$object->id);
5802 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
5803 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
5804 unset($params[
'attr'][
'title']);
5805 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
5807 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
5808 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
5815 $langs->load(
"contracts");
5817 if ($usercancreatecontract) {
5818 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>';
5825 if ($usercanvalidate) {
5826 unset($params[
'attr'][
'title']);
5827 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
5832 if (empty($user->socid)) {
5834 if ($objectidnext) {
5835 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'SendMail').
'</span>';
5838 unset($params[
'attr'][
'title']);
5839 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
5841 unset($params[
'attr'][
'title']);
5842 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
5850 if ($resteapayer > 0) {
5851 if ($usercancreatewithdrarequest) {
5852 if (!$objectidnext &&
$object->close_code !=
'replaced') {
5853 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>';
5855 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
5866 if (isModEnabled(
'takepos') &&
$object->module_source ==
'takepos') {
5867 $langs->load(
"cashdesk");
5868 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
5869 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
5874 if ($objectidnext) {
5875 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
5879 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
5880 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
5884 unset($params[
'attr'][
'title']);
5885 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);
5890 $sumofpayment = $totalpaid;
5891 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
5897 if ($resteapayer == 0) {
5898 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
5900 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
5906 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
5910 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
5912 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>';
5919 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
5921 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
5935 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
5936 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
5938 unset($params[
'attr'][
'title']);
5939 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken(),
'',
true, $params);
5945 if ($totalpaid > 0 || $totalcreditnotes > 0) {
5947 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
5950 if ($objectidnext) {
5951 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
5953 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
5961 if (!$objectidnext) {
5962 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>';
5969 && (
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
5972 &&
$object->is_last_in_cycle()
5975 if ($usercanunvalidate) {
5976 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>';
5978 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
5984 unset($params[
'attr'][
'title']);
5985 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice&token='.
newToken(),
'',
true, $params);
5990 if (!$objectidnext && count(
$object->lines) > 0) {
5991 unset($params[
'attr'][
'title']);
5992 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
6001 &&
$object->situation_counter > 1
6002 &&
$object->is_last_in_cycle()
6003 && $usercanunvalidate
6005 if ((
$object->total_ttc - $totalcreditnotes) == 0) {
6006 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6008 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6014 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
6015 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6016 } elseif (!
$object->is_last_in_cycle()) {
6017 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6019 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6024 $isErasable =
$object->is_erasable();
6026 if ($isErasable == -4) {
6027 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
6028 } elseif ($isErasable == -3) {
6029 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
6030 } elseif ($isErasable == -2) {
6031 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
6032 } elseif ($isErasable == -1) {
6033 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6034 } elseif ($isErasable <= 0) {
6035 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable');
6036 } elseif ($objectidnext) {
6037 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
6039 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
6040 $enableDelete =
false;
6042 if ($isErasable > 0 && ! $objectidnext) {
6043 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
6044 $enableDelete =
true;
6046 unset($params[
'attr'][
'title']);
6047 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
6049 unset($params[
'attr'][
'title']);
6050 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
6057 if (
GETPOST(
'modelselected',
'alpha')) {
6058 $action =
'presend';
6060 if ($action !=
'prerelance' && $action !=
'presend') {
6061 print
'<div class="fichecenter"><div class="fichehalfleft">';
6062 print
'<a name="builddoc"></a>';
6067 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
6068 $genallowed = $usercanread;
6069 $delallowed = $usercancreate;
6071 print $formfile->showdocuments(
6091 'remove_file_comfirm'
6094 $somethingshown = $formfile->numoffiles;
6097 $linktoelem = $form->showLinkToObjectBlock(
$object, array(), array(
'invoice'));
6099 $compatibleImportElementsList =
false;
6103 $compatibleImportElementsList = array(
'commande',
'propal');
6105 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem, $compatibleImportElementsList);
6109 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6110 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
6111 $useonlinepayment = count($validpaymentmethod);
6114 print
'<br><!-- Link to pay -->'.
"\n";
6115 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6116 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
6119 print
'</div><div class="fichehalfright">';
6123 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
6126 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
6128 $somethingshown = $formactions->showactions(
$object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
6130 print
'</div></div>';
6135 $modelmail =
'facture_send';
6136 $defaulttopic =
'SendBillRef';
6137 $diroutput = $conf->invoice->multidir_output[
$object->entity];
6138 $trackid =
'inv'.$object->id;
6140 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
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 shipments.
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.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
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 Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $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.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid