42require
'../../main.inc.php';
51require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_invoice/modules_facturefournisseur.php';
55require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
56require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture-rec.class.php';
57require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
58require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
59require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
60require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
61require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
62require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
64 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
65 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
68 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
69 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
73 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
76 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
79$langs->loadLangs(array(
'bills',
'compta',
'suppliers',
'companies',
'products',
'banks',
'admin'));
81 $langs->load(
'incoterm');
86$action =
GETPOST(
'action',
'aZ09');
89$cancel =
GETPOST(
'cancel',
'alpha');
90$backtopage =
GETPOST(
'backtopage',
'alpha');
91$backtopageforcancel =
'';
95$origin =
GETPOST(
'origin',
'alpha');
106$hookmanager->initHooks(array(
'invoicesuppliercard',
'globalcard'));
112$extrafields->fetch_name_optionals_label(
$object->table_element);
115if ($id > 0 || !empty($ref)) {
116 $ret =
$object->fetch($id, $ref);
120 $ret =
$object->fetch_thirdparty();
128if (!empty($user->socid)) {
129 $socid = $user->socid;
133$result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture',
'fk_soc',
'rowid', $isdraft);
136$usercanread = ($user->hasRight(
"fournisseur",
"facture",
"lire") || $user->hasRight(
"supplier_invoice",
"lire"));
137$usercancreate = ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"));
138$usercandelete = (($user->hasRight(
"fournisseur",
"facture",
"supprimer") || $user->hasRight(
"supplier_invoice",
"supprimer")) || ($usercancreate &&
$object->is_erasable() == 1));
139$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
142$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"validate")));
143$usercansend = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"send"));
144$usercancreatecreditransfer = $user->hasRight(
'paymentbybanktransfer',
'create');
147$permissionnote = $usercancreate;
148$permissiondellink = $usercancreate;
149$permissiontoedit = $usercancreate;
150$permissiontoadd = $usercancreate;
151$permissiontodelete = $usercandelete;
152$permissiontoeditextra = $permissiontoadd;
153if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
155 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
166$parameters = array(
'socid' => $socid);
167$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
172if (empty($reshook)) {
173 $backurlforlist =
dolBuildUrl(DOL_URL_ROOT.
'/fourn/facture/list.php');
175 if (empty($backtopage) || ($cancel && empty($id))) {
176 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
177 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
178 $backtopage = $backurlforlist;
180 $backtopage =
dolBuildUrl(DOL_URL_ROOT.
'/fourn/facture/card.php', [
'id' => ((!empty($id) && $id > 0) ? $id :
'__ID__')]);
186 if (!empty($backtopageforcancel)) {
187 header(
"Location: ".$backtopageforcancel);
189 } elseif (!empty($backtopage)) {
190 header(
"Location: ".$backtopage);
196 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
198 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
200 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
203 if (
GETPOST(
'linkedOrder') && empty($cancel) && $id > 0 && $permissiontoadd) {
206 $result =
$object->add_object_linked(
'order_supplier',
GETPOSTINT(
'linkedOrder'));
210 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
212 '@phan-var-force FactureFournisseur $objectutil';
214 if (
GETPOST(
'newsupplierref',
'alphanohtml')) {
215 $objectutil->ref_supplier =
GETPOST(
'newsupplierref',
'alphanohtml');
219 $result = $objectutil->createFromClone($user, $id);
221 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
224 $langs->load(
"errors");
228 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
229 $idwarehouse =
GETPOST(
'idwarehouse');
234 $qualified_for_stock_change = 0;
236 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
238 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
243 $langs->load(
"stocks");
244 if (!$idwarehouse || $idwarehouse == -1) {
246 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
254 $result =
$object->validate($user,
'', $idwarehouse);
261 $categories =
GETPOST(
'categories',
'array:int');
262 if (method_exists($object,
'setCategories')) {
263 $object->setCategories($categories);
271 $outputlangs = $langs;
274 $newlang =
GETPOST(
'lang_id',
'aZ09');
277 $newlang =
$object->thirdparty->default_lang;
279 if (!empty($newlang)) {
281 $outputlangs->setDefaultLang($newlang);
286 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
293 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $permissiontodelete) {
297 $isErasable =
$object->is_erasable();
299 if ($usercandelete && $isErasable > 0) {
300 $revertstock =
GETPOST(
'revertstock');
305 $qualified_for_stock_change = 0;
307 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
309 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
314 $langs->load(
"stocks");
315 if (!$idwarehouse || $idwarehouse == -1) {
317 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
320 $result =
$object->setDraft($user, $idwarehouse);
329 $result =
$object->delete($user);
331 header(
'Location: list.php?restore_lastsearch_values=1');
338 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
340 $result =
$object->deleteLine($lineid);
360 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
367 } elseif ($action ==
'confirm_delete_subtotalline' && $confirm ==
'yes' && $usercancreate) {
372 $result =
$object->deleteSubtotalLine($langs, $lineid, (
bool)
GETPOST(
'deletecorrespondingsubtotalline'));
375 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
381 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
384 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
385 $discount->unlink_invoice();
387 if (
$object->paye == 1 && (
float)
$object->getRemainToPay() > 0) {
390 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercancreate) {
392 $result =
$object->setPaid($user);
396 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercancreate) {
399 $close_code =
GETPOST(
"close_code",
'restricthtml');
400 $close_note =
GETPOST(
"close_note",
'restricthtml');
402 $result =
$object->setPaid($user, $close_code, $close_note);
407 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
409 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
412 $close_code =
GETPOST(
"close_code",
'restricthtml');
413 $close_note =
GETPOST(
"close_note",
'restricthtml');
415 $result =
$object->setCanceled($user, $close_code, $close_note);
420 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
425 if ($action ==
'setref_supplier' && $usercancreate) {
428 if (
$object->update($user) < 0) {
432 $outputlangs = $langs;
435 $newlang =
GETPOST(
'lang_id',
'aZ09');
438 $newlang =
$object->thirdparty->default_lang;
440 if (!empty($newlang)) {
442 $outputlangs->setDefaultLang($newlang);
446 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
452 if ($action ==
'setconditions' && $usercancreate) {
454 $object->cond_reglement_code = 0;
455 $object->cond_reglement_id = 0;
470 $new_date_echeance =
$object->calculate_date_lim_reglement();
471 if ($new_date_echeance) {
472 $object->date_echeance = $new_date_echeance;
477 $result =
$object->update($user);
489 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
492 } elseif ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
495 } elseif ($action ==
'setmode' && $usercancreate) {
498 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
500 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
501 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
504 } elseif ($action ==
'setbankaccount' && $usercancreate) {
507 } elseif ($action ==
'setvatreversecharge' && $usercancreate) {
509 $vatreversecharge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
510 $result =
$object->setVATReverseCharge($vatreversecharge);
513 if ($action ==
'settransportmode' && $usercancreate) {
516 } elseif ($action ==
'setlabel' && $usercancreate) {
520 $result =
$object->update($user);
524 } elseif ($action ==
'setdatef' && $usercancreate) {
528 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
530 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
537 $date_echence_calc =
$object->calculate_date_lim_reglement();
538 if (!empty(
$object->date_echeance)) {
539 $object->date_echeance = $date_echence_calc;
545 $result =
$object->update($user);
549 } elseif ($action ==
'setdate_lim_reglement' && $usercancreate) {
554 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
556 $result =
$object->update($user);
560 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
576 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
578 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
582 $remaintopay =
$object->getRemainToPay(0);
586 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
590 $result = $discount->link_to_invoice(0, $id);
597 $newremaintopay =
$object->getRemainToPay(0);
598 if ($newremaintopay == 0) {
609 $outputlangs = $langs;
612 $newlang =
GETPOST(
'lang_id',
'aZ09');
615 $newlang =
$object->thirdparty->default_lang;
617 if (!empty($newlang)) {
619 $outputlangs->setDefaultLang($newlang);
623 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
628 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
631 $langs->load(
'subtotals');
633 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
634 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
636 $subtotal_options = array();
638 foreach (FactureFournisseur::$TITLE_OPTIONS as $option) {
639 $value =
GETPOST($option,
'alphanohtml');
641 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
646 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
657 $outputlangs = $langs;
658 $newlang =
GETPOST(
'lang_id',
'alpha');
660 $newlang =
$object->thirdparty->default_lang;
662 if (!empty($newlang)) {
664 $outputlangs->setDefaultLang($newlang);
667 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
672 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
674 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
677 $langs->load(
'subtotals');
679 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
680 foreach (
$object->lines as $line) {
681 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
683 $depth = -$line->qty;
687 $subtotal_options = array();
689 foreach (FactureFournisseur::$SUBTOTAL_OPTIONS as $option) {
690 $value =
GETPOST($option,
'alphanohtml');
692 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
697 if (isset($desc) && isset($depth)) {
698 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
701 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
710 $outputlangs = $langs;
711 $newlang =
GETPOST(
'lang_id',
'alpha');
713 $newlang =
$object->thirdparty->default_lang;
715 if (!empty($newlang)) {
717 $outputlangs->setDefaultLang($newlang);
720 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
725 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
727 } elseif ($action ==
'confirm_addtextline' && $usercancreate) {
730 $langs->load(
'subtotals');
732 $desc =
GETPOST(
'subtotaltextcontent',
'restricthtml');
735 $result =
$object->addSubtotalLine($langs, $desc, 0, array());
746 $outputlangs = $langs;
747 $newlang =
GETPOST(
'lang_id',
'alpha');
749 $newlang =
$object->thirdparty->default_lang;
751 if (!empty($newlang)) {
753 $outputlangs->setDefaultLang($newlang);
756 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
761 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
763 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
771 $result = $discountcheck->fetch(0, 0,
$object->id);
783 $amount_ht = $amount_tva = $amount_ttc = array();
784 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
788 foreach (
$object->lines as $line) {
789 if ($line->product_type < 9 && $line->total_ht != 0) {
790 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
792 $amount_ht[$keyforvatrate] += $line->total_ht;
793 $amount_tva[$keyforvatrate] += $line->total_tva;
794 $amount_ttc[$keyforvatrate] += $line->total_ttc;
795 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
796 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
797 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
801 '@phan-var-force array<string,float> $amount_ht
802 @phan-var-force array<string,float> $amount_tva
803 @phan-var-force array<string,float> $amount_ttc
804 @phan-var-force array<string,float> $multicurrency_amount_ht
805 @phan-var-force array<string,float> $multicurrency_amount_tva
806 @phan-var-force array<string,float> $multicurrency_amount_ttc';
810 $alreadypaid =
$object->getSommePaiement();
811 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
812 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
813 foreach ($amount_ht as $vatrate => $val) {
814 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
815 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
816 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
817 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
818 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
819 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
828 $discount->description =
'(CREDIT_NOTE)';
830 $discount->description =
'(DEPOSIT)';
832 $discount->description =
'(EXCESS PAID)';
834 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
836 $discount->discount_type = 1;
837 $discount->fk_soc =
$object->socid;
838 $discount->socid =
$object->socid;
839 $discount->fk_invoice_supplier_source =
$object->id;
847 $sql =
'SELECT SUM(pf.amount) as total_paiements';
848 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'paiementfourn as p';
849 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN ('.
getEntity(
'c_paiement').
')';
850 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
851 $sql .=
' AND pf.fk_paiementfourn = p.rowid';
852 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
854 $resql =
$db->query($sql);
859 $res =
$db->fetch_object($resql);
860 $total_paiements = $res->total_paiements;
863 $total_creditnote_and_deposit = 0;
864 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
865 $sql .=
" re.description, re.fk_invoice_supplier_source";
866 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
867 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
868 $resql =
$db->query($sql);
869 if (!empty($resql)) {
870 while ($obj =
$db->fetch_object($resql)) {
871 $total_creditnote_and_deposit += $obj->amount_ttc;
877 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
878 $discount->amount_tva = 0;
879 $discount->tva_tx = 0;
880 $discount->vat_src_code =
'';
883 $discount->multicurrency_code =
$object->multicurrency_code;
884 $discount->multicurrency_tx =
$object->multicurrency_tx;
885 $discount->multicurrency_total_ht = $discount->multicurrency_total_ttc = (float)
price2num((
float) $discount->amount_ttc * (float)
$object->multicurrency_tx,
'MT');
886 $discount->multicurrency_total_tva = 0;
888 $discount->multicurrency_amount_ht = $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
889 $discount->multicurrency_amount_tva = 0;
891 $result = $discount->create($user);
897 foreach ($amount_ht as $tva_tx => $xxx) {
898 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
899 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
900 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
902 $discount->multicurrency_code =
$object->multicurrency_code;
903 $discount->multicurrency_tx =
$object->multicurrency_tx;
904 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
905 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
906 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
908 $discount->multicurrency_amount_ht = abs((
float) $discount->multicurrency_total_ht);
909 $discount->multicurrency_amount_tva = abs((
float) $discount->multicurrency_total_tva);
910 $discount->multicurrency_amount_ttc = abs((
float) $discount->multicurrency_total_ttc);
915 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
916 $vat_src_code = $reg[1];
917 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
920 $discount->tva_tx = abs((
float) $tva_tx);
921 $discount->vat_src_code = $vat_src_code;
923 $result = $discount->create($user);
934 $result =
$object->setPaid($user);
949 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate) {
954 $result = $paiementfourn->fetch(
GETPOSTINT(
'paiement_id'));
956 $result = $paiementfourn->delete($user);
958 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
966 } elseif ($action ==
'add' && $usercancreate) {
971 $selectedLines =
GETPOST(
'toselect',
'array:int');
979 $ret = $extrafields->setOptionalsFromPost(
null, $object);
993 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
998 if (empty($dateinvoice)) {
999 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1011 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1025 $object->date_echeance = $datedue;
1031 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1032 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1034 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1035 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1054 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1056 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1059 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1064 if (empty($dateinvoice)) {
1065 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1075 if (!
GETPOST(
'ref_supplier')) {
1076 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
1084 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1099 $object->date_echeance = $datedue;
1105 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1106 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1108 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1109 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1114 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1123 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1125 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1126 $fk_parent_line = 0;
1128 foreach ($facture_source->lines as $line) {
1130 if (method_exists($line,
'fetch_optionals')) {
1131 $line->fetch_optionals();
1135 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1136 $fk_parent_line = 0;
1139 $line->fk_facture_fourn =
$object->id;
1140 $line->fk_parent_line = $fk_parent_line;
1142 $line->subprice = -$line->subprice;
1143 $line->pa_ht = -((float) $line->pa_ht);
1144 $line->total_ht = -$line->total_ht;
1145 $line->total_tva = -$line->total_tva;
1146 $line->total_ttc = -$line->total_ttc;
1147 $line->total_localtax1 = -$line->total_localtax1;
1148 $line->total_localtax2 = -$line->total_localtax2;
1149 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1150 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1151 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1153 $result = $line->insert();
1158 if ($result > 0 && $line->product_type == 9) {
1159 $fk_parent_line = $result;
1167 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 &&
$id > 0) {
1169 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1170 $totalpaid = $facture_source->getSommePaiement();
1171 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1172 $totaldeposits = $facture_source->getSumDepositsUsed();
1173 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1174 $desc = $langs->trans(
'invoiceAvoirLineWithPaymentRestAmount');
1177 $retAddLine =
$object->addline($desc, -$remain_to_pay, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
'TTC');
1179 if ($retAddLine < 0) {
1186 if (!empty(
$object->fk_facture_source) && $id > 0) {
1188 if ($facture_source_link->fetch(
$object->fk_facture_source) > 0) {
1189 $facture_source_link->fetchObjectLinked();
1190 if (!empty($facture_source_link->linkedObjectsIds)) {
1191 foreach ($facture_source_link->linkedObjectsIds as $sourcetype => $TIds) {
1192 $object->add_object_linked($sourcetype, current($TIds));
1200 if (empty($dateinvoice)) {
1202 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1212 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1222 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1223 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1232 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1233 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1237 $object->fac_rec = $fac_recid;
1239 $fac_rec->fetch(
$object->fac_rec);
1240 $fac_rec->fetch_lines();
1241 $object->lines = $fac_rec->lines;
1248 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1253 if (empty($dateinvoice)) {
1254 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1264 if (!
GETPOST(
'ref_supplier')) {
1265 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
1273 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1290 $object->date_echeance = $datedue;
1296 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1297 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1299 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1300 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1305 if (empty(
$object->date_echeance)) {
1306 $object->date_echeance =
$object->calculate_date_lim_reglement();
1312 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
1314 $element = $subelement =
GETPOST(
'origin',
'alpha');
1322 if ($element ==
'order') {
1323 $element = $subelement =
'commande';
1325 if ($element ==
'propal') {
1326 $element =
'comm/propal';
1327 $subelement =
'propal';
1329 if ($element ==
'contract') {
1330 $element = $subelement =
'contrat';
1332 if ($element ==
'order_supplier') {
1334 $subelement =
'fournisseur.commande';
1336 if ($element ==
'project') {
1337 $element =
'projet';
1345 $classname = ucfirst($subelement);
1346 if ($classname ==
'Fournisseur.commande') {
1347 $classname =
'CommandeFournisseur';
1349 $objectsrc =
new $classname(
$db);
1350 $objectsrc->fetch($originid);
1351 $objectsrc->fetch_thirdparty();
1353 if (!empty(
$object->origin_type) && !empty(
$object->origin_id)) {
1358 if (
$object->origin_type ==
'reception') {
1359 $objectsrc->fetchObjectLinked();
1361 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1362 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1363 $object->linkedObjectsIds[
'order_supplier'][-1] = $value;
1373 $classname = ucfirst($subelement);
1374 if ($classname ==
'Fournisseur.commande') {
1375 $classname =
'CommandeFournisseur';
1377 $srcobject =
new $classname(
$db);
1379 $result = $srcobject->fetch(
GETPOSTINT(
'originid'));
1382 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1387 $amountdeposit = array();
1389 if ($typeamount ==
'amount') {
1390 $amount = $valuedeposit;
1392 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1395 $TTotalByTva = array();
1396 foreach ($srcobject->lines as &$line) {
1397 if (!empty($line->special_code)) {
1400 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1402 '@phan-var-force array<string,float> $TTotalByTva';
1404 $amount_ttc_diff = 0.;
1405 foreach ($TTotalByTva as $tva => &$total) {
1406 $coef = $total / $srcobject->total_ttc;
1407 $am = $amount * $coef;
1408 $amount_ttc_diff += $am;
1409 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1412 if ($typeamount ==
'amount') {
1413 $amountdeposit[0] = $valuedeposit;
1414 } elseif ($typeamount ==
'variable') {
1417 $lines = $srcobject->lines;
1418 $numlines = count($lines);
1419 for ($i = 0; $i < $numlines; $i++) {
1421 if (empty($lines[$i]->qty)) {
1424 if (!empty($lines[$i]->special_code)) {
1428 $totalamount += $lines[$i]->total_ht;
1429 $tva_tx = $lines[$i]->tva_tx;
1430 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1434 if ($totalamount == 0) {
1435 $amountdeposit[0] = 0;
1440 $amountdeposit[0] = 0;
1444 $amount_ttc_diff = array_key_exists(0, $amountdeposit) ? $amountdeposit[0] : 0;
1447 foreach ($amountdeposit as $tva => $amount) {
1448 if (empty($amount)) {
1453 'amount' =>
'FixAmount',
1454 'variable' =>
'VarAmount'
1456 $descline =
'(DEPOSIT)';
1458 if ($typeamount ==
'amount') {
1459 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1460 } elseif ($typeamount ==
'variable') {
1461 $descline .=
' ('.$valuedeposit.
'%)';
1464 $descline .=
' - '.$srcobject->ref;
1494 $diff =
$object->total_ttc - $amount_ttc_diff;
1498 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1504 $object->lines[0]->localtax1_tx,
1505 $object->lines[0]->localtax2_tx,
1507 $object->lines[0]->fk_product,
1510 $object->lines[0]->product_type,
1511 $object->lines[0]->remise_percent,
1513 $object->lines[0]->date_start,
1522 } elseif ($result > 0) {
1523 $lines = $srcobject->lines;
1524 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1525 $srcobject->fetch_lines();
1526 $lines = $srcobject->lines;
1529 $num = count($lines);
1530 for ($i = 0; $i < $num; $i++) {
1531 if (!in_array($lines[$i]->
id, $selectedLines)) {
1535 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->product_label);
1536 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1539 if (method_exists($lines[$i],
'fetch_optionals')) {
1540 $lines[$i]->fetch_optionals();
1546 if ($lines[$i]->date_debut_reel) {
1549 if ($lines[$i]->date_start) {
1552 $date_end = $lines[$i]->date_fin_prevue;
1553 if ($lines[$i]->date_fin_reel) {
1554 $date_end = $lines[$i]->date_fin_reel;
1556 if ($lines[$i]->date_end) {
1557 $date_end = $lines[$i]->date_end;
1560 $tva_tx = $lines[$i]->tva_tx;
1562 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
1563 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1567 $object->special_code = $lines[$i]->special_code;
1571 $line_price_base_type = $lines[$i]->getPriceBaseType();
1572 if ($line_price_base_type ===
'TTC') {
1574 $pu = (float) $lines[$i]->subprice_ttc;
1576 } elseif (
$object->multicurrency_code !=
$conf->currency ||
$object->multicurrency_tx != 1) {
1578 $pu_currency = $lines[$i]->multicurrency_subprice;
1580 $pu = $lines[$i]->subprice;
1589 $lines[$i]->localtax1_tx,
1590 $lines[$i]->localtax2_tx,
1592 $lines[$i]->fk_product,
1593 $lines[$i]->remise_percent,
1597 $lines[$i]->info_bits,
1598 $line_price_base_type,
1602 $lines[$i]->array_options,
1603 $lines[$i]->fk_unit,
1606 $lines[$i]->ref_supplier,
1607 $lines[$i]->special_code
1624 $parameters = array(
'objFrom' => $srcobject);
1625 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1635 } elseif (!$error) {
1645 $langs->load(
"errors");
1655 $outputlangs = $langs;
1656 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1663 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1666 } elseif ($action ==
'updateline' && $usercancreate) {
1670 if (!
$object->fetch($id) > 0) {
1676 $tva_tx = str_replace(
'*',
'', $tva_tx);
1685 $price_base_type =
'HT';
1686 if (empty($pu_ht) && !empty($pu_ttc)) {
1688 $price_base_type =
'TTC';
1689 } elseif (!empty($pu_ht) && !empty($pu_ttc)) {
1690 foreach (
$object->lines as $line_obj) {
1693 if ($line_obj->wasEnteredIncludingTax()) {
1695 $price_base_type =
'TTC';
1702 if (
GETPOST(
'productid') > 0) {
1704 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY') == 1) {
1706 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1712 $label =
$prod->description;
1713 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1714 $label =
GETPOST(
'product_desc',
'restricthtml');
1717 $type =
$prod->type;
1719 $label =
GETPOST(
'product_desc',
'restricthtml');
1728 if (preg_match(
'/\*/', $tva_tx)) {
1733 $tva_tx = str_replace(
'*',
'', $tva_tx);
1741 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1742 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1744 if (is_array($extralabelsline)) {
1745 foreach ($extralabelsline as $key => $value) {
1746 unset($_POST[
"options_".$key]);
1750 $result =
$object->updateline(
1762 (
float) $remise_percent,
1772 unset($_POST[
'label']);
1773 unset($_POST[
'fourn_ref']);
1774 unset($_POST[
'date_starthour']);
1775 unset($_POST[
'date_startmin']);
1776 unset($_POST[
'date_startsec']);
1777 unset($_POST[
'date_startday']);
1778 unset($_POST[
'date_startmonth']);
1779 unset($_POST[
'date_startyear']);
1780 unset($_POST[
'date_endhour']);
1781 unset($_POST[
'date_endmin']);
1782 unset($_POST[
'date_endsec']);
1783 unset($_POST[
'date_endday']);
1784 unset($_POST[
'date_endmonth']);
1785 unset($_POST[
'date_endyear']);
1786 unset($_POST[
'price_ttc']);
1787 unset($_POST[
'price_ht']);
1794 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
1798 foreach (
$object->lines as $line) {
1799 if ($line->product_type == 1) {
1801 $line_price_base_type = $line->getPriceBaseType();
1802 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
1803 $result =
$object->updateline($line->id, $line->desc, $line_pu, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->qty, $line->fk_product, $line_price_base_type, $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);
1806 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
1808 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
1809 $remise_percent = (float) str_replace(
'*',
'', $remise_percent);
1810 foreach (
$object->lines as $line) {
1812 $line_price_base_type = $line->getPriceBaseType();
1813 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
1814 $result =
$object->updateline($line->id, $line->desc, $line_pu, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->qty, $line->fk_product, $line_price_base_type, $line->info_bits, $line->product_type, $remise_percent, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier, $line->rang);
1816 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !=
'' && $usercancreate) {
1818 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1819 $vat_rate = str_replace(
'*',
'', $vat_rate);
1822 foreach (
$object->lines as $line) {
1824 $line_price_base_type = $line->getPriceBaseType();
1825 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
1826 $result =
$object->updateline($line->id, $line->desc, $line_pu, $vat_rate, $localtax1_rate, $localtax2_rate, $line->qty, $line->fk_product, $line_price_base_type, $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);
1828 } elseif ($action ==
'addline' && $usercancreate) {
1837 $ret =
$object->fetch_thirdparty();
1839 $langs->load(
'errors');
1844 $line_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
1848 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1849 if ($prod_entry_mode ==
'free') {
1856 $price_ht_devise =
'';
1858 $price_ttc_devise =
'';
1860 if (
GETPOST(
'price_ht') !==
'') {
1863 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
1866 if (
GETPOST(
'price_ttc') !==
'') {
1869 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
1870 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
1877 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
1878 if (empty($remise_percent)) {
1879 $remise_percent = 0;
1883 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1884 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
1886 if (is_array($extralabelsline)) {
1888 foreach ($extralabelsline as $key => $value) {
1889 unset($_POST[
"options_".$key]);
1893 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
1894 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1897 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOSTINT(
'type') < 0) {
1898 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
1903 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1')
1904 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
1905 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
1906 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
1907 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
1908 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
1909 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) {
1910 $langs->load(
"errors");
1911 if (
$object->type == $object::TYPE_DEPOSIT) {
1913 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
1915 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPrice"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
1920 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
1921 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
1925 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') && !
GETPOST(
'dp_desc')) {
1926 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
1929 if (!
GETPOST(
'qty',
'alpha')) {
1930 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1934 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
1935 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
1939 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1940 $idprod = $res->fk_product_child;
1942 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
1948 if ($prod_entry_mode !=
'free' && empty($error)) {
1952 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
1957 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
1958 $idprod = (int) $reg[1];
1959 $res = $productsupplier->fetch($idprod);
1962 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
1964 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1965 if ($productsupplier->fourn_socid != $socid) {
1966 $productsupplier->ref_supplier =
'';
1969 $fksoctosearch =
$object->thirdparty->id;
1970 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1972 } elseif (
GETPOSTINT(
'idprodfournprice') > 0) {
1973 $qtytosearch = (float) $qty;
1975 $idprod = $productsupplier->get_buyprice(
GETPOSTINT(
'idprodfournprice'), $qtytosearch);
1976 $res = $productsupplier->fetch($idprod);
1980 $label = $productsupplier->label;
1983 $outputlangs = $langs;
1985 if (
GETPOST(
'lang_id',
'aZ09')) {
1986 $newlang =
GETPOST(
'lang_id',
'aZ09');
1988 if (empty($newlang)) {
1989 $newlang =
$object->thirdparty->default_lang;
1991 if (!empty($newlang)) {
1993 $outputlangs->setDefaultLang($newlang);
1995 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
1997 $desc = $productsupplier->description;
2000 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
2001 $desc = $productsupplier->desc_supplier;
2012 $ref_supplier = $productsupplier->ref_supplier;
2015 if (!GETPOSTISSET(
'tva_tx')) {
2016 $tmpidprodfournprice =
GETPOST(
'idprodfournprice',
'alpha');
2017 if (is_numeric($tmpidprodfournprice) && (
int) $tmpidprodfournprice > 0) {
2018 $tmpidprodfournprice = (int) $tmpidprodfournprice;
2020 $tmpidprodfournprice = 0;
2026 if (empty($tva_tx) || empty($tva_npr)) {
2032 $type = $productsupplier->type;
2033 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
2034 $price_base_type =
'HT';
2036 $pu_devise =
price2num($price_ht_devise,
'CU');
2037 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
2038 $price_base_type =
'TTC';
2040 $pu_devise =
price2num($price_ttc_devise,
'CU');
2042 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
2043 if (empty(
$object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code !=
$object->multicurrency_code)) {
2044 $pu = $productsupplier->fourn_pu;
2047 $pu = $productsupplier->fourn_pu;
2048 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
2052 $ref_supplier = $productsupplier->ref_supplier;
2073 min($rank, count(
$object->lines) + 1),
2076 $productsupplier->fk_unit,
2079 GETPOST(
'fourn_ref',
'alpha'),
2083 if ($idprod == -99 || $idprod == 0) {
2086 $langs->load(
"errors");
2087 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2089 if ($idprod == -1) {
2092 $langs->load(
"errors");
2093 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
2095 } elseif (empty($error)) {
2096 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2097 $tva_tx = str_replace(
'*',
'', $tva_tx);
2098 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2101 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
2105 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
2114 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
2115 $price_base_type =
'HT';
2117 $pu_devise =
price2num($price_ht_devise,
'CU');
2119 $price_base_type =
'TTC';
2121 $pu_devise =
price2num($price_ttc_devise,
'CU');
2124 $result =
$object->addline($line_desc, (
float) $pu, $tva_tx, $localtax1_tx, $localtax2_tx, (
float) $qty, 0, $remise_percent,
$date_start, $date_end, 0, $tva_npr, $price_base_type, $type, -1, 0, $array_options, $fk_unit, 0, (
float) $pu_devise, $ref_supplier);
2128 if (!$error && $result > 0) {
2133 $outputlangs = $langs;
2136 $newlang =
GETPOST(
'lang_id',
'aZ09');
2139 $newlang =
$object->thirdparty->default_lang;
2141 if (!empty($newlang)) {
2143 $outputlangs->setDefaultLang($newlang);
2148 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2154 unset($_POST [
'prod_entry_mode']);
2156 unset($_POST[
'qty']);
2157 unset($_POST[
'type']);
2158 unset($_POST[
'remise_percent']);
2159 unset($_POST[
'pu']);
2160 unset($_POST[
'price_ht']);
2161 unset($_POST[
'multicurrency_price_ht']);
2162 unset($_POST[
'price_ttc']);
2163 unset($_POST[
'fourn_ref']);
2164 unset($_POST[
'tva_tx']);
2165 unset($_POST[
'label']);
2166 unset($localtax1_tx);
2167 unset($localtax2_tx);
2168 unset($_POST[
'np_marginRate']);
2169 unset($_POST[
'np_markRate']);
2170 unset($_POST[
'dp_desc']);
2171 unset($_POST[
'idprodfournprice']);
2172 unset($_POST[
'units']);
2174 unset($_POST[
'date_starthour']);
2175 unset($_POST[
'date_startmin']);
2176 unset($_POST[
'date_startsec']);
2177 unset($_POST[
'date_startday']);
2178 unset($_POST[
'date_startmonth']);
2179 unset($_POST[
'date_startyear']);
2180 unset($_POST[
'date_endhour']);
2181 unset($_POST[
'date_endmin']);
2182 unset($_POST[
'date_endsec']);
2183 unset($_POST[
'date_endday']);
2184 unset($_POST[
'date_endmonth']);
2185 unset($_POST[
'date_endyear']);
2187 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
2195 } elseif ($action ==
'classin' && $usercancreate) {
2197 $result =
$object->setProject($projectid);
2198 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
2202 $totalpaid =
$object->getSommePaiement();
2203 $resteapayer =
$object->total_ttc - $totalpaid;
2206 $ventilExportCompta =
$object->getVentilExportCompta();
2208 if (!$ventilExportCompta) {
2211 $idwarehouse =
GETPOST(
'idwarehouse');
2215 $qualified_for_stock_change = 0;
2217 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2219 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2224 $langs->load(
"stocks");
2225 if (!$idwarehouse || $idwarehouse == -1) {
2227 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
2232 $object->setDraft($user, $idwarehouse);
2236 $outputlangs = $langs;
2239 $newlang =
GETPOST(
'lang_id',
'aZ09');
2242 $newlang =
$object->thirdparty->default_lang;
2244 if (!empty($newlang)) {
2246 $outputlangs->setDefaultLang($newlang);
2251 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2260 } elseif ($action ==
'reopen' && $usercancreate) {
2262 $result =
$object->fetch($id);
2265 $result =
$object->setUnpaid($user);
2267 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
2276 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2279 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
2281 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
2282 $trackid =
'sinv'.$object->id;
2283 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2287 $permissiontoadd = $usercancreate;
2288 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2291 if ($action ==
'calculate' && $usercancreate) {
2292 $calculationrule =
GETPOST(
'calculationrule');
2296 $result =
$object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0,
$object->thirdparty);
2302 if ($action ==
'update_extras' && $permissiontoeditextra) {
2305 $attribute_name =
GETPOST(
'attribute',
'aZ09');
2308 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
2314 $result =
$object->updateExtraField($attribute_name,
'BILL_SUPPLIER_MODIFY');
2322 $action =
'edit_extras';
2327 if ($action ==
'addcontact' && $usercancreate) {
2328 $result =
$object->fetch($id);
2330 if ($result > 0 && $id > 0) {
2333 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2337 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2340 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2341 $langs->load(
"errors");
2342 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2347 } elseif ($action ==
'swapstatut' && $usercancreate) {
2354 } elseif ($action ==
'deletecontact' && $usercancreate) {
2360 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2384$title =
$object->ref.
" - ".$langs->trans(
'Card');
2385if ($action ==
'create') {
2386 $title = $langs->trans(
"NewSupplierInvoice");
2388$help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
2389llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-fourn-facture page-card');
2392if ($action ==
'create') {
2394 $selectedLines = array();
2396 print
load_fiche_titre($langs->trans(
'NewSupplierInvoice'),
'',
'supplier_invoice');
2400 $currency_code =
$conf->currency;
2401 $vat_reverse_charge = 0;
2407 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2408 $currency_code = $societe->multicurrency_code;
2413 if (!empty($origin) && !empty($originid)) {
2415 $element = $subelement = $origin;
2417 if ($element ==
'project') {
2418 $projectid = $originid;
2419 $element =
'projet';
2423 if ($element ==
'order') {
2424 $element = $subelement =
'commande';
2426 if ($element ==
'propal') {
2427 $element =
'comm/propal';
2428 $subelement =
'propal';
2430 if ($element ==
'contract') {
2431 $element = $subelement =
'contrat';
2433 if ($element ==
'order_supplier') {
2435 $subelement =
'fournisseur.commande';
2439 $classname = ucfirst($subelement);
2440 if ($classname ==
'Fournisseur.commande') {
2441 $classname =
'CommandeFournisseur';
2443 $objectsrc =
new $classname(
$db);
2444 '@phan-var-force Project|Commande|Propal|Facture|Contrat|CommandeFournisseur|CommonObject $objectsrc';
2446 $objectsrc->fetch($originid);
2447 $objectsrc->fetch_thirdparty();
2449 $projectid = (int) $objectsrc->fk_project;
2451 $soc = $objectsrc->thirdparty;
2453 $cond_reglement_id = 0;
2454 $mode_reglement_id = 0;
2456 $transport_mode_id = 0;
2459 if (!empty($objectsrc->cond_reglement_id)) {
2460 $cond_reglement_id = $objectsrc->cond_reglement_id;
2462 if (!empty($objectsrc->mode_reglement_id)) {
2463 $mode_reglement_id = $objectsrc->mode_reglement_id;
2465 if (!empty($objectsrc->fk_account)) {
2466 $fk_account = $objectsrc->fk_account;
2468 if (!empty($objectsrc->transport_mode_id)) {
2469 $transport_mode_id = $objectsrc->transport_mode_id;
2472 if (empty($cond_reglement_id)
2473 || empty($mode_reglement_id)
2474 || empty($fk_account)
2475 || empty($transport_mode_id)
2477 if ($origin ==
'reception') {
2479 if (!isset($objectsrc->supplier_order)) {
2480 $objectsrc->fetch_origin();
2483 if (!empty($objectsrc->origin_object)) {
2484 $originObject = $objectsrc->origin_object;
2485 if (empty($cond_reglement_id) && !empty($originObject->cond_reglement_id)) {
2486 $cond_reglement_id = $originObject->cond_reglement_id;
2488 if (empty($mode_reglement_id) && !empty($originObject->mode_reglement_id)) {
2489 $mode_reglement_id = $originObject->mode_reglement_id;
2491 if (empty($fk_account) && !empty($originObject->fk_account)) {
2492 $fk_account = $originObject->fk_account;
2494 if (empty($transport_mode_id) && !empty($originObject->transport_mode_id)) {
2495 $transport_mode_id = $originObject->transport_mode_id;
2502 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
2503 $cond_reglement_id = $soc->cond_reglement_supplier_id;
2505 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
2506 $mode_reglement_id = $soc->mode_reglement_supplier_id;
2508 if (empty($fk_account) && !empty($soc->fk_account)) {
2509 $fk_account = $soc->fk_account;
2511 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
2512 $transport_mode_id = $soc->transport_mode_id;
2518 if (!empty($objectsrc->multicurrency_code)) {
2519 $currency_code = $objectsrc->multicurrency_code;
2521 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
2522 $currency_tx = $objectsrc->multicurrency_tx;
2527 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2529 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2532 $objectsrc->fetch_optionals();
2533 $object->array_options = $objectsrc->array_options;
2535 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2536 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2537 $vat_reverse_charge = (empty($societe) ?
'' : $societe->vat_reverse_charge);
2538 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2539 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2541 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalInt(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2543 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2545 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2546 $currency_code = $societe->multicurrency_code;
2551 if (empty($cond_reglement_id)) {
2552 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2556 if (empty($mode_reglement_id)) {
2557 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2561 if (!
GETPOST(
'changecompany')) {
2562 if (GETPOSTISSET(
'cond_reglement_id')) {
2563 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
2565 if (GETPOSTISSET(
'mode_reglement_id')) {
2566 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
2568 if (GETPOSTISSET(
'cond_reglement_id')) {
2573 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
2574 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
2576 if ($origin ==
'contrat') {
2577 $langs->load(
"admin");
2578 $text = $langs->trans(
"ToCreateARecurringInvoice");
2579 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"SupplierBills"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
2581 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
2583 print
info_admin($text, 0, 0,
'0',
'opacitymedium').
'<br>';
2586 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2587 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2588 print
'<input type="hidden" name="action" value="add">';
2589 print
'<input type="hidden" name="changecompany" value="0">';
2591 if (!empty($societe->id) && $societe->id > 0) {
2592 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2594 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2595 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2596 if (!empty($currency_tx)) {
2597 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2599 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2604 $parameters = array();
2606 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierInvoice', $parameters, $object, $action);
2607 if (empty($reshook)) {
2608 print
'<table class="border centpercent">';
2615 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2616 $invoice_predefined->fetch($fac_recid);
2620 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2623 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2624 $absolute_discount = $societe->getAvailableDiscounts(
null,
'', 0, 1);
2625 print $societe->getNomUrl(1,
'supplier');
2626 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2628 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2629 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');
2632 print
'<script type="text/javascript">
2633 $(document).ready(function() {
2634 $("#socid").change(function() {
2635 console.log("We have changed the company - Reload page");
2637 $("input[name=action]").val("create");
2638 $("input[name=changecompany]").val("1");
2639 $("form[name=add]").submit();
2644 if ($fac_recid <= 0) {
2645 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>';
2651 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2652 $invoice_predefined->fetch($fac_recid);
2654 $dateinvoice = $invoice_predefined->date_when;
2655 if (empty($projectid)) {
2656 $projectid = $invoice_predefined->fk_project;
2658 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2659 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2660 $fk_account = $invoice_predefined->fk_account;
2661 $note_public = $invoice_predefined->note_public;
2662 $note_private = $invoice_predefined->note_private;
2664 if (!empty($invoice_predefined->multicurrency_code)) {
2665 $currency_code = $invoice_predefined->multicurrency_code;
2667 if (!empty($invoice_predefined->multicurrency_tx)) {
2668 $currency_tx = $invoice_predefined->multicurrency_tx;
2671 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2672 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2673 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2675 $resql =
$db->query($sql);
2677 $num =
$db->num_rows($resql);
2681 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2683 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2684 print
'<option value="0" selected></option>';
2686 $objp =
$db->fetch_object($resql);
2687 print
'<option value="'.$objp->rowid.
'"';
2688 if ($fac_recid == $objp->rowid) {
2690 $exampletemplateinvoice->fetch($fac_recid);
2692 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2698 print
'<script type="text/javascript">
2699 $(document).ready(function() {
2700 $("#fac_rec").change(function() {
2701 console.log("We have changed the template invoice - Reload page");
2703 $("input[name=action]").val("create");
2704 $("form[name=add]").submit();
2717 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2719 print
'<div class="tagtable">'.
"\n";
2722 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2723 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
'checked').
'> ';
2724 $desc = $form->textwithpicto($tmp.
'<label for="radio_standard">'.$langs->trans(
"InvoiceStandardAsk").
'</label>', $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2726 print
'</div></div>';
2728 if (empty($origin) || (($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') && !empty($originid))) {
2731 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2732 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOSTINT(
'type') == 3 ?
' checked' :
'') .
'> ';
2733 print
'<script type="text/javascript">
2734 jQuery(document).ready(function() {
2735 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2736 jQuery("#radio_standard").prop("checked", true);
2738 jQuery("#typedeposit, #valuedeposit").click(function() {
2739 jQuery("#radio_deposit").prop("checked", true);
2741 jQuery("#typedeposit").change(function() {
2742 console.log("We change type of down payment");
2743 jQuery("#radio_deposit").prop("checked", true);
2744 setRadioForTypeOfInvoice();
2746 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2747 setRadioForTypeOfInvoice();
2749 function setRadioForTypeOfInvoice() {
2750 console.log("Change radio");
2751 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2752 jQuery(".checkforselect").prop("disabled", true);
2753 jQuery(".checkforselect").prop("checked", false);
2755 jQuery(".checkforselect").prop("disabled", false);
2756 jQuery(".checkforselect").prop("checked", true);
2762 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2764 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2765 print
'<table class="nobordernopadding"><tr>';
2769 if ($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') {
2770 print
'<td class="nowrap" style="padding-left: 15px">';
2772 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2773 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2774 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2776 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
2777 $valuedeposit =
GETPOST(
'valuedeposit',
'int');
2778 $deposit_percent =
null;
2779 if ($origin ==
'reception') {
2781 if (!isset($objectsrc->origin_object)) {
2782 $objectsrc->fetch_origin();
2784 if (!empty($objectsrc->origin_object)) {
2785 $deposit_percent = $objectsrc->origin_object->deposit_percent;
2787 } elseif (!empty($objectsrc->deposit_percent)) {
2788 $deposit_percent = $objectsrc->deposit_percent;
2790 if (empty($typedeposit) && !empty($deposit_percent)) {
2791 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
2792 if (!empty($origin_payment_conditions_deposit_percent)) {
2793 $typedeposit =
'variable';
2796 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($deposit_percent)) {
2797 $valuedeposit = $deposit_percent;
2799 print $form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
2801 print
'<td class="nowrap" style="padding-left: 5px">';
2802 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' . $valuedeposit .
'"/>';
2805 print
'</tr></table>';
2807 print
'</div></div>';
2876 if (empty($origin)) {
2877 if (!empty($societe->id) && $societe->id > 0) {
2881 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2888 foreach ($facids as $key => $valarray) {
2889 $newinvoice_static->id = $key;
2890 $newinvoice_static->ref = $valarray [
'ref'];
2891 $newinvoice_static->status = $valarray [
'status'];
2892 $newinvoice_static->statut = $valarray [
'status'];
2893 $newinvoice_static->type = $valarray [
'type'];
2894 $newinvoice_static->paid = $valarray [
'paye'];
2895 $newinvoice_static->paye = $valarray [
'paye'];
2897 $optionsav .=
'<option value="'.$key.
'"';
2899 $optionsav .=
' selected';
2901 $newinvoice_static->fetch_optionals($key);
2902 $object->array_options = $newinvoice_static->array_options;
2905 $optionsav .= $newinvoice_static->ref;
2906 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
2907 $optionsav .=
'</option>';
2910 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2911 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOSTINT(
'type') == 2 ?
' checked' :
'');
2913 $tmp .=
' disabled';
2917 print
'<script type="text/javascript">
2918 jQuery(document).ready(function() {
2919 if (! jQuery("#radio_creditnote").is(":checked"))
2921 jQuery("#credit_note_options").hide();
2923 jQuery("#radio_creditnote").click(function() {
2924 jQuery("#credit_note_options").show();
2926 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2927 jQuery("#credit_note_options").hide();
2931 $text = $tmp.
'<label for="radio_creditnote">'.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
2933 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2935 $text .=
' disabled';
2939 $text .=
'<option value="-1"></option>';
2940 $text .= $optionsav;
2942 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
2944 $text .=
'</select>';
2945 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2948 print
'<div id="credit_note_options" class="clearboth">';
2949 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' :
'').
' /> ';
2950 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
2951 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' :
'').
' /> ';
2952 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
2955 print
'</div></div>';
2958 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2960 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2962 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2"> ';
2964 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
2965 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
2966 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2968 print
'</div></div>'.
"\n";
2978 print
'<tr><td class="fieldrequired">';
2979 print $form->textwithpicto($langs->trans(
'RefSupplierBill'), $langs->trans(
"RefOfOnVendorSide", $langs->trans(
"SupplierBill"))).
'</td><td>';
2980 print
'<input name="ref_supplier" value="'.(GETPOSTISSET(
'ref_supplier') ?
GETPOST(
'ref_supplier') : (!empty($objectsrc->ref_supplier) ? $objectsrc->ref_supplier :
'')).
'" type="text" spellcheck="false"';
2981 if (!empty($societe->id) && $societe->id > 0) {
2990 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
2991 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
2995 if (!empty($societe->id) && $societe->id > 0) {
2997 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2999 $thirdparty = $societe;
3001 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
3002 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3008 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth300" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
3012 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
3013 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3014 print $form->selectDate($dateinvoice ? (
int) $dateinvoice :
'',
'', 0, 0, 0,
"add", 1, 1);
3018 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
3019 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
3020 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth200 widthcentpercentminusx');
3024 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
3025 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3026 print $form->selectDate($datedue,
'ech', 0, 0, 0,
"add", 1, 1);
3030 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
3031 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
3032 $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'DBIT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
3037 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
3039 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
3047 $langs->load(
'projects');
3048 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
3049 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');
3050 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>';
3057 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
3058 print
'<td colspan="3" class="maxwidthonsmartphone">';
3059 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
3060 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 :
''));
3066 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
3067 print
'<tr><td>' . $langs->trans(
'VATReverseCharge') .
'</td><td>';
3069 if (GETPOSTISSET(
'vat_reverse_charge')) {
3070 $vat_reverse_charge = (
GETPOST(
'vat_reverse_charge',
'alpha') ==
'on' ||
GETPOST(
'vat_reverse_charge',
'alpha') ==
'1') ? 1 : 0;
3071 } elseif ($vat_reverse_charge == 1 || $societe->vat_reverse_charge == 1 || ($societe->country_code !=
'FR' &&
isInEEC($societe) && !empty($societe->tva_intra))) {
3072 $vat_reverse_charge = 1;
3074 $vat_reverse_charge = 0;
3077 print
'<input type="checkbox" name="vat_reverse_charge"'. (!empty($vat_reverse_charge) ?
' checked ' :
'') .
'>';
3084 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
3085 print
'<td class="maxwidthonsmartphone">';
3086 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
3087 $used_currency_code = $currency_code;
3088 if (!
GETPOST(
'changecompany')) {
3089 $used_currency_code = GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code;
3091 print $form->selectMultiCurrency($used_currency_code,
'multicurrency_code');
3097 if ($fac_recid > 0) {
3098 $dateexample = $dateinvoice;
3099 if (empty($dateexample)) {
3102 $substitutionarray = array(
3103 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
3104 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
3105 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
3106 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
3107 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
3108 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
3109 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
3110 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
3111 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
3112 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
3113 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
3116 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
3117 foreach ($substitutionarray as $key => $val) {
3118 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
3120 $htmltext .=
'</i>';
3125 $langs->loadLangs(array(
"intracommreport"));
3126 print
'<!-- If module intracomm on -->'.
"\n";
3127 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
3128 $form->selectTransportMode(GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
3132 if (empty($reshook)) {
3133 print
$object->showOptionals($extrafields,
'create');
3138 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
3139 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
3144 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
3146 $doleditor =
new DolEditor(
'note_public', (GETPOSTISSET(
'note_public') ?
GETPOST(
'note_public',
'restricthtml') : $note_public),
'', 80,
'dolibarr_notes',
'In', false, false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
3147 print $doleditor->Create(1);
3153 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
3155 $doleditor =
new DolEditor(
'note_private', (GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') : $note_private),
'', 80,
'dolibarr_notes',
'In', false, false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
3156 print $doleditor->Create(1);
3162 if (!empty($objectsrc) && $classname !==
null) {
3163 print
"\n<!-- ".$classname.
" info -->";
3165 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
3166 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
3167 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
3168 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
3169 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
3171 $txt = $langs->trans($classname);
3172 if ($classname ==
'CommandeFournisseur') {
3173 $langs->load(
'orders');
3174 $txt = $langs->trans(
"SupplierOrder");
3176 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
3178 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'invoice_supplier');
3180 if (isset($objectsrc->linkedObjects[
'invoice_supplier'])) {
3181 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
3183 $invoice_supplier = [];
3185 '@phan-var-force null|FactureFournisseur[] $invoice_supplier';
3188 if (is_array($invoice_supplier)) {
3189 $cntinvoice = count($invoice_supplier);
3191 if ($cntinvoice >= 1) {
3193 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
3198 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
3199 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
3200 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
3201 print
'<tr><td>'.$langs->transcountry(
"AmountLT1",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
3204 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
3205 print
'<tr><td>'.$langs->transcountry(
"AmountLT2",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
3207 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
3210 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
3211 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
3212 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
3217 $parameters = array();
3218 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
3219 print $hookmanager->resPrint;
3227 print $form->buttonsSaveCancel(
"CreateDraft");
3230 if (!empty($objectsrc)) {
3233 $title = $langs->trans(
'ProductsAndServices');
3236 print
'<div class="div-table-responsive-no-min">';
3237 print
'<table class="noborder centpercent">';
3239 $objectsrc->printOriginLinesList(
'', $selectedLines);
3247 if ($id > 0 || !empty($ref)) {
3253 $result =
$object->fetch($id, $ref);
3258 $result =
$object->fetch_thirdparty();
3264 $societe =
$object->thirdparty;
3266 $totalpaid =
$object->getSommePaiement();
3267 $totalcreditnotes =
$object->getSumCreditNotesUsed();
3268 $totaldeposits =
$object->getSumDepositsUsed();
3276 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
3279 $multicurrency_resteapayer = 0;
3281 $multicurrency_totalpaid =
$object->getSommePaiement(1);
3282 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
3283 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
3284 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
3288 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
3289 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
3296 $resteapayeraffiche = $resteapayer;
3299 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
3300 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
3302 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
3303 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
3306 $absolute_discount = $societe->getAvailableDiscounts(
null, $filterabsolutediscount, 0, 1);
3307 $absolute_creditnote = $societe->getAvailableDiscounts(
null, $filtercreditnote, 0, 1);
3308 $absolute_discount =
price2num($absolute_discount,
'MT');
3309 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
3313 $objectidnext =
$object->getIdReplacingInvoice();
3316 $titre = $langs->trans(
'SupplierInvoice');
3318 print
dol_get_fiche_head($head,
'card', $titre, -1,
'supplier_invoice', 0,
'',
'', 0,
'', 1);
3323 if ($action ==
'converttoreduc') {
3326 $type_fac =
'ExcessPaid';
3328 $type_fac =
'CreditNote';
3330 $type_fac =
'Deposit';
3332 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
3333 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
3334 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
3338 if ($action ==
'clone') {
3340 $formquestion = array(
3341 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplierBill"),
'value' => $langs->trans(
"CopyOf").
' '.
$object->ref_supplier),
3342 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
3345 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 0);
3349 if ($action ==
'valid') {
3351 if (preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) {
3353 $numref =
$object->getNextNumRef($societe);
3362 $text = $langs->trans(
'ConfirmValidateBill', $numref);
3370 $formquestion = array();
3372 $qualified_for_stock_change = 0;
3374 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3376 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3380 $langs->load(
"stocks");
3381 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3384 $warehouse_array = $warehouse->list_array();
3385 if (count($warehouse_array) == 1) {
3387 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3390 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3392 $formquestion = array(
3393 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3397 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
3402 if ($action ==
'edit') {
3403 $formquestion = array();
3405 $qualified_for_stock_change = 0;
3407 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3409 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3412 $langs->load(
"stocks");
3413 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3416 $warehouse_array = $warehouse->list_array();
3417 if (count($warehouse_array) == 1) {
3419 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3422 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3424 $formquestion = array(
3425 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3428 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill',
$object->ref),
'confirm_edit', $formquestion, 1, 1);
3432 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
3433 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'', 0, 1);
3436 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
3440 $close[$i][
'code'] =
'discount_vat';
3442 $close[$i][
'code'] =
'badsupplier';
3444 $close[$i][
'code'] =
'other';
3448 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
3450 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3452 $close[$i][
'label'] = $langs->trans(
"Other");
3456 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3458 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3460 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
3463 $arrayreasons = array();
3464 foreach ($close as $key => $val) {
3465 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
3469 $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'));
3471 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
3475 if ($action ==
'canceled') {
3477 $close[1][
'code'] =
'badsupplier';
3478 $close[2][
'code'] =
'abandon';
3480 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3481 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
3483 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier",
$object->ref), $close[1][
'label'], 1);
3484 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
3486 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
3487 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
3490 $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'));
3492 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 280);
3496 if ($action ==
'delete') {
3497 $formquestion = array();
3499 $qualified_for_stock_change = 0;
3501 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3503 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3507 $langs->load(
"stocks");
3508 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3511 $warehouse_array = $warehouse->list_array();
3513 $selectwarehouse =
'<span class="questionrevertstock hidden">';
3514 if (count($warehouse_array) == 1) {
3516 $selectwarehouse .=
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3519 $selectwarehouse .= $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3521 $selectwarehouse .=
'</span>';
3523 $selectyesno = array(0 => $langs->trans(
'No'), 1 => $langs->trans(
'Yes'));
3525 print
'<script type="text/javascript">
3526 $(document).ready(function() {
3527 $("#revertstock").change(function() {
3528 if(this.value > 0) {
3529 $(".questionrevertstock").removeClass("hidden");
3531 $(".questionrevertstock").addClass("hidden");
3537 $formquestion = array(
3538 array(
'type' =>
'select',
'name' =>
'revertstock',
'label' => $langs->trans(
"RevertProductsToStock"),
'select_show_empty' => 0,
'values' => $selectyesno),
3539 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $selectwarehouse,
'tdclass' =>
'questionrevertstock hidden')
3543 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete', $formquestion, 1, 1);
3545 if ($action ==
'deletepayment') {
3546 $payment_id =
GETPOST(
'paiement_id');
3547 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
3551 if ($action ==
'ask_deleteline') {
3552 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
3556 if ($action ==
'ask_subtotal_deleteline') {
3557 $langs->load(
'subtotals');
3558 $subtotaltitle =
'DeleteSubtotalLine';
3559 $subtotalquestion =
'ConfirmDeleteSubtotalLine';
3560 $subtotalformquestion = array();
3561 if (
GETPOST(
'type') ==
'title') {
3562 $subtotalformquestion = array(array(
'type' =>
'checkbox',
'name' =>
'deletecorrespondingsubtotalline',
'label' => $langs->trans(
'DeleteCorrespondingSubtotalLine'),
'value' => 0));
3563 $subtotaltitle =
'DeleteTitleLine';
3564 $subtotalquestion =
'ConfirmDeleteTitleLine';
3566 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans($subtotaltitle), $langs->trans($subtotalquestion),
'confirm_delete_subtotalline', $subtotalformquestion,
'no', 1);
3570 if ($action ==
'add_title_line') {
3571 $langs->load(
'subtotals');
3573 $depth_array =
$object->getPossibleLevels($langs);
3574 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3575 } elseif ($action ==
'add_subtotal_line') {
3576 $langs->load(
'subtotals');
3578 $titles =
$object->getPossibleTitles();
3579 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3580 } elseif ($action ==
'add_text_line') {
3581 $langs->load(
'subtotals');
3583 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3587 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
3588 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
3589 if (empty($reshook)) {
3590 $formconfirm .= $hookmanager->resPrint;
3591 } elseif ($reshook > 0) {
3592 $formconfirm = $hookmanager->resPrint;
3600 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
3602 $morehtmlref =
'<div class="refidno">';
3604 $morehtmlref .= $form->editfieldkey(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, (
int) $usercancreate,
'string',
'', 0, 1);
3605 $morehtmlref .= $form->editfieldval(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
3607 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'supplier');
3609 $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>';
3613 $langs->load(
"projects");
3614 $morehtmlref .=
'<br>';
3615 if ($permissiontoadd) {
3616 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
3617 if ($action !=
'classify') {
3618 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.((int)
$object->id).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
3620 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (!
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ?
$object->socid : -1), (
string)
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
3622 if (!empty(
$object->fk_project)) {
3624 $proj->fetch(
$object->fk_project);
3625 $morehtmlref .= $proj->getNomUrl(1);
3627 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
3632 $morehtmlref .=
'</div>';
3634 $object->totalpaid = $totalpaid;
3636 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
3639 $parameters = array();
3641 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierInvoice', $parameters, $object, $action);
3642 if (empty($reshook)) {
3643 print
'<div class="fichecenter">';
3644 print
'<div class="fichehalfleft">';
3645 print
'<div class="underbanner clearboth"></div>';
3647 print
'<table class="border tableforfield centpercent">';
3650 print
'<tr><td>'.$langs->trans(
'Type').
'</td><td>';
3651 print
'<span class="badgeneutral">';
3655 print
' '.$object->getSubtypeLabel(
'facture_fourn');
3659 $facreplaced->fetch(
$object->fk_facture_source);
3660 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
3663 if (
$object->fk_facture_source > 0) {
3665 $facusing->fetch(
$object->fk_facture_source);
3666 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
3668 $langs->load(
"errors");
3669 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"WarningCorrectedInvoiceNotFound").
'</span>';
3674 $object->getListIdAvoirFromInvoice();
3676 if (!empty(
$object->creditnote_ids)) {
3677 $invoicecredits = array();
3678 foreach (
$object->creditnote_ids as $invoiceid) {
3680 $creditnote->fetch($invoiceid);
3681 $invoicecredits[] = $creditnote->getNomUrl(1);
3683 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
3686 if (isset($objectidnext) && $objectidnext > 0) {
3689 $facthatreplace->fetch($objectidnext);
3690 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
3694 $result = $discount->fetch(0, 0,
$object->id);
3696 print
' <span class="opacitymediumbycolor paddingleft">';
3697 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
3698 $s = str_replace(
'{s1}',
$object->getLibType(1), $s);
3699 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
3701 print
'</span><br>';
3705 if (
$object->fk_fac_rec_source > 0) {
3707 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
3709 print
' <span class="opacitymediumbycolor paddingleft">';
3710 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->title).
'</a>';
3711 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
3721 print
'<!-- Discounts -->'.
"\n";
3722 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
3725 $thirdparty = $societe;
3727 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3733 print
'<td>'.$form->editfieldkey(
"Label",
'label',
$object->label, $object, (
int) $usercancreate).
'</td>';
3734 print
'<td>'.$form->editfieldval(
"Label",
'label',
$object->label, $object, $usercancreate).
'</td>';
3742 print $form->editfieldkey(
"DateInvoice",
'datef', (
string)
$object->date,
$object, (int) $form_permission,
'datepicker');
3743 print
'</td><td colspan="3">';
3744 print $form->editfieldval(
"Date",
'datef',
$object->date, $object, $form_permission,
'datepicker');
3748 $langs->load(
'bills');
3749 print
'<tr><td class="nowrap">';
3750 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3751 print $langs->trans(
'PaymentConditions');
3753 if ($action !=
'editconditions' && $form_permission) {
3754 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>';
3756 print
'</tr></table>';
3758 if ($action ==
'editconditions') {
3759 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
3761 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
3768 print $form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', (
string)
$object->date_echeance, $object, (
int) $form_permission,
'datepicker');
3770 print $form->editfieldval(
"DateMaxPayment",
'date_lim_reglement',
$object->date_echeance, $object, $form_permission,
'datepicker');
3771 if ($action !=
'editdate_lim_reglement' &&
$object->hasDelay()) {
3777 $langs->load(
'bills');
3778 print
'<tr><td class="nowrap">';
3779 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3780 print $langs->trans(
'PaymentMode');
3782 if ($action !=
'editmode' && $form_permission) {
3783 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>';
3785 print
'</tr></table>';
3787 if ($action ==
'editmode') {
3788 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3790 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'none');
3796 print
'<tr><td class="nowrap">';
3797 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3798 print $langs->trans(
'BankAccount');
3800 if ($action !=
'editbankaccount' && $usercancreate) {
3801 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>';
3803 print
'</tr></table>';
3805 if ($action ==
'editbankaccount') {
3806 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
3808 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
3816 print
'<tr><td class="nowrap">';
3817 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3818 print $langs->trans(
'VATReverseCharge');
3820 if ($action !=
'editvatreversecharge' && $usercancreate) {
3821 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editvatreversecharge&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->trans(
'SetVATReverseCharge'), 1).
'</a></td>';
3823 print
'</tr></table>';
3825 if ($action ==
'editvatreversecharge') {
3826 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
3827 print
'<input type="hidden" name="action" value="setvatreversecharge">';
3828 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3830 print
'<input type="checkbox" name="vat_reverse_charge"' . (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
'>';
3832 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
3835 print
'<input type="checkbox" name="vat_reverse_charge"'. (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
' disabled>';
3843 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3844 print $langs->trans(
'IncotermLabel');
3845 print
'<td><td class="right">';
3846 if ($usercancreate) {
3847 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
3851 print
'</td></tr></table>';
3854 if ($action !=
'editincoterm') {
3855 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
3857 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
3864 $langs->loadLangs(array(
"intracommreport"));
3865 print
'<!-- If module intracomm on -->'.
"\n";
3867 print
'<table class="nobordernopadding centpercent"><tr><td>';
3868 print $langs->trans(
'IntracommReportTransportMode');
3870 if ($action !=
'edittransportmode' && ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"))) {
3871 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edittransportmode&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit().
'</a></td>';
3873 print
'</tr></table>';
3876 if ($action ==
'edittransportmode') {
3877 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'transport_mode_id', 1, 1);
3879 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'none');
3887 print
'<table class="nobordernopadding centpercent"><tr><td>';
3888 print $langs->trans(
"Categories");
3889 print
'<td><td class="right">';
3890 if ($usercancreate) {
3891 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
3895 print
'</td></tr></table>';
3898 if ($action ==
'edittags') {
3899 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
3900 print
'<input type="hidden" name="action" value="settags">';
3901 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3902 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
3903 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
3906 print $form->showCategories(
$object->id, Categorie::TYPE_SUPPLIER_INVOICE, 1);
3914 if (
$object->status != $object::STATUS_DRAFT) {
3918 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
3923 print
'<div class="fichehalfright">';
3924 print
'<div class="underbanner clearboth"></div>';
3926 print
'<table class="border tableforfield centpercent">';
3928 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
3931 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
3932 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3934 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3939 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
3940 print
'<td class="nowrap amountcard right">';
3941 if (
GETPOST(
'calculationrule')) {
3942 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
3944 $calculationrule = (!
getDolGlobalString(
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND_SUPPLIER') ?
'totalofround' :
'roundoftotal');
3946 if ($calculationrule ==
'totalofround') {
3947 $calculationrulenum = 1;
3949 $calculationrulenum = 2;
3952 if (
$object->getVentilExportCompta() == 0) {
3953 $s =
'<span class="hideonsmartphone opacitymedium">' . $langs->trans(
"ReCalculate") .
' </span>';
3954 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=totalofround">' . $langs->trans(
"Mode1") .
'</a>';
3956 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=roundoftotal">' . (
$conf->dol_optimize_smallscreen ?
"2" : $langs->trans(
"Mode2")) .
'</a>';
3957 print
'<div class="inline-block">';
3958 print $form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum) .
'<br>' . $langs->trans(
"CalculationRuleDescSupplier"), 2, 1,
img_picto(
'',
'help',
'class="paddingleft paddingright"'),
'', 3,
'', 0,
'recalculate');
3959 print
' ';
3962 print
'<span class="nowraponall">'.price(
$object->total_tva, 1, $langs, 0, -1, -1,
$conf->currency).
'</span>';
3965 print
'<td class="nowraponall amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
3969 if ($societe->localtax1_assuj ==
"1") {
3971 print
'<td>' . $langs->transcountry(
"AmountLT1", $societe->country_code) .
'</td>';
3972 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3975 if ($societe->localtax2_assuj ==
"1") {
3977 print
'<td>' . $langs->transcountry(
"AmountLT2", $societe->country_code) .
'</td>';
3978 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3983 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
3984 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
3986 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
4019 if ($societe->localtax1_assuj ==
"1") {
4022 if ($societe->localtax2_assuj ==
"1") {
4026 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
4027 $sql .=
' c.id as payment_type, c.code as payment_code,';
4028 $sql .=
' pf.amount,';
4029 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
4030 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
4031 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
4032 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
4033 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
4034 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
4035 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
4036 $sql .=
' ORDER BY p.datep, p.tms';
4038 $result =
$db->query($sql);
4040 $num =
$db->num_rows($result);
4043 print
'<div class="div-table-responsive-no-min">';
4044 print
'<table class="noborder paymenttable centpercent">';
4045 print
'<tr class="liste_titre">';
4047 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
4048 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
4050 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
4055 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
4060 $objp =
$db->fetch_object($result);
4062 $paymentstatic->id = $objp->rowid;
4063 $paymentstatic->datepaye =
$db->jdate($objp->dp);
4064 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
4065 $paymentstatic->num_payment = $objp->num_payment;
4067 $paymentstatic->paiementcode = $objp->payment_code;
4068 $paymentstatic->type_code = $objp->payment_code;
4069 $paymentstatic->type_label = $objp->payment_type;
4071 print
'<tr class="oddeven">';
4072 print
'<td class="nowraponall">';
4073 print $paymentstatic->getNomUrl(1);
4075 print
'<td>'.dol_print_date(
$db->jdate($objp->dp),
'day').
'</td>';
4076 $s = $form->form_modes_reglement(
'', $objp->payment_type,
'none',
'', 1, 0,
'', 1).
' '.$objp->num_payment;
4077 print
'<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).
'">';
4081 $bankaccountstatic->id = $objp->baid;
4082 $bankaccountstatic->ref = $objp->baref;
4083 $bankaccountstatic->label = $objp->baref;
4084 $bankaccountstatic->number = $objp->banumber;
4087 $bankaccountstatic->account_number = $objp->account_number;
4090 $accountingjournal->fetch($objp->fk_accountancy_journal);
4091 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
4094 print
'<td class="right nowraponall">';
4095 if ($objp->baid > 0) {
4096 print $bankaccountstatic->getNomUrl(1,
'transactions');
4101 print
'<td class="center">';
4103 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
4109 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
4111 $totalpaid += $objp->amount;
4115 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
4141 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4142 print
'<span class="opacitymedium">';
4144 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
4146 print $langs->trans(
'AlreadyPaid');
4151 print
'<td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td>';
4155 $resteapayeraffiche = $resteapayer;
4157 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
4160 $creditnoteamount = 0;
4163 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
4164 $sql .=
" re.description, re.fk_invoice_supplier_source";
4165 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
4166 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
4167 $resql =
$db->query($sql);
4169 $num =
$db->num_rows($resql);
4173 $obj =
$db->fetch_object($resql);
4174 $invoice->fetch($obj->fk_invoice_supplier_source);
4175 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4177 print $langs->trans(
"CreditNote").
' ';
4180 print $langs->trans(
"Deposit").
' ';
4182 print $invoice->getNomUrl(0);
4185 print
'<td class="right">';
4186 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
4187 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
4191 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
4195 $creditnoteamount += $obj->amount_ttc;
4198 $depositamount += $obj->amount_ttc;
4207 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4208 print
'<span class="opacitymedium">';
4209 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
4213 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4215 $resteapayeraffiche = 0;
4216 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4220 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4221 print
'<span class="opacitymedium">';
4222 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
4226 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4229 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4233 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4234 print
'<span class="opacitymedium">';
4235 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
4239 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4241 $resteapayeraffiche = 0;
4242 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4246 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4247 $text = $langs->trans(
"HelpAbandonOther");
4249 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
4251 print
'<span class="opacitymedium">';
4253 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
4257 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4259 $resteapayeraffiche = 0;
4260 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4264 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4265 print
'<span class="opacitymedium">';
4266 print $langs->trans(
"Billed");
4270 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
4274 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4275 print
'<span class="opacitymedium">';
4276 print $langs->trans(
'RemainderToPay');
4277 if ($resteapayeraffiche < 0) {
4278 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4283 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
4288 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4289 print
'<span class="opacitymedium">';
4290 print $langs->trans(
'RemainderToPayMulticurrency');
4291 if ($resteapayeraffiche < 0) {
4292 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4297 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price(
price2num($multicurrency_resteapayer,
'MT'), 0, $langs, 1, -1, -1,
$object->multicurrency_code).
'</td>';
4301 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4304 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4305 print $langs->trans(
'AlreadyPaidBack');
4308 print
'<td class="right">'.price($sign * $totalpaid).
'</td>';
4312 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">'.$langs->trans(
"Billed").
'</td>';
4314 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
4318 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4319 print
'<span class="opacitymedium">';
4320 print $langs->trans(
'RemainderToPayBack');
4321 if ($resteapayeraffiche > 0) {
4322 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4327 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
4332 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4333 print
'<span class="opacitymedium">';
4334 print $langs->trans(
'RemainderToPayBackMulticurrency');
4335 if ($resteapayeraffiche > 0) {
4336 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4341 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcomplete)).
'">'.(!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency).
' '.
price(
price2num($sign *
$object->multicurrency_tx * $resteapayeraffiche,
'MT')).
'</td>';
4357 print
'<div class="clearboth"></div><br>';
4360 $blocname =
'contacts';
4361 $title = $langs->trans(
'ContactsAddresses');
4362 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4367 $blocname =
'notes';
4368 $title = $langs->trans(
'Notes');
4369 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4376 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
4377 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4378 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
4379 print
'<input type="hidden" name="mode" value="">';
4380 print
'<input type="hidden" name="page_y" value="">';
4381 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
4382 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
4383 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4387 include DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_ajaxrow.tpl.php';
4389 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
4393 print
'<div class="div-table-responsive-no-min">';
4394 print
'<table id="tablelines" class="noborder noshadow centpercent">';
4396 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
4399 $inputalsopricewithtax = 1;
4400 $senderissupplier = 2;
4401 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY')) {
4402 $senderissupplier =
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY');
4407 $object->printObjectLines($action, $societe,
$mysoc, $lineid, 1);
4414 if ($action !=
'editline') {
4417 $parameters = array();
4418 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
4422 if (empty($reshook)) {
4436 if ($action !=
'presend') {
4439 print
'<div class="tabsAction">';
4441 $parameters = array();
4442 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
4444 if (empty($reshook)) {
4448 $langs->load(
'subtotals');
4450 $url_button = array();
4452 $url_button[] = array(
4453 'lang' =>
'subtotals',
4455 'perm' => (
bool) $usercancreate,
4456 'label' => $langs->trans(
'AddTitleLine'),
4457 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_title_line'],
true)
4460 $url_button[] = array(
4461 'lang' =>
'subtotals',
4463 'perm' => (
bool) $usercancreate,
4464 'label' => $langs->trans(
'AddSubtotalLine'),
4465 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_subtotal_line'],
true)
4468 $url_button[] = array(
4469 'lang' =>
'subtotals',
4471 'perm' => (
bool) $usercancreate,
4472 'label' => $langs->trans(
'AddTextLine'),
4473 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_text_line'],
true)
4476 print
dolGetButtonAction(
'', $langs->trans(
'SubTotal'),
'default', $url_button,
'',
true);
4481 $ventilExportCompta =
$object->getVentilExportCompta();
4483 if ($ventilExportCompta == 0) {
4484 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=edit&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
4486 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
4491 $result = $discount->fetch(0, 0,
$object->id);
4498 if (!$objectidnext &&
$object->close_code !=
'replaced' && $usercancreate) {
4499 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
4501 if ($usercancreate) {
4502 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
4504 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
4514 if ($usercanvalidate) {
4515 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken().
'"';
4516 print
'>'.$langs->trans(
'Validate').
'</a>';
4518 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
4519 print
'>'.$langs->trans(
'Validate').
'</a>';
4525 if (empty($user->socid)) {
4528 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' =>
$object->id,
'action' =>
'presend',
'mode' =>
'init'],
true).
'#formmailbeforetitle',
'');
4537 $langs->load(
"withdrawals");
4538 if ($resteapayer > 0) {
4539 if ($usercancreatecreditransfer) {
4540 if (!$objectidnext &&
$object->close_code !=
'replaced') {
4541 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/facture/prelevement.php?facid='.
$object->id.
'&type=bank-transfer" title="'.
dol_escape_htmltag($langs->trans(
"MakeBankTransferOrder")).
'">'.$langs->trans(
"MakeBankTransferOrder").
'</a>';
4543 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeBankTransferOrder').
'</span>';
4555 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/paiement.php?facid='.
$object->id.
'&action=create'.(
$object->fk_account > 0 ?
'&accountid='.$object->fk_account :
'').
'">'.$langs->trans(
'DoPayment').
'</a>';
4562 if ($resteapayer == 0) {
4563 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
4564 } elseif ($usercancreate) {
4565 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>';
4571 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
4575 && (
getDolGlobalString(
'SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') ||
$object->getSommePaiement() == 0)
4577 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>';
4581 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
4592 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaid').
'</a>';
4597 if ($totalpaid > 0 || $totalcreditnotes > 0) {
4599 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
4602 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=canceled&token='.
newToken().
'">'.$langs->trans(
'ClassifyCanceled').
'</a>';
4614 if (!$objectidnext) {
4615 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>';
4620 if ($action !=
'edit' && $usercancreate) {
4621 print
'<a class="butAction butActionClone" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=clone&socid='.
$object->socid.
'&token='.
newToken().
'">'.$langs->trans(
'ToClone').
'</a>';
4626 if (!$objectidnext && count(
$object->lines) > 0) {
4627 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.
$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
4632 if ($action !=
'confirm_edit' && $usercandelete) {
4633 $isErasable =
$object->is_erasable();
4635 $enableDelete =
false;
4637 $params = (empty(
$conf->use_javascript_ajax) ? array() : array(
'attr' => array(
'class' =>
'reposition')));
4639 if ($isErasable == -4) {
4640 $htmltooltip = $langs->trans(
"DisabledBecausePayments");
4641 } elseif ($isErasable == -3) {
4642 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastSituationInvoice");
4643 } elseif ($isErasable == -2) {
4644 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastInvoice");
4645 } elseif ($isErasable == -1) {
4646 $htmltooltip = $langs->trans(
"DisabledBecauseDispatchedInBookkeeping");
4647 } elseif ($isErasable <= 0) {
4648 $htmltooltip = $langs->trans(
"DisabledBecauseNotErasable");
4650 $enableDelete =
true;
4653 print
dolGetButtonAction($htmltooltip, $langs->trans(
"Delete"),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken(), (
string)
$object->id, $enableDelete, $params);
4657 if ($action !=
'confirm_edit') {
4658 print
'<div class="fichecenter"><div class="fichehalfleft">';
4664 $subdir =
get_exdir(
$object->id, 2, 0, 0, $object,
'invoice_supplier').$ref;
4666 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.
$object->id;
4667 $genallowed = $usercanread;
4668 $delallowed = $usercancreate;
4672 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, (
int) $genallowed, (
int) $delallowed, $modelpdf, $genifempty, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
4673 $somethingshown = $formfile->numoffiles;
4676 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice_supplier'), 1);
4677 $linktoelem = $tmparray[
'linktoelem'];
4678 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
4679 print $htmltoenteralink;
4681 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
4683 print
'</div><div class="fichehalfright">';
4686 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
4688 $somethingshown = $formactions->showactions($object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
4690 print
'</div></div>';
4696 if (
GETPOST(
'modelselected')) {
4697 $action =
'presend';
4701 $modelmail =
'invoice_supplier_send';
4702 $defaulttopic =
'SendBillRef';
4704 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
4705 $trackid =
'sinv'.$object->id;
4707 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage bank accounts.
Class to manage accounting journals.
const TYPE_PROFORMA
Proforma invoice.
const TYPE_SITUATION
Situation invoice.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_STANDARD
Standard invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const STATUS_CLOSED
Classified paid.
Class to manage invoice templates.
Class to manage payments for supplier invoices.
Class ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
$date_start
Variables from include:
facturefourn_prepare_head(FactureFournisseur $object)
Prepare array with list of tabs.
dol_now($mode='gmt')
Return date for now.
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
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...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
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.