40require
'../../main.inc.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_invoice/modules_facturefournisseur.php';
44require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture-rec.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
52if (isModEnabled(
"product")) {
53 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
54 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
56if (isModEnabled(
'project')) {
57 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
58 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
61if (isModEnabled(
'variants')) {
62 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
64if (isModEnabled(
'accounting')) {
65 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
69$langs->loadLangs(array(
'bills',
'compta',
'suppliers',
'companies',
'products',
'banks',
'admin'));
70if (isModEnabled(
'incoterm')) {
71 $langs->load(
'incoterm');
76$action =
GETPOST(
'action',
'aZ09');
79$cancel =
GETPOST(
'cancel',
'alpha');
80$backtopage =
GETPOST(
'backtopage',
'alpha');
81$backtopageforcancel =
'';
85$origin =
GETPOST(
'origin',
'alpha');
96$hookmanager->initHooks(array(
'invoicesuppliercard',
'globalcard'));
102$extrafields->fetch_name_optionals_label(
$object->table_element);
105if ($id > 0 || !empty($ref)) {
106 $ret =
$object->fetch($id, $ref);
110 $ret =
$object->fetch_thirdparty();
118if (!empty($user->socid)) {
119 $socid = $user->socid;
123$result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture',
'fk_soc',
'rowid', $isdraft);
126$usercanread = ($user->hasRight(
"fournisseur",
"facture",
"lire") || $user->hasRight(
"supplier_invoice",
"lire"));
127$usercancreate = ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"));
128$usercandelete = ($user->hasRight(
"fournisseur",
"facture",
"supprimer") || $user->hasRight(
"supplier_invoice",
"supprimer"));
129$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
132$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"validate")));
133$usercansend = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"send"));
136$permissionnote = $usercancreate;
137$permissiondellink = $usercancreate;
138$permissiontoedit = $usercancreate;
139$permissiontoadd = $usercancreate;
140$permissiontodelete = $usercandelete;
149$parameters = array(
'socid' => $socid);
150$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
155if (empty($reshook)) {
156 $backurlforlist = DOL_URL_ROOT.
'/fourn/facture/list.php';
158 if (empty($backtopage) || ($cancel && empty($id))) {
159 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
160 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
161 $backtopage = $backurlforlist;
163 $backtopage = DOL_URL_ROOT.
'/fourn/facture/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
169 if (!empty($backtopageforcancel)) {
170 header(
"Location: ".$backtopageforcancel);
172 } elseif (!empty($backtopage)) {
173 header(
"Location: ".$backtopage);
179 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
181 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
183 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
186 if (
GETPOST(
'linkedOrder') && empty($cancel) && $id > 0 && $permissiontoadd) {
189 $result =
$object->add_object_linked(
'order_supplier',
GETPOST(
'linkedOrder'));
193 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
195 '@phan-var-force FactureFournisseur $objectutil';
197 if (
GETPOST(
'newsupplierref',
'alphanohtml')) {
198 $objectutil->ref_supplier =
GETPOST(
'newsupplierref',
'alphanohtml');
202 $result = $objectutil->createFromClone($user, $id);
204 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
207 $langs->load(
"errors");
211 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
212 $idwarehouse =
GETPOST(
'idwarehouse');
217 $qualified_for_stock_change = 0;
219 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
221 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
225 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
226 $langs->load(
"stocks");
227 if (!$idwarehouse || $idwarehouse == -1) {
229 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
237 $result =
$object->validate($user,
'', $idwarehouse);
247 $outputlangs = $langs;
250 $newlang =
GETPOST(
'lang_id',
'aZ09');
253 $newlang =
$object->thirdparty->default_lang;
255 if (!empty($newlang)) {
257 $outputlangs->setDefaultLang($newlang);
262 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
269 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $permissiontodelete) {
273 $isErasable =
$object->is_erasable();
275 if (($usercandelete && $isErasable > 0) || ($usercancreate && $isErasable == 1)) {
276 $revertstock =
GETPOST(
'revertstock');
279 $idwarehouse =
GETPOST(
'idwarehouse');
281 $qualified_for_stock_change = 0;
283 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
285 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
289 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
290 $langs->load(
"stocks");
291 if (!$idwarehouse || $idwarehouse == -1) {
293 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
296 $result =
$object->setDraft($user, $idwarehouse);
305 $result =
$object->delete($user);
307 header(
'Location: list.php?restore_lastsearch_values=1');
314 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
316 $result =
$object->deleteLine($lineid);
336 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
343 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
346 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
347 $discount->unlink_invoice();
348 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercancreate) {
350 $result =
$object->setPaid($user);
354 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercancreate) {
357 $close_code =
GETPOST(
"close_code",
'restricthtml');
358 $close_note =
GETPOST(
"close_note",
'restricthtml');
360 $result =
$object->setPaid($user, $close_code, $close_note);
365 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
367 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
370 $close_code =
GETPOST(
"close_code",
'restricthtml');
371 $close_note =
GETPOST(
"close_note",
'restricthtml');
373 $result =
$object->setCanceled($user, $close_code, $close_note);
378 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
383 if ($action ==
'setref_supplier' && $usercancreate) {
386 if (
$object->update($user) < 0) {
390 $outputlangs = $langs;
393 $newlang =
GETPOST(
'lang_id',
'aZ09');
396 $newlang =
$object->thirdparty->default_lang;
398 if (!empty($newlang)) {
400 $outputlangs->setDefaultLang($newlang);
404 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
410 if ($action ==
'setconditions' && $usercancreate) {
412 $object->cond_reglement_code = 0;
413 $object->cond_reglement_id = 0;
428 $new_date_echeance =
$object->calculate_date_lim_reglement();
429 if ($new_date_echeance) {
430 $object->date_echeance = $new_date_echeance;
435 $result =
$object->update($user);
447 } elseif ($action ==
'set_incoterms' && isModEnabled(
'incoterm') && $usercancreate) {
450 } elseif ($action ==
'setmode' && $usercancreate) {
453 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
455 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
456 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
459 } elseif ($action ==
'setbankaccount' && $usercancreate) {
462 } elseif ($action ==
'setvatreversecharge' && $usercancreate) {
464 $vatreversecharge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
465 $result =
$object->setVATReverseCharge($vatreversecharge);
468 if ($action ==
'settransportmode' && $usercancreate) {
471 } elseif ($action ==
'setlabel' && $usercancreate) {
475 $result =
$object->update($user);
479 } elseif ($action ==
'setdatef' && $usercancreate) {
483 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
485 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
492 $date_echence_calc =
$object->calculate_date_lim_reglement();
493 if (!empty(
$object->date_echeance)) {
494 $object->date_echeance = $date_echence_calc;
500 $result =
$object->update($user);
504 } elseif ($action ==
'setdate_lim_reglement' && $usercancreate) {
509 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
511 $result =
$object->update($user);
515 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
531 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
533 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
537 $remaintopay =
$object->getRemainToPay(0);
541 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
545 $result = $discount->link_to_invoice(0, $id);
552 $newremaintopay =
$object->getRemainToPay(0);
553 if ($newremaintopay == 0) {
564 $outputlangs = $langs;
567 $newlang =
GETPOST(
'lang_id',
'aZ09');
570 $newlang =
$object->thirdparty->default_lang;
572 if (!empty($newlang)) {
574 $outputlangs->setDefaultLang($newlang);
578 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
583 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
591 $result = $discountcheck->fetch(0, 0,
$object->id);
603 $amount_ht = $amount_tva = $amount_ttc = array();
604 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
608 foreach (
$object->lines as $line) {
609 if ($line->product_type < 9 && $line->total_ht != 0) {
610 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
612 $amount_ht[$keyforvatrate] += $line->total_ht;
613 $amount_tva[$keyforvatrate] += $line->total_tva;
614 $amount_ttc[$keyforvatrate] += $line->total_ttc;
615 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
616 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
617 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
621 '@phan-var-force array<string,float> $amount_ht
622 @phan-var-force array<string,float> $amount_tva
623 @phan-var-force array<string,float> $amount_ttc
624 @phan-var-force array<string,float> $multicurrency_amount_ht
625 @phan-var-force array<string,float> $multicurrency_amount_tva
626 @phan-var-force array<string,float> $multicurrency_amount_ttc';
630 $alreadypaid =
$object->getSommePaiement();
631 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
632 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
633 foreach ($amount_ht as $vatrate => $val) {
634 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
635 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
636 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
637 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
638 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
639 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
648 $discount->description =
'(CREDIT_NOTE)';
650 $discount->description =
'(DEPOSIT)';
652 $discount->description =
'(EXCESS PAID)';
654 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
656 $discount->discount_type = 1;
657 $discount->fk_soc =
$object->socid;
658 $discount->socid =
$object->socid;
659 $discount->fk_invoice_supplier_source =
$object->id;
667 $sql =
'SELECT SUM(pf.amount) as total_paiements';
668 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'paiementfourn as p';
669 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN ('.
getEntity(
'c_paiement').
')';
670 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
671 $sql .=
' AND pf.fk_paiementfourn = p.rowid';
672 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
674 $resql = $db->query($sql);
679 $res = $db->fetch_object($resql);
680 $total_paiements = $res->total_paiements;
683 $total_creditnote_and_deposit = 0;
684 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
685 $sql .=
" re.description, re.fk_invoice_supplier_source";
686 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
687 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
688 $resql = $db->query($sql);
689 if (!empty($resql)) {
690 while ($obj = $db->fetch_object($resql)) {
691 $total_creditnote_and_deposit += $obj->amount_ttc;
697 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
698 $discount->amount_tva = 0;
699 $discount->tva_tx = 0;
700 $discount->vat_src_code =
'';
703 $discount->multicurrency_code =
$object->multicurrency_code;
704 $discount->multicurrency_tx =
$object->multicurrency_tx;
705 $discount->multicurrency_total_ht = $discount->multicurrency_total_ttc = (float)
price2num((
float) $discount->amount_ttc * (float)
$object->multicurrency_tx,
'MT');
706 $discount->multicurrency_total_tva = 0;
708 $discount->multicurrency_amount_ht = $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
709 $discount->multicurrency_amount_tva = 0;
711 $result = $discount->create($user);
717 foreach ($amount_ht as $tva_tx => $xxx) {
718 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
719 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
720 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
722 $discount->multicurrency_code =
$object->multicurrency_code;
723 $discount->multicurrency_tx =
$object->multicurrency_tx;
724 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
725 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
726 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
728 $discount->multicurrency_amount_ht = abs((
float) $discount->multicurrency_total_ht);
729 $discount->multicurrency_amount_tva = abs((
float) $discount->multicurrency_total_tva);
730 $discount->multicurrency_amount_ttc = abs((
float) $discount->multicurrency_total_ttc);
735 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
736 $vat_src_code = $reg[1];
737 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
740 $discount->tva_tx = abs((
float) $tva_tx);
741 $discount->vat_src_code = $vat_src_code;
743 $result = $discount->create($user);
754 $result =
$object->setPaid($user);
769 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate) {
774 $result = $paiementfourn->fetch(
GETPOST(
'paiement_id'));
776 $result = $paiementfourn->delete($user);
778 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
786 } elseif ($action ==
'add' && $usercancreate) {
791 $selectedLines =
GETPOST(
'toselect',
'array');
799 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
813 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
818 if (empty($dateinvoice)) {
819 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
831 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
845 $object->date_echeance = $datedue;
851 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
852 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
854 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
855 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
863 $id =
$object->createFromCurrent($user);
876 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
879 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
884 if (empty($dateinvoice)) {
885 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
895 if (!
GETPOST(
'ref_supplier')) {
896 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
904 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
919 $object->date_echeance = $datedue;
925 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
926 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
928 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
929 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
934 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
943 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
945 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
948 foreach ($facture_source->lines as $line) {
950 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
954 $line->fk_facture_fourn =
$object->id;
955 $line->fk_parent_line = $fk_parent_line;
957 $line->subprice = -$line->subprice;
958 $line->pa_ht = -$line->pa_ht;
959 $line->total_ht = -$line->total_ht;
960 $line->total_tva = -$line->total_tva;
961 $line->total_ttc = -$line->total_ttc;
962 $line->total_localtax1 = -$line->total_localtax1;
963 $line->total_localtax2 = -$line->total_localtax2;
965 $result = $line->insert();
970 if ($result > 0 && $line->product_type == 9) {
971 $fk_parent_line = $result;
979 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
981 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
982 $totalpaid = $facture_source->getSommePaiement();
983 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
984 $totaldeposits = $facture_source->getSumDepositsUsed();
985 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
986 $desc = $langs->trans(
'invoiceAvoirLineWithPaymentRestAmount');
987 $retAddLine =
$object->addline($desc, $remain_to_pay, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
'TTC');
989 if ($retAddLine < 0) {
997 if (empty($dateinvoice)) {
999 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1009 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1019 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1020 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1031 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1032 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1036 $object->fac_rec = $fac_recid;
1038 $fac_rec->fetch(
$object->fac_rec);
1039 $fac_rec->fetch_lines();
1040 $object->lines = $fac_rec->lines;
1047 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1052 if (empty($dateinvoice)) {
1053 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1063 if (!
GETPOST(
'ref_supplier')) {
1064 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
1072 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1089 $object->date_echeance = $datedue;
1095 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1096 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1098 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1099 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1104 if (empty(
$object->date_echeance)) {
1105 $object->date_echeance =
$object->calculate_date_lim_reglement();
1111 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
1113 $element = $subelement =
GETPOST(
'origin',
'alpha');
1121 if ($element ==
'order') {
1122 $element = $subelement =
'commande';
1124 if ($element ==
'propal') {
1125 $element =
'comm/propal';
1126 $subelement =
'propal';
1128 if ($element ==
'contract') {
1129 $element = $subelement =
'contrat';
1131 if ($element ==
'order_supplier') {
1133 $subelement =
'fournisseur.commande';
1135 if ($element ==
'project') {
1136 $element =
'projet';
1143 $classname = ucfirst($subelement);
1144 if ($classname ==
'Fournisseur.commande') {
1145 $classname =
'CommandeFournisseur';
1147 $objectsrc =
new $classname($db);
1148 $objectsrc->fetch($originid);
1149 $objectsrc->fetch_thirdparty();
1156 if (
$object->origin ==
'reception') {
1157 $objectsrc->fetchObjectLinked();
1159 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1160 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1161 $object->linkedObjectsIds[
'order_supplier'] = $value;
1171 $classname = ucfirst($subelement);
1172 if ($classname ==
'Fournisseur.commande') {
1173 $classname =
'CommandeFournisseur';
1175 $srcobject =
new $classname($db);
1177 $result = $srcobject->fetch(
GETPOSTINT(
'originid'));
1180 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1185 $amountdeposit = array();
1187 if ($typeamount ==
'amount') {
1188 $amount = $valuedeposit;
1190 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1193 $TTotalByTva = array();
1194 foreach ($srcobject->lines as &$line) {
1195 if (!empty($line->special_code)) {
1198 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1200 '@phan-var-force array<string,float> $TTotalByTva';
1202 $amount_ttc_diff = 0.;
1203 foreach ($TTotalByTva as $tva => &$total) {
1204 $coef = $total / $srcobject->total_ttc;
1205 $am = $amount * $coef;
1206 $amount_ttc_diff += $am;
1207 $amountdeposit[$tva] += $am / (1 + $tva / 100);
1210 if ($typeamount ==
'amount') {
1211 $amountdeposit[0] = $valuedeposit;
1212 } elseif ($typeamount ==
'variable') {
1215 $lines = $srcobject->lines;
1216 $numlines = count($lines);
1217 for ($i = 0; $i < $numlines; $i++) {
1219 if (empty($lines[$i]->qty)) {
1222 if (!empty($lines[$i]->special_code)) {
1226 $totalamount += $lines[$i]->total_ht;
1227 $tva_tx = $lines[$i]->tva_tx;
1228 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1232 if ($totalamount == 0) {
1233 $amountdeposit[0] = 0;
1238 $amountdeposit[0] = 0;
1242 $amount_ttc_diff = $amountdeposit[0];
1245 foreach ($amountdeposit as $tva => $amount) {
1246 if (empty($amount)) {
1251 'amount' =>
'FixAmount',
1252 'variable' =>
'VarAmount'
1254 $descline =
'(DEPOSIT)';
1256 if ($typeamount ==
'amount') {
1257 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code : $conf->currency)).
')';
1258 } elseif ($typeamount ==
'variable') {
1259 $descline .=
' ('.$valuedeposit.
'%)';
1262 $descline .=
' - '.$srcobject->ref;
1292 $diff =
$object->total_ttc - $amount_ttc_diff;
1296 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1302 $object->lines[0]->localtax1_tx,
1303 $object->lines[0]->localtax2_tx,
1305 $object->lines[0]->fk_product,
1308 $object->lines[0]->product_type,
1309 $object->lines[0]->remise_percent,
1311 $object->lines[0]->date_start,
1320 } elseif ($result > 0) {
1321 $lines = $srcobject->lines;
1322 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1323 $srcobject->fetch_lines();
1324 $lines = $srcobject->lines;
1327 $num = count($lines);
1328 for ($i = 0; $i < $num; $i++) {
1329 if (!in_array($lines[$i]->
id, $selectedLines)) {
1333 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->product_label);
1334 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1337 if (method_exists($lines[$i],
'fetch_optionals')) {
1338 $lines[$i]->fetch_optionals();
1343 $date_start = $lines[$i]->date_debut_prevue;
1344 if ($lines[$i]->date_debut_reel) {
1345 $date_start = $lines[$i]->date_debut_reel;
1347 if ($lines[$i]->date_start) {
1348 $date_start = $lines[$i]->date_start;
1350 $date_end = $lines[$i]->date_fin_prevue;
1351 if ($lines[$i]->date_fin_reel) {
1352 $date_end = $lines[$i]->date_fin_reel;
1354 if ($lines[$i]->date_end) {
1355 $date_end = $lines[$i]->date_end;
1358 $tva_tx = $lines[$i]->tva_tx;
1360 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
1361 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1365 $object->special_code = $lines[$i]->special_code;
1368 if (
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
1370 $pu_currency = $lines[$i]->multicurrency_subprice;
1372 $pu = $lines[$i]->subprice;
1381 $lines[$i]->localtax1_tx,
1382 $lines[$i]->localtax2_tx,
1384 $lines[$i]->fk_product,
1385 $lines[$i]->remise_percent,
1389 $lines[$i]->info_bits,
1394 $lines[$i]->array_options,
1395 $lines[$i]->fk_unit,
1398 $lines[$i]->ref_supplier,
1399 $lines[$i]->special_code
1416 } elseif (!$error) {
1426 $langs->load(
"errors");
1436 $outputlangs = $langs;
1437 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1444 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1447 } elseif ($action ==
'updateline' && $usercancreate) {
1451 if (!
$object->fetch($id) > 0) {
1457 $tva_tx = str_replace(
'*',
'', $tva_tx);
1459 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_subprice') !=
'') {
1461 $price_base_type =
'HT';
1464 $price_base_type =
'TTC';
1467 if (
GETPOST(
'productid') > 0) {
1471 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1476 $prod->fetch(
GETPOST(
'productid'));
1477 $label = $prod->description;
1478 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1479 $label =
GETPOST(
'product_desc',
'restricthtml');
1482 $type = $prod->type;
1484 $label =
GETPOST(
'product_desc',
'restricthtml');
1493 if (preg_match(
'/\*/', $tva_tx)) {
1498 $tva_tx = str_replace(
'*',
'', $tva_tx);
1506 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1507 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1509 if (is_array($extralabelsline)) {
1510 foreach ($extralabelsline as $key => $value) {
1511 unset($_POST[
"options_".$key]);
1515 $result =
$object->updateline(
1537 unset($_POST[
'label']);
1538 unset($_POST[
'fourn_ref']);
1539 unset($_POST[
'date_starthour']);
1540 unset($_POST[
'date_startmin']);
1541 unset($_POST[
'date_startsec']);
1542 unset($_POST[
'date_startday']);
1543 unset($_POST[
'date_startmonth']);
1544 unset($_POST[
'date_startyear']);
1545 unset($_POST[
'date_endhour']);
1546 unset($_POST[
'date_endmin']);
1547 unset($_POST[
'date_endsec']);
1548 unset($_POST[
'date_endday']);
1549 unset($_POST[
'date_endmonth']);
1550 unset($_POST[
'date_endyear']);
1551 unset($_POST[
'price_ttc']);
1552 unset($_POST[
'price_ht']);
1559 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
1563 foreach (
$object->lines as $line) {
1564 if ($line->product_type == 1) {
1565 $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);
1568 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !=
'' && $usercancreate) {
1570 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1571 $vat_rate = str_replace(
'*',
'', $vat_rate);
1574 foreach (
$object->lines as $line) {
1575 $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);
1577 } elseif ($action ==
'addline' && $usercancreate) {
1586 $ret =
$object->fetch_thirdparty();
1588 $langs->load(
'errors');
1593 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
1597 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1598 if ($prod_entry_mode ==
'free') {
1609 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
1612 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
1613 if (empty($remise_percent)) {
1614 $remise_percent = 0;
1618 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1619 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
1621 if (is_array($extralabelsline)) {
1623 foreach ($extralabelsline as $key => $value) {
1624 unset($_POST[
"options_".$key]);
1628 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
1629 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1632 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
1633 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
1636 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
1637 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
1640 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
1641 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
1644 if (!
GETPOST(
'qty',
'alpha')) {
1645 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1649 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
1650 if ($combinations =
GETPOST(
'combinations',
'array')) {
1654 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1655 $idprod = $res->fk_product_child;
1657 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
1663 if ($prod_entry_mode !=
'free' && empty($error)) {
1667 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
1672 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
1674 $res = $productsupplier->fetch($idprod);
1677 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
1679 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1680 if ($productsupplier->fourn_socid != $socid) {
1681 $productsupplier->ref_supplier =
'';
1684 $fksoctosearch =
$object->thirdparty->id;
1685 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1687 } elseif (
GETPOST(
'idprodfournprice',
'alpha') > 0) {
1688 $qtytosearch = $qty;
1690 $idprod = $productsupplier->get_buyprice(
GETPOST(
'idprodfournprice',
'alpha'), $qtytosearch);
1691 $res = $productsupplier->fetch($idprod);
1695 $label = $productsupplier->label;
1698 $outputlangs = $langs;
1700 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1701 $newlang =
GETPOST(
'lang_id',
'aZ09');
1703 if (empty($newlang)) {
1704 $newlang =
$object->thirdparty->default_lang;
1706 if (!empty($newlang)) {
1707 $outputlangs =
new Translate(
"", $conf);
1708 $outputlangs->setDefaultLang($newlang);
1710 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
1712 $desc = $productsupplier->description;
1715 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
1716 $desc = $productsupplier->desc_supplier;
1720 if (trim($product_desc) == trim($desc) &&
getDolGlobalString(
'PRODUIT_AUTOFILL_DESC')) {
1724 $desc = $product_desc;
1726 if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
1730 $ref_supplier = $productsupplier->ref_supplier;
1733 if (!GETPOSTISSET(
'tva_tx')) {
1737 if (empty($tva_tx) || empty($tva_npr)) {
1743 $type = $productsupplier->type;
1744 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1745 $price_base_type =
'HT';
1747 $pu_devise =
price2num($price_ht_devise,
'CU');
1748 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
1749 $price_base_type =
'TTC';
1751 $pu_devise =
price2num($price_ttc_devise,
'CU');
1753 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
1754 if (empty(
$object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code !=
$object->multicurrency_code)) {
1755 $pu = $productsupplier->fourn_pu;
1758 $pu = $productsupplier->fourn_pu;
1759 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
1763 $ref_supplier = $productsupplier->ref_supplier;
1784 min($rank, count(
$object->lines) + 1),
1787 $productsupplier->fk_unit,
1790 GETPOST(
'fourn_ref',
'alpha'),
1794 if ($idprod == -99 || $idprod == 0) {
1797 $langs->load(
"errors");
1798 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
1800 if ($idprod == -1) {
1803 $langs->load(
"errors");
1804 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
1806 } elseif (empty($error)) {
1807 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1808 $tva_tx = str_replace(
'*',
'', $tva_tx);
1809 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1810 $desc = $product_desc;
1812 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
1814 $fk_unit =
GETPOST(
'units',
'alpha');
1816 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1824 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1828 $pu_ht =
price2num((
float) $pu_ttc / (1 + ((
float) $tva_tx / 100)),
'MU');
1830 $price_base_type =
'HT';
1831 $pu_devise =
price2num($price_ht_devise,
'CU');
1833 $result =
$object->addline($product_desc, $pu_ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $date_start, $date_end, 0, $tva_npr, $price_base_type, $type, -1, 0, $array_options, $fk_unit, 0, $pu_devise, $ref_supplier);
1837 if (!$error && $result > 0) {
1842 $outputlangs = $langs;
1845 $newlang =
GETPOST(
'lang_id',
'aZ09');
1848 $newlang =
$object->thirdparty->default_lang;
1850 if (!empty($newlang)) {
1851 $outputlangs =
new Translate(
"", $conf);
1852 $outputlangs->setDefaultLang($newlang);
1857 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1863 unset($_POST [
'prod_entry_mode']);
1865 unset($_POST[
'qty']);
1866 unset($_POST[
'type']);
1867 unset($_POST[
'remise_percent']);
1868 unset($_POST[
'pu']);
1869 unset($_POST[
'price_ht']);
1870 unset($_POST[
'multicurrency_price_ht']);
1871 unset($_POST[
'price_ttc']);
1872 unset($_POST[
'fourn_ref']);
1873 unset($_POST[
'tva_tx']);
1874 unset($_POST[
'label']);
1875 unset($localtax1_tx);
1876 unset($localtax2_tx);
1877 unset($_POST[
'np_marginRate']);
1878 unset($_POST[
'np_markRate']);
1879 unset($_POST[
'dp_desc']);
1880 unset($_POST[
'idprodfournprice']);
1881 unset($_POST[
'units']);
1883 unset($_POST[
'date_starthour']);
1884 unset($_POST[
'date_startmin']);
1885 unset($_POST[
'date_startsec']);
1886 unset($_POST[
'date_startday']);
1887 unset($_POST[
'date_startmonth']);
1888 unset($_POST[
'date_startyear']);
1889 unset($_POST[
'date_endhour']);
1890 unset($_POST[
'date_endmin']);
1891 unset($_POST[
'date_endsec']);
1892 unset($_POST[
'date_endday']);
1893 unset($_POST[
'date_endmonth']);
1894 unset($_POST[
'date_endyear']);
1901 } elseif ($action ==
'classin' && $usercancreate) {
1903 $result =
$object->setProject($projectid);
1904 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
1908 $totalpaid =
$object->getSommePaiement();
1909 $resteapayer =
$object->total_ttc - $totalpaid;
1912 $ventilExportCompta =
$object->getVentilExportCompta();
1914 if (!$ventilExportCompta) {
1917 $idwarehouse =
GETPOST(
'idwarehouse');
1921 $qualified_for_stock_change = 0;
1923 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
1925 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1929 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
1930 $langs->load(
"stocks");
1931 if (!$idwarehouse || $idwarehouse == -1) {
1933 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1938 $object->setDraft($user, $idwarehouse);
1942 $outputlangs = $langs;
1945 $newlang =
GETPOST(
'lang_id',
'aZ09');
1948 $newlang =
$object->thirdparty->default_lang;
1950 if (!empty($newlang)) {
1951 $outputlangs =
new Translate(
"", $conf);
1952 $outputlangs->setDefaultLang($newlang);
1957 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1966 } elseif ($action ==
'reopen' && $usercancreate) {
1968 $result =
$object->fetch($id);
1971 $result =
$object->setUnpaid($user);
1973 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
1982 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1985 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
1987 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
1988 $trackid =
'sinv'.$object->id;
1989 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1992 $upload_dir = $conf->fournisseur->facture->dir_output;
1993 $permissiontoadd = $usercancreate;
1994 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1997 if ($action ==
'calculate' && $usercancreate) {
1998 $calculationrule =
GETPOST(
'calculationrule');
2002 $result =
$object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0,
$object->thirdparty);
2008 if ($action ==
'update_extras' && $usercancreate) {
2012 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
GETPOST(
'attribute',
'restricthtml'));
2019 $result =
$object->insertExtraFields(
'BILL_SUPPLIER_MODIFY');
2027 $action =
'edit_extras';
2032 if ($action ==
'addcontact') {
2033 $result =
$object->fetch($id);
2035 if ($result > 0 && $id > 0) {
2038 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2042 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2045 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2046 $langs->load(
"errors");
2047 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2052 } elseif ($action ==
'swapstatut') {
2059 } elseif ($action ==
'deletecontact') {
2065 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2079$form =
new Form($db);
2081$bankaccountstatic =
new Account($db);
2083if (isModEnabled(
'project')) {
2089$title =
$object->ref.
" - ".$langs->trans(
'Card');
2090if ($action ==
'create') {
2091 $title = $langs->trans(
"NewSupplierInvoice");
2093$help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
2097if ($action ==
'create') {
2099 $selectedLines = array();
2101 print
load_fiche_titre($langs->trans(
'NewSupplierInvoice'),
'',
'supplier_invoice');
2105 $currency_code = $conf->currency;
2111 if (isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2112 $currency_code = $societe->multicurrency_code;
2116 if (!empty($origin) && !empty($originid)) {
2118 $element = $subelement = $origin;
2120 if ($element ==
'project') {
2121 $projectid = $originid;
2122 $element =
'projet';
2126 if ($element ==
'order') {
2127 $element = $subelement =
'commande';
2129 if ($element ==
'propal') {
2130 $element =
'comm/propal';
2131 $subelement =
'propal';
2133 if ($element ==
'contract') {
2134 $element = $subelement =
'contrat';
2136 if ($element ==
'order_supplier') {
2138 $subelement =
'fournisseur.commande';
2142 $classname = ucfirst($subelement);
2143 if ($classname ==
'Fournisseur.commande') {
2144 $classname =
'CommandeFournisseur';
2146 $objectsrc =
new $classname($db);
2147 '@phan-var-force Project|Commande|Propal|Facture|Contrat|CommandeFournisseur|CommonObject $objectsrc';
2148 $objectsrc->fetch($originid);
2149 $objectsrc->fetch_thirdparty();
2151 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
2153 $soc = $objectsrc->thirdparty;
2155 $cond_reglement_id = 0;
2156 $mode_reglement_id = 0;
2160 $transport_mode_id = 0;
2163 if (!empty($objectsrc->cond_reglement_id)) {
2164 $cond_reglement_id = $objectsrc->cond_reglement_id;
2166 if (!empty($objectsrc->mode_reglement_id)) {
2167 $mode_reglement_id = $objectsrc->mode_reglement_id;
2169 if (!empty($objectsrc->fk_account)) {
2170 $fk_account = $objectsrc->fk_account;
2172 if (!empty($objectsrc->transport_mode_id)) {
2173 $transport_mode_id = $objectsrc->transport_mode_id;
2176 if (empty($cond_reglement_id)
2177 || empty($mode_reglement_id)
2178 || empty($fk_account)
2179 || empty($transport_mode_id)
2181 if ($origin ==
'reception') {
2183 if (!isset($objectsrc->supplier_order)) {
2184 $objectsrc->fetch_origin();
2187 if (!empty($objectsrc->origin_object)) {
2188 $originObject = $objectsrc->origin_object;
2189 if (empty($cond_reglement_id) && !empty($originObject->cond_reglement_id)) {
2190 $cond_reglement_id = $originObject->cond_reglement_id;
2192 if (empty($mode_reglement_id) && !empty($originObject->mode_reglement_id)) {
2193 $mode_reglement_id = $originObject->mode_reglement_id;
2195 if (empty($fk_account) && !empty($originObject->fk_account)) {
2196 $fk_account = $originObject->fk_account;
2198 if (empty($transport_mode_id) && !empty($originObject->transport_mode_id)) {
2199 $transport_mode_id = $originObject->transport_mode_id;
2206 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
2207 $cond_reglement_id = $soc->cond_reglement_supplier_id;
2209 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
2210 $mode_reglement_id = $soc->mode_reglement_supplier_id;
2212 if (empty($fk_account) && !empty($soc->fk_account)) {
2213 $fk_account = $soc->fk_account;
2215 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
2216 $transport_mode_id = $soc->transport_mode_id;
2221 if (isModEnabled(
"multicurrency")) {
2222 if (!empty($objectsrc->multicurrency_code)) {
2223 $currency_code = $objectsrc->multicurrency_code;
2225 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
2226 $currency_tx = $objectsrc->multicurrency_tx;
2231 $dateinvoice = ($datetmp ==
'' ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $datetmp);
2233 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2236 $objectsrc->fetch_optionals();
2237 $object->array_options = $objectsrc->array_options;
2239 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2240 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2241 $vat_reverse_charge = (empty($societe) ?
'' : $societe->vat_reverse_charge);
2242 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2243 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2245 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalInt(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2247 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2249 if (isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2250 $currency_code = $societe->multicurrency_code;
2255 if (empty($cond_reglement_id)) {
2256 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2260 if (empty($mode_reglement_id)) {
2261 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2265 if (!
GETPOST(
'changecompany')) {
2266 if (GETPOSTISSET(
'cond_reglement_id')) {
2267 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
2269 if (GETPOSTISSET(
'mode_reglement_id')) {
2270 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
2272 if (GETPOSTISSET(
'cond_reglement_id')) {
2277 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
2278 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
2280 if ($origin ==
'contrat') {
2281 $langs->load(
"admin");
2282 $text = $langs->trans(
"ToCreateARecurringInvoice");
2283 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"SupplierBills"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
2285 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
2287 print
info_admin($text, 0, 0, 0,
'opacitymedium').
'<br>';
2290 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2291 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2292 print
'<input type="hidden" name="action" value="add">';
2293 print
'<input type="hidden" name="changecompany" value="0">';
2295 if (!empty($societe->id) && $societe->id > 0) {
2296 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2298 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2299 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2300 if (!empty($currency_tx)) {
2301 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2303 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2308 $parameters = array();
2310 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierInvoice', $parameters,
$object, $action);
2311 if (empty($reshook)) {
2312 print
'<table class="border centpercent">';
2315 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
2319 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2320 $invoice_predefined->fetch($fac_recid);
2324 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2327 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2328 $absolute_discount = $societe->getAvailableDiscounts(
null,
'', 0, 1);
2329 print $societe->getNomUrl(1,
'supplier');
2330 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2332 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2333 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');
2336 print
'<script type="text/javascript">
2337 $(document).ready(function() {
2338 $("#socid").change(function() {
2339 console.log("We have changed the company - Reload page");
2341 $("input[name=action]").val("create");
2342 $("input[name=changecompany]").val("1");
2343 $("form[name=add]").submit();
2348 if ($fac_recid <= 0) {
2349 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>';
2355 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2356 $invoice_predefined->fetch($fac_recid);
2358 $dateinvoice = $invoice_predefined->date_when;
2359 if (empty($projectid)) {
2360 $projectid = $invoice_predefined->fk_project;
2362 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2363 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2364 $fk_account = $invoice_predefined->fk_account;
2365 $note_public = $invoice_predefined->note_public;
2366 $note_private = $invoice_predefined->note_private;
2368 if (!empty($invoice_predefined->multicurrency_code)) {
2369 $currency_code = $invoice_predefined->multicurrency_code;
2371 if (!empty($invoice_predefined->multicurrency_tx)) {
2372 $currency_tx = $invoice_predefined->multicurrency_tx;
2375 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2376 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2377 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2379 $resql = $db->query($sql);
2381 $num = $db->num_rows($resql);
2385 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2387 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2388 print
'<option value="0" selected></option>';
2390 $objp = $db->fetch_object($resql);
2391 print
'<option value="'.$objp->rowid.
'"';
2392 if ($fac_recid == $objp->rowid) {
2394 $exampletemplateinvoice->fetch($fac_recid);
2396 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2402 print
'<script type="text/javascript">
2403 $(document).ready(function() {
2404 $("#fac_rec").change(function() {
2405 console.log("We have changed the template invoice - Reload page");
2407 $("input[name=action]").val("create");
2408 $("form[name=add]").submit();
2422 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"';
2423 if (!empty($societe->id) && $societe->id > 0) {
2429 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2431 print
'<div class="tagtable">'.
"\n";
2434 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2435 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
'checked').
'> ';
2436 $desc = $form->textwithpicto($tmp.
'<label for="radio_standard">'.$langs->trans(
"InvoiceStandardAsk").
'</label>', $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2438 print
'</div></div>';
2440 if (empty($origin) || ($origin ==
'order_supplier' && !empty($originid))) {
2443 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2444 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOSTINT(
'type') == 3 ?
' checked' :
'') .
'> ';
2445 print
'<script type="text/javascript">
2446 jQuery(document).ready(function() {
2447 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2448 jQuery("#radio_standard").prop("checked", true);
2450 jQuery("#typedeposit, #valuedeposit").click(function() {
2451 jQuery("#radio_deposit").prop("checked", true);
2453 jQuery("#typedeposit").change(function() {
2454 console.log("We change type of down payment");
2455 jQuery("#radio_deposit").prop("checked", true);
2456 setRadioForTypeOfInvoice();
2458 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2459 setRadioForTypeOfInvoice();
2461 function setRadioForTypeOfInvoice() {
2462 console.log("Change radio");
2463 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2464 jQuery(".checkforselect").prop("disabled", true);
2465 jQuery(".checkforselect").prop("checked", false);
2467 jQuery(".checkforselect").prop("disabled", false);
2468 jQuery(".checkforselect").prop("checked", true);
2474 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2476 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2477 print
'<table class="nobordernopadding"><tr>';
2481 if ($origin ==
'order_supplier') {
2482 print
'<td class="nowrap" style="padding-left: 15px">';
2484 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2485 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2486 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2488 print $form->selectarray(
'typedeposit', $arraylist,
GETPOST(
'typedeposit',
'aZ09'), 0, 0, 0,
'', 1);
2490 print
'<td class="nowrap" style="padding-left: 5px">';
2491 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' .
GETPOSTINT(
'valuedeposit') .
'"/>';
2494 print
'</tr></table>';
2496 print
'</div></div>';
2565 if (empty($origin)) {
2566 if (!empty($societe->id) && $societe->id > 0) {
2570 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2577 foreach ($facids as $key => $valarray) {
2578 $newinvoice_static->id = $key;
2579 $newinvoice_static->ref = $valarray [
'ref'];
2580 $newinvoice_static->status = $valarray [
'status'];
2581 $newinvoice_static->statut = $valarray [
'status'];
2582 $newinvoice_static->type = $valarray [
'type'];
2583 $newinvoice_static->paid = $valarray [
'paye'];
2584 $newinvoice_static->paye = $valarray [
'paye'];
2586 $optionsav .=
'<option value="'.$key.
'"';
2588 $optionsav .=
' selected';
2591 $optionsav .= $newinvoice_static->ref;
2592 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
2593 $optionsav .=
'</option>';
2596 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2597 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
2599 $tmp .=
' disabled';
2603 print
'<script type="text/javascript">
2604 jQuery(document).ready(function() {
2605 if (! jQuery("#radio_creditnote").is(":checked"))
2607 jQuery("#credit_note_options").hide();
2609 jQuery("#radio_creditnote").click(function() {
2610 jQuery("#credit_note_options").show();
2612 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2613 jQuery("#credit_note_options").hide();
2617 $text = $tmp.
'<label for="radio_creditnote">'.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
2619 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2621 $text .=
' disabled';
2625 $text .=
'<option value="-1"></option>';
2626 $text .= $optionsav;
2628 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
2630 $text .=
'</select>';
2631 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2634 print
'<div id="credit_note_options" class="clearboth">';
2635 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' :
'').
' /> ';
2636 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
2637 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' :
'').
' /> ';
2638 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
2641 print
'</div></div>';
2644 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2646 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2648 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2"> ';
2650 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
2651 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
2652 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2654 print
'</div></div>'.
"\n";
2665 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
2666 print $form->getSelectInvoiceSubtype(
GETPOST(
'subtype'),
'subtype', 1, 0,
'');
2670 if (!empty($societe->id) && $societe->id > 0) {
2672 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2674 $thirdparty = $societe;
2676 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2677 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2683 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth200" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
2686 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
2687 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2688 print $form->selectDate($dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
2692 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2693 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
2694 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1);
2699 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
2700 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2701 print $form->selectDate($datedue,
'ech', 0, 0, 0,
"add", 1, 1);
2705 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2706 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2707 $form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'DBIT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
2711 if (isModEnabled(
"bank")) {
2712 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2714 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
2719 if (isModEnabled(
'project')) {
2722 $langs->load(
'projects');
2723 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2724 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');
2725 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>';
2730 if (isModEnabled(
'incoterm')) {
2732 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
2733 print
'<td colspan="3" class="maxwidthonsmartphone">';
2734 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2735 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 :
''));
2741 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
2742 print
'<tr><td>' . $langs->trans(
'VATReverseCharge') .
'</td><td>';
2744 if (GETPOSTISSET(
'vat_reverse_charge')) {
2745 $vat_reverse_charge = (
GETPOST(
'vat_reverse_charge',
'alpha') ==
'on' ||
GETPOST(
'vat_reverse_charge',
'alpha') ==
'1') ? 1 : 0;
2746 } elseif ($vat_reverse_charge == 1 || $societe->vat_reverse_charge == 1 || ($societe->country_code !=
'FR' &&
isInEEC($societe) && !empty($societe->tva_intra))) {
2747 $vat_reverse_charge = 1;
2749 $vat_reverse_charge = 0;
2752 print
'<input type="checkbox" name="vat_reverse_charge"'. (!empty($vat_reverse_charge) ?
' checked ' :
'') .
'>';
2757 if (isModEnabled(
"multicurrency")) {
2759 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0).
'</td>';
2760 print
'<td class="maxwidthonsmartphone">';
2761 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
2762 $used_currency_code = $currency_code;
2763 if (!
GETPOST(
'changecompany')) {
2764 $used_currency_code = GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code;
2766 print $form->selectMultiCurrency($used_currency_code,
'multicurrency_code');
2772 if ($fac_recid > 0) {
2773 $dateexample = $dateinvoice;
2774 if (empty($dateexample)) {
2777 $substitutionarray = array(
2778 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
2779 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
2780 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
2781 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
2782 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
2783 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
2784 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
2785 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
2786 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
2787 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
2788 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
2791 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
2792 foreach ($substitutionarray as $key => $val) {
2793 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
2795 $htmltext .=
'</i>';
2799 if (isModEnabled(
'intracommreport')) {
2800 $langs->loadLangs(array(
"intracommreport"));
2801 print
'<!-- If module intracomm on -->'.
"\n";
2802 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
2803 $form->selectTransportMode(GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
2807 if (empty($reshook)) {
2808 print
$object->showOptionals($extrafields,
'create');
2812 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2814 $doleditor =
new DolEditor(
'note_public', (GETPOSTISSET(
'note_public') ?
GETPOST(
'note_public',
'restricthtml') : $note_public),
'', 80,
'dolibarr_notes',
'In', 0, false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
2815 print $doleditor->Create(1);
2821 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
2823 $doleditor =
new DolEditor(
'note_private', (GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') : $note_private),
'', 80,
'dolibarr_notes',
'In', 0, false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
2824 print $doleditor->Create(1);
2830 if (!empty($objectsrc) && is_object($objectsrc)) {
2831 print
"\n<!-- ".$classname.
" info -->";
2833 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2834 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2835 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2836 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2837 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2839 $txt = $langs->trans($classname);
2840 if ($classname ==
'CommandeFournisseur') {
2841 $langs->load(
'orders');
2842 $txt = $langs->trans(
"SupplierOrder");
2844 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
2846 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'invoice_supplier');
2848 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
2849 '@phan-var-force null|FactureFournisseur[] $invoice_supplier';
2852 if (is_array($invoice_supplier)) {
2853 $cntinvoice = count($invoice_supplier);
2855 if ($cntinvoice >= 1) {
2857 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
2862 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2863 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2864 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
2865 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2868 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
2869 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2871 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2873 if (isModEnabled(
"multicurrency")) {
2874 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2875 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2876 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2881 $parameters = array();
2882 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
2883 print $hookmanager->resPrint;
2891 print $form->buttonsSaveCancel(
"CreateDraft");
2894 if (!empty($objectsrc) && is_object($objectsrc)) {
2897 $title = $langs->trans(
'ProductsAndServices');
2900 print
'<div class="div-table-responsive-no-min">';
2901 print
'<table class="noborder centpercent">';
2903 $objectsrc->printOriginLinesList(
'', $selectedLines);
2911 if ($id > 0 || !empty($ref)) {
2917 $productstatic =
new Product($db);
2919 $result =
$object->fetch($id, $ref);
2921 $langs->load(
"errors");
2922 print $langs->trans(
"ErrorRecordNotFound");
2928 $result =
$object->fetch_thirdparty();
2934 $societe =
$object->thirdparty;
2936 $totalpaid =
$object->getSommePaiement();
2937 $totalcreditnotes =
$object->getSumCreditNotesUsed();
2938 $totaldeposits =
$object->getSumDepositsUsed();
2946 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
2949 $multicurrency_resteapayer = 0;
2950 if (isModEnabled(
"multicurrency")) {
2951 $multicurrency_totalpaid =
$object->getSommePaiement(1);
2952 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
2953 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
2954 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
2958 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code != $conf->currency) {
2959 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
2966 $resteapayeraffiche = $resteapayer;
2969 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2970 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2972 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2973 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2976 $absolute_discount = $societe->getAvailableDiscounts(
null, $filterabsolutediscount, 0, 1);
2977 $absolute_creditnote = $societe->getAvailableDiscounts(
null, $filtercreditnote, 0, 1);
2978 $absolute_discount =
price2num($absolute_discount,
'MT');
2979 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2984 $objectidnext =
$object->getIdReplacingInvoice();
2987 $titre = $langs->trans(
'SupplierInvoice');
2989 print
dol_get_fiche_head($head,
'card', $titre, -1,
'supplier_invoice', 0,
'',
'', 0,
'', 1);
2994 if ($action ==
'converttoreduc') {
2997 $type_fac =
'ExcessPaid';
2999 $type_fac =
'CreditNote';
3001 $type_fac =
'Deposit';
3003 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
3004 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
3005 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
3009 if ($action ==
'clone') {
3011 $formquestion = array(
3012 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplierBill"),
'value' => $langs->trans(
"CopyOf").
' '.
$object->ref_supplier),
3013 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
3016 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
3020 if ($action ==
'valid') {
3022 if (preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) {
3024 $numref =
$object->getNextNumRef($societe);
3033 $text = $langs->trans(
'ConfirmValidateBill', $numref);
3041 $formquestion = array();
3043 $qualified_for_stock_change = 0;
3045 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3047 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3050 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
3051 $langs->load(
"stocks");
3052 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3055 $warehouse_array = $warehouse->list_array();
3056 if (count($warehouse_array) == 1) {
3058 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3061 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3063 $formquestion = array(
3064 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3068 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
3073 if ($action ==
'edit') {
3074 $formquestion = array();
3076 $qualified_for_stock_change = 0;
3078 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3080 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3082 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
3083 $langs->load(
"stocks");
3084 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3087 $warehouse_array = $warehouse->list_array();
3088 if (count($warehouse_array) == 1) {
3090 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3093 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3095 $formquestion = array(
3096 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3099 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill',
$object->ref),
'confirm_edit', $formquestion, 1, 1);
3103 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
3104 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'', 0, 1);
3107 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
3111 $close[$i][
'code'] =
'discount_vat';
3113 $close[$i][
'code'] =
'badsupplier';
3115 $close[$i][
'code'] =
'other';
3119 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
3121 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3123 $close[$i][
'label'] = $langs->trans(
"Other");
3127 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3129 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3131 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
3134 $arrayreasons = array();
3135 foreach ($close as $key => $val) {
3136 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
3140 $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'));
3142 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
3146 if ($action ==
'canceled') {
3148 $close[1][
'code'] =
'badsupplier';
3149 $close[2][
'code'] =
'abandon';
3151 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3152 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
3154 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier",
$object->ref), $close[1][
'label'], 1);
3155 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
3157 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
3158 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
3161 $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'));
3163 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 280);
3167 if ($action ==
'delete') {
3168 $formquestion = array();
3170 $qualified_for_stock_change = 0;
3172 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3174 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3177 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
3178 $langs->load(
"stocks");
3179 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3182 $warehouse_array = $warehouse->list_array();
3184 $selectwarehouse =
'<span class="questionrevertstock hidden">';
3185 if (count($warehouse_array) == 1) {
3187 $selectwarehouse .=
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3190 $selectwarehouse .= $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3192 $selectwarehouse .=
'</span>';
3194 $selectyesno = array(0 => $langs->trans(
'No'), 1 => $langs->trans(
'Yes'));
3196 print
'<script type="text/javascript">
3197 $(document).ready(function() {
3198 $("#revertstock").change(function() {
3199 if(this.value > 0) {
3200 $(".questionrevertstock").removeClass("hidden");
3202 $(".questionrevertstock").addClass("hidden");
3208 $formquestion = array(
3209 array(
'type' =>
'select',
'name' =>
'revertstock',
'label' => $langs->trans(
"RevertProductsToStock"),
'select_show_empty' => 0,
'values' => $selectyesno),
3210 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $selectwarehouse,
'tdclass' =>
'questionrevertstock hidden')
3214 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete', $formquestion, 1, 1);
3216 if ($action ==
'deletepayment') {
3217 $payment_id =
GETPOST(
'paiement_id');
3218 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
3222 if ($action ==
'ask_deleteline') {
3223 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
3226 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
3227 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
3228 if (empty($reshook)) {
3229 $formconfirm .= $hookmanager->resPrint;
3230 } elseif ($reshook > 0) {
3231 $formconfirm = $hookmanager->resPrint;
3239 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
3241 $morehtmlref =
'<div class="refidno">';
3243 $morehtmlref .= $form->editfieldkey(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier,
$object, $usercancreate,
'string',
'', 0, 1);
3244 $morehtmlref .= $form->editfieldval(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier,
$object, $usercancreate,
'string',
'',
null,
null,
'', 1);
3246 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'supplier');
3248 $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>';
3251 if (isModEnabled(
'project')) {
3252 $langs->load(
"projects");
3253 $morehtmlref .=
'<br>';
3254 if ($permissiontoadd) {
3255 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
3256 if ($action !=
'classify') {
3257 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.((int)
$object->id).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
3259 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (!
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ?
$object->socid : -1),
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
3261 if (!empty(
$object->fk_project)) {
3263 $proj->fetch(
$object->fk_project);
3264 $morehtmlref .= $proj->getNomUrl(1);
3266 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
3271 $morehtmlref .=
'</div>';
3273 $object->totalpaid = $totalpaid;
3275 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
3278 $parameters = array();
3280 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierInvoice', $parameters,
$object, $action);
3281 if (empty($reshook)) {
3282 print
'<div class="fichecenter">';
3283 print
'<div class="fichehalfleft">';
3284 print
'<div class="underbanner clearboth"></div>';
3286 print
'<table class="border tableforfield centpercent">';
3289 print
'<tr><td class="titlefield">'.$langs->trans(
'Type').
'</td><td>';
3290 print
'<span class="badgeneutral">';
3294 print
' '.$object->getSubtypeLabel(
'facture_fourn');
3298 $facreplaced->fetch(
$object->fk_facture_source);
3299 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
3302 if (
$object->fk_facture_source > 0) {
3304 $facusing->fetch(
$object->fk_facture_source);
3305 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
3307 $langs->load(
"errors");
3308 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"WarningCorrectedInvoiceNotFound").
'</span>';
3312 $facidavoir =
$object->getListIdAvoirFromInvoice();
3313 if (count($facidavoir) > 0) {
3314 $invoicecredits = array();
3315 foreach ($facidavoir as $id) {
3317 $facavoir->fetch($id);
3318 $invoicecredits[] = $facavoir->getNomUrl(1);
3320 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
3323 if (isset($objectidnext) && $objectidnext > 0) {
3326 $facthatreplace->fetch($objectidnext);
3327 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
3331 $result = $discount->fetch(0, 0,
$object->id);
3333 print
' <span class="opacitymediumbycolor paddingleft">';
3334 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
3335 $s = str_replace(
'{s1}',
$object->getLibType(1), $s);
3336 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
3338 print
'</span><br>';
3342 if (
$object->fk_fac_rec_source > 0) {
3344 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
3346 print
' <span class="opacitymediumbycolor paddingleft">';
3347 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->title).
'</a>';
3348 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
3358 print
'<!-- Discounts -->'.
"\n";
3359 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
3362 $thirdparty = $societe;
3364 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3370 print
'<td>'.$form->editfieldkey(
"Label",
'label',
$object->label,
$object, $usercancreate).
'</td>';
3371 print
'<td>'.$form->editfieldval(
"Label",
'label',
$object->label,
$object, $usercancreate).
'</td>';
3379 print $form->editfieldkey(
"DateInvoice",
'datef',
$object->date,
$object, $form_permission,
'datepicker');
3380 print
'</td><td colspan="3">';
3381 print $form->editfieldval(
"Date",
'datef',
$object->date,
$object, $form_permission,
'datepicker');
3385 $langs->load(
'bills');
3386 print
'<tr><td class="nowrap">';
3387 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3388 print $langs->trans(
'PaymentConditions');
3390 if ($action !=
'editconditions' && $form_permission) {
3391 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>';
3393 print
'</tr></table>';
3395 if ($action ==
'editconditions') {
3396 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->cond_reglement_id,
'cond_reglement_id');
3398 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->cond_reglement_id,
'none');
3405 print $form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement',
$object->date_echeance,
$object, $form_permission,
'datepicker');
3407 print $form->editfieldval(
"DateMaxPayment",
'date_lim_reglement',
$object->date_echeance,
$object, $form_permission,
'datepicker');
3408 if ($action !=
'editdate_lim_reglement' &&
$object->hasDelay()) {
3414 $langs->load(
'bills');
3415 print
'<tr><td class="nowrap">';
3416 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3417 print $langs->trans(
'PaymentMode');
3419 if ($action !=
'editmode' && $form_permission) {
3420 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>';
3422 print
'</tr></table>';
3424 if ($action ==
'editmode') {
3425 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3427 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->mode_reglement_id,
'none');
3432 if (isModEnabled(
"multicurrency")) {
3436 print
'<table class="nobordernopadding" width="100%"><tr><td>';
3437 print $form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0);
3439 if ($action !=
'editmulticurrencycode' &&
$object->status == $object::STATUS_DRAFT) {
3440 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencycode&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
3442 print
'</tr></table>';
3444 if ($action ==
'editmulticurrencycode') {
3445 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_code,
'multicurrency_code');
3447 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_code,
'none');
3452 if (
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
3455 print
'<table class="nobordernopadding centpercent"><tr><td>';
3456 print $form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'',
$object, 0);
3458 if ($action !=
'editmulticurrencyrate' &&
$object->status == $object::STATUS_DRAFT &&
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency) {
3459 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencyrate&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
3461 print
'</tr></table>';
3463 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
3464 if ($action ==
'actualizemulticurrencyrate') {
3467 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_tx,
'multicurrency_tx',
$object->multicurrency_code);
3469 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_tx,
'none',
$object->multicurrency_code);
3470 if (
$object->status == $object::STATUS_DRAFT &&
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency) {
3471 print
'<div class="inline-block"> ';
3472 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
3481 if (isModEnabled(
"bank")) {
3482 print
'<tr><td class="nowrap">';
3483 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3484 print $langs->trans(
'BankAccount');
3486 if ($action !=
'editbankaccount' && $usercancreate) {
3487 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>';
3489 print
'</tr></table>';
3491 if ($action ==
'editbankaccount') {
3492 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'fk_account', 1);
3494 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'none');
3502 print
'<tr><td class="nowrap">';
3503 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3504 print $langs->trans(
'VATReverseCharge');
3506 if ($action !=
'editvatreversecharge' && $usercancreate) {
3507 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editvatreversecharge&id='.
$object->id.
'">'.
img_edit($langs->trans(
'SetVATReverseCharge'), 1).
'</a></td>';
3509 print
'</tr></table>';
3511 if ($action ==
'editvatreversecharge') {
3512 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
3513 print
'<input type="hidden" name="action" value="setvatreversecharge">';
3514 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3516 print
'<input type="checkbox" name="vat_reverse_charge"' . (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
'>';
3518 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
3521 print
'<input type="checkbox" name="vat_reverse_charge"'. (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
' disabled>';
3527 if (isModEnabled(
'incoterm')) {
3529 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3530 print $langs->trans(
'IncotermLabel');
3531 print
'<td><td class="right">';
3532 if ($usercancreate) {
3533 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
3537 print
'</td></tr></table>';
3540 if ($action !=
'editincoterm') {
3541 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
3543 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
3549 if (isModEnabled(
'intracommreport')) {
3550 $langs->loadLangs(array(
"intracommreport"));
3551 print
'<!-- If module intracomm on -->'.
"\n";
3553 print
'<table class="nobordernopadding centpercent"><tr><td>';
3554 print $langs->trans(
'IntracommReportTransportMode');
3556 if ($action !=
'edittransportmode' && ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"))) {
3557 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edittransportmode&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit().
'</a></td>';
3559 print
'</tr></table>';
3562 if ($action ==
'edittransportmode') {
3563 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->transport_mode_id,
'transport_mode_id', 1, 1);
3565 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->transport_mode_id,
'none');
3572 if (
$object->status != $object::STATUS_DRAFT) {
3576 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
3581 print
'<div class="fichehalfright">';
3582 print
'<div class="underbanner clearboth"></div>';
3584 print
'<table class="border tableforfield centpercent">';
3587 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
3588 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
3589 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
3590 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3595 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
3596 print
'<td class="nowrap amountcard right">';
3597 if (
GETPOST(
'calculationrule')) {
3598 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
3600 $calculationrule = (!
getDolGlobalString(
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND') ?
'totalofround' :
'roundoftotal');
3602 if ($calculationrule ==
'totalofround') {
3603 $calculationrulenum = 1;
3605 $calculationrulenum = 2;
3608 if (
$object->getVentilExportCompta() == 0) {
3609 $s =
'<span class="hideonsmartphone opacitymedium">' . $langs->trans(
"ReCalculate") .
' </span>';
3610 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=totalofround">' . $langs->trans(
"Mode1") .
'</a>';
3612 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=roundoftotal">' . $langs->trans(
"Mode2") .
'</a>';
3613 print
'<div class="inline-block">';
3614 print $form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum) .
'<br>' . $langs->trans(
"CalculationRuleDescSupplier"), 2, 1,
img_picto(
'',
'help'),
'', 3,
'', 0,
'recalculate');
3615 print
' ';
3618 print
price(
$object->total_tva, 1, $langs, 0, -1, -1, $conf->currency);
3620 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
3621 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3625 if ($societe->localtax1_assuj ==
"1") {
3627 print
'<td>' . $langs->transcountry(
"AmountLT1", $societe->country_code) .
'</td>';
3628 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency) .
'</td>';
3631 if ($societe->localtax2_assuj ==
"1") {
3633 print
'<td>' . $langs->transcountry(
"AmountLT2", $societe->country_code) .
'</td>';
3634 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency) .
'</td>';
3639 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
3640 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
3641 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
3642 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3660 if (isModEnabled(
'project')) {
3663 if (isModEnabled(
"bank")) {
3667 if (isModEnabled(
'incoterm')) {
3670 if (isModEnabled(
"multicurrency")) {
3675 if ($societe->localtax1_assuj ==
"1") {
3678 if ($societe->localtax2_assuj ==
"1") {
3682 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
3683 $sql .=
' c.id as payment_type, c.code as payment_code,';
3684 $sql .=
' pf.amount,';
3685 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
3686 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
3687 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
3688 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
3689 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
3690 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
3691 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
3692 $sql .=
' ORDER BY p.datep, p.tms';
3694 $result = $db->query($sql);
3696 $num = $db->num_rows($result);
3699 print
'<div class="div-table-responsive-no-min">';
3700 print
'<table class="noborder paymenttable centpercent">';
3701 print
'<tr class="liste_titre">';
3703 print
'<td>'.$langs->trans(
'Date').
'</td>';
3704 print
'<td>'.$langs->trans(
'Type').
'</td>';
3705 if (isModEnabled(
"bank")) {
3706 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
3708 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
3709 print
'<td width="18"> </td>';
3714 $objp = $db->fetch_object($result);
3716 $paymentstatic->id = $objp->rowid;
3717 $paymentstatic->datepaye = $db->jdate($objp->dp);
3718 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
3719 $paymentstatic->num_payment = $objp->num_payment;
3721 $paymentstatic->paiementcode = $objp->payment_code;
3722 $paymentstatic->type_code = $objp->payment_code;
3723 $paymentstatic->type_label = $objp->payment_type;
3725 print
'<tr class="oddeven">';
3726 print
'<td class="nowraponall">';
3727 print $paymentstatic->getNomUrl(1);
3729 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
'</td>';
3730 $s = $form->form_modes_reglement(
'', $objp->payment_type,
'none',
'', 1, 0,
'', 1).
' '.$objp->num_payment;
3731 print
'<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).
'">';
3734 if (isModEnabled(
"bank")) {
3735 $bankaccountstatic->id = $objp->baid;
3736 $bankaccountstatic->ref = $objp->baref;
3737 $bankaccountstatic->label = $objp->baref;
3738 $bankaccountstatic->number = $objp->banumber;
3740 if (isModEnabled(
'accounting')) {
3741 $bankaccountstatic->account_number = $objp->account_number;
3744 $accountingjournal->fetch($objp->fk_accountancy_journal);
3745 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
3748 print
'<td class="right">';
3749 if ($objp->baid > 0) {
3750 print $bankaccountstatic->getNomUrl(1,
'transactions');
3754 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
3755 print
'<td class="center">';
3757 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
3763 $totalpaid += $objp->amount;
3767 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td><td></td><td></td></tr>';
3790 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3791 print
'<span class="opacitymedium">';
3793 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
3795 print $langs->trans(
'AlreadyPaid');
3798 print
'</td><td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td><td> </td></tr>';
3801 $resteapayeraffiche = $resteapayer;
3803 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
3806 $creditnoteamount = 0;
3809 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
3810 $sql .=
" re.description, re.fk_invoice_supplier_source";
3811 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
3812 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
3813 $resql = $db->query($sql);
3815 $num = $db->num_rows($resql);
3819 $obj = $db->fetch_object($resql);
3820 $invoice->fetch($obj->fk_invoice_supplier_source);
3821 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3823 print $langs->trans(
"CreditNote").
' ';
3826 print $langs->trans(
"Deposit").
' ';
3828 print $invoice->getNomUrl(0);
3830 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
3831 print
'<td class="right">';
3832 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&discountid='.$obj->rowid.
'">';
3833 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
3838 $creditnoteamount += $obj->amount_ttc;
3841 $depositamount += $obj->amount_ttc;
3850 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3851 print
'<span class="opacitymedium">';
3852 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
3854 print
'</td><td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3855 $resteapayeraffiche = 0;
3856 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3860 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3861 print
'<span class="opacitymedium">';
3862 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
3864 print
'</td><td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3866 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3870 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3871 print
'<span class="opacitymedium">';
3872 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
3874 print
'</td><td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3875 $resteapayeraffiche = 0;
3876 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3880 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3881 $text = $langs->trans(
"HelpAbandonOther");
3883 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
3885 print
'<span class="opacitymedium">';
3887 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
3889 print
'</td><td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3890 $resteapayeraffiche = 0;
3891 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3895 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3896 print
'<span class="opacitymedium">';
3897 print $langs->trans(
"Billed");
3899 print
'</td><td class="right">'.price(
$object->total_ttc).
'</td><td> </td></tr>';
3902 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3903 print
'<span class="opacitymedium">';
3904 print $langs->trans(
'RemainderToPay');
3905 if ($resteapayeraffiche < 0) {
3906 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3910 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
3913 if (isModEnabled(
'multicurrency') &&
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
3914 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3915 print
'<span class="opacitymedium">';
3916 print $langs->trans(
'RemainderToPayMulticurrency');
3917 if ($resteapayeraffiche < 0) {
3918 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3922 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.(!empty(
$object->multicurrency_code) ?
$object->multicurrency_code : $conf->currency).
' '.
price(
price2num($multicurrency_resteapayer,
'MT')).
'</td><td> </td></tr>';
3925 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3928 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3929 print $langs->trans(
'AlreadyPaidBack');
3930 print
' :</td><td class="right">'.price($sign * $totalpaid).
'</td><td> </td></tr>';
3933 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"Billed").
' :</td><td class="right">'.
price($sign *
$object->total_ttc).
'</td><td> </td></tr>';
3936 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3937 print
'<span class="opacitymedium">';
3938 print $langs->trans(
'RemainderToPayBack');
3939 if ($resteapayeraffiche > 0) {
3940 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3944 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td><td> </td></tr>';
3947 if (isModEnabled(
'multicurrency') &&
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
3948 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3949 print
'<span class="opacitymedium">';
3950 print $langs->trans(
'RemainderToPayBackMulticurrency');
3951 if ($resteapayeraffiche > 0) {
3952 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3956 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>';
3971 print
'<div class="clearboth"></div><br>';
3974 $blocname =
'contacts';
3975 $title = $langs->trans(
'ContactsAddresses');
3976 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3981 $blocname =
'notes';
3982 $title = $langs->trans(
'Notes');
3983 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3990 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
3991 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3992 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
3993 print
'<input type="hidden" name="mode" value="">';
3994 print
'<input type="hidden" name="page_y" value="">';
3995 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
3996 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
3997 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4000 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
4003 print
'<div class="div-table-responsive-no-min">';
4004 print
'<table id="tablelines" class="noborder noshadow centpercent">';
4006 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
4009 $inputalsopricewithtax = 1;
4010 $senderissupplier = 2;
4013 $senderissupplier = 1;
4018 $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
4025 if ($action !=
'editline') {
4028 $parameters = array();
4029 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
4033 if (empty($reshook)) {
4034 $object->formAddObjectLine(1, $societe, $mysoc);
4047 if ($action !=
'presend') {
4052 print
'<div class="tabsAction">';
4054 $parameters = array();
4055 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
4057 if (empty($reshook)) {
4061 $ventilExportCompta =
$object->getVentilExportCompta();
4063 if ($ventilExportCompta == 0) {
4064 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=edit&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
4066 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
4071 $result = $discount->fetch(0, 0,
$object->id);
4078 if (!$objectidnext &&
$object->close_code !=
'replaced' && $usercancreate) {
4079 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
4081 if ($usercancreate) {
4082 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
4084 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
4092 if ($usercanvalidate) {
4093 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken().
'"';
4094 print
'>'.$langs->trans(
'Validate').
'</a>';
4096 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
4097 print
'>'.$langs->trans(
'Validate').
'</a>';
4103 if (empty($user->socid)) {
4106 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
4108 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'SendMail').
'</span>';
4115 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>';
4122 if ($resteapayer == 0) {
4123 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
4125 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>';
4131 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
4135 && (
getDolGlobalString(
'SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') ||
$object->getSommePaiement() == 0)
4137 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>';
4141 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
4152 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaid').
'</a>';
4157 if ($totalpaid > 0 || $totalcreditnotes > 0) {
4159 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
4162 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
4175 if (!$objectidnext) {
4176 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>';
4181 if ($action !=
'edit' && $usercancreate) {
4182 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=clone&socid='.
$object->socid.
'&token='.
newToken().
'">'.$langs->trans(
'ToClone').
'</a>';
4187 if (!$objectidnext && count(
$object->lines) > 0) {
4188 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.
$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
4193 $isErasable =
$object->is_erasable();
4194 if ($action !=
'confirm_edit' && ($usercandelete || ($usercancreate && $isErasable == 1))) {
4195 $enableDelete =
false;
4197 $params = (empty($conf->use_javascript_ajax) ? array() : array(
'attr' => array(
'class' =>
'reposition')));
4199 if ($isErasable == -4) {
4200 $htmltooltip = $langs->trans(
"DisabledBecausePayments");
4201 } elseif ($isErasable == -3) {
4202 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastSituationInvoice");
4203 } elseif ($isErasable == -2) {
4204 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastInvoice");
4205 } elseif ($isErasable == -1) {
4206 $htmltooltip = $langs->trans(
"DisabledBecauseDispatchedInBookkeeping");
4207 } elseif ($isErasable <= 0) {
4208 $htmltooltip = $langs->trans(
"DisabledBecauseNotErasable");
4210 $enableDelete =
true;
4217 if ($action !=
'confirm_edit') {
4218 print
'<div class="fichecenter"><div class="fichehalfleft">';
4225 $filedir = $conf->fournisseur->facture->dir_output.
'/'.$subdir;
4226 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.
$object->id;
4227 $genallowed = $usercanread;
4228 $delallowed = $usercancreate;
4229 $modelpdf = (!empty(
$object->model_pdf) ?
$object->model_pdf : (!
getDolGlobalString(
'INVOICE_SUPPLIER_ADDON_PDF') ?
'' : $conf->global->INVOICE_SUPPLIER_ADDON_PDF));
4231 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
4232 $somethingshown = $formfile->numoffiles;
4235 $linktoelem = $form->showLinkToObjectBlock(
$object, array(), array(
'invoice_supplier'));
4236 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem);
4238 print
'</div><div class="fichehalfright">';
4241 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
4243 $somethingshown = $formactions->showactions(
$object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
4245 print
'</div></div>';
4251 if (
GETPOST(
'modelselected')) {
4252 $action =
'presend';
4256 $modelmail =
'invoice_supplier_send';
4257 $defaulttopic =
'SendBillRef';
4258 $diroutput = $conf->fournisseur->facture->dir_output;
4259 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
4260 $trackid =
'sinv'.$object->id;
4262 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage bank accounts.
Class to manage accounting journals.
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.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
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.
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.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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)
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.
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'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return 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...
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.