40require
'../../main.inc.php';
41require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_invoice/modules_facturefournisseur.php';
45require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture-rec.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
53if (isModEnabled(
"product")) {
54 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
55 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
57if (isModEnabled(
'project')) {
58 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
59 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
62if (isModEnabled(
'variants')) {
63 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
65if (isModEnabled(
'accounting')) {
66 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
78$langs->loadLangs(array(
'bills',
'compta',
'suppliers',
'companies',
'products',
'banks',
'admin'));
79if (isModEnabled(
'incoterm')) {
80 $langs->load(
'incoterm');
85$action =
GETPOST(
'action',
'aZ09');
88$cancel =
GETPOST(
'cancel',
'alpha');
89$backtopage =
GETPOST(
'backtopage',
'alpha');
90$backtopageforcancel =
'';
94$origin =
GETPOST(
'origin',
'alpha');
105$hookmanager->initHooks(array(
'invoicesuppliercard',
'globalcard'));
111$extrafields->fetch_name_optionals_label(
$object->table_element);
114if ($id > 0 || !empty($ref)) {
115 $ret =
$object->fetch($id, $ref);
122 $ret =
$object->fetch_thirdparty();
130if (!empty($user->socid)) {
131 $socid = $user->socid;
135$result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture',
'fk_soc',
'rowid', $isdraft);
138$usercanread = ($user->hasRight(
"fournisseur",
"facture",
"lire") || $user->hasRight(
"supplier_invoice",
"lire"));
139$usercancreate = ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"));
140$usercandelete = (($user->hasRight(
"fournisseur",
"facture",
"supprimer") || $user->hasRight(
"supplier_invoice",
"supprimer")) || ($usercancreate &&
$object->is_erasable() == 1));
141$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
144$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"validate")));
145$usercansend = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"send"));
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')]);
166$parameters = array(
'socid' => $socid);
167$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
172if (empty($reshook)) {
173 $backurlforlist = DOL_URL_ROOT.
'/fourn/facture/list.php';
175 if (empty($backtopage) || ($cancel && empty($id))) {
176 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
177 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
178 $backtopage = $backurlforlist;
180 $backtopage = DOL_URL_ROOT.
'/fourn/facture/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
186 if (!empty($backtopageforcancel)) {
187 header(
"Location: ".$backtopageforcancel);
189 } elseif (!empty($backtopage)) {
190 header(
"Location: ".$backtopage);
196 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
198 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
200 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
203 if (
GETPOST(
'linkedOrder') && empty($cancel) && $id > 0 && $permissiontoadd) {
206 $result =
$object->add_object_linked(
'order_supplier',
GETPOSTINT(
'linkedOrder'));
210 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
212 '@phan-var-force FactureFournisseur $objectutil';
214 if (
GETPOST(
'newsupplierref',
'alphanohtml')) {
215 $objectutil->ref_supplier =
GETPOST(
'newsupplierref',
'alphanohtml');
219 $result = $objectutil->createFromClone($user, $id);
221 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
224 $langs->load(
"errors");
228 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
229 $idwarehouse =
GETPOST(
'idwarehouse');
234 $qualified_for_stock_change = 0;
236 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
238 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
242 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
243 $langs->load(
"stocks");
244 if (!$idwarehouse || $idwarehouse == -1) {
246 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
254 $result =
$object->validate($user,
'', $idwarehouse);
264 $outputlangs = $langs;
267 $newlang =
GETPOST(
'lang_id',
'aZ09');
270 $newlang =
$object->thirdparty->default_lang;
272 if (!empty($newlang)) {
274 $outputlangs->setDefaultLang($newlang);
279 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
286 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $permissiontodelete) {
290 $isErasable =
$object->is_erasable();
292 if ($usercandelete && $isErasable > 0) {
293 $revertstock =
GETPOST(
'revertstock');
298 $qualified_for_stock_change = 0;
300 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
302 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
306 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
307 $langs->load(
"stocks");
308 if (!$idwarehouse || $idwarehouse == -1) {
310 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
313 $result =
$object->setDraft($user, $idwarehouse);
322 $result =
$object->delete($user);
324 header(
'Location: list.php?restore_lastsearch_values=1');
331 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
333 $result =
$object->deleteLine($lineid);
353 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
360 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
363 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
364 if ($result > 0 &&
$object->id > 0 && $discount->fk_invoice_supplier ==
$object->id) {
365 $discount->unlink_invoice();
369 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercancreate) {
371 $result =
$object->setPaid($user);
375 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercancreate) {
378 $close_code =
GETPOST(
"close_code",
'restricthtml');
379 $close_note =
GETPOST(
"close_note",
'restricthtml');
381 $result =
$object->setPaid($user, $close_code, $close_note);
386 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
388 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
391 $close_code =
GETPOST(
"close_code",
'restricthtml');
392 $close_note =
GETPOST(
"close_note",
'restricthtml');
394 $result =
$object->setCanceled($user, $close_code, $close_note);
399 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
404 if ($action ==
'setref_supplier' && $usercancreate) {
407 if (
$object->update($user) < 0) {
411 $outputlangs = $langs;
414 $newlang =
GETPOST(
'lang_id',
'aZ09');
417 $newlang =
$object->thirdparty->default_lang;
419 if (!empty($newlang)) {
421 $outputlangs->setDefaultLang($newlang);
425 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
431 if ($action ==
'setconditions' && $usercancreate) {
433 $object->cond_reglement_code = 0;
434 $object->cond_reglement_id = 0;
449 $new_date_echeance =
$object->calculate_date_lim_reglement();
450 if ($new_date_echeance) {
451 $object->date_echeance = $new_date_echeance;
456 $result =
$object->update($user);
468 } elseif ($action ==
'set_incoterms' && isModEnabled(
'incoterm') && $usercancreate) {
471 } elseif ($action ==
'settags' && isModEnabled(
'category') && $usercancreate) {
474 } elseif ($action ==
'setmode' && $usercancreate) {
477 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
479 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
480 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
483 } elseif ($action ==
'setbankaccount' && $usercancreate) {
486 } elseif ($action ==
'setvatreversecharge' && $usercancreate) {
488 $vatreversecharge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
489 $result =
$object->setVATReverseCharge($vatreversecharge);
492 if ($action ==
'settransportmode' && $usercancreate) {
495 } elseif ($action ==
'setlabel' && $usercancreate) {
499 $result =
$object->update($user);
503 } elseif ($action ==
'setdatef' && $usercancreate) {
507 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
509 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
516 $date_echence_calc =
$object->calculate_date_lim_reglement();
517 if (!empty(
$object->date_echeance)) {
518 $object->date_echeance = $date_echence_calc;
524 $result =
$object->update($user);
528 } elseif ($action ==
'setdate_lim_reglement' && $usercancreate) {
533 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
535 $result =
$object->update($user);
539 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
555 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
557 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
561 $remaintopay =
$object->getRemainToPay(0);
565 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
569 $result = $discount->link_to_invoice(0, $id);
576 $newremaintopay =
$object->getRemainToPay(0);
577 if ($newremaintopay == 0) {
588 $outputlangs = $langs;
591 $newlang =
GETPOST(
'lang_id',
'aZ09');
594 $newlang =
$object->thirdparty->default_lang;
596 if (!empty($newlang)) {
598 $outputlangs->setDefaultLang($newlang);
602 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
607 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
615 $result = $discountcheck->fetch(0, 0,
$object->id);
627 $amount_ht = $amount_tva = $amount_ttc = array();
628 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
632 foreach (
$object->lines as $line) {
633 if ($line->product_type < 9 && $line->total_ht != 0) {
634 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
636 $amount_ht[$keyforvatrate] += $line->total_ht;
637 $amount_tva[$keyforvatrate] += $line->total_tva;
638 $amount_ttc[$keyforvatrate] += $line->total_ttc;
639 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
640 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
641 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
645 '@phan-var-force array<string,float> $amount_ht
646 @phan-var-force array<string,float> $amount_tva
647 @phan-var-force array<string,float> $amount_ttc
648 @phan-var-force array<string,float> $multicurrency_amount_ht
649 @phan-var-force array<string,float> $multicurrency_amount_tva
650 @phan-var-force array<string,float> $multicurrency_amount_ttc';
654 $alreadypaid =
$object->getSommePaiement();
655 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
656 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
657 foreach ($amount_ht as $vatrate => $val) {
658 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
659 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
660 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
661 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
662 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
663 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
672 $discount->description =
'(CREDIT_NOTE)';
674 $discount->description =
'(DEPOSIT)';
676 $discount->description =
'(EXCESS PAID)';
678 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
680 $discount->discount_type = 1;
681 $discount->fk_soc =
$object->socid;
682 $discount->socid =
$object->socid;
683 $discount->fk_invoice_supplier_source =
$object->id;
691 $sql =
'SELECT SUM(pf.amount) as total_paiements';
692 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'paiementfourn as p';
693 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN ('.
getEntity(
'c_paiement').
')';
694 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
695 $sql .=
' AND pf.fk_paiementfourn = p.rowid';
696 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
698 $resql = $db->query($sql);
703 $res = $db->fetch_object($resql);
704 $total_paiements = $res->total_paiements;
707 $total_creditnote_and_deposit = 0;
708 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
709 $sql .=
" re.description, re.fk_invoice_supplier_source";
710 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
711 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
712 $resql = $db->query($sql);
713 if (!empty($resql)) {
714 while ($obj = $db->fetch_object($resql)) {
715 $total_creditnote_and_deposit += $obj->amount_ttc;
721 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
722 $discount->amount_tva = 0;
723 $discount->tva_tx = 0;
724 $discount->vat_src_code =
'';
727 $discount->multicurrency_code =
$object->multicurrency_code;
728 $discount->multicurrency_tx =
$object->multicurrency_tx;
729 $discount->multicurrency_total_ht = $discount->multicurrency_total_ttc = (float)
price2num((
float) $discount->amount_ttc * (float)
$object->multicurrency_tx,
'MT');
730 $discount->multicurrency_total_tva = 0;
732 $discount->multicurrency_amount_ht = $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
733 $discount->multicurrency_amount_tva = 0;
735 $result = $discount->create($user);
741 foreach ($amount_ht as $tva_tx => $xxx) {
743 $discount->multicurrency_code =
$object->multicurrency_code;
744 $discount->multicurrency_tx =
$object->multicurrency_tx;
747 $discount->amount_ht = -((float) $amount_ht[$tva_tx]);
748 $discount->amount_tva = -((float) $amount_tva[$tva_tx]);
749 $discount->amount_ttc = -((float) $amount_ttc[$tva_tx]);
750 $discount->multicurrency_total_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
751 $discount->multicurrency_total_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
752 $discount->multicurrency_total_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
754 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
755 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
756 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
757 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
758 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
759 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
762 $discount->multicurrency_amount_ht = $discount->multicurrency_total_ht;
763 $discount->multicurrency_amount_tva = $discount->multicurrency_total_tva;
764 $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
769 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
770 $vat_src_code = $reg[1];
771 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
774 $discount->tva_tx = abs((
float) $tva_tx);
775 $discount->vat_src_code = $vat_src_code;
777 $result = $discount->create($user);
788 $result =
$object->setPaid($user);
803 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate) {
808 $result = $paiementfourn->fetch(
GETPOSTINT(
'paiement_id'));
810 $result = $paiementfourn->delete($user);
812 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
820 } elseif ($action ==
'add' && $usercancreate) {
825 $selectedLines =
GETPOST(
'toselect',
'array');
833 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
847 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
852 if (empty($dateinvoice)) {
853 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
865 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
881 $object->date_echeance = $datedue;
887 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
888 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
890 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
891 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
912 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
915 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
920 if (empty($dateinvoice)) {
921 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
931 if (!
GETPOST(
'ref_supplier')) {
932 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
940 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
955 $object->date_echeance = $datedue;
961 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
962 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
964 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
965 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
970 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
979 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
981 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
984 foreach ($facture_source->lines as $line) {
986 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
990 $line->fk_facture_fourn =
$object->id;
991 $line->fk_parent_line = $fk_parent_line;
993 $line->subprice = -$line->subprice;
994 $line->pa_ht = -((float) $line->pa_ht);
995 $line->total_ht = -$line->total_ht;
996 $line->total_tva = -$line->total_tva;
997 $line->total_ttc = -$line->total_ttc;
998 $line->total_localtax1 = -$line->total_localtax1;
999 $line->total_localtax2 = -$line->total_localtax2;
1001 $result = $line->insert();
1006 if ($result > 0 && $line->product_type == 9) {
1007 $fk_parent_line = $result;
1015 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 &&
$id > 0) {
1017 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1018 $totalpaid = $facture_source->getSommePaiement();
1019 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1020 $totaldeposits = $facture_source->getSumDepositsUsed();
1021 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1022 $desc = $langs->trans(
'invoiceAvoirLineWithPaymentRestAmount');
1026 $retAddLine =
$object->addline($desc, -$remain_to_pay, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
'TTC');
1028 if ($retAddLine < 0) {
1036 if (empty($dateinvoice)) {
1038 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1048 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1058 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1059 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1070 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1071 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1075 $object->fac_rec = $fac_recid;
1077 $fac_rec->fetch(
$object->fac_rec);
1078 $fac_rec->fetch_lines();
1079 $object->lines = $fac_rec->lines;
1086 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1091 if (empty($dateinvoice)) {
1092 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1102 if (!
GETPOST(
'ref_supplier')) {
1103 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
1111 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1128 $object->date_echeance = $datedue;
1134 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1135 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1137 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1138 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1143 if (empty(
$object->date_echeance)) {
1144 $object->date_echeance =
$object->calculate_date_lim_reglement();
1150 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
1152 $element = $subelement =
GETPOST(
'origin',
'alpha');
1160 if ($element ==
'order') {
1161 $element = $subelement =
'commande';
1163 if ($element ==
'propal') {
1164 $element =
'comm/propal';
1165 $subelement =
'propal';
1167 if ($element ==
'contract') {
1168 $element = $subelement =
'contrat';
1170 if ($element ==
'order_supplier') {
1172 $subelement =
'fournisseur.commande';
1174 if ($element ==
'project') {
1175 $element =
'projet';
1182 $classname = ucfirst($subelement);
1183 if ($classname ==
'Fournisseur.commande') {
1184 $classname =
'CommandeFournisseur';
1186 $objectsrc =
new $classname($db);
1187 $objectsrc->fetch($originid);
1188 $objectsrc->fetch_thirdparty();
1195 if (
$object->origin ==
'reception') {
1196 $objectsrc->fetchObjectLinked();
1198 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1199 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1200 $object->linkedObjectsIds[
'order_supplier'] = $value;
1210 $classname = ucfirst($subelement);
1211 if ($classname ==
'Fournisseur.commande') {
1212 $classname =
'CommandeFournisseur';
1214 $srcobject =
new $classname($db);
1216 $result = $srcobject->fetch(
GETPOSTINT(
'originid'));
1219 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1224 $amountdeposit = array();
1226 if ($typeamount ==
'amount') {
1227 $amount = $valuedeposit;
1229 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1232 $TTotalByTva = array();
1233 foreach ($srcobject->lines as &$line) {
1234 if (!empty($line->special_code)) {
1237 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1239 '@phan-var-force array<string,float> $TTotalByTva';
1241 $amount_ttc_diff = 0.;
1242 foreach ($TTotalByTva as $tva => &$total) {
1243 $coef = $total / $srcobject->total_ttc;
1244 $am = $amount * $coef;
1245 $amount_ttc_diff += $am;
1246 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1249 if ($typeamount ==
'amount') {
1250 $amountdeposit[0] = $valuedeposit;
1251 } elseif ($typeamount ==
'variable') {
1254 $lines = $srcobject->lines;
1255 $numlines = count($lines);
1256 for ($i = 0; $i < $numlines; $i++) {
1258 if (empty($lines[$i]->qty)) {
1261 if (!empty($lines[$i]->special_code)) {
1265 $totalamount += $lines[$i]->total_ht;
1266 $tva_tx = $lines[$i]->tva_tx;
1267 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1271 if ($totalamount == 0) {
1272 $amountdeposit[0] = 0;
1277 $amountdeposit[0] = 0;
1281 $amount_ttc_diff = array_key_exists(0, $amountdeposit) ? $amountdeposit[0] : 0;
1284 foreach ($amountdeposit as $tva => $amount) {
1285 if (empty($amount)) {
1290 'amount' =>
'FixAmount',
1291 'variable' =>
'VarAmount'
1293 $descline =
'(DEPOSIT)';
1295 if ($typeamount ==
'amount') {
1296 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1297 } elseif ($typeamount ==
'variable') {
1298 $descline .=
' ('.$valuedeposit.
'%)';
1301 $descline .=
' - '.$srcobject->ref;
1331 $diff =
$object->total_ttc - $amount_ttc_diff;
1335 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1341 $object->lines[0]->localtax1_tx,
1342 $object->lines[0]->localtax2_tx,
1344 $object->lines[0]->fk_product,
1347 $object->lines[0]->product_type,
1348 $object->lines[0]->remise_percent,
1350 $object->lines[0]->date_start,
1359 } elseif ($result > 0) {
1360 $lines = $srcobject->lines;
1361 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1362 $srcobject->fetch_lines();
1363 $lines = $srcobject->lines;
1366 $num = count($lines);
1367 for ($i = 0; $i < $num; $i++) {
1368 if (!in_array($lines[$i]->
id, $selectedLines)) {
1372 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->product_label);
1373 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1376 if (method_exists($lines[$i],
'fetch_optionals')) {
1377 $lines[$i]->fetch_optionals();
1382 $date_start = $lines[$i]->date_debut_prevue;
1383 if ($lines[$i]->date_debut_reel) {
1384 $date_start = $lines[$i]->date_debut_reel;
1386 if ($lines[$i]->date_start) {
1387 $date_start = $lines[$i]->date_start;
1389 $date_end = $lines[$i]->date_fin_prevue;
1390 if ($lines[$i]->date_fin_reel) {
1391 $date_end = $lines[$i]->date_fin_reel;
1393 if ($lines[$i]->date_end) {
1394 $date_end = $lines[$i]->date_end;
1397 $tva_tx = $lines[$i]->tva_tx;
1399 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
1400 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1404 $object->special_code = $lines[$i]->special_code;
1409 $pu_currency = $lines[$i]->multicurrency_subprice;
1411 $pu = $lines[$i]->subprice;
1420 $lines[$i]->localtax1_tx,
1421 $lines[$i]->localtax2_tx,
1423 $lines[$i]->fk_product,
1424 $lines[$i]->remise_percent,
1428 $lines[$i]->info_bits,
1433 $lines[$i]->array_options,
1434 $lines[$i]->fk_unit,
1437 $lines[$i]->ref_supplier,
1438 $lines[$i]->special_code
1455 $parameters = array(
'objFrom' => $srcobject);
1456 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
1466 } elseif (!$error) {
1476 $langs->load(
"errors");
1483 if (isModEnabled(
'category')) {
1484 $categories =
GETPOST(
'categories',
'array');
1485 if (method_exists(
$object,
'setCategories')) {
1486 $object->setCategories($categories);
1493 $outputlangs = $langs;
1494 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1501 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1504 } elseif ($action ==
'updateline' && $usercancreate) {
1508 if (!
$object->fetch($id) > 0) {
1514 $tva_tx = str_replace(
'*',
'', $tva_tx);
1516 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_subprice') !=
'') {
1518 $price_base_type =
'HT';
1521 $price_base_type =
'TTC';
1524 if (
GETPOST(
'productid') > 0) {
1526 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY') == 1) {
1528 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1534 $label = $prod->description;
1535 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1536 $label =
GETPOST(
'product_desc',
'restricthtml');
1539 $type = $prod->type;
1541 $label =
GETPOST(
'product_desc',
'restricthtml');
1550 if (preg_match(
'/\*/', $tva_tx)) {
1555 $tva_tx = str_replace(
'*',
'', $tva_tx);
1563 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1564 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1566 if (is_array($extralabelsline)) {
1567 foreach ($extralabelsline as $key => $value) {
1568 unset($_POST[
"options_".$key]);
1572 $result =
$object->updateline(
1584 (
float) $remise_percent,
1594 unset($_POST[
'label']);
1595 unset($_POST[
'fourn_ref']);
1596 unset($_POST[
'date_starthour']);
1597 unset($_POST[
'date_startmin']);
1598 unset($_POST[
'date_startsec']);
1599 unset($_POST[
'date_startday']);
1600 unset($_POST[
'date_startmonth']);
1601 unset($_POST[
'date_startyear']);
1602 unset($_POST[
'date_endhour']);
1603 unset($_POST[
'date_endmin']);
1604 unset($_POST[
'date_endsec']);
1605 unset($_POST[
'date_endday']);
1606 unset($_POST[
'date_endmonth']);
1607 unset($_POST[
'date_endyear']);
1608 unset($_POST[
'price_ttc']);
1609 unset($_POST[
'price_ht']);
1616 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
1620 foreach (
$object->lines as $line) {
1621 if ($line->product_type == 1) {
1622 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->qty, $line->fk_product,
'HT', $line->info_bits, $line->product_type, $line->remise_percent, 0, $alldate_start, $alldate_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier, $line->rang);
1625 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !=
'' && $usercancreate) {
1627 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1628 $vat_rate = str_replace(
'*',
'', $vat_rate);
1631 foreach (
$object->lines as $line) {
1632 $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);
1634 } elseif ($action ==
'addline' && $usercancreate) {
1643 $ret =
$object->fetch_thirdparty();
1645 $langs->load(
'errors');
1650 $line_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
1654 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1655 if ($prod_entry_mode ==
'free') {
1662 $price_ht_devise =
'';
1664 $price_ttc_devise =
'';
1666 if (
GETPOST(
'price_ht') !==
'') {
1669 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
1672 if (
GETPOST(
'price_ttc') !==
'') {
1675 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
1676 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
1683 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
1684 if (empty($remise_percent)) {
1685 $remise_percent = 0;
1689 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1690 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
1692 if (is_array($extralabelsline)) {
1694 foreach ($extralabelsline as $key => $value) {
1695 unset($_POST[
"options_".$key]);
1699 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
1700 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1703 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOST(
'type') < 0) {
1704 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
1709 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1')
1710 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
1711 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
1712 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
1713 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
1714 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
1715 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) {
1716 $langs->load(
"errors");
1717 if (
$object->type == $object::TYPE_DEPOSIT) {
1719 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
1721 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPrice"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
1726 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
1727 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
1731 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') && !
GETPOST(
'dp_desc')) {
1732 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
1735 if (!
GETPOST(
'qty',
'alpha')) {
1736 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1740 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
1741 if ($combinations =
GETPOST(
'combinations',
'array')) {
1745 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1746 $idprod = $res->fk_product_child;
1748 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
1754 if ($prod_entry_mode !=
'free' && empty($error)) {
1758 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
1763 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
1764 $idprod = (int) $reg[1];
1765 $res = $productsupplier->fetch($idprod);
1768 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
1770 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1771 if ($productsupplier->fourn_socid != $socid) {
1772 $productsupplier->ref_supplier =
'';
1775 $fksoctosearch =
$object->thirdparty->id;
1776 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1778 } elseif (
GETPOSTINT(
'idprodfournprice') > 0) {
1779 $qtytosearch = (float) $qty;
1781 $idprod = $productsupplier->get_buyprice(
GETPOSTINT(
'idprodfournprice'), $qtytosearch);
1782 $res = $productsupplier->fetch($idprod);
1786 $label = $productsupplier->label;
1789 $outputlangs = $langs;
1791 if (
GETPOST(
'lang_id',
'aZ09')) {
1792 $newlang =
GETPOST(
'lang_id',
'aZ09');
1794 if (empty($newlang)) {
1795 $newlang =
$object->thirdparty->default_lang;
1797 if (!empty($newlang)) {
1799 $outputlangs->setDefaultLang($newlang);
1801 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
1803 $desc = $productsupplier->description;
1806 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
1807 $desc = $productsupplier->desc_supplier;
1818 $ref_supplier = $productsupplier->ref_supplier;
1821 if (!GETPOSTISSET(
'tva_tx')) {
1822 $tmpidprodfournprice =
GETPOST(
'idprodfournprice',
'alpha');
1823 if (is_numeric($tmpidprodfournprice) && (
int) $tmpidprodfournprice > 0) {
1824 $tmpidprodfournprice = (int) $tmpidprodfournprice;
1826 $tmpidprodfournprice = 0;
1832 if (empty($tva_tx) || empty($tva_npr)) {
1838 $type = $productsupplier->type;
1839 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1840 $price_base_type =
'HT';
1842 $pu_devise =
price2num($price_ht_devise,
'CU');
1843 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
1844 $price_base_type =
'TTC';
1846 $pu_devise =
price2num($price_ttc_devise,
'CU');
1848 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
1849 if (empty(
$object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code !=
$object->multicurrency_code)) {
1850 $pu = $productsupplier->fourn_pu;
1853 $pu = $productsupplier->fourn_pu;
1854 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
1858 $ref_supplier = $productsupplier->ref_supplier;
1879 min($rank, count(
$object->lines) + 1),
1882 $productsupplier->fk_unit,
1885 GETPOST(
'fourn_ref',
'alpha'),
1889 if ($idprod == -99 || $idprod == 0) {
1892 $langs->load(
"errors");
1893 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
1895 if ($idprod == -1) {
1898 $langs->load(
"errors");
1899 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
1901 } elseif (empty($error)) {
1902 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1903 $tva_tx = str_replace(
'*',
'', $tva_tx);
1904 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1907 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
1911 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1919 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1923 $pu_ht =
price2num((
float) $pu_ttc / (1 + ((
float) $tva_tx / 100)),
'MU');
1925 $price_base_type =
'HT';
1926 $pu_devise =
price2num($price_ht_devise,
'CU');
1928 $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);
1932 if (!$error && $result > 0) {
1937 $outputlangs = $langs;
1940 $newlang =
GETPOST(
'lang_id',
'aZ09');
1943 $newlang =
$object->thirdparty->default_lang;
1945 if (!empty($newlang)) {
1947 $outputlangs->setDefaultLang($newlang);
1952 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1958 unset($_POST [
'prod_entry_mode']);
1960 unset($_POST[
'qty']);
1961 unset($_POST[
'type']);
1962 unset($_POST[
'remise_percent']);
1963 unset($_POST[
'pu']);
1964 unset($_POST[
'price_ht']);
1965 unset($_POST[
'multicurrency_price_ht']);
1966 unset($_POST[
'price_ttc']);
1967 unset($_POST[
'fourn_ref']);
1968 unset($_POST[
'tva_tx']);
1969 unset($_POST[
'label']);
1970 unset($localtax1_tx);
1971 unset($localtax2_tx);
1972 unset($_POST[
'np_marginRate']);
1973 unset($_POST[
'np_markRate']);
1974 unset($_POST[
'dp_desc']);
1975 unset($_POST[
'idprodfournprice']);
1976 unset($_POST[
'units']);
1978 unset($_POST[
'date_starthour']);
1979 unset($_POST[
'date_startmin']);
1980 unset($_POST[
'date_startsec']);
1981 unset($_POST[
'date_startday']);
1982 unset($_POST[
'date_startmonth']);
1983 unset($_POST[
'date_startyear']);
1984 unset($_POST[
'date_endhour']);
1985 unset($_POST[
'date_endmin']);
1986 unset($_POST[
'date_endsec']);
1987 unset($_POST[
'date_endday']);
1988 unset($_POST[
'date_endmonth']);
1989 unset($_POST[
'date_endyear']);
1996 } elseif ($action ==
'classin' && $usercancreate) {
1998 $result =
$object->setProject($projectid);
1999 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
2003 $totalpaid =
$object->getSommePaiement();
2004 $resteapayer =
$object->total_ttc - $totalpaid;
2007 $ventilExportCompta =
$object->getVentilExportCompta();
2009 if (!$ventilExportCompta) {
2012 $idwarehouse =
GETPOST(
'idwarehouse');
2016 $qualified_for_stock_change = 0;
2018 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2020 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2024 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
2025 $langs->load(
"stocks");
2026 if (!$idwarehouse || $idwarehouse == -1) {
2028 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
2033 $object->setDraft($user, $idwarehouse);
2037 $outputlangs = $langs;
2040 $newlang =
GETPOST(
'lang_id',
'aZ09');
2043 $newlang =
$object->thirdparty->default_lang;
2045 if (!empty($newlang)) {
2047 $outputlangs->setDefaultLang($newlang);
2052 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2061 } elseif ($action ==
'reopen' && $usercancreate) {
2063 $result =
$object->fetch($id);
2066 $result =
$object->setUnpaid($user);
2068 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
2077 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2080 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
2082 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
2083 $trackid =
'sinv'.$object->id;
2084 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2087 $upload_dir =
$conf->fournisseur->facture->dir_output;
2088 $permissiontoadd = $usercancreate;
2089 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2092 if ($action ==
'calculate' && $usercancreate) {
2093 $calculationrule =
GETPOST(
'calculationrule');
2097 $result =
$object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0,
$object->thirdparty);
2103 if ($action ==
'update_extras' && $permissiontoeditextra) {
2106 $attribute_name =
GETPOST(
'attribute',
'aZ09');
2109 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute_name);
2115 $result =
$object->updateExtraField($attribute_name,
'BILL_SUPPLIER_MODIFY');
2123 $action =
'edit_extras';
2128 if ($action ==
'addcontact' && $usercancreate) {
2129 $result =
$object->fetch($id);
2131 if ($result > 0 && $id > 0) {
2134 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2138 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2141 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2142 $langs->load(
"errors");
2143 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2148 } elseif ($action ==
'swapstatut' && $usercancreate) {
2155 } elseif ($action ==
'deletecontact' && $usercancreate) {
2161 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2175$form =
new Form($db);
2177$bankaccountstatic =
new Account($db);
2179if (isModEnabled(
'project')) {
2185$title =
$object->ref.
" - ".$langs->trans(
'Card');
2186if ($action ==
'create') {
2187 $title = $langs->trans(
"NewSupplierInvoice");
2189$help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
2190llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-fourn-facture page-card');
2193if ($action ==
'create') {
2195 $selectedLines = array();
2197 print
load_fiche_titre($langs->trans(
'NewSupplierInvoice'),
'',
'supplier_invoice');
2201 $currency_code =
$conf->currency;
2202 $vat_reverse_charge = 0;
2208 if (isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2209 $currency_code = $societe->multicurrency_code;
2213 if (!empty($origin) && !empty($originid)) {
2215 $element = $subelement = $origin;
2217 if ($element ==
'project') {
2218 $projectid = $originid;
2219 $element =
'projet';
2223 if ($element ==
'order') {
2224 $element = $subelement =
'commande';
2226 if ($element ==
'propal') {
2227 $element =
'comm/propal';
2228 $subelement =
'propal';
2230 if ($element ==
'contract') {
2231 $element = $subelement =
'contrat';
2233 if ($element ==
'order_supplier') {
2235 $subelement =
'fournisseur.commande';
2239 $classname = ucfirst($subelement);
2240 if ($classname ==
'Fournisseur.commande') {
2241 $classname =
'CommandeFournisseur';
2243 $objectsrc =
new $classname($db);
2244 '@phan-var-force Project|Commande|Propal|Facture|Contrat|CommandeFournisseur|CommonObject $objectsrc';
2245 $objectsrc->fetch($originid);
2246 $objectsrc->fetch_thirdparty();
2248 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
2250 $soc = $objectsrc->thirdparty;
2252 $cond_reglement_id = 0;
2253 $mode_reglement_id = 0;
2257 $transport_mode_id = 0;
2260 if (!empty($objectsrc->cond_reglement_id)) {
2261 $cond_reglement_id = $objectsrc->cond_reglement_id;
2263 if (!empty($objectsrc->mode_reglement_id)) {
2264 $mode_reglement_id = $objectsrc->mode_reglement_id;
2266 if (!empty($objectsrc->fk_account)) {
2267 $fk_account = $objectsrc->fk_account;
2269 if (!empty($objectsrc->transport_mode_id)) {
2270 $transport_mode_id = $objectsrc->transport_mode_id;
2273 if (empty($cond_reglement_id)
2274 || empty($mode_reglement_id)
2275 || empty($fk_account)
2276 || empty($transport_mode_id)
2278 if ($origin ==
'reception') {
2280 if (!isset($objectsrc->supplier_order)) {
2281 $objectsrc->fetch_origin();
2284 if (!empty($objectsrc->origin_object)) {
2285 $originObject = $objectsrc->origin_object;
2286 if (empty($cond_reglement_id) && !empty($originObject->cond_reglement_id)) {
2287 $cond_reglement_id = $originObject->cond_reglement_id;
2289 if (empty($mode_reglement_id) && !empty($originObject->mode_reglement_id)) {
2290 $mode_reglement_id = $originObject->mode_reglement_id;
2292 if (empty($fk_account) && !empty($originObject->fk_account)) {
2293 $fk_account = $originObject->fk_account;
2295 if (empty($transport_mode_id) && !empty($originObject->transport_mode_id)) {
2296 $transport_mode_id = $originObject->transport_mode_id;
2303 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
2304 $cond_reglement_id = $soc->cond_reglement_supplier_id;
2306 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
2307 $mode_reglement_id = $soc->mode_reglement_supplier_id;
2309 if (empty($fk_account) && !empty($soc->fk_account)) {
2310 $fk_account = $soc->fk_account;
2312 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
2313 $transport_mode_id = $soc->transport_mode_id;
2318 if (isModEnabled(
"multicurrency")) {
2319 if (!empty($objectsrc->multicurrency_code)) {
2320 $currency_code = $objectsrc->multicurrency_code;
2322 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
2323 $currency_tx = $objectsrc->multicurrency_tx;
2328 $dateinvoice = ($datetmp ==
'' ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $datetmp);
2330 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2333 $objectsrc->fetch_optionals();
2334 $object->array_options = $objectsrc->array_options;
2336 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2337 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2338 $vat_reverse_charge = (empty($societe) ?
'' : $societe->vat_reverse_charge);
2339 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2340 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2342 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalInt(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2344 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2346 if (isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2347 $currency_code = $societe->multicurrency_code;
2352 if (empty($cond_reglement_id)) {
2353 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2357 if (empty($mode_reglement_id)) {
2358 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2362 if (!
GETPOST(
'changecompany')) {
2363 if (GETPOSTISSET(
'cond_reglement_id')) {
2364 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
2366 if (GETPOSTISSET(
'mode_reglement_id')) {
2367 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
2369 if (GETPOSTISSET(
'cond_reglement_id')) {
2374 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
2375 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
2377 if ($origin ==
'contrat') {
2378 $langs->load(
"admin");
2379 $text = $langs->trans(
"ToCreateARecurringInvoice");
2380 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"SupplierBills"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
2382 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
2384 print
info_admin($text, 0, 0,
'0',
'opacitymedium').
'<br>';
2387 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2388 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2389 print
'<input type="hidden" name="action" value="add">';
2390 print
'<input type="hidden" name="changecompany" value="0">';
2392 if (!empty($societe->id) && $societe->id > 0) {
2393 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2395 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2396 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2397 if (!empty($currency_tx)) {
2398 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2400 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2405 $parameters = array();
2407 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierInvoice', $parameters,
$object, $action);
2408 if (empty($reshook)) {
2409 print
'<table class="border centpercent">';
2412 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
2416 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2417 $invoice_predefined->fetch($fac_recid);
2421 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2424 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2425 $absolute_discount = $societe->getAvailableDiscounts(
null,
'', 0, 1);
2426 print $societe->getNomUrl(1,
'supplier');
2427 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2429 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2430 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');
2433 print
'<script type="text/javascript">
2434 $(document).ready(function() {
2435 $("#socid").change(function() {
2436 console.log("We have changed the company - Reload page");
2438 $("input[name=action]").val("create");
2439 $("input[name=changecompany]").val("1");
2440 $("form[name=add]").submit();
2445 if ($fac_recid <= 0) {
2446 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>';
2452 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2453 $invoice_predefined->fetch($fac_recid);
2455 $dateinvoice = $invoice_predefined->date_when;
2456 if (empty($projectid)) {
2457 $projectid = $invoice_predefined->fk_project;
2459 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2460 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2461 $fk_account = $invoice_predefined->fk_account;
2462 $note_public = $invoice_predefined->note_public;
2463 $note_private = $invoice_predefined->note_private;
2465 if (!empty($invoice_predefined->multicurrency_code)) {
2466 $currency_code = $invoice_predefined->multicurrency_code;
2468 if (!empty($invoice_predefined->multicurrency_tx)) {
2469 $currency_tx = $invoice_predefined->multicurrency_tx;
2472 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2473 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2474 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2476 $resql = $db->query($sql);
2478 $num = $db->num_rows($resql);
2482 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2484 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2485 print
'<option value="0" selected></option>';
2487 $objp = $db->fetch_object($resql);
2488 print
'<option value="'.$objp->rowid.
'"';
2489 if ($fac_recid == $objp->rowid) {
2491 $exampletemplateinvoice->fetch($fac_recid);
2493 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2499 print
'<script type="text/javascript">
2500 $(document).ready(function() {
2501 $("#fac_rec").change(function() {
2502 console.log("We have changed the template invoice - Reload page");
2504 $("input[name=action]").val("create");
2505 $("form[name=add]").submit();
2519 print
'<tr><td class="fieldrequired">'.$langs->trans(
'RefSupplierBill').
'</td><td><input name="ref_supplier" value="'.(GETPOSTISSET(
'ref_supplier') ?
GETPOST(
'ref_supplier') : (!empty($objectsrc->ref_supplier) ? $objectsrc->ref_supplier :
'')).
'" type="text"';
2520 if (!empty($societe->id) && $societe->id > 0) {
2526 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2528 print
'<div class="tagtable">'.
"\n";
2531 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2532 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
'checked').
'> ';
2533 $desc = $form->textwithpicto($tmp.
'<label for="radio_standard">'.$langs->trans(
"InvoiceStandardAsk").
'</label>', $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2535 print
'</div></div>';
2537 if (empty($origin) || ($origin ==
'order_supplier' && !empty($originid))) {
2540 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2541 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOSTINT(
'type') == 3 ?
' checked' :
'') .
'> ';
2542 print
'<script type="text/javascript">
2543 jQuery(document).ready(function() {
2544 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2545 jQuery("#radio_standard").prop("checked", true);
2547 jQuery("#typedeposit, #valuedeposit").click(function() {
2548 jQuery("#radio_deposit").prop("checked", true);
2550 jQuery("#typedeposit").change(function() {
2551 console.log("We change type of down payment");
2552 jQuery("#radio_deposit").prop("checked", true);
2553 setRadioForTypeOfInvoice();
2555 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2556 setRadioForTypeOfInvoice();
2558 function setRadioForTypeOfInvoice() {
2559 console.log("Change radio");
2560 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2561 jQuery(".checkforselect").prop("disabled", true);
2562 jQuery(".checkforselect").prop("checked", false);
2564 jQuery(".checkforselect").prop("disabled", false);
2565 jQuery(".checkforselect").prop("checked", true);
2571 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2573 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2574 print
'<table class="nobordernopadding"><tr>';
2578 if ($origin ==
'order_supplier') {
2579 print
'<td class="nowrap" style="padding-left: 15px">';
2581 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2582 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2583 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2585 print $form->selectarray(
'typedeposit', $arraylist,
GETPOST(
'typedeposit',
'aZ09'), 0, 0, 0,
'', 1);
2587 print
'<td class="nowrap" style="padding-left: 5px">';
2588 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' .
GETPOSTINT(
'valuedeposit') .
'"/>';
2591 print
'</tr></table>';
2593 print
'</div></div>';
2662 if (empty($origin)) {
2663 if (!empty($societe->id) && $societe->id > 0) {
2667 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2674 foreach ($facids as $key => $valarray) {
2675 $newinvoice_static->id = $key;
2676 $newinvoice_static->ref = $valarray [
'ref'];
2677 $newinvoice_static->status = $valarray [
'status'];
2678 $newinvoice_static->statut = $valarray [
'status'];
2679 $newinvoice_static->type = $valarray [
'type'];
2680 $newinvoice_static->paid = $valarray [
'paye'];
2681 $newinvoice_static->paye = $valarray [
'paye'];
2683 $optionsav .=
'<option value="'.$key.
'"';
2685 $optionsav .=
' selected';
2688 $optionsav .= $newinvoice_static->ref;
2689 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
2690 $optionsav .=
'</option>';
2693 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2694 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
2696 $tmp .=
' disabled';
2700 print
'<script type="text/javascript">
2701 jQuery(document).ready(function() {
2702 if (! jQuery("#radio_creditnote").is(":checked"))
2704 jQuery("#credit_note_options").hide();
2706 jQuery("#radio_creditnote").click(function() {
2707 jQuery("#credit_note_options").show();
2709 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2710 jQuery("#credit_note_options").hide();
2714 $text = $tmp.
'<label for="radio_creditnote">'.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
2716 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2718 $text .=
' disabled';
2722 $text .=
'<option value="-1"></option>';
2723 $text .= $optionsav;
2725 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
2727 $text .=
'</select>';
2728 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2731 print
'<div id="credit_note_options" class="clearboth">';
2732 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' :
'').
' /> ';
2733 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
2734 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' :
'').
' /> ';
2735 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
2738 print
'</div></div>';
2741 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2743 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2745 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2"> ';
2747 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
2748 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
2749 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2751 print
'</div></div>'.
"\n";
2762 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
2763 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
2767 if (!empty($societe->id) && $societe->id > 0) {
2769 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2771 $thirdparty = $societe;
2773 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2774 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2780 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth200" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
2784 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
2785 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2786 print $form->selectDate($dateinvoice ? (
int) $dateinvoice :
'',
'', 0, 0, 0,
"add", 1, 1);
2790 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2791 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
2792 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth200 widthcentpercentminusx');
2796 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
2797 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2798 print $form->selectDate($datedue,
'ech', 0, 0, 0,
"add", 1, 1);
2802 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2803 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2804 $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'DBIT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
2808 if (isModEnabled(
"bank")) {
2809 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2811 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
2816 if (isModEnabled(
'project')) {
2819 $langs->load(
'projects');
2820 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2821 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');
2822 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>';
2827 if (isModEnabled(
'incoterm')) {
2829 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
2830 print
'<td colspan="3" class="maxwidthonsmartphone">';
2831 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2832 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 :
''));
2838 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
2839 print
'<tr><td>' . $langs->trans(
'VATReverseCharge') .
'</td><td>';
2841 if (GETPOSTISSET(
'vat_reverse_charge')) {
2842 $vat_reverse_charge = (
GETPOST(
'vat_reverse_charge',
'alpha') ==
'on' ||
GETPOST(
'vat_reverse_charge',
'alpha') ==
'1') ? 1 : 0;
2843 } elseif ($vat_reverse_charge == 1 || $societe->vat_reverse_charge == 1 || ($societe->country_code !=
'FR' &&
isInEEC($societe) && !empty($societe->tva_intra))) {
2844 $vat_reverse_charge = 1;
2846 $vat_reverse_charge = 0;
2849 print
'<input type="checkbox" name="vat_reverse_charge"'. (!empty($vat_reverse_charge) ?
' checked ' :
'') .
'>';
2854 if (isModEnabled(
"multicurrency")) {
2856 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0).
'</td>';
2857 print
'<td class="maxwidthonsmartphone">';
2858 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
2859 $used_currency_code = $currency_code;
2860 if (!
GETPOST(
'changecompany')) {
2861 $used_currency_code = GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code;
2863 print $form->selectMultiCurrency($used_currency_code,
'multicurrency_code');
2869 if ($fac_recid > 0) {
2870 $dateexample = $dateinvoice;
2871 if (empty($dateexample)) {
2874 $substitutionarray = array(
2875 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
2876 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
2877 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
2878 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
2879 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
2880 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
2881 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
2882 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
2883 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
2884 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
2885 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
2888 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
2889 foreach ($substitutionarray as $key => $val) {
2890 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
2892 $htmltext .=
'</i>';
2896 if (isModEnabled(
'intracommreport')) {
2897 $langs->loadLangs(array(
"intracommreport"));
2898 print
'<!-- If module intracomm on -->'.
"\n";
2899 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
2900 $form->selectTransportMode(GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
2904 if (empty($reshook)) {
2905 print
$object->showOptionals($extrafields,
'create');
2909 if (isModEnabled(
"category")) {
2910 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
2911 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories',
$object);
2916 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2918 $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%');
2919 print $doleditor->Create(1);
2925 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
2927 $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%');
2928 print $doleditor->Create(1);
2934 if (!empty($objectsrc) && is_object($objectsrc)) {
2935 print
"\n<!-- ".$classname.
" info -->";
2937 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2938 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2939 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2940 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2941 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2943 $txt = $langs->trans($classname);
2944 if ($classname ==
'CommandeFournisseur') {
2945 $langs->load(
'orders');
2946 $txt = $langs->trans(
"SupplierOrder");
2948 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
2950 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'invoice_supplier');
2952 if (isset($objectsrc->linkedObjects[
'invoice_supplier'])) {
2953 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
2955 $invoice_supplier = [];
2957 '@phan-var-force null|FactureFournisseur[] $invoice_supplier';
2960 if (is_array($invoice_supplier)) {
2961 $cntinvoice = count($invoice_supplier);
2963 if ($cntinvoice >= 1) {
2965 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
2970 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2971 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2972 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
2973 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2976 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
2977 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2979 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2981 if (isModEnabled(
"multicurrency")) {
2982 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
'</td></tr>';
2983 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
"</td></tr>";
2984 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
"</td></tr>";
2989 $parameters = array();
2990 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
2991 print $hookmanager->resPrint;
2999 print $form->buttonsSaveCancel(
"CreateDraft");
3002 if (!empty($objectsrc) && is_object($objectsrc)) {
3005 $title = $langs->trans(
'ProductsAndServices');
3008 print
'<div class="div-table-responsive-no-min">';
3009 print
'<table class="noborder centpercent">';
3011 $objectsrc->printOriginLinesList(
'', $selectedLines);
3019 if ($id > 0 || !empty($ref)) {
3025 $productstatic =
new Product($db);
3027 $result =
$object->fetch($id, $ref);
3032 $result =
$object->fetch_thirdparty();
3038 $societe =
$object->thirdparty;
3040 $totalpaid =
$object->getSommePaiement();
3041 $totalcreditnotes =
$object->getSumCreditNotesUsed();
3042 $totaldeposits =
$object->getSumDepositsUsed();
3050 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
3053 $multicurrency_resteapayer = 0;
3054 if (isModEnabled(
"multicurrency")) {
3055 $multicurrency_totalpaid =
$object->getSommePaiement(1);
3056 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
3057 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
3058 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
3062 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
3063 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
3070 $resteapayeraffiche = $resteapayer;
3073 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
3074 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
3076 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
3077 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
3080 $absolute_discount = $societe->getAvailableDiscounts(
null, $filterabsolutediscount, 0, 1);
3081 $absolute_creditnote = $societe->getAvailableDiscounts(
null, $filtercreditnote, 0, 1);
3082 $absolute_discount =
price2num($absolute_discount,
'MT');
3083 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
3087 $objectidnext =
$object->getIdReplacingInvoice();
3090 $titre = $langs->trans(
'SupplierInvoice');
3092 print
dol_get_fiche_head($head,
'card', $titre, -1,
'supplier_invoice', 0,
'',
'', 0,
'', 1);
3097 if ($action ==
'converttoreduc') {
3100 $type_fac =
'ExcessPaid';
3102 $type_fac =
'CreditNote';
3104 $type_fac =
'Deposit';
3106 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
3107 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
3108 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
3112 if ($action ==
'clone') {
3114 $formquestion = array(
3115 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplierBill"),
'value' => $langs->trans(
"CopyOf").
' '.
$object->ref_supplier),
3116 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
3119 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
3123 if ($action ==
'valid') {
3125 if (preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) {
3127 $numref =
$object->getNextNumRef($societe);
3136 $text = $langs->trans(
'ConfirmValidateBill', $numref);
3144 $formquestion = array();
3146 $qualified_for_stock_change = 0;
3148 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3150 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3153 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
3154 $langs->load(
"stocks");
3155 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3158 $warehouse_array = $warehouse->list_array();
3159 if (count($warehouse_array) == 1) {
3161 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3164 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3166 $formquestion = array(
3167 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3171 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
3176 if ($action ==
'edit') {
3177 $formquestion = array();
3179 $qualified_for_stock_change = 0;
3181 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3183 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3185 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
3186 $langs->load(
"stocks");
3187 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3190 $warehouse_array = $warehouse->list_array();
3191 if (count($warehouse_array) == 1) {
3193 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3196 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3198 $formquestion = array(
3199 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3202 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill',
$object->ref),
'confirm_edit', $formquestion, 1, 1);
3206 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
3207 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'', 0, 1);
3210 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
3214 $close[$i][
'code'] =
'discount_vat';
3216 $close[$i][
'code'] =
'badsupplier';
3218 $close[$i][
'code'] =
'other';
3222 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
3224 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3226 $close[$i][
'label'] = $langs->trans(
"Other");
3230 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3232 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3234 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
3237 $arrayreasons = array();
3238 foreach ($close as $key => $val) {
3239 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
3243 $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'));
3245 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
3249 if ($action ==
'canceled') {
3251 $close[1][
'code'] =
'badsupplier';
3252 $close[2][
'code'] =
'abandon';
3254 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3255 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
3257 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier",
$object->ref), $close[1][
'label'], 1);
3258 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
3260 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
3261 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
3264 $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'));
3266 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 280);
3270 if ($action ==
'delete') {
3271 $formquestion = array();
3273 $qualified_for_stock_change = 0;
3275 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3277 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3280 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
3281 $langs->load(
"stocks");
3282 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3285 $warehouse_array = $warehouse->list_array();
3287 $selectwarehouse =
'<span class="questionrevertstock hidden">';
3288 if (count($warehouse_array) == 1) {
3290 $selectwarehouse .=
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3293 $selectwarehouse .= $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3295 $selectwarehouse .=
'</span>';
3297 $selectyesno = array(0 => $langs->trans(
'No'), 1 => $langs->trans(
'Yes'));
3299 print
'<script type="text/javascript">
3300 $(document).ready(function() {
3301 $("#revertstock").change(function() {
3302 if(this.value > 0) {
3303 $(".questionrevertstock").removeClass("hidden");
3305 $(".questionrevertstock").addClass("hidden");
3311 $formquestion = array(
3312 array(
'type' =>
'select',
'name' =>
'revertstock',
'label' => $langs->trans(
"RevertProductsToStock"),
'select_show_empty' => 0,
'values' => $selectyesno),
3313 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $selectwarehouse,
'tdclass' =>
'questionrevertstock hidden')
3317 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete', $formquestion, 1, 1);
3319 if ($action ==
'deletepayment') {
3320 $payment_id =
GETPOST(
'paiement_id');
3321 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
3325 if ($action ==
'ask_deleteline') {
3326 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
3329 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
3330 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
3331 if (empty($reshook)) {
3332 $formconfirm .= $hookmanager->resPrint;
3333 } elseif ($reshook > 0) {
3334 $formconfirm = $hookmanager->resPrint;
3342 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
3344 $morehtmlref =
'<div class="refidno">';
3346 $morehtmlref .= $form->editfieldkey(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier,
$object, (
int) $usercancreate,
'string',
'', 0, 1);
3347 $morehtmlref .= $form->editfieldval(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier,
$object, $usercancreate,
'string',
'',
null,
null,
'', 1);
3349 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'supplier');
3351 $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>';
3354 if (isModEnabled(
'project')) {
3355 $langs->load(
"projects");
3356 $morehtmlref .=
'<br>';
3357 if ($permissiontoadd) {
3358 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
3359 if ($action !=
'classify') {
3360 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.((int)
$object->id).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
3362 $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');
3364 if (!empty(
$object->fk_project)) {
3366 $proj->fetch(
$object->fk_project);
3367 $morehtmlref .= $proj->getNomUrl(1);
3369 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
3374 $morehtmlref .=
'</div>';
3376 $object->totalpaid = $totalpaid;
3378 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
3381 $parameters = array();
3383 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierInvoice', $parameters,
$object, $action);
3384 if (empty($reshook)) {
3385 print
'<div class="fichecenter">';
3386 print
'<div class="fichehalfleft">';
3387 print
'<div class="underbanner clearboth"></div>';
3389 print
'<table class="border tableforfield centpercent">';
3392 print
'<tr><td class="titlefield">'.$langs->trans(
'Type').
'</td><td>';
3393 print
'<span class="badgeneutral">';
3397 print
' '.$object->getSubtypeLabel(
'facture_fourn');
3401 $facreplaced->fetch(
$object->fk_facture_source);
3402 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
3405 if (
$object->fk_facture_source > 0) {
3407 $facusing->fetch(
$object->fk_facture_source);
3408 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
3410 $langs->load(
"errors");
3411 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"WarningCorrectedInvoiceNotFound").
'</span>';
3416 $object->getListIdAvoirFromInvoice();
3418 if (!empty(
$object->creditnote_ids)) {
3419 $invoicecredits = array();
3420 foreach (
$object->creditnote_ids as $invoiceid) {
3422 $creditnote->fetch($invoiceid);
3423 $invoicecredits[] = $creditnote->getNomUrl(1);
3425 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
3428 if (isset($objectidnext) && $objectidnext > 0) {
3431 $facthatreplace->fetch($objectidnext);
3432 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
3436 $result = $discount->fetch(0, 0,
$object->id);
3438 print
' <span class="opacitymediumbycolor paddingleft">';
3439 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
3440 $s = str_replace(
'{s1}',
$object->getLibType(1), $s);
3441 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
3443 print
'</span><br>';
3447 if (
$object->fk_fac_rec_source > 0) {
3449 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
3451 print
' <span class="opacitymediumbycolor paddingleft">';
3452 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->title).
'</a>';
3453 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
3463 print
'<!-- Discounts -->'.
"\n";
3464 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
3467 $thirdparty = $societe;
3469 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3475 print
'<td>'.$form->editfieldkey(
"Label",
'label',
$object->label,
$object, (
int) $usercancreate).
'</td>';
3476 print
'<td>'.$form->editfieldval(
"Label",
'label',
$object->label,
$object, $usercancreate).
'</td>';
3484 print $form->editfieldkey(
"DateInvoice",
'datef', (
string)
$object->date,
$object, (int) $form_permission,
'datepicker');
3485 print
'</td><td colspan="3">';
3486 print $form->editfieldval(
"Date",
'datef',
$object->date,
$object, $form_permission,
'datepicker');
3490 $langs->load(
'bills');
3491 print
'<tr><td class="nowrap">';
3492 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3493 print $langs->trans(
'PaymentConditions');
3495 if ($action !=
'editconditions' && $form_permission) {
3496 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>';
3498 print
'</tr></table>';
3500 if ($action ==
'editconditions') {
3501 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
3503 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
3510 print $form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', (
string)
$object->date_echeance,
$object, (
int) $form_permission,
'datepicker');
3512 print $form->editfieldval(
"DateMaxPayment",
'date_lim_reglement',
$object->date_echeance,
$object, $form_permission,
'datepicker');
3513 if ($action !=
'editdate_lim_reglement' &&
$object->hasDelay()) {
3519 $langs->load(
'bills');
3520 print
'<tr><td class="nowrap">';
3521 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3522 print $langs->trans(
'PaymentMode');
3524 if ($action !=
'editmode' && $form_permission) {
3525 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>';
3527 print
'</tr></table>';
3529 if ($action ==
'editmode') {
3530 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3532 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'none');
3537 if (isModEnabled(
"bank")) {
3538 print
'<tr><td class="nowrap">';
3539 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3540 print $langs->trans(
'BankAccount');
3542 if ($action !=
'editbankaccount' && $usercancreate) {
3543 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>';
3545 print
'</tr></table>';
3547 if ($action ==
'editbankaccount') {
3548 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
3550 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
3558 print
'<tr><td class="nowrap">';
3559 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3560 print $langs->trans(
'VATReverseCharge');
3562 if ($action !=
'editvatreversecharge' && $usercancreate) {
3563 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editvatreversecharge&id='.
$object->id.
'">'.
img_edit($langs->trans(
'SetVATReverseCharge'), 1).
'</a></td>';
3565 print
'</tr></table>';
3567 if ($action ==
'editvatreversecharge') {
3568 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
3569 print
'<input type="hidden" name="action" value="setvatreversecharge">';
3570 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3572 print
'<input type="checkbox" name="vat_reverse_charge"' . (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
'>';
3574 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
3577 print
'<input type="checkbox" name="vat_reverse_charge"'. (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
' disabled>';
3583 if (isModEnabled(
'incoterm')) {
3585 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3586 print $langs->trans(
'IncotermLabel');
3587 print
'<td><td class="right">';
3588 if ($usercancreate) {
3589 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
3593 print
'</td></tr></table>';
3596 if ($action !=
'editincoterm') {
3597 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
3599 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
3605 if (isModEnabled(
'intracommreport')) {
3606 $langs->loadLangs(array(
"intracommreport"));
3607 print
'<!-- If module intracomm on -->'.
"\n";
3609 print
'<table class="nobordernopadding centpercent"><tr><td>';
3610 print $langs->trans(
'IntracommReportTransportMode');
3612 if ($action !=
'edittransportmode' && ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"))) {
3613 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edittransportmode&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit().
'</a></td>';
3615 print
'</tr></table>';
3618 if ($action ==
'edittransportmode') {
3619 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'transport_mode_id', 1, 1);
3621 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'none');
3627 if (isModEnabled(
'category')) {
3629 print
'<table class="nobordernopadding centpercent"><tr><td>';
3630 print $langs->trans(
"Categories");
3631 print
'<td><td class="right">';
3632 if ($usercancreate) {
3633 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
3637 print
'</td></tr></table>';
3640 if ($action ==
'edittags') {
3641 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
3642 print
'<input type="hidden" name="action" value="settags">';
3643 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3644 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories',
$object);
3645 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
3648 print $form->showCategories(
$object->id, Categorie::TYPE_SUPPLIER_INVOICE, 1);
3656 if (
$object->status != $object::STATUS_DRAFT) {
3660 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
3665 print
'<div class="fichehalfright">';
3666 print
'<div class="underbanner clearboth"></div>';
3668 print
'<table class="border tableforfield centpercent">';
3670 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
3673 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
3674 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3675 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
3676 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3681 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
3682 print
'<td class="nowrap amountcard right">';
3683 if (
GETPOST(
'calculationrule')) {
3684 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
3686 $calculationrule = (!
getDolGlobalString(
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND_SUPPLIER') ?
'totalofround' :
'roundoftotal');
3688 if ($calculationrule ==
'totalofround') {
3689 $calculationrulenum = 1;
3691 $calculationrulenum = 2;
3694 if (
$object->getVentilExportCompta() == 0) {
3695 $s =
'<span class="hideonsmartphone opacitymedium">' . $langs->trans(
"ReCalculate") .
' </span>';
3696 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=totalofround">' . $langs->trans(
"Mode1") .
'</a>';
3698 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=roundoftotal">' . $langs->trans(
"Mode2") .
'</a>';
3699 print
'<div class="inline-block">';
3700 print $form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum) .
'<br>' . $langs->trans(
"CalculationRuleDescSupplier"), 2, 1,
img_picto(
'',
'help'),
'', 3,
'', 0,
'recalculate');
3701 print
' ';
3704 print
'<span class="nowraponall">'.price(
$object->total_tva, 1, $langs, 0, -1, -1,
$conf->currency).
'</span>';
3706 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
3707 print
'<td class="nowraponall amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3711 if ($societe->localtax1_assuj ==
"1") {
3713 print
'<td>' . $langs->transcountry(
"AmountLT1", $societe->country_code) .
'</td>';
3714 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3717 if ($societe->localtax2_assuj ==
"1") {
3719 print
'<td>' . $langs->transcountry(
"AmountLT2", $societe->country_code) .
'</td>';
3720 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3725 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
3726 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3727 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
3728 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3746 if (isModEnabled(
'project')) {
3749 if (isModEnabled(
"bank")) {
3753 if (isModEnabled(
'incoterm')) {
3756 if (isModEnabled(
"multicurrency")) {
3761 if ($societe->localtax1_assuj ==
"1") {
3764 if ($societe->localtax2_assuj ==
"1") {
3768 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
3769 $sql .=
' c.id as payment_type, c.code as payment_code,';
3770 $sql .=
' pf.amount,';
3771 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
3772 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
3773 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
3774 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
3775 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
3776 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
3777 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
3778 $sql .=
' ORDER BY p.datep, p.tms';
3780 $result = $db->query($sql);
3782 $num = $db->num_rows($result);
3785 print
'<div class="div-table-responsive-no-min">';
3786 print
'<table class="noborder paymenttable centpercent">';
3787 print
'<tr class="liste_titre">';
3789 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
3790 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
3791 if (isModEnabled(
"bank")) {
3792 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
3794 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
3795 print
'<td width="18"> </td>';
3800 $objp = $db->fetch_object($result);
3802 $paymentstatic->id = $objp->rowid;
3803 $paymentstatic->datepaye = $db->jdate($objp->dp);
3804 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
3805 $paymentstatic->num_payment = $objp->num_payment;
3807 $paymentstatic->paiementcode = $objp->payment_code;
3808 $paymentstatic->type_code = $objp->payment_code;
3809 $paymentstatic->type_label = $objp->payment_type;
3811 print
'<tr class="oddeven">';
3812 print
'<td class="nowraponall">';
3813 print $paymentstatic->getNomUrl(1);
3815 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
'</td>';
3816 $s = $form->form_modes_reglement(
'', $objp->payment_type,
'none',
'', 1, 0,
'', 1).
' '.$objp->num_payment;
3817 print
'<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).
'">';
3820 if (isModEnabled(
"bank")) {
3821 $bankaccountstatic->id = $objp->baid;
3822 $bankaccountstatic->ref = $objp->baref;
3823 $bankaccountstatic->label = $objp->baref;
3824 $bankaccountstatic->number = $objp->banumber;
3826 if (isModEnabled(
'accounting')) {
3827 $bankaccountstatic->account_number = $objp->account_number;
3830 $accountingjournal->fetch($objp->fk_accountancy_journal);
3831 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
3834 print
'<td class="right">';
3835 if ($objp->baid > 0) {
3836 print $bankaccountstatic->getNomUrl(1,
'transactions');
3840 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
3841 print
'<td class="center">';
3843 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
3849 $totalpaid += $objp->amount;
3853 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td><td></td><td></td></tr>';
3876 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3877 print
'<span class="opacitymedium">';
3879 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
3881 print $langs->trans(
'AlreadyPaid');
3884 print
'</td><td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td><td> </td></tr>';
3887 $resteapayeraffiche = $resteapayer;
3889 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
3892 $creditnoteamount = 0;
3895 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
3896 $sql .=
" re.description, re.fk_invoice_supplier_source";
3897 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
3898 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
3899 $resql = $db->query($sql);
3901 $num = $db->num_rows($resql);
3905 $obj = $db->fetch_object($resql);
3906 $invoice->fetch($obj->fk_invoice_supplier_source);
3907 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3909 print $langs->trans(
"CreditNote").
' ';
3912 print $langs->trans(
"Deposit").
' ';
3914 print $invoice->getNomUrl(0);
3916 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
3917 print
'<td class="right">';
3918 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&discountid='.$obj->rowid.
'">';
3919 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
3924 $creditnoteamount += $obj->amount_ttc;
3927 $depositamount += $obj->amount_ttc;
3936 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3937 print
'<span class="opacitymedium">';
3938 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
3940 print
'</td><td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3941 $resteapayeraffiche = 0;
3942 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3946 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3947 print
'<span class="opacitymedium">';
3948 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
3950 print
'</td><td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3952 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3956 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3957 print
'<span class="opacitymedium">';
3958 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
3960 print
'</td><td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3961 $resteapayeraffiche = 0;
3962 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3966 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3967 $text = $langs->trans(
"HelpAbandonOther");
3969 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
3971 print
'<span class="opacitymedium">';
3973 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
3975 print
'</td><td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3976 $resteapayeraffiche = 0;
3977 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3981 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3982 print
'<span class="opacitymedium">';
3983 print $langs->trans(
"Billed");
3985 print
'</td><td class="right">'.price(
$object->total_ttc).
'</td><td> </td></tr>';
3988 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3989 print
'<span class="opacitymedium">';
3990 print $langs->trans(
'RemainderToPay');
3991 if ($resteapayeraffiche < 0) {
3992 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3996 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
3999 if (isModEnabled(
'multicurrency') &&
$object->multicurrency_code !=
$conf->currency ||
$object->multicurrency_tx != 1) {
4000 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4001 print
'<span class="opacitymedium">';
4002 print $langs->trans(
'RemainderToPayMulticurrency');
4003 if ($resteapayeraffiche < 0) {
4004 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4008 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price(
price2num($multicurrency_resteapayer,
'MT'), 0, $langs, 1, -1, -1,
$object->multicurrency_code).
'</td><td> </td></tr>';
4011 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4014 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4015 print $langs->trans(
'AlreadyPaidBack');
4016 print
' :</td><td class="right">'.price($sign * $totalpaid).
'</td><td> </td></tr>';
4019 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"Billed").
' :</td><td class="right">'.
price($sign *
$object->total_ttc).
'</td><td> </td></tr>';
4022 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4023 print
'<span class="opacitymedium">';
4024 print $langs->trans(
'RemainderToPayBack');
4025 if ($resteapayeraffiche > 0) {
4026 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4030 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td><td> </td></tr>';
4033 if (isModEnabled(
'multicurrency') &&
$object->multicurrency_code !=
$conf->currency ||
$object->multicurrency_tx != 1) {
4034 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4035 print
'<span class="opacitymedium">';
4036 print $langs->trans(
'RemainderToPayBackMulticurrency');
4037 if ($resteapayeraffiche > 0) {
4038 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4042 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.(!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency).
' '.
price(
price2num($sign *
$object->multicurrency_tx * $resteapayeraffiche,
'MT')).
'</td><td> </td></tr>';
4057 print
'<div class="clearboth"></div><br>';
4060 $blocname =
'contacts';
4061 $title = $langs->trans(
'ContactsAddresses');
4062 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4067 $blocname =
'notes';
4068 $title = $langs->trans(
'Notes');
4069 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4076 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
4077 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4078 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
4079 print
'<input type="hidden" name="mode" value="">';
4080 print
'<input type="hidden" name="page_y" value="">';
4081 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
4082 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
4083 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4086 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
4089 print
'<div class="div-table-responsive-no-min">';
4090 print
'<table id="tablelines" class="noborder noshadow centpercent">';
4092 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
4095 $inputalsopricewithtax = 1;
4096 $senderissupplier = 2;
4097 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY')) {
4098 $senderissupplier =
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY');
4103 $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
4110 if ($action !=
'editline') {
4113 $parameters = array();
4114 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
4118 if (empty($reshook)) {
4119 $object->formAddObjectLine(1, $societe, $mysoc);
4132 if ($action !=
'presend') {
4135 print
'<div class="tabsAction">';
4137 $parameters = array();
4138 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
4140 if (empty($reshook)) {
4144 $ventilExportCompta =
$object->getVentilExportCompta();
4146 if ($ventilExportCompta == 0) {
4147 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=edit&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
4149 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
4154 $result = $discount->fetch(0, 0,
$object->id);
4161 if (!$objectidnext &&
$object->close_code !=
'replaced' && $usercancreate) {
4162 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
4164 if ($usercancreate) {
4165 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
4167 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
4177 if ($usercanvalidate) {
4178 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken().
'"';
4179 print
'>'.$langs->trans(
'Validate').
'</a>';
4181 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
4182 print
'>'.$langs->trans(
'Validate').
'</a>';
4188 if (empty($user->socid)) {
4191 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
4193 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'SendMail').
'</span>';
4200 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" 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>';
4207 if ($resteapayer == 0) {
4208 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
4210 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>';
4216 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
4220 && (
getDolGlobalString(
'SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') ||
$object->getSommePaiement() == 0)
4222 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>';
4226 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
4237 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaid').
'</a>';
4242 if ($totalpaid > 0 || $totalcreditnotes > 0) {
4244 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
4247 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=canceled&token='.
newToken().
'">'.$langs->trans(
'ClassifyCanceled').
'</a>';
4259 if (!$objectidnext) {
4260 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>';
4265 if ($action !=
'edit' && $usercancreate) {
4266 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=clone&socid='.
$object->socid.
'&token='.
newToken().
'">'.$langs->trans(
'ToClone').
'</a>';
4271 if (!$objectidnext && count(
$object->lines) > 0) {
4272 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.
$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
4277 if ($action !=
'confirm_edit' && $usercandelete) {
4278 $isErasable =
$object->is_erasable();
4280 $enableDelete =
false;
4282 $params = (empty(
$conf->use_javascript_ajax) ? array() : array(
'attr' => array(
'class' =>
'reposition')));
4284 if ($isErasable == -4) {
4285 $htmltooltip = $langs->trans(
"DisabledBecausePayments");
4286 } elseif ($isErasable == -3) {
4287 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastSituationInvoice");
4288 } elseif ($isErasable == -2) {
4289 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastInvoice");
4290 } elseif ($isErasable == -1) {
4291 $htmltooltip = $langs->trans(
"DisabledBecauseDispatchedInBookkeeping");
4292 } elseif ($isErasable <= 0) {
4293 $htmltooltip = $langs->trans(
"DisabledBecauseNotErasable");
4295 $enableDelete =
true;
4298 print
dolGetButtonAction($htmltooltip, $langs->trans(
"Delete"),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken(), (
string)
$object->id, $enableDelete, $params);
4302 if ($action !=
'confirm_edit') {
4303 print
'<div class="fichecenter"><div class="fichehalfleft">';
4310 $filedir =
$conf->fournisseur->facture->dir_output.
'/'.$subdir;
4311 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.
$object->id;
4312 $genallowed = $usercanread;
4313 $delallowed = $usercancreate;
4317 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, (
int) $genallowed, (
int) $delallowed, $modelpdf, $genifempty, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
4318 $somethingshown = $formfile->numoffiles;
4321 $tmparray = $form->showLinkToObjectBlock(
$object, array(), array(
'invoice_supplier'), 1);
4322 $linktoelem = $tmparray[
'linktoelem'];
4323 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
4324 print $htmltoenteralink;
4326 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem);
4328 print
'</div><div class="fichehalfright">';
4331 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
4333 $somethingshown = $formactions->showactions(
$object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
4335 print
'</div></div>';
4341 if (
GETPOST(
'modelselected')) {
4342 $action =
'presend';
4346 $modelmail =
'invoice_supplier_send';
4347 $defaulttopic =
'SendBillRef';
4348 $diroutput =
$conf->fournisseur->facture->dir_output;
4349 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
4350 $trackid =
'sinv'.$object->id;
4352 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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.
facturefourn_prepare_head(FactureFournisseur $object)
Prepare array with list of tabs.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, 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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.