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 =
GETPOST(
'backtopageforcancel',
'alpha');
95$origin =
GETPOST(
'origin',
'alpha');
108$hookmanager->initHooks(array(
'invoicesuppliercard',
'globalcard'));
114$extrafields->fetch_name_optionals_label(
$object->table_element);
117if ($id > 0 || !empty($ref)) {
118 $ret =
$object->fetch($id, $ref);
120 dol_print_error($db,
$object->error);
125 $ret =
$object->fetch_thirdparty();
127 dol_print_error($db,
$object->error);
133if (!empty($user->socid)) {
134 $socid = $user->socid;
138$result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture',
'fk_soc',
'rowid', $isdraft);
141$usercanread = ($user->hasRight(
"fournisseur",
"facture",
"lire") || $user->hasRight(
"supplier_invoice",
"lire"));
142$usercancreate = ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"));
143$usercandelete = (($user->hasRight(
"fournisseur",
"facture",
"supprimer") || $user->hasRight(
"supplier_invoice",
"supprimer")) || ($usercancreate &&
$object->is_erasable() == 1));
144$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
147$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"validate")));
148$usercansend = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"send"));
149$usercancreatecreditransfer = $user->hasRight(
'paymentbybanktransfer',
'create');
152$permissionnote = $usercancreate;
153$permissiondellink = $usercancreate;
154$permissiontoedit = $usercancreate;
155$permissiontoadd = $usercancreate;
156$permissiontodelete = $usercandelete;
157$permissiontoeditextra = $permissiontoadd;
158if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
160 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
171$parameters = array(
'socid' => $socid);
172$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
174 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
177if (empty($reshook)) {
178 $backurlforlist =
dolBuildUrl(DOL_URL_ROOT.
'/fourn/facture/list.php');
180 if (empty($backtopage) || ($cancel && empty($id))) {
181 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
182 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
183 $backtopage = $backurlforlist;
185 $backtopage =
dolBuildUrl(DOL_URL_ROOT.
'/fourn/facture/card.php', [
'id' => ((!empty($id) && $id > 0) ? $id :
'__ID__')]);
191 if (!empty($backtopageforcancel)) {
192 header(
"Location: ".$backtopageforcancel);
194 } elseif (!empty($backtopage)) {
195 header(
"Location: ".$backtopage);
201 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
203 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
205 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
208 if (
GETPOST(
'linkedOrder') && empty($cancel) && $id > 0 && $permissiontoadd) {
211 $result =
$object->add_object_linked(
'order_supplier',
GETPOSTINT(
'linkedOrder'));
215 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
217 '@phan-var-force FactureFournisseur $objectutil';
219 if (
GETPOST(
'newsupplierref',
'alphanohtml')) {
220 $objectutil->ref_supplier =
GETPOST(
'newsupplierref',
'alphanohtml');
224 $result = $objectutil->createFromClone($user, $id);
226 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
229 $langs->load(
"errors");
230 setEventMessages($objectutil->error, $objectutil->errors,
'errors');
233 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
234 $idwarehouse =
GETPOST(
'idwarehouse');
239 $qualified_for_stock_change = 0;
241 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
243 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
248 $langs->load(
"stocks");
249 if (!$idwarehouse || $idwarehouse == -1) {
251 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
259 $result =
$object->validate($user,
'', $idwarehouse);
269 $outputlangs = $langs;
272 $newlang =
GETPOST(
'lang_id',
'aZ09');
275 $newlang =
$object->thirdparty->default_lang;
277 if (!empty($newlang)) {
279 $outputlangs->setDefaultLang($newlang);
284 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
291 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $permissiontodelete) {
295 $isErasable =
$object->is_erasable();
297 if ($usercandelete && $isErasable > 0) {
298 $revertstock =
GETPOST(
'revertstock');
303 $qualified_for_stock_change = 0;
305 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
307 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
312 $langs->load(
"stocks");
313 if (!$idwarehouse || $idwarehouse == -1) {
315 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
318 $result =
$object->setDraft($user, $idwarehouse);
328 $result =
$object->delete($user);
330 header(
'Location: list.php?restore_lastsearch_values=1');
337 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
339 $result =
$object->deleteLine($lineid);
359 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
366 } elseif ($action ==
'confirm_delete_subtotalline' && $confirm ==
'yes' && $usercancreate) {
371 $result =
$object->deleteSubtotalLine($langs, $lineid, (
bool)
GETPOST(
'deletecorrespondingsubtotalline'));
374 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
380 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
383 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
384 if ($result > 0 &&
$object->id > 0 && $discount->fk_invoice_supplier ==
$object->id) {
385 $discount->unlink_invoice();
387 if (
$object->paye == 1 && (
float)
$object->getRemainToPay() > 0) {
391 setEventMessages($langs->trans(
"ErrorRecordNotFound"),
null,
'errors');
393 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercancreate) {
395 $result =
$object->setPaid($user);
399 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercancreate) {
402 $close_code =
GETPOST(
"close_code",
'restricthtml');
403 $close_note =
GETPOST(
"close_note",
'restricthtml');
405 $result =
$object->setPaid($user, $close_code, $close_note);
410 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
412 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
415 $close_code =
GETPOST(
"close_code",
'restricthtml');
416 $close_note =
GETPOST(
"close_note",
'restricthtml');
418 $result =
$object->setCanceled($user, $close_code, $close_note);
423 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
428 if ($action ==
'setref_supplier' && $usercancreate) {
433 if (
$object->update($user) < 0) {
437 $outputlangs = $langs;
440 $newlang =
GETPOST(
'lang_id',
'aZ09');
443 $newlang =
$object->thirdparty->default_lang;
445 if (!empty($newlang)) {
447 $outputlangs->setDefaultLang($newlang);
451 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
457 if ($action ==
'setconditions' && $usercancreate) {
459 $object->cond_reglement_code = 0;
460 $object->cond_reglement_id = 0;
475 $new_date_echeance =
$object->calculate_date_lim_reglement();
476 if ($new_date_echeance) {
477 $object->date_echeance = $new_date_echeance;
482 $result =
$object->update($user);
494 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
497 } elseif ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
500 } elseif ($action ==
'setmode' && $usercancreate) {
503 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
505 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
506 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
508 if (!in_array(
GETPOSTINT(
'calculation_mode'), array(1, 2))) {
509 $langs->load(
"compta");
510 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CalculationMode")),
null,
'errors');
511 $action =
'editmulticurrencyrate';
515 } elseif ($action ==
'setbankaccount' && $usercancreate) {
518 } elseif ($action ==
'setvatreversecharge' && $usercancreate) {
520 $vatreversecharge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
521 $result =
$object->setVATReverseCharge($vatreversecharge);
524 if ($action ==
'settransportmode' && $usercancreate) {
527 } elseif ($action ==
'setlabel' && $usercancreate) {
531 $result =
$object->update($user);
535 } elseif ($action ==
'setdatef' && $usercancreate) {
539 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
541 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
548 $date_echence_calc =
$object->calculate_date_lim_reglement();
549 if (!empty(
$object->date_echeance)) {
550 $object->date_echeance = $date_echence_calc;
556 $result =
$object->update($user);
560 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
564 $object->date_pointoftax = $date_pointoftax;
566 $result =
$object->update($user);
569 $action =
'editdate_pointoftax';
571 } elseif ($action ==
'setdate_lim_reglement' && $usercancreate) {
576 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
578 $result =
$object->update($user);
582 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
592 $usemccompare =
false;
594 if ($discount->fetch($idremise) > 0) {
598 && !empty($discount->multicurrency_code) && !empty(
$object->multicurrency_code)
599 && $discount->multicurrency_code ==
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency);
600 $maxtoabsorb = (float)
price2num($usemccompare ?
$object->getRemainToPay(1) :
$object->getRemainToPay(0),
'MT');
601 $discountamountforcompare = (float)
price2num($usemccompare ? $discount->multicurrency_amount_ttc : $discount->amount_ttc,
'MT');
602 if ($discountamountforcompare > $maxtoabsorb) {
603 if ($maxtoabsorb <= 0) {
606 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
609 $depositeur = (float) $discount->amount_ttc;
610 $depositdev = (float) $discount->multicurrency_amount_ttc;
611 if ($usemccompare && $depositdev != 0) {
612 $applydev = $maxtoabsorb;
616 $creditrate = !empty($discount->multicurrency_tx) ? (float) $discount->multicurrency_tx : 0;
617 if ($creditrate > 0) {
618 $applyeur = (float)
price2num($applydev / $creditrate,
'MT');
620 $applyeur = (float)
price2num($applydev / $depositdev * $depositeur,
'MT');
623 $applyeur = $maxtoabsorb;
624 $applydev = ($depositeur != 0 ? (float)
price2num($applyeur / $depositeur * $depositdev,
'MT') : 0);
626 $splitparts = $discount->splitAmount($applyeur, (
float)
price2num($depositeur - $applyeur,
'MT'));
627 $applypart = $splitparts[0];
628 $remainpart = $splitparts[1];
630 if (!empty($discount->multicurrency_code) && $depositdev != 0) {
632 $remaindev = (float)
price2num($depositdev - $applydev,
'MT');
633 $applypart->multicurrency_amount_ttc = $applydev;
634 $applypart->multicurrency_amount_ht =
price2num($applydev / (1 + (
float) $applypart->tva_tx / 100),
'MT');
635 $applypart->multicurrency_amount_tva =
price2num($applydev - (
float) $applypart->multicurrency_amount_ht);
636 $remainpart->multicurrency_amount_ttc = $remaindev;
637 $remainpart->multicurrency_amount_ht =
price2num($remaindev / (1 + (
float) $remainpart->tva_tx / 100),
'MT');
638 $remainpart->multicurrency_amount_tva =
price2num($remaindev - (
float) $remainpart->multicurrency_amount_ht);
640 $discount->fk_facture_source = 0;
641 $discount->fk_invoice_supplier_source = 0;
642 $resdelete = $discount->delete($user);
643 $newidapply = $applypart->create($user);
644 $newidremain = $remainpart->create($user);
645 if ($resdelete > 0 && $newidapply > 0 && $newidremain > 0) {
646 $idremise = $newidapply;
647 $splitappliedmsg =
price($applyeur, 0, $langs, 1, -1, -1,
$conf->currency);
648 $splitremainmsg =
price((
float)
price2num($depositeur - $applyeur,
'MT'), 0, $langs, 1, -1, -1,
$conf->currency);
649 if (!empty($discount->multicurrency_code) && $depositdev != 0) {
650 $splitappliedmsg .=
' / '.price($applydev, 0, $langs, 1, -1, -1, $discount->multicurrency_code);
651 $splitremainmsg .=
' / '.price($remaindev, 0, $langs, 1, -1, -1, $discount->multicurrency_code);
653 setEventMessages($langs->trans(
'DepositSplitAutomaticallyApplied', $splitappliedmsg, $splitremainmsg),
null,
'warnings');
656 setEventMessages($langs->trans(
"Error"),
null,
'errors');
663 $result =
$object->insert_discount($idremise);
667 if ($result > 0 && $usemccompare) {
674 $foreigncredits = 0.0;
675 $companycredits = 0.0;
676 foreach (
$object->lines as $creditline) {
677 if (empty($creditline->fk_remise_except)) {
678 $foreigngoods += (float) $creditline->multicurrency_total_ttc;
680 $foreigncredits -= (float) $creditline->multicurrency_total_ttc;
681 $companycredits -= (float) $creditline->total_ttc;
684 $targetcompany = ((float)
$object->multicurrency_tx > 0 ? ($foreigngoods - $foreigncredits) / (float)
$object->multicurrency_tx : 0) + $companycredits;
685 if ($foreigngoods > 0 && $targetcompany > 0) {
686 $neweffectivetx = (float)
price2num($foreigngoods / $targetcompany,
'CR');
687 if (abs($neweffectivetx - (
float)
$object->multicurrency_tx) >= 0.00000001) {
688 $resrate =
$object->setMulticurrencyRate($neweffectivetx, 1);
693 setEventMessages($langs->trans(
'InvoiceRateRealigned',
price2num($neweffectivetx,
'CR')),
null,
'mesgs');
700 dol_print_error($db,
$object->error);
705 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
707 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
711 $remaintopay =
$object->getRemainToPay(0);
715 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
719 $result = $discount->link_to_invoice(0, $id);
722 setEventMessages($discount->error, $discount->errors,
'errors');
726 $newremaintopay =
$object->getRemainToPay(0);
727 if ($newremaintopay == 0) {
738 $outputlangs = $langs;
741 $newlang =
GETPOST(
'lang_id',
'aZ09');
744 $newlang =
$object->thirdparty->default_lang;
746 if (!empty($newlang)) {
748 $outputlangs->setDefaultLang($newlang);
752 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
757 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
760 $langs->load(
'subtotals');
762 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
763 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
765 $subtotal_options = array();
767 foreach (FactureFournisseur::$TITLE_OPTIONS as $option) {
768 $value =
GETPOST($option,
'alphanohtml');
770 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
775 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
786 $outputlangs = $langs;
787 $newlang =
GETPOST(
'lang_id',
'alpha');
789 $newlang =
$object->thirdparty->default_lang;
791 if (!empty($newlang)) {
793 $outputlangs->setDefaultLang($newlang);
796 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
801 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
803 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
806 $langs->load(
'subtotals');
808 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
809 foreach (
$object->lines as $line) {
810 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
812 $depth = -$line->qty;
816 $subtotal_options = array();
818 foreach (FactureFournisseur::$SUBTOTAL_OPTIONS as $option) {
819 $value =
GETPOST($option,
'alphanohtml');
821 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
826 if (isset($desc) && isset($depth)) {
827 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
830 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
839 $outputlangs = $langs;
840 $newlang =
GETPOST(
'lang_id',
'alpha');
842 $newlang =
$object->thirdparty->default_lang;
844 if (!empty($newlang)) {
846 $outputlangs->setDefaultLang($newlang);
849 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
854 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
856 } elseif ($action ==
'confirm_addtextline' && $usercancreate) {
859 $langs->load(
'subtotals');
861 $desc =
GETPOST(
'subtotaltextcontent',
'restricthtml');
864 $result =
$object->addSubtotalLine($langs, $desc, 0, array());
875 $outputlangs = $langs;
876 $newlang =
GETPOST(
'lang_id',
'alpha');
878 $newlang =
$object->thirdparty->default_lang;
880 if (!empty($newlang)) {
882 $outputlangs->setDefaultLang($newlang);
885 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
890 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
892 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
900 $result = $discountcheck->fetch(0, 0,
$object->id);
916 $amount_ht = $amount_tva = $amount_ttc = array();
917 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
921 foreach (
$object->lines as $line) {
922 if ($line->product_type < 9 && $line->total_ht != 0) {
923 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
925 $amount_ht[$keyforvatrate] += $line->total_ht;
926 $amount_tva[$keyforvatrate] += $line->total_tva;
927 $amount_ttc[$keyforvatrate] += $line->total_ttc;
928 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
929 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
930 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
934 '@phan-var-force array<string,float> $amount_ht
935 @phan-var-force array<string,float> $amount_tva
936 @phan-var-force array<string,float> $amount_ttc
937 @phan-var-force array<string,float> $multicurrency_amount_ht
938 @phan-var-force array<string,float> $multicurrency_amount_tva
939 @phan-var-force array<string,float> $multicurrency_amount_ttc';
943 $alreadypaid =
$object->getSommePaiement();
944 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
945 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
946 foreach ($amount_ht as $vatrate => $val) {
947 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
948 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
949 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
950 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
951 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
952 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
961 $discount->description =
'(CREDIT_NOTE)';
963 $discount->description =
'(DEPOSIT)';
965 $discount->description =
'(EXCESS PAID)';
967 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
969 $discount->discount_type = 1;
970 $discount->fk_soc =
$object->socid;
971 $discount->socid =
$object->socid;
972 $discount->fk_invoice_supplier_source =
$object->id;
980 $sql =
'SELECT SUM(pf.amount) as total_paiements';
981 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'paiementfourn as p';
982 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN ('.
getEntity(
'c_paiement').
')';
983 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
984 $sql .=
' AND pf.fk_paiementfourn = p.rowid';
985 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
987 $resql = $db->query($sql);
989 dol_print_error($db);
992 $res = $db->fetch_object($resql);
993 $total_paiements = $res->total_paiements;
996 $total_creditnote_and_deposit = 0;
997 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
998 $sql .=
" re.description, re.fk_invoice_supplier_source";
999 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1000 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
1001 $resql = $db->query($sql);
1002 if (!empty($resql)) {
1003 while ($obj = $db->fetch_object($resql)) {
1004 $total_creditnote_and_deposit += $obj->amount_ttc;
1007 dol_print_error($db);
1010 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
1011 $discount->amount_tva = 0;
1012 $discount->tva_tx = 0;
1013 $discount->vat_src_code =
'';
1016 $discount->multicurrency_code =
$object->multicurrency_code;
1017 $discount->multicurrency_tx =
$object->multicurrency_tx;
1018 $discount->multicurrency_total_ht = $discount->multicurrency_total_ttc = (float)
price2num((
float) $discount->amount_ttc * (float)
$object->multicurrency_tx,
'MT');
1019 $discount->multicurrency_total_tva = 0;
1021 $discount->multicurrency_amount_ht = $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
1022 $discount->multicurrency_amount_tva = 0;
1024 $result = $discount->create($user);
1030 foreach ($amount_ht as $tva_tx => $xxx) {
1032 $discount->multicurrency_code =
$object->multicurrency_code;
1033 $discount->multicurrency_tx =
$object->multicurrency_tx;
1036 $discount->amount_ht = -((float) $amount_ht[$tva_tx]);
1037 $discount->amount_tva = -((float) $amount_tva[$tva_tx]);
1038 $discount->amount_ttc = -((float) $amount_ttc[$tva_tx]);
1039 $discount->multicurrency_total_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1040 $discount->multicurrency_total_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1041 $discount->multicurrency_total_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1043 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
1044 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
1045 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
1046 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1047 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1048 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1051 $discount->multicurrency_amount_ht = $discount->multicurrency_total_ht;
1052 $discount->multicurrency_amount_tva = $discount->multicurrency_total_tva;
1053 $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
1058 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
1059 $vat_src_code = $reg[1];
1060 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
1063 $discount->tva_tx = abs((
float) $tva_tx);
1064 $discount->vat_src_code = $vat_src_code;
1066 $result = $discount->create($user);
1074 if (empty($error)) {
1077 $result =
$object->setPaid($user);
1088 setEventMessages($discount->error, $discount->errors,
'errors');
1091 } elseif (empty($discountcheck->id)) {
1092 setEventMessages($langs->trans(
'ErrorInvoiceCantBeConvertedToDiscountInThisState'),
null,
'errors');
1094 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate) {
1099 $result = $paiementfourn->fetch(
GETPOSTINT(
'paiement_id'));
1101 $result = $paiementfourn->delete($user);
1103 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1108 setEventMessages($paiementfourn->error, $paiementfourn->errors,
'errors');
1111 } elseif ($action ==
'add' && $usercancreate) {
1116 $selectedLines =
GETPOST(
'toselect',
'array:int');
1124 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1138 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1143 if (empty($dateinvoice)) {
1144 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1150 setEventMessages($langs->trans(
"ErrorDateIsInFuture"),
null,
'errors');
1156 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1172 $object->date_pointoftax = $date_pointoftax;
1173 $object->date_echeance = $datedue;
1179 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1181 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1183 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1184 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1203 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1205 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1208 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1213 if (empty($dateinvoice)) {
1214 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1220 setEventMessages($langs->trans(
"ErrorDateIsInFuture"),
null,
'errors');
1224 if (!
GETPOST(
'ref_supplier')) {
1225 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
1233 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1248 $object->date_pointoftax = $date_pointoftax;
1249 $object->date_echeance = $datedue;
1255 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1256 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1258 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1259 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1264 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1273 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1275 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1276 $fk_parent_line = 0;
1278 foreach ($facture_source->lines as $line) {
1280 if (method_exists($line,
'fetch_optionals')) {
1281 $line->fetch_optionals();
1285 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1286 $fk_parent_line = 0;
1289 $line->fk_facture_fourn =
$object->id;
1290 $line->fk_parent_line = $fk_parent_line;
1292 $line->subprice = -$line->subprice;
1293 $line->pa_ht = -((float) $line->pa_ht);
1294 $line->total_ht = -$line->total_ht;
1295 $line->total_tva = -$line->total_tva;
1296 $line->total_ttc = -$line->total_ttc;
1297 $line->total_localtax1 = -$line->total_localtax1;
1298 $line->total_localtax2 = -$line->total_localtax2;
1299 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1300 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1301 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1303 $result = $line->insert();
1308 if ($result > 0 && $line->product_type == 9) {
1309 $fk_parent_line = $result;
1317 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 &&
$id > 0) {
1319 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1320 $totalpaid = $facture_source->getSommePaiement();
1321 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1322 $totaldeposits = $facture_source->getSumDepositsUsed();
1323 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1324 $desc = $langs->trans(
'invoiceAvoirLineWithPaymentRestAmount');
1328 $retAddLine =
$object->addline($desc, -$remain_to_pay, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
'TTC');
1330 if ($retAddLine < 0) {
1337 if (!empty(
$object->fk_facture_source) && $id > 0) {
1339 if ($facture_source_link->fetch(
$object->fk_facture_source) > 0) {
1340 $facture_source_link->fetchObjectLinked();
1341 if (!empty($facture_source_link->linkedObjectsIds)) {
1342 foreach ($facture_source_link->linkedObjectsIds as $sourcetype => $TIds) {
1343 $object->add_object_linked($sourcetype, current($TIds));
1351 if (empty($dateinvoice)) {
1353 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1357 setEventMessages($langs->trans(
"ErrorDateIsInFuture"),
null,
'errors');
1363 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1373 $object->date_pointoftax = $date_pointoftax;
1374 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1375 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1384 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1385 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1389 $object->fac_rec = $fac_recid;
1391 $fac_rec->fetch(
$object->fac_rec);
1392 $fac_rec->fetch_lines();
1393 $object->lines = $fac_rec->lines;
1400 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1405 if (empty($dateinvoice)) {
1406 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1412 setEventMessages($langs->trans(
"ErrorDateIsInFuture"),
null,
'errors');
1416 if (!
GETPOST(
'ref_supplier')) {
1417 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
1425 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1442 $object->date_pointoftax = $date_pointoftax;
1443 $object->date_echeance = $datedue;
1449 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1450 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1452 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1453 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1458 if (empty(
$object->date_echeance)) {
1459 $object->date_echeance =
$object->calculate_date_lim_reglement();
1465 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
1467 $element = $subelement =
GETPOST(
'origin',
'alpha');
1475 if ($element ==
'order') {
1476 $element = $subelement =
'commande';
1478 if ($element ==
'propal') {
1479 $element =
'comm/propal';
1480 $subelement =
'propal';
1482 if ($element ==
'contract') {
1483 $element = $subelement =
'contrat';
1485 if ($element ==
'order_supplier') {
1487 $subelement =
'fournisseur.commande';
1489 if ($element ==
'project') {
1490 $element =
'projet';
1498 $classname = ucfirst($subelement);
1499 if ($classname ==
'Fournisseur.commande') {
1500 $classname =
'CommandeFournisseur';
1502 $objectsrc =
new $classname($db);
1503 $objectsrc->fetch($originid);
1504 $objectsrc->fetch_thirdparty();
1506 if (!empty(
$object->origin_type) && !empty(
$object->origin_id)) {
1511 if (
$object->origin_type ==
'reception') {
1512 $objectsrc->fetchObjectLinked();
1514 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1515 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1516 $object->linkedObjectsIds[
'order_supplier'][-1] = $value;
1526 $classname = ucfirst($subelement);
1527 if ($classname ==
'Fournisseur.commande') {
1528 $classname =
'CommandeFournisseur';
1530 $srcobject =
new $classname($db);
1532 $result = $srcobject->fetch(
GETPOSTINT(
'originid'));
1535 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1540 $amountdeposit = array();
1542 if ($typeamount ==
'amount') {
1543 $amount = $valuedeposit;
1545 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1548 $TTotalByTva = array();
1549 foreach ($srcobject->lines as &$line) {
1550 if (!empty($line->special_code)) {
1554 $vatkey = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
1555 if (!isset($TTotalByTva[$vatkey])) {
1556 $TTotalByTva[$vatkey] = 0;
1558 $TTotalByTva[$vatkey] += $line->total_ttc;
1561 '@phan-var-force array<string,float> $TTotalByTva';
1563 $amount_ttc_diff = 0.;
1564 foreach ($TTotalByTva as $tva => &$total) {
1565 $coef = ($srcobject->total_ttc != 0 ? $total / $srcobject->total_ttc : 0);
1566 $am = $amount * $coef;
1567 $amount_ttc_diff += $am;
1568 if (!isset($amountdeposit[$tva])) {
1569 $amountdeposit[$tva] = 0;
1571 $amountdeposit[$tva] += $am / (1 + (float) preg_replace(
'/\s*\(.*\)/',
'', (
string) $tva) / 100);
1575 if ($typeamount ==
'amount') {
1576 $amountdeposit[0] = $valuedeposit;
1577 } elseif ($typeamount ==
'variable') {
1580 $lines = $srcobject->lines;
1581 $numlines = count($lines);
1582 for ($i = 0; $i < $numlines; $i++) {
1584 if (empty($lines[$i]->qty)) {
1587 if (!empty($lines[$i]->special_code)) {
1591 $totalamount += $lines[$i]->total_ht;
1592 $tva_tx = $lines[$i]->tva_tx;
1593 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1597 if ($totalamount == 0) {
1598 $amountdeposit[0] = 0;
1601 setEventMessages($srcobject->error, $srcobject->errors,
'errors');
1603 $amountdeposit[0] = 0;
1607 $amount_ttc_diff = array_key_exists(0, $amountdeposit) ? $amountdeposit[0] : 0;
1610 foreach ($amountdeposit as $tva => $amount) {
1611 if (empty($amount)) {
1616 'amount' =>
'FixAmount',
1617 'variable' =>
'VarAmount'
1619 $descline =
'(DEPOSIT)';
1621 if ($typeamount ==
'amount') {
1622 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1623 } elseif ($typeamount ==
'variable') {
1624 $descline .=
' ('.$valuedeposit.
'%)';
1627 $descline .=
' - '.$srcobject->ref;
1657 $diff =
$object->total_ttc - $amount_ttc_diff;
1661 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1663 $tva_tx_with_code =
$object->lines[0]->tva_tx.($object->lines[0]->vat_src_code ?
' ('.$object->lines[0]->vat_src_code.
')' :
'');
1669 $object->lines[0]->localtax1_tx,
1670 $object->lines[0]->localtax2_tx,
1672 $object->lines[0]->fk_product,
1675 $object->lines[0]->product_type,
1676 $object->lines[0]->remise_percent,
1678 $object->lines[0]->date_start,
1687 } elseif ($result > 0) {
1688 $lines = $srcobject->lines;
1689 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1690 $srcobject->fetch_lines();
1691 $lines = $srcobject->lines;
1694 $num = count($lines);
1695 for ($i = 0; $i < $num; $i++) {
1696 if (!in_array($lines[$i]->
id, $selectedLines)) {
1700 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->product_label);
1701 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1704 if (method_exists($lines[$i],
'fetch_optionals')) {
1705 $lines[$i]->fetch_optionals();
1711 if ($lines[$i]->date_debut_reel) {
1714 if ($lines[$i]->date_start) {
1717 $date_end = $lines[$i]->date_fin_prevue;
1718 if ($lines[$i]->date_fin_reel) {
1719 $date_end = $lines[$i]->date_fin_reel;
1721 if ($lines[$i]->date_end) {
1722 $date_end = $lines[$i]->date_end;
1725 $tva_tx = $lines[$i]->tva_tx;
1727 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
1728 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1732 $object->special_code = $lines[$i]->special_code;
1736 $line_price_base_type = $lines[$i]->getPriceBaseType();
1737 if ($line_price_base_type ===
'TTC') {
1739 $pu = (float) $lines[$i]->subprice_ttc;
1741 } elseif (
$object->multicurrency_code !=
$conf->currency ||
$object->multicurrency_tx != 1) {
1743 $pu_currency = $lines[$i]->multicurrency_subprice;
1745 $pu = $lines[$i]->subprice;
1754 $lines[$i]->localtax1_tx,
1755 $lines[$i]->localtax2_tx,
1757 $lines[$i]->fk_product,
1758 $lines[$i]->remise_percent,
1762 $lines[$i]->info_bits,
1763 $line_price_base_type,
1767 $lines[$i]->array_options,
1768 $lines[$i]->fk_unit,
1771 $lines[$i]->ref_supplier,
1772 $lines[$i]->special_code
1781 if ($result > 0 && !empty($lines[$i]->extraparams)) {
1783 $newline->id = $result;
1784 $newline->extraparams = $lines[$i]->extraparams;
1785 $newline->setExtraParameters();
1797 $parameters = array(
'objFrom' => $srcobject);
1798 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1801 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
1808 } elseif (!$error) {
1818 $langs->load(
"errors");
1826 $categories =
GETPOST(
'categories',
'array:int');
1827 if (method_exists($object,
'setCategories')) {
1828 $object->setCategories($categories);
1835 $outputlangs = $langs;
1836 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1843 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1846 } elseif ($action ==
'updateline' && $usercancreate) {
1850 if (!
$object->fetch($id) > 0) {
1851 dol_print_error($db);
1856 $tva_tx = str_replace(
'*',
'', $tva_tx);
1865 $price_base_type =
'HT';
1866 if (empty($pu_ht) && !empty($pu_ttc)) {
1868 $price_base_type =
'TTC';
1869 } elseif (!empty($pu_ht) && !empty($pu_ttc)) {
1870 foreach (
$object->lines as $line_obj) {
1873 if ($line_obj->wasEnteredIncludingTax()) {
1875 $price_base_type =
'TTC';
1882 if (
GETPOST(
'productid') > 0) {
1884 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY') == 1) {
1886 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1892 $label = $prod->description;
1893 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1894 $label =
GETPOST(
'product_desc',
'restricthtml');
1897 $type = $prod->type;
1899 $label =
GETPOST(
'product_desc',
'restricthtml');
1908 if (preg_match(
'/\*/', $tva_tx)) {
1913 $tva_tx = str_replace(
'*',
'', $tva_tx);
1922 if (
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' &&
GETPOST(
'multicurrency_subprice') ===
'' &&
GETPOST(
'multicurrency_price_ttc') !==
'') {
1924 $price_base_type =
'TTC';
1929 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1930 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1932 if (is_array($extralabelsline)) {
1933 foreach ($extralabelsline as $key => $value) {
1934 unset($_POST[
"options_".$key]);
1938 $result =
$object->updateline(
1950 (
float) $remise_percent,
1960 unset($_POST[
'label']);
1961 unset($_POST[
'fourn_ref']);
1962 unset($_POST[
'date_starthour']);
1963 unset($_POST[
'date_startmin']);
1964 unset($_POST[
'date_startsec']);
1965 unset($_POST[
'date_startday']);
1966 unset($_POST[
'date_startmonth']);
1967 unset($_POST[
'date_startyear']);
1968 unset($_POST[
'date_endhour']);
1969 unset($_POST[
'date_endmin']);
1970 unset($_POST[
'date_endsec']);
1971 unset($_POST[
'date_endday']);
1972 unset($_POST[
'date_endmonth']);
1973 unset($_POST[
'date_endyear']);
1974 unset($_POST[
'price_ttc']);
1975 unset($_POST[
'price_ht']);
1982 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
1986 foreach (
$object->lines as $line) {
1987 if ($line->product_type == 1) {
1989 $line_price_base_type = $line->getPriceBaseType();
1990 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
1991 $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);
1994 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
1996 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
1997 $remise_percent = (float) str_replace(
'*',
'', $remise_percent);
1998 foreach (
$object->lines as $line) {
2000 $line_price_base_type = $line->getPriceBaseType();
2001 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
2002 $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);
2004 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !=
'' && $usercancreate) {
2006 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2007 $vat_rate = str_replace(
'*',
'', $vat_rate);
2010 foreach (
$object->lines as $line) {
2012 $line_price_base_type = $line->getPriceBaseType();
2013 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
2014 $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);
2016 } elseif ($action ==
'addline' && $usercancreate) {
2022 dol_print_error($db,
$object->error);
2025 $ret =
$object->fetch_thirdparty();
2027 $langs->load(
'errors');
2036 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
2037 if ($prod_entry_mode ==
'free') {
2044 $price_ht_devise =
'';
2046 $price_ttc_devise =
'';
2048 if (
GETPOST(
'price_ht') !==
'') {
2051 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2054 if (
GETPOST(
'price_ttc') !==
'') {
2057 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2058 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2066 if (empty($remise_percent)) {
2067 $remise_percent = 0;
2071 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2072 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2074 if (is_array($extralabelsline)) {
2076 foreach ($extralabelsline as $key => $value) {
2077 unset($_POST[
"options_".$key]);
2081 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
2082 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2085 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOSTINT(
'type') < 0) {
2086 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2091 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1')
2092 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
2093 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
2094 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
2095 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
2096 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
2097 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) {
2098 $langs->load(
"errors");
2099 if (
$object->type == $object::TYPE_DEPOSIT) {
2101 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2103 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPrice"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2108 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
2109 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
2113 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') && !
GETPOST(
'dp_desc')) {
2114 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2117 if (!
GETPOST(
'qty',
'alpha')) {
2118 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2122 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2123 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
2127 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2128 $idprod = $res->fk_product_child;
2130 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2136 if ($prod_entry_mode !=
'free' && empty($error)) {
2140 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
2145 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
2146 $idprod = (int) $reg[1];
2147 $res = $productsupplier->fetch($idprod);
2150 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
2152 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
2153 if ($productsupplier->fourn_socid != $socid) {
2154 $productsupplier->ref_supplier =
'';
2157 $fksoctosearch =
$object->thirdparty->id;
2158 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
2160 } elseif (
GETPOSTINT(
'idprodfournprice') > 0) {
2161 $qtytosearch = (float) $qty;
2163 $idprod = $productsupplier->get_buyprice(
GETPOSTINT(
'idprodfournprice'), $qtytosearch);
2164 $res = $productsupplier->fetch($idprod);
2168 $label = $productsupplier->label;
2171 $outputlangs = $langs;
2173 if (
GETPOST(
'lang_id',
'aZ09')) {
2174 $newlang =
GETPOST(
'lang_id',
'aZ09');
2176 if (empty($newlang)) {
2177 $newlang =
$object->thirdparty->default_lang;
2179 if (!empty($newlang)) {
2181 $outputlangs->setDefaultLang($newlang);
2183 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
2185 $desc = $productsupplier->description;
2188 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
2189 $desc = $productsupplier->desc_supplier;
2200 $ref_supplier = $productsupplier->ref_supplier;
2204 $tmpidprodfournprice =
GETPOST(
'idprodfournprice',
'alpha');
2205 if (is_numeric($tmpidprodfournprice) && (
int) $tmpidprodfournprice > 0) {
2206 $tmpidprodfournprice = (int) $tmpidprodfournprice;
2208 $tmpidprodfournprice = 0;
2214 if (empty($tva_tx) || empty($tva_npr)) {
2220 $type = $productsupplier->type;
2221 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
2222 $price_base_type =
'HT';
2224 $pu_devise =
price2num($price_ht_devise,
'CU');
2225 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
2226 $price_base_type =
'TTC';
2228 $pu_devise =
price2num($price_ttc_devise,
'CU');
2230 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
2231 if (empty(
$object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code !=
$object->multicurrency_code)) {
2232 $pu = $productsupplier->fourn_pu;
2235 $pu = $productsupplier->fourn_pu;
2236 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
2240 $ref_supplier = $productsupplier->ref_supplier;
2261 min($rank, count(
$object->lines) + 1),
2264 $productsupplier->fk_unit,
2267 GETPOST(
'fourn_ref',
'alpha'),
2271 if ($idprod == -99 || $idprod == 0) {
2274 $langs->load(
"errors");
2275 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2277 if ($idprod == -1) {
2280 $langs->load(
"errors");
2281 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
2283 } elseif (empty($error)) {
2284 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2285 $tva_tx = str_replace(
'*',
'', $tva_tx);
2286 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2289 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
2293 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
2302 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
2303 $price_base_type =
'HT';
2305 $pu_devise =
price2num($price_ht_devise,
'CU');
2307 $price_base_type =
'TTC';
2309 $pu_devise =
price2num($price_ttc_devise,
'CU');
2312 $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);
2316 if (!$error && $result > 0) {
2321 $outputlangs = $langs;
2324 $newlang =
GETPOST(
'lang_id',
'aZ09');
2327 $newlang =
$object->thirdparty->default_lang;
2329 if (!empty($newlang)) {
2331 $outputlangs->setDefaultLang($newlang);
2336 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2342 unset($_POST [
'prod_entry_mode']);
2344 unset($_POST[
'qty']);
2345 unset($_POST[
'type']);
2346 unset($_POST[
'remise_percent']);
2347 unset($_POST[
'pu']);
2348 unset($_POST[
'price_ht']);
2349 unset($_POST[
'multicurrency_price_ht']);
2350 unset($_POST[
'price_ttc']);
2351 unset($_POST[
'fourn_ref']);
2352 unset($_POST[
'tva_tx']);
2353 unset($_POST[
'label']);
2354 unset($localtax1_tx);
2355 unset($localtax2_tx);
2356 unset($_POST[
'np_marginRate']);
2357 unset($_POST[
'np_markRate']);
2358 unset($_POST[
'dp_desc']);
2359 unset($_POST[
'idprodfournprice']);
2360 unset($_POST[
'units']);
2362 unset($_POST[
'date_starthour']);
2363 unset($_POST[
'date_startmin']);
2364 unset($_POST[
'date_startsec']);
2365 unset($_POST[
'date_startday']);
2366 unset($_POST[
'date_startmonth']);
2367 unset($_POST[
'date_startyear']);
2368 unset($_POST[
'date_endhour']);
2369 unset($_POST[
'date_endmin']);
2370 unset($_POST[
'date_endsec']);
2371 unset($_POST[
'date_endday']);
2372 unset($_POST[
'date_endmonth']);
2373 unset($_POST[
'date_endyear']);
2375 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
2383 } elseif ($action ==
'classin' && $usercancreate) {
2385 $result =
$object->setProject($projectid);
2386 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
2390 $totalpaid =
$object->getSommePaiement();
2391 $resteapayer =
$object->total_ttc - $totalpaid;
2394 $ventilExportCompta =
$object->getVentilExportCompta();
2396 if (!$ventilExportCompta) {
2399 $idwarehouse =
GETPOST(
'idwarehouse');
2403 $qualified_for_stock_change = 0;
2405 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2407 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2412 $langs->load(
"stocks");
2413 if (!$idwarehouse || $idwarehouse == -1) {
2415 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
2420 $object->setDraft($user, $idwarehouse);
2424 $outputlangs = $langs;
2427 $newlang =
GETPOST(
'lang_id',
'aZ09');
2430 $newlang =
$object->thirdparty->default_lang;
2432 if (!empty($newlang)) {
2434 $outputlangs->setDefaultLang($newlang);
2439 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2448 } elseif ($action ==
'reopen' && $usercancreate) {
2450 $result =
$object->fetch($id);
2453 $result =
$object->setUnpaid($user);
2455 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
2464 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2467 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
2469 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
2470 $trackid =
'sinv'.$object->id;
2471 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2475 $permissiontoadd = $usercancreate;
2476 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2479 if ($action ==
'calculate' && $usercancreate) {
2480 $calculationrule =
GETPOST(
'calculationrule');
2484 $result =
$object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0,
$object->thirdparty);
2490 if ($action ==
'update_extras' && $permissiontoeditextra) {
2493 $attribute_name =
GETPOST(
'attribute',
'aZ09');
2496 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
2502 $result =
$object->updateExtraField($attribute_name,
'BILL_SUPPLIER_MODIFY');
2510 $action =
'edit_extras';
2515 if ($action ==
'addcontact' && $usercancreate) {
2516 $result =
$object->fetch($id);
2518 if ($result > 0 && $id > 0) {
2521 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2525 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2528 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2529 $langs->load(
"errors");
2530 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2535 } elseif ($action ==
'swapstatut' && $usercancreate) {
2540 dol_print_error($db);
2542 } elseif ($action ==
'deletecontact' && $usercancreate) {
2548 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2551 dol_print_error($db);
2562$form =
new Form($db);
2564$bankaccountstatic =
new Account($db);
2572$title =
$object->ref.
" - ".$langs->trans(
'Card');
2573if ($action ==
'create') {
2574 $title = $langs->trans(
"NewSupplierInvoice");
2576$help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
2577llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-fourn-facture page-card');
2580if ($action ==
'create') {
2582 $selectedLines = array();
2584 print
load_fiche_titre($langs->trans(
'NewSupplierInvoice'),
'',
'supplier_invoice');
2588 $currency_code =
$conf->currency;
2589 $vat_reverse_charge = 0;
2595 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2596 $currency_code = $societe->multicurrency_code;
2601 if (!empty($origin) && !empty($originid)) {
2603 $element = $subelement = $origin;
2605 if ($element ==
'project') {
2606 $projectid = $originid;
2607 $element =
'projet';
2611 if ($element ==
'order') {
2612 $element = $subelement =
'commande';
2614 if ($element ==
'propal') {
2615 $element =
'comm/propal';
2616 $subelement =
'propal';
2618 if ($element ==
'contract') {
2619 $element = $subelement =
'contrat';
2621 if ($element ==
'order_supplier') {
2623 $subelement =
'fournisseur.commande';
2627 $classname = ucfirst($subelement);
2628 if ($classname ==
'Fournisseur.commande') {
2629 $classname =
'CommandeFournisseur';
2631 $objectsrc =
new $classname($db);
2632 '@phan-var-force Project|Commande|Propal|Facture|Contrat|CommandeFournisseur|CommonObject $objectsrc';
2634 $objectsrc->fetch($originid);
2635 $objectsrc->fetch_thirdparty();
2637 $projectid = (int) $objectsrc->fk_project;
2639 $soc = $objectsrc->thirdparty;
2641 $cond_reglement_id = 0;
2642 $mode_reglement_id = 0;
2644 $transport_mode_id = 0;
2647 if (!empty($objectsrc->cond_reglement_id)) {
2648 $cond_reglement_id = $objectsrc->cond_reglement_id;
2650 if (!empty($objectsrc->mode_reglement_id)) {
2651 $mode_reglement_id = $objectsrc->mode_reglement_id;
2653 if (!empty($objectsrc->fk_account)) {
2654 $fk_account = $objectsrc->fk_account;
2656 if (!empty($objectsrc->transport_mode_id)) {
2657 $transport_mode_id = $objectsrc->transport_mode_id;
2660 if (empty($cond_reglement_id)
2661 || empty($mode_reglement_id)
2662 || empty($fk_account)
2663 || empty($transport_mode_id)
2665 if ($origin ==
'reception') {
2667 if (!isset($objectsrc->supplier_order)) {
2668 $objectsrc->fetch_origin();
2671 if (!empty($objectsrc->origin_object)) {
2672 $originObject = $objectsrc->origin_object;
2673 if (empty($cond_reglement_id) && !empty($originObject->cond_reglement_id)) {
2674 $cond_reglement_id = $originObject->cond_reglement_id;
2676 if (empty($mode_reglement_id) && !empty($originObject->mode_reglement_id)) {
2677 $mode_reglement_id = $originObject->mode_reglement_id;
2679 if (empty($fk_account) && !empty($originObject->fk_account)) {
2680 $fk_account = $originObject->fk_account;
2682 if (empty($transport_mode_id) && !empty($originObject->transport_mode_id)) {
2683 $transport_mode_id = $originObject->transport_mode_id;
2690 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
2691 $cond_reglement_id = $soc->cond_reglement_supplier_id;
2693 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
2694 $mode_reglement_id = $soc->mode_reglement_supplier_id;
2696 if (empty($fk_account) && !empty($soc->fk_account)) {
2697 $fk_account = $soc->fk_account;
2699 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
2700 $transport_mode_id = $soc->transport_mode_id;
2706 if (!empty($objectsrc->multicurrency_code)) {
2707 $currency_code = $objectsrc->multicurrency_code;
2709 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
2710 $currency_tx = $objectsrc->multicurrency_tx;
2715 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2717 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2720 $objectsrc->fetch_optionals();
2721 $object->array_options = $objectsrc->array_options;
2723 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2724 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2725 $vat_reverse_charge = (empty($societe) ?
'' : $societe->vat_reverse_charge);
2726 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2727 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2729 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalInt(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2731 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2733 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2734 $currency_code = $societe->multicurrency_code;
2739 if (empty($cond_reglement_id)) {
2740 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2744 if (empty($mode_reglement_id)) {
2745 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2749 if (!
GETPOST(
'changecompany')) {
2751 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
2754 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
2761 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
2762 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
2764 if ($origin ==
'contrat') {
2765 $langs->load(
"admin");
2766 $text = $langs->trans(
"ToCreateARecurringInvoice");
2767 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"SupplierBills"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
2769 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
2771 print
info_admin($text, 0, 0,
'0',
'opacitymedium').
'<br>';
2774 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2775 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2776 print
'<input type="hidden" name="action" value="add">';
2777 print
'<input type="hidden" name="changecompany" value="0">';
2779 if (!empty($societe->id) && $societe->id > 0) {
2780 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2782 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2783 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2784 if (!empty($currency_tx)) {
2785 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2787 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2788 if ($backtopageforcancel) {
2789 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
2795 $parameters = array();
2797 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierInvoice', $parameters, $object, $action);
2798 if (empty($reshook)) {
2799 print
'<table class="border centpercent">';
2806 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2807 $invoice_predefined->fetch($fac_recid);
2811 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2814 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2815 $absolute_discount = $societe->getAvailableDiscounts(
null,
'', 0, 1);
2816 print $societe->getNomUrl(1,
'supplier');
2817 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2819 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2820 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');
2823 print
'<script type="text/javascript">
2824 $(document).ready(function() {
2825 $("#socid").change(function() {
2826 console.log("We have changed the company - Reload page");
2828 $("input[name=action]").val("create");
2829 $("input[name=changecompany]").val("1");
2830 $("form[name=add]").submit();
2835 if ($fac_recid <= 0) {
2836 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>';
2842 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2843 $invoice_predefined->fetch($fac_recid);
2845 $dateinvoice = $invoice_predefined->date_when;
2846 if (empty($projectid)) {
2847 $projectid = $invoice_predefined->fk_project;
2849 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2850 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2851 $fk_account = $invoice_predefined->fk_account;
2852 $note_public = $invoice_predefined->note_public;
2853 $note_private = $invoice_predefined->note_private;
2855 if (!empty($invoice_predefined->multicurrency_code)) {
2856 $currency_code = $invoice_predefined->multicurrency_code;
2858 if (!empty($invoice_predefined->multicurrency_tx)) {
2859 $currency_tx = $invoice_predefined->multicurrency_tx;
2862 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2863 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2864 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2866 $resql = $db->query($sql);
2868 $num = $db->num_rows($resql);
2872 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2874 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2875 print
'<option value="0" selected></option>';
2877 $objp = $db->fetch_object($resql);
2878 print
'<option value="'.$objp->rowid.
'"';
2879 if ($fac_recid == $objp->rowid) {
2881 $exampletemplateinvoice->fetch($fac_recid);
2883 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2889 print
'<script type="text/javascript">
2890 $(document).ready(function() {
2891 $("#fac_rec").change(function() {
2892 console.log("We have changed the template invoice - Reload page");
2894 $("input[name=action]").val("create");
2895 $("form[name=add]").submit();
2904 dol_print_error($db);
2908 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2910 print
'<div class="tagtable">'.
"\n";
2913 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2914 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
'checked').
'> ';
2915 $desc = $form->textwithpicto($tmp.
'<label for="radio_standard">'.$langs->trans(
"InvoiceStandardAsk").
'</label>', $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2917 print
'</div></div>';
2919 if (empty($origin) || (($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') && !empty($originid))) {
2922 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2923 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOSTINT(
'type') == 3 ?
' checked' :
'') .
'> ';
2924 print
'<script type="text/javascript">
2925 jQuery(document).ready(function() {
2926 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2927 jQuery("#radio_standard").prop("checked", true);
2929 jQuery("#typedeposit, #valuedeposit").click(function() {
2930 jQuery("#radio_deposit").prop("checked", true);
2932 jQuery("#typedeposit").change(function() {
2933 console.log("We change type of down payment");
2934 jQuery("#radio_deposit").prop("checked", true);
2935 setRadioForTypeOfInvoice();
2937 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2938 setRadioForTypeOfInvoice();
2940 function setRadioForTypeOfInvoice() {
2941 console.log("Change radio");
2942 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2943 jQuery(".checkforselect").prop("disabled", true);
2944 jQuery(".checkforselect").prop("checked", false);
2946 jQuery(".checkforselect").prop("disabled", false);
2947 jQuery(".checkforselect").prop("checked", true);
2953 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2955 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2956 print
'<table class="nobordernopadding"><tr>';
2960 if ($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') {
2961 print
'<td class="nowrap" style="padding-left: 15px">';
2963 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2964 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2965 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2967 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
2968 $valuedeposit =
GETPOST(
'valuedeposit',
'int');
2969 $deposit_percent =
null;
2970 if ($origin ==
'reception') {
2972 if (!isset($objectsrc->origin_object)) {
2973 $objectsrc->fetch_origin();
2975 if (!empty($objectsrc->origin_object)) {
2976 $deposit_percent = $objectsrc->origin_object->deposit_percent;
2978 } elseif (!empty($objectsrc->deposit_percent)) {
2979 $deposit_percent = $objectsrc->deposit_percent;
2981 if (empty($typedeposit) && !empty($deposit_percent)) {
2982 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
2983 if (!empty($origin_payment_conditions_deposit_percent)) {
2984 $typedeposit =
'variable';
2987 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($deposit_percent)) {
2988 $valuedeposit = $deposit_percent;
2990 print $form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
2992 print
'<td class="nowrap" style="padding-left: 5px">';
2993 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' . $valuedeposit .
'"/>';
2996 print
'</tr></table>';
2998 print
'</div></div>';
3067 if (empty($origin)) {
3068 if (!empty($societe->id) && $societe->id > 0) {
3072 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
3074 dol_print_error($db, $facturestatic->error, $facturestatic->errors);
3079 foreach ($facids as $key => $valarray) {
3080 $newinvoice_static->id = $key;
3081 $newinvoice_static->ref = $valarray [
'ref'];
3082 $newinvoice_static->status = $valarray [
'status'];
3083 $newinvoice_static->statut = $valarray [
'status'];
3084 $newinvoice_static->type = $valarray [
'type'];
3085 $newinvoice_static->paid = $valarray [
'paye'];
3086 $newinvoice_static->paye = $valarray [
'paye'];
3088 $optionsav .=
'<option value="'.$key.
'"';
3090 $optionsav .=
' selected';
3092 $newinvoice_static->fetch_optionals($key);
3093 $object->array_options = $newinvoice_static->array_options;
3096 $optionsav .= $newinvoice_static->ref;
3097 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
3098 $optionsav .=
'</option>';
3101 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3102 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOSTINT(
'type') == 2 ?
' checked' :
'');
3104 $tmp .=
' disabled';
3108 print
'<script type="text/javascript">
3109 jQuery(document).ready(function() {
3110 if (! jQuery("#radio_creditnote").is(":checked"))
3112 jQuery("#credit_note_options").hide();
3114 jQuery("#radio_creditnote").click(function() {
3115 jQuery("#credit_note_options").show();
3117 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
3118 jQuery("#credit_note_options").hide();
3122 $text = $tmp.
'<label for="radio_creditnote">'.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
3124 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3126 $text .=
' disabled';
3130 $text .=
'<option value="-1"></option>';
3131 $text .= $optionsav;
3133 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
3135 $text .=
'</select>';
3136 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3139 print
'<div id="credit_note_options" class="clearboth">';
3140 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' :
'').
' /> ';
3141 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
3142 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' :
'').
' /> ';
3143 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
3146 print
'</div></div>';
3149 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3151 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3153 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2"> ';
3155 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
3156 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
3157 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3159 print
'</div></div>'.
"\n";
3169 print
'<tr><td class="fieldrequired">';
3170 print $form->textwithpicto($langs->trans(
'RefSupplierBill'), $langs->trans(
"RefOfOnVendorSide", $langs->trans(
"SupplierBill"))).
'</td><td>';
3171 print
'<input name="ref_supplier" value="'.(GETPOSTISSET(
'ref_supplier') ?
GETPOST(
'ref_supplier') : (!empty($objectsrc->ref_supplier) ? $objectsrc->ref_supplier :
'')).
'" type="text" spellcheck="false"';
3172 if (!empty($societe->id) && $societe->id > 0) {
3181 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
3182 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
3186 if (!empty($societe->id) && $societe->id > 0) {
3188 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
3190 $thirdparty = $societe;
3192 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
3193 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3199 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth300" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
3203 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
3204 print img_picto(
'',
'action',
'class="pictofixedwidth"');
3205 print $form->selectDate($dateinvoice ? (
int) $dateinvoice :
'',
'', 0, 0, 0,
"add", 1, 1);
3210 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td>';
3211 print img_picto(
'',
'action',
'class="pictofixedwidth"');
3212 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
3217 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
3218 print img_picto(
'',
'payment',
'class="pictofixedwidth"');
3219 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth200 widthcentpercentminusx');
3223 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
3224 print img_picto(
'',
'action',
'class="pictofixedwidth"');
3225 print $form->selectDate($datedue,
'ech', 0, 0, 0,
"add", 1, 1);
3229 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
3230 print img_picto(
'',
'bank',
'class="pictofixedwidth"');
3231 $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'DBIT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
3236 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
3238 print img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
3246 $langs->load(
'projects');
3247 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
3248 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');
3249 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>';
3256 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
3257 print
'<td colspan="3" class="maxwidthonsmartphone">';
3258 print img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
3259 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 :
''));
3265 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
3266 print
'<tr><td>' . $langs->trans(
'VATReverseCharge') .
'</td><td>';
3269 $vat_reverse_charge = (
GETPOST(
'vat_reverse_charge',
'alpha') ==
'on' ||
GETPOST(
'vat_reverse_charge',
'alpha') ==
'1') ? 1 : 0;
3270 } elseif ($vat_reverse_charge == 1 || $societe->vat_reverse_charge == 1 || ($societe->country_code !=
$mysoc->country_code &&
isInEEC(
$mysoc) &&
isInEEC($societe) && !empty($societe->tva_intra))) {
3271 $vat_reverse_charge = 1;
3273 $vat_reverse_charge = 0;
3276 print
'<input type="checkbox" name="vat_reverse_charge"'. (!empty($vat_reverse_charge) ?
' checked ' :
'') .
'>';
3283 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
3284 print
'<td class="maxwidthonsmartphone">';
3285 print img_picto(
'',
'currency',
'class="pictofixedwidth"');
3286 $used_currency_code = $currency_code;
3287 if (!
GETPOST(
'changecompany')) {
3288 $used_currency_code =
GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code;
3290 print $form->selectMultiCurrency($used_currency_code,
'multicurrency_code');
3296 if ($fac_recid > 0) {
3297 $dateexample = $dateinvoice;
3298 if (empty($dateexample)) {
3301 $substitutionarray = array(
3302 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
3303 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
3304 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
3305 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
3306 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
3307 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
3308 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
3309 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
3310 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
3311 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
3312 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
3315 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
3316 foreach ($substitutionarray as $key => $val) {
3317 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
3319 $htmltext .=
'</i>';
3324 $langs->loadLangs(array(
"intracommreport"));
3325 print
'<!-- If module intracomm on -->'.
"\n";
3326 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
3327 $form->selectTransportMode(
GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
3331 if (empty($reshook)) {
3332 print
$object->showOptionals($extrafields,
'create');
3337 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
3338 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
3343 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
3345 $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%');
3346 print $doleditor->Create(1);
3352 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
3354 $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%');
3355 print $doleditor->Create(1);
3361 if (!empty($objectsrc) && $classname !==
null) {
3362 print
"\n<!-- ".$classname.
" info -->";
3364 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
3365 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
3366 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
3367 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
3368 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
3370 $txt = $langs->trans($classname);
3371 if ($classname ==
'CommandeFournisseur') {
3372 $langs->load(
'orders');
3373 $txt = $langs->trans(
"SupplierOrder");
3375 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
3377 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'invoice_supplier');
3379 if (isset($objectsrc->linkedObjects[
'invoice_supplier'])) {
3380 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
3382 $invoice_supplier = [];
3384 '@phan-var-force null|FactureFournisseur[] $invoice_supplier';
3387 if (is_array($invoice_supplier)) {
3388 $cntinvoice = count($invoice_supplier);
3390 if ($cntinvoice >= 1) {
3391 setEventMessages(
'WarningBillExist',
null,
'warnings');
3392 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
3397 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
3398 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
3399 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
3400 print
'<tr><td>'.$langs->transcountry(
"AmountLT1",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
3403 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
3404 print
'<tr><td>'.$langs->transcountry(
"AmountLT2",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
3406 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
3409 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
'</td></tr>';
3410 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
"</td></tr>";
3411 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
"</td></tr>";
3416 $parameters = array();
3417 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
3418 print $hookmanager->resPrint;
3426 print $form->buttonsSaveCancel(
"CreateDraft");
3429 if (!empty($objectsrc)) {
3432 $title = $langs->trans(
'ProductsAndServices');
3435 print
'<div class="div-table-responsive-no-min">';
3436 print
'<table class="noborder centpercent">';
3438 $objectsrc->printOriginLinesList(
'', $selectedLines);
3446 if ($id > 0 || !empty($ref)) {
3452 $result =
$object->fetch($id, $ref);
3457 $result =
$object->fetch_thirdparty();
3463 $societe =
$object->thirdparty;
3465 $totalpaid =
$object->getSommePaiement();
3466 $totalcreditnotes =
$object->getSumCreditNotesUsed();
3467 $totaldeposits =
$object->getSumDepositsUsed();
3475 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
3478 $multicurrency_resteapayer = 0;
3480 $multicurrency_totalpaid =
$object->getSommePaiement(1);
3481 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
3482 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
3483 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
3487 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
3488 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
3495 $resteapayeraffiche = $resteapayer;
3498 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
3499 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
3501 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
3502 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
3505 $absolute_discount = $societe->getAvailableDiscounts(
null, $filterabsolutediscount, 0, 1);
3506 $absolute_creditnote = $societe->getAvailableDiscounts(
null, $filtercreditnote, 0, 1);
3507 $absolute_discount =
price2num($absolute_discount,
'MT');
3508 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
3512 $objectidnext =
$object->getIdReplacingInvoice();
3515 $titre = $langs->trans(
'SupplierInvoice');
3517 print
dol_get_fiche_head($head,
'card', $titre, -1,
'supplier_invoice', 0,
'',
'', 0,
'', 1);
3522 if ($action ==
'converttoreduc') {
3525 $type_fac =
'ExcessPaid';
3527 $type_fac =
'CreditNote';
3529 $type_fac =
'Deposit';
3531 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
3532 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
3533 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
3537 if ($action ==
'clone') {
3539 $formquestion = array(
3540 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplierBill"),
'value' => $langs->trans(
"CopyOf").
' '.
$object->ref_supplier),
3541 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
3544 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 0);
3548 if ($action ==
'valid') {
3550 if (preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) {
3552 $numref =
$object->getNextNumRef($societe);
3554 $numref = (string)
$object->ref;
3561 $text = $langs->trans(
'ConfirmValidateBill', $numref);
3569 $formquestion = array();
3571 $qualified_for_stock_change = 0;
3573 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3575 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3579 $langs->load(
"stocks");
3580 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3583 $warehouse_array = $warehouse->list_array();
3584 if (count($warehouse_array) == 1) {
3586 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3589 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3591 $formquestion = array(
3592 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3596 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
3601 if ($action ==
'edit') {
3602 $formquestion = array();
3604 $qualified_for_stock_change = 0;
3606 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3608 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3611 $langs->load(
"stocks");
3612 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3615 $warehouse_array = $warehouse->list_array();
3616 if (count($warehouse_array) == 1) {
3618 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3621 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3623 $formquestion = array(
3624 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3627 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill',
$object->ref),
'confirm_edit', $formquestion, 1, 1);
3631 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
3632 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'', 0, 1);
3635 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
3639 $close[$i][
'code'] =
'discount_vat';
3641 $close[$i][
'code'] =
'badsupplier';
3643 $close[$i][
'code'] =
'other';
3647 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
3649 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3651 $close[$i][
'label'] = $langs->trans(
"Other");
3655 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3657 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3659 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
3662 $arrayreasons = array();
3663 foreach ($close as $key => $val) {
3664 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
3668 $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'));
3670 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
3674 if ($action ==
'canceled') {
3676 $close[1][
'code'] =
'badsupplier';
3677 $close[2][
'code'] =
'abandon';
3679 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3680 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
3682 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier",
$object->ref), $close[1][
'label'], 1);
3683 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
3685 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
3686 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
3689 $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'));
3691 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 280);
3695 if ($action ==
'delete') {
3696 $formquestion = array();
3698 $qualified_for_stock_change = 0;
3700 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3702 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3706 $langs->load(
"stocks");
3707 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3710 $warehouse_array = $warehouse->list_array();
3712 $selectwarehouse =
'<span class="questionrevertstock hidden">';
3713 if (count($warehouse_array) == 1) {
3715 $selectwarehouse .=
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3718 $selectwarehouse .= $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3720 $selectwarehouse .=
'</span>';
3722 $selectyesno = array(0 => $langs->trans(
'No'), 1 => $langs->trans(
'Yes'));
3724 print
'<script type="text/javascript">
3725 $(document).ready(function() {
3726 $("#revertstock").change(function() {
3727 if(this.value > 0) {
3728 $(".questionrevertstock").removeClass("hidden");
3730 $(".questionrevertstock").addClass("hidden");
3736 $formquestion = array(
3737 array(
'type' =>
'select',
'name' =>
'revertstock',
'label' => $langs->trans(
"RevertProductsToStock"),
'select_show_empty' => 0,
'values' => $selectyesno),
3738 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $selectwarehouse,
'tdclass' =>
'questionrevertstock hidden')
3742 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete', $formquestion, 1, 1);
3744 if ($action ==
'deletepayment') {
3745 $payment_id =
GETPOST(
'paiement_id');
3746 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
3750 if ($action ==
'ask_deleteline') {
3751 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
3755 if ($action ==
'ask_subtotal_deleteline') {
3756 $langs->load(
'subtotals');
3757 $subtotaltitle =
'DeleteSubtotalLine';
3758 $subtotalquestion =
'ConfirmDeleteSubtotalLine';
3759 $subtotalformquestion = array();
3760 if (
GETPOST(
'type') ==
'title') {
3761 $subtotalformquestion = array(array(
'type' =>
'checkbox',
'name' =>
'deletecorrespondingsubtotalline',
'label' => $langs->trans(
'DeleteCorrespondingSubtotalLine'),
'value' => 0));
3762 $subtotaltitle =
'DeleteTitleLine';
3763 $subtotalquestion =
'ConfirmDeleteTitleLine';
3765 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans($subtotaltitle), $langs->trans($subtotalquestion),
'confirm_delete_subtotalline', $subtotalformquestion,
'no', 1);
3769 if ($action ==
'add_title_line') {
3770 $langs->load(
'subtotals');
3772 $depth_array =
$object->getPossibleLevels($langs);
3773 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3774 } elseif ($action ==
'add_subtotal_line') {
3775 $langs->load(
'subtotals');
3777 $titles =
$object->getPossibleTitles();
3778 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3779 } elseif ($action ==
'add_text_line') {
3780 $langs->load(
'subtotals');
3782 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3786 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
3787 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
3788 if (empty($reshook)) {
3789 $formconfirm .= $hookmanager->resPrint;
3790 } elseif ($reshook > 0) {
3791 $formconfirm = $hookmanager->resPrint;
3799 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
3801 $morehtmlref =
'<div class="refidno">';
3803 $morehtmlref .= $form->editfieldkey(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, (
int) $usercancreate,
'string',
'', 0, 1);
3804 $morehtmlref .= $form->editfieldval(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
3806 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'supplier');
3808 $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>';
3812 $langs->load(
"projects");
3813 $morehtmlref .=
'<br>';
3814 if ($permissiontoadd) {
3815 $morehtmlref .= img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
3816 if ($action !=
'classify') {
3817 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.((int)
$object->id).
'">'.img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
3819 $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');
3821 if (!empty(
$object->fk_project)) {
3823 $proj->fetch(
$object->fk_project);
3824 $morehtmlref .= $proj->getNomUrl(1);
3826 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
3831 $morehtmlref .=
'</div>';
3833 $object->totalpaid = $totalpaid;
3835 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
3838 $parameters = array();
3840 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierInvoice', $parameters, $object, $action);
3841 if (empty($reshook)) {
3842 print
'<div class="fichecenter">';
3843 print
'<div class="fichehalfleft">';
3844 print
'<div class="underbanner clearboth"></div>';
3846 print
'<table class="border tableforfield centpercent">';
3849 print
'<tr><td>'.$langs->trans(
'Type').
'</td><td>';
3850 print
'<span class="badgeneutral">';
3854 print
' '.$object->getSubtypeLabel(
'facture_fourn');
3858 $facreplaced->fetch(
$object->fk_facture_source);
3859 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
3862 if (
$object->fk_facture_source > 0) {
3864 $facusing->fetch(
$object->fk_facture_source);
3865 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
3867 $langs->load(
"errors");
3868 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"WarningCorrectedInvoiceNotFound").
'</span>';
3873 $object->getListIdAvoirFromInvoice();
3875 if (!empty(
$object->creditnote_ids)) {
3876 $invoicecredits = array();
3877 foreach (
$object->creditnote_ids as $invoiceid) {
3879 $creditnote->fetch($invoiceid);
3880 $invoicecredits[] = $creditnote->getNomUrl(1);
3882 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
3885 if (isset($objectidnext) && $objectidnext > 0) {
3888 $facthatreplace->fetch($objectidnext);
3889 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
3893 $result = $discount->fetch(0, 0,
$object->id);
3895 print
' <span class="opacitymediumbycolor paddingleft">';
3896 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
3897 $s = str_replace(
'{s1}',
$object->getLibType(1), $s);
3898 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
3900 print
'</span><br>';
3904 if (
$object->fk_fac_rec_source > 0) {
3906 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
3908 print
' <span class="opacitymediumbycolor paddingleft">';
3909 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->title).
'</a>';
3910 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
3920 print
'<!-- Discounts -->'.
"\n";
3921 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
3924 $thirdparty = $societe;
3926 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3932 print
'<td>'.$form->editfieldkey(
"Label",
'label',
$object->label, $object, (
int) $usercancreate).
'</td>';
3933 print
'<td>'.$form->editfieldval(
"Label",
'label',
$object->label, $object, $usercancreate).
'</td>';
3941 print $form->editfieldkey(
"DateInvoice",
'datef', (
string)
$object->date,
$object, (int) $form_permission,
'datepicker');
3942 print
'</td><td colspan="3">';
3943 print $form->editfieldval(
"Date",
'datef',
$object->date, $object, $form_permission,
'datepicker');
3949 print $form->editfieldkey(
"DatePointOfTax",
'date_pointoftax', (
string)
$object->date_pointoftax,
$object, (int) $pointoftax_form_permission,
'datepicker');
3950 print
'</td><td colspan="3">';
3951 print $form->editfieldval(
"DatePointOfTax",
'date_pointoftax',
$object->date_pointoftax, $object, $pointoftax_form_permission,
'datepicker');
3956 $langs->load(
'bills');
3957 print
'<tr><td class="nowrap">';
3958 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3959 print $langs->trans(
'PaymentConditions');
3961 if ($action !=
'editconditions' && $form_permission) {
3962 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>';
3964 print
'</tr></table>';
3966 if ($action ==
'editconditions') {
3967 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
3969 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
3976 print $form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', (
string)
$object->date_echeance, $object, (
int) $form_permission,
'datepicker');
3978 print $form->editfieldval(
"DateMaxPayment",
'date_lim_reglement',
$object->date_echeance, $object, $form_permission,
'datepicker');
3979 if ($action !=
'editdate_lim_reglement' &&
$object->hasDelay()) {
3980 print img_warning($langs->trans(
'Late'));
3985 $langs->load(
'bills');
3986 print
'<tr><td class="nowrap">';
3987 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3988 print $langs->trans(
'PaymentMode');
3990 if ($action !=
'editmode' && $form_permission) {
3991 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>';
3993 print
'</tr></table>';
3995 if ($action ==
'editmode') {
3996 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3998 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'none');
4004 print
'<tr><td class="nowrap">';
4005 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
4006 print $langs->trans(
'BankAccount');
4008 if ($action !=
'editbankaccount' && $usercancreate) {
4009 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>';
4011 print
'</tr></table>';
4013 if ($action ==
'editbankaccount') {
4014 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
4016 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
4024 print
'<tr><td class="nowrap">';
4025 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
4026 print $langs->trans(
'VATReverseCharge');
4028 if ($action !=
'editvatreversecharge' && $usercancreate) {
4029 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>';
4031 print
'</tr></table>';
4033 if ($action ==
'editvatreversecharge') {
4034 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
4035 print
'<input type="hidden" name="action" value="setvatreversecharge">';
4036 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4038 print
'<input type="checkbox" name="vat_reverse_charge"' . (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
'>';
4040 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4043 print
'<input type="checkbox" name="vat_reverse_charge"'. (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
' disabled>';
4051 print
'<table width="100%" class="nobordernopadding"><tr><td>';
4052 print $langs->trans(
'IncotermLabel');
4053 print
'<td><td class="right">';
4054 if ($usercancreate) {
4055 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.img_edit().
'</a>';
4059 print
'</td></tr></table>';
4062 if ($action !=
'editincoterm') {
4063 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
4065 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
4072 $langs->loadLangs(array(
"intracommreport"));
4073 print
'<!-- If module intracomm on -->'.
"\n";
4075 print
'<table class="nobordernopadding centpercent"><tr><td>';
4076 print $langs->trans(
'IntracommReportTransportMode');
4078 if ($action !=
'edittransportmode' && ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"))) {
4079 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edittransportmode&token='.
newToken().
'&id='.
$object->id.
'">'.img_edit().
'</a></td>';
4081 print
'</tr></table>';
4084 if ($action ==
'edittransportmode') {
4085 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'transport_mode_id', 1, 1);
4087 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'none');
4095 print
'<table class="nobordernopadding centpercent"><tr><td>';
4096 print $langs->trans(
"Categories");
4097 print
'<td><td class="right">';
4098 if ($usercancreate) {
4099 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.img_edit().
'</a>';
4103 print
'</td></tr></table>';
4106 if ($action ==
'edittags') {
4107 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
4108 print
'<input type="hidden" name="action" value="settags">';
4109 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4110 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
4111 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
4114 print $form->showCategories(
$object->id, Categorie::TYPE_SUPPLIER_INVOICE, 1);
4122 if (
$object->status != $object::STATUS_DRAFT) {
4126 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
4131 print
'<div class="fichehalfright">';
4132 print
'<div class="underbanner clearboth"></div>';
4134 print
'<table class="border tableforfield centpercent">';
4136 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
4139 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
4140 print
'<td class="nowrap amountcard right" data-dol-field="total_ht">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
4142 print
'<td class="nowrap amountcard right" data-dol-field="multicurrency_total_ht">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
4147 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
4148 print
'<td class="nowrap amountcard right">';
4149 if (
GETPOST(
'calculationrule')) {
4150 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
4152 $calculationrule = (!
getDolGlobalString(
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND_SUPPLIER') ?
'totalofround' :
'roundoftotal');
4154 if ($calculationrule ==
'totalofround') {
4155 $calculationrulenum = 1;
4157 $calculationrulenum = 2;
4160 if (
$object->getVentilExportCompta() == 0) {
4161 $s =
'<span class="hideonsmartphone opacitymedium">' . $langs->trans(
"ReCalculate") .
' </span>';
4162 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=totalofround">' . $langs->trans(
"Mode1") .
'</a>';
4164 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=roundoftotal">' . (
$conf->dol_optimize_smallscreen ?
"2" : $langs->trans(
"Mode2")) .
'</a>';
4165 print
'<div class="inline-block">';
4166 print $form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum) .
'<br>' . $langs->trans(
"CalculationRuleDescSupplier"), 2, 1, img_picto(
'',
'help',
'class="paddingleft paddingright"'),
'', 3,
'', 0,
'recalculate');
4167 print
' ';
4170 print
'<span class="nowraponall" data-dol-field="total_tva">'.price(
$object->total_tva, 1, $langs, 0, -1, -1,
$conf->currency).
'</span>';
4173 print
'<td class="nowraponall amountcard right" data-dol-field="multicurrency_total_tva">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
4177 if ($societe->localtax1_assuj ==
"1") {
4179 print
'<td>' . $langs->transcountry(
"AmountLT1", $societe->country_code) .
'</td>';
4180 print
'<td class="nowrap amountcard right" data-dol-field="total_localtax1">' .
price(
$object->total_localtax1, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
4183 if ($societe->localtax2_assuj ==
"1") {
4185 print
'<td>' . $langs->transcountry(
"AmountLT2", $societe->country_code) .
'</td>';
4186 print
'<td class="nowrap amountcard right" data-dol-field="total_localtax2">' .
price(
$object->total_localtax2, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
4191 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
4192 print
'<td class="nowrap amountcard right" data-dol-field="total_ttc">' .
price(
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
4194 print
'<td class="nowrap amountcard right" data-dol-field="multicurrency_total_ttc">' .
price(
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
4227 if ($societe->localtax1_assuj ==
"1") {
4230 if ($societe->localtax2_assuj ==
"1") {
4234 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
4235 $sql .=
' c.id as payment_type, c.code as payment_code,';
4236 $sql .=
' pf.amount,';
4237 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
4238 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
4239 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
4240 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
4241 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
4242 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
4243 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
4244 $sql .=
' ORDER BY p.datep, p.tms';
4246 $result = $db->query($sql);
4248 $num = $db->num_rows($result);
4251 print
'<div class="div-table-responsive-no-min">';
4252 print
'<table class="noborder paymenttable centpercent" id="paymenttable">';
4253 print
'<tr class="liste_titre">';
4255 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
4256 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
4258 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
4263 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
4268 $objp = $db->fetch_object($result);
4270 $paymentstatic->id = $objp->rowid;
4271 $paymentstatic->datepaye = $db->jdate($objp->dp);
4272 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
4273 $paymentstatic->num_payment = $objp->num_payment;
4275 $paymentstatic->paiementcode = $objp->payment_code;
4276 $paymentstatic->type_code = $objp->payment_code;
4277 $paymentstatic->type_label = $objp->payment_type;
4279 print
'<tr class="oddeven">';
4280 print
'<td class="nowraponall">';
4281 print $paymentstatic->getNomUrl(1);
4283 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
'</td>';
4284 $s = $form->form_modes_reglement(
'', $objp->payment_type,
'none',
'', 1, 0,
'', 1).
' '.$objp->num_payment;
4285 print
'<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).
'">';
4289 $bankaccountstatic->id = $objp->baid;
4290 $bankaccountstatic->ref = $objp->baref;
4291 $bankaccountstatic->label = $objp->baref;
4292 $bankaccountstatic->number = $objp->banumber;
4295 $bankaccountstatic->account_number = $objp->account_number;
4298 $accountingjournal->fetch($objp->fk_accountancy_journal);
4299 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
4302 print
'<td class="right nowraponall">';
4303 if ($objp->baid > 0) {
4304 print $bankaccountstatic->getNomUrl(1,
'transactions');
4309 print
'<td class="center">';
4311 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
4317 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
4319 $totalpaid += $objp->amount;
4323 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
4344 dol_print_error($db);
4349 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4350 print
'<span class="opacitymedium">';
4352 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
4354 print $langs->trans(
'AlreadyPaid');
4359 print
'<td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td>';
4363 $resteapayeraffiche = $resteapayer;
4365 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
4368 $creditnoteamount = 0;
4371 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
4372 $sql .=
" re.description, re.fk_invoice_supplier_source";
4373 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
4374 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
4375 $resql = $db->query($sql);
4377 $num = $db->num_rows($resql);
4381 $obj = $db->fetch_object($resql);
4382 $invoice->fetch($obj->fk_invoice_supplier_source);
4383 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4385 print $langs->trans(
"CreditNote").
' ';
4388 print $langs->trans(
"Deposit").
' ';
4390 print $invoice->getNomUrl(0);
4393 print
'<td class="right">';
4394 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
4395 print img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
4399 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
4403 $creditnoteamount += $obj->amount_ttc;
4406 $depositamount += $obj->amount_ttc;
4410 dol_print_error($db);
4415 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4416 print
'<span class="opacitymedium">';
4417 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
4421 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4423 $resteapayeraffiche = 0;
4424 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4428 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4429 print
'<span class="opacitymedium">';
4430 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
4434 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4437 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4441 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4442 print
'<span class="opacitymedium">';
4443 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
4447 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4449 $resteapayeraffiche = 0;
4450 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4454 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4455 $text = $langs->trans(
"HelpAbandonOther");
4457 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
4459 print
'<span class="opacitymedium">';
4461 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
4465 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4467 $resteapayeraffiche = 0;
4468 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4472 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4473 print
'<span class="opacitymedium">';
4474 print $langs->trans(
"Billed");
4478 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
4482 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4483 print
'<span class="opacitymedium">';
4484 print $langs->trans(
'RemainderToPay');
4485 if ($resteapayeraffiche < 0) {
4486 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4491 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
4496 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4497 print
'<span class="opacitymedium">';
4498 print $langs->trans(
'RemainderToPayMulticurrency');
4499 if ($resteapayeraffiche < 0) {
4500 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4505 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price(
price2num($multicurrency_resteapayer,
'MT'), 0, $langs, 1, -1, -1,
$object->multicurrency_code).
'</td>';
4509 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4512 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4513 print $langs->trans(
'AlreadyPaidBack');
4516 print
'<td class="right">'.price($sign * $totalpaid).
'</td>';
4520 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">'.$langs->trans(
"Billed").
'</td>';
4522 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
4526 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4527 print
'<span class="opacitymedium">';
4528 print $langs->trans(
'RemainderToPayBack');
4529 if ($resteapayeraffiche > 0) {
4530 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4535 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
4540 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4541 print
'<span class="opacitymedium">';
4542 print $langs->trans(
'RemainderToPayBackMulticurrency');
4543 if ($resteapayeraffiche > 0) {
4544 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4549 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>';
4565 print
'<div class="clearboth"></div><br>';
4568 $blocname =
'contacts';
4569 $title = $langs->trans(
'ContactsAddresses');
4570 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4575 $blocname =
'notes';
4576 $title = $langs->trans(
'Notes');
4577 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4584 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
4585 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4586 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
4587 print
'<input type="hidden" name="mode" value="">';
4588 print
'<input type="hidden" name="page_y" value="">';
4589 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
4590 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
4591 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4595 include DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_ajaxrow.tpl.php';
4597 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
4601 print
'<div class="div-table-responsive-no-min">';
4602 print
'<table id="tablelines" class="noborder noshadow centpercent">';
4604 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
4607 $inputalsopricewithtax = 1;
4608 $senderissupplier = 2;
4609 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY')) {
4610 $senderissupplier =
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY');
4615 $object->printObjectLines($action, $societe,
$mysoc, $lineid, 1);
4622 if ($action !=
'editline') {
4625 $parameters = array();
4626 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
4628 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
4630 if (empty($reshook)) {
4644 if ($action !=
'presend') {
4647 print
'<div class="tabsAction">';
4649 $parameters = array();
4650 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
4652 if (empty($reshook)) {
4656 $langs->load(
'subtotals');
4658 $url_button = array();
4660 $url_button[] = array(
4661 'lang' =>
'subtotals',
4663 'perm' => (
bool) $usercancreate,
4664 'label' => $langs->trans(
'AddTitleLine'),
4665 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_title_line'],
true)
4668 $url_button[] = array(
4669 'lang' =>
'subtotals',
4671 'perm' => (
bool) $usercancreate,
4672 'label' => $langs->trans(
'AddSubtotalLine'),
4673 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_subtotal_line'],
true)
4676 $url_button[] = array(
4677 'lang' =>
'subtotals',
4679 'perm' => (
bool) $usercancreate,
4680 'label' => $langs->trans(
'AddTextLine'),
4681 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_text_line'],
true)
4684 print dolGetButtonAction(
'', $langs->trans(
'SubTotal'),
'default', $url_button,
'',
true);
4689 $ventilExportCompta =
$object->getVentilExportCompta();
4691 if ($ventilExportCompta == 0) {
4692 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=edit&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
4694 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
4699 $result = $discount->fetch(0, 0,
$object->id);
4706 if (!$objectidnext &&
$object->close_code !=
'replaced' && $usercancreate) {
4707 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
4709 if ($usercancreate) {
4710 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
4712 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
4722 if ($usercanvalidate) {
4723 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken().
'"';
4724 print
'>'.$langs->trans(
'Validate').
'</a>';
4726 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
4727 print
'>'.$langs->trans(
'Validate').
'</a>';
4733 if (empty($user->socid)) {
4736 print dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' =>
$object->id,
'action' =>
'presend',
'mode' =>
'init'],
true).
'#formmailbeforetitle',
'');
4738 print dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false);
4745 $langs->load(
"withdrawals");
4746 if ($resteapayer > 0) {
4747 if ($usercancreatecreditransfer) {
4748 if (!$objectidnext &&
$object->close_code !=
'replaced') {
4749 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>';
4751 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeBankTransferOrder').
'</span>';
4763 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>';
4770 if ($resteapayer == 0) {
4771 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
4772 } elseif ($usercancreate) {
4773 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>';
4779 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
4783 && (
getDolGlobalString(
'SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') ||
$object->getSommePaiement() == 0)
4785 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>';
4789 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
4800 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaid').
'</a>';
4805 if ($totalpaid > 0 || $totalcreditnotes > 0) {
4807 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
4810 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=canceled&token='.
newToken().
'">'.$langs->trans(
'ClassifyCanceled').
'</a>';
4822 if (!$objectidnext) {
4823 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>';
4828 if ($action !=
'edit' && $usercancreate) {
4829 print dolGetButtonAction($langs->trans(
'ToClone'), $langs->trans(
'ToClone'),
'clone', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=clone&socid='.
$object->socid.
'&token='.
newToken(),
'',
true, array(
'attr' => array(
'class' =>
'reposition')));
4834 if (!$objectidnext && count(
$object->lines) > 0) {
4835 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.
$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
4840 if ($action !=
'confirm_edit' && $usercandelete) {
4841 $isErasable =
$object->is_erasable();
4843 $enableDelete =
false;
4845 $params = (empty(
$conf->use_javascript_ajax) ? array() : array(
'attr' => array(
'class' =>
'reposition')));
4847 if ($isErasable == -4) {
4848 $htmltooltip = $langs->trans(
"DisabledBecausePayments");
4849 } elseif ($isErasable == -3) {
4850 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastSituationInvoice");
4851 } elseif ($isErasable == -2) {
4852 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastInvoice");
4853 } elseif ($isErasable == -1) {
4854 $htmltooltip = $langs->trans(
"DisabledBecauseDispatchedInBookkeeping");
4855 } elseif ($isErasable <= 0) {
4856 $htmltooltip = $langs->trans(
"DisabledBecauseNotErasable");
4858 $enableDelete =
true;
4861 print dolGetButtonAction($htmltooltip, $langs->trans(
"Delete"),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken(), (
string)
$object->id, $enableDelete, array(
'attr' => array(
'class' =>
'reposition')));
4865 if ($action !=
'confirm_edit') {
4866 print
'<div class="fichecenter"><div class="fichehalfleft">';
4872 $subdir =
get_exdir(
$object->id, 2, 0, 0, $object,
'invoice_supplier').$ref;
4874 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.
$object->id;
4875 $genallowed = $usercanread;
4876 $delallowed = $usercancreate;
4880 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, (
int) $genallowed, (
int) $delallowed, $modelpdf, $genifempty, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
4881 $somethingshown = $formfile->numoffiles;
4884 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice_supplier'), 1);
4885 $linktoelem = $tmparray[
'linktoelem'];
4886 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
4887 print $htmltoenteralink;
4889 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
4891 print
'</div><div class="fichehalfright">';
4894 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
4896 $somethingshown = $formactions->showactions($object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
4898 print
'</div></div>';
4904 if (
GETPOST(
'modelselected')) {
4905 $action =
'presend';
4909 $modelmail =
'invoice_supplier_send';
4910 $defaulttopic =
'SendBillRef';
4912 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
4913 $trackid =
'sinv'.$object->id;
4915 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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage bank accounts.
Class to manage accounting journals.
const TYPE_PROFORMA
Proforma invoice.
const TYPE_SITUATION
Situation invoice.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_STANDARD
Standard invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const STATUS_CLOSED
Classified paid.
Class to manage invoice templates.
Class to manage payments for supplier invoices.
Class ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage line invoices.
Class to manage translations.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
$date_start
Variables from include:
facturefourn_prepare_head(FactureFournisseur $object)
Prepare array with list of tabs.
dol_now($mode='gmt')
Return date for now.
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0, $currencycode='')
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).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.
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.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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)
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.