41require
'../../main.inc.php';
50require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_invoice/modules_facturefournisseur.php';
54require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
55require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture-rec.class.php';
56require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
57require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
58require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
59require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
60require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
61require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
63 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
64 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
67 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
68 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
72 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
75 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
78$langs->loadLangs(array(
'bills',
'compta',
'suppliers',
'companies',
'products',
'banks',
'admin'));
80 $langs->load(
'incoterm');
85$action =
GETPOST(
'action',
'aZ09');
88$cancel =
GETPOST(
'cancel',
'alpha');
89$backtopage =
GETPOST(
'backtopage',
'alpha');
90$backtopageforcancel =
'';
94$origin =
GETPOST(
'origin',
'alpha');
105$hookmanager->initHooks(array(
'invoicesuppliercard',
'globalcard'));
111$extrafields->fetch_name_optionals_label(
$object->table_element);
114if ($id > 0 || !empty($ref)) {
115 $ret =
$object->fetch($id, $ref);
119 $ret =
$object->fetch_thirdparty();
127if (!empty($user->socid)) {
128 $socid = $user->socid;
132$result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture',
'fk_soc',
'rowid', $isdraft);
135$usercanread = ($user->hasRight(
"fournisseur",
"facture",
"lire") || $user->hasRight(
"supplier_invoice",
"lire"));
136$usercancreate = ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"));
137$usercandelete = (($user->hasRight(
"fournisseur",
"facture",
"supprimer") || $user->hasRight(
"supplier_invoice",
"supprimer")) || ($usercancreate &&
$object->is_erasable() == 1));
138$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
141$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"validate")));
142$usercansend = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"send"));
143$usercancreatecreditransfer = $user->hasRight(
'paymentbybanktransfer',
'create');
146$permissionnote = $usercancreate;
147$permissiondellink = $usercancreate;
148$permissiontoedit = $usercancreate;
149$permissiontoadd = $usercancreate;
150$permissiontodelete = $usercandelete;
151$permissiontoeditextra = $permissiontoadd;
152if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
154 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
165$parameters = array(
'socid' => $socid);
166$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
171if (empty($reshook)) {
172 $backurlforlist =
dolBuildUrl(DOL_URL_ROOT.
'/fourn/facture/list.php');
174 if (empty($backtopage) || ($cancel && empty($id))) {
175 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
176 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
177 $backtopage = $backurlforlist;
179 $backtopage =
dolBuildUrl(DOL_URL_ROOT.
'/fourn/facture/card.php', [
'id' => ((!empty($id) && $id > 0) ? $id :
'__ID__')]);
185 if (!empty($backtopageforcancel)) {
186 header(
"Location: ".$backtopageforcancel);
188 } elseif (!empty($backtopage)) {
189 header(
"Location: ".$backtopage);
195 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
197 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
199 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
202 if (
GETPOST(
'linkedOrder') && empty($cancel) && $id > 0 && $permissiontoadd) {
205 $result =
$object->add_object_linked(
'order_supplier',
GETPOSTINT(
'linkedOrder'));
209 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
211 '@phan-var-force FactureFournisseur $objectutil';
213 if (
GETPOST(
'newsupplierref',
'alphanohtml')) {
214 $objectutil->ref_supplier =
GETPOST(
'newsupplierref',
'alphanohtml');
218 $result = $objectutil->createFromClone($user, $id);
220 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
223 $langs->load(
"errors");
227 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
228 $idwarehouse =
GETPOST(
'idwarehouse');
233 $qualified_for_stock_change = 0;
235 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
237 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
242 $langs->load(
"stocks");
243 if (!$idwarehouse || $idwarehouse == -1) {
245 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
253 $result =
$object->validate($user,
'', $idwarehouse);
260 $categories =
GETPOST(
'categories',
'array:int');
261 if (method_exists($object,
'setCategories')) {
262 $object->setCategories($categories);
270 $outputlangs = $langs;
273 $newlang =
GETPOST(
'lang_id',
'aZ09');
276 $newlang =
$object->thirdparty->default_lang;
278 if (!empty($newlang)) {
280 $outputlangs->setDefaultLang($newlang);
285 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
292 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $permissiontodelete) {
296 $isErasable =
$object->is_erasable();
298 if ($usercandelete && $isErasable > 0) {
299 $revertstock =
GETPOST(
'revertstock');
304 $qualified_for_stock_change = 0;
306 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
308 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
313 $langs->load(
"stocks");
314 if (!$idwarehouse || $idwarehouse == -1) {
316 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
319 $result =
$object->setDraft($user, $idwarehouse);
328 $result =
$object->delete($user);
330 header(
'Location: list.php?restore_lastsearch_values=1');
337 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
339 $result =
$object->deleteLine($lineid);
359 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
366 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
369 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
370 $discount->unlink_invoice();
371 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercancreate) {
373 $result =
$object->setPaid($user);
377 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercancreate) {
380 $close_code =
GETPOST(
"close_code",
'restricthtml');
381 $close_note =
GETPOST(
"close_note",
'restricthtml');
383 $result =
$object->setPaid($user, $close_code, $close_note);
388 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
390 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
393 $close_code =
GETPOST(
"close_code",
'restricthtml');
394 $close_note =
GETPOST(
"close_note",
'restricthtml');
396 $result =
$object->setCanceled($user, $close_code, $close_note);
401 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
406 if ($action ==
'setref_supplier' && $usercancreate) {
409 if (
$object->update($user) < 0) {
413 $outputlangs = $langs;
416 $newlang =
GETPOST(
'lang_id',
'aZ09');
419 $newlang =
$object->thirdparty->default_lang;
421 if (!empty($newlang)) {
423 $outputlangs->setDefaultLang($newlang);
427 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
433 if ($action ==
'setconditions' && $usercancreate) {
435 $object->cond_reglement_code = 0;
436 $object->cond_reglement_id = 0;
451 $new_date_echeance =
$object->calculate_date_lim_reglement();
452 if ($new_date_echeance) {
453 $object->date_echeance = $new_date_echeance;
458 $result =
$object->update($user);
470 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
473 } elseif ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
476 } elseif ($action ==
'setmode' && $usercancreate) {
479 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
481 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
482 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
485 } elseif ($action ==
'setbankaccount' && $usercancreate) {
488 } elseif ($action ==
'setvatreversecharge' && $usercancreate) {
490 $vatreversecharge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
491 $result =
$object->setVATReverseCharge($vatreversecharge);
494 if ($action ==
'settransportmode' && $usercancreate) {
497 } elseif ($action ==
'setlabel' && $usercancreate) {
501 $result =
$object->update($user);
505 } elseif ($action ==
'setdatef' && $usercancreate) {
509 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
511 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
518 $date_echence_calc =
$object->calculate_date_lim_reglement();
519 if (!empty(
$object->date_echeance)) {
520 $object->date_echeance = $date_echence_calc;
526 $result =
$object->update($user);
530 } elseif ($action ==
'setdate_lim_reglement' && $usercancreate) {
535 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
537 $result =
$object->update($user);
541 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
557 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
559 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
563 $remaintopay =
$object->getRemainToPay(0);
567 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
571 $result = $discount->link_to_invoice(0, $id);
578 $newremaintopay =
$object->getRemainToPay(0);
579 if ($newremaintopay == 0) {
590 $outputlangs = $langs;
593 $newlang =
GETPOST(
'lang_id',
'aZ09');
596 $newlang =
$object->thirdparty->default_lang;
598 if (!empty($newlang)) {
600 $outputlangs->setDefaultLang($newlang);
604 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
609 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
617 $result = $discountcheck->fetch(0, 0,
$object->id);
629 $amount_ht = $amount_tva = $amount_ttc = array();
630 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
634 foreach (
$object->lines as $line) {
635 if ($line->product_type < 9 && $line->total_ht != 0) {
636 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
638 $amount_ht[$keyforvatrate] += $line->total_ht;
639 $amount_tva[$keyforvatrate] += $line->total_tva;
640 $amount_ttc[$keyforvatrate] += $line->total_ttc;
641 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
642 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
643 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
647 '@phan-var-force array<string,float> $amount_ht
648 @phan-var-force array<string,float> $amount_tva
649 @phan-var-force array<string,float> $amount_ttc
650 @phan-var-force array<string,float> $multicurrency_amount_ht
651 @phan-var-force array<string,float> $multicurrency_amount_tva
652 @phan-var-force array<string,float> $multicurrency_amount_ttc';
656 $alreadypaid =
$object->getSommePaiement();
657 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
658 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
659 foreach ($amount_ht as $vatrate => $val) {
660 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
661 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
662 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
663 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
664 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
665 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
674 $discount->description =
'(CREDIT_NOTE)';
676 $discount->description =
'(DEPOSIT)';
678 $discount->description =
'(EXCESS PAID)';
680 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
682 $discount->discount_type = 1;
683 $discount->fk_soc =
$object->socid;
684 $discount->socid =
$object->socid;
685 $discount->fk_invoice_supplier_source =
$object->id;
693 $sql =
'SELECT SUM(pf.amount) as total_paiements';
694 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'paiementfourn as p';
695 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN ('.
getEntity(
'c_paiement').
')';
696 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
697 $sql .=
' AND pf.fk_paiementfourn = p.rowid';
698 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
700 $resql =
$db->query($sql);
705 $res =
$db->fetch_object($resql);
706 $total_paiements = $res->total_paiements;
709 $total_creditnote_and_deposit = 0;
710 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
711 $sql .=
" re.description, re.fk_invoice_supplier_source";
712 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
713 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
714 $resql =
$db->query($sql);
715 if (!empty($resql)) {
716 while ($obj =
$db->fetch_object($resql)) {
717 $total_creditnote_and_deposit += $obj->amount_ttc;
723 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
724 $discount->amount_tva = 0;
725 $discount->tva_tx = 0;
726 $discount->vat_src_code =
'';
729 $discount->multicurrency_code =
$object->multicurrency_code;
730 $discount->multicurrency_tx =
$object->multicurrency_tx;
731 $discount->multicurrency_total_ht = $discount->multicurrency_total_ttc = (float)
price2num((
float) $discount->amount_ttc * (float)
$object->multicurrency_tx,
'MT');
732 $discount->multicurrency_total_tva = 0;
734 $discount->multicurrency_amount_ht = $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
735 $discount->multicurrency_amount_tva = 0;
737 $result = $discount->create($user);
743 foreach ($amount_ht as $tva_tx => $xxx) {
744 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
745 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
746 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
748 $discount->multicurrency_code =
$object->multicurrency_code;
749 $discount->multicurrency_tx =
$object->multicurrency_tx;
750 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
751 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
752 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
754 $discount->multicurrency_amount_ht = abs((
float) $discount->multicurrency_total_ht);
755 $discount->multicurrency_amount_tva = abs((
float) $discount->multicurrency_total_tva);
756 $discount->multicurrency_amount_ttc = abs((
float) $discount->multicurrency_total_ttc);
761 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
762 $vat_src_code = $reg[1];
763 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
766 $discount->tva_tx = abs((
float) $tva_tx);
767 $discount->vat_src_code = $vat_src_code;
769 $result = $discount->create($user);
780 $result =
$object->setPaid($user);
795 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate) {
800 $result = $paiementfourn->fetch(
GETPOSTINT(
'paiement_id'));
802 $result = $paiementfourn->delete($user);
804 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
812 } elseif ($action ==
'add' && $usercancreate) {
817 $selectedLines =
GETPOST(
'toselect',
'array:int');
825 $ret = $extrafields->setOptionalsFromPost(
null, $object);
839 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
844 if (empty($dateinvoice)) {
845 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
857 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
871 $object->date_echeance = $datedue;
877 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
878 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
880 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
881 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
902 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
905 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
910 if (empty($dateinvoice)) {
911 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
921 if (!
GETPOST(
'ref_supplier')) {
922 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
930 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
945 $object->date_echeance = $datedue;
951 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
952 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
954 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
955 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
960 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
969 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
971 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
974 foreach ($facture_source->lines as $line) {
976 if (method_exists($line,
'fetch_optionals')) {
977 $line->fetch_optionals();
981 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
985 $line->fk_facture_fourn =
$object->id;
986 $line->fk_parent_line = $fk_parent_line;
988 $line->subprice = -$line->subprice;
989 $line->pa_ht = -((float) $line->pa_ht);
990 $line->total_ht = -$line->total_ht;
991 $line->total_tva = -$line->total_tva;
992 $line->total_ttc = -$line->total_ttc;
993 $line->total_localtax1 = -$line->total_localtax1;
994 $line->total_localtax2 = -$line->total_localtax2;
995 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
996 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
997 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
999 $result = $line->insert();
1004 if ($result > 0 && $line->product_type == 9) {
1005 $fk_parent_line = $result;
1013 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 &&
$id > 0) {
1015 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1016 $totalpaid = $facture_source->getSommePaiement();
1017 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1018 $totaldeposits = $facture_source->getSumDepositsUsed();
1019 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1020 $desc = $langs->trans(
'invoiceAvoirLineWithPaymentRestAmount');
1021 $retAddLine =
$object->addline($desc, $remain_to_pay, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
'TTC');
1023 if ($retAddLine < 0) {
1030 if (!empty(
$object->fk_facture_source) && $id > 0) {
1032 if ($facture_source_link->fetch(
$object->fk_facture_source) > 0) {
1033 $facture_source_link->fetchObjectLinked();
1034 if (!empty($facture_source_link->linkedObjectsIds)) {
1035 foreach ($facture_source_link->linkedObjectsIds as $sourcetype => $TIds) {
1036 $object->add_object_linked($sourcetype, current($TIds));
1044 if (empty($dateinvoice)) {
1046 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1056 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1066 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1067 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1076 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1077 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1081 $object->fac_rec = $fac_recid;
1083 $fac_rec->fetch(
$object->fac_rec);
1084 $fac_rec->fetch_lines();
1085 $object->lines = $fac_rec->lines;
1092 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1097 if (empty($dateinvoice)) {
1098 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1108 if (!
GETPOST(
'ref_supplier')) {
1109 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
1117 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1134 $object->date_echeance = $datedue;
1140 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1141 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1143 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1144 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1149 if (empty(
$object->date_echeance)) {
1150 $object->date_echeance =
$object->calculate_date_lim_reglement();
1156 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
1158 $element = $subelement =
GETPOST(
'origin',
'alpha');
1166 if ($element ==
'order') {
1167 $element = $subelement =
'commande';
1169 if ($element ==
'propal') {
1170 $element =
'comm/propal';
1171 $subelement =
'propal';
1173 if ($element ==
'contract') {
1174 $element = $subelement =
'contrat';
1176 if ($element ==
'order_supplier') {
1178 $subelement =
'fournisseur.commande';
1180 if ($element ==
'project') {
1181 $element =
'projet';
1189 $classname = ucfirst($subelement);
1190 if ($classname ==
'Fournisseur.commande') {
1191 $classname =
'CommandeFournisseur';
1193 $objectsrc =
new $classname(
$db);
1194 $objectsrc->fetch($originid);
1195 $objectsrc->fetch_thirdparty();
1197 if (!empty(
$object->origin_type) && !empty(
$object->origin_id)) {
1202 if (
$object->origin_type ==
'reception') {
1203 $objectsrc->fetchObjectLinked();
1205 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1206 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1207 $object->linkedObjectsIds[
'order_supplier'][-1] = $value;
1217 $classname = ucfirst($subelement);
1218 if ($classname ==
'Fournisseur.commande') {
1219 $classname =
'CommandeFournisseur';
1221 $srcobject =
new $classname(
$db);
1223 $result = $srcobject->fetch(
GETPOSTINT(
'originid'));
1226 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1231 $amountdeposit = array();
1233 if ($typeamount ==
'amount') {
1234 $amount = $valuedeposit;
1236 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1239 $TTotalByTva = array();
1240 foreach ($srcobject->lines as &$line) {
1241 if (!empty($line->special_code)) {
1244 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1246 '@phan-var-force array<string,float> $TTotalByTva';
1248 $amount_ttc_diff = 0.;
1249 foreach ($TTotalByTva as $tva => &$total) {
1250 $coef = $total / $srcobject->total_ttc;
1251 $am = $amount * $coef;
1252 $amount_ttc_diff += $am;
1253 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1256 if ($typeamount ==
'amount') {
1257 $amountdeposit[0] = $valuedeposit;
1258 } elseif ($typeamount ==
'variable') {
1261 $lines = $srcobject->lines;
1262 $numlines = count($lines);
1263 for ($i = 0; $i < $numlines; $i++) {
1265 if (empty($lines[$i]->qty)) {
1268 if (!empty($lines[$i]->special_code)) {
1272 $totalamount += $lines[$i]->total_ht;
1273 $tva_tx = $lines[$i]->tva_tx;
1274 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1278 if ($totalamount == 0) {
1279 $amountdeposit[0] = 0;
1284 $amountdeposit[0] = 0;
1288 $amount_ttc_diff = array_key_exists(0, $amountdeposit) ? $amountdeposit[0] : 0;
1291 foreach ($amountdeposit as $tva => $amount) {
1292 if (empty($amount)) {
1297 'amount' =>
'FixAmount',
1298 'variable' =>
'VarAmount'
1300 $descline =
'(DEPOSIT)';
1302 if ($typeamount ==
'amount') {
1303 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1304 } elseif ($typeamount ==
'variable') {
1305 $descline .=
' ('.$valuedeposit.
'%)';
1308 $descline .=
' - '.$srcobject->ref;
1338 $diff =
$object->total_ttc - $amount_ttc_diff;
1342 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1348 $object->lines[0]->localtax1_tx,
1349 $object->lines[0]->localtax2_tx,
1351 $object->lines[0]->fk_product,
1354 $object->lines[0]->product_type,
1355 $object->lines[0]->remise_percent,
1357 $object->lines[0]->date_start,
1366 } elseif ($result > 0) {
1367 $lines = $srcobject->lines;
1368 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1369 $srcobject->fetch_lines();
1370 $lines = $srcobject->lines;
1373 $num = count($lines);
1374 for ($i = 0; $i < $num; $i++) {
1375 if (!in_array($lines[$i]->
id, $selectedLines)) {
1379 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->product_label);
1380 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1383 if (method_exists($lines[$i],
'fetch_optionals')) {
1384 $lines[$i]->fetch_optionals();
1390 if ($lines[$i]->date_debut_reel) {
1393 if ($lines[$i]->date_start) {
1396 $date_end = $lines[$i]->date_fin_prevue;
1397 if ($lines[$i]->date_fin_reel) {
1398 $date_end = $lines[$i]->date_fin_reel;
1400 if ($lines[$i]->date_end) {
1401 $date_end = $lines[$i]->date_end;
1404 $tva_tx = $lines[$i]->tva_tx;
1406 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
1407 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1411 $object->special_code = $lines[$i]->special_code;
1416 $pu_currency = $lines[$i]->multicurrency_subprice;
1418 $pu = $lines[$i]->subprice;
1427 $lines[$i]->localtax1_tx,
1428 $lines[$i]->localtax2_tx,
1430 $lines[$i]->fk_product,
1431 $lines[$i]->remise_percent,
1435 $lines[$i]->info_bits,
1440 $lines[$i]->array_options,
1441 $lines[$i]->fk_unit,
1444 $lines[$i]->ref_supplier,
1445 $lines[$i]->special_code
1462 $parameters = array(
'objFrom' => $srcobject);
1463 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1473 } elseif (!$error) {
1483 $langs->load(
"errors");
1493 $outputlangs = $langs;
1494 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1501 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1504 } elseif ($action ==
'updateline' && $usercancreate) {
1508 if (!
$object->fetch($id) > 0) {
1514 $tva_tx = str_replace(
'*',
'', $tva_tx);
1516 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_subprice') !=
'') {
1518 $price_base_type =
'HT';
1521 $price_base_type =
'TTC';
1524 if (
GETPOST(
'productid') > 0) {
1526 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY') == 1) {
1528 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1534 $label =
$prod->description;
1535 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1536 $label =
GETPOST(
'product_desc',
'restricthtml');
1539 $type =
$prod->type;
1541 $label =
GETPOST(
'product_desc',
'restricthtml');
1550 if (preg_match(
'/\*/', $tva_tx)) {
1555 $tva_tx = str_replace(
'*',
'', $tva_tx);
1563 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1564 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1566 if (is_array($extralabelsline)) {
1567 foreach ($extralabelsline as $key => $value) {
1568 unset($_POST[
"options_".$key]);
1572 $result =
$object->updateline(
1584 (
float) $remise_percent,
1594 unset($_POST[
'label']);
1595 unset($_POST[
'fourn_ref']);
1596 unset($_POST[
'date_starthour']);
1597 unset($_POST[
'date_startmin']);
1598 unset($_POST[
'date_startsec']);
1599 unset($_POST[
'date_startday']);
1600 unset($_POST[
'date_startmonth']);
1601 unset($_POST[
'date_startyear']);
1602 unset($_POST[
'date_endhour']);
1603 unset($_POST[
'date_endmin']);
1604 unset($_POST[
'date_endsec']);
1605 unset($_POST[
'date_endday']);
1606 unset($_POST[
'date_endmonth']);
1607 unset($_POST[
'date_endyear']);
1608 unset($_POST[
'price_ttc']);
1609 unset($_POST[
'price_ht']);
1616 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
1620 foreach (
$object->lines as $line) {
1621 if ($line->product_type == 1) {
1622 $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);
1625 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
1627 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
1628 $remise_percent = (float) str_replace(
'*',
'', $remise_percent);
1629 foreach (
$object->lines as $line) {
1630 $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, $remise_percent, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier, $line->rang);
1632 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !=
'' && $usercancreate) {
1634 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1635 $vat_rate = str_replace(
'*',
'', $vat_rate);
1638 foreach (
$object->lines as $line) {
1639 $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);
1641 } elseif ($action ==
'addline' && $usercancreate) {
1650 $ret =
$object->fetch_thirdparty();
1652 $langs->load(
'errors');
1661 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1662 if ($prod_entry_mode ==
'free') {
1669 $price_ht_devise =
'';
1671 $price_ttc_devise =
'';
1673 if (
GETPOST(
'price_ht') !==
'') {
1676 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
1679 if (
GETPOST(
'price_ttc') !==
'') {
1682 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
1683 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
1691 if (empty($remise_percent)) {
1692 $remise_percent = 0;
1696 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1697 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
1699 if (is_array($extralabelsline)) {
1701 foreach ($extralabelsline as $key => $value) {
1702 unset($_POST[
"options_".$key]);
1706 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
1707 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1710 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOSTINT(
'type') < 0) {
1711 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
1716 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1')
1717 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
1718 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
1719 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
1720 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
1721 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
1722 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) {
1723 $langs->load(
"errors");
1724 if (
$object->type == $object::TYPE_DEPOSIT) {
1726 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
1728 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPrice"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
1733 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
1734 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
1738 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') && !
GETPOST(
'dp_desc')) {
1739 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
1742 if (!
GETPOST(
'qty',
'alpha')) {
1743 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1747 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
1748 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
1752 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1753 $idprod = $res->fk_product_child;
1755 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
1761 if ($prod_entry_mode !=
'free' && empty($error)) {
1765 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
1770 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
1771 $idprod = (int) $reg[1];
1772 $res = $productsupplier->fetch($idprod);
1775 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
1777 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1778 if ($productsupplier->fourn_socid != $socid) {
1779 $productsupplier->ref_supplier =
'';
1782 $fksoctosearch =
$object->thirdparty->id;
1783 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1785 } elseif (
GETPOSTINT(
'idprodfournprice') > 0) {
1786 $qtytosearch = (float) $qty;
1788 $idprod = $productsupplier->get_buyprice(
GETPOSTINT(
'idprodfournprice'), $qtytosearch);
1789 $res = $productsupplier->fetch($idprod);
1793 $label = $productsupplier->label;
1796 $outputlangs = $langs;
1798 if (
GETPOST(
'lang_id',
'aZ09')) {
1799 $newlang =
GETPOST(
'lang_id',
'aZ09');
1801 if (empty($newlang)) {
1802 $newlang =
$object->thirdparty->default_lang;
1804 if (!empty($newlang)) {
1806 $outputlangs->setDefaultLang($newlang);
1808 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
1810 $desc = $productsupplier->description;
1813 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
1814 $desc = $productsupplier->desc_supplier;
1825 $ref_supplier = $productsupplier->ref_supplier;
1829 $tmpidprodfournprice =
GETPOST(
'idprodfournprice',
'alpha');
1830 if (is_numeric($tmpidprodfournprice) && (
int) $tmpidprodfournprice > 0) {
1831 $tmpidprodfournprice = (int) $tmpidprodfournprice;
1833 $tmpidprodfournprice = 0;
1839 if (empty($tva_tx) || empty($tva_npr)) {
1845 $type = $productsupplier->type;
1846 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1847 $price_base_type =
'HT';
1849 $pu_devise =
price2num($price_ht_devise,
'CU');
1850 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
1851 $price_base_type =
'TTC';
1853 $pu_devise =
price2num($price_ttc_devise,
'CU');
1855 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
1856 if (empty(
$object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code !=
$object->multicurrency_code)) {
1857 $pu = $productsupplier->fourn_pu;
1860 $pu = $productsupplier->fourn_pu;
1861 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
1865 $ref_supplier = $productsupplier->ref_supplier;
1886 min($rank, count(
$object->lines) + 1),
1889 $productsupplier->fk_unit,
1892 GETPOST(
'fourn_ref',
'alpha'),
1896 if ($idprod == -99 || $idprod == 0) {
1899 $langs->load(
"errors");
1900 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
1902 if ($idprod == -1) {
1905 $langs->load(
"errors");
1906 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
1908 } elseif (empty($error)) {
1909 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1910 $tva_tx = str_replace(
'*',
'', $tva_tx);
1911 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1914 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
1918 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1926 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1930 $pu_ht =
price2num((
float) $pu_ttc / (1 + ((
float) $tva_tx / 100)),
'MU');
1932 $price_base_type =
'HT';
1933 $pu_devise =
price2num($price_ht_devise,
'CU');
1935 $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);
1939 if (!$error && $result > 0) {
1944 $outputlangs = $langs;
1947 $newlang =
GETPOST(
'lang_id',
'aZ09');
1950 $newlang =
$object->thirdparty->default_lang;
1952 if (!empty($newlang)) {
1954 $outputlangs->setDefaultLang($newlang);
1959 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1965 unset($_POST [
'prod_entry_mode']);
1967 unset($_POST[
'qty']);
1968 unset($_POST[
'type']);
1969 unset($_POST[
'remise_percent']);
1970 unset($_POST[
'pu']);
1971 unset($_POST[
'price_ht']);
1972 unset($_POST[
'multicurrency_price_ht']);
1973 unset($_POST[
'price_ttc']);
1974 unset($_POST[
'fourn_ref']);
1975 unset($_POST[
'tva_tx']);
1976 unset($_POST[
'label']);
1977 unset($localtax1_tx);
1978 unset($localtax2_tx);
1979 unset($_POST[
'np_marginRate']);
1980 unset($_POST[
'np_markRate']);
1981 unset($_POST[
'dp_desc']);
1982 unset($_POST[
'idprodfournprice']);
1983 unset($_POST[
'units']);
1985 unset($_POST[
'date_starthour']);
1986 unset($_POST[
'date_startmin']);
1987 unset($_POST[
'date_startsec']);
1988 unset($_POST[
'date_startday']);
1989 unset($_POST[
'date_startmonth']);
1990 unset($_POST[
'date_startyear']);
1991 unset($_POST[
'date_endhour']);
1992 unset($_POST[
'date_endmin']);
1993 unset($_POST[
'date_endsec']);
1994 unset($_POST[
'date_endday']);
1995 unset($_POST[
'date_endmonth']);
1996 unset($_POST[
'date_endyear']);
2003 } elseif ($action ==
'classin' && $usercancreate) {
2005 $result =
$object->setProject($projectid);
2006 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
2010 $totalpaid =
$object->getSommePaiement();
2011 $resteapayer =
$object->total_ttc - $totalpaid;
2014 $ventilExportCompta =
$object->getVentilExportCompta();
2016 if (!$ventilExportCompta) {
2019 $idwarehouse =
GETPOST(
'idwarehouse');
2023 $qualified_for_stock_change = 0;
2025 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2027 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2032 $langs->load(
"stocks");
2033 if (!$idwarehouse || $idwarehouse == -1) {
2035 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
2040 $object->setDraft($user, $idwarehouse);
2044 $outputlangs = $langs;
2047 $newlang =
GETPOST(
'lang_id',
'aZ09');
2050 $newlang =
$object->thirdparty->default_lang;
2052 if (!empty($newlang)) {
2054 $outputlangs->setDefaultLang($newlang);
2059 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2068 } elseif ($action ==
'reopen' && $usercancreate) {
2070 $result =
$object->fetch($id);
2073 $result =
$object->setUnpaid($user);
2075 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
2084 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2087 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
2089 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
2090 $trackid =
'sinv'.$object->id;
2091 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2095 $permissiontoadd = $usercancreate;
2096 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2099 if ($action ==
'calculate' && $usercancreate) {
2100 $calculationrule =
GETPOST(
'calculationrule');
2104 $result =
$object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0,
$object->thirdparty);
2110 if ($action ==
'update_extras' && $permissiontoeditextra) {
2113 $attribute_name =
GETPOST(
'attribute',
'aZ09');
2116 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
2122 $result =
$object->updateExtraField($attribute_name,
'BILL_SUPPLIER_MODIFY');
2130 $action =
'edit_extras';
2135 if ($action ==
'addcontact' && $usercancreate) {
2136 $result =
$object->fetch($id);
2138 if ($result > 0 && $id > 0) {
2141 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2145 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2148 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2149 $langs->load(
"errors");
2150 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2155 } elseif ($action ==
'swapstatut' && $usercancreate) {
2162 } elseif ($action ==
'deletecontact' && $usercancreate) {
2168 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2192$title =
$object->ref.
" - ".$langs->trans(
'Card');
2193if ($action ==
'create') {
2194 $title = $langs->trans(
"NewSupplierInvoice");
2196$help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
2197llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-fourn-facture page-card');
2200if ($action ==
'create') {
2202 $selectedLines = array();
2204 print
load_fiche_titre($langs->trans(
'NewSupplierInvoice'),
'',
'supplier_invoice');
2208 $currency_code =
$conf->currency;
2209 $vat_reverse_charge = 0;
2215 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2216 $currency_code = $societe->multicurrency_code;
2221 if (!empty($origin) && !empty($originid)) {
2223 $element = $subelement = $origin;
2225 if ($element ==
'project') {
2226 $projectid = $originid;
2227 $element =
'projet';
2231 if ($element ==
'order') {
2232 $element = $subelement =
'commande';
2234 if ($element ==
'propal') {
2235 $element =
'comm/propal';
2236 $subelement =
'propal';
2238 if ($element ==
'contract') {
2239 $element = $subelement =
'contrat';
2241 if ($element ==
'order_supplier') {
2243 $subelement =
'fournisseur.commande';
2247 $classname = ucfirst($subelement);
2248 if ($classname ==
'Fournisseur.commande') {
2249 $classname =
'CommandeFournisseur';
2251 $objectsrc =
new $classname(
$db);
2252 '@phan-var-force Project|Commande|Propal|Facture|Contrat|CommandeFournisseur|CommonObject $objectsrc';
2254 $objectsrc->fetch($originid);
2255 $objectsrc->fetch_thirdparty();
2257 $projectid = (int) $objectsrc->fk_project;
2259 $soc = $objectsrc->thirdparty;
2261 $cond_reglement_id = 0;
2262 $mode_reglement_id = 0;
2264 $transport_mode_id = 0;
2267 if (!empty($objectsrc->cond_reglement_id)) {
2268 $cond_reglement_id = $objectsrc->cond_reglement_id;
2270 if (!empty($objectsrc->mode_reglement_id)) {
2271 $mode_reglement_id = $objectsrc->mode_reglement_id;
2273 if (!empty($objectsrc->fk_account)) {
2274 $fk_account = $objectsrc->fk_account;
2276 if (!empty($objectsrc->transport_mode_id)) {
2277 $transport_mode_id = $objectsrc->transport_mode_id;
2280 if (empty($cond_reglement_id)
2281 || empty($mode_reglement_id)
2282 || empty($fk_account)
2283 || empty($transport_mode_id)
2285 if ($origin ==
'reception') {
2287 if (!isset($objectsrc->supplier_order)) {
2288 $objectsrc->fetch_origin();
2291 if (!empty($objectsrc->origin_object)) {
2292 $originObject = $objectsrc->origin_object;
2293 if (empty($cond_reglement_id) && !empty($originObject->cond_reglement_id)) {
2294 $cond_reglement_id = $originObject->cond_reglement_id;
2296 if (empty($mode_reglement_id) && !empty($originObject->mode_reglement_id)) {
2297 $mode_reglement_id = $originObject->mode_reglement_id;
2299 if (empty($fk_account) && !empty($originObject->fk_account)) {
2300 $fk_account = $originObject->fk_account;
2302 if (empty($transport_mode_id) && !empty($originObject->transport_mode_id)) {
2303 $transport_mode_id = $originObject->transport_mode_id;
2310 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
2311 $cond_reglement_id = $soc->cond_reglement_supplier_id;
2313 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
2314 $mode_reglement_id = $soc->mode_reglement_supplier_id;
2316 if (empty($fk_account) && !empty($soc->fk_account)) {
2317 $fk_account = $soc->fk_account;
2319 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
2320 $transport_mode_id = $soc->transport_mode_id;
2326 if (!empty($objectsrc->multicurrency_code)) {
2327 $currency_code = $objectsrc->multicurrency_code;
2329 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
2330 $currency_tx = $objectsrc->multicurrency_tx;
2335 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2337 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2340 $objectsrc->fetch_optionals();
2341 $object->array_options = $objectsrc->array_options;
2343 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2344 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2345 $vat_reverse_charge = (empty($societe) ?
'' : $societe->vat_reverse_charge);
2346 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2347 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2349 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalInt(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2351 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2353 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2354 $currency_code = $societe->multicurrency_code;
2359 if (empty($cond_reglement_id)) {
2360 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2364 if (empty($mode_reglement_id)) {
2365 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2369 if (!
GETPOST(
'changecompany')) {
2371 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
2374 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
2381 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
2382 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
2384 if ($origin ==
'contrat') {
2385 $langs->load(
"admin");
2386 $text = $langs->trans(
"ToCreateARecurringInvoice");
2387 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"SupplierBills"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
2389 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
2391 print
info_admin($text, 0, 0,
'0',
'opacitymedium').
'<br>';
2394 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2395 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2396 print
'<input type="hidden" name="action" value="add">';
2397 print
'<input type="hidden" name="changecompany" value="0">';
2399 if (!empty($societe->id) && $societe->id > 0) {
2400 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2402 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2403 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2404 if (!empty($currency_tx)) {
2405 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2407 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2412 $parameters = array();
2414 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierInvoice', $parameters, $object, $action);
2415 if (empty($reshook)) {
2416 print
'<table class="border centpercent">';
2423 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2424 $invoice_predefined->fetch($fac_recid);
2428 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2431 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2432 $absolute_discount = $societe->getAvailableDiscounts(
null,
'', 0, 1);
2433 print $societe->getNomUrl(1,
'supplier');
2434 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2436 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2437 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');
2440 print
'<script type="text/javascript">
2441 $(document).ready(function() {
2442 $("#socid").change(function() {
2443 console.log("We have changed the company - Reload page");
2445 $("input[name=action]").val("create");
2446 $("input[name=changecompany]").val("1");
2447 $("form[name=add]").submit();
2452 if ($fac_recid <= 0) {
2453 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>';
2459 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2460 $invoice_predefined->fetch($fac_recid);
2462 $dateinvoice = $invoice_predefined->date_when;
2463 if (empty($projectid)) {
2464 $projectid = $invoice_predefined->fk_project;
2466 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2467 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2468 $fk_account = $invoice_predefined->fk_account;
2469 $note_public = $invoice_predefined->note_public;
2470 $note_private = $invoice_predefined->note_private;
2472 if (!empty($invoice_predefined->multicurrency_code)) {
2473 $currency_code = $invoice_predefined->multicurrency_code;
2475 if (!empty($invoice_predefined->multicurrency_tx)) {
2476 $currency_tx = $invoice_predefined->multicurrency_tx;
2479 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2480 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2481 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2483 $resql =
$db->query($sql);
2485 $num =
$db->num_rows($resql);
2489 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2491 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2492 print
'<option value="0" selected></option>';
2494 $objp =
$db->fetch_object($resql);
2495 print
'<option value="'.$objp->rowid.
'"';
2496 if ($fac_recid == $objp->rowid) {
2498 $exampletemplateinvoice->fetch($fac_recid);
2500 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2506 print
'<script type="text/javascript">
2507 $(document).ready(function() {
2508 $("#fac_rec").change(function() {
2509 console.log("We have changed the template invoice - Reload page");
2511 $("input[name=action]").val("create");
2512 $("form[name=add]").submit();
2525 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2527 print
'<div class="tagtable">'.
"\n";
2530 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2531 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
'checked').
'> ';
2532 $desc = $form->textwithpicto($tmp.
'<label for="radio_standard">'.$langs->trans(
"InvoiceStandardAsk").
'</label>', $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2534 print
'</div></div>';
2536 if (empty($origin) || (($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') && !empty($originid))) {
2539 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2540 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOSTINT(
'type') == 3 ?
' checked' :
'') .
'> ';
2541 print
'<script type="text/javascript">
2542 jQuery(document).ready(function() {
2543 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2544 jQuery("#radio_standard").prop("checked", true);
2546 jQuery("#typedeposit, #valuedeposit").click(function() {
2547 jQuery("#radio_deposit").prop("checked", true);
2549 jQuery("#typedeposit").change(function() {
2550 console.log("We change type of down payment");
2551 jQuery("#radio_deposit").prop("checked", true);
2552 setRadioForTypeOfInvoice();
2554 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2555 setRadioForTypeOfInvoice();
2557 function setRadioForTypeOfInvoice() {
2558 console.log("Change radio");
2559 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2560 jQuery(".checkforselect").prop("disabled", true);
2561 jQuery(".checkforselect").prop("checked", false);
2563 jQuery(".checkforselect").prop("disabled", false);
2564 jQuery(".checkforselect").prop("checked", true);
2570 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2572 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2573 print
'<table class="nobordernopadding"><tr>';
2577 if ($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') {
2578 print
'<td class="nowrap" style="padding-left: 15px">';
2580 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2581 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2582 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2584 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
2585 $valuedeposit =
GETPOST(
'valuedeposit',
'int');
2586 $deposit_percent =
null;
2587 if ($origin ==
'reception') {
2589 if (!isset($objectsrc->origin_object)) {
2590 $objectsrc->fetch_origin();
2592 if (!empty($objectsrc->origin_object)) {
2593 $deposit_percent = $objectsrc->origin_object->deposit_percent;
2595 } elseif (!empty($objectsrc->deposit_percent)) {
2596 $deposit_percent = $objectsrc->deposit_percent;
2598 if (empty($typedeposit) && !empty($deposit_percent)) {
2599 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
2600 if (!empty($origin_payment_conditions_deposit_percent)) {
2601 $typedeposit =
'variable';
2604 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($deposit_percent)) {
2605 $valuedeposit = $deposit_percent;
2607 print $form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
2609 print
'<td class="nowrap" style="padding-left: 5px">';
2610 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' . $valuedeposit .
'"/>';
2613 print
'</tr></table>';
2615 print
'</div></div>';
2684 if (empty($origin)) {
2685 if (!empty($societe->id) && $societe->id > 0) {
2689 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2696 foreach ($facids as $key => $valarray) {
2697 $newinvoice_static->id = $key;
2698 $newinvoice_static->ref = $valarray [
'ref'];
2699 $newinvoice_static->status = $valarray [
'status'];
2700 $newinvoice_static->statut = $valarray [
'status'];
2701 $newinvoice_static->type = $valarray [
'type'];
2702 $newinvoice_static->paid = $valarray [
'paye'];
2703 $newinvoice_static->paye = $valarray [
'paye'];
2705 $optionsav .=
'<option value="'.$key.
'"';
2707 $optionsav .=
' selected';
2709 $newinvoice_static->fetch_optionals($key);
2710 $object->array_options = $newinvoice_static->array_options;
2713 $optionsav .= $newinvoice_static->ref;
2714 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
2715 $optionsav .=
'</option>';
2718 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2719 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOSTINT(
'type') == 2 ?
' checked' :
'');
2721 $tmp .=
' disabled';
2725 print
'<script type="text/javascript">
2726 jQuery(document).ready(function() {
2727 if (! jQuery("#radio_creditnote").is(":checked"))
2729 jQuery("#credit_note_options").hide();
2731 jQuery("#radio_creditnote").click(function() {
2732 jQuery("#credit_note_options").show();
2734 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2735 jQuery("#credit_note_options").hide();
2739 $text = $tmp.
'<label for="radio_creditnote">'.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
2741 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2743 $text .=
' disabled';
2747 $text .=
'<option value="-1"></option>';
2748 $text .= $optionsav;
2750 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
2752 $text .=
'</select>';
2753 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2756 print
'<div id="credit_note_options" class="clearboth">';
2757 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' :
'').
' /> ';
2758 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
2759 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' :
'').
' /> ';
2760 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
2763 print
'</div></div>';
2766 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2768 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2770 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2"> ';
2772 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
2773 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
2774 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2776 print
'</div></div>'.
"\n";
2786 print
'<tr><td class="fieldrequired">';
2787 print $form->textwithpicto($langs->trans(
'RefSupplierBill'), $langs->trans(
"RefOfOnVendorSide", $langs->trans(
"SupplierBill"))).
'</td><td>';
2788 print
'<input name="ref_supplier" value="'.(GETPOSTISSET(
'ref_supplier') ?
GETPOST(
'ref_supplier') : (!empty($objectsrc->ref_supplier) ? $objectsrc->ref_supplier :
'')).
'" type="text" spellcheck="false"';
2789 if (!empty($societe->id) && $societe->id > 0) {
2798 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
2799 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
2803 if (!empty($societe->id) && $societe->id > 0) {
2805 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2807 $thirdparty = $societe;
2809 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2810 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2816 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth300" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
2820 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
2821 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2822 print $form->selectDate($dateinvoice ? (
int) $dateinvoice :
'',
'', 0, 0, 0,
"add", 1, 1);
2826 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2827 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
2828 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth200 widthcentpercentminusx');
2832 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
2833 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2834 print $form->selectDate($datedue,
'ech', 0, 0, 0,
"add", 1, 1);
2838 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2839 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2840 $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'DBIT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
2845 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2847 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
2855 $langs->load(
'projects');
2856 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2857 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');
2858 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>';
2865 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
2866 print
'<td colspan="3" class="maxwidthonsmartphone">';
2867 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2868 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 :
''));
2874 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
2875 print
'<tr><td>' . $langs->trans(
'VATReverseCharge') .
'</td><td>';
2878 $vat_reverse_charge = (
GETPOST(
'vat_reverse_charge',
'alpha') ==
'on' ||
GETPOST(
'vat_reverse_charge',
'alpha') ==
'1') ? 1 : 0;
2879 } elseif ($vat_reverse_charge == 1 || $societe->vat_reverse_charge == 1 || ($societe->country_code !=
'FR' &&
isInEEC($societe) && !empty($societe->tva_intra))) {
2880 $vat_reverse_charge = 1;
2882 $vat_reverse_charge = 0;
2885 print
'<input type="checkbox" name="vat_reverse_charge"'. (!empty($vat_reverse_charge) ?
' checked ' :
'') .
'>';
2892 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
2893 print
'<td class="maxwidthonsmartphone">';
2894 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
2895 $used_currency_code = $currency_code;
2896 if (!
GETPOST(
'changecompany')) {
2897 $used_currency_code =
GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code;
2899 print $form->selectMultiCurrency($used_currency_code,
'multicurrency_code');
2905 if ($fac_recid > 0) {
2906 $dateexample = $dateinvoice;
2907 if (empty($dateexample)) {
2910 $substitutionarray = array(
2911 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
2912 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
2913 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
2914 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
2915 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
2916 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
2917 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
2918 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
2919 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
2920 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
2921 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
2924 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
2925 foreach ($substitutionarray as $key => $val) {
2926 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
2928 $htmltext .=
'</i>';
2933 $langs->loadLangs(array(
"intracommreport"));
2934 print
'<!-- If module intracomm on -->'.
"\n";
2935 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
2936 $form->selectTransportMode(
GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
2940 if (empty($reshook)) {
2941 print
$object->showOptionals($extrafields,
'create');
2946 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
2947 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
2952 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2954 $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%');
2955 print $doleditor->Create(1);
2961 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
2963 $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%');
2964 print $doleditor->Create(1);
2970 if (!empty($objectsrc) && $classname !==
null) {
2971 print
"\n<!-- ".$classname.
" info -->";
2973 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2974 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2975 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2976 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2977 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2979 $txt = $langs->trans($classname);
2980 if ($classname ==
'CommandeFournisseur') {
2981 $langs->load(
'orders');
2982 $txt = $langs->trans(
"SupplierOrder");
2984 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
2986 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'invoice_supplier');
2988 if (isset($objectsrc->linkedObjects[
'invoice_supplier'])) {
2989 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
2991 $invoice_supplier = [];
2993 '@phan-var-force null|FactureFournisseur[] $invoice_supplier';
2996 if (is_array($invoice_supplier)) {
2997 $cntinvoice = count($invoice_supplier);
2999 if ($cntinvoice >= 1) {
3001 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
3006 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
3007 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
3008 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
3009 print
'<tr><td>'.$langs->transcountry(
"AmountLT1",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
3012 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
3013 print
'<tr><td>'.$langs->transcountry(
"AmountLT2",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
3015 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
3018 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
3019 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
3020 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
3025 $parameters = array();
3026 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
3027 print $hookmanager->resPrint;
3035 print $form->buttonsSaveCancel(
"CreateDraft");
3038 if (!empty($objectsrc)) {
3041 $title = $langs->trans(
'ProductsAndServices');
3044 print
'<div class="div-table-responsive-no-min">';
3045 print
'<table class="noborder centpercent">';
3047 $objectsrc->printOriginLinesList(
'', $selectedLines);
3055 if ($id > 0 || !empty($ref)) {
3061 $result =
$object->fetch($id, $ref);
3066 $result =
$object->fetch_thirdparty();
3072 $societe =
$object->thirdparty;
3074 $totalpaid =
$object->getSommePaiement();
3075 $totalcreditnotes =
$object->getSumCreditNotesUsed();
3076 $totaldeposits =
$object->getSumDepositsUsed();
3084 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
3087 $multicurrency_resteapayer = 0;
3089 $multicurrency_totalpaid =
$object->getSommePaiement(1);
3090 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
3091 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
3092 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
3096 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
3097 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
3104 $resteapayeraffiche = $resteapayer;
3107 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
3108 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
3110 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
3111 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
3114 $absolute_discount = $societe->getAvailableDiscounts(
null, $filterabsolutediscount, 0, 1);
3115 $absolute_creditnote = $societe->getAvailableDiscounts(
null, $filtercreditnote, 0, 1);
3116 $absolute_discount =
price2num($absolute_discount,
'MT');
3117 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
3121 $objectidnext =
$object->getIdReplacingInvoice();
3124 $titre = $langs->trans(
'SupplierInvoice');
3126 print
dol_get_fiche_head($head,
'card', $titre, -1,
'supplier_invoice', 0,
'',
'', 0,
'', 1);
3131 if ($action ==
'converttoreduc') {
3134 $type_fac =
'ExcessPaid';
3136 $type_fac =
'CreditNote';
3138 $type_fac =
'Deposit';
3140 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
3141 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
3142 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
3146 if ($action ==
'clone') {
3148 $formquestion = array(
3149 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplierBill"),
'value' => $langs->trans(
"CopyOf").
' '.
$object->ref_supplier),
3150 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
3153 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 0);
3157 if ($action ==
'valid') {
3159 if (preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) {
3161 $numref =
$object->getNextNumRef($societe);
3170 $text = $langs->trans(
'ConfirmValidateBill', $numref);
3178 $formquestion = array();
3180 $qualified_for_stock_change = 0;
3182 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3184 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3188 $langs->load(
"stocks");
3189 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3192 $warehouse_array = $warehouse->list_array();
3193 if (count($warehouse_array) == 1) {
3195 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3198 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3200 $formquestion = array(
3201 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3205 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
3210 if ($action ==
'edit') {
3211 $formquestion = array();
3213 $qualified_for_stock_change = 0;
3215 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3217 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3220 $langs->load(
"stocks");
3221 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3224 $warehouse_array = $warehouse->list_array();
3225 if (count($warehouse_array) == 1) {
3227 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3230 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3232 $formquestion = array(
3233 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3236 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill',
$object->ref),
'confirm_edit', $formquestion, 1, 1);
3240 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
3241 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'', 0, 1);
3244 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
3248 $close[$i][
'code'] =
'discount_vat';
3250 $close[$i][
'code'] =
'badsupplier';
3252 $close[$i][
'code'] =
'other';
3256 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
3258 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3260 $close[$i][
'label'] = $langs->trans(
"Other");
3264 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3266 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3268 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
3271 $arrayreasons = array();
3272 foreach ($close as $key => $val) {
3273 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
3277 $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'));
3279 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
3283 if ($action ==
'canceled') {
3285 $close[1][
'code'] =
'badsupplier';
3286 $close[2][
'code'] =
'abandon';
3288 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3289 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
3291 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier",
$object->ref), $close[1][
'label'], 1);
3292 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
3294 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
3295 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
3298 $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'));
3300 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 280);
3304 if ($action ==
'delete') {
3305 $formquestion = array();
3307 $qualified_for_stock_change = 0;
3309 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3311 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3315 $langs->load(
"stocks");
3316 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3319 $warehouse_array = $warehouse->list_array();
3321 $selectwarehouse =
'<span class="questionrevertstock hidden">';
3322 if (count($warehouse_array) == 1) {
3324 $selectwarehouse .=
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3327 $selectwarehouse .= $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3329 $selectwarehouse .=
'</span>';
3331 $selectyesno = array(0 => $langs->trans(
'No'), 1 => $langs->trans(
'Yes'));
3333 print
'<script type="text/javascript">
3334 $(document).ready(function() {
3335 $("#revertstock").change(function() {
3336 if(this.value > 0) {
3337 $(".questionrevertstock").removeClass("hidden");
3339 $(".questionrevertstock").addClass("hidden");
3345 $formquestion = array(
3346 array(
'type' =>
'select',
'name' =>
'revertstock',
'label' => $langs->trans(
"RevertProductsToStock"),
'select_show_empty' => 0,
'values' => $selectyesno),
3347 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $selectwarehouse,
'tdclass' =>
'questionrevertstock hidden')
3351 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete', $formquestion, 1, 1);
3353 if ($action ==
'deletepayment') {
3354 $payment_id =
GETPOST(
'paiement_id');
3355 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
3359 if ($action ==
'ask_deleteline') {
3360 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
3364 if ($action ==
'add_title_line') {
3365 $langs->load(
'subtotals');
3367 $depth_array =
$object->getPossibleLevels($langs);
3368 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3369 } elseif ($action ==
'add_subtotal_line') {
3370 $langs->load(
'subtotals');
3372 $titles =
$object->getPossibleTitles();
3373 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3377 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
3378 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
3379 if (empty($reshook)) {
3380 $formconfirm .= $hookmanager->resPrint;
3381 } elseif ($reshook > 0) {
3382 $formconfirm = $hookmanager->resPrint;
3390 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
3392 $morehtmlref =
'<div class="refidno">';
3394 $morehtmlref .= $form->editfieldkey(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, (
int) $usercancreate,
'string',
'', 0, 1);
3395 $morehtmlref .= $form->editfieldval(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
3397 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'supplier');
3399 $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>';
3403 $langs->load(
"projects");
3404 $morehtmlref .=
'<br>';
3405 if ($permissiontoadd) {
3406 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
3407 if ($action !=
'classify') {
3408 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.((int)
$object->id).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
3410 $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');
3412 if (!empty(
$object->fk_project)) {
3414 $proj->fetch(
$object->fk_project);
3415 $morehtmlref .= $proj->getNomUrl(1);
3417 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
3422 $morehtmlref .=
'</div>';
3424 $object->totalpaid = $totalpaid;
3426 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
3429 $parameters = array();
3431 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierInvoice', $parameters, $object, $action);
3432 if (empty($reshook)) {
3433 print
'<div class="fichecenter">';
3434 print
'<div class="fichehalfleft">';
3435 print
'<div class="underbanner clearboth"></div>';
3437 print
'<table class="border tableforfield centpercent">';
3440 print
'<tr><td>'.$langs->trans(
'Type').
'</td><td>';
3441 print
'<span class="badgeneutral">';
3445 print
' '.$object->getSubtypeLabel(
'facture_fourn');
3449 $facreplaced->fetch(
$object->fk_facture_source);
3450 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
3453 if (
$object->fk_facture_source > 0) {
3455 $facusing->fetch(
$object->fk_facture_source);
3456 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
3458 $langs->load(
"errors");
3459 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"WarningCorrectedInvoiceNotFound").
'</span>';
3464 $object->getListIdAvoirFromInvoice();
3466 if (!empty(
$object->creditnote_ids)) {
3467 $invoicecredits = array();
3468 foreach (
$object->creditnote_ids as $invoiceid) {
3470 $creditnote->fetch($invoiceid);
3471 $invoicecredits[] = $creditnote->getNomUrl(1);
3473 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
3476 if (isset($objectidnext) && $objectidnext > 0) {
3479 $facthatreplace->fetch($objectidnext);
3480 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
3484 $result = $discount->fetch(0, 0,
$object->id);
3486 print
' <span class="opacitymediumbycolor paddingleft">';
3487 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
3488 $s = str_replace(
'{s1}',
$object->getLibType(1), $s);
3489 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
3491 print
'</span><br>';
3495 if (
$object->fk_fac_rec_source > 0) {
3497 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
3499 print
' <span class="opacitymediumbycolor paddingleft">';
3500 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->title).
'</a>';
3501 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
3511 print
'<!-- Discounts -->'.
"\n";
3512 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
3515 $thirdparty = $societe;
3517 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3523 print
'<td>'.$form->editfieldkey(
"Label",
'label',
$object->label, $object, (
int) $usercancreate).
'</td>';
3524 print
'<td>'.$form->editfieldval(
"Label",
'label',
$object->label, $object, $usercancreate).
'</td>';
3532 print $form->editfieldkey(
"DateInvoice",
'datef', (
string)
$object->date,
$object, (int) $form_permission,
'datepicker');
3533 print
'</td><td colspan="3">';
3534 print $form->editfieldval(
"Date",
'datef',
$object->date, $object, $form_permission,
'datepicker');
3538 $langs->load(
'bills');
3539 print
'<tr><td class="nowrap">';
3540 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3541 print $langs->trans(
'PaymentConditions');
3543 if ($action !=
'editconditions' && $form_permission) {
3544 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>';
3546 print
'</tr></table>';
3548 if ($action ==
'editconditions') {
3549 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
3551 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
3558 print $form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', (
string)
$object->date_echeance, $object, (
int) $form_permission,
'datepicker');
3560 print $form->editfieldval(
"DateMaxPayment",
'date_lim_reglement',
$object->date_echeance, $object, $form_permission,
'datepicker');
3561 if ($action !=
'editdate_lim_reglement' &&
$object->hasDelay()) {
3567 $langs->load(
'bills');
3568 print
'<tr><td class="nowrap">';
3569 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3570 print $langs->trans(
'PaymentMode');
3572 if ($action !=
'editmode' && $form_permission) {
3573 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>';
3575 print
'</tr></table>';
3577 if ($action ==
'editmode') {
3578 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3580 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'none');
3586 print
'<tr><td class="nowrap">';
3587 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3588 print $langs->trans(
'BankAccount');
3590 if ($action !=
'editbankaccount' && $usercancreate) {
3591 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>';
3593 print
'</tr></table>';
3595 if ($action ==
'editbankaccount') {
3596 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
3598 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
3606 print
'<tr><td class="nowrap">';
3607 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3608 print $langs->trans(
'VATReverseCharge');
3610 if ($action !=
'editvatreversecharge' && $usercancreate) {
3611 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editvatreversecharge&id='.
$object->id.
'">'.
img_edit($langs->trans(
'SetVATReverseCharge'), 1).
'</a></td>';
3613 print
'</tr></table>';
3615 if ($action ==
'editvatreversecharge') {
3616 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
3617 print
'<input type="hidden" name="action" value="setvatreversecharge">';
3618 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3620 print
'<input type="checkbox" name="vat_reverse_charge"' . (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
'>';
3622 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
3625 print
'<input type="checkbox" name="vat_reverse_charge"'. (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
' disabled>';
3633 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3634 print $langs->trans(
'IncotermLabel');
3635 print
'<td><td class="right">';
3636 if ($usercancreate) {
3637 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
3641 print
'</td></tr></table>';
3644 if ($action !=
'editincoterm') {
3645 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
3647 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
3654 $langs->loadLangs(array(
"intracommreport"));
3655 print
'<!-- If module intracomm on -->'.
"\n";
3657 print
'<table class="nobordernopadding centpercent"><tr><td>';
3658 print $langs->trans(
'IntracommReportTransportMode');
3660 if ($action !=
'edittransportmode' && ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"))) {
3661 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edittransportmode&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit().
'</a></td>';
3663 print
'</tr></table>';
3666 if ($action ==
'edittransportmode') {
3667 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'transport_mode_id', 1, 1);
3669 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'none');
3677 print
'<table class="nobordernopadding centpercent"><tr><td>';
3678 print $langs->trans(
"Categories");
3679 print
'<td><td class="right">';
3680 if ($usercancreate) {
3681 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
3685 print
'</td></tr></table>';
3688 if ($action ==
'edittags') {
3689 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
3690 print
'<input type="hidden" name="action" value="settags">';
3691 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3692 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
3693 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
3696 print $form->showCategories(
$object->id, Categorie::TYPE_SUPPLIER_INVOICE, 1);
3704 if (
$object->status != $object::STATUS_DRAFT) {
3708 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
3713 print
'<div class="fichehalfright">';
3714 print
'<div class="underbanner clearboth"></div>';
3716 print
'<table class="border tableforfield centpercent">';
3718 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
3721 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
3722 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3724 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3729 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
3730 print
'<td class="nowrap amountcard right">';
3731 if (
GETPOST(
'calculationrule')) {
3732 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
3734 $calculationrule = (!
getDolGlobalString(
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND_SUPPLIER') ?
'totalofround' :
'roundoftotal');
3736 if ($calculationrule ==
'totalofround') {
3737 $calculationrulenum = 1;
3739 $calculationrulenum = 2;
3742 if (
$object->getVentilExportCompta() == 0) {
3743 $s =
'<span class="hideonsmartphone opacitymedium">' . $langs->trans(
"ReCalculate") .
' </span>';
3744 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=totalofround">' . $langs->trans(
"Mode1") .
'</a>';
3746 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=roundoftotal">' . (
$conf->dol_optimize_smallscreen ?
"2" : $langs->trans(
"Mode2")) .
'</a>';
3747 print
'<div class="inline-block">';
3748 print $form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum) .
'<br>' . $langs->trans(
"CalculationRuleDescSupplier"), 2, 1,
img_picto(
'',
'help',
'class="paddingleft paddingright"'),
'', 3,
'', 0,
'recalculate');
3749 print
' ';
3752 print
'<span class="nowraponall">'.price(
$object->total_tva, 1, $langs, 0, -1, -1,
$conf->currency).
'</span>';
3755 print
'<td class="nowraponall amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3759 if ($societe->localtax1_assuj ==
"1") {
3761 print
'<td>' . $langs->transcountry(
"AmountLT1", $societe->country_code) .
'</td>';
3762 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3765 if ($societe->localtax2_assuj ==
"1") {
3767 print
'<td>' . $langs->transcountry(
"AmountLT2", $societe->country_code) .
'</td>';
3768 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3773 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
3774 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3776 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3809 if ($societe->localtax1_assuj ==
"1") {
3812 if ($societe->localtax2_assuj ==
"1") {
3816 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
3817 $sql .=
' c.id as payment_type, c.code as payment_code,';
3818 $sql .=
' pf.amount,';
3819 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
3820 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
3821 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
3822 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
3823 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
3824 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
3825 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
3826 $sql .=
' ORDER BY p.datep, p.tms';
3828 $result =
$db->query($sql);
3830 $num =
$db->num_rows($result);
3833 print
'<div class="div-table-responsive-no-min">';
3834 print
'<table class="noborder paymenttable centpercent">';
3835 print
'<tr class="liste_titre">';
3837 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
3838 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
3840 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
3845 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
3850 $objp =
$db->fetch_object($result);
3852 $paymentstatic->id = $objp->rowid;
3853 $paymentstatic->datepaye =
$db->jdate($objp->dp);
3854 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
3855 $paymentstatic->num_payment = $objp->num_payment;
3857 $paymentstatic->paiementcode = $objp->payment_code;
3858 $paymentstatic->type_code = $objp->payment_code;
3859 $paymentstatic->type_label = $objp->payment_type;
3861 print
'<tr class="oddeven">';
3862 print
'<td class="nowraponall">';
3863 print $paymentstatic->getNomUrl(1);
3865 print
'<td>'.dol_print_date(
$db->jdate($objp->dp),
'day').
'</td>';
3866 $s = $form->form_modes_reglement(
'', $objp->payment_type,
'none',
'', 1, 0,
'', 1).
' '.$objp->num_payment;
3867 print
'<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).
'">';
3871 $bankaccountstatic->id = $objp->baid;
3872 $bankaccountstatic->ref = $objp->baref;
3873 $bankaccountstatic->label = $objp->baref;
3874 $bankaccountstatic->number = $objp->banumber;
3877 $bankaccountstatic->account_number = $objp->account_number;
3880 $accountingjournal->fetch($objp->fk_accountancy_journal);
3881 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
3884 print
'<td class="right nowraponall">';
3885 if ($objp->baid > 0) {
3886 print $bankaccountstatic->getNomUrl(1,
'transactions');
3891 print
'<td class="center">';
3893 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
3899 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
3901 $totalpaid += $objp->amount;
3905 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
3931 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
3932 print
'<span class="opacitymedium">';
3934 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
3936 print $langs->trans(
'AlreadyPaid');
3941 print
'<td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td>';
3945 $resteapayeraffiche = $resteapayer;
3947 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
3950 $creditnoteamount = 0;
3953 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
3954 $sql .=
" re.description, re.fk_invoice_supplier_source";
3955 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
3956 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
3957 $resql =
$db->query($sql);
3959 $num =
$db->num_rows($resql);
3963 $obj =
$db->fetch_object($resql);
3964 $invoice->fetch($obj->fk_invoice_supplier_source);
3965 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3967 print $langs->trans(
"CreditNote").
' ';
3970 print $langs->trans(
"Deposit").
' ';
3972 print $invoice->getNomUrl(0);
3975 print
'<td class="right">';
3976 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&discountid='.$obj->rowid.
'">';
3977 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
3981 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
3985 $creditnoteamount += $obj->amount_ttc;
3988 $depositamount += $obj->amount_ttc;
3997 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
3998 print
'<span class="opacitymedium">';
3999 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
4003 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4005 $resteapayeraffiche = 0;
4006 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4010 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4011 print
'<span class="opacitymedium">';
4012 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
4016 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4019 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4023 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4024 print
'<span class="opacitymedium">';
4025 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
4029 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4031 $resteapayeraffiche = 0;
4032 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4036 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4037 $text = $langs->trans(
"HelpAbandonOther");
4039 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
4041 print
'<span class="opacitymedium">';
4043 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
4047 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4049 $resteapayeraffiche = 0;
4050 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4054 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4055 print
'<span class="opacitymedium">';
4056 print $langs->trans(
"Billed");
4060 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
4064 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4065 print
'<span class="opacitymedium">';
4066 print $langs->trans(
'RemainderToPay');
4067 if ($resteapayeraffiche < 0) {
4068 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4073 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
4078 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4079 print
'<span class="opacitymedium">';
4080 print $langs->trans(
'RemainderToPayMulticurrency');
4081 if ($resteapayeraffiche < 0) {
4082 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4087 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price(
price2num($multicurrency_resteapayer,
'MT'), 0, $langs, 1, -1, -1,
$object->multicurrency_code).
'</td>';
4091 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4094 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4095 print $langs->trans(
'AlreadyPaidBack');
4098 print
'<td class="right">'.price($sign * $totalpaid).
'</td>';
4102 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">'.$langs->trans(
"Billed").
'</td>';
4104 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
4108 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4109 print
'<span class="opacitymedium">';
4110 print $langs->trans(
'RemainderToPayBack');
4111 if ($resteapayeraffiche > 0) {
4112 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4117 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
4122 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4123 print
'<span class="opacitymedium">';
4124 print $langs->trans(
'RemainderToPayBackMulticurrency');
4125 if ($resteapayeraffiche > 0) {
4126 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4131 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>';
4147 print
'<div class="clearboth"></div><br>';
4150 $blocname =
'contacts';
4151 $title = $langs->trans(
'ContactsAddresses');
4152 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4157 $blocname =
'notes';
4158 $title = $langs->trans(
'Notes');
4159 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4166 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
4167 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4168 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
4169 print
'<input type="hidden" name="mode" value="">';
4170 print
'<input type="hidden" name="page_y" value="">';
4171 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
4172 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
4173 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4177 include DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_ajaxrow.tpl.php';
4179 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
4183 print
'<div class="div-table-responsive-no-min">';
4184 print
'<table id="tablelines" class="noborder noshadow centpercent">';
4186 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
4189 $inputalsopricewithtax = 1;
4190 $senderissupplier = 2;
4191 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY')) {
4192 $senderissupplier =
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY');
4197 $object->printObjectLines($action, $societe,
$mysoc, $lineid, 1);
4204 if ($action !=
'editline') {
4207 $parameters = array();
4208 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
4212 if (empty($reshook)) {
4226 if ($action !=
'presend') {
4229 print
'<div class="tabsAction">';
4231 $parameters = array();
4232 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
4234 if (empty($reshook)) {
4237 $langs->load(
'subtotals');
4239 $url_button = array();
4241 $url_button[] = array(
4242 'lang' =>
'subtotals',
4244 'perm' => (
bool) $usercancreate,
4245 'label' => $langs->trans(
'AddTitleLine'),
4246 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_title_line'],
true)
4249 $url_button[] = array(
4250 'lang' =>
'subtotals',
4252 'perm' => (
bool) $usercancreate,
4253 'label' => $langs->trans(
'AddSubtotalLine'),
4254 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_subtotal_line'],
true)
4257 print
dolGetButtonAction(
'', $langs->trans(
'Subtotal'),
'default', $url_button,
'',
true);
4262 $ventilExportCompta =
$object->getVentilExportCompta();
4264 if ($ventilExportCompta == 0) {
4265 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=edit&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
4267 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
4272 $result = $discount->fetch(0, 0,
$object->id);
4279 if (!$objectidnext &&
$object->close_code !=
'replaced' && $usercancreate) {
4280 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
4282 if ($usercancreate) {
4283 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
4285 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
4295 if ($usercanvalidate) {
4296 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken().
'"';
4297 print
'>'.$langs->trans(
'Validate').
'</a>';
4299 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
4300 print
'>'.$langs->trans(
'Validate').
'</a>';
4306 if (empty($user->socid)) {
4309 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' =>
$object->id,
'action' =>
'presend',
'mode' =>
'init'],
true).
'#formmailbeforetitle',
'');
4318 $langs->load(
"withdrawals");
4319 if ($resteapayer > 0) {
4320 if ($usercancreatecreditransfer) {
4321 if (!$objectidnext &&
$object->close_code !=
'replaced') {
4322 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>';
4324 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeBankTransferOrder').
'</span>';
4336 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>';
4343 if ($resteapayer == 0) {
4344 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
4345 } elseif ($usercancreate) {
4346 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>';
4352 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
4356 && (
getDolGlobalString(
'SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') ||
$object->getSommePaiement() == 0)
4358 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>';
4362 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
4373 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaid').
'</a>';
4378 if ($totalpaid > 0 || $totalcreditnotes > 0) {
4380 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
4383 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
4395 if (!$objectidnext) {
4396 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>';
4401 if ($action !=
'edit' && $usercancreate) {
4402 print
'<a class="butAction butActionClone" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=clone&socid='.
$object->socid.
'&token='.
newToken().
'">'.$langs->trans(
'ToClone').
'</a>';
4407 if (!$objectidnext && count(
$object->lines) > 0) {
4408 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.
$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
4413 if ($action !=
'confirm_edit' && $usercandelete) {
4414 $isErasable =
$object->is_erasable();
4416 $enableDelete =
false;
4418 $params = (empty(
$conf->use_javascript_ajax) ? array() : array(
'attr' => array(
'class' =>
'reposition')));
4420 if ($isErasable == -4) {
4421 $htmltooltip = $langs->trans(
"DisabledBecausePayments");
4422 } elseif ($isErasable == -3) {
4423 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastSituationInvoice");
4424 } elseif ($isErasable == -2) {
4425 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastInvoice");
4426 } elseif ($isErasable == -1) {
4427 $htmltooltip = $langs->trans(
"DisabledBecauseDispatchedInBookkeeping");
4428 } elseif ($isErasable <= 0) {
4429 $htmltooltip = $langs->trans(
"DisabledBecauseNotErasable");
4431 $enableDelete =
true;
4434 print
dolGetButtonAction($htmltooltip, $langs->trans(
"Delete"),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken(), (
string)
$object->id, $enableDelete, $params);
4438 if ($action !=
'confirm_edit') {
4439 print
'<div class="fichecenter"><div class="fichehalfleft">';
4445 $subdir =
get_exdir(
$object->id, 2, 0, 0, $object,
'invoice_supplier').$ref;
4447 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.
$object->id;
4448 $genallowed = $usercanread;
4449 $delallowed = $usercancreate;
4453 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, (
int) $genallowed, (
int) $delallowed, $modelpdf, $genifempty, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
4454 $somethingshown = $formfile->numoffiles;
4457 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice_supplier'), 1);
4458 $linktoelem = $tmparray[
'linktoelem'];
4459 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
4460 print $htmltoenteralink;
4462 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
4464 print
'</div><div class="fichehalfright">';
4467 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
4469 $somethingshown = $formactions->showactions($object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
4471 print
'</div></div>';
4477 if (
GETPOST(
'modelselected')) {
4478 $action =
'presend';
4482 $modelmail =
'invoice_supplier_send';
4483 $defaulttopic =
'SendBillRef';
4485 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
4486 $trackid =
'sinv'.$object->id;
4488 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 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)
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
$date_start
Variables from include:
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.
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 '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
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).
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
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...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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.