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');
107$hookmanager->initHooks(array(
'invoicesuppliercard',
'globalcard'));
113$extrafields->fetch_name_optionals_label(
$object->table_element);
116if ($id > 0 || !empty($ref)) {
117 $ret =
$object->fetch($id, $ref);
124 $ret =
$object->fetch_thirdparty();
132if (!empty($user->socid)) {
133 $socid = $user->socid;
137$result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture',
'fk_soc',
'rowid', $isdraft);
140$usercanread = ($user->hasRight(
"fournisseur",
"facture",
"lire") || $user->hasRight(
"supplier_invoice",
"lire"));
141$usercancreate = ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"));
142$usercandelete = (($user->hasRight(
"fournisseur",
"facture",
"supprimer") || $user->hasRight(
"supplier_invoice",
"supprimer")) || ($usercancreate &&
$object->is_erasable() == 1));
143$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
146$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"validate")));
147$usercansend = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"send"));
148$usercancreatecreditransfer = $user->hasRight(
'paymentbybanktransfer',
'create');
151$permissionnote = $usercancreate;
152$permissiondellink = $usercancreate;
153$permissiontoedit = $usercancreate;
154$permissiontoadd = $usercancreate;
155$permissiontodelete = $usercandelete;
156$permissiontoeditextra = $permissiontoadd;
157if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
159 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
170$parameters = array(
'socid' => $socid);
171$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
176if (empty($reshook)) {
177 $backurlforlist =
dolBuildUrl(DOL_URL_ROOT.
'/fourn/facture/list.php');
179 if (empty($backtopage) || ($cancel && empty($id))) {
180 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
181 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
182 $backtopage = $backurlforlist;
184 $backtopage =
dolBuildUrl(DOL_URL_ROOT.
'/fourn/facture/card.php', [
'id' => ((!empty($id) && $id > 0) ? $id :
'__ID__')]);
190 if (!empty($backtopageforcancel)) {
191 header(
"Location: ".$backtopageforcancel);
193 } elseif (!empty($backtopage)) {
194 header(
"Location: ".$backtopage);
200 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
202 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
204 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
207 if (
GETPOST(
'linkedOrder') && empty($cancel) && $id > 0 && $permissiontoadd) {
210 $result =
$object->add_object_linked(
'order_supplier',
GETPOSTINT(
'linkedOrder'));
214 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
216 '@phan-var-force FactureFournisseur $objectutil';
218 if (
GETPOST(
'newsupplierref',
'alphanohtml')) {
219 $objectutil->ref_supplier =
GETPOST(
'newsupplierref',
'alphanohtml');
223 $result = $objectutil->createFromClone($user, $id);
225 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
228 $langs->load(
"errors");
232 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
233 $idwarehouse =
GETPOST(
'idwarehouse');
238 $qualified_for_stock_change = 0;
240 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
242 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
247 $langs->load(
"stocks");
248 if (!$idwarehouse || $idwarehouse == -1) {
250 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
258 $result =
$object->validate($user,
'', $idwarehouse);
268 $outputlangs = $langs;
271 $newlang =
GETPOST(
'lang_id',
'aZ09');
274 $newlang =
$object->thirdparty->default_lang;
276 if (!empty($newlang)) {
278 $outputlangs->setDefaultLang($newlang);
283 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
290 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $permissiontodelete) {
294 $isErasable =
$object->is_erasable();
296 if ($usercandelete && $isErasable > 0) {
297 $revertstock =
GETPOST(
'revertstock');
302 $qualified_for_stock_change = 0;
304 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
306 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
311 $langs->load(
"stocks");
312 if (!$idwarehouse || $idwarehouse == -1) {
314 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
317 $result =
$object->setDraft($user, $idwarehouse);
326 $result =
$object->delete($user);
328 header(
'Location: list.php?restore_lastsearch_values=1');
335 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
337 $result =
$object->deleteLine($lineid);
357 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
364 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
367 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
368 if ($result > 0 &&
$object->id > 0 && $discount->fk_invoice_supplier ==
$object->id) {
369 $discount->unlink_invoice();
373 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercancreate) {
375 $result =
$object->setPaid($user);
379 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercancreate) {
382 $close_code =
GETPOST(
"close_code",
'restricthtml');
383 $close_note =
GETPOST(
"close_note",
'restricthtml');
385 $result =
$object->setPaid($user, $close_code, $close_note);
390 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
392 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
395 $close_code =
GETPOST(
"close_code",
'restricthtml');
396 $close_note =
GETPOST(
"close_note",
'restricthtml');
398 $result =
$object->setCanceled($user, $close_code, $close_note);
403 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
408 if ($action ==
'setref_supplier' && $usercancreate) {
411 if (
$object->update($user) < 0) {
415 $outputlangs = $langs;
418 $newlang =
GETPOST(
'lang_id',
'aZ09');
421 $newlang =
$object->thirdparty->default_lang;
423 if (!empty($newlang)) {
425 $outputlangs->setDefaultLang($newlang);
429 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
435 if ($action ==
'setconditions' && $usercancreate) {
437 $object->cond_reglement_code = 0;
438 $object->cond_reglement_id = 0;
453 $new_date_echeance =
$object->calculate_date_lim_reglement();
454 if ($new_date_echeance) {
455 $object->date_echeance = $new_date_echeance;
460 $result =
$object->update($user);
472 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
475 } elseif ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
478 } elseif ($action ==
'setmode' && $usercancreate) {
481 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
483 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
484 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
487 } elseif ($action ==
'setbankaccount' && $usercancreate) {
490 } elseif ($action ==
'setvatreversecharge' && $usercancreate) {
492 $vatreversecharge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
493 $result =
$object->setVATReverseCharge($vatreversecharge);
496 if ($action ==
'settransportmode' && $usercancreate) {
499 } elseif ($action ==
'setlabel' && $usercancreate) {
503 $result =
$object->update($user);
507 } elseif ($action ==
'setdatef' && $usercancreate) {
511 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
513 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
520 $date_echence_calc =
$object->calculate_date_lim_reglement();
521 if (!empty(
$object->date_echeance)) {
522 $object->date_echeance = $date_echence_calc;
528 $result =
$object->update($user);
532 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
536 $object->date_pointoftax = $date_pointoftax;
538 $result =
$object->update($user);
541 $action =
'editdate_pointoftax';
543 } elseif ($action ==
'setdate_lim_reglement' && $usercancreate) {
548 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
550 $result =
$object->update($user);
554 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
570 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
572 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
576 $remaintopay =
$object->getRemainToPay(0);
580 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
584 $result = $discount->link_to_invoice(0, $id);
591 $newremaintopay =
$object->getRemainToPay(0);
592 if ($newremaintopay == 0) {
603 $outputlangs = $langs;
606 $newlang =
GETPOST(
'lang_id',
'aZ09');
609 $newlang =
$object->thirdparty->default_lang;
611 if (!empty($newlang)) {
613 $outputlangs->setDefaultLang($newlang);
617 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
622 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
630 $result = $discountcheck->fetch(0, 0,
$object->id);
642 $amount_ht = $amount_tva = $amount_ttc = array();
643 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
647 foreach (
$object->lines as $line) {
648 if ($line->product_type < 9 && $line->total_ht != 0) {
649 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
651 $amount_ht[$keyforvatrate] += $line->total_ht;
652 $amount_tva[$keyforvatrate] += $line->total_tva;
653 $amount_ttc[$keyforvatrate] += $line->total_ttc;
654 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
655 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
656 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
660 '@phan-var-force array<string,float> $amount_ht
661 @phan-var-force array<string,float> $amount_tva
662 @phan-var-force array<string,float> $amount_ttc
663 @phan-var-force array<string,float> $multicurrency_amount_ht
664 @phan-var-force array<string,float> $multicurrency_amount_tva
665 @phan-var-force array<string,float> $multicurrency_amount_ttc';
669 $alreadypaid =
$object->getSommePaiement();
670 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
671 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
672 foreach ($amount_ht as $vatrate => $val) {
673 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
674 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
675 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
676 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
677 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
678 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
687 $discount->description =
'(CREDIT_NOTE)';
689 $discount->description =
'(DEPOSIT)';
691 $discount->description =
'(EXCESS PAID)';
693 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
695 $discount->discount_type = 1;
696 $discount->fk_soc =
$object->socid;
697 $discount->socid =
$object->socid;
698 $discount->fk_invoice_supplier_source =
$object->id;
706 $sql =
'SELECT SUM(pf.amount) as total_paiements';
707 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'paiementfourn as p';
708 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN ('.
getEntity(
'c_paiement').
')';
709 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
710 $sql .=
' AND pf.fk_paiementfourn = p.rowid';
711 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
713 $resql =
$db->query($sql);
718 $res =
$db->fetch_object($resql);
719 $total_paiements = $res->total_paiements;
722 $total_creditnote_and_deposit = 0;
723 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
724 $sql .=
" re.description, re.fk_invoice_supplier_source";
725 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
726 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
727 $resql =
$db->query($sql);
728 if (!empty($resql)) {
729 while ($obj =
$db->fetch_object($resql)) {
730 $total_creditnote_and_deposit += $obj->amount_ttc;
736 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
737 $discount->amount_tva = 0;
738 $discount->tva_tx = 0;
739 $discount->vat_src_code =
'';
742 $discount->multicurrency_code =
$object->multicurrency_code;
743 $discount->multicurrency_tx =
$object->multicurrency_tx;
744 $discount->multicurrency_total_ht = $discount->multicurrency_total_ttc = (float)
price2num((
float) $discount->amount_ttc * (float)
$object->multicurrency_tx,
'MT');
745 $discount->multicurrency_total_tva = 0;
747 $discount->multicurrency_amount_ht = $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
748 $discount->multicurrency_amount_tva = 0;
750 $result = $discount->create($user);
756 foreach ($amount_ht as $tva_tx => $xxx) {
758 $discount->multicurrency_code =
$object->multicurrency_code;
759 $discount->multicurrency_tx =
$object->multicurrency_tx;
762 $discount->amount_ht = -((float) $amount_ht[$tva_tx]);
763 $discount->amount_tva = -((float) $amount_tva[$tva_tx]);
764 $discount->amount_ttc = -((float) $amount_ttc[$tva_tx]);
765 $discount->multicurrency_total_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
766 $discount->multicurrency_total_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
767 $discount->multicurrency_total_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
769 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
770 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
771 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
772 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
773 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
774 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
777 $discount->multicurrency_amount_ht = $discount->multicurrency_total_ht;
778 $discount->multicurrency_amount_tva = $discount->multicurrency_total_tva;
779 $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
784 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
785 $vat_src_code = $reg[1];
786 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
789 $discount->tva_tx = abs((
float) $tva_tx);
790 $discount->vat_src_code = $vat_src_code;
792 $result = $discount->create($user);
803 $result =
$object->setPaid($user);
818 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate) {
823 $result = $paiementfourn->fetch(
GETPOSTINT(
'paiement_id'));
825 $result = $paiementfourn->delete($user);
827 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
835 } elseif ($action ==
'add' && $usercancreate) {
840 $selectedLines =
GETPOST(
'toselect',
'array:int');
848 $ret = $extrafields->setOptionalsFromPost(
null, $object);
862 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
867 if (empty($dateinvoice)) {
868 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
880 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
896 $object->date_pointoftax = $date_pointoftax;
897 $object->date_echeance = $datedue;
903 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
904 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
906 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
907 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
928 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
931 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
936 if (empty($dateinvoice)) {
937 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
947 if (!
GETPOST(
'ref_supplier')) {
948 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
956 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
971 $object->date_pointoftax = $date_pointoftax;
972 $object->date_echeance = $datedue;
978 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
979 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
981 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
982 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
987 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
996 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
998 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1001 foreach ($facture_source->lines as $line) {
1003 if (method_exists($line,
'fetch_optionals')) {
1004 $line->fetch_optionals();
1008 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1009 $fk_parent_line = 0;
1012 $line->fk_facture_fourn =
$object->id;
1013 $line->fk_parent_line = $fk_parent_line;
1015 $line->subprice = -$line->subprice;
1016 $line->pa_ht = -((float) $line->pa_ht);
1017 $line->total_ht = -$line->total_ht;
1018 $line->total_tva = -$line->total_tva;
1019 $line->total_ttc = -$line->total_ttc;
1020 $line->total_localtax1 = -$line->total_localtax1;
1021 $line->total_localtax2 = -$line->total_localtax2;
1022 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1023 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1024 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1026 $result = $line->insert();
1031 if ($result > 0 && $line->product_type == 9) {
1032 $fk_parent_line = $result;
1040 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 &&
$id > 0) {
1042 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1043 $totalpaid = $facture_source->getSommePaiement();
1044 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1045 $totaldeposits = $facture_source->getSumDepositsUsed();
1046 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1047 $desc = $langs->trans(
'invoiceAvoirLineWithPaymentRestAmount');
1051 $retAddLine =
$object->addline($desc, -$remain_to_pay, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
'TTC');
1053 if ($retAddLine < 0) {
1060 if (!empty(
$object->fk_facture_source) && $id > 0) {
1062 if ($facture_source_link->fetch(
$object->fk_facture_source) > 0) {
1063 $facture_source_link->fetchObjectLinked();
1064 if (!empty($facture_source_link->linkedObjectsIds)) {
1065 foreach ($facture_source_link->linkedObjectsIds as $sourcetype => $TIds) {
1066 $object->add_object_linked($sourcetype, current($TIds));
1074 if (empty($dateinvoice)) {
1076 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1086 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1096 $object->date_pointoftax = $date_pointoftax;
1097 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1098 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1107 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1108 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1112 $object->fac_rec = $fac_recid;
1114 $fac_rec->fetch(
$object->fac_rec);
1115 $fac_rec->fetch_lines();
1116 $object->lines = $fac_rec->lines;
1123 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1128 if (empty($dateinvoice)) {
1129 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1139 if (!
GETPOST(
'ref_supplier')) {
1140 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
1148 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1165 $object->date_pointoftax = $date_pointoftax;
1166 $object->date_echeance = $datedue;
1172 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1173 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1175 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1176 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1181 if (empty(
$object->date_echeance)) {
1182 $object->date_echeance =
$object->calculate_date_lim_reglement();
1188 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
1190 $element = $subelement =
GETPOST(
'origin',
'alpha');
1198 if ($element ==
'order') {
1199 $element = $subelement =
'commande';
1201 if ($element ==
'propal') {
1202 $element =
'comm/propal';
1203 $subelement =
'propal';
1205 if ($element ==
'contract') {
1206 $element = $subelement =
'contrat';
1208 if ($element ==
'order_supplier') {
1210 $subelement =
'fournisseur.commande';
1212 if ($element ==
'project') {
1213 $element =
'projet';
1221 $classname = ucfirst($subelement);
1222 if ($classname ==
'Fournisseur.commande') {
1223 $classname =
'CommandeFournisseur';
1225 $objectsrc =
new $classname(
$db);
1226 $objectsrc->fetch($originid);
1227 $objectsrc->fetch_thirdparty();
1229 if (!empty(
$object->origin_type) && !empty(
$object->origin_id)) {
1234 if (
$object->origin_type ==
'reception') {
1235 $objectsrc->fetchObjectLinked();
1237 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1238 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1239 $object->linkedObjectsIds[
'order_supplier'][-1] = $value;
1249 $classname = ucfirst($subelement);
1250 if ($classname ==
'Fournisseur.commande') {
1251 $classname =
'CommandeFournisseur';
1253 $srcobject =
new $classname(
$db);
1255 $result = $srcobject->fetch(
GETPOSTINT(
'originid'));
1258 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1263 $amountdeposit = array();
1265 if ($typeamount ==
'amount') {
1266 $amount = $valuedeposit;
1268 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1271 $TTotalByTva = array();
1272 foreach ($srcobject->lines as &$line) {
1273 if (!empty($line->special_code)) {
1276 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1278 '@phan-var-force array<string,float> $TTotalByTva';
1280 $amount_ttc_diff = 0.;
1281 foreach ($TTotalByTva as $tva => &$total) {
1282 $coef = $total / $srcobject->total_ttc;
1283 $am = $amount * $coef;
1284 $amount_ttc_diff += $am;
1285 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1288 if ($typeamount ==
'amount') {
1289 $amountdeposit[0] = $valuedeposit;
1290 } elseif ($typeamount ==
'variable') {
1293 $lines = $srcobject->lines;
1294 $numlines = count($lines);
1295 for ($i = 0; $i < $numlines; $i++) {
1297 if (empty($lines[$i]->qty)) {
1300 if (!empty($lines[$i]->special_code)) {
1304 $totalamount += $lines[$i]->total_ht;
1305 $tva_tx = $lines[$i]->tva_tx;
1306 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1310 if ($totalamount == 0) {
1311 $amountdeposit[0] = 0;
1316 $amountdeposit[0] = 0;
1320 $amount_ttc_diff = array_key_exists(0, $amountdeposit) ? $amountdeposit[0] : 0;
1323 foreach ($amountdeposit as $tva => $amount) {
1324 if (empty($amount)) {
1329 'amount' =>
'FixAmount',
1330 'variable' =>
'VarAmount'
1332 $descline =
'(DEPOSIT)';
1334 if ($typeamount ==
'amount') {
1335 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1336 } elseif ($typeamount ==
'variable') {
1337 $descline .=
' ('.$valuedeposit.
'%)';
1340 $descline .=
' - '.$srcobject->ref;
1370 $diff =
$object->total_ttc - $amount_ttc_diff;
1374 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1380 $object->lines[0]->localtax1_tx,
1381 $object->lines[0]->localtax2_tx,
1383 $object->lines[0]->fk_product,
1386 $object->lines[0]->product_type,
1387 $object->lines[0]->remise_percent,
1389 $object->lines[0]->date_start,
1398 } elseif ($result > 0) {
1399 $lines = $srcobject->lines;
1400 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1401 $srcobject->fetch_lines();
1402 $lines = $srcobject->lines;
1405 $num = count($lines);
1406 for ($i = 0; $i < $num; $i++) {
1407 if (!in_array($lines[$i]->
id, $selectedLines)) {
1411 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->product_label);
1412 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1415 if (method_exists($lines[$i],
'fetch_optionals')) {
1416 $lines[$i]->fetch_optionals();
1422 if ($lines[$i]->date_debut_reel) {
1425 if ($lines[$i]->date_start) {
1428 $date_end = $lines[$i]->date_fin_prevue;
1429 if ($lines[$i]->date_fin_reel) {
1430 $date_end = $lines[$i]->date_fin_reel;
1432 if ($lines[$i]->date_end) {
1433 $date_end = $lines[$i]->date_end;
1436 $tva_tx = $lines[$i]->tva_tx;
1438 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
1439 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1443 $object->special_code = $lines[$i]->special_code;
1448 $pu_currency = $lines[$i]->multicurrency_subprice;
1450 $pu = $lines[$i]->subprice;
1459 $lines[$i]->localtax1_tx,
1460 $lines[$i]->localtax2_tx,
1462 $lines[$i]->fk_product,
1463 $lines[$i]->remise_percent,
1467 $lines[$i]->info_bits,
1472 $lines[$i]->array_options,
1473 $lines[$i]->fk_unit,
1476 $lines[$i]->ref_supplier,
1477 $lines[$i]->special_code
1486 if ($result > 0 && !empty($lines[$i]->extraparams)) {
1488 $newline->id = $result;
1489 $newline->extraparams = $lines[$i]->extraparams;
1490 $newline->setExtraParameters();
1502 $parameters = array(
'objFrom' => $srcobject);
1503 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1513 } elseif (!$error) {
1523 $langs->load(
"errors");
1531 $categories =
GETPOST(
'categories',
'array:int');
1532 if (method_exists($object,
'setCategories')) {
1533 $object->setCategories($categories);
1540 $outputlangs = $langs;
1541 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1548 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1551 } elseif ($action ==
'updateline' && $usercancreate) {
1555 if (!
$object->fetch($id) > 0) {
1561 $tva_tx = str_replace(
'*',
'', $tva_tx);
1563 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_subprice') !=
'') {
1565 $price_base_type =
'HT';
1568 $price_base_type =
'TTC';
1571 if (
GETPOST(
'productid') > 0) {
1573 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY') == 1) {
1575 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1581 $label =
$prod->description;
1582 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1583 $label =
GETPOST(
'product_desc',
'restricthtml');
1586 $type =
$prod->type;
1588 $label =
GETPOST(
'product_desc',
'restricthtml');
1597 if (preg_match(
'/\*/', $tva_tx)) {
1602 $tva_tx = str_replace(
'*',
'', $tva_tx);
1610 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1611 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1613 if (is_array($extralabelsline)) {
1614 foreach ($extralabelsline as $key => $value) {
1615 unset($_POST[
"options_".$key]);
1619 $result =
$object->updateline(
1631 (
float) $remise_percent,
1641 unset($_POST[
'label']);
1642 unset($_POST[
'fourn_ref']);
1643 unset($_POST[
'date_starthour']);
1644 unset($_POST[
'date_startmin']);
1645 unset($_POST[
'date_startsec']);
1646 unset($_POST[
'date_startday']);
1647 unset($_POST[
'date_startmonth']);
1648 unset($_POST[
'date_startyear']);
1649 unset($_POST[
'date_endhour']);
1650 unset($_POST[
'date_endmin']);
1651 unset($_POST[
'date_endsec']);
1652 unset($_POST[
'date_endday']);
1653 unset($_POST[
'date_endmonth']);
1654 unset($_POST[
'date_endyear']);
1655 unset($_POST[
'price_ttc']);
1656 unset($_POST[
'price_ht']);
1663 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
1667 foreach (
$object->lines as $line) {
1668 if ($line->product_type == 1) {
1669 $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);
1672 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
1674 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
1675 $remise_percent = (float) str_replace(
'*',
'', $remise_percent);
1676 foreach (
$object->lines as $line) {
1677 $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);
1679 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !=
'' && $usercancreate) {
1681 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1682 $vat_rate = str_replace(
'*',
'', $vat_rate);
1685 foreach (
$object->lines as $line) {
1686 $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);
1688 } elseif ($action ==
'addline' && $usercancreate) {
1697 $ret =
$object->fetch_thirdparty();
1699 $langs->load(
'errors');
1708 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1709 if ($prod_entry_mode ==
'free') {
1716 $price_ht_devise =
'';
1718 $price_ttc_devise =
'';
1720 if (
GETPOST(
'price_ht') !==
'') {
1723 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
1726 if (
GETPOST(
'price_ttc') !==
'') {
1729 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
1730 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
1738 if (empty($remise_percent)) {
1739 $remise_percent = 0;
1743 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1744 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
1746 if (is_array($extralabelsline)) {
1748 foreach ($extralabelsline as $key => $value) {
1749 unset($_POST[
"options_".$key]);
1753 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
1754 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1757 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOSTINT(
'type') < 0) {
1758 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
1763 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1')
1764 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
1765 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
1766 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
1767 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
1768 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
1769 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) {
1770 $langs->load(
"errors");
1771 if (
$object->type == $object::TYPE_DEPOSIT) {
1773 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
1775 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPrice"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
1780 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
1781 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
1785 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') && !
GETPOST(
'dp_desc')) {
1786 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
1789 if (!
GETPOST(
'qty',
'alpha')) {
1790 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1794 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
1795 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
1799 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1800 $idprod = $res->fk_product_child;
1802 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
1808 if ($prod_entry_mode !=
'free' && empty($error)) {
1812 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
1817 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
1818 $idprod = (int) $reg[1];
1819 $res = $productsupplier->fetch($idprod);
1822 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
1824 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1825 if ($productsupplier->fourn_socid != $socid) {
1826 $productsupplier->ref_supplier =
'';
1829 $fksoctosearch =
$object->thirdparty->id;
1830 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1832 } elseif (
GETPOSTINT(
'idprodfournprice') > 0) {
1833 $qtytosearch = (float) $qty;
1835 $idprod = $productsupplier->get_buyprice(
GETPOSTINT(
'idprodfournprice'), $qtytosearch);
1836 $res = $productsupplier->fetch($idprod);
1840 $label = $productsupplier->label;
1843 $outputlangs = $langs;
1845 if (
GETPOST(
'lang_id',
'aZ09')) {
1846 $newlang =
GETPOST(
'lang_id',
'aZ09');
1848 if (empty($newlang)) {
1849 $newlang =
$object->thirdparty->default_lang;
1851 if (!empty($newlang)) {
1853 $outputlangs->setDefaultLang($newlang);
1855 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
1857 $desc = $productsupplier->description;
1860 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
1861 $desc = $productsupplier->desc_supplier;
1872 $ref_supplier = $productsupplier->ref_supplier;
1876 $tmpidprodfournprice =
GETPOST(
'idprodfournprice',
'alpha');
1877 if (is_numeric($tmpidprodfournprice) && (
int) $tmpidprodfournprice > 0) {
1878 $tmpidprodfournprice = (int) $tmpidprodfournprice;
1880 $tmpidprodfournprice = 0;
1886 if (empty($tva_tx) || empty($tva_npr)) {
1892 $type = $productsupplier->type;
1893 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1894 $price_base_type =
'HT';
1896 $pu_devise =
price2num($price_ht_devise,
'CU');
1897 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
1898 $price_base_type =
'TTC';
1900 $pu_devise =
price2num($price_ttc_devise,
'CU');
1902 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
1903 if (empty(
$object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code !=
$object->multicurrency_code)) {
1904 $pu = $productsupplier->fourn_pu;
1907 $pu = $productsupplier->fourn_pu;
1908 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
1912 $ref_supplier = $productsupplier->ref_supplier;
1933 min($rank, count(
$object->lines) + 1),
1936 $productsupplier->fk_unit,
1939 GETPOST(
'fourn_ref',
'alpha'),
1943 if ($idprod == -99 || $idprod == 0) {
1946 $langs->load(
"errors");
1947 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
1949 if ($idprod == -1) {
1952 $langs->load(
"errors");
1953 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
1955 } elseif (empty($error)) {
1956 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1957 $tva_tx = str_replace(
'*',
'', $tva_tx);
1958 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1961 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
1965 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1973 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1977 $pu_ht =
price2num((
float) $pu_ttc / (1 + ((
float) $tva_tx / 100)),
'MU');
1979 $price_base_type =
'HT';
1980 $pu_devise =
price2num($price_ht_devise,
'CU');
1982 $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);
1986 if (!$error && $result > 0) {
1991 $outputlangs = $langs;
1994 $newlang =
GETPOST(
'lang_id',
'aZ09');
1997 $newlang =
$object->thirdparty->default_lang;
1999 if (!empty($newlang)) {
2001 $outputlangs->setDefaultLang($newlang);
2006 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2012 unset($_POST [
'prod_entry_mode']);
2014 unset($_POST[
'qty']);
2015 unset($_POST[
'type']);
2016 unset($_POST[
'remise_percent']);
2017 unset($_POST[
'pu']);
2018 unset($_POST[
'price_ht']);
2019 unset($_POST[
'multicurrency_price_ht']);
2020 unset($_POST[
'price_ttc']);
2021 unset($_POST[
'fourn_ref']);
2022 unset($_POST[
'tva_tx']);
2023 unset($_POST[
'label']);
2024 unset($localtax1_tx);
2025 unset($localtax2_tx);
2026 unset($_POST[
'np_marginRate']);
2027 unset($_POST[
'np_markRate']);
2028 unset($_POST[
'dp_desc']);
2029 unset($_POST[
'idprodfournprice']);
2030 unset($_POST[
'units']);
2032 unset($_POST[
'date_starthour']);
2033 unset($_POST[
'date_startmin']);
2034 unset($_POST[
'date_startsec']);
2035 unset($_POST[
'date_startday']);
2036 unset($_POST[
'date_startmonth']);
2037 unset($_POST[
'date_startyear']);
2038 unset($_POST[
'date_endhour']);
2039 unset($_POST[
'date_endmin']);
2040 unset($_POST[
'date_endsec']);
2041 unset($_POST[
'date_endday']);
2042 unset($_POST[
'date_endmonth']);
2043 unset($_POST[
'date_endyear']);
2050 } elseif ($action ==
'classin' && $usercancreate) {
2052 $result =
$object->setProject($projectid);
2053 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
2057 $totalpaid =
$object->getSommePaiement();
2058 $resteapayer =
$object->total_ttc - $totalpaid;
2061 $ventilExportCompta =
$object->getVentilExportCompta();
2063 if (!$ventilExportCompta) {
2066 $idwarehouse =
GETPOST(
'idwarehouse');
2070 $qualified_for_stock_change = 0;
2072 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2074 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2079 $langs->load(
"stocks");
2080 if (!$idwarehouse || $idwarehouse == -1) {
2082 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
2087 $object->setDraft($user, $idwarehouse);
2091 $outputlangs = $langs;
2094 $newlang =
GETPOST(
'lang_id',
'aZ09');
2097 $newlang =
$object->thirdparty->default_lang;
2099 if (!empty($newlang)) {
2101 $outputlangs->setDefaultLang($newlang);
2106 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2115 } elseif ($action ==
'reopen' && $usercancreate) {
2117 $result =
$object->fetch($id);
2120 $result =
$object->setUnpaid($user);
2122 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
2131 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2134 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
2136 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
2137 $trackid =
'sinv'.$object->id;
2138 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2142 $permissiontoadd = $usercancreate;
2143 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2146 if ($action ==
'calculate' && $usercancreate) {
2147 $calculationrule =
GETPOST(
'calculationrule');
2151 $result =
$object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0,
$object->thirdparty);
2157 if ($action ==
'update_extras' && $permissiontoeditextra) {
2160 $attribute_name =
GETPOST(
'attribute',
'aZ09');
2163 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
2169 $result =
$object->updateExtraField($attribute_name,
'BILL_SUPPLIER_MODIFY');
2177 $action =
'edit_extras';
2182 if ($action ==
'addcontact' && $usercancreate) {
2183 $result =
$object->fetch($id);
2185 if ($result > 0 && $id > 0) {
2188 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2192 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2195 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2196 $langs->load(
"errors");
2197 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2202 } elseif ($action ==
'swapstatut' && $usercancreate) {
2209 } elseif ($action ==
'deletecontact' && $usercancreate) {
2215 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2239$title =
$object->ref.
" - ".$langs->trans(
'Card');
2240if ($action ==
'create') {
2241 $title = $langs->trans(
"NewSupplierInvoice");
2243$help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
2244llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-fourn-facture page-card');
2247if ($action ==
'create') {
2249 $selectedLines = array();
2251 print
load_fiche_titre($langs->trans(
'NewSupplierInvoice'),
'',
'supplier_invoice');
2255 $currency_code =
$conf->currency;
2256 $vat_reverse_charge = 0;
2262 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2263 $currency_code = $societe->multicurrency_code;
2268 if (!empty($origin) && !empty($originid)) {
2270 $element = $subelement = $origin;
2272 if ($element ==
'project') {
2273 $projectid = $originid;
2274 $element =
'projet';
2278 if ($element ==
'order') {
2279 $element = $subelement =
'commande';
2281 if ($element ==
'propal') {
2282 $element =
'comm/propal';
2283 $subelement =
'propal';
2285 if ($element ==
'contract') {
2286 $element = $subelement =
'contrat';
2288 if ($element ==
'order_supplier') {
2290 $subelement =
'fournisseur.commande';
2294 $classname = ucfirst($subelement);
2295 if ($classname ==
'Fournisseur.commande') {
2296 $classname =
'CommandeFournisseur';
2298 $objectsrc =
new $classname(
$db);
2299 '@phan-var-force Project|Commande|Propal|Facture|Contrat|CommandeFournisseur|CommonObject $objectsrc';
2301 $objectsrc->fetch($originid);
2302 $objectsrc->fetch_thirdparty();
2304 $projectid = (int) $objectsrc->fk_project;
2306 $soc = $objectsrc->thirdparty;
2308 $cond_reglement_id = 0;
2309 $mode_reglement_id = 0;
2311 $transport_mode_id = 0;
2314 if (!empty($objectsrc->cond_reglement_id)) {
2315 $cond_reglement_id = $objectsrc->cond_reglement_id;
2317 if (!empty($objectsrc->mode_reglement_id)) {
2318 $mode_reglement_id = $objectsrc->mode_reglement_id;
2320 if (!empty($objectsrc->fk_account)) {
2321 $fk_account = $objectsrc->fk_account;
2323 if (!empty($objectsrc->transport_mode_id)) {
2324 $transport_mode_id = $objectsrc->transport_mode_id;
2327 if (empty($cond_reglement_id)
2328 || empty($mode_reglement_id)
2329 || empty($fk_account)
2330 || empty($transport_mode_id)
2332 if ($origin ==
'reception') {
2334 if (!isset($objectsrc->supplier_order)) {
2335 $objectsrc->fetch_origin();
2338 if (!empty($objectsrc->origin_object)) {
2339 $originObject = $objectsrc->origin_object;
2340 if (empty($cond_reglement_id) && !empty($originObject->cond_reglement_id)) {
2341 $cond_reglement_id = $originObject->cond_reglement_id;
2343 if (empty($mode_reglement_id) && !empty($originObject->mode_reglement_id)) {
2344 $mode_reglement_id = $originObject->mode_reglement_id;
2346 if (empty($fk_account) && !empty($originObject->fk_account)) {
2347 $fk_account = $originObject->fk_account;
2349 if (empty($transport_mode_id) && !empty($originObject->transport_mode_id)) {
2350 $transport_mode_id = $originObject->transport_mode_id;
2357 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
2358 $cond_reglement_id = $soc->cond_reglement_supplier_id;
2360 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
2361 $mode_reglement_id = $soc->mode_reglement_supplier_id;
2363 if (empty($fk_account) && !empty($soc->fk_account)) {
2364 $fk_account = $soc->fk_account;
2366 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
2367 $transport_mode_id = $soc->transport_mode_id;
2373 if (!empty($objectsrc->multicurrency_code)) {
2374 $currency_code = $objectsrc->multicurrency_code;
2376 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
2377 $currency_tx = $objectsrc->multicurrency_tx;
2382 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2384 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2387 $objectsrc->fetch_optionals();
2388 $object->array_options = $objectsrc->array_options;
2390 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2391 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2392 $vat_reverse_charge = (empty($societe) ?
'' : $societe->vat_reverse_charge);
2393 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2394 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2396 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalInt(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2398 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2400 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2401 $currency_code = $societe->multicurrency_code;
2406 if (empty($cond_reglement_id)) {
2407 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2411 if (empty($mode_reglement_id)) {
2412 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2416 if (!
GETPOST(
'changecompany')) {
2418 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
2421 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
2428 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
2429 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
2431 if ($origin ==
'contrat') {
2432 $langs->load(
"admin");
2433 $text = $langs->trans(
"ToCreateARecurringInvoice");
2434 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"SupplierBills"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
2436 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
2438 print
info_admin($text, 0, 0,
'0',
'opacitymedium').
'<br>';
2441 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2442 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2443 print
'<input type="hidden" name="action" value="add">';
2444 print
'<input type="hidden" name="changecompany" value="0">';
2446 if (!empty($societe->id) && $societe->id > 0) {
2447 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2449 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2450 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2451 if (!empty($currency_tx)) {
2452 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2454 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2459 $parameters = array();
2461 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierInvoice', $parameters, $object, $action);
2462 if (empty($reshook)) {
2463 print
'<table class="border centpercent">';
2470 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2471 $invoice_predefined->fetch($fac_recid);
2475 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2478 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2479 $absolute_discount = $societe->getAvailableDiscounts(
null,
'', 0, 1);
2480 print $societe->getNomUrl(1,
'supplier');
2481 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2483 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2484 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');
2487 print
'<script type="text/javascript">
2488 $(document).ready(function() {
2489 $("#socid").change(function() {
2490 console.log("We have changed the company - Reload page");
2492 $("input[name=action]").val("create");
2493 $("input[name=changecompany]").val("1");
2494 $("form[name=add]").submit();
2499 if ($fac_recid <= 0) {
2500 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>';
2506 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2507 $invoice_predefined->fetch($fac_recid);
2509 $dateinvoice = $invoice_predefined->date_when;
2510 if (empty($projectid)) {
2511 $projectid = $invoice_predefined->fk_project;
2513 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2514 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2515 $fk_account = $invoice_predefined->fk_account;
2516 $note_public = $invoice_predefined->note_public;
2517 $note_private = $invoice_predefined->note_private;
2519 if (!empty($invoice_predefined->multicurrency_code)) {
2520 $currency_code = $invoice_predefined->multicurrency_code;
2522 if (!empty($invoice_predefined->multicurrency_tx)) {
2523 $currency_tx = $invoice_predefined->multicurrency_tx;
2526 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2527 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2528 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2530 $resql =
$db->query($sql);
2532 $num =
$db->num_rows($resql);
2536 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2538 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2539 print
'<option value="0" selected></option>';
2541 $objp =
$db->fetch_object($resql);
2542 print
'<option value="'.$objp->rowid.
'"';
2543 if ($fac_recid == $objp->rowid) {
2545 $exampletemplateinvoice->fetch($fac_recid);
2547 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2553 print
'<script type="text/javascript">
2554 $(document).ready(function() {
2555 $("#fac_rec").change(function() {
2556 console.log("We have changed the template invoice - Reload page");
2558 $("input[name=action]").val("create");
2559 $("form[name=add]").submit();
2572 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2574 print
'<div class="tagtable">'.
"\n";
2577 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2578 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
'checked').
'> ';
2579 $desc = $form->textwithpicto($tmp.
'<label for="radio_standard">'.$langs->trans(
"InvoiceStandardAsk").
'</label>', $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2581 print
'</div></div>';
2583 if (empty($origin) || (($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') && !empty($originid))) {
2586 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2587 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOSTINT(
'type') == 3 ?
' checked' :
'') .
'> ';
2588 print
'<script type="text/javascript">
2589 jQuery(document).ready(function() {
2590 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2591 jQuery("#radio_standard").prop("checked", true);
2593 jQuery("#typedeposit, #valuedeposit").click(function() {
2594 jQuery("#radio_deposit").prop("checked", true);
2596 jQuery("#typedeposit").change(function() {
2597 console.log("We change type of down payment");
2598 jQuery("#radio_deposit").prop("checked", true);
2599 setRadioForTypeOfInvoice();
2601 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2602 setRadioForTypeOfInvoice();
2604 function setRadioForTypeOfInvoice() {
2605 console.log("Change radio");
2606 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2607 jQuery(".checkforselect").prop("disabled", true);
2608 jQuery(".checkforselect").prop("checked", false);
2610 jQuery(".checkforselect").prop("disabled", false);
2611 jQuery(".checkforselect").prop("checked", true);
2617 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2619 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2620 print
'<table class="nobordernopadding"><tr>';
2624 if ($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') {
2625 print
'<td class="nowrap" style="padding-left: 15px">';
2627 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2628 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2629 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2631 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
2632 $valuedeposit =
GETPOST(
'valuedeposit',
'int');
2633 $deposit_percent =
null;
2634 if ($origin ==
'reception') {
2636 if (!isset($objectsrc->origin_object)) {
2637 $objectsrc->fetch_origin();
2639 if (!empty($objectsrc->origin_object)) {
2640 $deposit_percent = $objectsrc->origin_object->deposit_percent;
2642 } elseif (!empty($objectsrc->deposit_percent)) {
2643 $deposit_percent = $objectsrc->deposit_percent;
2645 if (empty($typedeposit) && !empty($deposit_percent)) {
2646 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
2647 if (!empty($origin_payment_conditions_deposit_percent)) {
2648 $typedeposit =
'variable';
2651 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($deposit_percent)) {
2652 $valuedeposit = $deposit_percent;
2654 print $form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
2656 print
'<td class="nowrap" style="padding-left: 5px">';
2657 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' . $valuedeposit .
'"/>';
2660 print
'</tr></table>';
2662 print
'</div></div>';
2731 if (empty($origin)) {
2732 if (!empty($societe->id) && $societe->id > 0) {
2736 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2743 foreach ($facids as $key => $valarray) {
2744 $newinvoice_static->id = $key;
2745 $newinvoice_static->ref = $valarray [
'ref'];
2746 $newinvoice_static->status = $valarray [
'status'];
2747 $newinvoice_static->statut = $valarray [
'status'];
2748 $newinvoice_static->type = $valarray [
'type'];
2749 $newinvoice_static->paid = $valarray [
'paye'];
2750 $newinvoice_static->paye = $valarray [
'paye'];
2752 $optionsav .=
'<option value="'.$key.
'"';
2754 $optionsav .=
' selected';
2756 $newinvoice_static->fetch_optionals($key);
2757 $object->array_options = $newinvoice_static->array_options;
2760 $optionsav .= $newinvoice_static->ref;
2761 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
2762 $optionsav .=
'</option>';
2765 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2766 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOSTINT(
'type') == 2 ?
' checked' :
'');
2768 $tmp .=
' disabled';
2772 print
'<script type="text/javascript">
2773 jQuery(document).ready(function() {
2774 if (! jQuery("#radio_creditnote").is(":checked"))
2776 jQuery("#credit_note_options").hide();
2778 jQuery("#radio_creditnote").click(function() {
2779 jQuery("#credit_note_options").show();
2781 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2782 jQuery("#credit_note_options").hide();
2786 $text = $tmp.
'<label for="radio_creditnote">'.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
2788 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2790 $text .=
' disabled';
2794 $text .=
'<option value="-1"></option>';
2795 $text .= $optionsav;
2797 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
2799 $text .=
'</select>';
2800 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2803 print
'<div id="credit_note_options" class="clearboth">';
2804 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' :
'').
' /> ';
2805 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
2806 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' :
'').
' /> ';
2807 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
2810 print
'</div></div>';
2813 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2815 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2817 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2"> ';
2819 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
2820 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
2821 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2823 print
'</div></div>'.
"\n";
2833 print
'<tr><td class="fieldrequired">';
2834 print $form->textwithpicto($langs->trans(
'RefSupplierBill'), $langs->trans(
"RefOfOnVendorSide", $langs->trans(
"SupplierBill"))).
'</td><td>';
2835 print
'<input name="ref_supplier" value="'.(GETPOSTISSET(
'ref_supplier') ?
GETPOST(
'ref_supplier') : (!empty($objectsrc->ref_supplier) ? $objectsrc->ref_supplier :
'')).
'" type="text" spellcheck="false"';
2836 if (!empty($societe->id) && $societe->id > 0) {
2845 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
2846 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
2850 if (!empty($societe->id) && $societe->id > 0) {
2852 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2854 $thirdparty = $societe;
2856 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2857 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2863 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth300" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
2867 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
2868 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2869 print $form->selectDate($dateinvoice ? (
int) $dateinvoice :
'',
'', 0, 0, 0,
"add", 1, 1);
2874 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td>';
2875 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2876 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
2881 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2882 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
2883 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth200 widthcentpercentminusx');
2887 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
2888 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2889 print $form->selectDate($datedue,
'ech', 0, 0, 0,
"add", 1, 1);
2893 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2894 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2895 $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'DBIT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
2900 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2902 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
2910 $langs->load(
'projects');
2911 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2912 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');
2913 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>';
2920 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
2921 print
'<td colspan="3" class="maxwidthonsmartphone">';
2922 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2923 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 :
''));
2929 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
2930 print
'<tr><td>' . $langs->trans(
'VATReverseCharge') .
'</td><td>';
2933 $vat_reverse_charge = (
GETPOST(
'vat_reverse_charge',
'alpha') ==
'on' ||
GETPOST(
'vat_reverse_charge',
'alpha') ==
'1') ? 1 : 0;
2934 } elseif ($vat_reverse_charge == 1 || $societe->vat_reverse_charge == 1 || ($societe->country_code !=
$mysoc->country_code &&
isInEEC(
$mysoc) &&
isInEEC($societe) && !empty($societe->tva_intra))) {
2935 $vat_reverse_charge = 1;
2937 $vat_reverse_charge = 0;
2940 print
'<input type="checkbox" name="vat_reverse_charge"'. (!empty($vat_reverse_charge) ?
' checked ' :
'') .
'>';
2947 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
2948 print
'<td class="maxwidthonsmartphone">';
2949 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
2950 $used_currency_code = $currency_code;
2951 if (!
GETPOST(
'changecompany')) {
2952 $used_currency_code =
GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code;
2954 print $form->selectMultiCurrency($used_currency_code,
'multicurrency_code');
2960 if ($fac_recid > 0) {
2961 $dateexample = $dateinvoice;
2962 if (empty($dateexample)) {
2965 $substitutionarray = array(
2966 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
2967 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
2968 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
2969 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
2970 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
2971 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
2972 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
2973 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
2974 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
2975 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
2976 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
2979 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
2980 foreach ($substitutionarray as $key => $val) {
2981 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
2983 $htmltext .=
'</i>';
2988 $langs->loadLangs(array(
"intracommreport"));
2989 print
'<!-- If module intracomm on -->'.
"\n";
2990 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
2991 $form->selectTransportMode(
GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
2995 if (empty($reshook)) {
2996 print
$object->showOptionals($extrafields,
'create');
3001 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
3002 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
3007 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
3009 $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%');
3010 print $doleditor->Create(1);
3016 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
3018 $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%');
3019 print $doleditor->Create(1);
3025 if (!empty($objectsrc) && $classname !==
null) {
3026 print
"\n<!-- ".$classname.
" info -->";
3028 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
3029 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
3030 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
3031 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
3032 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
3034 $txt = $langs->trans($classname);
3035 if ($classname ==
'CommandeFournisseur') {
3036 $langs->load(
'orders');
3037 $txt = $langs->trans(
"SupplierOrder");
3039 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
3041 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'invoice_supplier');
3043 if (isset($objectsrc->linkedObjects[
'invoice_supplier'])) {
3044 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
3046 $invoice_supplier = [];
3048 '@phan-var-force null|FactureFournisseur[] $invoice_supplier';
3051 if (is_array($invoice_supplier)) {
3052 $cntinvoice = count($invoice_supplier);
3054 if ($cntinvoice >= 1) {
3056 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
3061 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
3062 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
3063 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
3064 print
'<tr><td>'.$langs->transcountry(
"AmountLT1",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
3067 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
3068 print
'<tr><td>'.$langs->transcountry(
"AmountLT2",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
3070 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
3073 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
'</td></tr>';
3074 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
"</td></tr>";
3075 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
"</td></tr>";
3080 $parameters = array();
3081 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
3082 print $hookmanager->resPrint;
3090 print $form->buttonsSaveCancel(
"CreateDraft");
3093 if (!empty($objectsrc)) {
3096 $title = $langs->trans(
'ProductsAndServices');
3099 print
'<div class="div-table-responsive-no-min">';
3100 print
'<table class="noborder centpercent">';
3102 $objectsrc->printOriginLinesList(
'', $selectedLines);
3110 if ($id > 0 || !empty($ref)) {
3116 $result =
$object->fetch($id, $ref);
3121 $result =
$object->fetch_thirdparty();
3127 $societe =
$object->thirdparty;
3129 $totalpaid =
$object->getSommePaiement();
3130 $totalcreditnotes =
$object->getSumCreditNotesUsed();
3131 $totaldeposits =
$object->getSumDepositsUsed();
3139 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
3142 $multicurrency_resteapayer = 0;
3144 $multicurrency_totalpaid =
$object->getSommePaiement(1);
3145 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
3146 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
3147 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
3151 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
3152 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
3159 $resteapayeraffiche = $resteapayer;
3162 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
3163 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
3165 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
3166 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
3169 $absolute_discount = $societe->getAvailableDiscounts(
null, $filterabsolutediscount, 0, 1);
3170 $absolute_creditnote = $societe->getAvailableDiscounts(
null, $filtercreditnote, 0, 1);
3171 $absolute_discount =
price2num($absolute_discount,
'MT');
3172 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
3176 $objectidnext =
$object->getIdReplacingInvoice();
3179 $titre = $langs->trans(
'SupplierInvoice');
3181 print
dol_get_fiche_head($head,
'card', $titre, -1,
'supplier_invoice', 0,
'',
'', 0,
'', 1);
3186 if ($action ==
'converttoreduc') {
3189 $type_fac =
'ExcessPaid';
3191 $type_fac =
'CreditNote';
3193 $type_fac =
'Deposit';
3195 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
3196 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
3197 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
3201 if ($action ==
'clone') {
3203 $formquestion = array(
3204 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplierBill"),
'value' => $langs->trans(
"CopyOf").
' '.
$object->ref_supplier),
3205 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
3208 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 0);
3212 if ($action ==
'valid') {
3214 if (preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) {
3216 $numref =
$object->getNextNumRef($societe);
3225 $text = $langs->trans(
'ConfirmValidateBill', $numref);
3233 $formquestion = array();
3235 $qualified_for_stock_change = 0;
3237 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3239 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3243 $langs->load(
"stocks");
3244 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3247 $warehouse_array = $warehouse->list_array();
3248 if (count($warehouse_array) == 1) {
3250 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3253 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3255 $formquestion = array(
3256 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3260 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
3265 if ($action ==
'edit') {
3266 $formquestion = array();
3268 $qualified_for_stock_change = 0;
3270 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3272 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3275 $langs->load(
"stocks");
3276 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3279 $warehouse_array = $warehouse->list_array();
3280 if (count($warehouse_array) == 1) {
3282 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3285 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3287 $formquestion = array(
3288 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3291 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill',
$object->ref),
'confirm_edit', $formquestion, 1, 1);
3295 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
3296 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'', 0, 1);
3299 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
3303 $close[$i][
'code'] =
'discount_vat';
3305 $close[$i][
'code'] =
'badsupplier';
3307 $close[$i][
'code'] =
'other';
3311 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
3313 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3315 $close[$i][
'label'] = $langs->trans(
"Other");
3319 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3321 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3323 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
3326 $arrayreasons = array();
3327 foreach ($close as $key => $val) {
3328 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
3332 $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'));
3334 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
3338 if ($action ==
'canceled') {
3340 $close[1][
'code'] =
'badsupplier';
3341 $close[2][
'code'] =
'abandon';
3343 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3344 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
3346 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier",
$object->ref), $close[1][
'label'], 1);
3347 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
3349 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
3350 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
3353 $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'));
3355 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 280);
3359 if ($action ==
'delete') {
3360 $formquestion = array();
3362 $qualified_for_stock_change = 0;
3364 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3366 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3370 $langs->load(
"stocks");
3371 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3374 $warehouse_array = $warehouse->list_array();
3376 $selectwarehouse =
'<span class="questionrevertstock hidden">';
3377 if (count($warehouse_array) == 1) {
3379 $selectwarehouse .=
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3382 $selectwarehouse .= $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3384 $selectwarehouse .=
'</span>';
3386 $selectyesno = array(0 => $langs->trans(
'No'), 1 => $langs->trans(
'Yes'));
3388 print
'<script type="text/javascript">
3389 $(document).ready(function() {
3390 $("#revertstock").change(function() {
3391 if(this.value > 0) {
3392 $(".questionrevertstock").removeClass("hidden");
3394 $(".questionrevertstock").addClass("hidden");
3400 $formquestion = array(
3401 array(
'type' =>
'select',
'name' =>
'revertstock',
'label' => $langs->trans(
"RevertProductsToStock"),
'select_show_empty' => 0,
'values' => $selectyesno),
3402 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $selectwarehouse,
'tdclass' =>
'questionrevertstock hidden')
3406 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete', $formquestion, 1, 1);
3408 if ($action ==
'deletepayment') {
3409 $payment_id =
GETPOST(
'paiement_id');
3410 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
3414 if ($action ==
'ask_deleteline') {
3415 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
3419 if ($action ==
'add_title_line') {
3420 $langs->load(
'subtotals');
3422 $depth_array =
$object->getPossibleLevels($langs);
3423 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3424 } elseif ($action ==
'add_subtotal_line') {
3425 $langs->load(
'subtotals');
3427 $titles =
$object->getPossibleTitles();
3428 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3432 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
3433 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
3434 if (empty($reshook)) {
3435 $formconfirm .= $hookmanager->resPrint;
3436 } elseif ($reshook > 0) {
3437 $formconfirm = $hookmanager->resPrint;
3445 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
3447 $morehtmlref =
'<div class="refidno">';
3449 $morehtmlref .= $form->editfieldkey(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, (
int) $usercancreate,
'string',
'', 0, 1);
3450 $morehtmlref .= $form->editfieldval(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
3452 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'supplier');
3454 $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>';
3458 $langs->load(
"projects");
3459 $morehtmlref .=
'<br>';
3460 if ($permissiontoadd) {
3461 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
3462 if ($action !=
'classify') {
3463 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.((int)
$object->id).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
3465 $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');
3467 if (!empty(
$object->fk_project)) {
3469 $proj->fetch(
$object->fk_project);
3470 $morehtmlref .= $proj->getNomUrl(1);
3472 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
3477 $morehtmlref .=
'</div>';
3479 $object->totalpaid = $totalpaid;
3481 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
3484 $parameters = array();
3486 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierInvoice', $parameters, $object, $action);
3487 if (empty($reshook)) {
3488 print
'<div class="fichecenter">';
3489 print
'<div class="fichehalfleft">';
3490 print
'<div class="underbanner clearboth"></div>';
3492 print
'<table class="border tableforfield centpercent">';
3495 print
'<tr><td>'.$langs->trans(
'Type').
'</td><td>';
3496 print
'<span class="badgeneutral">';
3500 print
' '.$object->getSubtypeLabel(
'facture_fourn');
3504 $facreplaced->fetch(
$object->fk_facture_source);
3505 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
3508 if (
$object->fk_facture_source > 0) {
3510 $facusing->fetch(
$object->fk_facture_source);
3511 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
3513 $langs->load(
"errors");
3514 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"WarningCorrectedInvoiceNotFound").
'</span>';
3519 $object->getListIdAvoirFromInvoice();
3521 if (!empty(
$object->creditnote_ids)) {
3522 $invoicecredits = array();
3523 foreach (
$object->creditnote_ids as $invoiceid) {
3525 $creditnote->fetch($invoiceid);
3526 $invoicecredits[] = $creditnote->getNomUrl(1);
3528 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
3531 if (isset($objectidnext) && $objectidnext > 0) {
3534 $facthatreplace->fetch($objectidnext);
3535 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
3539 $result = $discount->fetch(0, 0,
$object->id);
3541 print
' <span class="opacitymediumbycolor paddingleft">';
3542 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
3543 $s = str_replace(
'{s1}',
$object->getLibType(1), $s);
3544 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
3546 print
'</span><br>';
3550 if (
$object->fk_fac_rec_source > 0) {
3552 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
3554 print
' <span class="opacitymediumbycolor paddingleft">';
3555 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->title).
'</a>';
3556 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
3566 print
'<!-- Discounts -->'.
"\n";
3567 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
3570 $thirdparty = $societe;
3572 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3578 print
'<td>'.$form->editfieldkey(
"Label",
'label',
$object->label, $object, (
int) $usercancreate).
'</td>';
3579 print
'<td>'.$form->editfieldval(
"Label",
'label',
$object->label, $object, $usercancreate).
'</td>';
3587 print $form->editfieldkey(
"DateInvoice",
'datef', (
string)
$object->date,
$object, (int) $form_permission,
'datepicker');
3588 print
'</td><td colspan="3">';
3589 print $form->editfieldval(
"Date",
'datef',
$object->date, $object, $form_permission,
'datepicker');
3595 print $form->editfieldkey(
"DatePointOfTax",
'date_pointoftax', (
string)
$object->date_pointoftax,
$object, (int) $pointoftax_form_permission,
'datepicker');
3596 print
'</td><td colspan="3">';
3597 print $form->editfieldval(
"DatePointOfTax",
'date_pointoftax',
$object->date_pointoftax, $object, $pointoftax_form_permission,
'datepicker');
3602 $langs->load(
'bills');
3603 print
'<tr><td class="nowrap">';
3604 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3605 print $langs->trans(
'PaymentConditions');
3607 if ($action !=
'editconditions' && $form_permission) {
3608 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>';
3610 print
'</tr></table>';
3612 if ($action ==
'editconditions') {
3613 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
3615 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
3622 print $form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', (
string)
$object->date_echeance, $object, (
int) $form_permission,
'datepicker');
3624 print $form->editfieldval(
"DateMaxPayment",
'date_lim_reglement',
$object->date_echeance, $object, $form_permission,
'datepicker');
3625 if ($action !=
'editdate_lim_reglement' &&
$object->hasDelay()) {
3631 $langs->load(
'bills');
3632 print
'<tr><td class="nowrap">';
3633 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3634 print $langs->trans(
'PaymentMode');
3636 if ($action !=
'editmode' && $form_permission) {
3637 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>';
3639 print
'</tr></table>';
3641 if ($action ==
'editmode') {
3642 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3644 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'none');
3650 print
'<tr><td class="nowrap">';
3651 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3652 print $langs->trans(
'BankAccount');
3654 if ($action !=
'editbankaccount' && $usercancreate) {
3655 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>';
3657 print
'</tr></table>';
3659 if ($action ==
'editbankaccount') {
3660 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
3662 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
3670 print
'<tr><td class="nowrap">';
3671 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3672 print $langs->trans(
'VATReverseCharge');
3674 if ($action !=
'editvatreversecharge' && $usercancreate) {
3675 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editvatreversecharge&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->trans(
'SetVATReverseCharge'), 1).
'</a></td>';
3677 print
'</tr></table>';
3679 if ($action ==
'editvatreversecharge') {
3680 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
3681 print
'<input type="hidden" name="action" value="setvatreversecharge">';
3682 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3684 print
'<input type="checkbox" name="vat_reverse_charge"' . (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
'>';
3686 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
3689 print
'<input type="checkbox" name="vat_reverse_charge"'. (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
' disabled>';
3697 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3698 print $langs->trans(
'IncotermLabel');
3699 print
'<td><td class="right">';
3700 if ($usercancreate) {
3701 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
3705 print
'</td></tr></table>';
3708 if ($action !=
'editincoterm') {
3709 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
3711 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
3718 $langs->loadLangs(array(
"intracommreport"));
3719 print
'<!-- If module intracomm on -->'.
"\n";
3721 print
'<table class="nobordernopadding centpercent"><tr><td>';
3722 print $langs->trans(
'IntracommReportTransportMode');
3724 if ($action !=
'edittransportmode' && ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"))) {
3725 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edittransportmode&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit().
'</a></td>';
3727 print
'</tr></table>';
3730 if ($action ==
'edittransportmode') {
3731 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'transport_mode_id', 1, 1);
3733 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'none');
3741 print
'<table class="nobordernopadding centpercent"><tr><td>';
3742 print $langs->trans(
"Categories");
3743 print
'<td><td class="right">';
3744 if ($usercancreate) {
3745 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
3749 print
'</td></tr></table>';
3752 if ($action ==
'edittags') {
3753 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
3754 print
'<input type="hidden" name="action" value="settags">';
3755 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3756 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
3757 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
3760 print $form->showCategories(
$object->id, Categorie::TYPE_SUPPLIER_INVOICE, 1);
3768 if (
$object->status != $object::STATUS_DRAFT) {
3772 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
3777 print
'<div class="fichehalfright">';
3778 print
'<div class="underbanner clearboth"></div>';
3780 print
'<table class="border tableforfield centpercent">';
3782 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
3785 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
3786 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3788 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3793 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
3794 print
'<td class="nowrap amountcard right">';
3795 if (
GETPOST(
'calculationrule')) {
3796 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
3798 $calculationrule = (!
getDolGlobalString(
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND_SUPPLIER') ?
'totalofround' :
'roundoftotal');
3800 if ($calculationrule ==
'totalofround') {
3801 $calculationrulenum = 1;
3803 $calculationrulenum = 2;
3806 if (
$object->getVentilExportCompta() == 0) {
3807 $s =
'<span class="hideonsmartphone opacitymedium">' . $langs->trans(
"ReCalculate") .
' </span>';
3808 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=totalofround">' . $langs->trans(
"Mode1") .
'</a>';
3810 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=roundoftotal">' . (
$conf->dol_optimize_smallscreen ?
"2" : $langs->trans(
"Mode2")) .
'</a>';
3811 print
'<div class="inline-block">';
3812 print $form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum) .
'<br>' . $langs->trans(
"CalculationRuleDescSupplier"), 2, 1,
img_picto(
'',
'help',
'class="paddingleft paddingright"'),
'', 3,
'', 0,
'recalculate');
3813 print
' ';
3816 print
'<span class="nowraponall">'.price(
$object->total_tva, 1, $langs, 0, -1, -1,
$conf->currency).
'</span>';
3819 print
'<td class="nowraponall amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3823 if ($societe->localtax1_assuj ==
"1") {
3825 print
'<td>' . $langs->transcountry(
"AmountLT1", $societe->country_code) .
'</td>';
3826 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3829 if ($societe->localtax2_assuj ==
"1") {
3831 print
'<td>' . $langs->transcountry(
"AmountLT2", $societe->country_code) .
'</td>';
3832 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3837 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
3838 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3840 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3873 if ($societe->localtax1_assuj ==
"1") {
3876 if ($societe->localtax2_assuj ==
"1") {
3880 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
3881 $sql .=
' c.id as payment_type, c.code as payment_code,';
3882 $sql .=
' pf.amount,';
3883 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
3884 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
3885 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
3886 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
3887 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
3888 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
3889 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
3890 $sql .=
' ORDER BY p.datep, p.tms';
3892 $result =
$db->query($sql);
3894 $num =
$db->num_rows($result);
3897 print
'<div class="div-table-responsive-no-min">';
3898 print
'<table class="noborder paymenttable centpercent">';
3899 print
'<tr class="liste_titre">';
3901 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
3902 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
3904 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
3909 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
3914 $objp =
$db->fetch_object($result);
3916 $paymentstatic->id = $objp->rowid;
3917 $paymentstatic->datepaye =
$db->jdate($objp->dp);
3918 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
3919 $paymentstatic->num_payment = $objp->num_payment;
3921 $paymentstatic->paiementcode = $objp->payment_code;
3922 $paymentstatic->type_code = $objp->payment_code;
3923 $paymentstatic->type_label = $objp->payment_type;
3925 print
'<tr class="oddeven">';
3926 print
'<td class="nowraponall">';
3927 print $paymentstatic->getNomUrl(1);
3929 print
'<td>'.dol_print_date(
$db->jdate($objp->dp),
'day').
'</td>';
3930 $s = $form->form_modes_reglement(
'', $objp->payment_type,
'none',
'', 1, 0,
'', 1).
' '.$objp->num_payment;
3931 print
'<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).
'">';
3935 $bankaccountstatic->id = $objp->baid;
3936 $bankaccountstatic->ref = $objp->baref;
3937 $bankaccountstatic->label = $objp->baref;
3938 $bankaccountstatic->number = $objp->banumber;
3941 $bankaccountstatic->account_number = $objp->account_number;
3944 $accountingjournal->fetch($objp->fk_accountancy_journal);
3945 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
3948 print
'<td class="right nowraponall">';
3949 if ($objp->baid > 0) {
3950 print $bankaccountstatic->getNomUrl(1,
'transactions');
3955 print
'<td class="center">';
3957 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
3963 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
3965 $totalpaid += $objp->amount;
3969 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
3995 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
3996 print
'<span class="opacitymedium">';
3998 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
4000 print $langs->trans(
'AlreadyPaid');
4005 print
'<td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td>';
4009 $resteapayeraffiche = $resteapayer;
4011 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
4014 $creditnoteamount = 0;
4017 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
4018 $sql .=
" re.description, re.fk_invoice_supplier_source";
4019 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
4020 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
4021 $resql =
$db->query($sql);
4023 $num =
$db->num_rows($resql);
4027 $obj =
$db->fetch_object($resql);
4028 $invoice->fetch($obj->fk_invoice_supplier_source);
4029 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4031 print $langs->trans(
"CreditNote").
' ';
4034 print $langs->trans(
"Deposit").
' ';
4036 print $invoice->getNomUrl(0);
4039 print
'<td class="right">';
4040 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
4041 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
4045 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
4049 $creditnoteamount += $obj->amount_ttc;
4052 $depositamount += $obj->amount_ttc;
4061 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4062 print
'<span class="opacitymedium">';
4063 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
4067 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4069 $resteapayeraffiche = 0;
4070 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4074 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4075 print
'<span class="opacitymedium">';
4076 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
4080 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4083 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4087 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4088 print
'<span class="opacitymedium">';
4089 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
4093 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4095 $resteapayeraffiche = 0;
4096 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4100 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4101 $text = $langs->trans(
"HelpAbandonOther");
4103 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
4105 print
'<span class="opacitymedium">';
4107 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
4111 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4113 $resteapayeraffiche = 0;
4114 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4118 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4119 print
'<span class="opacitymedium">';
4120 print $langs->trans(
"Billed");
4124 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
4128 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4129 print
'<span class="opacitymedium">';
4130 print $langs->trans(
'RemainderToPay');
4131 if ($resteapayeraffiche < 0) {
4132 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4137 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
4142 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4143 print
'<span class="opacitymedium">';
4144 print $langs->trans(
'RemainderToPayMulticurrency');
4145 if ($resteapayeraffiche < 0) {
4146 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4151 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price(
price2num($multicurrency_resteapayer,
'MT'), 0, $langs, 1, -1, -1,
$object->multicurrency_code).
'</td>';
4155 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4158 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4159 print $langs->trans(
'AlreadyPaidBack');
4162 print
'<td class="right">'.price($sign * $totalpaid).
'</td>';
4166 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">'.$langs->trans(
"Billed").
'</td>';
4168 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
4172 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4173 print
'<span class="opacitymedium">';
4174 print $langs->trans(
'RemainderToPayBack');
4175 if ($resteapayeraffiche > 0) {
4176 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4181 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
4186 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4187 print
'<span class="opacitymedium">';
4188 print $langs->trans(
'RemainderToPayBackMulticurrency');
4189 if ($resteapayeraffiche > 0) {
4190 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4195 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>';
4211 print
'<div class="clearboth"></div><br>';
4214 $blocname =
'contacts';
4215 $title = $langs->trans(
'ContactsAddresses');
4216 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4221 $blocname =
'notes';
4222 $title = $langs->trans(
'Notes');
4223 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4230 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
4231 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4232 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
4233 print
'<input type="hidden" name="mode" value="">';
4234 print
'<input type="hidden" name="page_y" value="">';
4235 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
4236 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
4237 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4241 include DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_ajaxrow.tpl.php';
4243 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
4247 print
'<div class="div-table-responsive-no-min">';
4248 print
'<table id="tablelines" class="noborder noshadow centpercent">';
4250 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
4253 $inputalsopricewithtax = 1;
4254 $senderissupplier = 2;
4255 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY')) {
4256 $senderissupplier =
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY');
4261 $object->printObjectLines($action, $societe,
$mysoc, $lineid, 1);
4268 if ($action !=
'editline') {
4271 $parameters = array();
4272 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
4276 if (empty($reshook)) {
4290 if ($action !=
'presend') {
4293 print
'<div class="tabsAction">';
4295 $parameters = array();
4296 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
4298 if (empty($reshook)) {
4301 $langs->load(
'subtotals');
4303 $url_button = array();
4305 $url_button[] = array(
4306 'lang' =>
'subtotals',
4308 'perm' => (
bool) $usercancreate,
4309 'label' => $langs->trans(
'AddTitleLine'),
4310 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_title_line'],
true)
4313 $url_button[] = array(
4314 'lang' =>
'subtotals',
4316 'perm' => (
bool) $usercancreate,
4317 'label' => $langs->trans(
'AddSubtotalLine'),
4318 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_subtotal_line'],
true)
4321 print
dolGetButtonAction(
'', $langs->trans(
'SubTotal'),
'default', $url_button,
'',
true);
4326 $ventilExportCompta =
$object->getVentilExportCompta();
4328 if ($ventilExportCompta == 0) {
4329 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=edit&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
4331 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
4336 $result = $discount->fetch(0, 0,
$object->id);
4343 if (!$objectidnext &&
$object->close_code !=
'replaced' && $usercancreate) {
4344 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
4346 if ($usercancreate) {
4347 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
4349 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
4359 if ($usercanvalidate) {
4360 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken().
'"';
4361 print
'>'.$langs->trans(
'Validate').
'</a>';
4363 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
4364 print
'>'.$langs->trans(
'Validate').
'</a>';
4370 if (empty($user->socid)) {
4373 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' =>
$object->id,
'action' =>
'presend',
'mode' =>
'init'],
true).
'#formmailbeforetitle',
'');
4382 $langs->load(
"withdrawals");
4383 if ($resteapayer > 0) {
4384 if ($usercancreatecreditransfer) {
4385 if (!$objectidnext &&
$object->close_code !=
'replaced') {
4386 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>';
4388 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeBankTransferOrder').
'</span>';
4400 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>';
4407 if ($resteapayer == 0) {
4408 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
4409 } elseif ($usercancreate) {
4410 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>';
4416 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
4420 && (
getDolGlobalString(
'SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') ||
$object->getSommePaiement() == 0)
4422 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>';
4426 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
4437 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaid').
'</a>';
4442 if ($totalpaid > 0 || $totalcreditnotes > 0) {
4444 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
4447 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=canceled&token='.
newToken().
'">'.$langs->trans(
'ClassifyCanceled').
'</a>';
4459 if (!$objectidnext) {
4460 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>';
4465 if ($action !=
'edit' && $usercancreate) {
4466 print
'<a class="butAction butActionClone" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=clone&socid='.
$object->socid.
'&token='.
newToken().
'">'.$langs->trans(
'ToClone').
'</a>';
4471 if (!$objectidnext && count(
$object->lines) > 0) {
4472 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.
$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
4477 if ($action !=
'confirm_edit' && $usercandelete) {
4478 $isErasable =
$object->is_erasable();
4480 $enableDelete =
false;
4482 $params = (empty(
$conf->use_javascript_ajax) ? array() : array(
'attr' => array(
'class' =>
'reposition')));
4484 if ($isErasable == -4) {
4485 $htmltooltip = $langs->trans(
"DisabledBecausePayments");
4486 } elseif ($isErasable == -3) {
4487 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastSituationInvoice");
4488 } elseif ($isErasable == -2) {
4489 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastInvoice");
4490 } elseif ($isErasable == -1) {
4491 $htmltooltip = $langs->trans(
"DisabledBecauseDispatchedInBookkeeping");
4492 } elseif ($isErasable <= 0) {
4493 $htmltooltip = $langs->trans(
"DisabledBecauseNotErasable");
4495 $enableDelete =
true;
4498 print
dolGetButtonAction($htmltooltip, $langs->trans(
"Delete"),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken(), (
string)
$object->id, $enableDelete, $params);
4502 if ($action !=
'confirm_edit') {
4503 print
'<div class="fichecenter"><div class="fichehalfleft">';
4509 $subdir =
get_exdir(
$object->id, 2, 0, 0, $object,
'invoice_supplier').$ref;
4511 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.
$object->id;
4512 $genallowed = $usercanread;
4513 $delallowed = $usercancreate;
4517 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, (
int) $genallowed, (
int) $delallowed, $modelpdf, $genifempty, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
4518 $somethingshown = $formfile->numoffiles;
4521 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice_supplier'), 1);
4522 $linktoelem = $tmparray[
'linktoelem'];
4523 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
4524 print $htmltoenteralink;
4526 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
4528 print
'</div><div class="fichehalfright">';
4531 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
4533 $somethingshown = $formactions->showactions($object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
4535 print
'</div></div>';
4541 if (
GETPOST(
'modelselected')) {
4542 $action =
'presend';
4546 $modelmail =
'invoice_supplier_send';
4547 $defaulttopic =
'SendBillRef';
4549 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
4550 $trackid =
'sinv'.$object->id;
4552 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage bank accounts.
Class to manage accounting journals.
const TYPE_PROFORMA
Proforma invoice.
const TYPE_SITUATION
Situation invoice.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_STANDARD
Standard invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const STATUS_CLOSED
Classified paid.
Class to manage invoice templates.
Class to manage payments for supplier invoices.
Class ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage line invoices.
Class to manage translations.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
$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, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.