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);
265 $categories =
GETPOST(
'categories',
'array:int');
266 if (method_exists($object,
'setCategories')) {
267 $object->setCategories($categories);
275 $outputlangs = $langs;
278 $newlang =
GETPOST(
'lang_id',
'aZ09');
281 $newlang =
$object->thirdparty->default_lang;
283 if (!empty($newlang)) {
285 $outputlangs->setDefaultLang($newlang);
290 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
297 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $permissiontodelete) {
301 $isErasable =
$object->is_erasable();
303 if ($usercandelete && $isErasable > 0) {
304 $revertstock =
GETPOST(
'revertstock');
309 $qualified_for_stock_change = 0;
311 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
313 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
318 $langs->load(
"stocks");
319 if (!$idwarehouse || $idwarehouse == -1) {
321 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
324 $result =
$object->setDraft($user, $idwarehouse);
333 $result =
$object->delete($user);
335 header(
'Location: list.php?restore_lastsearch_values=1');
342 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
344 $result =
$object->deleteLine($lineid);
364 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
371 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
374 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
375 $discount->unlink_invoice();
376 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercancreate) {
378 $result =
$object->setPaid($user);
382 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercancreate) {
385 $close_code =
GETPOST(
"close_code",
'restricthtml');
386 $close_note =
GETPOST(
"close_note",
'restricthtml');
388 $result =
$object->setPaid($user, $close_code, $close_note);
393 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
395 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
398 $close_code =
GETPOST(
"close_code",
'restricthtml');
399 $close_note =
GETPOST(
"close_note",
'restricthtml');
401 $result =
$object->setCanceled($user, $close_code, $close_note);
406 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
411 if ($action ==
'setref_supplier' && $usercancreate) {
414 if (
$object->update($user) < 0) {
418 $outputlangs = $langs;
421 $newlang =
GETPOST(
'lang_id',
'aZ09');
424 $newlang =
$object->thirdparty->default_lang;
426 if (!empty($newlang)) {
428 $outputlangs->setDefaultLang($newlang);
432 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
438 if ($action ==
'setconditions' && $usercancreate) {
440 $object->cond_reglement_code = 0;
441 $object->cond_reglement_id = 0;
456 $new_date_echeance =
$object->calculate_date_lim_reglement();
457 if ($new_date_echeance) {
458 $object->date_echeance = $new_date_echeance;
463 $result =
$object->update($user);
475 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
478 } elseif ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
481 } elseif ($action ==
'setmode' && $usercancreate) {
484 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
486 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
487 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
490 } elseif ($action ==
'setbankaccount' && $usercancreate) {
493 } elseif ($action ==
'setvatreversecharge' && $usercancreate) {
495 $vatreversecharge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
496 $result =
$object->setVATReverseCharge($vatreversecharge);
499 if ($action ==
'settransportmode' && $usercancreate) {
502 } elseif ($action ==
'setlabel' && $usercancreate) {
506 $result =
$object->update($user);
510 } elseif ($action ==
'setdatef' && $usercancreate) {
514 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
516 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
523 $date_echence_calc =
$object->calculate_date_lim_reglement();
524 if (!empty(
$object->date_echeance)) {
525 $object->date_echeance = $date_echence_calc;
531 $result =
$object->update($user);
535 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
539 $object->date_pointoftax = $date_pointoftax;
541 $result =
$object->update($user);
544 $action =
'editdate_pointoftax';
546 } elseif ($action ==
'setdate_lim_reglement' && $usercancreate) {
551 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
553 $result =
$object->update($user);
557 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
573 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
575 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
579 $remaintopay =
$object->getRemainToPay(0);
583 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
587 $result = $discount->link_to_invoice(0, $id);
594 $newremaintopay =
$object->getRemainToPay(0);
595 if ($newremaintopay == 0) {
606 $outputlangs = $langs;
609 $newlang =
GETPOST(
'lang_id',
'aZ09');
612 $newlang =
$object->thirdparty->default_lang;
614 if (!empty($newlang)) {
616 $outputlangs->setDefaultLang($newlang);
620 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
625 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
633 $result = $discountcheck->fetch(0, 0,
$object->id);
645 $amount_ht = $amount_tva = $amount_ttc = array();
646 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
650 foreach (
$object->lines as $line) {
651 if ($line->product_type < 9 && $line->total_ht != 0) {
652 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
654 $amount_ht[$keyforvatrate] += $line->total_ht;
655 $amount_tva[$keyforvatrate] += $line->total_tva;
656 $amount_ttc[$keyforvatrate] += $line->total_ttc;
657 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
658 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
659 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
663 '@phan-var-force array<string,float> $amount_ht
664 @phan-var-force array<string,float> $amount_tva
665 @phan-var-force array<string,float> $amount_ttc
666 @phan-var-force array<string,float> $multicurrency_amount_ht
667 @phan-var-force array<string,float> $multicurrency_amount_tva
668 @phan-var-force array<string,float> $multicurrency_amount_ttc';
672 $alreadypaid =
$object->getSommePaiement();
673 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
674 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
675 foreach ($amount_ht as $vatrate => $val) {
676 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
677 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
678 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
679 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
680 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
681 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
690 $discount->description =
'(CREDIT_NOTE)';
692 $discount->description =
'(DEPOSIT)';
694 $discount->description =
'(EXCESS PAID)';
696 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
698 $discount->discount_type = 1;
699 $discount->fk_soc =
$object->socid;
700 $discount->socid =
$object->socid;
701 $discount->fk_invoice_supplier_source =
$object->id;
709 $sql =
'SELECT SUM(pf.amount) as total_paiements';
710 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'paiementfourn as p';
711 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN ('.
getEntity(
'c_paiement').
')';
712 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
713 $sql .=
' AND pf.fk_paiementfourn = p.rowid';
714 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
716 $resql =
$db->query($sql);
721 $res =
$db->fetch_object($resql);
722 $total_paiements = $res->total_paiements;
725 $total_creditnote_and_deposit = 0;
726 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
727 $sql .=
" re.description, re.fk_invoice_supplier_source";
728 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
729 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
730 $resql =
$db->query($sql);
731 if (!empty($resql)) {
732 while ($obj =
$db->fetch_object($resql)) {
733 $total_creditnote_and_deposit += $obj->amount_ttc;
739 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
740 $discount->amount_tva = 0;
741 $discount->tva_tx = 0;
742 $discount->vat_src_code =
'';
745 $discount->multicurrency_code =
$object->multicurrency_code;
746 $discount->multicurrency_tx =
$object->multicurrency_tx;
747 $discount->multicurrency_total_ht = $discount->multicurrency_total_ttc = (float)
price2num((
float) $discount->amount_ttc * (float)
$object->multicurrency_tx,
'MT');
748 $discount->multicurrency_total_tva = 0;
750 $discount->multicurrency_amount_ht = $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
751 $discount->multicurrency_amount_tva = 0;
753 $result = $discount->create($user);
759 foreach ($amount_ht as $tva_tx => $xxx) {
760 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
761 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
762 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
764 $discount->multicurrency_code =
$object->multicurrency_code;
765 $discount->multicurrency_tx =
$object->multicurrency_tx;
766 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
767 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
768 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
770 $discount->multicurrency_amount_ht = abs((
float) $discount->multicurrency_total_ht);
771 $discount->multicurrency_amount_tva = abs((
float) $discount->multicurrency_total_tva);
772 $discount->multicurrency_amount_ttc = abs((
float) $discount->multicurrency_total_ttc);
777 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
778 $vat_src_code = $reg[1];
779 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
782 $discount->tva_tx = abs((
float) $tva_tx);
783 $discount->vat_src_code = $vat_src_code;
785 $result = $discount->create($user);
796 $result =
$object->setPaid($user);
811 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate) {
816 $result = $paiementfourn->fetch(
GETPOSTINT(
'paiement_id'));
818 $result = $paiementfourn->delete($user);
820 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
828 } elseif ($action ==
'add' && $usercancreate) {
833 $selectedLines =
GETPOST(
'toselect',
'array:int');
841 $ret = $extrafields->setOptionalsFromPost(
null, $object);
855 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
860 if (empty($dateinvoice)) {
861 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
873 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
889 $object->date_pointoftax = $date_pointoftax;
890 $object->date_echeance = $datedue;
896 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
897 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
899 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
900 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
921 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
924 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
929 if (empty($dateinvoice)) {
930 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
940 if (!
GETPOST(
'ref_supplier')) {
941 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
949 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
964 $object->date_pointoftax = $date_pointoftax;
965 $object->date_echeance = $datedue;
971 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
972 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
974 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
975 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
980 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
989 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
991 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
994 foreach ($facture_source->lines as $line) {
996 if (method_exists($line,
'fetch_optionals')) {
997 $line->fetch_optionals();
1001 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1002 $fk_parent_line = 0;
1005 $line->fk_facture_fourn =
$object->id;
1006 $line->fk_parent_line = $fk_parent_line;
1008 $line->subprice = -$line->subprice;
1009 $line->pa_ht = -((float) $line->pa_ht);
1010 $line->total_ht = -$line->total_ht;
1011 $line->total_tva = -$line->total_tva;
1012 $line->total_ttc = -$line->total_ttc;
1013 $line->total_localtax1 = -$line->total_localtax1;
1014 $line->total_localtax2 = -$line->total_localtax2;
1015 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1016 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1017 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1019 $result = $line->insert();
1024 if ($result > 0 && $line->product_type == 9) {
1025 $fk_parent_line = $result;
1033 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 &&
$id > 0) {
1035 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1036 $totalpaid = $facture_source->getSommePaiement();
1037 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1038 $totaldeposits = $facture_source->getSumDepositsUsed();
1039 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1040 $desc = $langs->trans(
'invoiceAvoirLineWithPaymentRestAmount');
1044 $retAddLine =
$object->addline($desc, -$remain_to_pay, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
'TTC');
1046 if ($retAddLine < 0) {
1053 if (!empty(
$object->fk_facture_source) && $id > 0) {
1055 if ($facture_source_link->fetch(
$object->fk_facture_source) > 0) {
1056 $facture_source_link->fetchObjectLinked();
1057 if (!empty($facture_source_link->linkedObjectsIds)) {
1058 foreach ($facture_source_link->linkedObjectsIds as $sourcetype => $TIds) {
1059 $object->add_object_linked($sourcetype, current($TIds));
1067 if (empty($dateinvoice)) {
1069 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1079 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1089 $object->date_pointoftax = $date_pointoftax;
1090 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1091 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1100 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1101 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1105 $object->fac_rec = $fac_recid;
1107 $fac_rec->fetch(
$object->fac_rec);
1108 $fac_rec->fetch_lines();
1109 $object->lines = $fac_rec->lines;
1116 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1121 if (empty($dateinvoice)) {
1122 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1132 if (!
GETPOST(
'ref_supplier')) {
1133 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
1141 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1158 $object->date_pointoftax = $date_pointoftax;
1159 $object->date_echeance = $datedue;
1165 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1166 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1168 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1169 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1174 if (empty(
$object->date_echeance)) {
1175 $object->date_echeance =
$object->calculate_date_lim_reglement();
1181 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
1183 $element = $subelement =
GETPOST(
'origin',
'alpha');
1191 if ($element ==
'order') {
1192 $element = $subelement =
'commande';
1194 if ($element ==
'propal') {
1195 $element =
'comm/propal';
1196 $subelement =
'propal';
1198 if ($element ==
'contract') {
1199 $element = $subelement =
'contrat';
1201 if ($element ==
'order_supplier') {
1203 $subelement =
'fournisseur.commande';
1205 if ($element ==
'project') {
1206 $element =
'projet';
1214 $classname = ucfirst($subelement);
1215 if ($classname ==
'Fournisseur.commande') {
1216 $classname =
'CommandeFournisseur';
1218 $objectsrc =
new $classname(
$db);
1219 $objectsrc->fetch($originid);
1220 $objectsrc->fetch_thirdparty();
1222 if (!empty(
$object->origin_type) && !empty(
$object->origin_id)) {
1227 if (
$object->origin_type ==
'reception') {
1228 $objectsrc->fetchObjectLinked();
1230 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1231 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1232 $object->linkedObjectsIds[
'order_supplier'][-1] = $value;
1242 $classname = ucfirst($subelement);
1243 if ($classname ==
'Fournisseur.commande') {
1244 $classname =
'CommandeFournisseur';
1246 $srcobject =
new $classname(
$db);
1248 $result = $srcobject->fetch(
GETPOSTINT(
'originid'));
1251 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1256 $amountdeposit = array();
1258 if ($typeamount ==
'amount') {
1259 $amount = $valuedeposit;
1261 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1264 $TTotalByTva = array();
1265 foreach ($srcobject->lines as &$line) {
1266 if (!empty($line->special_code)) {
1269 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1271 '@phan-var-force array<string,float> $TTotalByTva';
1273 $amount_ttc_diff = 0.;
1274 foreach ($TTotalByTva as $tva => &$total) {
1275 $coef = $total / $srcobject->total_ttc;
1276 $am = $amount * $coef;
1277 $amount_ttc_diff += $am;
1278 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1281 if ($typeamount ==
'amount') {
1282 $amountdeposit[0] = $valuedeposit;
1283 } elseif ($typeamount ==
'variable') {
1286 $lines = $srcobject->lines;
1287 $numlines = count($lines);
1288 for ($i = 0; $i < $numlines; $i++) {
1290 if (empty($lines[$i]->qty)) {
1293 if (!empty($lines[$i]->special_code)) {
1297 $totalamount += $lines[$i]->total_ht;
1298 $tva_tx = $lines[$i]->tva_tx;
1299 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1303 if ($totalamount == 0) {
1304 $amountdeposit[0] = 0;
1309 $amountdeposit[0] = 0;
1313 $amount_ttc_diff = array_key_exists(0, $amountdeposit) ? $amountdeposit[0] : 0;
1316 foreach ($amountdeposit as $tva => $amount) {
1317 if (empty($amount)) {
1322 'amount' =>
'FixAmount',
1323 'variable' =>
'VarAmount'
1325 $descline =
'(DEPOSIT)';
1327 if ($typeamount ==
'amount') {
1328 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1329 } elseif ($typeamount ==
'variable') {
1330 $descline .=
' ('.$valuedeposit.
'%)';
1333 $descline .=
' - '.$srcobject->ref;
1363 $diff =
$object->total_ttc - $amount_ttc_diff;
1367 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1373 $object->lines[0]->localtax1_tx,
1374 $object->lines[0]->localtax2_tx,
1376 $object->lines[0]->fk_product,
1379 $object->lines[0]->product_type,
1380 $object->lines[0]->remise_percent,
1382 $object->lines[0]->date_start,
1391 } elseif ($result > 0) {
1392 $lines = $srcobject->lines;
1393 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1394 $srcobject->fetch_lines();
1395 $lines = $srcobject->lines;
1398 $num = count($lines);
1399 for ($i = 0; $i < $num; $i++) {
1400 if (!in_array($lines[$i]->
id, $selectedLines)) {
1404 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->product_label);
1405 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1408 if (method_exists($lines[$i],
'fetch_optionals')) {
1409 $lines[$i]->fetch_optionals();
1415 if ($lines[$i]->date_debut_reel) {
1418 if ($lines[$i]->date_start) {
1421 $date_end = $lines[$i]->date_fin_prevue;
1422 if ($lines[$i]->date_fin_reel) {
1423 $date_end = $lines[$i]->date_fin_reel;
1425 if ($lines[$i]->date_end) {
1426 $date_end = $lines[$i]->date_end;
1429 $tva_tx = $lines[$i]->tva_tx;
1431 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
1432 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1436 $object->special_code = $lines[$i]->special_code;
1441 $pu_currency = $lines[$i]->multicurrency_subprice;
1443 $pu = $lines[$i]->subprice;
1452 $lines[$i]->localtax1_tx,
1453 $lines[$i]->localtax2_tx,
1455 $lines[$i]->fk_product,
1456 $lines[$i]->remise_percent,
1460 $lines[$i]->info_bits,
1465 $lines[$i]->array_options,
1466 $lines[$i]->fk_unit,
1469 $lines[$i]->ref_supplier,
1470 $lines[$i]->special_code
1479 if ($result > 0 && !empty($lines[$i]->extraparams)) {
1481 $newline->id = $result;
1482 $newline->extraparams = $lines[$i]->extraparams;
1483 $newline->setExtraParameters();
1495 $parameters = array(
'objFrom' => $srcobject);
1496 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1506 } elseif (!$error) {
1516 $langs->load(
"errors");
1526 $outputlangs = $langs;
1527 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1534 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1537 } elseif ($action ==
'updateline' && $usercancreate) {
1541 if (!
$object->fetch($id) > 0) {
1547 $tva_tx = str_replace(
'*',
'', $tva_tx);
1549 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_subprice') !=
'') {
1551 $price_base_type =
'HT';
1554 $price_base_type =
'TTC';
1557 if (
GETPOST(
'productid') > 0) {
1559 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY') == 1) {
1561 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1567 $label =
$prod->description;
1568 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1569 $label =
GETPOST(
'product_desc',
'restricthtml');
1572 $type =
$prod->type;
1574 $label =
GETPOST(
'product_desc',
'restricthtml');
1583 if (preg_match(
'/\*/', $tva_tx)) {
1588 $tva_tx = str_replace(
'*',
'', $tva_tx);
1596 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1597 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1599 if (is_array($extralabelsline)) {
1600 foreach ($extralabelsline as $key => $value) {
1601 unset($_POST[
"options_".$key]);
1605 $result =
$object->updateline(
1617 (
float) $remise_percent,
1627 unset($_POST[
'label']);
1628 unset($_POST[
'fourn_ref']);
1629 unset($_POST[
'date_starthour']);
1630 unset($_POST[
'date_startmin']);
1631 unset($_POST[
'date_startsec']);
1632 unset($_POST[
'date_startday']);
1633 unset($_POST[
'date_startmonth']);
1634 unset($_POST[
'date_startyear']);
1635 unset($_POST[
'date_endhour']);
1636 unset($_POST[
'date_endmin']);
1637 unset($_POST[
'date_endsec']);
1638 unset($_POST[
'date_endday']);
1639 unset($_POST[
'date_endmonth']);
1640 unset($_POST[
'date_endyear']);
1641 unset($_POST[
'price_ttc']);
1642 unset($_POST[
'price_ht']);
1649 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
1653 foreach (
$object->lines as $line) {
1654 if ($line->product_type == 1) {
1655 $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);
1658 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
1660 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
1661 $remise_percent = (float) str_replace(
'*',
'', $remise_percent);
1662 foreach (
$object->lines as $line) {
1663 $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);
1665 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !=
'' && $usercancreate) {
1667 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1668 $vat_rate = str_replace(
'*',
'', $vat_rate);
1671 foreach (
$object->lines as $line) {
1672 $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);
1674 } elseif ($action ==
'addline' && $usercancreate) {
1683 $ret =
$object->fetch_thirdparty();
1685 $langs->load(
'errors');
1694 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1695 if ($prod_entry_mode ==
'free') {
1702 $price_ht_devise =
'';
1704 $price_ttc_devise =
'';
1706 if (
GETPOST(
'price_ht') !==
'') {
1709 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
1712 if (
GETPOST(
'price_ttc') !==
'') {
1715 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
1716 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
1724 if (empty($remise_percent)) {
1725 $remise_percent = 0;
1729 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1730 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
1732 if (is_array($extralabelsline)) {
1734 foreach ($extralabelsline as $key => $value) {
1735 unset($_POST[
"options_".$key]);
1739 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
1740 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1743 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOSTINT(
'type') < 0) {
1744 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
1749 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1')
1750 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
1751 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
1752 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
1753 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
1754 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
1755 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) {
1756 $langs->load(
"errors");
1757 if (
$object->type == $object::TYPE_DEPOSIT) {
1759 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
1761 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPrice"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
1766 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
1767 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
1771 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') && !
GETPOST(
'dp_desc')) {
1772 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
1775 if (!
GETPOST(
'qty',
'alpha')) {
1776 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1780 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
1781 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
1785 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1786 $idprod = $res->fk_product_child;
1788 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
1794 if ($prod_entry_mode !=
'free' && empty($error)) {
1798 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
1803 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
1804 $idprod = (int) $reg[1];
1805 $res = $productsupplier->fetch($idprod);
1808 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
1810 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1811 if ($productsupplier->fourn_socid != $socid) {
1812 $productsupplier->ref_supplier =
'';
1815 $fksoctosearch =
$object->thirdparty->id;
1816 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1818 } elseif (
GETPOSTINT(
'idprodfournprice') > 0) {
1819 $qtytosearch = (float) $qty;
1821 $idprod = $productsupplier->get_buyprice(
GETPOSTINT(
'idprodfournprice'), $qtytosearch);
1822 $res = $productsupplier->fetch($idprod);
1826 $label = $productsupplier->label;
1829 $outputlangs = $langs;
1831 if (
GETPOST(
'lang_id',
'aZ09')) {
1832 $newlang =
GETPOST(
'lang_id',
'aZ09');
1834 if (empty($newlang)) {
1835 $newlang =
$object->thirdparty->default_lang;
1837 if (!empty($newlang)) {
1839 $outputlangs->setDefaultLang($newlang);
1841 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
1843 $desc = $productsupplier->description;
1846 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
1847 $desc = $productsupplier->desc_supplier;
1858 $ref_supplier = $productsupplier->ref_supplier;
1862 $tmpidprodfournprice =
GETPOST(
'idprodfournprice',
'alpha');
1863 if (is_numeric($tmpidprodfournprice) && (
int) $tmpidprodfournprice > 0) {
1864 $tmpidprodfournprice = (int) $tmpidprodfournprice;
1866 $tmpidprodfournprice = 0;
1872 if (empty($tva_tx) || empty($tva_npr)) {
1878 $type = $productsupplier->type;
1879 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1880 $price_base_type =
'HT';
1882 $pu_devise =
price2num($price_ht_devise,
'CU');
1883 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
1884 $price_base_type =
'TTC';
1886 $pu_devise =
price2num($price_ttc_devise,
'CU');
1888 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
1889 if (empty(
$object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code !=
$object->multicurrency_code)) {
1890 $pu = $productsupplier->fourn_pu;
1893 $pu = $productsupplier->fourn_pu;
1894 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
1898 $ref_supplier = $productsupplier->ref_supplier;
1919 min($rank, count(
$object->lines) + 1),
1922 $productsupplier->fk_unit,
1925 GETPOST(
'fourn_ref',
'alpha'),
1929 if ($idprod == -99 || $idprod == 0) {
1932 $langs->load(
"errors");
1933 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
1935 if ($idprod == -1) {
1938 $langs->load(
"errors");
1939 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
1941 } elseif (empty($error)) {
1942 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1943 $tva_tx = str_replace(
'*',
'', $tva_tx);
1944 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1947 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
1951 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1959 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1963 $pu_ht =
price2num((
float) $pu_ttc / (1 + ((
float) $tva_tx / 100)),
'MU');
1965 $price_base_type =
'HT';
1966 $pu_devise =
price2num($price_ht_devise,
'CU');
1968 $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);
1972 if (!$error && $result > 0) {
1977 $outputlangs = $langs;
1980 $newlang =
GETPOST(
'lang_id',
'aZ09');
1983 $newlang =
$object->thirdparty->default_lang;
1985 if (!empty($newlang)) {
1987 $outputlangs->setDefaultLang($newlang);
1992 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1998 unset($_POST [
'prod_entry_mode']);
2000 unset($_POST[
'qty']);
2001 unset($_POST[
'type']);
2002 unset($_POST[
'remise_percent']);
2003 unset($_POST[
'pu']);
2004 unset($_POST[
'price_ht']);
2005 unset($_POST[
'multicurrency_price_ht']);
2006 unset($_POST[
'price_ttc']);
2007 unset($_POST[
'fourn_ref']);
2008 unset($_POST[
'tva_tx']);
2009 unset($_POST[
'label']);
2010 unset($localtax1_tx);
2011 unset($localtax2_tx);
2012 unset($_POST[
'np_marginRate']);
2013 unset($_POST[
'np_markRate']);
2014 unset($_POST[
'dp_desc']);
2015 unset($_POST[
'idprodfournprice']);
2016 unset($_POST[
'units']);
2018 unset($_POST[
'date_starthour']);
2019 unset($_POST[
'date_startmin']);
2020 unset($_POST[
'date_startsec']);
2021 unset($_POST[
'date_startday']);
2022 unset($_POST[
'date_startmonth']);
2023 unset($_POST[
'date_startyear']);
2024 unset($_POST[
'date_endhour']);
2025 unset($_POST[
'date_endmin']);
2026 unset($_POST[
'date_endsec']);
2027 unset($_POST[
'date_endday']);
2028 unset($_POST[
'date_endmonth']);
2029 unset($_POST[
'date_endyear']);
2036 } elseif ($action ==
'classin' && $usercancreate) {
2038 $result =
$object->setProject($projectid);
2039 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
2043 $totalpaid =
$object->getSommePaiement();
2044 $resteapayer =
$object->total_ttc - $totalpaid;
2047 $ventilExportCompta =
$object->getVentilExportCompta();
2049 if (!$ventilExportCompta) {
2052 $idwarehouse =
GETPOST(
'idwarehouse');
2056 $qualified_for_stock_change = 0;
2058 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2060 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2065 $langs->load(
"stocks");
2066 if (!$idwarehouse || $idwarehouse == -1) {
2068 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
2073 $object->setDraft($user, $idwarehouse);
2077 $outputlangs = $langs;
2080 $newlang =
GETPOST(
'lang_id',
'aZ09');
2083 $newlang =
$object->thirdparty->default_lang;
2085 if (!empty($newlang)) {
2087 $outputlangs->setDefaultLang($newlang);
2092 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2101 } elseif ($action ==
'reopen' && $usercancreate) {
2103 $result =
$object->fetch($id);
2106 $result =
$object->setUnpaid($user);
2108 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
2117 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2120 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
2122 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
2123 $trackid =
'sinv'.$object->id;
2124 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2128 $permissiontoadd = $usercancreate;
2129 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2132 if ($action ==
'calculate' && $usercancreate) {
2133 $calculationrule =
GETPOST(
'calculationrule');
2137 $result =
$object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0,
$object->thirdparty);
2143 if ($action ==
'update_extras' && $permissiontoeditextra) {
2146 $attribute_name =
GETPOST(
'attribute',
'aZ09');
2149 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
2155 $result =
$object->updateExtraField($attribute_name,
'BILL_SUPPLIER_MODIFY');
2163 $action =
'edit_extras';
2168 if ($action ==
'addcontact' && $usercancreate) {
2169 $result =
$object->fetch($id);
2171 if ($result > 0 && $id > 0) {
2174 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2178 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2181 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2182 $langs->load(
"errors");
2183 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2188 } elseif ($action ==
'swapstatut' && $usercancreate) {
2195 } elseif ($action ==
'deletecontact' && $usercancreate) {
2201 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2225$title =
$object->ref.
" - ".$langs->trans(
'Card');
2226if ($action ==
'create') {
2227 $title = $langs->trans(
"NewSupplierInvoice");
2229$help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
2230llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-fourn-facture page-card');
2233if ($action ==
'create') {
2235 $selectedLines = array();
2237 print
load_fiche_titre($langs->trans(
'NewSupplierInvoice'),
'',
'supplier_invoice');
2241 $currency_code =
$conf->currency;
2242 $vat_reverse_charge = 0;
2248 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2249 $currency_code = $societe->multicurrency_code;
2254 if (!empty($origin) && !empty($originid)) {
2256 $element = $subelement = $origin;
2258 if ($element ==
'project') {
2259 $projectid = $originid;
2260 $element =
'projet';
2264 if ($element ==
'order') {
2265 $element = $subelement =
'commande';
2267 if ($element ==
'propal') {
2268 $element =
'comm/propal';
2269 $subelement =
'propal';
2271 if ($element ==
'contract') {
2272 $element = $subelement =
'contrat';
2274 if ($element ==
'order_supplier') {
2276 $subelement =
'fournisseur.commande';
2280 $classname = ucfirst($subelement);
2281 if ($classname ==
'Fournisseur.commande') {
2282 $classname =
'CommandeFournisseur';
2284 $objectsrc =
new $classname(
$db);
2285 '@phan-var-force Project|Commande|Propal|Facture|Contrat|CommandeFournisseur|CommonObject $objectsrc';
2287 $objectsrc->fetch($originid);
2288 $objectsrc->fetch_thirdparty();
2290 $projectid = (int) $objectsrc->fk_project;
2292 $soc = $objectsrc->thirdparty;
2294 $cond_reglement_id = 0;
2295 $mode_reglement_id = 0;
2297 $transport_mode_id = 0;
2300 if (!empty($objectsrc->cond_reglement_id)) {
2301 $cond_reglement_id = $objectsrc->cond_reglement_id;
2303 if (!empty($objectsrc->mode_reglement_id)) {
2304 $mode_reglement_id = $objectsrc->mode_reglement_id;
2306 if (!empty($objectsrc->fk_account)) {
2307 $fk_account = $objectsrc->fk_account;
2309 if (!empty($objectsrc->transport_mode_id)) {
2310 $transport_mode_id = $objectsrc->transport_mode_id;
2313 if (empty($cond_reglement_id)
2314 || empty($mode_reglement_id)
2315 || empty($fk_account)
2316 || empty($transport_mode_id)
2318 if ($origin ==
'reception') {
2320 if (!isset($objectsrc->supplier_order)) {
2321 $objectsrc->fetch_origin();
2324 if (!empty($objectsrc->origin_object)) {
2325 $originObject = $objectsrc->origin_object;
2326 if (empty($cond_reglement_id) && !empty($originObject->cond_reglement_id)) {
2327 $cond_reglement_id = $originObject->cond_reglement_id;
2329 if (empty($mode_reglement_id) && !empty($originObject->mode_reglement_id)) {
2330 $mode_reglement_id = $originObject->mode_reglement_id;
2332 if (empty($fk_account) && !empty($originObject->fk_account)) {
2333 $fk_account = $originObject->fk_account;
2335 if (empty($transport_mode_id) && !empty($originObject->transport_mode_id)) {
2336 $transport_mode_id = $originObject->transport_mode_id;
2343 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
2344 $cond_reglement_id = $soc->cond_reglement_supplier_id;
2346 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
2347 $mode_reglement_id = $soc->mode_reglement_supplier_id;
2349 if (empty($fk_account) && !empty($soc->fk_account)) {
2350 $fk_account = $soc->fk_account;
2352 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
2353 $transport_mode_id = $soc->transport_mode_id;
2359 if (!empty($objectsrc->multicurrency_code)) {
2360 $currency_code = $objectsrc->multicurrency_code;
2362 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
2363 $currency_tx = $objectsrc->multicurrency_tx;
2368 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2370 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2373 $objectsrc->fetch_optionals();
2374 $object->array_options = $objectsrc->array_options;
2376 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2377 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2378 $vat_reverse_charge = (empty($societe) ?
'' : $societe->vat_reverse_charge);
2379 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2380 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2382 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalInt(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2384 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2386 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2387 $currency_code = $societe->multicurrency_code;
2392 if (empty($cond_reglement_id)) {
2393 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2397 if (empty($mode_reglement_id)) {
2398 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2402 if (!
GETPOST(
'changecompany')) {
2404 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
2407 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
2414 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
2415 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
2417 if ($origin ==
'contrat') {
2418 $langs->load(
"admin");
2419 $text = $langs->trans(
"ToCreateARecurringInvoice");
2420 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"SupplierBills"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
2422 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
2424 print
info_admin($text, 0, 0,
'0',
'opacitymedium').
'<br>';
2427 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2428 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2429 print
'<input type="hidden" name="action" value="add">';
2430 print
'<input type="hidden" name="changecompany" value="0">';
2432 if (!empty($societe->id) && $societe->id > 0) {
2433 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2435 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2436 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2437 if (!empty($currency_tx)) {
2438 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2440 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2445 $parameters = array();
2447 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierInvoice', $parameters, $object, $action);
2448 if (empty($reshook)) {
2449 print
'<table class="border centpercent">';
2456 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2457 $invoice_predefined->fetch($fac_recid);
2461 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2464 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2465 $absolute_discount = $societe->getAvailableDiscounts(
null,
'', 0, 1);
2466 print $societe->getNomUrl(1,
'supplier');
2467 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2469 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2470 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');
2473 print
'<script type="text/javascript">
2474 $(document).ready(function() {
2475 $("#socid").change(function() {
2476 console.log("We have changed the company - Reload page");
2478 $("input[name=action]").val("create");
2479 $("input[name=changecompany]").val("1");
2480 $("form[name=add]").submit();
2485 if ($fac_recid <= 0) {
2486 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>';
2492 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2493 $invoice_predefined->fetch($fac_recid);
2495 $dateinvoice = $invoice_predefined->date_when;
2496 if (empty($projectid)) {
2497 $projectid = $invoice_predefined->fk_project;
2499 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2500 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2501 $fk_account = $invoice_predefined->fk_account;
2502 $note_public = $invoice_predefined->note_public;
2503 $note_private = $invoice_predefined->note_private;
2505 if (!empty($invoice_predefined->multicurrency_code)) {
2506 $currency_code = $invoice_predefined->multicurrency_code;
2508 if (!empty($invoice_predefined->multicurrency_tx)) {
2509 $currency_tx = $invoice_predefined->multicurrency_tx;
2512 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2513 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2514 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2516 $resql =
$db->query($sql);
2518 $num =
$db->num_rows($resql);
2522 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2524 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2525 print
'<option value="0" selected></option>';
2527 $objp =
$db->fetch_object($resql);
2528 print
'<option value="'.$objp->rowid.
'"';
2529 if ($fac_recid == $objp->rowid) {
2531 $exampletemplateinvoice->fetch($fac_recid);
2533 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2539 print
'<script type="text/javascript">
2540 $(document).ready(function() {
2541 $("#fac_rec").change(function() {
2542 console.log("We have changed the template invoice - Reload page");
2544 $("input[name=action]").val("create");
2545 $("form[name=add]").submit();
2558 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2560 print
'<div class="tagtable">'.
"\n";
2563 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2564 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
'checked').
'> ';
2565 $desc = $form->textwithpicto($tmp.
'<label for="radio_standard">'.$langs->trans(
"InvoiceStandardAsk").
'</label>', $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2567 print
'</div></div>';
2569 if (empty($origin) || (($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') && !empty($originid))) {
2572 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2573 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOSTINT(
'type') == 3 ?
' checked' :
'') .
'> ';
2574 print
'<script type="text/javascript">
2575 jQuery(document).ready(function() {
2576 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2577 jQuery("#radio_standard").prop("checked", true);
2579 jQuery("#typedeposit, #valuedeposit").click(function() {
2580 jQuery("#radio_deposit").prop("checked", true);
2582 jQuery("#typedeposit").change(function() {
2583 console.log("We change type of down payment");
2584 jQuery("#radio_deposit").prop("checked", true);
2585 setRadioForTypeOfInvoice();
2587 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2588 setRadioForTypeOfInvoice();
2590 function setRadioForTypeOfInvoice() {
2591 console.log("Change radio");
2592 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2593 jQuery(".checkforselect").prop("disabled", true);
2594 jQuery(".checkforselect").prop("checked", false);
2596 jQuery(".checkforselect").prop("disabled", false);
2597 jQuery(".checkforselect").prop("checked", true);
2603 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2605 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2606 print
'<table class="nobordernopadding"><tr>';
2610 if ($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') {
2611 print
'<td class="nowrap" style="padding-left: 15px">';
2613 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2614 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2615 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2617 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
2618 $valuedeposit =
GETPOST(
'valuedeposit',
'int');
2619 $deposit_percent =
null;
2620 if ($origin ==
'reception') {
2622 if (!isset($objectsrc->origin_object)) {
2623 $objectsrc->fetch_origin();
2625 if (!empty($objectsrc->origin_object)) {
2626 $deposit_percent = $objectsrc->origin_object->deposit_percent;
2628 } elseif (!empty($objectsrc->deposit_percent)) {
2629 $deposit_percent = $objectsrc->deposit_percent;
2631 if (empty($typedeposit) && !empty($deposit_percent)) {
2632 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
2633 if (!empty($origin_payment_conditions_deposit_percent)) {
2634 $typedeposit =
'variable';
2637 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($deposit_percent)) {
2638 $valuedeposit = $deposit_percent;
2640 print $form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
2642 print
'<td class="nowrap" style="padding-left: 5px">';
2643 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' . $valuedeposit .
'"/>';
2646 print
'</tr></table>';
2648 print
'</div></div>';
2717 if (empty($origin)) {
2718 if (!empty($societe->id) && $societe->id > 0) {
2722 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2729 foreach ($facids as $key => $valarray) {
2730 $newinvoice_static->id = $key;
2731 $newinvoice_static->ref = $valarray [
'ref'];
2732 $newinvoice_static->status = $valarray [
'status'];
2733 $newinvoice_static->statut = $valarray [
'status'];
2734 $newinvoice_static->type = $valarray [
'type'];
2735 $newinvoice_static->paid = $valarray [
'paye'];
2736 $newinvoice_static->paye = $valarray [
'paye'];
2738 $optionsav .=
'<option value="'.$key.
'"';
2740 $optionsav .=
' selected';
2742 $newinvoice_static->fetch_optionals($key);
2743 $object->array_options = $newinvoice_static->array_options;
2746 $optionsav .= $newinvoice_static->ref;
2747 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
2748 $optionsav .=
'</option>';
2751 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2752 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOSTINT(
'type') == 2 ?
' checked' :
'');
2754 $tmp .=
' disabled';
2758 print
'<script type="text/javascript">
2759 jQuery(document).ready(function() {
2760 if (! jQuery("#radio_creditnote").is(":checked"))
2762 jQuery("#credit_note_options").hide();
2764 jQuery("#radio_creditnote").click(function() {
2765 jQuery("#credit_note_options").show();
2767 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2768 jQuery("#credit_note_options").hide();
2772 $text = $tmp.
'<label for="radio_creditnote">'.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
2774 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2776 $text .=
' disabled';
2780 $text .=
'<option value="-1"></option>';
2781 $text .= $optionsav;
2783 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
2785 $text .=
'</select>';
2786 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2789 print
'<div id="credit_note_options" class="clearboth">';
2790 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' :
'').
' /> ';
2791 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
2792 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' :
'').
' /> ';
2793 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
2796 print
'</div></div>';
2799 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2801 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2803 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2"> ';
2805 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
2806 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
2807 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2809 print
'</div></div>'.
"\n";
2819 print
'<tr><td class="fieldrequired">';
2820 print $form->textwithpicto($langs->trans(
'RefSupplierBill'), $langs->trans(
"RefOfOnVendorSide", $langs->trans(
"SupplierBill"))).
'</td><td>';
2821 print
'<input name="ref_supplier" value="'.(GETPOSTISSET(
'ref_supplier') ?
GETPOST(
'ref_supplier') : (!empty($objectsrc->ref_supplier) ? $objectsrc->ref_supplier :
'')).
'" type="text" spellcheck="false"';
2822 if (!empty($societe->id) && $societe->id > 0) {
2831 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
2832 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
2836 if (!empty($societe->id) && $societe->id > 0) {
2838 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2840 $thirdparty = $societe;
2842 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2843 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2849 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth300" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
2853 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
2854 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2855 print $form->selectDate($dateinvoice ? (
int) $dateinvoice :
'',
'', 0, 0, 0,
"add", 1, 1);
2860 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td>';
2861 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2862 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
2867 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2868 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
2869 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth200 widthcentpercentminusx');
2873 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
2874 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2875 print $form->selectDate($datedue,
'ech', 0, 0, 0,
"add", 1, 1);
2879 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2880 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2881 $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'DBIT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
2886 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2888 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
2896 $langs->load(
'projects');
2897 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2898 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');
2899 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>';
2906 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
2907 print
'<td colspan="3" class="maxwidthonsmartphone">';
2908 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2909 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 :
''));
2915 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
2916 print
'<tr><td>' . $langs->trans(
'VATReverseCharge') .
'</td><td>';
2919 $vat_reverse_charge = (
GETPOST(
'vat_reverse_charge',
'alpha') ==
'on' ||
GETPOST(
'vat_reverse_charge',
'alpha') ==
'1') ? 1 : 0;
2920 } elseif ($vat_reverse_charge == 1 || $societe->vat_reverse_charge == 1 || ($societe->country_code !=
'FR' &&
isInEEC($societe) && !empty($societe->tva_intra))) {
2921 $vat_reverse_charge = 1;
2923 $vat_reverse_charge = 0;
2926 print
'<input type="checkbox" name="vat_reverse_charge"'. (!empty($vat_reverse_charge) ?
' checked ' :
'') .
'>';
2933 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
2934 print
'<td class="maxwidthonsmartphone">';
2935 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
2936 $used_currency_code = $currency_code;
2937 if (!
GETPOST(
'changecompany')) {
2938 $used_currency_code =
GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code;
2940 print $form->selectMultiCurrency($used_currency_code,
'multicurrency_code');
2946 if ($fac_recid > 0) {
2947 $dateexample = $dateinvoice;
2948 if (empty($dateexample)) {
2951 $substitutionarray = array(
2952 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
2953 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
2954 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
2955 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
2956 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
2957 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
2958 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
2959 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
2960 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
2961 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
2962 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
2965 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
2966 foreach ($substitutionarray as $key => $val) {
2967 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
2969 $htmltext .=
'</i>';
2974 $langs->loadLangs(array(
"intracommreport"));
2975 print
'<!-- If module intracomm on -->'.
"\n";
2976 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
2977 $form->selectTransportMode(
GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
2981 if (empty($reshook)) {
2982 print
$object->showOptionals($extrafields,
'create');
2987 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
2988 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
2993 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2995 $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%');
2996 print $doleditor->Create(1);
3002 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
3004 $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%');
3005 print $doleditor->Create(1);
3011 if (!empty($objectsrc) && $classname !==
null) {
3012 print
"\n<!-- ".$classname.
" info -->";
3014 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
3015 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
3016 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
3017 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
3018 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
3020 $txt = $langs->trans($classname);
3021 if ($classname ==
'CommandeFournisseur') {
3022 $langs->load(
'orders');
3023 $txt = $langs->trans(
"SupplierOrder");
3025 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
3027 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'invoice_supplier');
3029 if (isset($objectsrc->linkedObjects[
'invoice_supplier'])) {
3030 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
3032 $invoice_supplier = [];
3034 '@phan-var-force null|FactureFournisseur[] $invoice_supplier';
3037 if (is_array($invoice_supplier)) {
3038 $cntinvoice = count($invoice_supplier);
3040 if ($cntinvoice >= 1) {
3042 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
3047 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
3048 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
3049 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
3050 print
'<tr><td>'.$langs->transcountry(
"AmountLT1",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
3053 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
3054 print
'<tr><td>'.$langs->transcountry(
"AmountLT2",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
3056 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
3059 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
'</td></tr>';
3060 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
"</td></tr>";
3061 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
"</td></tr>";
3066 $parameters = array();
3067 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
3068 print $hookmanager->resPrint;
3076 print $form->buttonsSaveCancel(
"CreateDraft");
3079 if (!empty($objectsrc)) {
3082 $title = $langs->trans(
'ProductsAndServices');
3085 print
'<div class="div-table-responsive-no-min">';
3086 print
'<table class="noborder centpercent">';
3088 $objectsrc->printOriginLinesList(
'', $selectedLines);
3096 if ($id > 0 || !empty($ref)) {
3102 $result =
$object->fetch($id, $ref);
3107 $result =
$object->fetch_thirdparty();
3113 $societe =
$object->thirdparty;
3115 $totalpaid =
$object->getSommePaiement();
3116 $totalcreditnotes =
$object->getSumCreditNotesUsed();
3117 $totaldeposits =
$object->getSumDepositsUsed();
3125 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
3128 $multicurrency_resteapayer = 0;
3130 $multicurrency_totalpaid =
$object->getSommePaiement(1);
3131 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
3132 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
3133 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
3137 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
3138 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
3145 $resteapayeraffiche = $resteapayer;
3148 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
3149 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
3151 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
3152 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
3155 $absolute_discount = $societe->getAvailableDiscounts(
null, $filterabsolutediscount, 0, 1);
3156 $absolute_creditnote = $societe->getAvailableDiscounts(
null, $filtercreditnote, 0, 1);
3157 $absolute_discount =
price2num($absolute_discount,
'MT');
3158 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
3162 $objectidnext =
$object->getIdReplacingInvoice();
3165 $titre = $langs->trans(
'SupplierInvoice');
3167 print
dol_get_fiche_head($head,
'card', $titre, -1,
'supplier_invoice', 0,
'',
'', 0,
'', 1);
3172 if ($action ==
'converttoreduc') {
3175 $type_fac =
'ExcessPaid';
3177 $type_fac =
'CreditNote';
3179 $type_fac =
'Deposit';
3181 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
3182 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
3183 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
3187 if ($action ==
'clone') {
3189 $formquestion = array(
3190 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplierBill"),
'value' => $langs->trans(
"CopyOf").
' '.
$object->ref_supplier),
3191 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
3194 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 0);
3198 if ($action ==
'valid') {
3200 if (preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) {
3202 $numref =
$object->getNextNumRef($societe);
3211 $text = $langs->trans(
'ConfirmValidateBill', $numref);
3219 $formquestion = array();
3221 $qualified_for_stock_change = 0;
3223 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3225 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3229 $langs->load(
"stocks");
3230 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3233 $warehouse_array = $warehouse->list_array();
3234 if (count($warehouse_array) == 1) {
3236 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3239 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3241 $formquestion = array(
3242 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3246 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
3251 if ($action ==
'edit') {
3252 $formquestion = array();
3254 $qualified_for_stock_change = 0;
3256 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3258 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3261 $langs->load(
"stocks");
3262 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3265 $warehouse_array = $warehouse->list_array();
3266 if (count($warehouse_array) == 1) {
3268 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3271 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3273 $formquestion = array(
3274 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3277 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill',
$object->ref),
'confirm_edit', $formquestion, 1, 1);
3281 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
3282 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'', 0, 1);
3285 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
3289 $close[$i][
'code'] =
'discount_vat';
3291 $close[$i][
'code'] =
'badsupplier';
3293 $close[$i][
'code'] =
'other';
3297 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
3299 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3301 $close[$i][
'label'] = $langs->trans(
"Other");
3305 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3307 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3309 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
3312 $arrayreasons = array();
3313 foreach ($close as $key => $val) {
3314 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
3318 $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'));
3320 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
3324 if ($action ==
'canceled') {
3326 $close[1][
'code'] =
'badsupplier';
3327 $close[2][
'code'] =
'abandon';
3329 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3330 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
3332 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier",
$object->ref), $close[1][
'label'], 1);
3333 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
3335 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
3336 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
3339 $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'));
3341 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 280);
3345 if ($action ==
'delete') {
3346 $formquestion = array();
3348 $qualified_for_stock_change = 0;
3350 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3352 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3356 $langs->load(
"stocks");
3357 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3360 $warehouse_array = $warehouse->list_array();
3362 $selectwarehouse =
'<span class="questionrevertstock hidden">';
3363 if (count($warehouse_array) == 1) {
3365 $selectwarehouse .=
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3368 $selectwarehouse .= $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3370 $selectwarehouse .=
'</span>';
3372 $selectyesno = array(0 => $langs->trans(
'No'), 1 => $langs->trans(
'Yes'));
3374 print
'<script type="text/javascript">
3375 $(document).ready(function() {
3376 $("#revertstock").change(function() {
3377 if(this.value > 0) {
3378 $(".questionrevertstock").removeClass("hidden");
3380 $(".questionrevertstock").addClass("hidden");
3386 $formquestion = array(
3387 array(
'type' =>
'select',
'name' =>
'revertstock',
'label' => $langs->trans(
"RevertProductsToStock"),
'select_show_empty' => 0,
'values' => $selectyesno),
3388 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $selectwarehouse,
'tdclass' =>
'questionrevertstock hidden')
3392 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete', $formquestion, 1, 1);
3394 if ($action ==
'deletepayment') {
3395 $payment_id =
GETPOST(
'paiement_id');
3396 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
3400 if ($action ==
'ask_deleteline') {
3401 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
3405 if ($action ==
'add_title_line') {
3406 $langs->load(
'subtotals');
3408 $depth_array =
$object->getPossibleLevels($langs);
3409 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3410 } elseif ($action ==
'add_subtotal_line') {
3411 $langs->load(
'subtotals');
3413 $titles =
$object->getPossibleTitles();
3414 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3418 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
3419 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
3420 if (empty($reshook)) {
3421 $formconfirm .= $hookmanager->resPrint;
3422 } elseif ($reshook > 0) {
3423 $formconfirm = $hookmanager->resPrint;
3431 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
3433 $morehtmlref =
'<div class="refidno">';
3435 $morehtmlref .= $form->editfieldkey(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, (
int) $usercancreate,
'string',
'', 0, 1);
3436 $morehtmlref .= $form->editfieldval(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
3438 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'supplier');
3440 $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>';
3444 $langs->load(
"projects");
3445 $morehtmlref .=
'<br>';
3446 if ($permissiontoadd) {
3447 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
3448 if ($action !=
'classify') {
3449 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.((int)
$object->id).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
3451 $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');
3453 if (!empty(
$object->fk_project)) {
3455 $proj->fetch(
$object->fk_project);
3456 $morehtmlref .= $proj->getNomUrl(1);
3458 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
3463 $morehtmlref .=
'</div>';
3465 $object->totalpaid = $totalpaid;
3467 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
3470 $parameters = array();
3472 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierInvoice', $parameters, $object, $action);
3473 if (empty($reshook)) {
3474 print
'<div class="fichecenter">';
3475 print
'<div class="fichehalfleft">';
3476 print
'<div class="underbanner clearboth"></div>';
3478 print
'<table class="border tableforfield centpercent">';
3481 print
'<tr><td>'.$langs->trans(
'Type').
'</td><td>';
3482 print
'<span class="badgeneutral">';
3486 print
' '.$object->getSubtypeLabel(
'facture_fourn');
3490 $facreplaced->fetch(
$object->fk_facture_source);
3491 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
3494 if (
$object->fk_facture_source > 0) {
3496 $facusing->fetch(
$object->fk_facture_source);
3497 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
3499 $langs->load(
"errors");
3500 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"WarningCorrectedInvoiceNotFound").
'</span>';
3505 $object->getListIdAvoirFromInvoice();
3507 if (!empty(
$object->creditnote_ids)) {
3508 $invoicecredits = array();
3509 foreach (
$object->creditnote_ids as $invoiceid) {
3511 $creditnote->fetch($invoiceid);
3512 $invoicecredits[] = $creditnote->getNomUrl(1);
3514 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
3517 if (isset($objectidnext) && $objectidnext > 0) {
3520 $facthatreplace->fetch($objectidnext);
3521 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
3525 $result = $discount->fetch(0, 0,
$object->id);
3527 print
' <span class="opacitymediumbycolor paddingleft">';
3528 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
3529 $s = str_replace(
'{s1}',
$object->getLibType(1), $s);
3530 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
3532 print
'</span><br>';
3536 if (
$object->fk_fac_rec_source > 0) {
3538 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
3540 print
' <span class="opacitymediumbycolor paddingleft">';
3541 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->title).
'</a>';
3542 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
3552 print
'<!-- Discounts -->'.
"\n";
3553 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
3556 $thirdparty = $societe;
3558 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3564 print
'<td>'.$form->editfieldkey(
"Label",
'label',
$object->label, $object, (
int) $usercancreate).
'</td>';
3565 print
'<td>'.$form->editfieldval(
"Label",
'label',
$object->label, $object, $usercancreate).
'</td>';
3573 print $form->editfieldkey(
"DateInvoice",
'datef', (
string)
$object->date,
$object, (int) $form_permission,
'datepicker');
3574 print
'</td><td colspan="3">';
3575 print $form->editfieldval(
"Date",
'datef',
$object->date, $object, $form_permission,
'datepicker');
3581 print $form->editfieldkey(
"DatePointOfTax",
'date_pointoftax', (
string)
$object->date_pointoftax,
$object, (int) $pointoftax_form_permission,
'datepicker');
3582 print
'</td><td colspan="3">';
3583 print $form->editfieldval(
"DatePointOfTax",
'date_pointoftax',
$object->date_pointoftax, $object, $pointoftax_form_permission,
'datepicker');
3588 $langs->load(
'bills');
3589 print
'<tr><td class="nowrap">';
3590 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3591 print $langs->trans(
'PaymentConditions');
3593 if ($action !=
'editconditions' && $form_permission) {
3594 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>';
3596 print
'</tr></table>';
3598 if ($action ==
'editconditions') {
3599 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
3601 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
3608 print $form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', (
string)
$object->date_echeance, $object, (
int) $form_permission,
'datepicker');
3610 print $form->editfieldval(
"DateMaxPayment",
'date_lim_reglement',
$object->date_echeance, $object, $form_permission,
'datepicker');
3611 if ($action !=
'editdate_lim_reglement' &&
$object->hasDelay()) {
3617 $langs->load(
'bills');
3618 print
'<tr><td class="nowrap">';
3619 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3620 print $langs->trans(
'PaymentMode');
3622 if ($action !=
'editmode' && $form_permission) {
3623 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>';
3625 print
'</tr></table>';
3627 if ($action ==
'editmode') {
3628 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3630 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'none');
3636 print
'<tr><td class="nowrap">';
3637 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3638 print $langs->trans(
'BankAccount');
3640 if ($action !=
'editbankaccount' && $usercancreate) {
3641 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>';
3643 print
'</tr></table>';
3645 if ($action ==
'editbankaccount') {
3646 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
3648 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
3656 print
'<tr><td class="nowrap">';
3657 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3658 print $langs->trans(
'VATReverseCharge');
3660 if ($action !=
'editvatreversecharge' && $usercancreate) {
3661 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>';
3663 print
'</tr></table>';
3665 if ($action ==
'editvatreversecharge') {
3666 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
3667 print
'<input type="hidden" name="action" value="setvatreversecharge">';
3668 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3670 print
'<input type="checkbox" name="vat_reverse_charge"' . (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
'>';
3672 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
3675 print
'<input type="checkbox" name="vat_reverse_charge"'. (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
' disabled>';
3683 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3684 print $langs->trans(
'IncotermLabel');
3685 print
'<td><td class="right">';
3686 if ($usercancreate) {
3687 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
3691 print
'</td></tr></table>';
3694 if ($action !=
'editincoterm') {
3695 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
3697 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
3704 $langs->loadLangs(array(
"intracommreport"));
3705 print
'<!-- If module intracomm on -->'.
"\n";
3707 print
'<table class="nobordernopadding centpercent"><tr><td>';
3708 print $langs->trans(
'IntracommReportTransportMode');
3710 if ($action !=
'edittransportmode' && ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"))) {
3711 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edittransportmode&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit().
'</a></td>';
3713 print
'</tr></table>';
3716 if ($action ==
'edittransportmode') {
3717 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'transport_mode_id', 1, 1);
3719 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'none');
3727 print
'<table class="nobordernopadding centpercent"><tr><td>';
3728 print $langs->trans(
"Categories");
3729 print
'<td><td class="right">';
3730 if ($usercancreate) {
3731 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
3735 print
'</td></tr></table>';
3738 if ($action ==
'edittags') {
3739 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
3740 print
'<input type="hidden" name="action" value="settags">';
3741 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3742 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
3743 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
3746 print $form->showCategories(
$object->id, Categorie::TYPE_SUPPLIER_INVOICE, 1);
3754 if (
$object->status != $object::STATUS_DRAFT) {
3758 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
3763 print
'<div class="fichehalfright">';
3764 print
'<div class="underbanner clearboth"></div>';
3766 print
'<table class="border tableforfield centpercent">';
3768 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
3771 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
3772 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3774 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3779 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
3780 print
'<td class="nowrap amountcard right">';
3781 if (
GETPOST(
'calculationrule')) {
3782 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
3784 $calculationrule = (!
getDolGlobalString(
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND_SUPPLIER') ?
'totalofround' :
'roundoftotal');
3786 if ($calculationrule ==
'totalofround') {
3787 $calculationrulenum = 1;
3789 $calculationrulenum = 2;
3792 if (
$object->getVentilExportCompta() == 0) {
3793 $s =
'<span class="hideonsmartphone opacitymedium">' . $langs->trans(
"ReCalculate") .
' </span>';
3794 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=totalofround">' . $langs->trans(
"Mode1") .
'</a>';
3796 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=roundoftotal">' . (
$conf->dol_optimize_smallscreen ?
"2" : $langs->trans(
"Mode2")) .
'</a>';
3797 print
'<div class="inline-block">';
3798 print $form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum) .
'<br>' . $langs->trans(
"CalculationRuleDescSupplier"), 2, 1,
img_picto(
'',
'help',
'class="paddingleft paddingright"'),
'', 3,
'', 0,
'recalculate');
3799 print
' ';
3802 print
'<span class="nowraponall">'.price(
$object->total_tva, 1, $langs, 0, -1, -1,
$conf->currency).
'</span>';
3805 print
'<td class="nowraponall amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3809 if ($societe->localtax1_assuj ==
"1") {
3811 print
'<td>' . $langs->transcountry(
"AmountLT1", $societe->country_code) .
'</td>';
3812 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3815 if ($societe->localtax2_assuj ==
"1") {
3817 print
'<td>' . $langs->transcountry(
"AmountLT2", $societe->country_code) .
'</td>';
3818 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3823 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
3824 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3826 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3859 if ($societe->localtax1_assuj ==
"1") {
3862 if ($societe->localtax2_assuj ==
"1") {
3866 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
3867 $sql .=
' c.id as payment_type, c.code as payment_code,';
3868 $sql .=
' pf.amount,';
3869 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
3870 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
3871 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
3872 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
3873 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
3874 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
3875 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
3876 $sql .=
' ORDER BY p.datep, p.tms';
3878 $result =
$db->query($sql);
3880 $num =
$db->num_rows($result);
3883 print
'<div class="div-table-responsive-no-min">';
3884 print
'<table class="noborder paymenttable centpercent">';
3885 print
'<tr class="liste_titre">';
3887 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
3888 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
3890 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
3895 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
3900 $objp =
$db->fetch_object($result);
3902 $paymentstatic->id = $objp->rowid;
3903 $paymentstatic->datepaye =
$db->jdate($objp->dp);
3904 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
3905 $paymentstatic->num_payment = $objp->num_payment;
3907 $paymentstatic->paiementcode = $objp->payment_code;
3908 $paymentstatic->type_code = $objp->payment_code;
3909 $paymentstatic->type_label = $objp->payment_type;
3911 print
'<tr class="oddeven">';
3912 print
'<td class="nowraponall">';
3913 print $paymentstatic->getNomUrl(1);
3915 print
'<td>'.dol_print_date(
$db->jdate($objp->dp),
'day').
'</td>';
3916 $s = $form->form_modes_reglement(
'', $objp->payment_type,
'none',
'', 1, 0,
'', 1).
' '.$objp->num_payment;
3917 print
'<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).
'">';
3921 $bankaccountstatic->id = $objp->baid;
3922 $bankaccountstatic->ref = $objp->baref;
3923 $bankaccountstatic->label = $objp->baref;
3924 $bankaccountstatic->number = $objp->banumber;
3927 $bankaccountstatic->account_number = $objp->account_number;
3930 $accountingjournal->fetch($objp->fk_accountancy_journal);
3931 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
3934 print
'<td class="right nowraponall">';
3935 if ($objp->baid > 0) {
3936 print $bankaccountstatic->getNomUrl(1,
'transactions');
3941 print
'<td class="center">';
3943 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
3949 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
3951 $totalpaid += $objp->amount;
3955 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
3981 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
3982 print
'<span class="opacitymedium">';
3984 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
3986 print $langs->trans(
'AlreadyPaid');
3991 print
'<td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td>';
3995 $resteapayeraffiche = $resteapayer;
3997 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
4000 $creditnoteamount = 0;
4003 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
4004 $sql .=
" re.description, re.fk_invoice_supplier_source";
4005 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
4006 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
4007 $resql =
$db->query($sql);
4009 $num =
$db->num_rows($resql);
4013 $obj =
$db->fetch_object($resql);
4014 $invoice->fetch($obj->fk_invoice_supplier_source);
4015 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4017 print $langs->trans(
"CreditNote").
' ';
4020 print $langs->trans(
"Deposit").
' ';
4022 print $invoice->getNomUrl(0);
4025 print
'<td class="right">';
4026 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
4027 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
4031 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
4035 $creditnoteamount += $obj->amount_ttc;
4038 $depositamount += $obj->amount_ttc;
4047 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4048 print
'<span class="opacitymedium">';
4049 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
4053 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4055 $resteapayeraffiche = 0;
4056 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4060 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4061 print
'<span class="opacitymedium">';
4062 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
4066 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4069 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4073 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4074 print
'<span class="opacitymedium">';
4075 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
4079 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4081 $resteapayeraffiche = 0;
4082 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4086 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4087 $text = $langs->trans(
"HelpAbandonOther");
4089 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
4091 print
'<span class="opacitymedium">';
4093 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
4097 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4099 $resteapayeraffiche = 0;
4100 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4104 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4105 print
'<span class="opacitymedium">';
4106 print $langs->trans(
"Billed");
4110 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
4114 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4115 print
'<span class="opacitymedium">';
4116 print $langs->trans(
'RemainderToPay');
4117 if ($resteapayeraffiche < 0) {
4118 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4123 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
4128 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4129 print
'<span class="opacitymedium">';
4130 print $langs->trans(
'RemainderToPayMulticurrency');
4131 if ($resteapayeraffiche < 0) {
4132 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4137 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price(
price2num($multicurrency_resteapayer,
'MT'), 0, $langs, 1, -1, -1,
$object->multicurrency_code).
'</td>';
4141 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4144 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4145 print $langs->trans(
'AlreadyPaidBack');
4148 print
'<td class="right">'.price($sign * $totalpaid).
'</td>';
4152 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">'.$langs->trans(
"Billed").
'</td>';
4154 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
4158 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4159 print
'<span class="opacitymedium">';
4160 print $langs->trans(
'RemainderToPayBack');
4161 if ($resteapayeraffiche > 0) {
4162 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4167 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
4172 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4173 print
'<span class="opacitymedium">';
4174 print $langs->trans(
'RemainderToPayBackMulticurrency');
4175 if ($resteapayeraffiche > 0) {
4176 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4181 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>';
4197 print
'<div class="clearboth"></div><br>';
4200 $blocname =
'contacts';
4201 $title = $langs->trans(
'ContactsAddresses');
4202 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4207 $blocname =
'notes';
4208 $title = $langs->trans(
'Notes');
4209 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4216 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
4217 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4218 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
4219 print
'<input type="hidden" name="mode" value="">';
4220 print
'<input type="hidden" name="page_y" value="">';
4221 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
4222 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
4223 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4227 include DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_ajaxrow.tpl.php';
4229 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
4233 print
'<div class="div-table-responsive-no-min">';
4234 print
'<table id="tablelines" class="noborder noshadow centpercent">';
4236 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
4239 $inputalsopricewithtax = 1;
4240 $senderissupplier = 2;
4241 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY')) {
4242 $senderissupplier =
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY');
4247 $object->printObjectLines($action, $societe,
$mysoc, $lineid, 1);
4254 if ($action !=
'editline') {
4257 $parameters = array();
4258 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
4262 if (empty($reshook)) {
4276 if ($action !=
'presend') {
4279 print
'<div class="tabsAction">';
4281 $parameters = array();
4282 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
4284 if (empty($reshook)) {
4287 $langs->load(
'subtotals');
4289 $url_button = array();
4291 $url_button[] = array(
4292 'lang' =>
'subtotals',
4294 'perm' => (
bool) $usercancreate,
4295 'label' => $langs->trans(
'AddTitleLine'),
4296 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_title_line'],
true)
4299 $url_button[] = array(
4300 'lang' =>
'subtotals',
4302 'perm' => (
bool) $usercancreate,
4303 'label' => $langs->trans(
'AddSubtotalLine'),
4304 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_subtotal_line'],
true)
4307 print
dolGetButtonAction(
'', $langs->trans(
'SubTotal'),
'default', $url_button,
'',
true);
4312 $ventilExportCompta =
$object->getVentilExportCompta();
4314 if ($ventilExportCompta == 0) {
4315 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=edit&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
4317 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
4322 $result = $discount->fetch(0, 0,
$object->id);
4329 if (!$objectidnext &&
$object->close_code !=
'replaced' && $usercancreate) {
4330 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
4332 if ($usercancreate) {
4333 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
4335 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
4345 if ($usercanvalidate) {
4346 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken().
'"';
4347 print
'>'.$langs->trans(
'Validate').
'</a>';
4349 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
4350 print
'>'.$langs->trans(
'Validate').
'</a>';
4356 if (empty($user->socid)) {
4359 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' =>
$object->id,
'action' =>
'presend',
'mode' =>
'init'],
true).
'#formmailbeforetitle',
'');
4368 $langs->load(
"withdrawals");
4369 if ($resteapayer > 0) {
4370 if ($usercancreatecreditransfer) {
4371 if (!$objectidnext &&
$object->close_code !=
'replaced') {
4372 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>';
4374 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeBankTransferOrder').
'</span>';
4386 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>';
4393 if ($resteapayer == 0) {
4394 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
4395 } elseif ($usercancreate) {
4396 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>';
4402 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
4406 && (
getDolGlobalString(
'SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') ||
$object->getSommePaiement() == 0)
4408 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>';
4412 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
4423 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaid').
'</a>';
4428 if ($totalpaid > 0 || $totalcreditnotes > 0) {
4430 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
4433 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=canceled&token='.
newToken().
'">'.$langs->trans(
'ClassifyCanceled').
'</a>';
4445 if (!$objectidnext) {
4446 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>';
4451 if ($action !=
'edit' && $usercancreate) {
4452 print
'<a class="butAction butActionClone" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=clone&socid='.
$object->socid.
'&token='.
newToken().
'">'.$langs->trans(
'ToClone').
'</a>';
4457 if (!$objectidnext && count(
$object->lines) > 0) {
4458 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.
$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
4463 if ($action !=
'confirm_edit' && $usercandelete) {
4464 $isErasable =
$object->is_erasable();
4466 $enableDelete =
false;
4468 $params = (empty(
$conf->use_javascript_ajax) ? array() : array(
'attr' => array(
'class' =>
'reposition')));
4470 if ($isErasable == -4) {
4471 $htmltooltip = $langs->trans(
"DisabledBecausePayments");
4472 } elseif ($isErasable == -3) {
4473 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastSituationInvoice");
4474 } elseif ($isErasable == -2) {
4475 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastInvoice");
4476 } elseif ($isErasable == -1) {
4477 $htmltooltip = $langs->trans(
"DisabledBecauseDispatchedInBookkeeping");
4478 } elseif ($isErasable <= 0) {
4479 $htmltooltip = $langs->trans(
"DisabledBecauseNotErasable");
4481 $enableDelete =
true;
4484 print
dolGetButtonAction($htmltooltip, $langs->trans(
"Delete"),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken(), (
string)
$object->id, $enableDelete, $params);
4488 if ($action !=
'confirm_edit') {
4489 print
'<div class="fichecenter"><div class="fichehalfleft">';
4495 $subdir =
get_exdir(
$object->id, 2, 0, 0, $object,
'invoice_supplier').$ref;
4497 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.
$object->id;
4498 $genallowed = $usercanread;
4499 $delallowed = $usercancreate;
4503 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, (
int) $genallowed, (
int) $delallowed, $modelpdf, $genifempty, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
4504 $somethingshown = $formfile->numoffiles;
4507 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice_supplier'), 1);
4508 $linktoelem = $tmparray[
'linktoelem'];
4509 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
4510 print $htmltoenteralink;
4512 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
4514 print
'</div><div class="fichehalfright">';
4517 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
4519 $somethingshown = $formactions->showactions($object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
4521 print
'</div></div>';
4527 if (
GETPOST(
'modelselected')) {
4528 $action =
'presend';
4532 $modelmail =
'invoice_supplier_send';
4533 $defaulttopic =
'SendBillRef';
4535 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
4536 $trackid =
'sinv'.$object->id;
4538 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.