37 require
'../../main.inc.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_invoice/modules_facturefournisseur.php';
41 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture-rec.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
46 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
47 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
48 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
51 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
54 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
55 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
59 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
62 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
66 $langs->loadLangs(array(
'bills',
'compta',
'suppliers',
'companies',
'products',
'banks',
'admin'));
68 $langs->load(
'incoterm');
72 $socid =
GETPOST(
'socid',
'int');
73 $action =
GETPOST(
'action',
'aZ09');
76 $cancel =
GETPOST(
'cancel',
'alpha');
77 $lineid =
GETPOST(
'lineid',
'int');
78 $projectid =
GETPOST(
'projectid',
'int');
79 $origin =
GETPOST(
'origin',
'alpha');
80 $originid =
GETPOST(
'originid',
'int');
81 $fac_recid =
GETPOST(
'fac_rec',
'int');
82 $rank = (
GETPOST(
'rank',
'int') > 0) ?
GETPOST(
'rank',
'int') : -1;
85 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
86 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
87 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
90 $hookmanager->initHooks(array(
'invoicesuppliercard',
'globalcard'));
96 $extrafields->fetch_name_optionals_label($object->table_element);
99 if ($id > 0 || !empty($ref)) {
100 $ret = $object->fetch($id, $ref);
104 $ret = $object->fetch_thirdparty();
112 if (!empty($user->socid)) {
113 $socid = $user->socid;
116 $result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture',
'fk_soc',
'rowid', $isdraft);
119 $usercanread = ($user->rights->fournisseur->facture->lire || $user->rights->supplier_invoice->lire);
120 $usercancreate = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
121 $usercandelete = ($user->rights->fournisseur->facture->supprimer || $user->rights->supplier_invoice->supprimer);
124 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->validate)));
125 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->fournisseur->supplier_invoice_advance->send);
128 $permissionnote = $usercancreate;
129 $permissiondellink = $usercancreate;
130 $permissiontoedit = $usercancreate;
131 $permissiontoadd = $usercancreate;
141 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
146 if (empty($reshook)) {
147 $backurlforlist = DOL_URL_ROOT.
'/fourn/facture/list.php';
149 if (empty($backtopage) || ($cancel && empty($id))) {
150 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
151 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
152 $backtopage = $backurlforlist;
154 $backtopage = DOL_URL_ROOT.
'/fourn/facture/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
160 if (!empty($backtopageforcancel)) {
161 header(
"Location: ".$backtopageforcancel);
163 } elseif (!empty($backtopage)) {
164 header(
"Location: ".$backtopage);
170 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
172 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
174 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
177 if (
GETPOST(
'linkedOrder') && empty($cancel) && $id > 0) {
179 $object->fetch_thirdparty();
180 $result = $object->add_object_linked(
'order_supplier',
GETPOST(
'linkedOrder'));
184 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
187 if (
GETPOST(
'newsupplierref',
'alphanohtml')) {
188 $objectutil->ref_supplier =
GETPOST(
'newsupplierref',
'alphanohtml');
192 $result = $objectutil->createFromClone($user, $id);
194 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
197 $langs->load(
"errors");
201 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
202 $idwarehouse =
GETPOST(
'idwarehouse');
205 $object->fetch_thirdparty();
207 $qualified_for_stock_change = 0;
208 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
209 $qualified_for_stock_change = $object->hasProductsOrServices(2);
211 $qualified_for_stock_change = $object->hasProductsOrServices(1);
215 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
216 $langs->load(
"stocks");
217 if (!$idwarehouse || $idwarehouse == -1) {
219 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
225 $result = $object->validate($user,
'', $idwarehouse);
230 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
231 $outputlangs = $langs;
234 $newlang =
GETPOST(
'lang_id',
'aZ09');
237 $newlang = $object->thirdparty->default_lang;
239 if (!empty($newlang)) {
241 $outputlangs->setDefaultLang($newlang);
243 $model = $object->model_pdf;
244 $ret = $object->fetch($id);
246 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
253 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
255 $object->fetch_thirdparty();
257 $isErasable = $object->is_erasable();
259 if (($usercandelete && $isErasable > 0) || ($usercancreate && $isErasable == 1)) {
260 $result = $object->delete($user);
262 header(
'Location: list.php?restore_lastsearch_values=1');
268 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
270 $result = $object->deleteline($lineid);
273 $object->line_order(
true);
290 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
297 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
300 $result = $discount->fetch(
GETPOST(
"discountid"));
301 $discount->unlink_invoice();
302 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercancreate) {
304 $result = $object->setPaid($user);
308 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes') {
311 $close_code =
GETPOST(
"close_code",
'restricthtml');
312 $close_note =
GETPOST(
"close_note",
'restricthtml');
314 $result = $object->setPaid($user, $close_code, $close_note);
319 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
321 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes') {
324 $close_code =
GETPOST(
"close_code",
'restricthtml');
325 $close_note =
GETPOST(
"close_note",
'restricthtml');
327 $result = $object->setCanceled($user, $close_code, $close_note);
332 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
337 if ($action ==
'setref_supplier' && $usercancreate) {
338 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alpha');
340 if ($object->update($user) < 0) {
344 $outputlangs = $langs;
347 $newlang =
GETPOST(
'lang_id',
'aZ09');
350 $newlang = $object->thirdparty->default_lang;
352 if (!empty($newlang)) {
354 $outputlangs->setDefaultLang($newlang);
356 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
357 $ret = $object->fetch($object->id);
358 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
364 if ($action ==
'setconditions' && $usercancreate) {
366 $object->cond_reglement_code = 0;
367 $object->cond_reglement_id = 0;
374 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
382 $old_date_echeance = $object->date_echeance;
383 $new_date_echeance = $object->calculate_date_lim_reglement();
384 if ($new_date_echeance > $old_date_echeance) {
385 $object->date_echeance = $new_date_echeance;
387 if ($object->date_echeance < $object->date) {
388 $object->date_echeance = $object->date;
390 $result = $object->update($user);
402 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm')) {
404 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
405 } elseif ($action ==
'setmode' && $usercancreate) {
407 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
408 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
410 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
411 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
413 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx',
'alpha')),
GETPOST(
'calculation_mode',
'int'));
414 } elseif ($action ==
'setbankaccount' && $usercancreate) {
416 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
420 if ($action ==
'settransportmode' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
422 $result = $object->setTransportMode(
GETPOST(
'transport_mode_id',
'int'));
423 } elseif ($action ==
'setlabel' && $usercancreate) {
426 $object->label =
GETPOST(
'label');
427 $result = $object->update($user);
431 } elseif ($action ==
'setdatef' && $usercancreate) {
433 if ($newdate > (
dol_now(
'tzuserrel') + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
434 if (empty($conf->global->INVOICE_MAX_FUTURE_DELAY)) {
435 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
437 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
443 $object->date = $newdate;
444 $date_echence_calc = $object->calculate_date_lim_reglement();
445 if (!empty($object->date_echeance) && $object->date_echeance < $date_echence_calc) {
446 $object->date_echeance = $date_echence_calc;
448 if ($object->date_echeance && $object->date_echeance < $object->date) {
449 $object->date_echeance = $object->date;
452 $result = $object->update($user);
456 } elseif ($action ==
'setdate_lim_reglement' && $usercancreate) {
458 $object->date_echeance =
dol_mktime(12, 0, 0,
GETPOST(
'date_lim_reglementmonth',
'int'),
GETPOST(
'date_lim_reglementday',
'int'),
GETPOST(
'date_lim_reglementyear',
'int'));
459 if (!empty($object->date_echeance) && $object->date_echeance < $object->date) {
460 $object->date_echeance = $object->date;
461 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
463 $result = $object->update($user);
467 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
469 if (
GETPOST(
"remise_id",
"int")) {
470 $ret = $object->fetch($id);
472 $result = $object->insert_discount(
GETPOST(
"remise_id",
"int"));
481 if (
GETPOST(
"remise_id_for_payment",
"int")) {
482 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
484 $discount->fetch(
GETPOST(
"remise_id_for_payment",
"int"));
491 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
495 $result = $discount->link_to_invoice(0, $id);
502 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
503 $outputlangs = $langs;
506 $newlang =
GETPOST(
'lang_id',
'aZ09');
509 $newlang = $object->thirdparty->default_lang;
511 if (!empty($newlang)) {
513 $outputlangs->setDefaultLang($newlang);
515 $ret = $object->fetch($id);
517 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
522 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
525 $object->fetch_thirdparty();
530 $result = $discountcheck->fetch(0, 0, $object->id);
542 $amount_ht = $amount_tva = $amount_ttc = array();
543 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
547 foreach ($object->lines as $line) {
548 if ($line->product_type < 9 && $line->total_ht != 0) {
549 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
551 $amount_ht[$keyforvatrate] += $line->total_ht;
552 $amount_tva[$keyforvatrate] += $line->total_tva;
553 $amount_ttc[$keyforvatrate] += $line->total_ttc;
554 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
555 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
556 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
563 $alreadypaid = $object->getSommePaiement();
564 if ($alreadypaid && abs($alreadypaid) < abs($object->total_ttc)) {
565 $ratio = abs(($object->total_ttc - $alreadypaid) / $object->total_ttc);
566 foreach ($amount_ht as $vatrate => $val) {
567 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
568 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
569 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
570 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
571 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
572 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
581 $discount->description =
'(CREDIT_NOTE)';
583 $discount->description =
'(DEPOSIT)';
585 $discount->description =
'(EXCESS PAID)';
587 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
589 $discount->discount_type = 1;
590 $discount->fk_soc = $object->socid;
591 $discount->fk_invoice_supplier_source = $object->id;
599 $sql =
'SELECT SUM(pf.amount) as total_paiements';
600 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'paiementfourn as p';
601 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN ('.
getEntity(
'c_paiement').
')';
602 $sql .=
' WHERE pf.fk_facturefourn = '.((int) $object->id);
603 $sql .=
' AND pf.fk_paiementfourn = p.rowid';
604 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
606 $resql = $db->query($sql);
611 $res = $db->fetch_object(
$resql);
612 $total_paiements = $res->total_paiements;
615 $total_creditnote_and_deposit = 0;
616 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
617 $sql .=
" re.description, re.fk_invoice_supplier_source";
618 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
619 $sql .=
" WHERE fk_invoice_supplier = ".((int) $object->id);
620 $resql = $db->query($sql);
622 while ($obj = $db->fetch_object(
$resql)) {
623 $total_creditnote_and_deposit += $obj->amount_ttc;
629 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object->total_ttc;
630 $discount->amount_tva = 0;
631 $discount->tva_tx = 0;
632 $discount->vat_src_code =
'';
634 $result = $discount->create($user);
640 foreach ($amount_ht as $tva_tx => $xxx) {
641 $discount->amount_ht = abs($amount_ht[$tva_tx]);
642 $discount->amount_tva = abs($amount_tva[$tva_tx]);
643 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
644 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
645 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
646 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
651 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
652 $vat_src_code = $reg[1];
653 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
656 $discount->tva_tx = abs($tva_tx);
657 $discount->vat_src_code = $vat_src_code;
659 $result = $discount->create($user);
670 $result = $object->setPaid($user);
685 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate) {
690 $result = $paiementfourn->fetch(
GETPOST(
'paiement_id'));
692 $result = $paiementfourn->delete();
693 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
699 } elseif ($action ==
'add' && $usercancreate) {
702 $object->socid =
GETPOST(
'socid',
'int');
704 $selectedLines =
GETPOST(
'toselect',
'array');
711 $ret = $extrafields->setOptionalsFromPost(
null, $object);
724 if (
GETPOST(
'type',
'int') ===
'') {
725 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
730 if (empty($dateinvoice)) {
731 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
733 $_GET[
'socid'] = $_POST[
'socid'];
735 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
741 if (!(
GETPOST(
'fac_replacement',
'int') > 0)) {
743 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
748 $result = $object->fetch(
GETPOST(
'fac_replacement',
'int'));
749 $object->fetch_thirdparty();
751 $object->ref =
GETPOST(
'ref',
'alphanohtml');
752 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alpha');
753 $object->socid =
GETPOST(
'socid',
'int');
754 $object->libelle =
GETPOST(
'label',
'alphanohtml');
755 $object->date = $dateinvoice;
756 $object->date_echeance = $datedue;
757 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
758 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
759 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
760 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
761 $object->fk_account =
GETPOST(
'fk_account',
'int');
762 $object->fk_project = ($tmpproject > 0) ? $tmpproject :
null;
763 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
764 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
765 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
766 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
767 $object->transport_mode_id =
GETPOST(
'transport_mode_id',
'int');
770 $object->fk_facture_source =
GETPOST(
'fac_replacement',
'int');
773 $id = $object->createFromCurrent($user);
783 $sourceinvoice =
GETPOST(
'fac_avoir',
'int');
784 if (!($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
786 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
788 if (
GETPOST(
'socid',
'int') < 1) {
789 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
794 if (empty($dateinvoice)) {
795 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
797 $_GET[
'socid'] = $_POST[
'socid'];
799 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
805 if (!
GETPOST(
'ref_supplier')) {
806 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplier')),
null,
'errors');
808 $_GET[
'socid'] = $_POST[
'socid'];
813 $tmpproject =
GETPOST(
'projectid',
'int');
816 $object->ref =
GETPOST(
'ref',
'alphanohtml');
817 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
818 $object->socid =
GETPOST(
'socid',
'int');
819 $object->libelle =
GETPOST(
'label',
'alphanohtml');
820 $object->label =
GETPOST(
'label',
'alphanohtml');
821 $object->date = $dateinvoice;
822 $object->date_echeance = $datedue;
823 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
824 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
825 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
826 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
827 $object->fk_account =
GETPOST(
'fk_account',
'int');
828 $object->fk_project = ($tmpproject > 0) ? $tmpproject :
null;
829 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
830 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
831 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
832 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
833 $object->transport_mode_id =
GETPOST(
'transport_mode_id',
'int');
836 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
839 $id = $object->create($user);
845 if (
GETPOST(
'invoiceAvoirWithLines',
'int') == 1 && $id > 0) {
847 if ($facture_source->fetch($object->fk_facture_source) > 0) {
850 foreach ($facture_source->lines as $line) {
852 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
856 $line->fk_facture_fourn = $object->id;
857 $line->fk_parent_line = $fk_parent_line;
859 $line->subprice = -$line->subprice;
860 $line->pa_ht = -$line->pa_ht;
861 $line->total_ht = -$line->total_ht;
862 $line->total_tva = -$line->total_tva;
863 $line->total_ttc = -$line->total_ttc;
864 $line->total_localtax1 = -$line->total_localtax1;
865 $line->total_localtax2 = -$line->total_localtax2;
867 $result = $line->insert();
869 $object->lines[] = $line;
872 if ($result > 0 && $line->product_type == 9) {
873 $fk_parent_line = $result;
877 $object->update_price(1);
881 if (
GETPOST(
'invoiceAvoirWithPaymentRestAmount',
'int') == 1 && $id > 0) {
883 if ($facture_source->fetch($object->fk_facture_source) > 0) {
884 $totalpaid = $facture_source->getSommePaiement();
885 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
886 $totaldeposits = $facture_source->getSumDepositsUsed();
887 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
889 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 0, 0, 0, 1, 0, 0,
'',
'',
'TTC');
895 if (empty($dateinvoice)) {
897 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
899 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
906 $object->socid =
GETPOST(
'socid',
'int');
907 $object->type =
GETPOST(
'type',
'alphanohtml');
908 $object->ref =
GETPOST(
'ref',
'alphanohtml');
909 $object->date = $dateinvoice;
910 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
911 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
912 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
913 $object->model_pdf =
GETPOST(
'model',
'alphanohtml');
914 $object->fk_project =
GETPOST(
'projectid',
'int');
915 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
916 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
917 $object->fk_account =
GETPOST(
'fk_account',
'int');
921 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
922 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
923 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
924 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
927 $object->fac_rec = $fac_recid;
929 $fac_rec->fetch($object->fac_rec);
930 $fac_rec->fetch_lines();
931 $object->lines = $fac_rec->lines;
933 $id = $object->create($user);
937 if (
GETPOST(
'socid',
'int') < 1) {
938 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
943 if (empty($dateinvoice)) {
944 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
946 $_GET[
'socid'] = $_POST[
'socid'];
948 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
954 if (!
GETPOST(
'ref_supplier')) {
955 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplier')),
null,
'errors');
957 $_GET[
'socid'] = $_POST[
'socid'];
962 $tmpproject =
GETPOST(
'projectid',
'int');
965 $object->socid =
GETPOST(
'socid',
'int');
966 $object->type =
GETPOST(
'type',
'alphanohtml');
967 $object->ref =
GETPOST(
'ref',
'alphanohtml');
968 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
969 $object->socid =
GETPOST(
'socid',
'int');
970 $object->libelle =
GETPOST(
'label',
'alphanohtml');
971 $object->label =
GETPOST(
'label',
'alphanohtml');
972 $object->date = $dateinvoice;
973 $object->date_echeance = $datedue;
974 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
975 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
976 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
977 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
978 $object->fk_account =
GETPOST(
'fk_account',
'int');
979 $object->fk_project = ($tmpproject > 0) ? $tmpproject :
null;
980 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
981 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
982 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
983 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
984 $object->transport_mode_id =
GETPOST(
'transport_mode_id');
987 if (empty($object->date_echeance)) {
988 $object->date_echeance = $object->calculate_date_lim_reglement();
991 $object->fetch_thirdparty();
994 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
996 $element = $subelement =
GETPOST(
'origin',
'alpha');
1004 if ($element ==
'order') {
1005 $element = $subelement =
'commande';
1007 if ($element ==
'propal') {
1008 $element =
'comm/propal'; $subelement =
'propal';
1010 if ($element ==
'contract') {
1011 $element = $subelement =
'contrat';
1013 if ($element ==
'order_supplier') {
1014 $element =
'fourn'; $subelement =
'fournisseur.commande';
1016 if ($element ==
'project') {
1017 $element =
'projet';
1019 $object->origin =
GETPOST(
'origin',
'alpha');
1020 $object->origin_id =
GETPOST(
'originid',
'int');
1023 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
1024 $classname = ucfirst($subelement);
1025 if ($classname ==
'Fournisseur.commande') {
1026 $classname =
'CommandeFournisseur';
1028 $objectsrc =
new $classname($db);
1029 $objectsrc->fetch($originid);
1030 $objectsrc->fetch_thirdparty();
1032 if (!empty($object->origin) && !empty($object->origin_id)) {
1033 $object->linkedObjectsIds[$object->origin] = $object->origin_id;
1037 if ($object->origin ==
'reception') {
1038 $objectsrc->fetchObjectLinked();
1040 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1041 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1042 $object->linkedObjectsIds[
'order_supplier'] = $value;
1047 $id = $object->create($user);
1051 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
1052 $classname = ucfirst($subelement);
1053 if ($classname ==
'Fournisseur.commande') {
1054 $classname =
'CommandeFournisseur';
1056 $srcobject =
new $classname($db);
1058 $result = $srcobject->fetch(
GETPOST(
'originid',
'int'));
1061 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1066 $amountdeposit = array();
1067 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)) {
1068 if ($typeamount ==
'amount') {
1069 $amount = $valuedeposit;
1071 $amount = $srcobject->total_ttc * ($valuedeposit / 100);
1074 $TTotalByTva = array();
1075 foreach ($srcobject->lines as &$line) {
1076 if (!empty($line->special_code)) {
1079 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1082 foreach ($TTotalByTva as $tva => &$total) {
1083 $coef = $total / $srcobject->total_ttc;
1084 $am = $amount * $coef;
1085 $amount_ttc_diff += $am;
1086 $amountdeposit[$tva] += $am / (1 + $tva / 100);
1089 if ($typeamount ==
'amount') {
1090 $amountdeposit[0] = $valuedeposit;
1091 } elseif ($typeamount ==
'variable') {
1094 $lines = $srcobject->lines;
1095 $numlines = count($lines);
1096 for ($i = 0; $i < $numlines; $i++) {
1098 if (empty($lines[$i]->qty)) {
1101 if (!empty($lines[$i]->special_code)) {
1105 $totalamount += $lines[$i]->total_ht;
1106 $tva_tx = $lines[$i]->tva_tx;
1107 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $valuedeposit) / 100;
1111 if ($totalamount == 0) {
1112 $amountdeposit[0] = 0;
1120 $amount_ttc_diff = $amountdeposit[0];
1123 foreach ($amountdeposit as $tva => $amount) {
1124 if (empty($amount)) {
1129 'amount' =>
'FixAmount',
1130 'variable' =>
'VarAmount'
1132 $descline =
'(DEPOSIT)';
1134 if ($typeamount ==
'amount') {
1135 $descline .=
' ('.price($valuedeposit,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
')';
1136 } elseif ($typeamount ==
'variable') {
1137 $descline .=
' ('.$valuedeposit.
'%)';
1140 $descline .=
' - '.$srcobject->ref;
1141 $result = $object->addline(
1148 (empty($conf->global->INVOICE_PRODUCTID_DEPOSIT) ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT),
1153 $lines[$i]->info_bits,
1163 $lines[$i]->special_code,
1170 $diff = $object->total_ttc - $amount_ttc_diff;
1172 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0) {
1173 $object->fetch_lines();
1174 $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100);
1175 $object->updateline(
1176 $object->lines[0]->id,
1177 $object->lines[0]->desc,
1179 $object->lines[0]->tva_tx,
1180 $object->lines[0]->localtax1_tx,
1181 $object->lines[0]->localtax2_tx,
1182 $object->lines[0]->qty,
1183 $object->lines[0]->fk_product,
1185 $object->lines[0]->info_bits,
1186 $object->lines[0]->product_type,
1187 $object->lines[0]->remise_percent,
1189 $object->lines[0]->date_start,
1190 $object->lines[0]->date_end,
1198 } elseif ($result > 0) {
1199 $lines = $srcobject->lines;
1200 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1201 $srcobject->fetch_lines();
1202 $lines = $srcobject->lines;
1205 $num = count($lines);
1206 for ($i = 0; $i < $num; $i++) {
1207 if (!in_array($lines[$i]->
id, $selectedLines)) {
1211 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
1212 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1215 if (method_exists($lines[$i],
'fetch_optionals')) {
1216 $lines[$i]->fetch_optionals();
1221 $date_start = $lines[$i]->date_debut_prevue;
1222 if ($lines[$i]->date_debut_reel) {
1223 $date_start = $lines[$i]->date_debut_reel;
1225 if ($lines[$i]->date_start) {
1226 $date_start = $lines[$i]->date_start;
1228 $date_end = $lines[$i]->date_fin_prevue;
1229 if ($lines[$i]->date_fin_reel) {
1230 $date_end = $lines[$i]->date_fin_reel;
1232 if ($lines[$i]->date_end) {
1233 $date_end = $lines[$i]->date_end;
1237 $object->special_code = $lines[$i]->special_code;
1240 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
1242 $pu_currency = $lines[$i]->multicurrency_subprice;
1244 $pu = $lines[$i]->subprice;
1249 $result = $object->addline(
1253 $lines[$i]->localtax1_tx,
1254 $lines[$i]->localtax2_tx,
1256 $lines[$i]->fk_product,
1257 $lines[$i]->remise_percent,
1261 $lines[$i]->info_bits,
1266 $lines[$i]->array_options,
1267 $lines[$i]->fk_unit,
1270 $lines[$i]->ref_supplier,
1271 $lines[$i]->special_code
1281 $object->fetch_lines();
1288 } elseif (!$error) {
1289 $id = $object->create($user);
1298 $langs->load(
"errors");
1303 $_GET[
'socid'] = $_POST[
'socid'];
1307 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1308 $outputlangs = $langs;
1309 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1316 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1319 } elseif ($action ==
'updateline' && $usercancreate) {
1323 if (! $object->fetch($id) > 0) {
1326 $object->fetch_thirdparty();
1329 $tva_tx = str_replace(
'*',
'', $tva_tx);
1331 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_subprice') !=
'') {
1333 $price_base_type =
'HT';
1336 $price_base_type =
'TTC';
1339 if (
GETPOST(
'productid') > 0) {
1341 if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
1343 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1348 $prod->fetch(
GETPOST(
'productid'));
1349 $label = $prod->description;
1350 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1351 $label =
GETPOST(
'product_desc',
'restricthtml');
1354 $type = $prod->type;
1356 $label =
GETPOST(
'product_desc',
'restricthtml');
1365 if (preg_match(
'/\*/', $tva_tx)) {
1370 $tva_tx = str_replace(
'*',
'', $tva_tx);
1371 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1372 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1378 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1379 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1381 if (is_array($extralabelsline)) {
1382 foreach ($extralabelsline as $key => $value) {
1383 unset($_POST[
"options_".$key]);
1387 $result = $object->updateline(
1409 unset($_POST[
'label']);
1410 unset($_POST[
'fourn_ref']);
1411 unset($_POST[
'date_starthour']);
1412 unset($_POST[
'date_startmin']);
1413 unset($_POST[
'date_startsec']);
1414 unset($_POST[
'date_startday']);
1415 unset($_POST[
'date_startmonth']);
1416 unset($_POST[
'date_startyear']);
1417 unset($_POST[
'date_endhour']);
1418 unset($_POST[
'date_endmin']);
1419 unset($_POST[
'date_endsec']);
1420 unset($_POST[
'date_endday']);
1421 unset($_POST[
'date_endmonth']);
1422 unset($_POST[
'date_endyear']);
1423 unset($_POST[
'price_ttc']);
1424 unset($_POST[
'price_ht']);
1431 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') && $usercancreate) {
1433 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1434 $vat_rate = str_replace(
'*',
'', $vat_rate);
1435 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1436 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1437 foreach ($object->lines as $line) {
1438 $result = $object->updateline($line->id, $line->desc, $line->subprice, $vat_rate, $localtax1_rate, $localtax2_rate, $line->qty, $line->fk_product,
'HT', $line->info_bits, $line->product_type, $line->remise_percent, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier, $line->rang);
1440 } elseif ($action ==
'addline' && $usercancreate) {
1444 $ret = $object->fetch($id);
1449 $ret = $object->fetch_thirdparty();
1451 $langs->load(
'errors');
1460 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1461 if ($prod_entry_mode ==
'free') {
1464 $idprod =
GETPOST(
'idprod',
'int');
1472 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
1476 if (empty($remise_percent)) {
1477 $remise_percent = 0;
1481 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1482 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
1484 if (is_array($extralabelsline)) {
1486 foreach ($extralabelsline as $key => $value) {
1487 unset($_POST[
"options_".$key]);
1491 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
1492 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1495 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
1496 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
1499 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
1500 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
1503 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
1504 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
1507 if (!
GETPOST(
'qty',
'alpha')) {
1508 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1512 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
1513 if ($combinations =
GETPOST(
'combinations',
'array')) {
1517 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1518 $idprod = $res->fk_product_child;
1520 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
1526 if ($prod_entry_mode !=
'free' && empty($error)) {
1530 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
1535 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
1537 $res = $productsupplier->fetch($idprod);
1540 if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) {
1542 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1543 if ($productsupplier->fourn_socid != $socid) {
1544 $productsupplier->ref_supplier =
'';
1547 $fksoctosearch = $object->thirdparty->id;
1548 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1550 } elseif (
GETPOST(
'idprodfournprice',
'alpha') > 0) {
1551 $qtytosearch = $qty;
1553 $idprod = $productsupplier->get_buyprice(
GETPOST(
'idprodfournprice',
'alpha'), $qtytosearch);
1554 $res = $productsupplier->fetch($idprod);
1558 $label = $productsupplier->label;
1560 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1561 $outputlangs = $langs;
1563 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1564 $newlang =
GETPOST(
'lang_id',
'aZ09');
1566 if (empty($newlang)) {
1567 $newlang = $object->thirdparty->default_lang;
1569 if (!empty($newlang)) {
1570 $outputlangs =
new Translate(
"", $conf);
1571 $outputlangs->setDefaultLang($newlang);
1573 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->description;
1575 $desc = $productsupplier->description;
1578 if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
1579 $desc = $productsupplier->desc_supplier;
1583 if (trim($product_desc) == trim($desc) && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
1586 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
1587 $desc = $product_desc;
1589 if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
1590 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
1593 $ref_supplier = $productsupplier->ref_supplier;
1597 $tva_tx =
get_default_tva($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
1598 $tva_npr =
get_default_npr($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
1600 if (empty($tva_tx)) {
1603 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
1604 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
1606 $type = $productsupplier->type;
1607 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'price_ht_devise') !=
'') {
1608 $price_base_type =
'HT';
1610 $pu_devise =
price2num($price_ht_devise,
'CU');
1611 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'price_ttc_devise') !=
'') {
1612 $price_base_type =
'TTC';
1614 $pu_devise =
price2num($price_ttc_devise,
'CU');
1616 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
1617 if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) {
1618 $pu = $productsupplier->fourn_pu;
1621 $pu = $productsupplier->fourn_pu;
1622 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
1630 $result = $object->addline(
1645 min($rank, count($object->lines) + 1),
1648 $productsupplier->fk_unit,
1651 GETPOST(
'fourn_ref',
'alpha'),
1655 if ($idprod == -99 || $idprod == 0) {
1658 $langs->load(
"errors");
1659 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
1661 if ($idprod == -1) {
1664 $langs->load(
"errors");
1665 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
1667 } elseif (empty($error)) {
1668 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1669 $tva_tx = str_replace(
'*',
'', $tva_tx);
1670 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1671 $desc = $product_desc;
1673 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
1675 $fk_unit =
GETPOST(
'units',
'alpha');
1677 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1682 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1683 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1685 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'price_ht_devise') !=
'') {
1689 $pu_ht =
price2num($pu_ttc / (1 + ($tva_tx / 100)),
'MU');
1691 $price_base_type =
'HT';
1692 $pu_devise =
price2num($price_devise,
'CU');
1694 $result = $object->addline($product_desc, $pu_ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $date_start, $date_end, 0, $tva_npr, $price_base_type, $type, -1, 0, $array_options, $fk_unit, 0, $pu_devise, $ref_supplier);
1698 if (!$error && $result > 0) {
1702 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1703 $outputlangs = $langs;
1706 $newlang =
GETPOST(
'lang_id',
'aZ09');
1709 $newlang = $object->thirdparty->default_lang;
1711 if (!empty($newlang)) {
1712 $outputlangs =
new Translate(
"", $conf);
1713 $outputlangs->setDefaultLang($newlang);
1715 $model = $object->model_pdf;
1716 $ret = $object->fetch($id);
1718 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1724 unset($_POST [
'prod_entry_mode']);
1726 unset($_POST[
'qty']);
1727 unset($_POST[
'type']);
1728 unset($_POST[
'remise_percent']);
1729 unset($_POST[
'pu']);
1730 unset($_POST[
'price_ht']);
1731 unset($_POST[
'multicurrency_price_ht']);
1732 unset($_POST[
'price_ttc']);
1733 unset($_POST[
'fourn_ref']);
1734 unset($_POST[
'tva_tx']);
1735 unset($_POST[
'label']);
1736 unset($localtax1_tx);
1737 unset($localtax2_tx);
1738 unset($_POST[
'np_marginRate']);
1739 unset($_POST[
'np_markRate']);
1740 unset($_POST[
'dp_desc']);
1741 unset($_POST[
'idprodfournprice']);
1742 unset($_POST[
'units']);
1744 unset($_POST[
'date_starthour']);
1745 unset($_POST[
'date_startmin']);
1746 unset($_POST[
'date_startsec']);
1747 unset($_POST[
'date_startday']);
1748 unset($_POST[
'date_startmonth']);
1749 unset($_POST[
'date_startyear']);
1750 unset($_POST[
'date_endhour']);
1751 unset($_POST[
'date_endmin']);
1752 unset($_POST[
'date_endsec']);
1753 unset($_POST[
'date_endday']);
1754 unset($_POST[
'date_endmonth']);
1755 unset($_POST[
'date_endyear']);
1762 } elseif ($action ==
'classin' && $usercancreate) {
1763 $object->fetch($id);
1764 $result = $object->setProject($projectid);
1765 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
1767 $object->fetch($id);
1769 $totalpaid = $object->getSommePaiement();
1770 $resteapayer = $object->total_ttc - $totalpaid;
1773 $ventilExportCompta = $object->getVentilExportCompta();
1775 if (!$ventilExportCompta) {
1778 $idwarehouse =
GETPOST(
'idwarehouse');
1780 $object->fetch_thirdparty();
1782 $qualified_for_stock_change = 0;
1783 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1784 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1786 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1790 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
1791 $langs->load(
"stocks");
1792 if (!$idwarehouse || $idwarehouse == -1) {
1794 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1799 $object->setDraft($user, $idwarehouse);
1802 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1803 $outputlangs = $langs;
1806 $newlang =
GETPOST(
'lang_id',
'aZ09');
1809 $newlang = $object->thirdparty->default_lang;
1811 if (!empty($newlang)) {
1812 $outputlangs =
new Translate(
"", $conf);
1813 $outputlangs->setDefaultLang($newlang);
1815 $model = $object->model_pdf;
1816 $ret = $object->fetch($id);
1818 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1827 } elseif ($action ==
'reopen' && $usercancreate) {
1829 $result = $object->fetch($id);
1832 $result = $object->setUnpaid($user);
1834 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
1843 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1846 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
1848 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
1849 $trackid =
'sinv'.$object->id;
1850 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1853 $upload_dir = $conf->fournisseur->facture->dir_output;
1854 $permissiontoadd = $usercancreate;
1855 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1858 if ($action ==
'calculate') {
1859 $calculationrule =
GETPOST(
'calculationrule');
1861 $object->fetch($id);
1862 $object->fetch_thirdparty();
1863 $result = $object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0, $object->thirdparty);
1869 if ($action ==
'update_extras') {
1873 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1881 $result = $object->insertExtraFields(
'BILL_SUPPLIER_MODIFY');
1889 $action =
'edit_extras';
1893 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1894 if ($action ==
'addcontact') {
1895 $result = $object->fetch($id);
1897 if ($result > 0 && $id > 0) {
1900 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1904 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1907 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1908 $langs->load(
"errors");
1909 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1914 } elseif ($action ==
'swapstatut') {
1916 if ($object->fetch($id)) {
1917 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1921 } elseif ($action ==
'deletecontact') {
1923 $object->fetch($id);
1924 $result = $object->delete_contact(
GETPOST(
"lineid",
'int'));
1927 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1943 $bankaccountstatic =
new Account($db);
1951 $title = $object->ref.
" - ".$langs->trans(
'Card');
1952 if ($action ==
'create') {
1953 $title = $langs->trans(
"NewSupplierInvoice");
1955 $help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
1959 if ($action ==
'create') {
1962 print
load_fiche_titre($langs->trans(
'NewSupplierInvoice'),
'',
'supplier_invoice');
1966 $currency_code = $conf->currency;
1969 if (
GETPOST(
'socid',
'int') > 0) {
1971 $societe->fetch(
GETPOST(
'socid',
'int'));
1972 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
1973 $currency_code = $societe->multicurrency_code;
1977 if (!empty($origin) && !empty($originid)) {
1979 $element = $subelement = $origin;
1981 if ($element ==
'project') {
1982 $projectid = $originid;
1983 $element =
'projet';
1987 if ($element ==
'order') {
1988 $element = $subelement =
'commande';
1990 if ($element ==
'propal') {
1991 $element =
'comm/propal'; $subelement =
'propal';
1993 if ($element ==
'contract') {
1994 $element = $subelement =
'contrat';
1996 if ($element ==
'order_supplier') {
1997 $element =
'fourn'; $subelement =
'fournisseur.commande';
2000 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
2001 $classname = ucfirst($subelement);
2002 if ($classname ==
'Fournisseur.commande') {
2003 $classname =
'CommandeFournisseur';
2005 $objectsrc =
new $classname($db);
2006 $objectsrc->fetch($originid);
2007 $objectsrc->fetch_thirdparty();
2009 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
2012 $soc = $objectsrc->thirdparty;
2013 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_supplier_id) ? $soc->cond_reglement_supplier_id : 0));
2014 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_supplier_id) ? $soc->mode_reglement_supplier_id : 0));
2015 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
2016 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_supplier_percent) ? $soc->remise_supplier_percent : 0));
2017 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
2018 $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'';
2019 $transport_mode_id = (!empty($objectsrc->transport_mode_id) ? $objectsrc->transport_mode_id : (!empty($soc->transport_mode_id) ? $soc->transport_mode_id : 0));
2022 if (!empty($objectsrc->multicurrency_code)) {
2023 $currency_code = $objectsrc->multicurrency_code;
2025 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
2026 $currency_tx = $objectsrc->multicurrency_tx;
2031 $dateinvoice = ($datetmp ==
'' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $datetmp);
2033 $datedue = ($datetmp ==
'' ?-1 : $datetmp);
2036 $objectsrc->fetch_optionals();
2037 $object->array_options = $objectsrc->array_options;
2039 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2040 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2041 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2042 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2044 $dateinvoice = ($datetmp ==
'' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $datetmp);
2046 $datedue = ($datetmp ==
'' ?-1 : $datetmp);
2048 if (
isModEnabled(
"multicurrency") && !empty($soc->multicurrency_code)) {
2049 $currency_code = $soc->multicurrency_code;
2054 if (empty($cond_reglement_id)) {
2055 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2059 if (empty($mode_reglement_id)) {
2060 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2063 $note_public = $object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($conf->global->FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM)) ? $objectsrc->note_public :
null));
2064 $note_private = $object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($conf->global->FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM)) ? $objectsrc->note_private :
null));
2066 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2067 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2068 print
'<input type="hidden" name="action" value="add">';
2069 if (!empty($societe->id) && $societe->id > 0) {
2070 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2072 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2073 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2074 if (!empty($currency_tx)) {
2075 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2080 print
'<table class="border centpercent">';
2083 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
2087 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2088 $invoice_predefined->fetch($fac_recid);
2092 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2095 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2096 $absolute_discount = $societe->getAvailableDiscounts(
'',
'', 0, 1);
2097 print $societe->getNomUrl(1,
'supplier');
2098 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2100 print
img_picto(
'',
'company').$form->select_company(empty($societe->id) ? 0 : $societe->id,
'socid',
'(s.fournisseur = 1 AND s.status = 1)',
'SelectThirdParty', 1, 0,
null, 0,
'minwidth175 widthcentpercentminusxx maxwidth500');
2102 if (!empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE)) {
2103 print
'<script type="text/javascript">
2104 $(document).ready(function() {
2105 $("#socid").change(function() {
2106 var socid = $(this).val();
2107 var fac_rec = $(\'#fac_rec\').val();
2108 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
2113 if ($fac_recid <= 0) {
2114 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>';
2120 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2121 $invoice_predefined->fetch($fac_recid);
2123 $dateinvoice = $invoice_predefined->date_when;
2124 if (empty($projectid)) {
2125 $projectid = $invoice_predefined->fk_project;
2127 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2128 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2129 $fk_account = $invoice_predefined->fk_account;
2130 $note_public = $invoice_predefined->note_public;
2131 $note_private = $invoice_predefined->note_private;
2133 if (!empty($invoice_predefined->multicurrency_code)) {
2134 $currency_code = $invoice_predefined->multicurrency_code;
2136 if (!empty($invoice_predefined->multicurrency_tx)) {
2137 $currency_tx = $invoice_predefined->multicurrency_tx;
2140 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2141 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2142 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2144 $resql = $db->query($sql);
2146 $num = $db->num_rows(
$resql);
2150 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2152 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2153 print
'<option value="0" selected></option>';
2155 $objp = $db->fetch_object(
$resql);
2156 print
'<option value="'.$objp->rowid.
'"';
2157 if ($fac_recid == $objp->rowid) {
2159 $exampletemplateinvoice->fetch($fac_recid);
2161 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2166 if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED)) {
2167 print
'<script type="text/javascript">
2168 $(document).ready(function() {
2169 $("#fac_rec").change(function() {
2170 console.log("We have changed the template invoice - Reload page");
2171 var fac_rec = $(this).val();
2172 var socid = $(\'#socid\').val();
2173 // For template invoice change, we must reuse data of template, not input already done, so we call a GET with action=create, not a POST submit.
2174 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
2188 print
'<tr><td class="fieldrequired">'.$langs->trans(
'RefSupplier').
'</td><td><input name="ref_supplier" value="'.(
GETPOSTISSET(
'ref_supplier') ?
GETPOST(
'ref_supplier') : (!empty($objectsrc->ref_supplier) ? $objectsrc->ref_supplier :
'')).
'" type="text"';
2189 if (!empty($societe->id) && $societe->id > 0) {
2195 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2197 print
'<div class="tagtable">'.
"\n";
2200 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2201 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOST(
'type',
'int')?
'' :
'checked').
'> ';
2202 $desc =
$form->textwithpicto($tmp.$langs->trans(
"InvoiceStandardAsk"), $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2204 print
'</div></div>';
2206 if (empty($origin) || ($origin ==
'order_supplier' && !empty($originid))) {
2208 if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) {
2209 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2210 $tmp=
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOST(
'type') == 3 ?
' checked' :
'') .
'> ';
2211 print
'<script type="text/javascript">
2212 jQuery(document).ready(function() {
2213 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2214 jQuery("#radio_standard").prop("checked", true);
2216 jQuery("#typedeposit, #valuedeposit").click(function() {
2217 jQuery("#radio_deposit").prop("checked", true);
2219 jQuery("#typedeposit").change(function() {
2220 console.log("We change type of down payment");
2221 jQuery("#radio_deposit").prop("checked", true);
2222 setRadioForTypeOfInvoice();
2224 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2225 setRadioForTypeOfInvoice();
2227 function setRadioForTypeOfInvoice() {
2228 console.log("Change radio");
2229 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2230 jQuery(".checkforselect").prop("disabled", true);
2231 jQuery(".checkforselect").prop("checked", false);
2233 jQuery(".checkforselect").prop("disabled", false);
2234 jQuery(".checkforselect").prop("checked", true);
2240 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2241 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2242 print
'<table class="nobordernopadding"><tr>';
2246 if ($origin ==
'order_supplier') {
2247 print
'<td class="nowrap" style="padding-left: 15px">';
2249 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2250 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2251 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2253 print
$form->selectarray(
'typedeposit', $arraylist,
GETPOST(
'typedeposit',
'aZ09'), 0, 0, 0,
'', 1);
2255 print
'<td class="nowrap" style="padding-left: 5px">';
2256 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' .
GETPOST(
'valuedeposit',
'int') .
'"/>';
2259 print
'</tr></table>';
2261 print
'</div></div>';
2330 if (empty($origin)) {
2331 if (!empty($societe->id) && $societe->id > 0) {
2333 if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) {
2335 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2342 foreach ($facids as $key => $valarray) {
2343 $newinvoice_static->id = $key;
2344 $newinvoice_static->ref = $valarray [
'ref'];
2345 $newinvoice_static->statut = $valarray [
'status'];
2346 $newinvoice_static->type = $valarray [
'type'];
2347 $newinvoice_static->paye = $valarray [
'paye'];
2349 $optionsav .=
'<option value="'.$key.
'"';
2350 if ($key ==
GETPOST(
'fac_avoir',
'int')) {
2351 $optionsav .=
' selected';
2354 $optionsav .= $newinvoice_static->ref;
2355 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
2356 $optionsav .=
'</option>';
2359 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2360 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
2361 if (!$optionsav && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
2362 $tmp .=
' disabled';
2366 print
'<script type="text/javascript">
2367 jQuery(document).ready(function() {
2368 if (! jQuery("#radio_creditnote").is(":checked"))
2370 jQuery("#credit_note_options").hide();
2372 jQuery("#radio_creditnote").click(function() {
2373 jQuery("#credit_note_options").show();
2375 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2376 jQuery("#credit_note_options").hide();
2380 $text = $tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
' ';
2382 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2384 $text .=
' disabled';
2388 $text .=
'<option value="-1"></option>';
2389 $text .= $optionsav;
2391 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
2393 $text .=
'</select>';
2394 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2397 print
'<div id="credit_note_options" class="clearboth">';
2398 print
' <input type="checkbox" name="invoiceAvoirWithLines" id="invoiceAvoirWithLines" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithPaymentRestAmount\').removeAttr(\'checked\'); }" '.(GETPOST(
'invoiceAvoirWithLines',
'int') > 0 ?
'checked' :
'').
' /> ';
2399 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
2400 print
'<br> <input type="checkbox" name="invoiceAvoirWithPaymentRestAmount" id="invoiceAvoirWithPaymentRestAmount" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithLines\').removeAttr(\'checked\'); }" '.(GETPOST(
'invoiceAvoirWithPaymentRestAmount',
'int') > 0 ?
'checked' :
'').
' /> ';
2401 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
2404 print
'</div></div>';
2407 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2408 if (empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
2409 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2411 $tmp=
'<input type="radio" name="type" id="radio_creditnote" value="2"> ';
2413 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
2414 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
2415 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2417 print
'</div></div>'.
"\n";
2425 if (!empty($societe->id) && $societe->id > 0) {
2427 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2429 $thirdparty = $societe;
2431 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2432 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2438 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth200" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
2441 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
2442 print
$form->selectDate($dateinvoice,
'',
'',
'',
'',
"add", 1, 1);
2446 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
2447 print
$form->selectDate($datedue,
'ech',
'',
'',
'',
"add", 1, 1);
2451 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2452 print
$form->getSelectConditionsPaiements(
GETPOSTISSET(
'cond_reglement_id') ?
GETPOST(
'cond_reglement_id',
'int') : $cond_reglement_id,
'cond_reglement_id');
2456 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2457 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2458 $form->select_types_paiements(
GETPOSTISSET(
'mode_reglement_id') ?
GETPOST(
'mode_reglement_id',
'int') : $mode_reglement_id,
'mode_reglement_id',
'DBIT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
2463 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2464 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes((
GETPOSTISSET(
'fk_account') ?
GETPOST(
'fk_account',
'alpha') : $fk_account),
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
2472 $langs->load(
'projects');
2473 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2474 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $societe->id : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
2475 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>';
2482 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
2483 print
'<td colspan="3" class="maxwidthonsmartphone">';
2484 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 :
''));
2491 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
2492 print
'<td class="maxwidthonsmartphone">';
2493 print
$form->selectMultiCurrency((
GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code),
'multicurrency_code');
2499 if ($fac_recid > 0) {
2500 $dateexample = $newdateinvoice ? $newdateinvoice : $dateinvoice;
2501 if (empty($dateexample)) {
2504 $substitutionarray = array(
2505 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
2506 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
2507 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
2508 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
2509 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
2510 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
2511 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
2512 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
2513 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
2514 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
2515 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
2518 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
2519 foreach ($substitutionarray as $key => $val) {
2520 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
2522 $htmltext .=
'</i>';
2527 $langs->loadLangs(array(
"intracommreport"));
2528 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
2529 $form->selectTransportMode(
GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
2533 if (empty($reshook)) {
2534 print $object->showOptionals($extrafields,
'create');
2538 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2540 $doleditor =
new DolEditor(
'note_public', (
GETPOSTISSET(
'note_public') ?
GETPOST(
'note_public',
'restricthtml') : $note_public),
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3,
'90%');
2541 print $doleditor->Create(1);
2547 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
2549 $doleditor =
new DolEditor(
'note_private', (
GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') : $note_private),
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3,
'90%');
2550 print $doleditor->Create(1);
2556 if (!empty($objectsrc) && is_object($objectsrc)) {
2557 print
"\n<!-- ".$classname.
" info -->";
2559 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2560 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2561 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2562 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2563 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2565 $txt = $langs->trans($classname);
2566 if ($classname ==
'CommandeFournisseur') {
2567 $langs->load(
'orders');
2568 $txt = $langs->trans(
"SupplierOrder");
2570 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
2572 $objectsrc->fetchObjectLinked($originid, $origin,
'',
'invoice_supplier');
2574 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
2577 if (is_array($invoice_supplier)) {
2578 $cntinvoice = count($invoice_supplier);
2580 if ($cntinvoice >= 1) {
2582 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
2587 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2588 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2589 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2590 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2593 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2594 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2596 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2599 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2600 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2601 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2607 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
2608 print $hookmanager->resPrint;
2615 print
$form->buttonsSaveCancel(
"CreateDraft");
2618 if (!empty($objectsrc) && is_object($objectsrc)) {
2621 $title = $langs->trans(
'ProductsAndServices');
2624 print
'<div class="div-table-responsive-no-min">';
2625 print
'<table class="noborder centpercent">';
2627 $objectsrc->printOriginLinesList(
'', $selectedLines);
2635 if ($id > 0 || !empty($ref)) {
2641 $productstatic =
new Product($db);
2643 $result = $object->fetch($id, $ref);
2645 $langs->load(
"errors");
2646 print $langs->trans(
"ErrorRecordNotFound");
2652 $result = $object->fetch_thirdparty();
2658 $societe = $object->thirdparty;
2660 $totalpaid = $object->getSommePaiement();
2661 $totalcreditnotes = $object->getSumCreditNotesUsed();
2662 $totaldeposits = $object->getSumDepositsUsed();
2670 $resteapayer =
price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
2673 $multicurrency_resteapayer = 0;
2675 $multicurrency_totalpaid = $object->getSommePaiement(1);
2676 $multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
2677 $multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
2678 $multicurrency_resteapayer =
price2num($object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
2682 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 && $object->multicurrency_code != $conf->currency) {
2683 $resteapayer =
price2num($multicurrency_resteapayer / $object->multicurrency_tx,
'MT');
2687 if ($object->paye) {
2690 $resteapayeraffiche = $resteapayer;
2692 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
2693 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2694 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2696 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2697 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2700 $absolute_discount = $societe->getAvailableDiscounts(
'', $filterabsolutediscount, 0, 1);
2701 $absolute_creditnote = $societe->getAvailableDiscounts(
'', $filtercreditnote, 0, 1);
2702 $absolute_discount =
price2num($absolute_discount,
'MT');
2703 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2708 $objectidnext = $object->getIdReplacingInvoice();
2711 $titre = $langs->trans(
'SupplierInvoice');
2718 if ($action ==
'converttoreduc') {
2721 $type_fac =
'ExcessPaid';
2723 $type_fac =
'CreditNote';
2725 $type_fac =
'Deposit';
2727 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
2728 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
2729 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
2733 if ($action ==
'clone') {
2735 $formquestion = array(
2736 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplier"),
'value' => $langs->trans(
"CopyOf").
' '.$object->ref_supplier),
2737 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
2740 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
2744 if ($action ==
'valid') {
2746 if (preg_match(
'/^[\(]?PROV/i', $object->ref) || empty($object->ref)) {
2748 $numref = $object->getNextNumRef($societe);
2750 $numref = $object->ref;
2757 $text = $langs->trans(
'ConfirmValidateBill', $numref);
2765 $formquestion = array();
2767 $qualified_for_stock_change = 0;
2768 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2769 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2771 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2774 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
2775 $langs->load(
"stocks");
2776 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2779 $warehouse_array = $warehouse->list_array();
2780 if (count($warehouse_array) == 1) {
2781 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
2782 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
2785 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
2787 $formquestion = array(
2788 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
2792 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
2797 if ($action ==
'edit') {
2798 $formquestion = array();
2800 $qualified_for_stock_change = 0;
2801 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2802 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2804 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2806 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
2807 $langs->load(
"stocks");
2808 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2811 $warehouse_array = $warehouse->list_array();
2812 if (count($warehouse_array) == 1) {
2813 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
2814 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
2817 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
2819 $formquestion = array(
2820 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
2823 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill', $object->ref),
'confirm_edit', $formquestion, 1, 1);
2827 if ($action ==
'paid' && ($resteapayer <= 0 || (!empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) && $resteapayer == $object->total_ttc))) {
2828 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill', $object->ref),
'confirm_paid',
'', 0, 1);
2831 if ($action ==
'paid' && $resteapayer > 0 && (empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $resteapayer != $object->total_ttc)) {
2835 $close[$i][
'code'] =
'discount_vat';
2837 $close[$i][
'code'] =
'badsupplier';
2839 $close[$i][
'code'] =
'other';
2843 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
2845 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
2847 $close[$i][
'label'] = $langs->trans(
"Other");
2851 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
2853 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
2855 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
2858 foreach ($close as $key => $val) {
2859 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
2863 $formquestion = array(
'text' => $langs->trans(
"ConfirmClassifyPaidPartiallyQuestion"), array(
'type' =>
'radio',
'name' =>
'close_code',
'label' => $langs->trans(
"Reason"),
'values' => $arrayreasons), array(
'type' =>
'text',
'name' =>
'close_note',
'label' => $langs->trans(
"Comment"),
'value' =>
'',
'morecss' =>
'minwidth300'));
2865 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially', $object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
2869 if ($action ==
'canceled') {
2871 $close[1][
'code'] =
'badsupplier';
2872 $close[2][
'code'] =
'abandon';
2874 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
2875 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
2877 $close[1][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier", $object->ref), $close[1][
'label'], 1);
2878 $close[2][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
2880 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
2881 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
2884 $formquestion = array(
'text' => $langs->trans(
"ConfirmCancelBillQuestion"), array(
'type' =>
'radio',
'name' =>
'close_code',
'label' => $langs->trans(
"Reason"),
'values' => $arrayreasons), array(
'type' =>
'text',
'name' =>
'close_note',
'label' => $langs->trans(
"Comment"),
'value' =>
'',
'morecss' =>
'minwidth300'));
2886 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill', $object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 250);
2890 if ($action ==
'delete') {
2891 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete',
'', 0, 1);
2893 if ($action ==
'deletepayment') {
2894 $payment_id =
GETPOST(
'paiement_id');
2895 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
2899 if ($action ==
'ask_deleteline') {
2900 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2905 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
2906 if (empty($reshook)) {
2908 } elseif ($reshook > 0) {
2918 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2920 $morehtmlref =
'<div class="refidno">';
2922 $morehtmlref .=
$form->editfieldkey(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'', 0, 1);
2923 $morehtmlref .=
$form->editfieldval(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
2925 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'supplier');
2926 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2927 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$object->thirdparty->id.
'&search_company='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
2931 $langs->load(
"projects");
2932 $morehtmlref .=
'<br>';
2933 if ($permissiontoadd) {
2934 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2935 if ($action !=
'classify') {
2936 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2938 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, ($action ==
'classify' ? 1 : 0), 0, 1,
'');
2940 if (!empty($object->fk_project)) {
2942 $proj->fetch($object->fk_project);
2943 $morehtmlref .= $proj->getNomUrl(1);
2945 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2950 $morehtmlref .=
'</div>';
2952 $object->totalpaid = $totalpaid;
2954 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2956 print
'<div class="fichecenter">';
2957 print
'<div class="fichehalfleft">';
2958 print
'<div class="underbanner clearboth"></div>';
2960 print
'<table class="border tableforfield centpercent">';
2963 print
'<tr><td class="titlefield">'.$langs->trans(
'Type').
'</td><td>';
2964 print
'<span class="badgeneutral">';
2965 print $object->getLibType();
2969 $facreplaced->fetch($object->fk_facture_source);
2970 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
2974 if ($object->fk_facture_source > 0) {
2975 $facusing->fetch($object->fk_facture_source);
2976 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
2978 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectedInvoiceNotFound").
'</span>';
2982 $facidavoir = $object->getListIdAvoirFromInvoice();
2983 if (count($facidavoir) > 0) {
2984 $invoicecredits = array();
2985 foreach ($facidavoir as $id) {
2987 $facavoir->fetch($id);
2988 $invoicecredits[] = $facavoir->getNomUrl(1);
2990 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
2993 if (isset($objectidnext) && $objectidnext > 0) {
2995 $facthatreplace->fetch($facidnext);
2996 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
3000 $result = $discount->fetch(0, 0, $object->id);
3002 print
' <span class="opacitymediumbycolor paddingleft">';
3003 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
3004 $s = str_replace(
'{s1}', $object->getLibType(1), $s);
3005 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
3007 print
'</span><br>';
3011 if ($object->fk_fac_rec_source > 0) {
3013 $result = $tmptemplate->fetch($object->fk_fac_rec_source);
3015 print
' <span class="opacitymediumbycolor paddingleft">';
3016 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->titre).
'</a>';
3017 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
3027 print
'<!-- Discounts -->'.
"\n";
3028 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
3031 $thirdparty = $societe;
3033 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?facid='.$object->id);
3034 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3040 print
'<td>'.$form->editfieldkey(
"Label",
'label', $object->label, $object, $usercancreate).
'</td>';
3041 print
'<td>'.$form->editfieldval(
"Label",
'label', $object->label, $object, $usercancreate).
'</td>';
3049 print
$form->editfieldkey(
"DateInvoice",
'datef', $object->datep, $object, $form_permission,
'datepicker');
3050 print
'</td><td colspan="3">';
3051 print
$form->editfieldval(
"Date",
'datef', $object->datep, $object, $form_permission,
'datepicker');
3055 $langs->load(
'bills');
3056 print
'<tr><td class="nowrap">';
3057 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3058 print $langs->trans(
'PaymentConditions');
3060 if ($action !=
'editconditions' && $form_permission) {
3061 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>';
3063 print
'</tr></table>';
3065 if ($action ==
'editconditions') {
3066 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
3068 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none');
3075 print
$form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', $object->date_echeance, $object, $form_permission,
'datepicker');
3077 print
$form->editfieldval(
"DateMaxPayment",
'date_lim_reglement', $object->date_echeance, $object, $form_permission,
'datepicker');
3078 if ($action !=
'editdate_lim_reglement' && $object->hasDelay()) {
3084 $langs->load(
'bills');
3085 print
'<tr><td class="nowrap">';
3086 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3087 print $langs->trans(
'PaymentMode');
3089 if ($action !=
'editmode' && $form_permission) {
3090 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>';
3092 print
'</tr></table>';
3094 if ($action ==
'editmode') {
3095 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3097 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
3106 print
'<table class="nobordernopadding" width="100%"><tr><td>';
3107 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
3109 if ($action !=
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT) {
3110 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencycode&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
3112 print
'</tr></table>';
3114 if ($action ==
'editmulticurrencycode') {
3115 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
3117 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
3122 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3125 print
'<table class="nobordernopadding centpercent"><tr><td>';
3126 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
3128 if ($action !=
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3129 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencyrate&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
3131 print
'</tr></table>';
3133 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
3134 if ($action ==
'actualizemulticurrencyrate') {
3137 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
3139 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
3140 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3141 print
'<div class="inline-block"> ';
3142 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
3152 print
'<tr><td class="nowrap">';
3153 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3154 print $langs->trans(
'BankAccount');
3156 if ($action !=
'editbankaccount' && $usercancreate) {
3157 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>';
3159 print
'</tr></table>';
3161 if ($action ==
'editbankaccount') {
3162 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
3164 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
3173 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3174 print $langs->trans(
'IncotermLabel');
3175 print
'<td><td class="right">';
3176 if ($usercancreate) {
3177 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
3181 print
'</td></tr></table>';
3184 if ($action !=
'editincoterm') {
3185 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
3187 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
3194 $langs->loadLangs(array(
"intracommreport"));
3196 print
'<table class="nobordernopadding centpercent"><tr><td>';
3197 print $langs->trans(
'IntracommReportTransportMode');
3199 if ($action !=
'editmode' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
3200 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit().
'</a></td>';
3202 print
'</tr></table>';
3205 if ($action ==
'editmode') {
3206 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->transport_mode_id,
'transport_mode_id', 1, 1);
3208 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->transport_mode_id,
'none');
3215 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
3220 print
'<div class="fichehalfright">';
3221 print
'<div class="underbanner clearboth"></div>';
3223 print
'<table class="border tableforfield centpercent">';
3225 if (
isModEnabled(
"multicurrency") && ($object->multicurrency_code != $conf->currency)) {
3227 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
3228 print
'<td class="nowrap right amountcard">'.price($object->multicurrency_total_ht,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
3232 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
3233 print
'<td class="nowrap right amountcard">'.price($object->multicurrency_total_tva,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
3237 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
3238 print
'<td class="nowrap right amountcard">'.price($object->multicurrency_total_ttc,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
3243 print
'<tr><td class="titlefield">'.$langs->trans(
'AmountHT').
'</td>';
3244 print
'<td class="nowrap right amountcard">'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3248 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td>';
3249 print
'<td class="nowrap right amountcard">';
3250 if (
GETPOST(
'calculationrule')) {
3251 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
3253 $calculationrule = (empty($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND) ?
'totalofround' :
'roundoftotal');
3255 if ($calculationrule ==
'totalofround') {
3256 $calculationrulenum = 1;
3258 $calculationrulenum = 2;
3261 if ($object->getVentilExportCompta() == 0) {
3262 $s =
'<span class="hideonsmartphone opacitymedium">'.$langs->trans(
"ReCalculate").
' </span>';
3263 $s .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=calculate&calculationrule=totalofround">'.$langs->trans(
"Mode1").
'</a>';
3265 $s .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=calculate&calculationrule=roundoftotal">'.$langs->trans(
"Mode2").
'</a>';
3266 print
'<div class="inline-block">';
3267 print
$form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum).
'<br>'.$langs->trans(
"CalculationRuleDescSupplier"), 2, 1,
img_picto(
'',
'help'),
'', 3,
'', 0,
'recalculate');
3268 print
' ';
3271 print
price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency);
3276 if ($societe->localtax1_assuj ==
"1") {
3277 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $societe->country_code).
'</td>';
3278 print
'<td class="nowrap right amountcard">'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3281 if ($societe->localtax2_assuj ==
"1") {
3282 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $societe->country_code).
'</td>';
3283 print
'<td class="nowrap right amountcard">'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3286 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td>';
3287 print
'<td colspan="3" class="nowrap right amountcard">'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3302 $nbrows = 9; $nbcols = 3;
3307 $nbrows++; $nbcols++;
3317 if ($societe->localtax1_assuj ==
"1") {
3320 if ($societe->localtax2_assuj ==
"1") {
3324 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
3325 $sql .=
' c.id as paiement_type, c.code as payment_code,';
3326 $sql .=
' pf.amount,';
3327 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
3328 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
3329 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
3330 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
3331 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
3332 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
3333 $sql .=
' WHERE pf.fk_facturefourn = '.((int) $object->id);
3334 $sql .=
' ORDER BY p.datep, p.tms';
3336 $result = $db->query($sql);
3338 $num = $db->num_rows($result);
3341 print
'<div class="div-table-responsive-no-min">';
3342 print
'<table class="noborder paymenttable centpercent">';
3343 print
'<tr class="liste_titre">';
3345 print
'<td>'.$langs->trans(
'Date').
'</td>';
3346 print
'<td>'.$langs->trans(
'Type').
'</td>';
3348 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
3350 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
3351 print
'<td width="18"> </td>';
3356 $objp = $db->fetch_object($result);
3358 $paymentstatic->id = $objp->rowid;
3359 $paymentstatic->datepaye = $db->jdate($objp->dp);
3360 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
3361 $paymentstatic->num_payment = $objp->num_payment;
3363 $paymentstatic->paiementcode = $objp->payment_code;
3364 $paymentstatic->type_code = $objp->payment_code;
3365 $paymentstatic->type_label = $objp->payment_type;
3367 print
'<tr class="oddeven">';
3368 print
'<td class="nowraponall">';
3369 print $paymentstatic->getNomUrl(1);
3371 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
'</td>';
3372 $s =
$form->form_modes_reglement(
null, $objp->paiement_type,
'none',
'', 1, 0,
'', 1).
' '.$objp->num_payment;
3373 print
'<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).
'">';
3377 $bankaccountstatic->id = $objp->baid;
3378 $bankaccountstatic->ref = $objp->baref;
3379 $bankaccountstatic->label = $objp->baref;
3380 $bankaccountstatic->number = $objp->banumber;
3383 $bankaccountstatic->account_number = $objp->account_number;
3386 $accountingjournal->fetch($objp->fk_accountancy_journal);
3387 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
3390 print
'<td class="right">';
3391 if ($objp->baid > 0) {
3392 print $bankaccountstatic->getNomUrl(1,
'transactions');
3396 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
3397 print
'<td class="center">';
3399 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
3405 $totalpaid += $objp->amount;
3409 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td><td></td><td></td></tr>';
3432 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3433 print
'<span class="opacitymedium">';
3435 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
3437 print $langs->trans(
'AlreadyPaid');
3440 print
'</td><td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td><td> </td></tr>';
3443 $resteapayeraffiche = $resteapayer;
3445 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
3448 $creditnoteamount = 0;
3451 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
3452 $sql .=
" re.description, re.fk_invoice_supplier_source";
3453 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
3454 $sql .=
" WHERE fk_invoice_supplier = ".((int) $object->id);
3455 $resql = $db->query($sql);
3457 $num = $db->num_rows(
$resql);
3461 $obj = $db->fetch_object(
$resql);
3462 $invoice->fetch($obj->fk_invoice_supplier_source);
3463 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3465 print $langs->trans(
"CreditNote").
' ';
3468 print $langs->trans(
"Deposit").
' ';
3470 print $invoice->getNomUrl(0);
3472 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
3473 print
'<td class="right">';
3474 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=unlinkdiscount&discountid='.$obj->rowid.
'">'.
img_delete().
'</a>';
3478 $creditnoteamount += $obj->amount_ttc;
3481 $depositamount += $obj->amount_ttc;
3490 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3491 print
'<span class="opacitymedium">';
3492 print
$form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
3494 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3495 $resteapayeraffiche = 0;
3496 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3500 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3501 print
'<span class="opacitymedium">';
3502 print
$form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
3504 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3506 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3510 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3511 print
'<span class="opacitymedium">';
3512 print
$form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
3514 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3515 $resteapayeraffiche = 0;
3516 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3520 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3521 $text = $langs->trans(
"HelpAbandonOther");
3522 if ($object->close_note) {
3523 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.$object->close_note;
3525 print
'<span class="opacitymedium">';
3526 print
$form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
3528 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3529 $resteapayeraffiche = 0;
3530 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3534 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3535 print
'<span class="opacitymedium">';
3536 print $langs->trans(
"Billed");
3538 print
'</td><td class="right">'.price($object->total_ttc).
'</td><td> </td></tr>';
3541 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3542 print
'<span class="opacitymedium">';
3543 print $langs->trans(
'RemainderToPay');
3544 if ($resteapayeraffiche < 0) {
3545 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3549 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
3552 if (
isModEnabled(
'multicurreny') && $object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3553 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3554 print
'<span class="opacitymedium">';
3555 print $langs->trans(
'RemainderToPayMulticurrency');
3556 if ($resteapayeraffiche < 0) {
3557 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3561 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.(!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency).
' '.
price(
price2num($multicurrency_resteapayer,
'MT')).
'</td><td> </td></tr>';
3564 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3567 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3568 print $langs->trans(
'AlreadyPaidBack');
3569 print
' :</td><td class="right">'.price($sign * $totalpaid).
'</td><td> </td></tr>';
3572 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"Billed").
' :</td><td class="right">'.
price($sign * $object->total_ttc).
'</td><td> </td></tr>';
3575 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3576 print
'<span class="opacitymedium">';
3577 print $langs->trans(
'RemainderToPayBack');
3578 if ($resteapayeraffiche > 0) {
3579 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3583 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td><td> </td></tr>';
3586 if (
isModEnabled(
'multicurreny') && $object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3587 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3588 print
'<span class="opacitymedium">';
3589 print $langs->trans(
'RemainderToPayBackMulticurrency');
3590 if ($resteapayeraffiche> 0) {
3591 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3595 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.(!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency).
' '.
price(
price2num($sign * $object->multicurrency_tx * $resteapayeraffiche,
'MT')).
'</td><td> </td></tr>';
3610 print
'<div class="clearboth"></div><br>';
3612 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
3613 $blocname =
'contacts';
3614 $title = $langs->trans(
'ContactsAddresses');
3615 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3618 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
3620 $blocname =
'notes';
3621 $title = $langs->trans(
'Notes');
3622 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3629 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
3630 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3631 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
3632 print
'<input type="hidden" name="mode" value="">';
3633 print
'<input type="hidden" name="page_y" value="">';
3634 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
3635 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
3638 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
3641 print
'<div class="div-table-responsive-no-min">';
3642 print
'<table id="tablelines" class="noborder noshadow centpercent">';
3644 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
3645 $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
3646 $senderissupplier = 2;
3648 if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
3649 $senderissupplier = 1;
3653 if (!empty($object->lines)) {
3654 $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
3657 $num = count($object->lines);
3661 if ($action !=
'editline') {
3665 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
3666 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
3667 if (empty($reshook))
3668 $object->formAddObjectLine(1, $societe, $mysoc);
3679 if ($action !=
'presend') {
3684 print
'<div class="tabsAction">';
3687 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
3689 if (empty($reshook)) {
3693 $ventilExportCompta = $object->getVentilExportCompta();
3695 if ($ventilExportCompta == 0) {
3696 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=edit&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
3698 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
3703 $result = $discount->fetch(0, 0, $object->id);
3710 if (!$objectidnext && $object->close_code !=
'replaced' && $usercancreate) {
3711 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
3713 if ($usercancreate) {
3714 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
3715 } elseif (empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
3716 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
3723 if (count($object->lines)) {
3724 if ($usercanvalidate) {
3725 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid"';
3726 print
'>'.$langs->trans(
'Validate').
'</a>';
3728 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
3729 print
'>'.$langs->trans(
'Validate').
'</a>';
3735 if (empty($user->socid)) {
3738 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
3740 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'SendMail').
'</span>';
3747 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.DOL_URL_ROOT.
'/fourn/facture/paiement.php?facid='.$object->id.
'&action=create'.($object->fk_account > 0 ?
'&accountid='.$object->fk_account :
'').
'">'.$langs->trans(
'DoPayment').
'</a>';
3754 if ($resteapayer == 0) {
3755 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
3757 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>';
3762 if ($object->type ==
FactureFournisseur::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) < 0 && $usercancreate && empty($discount->id)) {
3763 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
3767 && (!empty($conf->global->SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) || $object->getSommePaiement() == 0)
3769 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc" title="'.
dol_escape_htmltag($langs->trans(
"ConfirmConvertToReducSupplier2")).
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
3773 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertToReduc').
'</a>';
3781 ($object->type ==
FactureFournisseur::TYPE_DEPOSIT && $object->total_ttc > 0 && ($resteapayer == 0 || (!empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) && $object->total_ttc == $resteapayer)))
3784 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaid').
'</a>';
3788 if ($object->statut ==
FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && $resteapayer > 0 && (empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $object->total_ttc != $resteapayer)) {
3789 if ($totalpaid > 0 || $totalcreditnotes > 0) {
3791 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
3793 if (empty($conf->global->INVOICE_CAN_NEVER_BE_CANCELED)) {
3794 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
3807 if (!$objectidnext) {
3808 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>';
3813 if ($action !=
'edit' && $usercancreate) {
3814 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=clone&socid='.$object->socid.
'">'.$langs->trans(
'ToClone').
'</a>';
3819 if (!$objectidnext && count($object->lines) > 0) {
3820 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
3825 $isErasable = $object->is_erasable();
3826 if ($action !=
'confirm_edit' && ($usercandelete || ($usercancreate && $isErasable == 1))) {
3827 $enableDelete =
false;
3829 $params = (empty($conf->use_javascript_ajax) ? array() : array(
'attr' => array(
'class' =>
'reposition')));
3831 if ($isErasable == -4) {
3832 $htmltooltip = $langs->trans(
"DisabledBecausePayments");
3833 } elseif ($isErasable == -3) {
3834 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastSituationInvoice");
3835 } elseif ($isErasable == -2) {
3836 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastInvoice");
3837 } elseif ($isErasable == -1) {
3838 $htmltooltip = $langs->trans(
"DisabledBecauseDispatchedInBookkeeping");
3839 } elseif ($isErasable <= 0) {
3840 $htmltooltip = $langs->trans(
"DisabledBecauseNotErasable");
3842 $enableDelete =
true;
3845 print
dolGetButtonAction($htmltooltip, $langs->trans(
"Delete"),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken(), $object->id, $enableDelete, $params);
3849 if ($action !=
'confirm_edit') {
3850 print
'<div class="fichecenter"><div class="fichehalfleft">';
3856 $subdir =
get_exdir($object->id, 2, 0, 0, $object,
'invoice_supplier').$ref;
3857 $filedir = $conf->fournisseur->facture->dir_output.
'/'.$subdir;
3858 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.$object->id;
3859 $genallowed = $usercanread;
3860 $delallowed = $usercancreate;
3861 $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF) ?
'' : $conf->global->INVOICE_SUPPLIER_ADDON_PDF));
3863 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
3864 $somethingshown = $formfile->numoffiles;
3867 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'invoice_supplier'));
3868 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
3870 print
'</div><div class="fichehalfright">';
3873 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3875 $somethingshown =
$formactions->showactions($object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
3877 print
'</div></div>';
3883 if (
GETPOST(
'modelselected')) {
3884 $action =
'presend';
3888 $modelmail =
'invoice_supplier_send';
3889 $defaulttopic =
'SendBillRef';
3890 $diroutput = $conf->fournisseur->facture->dir_output;
3891 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
3892 $trackid =
'sinv'.$object->id;
3894 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage bank accounts.
Class to manage accounting accounts.
const TYPE_SITUATION
Situation invoice.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_STANDARD
Standard invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const STATUS_CLOSED
Classified paid.
Class to manage invoice templates.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage payments for supplier invoices.
Class ProductCombination Used to represent a product combination.
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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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.
facturefourn_prepare_head($object)
Prepare array with list of tabs.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated messages to output (Used to show messages on html output).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_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.
$formconfirm
if ($action == 'delbookkeepingyear') {
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.