40require
'../../main.inc.php';
49require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_invoice/modules_facturefournisseur.php';
53require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture-rec.class.php';
55require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
56require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
57require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
58require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
59require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
60require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
62 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
63 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
66 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
67 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
71 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
74 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
77$langs->loadLangs(array(
'bills',
'compta',
'suppliers',
'companies',
'products',
'banks',
'admin'));
79 $langs->load(
'incoterm');
84$action =
GETPOST(
'action',
'aZ09');
87$cancel =
GETPOST(
'cancel',
'alpha');
88$backtopage =
GETPOST(
'backtopage',
'alpha');
89$backtopageforcancel =
'';
93$origin =
GETPOST(
'origin',
'alpha');
106$hookmanager->initHooks(array(
'invoicesuppliercard',
'globalcard'));
112$extrafields->fetch_name_optionals_label(
$object->table_element);
115if ($id > 0 || !empty($ref)) {
116 $ret =
$object->fetch($id, $ref);
123 $ret =
$object->fetch_thirdparty();
131if (!empty($user->socid)) {
132 $socid = $user->socid;
136$result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture',
'fk_soc',
'rowid', $isdraft);
139$usercanread = ($user->hasRight(
"fournisseur",
"facture",
"lire") || $user->hasRight(
"supplier_invoice",
"lire"));
140$usercancreate = ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"));
141$usercandelete = (($user->hasRight(
"fournisseur",
"facture",
"supprimer") || $user->hasRight(
"supplier_invoice",
"supprimer")) || ($usercancreate &&
$object->is_erasable() == 1));
142$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
145$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"validate")));
146$usercansend = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"send"));
147$usercancreatecreditransfer = $user->hasRight(
'paymentbybanktransfer',
'create');
150$permissionnote = $usercancreate;
151$permissiondellink = $usercancreate;
152$permissiontoedit = $usercancreate;
153$permissiontoadd = $usercancreate;
154$permissiontodelete = $usercandelete;
155$permissiontoeditextra = $permissiontoadd;
156if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
158 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
168$parameters = array(
'socid' => $socid);
169$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
174if (empty($reshook)) {
175 $backurlforlist = DOL_URL_ROOT.
'/fourn/facture/list.php';
177 if (empty($backtopage) || ($cancel && empty($id))) {
178 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
179 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
180 $backtopage = $backurlforlist;
182 $backtopage = DOL_URL_ROOT.
'/fourn/facture/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
188 if (!empty($backtopageforcancel)) {
189 header(
"Location: ".$backtopageforcancel);
191 } elseif (!empty($backtopage)) {
192 header(
"Location: ".$backtopage);
198 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
200 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
202 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
205 if (
GETPOST(
'linkedOrder') && empty($cancel) && $id > 0 && $permissiontoadd) {
208 $result =
$object->add_object_linked(
'order_supplier',
GETPOSTINT(
'linkedOrder'));
212 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
214 '@phan-var-force FactureFournisseur $objectutil';
216 if (
GETPOST(
'newsupplierref',
'alphanohtml')) {
217 $objectutil->ref_supplier =
GETPOST(
'newsupplierref',
'alphanohtml');
221 $result = $objectutil->createFromClone($user, $id);
223 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
226 $langs->load(
"errors");
230 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
231 $idwarehouse =
GETPOST(
'idwarehouse');
236 $qualified_for_stock_change = 0;
238 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
240 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
245 $langs->load(
"stocks");
246 if (!$idwarehouse || $idwarehouse == -1) {
248 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
256 $result =
$object->validate($user,
'', $idwarehouse);
263 $categories =
GETPOST(
'categories',
'array:int');
264 if (method_exists($object,
'setCategories')) {
265 $object->setCategories($categories);
273 $outputlangs = $langs;
276 $newlang =
GETPOST(
'lang_id',
'aZ09');
279 $newlang =
$object->thirdparty->default_lang;
281 if (!empty($newlang)) {
283 $outputlangs->setDefaultLang($newlang);
288 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
295 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $permissiontodelete) {
299 $isErasable =
$object->is_erasable();
301 if ($usercandelete && $isErasable > 0) {
302 $revertstock =
GETPOST(
'revertstock');
307 $qualified_for_stock_change = 0;
309 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
311 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
316 $langs->load(
"stocks");
317 if (!$idwarehouse || $idwarehouse == -1) {
319 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
322 $result =
$object->setDraft($user, $idwarehouse);
331 $result =
$object->delete($user);
333 header(
'Location: list.php?restore_lastsearch_values=1');
340 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
342 $result =
$object->deleteLine($lineid);
362 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
369 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
372 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
373 $discount->unlink_invoice();
374 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercancreate) {
376 $result =
$object->setPaid($user);
380 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercancreate) {
383 $close_code =
GETPOST(
"close_code",
'restricthtml');
384 $close_note =
GETPOST(
"close_note",
'restricthtml');
386 $result =
$object->setPaid($user, $close_code, $close_note);
391 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
393 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
396 $close_code =
GETPOST(
"close_code",
'restricthtml');
397 $close_note =
GETPOST(
"close_note",
'restricthtml');
399 $result =
$object->setCanceled($user, $close_code, $close_note);
404 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
409 if ($action ==
'setref_supplier' && $usercancreate) {
412 if (
$object->update($user) < 0) {
416 $outputlangs = $langs;
419 $newlang =
GETPOST(
'lang_id',
'aZ09');
422 $newlang =
$object->thirdparty->default_lang;
424 if (!empty($newlang)) {
426 $outputlangs->setDefaultLang($newlang);
430 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
436 if ($action ==
'setconditions' && $usercancreate) {
438 $object->cond_reglement_code = 0;
439 $object->cond_reglement_id = 0;
454 $new_date_echeance =
$object->calculate_date_lim_reglement();
455 if ($new_date_echeance) {
456 $object->date_echeance = $new_date_echeance;
461 $result =
$object->update($user);
473 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
476 } elseif ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
479 } elseif ($action ==
'setmode' && $usercancreate) {
482 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
484 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
485 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
488 } elseif ($action ==
'setbankaccount' && $usercancreate) {
491 } elseif ($action ==
'setvatreversecharge' && $usercancreate) {
493 $vatreversecharge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
494 $result =
$object->setVATReverseCharge($vatreversecharge);
497 if ($action ==
'settransportmode' && $usercancreate) {
500 } elseif ($action ==
'setlabel' && $usercancreate) {
504 $result =
$object->update($user);
508 } elseif ($action ==
'setdatef' && $usercancreate) {
512 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
514 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
521 $date_echence_calc =
$object->calculate_date_lim_reglement();
522 if (!empty(
$object->date_echeance)) {
523 $object->date_echeance = $date_echence_calc;
529 $result =
$object->update($user);
533 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
537 $object->date_pointoftax = $date_pointoftax;
539 $result =
$object->update($user);
542 $action =
'editdate_pointoftax';
544 } elseif ($action ==
'setdate_lim_reglement' && $usercancreate) {
549 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
551 $result =
$object->update($user);
555 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
571 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
573 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
577 $remaintopay =
$object->getRemainToPay(0);
581 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
585 $result = $discount->link_to_invoice(0, $id);
592 $newremaintopay =
$object->getRemainToPay(0);
593 if ($newremaintopay == 0) {
604 $outputlangs = $langs;
607 $newlang =
GETPOST(
'lang_id',
'aZ09');
610 $newlang =
$object->thirdparty->default_lang;
612 if (!empty($newlang)) {
614 $outputlangs->setDefaultLang($newlang);
618 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
623 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
631 $result = $discountcheck->fetch(0, 0,
$object->id);
643 $amount_ht = $amount_tva = $amount_ttc = array();
644 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
648 foreach (
$object->lines as $line) {
649 if ($line->product_type < 9 && $line->total_ht != 0) {
650 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
652 $amount_ht[$keyforvatrate] += $line->total_ht;
653 $amount_tva[$keyforvatrate] += $line->total_tva;
654 $amount_ttc[$keyforvatrate] += $line->total_ttc;
655 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
656 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
657 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
661 '@phan-var-force array<string,float> $amount_ht
662 @phan-var-force array<string,float> $amount_tva
663 @phan-var-force array<string,float> $amount_ttc
664 @phan-var-force array<string,float> $multicurrency_amount_ht
665 @phan-var-force array<string,float> $multicurrency_amount_tva
666 @phan-var-force array<string,float> $multicurrency_amount_ttc';
670 $alreadypaid =
$object->getSommePaiement();
671 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
672 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
673 foreach ($amount_ht as $vatrate => $val) {
674 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
675 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
676 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
677 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
678 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
679 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
688 $discount->description =
'(CREDIT_NOTE)';
690 $discount->description =
'(DEPOSIT)';
692 $discount->description =
'(EXCESS PAID)';
694 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
696 $discount->discount_type = 1;
697 $discount->fk_soc =
$object->socid;
698 $discount->socid =
$object->socid;
699 $discount->fk_invoice_supplier_source =
$object->id;
707 $sql =
'SELECT SUM(pf.amount) as total_paiements';
708 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'paiementfourn as p';
709 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN ('.
getEntity(
'c_paiement').
')';
710 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
711 $sql .=
' AND pf.fk_paiementfourn = p.rowid';
712 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
714 $resql = $db->query($sql);
719 $res = $db->fetch_object($resql);
720 $total_paiements = $res->total_paiements;
723 $total_creditnote_and_deposit = 0;
724 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
725 $sql .=
" re.description, re.fk_invoice_supplier_source";
726 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
727 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
728 $resql = $db->query($sql);
729 if (!empty($resql)) {
730 while ($obj = $db->fetch_object($resql)) {
731 $total_creditnote_and_deposit += $obj->amount_ttc;
737 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
738 $discount->amount_tva = 0;
739 $discount->tva_tx = 0;
740 $discount->vat_src_code =
'';
743 $discount->multicurrency_code =
$object->multicurrency_code;
744 $discount->multicurrency_tx =
$object->multicurrency_tx;
745 $discount->multicurrency_total_ht = $discount->multicurrency_total_ttc = (float)
price2num((
float) $discount->amount_ttc * (float)
$object->multicurrency_tx,
'MT');
746 $discount->multicurrency_total_tva = 0;
748 $discount->multicurrency_amount_ht = $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
749 $discount->multicurrency_amount_tva = 0;
751 $result = $discount->create($user);
757 foreach ($amount_ht as $tva_tx => $xxx) {
758 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
759 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
760 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
762 $discount->multicurrency_code =
$object->multicurrency_code;
763 $discount->multicurrency_tx =
$object->multicurrency_tx;
764 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
765 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
766 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
768 $discount->multicurrency_amount_ht = abs((
float) $discount->multicurrency_total_ht);
769 $discount->multicurrency_amount_tva = abs((
float) $discount->multicurrency_total_tva);
770 $discount->multicurrency_amount_ttc = abs((
float) $discount->multicurrency_total_ttc);
775 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
776 $vat_src_code = $reg[1];
777 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
780 $discount->tva_tx = abs((
float) $tva_tx);
781 $discount->vat_src_code = $vat_src_code;
783 $result = $discount->create($user);
794 $result =
$object->setPaid($user);
809 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate) {
814 $result = $paiementfourn->fetch(
GETPOSTINT(
'paiement_id'));
816 $result = $paiementfourn->delete($user);
818 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
826 } elseif ($action ==
'add' && $usercancreate) {
831 $selectedLines =
GETPOST(
'toselect',
'array:int');
839 $ret = $extrafields->setOptionalsFromPost(
null, $object);
853 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
858 if (empty($dateinvoice)) {
859 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
871 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
885 $object->date_pointoftax = $date_pointoftax;
886 $object->date_echeance = $datedue;
892 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
893 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
895 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
896 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
917 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
920 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
925 if (empty($dateinvoice)) {
926 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
936 if (!
GETPOST(
'ref_supplier')) {
937 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
945 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
960 $object->date_pointoftax = $date_pointoftax;
961 $object->date_echeance = $datedue;
967 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
968 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
970 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
971 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
976 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
985 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
987 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
990 foreach ($facture_source->lines as $line) {
992 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
996 $line->fk_facture_fourn =
$object->id;
997 $line->fk_parent_line = $fk_parent_line;
999 $line->subprice = -$line->subprice;
1000 $line->pa_ht = -((float) $line->pa_ht);
1001 $line->total_ht = -$line->total_ht;
1002 $line->total_tva = -$line->total_tva;
1003 $line->total_ttc = -$line->total_ttc;
1004 $line->total_localtax1 = -$line->total_localtax1;
1005 $line->total_localtax2 = -$line->total_localtax2;
1007 $result = $line->insert();
1012 if ($result > 0 && $line->product_type == 9) {
1013 $fk_parent_line = $result;
1021 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 &&
$id > 0) {
1023 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1024 $totalpaid = $facture_source->getSommePaiement();
1025 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1026 $totaldeposits = $facture_source->getSumDepositsUsed();
1027 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1028 $desc = $langs->trans(
'invoiceAvoirLineWithPaymentRestAmount');
1032 $retAddLine =
$object->addline($desc, -$remain_to_pay, 0, 0, 0, 1, 0, 0,
'',
'', 0,
'',
'TTC');
1034 if ($retAddLine < 0) {
1042 if (empty($dateinvoice)) {
1044 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1054 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1064 $object->date_pointoftax = $date_pointoftax;
1065 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1066 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1077 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1078 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1082 $object->fac_rec = $fac_recid;
1084 $fac_rec->fetch(
$object->fac_rec);
1085 $fac_rec->fetch_lines();
1086 $object->lines = $fac_rec->lines;
1093 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1098 if (empty($dateinvoice)) {
1099 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1109 if (!
GETPOST(
'ref_supplier')) {
1110 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
1118 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1135 $object->date_pointoftax = $date_pointoftax;
1136 $object->date_echeance = $datedue;
1142 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1143 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1145 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1146 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1151 if (empty(
$object->date_echeance)) {
1152 $object->date_echeance =
$object->calculate_date_lim_reglement();
1158 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
1160 $element = $subelement =
GETPOST(
'origin',
'alpha');
1168 if ($element ==
'order') {
1169 $element = $subelement =
'commande';
1171 if ($element ==
'propal') {
1172 $element =
'comm/propal';
1173 $subelement =
'propal';
1175 if ($element ==
'contract') {
1176 $element = $subelement =
'contrat';
1178 if ($element ==
'order_supplier') {
1180 $subelement =
'fournisseur.commande';
1182 if ($element ==
'project') {
1183 $element =
'projet';
1191 $classname = ucfirst($subelement);
1192 if ($classname ==
'Fournisseur.commande') {
1193 $classname =
'CommandeFournisseur';
1195 $objectsrc =
new $classname($db);
1196 $objectsrc->fetch($originid);
1197 $objectsrc->fetch_thirdparty();
1199 if (!empty(
$object->origin_type) && !empty(
$object->origin_id)) {
1204 if (
$object->origin_type ==
'reception') {
1205 $objectsrc->fetchObjectLinked();
1207 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1208 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1209 $object->linkedObjectsIds[
'order_supplier'][-1] = $value;
1219 $classname = ucfirst($subelement);
1220 if ($classname ==
'Fournisseur.commande') {
1221 $classname =
'CommandeFournisseur';
1223 $srcobject =
new $classname($db);
1225 $result = $srcobject->fetch(
GETPOSTINT(
'originid'));
1228 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1233 $amountdeposit = array();
1235 if ($typeamount ==
'amount') {
1236 $amount = $valuedeposit;
1238 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1241 $TTotalByTva = array();
1242 foreach ($srcobject->lines as &$line) {
1243 if (!empty($line->special_code)) {
1246 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1248 '@phan-var-force array<string,float> $TTotalByTva';
1250 $amount_ttc_diff = 0.;
1251 foreach ($TTotalByTva as $tva => &$total) {
1252 $coef = $total / $srcobject->total_ttc;
1253 $am = $amount * $coef;
1254 $amount_ttc_diff += $am;
1255 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1258 if ($typeamount ==
'amount') {
1259 $amountdeposit[0] = $valuedeposit;
1260 } elseif ($typeamount ==
'variable') {
1263 $lines = $srcobject->lines;
1264 $numlines = count($lines);
1265 for ($i = 0; $i < $numlines; $i++) {
1267 if (empty($lines[$i]->qty)) {
1270 if (!empty($lines[$i]->special_code)) {
1274 $totalamount += $lines[$i]->total_ht;
1275 $tva_tx = $lines[$i]->tva_tx;
1276 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1280 if ($totalamount == 0) {
1281 $amountdeposit[0] = 0;
1286 $amountdeposit[0] = 0;
1290 $amount_ttc_diff = array_key_exists(0, $amountdeposit) ? $amountdeposit[0] : 0;
1293 foreach ($amountdeposit as $tva => $amount) {
1294 if (empty($amount)) {
1299 'amount' =>
'FixAmount',
1300 'variable' =>
'VarAmount'
1302 $descline =
'(DEPOSIT)';
1304 if ($typeamount ==
'amount') {
1305 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code : $conf->currency)).
')';
1306 } elseif ($typeamount ==
'variable') {
1307 $descline .=
' ('.$valuedeposit.
'%)';
1310 $descline .=
' - '.$srcobject->ref;
1340 $diff =
$object->total_ttc - $amount_ttc_diff;
1344 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1350 $object->lines[0]->localtax1_tx,
1351 $object->lines[0]->localtax2_tx,
1353 $object->lines[0]->fk_product,
1356 $object->lines[0]->product_type,
1357 $object->lines[0]->remise_percent,
1359 $object->lines[0]->date_start,
1368 } elseif ($result > 0) {
1369 $lines = $srcobject->lines;
1370 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1371 $srcobject->fetch_lines();
1372 $lines = $srcobject->lines;
1375 $num = count($lines);
1376 for ($i = 0; $i < $num; $i++) {
1377 if (!in_array($lines[$i]->
id, $selectedLines)) {
1381 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->product_label);
1382 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1385 if (method_exists($lines[$i],
'fetch_optionals')) {
1386 $lines[$i]->fetch_optionals();
1391 $date_start = $lines[$i]->date_debut_prevue;
1392 if ($lines[$i]->date_debut_reel) {
1393 $date_start = $lines[$i]->date_debut_reel;
1395 if ($lines[$i]->date_start) {
1396 $date_start = $lines[$i]->date_start;
1398 $date_end = $lines[$i]->date_fin_prevue;
1399 if ($lines[$i]->date_fin_reel) {
1400 $date_end = $lines[$i]->date_fin_reel;
1402 if ($lines[$i]->date_end) {
1403 $date_end = $lines[$i]->date_end;
1406 $tva_tx = $lines[$i]->tva_tx;
1408 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
1409 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1413 $object->special_code = $lines[$i]->special_code;
1416 if (
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
1418 $pu_currency = $lines[$i]->multicurrency_subprice;
1420 $pu = $lines[$i]->subprice;
1429 $lines[$i]->localtax1_tx,
1430 $lines[$i]->localtax2_tx,
1432 $lines[$i]->fk_product,
1433 $lines[$i]->remise_percent,
1437 $lines[$i]->info_bits,
1442 $lines[$i]->array_options,
1443 $lines[$i]->fk_unit,
1446 $lines[$i]->ref_supplier,
1447 $lines[$i]->special_code
1456 if ($result > 0 && !empty($lines[$i]->extraparams)) {
1458 $newline->id = $result;
1459 $newline->extraparams = $lines[$i]->extraparams;
1460 $newline->setExtraParameters();
1472 $parameters = array(
'objFrom' => $srcobject);
1473 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1483 } elseif (!$error) {
1493 $langs->load(
"errors");
1503 $outputlangs = $langs;
1504 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1511 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1514 } elseif ($action ==
'updateline' && $usercancreate) {
1518 if (!
$object->fetch($id) > 0) {
1524 $tva_tx = str_replace(
'*',
'', $tva_tx);
1526 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_subprice') !=
'') {
1528 $price_base_type =
'HT';
1531 $price_base_type =
'TTC';
1534 if (
GETPOST(
'productid') > 0) {
1536 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY') == 1) {
1538 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1544 $label = $prod->description;
1545 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1546 $label =
GETPOST(
'product_desc',
'restricthtml');
1549 $type = $prod->type;
1551 $label =
GETPOST(
'product_desc',
'restricthtml');
1560 if (preg_match(
'/\*/', $tva_tx)) {
1565 $tva_tx = str_replace(
'*',
'', $tva_tx);
1573 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1574 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1576 if (is_array($extralabelsline)) {
1577 foreach ($extralabelsline as $key => $value) {
1578 unset($_POST[
"options_".$key]);
1582 $result =
$object->updateline(
1594 (
float) $remise_percent,
1604 unset($_POST[
'label']);
1605 unset($_POST[
'fourn_ref']);
1606 unset($_POST[
'date_starthour']);
1607 unset($_POST[
'date_startmin']);
1608 unset($_POST[
'date_startsec']);
1609 unset($_POST[
'date_startday']);
1610 unset($_POST[
'date_startmonth']);
1611 unset($_POST[
'date_startyear']);
1612 unset($_POST[
'date_endhour']);
1613 unset($_POST[
'date_endmin']);
1614 unset($_POST[
'date_endsec']);
1615 unset($_POST[
'date_endday']);
1616 unset($_POST[
'date_endmonth']);
1617 unset($_POST[
'date_endyear']);
1618 unset($_POST[
'price_ttc']);
1619 unset($_POST[
'price_ht']);
1626 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
1630 foreach (
$object->lines as $line) {
1631 if ($line->product_type == 1) {
1632 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->qty, $line->fk_product,
'HT', $line->info_bits, $line->product_type, $line->remise_percent, 0, $alldate_start, $alldate_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier, $line->rang);
1635 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !=
'' && $usercancreate) {
1637 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1638 $vat_rate = str_replace(
'*',
'', $vat_rate);
1641 foreach (
$object->lines as $line) {
1642 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $vat_rate, $localtax1_rate, $localtax2_rate, $line->qty, $line->fk_product,
'HT', $line->info_bits, $line->product_type, $line->remise_percent, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier, $line->rang);
1644 } elseif ($action ==
'addline' && $usercancreate) {
1653 $ret =
$object->fetch_thirdparty();
1655 $langs->load(
'errors');
1660 $line_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
1664 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1665 if ($prod_entry_mode ==
'free') {
1672 $price_ht_devise =
'';
1674 $price_ttc_devise =
'';
1676 if (
GETPOST(
'price_ht') !==
'') {
1679 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
1682 if (
GETPOST(
'price_ttc') !==
'') {
1685 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
1686 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
1693 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
1694 if (empty($remise_percent)) {
1695 $remise_percent = 0;
1699 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1700 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
1702 if (is_array($extralabelsline)) {
1704 foreach ($extralabelsline as $key => $value) {
1705 unset($_POST[
"options_".$key]);
1709 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
1710 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1713 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOST(
'type') < 0) {
1714 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
1719 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1')
1720 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
1721 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
1722 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
1723 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
1724 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
1725 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) {
1726 $langs->load(
"errors");
1727 if (
$object->type == $object::TYPE_DEPOSIT) {
1729 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
1731 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPrice"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
1736 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
1737 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
1741 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') && !
GETPOST(
'dp_desc')) {
1742 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
1745 if (!
GETPOST(
'qty',
'alpha')) {
1746 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1750 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
1751 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
1755 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1756 $idprod = $res->fk_product_child;
1758 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
1764 if ($prod_entry_mode !=
'free' && empty($error)) {
1768 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
1773 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
1774 $idprod = (int) $reg[1];
1775 $res = $productsupplier->fetch($idprod);
1778 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
1780 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1781 if ($productsupplier->fourn_socid != $socid) {
1782 $productsupplier->ref_supplier =
'';
1785 $fksoctosearch =
$object->thirdparty->id;
1786 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1788 } elseif (
GETPOSTINT(
'idprodfournprice') > 0) {
1789 $qtytosearch = (float) $qty;
1791 $idprod = $productsupplier->get_buyprice(
GETPOSTINT(
'idprodfournprice'), $qtytosearch);
1792 $res = $productsupplier->fetch($idprod);
1796 $label = $productsupplier->label;
1799 $outputlangs = $langs;
1801 if (
GETPOST(
'lang_id',
'aZ09')) {
1802 $newlang =
GETPOST(
'lang_id',
'aZ09');
1804 if (empty($newlang)) {
1805 $newlang =
$object->thirdparty->default_lang;
1807 if (!empty($newlang)) {
1808 $outputlangs =
new Translate(
"", $conf);
1809 $outputlangs->setDefaultLang($newlang);
1811 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
1813 $desc = $productsupplier->description;
1816 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
1817 $desc = $productsupplier->desc_supplier;
1828 $ref_supplier = $productsupplier->ref_supplier;
1831 if (!GETPOSTISSET(
'tva_tx')) {
1832 $tmpidprodfournprice =
GETPOST(
'idprodfournprice',
'alpha');
1833 if (is_numeric($tmpidprodfournprice) && (
int) $tmpidprodfournprice > 0) {
1834 $tmpidprodfournprice = (int) $tmpidprodfournprice;
1836 $tmpidprodfournprice = 0;
1842 if (empty($tva_tx) || empty($tva_npr)) {
1848 $type = $productsupplier->type;
1849 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1850 $price_base_type =
'HT';
1852 $pu_devise =
price2num($price_ht_devise,
'CU');
1853 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
1854 $price_base_type =
'TTC';
1856 $pu_devise =
price2num($price_ttc_devise,
'CU');
1858 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
1859 if (empty(
$object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code !=
$object->multicurrency_code)) {
1860 $pu = $productsupplier->fourn_pu;
1863 $pu = $productsupplier->fourn_pu;
1864 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
1868 $ref_supplier = $productsupplier->ref_supplier;
1889 min($rank, count(
$object->lines) + 1),
1892 $productsupplier->fk_unit,
1895 GETPOST(
'fourn_ref',
'alpha'),
1899 if ($idprod == -99 || $idprod == 0) {
1902 $langs->load(
"errors");
1903 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
1905 if ($idprod == -1) {
1908 $langs->load(
"errors");
1909 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
1911 } elseif (empty($error)) {
1912 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1913 $tva_tx = str_replace(
'*',
'', $tva_tx);
1914 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1917 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
1921 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1929 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1933 $pu_ht =
price2num((
float) $pu_ttc / (1 + ((
float) $tva_tx / 100)),
'MU');
1935 $price_base_type =
'HT';
1936 $pu_devise =
price2num($price_ht_devise,
'CU');
1938 $result =
$object->addline($line_desc, (
float) $pu_ht, $tva_tx, $localtax1_tx, $localtax2_tx, (
float) $qty, 0, $remise_percent, $date_start, $date_end, 0, $tva_npr, $price_base_type, $type, -1, 0, $array_options, $fk_unit, 0, (
float) $pu_devise, $ref_supplier);
1942 if (!$error && $result > 0) {
1947 $outputlangs = $langs;
1950 $newlang =
GETPOST(
'lang_id',
'aZ09');
1953 $newlang =
$object->thirdparty->default_lang;
1955 if (!empty($newlang)) {
1956 $outputlangs =
new Translate(
"", $conf);
1957 $outputlangs->setDefaultLang($newlang);
1962 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1968 unset($_POST [
'prod_entry_mode']);
1970 unset($_POST[
'qty']);
1971 unset($_POST[
'type']);
1972 unset($_POST[
'remise_percent']);
1973 unset($_POST[
'pu']);
1974 unset($_POST[
'price_ht']);
1975 unset($_POST[
'multicurrency_price_ht']);
1976 unset($_POST[
'price_ttc']);
1977 unset($_POST[
'fourn_ref']);
1978 unset($_POST[
'tva_tx']);
1979 unset($_POST[
'label']);
1980 unset($localtax1_tx);
1981 unset($localtax2_tx);
1982 unset($_POST[
'np_marginRate']);
1983 unset($_POST[
'np_markRate']);
1984 unset($_POST[
'dp_desc']);
1985 unset($_POST[
'idprodfournprice']);
1986 unset($_POST[
'units']);
1988 unset($_POST[
'date_starthour']);
1989 unset($_POST[
'date_startmin']);
1990 unset($_POST[
'date_startsec']);
1991 unset($_POST[
'date_startday']);
1992 unset($_POST[
'date_startmonth']);
1993 unset($_POST[
'date_startyear']);
1994 unset($_POST[
'date_endhour']);
1995 unset($_POST[
'date_endmin']);
1996 unset($_POST[
'date_endsec']);
1997 unset($_POST[
'date_endday']);
1998 unset($_POST[
'date_endmonth']);
1999 unset($_POST[
'date_endyear']);
2006 } elseif ($action ==
'classin' && $usercancreate) {
2008 $result =
$object->setProject($projectid);
2009 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
2013 $totalpaid =
$object->getSommePaiement();
2014 $resteapayer =
$object->total_ttc - $totalpaid;
2017 $ventilExportCompta =
$object->getVentilExportCompta();
2019 if (!$ventilExportCompta) {
2022 $idwarehouse =
GETPOST(
'idwarehouse');
2026 $qualified_for_stock_change = 0;
2028 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2030 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2035 $langs->load(
"stocks");
2036 if (!$idwarehouse || $idwarehouse == -1) {
2038 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
2043 $object->setDraft($user, $idwarehouse);
2047 $outputlangs = $langs;
2050 $newlang =
GETPOST(
'lang_id',
'aZ09');
2053 $newlang =
$object->thirdparty->default_lang;
2055 if (!empty($newlang)) {
2056 $outputlangs =
new Translate(
"", $conf);
2057 $outputlangs->setDefaultLang($newlang);
2062 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2071 } elseif ($action ==
'reopen' && $usercancreate) {
2073 $result =
$object->fetch($id);
2076 $result =
$object->setUnpaid($user);
2078 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
2087 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2090 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
2092 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
2093 $trackid =
'sinv'.$object->id;
2094 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2097 $upload_dir = $conf->fournisseur->facture->dir_output;
2098 $permissiontoadd = $usercancreate;
2099 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2102 if ($action ==
'calculate' && $usercancreate) {
2103 $calculationrule =
GETPOST(
'calculationrule');
2107 $result =
$object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0,
$object->thirdparty);
2113 if ($action ==
'update_extras' && $permissiontoeditextra) {
2116 $attribute_name =
GETPOST(
'attribute',
'aZ09');
2119 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
2125 $result =
$object->updateExtraField($attribute_name,
'BILL_SUPPLIER_MODIFY');
2133 $action =
'edit_extras';
2138 if ($action ==
'addcontact' && $usercancreate) {
2139 $result =
$object->fetch($id);
2141 if ($result > 0 && $id > 0) {
2144 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2148 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2151 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2152 $langs->load(
"errors");
2153 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2158 } elseif ($action ==
'swapstatut' && $usercancreate) {
2165 } elseif ($action ==
'deletecontact' && $usercancreate) {
2171 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2185$form =
new Form($db);
2187$bankaccountstatic =
new Account($db);
2195$title =
$object->ref.
" - ".$langs->trans(
'Card');
2196if ($action ==
'create') {
2197 $title = $langs->trans(
"NewSupplierInvoice");
2199$help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
2200llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-fourn-facture page-card');
2203if ($action ==
'create') {
2205 $selectedLines = array();
2207 print
load_fiche_titre($langs->trans(
'NewSupplierInvoice'),
'',
'supplier_invoice');
2211 $currency_code = $conf->currency;
2212 $vat_reverse_charge = 0;
2218 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2219 $currency_code = $societe->multicurrency_code;
2224 if (!empty($origin) && !empty($originid)) {
2226 $element = $subelement = $origin;
2228 if ($element ==
'project') {
2229 $projectid = $originid;
2230 $element =
'projet';
2234 if ($element ==
'order') {
2235 $element = $subelement =
'commande';
2237 if ($element ==
'propal') {
2238 $element =
'comm/propal';
2239 $subelement =
'propal';
2241 if ($element ==
'contract') {
2242 $element = $subelement =
'contrat';
2244 if ($element ==
'order_supplier') {
2246 $subelement =
'fournisseur.commande';
2250 $classname = ucfirst($subelement);
2251 if ($classname ==
'Fournisseur.commande') {
2252 $classname =
'CommandeFournisseur';
2254 $objectsrc =
new $classname($db);
2255 '@phan-var-force Project|Commande|Propal|Facture|Contrat|CommandeFournisseur|CommonObject $objectsrc';
2257 $objectsrc->fetch($originid);
2258 $objectsrc->fetch_thirdparty();
2260 $projectid = (int) $objectsrc->fk_project;
2262 $soc = $objectsrc->thirdparty;
2264 $cond_reglement_id = 0;
2265 $mode_reglement_id = 0;
2269 $transport_mode_id = 0;
2272 if (!empty($objectsrc->cond_reglement_id)) {
2273 $cond_reglement_id = $objectsrc->cond_reglement_id;
2275 if (!empty($objectsrc->mode_reglement_id)) {
2276 $mode_reglement_id = $objectsrc->mode_reglement_id;
2278 if (!empty($objectsrc->fk_account)) {
2279 $fk_account = $objectsrc->fk_account;
2281 if (!empty($objectsrc->transport_mode_id)) {
2282 $transport_mode_id = $objectsrc->transport_mode_id;
2285 if (empty($cond_reglement_id)
2286 || empty($mode_reglement_id)
2287 || empty($fk_account)
2288 || empty($transport_mode_id)
2290 if ($origin ==
'reception') {
2292 if (!isset($objectsrc->supplier_order)) {
2293 $objectsrc->fetch_origin();
2296 if (!empty($objectsrc->origin_object)) {
2297 $originObject = $objectsrc->origin_object;
2298 if (empty($cond_reglement_id) && !empty($originObject->cond_reglement_id)) {
2299 $cond_reglement_id = $originObject->cond_reglement_id;
2301 if (empty($mode_reglement_id) && !empty($originObject->mode_reglement_id)) {
2302 $mode_reglement_id = $originObject->mode_reglement_id;
2304 if (empty($fk_account) && !empty($originObject->fk_account)) {
2305 $fk_account = $originObject->fk_account;
2307 if (empty($transport_mode_id) && !empty($originObject->transport_mode_id)) {
2308 $transport_mode_id = $originObject->transport_mode_id;
2315 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
2316 $cond_reglement_id = $soc->cond_reglement_supplier_id;
2318 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
2319 $mode_reglement_id = $soc->mode_reglement_supplier_id;
2321 if (empty($fk_account) && !empty($soc->fk_account)) {
2322 $fk_account = $soc->fk_account;
2324 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
2325 $transport_mode_id = $soc->transport_mode_id;
2331 if (!empty($objectsrc->multicurrency_code)) {
2332 $currency_code = $objectsrc->multicurrency_code;
2334 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
2335 $currency_tx = $objectsrc->multicurrency_tx;
2340 $dateinvoice = ($datetmp ==
'' ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $datetmp);
2342 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2345 $objectsrc->fetch_optionals();
2346 $object->array_options = $objectsrc->array_options;
2348 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2349 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2350 $vat_reverse_charge = (empty($societe) ?
'' : $societe->vat_reverse_charge);
2351 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2352 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2354 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalInt(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2356 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2358 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2359 $currency_code = $societe->multicurrency_code;
2364 if (empty($cond_reglement_id)) {
2365 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2369 if (empty($mode_reglement_id)) {
2370 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2374 if (!
GETPOST(
'changecompany')) {
2375 if (GETPOSTISSET(
'cond_reglement_id')) {
2376 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
2378 if (GETPOSTISSET(
'mode_reglement_id')) {
2379 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
2381 if (GETPOSTISSET(
'cond_reglement_id')) {
2386 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
2387 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
2389 if ($origin ==
'contrat') {
2390 $langs->load(
"admin");
2391 $text = $langs->trans(
"ToCreateARecurringInvoice");
2392 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"SupplierBills"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
2394 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
2396 print
info_admin($text, 0, 0,
'0',
'opacitymedium').
'<br>';
2399 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2400 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2401 print
'<input type="hidden" name="action" value="add">';
2402 print
'<input type="hidden" name="changecompany" value="0">';
2404 if (!empty($societe->id) && $societe->id > 0) {
2405 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2407 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2408 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2409 if (!empty($currency_tx)) {
2410 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2412 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2417 $parameters = array();
2419 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierInvoice', $parameters, $object, $action);
2420 if (empty($reshook)) {
2421 print
'<table class="border centpercent">';
2424 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
2428 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2429 $invoice_predefined->fetch($fac_recid);
2433 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2436 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2437 $absolute_discount = $societe->getAvailableDiscounts(
null,
'', 0, 1);
2438 print $societe->getNomUrl(1,
'supplier');
2439 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2441 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2442 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company(empty($societe->id) ? 0 : $societe->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth175 widthcentpercentminusxx maxwidth500');
2445 print
'<script type="text/javascript">
2446 $(document).ready(function() {
2447 $("#socid").change(function() {
2448 console.log("We have changed the company - Reload page");
2450 $("input[name=action]").val("create");
2451 $("input[name=changecompany]").val("1");
2452 $("form[name=add]").submit();
2457 if ($fac_recid <= 0) {
2458 print
' <a href="'.DOL_URL_ROOT.
'/societe/card.php?action=create&client=0&fournisseur=1&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create').
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddThirdParty").
'"></span></a>';
2464 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2465 $invoice_predefined->fetch($fac_recid);
2467 $dateinvoice = $invoice_predefined->date_when;
2468 if (empty($projectid)) {
2469 $projectid = $invoice_predefined->fk_project;
2471 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2472 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2473 $fk_account = $invoice_predefined->fk_account;
2474 $note_public = $invoice_predefined->note_public;
2475 $note_private = $invoice_predefined->note_private;
2477 if (!empty($invoice_predefined->multicurrency_code)) {
2478 $currency_code = $invoice_predefined->multicurrency_code;
2480 if (!empty($invoice_predefined->multicurrency_tx)) {
2481 $currency_tx = $invoice_predefined->multicurrency_tx;
2484 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2485 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2486 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2488 $resql = $db->query($sql);
2490 $num = $db->num_rows($resql);
2494 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2496 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2497 print
'<option value="0" selected></option>';
2499 $objp = $db->fetch_object($resql);
2500 print
'<option value="'.$objp->rowid.
'"';
2501 if ($fac_recid == $objp->rowid) {
2503 $exampletemplateinvoice->fetch($fac_recid);
2505 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2511 print
'<script type="text/javascript">
2512 $(document).ready(function() {
2513 $("#fac_rec").change(function() {
2514 console.log("We have changed the template invoice - Reload page");
2516 $("input[name=action]").val("create");
2517 $("form[name=add]").submit();
2531 print
'<tr><td class="fieldrequired">'.$langs->trans(
'RefSupplierBill').
'</td><td><input name="ref_supplier" value="'.(GETPOSTISSET(
'ref_supplier') ?
GETPOST(
'ref_supplier') : (!empty($objectsrc->ref_supplier) ? $objectsrc->ref_supplier :
'')).
'" type="text" spellcheck="false"';
2532 if (!empty($societe->id) && $societe->id > 0) {
2538 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2540 print
'<div class="tagtable">'.
"\n";
2543 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2544 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
'checked').
'> ';
2545 $desc = $form->textwithpicto($tmp.
'<label for="radio_standard">'.$langs->trans(
"InvoiceStandardAsk").
'</label>', $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2547 print
'</div></div>';
2549 if (empty($origin) || (($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') && !empty($originid))) {
2552 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2553 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOSTINT(
'type') == 3 ?
' checked' :
'') .
'> ';
2554 print
'<script type="text/javascript">
2555 jQuery(document).ready(function() {
2556 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2557 jQuery("#radio_standard").prop("checked", true);
2559 jQuery("#typedeposit, #valuedeposit").click(function() {
2560 jQuery("#radio_deposit").prop("checked", true);
2562 jQuery("#typedeposit").change(function() {
2563 console.log("We change type of down payment");
2564 jQuery("#radio_deposit").prop("checked", true);
2565 setRadioForTypeOfInvoice();
2567 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2568 setRadioForTypeOfInvoice();
2570 function setRadioForTypeOfInvoice() {
2571 console.log("Change radio");
2572 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2573 jQuery(".checkforselect").prop("disabled", true);
2574 jQuery(".checkforselect").prop("checked", false);
2576 jQuery(".checkforselect").prop("disabled", false);
2577 jQuery(".checkforselect").prop("checked", true);
2583 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2585 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2586 print
'<table class="nobordernopadding"><tr>';
2590 if ($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') {
2591 print
'<td class="nowrap" style="padding-left: 15px">';
2593 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2594 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2595 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2597 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
2598 $valuedeposit =
GETPOST(
'valuedeposit',
'int');
2599 $deposit_percent =
null;
2600 if ($origin ==
'reception') {
2602 if (!isset($objectsrc->origin_object)) {
2603 $objectsrc->fetch_origin();
2605 if (!empty($objectsrc->origin_object)) {
2606 $deposit_percent = $objectsrc->origin_object->deposit_percent;
2608 } elseif (!empty($objectsrc->deposit_percent)) {
2609 $deposit_percent = $objectsrc->deposit_percent;
2611 if (empty($typedeposit) && !empty($deposit_percent)) {
2612 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
2613 if (!empty($origin_payment_conditions_deposit_percent)) {
2614 $typedeposit =
'variable';
2617 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($deposit_percent)) {
2618 $valuedeposit = $deposit_percent;
2620 print $form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
2622 print
'<td class="nowrap" style="padding-left: 5px">';
2623 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' . $valuedeposit .
'"/>';
2626 print
'</tr></table>';
2628 print
'</div></div>';
2697 if (empty($origin)) {
2698 if (!empty($societe->id) && $societe->id > 0) {
2702 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2709 foreach ($facids as $key => $valarray) {
2710 $newinvoice_static->id = $key;
2711 $newinvoice_static->ref = $valarray [
'ref'];
2712 $newinvoice_static->status = $valarray [
'status'];
2713 $newinvoice_static->statut = $valarray [
'status'];
2714 $newinvoice_static->type = $valarray [
'type'];
2715 $newinvoice_static->paid = $valarray [
'paye'];
2716 $newinvoice_static->paye = $valarray [
'paye'];
2718 $optionsav .=
'<option value="'.$key.
'"';
2720 $optionsav .=
' selected';
2723 $optionsav .= $newinvoice_static->ref;
2724 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
2725 $optionsav .=
'</option>';
2728 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2729 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
2731 $tmp .=
' disabled';
2735 print
'<script type="text/javascript">
2736 jQuery(document).ready(function() {
2737 if (! jQuery("#radio_creditnote").is(":checked"))
2739 jQuery("#credit_note_options").hide();
2741 jQuery("#radio_creditnote").click(function() {
2742 jQuery("#credit_note_options").show();
2744 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2745 jQuery("#credit_note_options").hide();
2749 $text = $tmp.
'<label for="radio_creditnote">'.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
2751 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2753 $text .=
' disabled';
2757 $text .=
'<option value="-1"></option>';
2758 $text .= $optionsav;
2760 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
2762 $text .=
'</select>';
2763 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2766 print
'<div id="credit_note_options" class="clearboth">';
2767 print
' <input type="checkbox" name="invoiceAvoirWithLines" id="invoiceAvoirWithLines" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithPaymentRestAmount\').removeAttr(\'checked\'); }" '.(GETPOSTINT(
'invoiceAvoirWithLines') > 0 ?
'checked' :
'').
' /> ';
2768 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
2769 print
'<br> <input type="checkbox" name="invoiceAvoirWithPaymentRestAmount" id="invoiceAvoirWithPaymentRestAmount" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithLines\').removeAttr(\'checked\'); }" '.(GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') > 0 ?
'checked' :
'').
' /> ';
2770 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
2773 print
'</div></div>';
2776 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2778 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2780 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2"> ';
2782 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
2783 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
2784 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2786 print
'</div></div>'.
"\n";
2797 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
2798 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
2802 if (!empty($societe->id) && $societe->id > 0) {
2804 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2806 $thirdparty = $societe;
2808 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2809 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2815 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth200" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
2819 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
2820 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2821 print $form->selectDate($dateinvoice ? (
int) $dateinvoice :
'',
'', 0, 0, 0,
"add", 1, 1);
2826 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td>';
2827 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2828 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
2833 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2834 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
2835 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth200 widthcentpercentminusx');
2839 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
2840 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2841 print $form->selectDate($datedue,
'ech', 0, 0, 0,
"add", 1, 1);
2845 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2846 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2847 $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'DBIT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
2852 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2854 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
2862 $langs->load(
'projects');
2863 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2864 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects((!
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $societe->id : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
2865 print
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?socid='.(!empty($soc->id) ? $soc->id : 0).
'&action=create&status=1&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create&socid='.(!empty($soc->id) ? $soc->id : 0).($fac_recid > 0 ?
'&fac_rec='.$fac_recid :
'')).
'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans(
"AddProject").
'"></span></a>';
2872 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
2873 print
'<td colspan="3" class="maxwidthonsmartphone">';
2874 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2875 print $form->select_incoterms(GETPOSTISSET(
'incoterm_id') ?
GETPOST(
'incoterm_id',
'alphanohtml') : (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms :
''), GETPOSTISSET(
'location_incoterms') ?
GETPOST(
'location_incoterms',
'alphanohtml') : (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms :
''));
2881 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
2882 print
'<tr><td>' . $langs->trans(
'VATReverseCharge') .
'</td><td>';
2884 if (GETPOSTISSET(
'vat_reverse_charge')) {
2885 $vat_reverse_charge = (
GETPOST(
'vat_reverse_charge',
'alpha') ==
'on' ||
GETPOST(
'vat_reverse_charge',
'alpha') ==
'1') ? 1 : 0;
2886 } elseif ($vat_reverse_charge == 1 || $societe->vat_reverse_charge == 1 || ($societe->country_code !=
'FR' &&
isInEEC($societe) && !empty($societe->tva_intra))) {
2887 $vat_reverse_charge = 1;
2889 $vat_reverse_charge = 0;
2892 print
'<input type="checkbox" name="vat_reverse_charge"'. (!empty($vat_reverse_charge) ?
' checked ' :
'') .
'>';
2899 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
2900 print
'<td class="maxwidthonsmartphone">';
2901 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
2902 $used_currency_code = $currency_code;
2903 if (!
GETPOST(
'changecompany')) {
2904 $used_currency_code = GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code;
2906 print $form->selectMultiCurrency($used_currency_code,
'multicurrency_code');
2912 if ($fac_recid > 0) {
2913 $dateexample = $dateinvoice;
2914 if (empty($dateexample)) {
2917 $substitutionarray = array(
2918 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
2919 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
2920 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
2921 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
2922 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
2923 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
2924 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
2925 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
2926 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
2927 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
2928 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
2931 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
2932 foreach ($substitutionarray as $key => $val) {
2933 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
2935 $htmltext .=
'</i>';
2940 $langs->loadLangs(array(
"intracommreport"));
2941 print
'<!-- If module intracomm on -->'.
"\n";
2942 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
2943 $form->selectTransportMode(GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
2947 if (empty($reshook)) {
2948 print
$object->showOptionals($extrafields,
'create');
2953 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
2954 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
2959 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2961 $doleditor =
new DolEditor(
'note_public', (GETPOSTISSET(
'note_public') ?
GETPOST(
'note_public',
'restricthtml') : $note_public),
'', 80,
'dolibarr_notes',
'In', false, false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
2962 print $doleditor->Create(1);
2968 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
2970 $doleditor =
new DolEditor(
'note_private', (GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') : $note_private),
'', 80,
'dolibarr_notes',
'In', false, false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
2971 print $doleditor->Create(1);
2977 if (!empty($objectsrc)) {
2978 print
"\n<!-- ".$classname.
" info -->";
2980 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2981 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2982 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2983 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2984 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2986 $txt = $langs->trans($classname);
2987 if ($classname ==
'CommandeFournisseur') {
2988 $langs->load(
'orders');
2989 $txt = $langs->trans(
"SupplierOrder");
2991 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
2993 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'invoice_supplier');
2995 if (isset($objectsrc->linkedObjects[
'invoice_supplier'])) {
2996 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
2998 $invoice_supplier = [];
3000 '@phan-var-force null|FactureFournisseur[] $invoice_supplier';
3003 if (is_array($invoice_supplier)) {
3004 $cntinvoice = count($invoice_supplier);
3006 if ($cntinvoice >= 1) {
3008 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
3013 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
3014 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
3015 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
3016 print
'<tr><td>'.$langs->transcountry(
"AmountLT1",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
3019 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
3020 print
'<tr><td>'.$langs->transcountry(
"AmountLT2",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
3022 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
3025 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
'</td></tr>';
3026 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
"</td></tr>";
3027 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
"</td></tr>";
3032 $parameters = array();
3033 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
3034 print $hookmanager->resPrint;
3042 print $form->buttonsSaveCancel(
"CreateDraft");
3045 if (!empty($objectsrc)) {
3048 $title = $langs->trans(
'ProductsAndServices');
3051 print
'<div class="div-table-responsive-no-min">';
3052 print
'<table class="noborder centpercent">';
3054 $objectsrc->printOriginLinesList(
'', $selectedLines);
3062 if ($id > 0 || !empty($ref)) {
3068 $result =
$object->fetch($id, $ref);
3073 $result =
$object->fetch_thirdparty();
3079 $societe =
$object->thirdparty;
3081 $totalpaid =
$object->getSommePaiement();
3082 $totalcreditnotes =
$object->getSumCreditNotesUsed();
3083 $totaldeposits =
$object->getSumDepositsUsed();
3091 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
3094 $multicurrency_resteapayer = 0;
3096 $multicurrency_totalpaid =
$object->getSommePaiement(1);
3097 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
3098 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
3099 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
3103 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code != $conf->currency) {
3104 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
3111 $resteapayeraffiche = $resteapayer;
3114 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
3115 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
3117 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
3118 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
3121 $absolute_discount = $societe->getAvailableDiscounts(
null, $filterabsolutediscount, 0, 1);
3122 $absolute_creditnote = $societe->getAvailableDiscounts(
null, $filtercreditnote, 0, 1);
3123 $absolute_discount =
price2num($absolute_discount,
'MT');
3124 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
3128 $objectidnext =
$object->getIdReplacingInvoice();
3131 $titre = $langs->trans(
'SupplierInvoice');
3133 print
dol_get_fiche_head($head,
'card', $titre, -1,
'supplier_invoice', 0,
'',
'', 0,
'', 1);
3138 if ($action ==
'converttoreduc') {
3141 $type_fac =
'ExcessPaid';
3143 $type_fac =
'CreditNote';
3145 $type_fac =
'Deposit';
3147 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
3148 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
3149 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
3153 if ($action ==
'clone') {
3155 $formquestion = array(
3156 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplierBill"),
'value' => $langs->trans(
"CopyOf").
' '.
$object->ref_supplier),
3157 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
3160 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
3164 if ($action ==
'valid') {
3166 if (preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) {
3168 $numref =
$object->getNextNumRef($societe);
3170 $numref = (string)
$object->ref;
3177 $text = $langs->trans(
'ConfirmValidateBill', $numref);
3185 $formquestion = array();
3187 $qualified_for_stock_change = 0;
3189 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3191 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3195 $langs->load(
"stocks");
3196 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3199 $warehouse_array = $warehouse->list_array();
3200 if (count($warehouse_array) == 1) {
3202 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3205 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3207 $formquestion = array(
3208 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3212 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
3217 if ($action ==
'edit') {
3218 $formquestion = array();
3220 $qualified_for_stock_change = 0;
3222 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3224 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3227 $langs->load(
"stocks");
3228 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3231 $warehouse_array = $warehouse->list_array();
3232 if (count($warehouse_array) == 1) {
3234 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3237 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3239 $formquestion = array(
3240 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3243 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill',
$object->ref),
'confirm_edit', $formquestion, 1, 1);
3247 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
3248 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'', 0, 1);
3251 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
3255 $close[$i][
'code'] =
'discount_vat';
3257 $close[$i][
'code'] =
'badsupplier';
3259 $close[$i][
'code'] =
'other';
3263 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
3265 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3267 $close[$i][
'label'] = $langs->trans(
"Other");
3271 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3273 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3275 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
3278 $arrayreasons = array();
3279 foreach ($close as $key => $val) {
3280 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
3284 $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'));
3286 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
3290 if ($action ==
'canceled') {
3292 $close[1][
'code'] =
'badsupplier';
3293 $close[2][
'code'] =
'abandon';
3295 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3296 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
3298 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier",
$object->ref), $close[1][
'label'], 1);
3299 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
3301 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
3302 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
3305 $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'));
3307 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 280);
3311 if ($action ==
'delete') {
3312 $formquestion = array();
3314 $qualified_for_stock_change = 0;
3316 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3318 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3322 $langs->load(
"stocks");
3323 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3326 $warehouse_array = $warehouse->list_array();
3328 $selectwarehouse =
'<span class="questionrevertstock hidden">';
3329 if (count($warehouse_array) == 1) {
3331 $selectwarehouse .=
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3334 $selectwarehouse .= $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3336 $selectwarehouse .=
'</span>';
3338 $selectyesno = array(0 => $langs->trans(
'No'), 1 => $langs->trans(
'Yes'));
3340 print
'<script type="text/javascript">
3341 $(document).ready(function() {
3342 $("#revertstock").change(function() {
3343 if(this.value > 0) {
3344 $(".questionrevertstock").removeClass("hidden");
3346 $(".questionrevertstock").addClass("hidden");
3352 $formquestion = array(
3353 array(
'type' =>
'select',
'name' =>
'revertstock',
'label' => $langs->trans(
"RevertProductsToStock"),
'select_show_empty' => 0,
'values' => $selectyesno),
3354 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $selectwarehouse,
'tdclass' =>
'questionrevertstock hidden')
3358 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete', $formquestion, 1, 1);
3360 if ($action ==
'deletepayment') {
3361 $payment_id =
GETPOST(
'paiement_id');
3362 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
3366 if ($action ==
'ask_deleteline') {
3367 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
3370 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
3371 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
3372 if (empty($reshook)) {
3373 $formconfirm .= $hookmanager->resPrint;
3374 } elseif ($reshook > 0) {
3375 $formconfirm = $hookmanager->resPrint;
3383 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
3385 $morehtmlref =
'<div class="refidno">';
3387 $morehtmlref .= $form->editfieldkey(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, (
int) $usercancreate,
'string',
'', 0, 1);
3388 $morehtmlref .= $form->editfieldval(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
3390 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'supplier');
3392 $morehtmlref .=
' <div class="inline-block valignmiddle">(<a class="valignmiddle" href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.((int)
$object->thirdparty->id).
'">'.$langs->trans(
"OtherBills").
'</a>)</div>';
3396 $langs->load(
"projects");
3397 $morehtmlref .=
'<br>';
3398 if ($permissiontoadd) {
3399 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
3400 if ($action !=
'classify') {
3401 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.((int)
$object->id).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
3403 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (!
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ?
$object->socid : -1), (string)
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
3405 if (!empty(
$object->fk_project)) {
3407 $proj->fetch(
$object->fk_project);
3408 $morehtmlref .= $proj->getNomUrl(1);
3410 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
3415 $morehtmlref .=
'</div>';
3417 $object->totalpaid = $totalpaid;
3419 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
3422 $parameters = array();
3424 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierInvoice', $parameters, $object, $action);
3425 if (empty($reshook)) {
3426 print
'<div class="fichecenter">';
3427 print
'<div class="fichehalfleft">';
3428 print
'<div class="underbanner clearboth"></div>';
3430 print
'<table class="border tableforfield centpercent">';
3433 print
'<tr><td>'.$langs->trans(
'Type').
'</td><td>';
3434 print
'<span class="badgeneutral">';
3438 print
' '.$object->getSubtypeLabel(
'facture_fourn');
3442 $facreplaced->fetch(
$object->fk_facture_source);
3443 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
3446 if (
$object->fk_facture_source > 0) {
3448 $facusing->fetch(
$object->fk_facture_source);
3449 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
3451 $langs->load(
"errors");
3452 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"WarningCorrectedInvoiceNotFound").
'</span>';
3457 $object->getListIdAvoirFromInvoice();
3459 if (!empty(
$object->creditnote_ids)) {
3460 $invoicecredits = array();
3461 foreach (
$object->creditnote_ids as $invoiceid) {
3463 $creditnote->fetch($invoiceid);
3464 $invoicecredits[] = $creditnote->getNomUrl(1);
3466 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
3469 if (isset($objectidnext) && $objectidnext > 0) {
3472 $facthatreplace->fetch($objectidnext);
3473 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
3477 $result = $discount->fetch(0, 0,
$object->id);
3479 print
' <span class="opacitymediumbycolor paddingleft">';
3480 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
3481 $s = str_replace(
'{s1}',
$object->getLibType(1), $s);
3482 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
3484 print
'</span><br>';
3488 if (
$object->fk_fac_rec_source > 0) {
3490 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
3492 print
' <span class="opacitymediumbycolor paddingleft">';
3493 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->title).
'</a>';
3494 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
3504 print
'<!-- Discounts -->'.
"\n";
3505 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
3508 $thirdparty = $societe;
3510 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3516 print
'<td>'.$form->editfieldkey(
"Label",
'label',
$object->label, $object, (
int) $usercancreate).
'</td>';
3517 print
'<td>'.$form->editfieldval(
"Label",
'label',
$object->label, $object, $usercancreate).
'</td>';
3525 print $form->editfieldkey(
"DateInvoice",
'datef', (
string)
$object->date,
$object, (int) $form_permission,
'datepicker');
3526 print
'</td><td colspan="3">';
3527 print $form->editfieldval(
"Date",
'datef',
$object->date, $object, $form_permission,
'datepicker');
3533 print $form->editfieldkey(
"DatePointOfTax",
'date_pointoftax', (
string)
$object->date_pointoftax,
$object, (int) $pointoftax_form_permission,
'datepicker');
3534 print
'</td><td colspan="3">';
3535 print $form->editfieldval(
"DatePointOfTax",
'date_pointoftax',
$object->date_pointoftax, $object, $pointoftax_form_permission,
'datepicker');
3540 $langs->load(
'bills');
3541 print
'<tr><td class="nowrap">';
3542 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3543 print $langs->trans(
'PaymentConditions');
3545 if ($action !=
'editconditions' && $form_permission) {
3546 print
'<td class="right"><a class="editfielda reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=editconditions&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->trans(
'SetConditions'), 1).
'</a></td>';
3548 print
'</tr></table>';
3550 if ($action ==
'editconditions') {
3551 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
3553 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
3560 print $form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', (
string)
$object->date_echeance, $object, (
int) $form_permission,
'datepicker');
3562 print $form->editfieldval(
"DateMaxPayment",
'date_lim_reglement',
$object->date_echeance, $object, $form_permission,
'datepicker');
3563 if ($action !=
'editdate_lim_reglement' &&
$object->hasDelay()) {
3569 $langs->load(
'bills');
3570 print
'<tr><td class="nowrap">';
3571 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3572 print $langs->trans(
'PaymentMode');
3574 if ($action !=
'editmode' && $form_permission) {
3575 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->trans(
'SetMode'), 1).
'</a></td>';
3577 print
'</tr></table>';
3579 if ($action ==
'editmode') {
3580 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3582 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'none');
3588 print
'<tr><td class="nowrap">';
3589 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3590 print $langs->trans(
'BankAccount');
3592 if ($action !=
'editbankaccount' && $usercancreate) {
3593 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>';
3595 print
'</tr></table>';
3597 if ($action ==
'editbankaccount') {
3598 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
3600 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
3608 print
'<tr><td class="nowrap">';
3609 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3610 print $langs->trans(
'VATReverseCharge');
3612 if ($action !=
'editvatreversecharge' && $usercancreate) {
3613 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editvatreversecharge&id='.
$object->id.
'">'.
img_edit($langs->trans(
'SetVATReverseCharge'), 1).
'</a></td>';
3615 print
'</tr></table>';
3617 if ($action ==
'editvatreversecharge') {
3618 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
3619 print
'<input type="hidden" name="action" value="setvatreversecharge">';
3620 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3622 print
'<input type="checkbox" name="vat_reverse_charge"' . (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
'>';
3624 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
3627 print
'<input type="checkbox" name="vat_reverse_charge"'. (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
' disabled>';
3635 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3636 print $langs->trans(
'IncotermLabel');
3637 print
'<td><td class="right">';
3638 if ($usercancreate) {
3639 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
3643 print
'</td></tr></table>';
3646 if ($action !=
'editincoterm') {
3647 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
3649 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
3656 $langs->loadLangs(array(
"intracommreport"));
3657 print
'<!-- If module intracomm on -->'.
"\n";
3659 print
'<table class="nobordernopadding centpercent"><tr><td>';
3660 print $langs->trans(
'IntracommReportTransportMode');
3662 if ($action !=
'edittransportmode' && ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"))) {
3663 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edittransportmode&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit().
'</a></td>';
3665 print
'</tr></table>';
3668 if ($action ==
'edittransportmode') {
3669 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'transport_mode_id', 1, 1);
3671 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'none');
3679 print
'<table class="nobordernopadding centpercent"><tr><td>';
3680 print $langs->trans(
"Categories");
3681 print
'<td><td class="right">';
3682 if ($usercancreate) {
3683 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
3687 print
'</td></tr></table>';
3690 if ($action ==
'edittags') {
3691 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
3692 print
'<input type="hidden" name="action" value="settags">';
3693 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3694 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
3695 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
3698 print $form->showCategories(
$object->id, Categorie::TYPE_SUPPLIER_INVOICE, 1);
3706 if (
$object->status != $object::STATUS_DRAFT) {
3710 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
3715 print
'<div class="fichehalfright">';
3716 print
'<div class="underbanner clearboth"></div>';
3718 print
'<table class="border tableforfield centpercent">';
3720 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
3723 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
3724 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
3726 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3731 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
3732 print
'<td class="nowrap amountcard right">';
3733 if (
GETPOST(
'calculationrule')) {
3734 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
3736 $calculationrule = (!
getDolGlobalString(
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND_SUPPLIER') ?
'totalofround' :
'roundoftotal');
3738 if ($calculationrule ==
'totalofround') {
3739 $calculationrulenum = 1;
3741 $calculationrulenum = 2;
3744 if (
$object->getVentilExportCompta() == 0) {
3745 $s =
'<span class="hideonsmartphone opacitymedium">' . $langs->trans(
"ReCalculate") .
' </span>';
3746 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=totalofround">' . $langs->trans(
"Mode1") .
'</a>';
3748 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=roundoftotal">' . ($conf->dol_optimize_smallscreen ?
"2" : $langs->trans(
"Mode2")) .
'</a>';
3749 print
'<div class="inline-block">';
3750 print $form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum) .
'<br>' . $langs->trans(
"CalculationRuleDescSupplier"), 2, 1,
img_picto(
'',
'help',
'class="paddingleft paddingright"'),
'', 3,
'', 0,
'recalculate');
3751 print
' ';
3754 print
'<span class="nowraponall">'.price(
$object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).
'</span>';
3757 print
'<td class="nowraponall amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3761 if ($societe->localtax1_assuj ==
"1") {
3763 print
'<td>' . $langs->transcountry(
"AmountLT1", $societe->country_code) .
'</td>';
3764 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency) .
'</td>';
3767 if ($societe->localtax2_assuj ==
"1") {
3769 print
'<td>' . $langs->transcountry(
"AmountLT2", $societe->country_code) .
'</td>';
3770 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency) .
'</td>';
3775 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
3776 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
3778 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3811 if ($societe->localtax1_assuj ==
"1") {
3814 if ($societe->localtax2_assuj ==
"1") {
3818 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
3819 $sql .=
' c.id as payment_type, c.code as payment_code,';
3820 $sql .=
' pf.amount,';
3821 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
3822 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
3823 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
3824 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
3825 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
3826 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
3827 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
3828 $sql .=
' ORDER BY p.datep, p.tms';
3830 $result = $db->query($sql);
3832 $num = $db->num_rows($result);
3835 print
'<div class="div-table-responsive-no-min">';
3836 print
'<table class="noborder paymenttable centpercent">';
3837 print
'<tr class="liste_titre">';
3839 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
3840 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
3842 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
3847 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
3852 $objp = $db->fetch_object($result);
3854 $paymentstatic->id = $objp->rowid;
3855 $paymentstatic->datepaye = $db->jdate($objp->dp);
3856 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
3857 $paymentstatic->num_payment = $objp->num_payment;
3859 $paymentstatic->paiementcode = $objp->payment_code;
3860 $paymentstatic->type_code = $objp->payment_code;
3861 $paymentstatic->type_label = $objp->payment_type;
3863 print
'<tr class="oddeven">';
3864 print
'<td class="nowraponall">';
3865 print $paymentstatic->getNomUrl(1);
3867 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
'</td>';
3868 $s = $form->form_modes_reglement(
'', $objp->payment_type,
'none',
'', 1, 0,
'', 1).
' '.$objp->num_payment;
3869 print
'<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).
'">';
3873 $bankaccountstatic->id = $objp->baid;
3874 $bankaccountstatic->ref = $objp->baref;
3875 $bankaccountstatic->label = $objp->baref;
3876 $bankaccountstatic->number = $objp->banumber;
3879 $bankaccountstatic->account_number = $objp->account_number;
3882 $accountingjournal->fetch($objp->fk_accountancy_journal);
3883 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
3886 print
'<td class="right nowraponall">';
3887 if ($objp->baid > 0) {
3888 print $bankaccountstatic->getNomUrl(1,
'transactions');
3893 print
'<td class="center">';
3895 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
3901 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
3903 $totalpaid += $objp->amount;
3907 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
3933 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
3934 print
'<span class="opacitymedium">';
3936 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
3938 print $langs->trans(
'AlreadyPaid');
3943 print
'<td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td>';
3947 $resteapayeraffiche = $resteapayer;
3949 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
3952 $creditnoteamount = 0;
3955 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
3956 $sql .=
" re.description, re.fk_invoice_supplier_source";
3957 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
3958 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
3959 $resql = $db->query($sql);
3961 $num = $db->num_rows($resql);
3965 $obj = $db->fetch_object($resql);
3966 $invoice->fetch($obj->fk_invoice_supplier_source);
3967 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3969 print $langs->trans(
"CreditNote").
' ';
3972 print $langs->trans(
"Deposit").
' ';
3974 print $invoice->getNomUrl(0);
3977 print
'<td class="right">';
3978 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&discountid='.$obj->rowid.
'">';
3979 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
3983 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
3987 $creditnoteamount += $obj->amount_ttc;
3990 $depositamount += $obj->amount_ttc;
3999 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4000 print
'<span class="opacitymedium">';
4001 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
4005 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4007 $resteapayeraffiche = 0;
4008 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4012 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4013 print
'<span class="opacitymedium">';
4014 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
4018 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4021 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4025 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4026 print
'<span class="opacitymedium">';
4027 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
4031 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4033 $resteapayeraffiche = 0;
4034 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4038 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4039 $text = $langs->trans(
"HelpAbandonOther");
4041 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
4043 print
'<span class="opacitymedium">';
4045 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
4049 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4051 $resteapayeraffiche = 0;
4052 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4056 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4057 print
'<span class="opacitymedium">';
4058 print $langs->trans(
"Billed");
4062 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
4066 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4067 print
'<span class="opacitymedium">';
4068 print $langs->trans(
'RemainderToPay');
4069 if ($resteapayeraffiche < 0) {
4070 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4075 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
4080 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4081 print
'<span class="opacitymedium">';
4082 print $langs->trans(
'RemainderToPayMulticurrency');
4083 if ($resteapayeraffiche < 0) {
4084 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4089 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price(
price2num($multicurrency_resteapayer,
'MT'), 0, $langs, 1, -1, -1,
$object->multicurrency_code).
'</td>';
4093 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4096 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4097 print $langs->trans(
'AlreadyPaidBack');
4100 print
'<td class="right">'.price($sign * $totalpaid).
'</td>';
4104 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">'.$langs->trans(
"Billed").
'</td>';
4106 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
4110 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4111 print
'<span class="opacitymedium">';
4112 print $langs->trans(
'RemainderToPayBack');
4113 if ($resteapayeraffiche > 0) {
4114 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4119 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
4124 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4125 print
'<span class="opacitymedium">';
4126 print $langs->trans(
'RemainderToPayBackMulticurrency');
4127 if ($resteapayeraffiche > 0) {
4128 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4133 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcomplete)).
'">'.(!empty(
$object->multicurrency_code) ?
$object->multicurrency_code : $conf->currency).
' '.
price(
price2num($sign *
$object->multicurrency_tx * $resteapayeraffiche,
'MT')).
'</td>';
4149 print
'<div class="clearboth"></div><br>';
4152 $blocname =
'contacts';
4153 $title = $langs->trans(
'ContactsAddresses');
4154 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4159 $blocname =
'notes';
4160 $title = $langs->trans(
'Notes');
4161 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4168 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
4169 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4170 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
4171 print
'<input type="hidden" name="mode" value="">';
4172 print
'<input type="hidden" name="page_y" value="">';
4173 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
4174 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
4175 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4178 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
4181 print
'<div class="div-table-responsive-no-min">';
4182 print
'<table id="tablelines" class="noborder noshadow centpercent">';
4184 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
4187 $inputalsopricewithtax = 1;
4188 $senderissupplier = 2;
4189 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY')) {
4190 $senderissupplier =
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY');
4195 $object->printObjectLines($action, $societe,
$mysoc, $lineid, 1);
4202 if ($action !=
'editline') {
4205 $parameters = array();
4206 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
4210 if (empty($reshook)) {
4224 if ($action !=
'presend') {
4227 print
'<div class="tabsAction">';
4229 $parameters = array();
4230 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
4232 if (empty($reshook)) {
4236 $ventilExportCompta =
$object->getVentilExportCompta();
4238 if ($ventilExportCompta == 0) {
4239 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=edit&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
4241 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
4246 $result = $discount->fetch(0, 0,
$object->id);
4253 if (!$objectidnext &&
$object->close_code !=
'replaced' && $usercancreate) {
4254 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
4256 if ($usercancreate) {
4257 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
4259 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
4269 if ($usercanvalidate) {
4270 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken().
'"';
4271 print
'>'.$langs->trans(
'Validate').
'</a>';
4273 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
4274 print
'>'.$langs->trans(
'Validate').
'</a>';
4280 if (empty($user->socid)) {
4283 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' =>
$object->id,
'action' =>
'presend',
'mode' =>
'init'],
true).
'#formmailbeforetitle',
'');
4292 $langs->load(
"withdrawals");
4293 if ($resteapayer > 0) {
4294 if ($usercancreatecreditransfer) {
4295 if (!$objectidnext &&
$object->close_code !=
'replaced') {
4296 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/facture/prelevement.php?facid='.
$object->id.
'&type=bank-transfer" title="'.
dol_escape_htmltag($langs->trans(
"MakeBankTransferOrder")).
'">'.$langs->trans(
"MakeBankTransferOrder").
'</a>';
4298 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeBankTransferOrder').
'</span>';
4310 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/paiement.php?facid='.
$object->id.
'&action=create'.(
$object->fk_account > 0 ?
'&accountid='.$object->fk_account :
'').
'">'.$langs->trans(
'DoPayment').
'</a>';
4317 if ($resteapayer == 0) {
4318 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
4319 } elseif ($usercancreate) {
4320 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
4326 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
4330 && (
getDolGlobalString(
'SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') ||
$object->getSommePaiement() == 0)
4332 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'" title="'.
dol_escape_htmltag($langs->trans(
"ConfirmConvertToReducSupplier2")).
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
4336 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
4347 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaid').
'</a>';
4352 if ($totalpaid > 0 || $totalcreditnotes > 0) {
4354 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
4357 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=canceled&token='.
newToken().
'">'.$langs->trans(
'ClassifyCanceled').
'</a>';
4369 if (!$objectidnext) {
4370 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 :
'').
'">'.$langs->trans(
"CreateCreditNote").
'</a>';
4375 if ($action !=
'edit' && $usercancreate) {
4376 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=clone&socid='.
$object->socid.
'&token='.
newToken().
'">'.$langs->trans(
'ToClone').
'</a>';
4381 if (!$objectidnext && count(
$object->lines) > 0) {
4382 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.
$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
4387 if ($action !=
'confirm_edit' && $usercandelete) {
4388 $isErasable =
$object->is_erasable();
4390 $enableDelete =
false;
4392 $params = (empty($conf->use_javascript_ajax) ? array() : array(
'attr' => array(
'class' =>
'reposition')));
4394 if ($isErasable == -4) {
4395 $htmltooltip = $langs->trans(
"DisabledBecausePayments");
4396 } elseif ($isErasable == -3) {
4397 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastSituationInvoice");
4398 } elseif ($isErasable == -2) {
4399 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastInvoice");
4400 } elseif ($isErasable == -1) {
4401 $htmltooltip = $langs->trans(
"DisabledBecauseDispatchedInBookkeeping");
4402 } elseif ($isErasable <= 0) {
4403 $htmltooltip = $langs->trans(
"DisabledBecauseNotErasable");
4405 $enableDelete =
true;
4408 print
dolGetButtonAction($htmltooltip, $langs->trans(
"Delete"),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken(), (
string)
$object->id, $enableDelete, $params);
4412 if ($action !=
'confirm_edit') {
4413 print
'<div class="fichecenter"><div class="fichehalfleft">';
4419 $subdir =
get_exdir(
$object->id, 2, 0, 0, $object,
'invoice_supplier').$ref;
4420 $filedir = $conf->fournisseur->facture->dir_output.
'/'.$subdir;
4421 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.
$object->id;
4422 $genallowed = $usercanread;
4423 $delallowed = $usercancreate;
4427 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, (
int) $genallowed, (
int) $delallowed, $modelpdf, $genifempty, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
4428 $somethingshown = $formfile->numoffiles;
4431 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice_supplier'), 1);
4432 $linktoelem = $tmparray[
'linktoelem'];
4433 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
4434 print $htmltoenteralink;
4436 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
4438 print
'</div><div class="fichehalfright">';
4441 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
4443 $somethingshown = $formactions->showactions($object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
4445 print
'</div></div>';
4451 if (
GETPOST(
'modelselected')) {
4452 $action =
'presend';
4456 $modelmail =
'invoice_supplier_send';
4457 $defaulttopic =
'SendBillRef';
4458 $diroutput = $conf->fournisseur->facture->dir_output;
4459 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
4460 $trackid =
'sinv'.$object->id;
4462 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage bank accounts.
Class to manage accounting journals.
const TYPE_PROFORMA
Proforma invoice.
const TYPE_SITUATION
Situation invoice.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_STANDARD
Standard invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const STATUS_CLOSED
Classified paid.
Class to manage invoice templates.
Class to manage payments for supplier invoices.
Class ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage line invoices.
Class to manage translations.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
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, $tz='')
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
facturefourn_prepare_head(FactureFournisseur $object)
Prepare array with list of tabs.
dol_now($mode='gmt')
Return date for now.
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolBuildUrl($url, $params=[], $addtoken=false)
Return path of url.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
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...
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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...
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.