43 require
'../../main.inc.php';
44 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
46 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
49 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
51 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
52 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
53 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
54 require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
55 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
56 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
58 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
61 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
62 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
64 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
67 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
70 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
74 $langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
76 $langs->load(
'incoterm');
79 $langs->load(
'margins');
86 $action =
GETPOST(
'action',
'aZ09');
87 $confirm =
GETPOST(
'confirm',
'alpha');
88 $cancel =
GETPOST(
'cancel',
'alpha');
89 $backtopage =
GETPOST(
'backtopage',
'alpha');
92 $search_ref =
GETPOST(
'sf_ref',
'alpha') ?
GETPOST(
'sf_ref',
'alpha') :
GETPOST(
'search_ref',
'alpha');
93 $search_societe =
GETPOST(
'search_societe',
'alpha');
94 $search_montant_ht =
GETPOST(
'search_montant_ht',
'alpha');
95 $search_montant_ttc =
GETPOST(
'search_montant_ttc',
'alpha');
96 $origin =
GETPOST(
'origin',
'alpha');
103 $selectedLines =
GETPOST(
'toselect',
'array');
119 $extrafields->fetch_name_optionals_label(
$object->table_element);
122 if ($id > 0 || !empty($ref)) {
123 if ($action !=
'add') {
125 $fetch_situation =
false;
127 $fetch_situation =
true;
129 $ret =
$object->fetch($id, $ref,
'', 0, $fetch_situation);
130 if ($ret > 0 && isset(
$object->fk_project)) {
131 $ret =
$object->fetch_project();
137 $hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
140 $usercanread = $user->hasRight(
"facture",
"lire");
141 $usercancreate = $user->hasRight(
"facture",
"creer");
142 $usercanissuepayment = $user->hasRight(
"facture",
"paiement");
143 $usercandelete = $user->hasRight(
"facture",
"supprimer") || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
144 $usercancreatecontract = $user->hasRight(
"contrat",
"creer");
147 $usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'validate')));
149 $usercanreopen = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'reopen')));
151 $usercanreopen =
false;
153 $usercanunvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'unvalidate')));
155 $usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
156 $usercancreatemargin = $user->hasRight(
'margins',
'creer');
157 $usercanreadallmargin = $user->hasRight(
'margins',
'liretous');
158 $usercancreatewithdrarequest = $user->hasRight(
'prelevement',
'bons',
'creer');
160 $permissionnote = $usercancreate;
161 $permissiondellink = $usercancreate;
162 $permissiontoedit = $usercancreate;
163 $permissiontoadd = $usercancreate;
166 $retainedWarrantyInvoiceAvailableType = array();
168 $retainedWarrantyInvoiceAvailableType = explode(
'+',
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY'));
173 $socid = $user->socid;
190 if (empty($reshook)) {
191 $backurlforlist = DOL_URL_ROOT.
'/compta/facture/list.php';
193 if (empty($backtopage) || ($cancel && empty($id))) {
194 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
195 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
196 $backtopage = $backurlforlist;
198 $backtopage = DOL_URL_ROOT.
'/compta/facture/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
204 if (!empty($backtopageforcancel)) {
205 header(
"Location: ".$backtopageforcancel);
207 } elseif (!empty($backtopage)) {
208 header(
"Location: ".$backtopage);
214 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
216 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
218 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
221 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
223 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'IdThirdParty')),
null,
'errors');
226 '@phan-var-force Facture $objectutil';
229 $objectutil->socid = $socid;
230 $result = $objectutil->createFromClone($user, $id);
232 $warningMsgLineList = array();
234 foreach ($objectutil->lines as $line) {
235 if (!is_object($line->product)) {
236 $line->fetch_product();
238 if (is_object($line->product) && $line->product->id > 0) {
239 if (empty($line->product->status)) {
240 $warningMsgLineList[$line->id] = $langs->trans(
'WarningLineProductNotToSell', $line->product->ref);
244 if (!empty($warningMsgLineList)) {
248 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?facid=' . $result);
251 $langs->load(
"errors");
256 } elseif ($action ==
'reopen' && $usercanreopen) {
260 $result =
$object->setUnpaid($user);
262 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
268 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
273 $idwarehouse =
GETPOST(
'idwarehouse');
275 $qualified_for_stock_change = 0;
277 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
279 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
282 $isErasable =
$object->is_erasable();
284 if (($usercandelete && $isErasable > 0)
285 || ($usercancreate && $isErasable == 1)) {
286 $result =
$object->delete($user, 0, $idwarehouse);
288 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
295 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
305 $outputlangs = $langs;
311 $newlang =
$object->thirdparty->default_lang;
313 if (!empty($newlang)) {
315 $outputlangs->setDefaultLang($newlang);
316 $outputlangs->load(
'products');
320 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
323 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
330 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
333 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
334 $discount->unlink_invoice();
335 } elseif ($action ==
'valid' && $usercancreate) {
339 if ((preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) &&
346 $last_of_type =
$object->willBeLastOfSameType(
true);
347 if (empty(
$object->date_validation) && !$last_of_type[0]) {
357 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
366 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
375 $array_of_total_ht_per_vat_rate = array();
376 $array_of_total_ht_devise_per_vat_rate = array();
377 foreach (
$object->lines as $line) {
379 $vat_src_code_for_line =
'';
380 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
381 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
383 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
384 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
386 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
387 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
391 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
392 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
393 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
395 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
396 if (
$object->type == $object::TYPE_DEPOSIT) {
397 $langs->load(
"errors");
399 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
403 $tmpvatratetoshow = explode(
'_', $vatrate);
404 $tmpvatratetoshow[0] = round((
float) $tmpvatratetoshow[0], 2);
406 if ($tmpvatratetoshow[0] != 0) {
407 $langs->load(
"errors");
408 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", $tmpvatratetoshow[0]),
null,
'errors');
416 } elseif ($action ==
'classin' && $usercancreate) {
419 } elseif ($action ==
'setmode' && $usercancreate) {
425 } elseif ($action ==
'setretainedwarrantyconditions' && $user->hasRight(
'facture',
'creer')) {
427 $object->retained_warranty_fk_cond_reglement = 0;
428 $result =
$object->setRetainedWarrantyPaymentTerms(
GETPOSTINT(
'retained_warranty_fk_cond_reglement'));
433 $old_rw_date_lim_reglement =
$object->retained_warranty_date_limit;
434 $new_rw_date_lim_reglement =
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
435 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
436 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
441 $result =
$object->update($user);
445 } elseif ($action ==
'setretainedwarranty' && $user->hasRight(
'facture',
'creer')) {
451 } elseif ($action ==
'setretainedwarrantydatelimit' && $user->hasRight(
'facture',
'creer')) {
453 $result =
$object->setRetainedWarrantyDateLimit(
GETPOSTFLOAT(
'retained_warranty_date_limit'));
457 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
458 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
459 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
461 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
463 $old_date_lim_reglement =
$object->date_lim_reglement;
465 if (empty($newdate)) {
466 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
467 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id.
'&action=editinvoicedate&token='.
newToken());
472 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
474 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
479 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
480 if ($new_date_lim_reglement) {
481 $object->date_lim_reglement = $new_date_lim_reglement;
486 $result =
$object->update($user);
489 $action =
'editinvoicedate';
491 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
496 $object->date_pointoftax = $date_pointoftax;
497 $result =
$object->update($user);
501 } elseif ($action ==
'setconditions' && $usercancreate) {
503 $object->cond_reglement_code = 0;
504 $object->cond_reglement_id = 0;
519 $old_date_lim_reglement =
$object->date_lim_reglement;
520 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
521 if ($new_date_lim_reglement) {
522 $object->date_lim_reglement = $new_date_lim_reglement;
527 $result =
$object->update($user);
539 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
543 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
544 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
546 $result =
$object->update($user);
550 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
553 $result =
$object->update($user);
560 $outputlangs = $langs;
563 $newlang =
GETPOST(
'lang_id',
'aZ09');
566 $newlang =
$object->thirdparty->default_lang;
568 if (!empty($newlang)) {
570 $outputlangs->setDefaultLang($newlang);
571 $outputlangs->load(
'products');
576 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
582 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm')) {
584 } elseif ($action ==
'setbankaccount' && $usercancreate) {
586 } elseif ($action ==
'setremisepercent' && $usercancreate) {
589 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
607 if (
GETPOSTINT(
"remise_id_for_payment") > 0) {
608 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
610 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
614 $remaintopay =
$object->getRemainToPay(0);
618 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
622 $result = $discount->link_to_invoice(0, $id);
630 $newremaintopay =
$object->getRemainToPay(0);
631 if ($newremaintopay == 0) {
644 $outputlangs = $langs;
647 $newlang =
GETPOST(
'lang_id',
'aZ09');
651 $newlang =
$object->thirdparty->default_lang;
653 if (!empty($newlang)) {
655 $outputlangs->setDefaultLang($newlang);
659 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
664 } elseif ($action ==
'setref' && $usercancreate) {
666 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', 0,
'',
'', $user,
'BILL_MODIFY');
667 } elseif ($action ==
'setref_client' && $usercancreate) {
670 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
679 $qualified_for_stock_change = 0;
681 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
683 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
686 if ($qualified_for_stock_change) {
687 if (!$idwarehouse || $idwarehouse == - 1) {
689 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
696 $result =
$object->validate($user,
'', $idwarehouse);
700 $outputlangs = $langs;
703 $newlang =
GETPOST(
'lang_id',
'aZ09');
706 $newlang =
$object->thirdparty->default_lang;
708 if (!empty($newlang)) {
710 $outputlangs->setDefaultLang($newlang);
711 $outputlangs->load(
'products');
717 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
730 } elseif ($action ==
'confirm_modif' && $usercanunvalidate) {
739 $qualified_for_stock_change = 0;
741 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
743 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
746 if ($qualified_for_stock_change) {
747 if (!$idwarehouse || $idwarehouse == - 1) {
749 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
758 $sql =
'SELECT pf.amount';
759 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf';
760 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
762 $result = $db->query(
$sql);
765 $num = $db->num_rows($result);
768 $objp = $db->fetch_object($result);
769 $totalpaid += $objp->amount;
776 $resteapayer =
$object->total_ttc - $totalpaid;
779 $ventilExportCompta =
$object->getVentilExportCompta();
782 if ($ventilExportCompta == 0) {
784 $result =
$object->setDraft($user, $idwarehouse);
791 $outputlangs = $langs;
794 $newlang =
GETPOST(
'lang_id',
'aZ09');
797 $newlang =
$object->thirdparty->default_lang;
799 if (!empty($newlang)) {
801 $outputlangs->setDefaultLang($newlang);
802 $outputlangs->load(
'products');
807 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
812 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
815 $result =
$object->setPaid($user);
819 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
822 $close_code =
GETPOST(
"close_code",
'restricthtml');
823 $close_note =
GETPOST(
"close_note",
'restricthtml');
825 $result =
$object->setPaid($user, $close_code, $close_note);
830 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
832 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes') {
835 $close_code =
GETPOST(
"close_code",
'restricthtml');
836 $close_note =
GETPOST(
"close_note",
'restricthtml');
838 $result =
$object->setCanceled($user, $close_code, $close_note);
843 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
845 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
853 $result = $discountcheck->fetch(0,
$object->id);
866 $amount_ht = $amount_tva = $amount_ttc = array();
867 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
871 foreach (
$object->lines as $line) {
872 if ($line->product_type < 9 && $line->total_ht != 0) {
873 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
875 $amount_ht[$keyforvatrate] += $line->total_ht;
876 $amount_tva[$keyforvatrate] += $line->total_tva;
877 $amount_ttc[$keyforvatrate] += $line->total_ttc;
878 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
879 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
880 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
884 '@phan-var-force array<string,float> $amount_ht
885 @phan-var-force array<string,float> $amount_tva
886 @phan-var-force array<string,float> $amount_ttc
887 @phan-var-force array<string,float> $multicurrency_amount_ht
888 @phan-var-force array<string,float> $multicurrency_amount_tva
889 @phan-var-force array<string,float> $multicurrency_amount_ttc';
893 $alreadypaid =
$object->getSommePaiement();
894 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
895 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
896 foreach ($amount_ht as $vatrate => $val) {
897 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
898 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
899 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
900 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
901 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
902 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
911 $discount->description =
'(CREDIT_NOTE)';
913 $discount->description =
'(DEPOSIT)';
915 $discount->description =
'(EXCESS RECEIVED)';
917 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
919 $discount->fk_soc =
$object->socid;
920 $discount->socid =
$object->socid;
921 $discount->fk_facture_source =
$object->id;
929 $sql =
'SELECT SUM(pf.amount) as total_paiements';
930 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
931 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
932 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
933 $sql .=
' AND pf.fk_paiement = p.rowid';
934 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
935 $resql = $db->query(
$sql);
940 $res = $db->fetch_object($resql);
941 $total_paiements = $res->total_paiements;
944 $total_creditnote_and_deposit = 0;
945 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
946 $sql .=
" re.description, re.fk_facture_source";
947 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
948 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
949 $resql = $db->query(
$sql);
950 if (!empty($resql)) {
951 while ($obj = $db->fetch_object($resql)) {
952 $total_creditnote_and_deposit += $obj->amount_ttc;
958 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
959 $discount->amount_tva = 0;
960 $discount->tva_tx = 0;
961 $discount->vat_src_code =
'';
963 $result = $discount->create($user);
969 foreach ($amount_ht as $tva_tx => $xxx) {
970 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
971 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
972 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
973 $discount->multicurrency_amount_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
974 $discount->multicurrency_amount_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
975 $discount->multicurrency_amount_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
980 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
981 $vat_src_code = $reg[1];
982 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
985 $discount->tva_tx = abs((
float) $tva_tx);
986 $discount->vat_src_code = $vat_src_code;
988 $result = $discount->create($user);
999 $result =
$object->setPaid($user);
1014 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
1019 $result = $paiement->fetch(
GETPOSTINT(
'paiement_id'));
1021 $result = $paiement->delete($user);
1023 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1031 } elseif ($action ==
'add' && $usercancreate) {
1038 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1044 $originentity =
GETPOST(
'originentity');
1046 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
1056 if (empty($dateinvoice)) {
1058 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1068 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1078 $object->date_pointoftax = $date_pointoftax;
1079 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1080 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1091 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1092 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1099 $id =
$object->createFromCurrent($user);
1109 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1111 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1115 if (empty($dateinvoice)) {
1117 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1127 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1132 if (!empty($originentity)) {
1133 $object->entity = $originentity;
1139 $object->date_pointoftax = $date_pointoftax;
1140 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1141 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1146 $object->cond_reglement_id = 0;
1152 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1153 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1157 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1160 $facture_source =
new Facture($db);
1161 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1163 $object->situation_counter = $facture_source->situation_counter;
1164 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1165 $facture_source->fetchPreviousNextSituationInvoice();
1175 if (
$object->copy_linked_contact($facture_source,
'internal') < 0) {
1177 } elseif ($facture_source->socid ==
$object->socid) {
1179 if (
$object->copy_linked_contact($facture_source,
'external') < 0) {
1190 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1191 if (!empty($facture_source->lines)) {
1192 $fk_parent_line = 0;
1194 foreach ($facture_source->lines as $line) {
1196 if (method_exists($line,
'fetch_optionals')) {
1198 $line->fetch_optionals();
1202 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1203 $fk_parent_line = 0;
1208 $source_fk_prev_id = $line->fk_prev_id;
1209 $line->fk_prev_id = $line->id;
1211 if (!empty($facture_source->tab_previous_situation_invoice)) {
1214 $tab_jumped_credit_notes = array();
1215 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1216 $searchPreviousInvoice =
true;
1217 while ($searchPreviousInvoice) {
1218 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1219 $searchPreviousInvoice =
false;
1223 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1229 $maxPrevSituationPercent = 0;
1230 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1231 if ($prevLine->id == $source_fk_prev_id) {
1232 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1235 $line->total_ht -= $prevLine->total_ht;
1236 $line->total_tva -= $prevLine->total_tva;
1237 $line->total_ttc -= $prevLine->total_ttc;
1238 $line->total_localtax1 -= $prevLine->total_localtax1;
1239 $line->total_localtax2 -= $prevLine->total_localtax2;
1241 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1242 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1243 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1244 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1249 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1254 $maxPrevSituationPercent = 0;
1255 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1256 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1257 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1258 $maxPrevSituationPercent = $prevLine->situation_percent;
1260 $line->total_ht -= $prevLine->total_ht;
1261 $line->total_tva -= $prevLine->total_tva;
1262 $line->total_ttc -= $prevLine->total_ttc;
1263 $line->total_localtax1 -= $prevLine->total_localtax1;
1264 $line->total_localtax2 -= $prevLine->total_localtax2;
1266 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1267 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1268 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1269 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1275 $line->situation_percent += $maxPrevSituationPercent;
1281 $line->fk_facture =
$object->id;
1282 $line->fk_parent_line = $fk_parent_line;
1284 $line->subprice = -$line->subprice;
1286 $line->total_ht = -$line->total_ht;
1287 $line->total_tva = -$line->total_tva;
1288 $line->total_ttc = -$line->total_ttc;
1289 $line->total_localtax1 = -$line->total_localtax1;
1290 $line->total_localtax2 = -$line->total_localtax2;
1292 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1293 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1294 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1295 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1297 $line->context[
'createcreditnotefrominvoice'] = 1;
1298 $result = $line->insert(0, 1);
1303 if ($result > 0 && $line->product_type == 9) {
1304 $fk_parent_line = $result;
1312 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1313 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1314 $totalpaid = $facture_source->getSommePaiement();
1315 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1316 $totaldeposits = $facture_source->getSumDepositsUsed();
1317 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1319 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1320 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1323 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1328 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1334 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC');
1339 if (!empty(
$object->fk_facture_source) && $id > 0) {
1340 $facture_source->fetch(
$object->fk_facture_source);
1341 $facture_source->fetchObjectLinked();
1343 if (!empty($facture_source->linkedObjectsIds)) {
1344 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1345 $object->add_object_linked($sourcetype, current($TIds));
1354 if (empty($dateinvoice)) {
1356 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1367 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1377 $object->date_pointoftax = $date_pointoftax;
1378 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1379 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1391 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1392 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1404 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1405 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1406 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1410 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1414 if (empty($dateinvoice)) {
1416 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1426 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1427 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1432 if ($typeamount && !empty($origin) && !empty($originid)) {
1433 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1434 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1438 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1439 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1443 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1444 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1454 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1464 $object->date_pointoftax = $date_pointoftax;
1465 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1466 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1478 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1479 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1483 $object->situation_counter = 1;
1488 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1490 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1492 $object->retained_warranty = 0;
1493 $object->retained_warranty_fk_cond_reglement = 0;
1496 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1497 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1500 $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);
1505 if (!empty($origin) && !empty($originid)) {
1508 $element = $subelement = $origin;
1509 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1510 $element = $regs[1];
1511 $subelement = $regs[2];
1515 if ($element ==
'order') {
1516 $element = $subelement =
'commande';
1518 if ($element ==
'propal') {
1519 $element =
'comm/propal';
1520 $subelement =
'propal';
1522 if ($element ==
'contract') {
1523 $element = $subelement =
'contrat';
1525 if ($element ==
'inter') {
1526 $element = $subelement =
'ficheinter';
1528 if ($element ==
'shipping') {
1529 $element = $subelement =
'expedition';
1533 $object->origin_id = $originid;
1538 if (
$object->origin ==
'shipping') {
1539 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1541 $exp->fetch(
$object->origin_id);
1542 $exp->fetchObjectLinked();
1543 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1544 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1545 $object->linked_objects[
'commande'] = $value;
1551 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
1559 $classname = ucfirst($subelement);
1560 $srcobject =
new $classname($db);
1561 '@phan-var-force CommonObject $srcobject';
1563 dol_syslog(
"Try to find source object origin=".
$object->origin.
" originid=".
$object->origin_id.
" to add lines or deposit lines");
1564 $result = $srcobject->fetch(
$object->origin_id);
1569 $amountdeposit = array();
1571 if ($typeamount ==
'amount') {
1572 $amount = (
float) $valuedeposit;
1574 $amount = $srcobject->total_ttc * ((
float) $valuedeposit / 100);
1577 $TTotalByTva = array();
1578 foreach ($srcobject->lines as &$line) {
1579 if (!empty($line->special_code)) {
1582 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1584 '@phan-var-force array<string,float> $TTotalByTva';
1586 $amount_ttc_diff = 0.;
1587 foreach ($TTotalByTva as $tva => &$total) {
1588 $coef = $total / $srcobject->total_ttc;
1589 $am = $amount * $coef;
1590 $amount_ttc_diff += $am;
1591 $amountdeposit[$tva] += $am / (1 + (
float) $tva / 100);
1594 if ($typeamount ==
'amount') {
1595 $amountdeposit[0] = $valuedeposit;
1596 } elseif ($typeamount ==
'variable') {
1599 $lines = $srcobject->lines;
1600 $numlines = count($lines);
1601 for ($i = 0; $i < $numlines; $i++) {
1603 if (empty($lines[$i]->qty)) {
1606 if (!empty($lines[$i]->special_code)) {
1610 $totalamount += $lines[$i]->total_ht;
1611 $tva_tx = $lines[$i]->tva_tx;
1612 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (
float) $valuedeposit) / 100;
1616 if ($totalamount == 0) {
1617 $amountdeposit[0] = 0;
1625 $amount_ttc_diff = $amountdeposit[0];
1628 foreach ($amountdeposit as $tva => $amount) {
1629 if (empty($amount)) {
1634 'amount' =>
'FixAmount',
1635 'variable' =>
'VarAmount'
1637 $descline =
'(DEPOSIT)';
1639 if ($typeamount ==
'amount') {
1640 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code : $conf->currency)).
')';
1641 } elseif ($typeamount ==
'variable') {
1642 $descline .=
' ('.$valuedeposit.
'%)';
1645 $descline .=
' - '.$srcobject->ref;
1658 $lines[$i]->info_bits,
1664 $lines[$i]->special_code,
1677 (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) ? 0 : 1)
1681 $diff =
$object->total_ttc - $amount_ttc_diff;
1685 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1686 $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);
1693 $lines = $srcobject->lines;
1694 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1695 $srcobject->fetch_lines();
1696 $lines = $srcobject->lines;
1701 if (is_array($lines)) {
1702 foreach ($lines as $line) {
1704 $line->qty =
price2num((
float) $line->qty * (
float) $valuestandardinvoice / 100,
'MS');
1710 if (is_array($lines)) {
1711 foreach ($lines as $line) {
1713 $line->qty =
price2num((
float) $line->qty * (
float) $valuedeposit / 100,
'MS');
1718 $fk_parent_line = 0;
1719 $num = count($lines);
1721 for ($i = 0; $i < $num; $i++) {
1722 if (!in_array($lines[$i]->
id, $selectedLines)) {
1727 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
1731 if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1732 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1734 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
1738 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1739 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1741 if (
$object->situation_counter == 1) {
1742 $lines[$i]->situation_percent = 0;
1745 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
1748 $desc = $label ? $label : $langs->trans(
'Discount');
1752 $discount->fk_soc =
$object->socid;
1753 $discount->socid =
$object->socid;
1754 $discount->amount_ht = abs($lines[$i]->total_ht);
1755 $discount->amount_tva = abs($lines[$i]->total_tva);
1756 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1757 $discount->tva_tx = $lines[$i]->tva_tx;
1758 $discount->fk_user = $user->id;
1759 $discount->description = $desc;
1760 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1761 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1762 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1763 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1765 $discountid = $discount->create($user);
1766 if ($discountid > 0) {
1767 $result =
$object->insert_discount($discountid);
1779 $date_start =
false;
1780 if (isset($lines[$i]->date_debut_prevue)) {
1781 $date_start = $lines[$i]->date_debut_prevue;
1783 if (isset($lines[$i]->date_debut_reel)) {
1784 $date_start = $lines[$i]->date_debut_reel;
1786 if (isset($lines[$i]->date_start)) {
1787 $date_start = $lines[$i]->date_start;
1792 if (isset($lines[$i]->date_fin_prevue)) {
1793 $date_end = $lines[$i]->date_fin_prevue;
1795 if (isset($lines[$i]->date_fin_reel)) {
1796 $date_end = $lines[$i]->date_fin_reel;
1798 if (isset($lines[$i]->date_end)) {
1799 $date_end = $lines[$i]->date_end;
1803 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1804 $fk_parent_line = 0;
1808 if (method_exists($lines[$i],
'fetch_optionals')) {
1809 $lines[$i]->fetch_optionals();
1810 $array_options = $lines[$i]->array_options;
1813 $tva_tx = $lines[$i]->tva_tx;
1814 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
1815 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1825 $lines[$i]->subprice,
1830 $lines[$i]->fk_product,
1831 $lines[$i]->remise_percent,
1835 $lines[$i]->info_bits,
1836 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except :
null,
1841 $lines[$i]->special_code,
1845 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice :
null,
1849 $lines[$i]->situation_percent ?? 100,
1850 $lines[$i]->fk_prev_id ?? 0,
1851 $lines[$i]->fk_unit,
1866 if ($result > 0 && $lines[$i]->product_type == 9) {
1867 $fk_parent_line = $result;
1877 $object->update_price(1,
'auto', 0, $mysoc);
1919 for ($i = 1; $i <= $NBLINES; $i++) {
1925 $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);
1929 $object->update_price(1,
'auto', 0, $mysoc);
1936 if (empty($dateinvoice)) {
1938 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
1948 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
1958 if (!empty($origin) && !empty($originid)) {
1959 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1962 $object->origin_id = $originid;
1966 $retained_warranty =
GETPOSTINT(
'retained_warranty');
1967 if (
price2num($retained_warranty) > 0) {
1971 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
1972 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1975 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1976 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
1977 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
1979 $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);
1982 foreach (
$object->lines as $i => &$line) {
1983 $line->origin =
$object->origin;
1984 $line->origin_id = $line->id;
1985 $line->fk_prev_id = $line->id;
1986 $line->fetch_optionals();
1987 $line->situation_percent = $line->get_prev_progress(
$object->id);
1990 $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);
1991 $line->total_ht = $tabprice[0];
1992 $line->total_tva = $tabprice[1];
1993 $line->total_ttc = $tabprice[2];
1994 $line->total_localtax1 = $tabprice[9];
1995 $line->total_localtax2 = $tabprice[10];
1996 $line->multicurrency_total_ht = $tabprice[16];
1997 $line->multicurrency_total_tva = $tabprice[17];
1998 $line->multicurrency_total_ttc = $tabprice[18];
2001 if ($line->fk_remise_except) {
2003 $result = $discount->fetch($line->fk_remise_except);
2006 if ($discount->fk_facture_line > 0) {
2007 $line->fk_remise_except = 0;
2016 $object->date_pointoftax = $date_pointoftax;
2017 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2032 $object->situation_counter += 1;
2033 $id =
$object->createFromCurrent($user);
2037 $nextSituationInvoice =
new Facture($db);
2038 $nextSituationInvoice->fetch($id);
2041 $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
2042 $ret = $extrafields->setOptionalsFromPost(
null, $nextSituationInvoice);
2044 $nextSituationInvoice->insertExtraFields();
2051 if ($id > 0 && !$error) {
2056 $outputlangs = $langs;
2059 $newlang =
GETPOST(
'lang_id',
'aZ09');
2062 $newlang =
$object->thirdparty->default_lang;
2064 if (!empty($newlang)) {
2065 $outputlangs =
new Translate(
"", $conf);
2066 $outputlangs->setDefaultLang($newlang);
2067 $outputlangs->load(
'products');
2072 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2078 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2083 $_GET[
"origin"] = $_POST[
"origin"];
2084 $_GET[
"originid"] = $_POST[
"originid"];
2087 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2091 foreach (
$object->lines as $line) {
2092 if ($line->product_type == 1) {
2093 $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);
2096 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2098 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2099 $vat_rate = str_replace(
'*',
'', $vat_rate);
2102 foreach (
$object->lines as $line) {
2103 $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);
2105 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2107 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2108 $remise_percent = str_replace(
'*',
'', $remise_percent);
2109 foreach (
$object->lines as $line) {
2110 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $remise_percent, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx,
'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice);
2112 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && $usercancreate) {
2113 $langs->load(
'errors');
2121 $price_ht_devise =
'';
2123 $price_ttc_devise =
'';
2125 $price_min_ttc =
'';
2127 if (
GETPOST(
'price_ht') !==
'') {
2130 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2133 if (
GETPOST(
'price_ttc') !==
'') {
2136 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2137 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2140 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2141 if ($prod_entry_mode ==
'free') {
2147 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2152 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2156 if (empty($remise_percent)) {
2157 $remise_percent = 0;
2161 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2162 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2164 if (is_array($extralabelsline)) {
2166 foreach ($extralabelsline as $key => $value) {
2167 unset($_POST[
"options_".$key.$predef]);
2171 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2172 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2175 if (!$prod_entry_mode) {
2177 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2181 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2182 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2185 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) {
2186 if (($price_ht < 0 || $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2187 $langs->load(
"errors");
2188 if (
$object->type == $object::TYPE_DEPOSIT) {
2190 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2192 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2196 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2201 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2204 if ($prod_entry_mode ==
'free' && empty($idprod) && empty($product_desc)) {
2205 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2209 $langs->load(
"errors");
2210 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2214 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2215 if ($combinations =
GETPOST(
'combinations',
'array')) {
2219 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2220 $idprod = $res->fk_product_child;
2222 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2228 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
2234 $ret =
$object->fetch_thirdparty();
2239 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2250 if (!empty($idprod) && $idprod > 0) {
2252 $prod->fetch($idprod);
2254 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2259 $datapriceofproduct = $prod->getSellPrice($mysoc,
$object->thirdparty, $pqp);
2261 $pu_ht = $datapriceofproduct[
'pu_ht'];
2262 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2263 $price_min = $datapriceofproduct[
'price_min'];
2264 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] :
null;
2265 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2269 $tmpvat = (
float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2270 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $prod->tva_tx));
2274 if (!empty($price_ht) || $price_ht ===
'0') {
2276 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2277 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2278 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2281 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2283 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2284 } elseif ($tmpvat != $tmpprodvat) {
2286 if ($price_base_type !=
'HT') {
2287 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2289 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2297 $outputlangs = $langs;
2299 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
2300 $newlang =
GETPOST(
'lang_id',
'aZ09');
2302 if (empty($newlang)) {
2303 $newlang =
$object->thirdparty->default_lang;
2305 if (!empty($newlang)) {
2306 $outputlangs =
new Translate(
"", $conf);
2307 $outputlangs->setDefaultLang($newlang);
2308 $outputlangs->load(
'products');
2311 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->description;
2313 $desc = $prod->description;
2322 $desc = $product_desc;
2328 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
2332 $outputlangs = $langs;
2334 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
2335 $newlang =
GETPOST(
'lang_id',
'alpha');
2337 if (empty($newlang)) {
2338 $newlang =
$object->thirdparty->default_lang;
2340 if (!empty($newlang)) {
2341 $outputlangs =
new Translate(
"", $conf);
2342 $outputlangs->setDefaultLang($newlang);
2343 $outputlangs->load(
'products');
2345 if (!empty($prod->customcode)) {
2346 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2348 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2351 if (!empty($prod->country_code)) {
2352 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
2355 if (!empty($prod->customcode)) {
2356 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2358 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2361 if (!empty($prod->country_code)) {
2362 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
2369 $type = $prod->type;
2370 $fk_unit = $prod->fk_unit;
2372 if (!empty($price_ht)) {
2377 if (!empty($price_ttc)) {
2382 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2383 $tva_tx = str_replace(
'*',
'', $tva_tx);
2384 if (empty($tva_tx)) {
2387 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2388 $desc = $product_desc;
2390 $fk_unit =
GETPOST(
'units',
'alpha');
2392 if ($pu_ttc && !$pu_ht) {
2393 $price_base_type =
'TTC';
2407 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2408 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2411 $pu_equivalent = $pu_ht;
2412 $pu_equivalent_ttc = $pu_ttc;
2414 $currency_tx =
$object->multicurrency_tx;
2418 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2419 $pu_equivalent = (
float) $pu_ht_devise * $currency_tx;
2421 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2422 $pu_equivalent_ttc = (
float) $pu_ttc_devise * $currency_tx;
2442 $price2num_remise_percent =
price2num($remise_percent);
2443 $price2num_price_min =
price2num($price_min);
2444 $price2num_price_min_ttc =
price2num($price_min_ttc);
2445 if (empty($price2num_pu_ht)) {
2446 $price2num_pu_ht = 0;
2448 if (empty($price2num_remise_percent)) {
2449 $price2num_remise_percent = 0;
2451 if (empty($price2num_price_min)) {
2452 $price2num_price_min = 0;
2454 if (empty($price2num_price_min_ttc)) {
2455 $price2num_price_min_ttc = 0;
2460 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2461 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2464 } 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') {
2465 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2472 '@phan-var-force array<string,mixed> $lines';
2474 if (
isModEnabled(
'productbatch') && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) &&
getDolGlobalString(
'INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS')) {
2475 $langs->load(
'productbatch');
2476 foreach ($lines[$i]->detail_batch as $batchline) {
2477 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2482 $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);
2487 $outputlangs = $langs;
2490 $newlang =
GETPOST(
'lang_id',
'aZ09');
2493 $newlang =
$object->thirdparty->default_lang;
2495 if (!empty($newlang)) {
2496 $outputlangs =
new Translate(
"", $conf);
2497 $outputlangs->setDefaultLang($newlang);
2498 $outputlangs->load(
'products');
2503 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2509 unset($_POST[
'prod_entry_mode']);
2510 unset($_POST[
'qty']);
2511 unset($_POST[
'type']);
2512 unset($_POST[
'remise_percent']);
2513 unset($_POST[
'price_ht']);
2514 unset($_POST[
'multicurrency_price_ht']);
2515 unset($_POST[
'price_ttc']);
2516 unset($_POST[
'tva_tx']);
2517 unset($_POST[
'product_ref']);
2518 unset($_POST[
'product_label']);
2519 unset($_POST[
'product_desc']);
2520 unset($_POST[
'fournprice']);
2521 unset($_POST[
'buying_price']);
2522 unset($_POST[
'np_marginRate']);
2523 unset($_POST[
'np_markRate']);
2524 unset($_POST[
'dp_desc']);
2525 unset($_POST[
'idprod']);
2526 unset($_POST[
'units']);
2527 unset($_POST[
'date_starthour']);
2528 unset($_POST[
'date_startmin']);
2529 unset($_POST[
'date_startsec']);
2530 unset($_POST[
'date_startday']);
2531 unset($_POST[
'date_startmonth']);
2532 unset($_POST[
'date_startyear']);
2533 unset($_POST[
'date_endhour']);
2534 unset($_POST[
'date_endmin']);
2535 unset($_POST[
'date_endsec']);
2536 unset($_POST[
'date_endday']);
2537 unset($_POST[
'date_endmonth']);
2538 unset($_POST[
'date_endyear']);
2539 unset($_POST[
'situations']);
2540 unset($_POST[
'progress']);
2548 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2549 if (!
$object->fetch($id) > 0) {
2561 $vat_rate = str_replace(
'*',
'', $vat_rate);
2573 if (preg_match(
'/\*/', $vat_rate)) {
2578 $vat_rate = str_replace(
'*',
'', $vat_rate);
2587 $pu_equivalent = $pu_ht;
2588 $pu_equivalent_ttc = $pu_ttc;
2590 $currency_tx =
$object->multicurrency_tx;
2594 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2595 $pu_equivalent = (
float) $pu_ht_devise * (
float) $currency_tx;
2597 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2598 $pu_equivalent_ttc = (
float) $pu_ttc_devise * (
float) $currency_tx;
2613 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2614 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
2616 if (is_array($extralabelsline)) {
2618 foreach ($extralabelsline as $key => $value) {
2619 unset($_POST[
"options_".$key]);
2625 if ($special_code == 3) {
2631 $percent = $line->get_prev_progress(
$object->id);
2636 if ($progress >= 0) {
2637 $mesg = $langs->trans(
"CantBeNullOrPositive");
2641 } elseif ($progress < $line->situation_percent) {
2642 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
2646 } elseif ($progress < $percent) {
2647 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
2658 if (!empty($productid)) {
2660 $product->fetch($productid);
2662 $type = $product->type;
2664 $price_min = $product->price_min;
2666 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
2668 $price_min_ttc = $product->price_min_ttc;
2670 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
2677 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2678 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2681 $action =
'editline';
2682 } 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') {
2683 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2686 $action =
'editline';
2691 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2695 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
2700 $langs->load(
"errors");
2701 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2705 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2706 $langs->load(
"errors");
2707 if (
$object->type == $object::TYPE_DEPOSIT) {
2709 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2711 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2715 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2723 if (empty($usercancreatemargin)) {
2724 foreach (
$object->lines as &$line) {
2726 $fournprice = $line->fk_fournprice;
2727 $buyingprice = $line->pa_ht;
2733 $price_base_type =
'HT';
2735 if (empty($pu) && !empty($pu_ttc)) {
2737 $price_base_type =
'TTC';
2740 $result =
$object->updateline(
2769 $outputlangs = $langs;
2772 $newlang =
GETPOST(
'lang_id',
'aZ09');
2775 $newlang =
$object->thirdparty->default_lang;
2777 if (!empty($newlang)) {
2778 $outputlangs =
new Translate(
"", $conf);
2779 $outputlangs->setDefaultLang($newlang);
2780 $outputlangs->load(
'products');
2784 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2787 unset($_POST[
'qty']);
2788 unset($_POST[
'type']);
2789 unset($_POST[
'productid']);
2790 unset($_POST[
'remise_percent']);
2791 unset($_POST[
'price_ht']);
2792 unset($_POST[
'multicurrency_price_ht']);
2793 unset($_POST[
'price_ttc']);
2794 unset($_POST[
'tva_tx']);
2795 unset($_POST[
'product_ref']);
2796 unset($_POST[
'product_label']);
2797 unset($_POST[
'product_desc']);
2798 unset($_POST[
'fournprice']);
2799 unset($_POST[
'buying_price']);
2800 unset($_POST[
'np_marginRate']);
2801 unset($_POST[
'np_markRate']);
2802 unset($_POST[
'dp_desc']);
2803 unset($_POST[
'idprod']);
2804 unset($_POST[
'units']);
2805 unset($_POST[
'date_starthour']);
2806 unset($_POST[
'date_startmin']);
2807 unset($_POST[
'date_startsec']);
2808 unset($_POST[
'date_startday']);
2809 unset($_POST[
'date_startmonth']);
2810 unset($_POST[
'date_startyear']);
2811 unset($_POST[
'date_endhour']);
2812 unset($_POST[
'date_endmin']);
2813 unset($_POST[
'date_endsec']);
2814 unset($_POST[
'date_endday']);
2815 unset($_POST[
'date_endmonth']);
2816 unset($_POST[
'date_endyear']);
2817 unset($_POST[
'situations']);
2818 unset($_POST[
'progress']);
2823 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modifier')) {
2824 if (!
$object->fetch($id) > 0) {
2827 if (
GETPOST(
'all_progress') !=
"") {
2829 foreach (
$object->lines as $line) {
2830 $percent = $line->get_prev_progress(
$object->id);
2831 if ((
float) $all_progress < (
float) $percent) {
2832 $mesg = $langs->trans(
"Line").
' '.$i.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
2841 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
2842 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2844 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
2846 $object->fetch($id,
'',
'', 0,
true);
2852 &&
$object->is_last_in_cycle()
2853 && $usercanunvalidate
2856 $newCycle =
$object->newCycle();
2857 if ($newCycle > 1) {
2859 $lastCycle =
$object->situation_cycle_ref;
2860 $lastSituationCounter =
$object->situation_counter;
2861 $linkedCreditNotesList = array();
2863 if (count(
$object->tab_next_situation_invoice) > 0) {
2864 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
2866 && $next_invoice->situation_counter ==
$object->situation_counter
2867 && $next_invoice->fk_facture_source ==
$object->id
2869 $linkedCreditNotesList[] = $next_invoice->id;
2874 $object->situation_cycle_ref = $newCycle;
2875 $object->situation_counter = 1;
2877 if (
$object->update($user) > 0) {
2879 if (count($linkedCreditNotesList) > 0) {
2881 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
2882 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
2883 $sql .=
' , situation_final=0';
2884 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
2885 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
2887 $resql = $db->query(
$sql);
2893 foreach (
$object->lines as $line) {
2895 if ($line->product_type == 9) {
2900 if (!empty(
$object->tab_previous_situation_invoice)) {
2902 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
2903 $searchPreviousInvoice =
true;
2904 while ($searchPreviousInvoice) {
2906 $searchPreviousInvoice =
false;
2914 $maxPrevSituationPercent = 0;
2915 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
2916 if ($prevLine->id == $line->fk_prev_id) {
2917 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
2922 $line->situation_percent -= $maxPrevSituationPercent;
2924 if ($line->update() < 0) {
2933 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
2935 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
2938 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
2941 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
2944 } elseif ($action ==
'import_lines_from_object'
2949 $fromElement =
GETPOST(
'fromelement');
2950 $fromElementid =
GETPOST(
'fromelementid');
2951 $importLines =
GETPOST(
'line_checkbox');
2953 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
2954 if ($fromElement ==
'commande') {
2956 $lineClassName =
'OrderLine';
2957 } elseif ($fromElement ==
'propal') {
2958 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
2959 $lineClassName =
'PropaleLigne';
2961 $nextRang = count(
$object->lines) + 1;
2964 foreach ($importLines as $lineId) {
2965 $lineId = intval($lineId);
2966 $originLine =
new $lineClassName($db);
2967 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
2968 $originLine->fetch_optionals();
2969 $desc = $originLine->desc;
2970 $pu_ht = $originLine->subprice;
2971 $qty = $originLine->qty;
2972 $txtva = $originLine->tva_tx;
2973 $txlocaltax1 = $originLine->localtax1_tx;
2974 $txlocaltax2 = $originLine->localtax2_tx;
2975 $fk_product = $originLine->fk_product;
2976 $remise_percent = $originLine->remise_percent;
2977 $date_start = $originLine->date_start;
2978 $date_end = $originLine->date_end;
2979 $fk_code_ventilation = 0;
2980 $info_bits = $originLine->info_bits;
2981 $fk_remise_except = $originLine->fk_remise_except;
2982 $price_base_type =
'HT';
2984 $type = $originLine->product_type;
2985 $rang = $nextRang++;
2986 $special_code = $originLine->special_code;
2987 $origin = $originLine->element;
2988 $origin_id = $originLine->id;
2989 $fk_parent_line = 0;
2990 $fk_fournprice = $originLine->fk_fournprice;
2991 $pa_ht = $originLine->pa_ht;
2992 $label = $originLine->label;
2993 $array_options = $originLine->array_options;
2995 $situation_percent = 0;
2997 $situation_percent = 100;
3000 $fk_unit = $originLine->fk_unit;
3001 $pu_ht_devise = $originLine->multicurrency_subprice;
3003 $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);
3022 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3028 $triggersendname =
'BILL_SENTBYMAIL';
3030 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3031 $trackid =
'inv'.$object->id;
3032 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3035 $upload_dir = $conf->invoice->multidir_output[!empty(
$object->entity) ?
$object->entity : $conf->entity];
3036 $permissiontoadd = $usercancreate;
3037 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3040 if ($action ==
'update_extras') {
3044 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
GETPOST(
'attribute',
'restricthtml'));
3051 $result =
$object->insertExtraFields(
'BILL_MODIFY');
3059 $action =
'edit_extras';
3064 if ($action ==
'addcontact') {
3065 $result =
$object->fetch($id);
3067 if ($result > 0 && $id > 0) {
3070 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3074 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3077 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3078 $langs->load(
"errors");
3079 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3084 } elseif ($action ==
'swapstatut') {
3091 } elseif ($action ==
'deletecontact') {
3094 $result =
$object->delete_contact($lineid);
3097 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3105 $action =
'edit_extras';
3121 $paymentstatic =
new Paiement($db);
3122 $bankaccountstatic =
new Account($db);
3129 $title =
$object->ref.
" - ".$langs->trans(
'Card');
3130 if ($action ==
'create') {
3131 $title = $langs->trans(
"NewBill");
3133 $help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3139 if ($action ==
'create') {
3140 $facturestatic =
new Facture($db);
3141 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3146 $res = $soc->fetch($socid);
3149 $currency_code = $conf->currency;
3151 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3152 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3157 if (!empty($origin) && !empty($originid)) {
3159 $element = $subelement = $origin;
3161 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3162 $element = $regs[1];
3163 $subelement = $regs[2];
3166 if ($element ==
'project') {
3167 $projectid = $originid;
3169 if (empty($cond_reglement_id)) {
3170 $cond_reglement_id = $soc->cond_reglement_id;
3172 if (empty($mode_reglement_id)) {
3173 $mode_reglement_id = $soc->mode_reglement_id;
3175 if (empty($fk_account)) {
3176 $fk_account = $soc->fk_account;
3178 if (!$remise_percent) {
3179 $remise_percent = $soc->remise_percent;
3181 if (!$dateinvoice) {
3183 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3187 if ($element ==
'order' || $element ==
'commande') {
3188 $element = $subelement =
'commande';
3190 if ($element ==
'propal') {
3191 $element =
'comm/propal';
3192 $subelement =
'propal';
3194 if ($element ==
'contract') {
3195 $element = $subelement =
'contrat';
3197 if ($element ==
'shipping') {
3198 $element = $subelement =
'expedition';
3203 $classname = ucfirst($subelement);
3204 $objectsrc =
new $classname($db);
3205 $objectsrc->fetch($originid);
3206 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3207 $objectsrc->fetch_lines();
3209 $objectsrc->fetch_thirdparty();
3211 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3212 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3215 if (empty($socid)) {
3216 $soc = $objectsrc->thirdparty;
3219 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3221 if ($element ==
'expedition') {
3222 $ref_client = (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
'');
3224 $elem = $subelem = $objectsrc->origin;
3225 $expeoriginid = $objectsrc->origin_id;
3227 $classname = ucfirst($subelem);
3229 $expesrc =
new $classname($db);
3230 $expesrc->fetch($expeoriginid);
3232 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3233 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3234 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3239 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3240 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3244 $expesrc->fetch_optionals();
3245 $object->array_options = $expesrc->array_options;
3247 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
3248 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3249 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3254 if (!empty($objectsrc->multicurrency_code)) {
3255 $currency_code = $objectsrc->multicurrency_code;
3257 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
3258 $currency_tx = $objectsrc->multicurrency_tx;
3263 $objectsrc->fetch_optionals();
3264 $object->array_options = $objectsrc->array_options;
3268 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
3269 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
3270 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
3273 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3275 if (
isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3276 $currency_code = $soc->multicurrency_code;
3281 if (!
GETPOST(
'changecompany')) {
3283 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3286 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3294 if (empty($cond_reglement_id)) {
3295 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
3299 if (empty($mode_reglement_id)) {
3300 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
3310 if (!empty($soc->id)) {
3311 $absolute_discount = $soc->getAvailableDiscounts();
3313 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public :
null));
3314 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private :
null));
3316 if (!empty($conf->use_javascript_ajax)) {
3317 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3323 if ($origin ==
'contrat') {
3324 $langs->load(
"admin");
3325 $text = $langs->trans(
"ToCreateARecurringInvoice");
3326 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3328 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3330 print
info_admin($text, 0, 0, 0,
'opacitymedium').
'<br>';
3333 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3334 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3335 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3336 print
'<input type="hidden" name="changecompany" value="0">';
3338 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3340 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3341 print
'<input name="ref" type="hidden" value="provisoire">';
3342 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3343 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3344 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3345 print
'<input name="force_fk_account" type="hidden" value="0">';
3346 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3347 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3348 print
'<input type="hidden" name="originentity" value="'.GETPOST(
'originentity').
'">';
3349 if (!empty($currency_tx)) {
3350 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3358 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice',
$parameters,
$object, $action);
3359 if (empty($reshook)) {
3360 print
'<table class="border centpercent">';
3365 $exampletemplateinvoice =
new FactureRec($db);
3367 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3368 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
3372 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
3374 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3375 print
'<td colspan="2">';
3376 print $soc->getNomUrl(1,
'customer');
3377 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3379 $arrayoutstandingbills = $soc->getOutstandingBills();
3380 $outstandingBills = $arrayoutstandingbills[
'opened'];
3381 print
' - <span class="opacitymedium">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3382 print
'<span class="amount">'.price($outstandingBills, 0, $langs, 0, 0, -1, $conf->currency).
'</span>';
3383 if ($soc->outstanding_limit !=
'') {
3384 if ($outstandingBills > $soc->outstanding_limit) {
3385 print
img_warning($langs->trans(
"OutstandingBillReached"));
3387 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1, $conf->currency);
3392 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3393 print
'<td colspan="2">';
3394 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
3395 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3399 $(document).ready(function() {
3400 $("#socid").change(function() {
3402 console.log("Submit page");
3403 $(\'input[name="action"]\').val(\'create\');
3404 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3405 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3406 $(\'input[name="force_fk_account"]\').val(\'1\');
3407 $("#formtocreate").submit(); */
3409 // For company change, we must submit page with action=create instead of action=add
3410 console.log("We have changed the company - Resubmit page");
3411 jQuery("input[name=changecompany]").val("1");
3412 jQuery("#formtocreateaction").val("create");
3413 jQuery("#formtocreate").submit();
3419 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>';
3426 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3427 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
3429 $dateinvoice = $invoice_predefined->date_when;
3430 if (empty($projectid)) {
3431 $projectid = $invoice_predefined->fk_project;
3433 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
3434 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
3435 $fk_account = $invoice_predefined->fk_account;
3436 $note_public = $invoice_predefined->note_public;
3437 $note_private = $invoice_predefined->note_private;
3439 if (!empty($invoice_predefined->multicurrency_code)) {
3440 $currency_code = $invoice_predefined->multicurrency_code;
3442 if (!empty($invoice_predefined->multicurrency_tx)) {
3443 $currency_tx = $invoice_predefined->multicurrency_tx;
3446 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
3447 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
3448 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
3450 $resql = $db->query(
$sql);
3452 $num = $db->num_rows($resql);
3456 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
3458 print
'<select class="flat" id="fac_rec" name="fac_rec">';
3459 print
'<option value="0" selected></option>';
3461 $objp = $db->fetch_object($resql);
3462 print
'<option value="'.$objp->rowid.
'"';
3465 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
3467 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
3476 print
'<script type="text/javascript">
3477 $(document).ready(function() {
3478 $("#fac_rec").change(function() {
3479 console.log("We have changed the template invoice - Reload page");
3480 var fac_rec = $(this).val();
3481 var socid = $(\'#socid\').val();
3482 // 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.
3483 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3496 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td colspan="2">';
3497 print
'<div class="tagtable">'.
"\n";
3500 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3501 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
3502 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
3504 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3,
'standardonsmartphone');
3505 print
'<table class="nobordernopadding"><tr>';
3509 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
3518 print
'<td class="nowrap" style="padding-left: 15px">';
3519 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%').
'"/>';
3522 print
'</tr></table>';
3523 print
'</div></div>';
3525 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
3528 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3529 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
3530 print
'<script type="text/javascript">
3531 jQuery(document).ready(function() {
3532 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
3533 jQuery("#radio_standard").prop("checked", true);
3535 jQuery("#typedeposit, #valuedeposit").click(function() {
3536 jQuery("#radio_deposit").prop("checked", true);
3538 jQuery("#typedeposit").change(function() {
3539 console.log("We change type of down payment");
3540 jQuery("#radio_deposit").prop("checked", true);
3541 setRadioForTypeOfInvoice();
3543 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
3544 setRadioForTypeOfInvoice();
3546 function setRadioForTypeOfInvoice() {
3547 console.log("Change radio for type of invoice");
3548 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
3549 jQuery("#checkforselects").prop("disabled", true);
3550 jQuery("#checkforselects").prop("checked", false);
3551 jQuery(".checkforselect").prop("disabled", true);
3552 jQuery(".checkforselect").prop("checked", false);
3554 jQuery("#checkforselects").prop("disabled", false);
3555 jQuery("#checkforselects").prop("checked", true);
3556 jQuery(".checkforselect").prop("disabled", false);
3557 jQuery(".checkforselect").prop("checked", true);
3563 print
'<table class="nobordernopadding"><tr>';
3565 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
3567 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
3570 if (($origin ==
'propal') || ($origin ==
'commande')) {
3571 print
'<td class="nowrap" style="padding-left: 15px">';
3573 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
3574 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
3575 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
3577 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
3579 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
3580 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
3581 if (!empty($origin_payment_conditions_deposit_percent)) {
3582 $typedeposit =
'variable';
3585 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
3586 $valuedeposit = $objectsrc->deposit_percent;
3588 print
$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
3590 print
'<td class="nowrap" style="padding-left: 5px">';
3591 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.$valuedeposit.
'"/>';
3594 print
'</tr></table>';
3596 print
'</div></div>';
3603 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3604 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
3605 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
3607 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
3609 print
'</div></div>';
3612 $opt =
$form->selectSituationInvoices(
GETPOSTINT(
'originid'), $socid);
3614 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3615 $tmp =
'<input type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
3616 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3617 $tmp .=
' disabled';
3620 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3621 $text .=
'<select class="flat" id="situations" name="situations"';
3622 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3623 $text .=
' disabled';
3627 $text .=
'</select>';
3628 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
3630 print
'</div></div>';
3636 $facids = $facturestatic->list_replacable_invoices($soc->id);
3642 if (is_array($facids)) {
3643 foreach ($facids as $facparam) {
3644 $options .=
'<option value="'.$facparam [
'id'].
'"';
3645 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
3646 $options .=
' selected';
3648 $options .=
'>'.$facparam[
'ref'];
3649 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
3650 $options .=
'</option>';
3654 print
'<!-- replacement line -->';
3655 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3656 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
3657 if (!$options || $invoice_predefined->id > 0) {
3658 $tmp .=
' disabled';
3661 print
'<script type="text/javascript">
3662 jQuery(document).ready(function() {
3663 jQuery("#fac_replacement").change(function() {
3664 jQuery("#radio_replacement").prop("checked", true);
3668 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
3669 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
3670 if (!$options || $invoice_predefined->id > 0) {
3671 $text .=
' disabled';
3675 $text .=
'<option value="-1"> </option>';
3678 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
3680 $text .=
'</select>';
3681 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3683 print
'</div></div>';
3687 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3688 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3689 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3690 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3691 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
3693 print
'</div></div>';
3696 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3697 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
3698 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
3700 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'', 0, 3,
'replacementonsmartphone');
3702 print
'</div></div>';
3705 if (empty($origin)) {
3710 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
3716 $newinvoice_static =
new Facture($db);
3717 foreach ($facids as $key => $valarray) {
3718 $newinvoice_static->id = $key;
3719 $newinvoice_static->ref = $valarray [
'ref'];
3720 $newinvoice_static->statut = $valarray [
'status'];
3721 $newinvoice_static->status = $valarray [
'status'];
3722 $newinvoice_static->type = $valarray [
'type'];
3723 $newinvoice_static->paye = $valarray [
'paye'];
3725 $optionsav .=
'<option value="'.$key.
'"';
3726 if ($key ==
GETPOST(
'fac_avoir')) {
3727 $optionsav .=
' selected';
3730 $newinvoice_static->fetch_optionals($key);
3731 $object->array_options = $newinvoice_static->array_options;
3734 $optionsav .= $newinvoice_static->ref;
3735 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
3736 $optionsav .=
'</option>';
3739 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3740 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
3741 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
3742 $tmp .=
' disabled';
3746 print
'<script type="text/javascript">
3747 jQuery(document).ready(function() {
3748 if (jQuery("#radio_creditnote").is(":checked"))
3750 jQuery("#radio_standard").prop("disabled", true);
3752 jQuery("#radio_standard").prop("disabled", false);
3754 if (! jQuery("#radio_creditnote").is(":checked"))
3756 jQuery("#credit_note_options").hide();
3758 jQuery("#radio_creditnote").click(function() {
3759 jQuery("#credit_note_options").show();
3761 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
3762 jQuery("#credit_note_options").hide();
3766 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
3767 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3768 if (!$optionsav || $invoice_predefined->id > 0) {
3769 $text .=
' disabled';
3773 $text .=
'<option value="-1"></option>';
3774 $text .= $optionsav;
3776 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
3778 $text .=
'</select>';
3779 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3782 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
3783 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>";
3784 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>";
3787 print
'</div></div>';
3790 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3792 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3794 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
3796 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
3798 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
3800 print
'</div></div>'.
"\n";
3805 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3806 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
3807 $text = $tmp.
'<label class="opacitymedium" for="radio_template">'.$langs->trans(
"RepeatableInvoice").
'</label> ';
3808 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3,
'templateonsmartphone');
3810 print
'</div></div>';
3819 foreach ($listtType as $type) {
3820 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
3822 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
3825 print
'<script type="text/javascript">
3826 $(document).ready(function() {
3827 var listType = {'.$jsListType.
'};
3828 $("[name=\'type\'").change(function() {
3829 console.log("change name=type");
3830 if ($( this ).prop("checked"))
3832 if(($( this ).val() in listType))
3834 $("#model").val(listType[$( this ).val()]);
3851 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
3852 print
$form->getSelectInvoiceSubtype(
GETPOST(
'subtype'),
'subtype', 1, 0,
'');
3858 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
3862 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
3863 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3872 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
3873 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3874 print
$form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
3879 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
3880 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3881 print
$form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
3886 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
3887 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
3888 print
$form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
3893 $rwStyle =
'display:none;';
3894 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
3898 $retained_warranty =
GETPOSTINT(
'retained_warranty');
3899 if (empty($retained_warranty)) {
3900 if (!empty($objectsrc->retained_warranty)) {
3901 $retained_warranty = $objectsrc->retained_warranty;
3904 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
3906 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
3907 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
3910 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
3911 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
3912 if (empty($retained_warranty_fk_cond_reglement)) {
3913 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
3914 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
3915 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
3917 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
3920 print
$form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
3923 print
'<script type="text/javascript">
3924 $(document).ready(function() {
3925 $("[name=\'type\']").change(function() {
3926 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
3928 $(".retained-warranty-line").show();
3929 $("#new-situation-invoice-retained-warranty").val("'.(
float) $retained_warranty_js_default.
'");
3932 $(".retained-warranty-line").hide();
3933 $("#new-situation-invoice-retained-warranty").val("");
3937 $("[name=\'type\']:checked").trigger("change");
3943 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
3944 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
3945 print
$form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
3950 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td colspan="2">';
3951 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
3952 print
$form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
3958 $langs->load(
'projects');
3959 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
3960 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');
3961 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>';
3968 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
3969 print
'<td colspan="2" class="maxwidthonsmartphone">';
3970 $incoterm_id =
GETPOST(
'incoterm_id');
3971 $location_incoterms =
GETPOST(
'location_incoterms');
3972 if (empty($incoterm_id)) {
3973 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
3974 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
3976 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
3977 print
$form->select_incoterms($incoterm_id, $location_incoterms);
3982 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
3983 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters,
$object, $action);
3984 print $hookmanager->resPrint;
3985 if (empty($reshook)) {
3986 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
3989 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
3990 if ($soc->fetch_optionals() > 0) {
3991 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
3999 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
4000 print
'<td colspan="2">';
4001 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
4002 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
4006 $paramkey =
'FACTURE_ADDON_PDF_'.$object->type;
4011 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
4017 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0).
'</td>';
4018 print
'<td colspan="2" class="maxwidthonsmartphone">';
4019 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
4020 print
$form->selectMultiCurrency(((
GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code');
4027 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
4028 if (empty($dateexample)) {
4031 $substitutionarray = array(
4032 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
4033 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
4034 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
4035 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
4036 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
4037 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
4038 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
4039 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
4040 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
4041 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
4042 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
4045 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
4046 foreach ($substitutionarray as $key => $val) {
4047 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
4049 $htmltext .=
'</i>';
4054 print
'<td class="tdtop">';
4055 print
$form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
4057 print
'<td valign="top" colspan="2">';
4058 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
4059 print $doleditor->Create(1);
4062 if (empty($user->socid)) {
4064 print
'<td class="tdtop">';
4065 print
$form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4067 print
'<td valign="top" colspan="2">';
4068 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4069 print $doleditor->Create(1);
4075 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4076 $langs->loadLangs(array(
'orders',
'propal'));
4079 if ($origin ==
'contrat') {
4083 $objectsrc->update_price(1,
'auto', 1);
4086 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4087 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4088 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4089 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4094 switch (get_class($objectsrc)) {
4096 $newclassname =
'CommercialProposal';
4099 $newclassname =
'Order';
4102 $newclassname =
'Sending';
4105 $newclassname =
'Contract';
4108 $newclassname =
'Intervention';
4111 $newclassname = get_class($objectsrc);
4115 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4116 print
'<td colspan="2">';
4117 print $objectsrc->getNomUrl(1);
4119 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
4120 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4122 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4125 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht).
'</td></tr>';
4126 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva).
"</td></tr>";
4127 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4128 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax1).
"</td></tr>";
4131 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4132 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax2).
"</td></tr>";
4134 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc).
"</td></tr>";
4137 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
4138 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
4139 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
4147 print
$form->buttonsSaveCancel(
"CreateDraft");
4150 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4153 $title = $langs->trans(
'ProductsAndServices');
4156 print
'<div class="div-table-responsive-no-min">';
4157 print
'<table class="noborder centpercent">';
4159 $objectsrc->printOriginLinesList(
'', $selectedLines);
4166 } elseif ($id > 0 || !empty($ref)) {
4168 $langs->load(
'errors');
4169 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4178 $result =
$object->fetch($id, $ref);
4185 $extrafields->fetch_name_optionals_label(
$object->table_element);
4187 if ($user->socid > 0 && $user->socid !=
$object->socid) {
4191 $result =
$object->fetch_thirdparty();
4193 $result = $soc->fetch(
$object->socid);
4197 $selleruserevenustamp = $mysoc->useRevenueStamp();
4199 $totalpaid =
$object->getSommePaiement();
4200 $totalcreditnotes =
$object->getSumCreditNotesUsed();
4201 $totaldeposits =
$object->getSumDepositsUsed();
4207 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4211 $multicurrency_totalpaid =
$object->getSommePaiement(1);
4212 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
4213 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
4214 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4218 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code != $conf->currency) {
4219 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
4226 $resteapayeraffiche = $resteapayer;
4229 $filterabsolutediscount =
"fk_facture_source IS NULL";
4230 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4232 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4233 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4236 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
4237 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
4238 $absolute_discount =
price2num($absolute_discount,
'MT');
4239 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4241 $author =
new User($db);
4242 if (
$object->user_creation_id) {
4243 $author->fetch(
$object->user_creation_id);
4246 $objectidnext =
$object->getIdReplacingInvoice();
4250 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
'bill');
4255 if ($action ==
'converttoreduc') {
4257 $type_fac =
'ExcessReceived';
4259 $type_fac =
'CreditNote';
4261 $type_fac =
'Deposit';
4263 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4264 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4265 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4269 if ($action ==
'delete') {
4270 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
4271 $formquestion = array();
4274 $qualified_for_stock_change = 0;
4276 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4278 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4281 if ($qualified_for_stock_change) {
4282 $langs->load(
"stocks");
4283 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4287 if ($conf->browser->name ==
'ie') {
4290 $formquestion = array(
4294 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4296 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4298 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4301 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4306 if ($action ==
'situationout') {
4307 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
4308 $label = $langs->trans(
"ConfirmOuting");
4309 $formquestion = array();
4314 &&
$object->is_last_in_cycle()
4315 && $usercanunvalidate
4317 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4322 if ($action ==
'valid') {
4324 $objectref = substr(
$object->ref, 1, 4);
4325 if ($objectref ==
'PROV') {
4329 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
4331 $numref =
$object->getNextNumRef($soc);
4337 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4339 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4340 $notify =
new Notify($db);
4342 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid,
$object);
4344 $formquestion = array();
4347 $qualified_for_stock_change = 0;
4349 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4351 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4354 if ($qualified_for_stock_change) {
4355 $langs->load(
"stocks");
4356 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4357 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4360 $warehouse_array = $warehouse->list_array();
4361 if (count($warehouse_array) == 1) {
4362 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4363 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4366 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4368 $formquestion = array(
4374 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4378 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
4383 foreach (
$object->lines as $line) {
4384 $res = $line->fetch_product();
4386 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
4392 if ($nbMandated > 0) {
4393 $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
4401 if ($action ==
'modif') {
4402 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
4403 $formquestion = array();
4406 $qualified_for_stock_change = 0;
4408 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4410 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4413 if ($qualified_for_stock_change) {
4414 $langs->load(
"stocks");
4415 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4416 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4419 $warehouse_array = $warehouse->list_array();
4420 if (count($warehouse_array) == 1) {
4421 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
4422 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4425 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4427 $formquestion = array(
4433 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4437 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
4441 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
4442 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
4444 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
4448 $close[$i][
'code'] =
'discount_vat';
4450 $close[$i][
'code'] =
'badcustomer';
4452 $close[$i][
'code'] =
'bankcharge';
4454 $close[$i][
'code'] =
'withholdingtax';
4456 $close[$i][
'code'] =
'other';
4460 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
4462 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4464 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
4466 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
4468 $close[$i][
'label'] = $langs->trans(
"Other");
4472 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4474 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4476 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4478 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
4480 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
4484 foreach ($close as $key => $val) {
4485 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
4489 $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'));
4491 $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);
4495 if ($action ==
'canceled') {
4498 if ($objectidnext) {
4499 $facturereplacement =
new Facture($db);
4500 $facturereplacement->fetch($objectidnext);
4501 $statusreplacement = $facturereplacement->status;
4503 if ($objectidnext && $statusreplacement == 0) {
4504 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
4507 $close[1][
'code'] =
'badcustomer';
4508 $close[2][
'code'] =
'abandon';
4510 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4511 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
4513 $close[1][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
4514 $close[2][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
4517 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
4518 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
4521 $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'));
4523 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 270);
4527 if ($action ==
'deletepayment') {
4528 $payment_id =
GETPOST(
'paiement_id');
4529 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
4533 if ($action ==
'ask_deleteline') {
4534 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
4538 if ($action ==
'clone') {
4539 $filter =
'(s.client:IN:1,2,3)';
4541 $formquestion = array(
4542 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' =>
$form->select_company(
$object->socid,
'socid', $filter, 1)),
4543 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
4546 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
4549 if ($action ==
"remove_file_comfirm") {
4550 $file =
GETPOST(
'file',
'alpha');
4553 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
4554 $langs->trans(
'DeleteFileHeader'),
4555 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
4566 if (empty($reshook)) {
4568 } elseif ($reshook > 0) {
4577 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
4579 $morehtmlref =
'<div class="refidno">';
4582 $morehtmlref .=
$form->editfieldkey(
"Ref",
'ref',
$object->ref,
$object, $usercancreate,
'string',
'', 0, 1);
4583 $morehtmlref .=
$form->editfieldval(
"Ref",
'ref',
$object->ref,
$object, $usercancreate,
'string',
'',
null,
null,
'', 1);
4584 $morehtmlref .=
'<br>';
4587 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer,
$object, $usercancreate,
'string',
'', 0, 1);
4588 $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);
4590 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
4592 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'&search_societe='.urlencode(
$object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
4596 $langs->load(
"projects");
4597 $morehtmlref .=
'<br>';
4598 if ($usercancreate) {
4599 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
4600 if ($action !=
'classify') {
4601 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
4603 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->socid,
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
4605 if (!empty(
$object->fk_project)) {
4607 $proj->fetch(
$object->fk_project);
4608 $morehtmlref .= $proj->getNomUrl(1);
4610 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
4615 $morehtmlref .=
'</div>';
4617 $object->totalpaid = $totalpaid;
4619 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
4624 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice',
$parameters,
$object, $action);
4625 if (empty($reshook)) {
4626 print
'<div class="fichecenter">';
4627 print
'<div class="fichehalfleft">';
4628 print
'<div class="underbanner clearboth"></div>';
4630 print
'<table class="border centpercent tableforfield">';
4633 print
'<tr><td class="titlefield fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
4636 print
' '.$object->getSubtypeLabel(
'facture');
4642 $facreplaced =
new Facture($db);
4643 $facreplaced->fetch(
$object->fk_facture_source);
4644 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
4648 $facusing->fetch(
$object->fk_facture_source);
4649 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
4652 $facidavoir =
$object->getListIdAvoirFromInvoice();
4653 if (count($facidavoir) > 0) {
4654 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
4656 foreach ($facidavoir as $id) {
4663 $facavoir->fetch($id);
4664 print $facavoir->getNomUrl(1,
'', 32);
4668 if ($objectidnext > 0) {
4669 $facthatreplace =
new Facture($db);
4670 $facthatreplace->fetch($objectidnext);
4671 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
4676 $result = $discount->fetch(0,
$object->id);
4678 print
' <span class="opacitymediumbycolor paddingleft">';
4679 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
4680 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
4681 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
4683 print
'</span><br>';
4687 if (
$object->fk_fac_rec_source > 0) {
4689 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
4691 print
' <span class="opacitymediumbycolor paddingleft">';
4692 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
4693 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
4701 print
'<!-- Discounts -->'.
"\n";
4702 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
4706 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
4707 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
4712 print
'<table class="nobordernopadding centpercent"><tr><td>';
4713 print $langs->trans(
'DateInvoice');
4715 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
4716 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>';
4718 print
'</tr></table>';
4721 if ($action ==
'editinvoicedate') {
4722 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
4724 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
4733 print
'<table class="nobordernopadding centpercent"><tr><td>';
4734 print $langs->trans(
'DatePointOfTax');
4736 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>';
4737 print
'</tr></table>';
4739 if ($action ==
'editdate_pointoftax') {
4740 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
4742 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
4749 print
'<table class="nobordernopadding centpercent"><tr><td>';
4750 print $langs->trans(
'PaymentConditionsShort');
4753 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>';
4755 print
'</tr></table>';
4758 if ($action ==
'editconditions') {
4759 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->cond_reglement_id,
'cond_reglement_id');
4761 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->cond_reglement_id,
'none');
4770 print
'<table class="nobordernopadding centpercent"><tr><td>';
4771 print $langs->trans(
'DateMaxPayment');
4774 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>';
4776 print
'</tr></table>';
4779 if ($action ==
'editpaymentterm') {
4780 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
4782 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
4794 print
'<table class="nobordernopadding centpercent"><tr><td>';
4795 print $langs->trans(
'PaymentMode');
4797 if ($action !=
'editmode' && $usercancreate) {
4798 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>';
4800 print
'</tr></table>';
4802 if ($action ==
'editmode') {
4803 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
4805 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->mode_reglement_id,
'none',
'CRDT');
4814 print
'<table class="nobordernopadding centpercent"><tr><td>';
4815 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0);
4817 if ($usercancreate && $action !=
'editmulticurrencycode' &&
$object->status == $object::STATUS_DRAFT) {
4818 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>';
4820 print
'</tr></table>';
4822 $htmlname = (($usercancreate && $action ==
'editmulticurrencycode') ?
'multicurrency_code' :
'none');
4823 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_code, $htmlname);
4827 if (
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
4830 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4831 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'',
$object, 0);
4833 if ($usercancreate && $action !=
'editmulticurrencyrate' &&
$object->status == $object::STATUS_DRAFT &&
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency) {
4834 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>';
4836 print
'</tr></table>';
4838 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
4839 if ($action ==
'actualizemulticurrencyrate') {
4842 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_tx, ($usercancreate ?
'multicurrency_tx' :
'none'),
$object->multicurrency_code);
4844 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_tx,
'none',
$object->multicurrency_code);
4845 if (
$object->status == $object::STATUS_DRAFT &&
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency) {
4846 print
'<div class="inline-block"> ';
4847 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
4857 print
'<tr><td class="nowrap">';
4858 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
4859 print $langs->trans(
'BankAccount');
4861 if (($action !=
'editbankaccount') && $usercancreate) {
4862 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>';
4864 print
'</tr></table>';
4866 if ($action ==
'editbankaccount') {
4867 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'fk_account', 1);
4869 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'none');
4878 print
'<table class="nobordernopadding centpercent"><tr><td>';
4879 print $langs->trans(
'IncotermLabel');
4880 print
'<td><td class="right">';
4881 if ($usercancreate) {
4882 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
4886 print
'</td></tr></table>';
4889 if ($action !=
'editincoterm') {
4892 print
$form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
4900 $displayWarranty =
true;
4901 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
4902 $displayWarranty =
false;
4905 if ($displayWarranty) {
4907 print
'<tr class="retained-warranty-lines" ><td>';
4908 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
4909 print $langs->trans(
'RetainedWarranty');
4912 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>';
4915 print
'</tr></table>';
4918 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
4919 print
'<input type="hidden" name="action" value="setretainedwarranty">';
4920 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4921 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4922 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
4923 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
4931 print
'<tr class="retained-warranty-lines" ><td>';
4932 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
4933 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
4935 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
4936 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>';
4939 print
'</tr></table>';
4941 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
4942 if (
$object->date > $defaultDate) {
4948 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
4949 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
4950 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4951 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4952 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
4953 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
4954 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4955 print
$form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4956 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4959 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->retained_warranty_fk_cond_reglement,
'none');
4960 if (!$displayWarranty) {
4961 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning.png',
'class="pictowarning valignmiddle" ');
4967 print
'<tr class="retained-warranty-lines" ><td>';
4968 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
4969 print $langs->trans(
'RetainedWarrantyDateLimit');
4972 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>';
4975 print
'</tr></table>';
4977 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
4978 if (
$object->date > $defaultDate) {
4984 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
4985 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
4986 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4987 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4988 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').
'" >';
4989 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5001 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
5006 print
'<div class="fichehalfright">';
5008 print
'<!-- amounts -->'.
"\n";
5009 print
'<div class="underbanner clearboth"></div>'.
"\n";
5011 print
'<table class="border tableforfield centpercent">';
5019 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
5020 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5023 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5029 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountVAT') .
'</td>';
5030 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5033 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5038 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
5040 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
5041 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5045 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5050 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
5052 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
5053 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5057 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5063 if ($selleruserevenustamp) {
5064 print
'<tr><td class="titlefieldmiddle">';
5065 print
'<table class="nobordernopadding centpercent"><tr><td>';
5066 print $langs->trans(
'RevenueStamp');
5068 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
5069 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>';
5071 print
'</tr></table>';
5072 print
'</td><td class="nowrap amountcard right">';
5073 if ($action ==
'editrevenuestamp') {
5074 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
5075 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5076 print
'<input type="hidden" name="action" value="setrevenuestamp">';
5077 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
5078 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5079 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
5080 print
' → <span id="revenuestamp_span"></span>';
5081 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
5084 $(document).ready(function(){
5085 js_recalculate_revenuestamp();
5086 $('select[name=revenuestamp_type]').on('change',function(){
5087 js_recalculate_revenuestamp();
5090 function js_recalculate_revenuestamp(){
5091 var valselected = $('select[name=revenuestamp_type]').val();
5092 console.log('Calculate revenue stamp from '+valselected);
5094 if (valselected.indexOf('%') == -1)
5096 revenue = valselected;
5100 var revenue_type = parseFloat(valselected);
5101 var amount_net = ".round(
$object->total_ht, 2).
";
5102 revenue = revenue_type * amount_net / 100;
5103 revenue = revenue.toFixed(2);
5105 $('#revenuestamp_val').val(revenue);
5106 $('#revenuestamp_span').html(revenue);
5110 print
price(
$object->revenuestamp, 1,
'', 1, -1, -1, $conf->currency);
5117 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
5118 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5121 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5136 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
5139 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
5142 if ($selleruserevenustamp) {
5154 print
'<!-- List of situation invoices -->';
5155 print
'<table class="noborder situationstable" width="100%">';
5157 print
'<tr class="liste_titre">';
5158 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
5160 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
5162 print
'<td class="right"></td>';
5164 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
5165 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
5166 print
'<td width="18"> </td>';
5169 $total_prev_ht = $total_prev_ttc = 0;
5170 $total_global_ht = $total_global_ttc = 0;
5172 if (count(
$object->tab_previous_situation_invoice) > 0) {
5175 $current_situation_counter = array();
5176 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
5177 $tmptotalpaidforthisinvoice = $prev_invoice->getSommePaiement();
5178 $total_prev_ht += $prev_invoice->total_ht;
5179 $total_prev_ttc += $prev_invoice->total_ttc;
5180 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
5181 print
'<tr class="oddeven">';
5182 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
5184 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
5186 print
'<td class="right"></td>';
5188 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
5189 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
5190 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).
'</td>';
5196 $total_global_ht += $total_prev_ht;
5197 $total_global_ttc += $total_prev_ttc;
5198 $total_global_ht +=
$object->total_ht;
5199 $total_global_ttc +=
$object->total_ttc;
5201 print
'<tr class="oddeven">';
5202 print
'<td>'.$object->getNomUrl(1).
'</td>';
5204 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
5206 print
'<td class="right"></td>';
5208 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
5209 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
5210 print
'<td class="right">'.$object->getLibStatut(3,
$object->getSommePaiement()).
'</td>';
5214 print
'<tr class="oddeven">';
5215 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'CurrentSituationTotal').
'</b></td>';
5218 foreach ($current_situation_counter as $sit) {
5219 $curSign = $sit > 0 ?
'+' :
'-';
5220 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
5222 print
' '.$curSign.
' ';
5224 print $curType.abs($sit);
5231 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5232 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5233 print
'<td width="18"> </td>';
5237 if (count(
$object->tab_next_situation_invoice) > 0) {
5249 $total_next_ht = $total_next_ttc = 0;
5251 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
5252 $totalpaid = $next_invoice->getSommePaiement();
5253 $total_next_ht += $next_invoice->total_ht;
5254 $total_next_ttc += $next_invoice->total_ttc;
5256 print
'<tr class="oddeven">';
5257 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
5259 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
5261 print
'<td class="right"></td>';
5263 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
5264 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
5265 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid).
'</td>';
5269 $total_global_ht += $total_next_ht;
5270 $total_global_ttc += $total_next_ttc;
5272 print
'<tr class="oddeven">';
5273 print
'<td colspan="3" class="right"></td>';
5275 print
'<td class="right"></td>';
5277 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5278 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5279 print
'<td width="18"> </td>';
5287 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
5293 print
'<!-- List of payments already done -->';
5294 print
'<div class="div-table-responsive-no-min">';
5295 print
'<table class="noborder paymenttable centpercent">';
5297 print
'<tr class="liste_titre">';
5298 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
5299 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
5300 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
5302 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
5304 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
5305 print
'<td class="liste_titre" width="18"> </td>';
5309 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
5310 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
5311 $sql .=
' pf.amount,';
5312 $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';
5313 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
5314 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
5315 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
5316 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
5317 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
5318 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
5319 $sql .=
' ORDER BY p.datep, p.tms';
5321 $result = $db->query(
$sql);
5323 $num = $db->num_rows($result);
5328 $objp = $db->fetch_object($result);
5330 $paymentstatic->id = $objp->rowid;
5331 $paymentstatic->datepaye = $db->jdate($objp->dp);
5332 $paymentstatic->ref = $objp->ref;
5333 $paymentstatic->num_payment = $objp->num_payment;
5334 $paymentstatic->paiementcode = $objp->payment_code;
5336 print
'<tr class="oddeven"><td class="nowraponall">';
5337 print $paymentstatic->getNomUrl(1);
5340 $dateofpayment = $db->jdate($objp->dp);
5342 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
5349 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
5350 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
5352 $bankaccountstatic->id = $objp->baid;
5353 $bankaccountstatic->ref = $objp->baref;
5354 $bankaccountstatic->label = $objp->baref;
5355 $bankaccountstatic->number = $objp->banumber;
5356 $bankaccountstatic->currency_code = $objp->bacurrency_code;
5359 $bankaccountstatic->account_number = $objp->account_number;
5362 $accountingjournal->fetch($objp->fk_accountancy_journal);
5363 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
5366 print
'<td class="nowraponall">';
5367 if ($bankaccountstatic->id) {
5368 print $bankaccountstatic->getNomUrl(1,
'transactions');
5372 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
5373 print
'<td class="center">';
5376 $paiement->fetch($objp->rowid);
5378 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
5395 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5396 print
'<span class="opacitymedium">';
5398 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
5400 print $langs->trans(
'AlreadyPaid');
5402 print
'</span></td><td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td><td> </td></tr>';
5404 $resteapayeraffiche = $resteapayer;
5405 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
5408 $creditnoteamount = 0;
5410 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
5411 $sql .=
" re.description, re.fk_facture_source";
5412 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
5413 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
5414 $resql = $db->query(
$sql);
5416 $num = $db->num_rows($resql);
5420 $obj = $db->fetch_object($resql);
5421 $invoice->fetch($obj->fk_facture_source);
5422 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5423 print
'<span class="opacitymedium">';
5425 print $langs->trans(
"CreditNote").
' ';
5428 print $langs->trans(
"Deposit").
' ';
5430 print $invoice->getNomUrl(0);
5433 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
5434 print
'<td class="right">';
5435 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
5436 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
5441 $creditnoteamount += $obj->amount_ttc;
5444 $depositamount += $obj->amount_ttc;
5453 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5454 print
'<span class="opacitymedium">';
5455 print
$form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
5457 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5458 $resteapayeraffiche = 0;
5459 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5463 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5464 print
'<span class="opacitymedium">';
5465 print
$form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
5467 print
'</td><td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td><td> </td></tr>';
5469 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5473 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5474 print
'<span class="opacitymedium">';
5475 print
$form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
5477 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5478 $resteapayeraffiche = 0;
5479 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5483 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5484 $text = $langs->trans(
"HelpAbandonOther");
5486 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
5488 print
'<span class="opacitymedium">';
5490 print
$form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
5492 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5493 $resteapayeraffiche = 0;
5494 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5498 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5499 print
'<span class="opacitymedium">';
5500 print $langs->trans(
"Billed");
5501 print
'</td><td class="right">'.price(
$object->total_ttc).
'</td><td> </td></tr>';
5503 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5504 print
'<span class="opacitymedium">';
5505 print $langs->trans(
'RemainderToPay');
5506 if ($resteapayeraffiche < 0) {
5507 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5511 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
5514 if (
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
5515 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5516 print
'<span class="opacitymedium">';
5517 print $langs->trans(
'RemainderToPayMulticurrency');
5518 if ($resteapayeraffiche < 0) {
5519 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5523 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">';
5525 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>';
5529 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
5532 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
5535 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
5538 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
5540 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>';
5543 print
'<tr><td colspan="'.$nbcols.
'" align="right">';
5544 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
5545 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
5546 print
' :</td><td align="right">'.price($retainedWarranty).
'</td><td> </td></tr>';
5549 $resteapayeraffiche = $resteapayer;
5550 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5553 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5554 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
5555 print
'</td><td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td><td> </td></tr>';
5558 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>';
5561 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5562 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
5563 if ($resteapayeraffiche > 0) {
5564 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5566 print
'</span></td>';
5567 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
5568 print
'<td class="nowrap"> </td></tr>';
5571 if (
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
5572 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5573 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
5574 if ($resteapayeraffiche > 0) {
5575 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5579 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>';
5593 $formmargin->displayMarginInfos(
$object);
5599 print
'<div class="clearboth"></div><br><br>';
5602 $blocname =
'contacts';
5603 $title = $langs->trans(
'ContactsAddresses');
5604 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5608 $blocname =
'notes';
5609 $title = $langs->trans(
'Notes');
5610 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5614 $result =
$object->getLinesArray();
5618 global $inputalsopricewithtax;
5619 $inputalsopricewithtax = 1;
5624 print
'<!-- Area to change globally the situation percent -->'.
"\n";
5625 print
'<div class="div-table-responsive">';
5627 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'#updatealllines" method="POST">';
5628 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
5629 print
'<input type="hidden" name="action" value="updatealllines" />';
5630 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
5631 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5633 print
'<table id="tablelines_all_progress" class="noborder noshadow" width="100%">';
5635 print
'<tr class="liste_titre nodrag nodrop">';
5639 print
'<td align="center" width="5"> </td>';
5641 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
5642 print
'<td class="right">'.$langs->trans(
'Progress').
'</td>';
5643 print
'<td> </td>';
5646 print
'<tr class="nodrag nodrop">';
5649 print
'<td align="center" width="5"> </td>';
5651 print
'<td> </td>';
5652 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
5653 print
'<td class="right"><input type="submit" class="button" name="all_percent" value="Modifier" /></td>';
5664 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
5665 <input type="hidden" name="token" value="' .
newToken().
'">
5666 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
5667 <input type="hidden" name="mode" value="">
5668 <input type="hidden" name="page_y" value="">
5669 <input type="hidden" name="id" value="' .
$object->id.
'">
5670 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
5673 if (!empty($conf->use_javascript_ajax) &&
$object->status == 0) {
5674 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
5677 print
'<div class="div-table-responsive-no-min">';
5678 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
5682 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
5686 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
5687 if ($action !=
'editline' && $action !=
'selectlines') {
5691 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters,
$object, $action);
5695 if (empty($reshook)) {
5696 $object->formAddObjectLine(1, $mysoc, $soc);
5700 $reshook = $hookmanager->executeHooks(
'formEditObjectLine',
$parameters,
$object, $action);
5714 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
5715 print
'<div class="tabsAction">';
5718 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters,
$object, $action);
5719 if (empty($reshook)) {
5722 'class' =>
'classfortooltip',
5729 $ventilExportCompta =
$object->getVentilExportCompta();
5731 if ($ventilExportCompta == 0) {
5733 if (!$objectidnext &&
$object->is_last_in_cycle()) {
5734 if ($usercanunvalidate) {
5735 unset($params[
'attr'][
'title']);
5736 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=modif&token='.
newToken(),
'',
true, $params);
5738 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
5739 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=modif&token='.
newToken(),
'',
false, $params);
5741 } elseif (!
$object->is_last_in_cycle()) {
5742 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
5743 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5745 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
5746 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5750 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5751 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5756 $result = $discount->fetch(0,
$object->id);
5764 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
5765 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
5766 unset($params[
'attr'][
'title']);
5767 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
5769 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
5770 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
5777 $langs->load(
"contracts");
5779 if ($usercancreatecontract) {
5780 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>';
5787 if ($usercanvalidate) {
5788 unset($params[
'attr'][
'title']);
5789 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
5794 if (empty($user->socid)) {
5796 if ($objectidnext) {
5797 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'SendMail').
'</span>';
5800 unset($params[
'attr'][
'title']);
5801 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
5803 unset($params[
'attr'][
'title']);
5804 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
5812 if ($resteapayer > 0) {
5813 if ($usercancreatewithdrarequest) {
5814 if (!$objectidnext &&
$object->close_code !=
'replaced') {
5815 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>';
5817 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
5829 $langs->load(
"cashdesk");
5830 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
5831 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
5836 if ($objectidnext) {
5837 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
5841 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
5842 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
5846 unset($params[
'attr'][
'title']);
5847 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);
5852 $sumofpayment = $totalpaid;
5853 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
5859 if ($resteapayer == 0) {
5860 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
5862 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
5868 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
5872 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
5874 print
'<a class="butAction classfortooltip'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc" title="'.
dol_escape_htmltag($langs->trans(
"ConfirmConvertToReduc2")).
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
5881 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertToReduc').
'</a>';
5883 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
5897 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
5898 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
5900 unset($params[
'attr'][
'title']);
5901 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid',
'',
true, $params);
5907 if ($totalpaid > 0 || $totalcreditnotes > 0) {
5909 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
5912 if ($objectidnext) {
5913 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
5915 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
5923 if (!$objectidnext) {
5924 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>';
5931 && (
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
5934 &&
$object->is_last_in_cycle()
5937 if ($usercanunvalidate) {
5938 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>';
5940 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
5946 unset($params[
'attr'][
'title']);
5947 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice',
'',
true, $params);
5952 if (!$objectidnext && count(
$object->lines) > 0) {
5953 unset($params[
'attr'][
'title']);
5954 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
5963 &&
$object->situation_counter > 1
5964 &&
$object->is_last_in_cycle()
5965 && $usercanunvalidate
5967 if ((
$object->total_ttc - $totalcreditnotes) == 0) {
5968 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
5970 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
5976 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
5977 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5978 } elseif (!
$object->is_last_in_cycle()) {
5979 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5981 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5986 $isErasable =
$object->is_erasable();
5988 if ($isErasable == -4) {
5989 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
5990 } elseif ($isErasable == -3) {
5991 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
5992 } elseif ($isErasable == -2) {
5993 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
5994 } elseif ($isErasable == -1) {
5995 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5996 } elseif ($isErasable <= 0) {
5997 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable');
5998 } elseif ($objectidnext) {
5999 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
6001 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
6002 $enableDelete =
false;
6004 if ($isErasable > 0 && ! $objectidnext) {
6005 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
6006 $enableDelete =
true;
6008 unset($params[
'attr'][
'title']);
6009 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
6011 unset($params[
'attr'][
'title']);
6012 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
6019 if (
GETPOST(
'modelselected',
'alpha')) {
6020 $action =
'presend';
6022 if ($action !=
'prerelance' && $action !=
'presend') {
6023 print
'<div class="fichecenter"><div class="fichehalfleft">';
6024 print
'<a name="builddoc"></a>';
6029 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
6030 $genallowed = $usercanread;
6031 $delallowed = $usercancreate;
6033 print $formfile->showdocuments(
6053 'remove_file_comfirm'
6056 $somethingshown = $formfile->numoffiles;
6059 $linktoelem =
$form->showLinkToObjectBlock(
$object, array(), array(
'invoice'));
6061 $compatibleImportElementsList =
false;
6065 $compatibleImportElementsList = array(
'commande',
'propal');
6067 $somethingshown =
$form->showLinkedObjectBlock(
$object, $linktoelem, $compatibleImportElementsList);
6071 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6072 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
6073 $useonlinepayment = count($validpaymentmethod);
6076 $reshook = $hookmanager->executeHooks(
'doShowOnlinePaymentUrl',
$parameters,
$object, $action);
6078 if (isset($hookmanager->resArray[
'showonlinepaymenturl'])) {
6079 $useonlinepayment = $hookmanager->resArray[
'showonlinepaymenturl'];
6084 print
'<br><!-- Link to pay -->'.
"\n";
6085 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6086 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
6089 print
'</div><div class="fichehalfright">';
6093 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
6096 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
6098 $somethingshown =
$formactions->showactions(
$object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
6100 print
'</div></div>';
6105 $modelmail =
'facture_send';
6106 $defaulttopic =
'SendBillRef';
6107 $diroutput = $conf->invoice->multidir_output[
$object->entity];
6108 $trackid =
'inv'.$object->id;
6110 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
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.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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...
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.
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
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).
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information in HTML for admin users or standard users.
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...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
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.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
$formconfirm
if ($action == 'delbookkeepingyear') {
div float
Buy price without taxes.
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.