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);
888 $desc = $langs->trans(
'invoiceAvoirLineWithPaymentRestAmount');
889 $retAddLine = $object->addline($desc, $remain_to_pay, 0, 0, 0, 1, 0, 0,
'',
'', 0,
'',
'TTC');
891 if ($retAddLine < 0) {
899 if (empty($dateinvoice)) {
901 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
903 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
910 $object->socid =
GETPOST(
'socid',
'int');
911 $object->type =
GETPOST(
'type',
'alphanohtml');
912 $object->ref =
GETPOST(
'ref',
'alphanohtml');
913 $object->date = $dateinvoice;
914 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
915 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
916 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
917 $object->model_pdf =
GETPOST(
'model',
'alphanohtml');
918 $object->fk_project =
GETPOST(
'projectid',
'int');
919 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
920 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
921 $object->fk_account =
GETPOST(
'fk_account',
'int');
925 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
926 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
927 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
928 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
931 $object->fac_rec = $fac_recid;
933 $fac_rec->fetch($object->fac_rec);
934 $fac_rec->fetch_lines();
935 $object->lines = $fac_rec->lines;
937 $id = $object->create($user);
941 if (
GETPOST(
'socid',
'int') < 1) {
942 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
947 if (empty($dateinvoice)) {
948 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
950 $_GET[
'socid'] = $_POST[
'socid'];
952 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
958 if (!
GETPOST(
'ref_supplier')) {
959 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplier')),
null,
'errors');
961 $_GET[
'socid'] = $_POST[
'socid'];
966 $tmpproject =
GETPOST(
'projectid',
'int');
969 $object->socid =
GETPOST(
'socid',
'int');
970 $object->type =
GETPOST(
'type',
'alphanohtml');
971 $object->ref =
GETPOST(
'ref',
'alphanohtml');
972 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
973 $object->socid =
GETPOST(
'socid',
'int');
974 $object->libelle =
GETPOST(
'label',
'alphanohtml');
975 $object->label =
GETPOST(
'label',
'alphanohtml');
976 $object->date = $dateinvoice;
977 $object->date_echeance = $datedue;
978 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
979 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
980 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
981 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
982 $object->fk_account =
GETPOST(
'fk_account',
'int');
983 $object->fk_project = ($tmpproject > 0) ? $tmpproject :
null;
984 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
985 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
986 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
987 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
988 $object->transport_mode_id =
GETPOST(
'transport_mode_id');
991 if (empty($object->date_echeance)) {
992 $object->date_echeance = $object->calculate_date_lim_reglement();
995 $object->fetch_thirdparty();
998 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
1000 $element = $subelement =
GETPOST(
'origin',
'alpha');
1008 if ($element ==
'order') {
1009 $element = $subelement =
'commande';
1011 if ($element ==
'propal') {
1012 $element =
'comm/propal'; $subelement =
'propal';
1014 if ($element ==
'contract') {
1015 $element = $subelement =
'contrat';
1017 if ($element ==
'order_supplier') {
1018 $element =
'fourn'; $subelement =
'fournisseur.commande';
1020 if ($element ==
'project') {
1021 $element =
'projet';
1023 $object->origin =
GETPOST(
'origin',
'alpha');
1024 $object->origin_id =
GETPOST(
'originid',
'int');
1027 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
1028 $classname = ucfirst($subelement);
1029 if ($classname ==
'Fournisseur.commande') {
1030 $classname =
'CommandeFournisseur';
1032 $objectsrc =
new $classname($db);
1033 $objectsrc->fetch($originid);
1034 $objectsrc->fetch_thirdparty();
1036 if (!empty($object->origin) && !empty($object->origin_id)) {
1037 $object->linkedObjectsIds[$object->origin] = $object->origin_id;
1041 if ($object->origin ==
'reception') {
1042 $objectsrc->fetchObjectLinked();
1044 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1045 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1046 $object->linkedObjectsIds[
'order_supplier'] = $value;
1051 $id = $object->create($user);
1055 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
1056 $classname = ucfirst($subelement);
1057 if ($classname ==
'Fournisseur.commande') {
1058 $classname =
'CommandeFournisseur';
1060 $srcobject =
new $classname($db);
1062 $result = $srcobject->fetch(
GETPOST(
'originid',
'int'));
1065 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1070 $amountdeposit = array();
1071 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)) {
1072 if ($typeamount ==
'amount') {
1073 $amount = $valuedeposit;
1075 $amount = $srcobject->total_ttc * ($valuedeposit / 100);
1078 $TTotalByTva = array();
1079 foreach ($srcobject->lines as &$line) {
1080 if (!empty($line->special_code)) {
1083 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1086 foreach ($TTotalByTva as $tva => &$total) {
1087 $coef = $total / $srcobject->total_ttc;
1088 $am = $amount * $coef;
1089 $amount_ttc_diff += $am;
1090 $amountdeposit[$tva] += $am / (1 + $tva / 100);
1093 if ($typeamount ==
'amount') {
1094 $amountdeposit[0] = $valuedeposit;
1095 } elseif ($typeamount ==
'variable') {
1098 $lines = $srcobject->lines;
1099 $numlines = count($lines);
1100 for ($i = 0; $i < $numlines; $i++) {
1102 if (empty($lines[$i]->qty)) {
1105 if (!empty($lines[$i]->special_code)) {
1109 $totalamount += $lines[$i]->total_ht;
1110 $tva_tx = $lines[$i]->tva_tx;
1111 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $valuedeposit) / 100;
1115 if ($totalamount == 0) {
1116 $amountdeposit[0] = 0;
1124 $amount_ttc_diff = $amountdeposit[0];
1127 foreach ($amountdeposit as $tva => $amount) {
1128 if (empty($amount)) {
1133 'amount' =>
'FixAmount',
1134 'variable' =>
'VarAmount'
1136 $descline =
'(DEPOSIT)';
1138 if ($typeamount ==
'amount') {
1139 $descline .=
' ('.price($valuedeposit,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
')';
1140 } elseif ($typeamount ==
'variable') {
1141 $descline .=
' ('.$valuedeposit.
'%)';
1144 $descline .=
' - '.$srcobject->ref;
1145 $result = $object->addline(
1152 (empty($conf->global->INVOICE_PRODUCTID_DEPOSIT) ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT),
1157 $lines[$i]->info_bits,
1167 $lines[$i]->special_code,
1174 $diff = $object->total_ttc - $amount_ttc_diff;
1176 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0) {
1177 $object->fetch_lines();
1178 $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100);
1179 $object->updateline(
1180 $object->lines[0]->id,
1181 $object->lines[0]->desc,
1183 $object->lines[0]->tva_tx,
1184 $object->lines[0]->localtax1_tx,
1185 $object->lines[0]->localtax2_tx,
1186 $object->lines[0]->qty,
1187 $object->lines[0]->fk_product,
1189 $object->lines[0]->info_bits,
1190 $object->lines[0]->product_type,
1191 $object->lines[0]->remise_percent,
1193 $object->lines[0]->date_start,
1194 $object->lines[0]->date_end,
1202 } elseif ($result > 0) {
1203 $lines = $srcobject->lines;
1204 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1205 $srcobject->fetch_lines();
1206 $lines = $srcobject->lines;
1209 $num = count($lines);
1210 for ($i = 0; $i < $num; $i++) {
1211 if (!in_array($lines[$i]->
id, $selectedLines)) {
1215 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
1216 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1219 if (method_exists($lines[$i],
'fetch_optionals')) {
1220 $lines[$i]->fetch_optionals();
1225 $date_start = $lines[$i]->date_debut_prevue;
1226 if ($lines[$i]->date_debut_reel) {
1227 $date_start = $lines[$i]->date_debut_reel;
1229 if ($lines[$i]->date_start) {
1230 $date_start = $lines[$i]->date_start;
1232 $date_end = $lines[$i]->date_fin_prevue;
1233 if ($lines[$i]->date_fin_reel) {
1234 $date_end = $lines[$i]->date_fin_reel;
1236 if ($lines[$i]->date_end) {
1237 $date_end = $lines[$i]->date_end;
1241 $object->special_code = $lines[$i]->special_code;
1244 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
1246 $pu_currency = $lines[$i]->multicurrency_subprice;
1248 $pu = $lines[$i]->subprice;
1253 $result = $object->addline(
1257 $lines[$i]->localtax1_tx,
1258 $lines[$i]->localtax2_tx,
1260 $lines[$i]->fk_product,
1261 $lines[$i]->remise_percent,
1265 $lines[$i]->info_bits,
1270 $lines[$i]->array_options,
1271 $lines[$i]->fk_unit,
1274 $lines[$i]->ref_supplier,
1275 $lines[$i]->special_code
1285 $object->fetch_lines();
1292 } elseif (!$error) {
1293 $id = $object->create($user);
1302 $langs->load(
"errors");
1307 $_GET[
'socid'] = $_POST[
'socid'];
1311 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1312 $outputlangs = $langs;
1313 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1320 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1323 } elseif ($action ==
'updateline' && $usercancreate) {
1327 if (! $object->fetch($id) > 0) {
1330 $object->fetch_thirdparty();
1333 $tva_tx = str_replace(
'*',
'', $tva_tx);
1335 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_subprice') !=
'') {
1337 $price_base_type =
'HT';
1340 $price_base_type =
'TTC';
1343 if (
GETPOST(
'productid') > 0) {
1345 if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
1347 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1352 $prod->fetch(
GETPOST(
'productid'));
1353 $label = $prod->description;
1354 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1355 $label =
GETPOST(
'product_desc',
'restricthtml');
1358 $type = $prod->type;
1360 $label =
GETPOST(
'product_desc',
'restricthtml');
1369 if (preg_match(
'/\*/', $tva_tx)) {
1374 $tva_tx = str_replace(
'*',
'', $tva_tx);
1375 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1376 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1382 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1383 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1385 if (is_array($extralabelsline)) {
1386 foreach ($extralabelsline as $key => $value) {
1387 unset($_POST[
"options_".$key]);
1391 $result = $object->updateline(
1413 unset($_POST[
'label']);
1414 unset($_POST[
'fourn_ref']);
1415 unset($_POST[
'date_starthour']);
1416 unset($_POST[
'date_startmin']);
1417 unset($_POST[
'date_startsec']);
1418 unset($_POST[
'date_startday']);
1419 unset($_POST[
'date_startmonth']);
1420 unset($_POST[
'date_startyear']);
1421 unset($_POST[
'date_endhour']);
1422 unset($_POST[
'date_endmin']);
1423 unset($_POST[
'date_endsec']);
1424 unset($_POST[
'date_endday']);
1425 unset($_POST[
'date_endmonth']);
1426 unset($_POST[
'date_endyear']);
1427 unset($_POST[
'price_ttc']);
1428 unset($_POST[
'price_ht']);
1435 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') && $usercancreate) {
1437 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1438 $vat_rate = str_replace(
'*',
'', $vat_rate);
1439 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1440 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1441 foreach ($object->lines as $line) {
1442 $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);
1444 } elseif ($action ==
'addline' && $usercancreate) {
1448 $ret = $object->fetch($id);
1453 $ret = $object->fetch_thirdparty();
1455 $langs->load(
'errors');
1464 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1465 if ($prod_entry_mode ==
'free') {
1468 $idprod =
GETPOST(
'idprod',
'int');
1476 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
1480 if (empty($remise_percent)) {
1481 $remise_percent = 0;
1485 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1486 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
1488 if (is_array($extralabelsline)) {
1490 foreach ($extralabelsline as $key => $value) {
1491 unset($_POST[
"options_".$key]);
1495 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
1496 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1499 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
1500 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
1503 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
1504 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
1507 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
1508 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
1511 if (!
GETPOST(
'qty',
'alpha')) {
1512 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1516 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
1517 if ($combinations =
GETPOST(
'combinations',
'array')) {
1521 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1522 $idprod = $res->fk_product_child;
1524 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
1530 if ($prod_entry_mode !=
'free' && empty($error)) {
1534 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
1539 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
1541 $res = $productsupplier->fetch($idprod);
1544 if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) {
1546 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1547 if ($productsupplier->fourn_socid != $socid) {
1548 $productsupplier->ref_supplier =
'';
1551 $fksoctosearch = $object->thirdparty->id;
1552 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1554 } elseif (
GETPOST(
'idprodfournprice',
'alpha') > 0) {
1555 $qtytosearch = $qty;
1557 $idprod = $productsupplier->get_buyprice(
GETPOST(
'idprodfournprice',
'alpha'), $qtytosearch);
1558 $res = $productsupplier->fetch($idprod);
1562 $label = $productsupplier->label;
1564 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1565 $outputlangs = $langs;
1567 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1568 $newlang =
GETPOST(
'lang_id',
'aZ09');
1570 if (empty($newlang)) {
1571 $newlang = $object->thirdparty->default_lang;
1573 if (!empty($newlang)) {
1574 $outputlangs =
new Translate(
"", $conf);
1575 $outputlangs->setDefaultLang($newlang);
1577 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->description;
1579 $desc = $productsupplier->description;
1582 if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
1583 $desc = $productsupplier->desc_supplier;
1587 if (trim($product_desc) == trim($desc) && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
1590 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
1591 $desc = $product_desc;
1593 if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
1594 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
1597 $ref_supplier = $productsupplier->ref_supplier;
1601 $tva_tx =
get_default_tva($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
1602 $tva_npr =
get_default_npr($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
1604 if (empty($tva_tx)) {
1607 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
1608 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
1610 $type = $productsupplier->type;
1611 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'price_ht_devise') !=
'') {
1612 $price_base_type =
'HT';
1614 $pu_devise =
price2num($price_ht_devise,
'CU');
1615 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'price_ttc_devise') !=
'') {
1616 $price_base_type =
'TTC';
1618 $pu_devise =
price2num($price_ttc_devise,
'CU');
1620 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
1621 if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) {
1622 $pu = $productsupplier->fourn_pu;
1625 $pu = $productsupplier->fourn_pu;
1626 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
1634 $result = $object->addline(
1649 min($rank, count($object->lines) + 1),
1652 $productsupplier->fk_unit,
1659 if ($idprod == -99 || $idprod == 0) {
1662 $langs->load(
"errors");
1663 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
1665 if ($idprod == -1) {
1668 $langs->load(
"errors");
1669 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
1671 } elseif (empty($error)) {
1672 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1673 $tva_tx = str_replace(
'*',
'', $tva_tx);
1674 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1675 $desc = $product_desc;
1677 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
1679 $fk_unit =
GETPOST(
'units',
'alpha');
1681 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1686 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1687 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1689 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'price_ht_devise') !=
'') {
1693 $pu_ht =
price2num($pu_ttc / (1 + ($tva_tx / 100)),
'MU');
1695 $price_base_type =
'HT';
1696 $pu_devise =
price2num($price_devise,
'CU');
1698 $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);
1702 if (!$error && $result > 0) {
1706 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1707 $outputlangs = $langs;
1710 $newlang =
GETPOST(
'lang_id',
'aZ09');
1713 $newlang = $object->thirdparty->default_lang;
1715 if (!empty($newlang)) {
1716 $outputlangs =
new Translate(
"", $conf);
1717 $outputlangs->setDefaultLang($newlang);
1719 $model = $object->model_pdf;
1720 $ret = $object->fetch($id);
1722 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1728 unset($_POST [
'prod_entry_mode']);
1730 unset($_POST[
'qty']);
1731 unset($_POST[
'type']);
1732 unset($_POST[
'remise_percent']);
1733 unset($_POST[
'pu']);
1734 unset($_POST[
'price_ht']);
1735 unset($_POST[
'multicurrency_price_ht']);
1736 unset($_POST[
'price_ttc']);
1737 unset($_POST[
'fourn_ref']);
1738 unset($_POST[
'tva_tx']);
1739 unset($_POST[
'label']);
1740 unset($localtax1_tx);
1741 unset($localtax2_tx);
1742 unset($_POST[
'np_marginRate']);
1743 unset($_POST[
'np_markRate']);
1744 unset($_POST[
'dp_desc']);
1745 unset($_POST[
'idprodfournprice']);
1746 unset($_POST[
'units']);
1748 unset($_POST[
'date_starthour']);
1749 unset($_POST[
'date_startmin']);
1750 unset($_POST[
'date_startsec']);
1751 unset($_POST[
'date_startday']);
1752 unset($_POST[
'date_startmonth']);
1753 unset($_POST[
'date_startyear']);
1754 unset($_POST[
'date_endhour']);
1755 unset($_POST[
'date_endmin']);
1756 unset($_POST[
'date_endsec']);
1757 unset($_POST[
'date_endday']);
1758 unset($_POST[
'date_endmonth']);
1759 unset($_POST[
'date_endyear']);
1766 } elseif ($action ==
'classin' && $usercancreate) {
1767 $object->fetch($id);
1768 $result = $object->setProject($projectid);
1769 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
1771 $object->fetch($id);
1773 $totalpaid = $object->getSommePaiement();
1774 $resteapayer = $object->total_ttc - $totalpaid;
1777 $ventilExportCompta = $object->getVentilExportCompta();
1779 if (!$ventilExportCompta) {
1782 $idwarehouse =
GETPOST(
'idwarehouse');
1784 $object->fetch_thirdparty();
1786 $qualified_for_stock_change = 0;
1787 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1788 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1790 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1794 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
1795 $langs->load(
"stocks");
1796 if (!$idwarehouse || $idwarehouse == -1) {
1798 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1803 $object->setDraft($user, $idwarehouse);
1806 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1807 $outputlangs = $langs;
1810 $newlang =
GETPOST(
'lang_id',
'aZ09');
1813 $newlang = $object->thirdparty->default_lang;
1815 if (!empty($newlang)) {
1816 $outputlangs =
new Translate(
"", $conf);
1817 $outputlangs->setDefaultLang($newlang);
1819 $model = $object->model_pdf;
1820 $ret = $object->fetch($id);
1822 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1831 } elseif ($action ==
'reopen' && $usercancreate) {
1833 $result = $object->fetch($id);
1836 $result = $object->setUnpaid($user);
1838 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
1847 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1850 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
1852 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
1853 $trackid =
'sinv'.$object->id;
1854 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1857 $upload_dir = $conf->fournisseur->facture->dir_output;
1858 $permissiontoadd = $usercancreate;
1859 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1862 if ($action ==
'calculate') {
1863 $calculationrule =
GETPOST(
'calculationrule');
1865 $object->fetch($id);
1866 $object->fetch_thirdparty();
1867 $result = $object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0, $object->thirdparty);
1873 if ($action ==
'update_extras') {
1877 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1885 $result = $object->insertExtraFields(
'BILL_SUPPLIER_MODIFY');
1893 $action =
'edit_extras';
1897 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1898 if ($action ==
'addcontact') {
1899 $result = $object->fetch($id);
1901 if ($result > 0 && $id > 0) {
1904 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1908 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1911 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1912 $langs->load(
"errors");
1913 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1918 } elseif ($action ==
'swapstatut') {
1920 if ($object->fetch($id)) {
1921 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1925 } elseif ($action ==
'deletecontact') {
1927 $object->fetch($id);
1928 $result = $object->delete_contact(
GETPOST(
"lineid",
'int'));
1931 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1947 $bankaccountstatic =
new Account($db);
1955 $title = $object->ref.
" - ".$langs->trans(
'Card');
1956 if ($action ==
'create') {
1957 $title = $langs->trans(
"NewSupplierInvoice");
1959 $help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
1963 if ($action ==
'create') {
1966 print
load_fiche_titre($langs->trans(
'NewSupplierInvoice'),
'',
'supplier_invoice');
1970 $currency_code = $conf->currency;
1973 if (
GETPOST(
'socid',
'int') > 0) {
1975 $societe->fetch(
GETPOST(
'socid',
'int'));
1976 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
1977 $currency_code = $societe->multicurrency_code;
1981 if (!empty($origin) && !empty($originid)) {
1983 $element = $subelement = $origin;
1985 if ($element ==
'project') {
1986 $projectid = $originid;
1987 $element =
'projet';
1991 if ($element ==
'order') {
1992 $element = $subelement =
'commande';
1994 if ($element ==
'propal') {
1995 $element =
'comm/propal'; $subelement =
'propal';
1997 if ($element ==
'contract') {
1998 $element = $subelement =
'contrat';
2000 if ($element ==
'order_supplier') {
2001 $element =
'fourn'; $subelement =
'fournisseur.commande';
2004 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
2005 $classname = ucfirst($subelement);
2006 if ($classname ==
'Fournisseur.commande') {
2007 $classname =
'CommandeFournisseur';
2009 $objectsrc =
new $classname($db);
2010 $objectsrc->fetch($originid);
2011 $objectsrc->fetch_thirdparty();
2013 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
2016 $soc = $objectsrc->thirdparty;
2017 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_supplier_id) ? $soc->cond_reglement_supplier_id : 0));
2018 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_supplier_id) ? $soc->mode_reglement_supplier_id : 0));
2019 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
2020 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_supplier_percent) ? $soc->remise_supplier_percent : 0));
2021 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
2022 $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'';
2023 $transport_mode_id = (!empty($objectsrc->transport_mode_id) ? $objectsrc->transport_mode_id : (!empty($soc->transport_mode_id) ? $soc->transport_mode_id : 0));
2026 if (!empty($objectsrc->multicurrency_code)) {
2027 $currency_code = $objectsrc->multicurrency_code;
2029 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
2030 $currency_tx = $objectsrc->multicurrency_tx;
2035 $dateinvoice = ($datetmp ==
'' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $datetmp);
2037 $datedue = ($datetmp ==
'' ?-1 : $datetmp);
2040 $objectsrc->fetch_optionals();
2041 $object->array_options = $objectsrc->array_options;
2043 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2044 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2045 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2046 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2048 $dateinvoice = ($datetmp ==
'' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $datetmp);
2050 $datedue = ($datetmp ==
'' ?-1 : $datetmp);
2052 if (
isModEnabled(
"multicurrency") && !empty($soc->multicurrency_code)) {
2053 $currency_code = $soc->multicurrency_code;
2058 if (empty($cond_reglement_id)) {
2059 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2063 if (empty($mode_reglement_id)) {
2064 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2067 $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));
2068 $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));
2070 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2071 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2072 print
'<input type="hidden" name="action" value="add">';
2073 if (!empty($societe->id) && $societe->id > 0) {
2074 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2076 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2077 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2078 if (!empty($currency_tx)) {
2079 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2084 print
'<table class="border centpercent">';
2087 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
2091 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2092 $invoice_predefined->fetch($fac_recid);
2096 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2099 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2100 $absolute_discount = $societe->getAvailableDiscounts(
'',
'', 0, 1);
2101 print $societe->getNomUrl(1,
'supplier');
2102 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2104 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');
2106 if (empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE_DISABLED)) {
2107 print
'<script type="text/javascript">
2108 $(document).ready(function() {
2109 $("#socid").change(function() {
2110 console.log("We have changed the company - Reload page");
2112 $("input[name=action]").val("create");
2113 $("form[name=add]").submit();
2118 if ($fac_recid <= 0) {
2119 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>';
2125 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2126 $invoice_predefined->fetch($fac_recid);
2128 $dateinvoice = $invoice_predefined->date_when;
2129 if (empty($projectid)) {
2130 $projectid = $invoice_predefined->fk_project;
2132 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2133 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2134 $fk_account = $invoice_predefined->fk_account;
2135 $note_public = $invoice_predefined->note_public;
2136 $note_private = $invoice_predefined->note_private;
2138 if (!empty($invoice_predefined->multicurrency_code)) {
2139 $currency_code = $invoice_predefined->multicurrency_code;
2141 if (!empty($invoice_predefined->multicurrency_tx)) {
2142 $currency_tx = $invoice_predefined->multicurrency_tx;
2145 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2146 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2147 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2149 $resql = $db->query($sql);
2151 $num = $db->num_rows(
$resql);
2155 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2157 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2158 print
'<option value="0" selected></option>';
2160 $objp = $db->fetch_object(
$resql);
2161 print
'<option value="'.$objp->rowid.
'"';
2162 if ($fac_recid == $objp->rowid) {
2164 $exampletemplateinvoice->fetch($fac_recid);
2166 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2171 if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED)) {
2172 print
'<script type="text/javascript">
2173 $(document).ready(function() {
2174 $("#fac_rec").change(function() {
2175 console.log("We have changed the template invoice - Reload page");
2177 $("input[name=action]").val("create");
2178 $("form[name=add]").submit();
2192 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"';
2193 if (!empty($societe->id) && $societe->id > 0) {
2199 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2201 print
'<div class="tagtable">'.
"\n";
2204 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2205 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOST(
'type',
'int')?
'' :
'checked').
'> ';
2206 $desc =
$form->textwithpicto($tmp.
'<label for="radio_standard">'.$langs->trans(
"InvoiceStandardAsk").
'</label>', $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2208 print
'</div></div>';
2210 if (empty($origin) || ($origin ==
'order_supplier' && !empty($originid))) {
2212 if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) {
2213 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2214 $tmp=
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOST(
'type') == 3 ?
' checked' :
'') .
'> ';
2215 print
'<script type="text/javascript">
2216 jQuery(document).ready(function() {
2217 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2218 jQuery("#radio_standard").prop("checked", true);
2220 jQuery("#typedeposit, #valuedeposit").click(function() {
2221 jQuery("#radio_deposit").prop("checked", true);
2223 jQuery("#typedeposit").change(function() {
2224 console.log("We change type of down payment");
2225 jQuery("#radio_deposit").prop("checked", true);
2226 setRadioForTypeOfInvoice();
2228 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2229 setRadioForTypeOfInvoice();
2231 function setRadioForTypeOfInvoice() {
2232 console.log("Change radio");
2233 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2234 jQuery(".checkforselect").prop("disabled", true);
2235 jQuery(".checkforselect").prop("checked", false);
2237 jQuery(".checkforselect").prop("disabled", false);
2238 jQuery(".checkforselect").prop("checked", true);
2244 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2245 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2246 print
'<table class="nobordernopadding"><tr>';
2250 if ($origin ==
'order_supplier') {
2251 print
'<td class="nowrap" style="padding-left: 15px">';
2253 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2254 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2255 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2257 print
$form->selectarray(
'typedeposit', $arraylist,
GETPOST(
'typedeposit',
'aZ09'), 0, 0, 0,
'', 1);
2259 print
'<td class="nowrap" style="padding-left: 5px">';
2260 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' .
GETPOST(
'valuedeposit',
'int') .
'"/>';
2263 print
'</tr></table>';
2265 print
'</div></div>';
2334 if (empty($origin)) {
2335 if (!empty($societe->id) && $societe->id > 0) {
2337 if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) {
2339 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2346 foreach ($facids as $key => $valarray) {
2347 $newinvoice_static->id = $key;
2348 $newinvoice_static->ref = $valarray [
'ref'];
2349 $newinvoice_static->statut = $valarray [
'status'];
2350 $newinvoice_static->type = $valarray [
'type'];
2351 $newinvoice_static->paye = $valarray [
'paye'];
2353 $optionsav .=
'<option value="'.$key.
'"';
2354 if ($key ==
GETPOST(
'fac_avoir',
'int')) {
2355 $optionsav .=
' selected';
2358 $optionsav .= $newinvoice_static->ref;
2359 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
2360 $optionsav .=
'</option>';
2363 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2364 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
2365 if (!$optionsav && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
2366 $tmp .=
' disabled';
2370 print
'<script type="text/javascript">
2371 jQuery(document).ready(function() {
2372 if (! jQuery("#radio_creditnote").is(":checked"))
2374 jQuery("#credit_note_options").hide();
2376 jQuery("#radio_creditnote").click(function() {
2377 jQuery("#credit_note_options").show();
2379 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2380 jQuery("#credit_note_options").hide();
2384 $text = $tmp.
'<label for="radio_creditnote">'.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
2386 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2388 $text .=
' disabled';
2392 $text .=
'<option value="-1"></option>';
2393 $text .= $optionsav;
2395 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
2397 $text .=
'</select>';
2398 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2401 print
'<div id="credit_note_options" class="clearboth">';
2402 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' :
'').
' /> ';
2403 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
2404 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' :
'').
' /> ';
2405 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
2408 print
'</div></div>';
2411 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2412 if (empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
2413 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2415 $tmp=
'<input type="radio" name="type" id="radio_creditnote" value="2"> ';
2417 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
2418 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
2419 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2421 print
'</div></div>'.
"\n";
2429 if (!empty($societe->id) && $societe->id > 0) {
2431 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2433 $thirdparty = $societe;
2435 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2436 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2442 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth200" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
2445 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
2446 print
$form->selectDate($dateinvoice,
'',
'',
'',
'',
"add", 1, 1);
2450 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2451 print
$form->getSelectConditionsPaiements(
GETPOSTISSET(
'cond_reglement_id') ?
GETPOST(
'cond_reglement_id',
'int') : $cond_reglement_id,
'cond_reglement_id');
2455 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
2456 print
$form->selectDate($datedue,
'ech',
'',
'',
'',
"add", 1, 1);
2460 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2461 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2462 $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');
2467 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2468 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);
2476 $langs->load(
'projects');
2477 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2478 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');
2479 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>';
2486 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
2487 print
'<td colspan="3" class="maxwidthonsmartphone">';
2488 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 :
''));
2495 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
2496 print
'<td class="maxwidthonsmartphone">';
2497 print
$form->selectMultiCurrency((
GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code),
'multicurrency_code');
2503 if ($fac_recid > 0) {
2504 $dateexample = $newdateinvoice ? $newdateinvoice : $dateinvoice;
2505 if (empty($dateexample)) {
2508 $substitutionarray = array(
2509 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
2510 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
2511 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
2512 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
2513 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
2514 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
2515 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
2516 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
2517 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
2518 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
2519 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
2522 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
2523 foreach ($substitutionarray as $key => $val) {
2524 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
2526 $htmltext .=
'</i>';
2531 $langs->loadLangs(array(
"intracommreport"));
2532 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
2533 $form->selectTransportMode(
GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
2537 if (empty($reshook)) {
2538 print $object->showOptionals($extrafields,
'create');
2542 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2544 $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%');
2545 print $doleditor->Create(1);
2551 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
2553 $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%');
2554 print $doleditor->Create(1);
2560 if (!empty($objectsrc) && is_object($objectsrc)) {
2561 print
"\n<!-- ".$classname.
" info -->";
2563 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2564 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2565 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2566 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2567 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2569 $txt = $langs->trans($classname);
2570 if ($classname ==
'CommandeFournisseur') {
2571 $langs->load(
'orders');
2572 $txt = $langs->trans(
"SupplierOrder");
2574 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
2576 $objectsrc->fetchObjectLinked($originid, $origin,
'',
'invoice_supplier');
2578 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
2581 if (is_array($invoice_supplier)) {
2582 $cntinvoice = count($invoice_supplier);
2584 if ($cntinvoice >= 1) {
2586 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
2591 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2592 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2593 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2594 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2597 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2598 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2600 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2603 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2604 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2605 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2611 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
2612 print $hookmanager->resPrint;
2619 print
$form->buttonsSaveCancel(
"CreateDraft");
2622 if (!empty($objectsrc) && is_object($objectsrc)) {
2625 $title = $langs->trans(
'ProductsAndServices');
2628 print
'<div class="div-table-responsive-no-min">';
2629 print
'<table class="noborder centpercent">';
2631 $objectsrc->printOriginLinesList(
'', $selectedLines);
2639 if ($id > 0 || !empty($ref)) {
2645 $productstatic =
new Product($db);
2647 $result = $object->fetch($id, $ref);
2649 $langs->load(
"errors");
2650 print $langs->trans(
"ErrorRecordNotFound");
2656 $result = $object->fetch_thirdparty();
2662 $societe = $object->thirdparty;
2664 $totalpaid = $object->getSommePaiement();
2665 $totalcreditnotes = $object->getSumCreditNotesUsed();
2666 $totaldeposits = $object->getSumDepositsUsed();
2674 $resteapayer =
price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
2678 $multicurrency_totalpaid = $object->getSommePaiement(1);
2679 $multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
2680 $multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
2681 $multicurrency_resteapayer =
price2num($object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
2685 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 && $object->multicurrency_code != $conf->currency) {
2686 $resteapayer =
price2num($multicurrency_resteapayer / $object->multicurrency_tx,
'MT');
2690 if ($object->paye) {
2693 $resteapayeraffiche = $resteapayer;
2695 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
2696 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2697 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2699 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2700 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2703 $absolute_discount = $societe->getAvailableDiscounts(
'', $filterabsolutediscount, 0, 1);
2704 $absolute_creditnote = $societe->getAvailableDiscounts(
'', $filtercreditnote, 0, 1);
2705 $absolute_discount =
price2num($absolute_discount,
'MT');
2706 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2711 $objectidnext = $object->getIdReplacingInvoice();
2714 $titre = $langs->trans(
'SupplierInvoice');
2721 if ($action ==
'converttoreduc') {
2723 $type_fac =
'ExcessPaid';
2725 $type_fac =
'CreditNote';
2727 $type_fac =
'Deposit';
2729 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
2730 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
2731 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
2735 if ($action ==
'clone') {
2737 $formquestion = array(
2738 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplier"),
'value' => $langs->trans(
"CopyOf").
' '.$object->ref_supplier),
2739 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
2742 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
2746 if ($action ==
'valid') {
2748 if (preg_match(
'/^[\(]?PROV/i', $object->ref) || empty($object->ref)) {
2750 $numref = $object->getNextNumRef($societe);
2752 $numref = $object->ref;
2759 $text = $langs->trans(
'ConfirmValidateBill', $numref);
2767 $formquestion = array();
2769 $qualified_for_stock_change = 0;
2770 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2771 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2773 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2776 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
2777 $langs->load(
"stocks");
2778 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2781 $warehouse_array = $warehouse->list_array();
2782 if (count($warehouse_array) == 1) {
2783 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
2784 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
2787 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
2789 $formquestion = array(
2790 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
2794 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
2799 if ($action ==
'edit') {
2800 $formquestion = array();
2802 $qualified_for_stock_change = 0;
2803 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2804 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2806 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2808 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
2809 $langs->load(
"stocks");
2810 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2813 $warehouse_array = $warehouse->list_array();
2814 if (count($warehouse_array) == 1) {
2815 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
2816 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
2819 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
2821 $formquestion = array(
2822 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
2825 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill', $object->ref),
'confirm_edit', $formquestion, 1, 1);
2829 if ($action ==
'paid' && ($resteapayer <= 0 || (!empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) && $resteapayer == $object->total_ttc))) {
2830 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill', $object->ref),
'confirm_paid',
'', 0, 1);
2833 if ($action ==
'paid' && $resteapayer > 0 && (empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $resteapayer != $object->total_ttc)) {
2837 $close[$i][
'code'] =
'discount_vat';
2839 $close[$i][
'code'] =
'badsupplier';
2841 $close[$i][
'code'] =
'other';
2845 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
2847 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
2849 $close[$i][
'label'] = $langs->trans(
"Other");
2853 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
2855 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
2857 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
2860 foreach ($close as $key => $val) {
2861 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
2865 $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'));
2867 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially', $object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
2871 if ($action ==
'canceled') {
2873 $close[1][
'code'] =
'badsupplier';
2874 $close[2][
'code'] =
'abandon';
2876 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
2877 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
2879 $close[1][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier", $object->ref), $close[1][
'label'], 1);
2880 $close[2][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
2882 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
2883 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
2886 $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'));
2888 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill', $object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 250);
2892 if ($action ==
'delete') {
2893 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete',
'', 0, 1);
2895 if ($action ==
'deletepayment') {
2896 $payment_id =
GETPOST(
'paiement_id');
2897 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
2901 if ($action ==
'ask_deleteline') {
2902 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2907 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
2908 if (empty($reshook)) {
2910 } elseif ($reshook > 0) {
2920 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2922 $morehtmlref =
'<div class="refidno">';
2924 $morehtmlref .=
$form->editfieldkey(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'', 0, 1);
2925 $morehtmlref .=
$form->editfieldval(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
2927 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'supplier');
2928 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2929 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$object->thirdparty->id.
'&search_company='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
2933 $langs->load(
"projects");
2934 $morehtmlref .=
'<br>';
2935 if ($permissiontoadd) {
2936 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2937 if ($action !=
'classify') {
2938 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2940 $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, 0, 0, 1,
'',
'maxwidth300');
2942 if (!empty($object->fk_project)) {
2944 $proj->fetch($object->fk_project);
2945 $morehtmlref .= $proj->getNomUrl(1);
2947 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2952 $morehtmlref .=
'</div>';
2954 $object->totalpaid = $totalpaid;
2956 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2958 print
'<div class="fichecenter">';
2959 print
'<div class="fichehalfleft">';
2960 print
'<div class="underbanner clearboth"></div>';
2962 print
'<table class="border tableforfield centpercent">';
2965 print
'<tr><td class="titlefield">'.$langs->trans(
'Type').
'</td><td>';
2966 print
'<span class="badgeneutral">';
2967 print $object->getLibType();
2971 $facreplaced->fetch($object->fk_facture_source);
2972 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
2976 if ($object->fk_facture_source > 0) {
2977 $facusing->fetch($object->fk_facture_source);
2978 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
2980 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectedInvoiceNotFound").
'</span>';
2984 $facidavoir = $object->getListIdAvoirFromInvoice();
2985 if (count($facidavoir) > 0) {
2986 $invoicecredits = array();
2987 foreach ($facidavoir as $id) {
2989 $facavoir->fetch($id);
2990 $invoicecredits[] = $facavoir->getNomUrl(1);
2992 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
2995 if (isset($objectidnext) && $objectidnext > 0) {
2998 $facthatreplace->fetch($objectidnext);
2999 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
3003 $result = $discount->fetch(0, 0, $object->id);
3005 print
' <span class="opacitymediumbycolor paddingleft">';
3006 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
3007 $s = str_replace(
'{s1}', $object->getLibType(1), $s);
3008 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
3010 print
'</span><br>';
3014 if ($object->fk_fac_rec_source > 0) {
3016 $result = $tmptemplate->fetch($object->fk_fac_rec_source);
3018 print
' <span class="opacitymediumbycolor paddingleft">';
3019 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->titre).
'</a>';
3020 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
3030 print
'<!-- Discounts -->'.
"\n";
3031 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
3034 $thirdparty = $societe;
3036 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?facid='.$object->id);
3037 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3043 print
'<td>'.$form->editfieldkey(
"Label",
'label', $object->label, $object, $usercancreate).
'</td>';
3044 print
'<td>'.$form->editfieldval(
"Label",
'label', $object->label, $object, $usercancreate).
'</td>';
3052 print
$form->editfieldkey(
"DateInvoice",
'datef', $object->datep, $object, $form_permission,
'datepicker');
3053 print
'</td><td colspan="3">';
3054 print
$form->editfieldval(
"Date",
'datef', $object->datep, $object, $form_permission,
'datepicker');
3058 $langs->load(
'bills');
3059 print
'<tr><td class="nowrap">';
3060 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3061 print $langs->trans(
'PaymentConditions');
3063 if ($action !=
'editconditions' && $form_permission) {
3064 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>';
3066 print
'</tr></table>';
3068 if ($action ==
'editconditions') {
3069 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
3071 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none');
3078 print
$form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', $object->date_echeance, $object, $form_permission,
'datepicker');
3080 print
$form->editfieldval(
"DateMaxPayment",
'date_lim_reglement', $object->date_echeance, $object, $form_permission,
'datepicker');
3081 if ($action !=
'editdate_lim_reglement' && $object->hasDelay()) {
3087 $langs->load(
'bills');
3088 print
'<tr><td class="nowrap">';
3089 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3090 print $langs->trans(
'PaymentMode');
3092 if ($action !=
'editmode' && $form_permission) {
3093 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>';
3095 print
'</tr></table>';
3097 if ($action ==
'editmode') {
3098 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3100 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
3109 print
'<table class="nobordernopadding" width="100%"><tr><td>';
3110 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
3112 if ($action !=
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT) {
3113 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>';
3115 print
'</tr></table>';
3117 if ($action ==
'editmulticurrencycode') {
3118 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
3120 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
3125 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3128 print
'<table class="nobordernopadding centpercent"><tr><td>';
3129 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
3131 if ($action !=
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3132 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>';
3134 print
'</tr></table>';
3136 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
3137 if ($action ==
'actualizemulticurrencyrate') {
3140 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
3142 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
3143 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3144 print
'<div class="inline-block"> ';
3145 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
3155 print
'<tr><td class="nowrap">';
3156 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3157 print $langs->trans(
'BankAccount');
3159 if ($action !=
'editbankaccount' && $usercancreate) {
3160 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>';
3162 print
'</tr></table>';
3164 if ($action ==
'editbankaccount') {
3165 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
3167 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
3176 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3177 print $langs->trans(
'IncotermLabel');
3178 print
'<td><td class="right">';
3179 if ($usercancreate) {
3180 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
3184 print
'</td></tr></table>';
3187 if ($action !=
'editincoterm') {
3188 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
3190 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
3197 $langs->loadLangs(array(
"intracommreport"));
3199 print
'<table class="nobordernopadding centpercent"><tr><td>';
3200 print $langs->trans(
'IntracommReportTransportMode');
3202 if ($action !=
'editmode' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
3203 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit().
'</a></td>';
3205 print
'</tr></table>';
3208 if ($action ==
'editmode') {
3209 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->transport_mode_id,
'transport_mode_id', 1, 1);
3211 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->transport_mode_id,
'none');
3218 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
3223 print
'<div class="fichehalfright">';
3224 print
'<div class="underbanner clearboth"></div>';
3226 print
'<table class="border tableforfield centpercent">';
3228 if (
isModEnabled(
"multicurrency") && ($object->multicurrency_code != $conf->currency)) {
3230 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
3231 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>';
3235 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
3236 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>';
3240 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
3241 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>';
3246 print
'<tr><td class="titlefield">'.$langs->trans(
'AmountHT').
'</td>';
3247 print
'<td class="nowrap right amountcard">'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3251 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td>';
3252 print
'<td class="nowrap right amountcard">';
3253 if (
GETPOST(
'calculationrule')) {
3254 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
3256 $calculationrule = (empty($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND) ?
'totalofround' :
'roundoftotal');
3258 if ($calculationrule ==
'totalofround') {
3259 $calculationrulenum = 1;
3261 $calculationrulenum = 2;
3264 if ($object->getVentilExportCompta() == 0) {
3265 $s =
'<span class="hideonsmartphone opacitymedium">'.$langs->trans(
"ReCalculate").
' </span>';
3266 $s .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=calculate&calculationrule=totalofround">'.$langs->trans(
"Mode1").
'</a>';
3268 $s .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=calculate&calculationrule=roundoftotal">'.$langs->trans(
"Mode2").
'</a>';
3269 print
'<div class="inline-block">';
3270 print
$form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum).
'<br>'.$langs->trans(
"CalculationRuleDescSupplier"), 2, 1,
img_picto(
'',
'help'),
'', 3,
'', 0,
'recalculate');
3271 print
' ';
3274 print
price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency);
3279 if ($societe->localtax1_assuj ==
"1") {
3280 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $societe->country_code).
'</td>';
3281 print
'<td class="nowrap right amountcard">'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3284 if ($societe->localtax2_assuj ==
"1") {
3285 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $societe->country_code).
'</td>';
3286 print
'<td class="nowrap right amountcard">'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3289 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td>';
3290 print
'<td colspan="3" class="nowrap right amountcard">'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3305 $nbrows = 9; $nbcols = 3;
3310 $nbrows++; $nbcols++;
3320 if ($societe->localtax1_assuj ==
"1") {
3323 if ($societe->localtax2_assuj ==
"1") {
3327 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
3328 $sql .=
' c.id as paiement_type, c.code as payment_code,';
3329 $sql .=
' pf.amount,';
3330 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
3331 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
3332 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
3333 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
3334 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
3335 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
3336 $sql .=
' WHERE pf.fk_facturefourn = '.((int) $object->id);
3337 $sql .=
' ORDER BY p.datep, p.tms';
3339 $result = $db->query($sql);
3341 $num = $db->num_rows($result);
3344 print
'<div class="div-table-responsive-no-min">';
3345 print
'<table class="noborder paymenttable centpercent">';
3346 print
'<tr class="liste_titre">';
3348 print
'<td>'.$langs->trans(
'Date').
'</td>';
3349 print
'<td>'.$langs->trans(
'Type').
'</td>';
3351 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
3353 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
3354 print
'<td width="18"> </td>';
3359 $objp = $db->fetch_object($result);
3361 $paymentstatic->id = $objp->rowid;
3362 $paymentstatic->datepaye = $db->jdate($objp->dp);
3363 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
3364 $paymentstatic->num_payment = $objp->num_payment;
3366 $paymentstatic->paiementcode = $objp->payment_code;
3367 $paymentstatic->type_code = $objp->payment_code;
3368 $paymentstatic->type_label = $objp->payment_type;
3370 print
'<tr class="oddeven">';
3371 print
'<td class="nowraponall">';
3372 print $paymentstatic->getNomUrl(1);
3374 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
'</td>';
3375 $s =
$form->form_modes_reglement(
null, $objp->paiement_type,
'none',
'', 1, 0,
'', 1).
' '.$objp->num_payment;
3376 print
'<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).
'">';
3380 $bankaccountstatic->id = $objp->baid;
3381 $bankaccountstatic->ref = $objp->baref;
3382 $bankaccountstatic->label = $objp->baref;
3383 $bankaccountstatic->number = $objp->banumber;
3386 $bankaccountstatic->account_number = $objp->account_number;
3389 $accountingjournal->fetch($objp->fk_accountancy_journal);
3390 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
3393 print
'<td class="right">';
3394 if ($objp->baid > 0) {
3395 print $bankaccountstatic->getNomUrl(1,
'transactions');
3399 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
3400 print
'<td class="center">';
3402 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
3408 $totalpaid += $objp->amount;
3412 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td><td></td><td></td></tr>';
3435 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3436 print
'<span class="opacitymedium">';
3438 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
3440 print $langs->trans(
'AlreadyPaid');
3443 print
'</td><td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td><td> </td></tr>';
3446 $resteapayeraffiche = $resteapayer;
3448 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
3451 $creditnoteamount = 0;
3454 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
3455 $sql .=
" re.description, re.fk_invoice_supplier_source";
3456 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
3457 $sql .=
" WHERE fk_invoice_supplier = ".((int) $object->id);
3458 $resql = $db->query($sql);
3460 $num = $db->num_rows(
$resql);
3464 $obj = $db->fetch_object(
$resql);
3465 $invoice->fetch($obj->fk_invoice_supplier_source);
3466 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3468 print $langs->trans(
"CreditNote").
' ';
3471 print $langs->trans(
"Deposit").
' ';
3473 print $invoice->getNomUrl(0);
3475 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
3476 print
'<td class="right">';
3477 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=unlinkdiscount&discountid='.$obj->rowid.
'">'.
img_delete().
'</a>';
3481 $creditnoteamount += $obj->amount_ttc;
3484 $depositamount += $obj->amount_ttc;
3493 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3494 print
'<span class="opacitymedium">';
3495 print
$form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
3497 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3498 $resteapayeraffiche = 0;
3499 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3503 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3504 print
'<span class="opacitymedium">';
3505 print
$form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
3507 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3509 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3513 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3514 print
'<span class="opacitymedium">';
3515 print
$form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
3517 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3518 $resteapayeraffiche = 0;
3519 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3523 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3524 $text = $langs->trans(
"HelpAbandonOther");
3525 if ($object->close_note) {
3526 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.$object->close_note;
3528 print
'<span class="opacitymedium">';
3529 print
$form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
3531 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3532 $resteapayeraffiche = 0;
3533 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3537 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3538 print
'<span class="opacitymedium">';
3539 print $langs->trans(
"Billed");
3541 print
'</td><td class="right">'.price($object->total_ttc).
'</td><td> </td></tr>';
3544 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3545 print
'<span class="opacitymedium">';
3546 print $langs->trans(
'RemainderToPay');
3547 if ($resteapayeraffiche < 0) {
3548 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3552 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
3555 if (
isModEnabled(
'multicurreny') && $object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3556 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3557 print
'<span class="opacitymedium">';
3558 print $langs->trans(
'RemainderToPayMulticurrency');
3559 if ($resteapayeraffiche < 0) {
3560 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3564 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>';
3567 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3570 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3571 print $langs->trans(
'AlreadyPaidBack');
3572 print
' :</td><td class="right">'.price($sign * $totalpaid).
'</td><td> </td></tr>';
3575 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"Billed").
' :</td><td class="right">'.
price($sign * $object->total_ttc).
'</td><td> </td></tr>';
3578 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3579 print
'<span class="opacitymedium">';
3580 print $langs->trans(
'RemainderToPayBack');
3581 if ($resteapayeraffiche > 0) {
3582 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3586 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td><td> </td></tr>';
3589 if (
isModEnabled(
'multicurreny') && $object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3590 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3591 print
'<span class="opacitymedium">';
3592 print $langs->trans(
'RemainderToPayBackMulticurrency');
3593 if ($resteapayeraffiche> 0) {
3594 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3598 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>';
3613 print
'<div class="clearboth"></div><br>';
3615 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
3616 $blocname =
'contacts';
3617 $title = $langs->trans(
'ContactsAddresses');
3618 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3621 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
3623 $blocname =
'notes';
3624 $title = $langs->trans(
'Notes');
3625 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3632 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
3633 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3634 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
3635 print
'<input type="hidden" name="mode" value="">';
3636 print
'<input type="hidden" name="page_y" value="">';
3637 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
3638 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
3641 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
3644 print
'<div class="div-table-responsive-no-min">';
3645 print
'<table id="tablelines" class="noborder noshadow centpercent">';
3647 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
3648 $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
3649 $senderissupplier = 2;
3651 if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
3652 $senderissupplier = 1;
3656 if (!empty($object->lines)) {
3657 $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
3660 $num = count($object->lines);
3664 if ($action !=
'editline') {
3668 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
3669 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
3670 if (empty($reshook))
3671 $object->formAddObjectLine(1, $societe, $mysoc);
3682 if ($action !=
'presend') {
3687 print
'<div class="tabsAction">';
3690 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
3692 if (empty($reshook)) {
3696 $ventilExportCompta = $object->getVentilExportCompta();
3698 if ($ventilExportCompta == 0) {
3699 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=edit&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
3701 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
3706 $result = $discount->fetch(0, 0, $object->id);
3713 if (!$objectidnext && $object->close_code !=
'replaced' && $usercancreate) {
3714 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
3716 if ($usercancreate) {
3717 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
3718 } elseif (empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
3719 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
3726 if (count($object->lines)) {
3727 if ($usercanvalidate) {
3728 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid"';
3729 print
'>'.$langs->trans(
'Validate').
'</a>';
3731 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
3732 print
'>'.$langs->trans(
'Validate').
'</a>';
3738 if (empty($user->socid)) {
3741 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
3743 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'SendMail').
'</span>';
3750 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>';
3757 if ($resteapayer == 0) {
3758 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
3760 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>';
3765 if ($object->type ==
FactureFournisseur::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) < 0 && $usercancreate && empty($discount->id)) {
3766 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
3770 && (!empty($conf->global->SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) || $object->getSommePaiement() == 0)
3772 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>';
3776 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertToReduc').
'</a>';
3784 ($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)))
3787 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaid').
'</a>';
3791 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)) {
3792 if ($totalpaid > 0 || $totalcreditnotes > 0) {
3794 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
3796 if (empty($conf->global->INVOICE_CAN_NEVER_BE_CANCELED)) {
3797 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
3810 if (!$objectidnext) {
3811 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>';
3816 if ($action !=
'edit' && $usercancreate) {
3817 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=clone&socid='.$object->socid.
'">'.$langs->trans(
'ToClone').
'</a>';
3822 if (!$objectidnext && count($object->lines) > 0) {
3823 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
3828 $isErasable = $object->is_erasable();
3829 if ($action !=
'confirm_edit' && ($usercandelete || ($usercancreate && $isErasable == 1))) {
3830 $enableDelete =
false;
3832 $params = (empty($conf->use_javascript_ajax) ? array() : array(
'attr' => array(
'class' =>
'reposition')));
3834 if ($isErasable == -4) {
3835 $htmltooltip = $langs->trans(
"DisabledBecausePayments");
3836 } elseif ($isErasable == -3) {
3837 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastSituationInvoice");
3838 } elseif ($isErasable == -2) {
3839 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastInvoice");
3840 } elseif ($isErasable == -1) {
3841 $htmltooltip = $langs->trans(
"DisabledBecauseDispatchedInBookkeeping");
3842 } elseif ($isErasable <= 0) {
3843 $htmltooltip = $langs->trans(
"DisabledBecauseNotErasable");
3845 $enableDelete =
true;
3848 print
dolGetButtonAction($htmltooltip, $langs->trans(
"Delete"),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken(), $object->id, $enableDelete, $params);
3852 if ($action !=
'confirm_edit') {
3853 print
'<div class="fichecenter"><div class="fichehalfleft">';
3859 $subdir =
get_exdir($object->id, 2, 0, 0, $object,
'invoice_supplier').$ref;
3860 $filedir = $conf->fournisseur->facture->dir_output.
'/'.$subdir;
3861 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.$object->id;
3862 $genallowed = $usercanread;
3863 $delallowed = $usercancreate;
3864 $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF) ?
'' : $conf->global->INVOICE_SUPPLIER_ADDON_PDF));
3866 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
3867 $somethingshown = $formfile->numoffiles;
3870 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'invoice_supplier'));
3871 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
3873 print
'</div><div class="fichehalfright">';
3876 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3878 $somethingshown =
$formactions->showactions($object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
3880 print
'</div></div>';
3886 if (
GETPOST(
'modelselected')) {
3887 $action =
'presend';
3891 $modelmail =
'invoice_supplier_send';
3892 $defaulttopic =
'SendBillRef';
3893 $diroutput = $conf->fournisseur->facture->dir_output;
3894 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
3895 $trackid =
'sinv'.$object->id;
3897 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.