42require
'../../main.inc.php';
51require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_invoice/modules_facturefournisseur.php';
55require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
56require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture-rec.class.php';
57require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
58require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
59require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
60require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
61require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
62require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
64 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
65 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
68 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
69 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
73 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
76 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
79$langs->loadLangs(array(
'bills',
'compta',
'suppliers',
'companies',
'products',
'banks',
'admin'));
81 $langs->load(
'incoterm');
86$action =
GETPOST(
'action',
'aZ09');
89$cancel =
GETPOST(
'cancel',
'alpha');
90$backtopage =
GETPOST(
'backtopage',
'alpha');
91$backtopageforcancel =
'';
95$origin =
GETPOST(
'origin',
'alpha');
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);
122 $ret =
$object->fetch_thirdparty();
124 dol_print_error($db,
$object->error);
130if (!empty($user->socid)) {
131 $socid = $user->socid;
135$result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture',
'fk_soc',
'rowid', $isdraft);
138$usercanread = ($user->hasRight(
"fournisseur",
"facture",
"lire") || $user->hasRight(
"supplier_invoice",
"lire"));
139$usercancreate = ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"));
140$usercandelete = (($user->hasRight(
"fournisseur",
"facture",
"supprimer") || $user->hasRight(
"supplier_invoice",
"supprimer")) || ($usercancreate &&
$object->is_erasable() == 1));
141$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
144$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"validate")));
145$usercansend = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"send"));
146$usercancreatecreditransfer = $user->hasRight(
'paymentbybanktransfer',
'create');
149$permissionnote = $usercancreate;
150$permissiondellink = $usercancreate;
151$permissiontoedit = $usercancreate;
152$permissiontoadd = $usercancreate;
153$permissiontodelete = $usercandelete;
154$permissiontoeditextra = $permissiontoadd;
155if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
157 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
168$parameters = array(
'socid' => $socid);
169$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
171 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
174if (empty($reshook)) {
175 $backurlforlist =
dolBuildUrl(DOL_URL_ROOT.
'/fourn/facture/list.php');
177 if (empty($backtopage) || ($cancel && empty($id))) {
178 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
179 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
180 $backtopage = $backurlforlist;
182 $backtopage =
dolBuildUrl(DOL_URL_ROOT.
'/fourn/facture/card.php', [
'id' => ((!empty($id) && $id > 0) ? $id :
'__ID__')]);
188 if (!empty($backtopageforcancel)) {
189 header(
"Location: ".$backtopageforcancel);
191 } elseif (!empty($backtopage)) {
192 header(
"Location: ".$backtopage);
198 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
200 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
202 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
205 if (
GETPOST(
'linkedOrder') && empty($cancel) && $id > 0 && $permissiontoadd) {
208 $result =
$object->add_object_linked(
'order_supplier',
GETPOSTINT(
'linkedOrder'));
212 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
214 '@phan-var-force FactureFournisseur $objectutil';
216 if (
GETPOST(
'newsupplierref',
'alphanohtml')) {
217 $objectutil->ref_supplier =
GETPOST(
'newsupplierref',
'alphanohtml');
221 $result = $objectutil->createFromClone($user, $id);
223 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
226 $langs->load(
"errors");
227 setEventMessages($objectutil->error, $objectutil->errors,
'errors');
230 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
231 $idwarehouse =
GETPOST(
'idwarehouse');
236 $qualified_for_stock_change = 0;
238 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
240 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
245 $langs->load(
"stocks");
246 if (!$idwarehouse || $idwarehouse == -1) {
248 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
256 $result =
$object->validate($user,
'', $idwarehouse);
263 $categories =
GETPOST(
'categories',
'array:int');
264 if (method_exists($object,
'setCategories')) {
265 $object->setCategories($categories);
273 $outputlangs = $langs;
276 $newlang =
GETPOST(
'lang_id',
'aZ09');
279 $newlang =
$object->thirdparty->default_lang;
281 if (!empty($newlang)) {
283 $outputlangs->setDefaultLang($newlang);
288 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
295 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $permissiontodelete) {
299 $isErasable =
$object->is_erasable();
301 if ($usercandelete && $isErasable > 0) {
302 $revertstock =
GETPOST(
'revertstock');
307 $qualified_for_stock_change = 0;
309 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
311 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
316 $langs->load(
"stocks");
317 if (!$idwarehouse || $idwarehouse == -1) {
319 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
322 $result =
$object->setDraft($user, $idwarehouse);
332 $result =
$object->delete($user);
334 header(
'Location: list.php?restore_lastsearch_values=1');
341 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
343 $result =
$object->deleteLine($lineid);
363 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
370 } elseif ($action ==
'confirm_delete_subtotalline' && $confirm ==
'yes' && $usercancreate) {
375 $result =
$object->deleteSubtotalLine($langs, $lineid, (
bool)
GETPOST(
'deletecorrespondingsubtotalline'));
378 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
384 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
387 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
388 $discount->unlink_invoice();
390 if (
$object->paye == 1 && (
float)
$object->getRemainToPay() > 0) {
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) {
431 if (
$object->update($user) < 0) {
435 $outputlangs = $langs;
438 $newlang =
GETPOST(
'lang_id',
'aZ09');
441 $newlang =
$object->thirdparty->default_lang;
443 if (!empty($newlang)) {
445 $outputlangs->setDefaultLang($newlang);
449 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
455 if ($action ==
'setconditions' && $usercancreate) {
457 $object->cond_reglement_code = 0;
458 $object->cond_reglement_id = 0;
473 $new_date_echeance =
$object->calculate_date_lim_reglement();
474 if ($new_date_echeance) {
475 $object->date_echeance = $new_date_echeance;
480 $result =
$object->update($user);
492 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
495 } elseif ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
498 } elseif ($action ==
'setmode' && $usercancreate) {
501 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
503 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
504 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
507 } elseif ($action ==
'setbankaccount' && $usercancreate) {
510 } elseif ($action ==
'setvatreversecharge' && $usercancreate) {
512 $vatreversecharge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
513 $result =
$object->setVATReverseCharge($vatreversecharge);
516 if ($action ==
'settransportmode' && $usercancreate) {
519 } elseif ($action ==
'setlabel' && $usercancreate) {
523 $result =
$object->update($user);
527 } elseif ($action ==
'setdatef' && $usercancreate) {
531 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
533 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
540 $date_echence_calc =
$object->calculate_date_lim_reglement();
541 if (!empty(
$object->date_echeance)) {
542 $object->date_echeance = $date_echence_calc;
548 $result =
$object->update($user);
552 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
556 $object->date_pointoftax = $date_pointoftax;
558 $result =
$object->update($user);
561 $action =
'editdate_pointoftax';
563 } elseif ($action ==
'setdate_lim_reglement' && $usercancreate) {
568 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
570 $result =
$object->update($user);
574 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
584 $usemccompare =
false;
586 if ($discount->fetch($idremise) > 0) {
590 && !empty($discount->multicurrency_code) && !empty(
$object->multicurrency_code)
591 && $discount->multicurrency_code ==
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency);
592 $maxtoabsorb = (float)
price2num($usemccompare ?
$object->getRemainToPay(1) :
$object->getRemainToPay(0),
'MT');
593 $discountamountforcompare = (float)
price2num($usemccompare ? $discount->multicurrency_amount_ttc : $discount->amount_ttc,
'MT');
594 if ($discountamountforcompare > $maxtoabsorb) {
595 if ($maxtoabsorb <= 0) {
598 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
601 $depositeur = (float) $discount->amount_ttc;
602 $depositdev = (float) $discount->multicurrency_amount_ttc;
603 if ($usemccompare && $depositdev != 0) {
604 $applydev = $maxtoabsorb;
608 $creditrate = !empty($discount->multicurrency_tx) ? (float) $discount->multicurrency_tx : 0;
609 if ($creditrate > 0) {
610 $applyeur = (float)
price2num($applydev / $creditrate,
'MT');
612 $applyeur = (float)
price2num($applydev / $depositdev * $depositeur,
'MT');
615 $applyeur = $maxtoabsorb;
616 $applydev = ($depositeur != 0 ? (float)
price2num($applyeur / $depositeur * $depositdev,
'MT') : 0);
618 $splitparts = $discount->splitAmount($applyeur, (
float)
price2num($depositeur - $applyeur,
'MT'));
619 $applypart = $splitparts[0];
620 $remainpart = $splitparts[1];
622 if (!empty($discount->multicurrency_code) && $depositdev != 0) {
624 $remaindev = (float)
price2num($depositdev - $applydev,
'MT');
625 $applypart->multicurrency_amount_ttc = $applydev;
626 $applypart->multicurrency_amount_ht =
price2num($applydev / (1 + (
float) $applypart->tva_tx / 100),
'MT');
627 $applypart->multicurrency_amount_tva =
price2num($applydev - (
float) $applypart->multicurrency_amount_ht);
628 $remainpart->multicurrency_amount_ttc = $remaindev;
629 $remainpart->multicurrency_amount_ht =
price2num($remaindev / (1 + (
float) $remainpart->tva_tx / 100),
'MT');
630 $remainpart->multicurrency_amount_tva =
price2num($remaindev - (
float) $remainpart->multicurrency_amount_ht);
632 $discount->fk_facture_source = 0;
633 $discount->fk_invoice_supplier_source = 0;
634 $resdelete = $discount->delete($user);
635 $newidapply = $applypart->create($user);
636 $newidremain = $remainpart->create($user);
637 if ($resdelete > 0 && $newidapply > 0 && $newidremain > 0) {
638 $idremise = $newidapply;
639 $splitappliedmsg =
price($applyeur, 0, $langs, 1, -1, -1,
$conf->currency);
640 $splitremainmsg =
price((
float)
price2num($depositeur - $applyeur,
'MT'), 0, $langs, 1, -1, -1,
$conf->currency);
641 if (!empty($discount->multicurrency_code) && $depositdev != 0) {
642 $splitappliedmsg .=
' / '.price($applydev, 0, $langs, 1, -1, -1, $discount->multicurrency_code);
643 $splitremainmsg .=
' / '.price($remaindev, 0, $langs, 1, -1, -1, $discount->multicurrency_code);
645 setEventMessages($langs->trans(
'DepositSplitAutomaticallyApplied', $splitappliedmsg, $splitremainmsg),
null,
'warnings');
648 setEventMessages($langs->trans(
"Error"),
null,
'errors');
655 $result =
$object->insert_discount($idremise);
659 if ($result > 0 && $usemccompare) {
666 $foreigncredits = 0.0;
667 $companycredits = 0.0;
668 foreach (
$object->lines as $creditline) {
669 if (empty($creditline->fk_remise_except)) {
670 $foreigngoods += (float) $creditline->multicurrency_total_ttc;
672 $foreigncredits -= (float) $creditline->multicurrency_total_ttc;
673 $companycredits -= (float) $creditline->total_ttc;
676 $targetcompany = ((float)
$object->multicurrency_tx > 0 ? ($foreigngoods - $foreigncredits) / (float)
$object->multicurrency_tx : 0) + $companycredits;
677 if ($foreigngoods > 0 && $targetcompany > 0) {
678 $neweffectivetx = (float)
price2num($foreigngoods / $targetcompany,
'CR');
679 if (abs($neweffectivetx - (
float)
$object->multicurrency_tx) >= 0.00000001) {
680 $resrate =
$object->setMulticurrencyRate($neweffectivetx, 1);
685 setEventMessages($langs->trans(
'InvoiceRateRealigned',
price2num($neweffectivetx,
'CR')),
null,
'mesgs');
692 dol_print_error($db,
$object->error);
697 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
699 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
703 $remaintopay =
$object->getRemainToPay(0);
707 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
711 $result = $discount->link_to_invoice(0, $id);
714 setEventMessages($discount->error, $discount->errors,
'errors');
718 $newremaintopay =
$object->getRemainToPay(0);
719 if ($newremaintopay == 0) {
730 $outputlangs = $langs;
733 $newlang =
GETPOST(
'lang_id',
'aZ09');
736 $newlang =
$object->thirdparty->default_lang;
738 if (!empty($newlang)) {
740 $outputlangs->setDefaultLang($newlang);
744 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
749 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
752 $langs->load(
'subtotals');
754 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
755 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
757 $subtotal_options = array();
759 foreach (FactureFournisseur::$TITLE_OPTIONS as $option) {
760 $value =
GETPOST($option,
'alphanohtml');
762 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
767 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
778 $outputlangs = $langs;
779 $newlang =
GETPOST(
'lang_id',
'alpha');
781 $newlang =
$object->thirdparty->default_lang;
783 if (!empty($newlang)) {
785 $outputlangs->setDefaultLang($newlang);
788 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
793 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
795 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
798 $langs->load(
'subtotals');
800 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
801 foreach (
$object->lines as $line) {
802 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
804 $depth = -$line->qty;
808 $subtotal_options = array();
810 foreach (FactureFournisseur::$SUBTOTAL_OPTIONS as $option) {
811 $value =
GETPOST($option,
'alphanohtml');
813 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
818 if (isset($desc) && isset($depth)) {
819 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
822 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
831 $outputlangs = $langs;
832 $newlang =
GETPOST(
'lang_id',
'alpha');
834 $newlang =
$object->thirdparty->default_lang;
836 if (!empty($newlang)) {
838 $outputlangs->setDefaultLang($newlang);
841 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
846 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
848 } elseif ($action ==
'confirm_addtextline' && $usercancreate) {
851 $langs->load(
'subtotals');
853 $desc =
GETPOST(
'subtotaltextcontent',
'restricthtml');
856 $result =
$object->addSubtotalLine($langs, $desc, 0, array());
867 $outputlangs = $langs;
868 $newlang =
GETPOST(
'lang_id',
'alpha');
870 $newlang =
$object->thirdparty->default_lang;
872 if (!empty($newlang)) {
874 $outputlangs->setDefaultLang($newlang);
877 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
882 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
884 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
892 $result = $discountcheck->fetch(0, 0,
$object->id);
904 $amount_ht = $amount_tva = $amount_ttc = array();
905 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
909 foreach (
$object->lines as $line) {
910 if ($line->product_type < 9 && $line->total_ht != 0) {
911 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
913 $amount_ht[$keyforvatrate] += $line->total_ht;
914 $amount_tva[$keyforvatrate] += $line->total_tva;
915 $amount_ttc[$keyforvatrate] += $line->total_ttc;
916 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
917 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
918 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
922 '@phan-var-force array<string,float> $amount_ht
923 @phan-var-force array<string,float> $amount_tva
924 @phan-var-force array<string,float> $amount_ttc
925 @phan-var-force array<string,float> $multicurrency_amount_ht
926 @phan-var-force array<string,float> $multicurrency_amount_tva
927 @phan-var-force array<string,float> $multicurrency_amount_ttc';
931 $alreadypaid =
$object->getSommePaiement();
932 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
933 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
934 foreach ($amount_ht as $vatrate => $val) {
935 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
936 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
937 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
938 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
939 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
940 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
949 $discount->description =
'(CREDIT_NOTE)';
951 $discount->description =
'(DEPOSIT)';
953 $discount->description =
'(EXCESS PAID)';
955 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
957 $discount->discount_type = 1;
958 $discount->fk_soc =
$object->socid;
959 $discount->socid =
$object->socid;
960 $discount->fk_invoice_supplier_source =
$object->id;
968 $sql =
'SELECT SUM(pf.amount) as total_paiements';
969 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'paiementfourn as p';
970 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN ('.
getEntity(
'c_paiement').
')';
971 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
972 $sql .=
' AND pf.fk_paiementfourn = p.rowid';
973 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
975 $resql = $db->query($sql);
977 dol_print_error($db);
980 $res = $db->fetch_object($resql);
981 $total_paiements = $res->total_paiements;
984 $total_creditnote_and_deposit = 0;
985 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
986 $sql .=
" re.description, re.fk_invoice_supplier_source";
987 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
988 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
989 $resql = $db->query($sql);
990 if (!empty($resql)) {
991 while ($obj = $db->fetch_object($resql)) {
992 $total_creditnote_and_deposit += $obj->amount_ttc;
995 dol_print_error($db);
998 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
999 $discount->amount_tva = 0;
1000 $discount->tva_tx = 0;
1001 $discount->vat_src_code =
'';
1004 $discount->multicurrency_code =
$object->multicurrency_code;
1005 $discount->multicurrency_tx =
$object->multicurrency_tx;
1006 $discount->multicurrency_total_ht = $discount->multicurrency_total_ttc = (float)
price2num((
float) $discount->amount_ttc * (float)
$object->multicurrency_tx,
'MT');
1007 $discount->multicurrency_total_tva = 0;
1009 $discount->multicurrency_amount_ht = $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
1010 $discount->multicurrency_amount_tva = 0;
1012 $result = $discount->create($user);
1018 foreach ($amount_ht as $tva_tx => $xxx) {
1019 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
1020 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
1021 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
1023 $discount->multicurrency_code =
$object->multicurrency_code;
1024 $discount->multicurrency_tx =
$object->multicurrency_tx;
1025 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1026 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1027 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1029 $discount->multicurrency_amount_ht = abs((
float) $discount->multicurrency_total_ht);
1030 $discount->multicurrency_amount_tva = abs((
float) $discount->multicurrency_total_tva);
1031 $discount->multicurrency_amount_ttc = abs((
float) $discount->multicurrency_total_ttc);
1036 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
1037 $vat_src_code = $reg[1];
1038 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
1041 $discount->tva_tx = abs((
float) $tva_tx);
1042 $discount->vat_src_code = $vat_src_code;
1044 $result = $discount->create($user);
1052 if (empty($error)) {
1055 $result =
$object->setPaid($user);
1066 setEventMessages($discount->error, $discount->errors,
'errors');
1070 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate) {
1075 $result = $paiementfourn->fetch(
GETPOSTINT(
'paiement_id'));
1077 $result = $paiementfourn->delete($user);
1079 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1084 setEventMessages($paiementfourn->error, $paiementfourn->errors,
'errors');
1087 } elseif ($action ==
'add' && $usercancreate) {
1092 $selectedLines =
GETPOST(
'toselect',
'array:int');
1100 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1114 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1119 if (empty($dateinvoice)) {
1120 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1126 setEventMessages($langs->trans(
"ErrorDateIsInFuture"),
null,
'errors');
1132 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1146 $object->date_pointoftax = $date_pointoftax;
1147 $object->date_echeance = $datedue;
1153 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1155 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1157 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1158 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1177 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1179 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1182 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1187 if (empty($dateinvoice)) {
1188 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1194 setEventMessages($langs->trans(
"ErrorDateIsInFuture"),
null,
'errors');
1198 if (!
GETPOST(
'ref_supplier')) {
1199 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
1207 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1222 $object->date_pointoftax = $date_pointoftax;
1223 $object->date_echeance = $datedue;
1229 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1230 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1232 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1233 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1238 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1247 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1249 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1250 $fk_parent_line = 0;
1252 foreach ($facture_source->lines as $line) {
1254 if (method_exists($line,
'fetch_optionals')) {
1255 $line->fetch_optionals();
1259 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1260 $fk_parent_line = 0;
1263 $line->fk_facture_fourn =
$object->id;
1264 $line->fk_parent_line = $fk_parent_line;
1266 $line->subprice = -$line->subprice;
1267 $line->pa_ht = -((float) $line->pa_ht);
1268 $line->total_ht = -$line->total_ht;
1269 $line->total_tva = -$line->total_tva;
1270 $line->total_ttc = -$line->total_ttc;
1271 $line->total_localtax1 = -$line->total_localtax1;
1272 $line->total_localtax2 = -$line->total_localtax2;
1273 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1274 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1275 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1277 $result = $line->insert();
1282 if ($result > 0 && $line->product_type == 9) {
1283 $fk_parent_line = $result;
1291 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 &&
$id > 0) {
1293 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1294 $totalpaid = $facture_source->getSommePaiement();
1295 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1296 $totaldeposits = $facture_source->getSumDepositsUsed();
1297 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1298 $desc = $langs->trans(
'invoiceAvoirLineWithPaymentRestAmount');
1301 $retAddLine =
$object->addline($desc, -$remain_to_pay, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
'TTC');
1303 if ($retAddLine < 0) {
1310 if (!empty(
$object->fk_facture_source) && $id > 0) {
1312 if ($facture_source_link->fetch(
$object->fk_facture_source) > 0) {
1313 $facture_source_link->fetchObjectLinked();
1314 if (!empty($facture_source_link->linkedObjectsIds)) {
1315 foreach ($facture_source_link->linkedObjectsIds as $sourcetype => $TIds) {
1316 $object->add_object_linked($sourcetype, current($TIds));
1324 if (empty($dateinvoice)) {
1326 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1330 setEventMessages($langs->trans(
"ErrorDateIsInFuture"),
null,
'errors');
1336 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1346 $object->date_pointoftax = $date_pointoftax;
1347 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1348 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1357 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1358 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1362 $object->fac_rec = $fac_recid;
1364 $fac_rec->fetch(
$object->fac_rec);
1365 $fac_rec->fetch_lines();
1366 $object->lines = $fac_rec->lines;
1373 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1378 if (empty($dateinvoice)) {
1379 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1385 setEventMessages($langs->trans(
"ErrorDateIsInFuture"),
null,
'errors');
1389 if (!
GETPOST(
'ref_supplier')) {
1390 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
1398 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1415 $object->date_pointoftax = $date_pointoftax;
1416 $object->date_echeance = $datedue;
1422 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1423 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1425 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1426 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1431 if (empty(
$object->date_echeance)) {
1432 $object->date_echeance =
$object->calculate_date_lim_reglement();
1438 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
1440 $element = $subelement =
GETPOST(
'origin',
'alpha');
1448 if ($element ==
'order') {
1449 $element = $subelement =
'commande';
1451 if ($element ==
'propal') {
1452 $element =
'comm/propal';
1453 $subelement =
'propal';
1455 if ($element ==
'contract') {
1456 $element = $subelement =
'contrat';
1458 if ($element ==
'order_supplier') {
1460 $subelement =
'fournisseur.commande';
1462 if ($element ==
'project') {
1463 $element =
'projet';
1471 $classname = ucfirst($subelement);
1472 if ($classname ==
'Fournisseur.commande') {
1473 $classname =
'CommandeFournisseur';
1475 $objectsrc =
new $classname($db);
1476 $objectsrc->fetch($originid);
1477 $objectsrc->fetch_thirdparty();
1479 if (!empty(
$object->origin_type) && !empty(
$object->origin_id)) {
1484 if (
$object->origin_type ==
'reception') {
1485 $objectsrc->fetchObjectLinked();
1487 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1488 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1489 $object->linkedObjectsIds[
'order_supplier'][-1] = $value;
1499 $classname = ucfirst($subelement);
1500 if ($classname ==
'Fournisseur.commande') {
1501 $classname =
'CommandeFournisseur';
1503 $srcobject =
new $classname($db);
1505 $result = $srcobject->fetch(
GETPOSTINT(
'originid'));
1508 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1513 $amountdeposit = array();
1515 if ($typeamount ==
'amount') {
1516 $amount = $valuedeposit;
1518 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1521 $TTotalByTva = array();
1522 foreach ($srcobject->lines as &$line) {
1523 if (!empty($line->special_code)) {
1526 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1528 '@phan-var-force array<string,float> $TTotalByTva';
1530 $amount_ttc_diff = 0.;
1531 foreach ($TTotalByTva as $tva => &$total) {
1532 $coef = $total / $srcobject->total_ttc;
1533 $am = $amount * $coef;
1534 $amount_ttc_diff += $am;
1535 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1538 if ($typeamount ==
'amount') {
1539 $amountdeposit[0] = $valuedeposit;
1540 } elseif ($typeamount ==
'variable') {
1543 $lines = $srcobject->lines;
1544 $numlines = count($lines);
1545 for ($i = 0; $i < $numlines; $i++) {
1547 if (empty($lines[$i]->qty)) {
1550 if (!empty($lines[$i]->special_code)) {
1554 $totalamount += $lines[$i]->total_ht;
1555 $tva_tx = $lines[$i]->tva_tx;
1556 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1560 if ($totalamount == 0) {
1561 $amountdeposit[0] = 0;
1564 setEventMessages($srcobject->error, $srcobject->errors,
'errors');
1566 $amountdeposit[0] = 0;
1570 $amount_ttc_diff = array_key_exists(0, $amountdeposit) ? $amountdeposit[0] : 0;
1573 foreach ($amountdeposit as $tva => $amount) {
1574 if (empty($amount)) {
1579 'amount' =>
'FixAmount',
1580 'variable' =>
'VarAmount'
1582 $descline =
'(DEPOSIT)';
1584 if ($typeamount ==
'amount') {
1585 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1586 } elseif ($typeamount ==
'variable') {
1587 $descline .=
' ('.$valuedeposit.
'%)';
1590 $descline .=
' - '.$srcobject->ref;
1620 $diff =
$object->total_ttc - $amount_ttc_diff;
1624 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1630 $object->lines[0]->localtax1_tx,
1631 $object->lines[0]->localtax2_tx,
1633 $object->lines[0]->fk_product,
1636 $object->lines[0]->product_type,
1637 $object->lines[0]->remise_percent,
1639 $object->lines[0]->date_start,
1648 } elseif ($result > 0) {
1649 $lines = $srcobject->lines;
1650 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1651 $srcobject->fetch_lines();
1652 $lines = $srcobject->lines;
1655 $num = count($lines);
1656 for ($i = 0; $i < $num; $i++) {
1657 if (!in_array($lines[$i]->
id, $selectedLines)) {
1661 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->product_label);
1662 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1665 if (method_exists($lines[$i],
'fetch_optionals')) {
1666 $lines[$i]->fetch_optionals();
1672 if ($lines[$i]->date_debut_reel) {
1675 if ($lines[$i]->date_start) {
1678 $date_end = $lines[$i]->date_fin_prevue;
1679 if ($lines[$i]->date_fin_reel) {
1680 $date_end = $lines[$i]->date_fin_reel;
1682 if ($lines[$i]->date_end) {
1683 $date_end = $lines[$i]->date_end;
1686 $tva_tx = $lines[$i]->tva_tx;
1688 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
1689 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1693 $object->special_code = $lines[$i]->special_code;
1697 $line_price_base_type = $lines[$i]->getPriceBaseType();
1698 if ($line_price_base_type ===
'TTC') {
1700 $pu = (float) $lines[$i]->subprice_ttc;
1702 } elseif (
$object->multicurrency_code !=
$conf->currency ||
$object->multicurrency_tx != 1) {
1704 $pu_currency = $lines[$i]->multicurrency_subprice;
1706 $pu = $lines[$i]->subprice;
1715 $lines[$i]->localtax1_tx,
1716 $lines[$i]->localtax2_tx,
1718 $lines[$i]->fk_product,
1719 $lines[$i]->remise_percent,
1723 $lines[$i]->info_bits,
1724 $line_price_base_type,
1728 $lines[$i]->array_options,
1729 $lines[$i]->fk_unit,
1732 $lines[$i]->ref_supplier,
1733 $lines[$i]->special_code
1750 $parameters = array(
'objFrom' => $srcobject);
1751 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1754 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
1761 } elseif (!$error) {
1771 $langs->load(
"errors");
1781 $outputlangs = $langs;
1782 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1789 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1792 } elseif ($action ==
'updateline' && $usercancreate) {
1796 if (!
$object->fetch($id) > 0) {
1797 dol_print_error($db);
1802 $tva_tx = str_replace(
'*',
'', $tva_tx);
1811 $price_base_type =
'HT';
1812 if (empty($pu_ht) && !empty($pu_ttc)) {
1814 $price_base_type =
'TTC';
1815 } elseif (!empty($pu_ht) && !empty($pu_ttc)) {
1816 foreach (
$object->lines as $line_obj) {
1819 if ($line_obj->wasEnteredIncludingTax()) {
1821 $price_base_type =
'TTC';
1828 if (
GETPOST(
'productid') > 0) {
1830 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY') == 1) {
1832 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1838 $label =
$prod->description;
1839 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1840 $label =
GETPOST(
'product_desc',
'restricthtml');
1843 $type =
$prod->type;
1845 $label =
GETPOST(
'product_desc',
'restricthtml');
1854 if (preg_match(
'/\*/', $tva_tx)) {
1859 $tva_tx = str_replace(
'*',
'', $tva_tx);
1867 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1868 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1870 if (is_array($extralabelsline)) {
1871 foreach ($extralabelsline as $key => $value) {
1872 unset($_POST[
"options_".$key]);
1876 $result =
$object->updateline(
1888 (
float) $remise_percent,
1898 unset($_POST[
'label']);
1899 unset($_POST[
'fourn_ref']);
1900 unset($_POST[
'date_starthour']);
1901 unset($_POST[
'date_startmin']);
1902 unset($_POST[
'date_startsec']);
1903 unset($_POST[
'date_startday']);
1904 unset($_POST[
'date_startmonth']);
1905 unset($_POST[
'date_startyear']);
1906 unset($_POST[
'date_endhour']);
1907 unset($_POST[
'date_endmin']);
1908 unset($_POST[
'date_endsec']);
1909 unset($_POST[
'date_endday']);
1910 unset($_POST[
'date_endmonth']);
1911 unset($_POST[
'date_endyear']);
1912 unset($_POST[
'price_ttc']);
1913 unset($_POST[
'price_ht']);
1920 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
1924 foreach (
$object->lines as $line) {
1925 if ($line->product_type == 1) {
1927 $line_price_base_type = $line->getPriceBaseType();
1928 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
1929 $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);
1932 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
1934 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
1935 $remise_percent = (float) str_replace(
'*',
'', $remise_percent);
1936 foreach (
$object->lines as $line) {
1938 $line_price_base_type = $line->getPriceBaseType();
1939 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
1940 $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);
1942 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !=
'' && $usercancreate) {
1944 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1945 $vat_rate = str_replace(
'*',
'', $vat_rate);
1948 foreach (
$object->lines as $line) {
1950 $line_price_base_type = $line->getPriceBaseType();
1951 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
1952 $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);
1954 } elseif ($action ==
'addline' && $usercancreate) {
1960 dol_print_error($db,
$object->error);
1963 $ret =
$object->fetch_thirdparty();
1965 $langs->load(
'errors');
1974 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1975 if ($prod_entry_mode ==
'free') {
1982 $price_ht_devise =
'';
1984 $price_ttc_devise =
'';
1986 if (
GETPOST(
'price_ht') !==
'') {
1989 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
1992 if (
GETPOST(
'price_ttc') !==
'') {
1995 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
1996 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2004 if (empty($remise_percent)) {
2005 $remise_percent = 0;
2009 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2010 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2012 if (is_array($extralabelsline)) {
2014 foreach ($extralabelsline as $key => $value) {
2015 unset($_POST[
"options_".$key]);
2019 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
2020 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2023 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOSTINT(
'type') < 0) {
2024 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2029 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1')
2030 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
2031 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
2032 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
2033 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
2034 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
2035 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) {
2036 $langs->load(
"errors");
2037 if (
$object->type == $object::TYPE_DEPOSIT) {
2039 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2041 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPrice"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2046 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
2047 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
2051 if ($prod_entry_mode ==
'free' && (!
GETPOST(
'idprodfournprice') ||
GETPOST(
'idprodfournprice') ==
'-1') && !
GETPOST(
'dp_desc')) {
2052 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2055 if (!
GETPOST(
'qty',
'alpha')) {
2056 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2060 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2061 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
2065 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2066 $idprod = $res->fk_product_child;
2068 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2074 if ($prod_entry_mode !=
'free' && empty($error)) {
2078 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
2083 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
2084 $idprod = (int) $reg[1];
2085 $res = $productsupplier->fetch($idprod);
2088 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
2090 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
2091 if ($productsupplier->fourn_socid != $socid) {
2092 $productsupplier->ref_supplier =
'';
2095 $fksoctosearch =
$object->thirdparty->id;
2096 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
2098 } elseif (
GETPOSTINT(
'idprodfournprice') > 0) {
2099 $qtytosearch = (float) $qty;
2101 $idprod = $productsupplier->get_buyprice(
GETPOSTINT(
'idprodfournprice'), $qtytosearch);
2102 $res = $productsupplier->fetch($idprod);
2106 $label = $productsupplier->label;
2109 $outputlangs = $langs;
2111 if (
GETPOST(
'lang_id',
'aZ09')) {
2112 $newlang =
GETPOST(
'lang_id',
'aZ09');
2114 if (empty($newlang)) {
2115 $newlang =
$object->thirdparty->default_lang;
2117 if (!empty($newlang)) {
2119 $outputlangs->setDefaultLang($newlang);
2121 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
2123 $desc = $productsupplier->description;
2126 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
2127 $desc = $productsupplier->desc_supplier;
2138 $ref_supplier = $productsupplier->ref_supplier;
2142 $tmpidprodfournprice =
GETPOST(
'idprodfournprice',
'alpha');
2143 if (is_numeric($tmpidprodfournprice) && (
int) $tmpidprodfournprice > 0) {
2144 $tmpidprodfournprice = (int) $tmpidprodfournprice;
2146 $tmpidprodfournprice = 0;
2152 if (empty($tva_tx) || empty($tva_npr)) {
2158 $type = $productsupplier->type;
2159 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
2160 $price_base_type =
'HT';
2162 $pu_devise =
price2num($price_ht_devise,
'CU');
2163 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
2164 $price_base_type =
'TTC';
2166 $pu_devise =
price2num($price_ttc_devise,
'CU');
2168 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
2169 if (empty(
$object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code !=
$object->multicurrency_code)) {
2170 $pu = $productsupplier->fourn_pu;
2173 $pu = $productsupplier->fourn_pu;
2174 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
2178 $ref_supplier = $productsupplier->ref_supplier;
2199 min($rank, count(
$object->lines) + 1),
2202 $productsupplier->fk_unit,
2205 GETPOST(
'fourn_ref',
'alpha'),
2209 if ($idprod == -99 || $idprod == 0) {
2212 $langs->load(
"errors");
2213 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2215 if ($idprod == -1) {
2218 $langs->load(
"errors");
2219 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
2221 } elseif (empty($error)) {
2222 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2223 $tva_tx = str_replace(
'*',
'', $tva_tx);
2224 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2227 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
2231 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
2240 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
2241 $price_base_type =
'HT';
2243 $pu_devise =
price2num($price_ht_devise,
'CU');
2245 $price_base_type =
'TTC';
2247 $pu_devise =
price2num($price_ttc_devise,
'CU');
2250 $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);
2254 if (!$error && $result > 0) {
2259 $outputlangs = $langs;
2262 $newlang =
GETPOST(
'lang_id',
'aZ09');
2265 $newlang =
$object->thirdparty->default_lang;
2267 if (!empty($newlang)) {
2269 $outputlangs->setDefaultLang($newlang);
2274 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2280 unset($_POST [
'prod_entry_mode']);
2282 unset($_POST[
'qty']);
2283 unset($_POST[
'type']);
2284 unset($_POST[
'remise_percent']);
2285 unset($_POST[
'pu']);
2286 unset($_POST[
'price_ht']);
2287 unset($_POST[
'multicurrency_price_ht']);
2288 unset($_POST[
'price_ttc']);
2289 unset($_POST[
'fourn_ref']);
2290 unset($_POST[
'tva_tx']);
2291 unset($_POST[
'label']);
2292 unset($localtax1_tx);
2293 unset($localtax2_tx);
2294 unset($_POST[
'np_marginRate']);
2295 unset($_POST[
'np_markRate']);
2296 unset($_POST[
'dp_desc']);
2297 unset($_POST[
'idprodfournprice']);
2298 unset($_POST[
'units']);
2300 unset($_POST[
'date_starthour']);
2301 unset($_POST[
'date_startmin']);
2302 unset($_POST[
'date_startsec']);
2303 unset($_POST[
'date_startday']);
2304 unset($_POST[
'date_startmonth']);
2305 unset($_POST[
'date_startyear']);
2306 unset($_POST[
'date_endhour']);
2307 unset($_POST[
'date_endmin']);
2308 unset($_POST[
'date_endsec']);
2309 unset($_POST[
'date_endday']);
2310 unset($_POST[
'date_endmonth']);
2311 unset($_POST[
'date_endyear']);
2313 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
2321 } elseif ($action ==
'classin' && $usercancreate) {
2323 $result =
$object->setProject($projectid);
2324 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
2328 $totalpaid =
$object->getSommePaiement();
2329 $resteapayer =
$object->total_ttc - $totalpaid;
2332 $ventilExportCompta =
$object->getVentilExportCompta();
2334 if (!$ventilExportCompta) {
2337 $idwarehouse =
GETPOST(
'idwarehouse');
2341 $qualified_for_stock_change = 0;
2343 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2345 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2350 $langs->load(
"stocks");
2351 if (!$idwarehouse || $idwarehouse == -1) {
2353 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
2358 $object->setDraft($user, $idwarehouse);
2362 $outputlangs = $langs;
2365 $newlang =
GETPOST(
'lang_id',
'aZ09');
2368 $newlang =
$object->thirdparty->default_lang;
2370 if (!empty($newlang)) {
2372 $outputlangs->setDefaultLang($newlang);
2377 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2386 } elseif ($action ==
'reopen' && $usercancreate) {
2388 $result =
$object->fetch($id);
2391 $result =
$object->setUnpaid($user);
2393 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
2402 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2405 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
2407 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
2408 $trackid =
'sinv'.$object->id;
2409 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2413 $permissiontoadd = $usercancreate;
2414 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2417 if ($action ==
'calculate' && $usercancreate) {
2418 $calculationrule =
GETPOST(
'calculationrule');
2422 $result =
$object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0,
$object->thirdparty);
2428 if ($action ==
'update_extras' && $permissiontoeditextra) {
2431 $attribute_name =
GETPOST(
'attribute',
'aZ09');
2434 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
2440 $result =
$object->updateExtraField($attribute_name,
'BILL_SUPPLIER_MODIFY');
2448 $action =
'edit_extras';
2453 if ($action ==
'addcontact' && $usercancreate) {
2454 $result =
$object->fetch($id);
2456 if ($result > 0 && $id > 0) {
2459 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2463 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2466 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2467 $langs->load(
"errors");
2468 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2473 } elseif ($action ==
'swapstatut' && $usercancreate) {
2478 dol_print_error($db);
2480 } elseif ($action ==
'deletecontact' && $usercancreate) {
2486 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
2489 dol_print_error($db);
2500$form =
new Form($db);
2502$bankaccountstatic =
new Account($db);
2510$title =
$object->ref.
" - ".$langs->trans(
'Card');
2511if ($action ==
'create') {
2512 $title = $langs->trans(
"NewSupplierInvoice");
2514$help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
2515llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-fourn-facture page-card');
2518if ($action ==
'create') {
2520 $selectedLines = array();
2522 print
load_fiche_titre($langs->trans(
'NewSupplierInvoice'),
'',
'supplier_invoice');
2526 $currency_code =
$conf->currency;
2527 $vat_reverse_charge = 0;
2533 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2534 $currency_code = $societe->multicurrency_code;
2539 if (!empty($origin) && !empty($originid)) {
2541 $element = $subelement = $origin;
2543 if ($element ==
'project') {
2544 $projectid = $originid;
2545 $element =
'projet';
2549 if ($element ==
'order') {
2550 $element = $subelement =
'commande';
2552 if ($element ==
'propal') {
2553 $element =
'comm/propal';
2554 $subelement =
'propal';
2556 if ($element ==
'contract') {
2557 $element = $subelement =
'contrat';
2559 if ($element ==
'order_supplier') {
2561 $subelement =
'fournisseur.commande';
2565 $classname = ucfirst($subelement);
2566 if ($classname ==
'Fournisseur.commande') {
2567 $classname =
'CommandeFournisseur';
2569 $objectsrc =
new $classname($db);
2570 '@phan-var-force Project|Commande|Propal|Facture|Contrat|CommandeFournisseur|CommonObject $objectsrc';
2572 $objectsrc->fetch($originid);
2573 $objectsrc->fetch_thirdparty();
2575 $projectid = (int) $objectsrc->fk_project;
2577 $soc = $objectsrc->thirdparty;
2579 $cond_reglement_id = 0;
2580 $mode_reglement_id = 0;
2582 $transport_mode_id = 0;
2585 if (!empty($objectsrc->cond_reglement_id)) {
2586 $cond_reglement_id = $objectsrc->cond_reglement_id;
2588 if (!empty($objectsrc->mode_reglement_id)) {
2589 $mode_reglement_id = $objectsrc->mode_reglement_id;
2591 if (!empty($objectsrc->fk_account)) {
2592 $fk_account = $objectsrc->fk_account;
2594 if (!empty($objectsrc->transport_mode_id)) {
2595 $transport_mode_id = $objectsrc->transport_mode_id;
2598 if (empty($cond_reglement_id)
2599 || empty($mode_reglement_id)
2600 || empty($fk_account)
2601 || empty($transport_mode_id)
2603 if ($origin ==
'reception') {
2605 if (!isset($objectsrc->supplier_order)) {
2606 $objectsrc->fetch_origin();
2609 if (!empty($objectsrc->origin_object)) {
2610 $originObject = $objectsrc->origin_object;
2611 if (empty($cond_reglement_id) && !empty($originObject->cond_reglement_id)) {
2612 $cond_reglement_id = $originObject->cond_reglement_id;
2614 if (empty($mode_reglement_id) && !empty($originObject->mode_reglement_id)) {
2615 $mode_reglement_id = $originObject->mode_reglement_id;
2617 if (empty($fk_account) && !empty($originObject->fk_account)) {
2618 $fk_account = $originObject->fk_account;
2620 if (empty($transport_mode_id) && !empty($originObject->transport_mode_id)) {
2621 $transport_mode_id = $originObject->transport_mode_id;
2628 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
2629 $cond_reglement_id = $soc->cond_reglement_supplier_id;
2631 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
2632 $mode_reglement_id = $soc->mode_reglement_supplier_id;
2634 if (empty($fk_account) && !empty($soc->fk_account)) {
2635 $fk_account = $soc->fk_account;
2637 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
2638 $transport_mode_id = $soc->transport_mode_id;
2644 if (!empty($objectsrc->multicurrency_code)) {
2645 $currency_code = $objectsrc->multicurrency_code;
2647 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
2648 $currency_tx = $objectsrc->multicurrency_tx;
2653 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2655 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2658 $objectsrc->fetch_optionals();
2659 $object->array_options = $objectsrc->array_options;
2661 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2662 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2663 $vat_reverse_charge = (empty($societe) ?
'' : $societe->vat_reverse_charge);
2664 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2665 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2667 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalInt(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2669 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2671 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2672 $currency_code = $societe->multicurrency_code;
2677 if (empty($cond_reglement_id)) {
2678 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2682 if (empty($mode_reglement_id)) {
2683 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2687 if (!
GETPOST(
'changecompany')) {
2689 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
2692 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
2699 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
2700 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
2702 if ($origin ==
'contrat') {
2703 $langs->load(
"admin");
2704 $text = $langs->trans(
"ToCreateARecurringInvoice");
2705 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"SupplierBills"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
2707 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
2709 print
info_admin($text, 0, 0,
'0',
'opacitymedium').
'<br>';
2712 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2713 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2714 print
'<input type="hidden" name="action" value="add">';
2715 print
'<input type="hidden" name="changecompany" value="0">';
2717 if (!empty($societe->id) && $societe->id > 0) {
2718 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2720 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2721 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2722 if (!empty($currency_tx)) {
2723 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2725 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2730 $parameters = array();
2732 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierInvoice', $parameters, $object, $action);
2733 if (empty($reshook)) {
2734 print
'<table class="border centpercent">';
2741 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2742 $invoice_predefined->fetch($fac_recid);
2746 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2749 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2750 $absolute_discount = $societe->getAvailableDiscounts(
null,
'', 0, 1);
2751 print $societe->getNomUrl(1,
'supplier');
2752 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2754 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2755 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');
2758 print
'<script type="text/javascript">
2759 $(document).ready(function() {
2760 $("#socid").change(function() {
2761 console.log("We have changed the company - Reload page");
2763 $("input[name=action]").val("create");
2764 $("input[name=changecompany]").val("1");
2765 $("form[name=add]").submit();
2770 if ($fac_recid <= 0) {
2771 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>';
2777 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2778 $invoice_predefined->fetch($fac_recid);
2780 $dateinvoice = $invoice_predefined->date_when;
2781 if (empty($projectid)) {
2782 $projectid = $invoice_predefined->fk_project;
2784 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2785 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2786 $fk_account = $invoice_predefined->fk_account;
2787 $note_public = $invoice_predefined->note_public;
2788 $note_private = $invoice_predefined->note_private;
2790 if (!empty($invoice_predefined->multicurrency_code)) {
2791 $currency_code = $invoice_predefined->multicurrency_code;
2793 if (!empty($invoice_predefined->multicurrency_tx)) {
2794 $currency_tx = $invoice_predefined->multicurrency_tx;
2797 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2798 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2799 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2801 $resql = $db->query($sql);
2803 $num = $db->num_rows($resql);
2807 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2809 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2810 print
'<option value="0" selected></option>';
2812 $objp = $db->fetch_object($resql);
2813 print
'<option value="'.$objp->rowid.
'"';
2814 if ($fac_recid == $objp->rowid) {
2816 $exampletemplateinvoice->fetch($fac_recid);
2818 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2824 print
'<script type="text/javascript">
2825 $(document).ready(function() {
2826 $("#fac_rec").change(function() {
2827 console.log("We have changed the template invoice - Reload page");
2829 $("input[name=action]").val("create");
2830 $("form[name=add]").submit();
2839 dol_print_error($db);
2843 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2845 print
'<div class="tagtable">'.
"\n";
2848 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2849 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
'checked').
'> ';
2850 $desc = $form->textwithpicto($tmp.
'<label for="radio_standard">'.$langs->trans(
"InvoiceStandardAsk").
'</label>', $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2852 print
'</div></div>';
2854 if (empty($origin) || (($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') && !empty($originid))) {
2857 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2858 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOSTINT(
'type') == 3 ?
' checked' :
'') .
'> ';
2859 print
'<script type="text/javascript">
2860 jQuery(document).ready(function() {
2861 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2862 jQuery("#radio_standard").prop("checked", true);
2864 jQuery("#typedeposit, #valuedeposit").click(function() {
2865 jQuery("#radio_deposit").prop("checked", true);
2867 jQuery("#typedeposit").change(function() {
2868 console.log("We change type of down payment");
2869 jQuery("#radio_deposit").prop("checked", true);
2870 setRadioForTypeOfInvoice();
2872 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2873 setRadioForTypeOfInvoice();
2875 function setRadioForTypeOfInvoice() {
2876 console.log("Change radio");
2877 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2878 jQuery(".checkforselect").prop("disabled", true);
2879 jQuery(".checkforselect").prop("checked", false);
2881 jQuery(".checkforselect").prop("disabled", false);
2882 jQuery(".checkforselect").prop("checked", true);
2888 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2890 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2891 print
'<table class="nobordernopadding"><tr>';
2895 if ($origin ==
'supplier_proposal' || $origin ==
'order_supplier' || $origin ==
'reception') {
2896 print
'<td class="nowrap" style="padding-left: 15px">';
2898 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2899 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2900 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2902 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
2903 $valuedeposit =
GETPOST(
'valuedeposit',
'int');
2904 $deposit_percent =
null;
2905 if ($origin ==
'reception') {
2907 if (!isset($objectsrc->origin_object)) {
2908 $objectsrc->fetch_origin();
2910 if (!empty($objectsrc->origin_object)) {
2911 $deposit_percent = $objectsrc->origin_object->deposit_percent;
2913 } elseif (!empty($objectsrc->deposit_percent)) {
2914 $deposit_percent = $objectsrc->deposit_percent;
2916 if (empty($typedeposit) && !empty($deposit_percent)) {
2917 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
2918 if (!empty($origin_payment_conditions_deposit_percent)) {
2919 $typedeposit =
'variable';
2922 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($deposit_percent)) {
2923 $valuedeposit = $deposit_percent;
2925 print $form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
2927 print
'<td class="nowrap" style="padding-left: 5px">';
2928 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' . $valuedeposit .
'"/>';
2931 print
'</tr></table>';
2933 print
'</div></div>';
3002 if (empty($origin)) {
3003 if (!empty($societe->id) && $societe->id > 0) {
3007 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
3009 dol_print_error($db, $facturestatic->error, $facturestatic->errors);
3014 foreach ($facids as $key => $valarray) {
3015 $newinvoice_static->id = $key;
3016 $newinvoice_static->ref = $valarray [
'ref'];
3017 $newinvoice_static->status = $valarray [
'status'];
3018 $newinvoice_static->statut = $valarray [
'status'];
3019 $newinvoice_static->type = $valarray [
'type'];
3020 $newinvoice_static->paid = $valarray [
'paye'];
3021 $newinvoice_static->paye = $valarray [
'paye'];
3023 $optionsav .=
'<option value="'.$key.
'"';
3025 $optionsav .=
' selected';
3027 $newinvoice_static->fetch_optionals($key);
3028 $object->array_options = $newinvoice_static->array_options;
3031 $optionsav .= $newinvoice_static->ref;
3032 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
3033 $optionsav .=
'</option>';
3036 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3037 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOSTINT(
'type') == 2 ?
' checked' :
'');
3039 $tmp .=
' disabled';
3043 print
'<script type="text/javascript">
3044 jQuery(document).ready(function() {
3045 if (! jQuery("#radio_creditnote").is(":checked"))
3047 jQuery("#credit_note_options").hide();
3049 jQuery("#radio_creditnote").click(function() {
3050 jQuery("#credit_note_options").show();
3052 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
3053 jQuery("#credit_note_options").hide();
3057 $text = $tmp.
'<label for="radio_creditnote">'.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
3059 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3061 $text .=
' disabled';
3065 $text .=
'<option value="-1"></option>';
3066 $text .= $optionsav;
3068 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
3070 $text .=
'</select>';
3071 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3074 print
'<div id="credit_note_options" class="clearboth">';
3075 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' :
'').
' /> ';
3076 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
3077 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' :
'').
' /> ';
3078 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
3081 print
'</div></div>';
3084 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3086 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3088 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2"> ';
3090 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
3091 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
3092 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3094 print
'</div></div>'.
"\n";
3104 print
'<tr><td class="fieldrequired">';
3105 print $form->textwithpicto($langs->trans(
'RefSupplierBill'), $langs->trans(
"RefOfOnVendorSide", $langs->trans(
"SupplierBill"))).
'</td><td>';
3106 print
'<input name="ref_supplier" value="'.(GETPOSTISSET(
'ref_supplier') ?
GETPOST(
'ref_supplier') : (!empty($objectsrc->ref_supplier) ? $objectsrc->ref_supplier :
'')).
'" type="text" spellcheck="false"';
3107 if (!empty($societe->id) && $societe->id > 0) {
3116 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
3117 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
3121 if (!empty($societe->id) && $societe->id > 0) {
3123 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
3125 $thirdparty = $societe;
3127 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
3128 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3134 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth300" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
3138 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
3139 print img_picto(
'',
'action',
'class="pictofixedwidth"');
3140 print $form->selectDate($dateinvoice ? (
int) $dateinvoice :
'',
'', 0, 0, 0,
"add", 1, 1);
3145 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td>';
3146 print img_picto(
'',
'action',
'class="pictofixedwidth"');
3147 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
3152 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
3153 print img_picto(
'',
'payment',
'class="pictofixedwidth"');
3154 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth200 widthcentpercentminusx');
3158 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
3159 print img_picto(
'',
'action',
'class="pictofixedwidth"');
3160 print $form->selectDate($datedue,
'ech', 0, 0, 0,
"add", 1, 1);
3164 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
3165 print img_picto(
'',
'bank',
'class="pictofixedwidth"');
3166 $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'DBIT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
3171 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
3173 print img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
3181 $langs->load(
'projects');
3182 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
3183 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');
3184 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>';
3191 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
3192 print
'<td colspan="3" class="maxwidthonsmartphone">';
3193 print img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
3194 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 :
''));
3200 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
3201 print
'<tr><td>' . $langs->trans(
'VATReverseCharge') .
'</td><td>';
3204 $vat_reverse_charge = (
GETPOST(
'vat_reverse_charge',
'alpha') ==
'on' ||
GETPOST(
'vat_reverse_charge',
'alpha') ==
'1') ? 1 : 0;
3205 } elseif ($vat_reverse_charge == 1 || $societe->vat_reverse_charge == 1 || ($societe->country_code !=
'FR' &&
isInEEC($societe) && !empty($societe->tva_intra))) {
3206 $vat_reverse_charge = 1;
3208 $vat_reverse_charge = 0;
3211 print
'<input type="checkbox" name="vat_reverse_charge"'. (!empty($vat_reverse_charge) ?
' checked ' :
'') .
'>';
3218 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
3219 print
'<td class="maxwidthonsmartphone">';
3220 print img_picto(
'',
'currency',
'class="pictofixedwidth"');
3221 $used_currency_code = $currency_code;
3222 if (!
GETPOST(
'changecompany')) {
3223 $used_currency_code =
GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code;
3225 print $form->selectMultiCurrency($used_currency_code,
'multicurrency_code');
3231 if ($fac_recid > 0) {
3232 $dateexample = $dateinvoice;
3233 if (empty($dateexample)) {
3236 $substitutionarray = array(
3237 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
3238 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
3239 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
3240 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
3241 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
3242 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
3243 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
3244 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
3245 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
3246 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
3247 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
3250 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
3251 foreach ($substitutionarray as $key => $val) {
3252 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
3254 $htmltext .=
'</i>';
3259 $langs->loadLangs(array(
"intracommreport"));
3260 print
'<!-- If module intracomm on -->'.
"\n";
3261 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
3262 $form->selectTransportMode(
GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
3266 if (empty($reshook)) {
3267 print
$object->showOptionals($extrafields,
'create');
3272 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
3273 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
3278 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
3280 $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%');
3281 print $doleditor->Create(1);
3287 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
3289 $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%');
3290 print $doleditor->Create(1);
3296 if (!empty($objectsrc) && $classname !==
null) {
3297 print
"\n<!-- ".$classname.
" info -->";
3299 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
3300 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
3301 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
3302 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
3303 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
3305 $txt = $langs->trans($classname);
3306 if ($classname ==
'CommandeFournisseur') {
3307 $langs->load(
'orders');
3308 $txt = $langs->trans(
"SupplierOrder");
3310 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
3312 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'invoice_supplier');
3314 if (isset($objectsrc->linkedObjects[
'invoice_supplier'])) {
3315 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
3317 $invoice_supplier = [];
3319 '@phan-var-force null|FactureFournisseur[] $invoice_supplier';
3322 if (is_array($invoice_supplier)) {
3323 $cntinvoice = count($invoice_supplier);
3325 if ($cntinvoice >= 1) {
3326 setEventMessages(
'WarningBillExist',
null,
'warnings');
3327 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
3332 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
3333 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
3334 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
3335 print
'<tr><td>'.$langs->transcountry(
"AmountLT1",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
3338 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
3339 print
'<tr><td>'.$langs->transcountry(
"AmountLT2",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
3341 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
3344 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
'</td></tr>';
3345 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
"</td></tr>";
3346 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
"</td></tr>";
3351 $parameters = array();
3352 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
3353 print $hookmanager->resPrint;
3361 print $form->buttonsSaveCancel(
"CreateDraft");
3364 if (!empty($objectsrc)) {
3367 $title = $langs->trans(
'ProductsAndServices');
3370 print
'<div class="div-table-responsive-no-min">';
3371 print
'<table class="noborder centpercent">';
3373 $objectsrc->printOriginLinesList(
'', $selectedLines);
3381 if ($id > 0 || !empty($ref)) {
3387 $result =
$object->fetch($id, $ref);
3392 $result =
$object->fetch_thirdparty();
3398 $societe =
$object->thirdparty;
3400 $totalpaid =
$object->getSommePaiement();
3401 $totalcreditnotes =
$object->getSumCreditNotesUsed();
3402 $totaldeposits =
$object->getSumDepositsUsed();
3410 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
3413 $multicurrency_resteapayer = 0;
3415 $multicurrency_totalpaid =
$object->getSommePaiement(1);
3416 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
3417 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
3418 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
3422 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
3423 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
3430 $resteapayeraffiche = $resteapayer;
3433 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
3434 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
3436 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
3437 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
3440 $absolute_discount = $societe->getAvailableDiscounts(
null, $filterabsolutediscount, 0, 1);
3441 $absolute_creditnote = $societe->getAvailableDiscounts(
null, $filtercreditnote, 0, 1);
3442 $absolute_discount =
price2num($absolute_discount,
'MT');
3443 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
3447 $objectidnext =
$object->getIdReplacingInvoice();
3450 $titre = $langs->trans(
'SupplierInvoice');
3452 print
dol_get_fiche_head($head,
'card', $titre, -1,
'supplier_invoice', 0,
'',
'', 0,
'', 1);
3457 if ($action ==
'converttoreduc') {
3460 $type_fac =
'ExcessPaid';
3462 $type_fac =
'CreditNote';
3464 $type_fac =
'Deposit';
3466 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
3467 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
3468 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
3472 if ($action ==
'clone') {
3474 $formquestion = array(
3475 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplierBill"),
'value' => $langs->trans(
"CopyOf").
' '.
$object->ref_supplier),
3476 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
3479 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 0);
3483 if ($action ==
'valid') {
3485 if (preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) {
3487 $numref =
$object->getNextNumRef($societe);
3489 $numref = (string)
$object->ref;
3496 $text = $langs->trans(
'ConfirmValidateBill', $numref);
3504 $formquestion = array();
3506 $qualified_for_stock_change = 0;
3508 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3510 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3514 $langs->load(
"stocks");
3515 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3518 $warehouse_array = $warehouse->list_array();
3519 if (count($warehouse_array) == 1) {
3521 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3524 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3526 $formquestion = array(
3527 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3531 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
3536 if ($action ==
'edit') {
3537 $formquestion = array();
3539 $qualified_for_stock_change = 0;
3541 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3543 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3546 $langs->load(
"stocks");
3547 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3550 $warehouse_array = $warehouse->list_array();
3551 if (count($warehouse_array) == 1) {
3553 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3556 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3558 $formquestion = array(
3559 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3562 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill',
$object->ref),
'confirm_edit', $formquestion, 1, 1);
3566 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
3567 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'', 0, 1);
3570 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
3574 $close[$i][
'code'] =
'discount_vat';
3576 $close[$i][
'code'] =
'badsupplier';
3578 $close[$i][
'code'] =
'other';
3582 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
3584 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3586 $close[$i][
'label'] = $langs->trans(
"Other");
3590 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3592 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3594 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
3597 $arrayreasons = array();
3598 foreach ($close as $key => $val) {
3599 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
3603 $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'));
3605 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
3609 if ($action ==
'canceled') {
3611 $close[1][
'code'] =
'badsupplier';
3612 $close[2][
'code'] =
'abandon';
3614 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3615 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
3617 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier",
$object->ref), $close[1][
'label'], 1);
3618 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
3620 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
3621 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
3624 $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'));
3626 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 280);
3630 if ($action ==
'delete') {
3631 $formquestion = array();
3633 $qualified_for_stock_change = 0;
3635 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
3637 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
3641 $langs->load(
"stocks");
3642 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3645 $warehouse_array = $warehouse->list_array();
3647 $selectwarehouse =
'<span class="questionrevertstock hidden">';
3648 if (count($warehouse_array) == 1) {
3650 $selectwarehouse .=
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3653 $selectwarehouse .= $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3655 $selectwarehouse .=
'</span>';
3657 $selectyesno = array(0 => $langs->trans(
'No'), 1 => $langs->trans(
'Yes'));
3659 print
'<script type="text/javascript">
3660 $(document).ready(function() {
3661 $("#revertstock").change(function() {
3662 if(this.value > 0) {
3663 $(".questionrevertstock").removeClass("hidden");
3665 $(".questionrevertstock").addClass("hidden");
3671 $formquestion = array(
3672 array(
'type' =>
'select',
'name' =>
'revertstock',
'label' => $langs->trans(
"RevertProductsToStock"),
'select_show_empty' => 0,
'values' => $selectyesno),
3673 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $selectwarehouse,
'tdclass' =>
'questionrevertstock hidden')
3677 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete', $formquestion, 1, 1);
3679 if ($action ==
'deletepayment') {
3680 $payment_id =
GETPOST(
'paiement_id');
3681 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
3685 if ($action ==
'ask_deleteline') {
3686 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
3690 if ($action ==
'ask_subtotal_deleteline') {
3691 $langs->load(
'subtotals');
3692 $subtotaltitle =
'DeleteSubtotalLine';
3693 $subtotalquestion =
'ConfirmDeleteSubtotalLine';
3694 $subtotalformquestion = array();
3695 if (
GETPOST(
'type') ==
'title') {
3696 $subtotalformquestion = array(array(
'type' =>
'checkbox',
'name' =>
'deletecorrespondingsubtotalline',
'label' => $langs->trans(
'DeleteCorrespondingSubtotalLine'),
'value' => 0));
3697 $subtotaltitle =
'DeleteTitleLine';
3698 $subtotalquestion =
'ConfirmDeleteTitleLine';
3700 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans($subtotaltitle), $langs->trans($subtotalquestion),
'confirm_delete_subtotalline', $subtotalformquestion,
'no', 1);
3704 if ($action ==
'add_title_line') {
3705 $langs->load(
'subtotals');
3707 $depth_array =
$object->getPossibleLevels($langs);
3708 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3709 } elseif ($action ==
'add_subtotal_line') {
3710 $langs->load(
'subtotals');
3712 $titles =
$object->getPossibleTitles();
3713 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3714 } elseif ($action ==
'add_text_line') {
3715 $langs->load(
'subtotals');
3717 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
3721 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
3722 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
3723 if (empty($reshook)) {
3724 $formconfirm .= $hookmanager->resPrint;
3725 } elseif ($reshook > 0) {
3726 $formconfirm = $hookmanager->resPrint;
3734 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
3736 $morehtmlref =
'<div class="refidno">';
3738 $morehtmlref .= $form->editfieldkey(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, (
int) $usercancreate,
'string',
'', 0, 1);
3739 $morehtmlref .= $form->editfieldval(
"RefSupplierBill",
'ref_supplier',
$object->ref_supplier, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
3741 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'supplier');
3743 $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>';
3747 $langs->load(
"projects");
3748 $morehtmlref .=
'<br>';
3749 if ($permissiontoadd) {
3750 $morehtmlref .= img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
3751 if ($action !=
'classify') {
3752 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.((int)
$object->id).
'">'.img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
3754 $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');
3756 if (!empty(
$object->fk_project)) {
3758 $proj->fetch(
$object->fk_project);
3759 $morehtmlref .= $proj->getNomUrl(1);
3761 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
3766 $morehtmlref .=
'</div>';
3768 $object->totalpaid = $totalpaid;
3770 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
3773 $parameters = array();
3775 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierInvoice', $parameters, $object, $action);
3776 if (empty($reshook)) {
3777 print
'<div class="fichecenter">';
3778 print
'<div class="fichehalfleft">';
3779 print
'<div class="underbanner clearboth"></div>';
3781 print
'<table class="border tableforfield centpercent">';
3784 print
'<tr><td>'.$langs->trans(
'Type').
'</td><td>';
3785 print
'<span class="badgeneutral">';
3789 print
' '.$object->getSubtypeLabel(
'facture_fourn');
3793 $facreplaced->fetch(
$object->fk_facture_source);
3794 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
3797 if (
$object->fk_facture_source > 0) {
3799 $facusing->fetch(
$object->fk_facture_source);
3800 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
3802 $langs->load(
"errors");
3803 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"WarningCorrectedInvoiceNotFound").
'</span>';
3808 $object->getListIdAvoirFromInvoice();
3810 if (!empty(
$object->creditnote_ids)) {
3811 $invoicecredits = array();
3812 foreach (
$object->creditnote_ids as $invoiceid) {
3814 $creditnote->fetch($invoiceid);
3815 $invoicecredits[] = $creditnote->getNomUrl(1);
3817 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
3820 if (isset($objectidnext) && $objectidnext > 0) {
3823 $facthatreplace->fetch($objectidnext);
3824 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
3828 $result = $discount->fetch(0, 0,
$object->id);
3830 print
' <span class="opacitymediumbycolor paddingleft">';
3831 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
3832 $s = str_replace(
'{s1}',
$object->getLibType(1), $s);
3833 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
3835 print
'</span><br>';
3839 if (
$object->fk_fac_rec_source > 0) {
3841 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
3843 print
' <span class="opacitymediumbycolor paddingleft">';
3844 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->title).
'</a>';
3845 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
3855 print
'<!-- Discounts -->'.
"\n";
3856 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
3859 $thirdparty = $societe;
3861 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3867 print
'<td>'.$form->editfieldkey(
"Label",
'label',
$object->label, $object, (
int) $usercancreate).
'</td>';
3868 print
'<td>'.$form->editfieldval(
"Label",
'label',
$object->label, $object, $usercancreate).
'</td>';
3876 print $form->editfieldkey(
"DateInvoice",
'datef', (
string)
$object->date,
$object, (int) $form_permission,
'datepicker');
3877 print
'</td><td colspan="3">';
3878 print $form->editfieldval(
"Date",
'datef',
$object->date, $object, $form_permission,
'datepicker');
3884 print $form->editfieldkey(
"DatePointOfTax",
'date_pointoftax', (
string)
$object->date_pointoftax,
$object, (int) $pointoftax_form_permission,
'datepicker');
3885 print
'</td><td colspan="3">';
3886 print $form->editfieldval(
"DatePointOfTax",
'date_pointoftax',
$object->date_pointoftax, $object, $pointoftax_form_permission,
'datepicker');
3891 $langs->load(
'bills');
3892 print
'<tr><td class="nowrap">';
3893 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3894 print $langs->trans(
'PaymentConditions');
3896 if ($action !=
'editconditions' && $form_permission) {
3897 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>';
3899 print
'</tr></table>';
3901 if ($action ==
'editconditions') {
3902 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
3904 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
3911 print $form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', (
string)
$object->date_echeance, $object, (
int) $form_permission,
'datepicker');
3913 print $form->editfieldval(
"DateMaxPayment",
'date_lim_reglement',
$object->date_echeance, $object, $form_permission,
'datepicker');
3914 if ($action !=
'editdate_lim_reglement' &&
$object->hasDelay()) {
3915 print img_warning($langs->trans(
'Late'));
3920 $langs->load(
'bills');
3921 print
'<tr><td class="nowrap">';
3922 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3923 print $langs->trans(
'PaymentMode');
3925 if ($action !=
'editmode' && $form_permission) {
3926 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>';
3928 print
'</tr></table>';
3930 if ($action ==
'editmode') {
3931 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3933 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'none');
3939 print
'<tr><td class="nowrap">';
3940 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3941 print $langs->trans(
'BankAccount');
3943 if ($action !=
'editbankaccount' && $usercancreate) {
3944 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>';
3946 print
'</tr></table>';
3948 if ($action ==
'editbankaccount') {
3949 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
3951 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
3959 print
'<tr><td class="nowrap">';
3960 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3961 print $langs->trans(
'VATReverseCharge');
3963 if ($action !=
'editvatreversecharge' && $usercancreate) {
3964 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>';
3966 print
'</tr></table>';
3968 if ($action ==
'editvatreversecharge') {
3969 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
3970 print
'<input type="hidden" name="action" value="setvatreversecharge">';
3971 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3973 print
'<input type="checkbox" name="vat_reverse_charge"' . (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
'>';
3975 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
3978 print
'<input type="checkbox" name="vat_reverse_charge"'. (
$object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
' disabled>';
3986 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3987 print $langs->trans(
'IncotermLabel');
3988 print
'<td><td class="right">';
3989 if ($usercancreate) {
3990 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.img_edit().
'</a>';
3994 print
'</td></tr></table>';
3997 if ($action !=
'editincoterm') {
3998 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
4000 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
4007 $langs->loadLangs(array(
"intracommreport"));
4008 print
'<!-- If module intracomm on -->'.
"\n";
4010 print
'<table class="nobordernopadding centpercent"><tr><td>';
4011 print $langs->trans(
'IntracommReportTransportMode');
4013 if ($action !=
'edittransportmode' && ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"))) {
4014 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edittransportmode&token='.
newToken().
'&id='.
$object->id.
'">'.img_edit().
'</a></td>';
4016 print
'</tr></table>';
4019 if ($action ==
'edittransportmode') {
4020 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'transport_mode_id', 1, 1);
4022 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->transport_mode_id,
'none');
4030 print
'<table class="nobordernopadding centpercent"><tr><td>';
4031 print $langs->trans(
"Categories");
4032 print
'<td><td class="right">';
4033 if ($usercancreate) {
4034 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.img_edit().
'</a>';
4038 print
'</td></tr></table>';
4041 if ($action ==
'edittags') {
4042 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
4043 print
'<input type="hidden" name="action" value="settags">';
4044 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4045 print $form->selectCategories(Categorie::TYPE_SUPPLIER_INVOICE,
'categories', $object);
4046 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
4049 print $form->showCategories(
$object->id, Categorie::TYPE_SUPPLIER_INVOICE, 1);
4057 if (
$object->status != $object::STATUS_DRAFT) {
4061 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
4066 print
'<div class="fichehalfright">';
4067 print
'<div class="underbanner clearboth"></div>';
4069 print
'<table class="border tableforfield centpercent">';
4071 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
4074 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
4075 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
4077 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
4082 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
4083 print
'<td class="nowrap amountcard right">';
4084 if (
GETPOST(
'calculationrule')) {
4085 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
4087 $calculationrule = (!
getDolGlobalString(
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND_SUPPLIER') ?
'totalofround' :
'roundoftotal');
4089 if ($calculationrule ==
'totalofround') {
4090 $calculationrulenum = 1;
4092 $calculationrulenum = 2;
4095 if (
$object->getVentilExportCompta() == 0) {
4096 $s =
'<span class="hideonsmartphone opacitymedium">' . $langs->trans(
"ReCalculate") .
' </span>';
4097 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=totalofround">' . $langs->trans(
"Mode1") .
'</a>';
4099 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=calculate&token='.newToken().
'&calculationrule=roundoftotal">' . (
$conf->dol_optimize_smallscreen ?
"2" : $langs->trans(
"Mode2")) .
'</a>';
4100 print
'<div class="inline-block">';
4101 print $form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum) .
'<br>' . $langs->trans(
"CalculationRuleDescSupplier"), 2, 1, img_picto(
'',
'help',
'class="paddingleft paddingright"'),
'', 3,
'', 0,
'recalculate');
4102 print
' ';
4105 print
'<span class="nowraponall">'.price(
$object->total_tva, 1, $langs, 0, -1, -1,
$conf->currency).
'</span>';
4108 print
'<td class="nowraponall amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
4112 if ($societe->localtax1_assuj ==
"1") {
4114 print
'<td>' . $langs->transcountry(
"AmountLT1", $societe->country_code) .
'</td>';
4115 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
4118 if ($societe->localtax2_assuj ==
"1") {
4120 print
'<td>' . $langs->transcountry(
"AmountLT2", $societe->country_code) .
'</td>';
4121 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 1, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
4126 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
4127 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
4129 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
4162 if ($societe->localtax1_assuj ==
"1") {
4165 if ($societe->localtax2_assuj ==
"1") {
4169 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
4170 $sql .=
' c.id as payment_type, c.code as payment_code,';
4171 $sql .=
' pf.amount,';
4172 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
4173 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
4174 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
4175 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
4176 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
4177 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
4178 $sql .=
' WHERE pf.fk_facturefourn = '.((int)
$object->id);
4179 $sql .=
' ORDER BY p.datep, p.tms';
4181 $result = $db->query($sql);
4183 $num = $db->num_rows($result);
4186 print
'<div class="div-table-responsive-no-min">';
4187 print
'<table class="noborder paymenttable centpercent">';
4188 print
'<tr class="liste_titre">';
4190 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
4191 print
'<td><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
4193 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
4198 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
4203 $objp = $db->fetch_object($result);
4205 $paymentstatic->id = $objp->rowid;
4206 $paymentstatic->datepaye = $db->jdate($objp->dp);
4207 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
4208 $paymentstatic->num_payment = $objp->num_payment;
4210 $paymentstatic->paiementcode = $objp->payment_code;
4211 $paymentstatic->type_code = $objp->payment_code;
4212 $paymentstatic->type_label = $objp->payment_type;
4214 print
'<tr class="oddeven">';
4215 print
'<td class="nowraponall">';
4216 print $paymentstatic->getNomUrl(1);
4218 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
'</td>';
4219 $s = $form->form_modes_reglement(
'', $objp->payment_type,
'none',
'', 1, 0,
'', 1).
' '.$objp->num_payment;
4220 print
'<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).
'">';
4224 $bankaccountstatic->id = $objp->baid;
4225 $bankaccountstatic->ref = $objp->baref;
4226 $bankaccountstatic->label = $objp->baref;
4227 $bankaccountstatic->number = $objp->banumber;
4230 $bankaccountstatic->account_number = $objp->account_number;
4233 $accountingjournal->fetch($objp->fk_accountancy_journal);
4234 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
4237 print
'<td class="right nowraponall">';
4238 if ($objp->baid > 0) {
4239 print $bankaccountstatic->getNomUrl(1,
'transactions');
4244 print
'<td class="center">';
4246 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
4252 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
4254 $totalpaid += $objp->amount;
4258 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
4279 dol_print_error($db);
4284 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4285 print
'<span class="opacitymedium">';
4287 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
4289 print $langs->trans(
'AlreadyPaid');
4294 print
'<td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td>';
4298 $resteapayeraffiche = $resteapayer;
4300 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
4303 $creditnoteamount = 0;
4306 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
4307 $sql .=
" re.description, re.fk_invoice_supplier_source";
4308 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
4309 $sql .=
" WHERE fk_invoice_supplier = ".((int)
$object->id);
4310 $resql = $db->query($sql);
4312 $num = $db->num_rows($resql);
4316 $obj = $db->fetch_object($resql);
4317 $invoice->fetch($obj->fk_invoice_supplier_source);
4318 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4320 print $langs->trans(
"CreditNote").
' ';
4323 print $langs->trans(
"Deposit").
' ';
4325 print $invoice->getNomUrl(0);
4328 print
'<td class="right">';
4329 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
4330 print img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
4334 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
4338 $creditnoteamount += $obj->amount_ttc;
4341 $depositamount += $obj->amount_ttc;
4345 dol_print_error($db);
4350 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4351 print
'<span class="opacitymedium">';
4352 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
4356 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4358 $resteapayeraffiche = 0;
4359 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4363 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4364 print
'<span class="opacitymedium">';
4365 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
4369 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4372 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4376 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4377 print
'<span class="opacitymedium">';
4378 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
4382 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4384 $resteapayeraffiche = 0;
4385 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4389 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right nowrap">';
4390 $text = $langs->trans(
"HelpAbandonOther");
4392 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
4394 print
'<span class="opacitymedium">';
4396 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
4400 print
'<td class="right">'.price(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td>';
4402 $resteapayeraffiche = 0;
4403 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4407 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4408 print
'<span class="opacitymedium">';
4409 print $langs->trans(
"Billed");
4413 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
4417 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4418 print
'<span class="opacitymedium">';
4419 print $langs->trans(
'RemainderToPay');
4420 if ($resteapayeraffiche < 0) {
4421 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4426 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
4431 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4432 print
'<span class="opacitymedium">';
4433 print $langs->trans(
'RemainderToPayMulticurrency');
4434 if ($resteapayeraffiche < 0) {
4435 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
4440 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price(
price2num($multicurrency_resteapayer,
'MT'), 0, $langs, 1, -1, -1,
$object->multicurrency_code).
'</td>';
4444 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4447 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4448 print $langs->trans(
'AlreadyPaidBack');
4451 print
'<td class="right">'.price($sign * $totalpaid).
'</td>';
4455 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">'.$langs->trans(
"Billed").
'</td>';
4457 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
4461 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4462 print
'<span class="opacitymedium">';
4463 print $langs->trans(
'RemainderToPayBack');
4464 if ($resteapayeraffiche > 0) {
4465 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4470 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
4475 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
4476 print
'<span class="opacitymedium">';
4477 print $langs->trans(
'RemainderToPayBackMulticurrency');
4478 if ($resteapayeraffiche > 0) {
4479 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
4484 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>';
4500 print
'<div class="clearboth"></div><br>';
4503 $blocname =
'contacts';
4504 $title = $langs->trans(
'ContactsAddresses');
4505 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4510 $blocname =
'notes';
4511 $title = $langs->trans(
'Notes');
4512 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4519 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
4520 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4521 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
4522 print
'<input type="hidden" name="mode" value="">';
4523 print
'<input type="hidden" name="page_y" value="">';
4524 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
4525 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
4526 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4530 include DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_ajaxrow.tpl.php';
4532 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
4536 print
'<div class="div-table-responsive-no-min">';
4537 print
'<table id="tablelines" class="noborder noshadow centpercent">';
4539 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
4542 $inputalsopricewithtax = 1;
4543 $senderissupplier = 2;
4544 if (
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY')) {
4545 $senderissupplier =
getDolGlobalInt(
'SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY');
4550 $object->printObjectLines($action, $societe,
$mysoc, $lineid, 1);
4557 if ($action !=
'editline') {
4560 $parameters = array();
4561 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
4563 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
4565 if (empty($reshook)) {
4579 if ($action !=
'presend') {
4582 print
'<div class="tabsAction">';
4584 $parameters = array();
4585 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
4587 if (empty($reshook)) {
4591 $langs->load(
'subtotals');
4593 $url_button = array();
4595 $url_button[] = array(
4596 'lang' =>
'subtotals',
4598 'perm' => (
bool) $usercancreate,
4599 'label' => $langs->trans(
'AddTitleLine'),
4600 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_title_line'],
true)
4603 $url_button[] = array(
4604 'lang' =>
'subtotals',
4606 'perm' => (
bool) $usercancreate,
4607 'label' => $langs->trans(
'AddSubtotalLine'),
4608 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_subtotal_line'],
true)
4611 $url_button[] = array(
4612 'lang' =>
'subtotals',
4614 'perm' => (
bool) $usercancreate,
4615 'label' => $langs->trans(
'AddTextLine'),
4616 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_text_line'],
true)
4619 print dolGetButtonAction(
'', $langs->trans(
'SubTotal'),
'default', $url_button,
'',
true);
4624 $ventilExportCompta =
$object->getVentilExportCompta();
4626 if ($ventilExportCompta == 0) {
4627 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=edit&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
4629 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
4634 $result = $discount->fetch(0, 0,
$object->id);
4641 if (!$objectidnext &&
$object->close_code !=
'replaced' && $usercancreate) {
4642 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
4644 if ($usercancreate) {
4645 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
4647 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
4657 if ($usercanvalidate) {
4658 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken().
'"';
4659 print
'>'.$langs->trans(
'Validate').
'</a>';
4661 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
4662 print
'>'.$langs->trans(
'Validate').
'</a>';
4668 if (empty($user->socid)) {
4671 print dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' =>
$object->id,
'action' =>
'presend',
'mode' =>
'init'],
true).
'#formmailbeforetitle',
'');
4673 print dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false);
4680 $langs->load(
"withdrawals");
4681 if ($resteapayer > 0) {
4682 if ($usercancreatecreditransfer) {
4683 if (!$objectidnext &&
$object->close_code !=
'replaced') {
4684 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>';
4686 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeBankTransferOrder').
'</span>';
4698 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>';
4705 if ($resteapayer == 0) {
4706 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
4707 } elseif ($usercancreate) {
4708 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>';
4714 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
4718 && (
getDolGlobalString(
'SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') ||
$object->getSommePaiement() == 0)
4720 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>';
4724 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
4735 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaid').
'</a>';
4740 if ($totalpaid > 0 || $totalcreditnotes > 0) {
4742 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
4745 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=canceled&token='.
newToken().
'">'.$langs->trans(
'ClassifyCanceled').
'</a>';
4757 if (!$objectidnext) {
4758 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>';
4763 if ($action !=
'edit' && $usercancreate) {
4764 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')));
4769 if (!$objectidnext && count(
$object->lines) > 0) {
4770 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.
$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
4775 if ($action !=
'confirm_edit' && $usercandelete) {
4776 $isErasable =
$object->is_erasable();
4778 $enableDelete =
false;
4780 $params = (empty(
$conf->use_javascript_ajax) ? array() : array(
'attr' => array(
'class' =>
'reposition')));
4782 if ($isErasable == -4) {
4783 $htmltooltip = $langs->trans(
"DisabledBecausePayments");
4784 } elseif ($isErasable == -3) {
4785 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastSituationInvoice");
4786 } elseif ($isErasable == -2) {
4787 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastInvoice");
4788 } elseif ($isErasable == -1) {
4789 $htmltooltip = $langs->trans(
"DisabledBecauseDispatchedInBookkeeping");
4790 } elseif ($isErasable <= 0) {
4791 $htmltooltip = $langs->trans(
"DisabledBecauseNotErasable");
4793 $enableDelete =
true;
4796 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')));
4800 if ($action !=
'confirm_edit') {
4801 print
'<div class="fichecenter"><div class="fichehalfleft">';
4807 $subdir =
get_exdir(
$object->id, 2, 0, 0, $object,
'invoice_supplier').$ref;
4809 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.
$object->id;
4810 $genallowed = $usercanread;
4811 $delallowed = $usercancreate;
4815 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, (
int) $genallowed, (
int) $delallowed, $modelpdf, $genifempty, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
4816 $somethingshown = $formfile->numoffiles;
4819 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice_supplier'), 1);
4820 $linktoelem = $tmparray[
'linktoelem'];
4821 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
4822 print $htmltoenteralink;
4824 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
4826 print
'</div><div class="fichehalfright">';
4829 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
4831 $somethingshown = $formactions->showactions($object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
4833 print
'</div></div>';
4839 if (
GETPOST(
'modelselected')) {
4840 $action =
'presend';
4844 $modelmail =
'invoice_supplier_send';
4845 $defaulttopic =
'SendBillRef';
4847 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
4848 $trackid =
'sinv'.$object->id;
4850 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage bank accounts.
Class to manage accounting journals.
const TYPE_PROFORMA
Proforma invoice.
const TYPE_SITUATION
Situation invoice.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_STANDARD
Standard invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const STATUS_CLOSED
Classified paid.
Class to manage invoice templates.
Class to manage payments for supplier invoices.
Class ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
$date_start
Variables from include:
facturefourn_prepare_head(FactureFournisseur $object)
Prepare array with list of tabs.
dol_now($mode='gmt')
Return date for now.
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.