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);
121 $ret =
$object->fetch_thirdparty();
129if (!empty($user->socid)) {
130 $socid = $user->socid;
134$result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture',
'fk_soc',
'rowid', $isdraft);
137$usercanread = ($user->hasRight(
"fournisseur",
"facture",
"lire") || $user->hasRight(
"supplier_invoice",
"lire"));
138$usercancreate = ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"));
139$usercandelete = (($user->hasRight(
"fournisseur",
"facture",
"supprimer") || $user->hasRight(
"supplier_invoice",
"supprimer")) || ($usercancreate &&
$object->is_erasable() == 1));
140$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
143$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"validate")));
144$usercansend = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"send"));
145$usercancreatecreditransfer = $user->hasRight(
'paymentbybanktransfer',
'create');
148$permissionnote = $usercancreate;
149$permissiondellink = $usercancreate;
150$permissiontoedit = $usercancreate;
151$permissiontoadd = $usercancreate;
152$permissiontodelete = $usercandelete;
153$permissiontoeditextra = $permissiontoadd;
154if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
156 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
167$parameters = array(
'socid' => $socid);
168$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
173if (empty($reshook)) {
174 $backurlforlist =
dolBuildUrl(DOL_URL_ROOT.
'/fourn/facture/list.php');
176 if (empty($backtopage) || ($cancel && empty($id))) {
177 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
178 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
179 $backtopage = $backurlforlist;
181 $backtopage =
dolBuildUrl(DOL_URL_ROOT.
'/fourn/facture/card.php', [
'id' => ((!empty($id) && $id > 0) ? $id :
'__ID__')]);
187 if (!empty($backtopageforcancel)) {
188 header(
"Location: ".$backtopageforcancel);
190 } elseif (!empty($backtopage)) {
191 header(
"Location: ".$backtopage);
197 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
199 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
201 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
204 if (
GETPOST(
'linkedOrder') && empty($cancel) && $id > 0 && $permissiontoadd) {
207 $result =
$object->add_object_linked(
'order_supplier',
GETPOSTINT(
'linkedOrder'));
211 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
213 '@phan-var-force FactureFournisseur $objectutil';
215 if (
GETPOST(
'newsupplierref',
'alphanohtml')) {
216 $objectutil->ref_supplier =
GETPOST(
'newsupplierref',
'alphanohtml');
220 $result = $objectutil->createFromClone($user, $id);
222 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
225 $langs->load(
"errors");
229 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
230 $idwarehouse =
GETPOST(
'idwarehouse');
235 $qualified_for_stock_change = 0;
237 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
239 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
244 $langs->load(
"stocks");
245 if (!$idwarehouse || $idwarehouse == -1) {
247 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
255 $result =
$object->validate($user,
'', $idwarehouse);
262 $categories =
GETPOST(
'categories',
'array:int');
263 if (method_exists($object,
'setCategories')) {
264 $object->setCategories($categories);
272 $outputlangs = $langs;
275 $newlang =
GETPOST(
'lang_id',
'aZ09');
278 $newlang =
$object->thirdparty->default_lang;
280 if (!empty($newlang)) {
282 $outputlangs->setDefaultLang($newlang);
287 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
294 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $permissiontodelete) {
298 $isErasable =
$object->is_erasable();
300 if ($usercandelete && $isErasable > 0) {
301 $revertstock =
GETPOST(
'revertstock');
306 $qualified_for_stock_change = 0;
308 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
310 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
315 $langs->load(
"stocks");
316 if (!$idwarehouse || $idwarehouse == -1) {
318 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
321 $result =
$object->setDraft($user, $idwarehouse);
330 $result =
$object->delete($user);
332 header(
'Location: list.php?restore_lastsearch_values=1');
339 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
341 $result =
$object->deleteLine($lineid);
361 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
368 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
371 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
372 $discount->unlink_invoice();
373 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercancreate) {
375 $result =
$object->setPaid($user);
379 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercancreate) {
382 $close_code =
GETPOST(
"close_code",
'restricthtml');
383 $close_note =
GETPOST(
"close_note",
'restricthtml');
385 $result =
$object->setPaid($user, $close_code, $close_note);
390 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
392 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
395 $close_code =
GETPOST(
"close_code",
'restricthtml');
396 $close_note =
GETPOST(
"close_note",
'restricthtml');
398 $result =
$object->setCanceled($user, $close_code, $close_note);
403 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
408 if ($action ==
'setref_supplier' && $usercancreate) {
411 if (
$object->update($user) < 0) {
415 $outputlangs = $langs;
418 $newlang =
GETPOST(
'lang_id',
'aZ09');
421 $newlang =
$object->thirdparty->default_lang;
423 if (!empty($newlang)) {
425 $outputlangs->setDefaultLang($newlang);
429 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
435 if ($action ==
'setconditions' && $usercancreate) {
437 $object->cond_reglement_code = 0;
438 $object->cond_reglement_id = 0;
453 $new_date_echeance =
$object->calculate_date_lim_reglement();
454 if ($new_date_echeance) {
455 $object->date_echeance = $new_date_echeance;
460 $result =
$object->update($user);
472 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
475 } elseif ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
478 } elseif ($action ==
'setmode' && $usercancreate) {
481 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
483 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
484 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
487 } elseif ($action ==
'setbankaccount' && $usercancreate) {
490 } elseif ($action ==
'setvatreversecharge' && $usercancreate) {
492 $vatreversecharge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
493 $result =
$object->setVATReverseCharge($vatreversecharge);
496 if ($action ==
'settransportmode' && $usercancreate) {
499 } elseif ($action ==
'setlabel' && $usercancreate) {
503 $result =
$object->update($user);
507 } elseif ($action ==
'setdatef' && $usercancreate) {
511 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
513 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
520 $date_echence_calc =
$object->calculate_date_lim_reglement();
521 if (!empty(
$object->date_echeance)) {
522 $object->date_echeance = $date_echence_calc;
528 $result =
$object->update($user);
532 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
536 $object->date_pointoftax = $date_pointoftax;
538 $result =
$object->update($user);
541 $action =
'editdate_pointoftax';
543 } elseif ($action ==
'setdate_lim_reglement' && $usercancreate) {
548 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
550 $result =
$object->update($user);
554 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
570 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
572 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
576 $remaintopay =
$object->getRemainToPay(0);
580 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
584 $result = $discount->link_to_invoice(0, $id);
591 $newremaintopay =
$object->getRemainToPay(0);
592 if ($newremaintopay == 0) {
603 $outputlangs = $langs;
606 $newlang =
GETPOST(
'lang_id',
'aZ09');
609 $newlang =
$object->thirdparty->default_lang;
611 if (!empty($newlang)) {
613 $outputlangs->setDefaultLang($newlang);
617 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
622 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
630 $result = $discountcheck->fetch(0, 0,
$object->id);
642 $amount_ht = $amount_tva = $amount_ttc = array();
643 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
647 foreach (
$object->lines as $line) {
648 if ($line->product_type < 9 && $line->total_ht != 0) {
649 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
651 $amount_ht[$keyforvatrate] += $line->total_ht;
652 $amount_tva[$keyforvatrate] += $line->total_tva;
653 $amount_ttc[$keyforvatrate] += $line->total_ttc;
654 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
655 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
656 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
660 '@phan-var-force array<string,float> $amount_ht
661 @phan-var-force array<string,float> $amount_tva
662 @phan-var-force array<string,float> $amount_ttc
663 @phan-var-force array<string,float> $multicurrency_amount_ht
664 @phan-var-force array<string,float> $multicurrency_amount_tva
665 @phan-var-force array<string,float> $multicurrency_amount_ttc';
669 $alreadypaid =
$object->getSommePaiement();
670 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
671 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
672 foreach ($amount_ht as $vatrate => $val) {
673 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
674 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
675 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
676 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
677 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
678 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
687 $discount->description =
'(CREDIT_NOTE)';
689 $discount->description =
'(DEPOSIT)';
691 $discount->description =
'(EXCESS PAID)';
693 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
695 $discount->discount_type = 1;
696 $discount->fk_soc =
$object->socid;
697 $discount->socid =
$object->socid;
698 $discount->fk_invoice_supplier_source =
$object->id;
706 $sql =
'SELECT SUM(pf.amount) as total_paiements';
707 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'paiementfourn as p';
708 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN ('.
getEntity(
'c_paiement').
')';
709 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
710 $sql .=
' AND pf.fk_paiementfourn = p.rowid';
711 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
713 $resql =
$db->query($sql);
718 $res =
$db->fetch_object($resql);
719 $total_paiements = $res->total_paiements;
722 $total_creditnote_and_deposit = 0;
723 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
724 $sql .=
" re.description, re.fk_invoice_supplier_source";
725 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
726 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
727 $resql =
$db->query($sql);
728 if (!empty($resql)) {
729 while ($obj =
$db->fetch_object($resql)) {
730 $total_creditnote_and_deposit += $obj->amount_ttc;
736 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
737 $discount->amount_tva = 0;
738 $discount->tva_tx = 0;
739 $discount->vat_src_code =
'';
742 $discount->multicurrency_code =
$object->multicurrency_code;
743 $discount->multicurrency_tx =
$object->multicurrency_tx;
744 $discount->multicurrency_total_ht = $discount->multicurrency_total_ttc = (float)
price2num((
float) $discount->amount_ttc * (float)
$object->multicurrency_tx,
'MT');
745 $discount->multicurrency_total_tva = 0;
747 $discount->multicurrency_amount_ht = $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
748 $discount->multicurrency_amount_tva = 0;
750 $result = $discount->create($user);
756 foreach ($amount_ht as $tva_tx => $xxx) {
757 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
758 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
759 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
761 $discount->multicurrency_code =
$object->multicurrency_code;
762 $discount->multicurrency_tx =
$object->multicurrency_tx;
763 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
764 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
765 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
767 $discount->multicurrency_amount_ht = abs((
float) $discount->multicurrency_total_ht);
768 $discount->multicurrency_amount_tva = abs((
float) $discount->multicurrency_total_tva);
769 $discount->multicurrency_amount_ttc = abs((
float) $discount->multicurrency_total_ttc);
774 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
775 $vat_src_code = $reg[1];
776 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
779 $discount->tva_tx = abs((
float) $tva_tx);
780 $discount->vat_src_code = $vat_src_code;
782 $result = $discount->create($user);
793 $result =
$object->setPaid($user);
808 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate) {
813 $result = $paiementfourn->fetch(
GETPOSTINT(
'paiement_id'));
815 $result = $paiementfourn->delete($user);
817 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
825 } elseif ($action ==
'add' && $usercancreate) {
830 $selectedLines =
GETPOST(
'toselect',
'array:int');
838 $ret = $extrafields->setOptionalsFromPost(
null, $object);
852 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
857 if (empty($dateinvoice)) {
858 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
870 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
884 $object->date_pointoftax = $date_pointoftax;
885 $object->date_echeance = $datedue;
891 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
892 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
894 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
895 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
916 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
919 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
924 if (empty($dateinvoice)) {
925 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
935 if (!
GETPOST(
'ref_supplier')) {
936 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
944 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
959 $object->date_pointoftax = $date_pointoftax;
960 $object->date_echeance = $datedue;
966 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
967 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
969 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
970 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
975 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
984 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
986 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
989 foreach ($facture_source->lines as $line) {
991 if (method_exists($line,
'fetch_optionals')) {
992 $line->fetch_optionals();
996 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1000 $line->fk_facture_fourn =
$object->id;
1001 $line->fk_parent_line = $fk_parent_line;
1003 $line->subprice = -$line->subprice;
1004 $line->pa_ht = -((float) $line->pa_ht);
1005 $line->total_ht = -$line->total_ht;
1006 $line->total_tva = -$line->total_tva;
1007 $line->total_ttc = -$line->total_ttc;
1008 $line->total_localtax1 = -$line->total_localtax1;
1009 $line->total_localtax2 = -$line->total_localtax2;
1010 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1011 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1012 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1014 $result = $line->insert();
1019 if ($result > 0 && $line->product_type == 9) {
1020 $fk_parent_line = $result;
1028 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 &&
$id > 0) {
1030 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1031 $totalpaid = $facture_source->getSommePaiement();
1032 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1033 $totaldeposits = $facture_source->getSumDepositsUsed();
1034 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1035 $desc = $langs->trans(
'invoiceAvoirLineWithPaymentRestAmount');
1038 $retAddLine =
$object->addline($desc, -$remain_to_pay, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
'TTC');
1040 if ($retAddLine < 0) {
1047 if (!empty(
$object->fk_facture_source) && $id > 0) {
1049 if ($facture_source_link->fetch(
$object->fk_facture_source) > 0) {
1050 $facture_source_link->fetchObjectLinked();
1051 if (!empty($facture_source_link->linkedObjectsIds)) {
1052 foreach ($facture_source_link->linkedObjectsIds as $sourcetype => $TIds) {
1053 $object->add_object_linked($sourcetype, current($TIds));
1061 if (empty($dateinvoice)) {
1063 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1073 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1083 $object->date_pointoftax = $date_pointoftax;
1084 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1085 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1094 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1095 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1099 $object->fac_rec = $fac_recid;
1101 $fac_rec->fetch(
$object->fac_rec);
1102 $fac_rec->fetch_lines();
1103 $object->lines = $fac_rec->lines;
1110 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1115 if (empty($dateinvoice)) {
1116 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1126 if (!
GETPOST(
'ref_supplier')) {
1127 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
1135 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1152 $object->date_pointoftax = $date_pointoftax;
1153 $object->date_echeance = $datedue;
1159 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1160 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1162 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1163 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1168 if (empty(
$object->date_echeance)) {
1169 $object->date_echeance =
$object->calculate_date_lim_reglement();
1175 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
1177 $element = $subelement =
GETPOST(
'origin',
'alpha');
1185 if ($element ==
'order') {
1186 $element = $subelement =
'commande';
1188 if ($element ==
'propal') {
1189 $element =
'comm/propal';
1190 $subelement =
'propal';
1192 if ($element ==
'contract') {
1193 $element = $subelement =
'contrat';
1195 if ($element ==
'order_supplier') {
1197 $subelement =
'fournisseur.commande';
1199 if ($element ==
'project') {
1200 $element =
'projet';
1208 $classname = ucfirst($subelement);
1209 if ($classname ==
'Fournisseur.commande') {
1210 $classname =
'CommandeFournisseur';
1212 $objectsrc =
new $classname(
$db);
1213 $objectsrc->fetch($originid);
1214 $objectsrc->fetch_thirdparty();
1216 if (!empty(
$object->origin_type) && !empty(
$object->origin_id)) {
1221 if (
$object->origin_type ==
'reception') {
1222 $objectsrc->fetchObjectLinked();
1224 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1225 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1226 $object->linkedObjectsIds[
'order_supplier'][-1] = $value;
1236 $classname = ucfirst($subelement);
1237 if ($classname ==
'Fournisseur.commande') {
1238 $classname =
'CommandeFournisseur';
1240 $srcobject =
new $classname(
$db);
1242 $result = $srcobject->fetch(
GETPOSTINT(
'originid'));
1245 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1250 $amountdeposit = array();
1252 if ($typeamount ==
'amount') {
1253 $amount = $valuedeposit;
1255 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1258 $TTotalByTva = array();
1259 foreach ($srcobject->lines as &$line) {
1260 if (!empty($line->special_code)) {
1263 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1265 '@phan-var-force array<string,float> $TTotalByTva';
1267 $amount_ttc_diff = 0.;
1268 foreach ($TTotalByTva as $tva => &$total) {
1269 $coef = $total / $srcobject->total_ttc;
1270 $am = $amount * $coef;
1271 $amount_ttc_diff += $am;
1272 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1275 if ($typeamount ==
'amount') {
1276 $amountdeposit[0] = $valuedeposit;
1277 } elseif ($typeamount ==
'variable') {
1280 $lines = $srcobject->lines;
1281 $numlines = count($lines);
1282 for ($i = 0; $i < $numlines; $i++) {
1284 if (empty($lines[$i]->qty)) {
1287 if (!empty($lines[$i]->special_code)) {
1291 $totalamount += $lines[$i]->total_ht;
1292 $tva_tx = $lines[$i]->tva_tx;
1293 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1297 if ($totalamount == 0) {
1298 $amountdeposit[0] = 0;
1303 $amountdeposit[0] = 0;
1307 $amount_ttc_diff = array_key_exists(0, $amountdeposit) ? $amountdeposit[0] : 0;
1310 foreach ($amountdeposit as $tva => $amount) {
1311 if (empty($amount)) {
1316 'amount' =>
'FixAmount',
1317 'variable' =>
'VarAmount'
1319 $descline =
'(DEPOSIT)';
1321 if ($typeamount ==
'amount') {
1322 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1323 } elseif ($typeamount ==
'variable') {
1324 $descline .=
' ('.$valuedeposit.
'%)';
1327 $descline .=
' - '.$srcobject->ref;
1357 $diff =
$object->total_ttc - $amount_ttc_diff;
1361 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1367 $object->lines[0]->localtax1_tx,
1368 $object->lines[0]->localtax2_tx,
1370 $object->lines[0]->fk_product,
1373 $object->lines[0]->product_type,
1374 $object->lines[0]->remise_percent,
1376 $object->lines[0]->date_start,
1385 } elseif ($result > 0) {
1386 $lines = $srcobject->lines;
1387 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1388 $srcobject->fetch_lines();
1389 $lines = $srcobject->lines;
1392 $num = count($lines);
1393 for ($i = 0; $i < $num; $i++) {
1394 if (!in_array($lines[$i]->
id, $selectedLines)) {
1398 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->product_label);
1399 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1402 if (method_exists($lines[$i],
'fetch_optionals')) {
1403 $lines[$i]->fetch_optionals();
1409 if ($lines[$i]->date_debut_reel) {
1412 if ($lines[$i]->date_start) {
1415 $date_end = $lines[$i]->date_fin_prevue;
1416 if ($lines[$i]->date_fin_reel) {
1417 $date_end = $lines[$i]->date_fin_reel;
1419 if ($lines[$i]->date_end) {
1420 $date_end = $lines[$i]->date_end;
1423 $tva_tx = $lines[$i]->tva_tx;
1425 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
1426 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1430 $object->special_code = $lines[$i]->special_code;
1435 $pu_currency = $lines[$i]->multicurrency_subprice;
1437 $pu = $lines[$i]->subprice;
1446 $lines[$i]->localtax1_tx,
1447 $lines[$i]->localtax2_tx,
1449 $lines[$i]->fk_product,
1450 $lines[$i]->remise_percent,
1454 $lines[$i]->info_bits,
1459 $lines[$i]->array_options,
1460 $lines[$i]->fk_unit,
1463 $lines[$i]->ref_supplier,
1464 $lines[$i]->special_code
1481 $parameters = array(
'objFrom' => $srcobject);
1482 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1492 } elseif (!$error) {
1502 $langs->load(
"errors");
1512 $outputlangs = $langs;
1513 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1520 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1523 } elseif ($action ==
'updateline' && $usercancreate) {
1527 if (!
$object->fetch($id) > 0) {
1533 $tva_tx = str_replace(
'*',
'', $tva_tx);
1535 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_subprice') !=
'') {
1537 $price_base_type =
'HT';
1540 $price_base_type =
'TTC';
1543 if (
GETPOST(
'productid') > 0) {
1545 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY') == 1) {
1547 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1553 $label =
$prod->description;
1554 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1555 $label =
GETPOST(
'product_desc',
'restricthtml');
1558 $type =
$prod->type;
1560 $label =
GETPOST(
'product_desc',
'restricthtml');
1569 if (preg_match(
'/\*/', $tva_tx)) {
1574 $tva_tx = str_replace(
'*',
'', $tva_tx);
1582 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1583 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1585 if (is_array($extralabelsline)) {
1586 foreach ($extralabelsline as $key => $value) {
1587 unset($_POST[
"options_".$key]);
1591 $result =
$object->updateline(
1603 (
float) $remise_percent,
1613 unset($_POST[
'label']);
1614 unset($_POST[
'fourn_ref']);
1615 unset($_POST[
'date_starthour']);
1616 unset($_POST[
'date_startmin']);
1617 unset($_POST[
'date_startsec']);
1618 unset($_POST[
'date_startday']);
1619 unset($_POST[
'date_startmonth']);
1620 unset($_POST[
'date_startyear']);
1621 unset($_POST[
'date_endhour']);
1622 unset($_POST[
'date_endmin']);
1623 unset($_POST[
'date_endsec']);
1624 unset($_POST[
'date_endday']);
1625 unset($_POST[
'date_endmonth']);
1626 unset($_POST[
'date_endyear']);
1627 unset($_POST[
'price_ttc']);
1628 unset($_POST[
'price_ht']);
1635 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
1639 foreach (
$object->lines as $line) {
1640 if ($line->product_type == 1) {
1641 $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);
1644 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
1646 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
1647 $remise_percent = (float) str_replace(
'*',
'', $remise_percent);
1648 foreach (
$object->lines as $line) {
1649 $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);
1651 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !=
'' && $usercancreate) {
1653 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1654 $vat_rate = str_replace(
'*',
'', $vat_rate);
1657 foreach (
$object->lines as $line) {
1658 $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);
1660 } elseif ($action ==
'addline' && $usercancreate) {
1669 $ret =
$object->fetch_thirdparty();
1671 $langs->load(
'errors');
1680 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1681 if ($prod_entry_mode ==
'free') {
1688 $price_ht_devise =
'';
1690 $price_ttc_devise =
'';
1692 if (
GETPOST(
'price_ht') !==
'') {
1695 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
1698 if (
GETPOST(
'price_ttc') !==
'') {
1701 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
1702 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
1710 if (empty($remise_percent)) {
1711 $remise_percent = 0;
1715 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1716 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
1718 if (is_array($extralabelsline)) {
1720 foreach ($extralabelsline as $key => $value) {
1721 unset($_POST[
"options_".$key]);
1725 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
1726 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1729 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOSTINT(
'type') < 0) {
1730 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
1735 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1')
1736 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
1737 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
1738 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
1739 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
1740 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
1741 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) {
1742 $langs->load(
"errors");
1743 if (
$object->type == $object::TYPE_DEPOSIT) {
1745 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
1747 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPrice"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
1752 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
1753 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
1757 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') && !
GETPOST(
'dp_desc')) {
1758 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
1761 if (!
GETPOST(
'qty',
'alpha')) {
1762 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1766 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
1767 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
1771 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1772 $idprod = $res->fk_product_child;
1774 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
1780 if ($prod_entry_mode !=
'free' && empty($error)) {
1784 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
1789 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
1790 $idprod = (int) $reg[1];
1791 $res = $productsupplier->fetch($idprod);
1794 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
1796 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1797 if ($productsupplier->fourn_socid != $socid) {
1798 $productsupplier->ref_supplier =
'';
1801 $fksoctosearch =
$object->thirdparty->id;
1802 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1804 } elseif (
GETPOSTINT(
'idprodfournprice') > 0) {
1805 $qtytosearch = (float) $qty;
1807 $idprod = $productsupplier->get_buyprice(
GETPOSTINT(
'idprodfournprice'), $qtytosearch);
1808 $res = $productsupplier->fetch($idprod);
1812 $label = $productsupplier->label;
1815 $outputlangs = $langs;
1817 if (
GETPOST(
'lang_id',
'aZ09')) {
1818 $newlang =
GETPOST(
'lang_id',
'aZ09');
1820 if (empty($newlang)) {
1821 $newlang =
$object->thirdparty->default_lang;
1823 if (!empty($newlang)) {
1825 $outputlangs->setDefaultLang($newlang);
1827 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
1829 $desc = $productsupplier->description;
1832 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
1833 $desc = $productsupplier->desc_supplier;
1844 $ref_supplier = $productsupplier->ref_supplier;
1848 $tmpidprodfournprice =
GETPOST(
'idprodfournprice',
'alpha');
1849 if (is_numeric($tmpidprodfournprice) && (
int) $tmpidprodfournprice > 0) {
1850 $tmpidprodfournprice = (int) $tmpidprodfournprice;
1852 $tmpidprodfournprice = 0;
1858 if (empty($tva_tx) || empty($tva_npr)) {
1864 $type = $productsupplier->type;
1865 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1866 $price_base_type =
'HT';
1868 $pu_devise =
price2num($price_ht_devise,
'CU');
1869 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
1870 $price_base_type =
'TTC';
1872 $pu_devise =
price2num($price_ttc_devise,
'CU');
1874 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
1875 if (empty(
$object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code !=
$object->multicurrency_code)) {
1876 $pu = $productsupplier->fourn_pu;
1879 $pu = $productsupplier->fourn_pu;
1880 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
1884 $ref_supplier = $productsupplier->ref_supplier;
1905 min($rank, count(
$object->lines) + 1),
1908 $productsupplier->fk_unit,
1911 GETPOST(
'fourn_ref',
'alpha'),
1915 if ($idprod == -99 || $idprod == 0) {
1918 $langs->load(
"errors");
1919 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
1921 if ($idprod == -1) {
1924 $langs->load(
"errors");
1925 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
1927 } elseif (empty($error)) {
1928 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1929 $tva_tx = str_replace(
'*',
'', $tva_tx);
1930 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1933 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
1937 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1945 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1949 $pu_ht =
price2num((
float) $pu_ttc / (1 + ((
float) $tva_tx / 100)),
'MU');
1951 $price_base_type =
'HT';
1952 $pu_devise =
price2num($price_ht_devise,
'CU');
1954 $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);
1958 if (!$error && $result > 0) {
1963 $outputlangs = $langs;
1966 $newlang =
GETPOST(
'lang_id',
'aZ09');
1969 $newlang =
$object->thirdparty->default_lang;
1971 if (!empty($newlang)) {
1973 $outputlangs->setDefaultLang($newlang);
1978 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1984 unset($_POST [
'prod_entry_mode']);
1986 unset($_POST[
'qty']);
1987 unset($_POST[
'type']);
1988 unset($_POST[
'remise_percent']);
1989 unset($_POST[
'pu']);
1990 unset($_POST[
'price_ht']);
1991 unset($_POST[
'multicurrency_price_ht']);
1992 unset($_POST[
'price_ttc']);
1993 unset($_POST[
'fourn_ref']);
1994 unset($_POST[
'tva_tx']);
1995 unset($_POST[
'label']);
1996 unset($localtax1_tx);
1997 unset($localtax2_tx);
1998 unset($_POST[
'np_marginRate']);
1999 unset($_POST[
'np_markRate']);
2000 unset($_POST[
'dp_desc']);
2001 unset($_POST[
'idprodfournprice']);
2002 unset($_POST[
'units']);
2004 unset($_POST[
'date_starthour']);
2005 unset($_POST[
'date_startmin']);
2006 unset($_POST[
'date_startsec']);
2007 unset($_POST[
'date_startday']);
2008 unset($_POST[
'date_startmonth']);
2009 unset($_POST[
'date_startyear']);
2010 unset($_POST[
'date_endhour']);
2011 unset($_POST[
'date_endmin']);
2012 unset($_POST[
'date_endsec']);
2013 unset($_POST[
'date_endday']);
2014 unset($_POST[
'date_endmonth']);
2015 unset($_POST[
'date_endyear']);
2022 } elseif ($action ==
'classin' && $usercancreate) {
2024 $result =
$object->setProject($projectid);
2025 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
2029 $totalpaid =
$object->getSommePaiement();
2030 $resteapayer =
$object->total_ttc - $totalpaid;
2033 $ventilExportCompta =
$object->getVentilExportCompta();
2035 if (!$ventilExportCompta) {
2038 $idwarehouse =
GETPOST(
'idwarehouse');
2042 $qualified_for_stock_change = 0;
2044 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2046 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2051 $langs->load(
"stocks");
2052 if (!$idwarehouse || $idwarehouse == -1) {
2054 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
2059 $object->setDraft($user, $idwarehouse);
2063 $outputlangs = $langs;
2066 $newlang =
GETPOST(
'lang_id',
'aZ09');
2069 $newlang =
$object->thirdparty->default_lang;
2071 if (!empty($newlang)) {
2073 $outputlangs->setDefaultLang($newlang);
2078 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2087 } elseif ($action ==
'reopen' && $usercancreate) {
2089 $result =
$object->fetch($id);
2092 $result =
$object->setUnpaid($user);
2094 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
2103 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2106 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
2108 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
2109 $trackid =
'sinv'.$object->id;
2110 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2114 $permissiontoadd = $usercancreate;
2115 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2118 if ($action ==
'calculate' && $usercancreate) {
2119 $calculationrule =
GETPOST(
'calculationrule');
2123 $result =
$object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0,
$object->thirdparty);
2129 if ($action ==
'update_extras' && $permissiontoeditextra) {
2132 $attribute_name =
GETPOST(
'attribute',
'aZ09');
2135 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
2141 $result =
$object->updateExtraField($attribute_name,
'BILL_SUPPLIER_MODIFY');
2149 $action =
'edit_extras';
2154 if ($action ==
'addcontact' && $usercancreate) {
2155 $result =
$object->fetch($id);
2157 if ($result > 0 && $id > 0) {
2160 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2164 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2167 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2168 $langs->load(
"errors");
2169 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2174 } elseif ($action ==
'swapstatut' && $usercancreate) {
2181 } elseif ($action ==
'deletecontact' && $usercancreate) {
2187 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2211$title =
$object->ref.
" - ".$langs->trans(
'Card');
2212if ($action ==
'create') {
2213 $title = $langs->trans(
"NewSupplierInvoice");
2215$help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
2216llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-fourn-facture page-card');
2219if ($action ==
'create') {
2221 $selectedLines = array();
2223 print
load_fiche_titre($langs->trans(
'NewSupplierInvoice'),
'',
'supplier_invoice');
2227 $currency_code =
$conf->currency;
2228 $vat_reverse_charge = 0;
2234 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2235 $currency_code = $societe->multicurrency_code;
2240 if (!empty($origin) && !empty($originid)) {
2242 $element = $subelement = $origin;
2244 if ($element ==
'project') {
2245 $projectid = $originid;
2246 $element =
'projet';
2250 if ($element ==
'order') {
2251 $element = $subelement =
'commande';
2253 if ($element ==
'propal') {
2254 $element =
'comm/propal';
2255 $subelement =
'propal';
2257 if ($element ==
'contract') {
2258 $element = $subelement =
'contrat';
2260 if ($element ==
'order_supplier') {
2262 $subelement =
'fournisseur.commande';
2266 $classname = ucfirst($subelement);
2267 if ($classname ==
'Fournisseur.commande') {
2268 $classname =
'CommandeFournisseur';
2270 $objectsrc =
new $classname(
$db);
2271 '@phan-var-force Project|Commande|Propal|Facture|Contrat|CommandeFournisseur|CommonObject $objectsrc';
2273 $objectsrc->fetch($originid);
2274 $objectsrc->fetch_thirdparty();
2276 $projectid = (int) $objectsrc->fk_project;
2278 $soc = $objectsrc->thirdparty;
2280 $cond_reglement_id = 0;
2281 $mode_reglement_id = 0;
2283 $transport_mode_id = 0;
2286 if (!empty($objectsrc->cond_reglement_id)) {
2287 $cond_reglement_id = $objectsrc->cond_reglement_id;
2289 if (!empty($objectsrc->mode_reglement_id)) {
2290 $mode_reglement_id = $objectsrc->mode_reglement_id;
2292 if (!empty($objectsrc->fk_account)) {
2293 $fk_account = $objectsrc->fk_account;
2295 if (!empty($objectsrc->transport_mode_id)) {
2296 $transport_mode_id = $objectsrc->transport_mode_id;
2299 if (empty($cond_reglement_id)
2300 || empty($mode_reglement_id)
2301 || empty($fk_account)
2302 || empty($transport_mode_id)
2304 if ($origin ==
'reception') {
2306 if (!isset($objectsrc->supplier_order)) {
2307 $objectsrc->fetch_origin();
2310 if (!empty($objectsrc->origin_object)) {
2311 $originObject = $objectsrc->origin_object;
2312 if (empty($cond_reglement_id) && !empty($originObject->cond_reglement_id)) {
2313 $cond_reglement_id = $originObject->cond_reglement_id;
2315 if (empty($mode_reglement_id) && !empty($originObject->mode_reglement_id)) {
2316 $mode_reglement_id = $originObject->mode_reglement_id;
2318 if (empty($fk_account) && !empty($originObject->fk_account)) {
2319 $fk_account = $originObject->fk_account;
2321 if (empty($transport_mode_id) && !empty($originObject->transport_mode_id)) {
2322 $transport_mode_id = $originObject->transport_mode_id;
2329 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
2330 $cond_reglement_id = $soc->cond_reglement_supplier_id;
2332 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
2333 $mode_reglement_id = $soc->mode_reglement_supplier_id;
2335 if (empty($fk_account) && !empty($soc->fk_account)) {
2336 $fk_account = $soc->fk_account;
2338 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
2339 $transport_mode_id = $soc->transport_mode_id;
2345 if (!empty($objectsrc->multicurrency_code)) {
2346 $currency_code = $objectsrc->multicurrency_code;
2348 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
2349 $currency_tx = $objectsrc->multicurrency_tx;
2354 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2356 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2359 $objectsrc->fetch_optionals();
2360 $object->array_options = $objectsrc->array_options;
2362 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2363 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2364 $vat_reverse_charge = (empty($societe) ?
'' : $societe->vat_reverse_charge);
2365 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2366 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2368 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalInt(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2370 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2372 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2373 $currency_code = $societe->multicurrency_code;
2378 if (empty($cond_reglement_id)) {
2379 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2383 if (empty($mode_reglement_id)) {
2384 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2388 if (!
GETPOST(
'changecompany')) {
2390 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
2393 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
2400 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
2401 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
2403 if ($origin ==
'contrat') {
2404 $langs->load(
"admin");
2405 $text = $langs->trans(
"ToCreateARecurringInvoice");
2406 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"SupplierBills"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
2408 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
2410 print
info_admin($text, 0, 0,
'0',
'opacitymedium').
'<br>';
2413 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2414 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2415 print
'<input type="hidden" name="action" value="add">';
2416 print
'<input type="hidden" name="changecompany" value="0">';
2418 if (!empty($societe->id) && $societe->id > 0) {
2419 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2421 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2422 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2423 if (!empty($currency_tx)) {
2424 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2426 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2431 $parameters = array();
2433 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierInvoice', $parameters, $object, $action);
2434 if (empty($reshook)) {
2435 print
'<table class="border centpercent">';
2442 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2443 $invoice_predefined->fetch($fac_recid);
2447 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2450 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2451 $absolute_discount = $societe->getAvailableDiscounts(
null,
'', 0, 1);
2452 print $societe->getNomUrl(1,
'supplier');
2453 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2455 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2456 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');
2459 print
'<script type="text/javascript">
2460 $(document).ready(function() {
2461 $("#socid").change(function() {
2462 console.log("We have changed the company - Reload page");
2464 $("input[name=action]").val("create");
2465 $("input[name=changecompany]").val("1");
2466 $("form[name=add]").submit();
2471 if ($fac_recid <= 0) {
2472 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>';
2478 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2479 $invoice_predefined->fetch($fac_recid);
2481 $dateinvoice = $invoice_predefined->date_when;
2482 if (empty($projectid)) {
2483 $projectid = $invoice_predefined->fk_project;
2485 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2486 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2487 $fk_account = $invoice_predefined->fk_account;
2488 $note_public = $invoice_predefined->note_public;
2489 $note_private = $invoice_predefined->note_private;
2491 if (!empty($invoice_predefined->multicurrency_code)) {
2492 $currency_code = $invoice_predefined->multicurrency_code;
2494 if (!empty($invoice_predefined->multicurrency_tx)) {
2495 $currency_tx = $invoice_predefined->multicurrency_tx;
2498 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2499 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2500 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2502 $resql =
$db->query($sql);
2504 $num =
$db->num_rows($resql);
2508 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2510 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2511 print
'<option value="0" selected></option>';
2513 $objp =
$db->fetch_object($resql);
2514 print
'<option value="'.$objp->rowid.
'"';
2515 if ($fac_recid == $objp->rowid) {
2517 $exampletemplateinvoice->fetch($fac_recid);
2519 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2525 print
'<script type="text/javascript">
2526 $(document).ready(function() {
2527 $("#fac_rec").change(function() {
2528 console.log("We have changed the template invoice - Reload page");
2530 $("input[name=action]").val("create");
2531 $("form[name=add]").submit();
2544 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2546 print
'<div class="tagtable">'.
"\n";
2549 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2550 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
'checked').
'> ';
2551 $desc = $form->textwithpicto($tmp.
'<label for="radio_standard">'.$langs->trans(
"InvoiceStandardAsk").
'</label>', $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2553 print
'</div></div>';
2555 if (empty($origin) || (($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') && !empty($originid))) {
2558 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2559 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOSTINT(
'type') == 3 ?
' checked' :
'') .
'> ';
2560 print
'<script type="text/javascript">
2561 jQuery(document).ready(function() {
2562 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2563 jQuery("#radio_standard").prop("checked", true);
2565 jQuery("#typedeposit, #valuedeposit").click(function() {
2566 jQuery("#radio_deposit").prop("checked", true);
2568 jQuery("#typedeposit").change(function() {
2569 console.log("We change type of down payment");
2570 jQuery("#radio_deposit").prop("checked", true);
2571 setRadioForTypeOfInvoice();
2573 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2574 setRadioForTypeOfInvoice();
2576 function setRadioForTypeOfInvoice() {
2577 console.log("Change radio");
2578 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2579 jQuery(".checkforselect").prop("disabled", true);
2580 jQuery(".checkforselect").prop("checked", false);
2582 jQuery(".checkforselect").prop("disabled", false);
2583 jQuery(".checkforselect").prop("checked", true);
2589 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2591 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2592 print
'<table class="nobordernopadding"><tr>';
2596 if ($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') {
2597 print
'<td class="nowrap" style="padding-left: 15px">';
2599 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2600 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2601 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2603 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
2604 $valuedeposit =
GETPOST(
'valuedeposit',
'int');
2605 $deposit_percent =
null;
2606 if ($origin ==
'reception') {
2608 if (!isset($objectsrc->origin_object)) {
2609 $objectsrc->fetch_origin();
2611 if (!empty($objectsrc->origin_object)) {
2612 $deposit_percent = $objectsrc->origin_object->deposit_percent;
2614 } elseif (!empty($objectsrc->deposit_percent)) {
2615 $deposit_percent = $objectsrc->deposit_percent;
2617 if (empty($typedeposit) && !empty($deposit_percent)) {
2618 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
2619 if (!empty($origin_payment_conditions_deposit_percent)) {
2620 $typedeposit =
'variable';
2623 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($deposit_percent)) {
2624 $valuedeposit = $deposit_percent;
2626 print $form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
2628 print
'<td class="nowrap" style="padding-left: 5px">';
2629 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' . $valuedeposit .
'"/>';
2632 print
'</tr></table>';
2634 print
'</div></div>';
2703 if (empty($origin)) {
2704 if (!empty($societe->id) && $societe->id > 0) {
2708 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2715 foreach ($facids as $key => $valarray) {
2716 $newinvoice_static->id = $key;
2717 $newinvoice_static->ref = $valarray [
'ref'];
2718 $newinvoice_static->status = $valarray [
'status'];
2719 $newinvoice_static->statut = $valarray [
'status'];
2720 $newinvoice_static->type = $valarray [
'type'];
2721 $newinvoice_static->paid = $valarray [
'paye'];
2722 $newinvoice_static->paye = $valarray [
'paye'];
2724 $optionsav .=
'<option value="'.$key.
'"';
2726 $optionsav .=
' selected';
2728 $newinvoice_static->fetch_optionals($key);
2729 $object->array_options = $newinvoice_static->array_options;
2732 $optionsav .= $newinvoice_static->ref;
2733 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
2734 $optionsav .=
'</option>';
2737 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2738 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOSTINT(
'type') == 2 ?
' checked' :
'');
2740 $tmp .=
' disabled';
2744 print
'<script type="text/javascript">
2745 jQuery(document).ready(function() {
2746 if (! jQuery("#radio_creditnote").is(":checked"))
2748 jQuery("#credit_note_options").hide();
2750 jQuery("#radio_creditnote").click(function() {
2751 jQuery("#credit_note_options").show();
2753 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2754 jQuery("#credit_note_options").hide();
2758 $text = $tmp.
'<label for="radio_creditnote">'.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
2760 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2762 $text .=
' disabled';
2766 $text .=
'<option value="-1"></option>';
2767 $text .= $optionsav;
2769 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
2771 $text .=
'</select>';
2772 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2775 print
'<div id="credit_note_options" class="clearboth">';
2776 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' :
'').
' /> ';
2777 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
2778 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' :
'').
' /> ';
2779 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
2782 print
'</div></div>';
2785 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2787 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2789 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2"> ';
2791 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
2792 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
2793 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2795 print
'</div></div>'.
"\n";
2805 print
'<tr><td class="fieldrequired">';
2806 print $form->textwithpicto($langs->trans(
'RefSupplierBill'), $langs->trans(
"RefOfOnVendorSide", $langs->trans(
"SupplierBill"))).
'</td><td>';
2807 print
'<input name="ref_supplier" value="'.(GETPOSTISSET(
'ref_supplier') ?
GETPOST(
'ref_supplier') : (!empty($objectsrc->ref_supplier) ? $objectsrc->ref_supplier :
'')).
'" type="text" spellcheck="false"';
2808 if (!empty($societe->id) && $societe->id > 0) {
2817 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
2818 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
2822 if (!empty($societe->id) && $societe->id > 0) {
2824 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2826 $thirdparty = $societe;
2828 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2829 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2835 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth300" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
2839 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
2840 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2841 print $form->selectDate($dateinvoice ? (
int) $dateinvoice :
'',
'', 0, 0, 0,
"add", 1, 1);
2846 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td>';
2847 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2848 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
2853 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2854 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
2855 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth200 widthcentpercentminusx');
2859 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
2860 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2861 print $form->selectDate($datedue,
'ech', 0, 0, 0,
"add", 1, 1);
2865 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2866 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2867 $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'DBIT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
2872 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2874 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
2882 $langs->load(
'projects');
2883 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2884 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');
2885 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>';
2892 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
2893 print
'<td colspan="3" class="maxwidthonsmartphone">';
2894 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2895 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 :
''));
2901 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
2902 print
'<tr><td>' . $langs->trans(
'VATReverseCharge') .
'</td><td>';
2905 $vat_reverse_charge = (
GETPOST(
'vat_reverse_charge',
'alpha') ==
'on' ||
GETPOST(
'vat_reverse_charge',
'alpha') ==
'1') ? 1 : 0;
2906 } elseif ($vat_reverse_charge == 1 || $societe->vat_reverse_charge == 1 || ($societe->country_code !=
'FR' &&
isInEEC($societe) && !empty($societe->tva_intra))) {
2907 $vat_reverse_charge = 1;
2909 $vat_reverse_charge = 0;
2912 print
'<input type="checkbox" name="vat_reverse_charge"'. (!empty($vat_reverse_charge) ?
' checked ' :
'') .
'>';
2919 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
2920 print
'<td class="maxwidthonsmartphone">';
2921 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
2922 $used_currency_code = $currency_code;
2923 if (!
GETPOST(
'changecompany')) {
2924 $used_currency_code =
GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code;
2926 print $form->selectMultiCurrency($used_currency_code,
'multicurrency_code');
2932 if ($fac_recid > 0) {
2933 $dateexample = $dateinvoice;
2934 if (empty($dateexample)) {
2937 $substitutionarray = array(
2938 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
2939 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
2940 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
2941 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
2942 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
2943 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
2944 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
2945 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
2946 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
2947 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
2948 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
2951 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
2952 foreach ($substitutionarray as $key => $val) {
2953 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
2955 $htmltext .=
'</i>';
2960 $langs->loadLangs(array(
"intracommreport"));
2961 print
'<!-- If module intracomm on -->'.
"\n";
2962 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
2963 $form->selectTransportMode(
GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
2967 if (empty($reshook)) {
2968 print
$object->showOptionals($extrafields,
'create');
2973 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
2974 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
2979 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2981 $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%');
2982 print $doleditor->Create(1);
2988 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
2990 $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%');
2991 print $doleditor->Create(1);
2997 if (!empty($objectsrc) && $classname !==
null) {
2998 print
"\n<!-- ".$classname.
" info -->";
3000 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
3001 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
3002 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
3003 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
3004 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
3006 $txt = $langs->trans($classname);
3007 if ($classname ==
'CommandeFournisseur') {
3008 $langs->load(
'orders');
3009 $txt = $langs->trans(
"SupplierOrder");
3011 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
3013 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'invoice_supplier');
3015 if (isset($objectsrc->linkedObjects[
'invoice_supplier'])) {
3016 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
3018 $invoice_supplier = [];
3020 '@phan-var-force null|FactureFournisseur[] $invoice_supplier';
3023 if (is_array($invoice_supplier)) {
3024 $cntinvoice = count($invoice_supplier);
3026 if ($cntinvoice >= 1) {
3028 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
3033 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
3034 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
3035 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
3036 print
'<tr><td>'.$langs->transcountry(
"AmountLT1",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
3039 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
3040 print
'<tr><td>'.$langs->transcountry(
"AmountLT2",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
3042 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
3045 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
'</td></tr>';
3046 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
"</td></tr>";
3047 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
"</td></tr>";
3052 $parameters = array();
3053 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
3054 print $hookmanager->resPrint;
3062 print $form->buttonsSaveCancel(
"CreateDraft");
3065 if (!empty($objectsrc)) {
3068 $title = $langs->trans(
'ProductsAndServices');
3071 print
'<div class="div-table-responsive-no-min">';
3072 print
'<table class="noborder centpercent">';
3074 $objectsrc->printOriginLinesList(
'', $selectedLines);
3082 if ($id > 0 || !empty($ref)) {
3088 $result =
$object->fetch($id, $ref);
3093 $result =
$object->fetch_thirdparty();
3099 $societe =
$object->thirdparty;
3101 $totalpaid =
$object->getSommePaiement();
3102 $totalcreditnotes =
$object->getSumCreditNotesUsed();
3103 $totaldeposits =
$object->getSumDepositsUsed();
3111 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
3114 $multicurrency_resteapayer = 0;
3116 $multicurrency_totalpaid =
$object->getSommePaiement(1);
3117 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
3118 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
3119 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
3123 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
3124 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
3131 $resteapayeraffiche = $resteapayer;
3134 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
3135 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
3137 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
3138 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
3141 $absolute_discount = $societe->getAvailableDiscounts(
null, $filterabsolutediscount, 0, 1);
3142 $absolute_creditnote = $societe->getAvailableDiscounts(
null, $filtercreditnote, 0, 1);
3143 $absolute_discount =
price2num($absolute_discount,
'MT');
3144 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
3148 $objectidnext =
$object->getIdReplacingInvoice();
3151 $titre = $langs->trans(
'SupplierInvoice');
3153 print
dol_get_fiche_head($head,
'card', $titre, -1,
'supplier_invoice', 0,
'',
'', 0,
'', 1);
3158 if ($action ==
'converttoreduc') {
3161 $type_fac =
'ExcessPaid';
3163 $type_fac =
'CreditNote';
3165 $type_fac =
'Deposit';
3167 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
3168 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
3169 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
3173 if ($action ==
'clone') {
3175 $formquestion = array(
3176 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplierBill"),
'value' => $langs->trans(
"CopyOf").
' '.
$object->ref_supplier),
3177 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
3180 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 0);
3184 if ($action ==
'valid') {
3186 if (preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) {
3188 $numref =
$object->getNextNumRef($societe);
3197 $text = $langs->trans(
'ConfirmValidateBill', $numref);
3205 $formquestion = array();
3207 $qualified_for_stock_change = 0;
3209 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3211 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3215 $langs->load(
"stocks");
3216 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3219 $warehouse_array = $warehouse->list_array();
3220 if (count($warehouse_array) == 1) {
3222 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3225 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3227 $formquestion = array(
3228 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3232 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
3237 if ($action ==
'edit') {
3238 $formquestion = array();
3240 $qualified_for_stock_change = 0;
3242 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3244 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3247 $langs->load(
"stocks");
3248 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3251 $warehouse_array = $warehouse->list_array();
3252 if (count($warehouse_array) == 1) {
3254 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3257 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3259 $formquestion = array(
3260 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3263 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill',
$object->ref),
'confirm_edit', $formquestion, 1, 1);
3267 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
3268 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'', 0, 1);
3271 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
3275 $close[$i][
'code'] =
'discount_vat';
3277 $close[$i][
'code'] =
'badsupplier';
3279 $close[$i][
'code'] =
'other';
3283 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
3285 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3287 $close[$i][
'label'] = $langs->trans(
"Other");
3291 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3293 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3295 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
3298 $arrayreasons = array();
3299 foreach ($close as $key => $val) {
3300 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
3304 $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'));
3306 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
3310 if ($action ==
'canceled') {
3312 $close[1][
'code'] =
'badsupplier';
3313 $close[2][
'code'] =
'abandon';
3315 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3316 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
3318 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier",
$object->ref), $close[1][
'label'], 1);
3319 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
3321 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
3322 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
3325 $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'));
3327 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 280);
3331 if ($action ==
'delete') {
3332 $formquestion = array();
3334 $qualified_for_stock_change = 0;
3336 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3338 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3342 $langs->load(
"stocks");
3343 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3346 $warehouse_array = $warehouse->list_array();
3348 $selectwarehouse =
'<span class="questionrevertstock hidden">';
3349 if (count($warehouse_array) == 1) {
3351 $selectwarehouse .=
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3354 $selectwarehouse .= $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3356 $selectwarehouse .=
'</span>';
3358 $selectyesno = array(0 => $langs->trans(
'No'), 1 => $langs->trans(
'Yes'));
3360 print
'<script type="text/javascript">
3361 $(document).ready(function() {
3362 $("#revertstock").change(function() {
3363 if(this.value > 0) {
3364 $(".questionrevertstock").removeClass("hidden");
3366 $(".questionrevertstock").addClass("hidden");
3372 $formquestion = array(
3373 array(
'type' =>
'select',
'name' =>
'revertstock',
'label' => $langs->trans(
"RevertProductsToStock"),
'select_show_empty' => 0,
'values' => $selectyesno),
3374 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $selectwarehouse,
'tdclass' =>
'questionrevertstock hidden')
3378 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete', $formquestion, 1, 1);
3380 if ($action ==
'deletepayment') {
3381 $payment_id =
GETPOST(
'paiement_id');
3382 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
3386 if ($action ==
'ask_deleteline') {
3387 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
3391 if ($action ==
'add_title_line') {
3392 $langs->load(
'subtotals');
3394 $depth_array =
$object->getPossibleLevels($langs);
3395 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3396 } elseif ($action ==
'add_subtotal_line') {
3397 $langs->load(
'subtotals');
3399 $titles =
$object->getPossibleTitles();
3400 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3404 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
3405 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
3406 if (empty($reshook)) {
3407 $formconfirm .= $hookmanager->resPrint;
3408 } elseif ($reshook > 0) {
3409 $formconfirm = $hookmanager->resPrint;
3417 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
3419 $morehtmlref =
'<div class="refidno">';
3421 $morehtmlref .= $form->editfieldkey(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, (
int) $usercancreate,
'string',
'', 0, 1);
3422 $morehtmlref .= $form->editfieldval(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
3424 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'supplier');
3426 $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>';
3430 $langs->load(
"projects");
3431 $morehtmlref .=
'<br>';
3432 if ($permissiontoadd) {
3433 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
3434 if ($action !=
'classify') {
3435 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.((int)
$object->id).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
3437 $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');
3439 if (!empty(
$object->fk_project)) {
3441 $proj->fetch(
$object->fk_project);
3442 $morehtmlref .= $proj->getNomUrl(1);
3444 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
3449 $morehtmlref .=
'</div>';
3451 $object->totalpaid = $totalpaid;
3453 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
3456 $parameters = array();
3458 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierInvoice', $parameters, $object, $action);
3459 if (empty($reshook)) {
3460 print
'<div class="fichecenter">';
3461 print
'<div class="fichehalfleft">';
3462 print
'<div class="underbanner clearboth"></div>';
3464 print
'<table class="border tableforfield centpercent">';
3467 print
'<tr><td>'.$langs->trans(
'Type').
'</td><td>';
3468 print
'<span class="badgeneutral">';
3472 print
' '.$object->getSubtypeLabel(
'facture_fourn');
3476 $facreplaced->fetch(
$object->fk_facture_source);
3477 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
3480 if (
$object->fk_facture_source > 0) {
3482 $facusing->fetch(
$object->fk_facture_source);
3483 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
3485 $langs->load(
"errors");
3486 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"WarningCorrectedInvoiceNotFound").
'</span>';
3491 $object->getListIdAvoirFromInvoice();
3493 if (!empty(
$object->creditnote_ids)) {
3494 $invoicecredits = array();
3495 foreach (
$object->creditnote_ids as $invoiceid) {
3497 $creditnote->fetch($invoiceid);
3498 $invoicecredits[] = $creditnote->getNomUrl(1);
3500 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
3503 if (isset($objectidnext) && $objectidnext > 0) {
3506 $facthatreplace->fetch($objectidnext);
3507 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
3511 $result = $discount->fetch(0, 0,
$object->id);
3513 print
' <span class="opacitymediumbycolor paddingleft">';
3514 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
3515 $s = str_replace(
'{s1}',
$object->getLibType(1), $s);
3516 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
3518 print
'</span><br>';
3522 if (
$object->fk_fac_rec_source > 0) {
3524 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
3526 print
' <span class="opacitymediumbycolor paddingleft">';
3527 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->title).
'</a>';
3528 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
3538 print
'<!-- Discounts -->'.
"\n";
3539 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
3542 $thirdparty = $societe;
3544 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3550 print
'<td>'.$form->editfieldkey(
"Label",
'label',
$object->label, $object, (
int) $usercancreate).
'</td>';
3551 print
'<td>'.$form->editfieldval(
"Label",
'label',
$object->label, $object, $usercancreate).
'</td>';
3559 print $form->editfieldkey(
"DateInvoice",
'datef', (
string)
$object->date,
$object, (int) $form_permission,
'datepicker');
3560 print
'</td><td colspan="3">';
3561 print $form->editfieldval(
"Date",
'datef',
$object->date, $object, $form_permission,
'datepicker');
3567 print $form->editfieldkey(
"DatePointOfTax",
'date_pointoftax', (
string)
$object->date_pointoftax,
$object, (int) $pointoftax_form_permission,
'datepicker');
3568 print
'</td><td colspan="3">';
3569 print $form->editfieldval(
"DatePointOfTax",
'date_pointoftax',
$object->date_pointoftax, $object, $pointoftax_form_permission,
'datepicker');
3574 $langs->load(
'bills');
3575 print
'<tr><td class="nowrap">';
3576 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3577 print $langs->trans(
'PaymentConditions');
3579 if ($action !=
'editconditions' && $form_permission) {
3580 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>';
3582 print
'</tr></table>';
3584 if ($action ==
'editconditions') {
3585 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
3587 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
3594 print $form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', (
string)
$object->date_echeance, $object, (
int) $form_permission,
'datepicker');
3596 print $form->editfieldval(
"DateMaxPayment",
'date_lim_reglement',
$object->date_echeance, $object, $form_permission,
'datepicker');
3597 if ($action !=
'editdate_lim_reglement' &&
$object->hasDelay()) {
3603 $langs->load(
'bills');
3604 print
'<tr><td class="nowrap">';
3605 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3606 print $langs->trans(
'PaymentMode');
3608 if ($action !=
'editmode' && $form_permission) {
3609 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>';
3611 print
'</tr></table>';
3613 if ($action ==
'editmode') {
3614 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3616 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'none');
3622 print
'<tr><td class="nowrap">';
3623 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3624 print $langs->trans(
'BankAccount');
3626 if ($action !=
'editbankaccount' && $usercancreate) {
3627 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>';
3629 print
'</tr></table>';
3631 if ($action ==
'editbankaccount') {
3632 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
3634 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
3642 print
'<tr><td class="nowrap">';
3643 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3644 print $langs->trans(
'VATReverseCharge');
3646 if ($action !=
'editvatreversecharge' && $usercancreate) {
3647 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>';
3649 print
'</tr></table>';
3651 if ($action ==
'editvatreversecharge') {
3652 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
3653 print
'<input type="hidden" name="action" value="setvatreversecharge">';
3654 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3656 print
'<input type="checkbox" name="vat_reverse_charge"' . (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
'>';
3658 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
3661 print
'<input type="checkbox" name="vat_reverse_charge"'. (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
' disabled>';
3669 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3670 print $langs->trans(
'IncotermLabel');
3671 print
'<td><td class="right">';
3672 if ($usercancreate) {
3673 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
3677 print
'</td></tr></table>';
3680 if ($action !=
'editincoterm') {
3681 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
3683 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
3690 $langs->loadLangs(array(
"intracommreport"));
3691 print
'<!-- If module intracomm on -->'.
"\n";
3693 print
'<table class="nobordernopadding centpercent"><tr><td>';
3694 print $langs->trans(
'IntracommReportTransportMode');
3696 if ($action !=
'edittransportmode' && ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"))) {
3697 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edittransportmode&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit().
'</a></td>';
3699 print
'</tr></table>';
3702 if ($action ==
'edittransportmode') {
3703 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'transport_mode_id', 1, 1);
3705 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'none');
3713 print
'<table class="nobordernopadding centpercent"><tr><td>';
3714 print $langs->trans(
"Categories");
3715 print
'<td><td class="right">';
3716 if ($usercancreate) {
3717 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
3721 print
'</td></tr></table>';
3724 if ($action ==
'edittags') {
3725 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
3726 print
'<input type="hidden" name="action" value="settags">';
3727 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3728 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
3729 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
3732 print $form->showCategories(
$object->id, Categorie::TYPE_SUPPLIER_INVOICE, 1);
3740 if (
$object->status != $object::STATUS_DRAFT) {
3744 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
3749 print
'<div class="fichehalfright">';
3750 print
'<div class="underbanner clearboth"></div>';
3752 print
'<table class="border tableforfield centpercent">';
3754 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
3757 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
3758 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3760 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3765 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
3766 print
'<td class="nowrap amountcard right">';
3767 if (
GETPOST(
'calculationrule')) {
3768 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
3770 $calculationrule = (!
getDolGlobalString(
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND_SUPPLIER') ?
'totalofround' :
'roundoftotal');
3772 if ($calculationrule ==
'totalofround') {
3773 $calculationrulenum = 1;
3775 $calculationrulenum = 2;
3778 if (
$object->getVentilExportCompta() == 0) {
3779 $s =
'<span class="hideonsmartphone opacitymedium">' . $langs->trans(
"ReCalculate") .
' </span>';
3780 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=totalofround">' . $langs->trans(
"Mode1") .
'</a>';
3782 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=roundoftotal">' . (
$conf->dol_optimize_smallscreen ?
"2" : $langs->trans(
"Mode2")) .
'</a>';
3783 print
'<div class="inline-block">';
3784 print $form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum) .
'<br>' . $langs->trans(
"CalculationRuleDescSupplier"), 2, 1,
img_picto(
'',
'help',
'class="paddingleft paddingright"'),
'', 3,
'', 0,
'recalculate');
3785 print
' ';
3788 print
'<span class="nowraponall">'.price(
$object->total_tva, 1, $langs, 0, -1, -1,
$conf->currency).
'</span>';
3791 print
'<td class="nowraponall amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3795 if ($societe->localtax1_assuj ==
"1") {
3797 print
'<td>' . $langs->transcountry(
"AmountLT1", $societe->country_code) .
'</td>';
3798 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3801 if ($societe->localtax2_assuj ==
"1") {
3803 print
'<td>' . $langs->transcountry(
"AmountLT2", $societe->country_code) .
'</td>';
3804 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3809 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
3810 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3812 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3845 if ($societe->localtax1_assuj ==
"1") {
3848 if ($societe->localtax2_assuj ==
"1") {
3852 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
3853 $sql .=
' c.id as payment_type, c.code as payment_code,';
3854 $sql .=
' pf.amount,';
3855 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
3856 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
3857 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
3858 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
3859 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
3860 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
3861 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
3862 $sql .=
' ORDER BY p.datep, p.tms';
3864 $result =
$db->query($sql);
3866 $num =
$db->num_rows($result);
3869 print
'<div class="div-table-responsive-no-min">';
3870 print
'<table class="noborder paymenttable centpercent">';
3871 print
'<tr class="liste_titre">';
3873 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
3874 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
3876 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
3881 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
3886 $objp =
$db->fetch_object($result);
3888 $paymentstatic->id = $objp->rowid;
3889 $paymentstatic->datepaye =
$db->jdate($objp->dp);
3890 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
3891 $paymentstatic->num_payment = $objp->num_payment;
3893 $paymentstatic->paiementcode = $objp->payment_code;
3894 $paymentstatic->type_code = $objp->payment_code;
3895 $paymentstatic->type_label = $objp->payment_type;
3897 print
'<tr class="oddeven">';
3898 print
'<td class="nowraponall">';
3899 print $paymentstatic->getNomUrl(1);
3901 print
'<td>'.dol_print_date(
$db->jdate($objp->dp),
'day').
'</td>';
3902 $s = $form->form_modes_reglement(
'', $objp->payment_type,
'none',
'', 1, 0,
'', 1).
' '.$objp->num_payment;
3903 print
'<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).
'">';
3907 $bankaccountstatic->id = $objp->baid;
3908 $bankaccountstatic->ref = $objp->baref;
3909 $bankaccountstatic->label = $objp->baref;
3910 $bankaccountstatic->number = $objp->banumber;
3913 $bankaccountstatic->account_number = $objp->account_number;
3916 $accountingjournal->fetch($objp->fk_accountancy_journal);
3917 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
3920 print
'<td class="right nowraponall">';
3921 if ($objp->baid > 0) {
3922 print $bankaccountstatic->getNomUrl(1,
'transactions');
3927 print
'<td class="center">';
3929 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
3935 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
3937 $totalpaid += $objp->amount;
3941 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
3967 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
3968 print
'<span class="opacitymedium">';
3970 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
3972 print $langs->trans(
'AlreadyPaid');
3977 print
'<td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td>';
3981 $resteapayeraffiche = $resteapayer;
3983 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
3986 $creditnoteamount = 0;
3989 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
3990 $sql .=
" re.description, re.fk_invoice_supplier_source";
3991 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
3992 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
3993 $resql =
$db->query($sql);
3995 $num =
$db->num_rows($resql);
3999 $obj =
$db->fetch_object($resql);
4000 $invoice->fetch($obj->fk_invoice_supplier_source);
4001 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4003 print $langs->trans(
"CreditNote").
' ';
4006 print $langs->trans(
"Deposit").
' ';
4008 print $invoice->getNomUrl(0);
4011 print
'<td class="right">';
4012 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
4013 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
4017 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
4021 $creditnoteamount += $obj->amount_ttc;
4024 $depositamount += $obj->amount_ttc;
4033 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4034 print
'<span class="opacitymedium">';
4035 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
4039 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4041 $resteapayeraffiche = 0;
4042 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4046 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4047 print
'<span class="opacitymedium">';
4048 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
4052 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4055 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4059 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4060 print
'<span class="opacitymedium">';
4061 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
4065 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4067 $resteapayeraffiche = 0;
4068 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4072 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4073 $text = $langs->trans(
"HelpAbandonOther");
4075 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
4077 print
'<span class="opacitymedium">';
4079 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
4083 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4085 $resteapayeraffiche = 0;
4086 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4090 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4091 print
'<span class="opacitymedium">';
4092 print $langs->trans(
"Billed");
4096 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
4100 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4101 print
'<span class="opacitymedium">';
4102 print $langs->trans(
'RemainderToPay');
4103 if ($resteapayeraffiche < 0) {
4104 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4109 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
4114 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4115 print
'<span class="opacitymedium">';
4116 print $langs->trans(
'RemainderToPayMulticurrency');
4117 if ($resteapayeraffiche < 0) {
4118 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4123 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price(
price2num($multicurrency_resteapayer,
'MT'), 0, $langs, 1, -1, -1,
$object->multicurrency_code).
'</td>';
4127 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4130 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4131 print $langs->trans(
'AlreadyPaidBack');
4134 print
'<td class="right">'.price($sign * $totalpaid).
'</td>';
4138 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">'.$langs->trans(
"Billed").
'</td>';
4140 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
4144 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4145 print
'<span class="opacitymedium">';
4146 print $langs->trans(
'RemainderToPayBack');
4147 if ($resteapayeraffiche > 0) {
4148 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4153 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
4158 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4159 print
'<span class="opacitymedium">';
4160 print $langs->trans(
'RemainderToPayBackMulticurrency');
4161 if ($resteapayeraffiche > 0) {
4162 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4167 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>';
4183 print
'<div class="clearboth"></div><br>';
4186 $blocname =
'contacts';
4187 $title = $langs->trans(
'ContactsAddresses');
4188 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4193 $blocname =
'notes';
4194 $title = $langs->trans(
'Notes');
4195 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4202 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
4203 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4204 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
4205 print
'<input type="hidden" name="mode" value="">';
4206 print
'<input type="hidden" name="page_y" value="">';
4207 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
4208 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
4209 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4213 include DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_ajaxrow.tpl.php';
4215 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
4219 print
'<div class="div-table-responsive-no-min">';
4220 print
'<table id="tablelines" class="noborder noshadow centpercent">';
4222 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
4225 $inputalsopricewithtax = 1;
4226 $senderissupplier = 2;
4227 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY')) {
4228 $senderissupplier =
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY');
4233 $object->printObjectLines($action, $societe,
$mysoc, $lineid, 1);
4240 if ($action !=
'editline') {
4243 $parameters = array();
4244 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
4248 if (empty($reshook)) {
4262 if ($action !=
'presend') {
4265 print
'<div class="tabsAction">';
4267 $parameters = array();
4268 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
4270 if (empty($reshook)) {
4273 $langs->load(
'subtotals');
4275 $url_button = array();
4277 $url_button[] = array(
4278 'lang' =>
'subtotals',
4280 'perm' => (
bool) $usercancreate,
4281 'label' => $langs->trans(
'AddTitleLine'),
4282 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_title_line'],
true)
4285 $url_button[] = array(
4286 'lang' =>
'subtotals',
4288 'perm' => (
bool) $usercancreate,
4289 'label' => $langs->trans(
'AddSubtotalLine'),
4290 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_subtotal_line'],
true)
4293 print
dolGetButtonAction(
'', $langs->trans(
'SubTotal'),
'default', $url_button,
'',
true);
4298 $ventilExportCompta =
$object->getVentilExportCompta();
4300 if ($ventilExportCompta == 0) {
4301 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=edit&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
4303 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
4308 $result = $discount->fetch(0, 0,
$object->id);
4315 if (!$objectidnext &&
$object->close_code !=
'replaced' && $usercancreate) {
4316 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
4318 if ($usercancreate) {
4319 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
4321 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
4331 if ($usercanvalidate) {
4332 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken().
'"';
4333 print
'>'.$langs->trans(
'Validate').
'</a>';
4335 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
4336 print
'>'.$langs->trans(
'Validate').
'</a>';
4342 if (empty($user->socid)) {
4345 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' =>
$object->id,
'action' =>
'presend',
'mode' =>
'init'],
true).
'#formmailbeforetitle',
'');
4354 $langs->load(
"withdrawals");
4355 if ($resteapayer > 0) {
4356 if ($usercancreatecreditransfer) {
4357 if (!$objectidnext &&
$object->close_code !=
'replaced') {
4358 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>';
4360 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeBankTransferOrder').
'</span>';
4372 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>';
4379 if ($resteapayer == 0) {
4380 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
4381 } elseif ($usercancreate) {
4382 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>';
4388 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
4392 && (
getDolGlobalString(
'SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') ||
$object->getSommePaiement() == 0)
4394 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>';
4398 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
4409 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaid').
'</a>';
4414 if ($totalpaid > 0 || $totalcreditnotes > 0) {
4416 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
4419 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
4431 if (!$objectidnext) {
4432 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>';
4437 if ($action !=
'edit' && $usercancreate) {
4438 print
'<a class="butAction butActionClone" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=clone&socid='.
$object->socid.
'&token='.
newToken().
'">'.$langs->trans(
'ToClone').
'</a>';
4443 if (!$objectidnext && count(
$object->lines) > 0) {
4444 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.
$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
4449 if ($action !=
'confirm_edit' && $usercandelete) {
4450 $isErasable =
$object->is_erasable();
4452 $enableDelete =
false;
4454 $params = (empty(
$conf->use_javascript_ajax) ? array() : array(
'attr' => array(
'class' =>
'reposition')));
4456 if ($isErasable == -4) {
4457 $htmltooltip = $langs->trans(
"DisabledBecausePayments");
4458 } elseif ($isErasable == -3) {
4459 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastSituationInvoice");
4460 } elseif ($isErasable == -2) {
4461 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastInvoice");
4462 } elseif ($isErasable == -1) {
4463 $htmltooltip = $langs->trans(
"DisabledBecauseDispatchedInBookkeeping");
4464 } elseif ($isErasable <= 0) {
4465 $htmltooltip = $langs->trans(
"DisabledBecauseNotErasable");
4467 $enableDelete =
true;
4470 print
dolGetButtonAction($htmltooltip, $langs->trans(
"Delete"),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken(), (
string)
$object->id, $enableDelete, $params);
4474 if ($action !=
'confirm_edit') {
4475 print
'<div class="fichecenter"><div class="fichehalfleft">';
4481 $subdir =
get_exdir(
$object->id, 2, 0, 0, $object,
'invoice_supplier').$ref;
4483 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.
$object->id;
4484 $genallowed = $usercanread;
4485 $delallowed = $usercancreate;
4489 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, (
int) $genallowed, (
int) $delallowed, $modelpdf, $genifempty, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
4490 $somethingshown = $formfile->numoffiles;
4493 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice_supplier'), 1);
4494 $linktoelem = $tmparray[
'linktoelem'];
4495 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
4496 print $htmltoenteralink;
4498 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
4500 print
'</div><div class="fichehalfright">';
4503 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
4505 $somethingshown = $formactions->showactions($object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
4507 print
'</div></div>';
4513 if (
GETPOST(
'modelselected')) {
4514 $action =
'presend';
4518 $modelmail =
'invoice_supplier_send';
4519 $defaulttopic =
'SendBillRef';
4521 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
4522 $trackid =
'sinv'.$object->id;
4524 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage bank accounts.
Class to manage accounting journals.
const TYPE_PROFORMA
Proforma invoice.
const TYPE_SITUATION
Situation invoice.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_STANDARD
Standard invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const STATUS_CLOSED
Classified paid.
Class to manage invoice templates.
Class to manage payments for supplier invoices.
Class ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
$date_start
Variables from include:
facturefourn_prepare_head(FactureFournisseur $object)
Prepare array with list of tabs.
dol_now($mode='gmt')
Return date for now.
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.