36 require
'../../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_invoice/modules_facturefournisseur.php';
40 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture-rec.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
45 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
46 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
47 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
48 if (!empty($conf->product->enabled)) {
49 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
52 if (!empty($conf->project->enabled)) {
53 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
54 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
57 if (!empty($conf->variants->enabled)) {
58 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
60 if (!empty($conf->accounting->enabled)) {
61 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
65 $langs->loadLangs(array(
'bills',
'compta',
'suppliers',
'companies',
'products',
'banks',
'admin'));
66 if (!empty($conf->incoterm->enabled)) {
67 $langs->load(
'incoterm');
71 $socid =
GETPOST(
'socid',
'int');
72 $action =
GETPOST(
'action',
'aZ09');
75 $cancel =
GETPOST(
'cancel',
'alpha');
76 $lineid =
GETPOST(
'lineid',
'int');
77 $projectid =
GETPOST(
'projectid',
'int');
78 $origin =
GETPOST(
'origin',
'alpha');
79 $originid =
GETPOST(
'originid',
'int');
80 $fac_recid =
GETPOST(
'fac_rec',
'int');
81 $rank = (
GETPOST(
'rank',
'int') > 0) ?
GETPOST(
'rank',
'int') : -1;
84 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
85 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
86 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
89 $hookmanager->initHooks(array(
'invoicesuppliercard',
'globalcard'));
95 $extrafields->fetch_name_optionals_label($object->table_element);
98 if ($id > 0 || !empty($ref)) {
99 $ret = $object->fetch($id, $ref);
103 $ret = $object->fetch_thirdparty();
111 if (!empty($user->socid)) {
112 $socid = $user->socid;
115 $result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture',
'fk_soc',
'rowid', $isdraft);
118 $usercanread = ($user->rights->fournisseur->facture->lire || $user->rights->supplier_invoice->lire);
119 $usercancreate = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
120 $usercandelete = ($user->rights->fournisseur->facture->supprimer || $user->rights->supplier_invoice->supprimer);
123 $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)));
124 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->fournisseur->supplier_invoice_advance->send);
127 $permissionnote = $usercancreate;
128 $permissiondellink = $usercancreate;
129 $permissiontoedit = $usercancreate;
130 $permissiontoadd = $usercancreate;
140 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
145 if (empty($reshook)) {
146 $backurlforlist = DOL_URL_ROOT.
'/fourn/facture/list.php';
148 if (empty($backtopage) || ($cancel && empty($id))) {
149 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
150 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
151 $backtopage = $backurlforlist;
153 $backtopage = DOL_URL_ROOT.
'/fourn/facture/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
159 if (!empty($backtopageforcancel)) {
160 header(
"Location: ".$backtopageforcancel);
162 } elseif (!empty($backtopage)) {
163 header(
"Location: ".$backtopage);
169 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
171 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
173 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
176 if (
GETPOST(
'linkedOrder') && empty($cancel) && $id > 0) {
178 $object->fetch_thirdparty();
179 $result = $object->add_object_linked(
'order_supplier',
GETPOST(
'linkedOrder'));
183 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
186 if (
GETPOST(
'newsupplierref',
'alphanohtml')) {
187 $objectutil->ref_supplier =
GETPOST(
'newsupplierref',
'alphanohtml');
191 $result = $objectutil->createFromClone($user, $id);
193 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
196 $langs->load(
"errors");
200 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
201 $idwarehouse =
GETPOST(
'idwarehouse');
204 $object->fetch_thirdparty();
206 $qualified_for_stock_change = 0;
207 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
208 $qualified_for_stock_change = $object->hasProductsOrServices(2);
210 $qualified_for_stock_change = $object->hasProductsOrServices(1);
214 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
215 $langs->load(
"stocks");
216 if (!$idwarehouse || $idwarehouse == -1) {
218 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
224 $result = $object->validate($user,
'', $idwarehouse);
229 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
230 $outputlangs = $langs;
232 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
233 $newlang =
GETPOST(
'lang_id',
'aZ09');
235 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
236 $newlang = $object->thirdparty->default_lang;
238 if (!empty($newlang)) {
240 $outputlangs->setDefaultLang($newlang);
242 $model = $object->model_pdf;
243 $ret = $object->fetch($id);
245 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
252 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
254 $object->fetch_thirdparty();
256 $isErasable = $object->is_erasable();
258 if (($usercandelete && $isErasable > 0) || ($usercancreate && $isErasable == 1)) {
259 $result = $object->delete($user);
261 header(
'Location: list.php?restore_lastsearch_values=1');
267 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
269 $result = $object->deleteline($lineid);
272 $object->line_order(
true);
289 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
296 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
299 $result = $discount->fetch(
GETPOST(
"discountid"));
300 $discount->unlink_invoice();
301 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercancreate) {
303 $result = $object->setPaid($user);
307 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes') {
310 $close_code =
GETPOST(
"close_code",
'restricthtml');
311 $close_note =
GETPOST(
"close_note",
'restricthtml');
313 $result = $object->setPaid($user, $close_code, $close_note);
318 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
320 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes') {
323 $close_code =
GETPOST(
"close_code",
'restricthtml');
324 $close_note =
GETPOST(
"close_note",
'restricthtml');
326 $result = $object->setCanceled($user, $close_code, $close_note);
331 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
336 if ($action ==
'setref_supplier' && $usercancreate) {
337 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alpha');
339 if ($object->update($user) < 0) {
343 $outputlangs = $langs;
345 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
346 $newlang =
GETPOST(
'lang_id',
'aZ09');
348 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
349 $newlang = $object->thirdparty->default_lang;
351 if (!empty($newlang)) {
353 $outputlangs->setDefaultLang($newlang);
355 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
356 $ret = $object->fetch($object->id);
357 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
363 if ($action ==
'setconditions' && $usercancreate) {
365 $object->cond_reglement_code = 0;
366 $object->cond_reglement_id = 0;
373 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
381 $old_date_echeance = $object->date_echeance;
382 $new_date_echeance = $object->calculate_date_lim_reglement();
383 if ($new_date_echeance > $old_date_echeance) {
384 $object->date_echeance = $new_date_echeance;
386 if ($object->date_echeance < $object->date) {
387 $object->date_echeance = $object->date;
389 $result = $object->update($user);
401 } elseif ($action ==
'set_incoterms' && !empty($conf->incoterm->enabled)) {
403 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
404 } elseif ($action ==
'setmode' && $usercancreate) {
406 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
407 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
409 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
410 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
412 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx',
'alpha')),
GETPOST(
'calculation_mode',
'int'));
413 } elseif ($action ==
'setbankaccount' && $usercancreate) {
415 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
419 if ($action ==
'settransportmode' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
421 $result = $object->setTransportMode(
GETPOST(
'transport_mode_id',
'int'));
422 } elseif ($action ==
'setlabel' && $usercancreate) {
425 $object->label =
GETPOST(
'label');
426 $result = $object->update($user);
430 } elseif ($action ==
'setdatef' && $usercancreate) {
432 if ($newdate > (
dol_now(
'tzuserrel') + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
433 if (empty($conf->global->INVOICE_MAX_FUTURE_DELAY)) {
434 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
436 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
442 $object->date = $newdate;
443 $date_echence_calc = $object->calculate_date_lim_reglement();
444 if (!empty($object->date_echeance) && $object->date_echeance < $date_echence_calc) {
445 $object->date_echeance = $date_echence_calc;
447 if ($object->date_echeance && $object->date_echeance < $object->date) {
448 $object->date_echeance = $object->date;
451 $result = $object->update($user);
455 } elseif ($action ==
'setdate_lim_reglement' && $usercancreate) {
457 $object->date_echeance =
dol_mktime(12, 0, 0,
GETPOST(
'date_lim_reglementmonth',
'int'),
GETPOST(
'date_lim_reglementday',
'int'),
GETPOST(
'date_lim_reglementyear',
'int'));
458 if (!empty($object->date_echeance) && $object->date_echeance < $object->date) {
459 $object->date_echeance = $object->date;
460 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
462 $result = $object->update($user);
466 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
468 if (
GETPOST(
"remise_id",
"int")) {
469 $ret = $object->fetch($id);
471 $result = $object->insert_discount(
GETPOST(
"remise_id",
"int"));
480 if (
GETPOST(
"remise_id_for_payment",
"int")) {
481 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
483 $discount->fetch(
GETPOST(
"remise_id_for_payment",
"int"));
490 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
494 $result = $discount->link_to_invoice(0, $id);
501 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
502 $outputlangs = $langs;
504 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
505 $newlang =
GETPOST(
'lang_id',
'aZ09');
507 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
508 $newlang = $object->thirdparty->default_lang;
510 if (!empty($newlang)) {
512 $outputlangs->setDefaultLang($newlang);
514 $ret = $object->fetch($id);
516 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
521 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
524 $object->fetch_thirdparty();
529 $result = $discountcheck->fetch(0, 0, $object->id);
541 $amount_ht = $amount_tva = $amount_ttc = array();
542 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
546 foreach ($object->lines as $line) {
547 if ($line->product_type < 9 && $line->total_ht != 0) {
548 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
550 $amount_ht[$keyforvatrate] += $line->total_ht;
551 $amount_tva[$keyforvatrate] += $line->total_tva;
552 $amount_ttc[$keyforvatrate] += $line->total_ttc;
553 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
554 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
555 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
562 $alreadypaid = $object->getSommePaiement();
563 if ($alreadypaid && abs($alreadypaid) < abs($object->total_ttc)) {
564 $ratio = abs(($object->total_ttc - $alreadypaid) / $object->total_ttc);
565 foreach ($amount_ht as $vatrate => $val) {
566 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
567 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
568 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
569 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
570 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
571 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
580 $discount->description =
'(CREDIT_NOTE)';
582 $discount->description =
'(DEPOSIT)';
584 $discount->description =
'(EXCESS PAID)';
586 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
588 $discount->discount_type = 1;
589 $discount->fk_soc = $object->socid;
590 $discount->fk_invoice_supplier_source = $object->id;
598 $sql =
'SELECT SUM(pf.amount) as total_paiements';
599 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'paiementfourn as p';
600 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN ('.
getEntity(
'c_paiement').
')';
601 $sql .=
' WHERE pf.fk_facturefourn = '.((int) $object->id);
602 $sql .=
' AND pf.fk_paiementfourn = p.rowid';
603 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
605 $resql = $db->query($sql);
610 $res = $db->fetch_object(
$resql);
611 $total_paiements = $res->total_paiements;
614 $total_creditnote_and_deposit = 0;
615 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
616 $sql .=
" re.description, re.fk_invoice_supplier_source";
617 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
618 $sql .=
" WHERE fk_invoice_supplier = ".((int) $object->id);
619 $resql = $db->query($sql);
621 while ($obj = $db->fetch_object(
$resql)) {
622 $total_creditnote_and_deposit += $obj->amount_ttc;
628 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object->total_ttc;
629 $discount->amount_tva = 0;
630 $discount->tva_tx = 0;
631 $discount->vat_src_code =
'';
633 $result = $discount->create($user);
639 foreach ($amount_ht as $tva_tx => $xxx) {
640 $discount->amount_ht = abs($amount_ht[$tva_tx]);
641 $discount->amount_tva = abs($amount_tva[$tva_tx]);
642 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
643 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
644 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
645 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
650 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
651 $vat_src_code = $reg[1];
652 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
655 $discount->tva_tx = abs($tva_tx);
656 $discount->vat_src_code = $vat_src_code;
658 $result = $discount->create($user);
669 $result = $object->setPaid($user);
684 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate) {
689 $result = $paiementfourn->fetch(
GETPOST(
'paiement_id'));
691 $result = $paiementfourn->delete();
692 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
698 } elseif ($action ==
'add' && $usercancreate) {
701 $object->socid =
GETPOST(
'socid',
'int');
703 $selectedLines =
GETPOST(
'toselect',
'array');
710 $ret = $extrafields->setOptionalsFromPost(
null, $object);
723 if (
GETPOST(
'type',
'int') ===
'') {
724 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
729 if (empty($dateinvoice)) {
730 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
732 $_GET[
'socid'] = $_POST[
'socid'];
734 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
740 if (!(
GETPOST(
'fac_replacement',
'int') > 0)) {
742 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
747 $result = $object->fetch(
GETPOST(
'fac_replacement',
'int'));
748 $object->fetch_thirdparty();
750 $object->ref =
GETPOST(
'ref',
'alphanohtml');
751 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alpha');
752 $object->socid =
GETPOST(
'socid',
'int');
753 $object->libelle =
GETPOST(
'label',
'alphanohtml');
754 $object->date = $dateinvoice;
755 $object->date_echeance = $datedue;
756 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
757 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
758 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
759 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
760 $object->fk_account =
GETPOST(
'fk_account',
'int');
761 $object->fk_project = ($tmpproject > 0) ? $tmpproject :
null;
762 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
763 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
764 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
765 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
766 $object->transport_mode_id =
GETPOST(
'transport_mode_id',
'int');
769 $object->fk_facture_source =
GETPOST(
'fac_replacement',
'int');
772 $id = $object->createFromCurrent($user);
782 $sourceinvoice =
GETPOST(
'fac_avoir',
'int');
783 if (!($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
785 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
787 if (
GETPOST(
'socid',
'int') < 1) {
788 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
793 if (empty($dateinvoice)) {
794 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
796 $_GET[
'socid'] = $_POST[
'socid'];
798 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
804 if (!
GETPOST(
'ref_supplier')) {
805 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplier')),
null,
'errors');
807 $_GET[
'socid'] = $_POST[
'socid'];
812 $tmpproject =
GETPOST(
'projectid',
'int');
815 $object->ref =
GETPOST(
'ref',
'alphanohtml');
816 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
817 $object->socid =
GETPOST(
'socid',
'int');
818 $object->libelle =
GETPOST(
'label',
'alphanohtml');
819 $object->label =
GETPOST(
'label',
'alphanohtml');
820 $object->date = $dateinvoice;
821 $object->date_echeance = $datedue;
822 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
823 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
824 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
825 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
826 $object->fk_account =
GETPOST(
'fk_account',
'int');
827 $object->fk_project = ($tmpproject > 0) ? $tmpproject :
null;
828 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
829 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
830 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
831 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
832 $object->transport_mode_id =
GETPOST(
'transport_mode_id',
'int');
835 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
838 $id = $object->create($user);
844 if (
GETPOST(
'invoiceAvoirWithLines',
'int') == 1 && $id > 0) {
846 if ($facture_source->fetch($object->fk_facture_source) > 0) {
849 foreach ($facture_source->lines as $line) {
851 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
855 $line->fk_facture_fourn = $object->id;
856 $line->fk_parent_line = $fk_parent_line;
858 $line->subprice = -$line->subprice;
859 $line->pa_ht = -$line->pa_ht;
860 $line->total_ht = -$line->total_ht;
861 $line->total_tva = -$line->total_tva;
862 $line->total_ttc = -$line->total_ttc;
863 $line->total_localtax1 = -$line->total_localtax1;
864 $line->total_localtax2 = -$line->total_localtax2;
866 $result = $line->insert();
868 $object->lines[] = $line;
871 if ($result > 0 && $line->product_type == 9) {
872 $fk_parent_line = $result;
876 $object->update_price(1);
880 if (
GETPOST(
'invoiceAvoirWithPaymentRestAmount',
'int') == 1 && $id > 0) {
882 if ($facture_source->fetch($object->fk_facture_source) > 0) {
883 $totalpaid = $facture_source->getSommePaiement();
884 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
885 $totaldeposits = $facture_source->getSumDepositsUsed();
886 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
887 $desc = $langs->trans(
'invoiceAvoirLineWithPaymentRestAmount');
888 $retAddLine = $object->addline($desc, $remain_to_pay, 0, 0, 0, 1, 0, 0,
'',
'', 0,
'',
'TTC');
890 if ($retAddLine < 0) {
898 if (empty($dateinvoice)) {
900 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
902 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
909 $object->socid =
GETPOST(
'socid',
'int');
910 $object->type =
GETPOST(
'type',
'alphanohtml');
911 $object->ref =
GETPOST(
'ref',
'alphanohtml');
912 $object->date = $dateinvoice;
913 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
914 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
915 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
916 $object->model_pdf =
GETPOST(
'model',
'alphanohtml');
917 $object->fk_project =
GETPOST(
'projectid',
'int');
918 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
919 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
920 $object->fk_account =
GETPOST(
'fk_account',
'int');
924 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
925 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
926 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
927 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
930 $object->fac_rec = $fac_recid;
932 $fac_rec->fetch($object->fac_rec);
933 $fac_rec->fetch_lines();
934 $object->lines = $fac_rec->lines;
936 $id = $object->create($user);
940 if (
GETPOST(
'socid',
'int') < 1) {
941 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
946 if (empty($dateinvoice)) {
947 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
949 $_GET[
'socid'] = $_POST[
'socid'];
951 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
957 if (!
GETPOST(
'ref_supplier')) {
958 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplier')),
null,
'errors');
960 $_GET[
'socid'] = $_POST[
'socid'];
965 $tmpproject =
GETPOST(
'projectid',
'int');
968 $object->socid =
GETPOST(
'socid',
'int');
969 $object->type =
GETPOST(
'type',
'alphanohtml');
970 $object->ref =
GETPOST(
'ref',
'alphanohtml');
971 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
972 $object->socid =
GETPOST(
'socid',
'int');
973 $object->libelle =
GETPOST(
'label',
'alphanohtml');
974 $object->label =
GETPOST(
'label',
'alphanohtml');
975 $object->date = $dateinvoice;
976 $object->date_echeance = $datedue;
977 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
978 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
979 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
980 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
981 $object->fk_account =
GETPOST(
'fk_account',
'int');
982 $object->fk_project = ($tmpproject > 0) ? $tmpproject :
null;
983 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
984 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
985 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
986 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
987 $object->transport_mode_id =
GETPOST(
'transport_mode_id');
990 if (empty($object->date_echeance)) {
991 $object->date_echeance = $object->calculate_date_lim_reglement();
994 $object->fetch_thirdparty();
997 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
999 $element = $subelement =
GETPOST(
'origin',
'alpha');
1007 if ($element ==
'order') {
1008 $element = $subelement =
'commande';
1010 if ($element ==
'propal') {
1011 $element =
'comm/propal'; $subelement =
'propal';
1013 if ($element ==
'contract') {
1014 $element = $subelement =
'contrat';
1016 if ($element ==
'order_supplier') {
1017 $element =
'fourn'; $subelement =
'fournisseur.commande';
1019 if ($element ==
'project') {
1020 $element =
'projet';
1022 $object->origin =
GETPOST(
'origin',
'alpha');
1023 $object->origin_id =
GETPOST(
'originid',
'int');
1026 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
1027 $classname = ucfirst($subelement);
1028 if ($classname ==
'Fournisseur.commande') {
1029 $classname =
'CommandeFournisseur';
1031 $objectsrc =
new $classname($db);
1032 $objectsrc->fetch($originid);
1033 $objectsrc->fetch_thirdparty();
1035 if (!empty($object->origin) && !empty($object->origin_id)) {
1036 $object->linkedObjectsIds[$object->origin] = $object->origin_id;
1040 if ($object->origin ==
'reception') {
1041 $objectsrc->fetchObjectLinked();
1043 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1044 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1045 $object->linkedObjectsIds[
'order_supplier'] = $value;
1050 $id = $object->create($user);
1054 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
1055 $classname = ucfirst($subelement);
1056 if ($classname ==
'Fournisseur.commande') {
1057 $classname =
'CommandeFournisseur';
1059 $srcobject =
new $classname($db);
1061 $result = $srcobject->fetch(
GETPOST(
'originid',
'int'));
1064 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1069 $amountdeposit = array();
1070 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)) {
1071 if ($typeamount ==
'amount') {
1072 $amount = $valuedeposit;
1074 $amount = $srcobject->total_ttc * ($valuedeposit / 100);
1077 $TTotalByTva = array();
1078 foreach ($srcobject->lines as &$line) {
1079 if (!empty($line->special_code)) {
1082 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1085 foreach ($TTotalByTva as $tva => &$total) {
1086 $coef = $total / $srcobject->total_ttc;
1087 $am = $amount * $coef;
1088 $amount_ttc_diff += $am;
1089 $amountdeposit[$tva] += $am / (1 + $tva / 100);
1092 if ($typeamount ==
'amount') {
1093 $amountdeposit[0] = $valuedeposit;
1094 } elseif ($typeamount ==
'variable') {
1097 $lines = $srcobject->lines;
1098 $numlines = count($lines);
1099 for ($i = 0; $i < $numlines; $i++) {
1101 if (empty($lines[$i]->qty)) {
1104 if (!empty($lines[$i]->special_code)) {
1108 $totalamount += $lines[$i]->total_ht;
1109 $tva_tx = $lines[$i]->tva_tx;
1110 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $valuedeposit) / 100;
1114 if ($totalamount == 0) {
1115 $amountdeposit[0] = 0;
1123 $amount_ttc_diff = $amountdeposit[0];
1126 foreach ($amountdeposit as $tva => $amount) {
1127 if (empty($amount)) {
1132 'amount' =>
'FixAmount',
1133 'variable' =>
'VarAmount'
1135 $descline =
'(DEPOSIT)';
1137 if ($typeamount ==
'amount') {
1138 $descline .=
' ('.price($valuedeposit,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
')';
1139 } elseif ($typeamount ==
'variable') {
1140 $descline .=
' ('.$valuedeposit.
'%)';
1143 $descline .=
' - '.$srcobject->ref;
1144 $result = $object->addline(
1151 (empty($conf->global->INVOICE_PRODUCTID_DEPOSIT) ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT),
1156 $lines[$i]->info_bits,
1166 $lines[$i]->special_code,
1173 $diff = $object->total_ttc - $amount_ttc_diff;
1175 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0) {
1176 $object->fetch_lines();
1177 $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100);
1178 $object->updateline($object->lines[0]->id, $object->lines[0]->desc, $subprice_diff, $object->lines[0]->qty, $object->lines[0]->remise_percent, $object->lines[0]->date_start, $object->lines[0]->date_end, $object->lines[0]->tva_tx, 0, 0,
'HT', $object->lines[0]->info_bits, $object->lines[0]->product_type, 0, 0, 0, $object->lines[0]->pa_ht, $object->lines[0]->label, 0, array(), 100);
1180 } elseif ($result > 0) {
1181 $lines = $srcobject->lines;
1182 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1183 $srcobject->fetch_lines();
1184 $lines = $srcobject->lines;
1187 $num = count($lines);
1188 for ($i = 0; $i < $num; $i++) {
1189 if (!in_array($lines[$i]->
id, $selectedLines)) {
1193 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
1194 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1197 if (method_exists($lines[$i],
'fetch_optionals')) {
1198 $lines[$i]->fetch_optionals();
1203 $date_start = $lines[$i]->date_debut_prevue;
1204 if ($lines[$i]->date_debut_reel) {
1205 $date_start = $lines[$i]->date_debut_reel;
1207 if ($lines[$i]->date_start) {
1208 $date_start = $lines[$i]->date_start;
1210 $date_end = $lines[$i]->date_fin_prevue;
1211 if ($lines[$i]->date_fin_reel) {
1212 $date_end = $lines[$i]->date_fin_reel;
1214 if ($lines[$i]->date_end) {
1215 $date_end = $lines[$i]->date_end;
1219 $object->special_code = $lines[$i]->special_code;
1222 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
1224 $pu_currency = $lines[$i]->multicurrency_subprice;
1226 $pu = $lines[$i]->subprice;
1231 $result = $object->addline(
1235 $lines[$i]->localtax1_tx,
1236 $lines[$i]->localtax2_tx,
1238 $lines[$i]->fk_product,
1239 $lines[$i]->remise_percent,
1243 $lines[$i]->info_bits,
1248 $lines[$i]->array_options,
1249 $lines[$i]->fk_unit,
1252 $lines[$i]->ref_supplier,
1253 $lines[$i]->special_code
1263 $object->fetch_lines();
1270 } elseif (!$error) {
1271 $id = $object->create($user);
1280 $langs->load(
"errors");
1285 $_GET[
'socid'] = $_POST[
'socid'];
1289 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1290 $outputlangs = $langs;
1291 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1298 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1301 } elseif ($action ==
'updateline' && $usercancreate) {
1306 $object->fetch_thirdparty();
1310 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_subprice') !=
'') {
1312 $price_base_type =
'HT';
1315 $price_base_type =
'TTC';
1318 if (
GETPOST(
'productid') > 0) {
1320 if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
1322 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1327 $prod->fetch(
GETPOST(
'productid'));
1328 $label = $prod->description;
1329 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1330 $label =
GETPOST(
'product_desc',
'restricthtml');
1333 $type = $prod->type;
1335 $label =
GETPOST(
'product_desc',
'restricthtml');
1344 if (preg_match(
'/\*/', $tva_tx)) {
1349 $tva_tx = str_replace(
'*',
'', $tva_tx);
1350 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1351 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1357 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1358 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1360 if (is_array($extralabelsline)) {
1361 foreach ($extralabelsline as $key => $value) {
1362 unset($_POST[
"options_".$key]);
1366 $result = $object->updateline(
GETPOST(
'lineid',
'int'), $label, $up, $tva_tx, $localtax1_tx, $localtax2_tx,
price2num(
GETPOST(
'qty'),
'MS'),
GETPOST(
'productid',
'int'), $price_base_type, $info_bits, $type, $remise_percent, 0, $date_start, $date_end, $array_options,
GETPOST(
'units'), $pu_devise,
GETPOST(
'fourn_ref',
'alpha'));
1368 unset($_POST[
'label']);
1369 unset($_POST[
'fourn_ref']);
1370 unset($_POST[
'date_starthour']);
1371 unset($_POST[
'date_startmin']);
1372 unset($_POST[
'date_startsec']);
1373 unset($_POST[
'date_startday']);
1374 unset($_POST[
'date_startmonth']);
1375 unset($_POST[
'date_startyear']);
1376 unset($_POST[
'date_endhour']);
1377 unset($_POST[
'date_endmin']);
1378 unset($_POST[
'date_endsec']);
1379 unset($_POST[
'date_endday']);
1380 unset($_POST[
'date_endmonth']);
1381 unset($_POST[
'date_endyear']);
1382 unset($_POST[
'price_ttc']);
1383 unset($_POST[
'price_ht']);
1390 } elseif ($action ==
'addline' && $usercancreate) {
1394 $ret = $object->fetch($id);
1399 $ret = $object->fetch_thirdparty();
1401 $langs->load(
'errors');
1410 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1411 if ($prod_entry_mode ==
'free') {
1414 $idprod =
GETPOST(
'idprod',
'int');
1422 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
1426 if (empty($remise_percent)) {
1427 $remise_percent = 0;
1431 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1432 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
1434 if (is_array($extralabelsline)) {
1436 foreach ($extralabelsline as $key => $value) {
1437 unset($_POST[
"options_".$key]);
1441 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
1442 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1445 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
1446 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
1449 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
1450 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
1453 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
1454 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
1457 if (!
GETPOST(
'qty',
'alpha')) {
1458 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1462 if (!$error && !empty($conf->variants->enabled) && $prod_entry_mode !=
'free') {
1463 if ($combinations =
GETPOST(
'combinations',
'array')) {
1467 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1468 $idprod = $res->fk_product_child;
1470 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
1476 if ($prod_entry_mode !=
'free' && empty($error)) {
1480 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
1485 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
1487 $res = $productsupplier->fetch($idprod);
1490 if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) {
1492 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1493 if ($productsupplier->fourn_socid != $socid) {
1494 $productsupplier->ref_supplier =
'';
1497 $fksoctosearch = $object->thirdparty->id;
1498 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1500 } elseif (
GETPOST(
'idprodfournprice',
'alpha') > 0) {
1501 $qtytosearch = $qty;
1503 $idprod = $productsupplier->get_buyprice(
GETPOST(
'idprodfournprice',
'alpha'), $qtytosearch);
1504 $res = $productsupplier->fetch($idprod);
1508 $label = $productsupplier->label;
1510 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1511 $outputlangs = $langs;
1513 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1514 $newlang =
GETPOST(
'lang_id',
'aZ09');
1516 if (empty($newlang)) {
1517 $newlang = $object->thirdparty->default_lang;
1519 if (!empty($newlang)) {
1520 $outputlangs =
new Translate(
"", $conf);
1521 $outputlangs->setDefaultLang($newlang);
1523 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->description;
1525 $desc = $productsupplier->description;
1528 if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
1529 $desc = $productsupplier->desc_supplier;
1533 if (trim($product_desc) == trim($desc) && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
1536 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
1537 $desc = $product_desc;
1539 if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
1540 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
1543 $ref_supplier = $productsupplier->ref_supplier;
1547 $tva_tx =
get_default_tva($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
1548 $tva_npr =
get_default_npr($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
1550 if (empty($tva_tx)) {
1553 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
1554 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
1556 $type = $productsupplier->type;
1557 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'price_ht_devise') !=
'') {
1558 $price_base_type =
'HT';
1560 $pu_devise =
price2num($price_ht_devise,
'CU');
1561 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'price_ttc_devise') !=
'') {
1562 $price_base_type =
'TTC';
1564 $pu_devise =
price2num($price_ttc_devise,
'CU');
1566 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
1567 if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) {
1568 $pu = $productsupplier->fourn_pu;
1571 $pu = $productsupplier->fourn_pu;
1572 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
1580 $result = $object->addline(
1595 min($rank, count($object->lines) + 1),
1598 $productsupplier->fk_unit,
1605 if ($idprod == -99 || $idprod == 0) {
1608 $langs->load(
"errors");
1609 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
1611 if ($idprod == -1) {
1614 $langs->load(
"errors");
1615 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
1617 } elseif (empty($error)) {
1618 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1619 $tva_tx = str_replace(
'*',
'', $tva_tx);
1620 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1621 $desc = $product_desc;
1623 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
1625 $fk_unit =
GETPOST(
'units',
'alpha');
1627 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1632 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1633 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1635 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'price_ht_devise') !=
'') {
1639 $pu_ht =
price2num($pu_ttc / (1 + ($tva_tx / 100)),
'MU');
1641 $price_base_type =
'HT';
1642 $pu_devise =
price2num($price_devise,
'CU');
1644 $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);
1648 if (!$error && $result > 0) {
1652 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1653 $outputlangs = $langs;
1655 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1656 $newlang =
GETPOST(
'lang_id',
'aZ09');
1658 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1659 $newlang = $object->thirdparty->default_lang;
1661 if (!empty($newlang)) {
1662 $outputlangs =
new Translate(
"", $conf);
1663 $outputlangs->setDefaultLang($newlang);
1665 $model = $object->model_pdf;
1666 $ret = $object->fetch($id);
1668 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1674 unset($_POST [
'prod_entry_mode']);
1676 unset($_POST[
'qty']);
1677 unset($_POST[
'type']);
1678 unset($_POST[
'remise_percent']);
1679 unset($_POST[
'pu']);
1680 unset($_POST[
'price_ht']);
1681 unset($_POST[
'multicurrency_price_ht']);
1682 unset($_POST[
'price_ttc']);
1683 unset($_POST[
'fourn_ref']);
1684 unset($_POST[
'tva_tx']);
1685 unset($_POST[
'label']);
1686 unset($localtax1_tx);
1687 unset($localtax2_tx);
1688 unset($_POST[
'np_marginRate']);
1689 unset($_POST[
'np_markRate']);
1690 unset($_POST[
'dp_desc']);
1691 unset($_POST[
'idprodfournprice']);
1692 unset($_POST[
'units']);
1694 unset($_POST[
'date_starthour']);
1695 unset($_POST[
'date_startmin']);
1696 unset($_POST[
'date_startsec']);
1697 unset($_POST[
'date_startday']);
1698 unset($_POST[
'date_startmonth']);
1699 unset($_POST[
'date_startyear']);
1700 unset($_POST[
'date_endhour']);
1701 unset($_POST[
'date_endmin']);
1702 unset($_POST[
'date_endsec']);
1703 unset($_POST[
'date_endday']);
1704 unset($_POST[
'date_endmonth']);
1705 unset($_POST[
'date_endyear']);
1712 } elseif ($action ==
'classin' && $usercancreate) {
1713 $object->fetch($id);
1714 $result = $object->setProject($projectid);
1715 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
1717 $object->fetch($id);
1719 $totalpaid = $object->getSommePaiement();
1720 $resteapayer = $object->total_ttc - $totalpaid;
1723 $ventilExportCompta = $object->getVentilExportCompta();
1725 if (!$ventilExportCompta) {
1728 $idwarehouse =
GETPOST(
'idwarehouse');
1730 $object->fetch_thirdparty();
1732 $qualified_for_stock_change = 0;
1733 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1734 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1736 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1740 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
1741 $langs->load(
"stocks");
1742 if (!$idwarehouse || $idwarehouse == -1) {
1744 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1749 $object->setDraft($user, $idwarehouse);
1752 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1753 $outputlangs = $langs;
1755 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1756 $newlang =
GETPOST(
'lang_id',
'aZ09');
1758 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1759 $newlang = $object->thirdparty->default_lang;
1761 if (!empty($newlang)) {
1762 $outputlangs =
new Translate(
"", $conf);
1763 $outputlangs->setDefaultLang($newlang);
1765 $model = $object->model_pdf;
1766 $ret = $object->fetch($id);
1768 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1777 } elseif ($action ==
'reopen' && $usercancreate) {
1779 $result = $object->fetch($id);
1782 $result = $object->setUnpaid($user);
1784 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
1793 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1796 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
1798 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
1799 $trackid =
'sinv'.$object->id;
1800 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1803 $upload_dir = $conf->fournisseur->facture->dir_output;
1804 $permissiontoadd = $usercancreate;
1805 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1808 if ($action ==
'calculate') {
1809 $calculationrule =
GETPOST(
'calculationrule');
1811 $object->fetch($id);
1812 $object->fetch_thirdparty();
1813 $result = $object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0, $object->thirdparty);
1819 if ($action ==
'update_extras') {
1823 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1831 $result = $object->insertExtraFields(
'BILL_SUPPLIER_MODIFY');
1839 $action =
'edit_extras';
1843 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1844 if ($action ==
'addcontact') {
1845 $result = $object->fetch($id);
1847 if ($result > 0 && $id > 0) {
1850 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1854 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1857 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1858 $langs->load(
"errors");
1859 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1864 } elseif ($action ==
'swapstatut') {
1866 if ($object->fetch($id)) {
1867 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1871 } elseif ($action ==
'deletecontact') {
1873 $object->fetch($id);
1874 $result = $object->delete_contact(
GETPOST(
"lineid",
'int'));
1877 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1893 $bankaccountstatic =
new Account($db);
1895 if (!empty($conf->project->enabled)) {
1901 $title = $langs->trans(
'SupplierInvoice').
" - ".$langs->trans(
'Card');
1902 $help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
1906 if ($action ==
'create') {
1913 $currency_code = $conf->currency;
1916 if (
GETPOST(
'socid',
'int') > 0) {
1918 $societe->fetch(
GETPOST(
'socid',
'int'));
1919 if (!empty($conf->multicurrency->enabled) && !empty($societe->multicurrency_code)) {
1920 $currency_code = $societe->multicurrency_code;
1924 if (!empty($origin) && !empty($originid)) {
1926 $element = $subelement = $origin;
1928 if ($element ==
'project') {
1929 $projectid = $originid;
1930 $element =
'projet';
1934 if ($element ==
'order') {
1935 $element = $subelement =
'commande';
1937 if ($element ==
'propal') {
1938 $element =
'comm/propal'; $subelement =
'propal';
1940 if ($element ==
'contract') {
1941 $element = $subelement =
'contrat';
1943 if ($element ==
'order_supplier') {
1944 $element =
'fourn'; $subelement =
'fournisseur.commande';
1947 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
1948 $classname = ucfirst($subelement);
1949 if ($classname ==
'Fournisseur.commande') {
1950 $classname =
'CommandeFournisseur';
1952 $objectsrc =
new $classname($db);
1953 $objectsrc->fetch($originid);
1954 $objectsrc->fetch_thirdparty();
1956 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1959 $soc = $objectsrc->thirdparty;
1960 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_supplier_id) ? $soc->cond_reglement_supplier_id : 0));
1961 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_supplier_id) ? $soc->mode_reglement_supplier_id : 0));
1962 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1963 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_supplier_percent) ? $soc->remise_supplier_percent : 0));
1964 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1965 $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'';
1966 $transport_mode_id = (!empty($objectsrc->transport_mode_id) ? $objectsrc->transport_mode_id : (!empty($soc->transport_mode_id) ? $soc->transport_mode_id : 0));
1968 if (!empty($conf->multicurrency->enabled)) {
1969 if (!empty($objectsrc->multicurrency_code)) {
1970 $currency_code = $objectsrc->multicurrency_code;
1972 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1973 $currency_tx = $objectsrc->multicurrency_tx;
1978 $dateinvoice = ($datetmp ==
'' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $datetmp);
1980 $datedue = ($datetmp ==
'' ?-1 : $datetmp);
1983 $objectsrc->fetch_optionals();
1984 $object->array_options = $objectsrc->array_options;
1986 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
1987 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
1988 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
1989 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
1991 $dateinvoice = ($datetmp ==
'' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $datetmp);
1993 $datedue = ($datetmp ==
'' ?-1 : $datetmp);
1995 if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) {
1996 $currency_code = $soc->multicurrency_code;
2001 if (empty($cond_reglement_id)) {
2002 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2006 if (empty($mode_reglement_id)) {
2007 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2010 $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));
2011 $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));
2013 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2014 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2015 print
'<input type="hidden" name="action" value="add">';
2016 if (!empty($societe->id) && $societe->id > 0) {
2017 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2019 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2020 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2021 if (!empty($currency_tx)) {
2022 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2027 print
'<table class="border centpercent">';
2030 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
2034 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2035 $invoice_predefined->fetch($fac_recid);
2039 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2042 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2043 $absolute_discount = $societe->getAvailableDiscounts(
'',
'', 0, 1);
2044 print $societe->getNomUrl(1,
'supplier');
2045 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2047 print
img_picto(
'',
'company').$form->select_company(empty($societe->id) ? 0 : $societe->id,
'socid',
'(s.fournisseur = 1 and s.status = 1)',
'SelectThirdParty', 0, 0,
null, 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
2049 if (!empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE)) {
2050 print
'<script type="text/javascript">
2051 $(document).ready(function() {
2052 $("#socid").change(function() {
2053 var socid = $(this).val();
2054 var fac_rec = $(\'#fac_rec\').val();
2055 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
2060 if ($fac_recid <= 0) {
2061 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>';
2067 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2068 $invoice_predefined->fetch($fac_recid);
2070 $dateinvoice = $invoice_predefined->date_when;
2071 if (empty($projectid)) {
2072 $projectid = $invoice_predefined->fk_project;
2074 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2075 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2076 $fk_account = $invoice_predefined->fk_account;
2077 $note_public = $invoice_predefined->note_public;
2078 $note_private = $invoice_predefined->note_private;
2080 if (!empty($invoice_predefined->multicurrency_code)) {
2081 $currency_code = $invoice_predefined->multicurrency_code;
2083 if (!empty($invoice_predefined->multicurrency_tx)) {
2084 $currency_tx = $invoice_predefined->multicurrency_tx;
2087 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2088 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2089 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2091 $resql = $db->query($sql);
2093 $num = $db->num_rows(
$resql);
2097 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2099 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2100 print
'<option value="0" selected></option>';
2102 $objp = $db->fetch_object(
$resql);
2103 print
'<option value="'.$objp->rowid.
'"';
2104 if ($fac_recid == $objp->rowid) {
2106 $exampletemplateinvoice->fetch($fac_recid);
2108 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2113 if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED)) {
2114 print
'<script type="text/javascript">
2115 $(document).ready(function() {
2116 $("#fac_rec").change(function() {
2117 console.log("We have changed the template invoice - Reload page");
2118 var fac_rec = $(this).val();
2119 var socid = $(\'#socid\').val();
2120 // For template invoice change, we must reuse data of template, not input already done, so we call a GET with action=create, not a POST submit.
2121 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
2135 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"';
2136 if (!empty($societe->id) && $societe->id > 0) {
2142 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2144 print
'<div class="tagtable">'.
"\n";
2147 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2148 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOST(
'type',
'int')?
'' :
'checked').
'> ';
2149 $desc =
$form->textwithpicto($tmp.$langs->trans(
"InvoiceStandardAsk"), $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2151 print
'</div></div>';
2153 if (empty($origin) || ($origin ==
'order_supplier' && !empty($originid))) {
2155 if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) {
2156 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2157 $tmp=
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOST(
'type') == 3 ?
' checked' :
'') .
'> ';
2158 print
'<script type="text/javascript">
2159 jQuery(document).ready(function() {
2160 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2161 jQuery("#radio_standard").prop("checked", true);
2163 jQuery("#typedeposit, #valuedeposit").click(function() {
2164 jQuery("#radio_deposit").prop("checked", true);
2166 jQuery("#typedeposit").change(function() {
2167 console.log("We change type of down payment");
2168 jQuery("#radio_deposit").prop("checked", true);
2169 setRadioForTypeOfInvoice();
2171 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2172 setRadioForTypeOfInvoice();
2174 function setRadioForTypeOfInvoice() {
2175 console.log("Change radio");
2176 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2177 jQuery(".checkforselect").prop("disabled", true);
2178 jQuery(".checkforselect").prop("checked", false);
2180 jQuery(".checkforselect").prop("disabled", false);
2181 jQuery(".checkforselect").prop("checked", true);
2187 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2188 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2189 print
'<table class="nobordernopadding"><tr>';
2193 if ($origin ==
'order_supplier') {
2194 print
'<td class="nowrap" style="padding-left: 15px">';
2196 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2197 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2198 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2200 print
$form->selectarray(
'typedeposit', $arraylist,
GETPOST(
'typedeposit',
'aZ09'), 0, 0, 0,
'', 1);
2202 print
'<td class="nowrap" style="padding-left: 5px">';
2203 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' .
GETPOST(
'valuedeposit',
'int') .
'"/>';
2206 print
'</tr></table>';
2208 print
'</div></div>';
2277 if (empty($origin)) {
2278 if (!empty($societe->id) && $societe->id > 0) {
2280 if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) {
2282 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2289 foreach ($facids as $key => $valarray) {
2290 $newinvoice_static->id = $key;
2291 $newinvoice_static->ref = $valarray [
'ref'];
2292 $newinvoice_static->statut = $valarray [
'status'];
2293 $newinvoice_static->type = $valarray [
'type'];
2294 $newinvoice_static->paye = $valarray [
'paye'];
2296 $optionsav .=
'<option value="'.$key.
'"';
2297 if ($key ==
GETPOST(
'fac_avoir',
'int')) {
2298 $optionsav .=
' selected';
2301 $optionsav .= $newinvoice_static->ref;
2302 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
2303 $optionsav .=
'</option>';
2306 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2307 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
2309 $tmp .=
' disabled';
2313 print
'<script type="text/javascript">
2314 jQuery(document).ready(function() {
2315 if (! jQuery("#radio_creditnote").is(":checked"))
2317 jQuery("#credit_note_options").hide();
2319 jQuery("#radio_creditnote").click(function() {
2320 jQuery("#credit_note_options").show();
2322 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2323 jQuery("#credit_note_options").hide();
2327 $text = $tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
' ';
2329 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2331 $text .=
' disabled';
2335 $text .=
'<option value="-1"></option>';
2336 $text .= $optionsav;
2338 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
2340 $text .=
'</select>';
2341 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2344 print
'<div id="credit_note_options" class="clearboth">';
2345 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' :
'').
' /> ';
2346 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
2347 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' :
'').
' /> ';
2348 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
2351 print
'</div></div>';
2354 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2355 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2356 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
2357 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
2358 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2360 print
'</div></div>'.
"\n";
2368 if (!empty($societe->id) && $societe->id > 0) {
2370 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2372 $thirdparty = $societe;
2374 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2375 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2381 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth200" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
2384 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
2385 print
$form->selectDate($dateinvoice,
'',
'',
'',
'',
"add", 1, 1);
2389 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
2390 print
$form->selectDate($datedue,
'ech',
'',
'',
'',
"add", 1, 1);
2394 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2395 $form->select_conditions_paiements(
GETPOSTISSET(
'cond_reglement_id') ?
GETPOST(
'cond_reglement_id',
'int') : $cond_reglement_id,
'cond_reglement_id');
2399 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2400 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2401 $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');
2405 if (!empty($conf->banque->enabled)) {
2406 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2407 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);
2412 if (!empty($conf->project->enabled)) {
2415 $langs->load(
'projects');
2416 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2417 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');
2418 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>';
2423 if (!empty($conf->incoterm->enabled)) {
2425 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
2426 print
'<td colspan="3" class="maxwidthonsmartphone">';
2427 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 :
''));
2432 if (!empty($conf->multicurrency->enabled)) {
2434 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
2435 print
'<td class="maxwidthonsmartphone">';
2436 print
$form->selectMultiCurrency((
GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code),
'multicurrency_code');
2442 if ($fac_recid > 0) {
2443 $dateexample = $newdateinvoice ? $newdateinvoice : $dateinvoice;
2444 if (empty($dateexample)) {
2447 $substitutionarray = array(
2448 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
2449 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
2450 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
2451 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
2452 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
2453 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
2454 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
2455 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
2456 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
2457 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
2458 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
2461 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
2462 foreach ($substitutionarray as $key => $val) {
2463 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
2465 $htmltext .=
'</i>';
2469 if (!empty($conf->intracommreport->enabled)) {
2470 $langs->loadLangs(array(
"intracommreport"));
2471 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
2472 $form->selectTransportMode(
GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
2476 if (empty($reshook)) {
2477 print $object->showOptionals($extrafields,
'create');
2481 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2483 $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%');
2484 print $doleditor->Create(1);
2490 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
2492 $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%');
2493 print $doleditor->Create(1);
2499 if (!empty($objectsrc) && is_object($objectsrc)) {
2500 print
"\n<!-- ".$classname.
" info -->";
2502 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2503 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2504 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2505 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2506 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2508 $txt = $langs->trans($classname);
2509 if ($classname ==
'CommandeFournisseur') {
2510 $langs->load(
'orders');
2511 $txt = $langs->trans(
"SupplierOrder");
2513 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
2515 $objectsrc->fetchObjectLinked($originid, $origin,
'',
'invoice_supplier');
2517 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
2520 if (is_array($invoice_supplier)) {
2521 $cntinvoice = count($invoice_supplier);
2523 if ($cntinvoice >= 1) {
2525 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
2530 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2531 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2532 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2533 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2536 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2537 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2539 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2541 if (!empty($conf->multicurrency->enabled)) {
2542 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2543 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2544 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2550 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
2551 print $hookmanager->resPrint;
2558 print
$form->buttonsSaveCancel(
"CreateDraft");
2561 if (!empty($objectsrc) && is_object($objectsrc)) {
2564 $title = $langs->trans(
'ProductsAndServices');
2567 print
'<div class="div-table-responsive-no-min">';
2568 print
'<table class="noborder centpercent">';
2570 $objectsrc->printOriginLinesList(
'', $selectedLines);
2578 if ($id > 0 || !empty($ref)) {
2585 $productstatic =
new Product($db);
2587 $result = $object->fetch($id, $ref);
2589 $langs->load(
"errors");
2590 print $langs->trans(
"ErrorRecordNotFound");
2596 $result = $object->fetch_thirdparty();
2602 $societe = $object->thirdparty;
2604 $totalpaid = $object->getSommePaiement();
2605 $totalcreditnotes = $object->getSumCreditNotesUsed();
2606 $totaldeposits = $object->getSumDepositsUsed();
2614 $resteapayer =
price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
2617 if (!empty($conf->multicurrency->enabled)) {
2618 $multicurrency_totalpaid = $object->getSommePaiement(1);
2619 $multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
2620 $multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
2621 $multicurrency_resteapayer =
price2num($object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
2625 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 && $object->multicurrency_code != $conf->currency) {
2626 $resteapayer =
price2num($multicurrency_resteapayer / $object->multicurrency_tx,
'MT');
2630 if ($object->paye) {
2633 $resteapayeraffiche = $resteapayer;
2635 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
2636 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2637 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2639 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2640 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2643 $absolute_discount = $societe->getAvailableDiscounts(
'', $filterabsolutediscount, 0, 1);
2644 $absolute_creditnote = $societe->getAvailableDiscounts(
'', $filtercreditnote, 0, 1);
2645 $absolute_discount =
price2num($absolute_discount,
'MT');
2646 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2651 $objectidnext = $object->getIdReplacingInvoice();
2654 $titre = $langs->trans(
'SupplierInvoice');
2661 if ($action ==
'converttoreduc') {
2663 $type_fac =
'ExcessPaid';
2665 $type_fac =
'CreditNote';
2667 $type_fac =
'Deposit';
2669 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
2670 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
2671 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
2675 if ($action ==
'clone') {
2677 $formquestion = array(
2678 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplier"),
'value' => $langs->trans(
"CopyOf").
' '.$object->ref_supplier),
2679 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
2682 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
2686 if ($action ==
'valid') {
2688 if (preg_match(
'/^[\(]?PROV/i', $object->ref) || empty($object->ref)) {
2690 $numref = $object->getNextNumRef($societe);
2692 $numref = $object->ref;
2699 $text = $langs->trans(
'ConfirmValidateBill', $numref);
2707 $formquestion = array();
2709 $qualified_for_stock_change = 0;
2710 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2711 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2713 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2716 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
2717 $langs->load(
"stocks");
2718 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2721 $warehouse_array = $warehouse->list_array();
2722 if (count($warehouse_array) == 1) {
2723 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
2724 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
2727 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
2729 $formquestion = array(
2730 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
2734 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
2739 if ($action ==
'edit') {
2740 $formquestion = array();
2742 $qualified_for_stock_change = 0;
2743 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2744 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2746 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2748 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
2749 $langs->load(
"stocks");
2750 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2753 $warehouse_array = $warehouse->list_array();
2754 if (count($warehouse_array) == 1) {
2755 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
2756 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
2759 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
2761 $formquestion = array(
2762 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
2765 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill', $object->ref),
'confirm_edit', $formquestion, 1, 1);
2769 if ($action ==
'paid' && ($resteapayer <= 0 || (!empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) && $resteapayer == $object->total_ttc))) {
2770 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill', $object->ref),
'confirm_paid',
'', 0, 1);
2773 if ($action ==
'paid' && $resteapayer > 0 && (empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $resteapayer != $object->total_ttc)) {
2777 $close[$i][
'code'] =
'discount_vat';
2779 $close[$i][
'code'] =
'badsupplier';
2781 $close[$i][
'code'] =
'other';
2785 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
2787 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
2789 $close[$i][
'label'] = $langs->trans(
"Other");
2793 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
2795 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
2797 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
2800 foreach ($close as $key => $val) {
2801 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
2805 $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'));
2807 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially', $object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
2811 if ($action ==
'canceled') {
2813 $close[1][
'code'] =
'badsupplier';
2814 $close[2][
'code'] =
'abandon';
2816 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
2817 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
2819 $close[1][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier", $object->ref), $close[1][
'label'], 1);
2820 $close[2][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
2822 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
2823 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
2826 $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'));
2828 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill', $object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 250);
2832 if ($action ==
'delete') {
2833 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete',
'', 0, 1);
2835 if ($action ==
'deletepayment') {
2836 $payment_id =
GETPOST(
'paiement_id');
2837 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
2841 if ($action ==
'ask_deleteline') {
2842 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2847 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
2848 if (empty($reshook)) {
2850 } elseif ($reshook > 0) {
2860 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2862 $morehtmlref =
'<div class="refidno">';
2864 $morehtmlref .=
$form->editfieldkey(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'', 0, 1);
2865 $morehtmlref .=
$form->editfieldval(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
2867 $morehtmlref .=
'<br>'.$langs->trans(
'ThirdParty').
' : '.$object->thirdparty->getNomUrl(1,
'supplier');
2868 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2869 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$object->thirdparty->id.
'&search_company='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
2872 if (!empty($conf->project->enabled)) {
2873 $langs->load(
"projects");
2874 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
2875 if ($usercancreate) {
2876 if ($action !=
'classify') {
2877 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
2879 if ($action ==
'classify') {
2881 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
2882 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
2883 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2884 $morehtmlref .= $formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
2885 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2886 $morehtmlref .=
'</form>';
2888 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
2891 if (!empty($object->fk_project)) {
2893 $proj->fetch($object->fk_project);
2894 $morehtmlref .=
' : '.$proj->getNomUrl(1);
2896 $morehtmlref .=
' - '.$proj->title;
2903 $morehtmlref .=
'</div>';
2905 $object->totalpaid = $totalpaid;
2907 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2909 print
'<div class="fichecenter">';
2910 print
'<div class="fichehalfleft">';
2911 print
'<div class="underbanner clearboth"></div>';
2913 print
'<table class="border tableforfield" width="100%">';
2916 print
'<tr><td class="titlefield">'.$langs->trans(
'Type').
'</td><td>';
2917 print
'<span class="badgeneutral">';
2918 print $object->getLibType();
2922 $facreplaced->fetch($object->fk_facture_source);
2923 print
' '.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1));
2927 if ($object->fk_facture_source > 0) {
2928 $facusing->fetch($object->fk_facture_source);
2929 print
' '.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1));
2931 print
' '.$langs->transnoentities(
"CorrectedInvoiceNotFound");
2935 $facidavoir = $object->getListIdAvoirFromInvoice();
2936 if (count($facidavoir) > 0) {
2937 $invoicecredits = array();
2938 foreach ($facidavoir as $id) {
2940 $facavoir->fetch($id);
2941 $invoicecredits[] = $facavoir->getNomUrl(1);
2943 print
' ('.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits) .
')';
2945 if (isset($objectidnext) && $objectidnext > 0) {
2947 $facthatreplace->fetch($objectidnext);
2948 print
' ('.$langs->transnoentities(
"ReplacedByInvoice", $facthatreplace->getNomUrl(1)).
')';
2952 $result = $discount->fetch(0, 0, $object->id);
2954 print
' <span class="opacitymediumbycolor paddingleft">';
2955 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
2956 $s = str_replace(
'{s1}', $object->getLibType(1), $s);
2957 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
2959 print
'</span><br>';
2963 if ($object->fk_fac_rec_source > 0) {
2965 $result = $tmptemplate->fetch($object->fk_fac_rec_source);
2967 print
' <span class="opacitymediumbycolor paddingleft">';
2968 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->titre).
'</a>';
2969 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
2979 print
'<!-- Discounts -->'.
"\n";
2980 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
2983 $thirdparty = $societe;
2985 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?facid='.$object->id);
2986 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2992 print
'<td>'.$form->editfieldkey(
"Label",
'label', $object->label, $object, $usercancreate).
'</td>';
2993 print
'<td>'.$form->editfieldval(
"Label",
'label', $object->label, $object, $usercancreate).
'</td>';
3001 print
$form->editfieldkey(
"DateInvoice",
'datef', $object->datep, $object, $form_permission,
'datepicker');
3002 print
'</td><td colspan="3">';
3003 print
$form->editfieldval(
"Date",
'datef', $object->datep, $object, $form_permission,
'datepicker');
3007 $langs->load(
'bills');
3008 print
'<tr><td class="nowrap">';
3009 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3010 print $langs->trans(
'PaymentConditions');
3012 if ($action !=
'editconditions' && $form_permission) {
3013 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editconditions&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetConditions'), 1).
'</a></td>';
3015 print
'</tr></table>';
3017 if ($action ==
'editconditions') {
3018 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
3020 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none');
3027 print
$form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', $object->date_echeance, $object, $form_permission2,
'datepicker');
3029 print
$form->editfieldval(
"DateMaxPayment",
'date_lim_reglement', $object->date_echeance, $object, $form_permission2,
'datepicker');
3030 if ($action !=
'editdate_lim_reglement' && $object->hasDelay()) {
3036 $langs->load(
'bills');
3037 print
'<tr><td class="nowrap">';
3038 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3039 print $langs->trans(
'PaymentMode');
3041 if ($action !=
'editmode' && $form_permission2) {
3042 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>';
3044 print
'</tr></table>';
3046 if ($action ==
'editmode') {
3047 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3049 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
3054 if (!empty($conf->multicurrency->enabled)) {
3058 print
'<table class="nobordernopadding" width="100%"><tr><td>';
3059 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
3061 if ($action !=
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT) {
3062 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>';
3064 print
'</tr></table>';
3066 if ($action ==
'editmulticurrencycode') {
3067 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
3069 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
3074 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3077 print
'<table class="nobordernopadding centpercent"><tr><td>';
3078 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
3080 if ($action !=
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3081 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>';
3083 print
'</tr></table>';
3085 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
3086 if ($action ==
'actualizemulticurrencyrate') {
3089 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
3091 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
3092 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3093 print
'<div class="inline-block"> ';
3094 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
3103 if (!empty($conf->banque->enabled)) {
3104 print
'<tr><td class="nowrap">';
3105 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3106 print $langs->trans(
'BankAccount');
3108 if ($action !=
'editbankaccount' && $usercancreate) {
3109 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>';
3111 print
'</tr></table>';
3113 if ($action ==
'editbankaccount') {
3114 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
3116 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
3123 if (!empty($conf->incoterm->enabled)) {
3125 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3126 print $langs->trans(
'IncotermLabel');
3127 print
'<td><td class="right">';
3128 if ($usercancreate) {
3129 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
3133 print
'</td></tr></table>';
3136 if ($action !=
'editincoterm') {
3137 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
3139 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
3145 if (!empty($conf->intracommreport->enabled)) {
3146 $langs->loadLangs(array(
"intracommreport"));
3148 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3149 print $langs->trans(
'IntracommReportTransportMode');
3151 if ($action !=
'editmode' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
3152 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit().
'</a></td>';
3154 print
'</tr></table>';
3157 if ($action ==
'editmode') {
3158 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->transport_mode_id,
'transport_mode_id', 1, 1);
3160 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->transport_mode_id,
'none');
3167 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
3172 print
'<div class="fichehalfright">';
3173 print
'<div class="underbanner clearboth"></div>';
3175 print
'<table class="border tableforfield centpercent">';
3177 if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) {
3179 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
3180 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>';
3184 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
3185 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>';
3189 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
3190 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>';
3195 print
'<tr><td class="titlefield">'.$langs->trans(
'AmountHT').
'</td>';
3196 print
'<td class="nowrap right amountcard">'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3200 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td>';
3201 print
'<td class="nowrap right amountcard">';
3202 if (
GETPOST(
'calculationrule')) {
3203 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
3205 $calculationrule = (empty($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND) ?
'totalofround' :
'roundoftotal');
3207 if ($calculationrule ==
'totalofround') {
3208 $calculationrulenum = 1;
3210 $calculationrulenum = 2;
3213 if ($object->getVentilExportCompta() == 0) {
3214 $s =
'<span class="hideonsmartphone opacitymedium">'.$langs->trans(
"ReCalculate").
' </span>';
3215 $s .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=calculate&calculationrule=totalofround">'.$langs->trans(
"Mode1").
'</a>';
3217 $s .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=calculate&calculationrule=roundoftotal">'.$langs->trans(
"Mode2").
'</a>';
3218 print
'<div class="inline-block">';
3219 print
$form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum).
'<br>'.$langs->trans(
"CalculationRuleDescSupplier"), 2, 1,
img_picto(
'',
'help'),
'', 3,
'', 0,
'recalculate');
3220 print
' ';
3223 print
price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency);
3228 if ($societe->localtax1_assuj ==
"1") {
3229 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $societe->country_code).
'</td>';
3230 print
'<td class="nowrap right amountcard">'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3233 if ($societe->localtax2_assuj ==
"1") {
3234 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $societe->country_code).
'</td>';
3235 print
'<td class="nowrap right amountcard">'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3238 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td>';
3239 print
'<td colspan="3" class="nowrap right amountcard">'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3254 $nbrows = 9; $nbcols = 3;
3255 if (!empty($conf->project->enabled)) {
3258 if (!empty($conf->banque->enabled)) {
3259 $nbrows++; $nbcols++;
3261 if (!empty($conf->incoterm->enabled)) {
3264 if (!empty($conf->multicurrency->enabled)) {
3269 if ($societe->localtax1_assuj ==
"1") {
3272 if ($societe->localtax2_assuj ==
"1") {
3276 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
3277 $sql .=
' c.id as paiement_type, c.code as payment_code,';
3278 $sql .=
' pf.amount,';
3279 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
3280 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
3281 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
3282 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
3283 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
3284 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
3285 $sql .=
' WHERE pf.fk_facturefourn = '.((int) $object->id);
3286 $sql .=
' ORDER BY p.datep, p.tms';
3288 $result = $db->query($sql);
3290 $num = $db->num_rows($result);
3293 print
'<div class="div-table-responsive-no-min">';
3294 print
'<table class="noborder paymenttable" width="100%">';
3295 print
'<tr class="liste_titre">';
3297 print
'<td>'.$langs->trans(
'Date').
'</td>';
3298 print
'<td>'.$langs->trans(
'Type').
'</td>';
3299 if (!empty($conf->banque->enabled)) {
3300 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
3302 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
3303 print
'<td width="18"> </td>';
3308 $objp = $db->fetch_object($result);
3310 $paymentstatic->id = $objp->rowid;
3311 $paymentstatic->datepaye = $db->jdate($objp->dp);
3312 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
3313 $paymentstatic->num_payment = $objp->num_payment;
3315 $paymentstatic->paiementcode = $objp->payment_code;
3316 $paymentstatic->type_code = $objp->payment_code;
3317 $paymentstatic->type_label = $objp->payment_type;
3319 print
'<tr class="oddeven">';
3321 print $paymentstatic->getNomUrl(1);
3323 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
'</td>';
3325 print
$form->form_modes_reglement(
null, $objp->paiement_type,
'none').
' '.$objp->num_payment;
3327 if (!empty($conf->banque->enabled)) {
3328 $bankaccountstatic->id = $objp->baid;
3329 $bankaccountstatic->ref = $objp->baref;
3330 $bankaccountstatic->label = $objp->baref;
3331 $bankaccountstatic->number = $objp->banumber;
3333 if (!empty($conf->accounting->enabled)) {
3334 $bankaccountstatic->account_number = $objp->account_number;
3337 $accountingjournal->fetch($objp->fk_accountancy_journal);
3338 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
3341 print
'<td class="right">';
3342 if ($objp->baid > 0) {
3343 print $bankaccountstatic->getNomUrl(1,
'transactions');
3347 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
3348 print
'<td class="center">';
3350 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
3356 $totalpaid += $objp->amount;
3360 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td><td></td><td></td></tr>';
3383 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3384 print
'<span class="opacitymedium">';
3386 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
3388 print $langs->trans(
'AlreadyPaid');
3391 print
'</td><td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td><td> </td></tr>';
3394 $resteapayeraffiche = $resteapayer;
3396 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
3399 $creditnoteamount = 0;
3402 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
3403 $sql .=
" re.description, re.fk_invoice_supplier_source";
3404 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
3405 $sql .=
" WHERE fk_invoice_supplier = ".((int) $object->id);
3406 $resql = $db->query($sql);
3408 $num = $db->num_rows(
$resql);
3412 $obj = $db->fetch_object(
$resql);
3413 $invoice->fetch($obj->fk_invoice_supplier_source);
3414 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3416 print $langs->trans(
"CreditNote").
' ';
3419 print $langs->trans(
"Deposit").
' ';
3421 print $invoice->getNomUrl(0);
3423 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
3424 print
'<td class="right">';
3425 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=unlinkdiscount&discountid='.$obj->rowid.
'">'.
img_delete().
'</a>';
3429 $creditnoteamount += $obj->amount_ttc;
3432 $depositamount += $obj->amount_ttc;
3441 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3442 print
'<span class="opacitymedium">';
3443 print
$form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
3445 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3446 $resteapayeraffiche = 0;
3447 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3451 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3452 print
'<span class="opacitymedium">';
3453 print
$form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
3455 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3457 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3461 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3462 print
'<span class="opacitymedium">';
3463 print
$form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
3465 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3466 $resteapayeraffiche = 0;
3467 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3471 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3472 $text = $langs->trans(
"HelpAbandonOther");
3473 if ($object->close_note) {
3474 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.$object->close_note;
3476 print
'<span class="opacitymedium">';
3477 print
$form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
3479 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3480 $resteapayeraffiche = 0;
3481 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3485 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3486 print
'<span class="opacitymedium">';
3487 print $langs->trans(
"Billed");
3489 print
'</td><td class="right">'.price($object->total_ttc).
'</td><td> </td></tr>';
3492 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3493 print
'<span class="opacitymedium">';
3494 print $langs->trans(
'RemainderToPay');
3495 if ($resteapayeraffiche < 0) {
3496 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3500 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
3503 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3504 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3505 print
'<span class="opacitymedium">';
3506 print $langs->trans(
'RemainderToPayMulticurrency');
3507 if ($resteapayeraffiche < 0) {
3508 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3512 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>';
3516 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3519 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3520 print $langs->trans(
'AlreadyPaidBack');
3521 print
' :</td><td class="right">'.price($sign * $totalpaid).
'</td><td> </td></tr>';
3524 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"Billed").
' :</td><td class="right">'.
price($sign * $object->total_ttc).
'</td><td> </td></tr>';
3527 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3528 print
'<span class="opacitymedium">';
3529 print $langs->trans(
'RemainderToPayBack');
3530 if ($resteapayeraffiche > 0) {
3531 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3535 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td><td> </td></tr>';
3538 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3539 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3540 print
'<span class="opacitymedium">';
3541 print $langs->trans(
'RemainderToPayBackMulticurrency');
3542 if ($resteapayeraffiche> 0) {
3543 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3547 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>';
3562 print
'<div class="clearboth"></div><br>';
3564 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
3565 $blocname =
'contacts';
3566 $title = $langs->trans(
'ContactsAddresses');
3567 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3570 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
3572 $blocname =
'notes';
3573 $title = $langs->trans(
'Notes');
3574 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3581 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">';
3582 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3583 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
3584 print
'<input type="hidden" name="mode" value="">';
3585 print
'<input type="hidden" name="page_y" value="">';
3586 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
3587 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
3590 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
3593 print
'<div class="div-table-responsive-no-min">';
3594 print
'<table id="tablelines" class="noborder noshadow centpercent">';
3596 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
3597 $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
3598 $senderissupplier = 2;
3600 if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
3601 $senderissupplier = 1;
3605 if (!empty($object->lines)) {
3606 $ret = $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
3609 $num = count($object->lines);
3613 if ($action !=
'editline') {
3617 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
3618 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
3619 if (empty($reshook))
3620 $object->formAddObjectLine(1, $societe, $mysoc);
3631 if ($action !=
'presend') {
3636 print
'<div class="tabsAction">';
3639 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
3641 if (empty($reshook)) {
3645 $ventilExportCompta = $object->getVentilExportCompta();
3647 if ($ventilExportCompta == 0) {
3648 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=edit&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
3650 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
3655 $result = $discount->fetch(0, 0, $object->id);
3662 if (!$objectidnext && $object->close_code !=
'replaced' && $usercancreate) {
3663 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
3665 if ($usercancreate) {
3666 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
3667 } elseif (empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
3668 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
3675 if (count($object->lines)) {
3676 if ($usercanvalidate) {
3677 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid"';
3678 print
'>'.$langs->trans(
'Validate').
'</a>';
3680 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
3681 print
'>'.$langs->trans(
'Validate').
'</a>';
3687 if (empty($user->socid)) {
3690 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
3692 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'SendMail').
'</span>';
3699 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>';
3706 if ($resteapayer == 0) {
3707 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
3709 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>';
3714 if ($object->type ==
FactureFournisseur::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) < 0 && $usercancreate && empty($discount->id)) {
3715 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
3719 && (!empty($conf->global->SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) || $object->getSommePaiement() == 0)
3721 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>';
3725 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertToReduc').
'</a>';
3733 ($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)))
3736 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaid').
'</a>';
3740 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)) {
3741 if ($totalpaid > 0 || $totalcreditnotes > 0) {
3743 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
3745 if (empty($conf->global->INVOICE_CAN_NEVER_BE_CANCELED)) {
3746 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
3759 if (!$objectidnext) {
3760 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>';
3765 if ($action !=
'edit' && $usercancreate) {
3766 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=clone&socid='.$object->socid.
'">'.$langs->trans(
'ToClone').
'</a>';
3771 if (!$objectidnext && count($object->lines) > 0) {
3772 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
3777 $isErasable = $object->is_erasable();
3778 if ($action !=
'confirm_edit' && ($user->rights->fournisseur->facture->supprimer || ($usercancreate && $isErasable == 1))) {
3780 if ($isErasable == -4) {
3781 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecausePayments").
'">'.$langs->trans(
'Delete').
'</a>';
3782 } elseif ($isErasable == -3) {
3783 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastSituationInvoice").
'">'.$langs->trans(
'Delete').
'</a>';
3784 } elseif ($isErasable == -2) {
3785 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInvoice").
'">'.$langs->trans(
'Delete').
'</a>';
3786 } elseif ($isErasable == -1) {
3787 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Delete').
'</a>';
3788 } elseif ($isErasable <= 0) {
3789 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotErasable").
'">'.$langs->trans(
'Delete').
'</a>';
3791 print
'<a class="butActionDelete'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
'Delete').
'</a>';
3796 if ($action !=
'confirm_edit') {
3797 print
'<div class="fichecenter"><div class="fichehalfleft">';
3803 $subdir =
get_exdir($object->id, 2, 0, 0, $object,
'invoice_supplier').$ref;
3804 $filedir = $conf->fournisseur->facture->dir_output.
'/'.$subdir;
3805 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.$object->id;
3806 $genallowed = $usercanread;
3807 $delallowed = $usercancreate;
3808 $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF) ?
'' : $conf->global->INVOICE_SUPPLIER_ADDON_PDF));
3810 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
3811 $somethingshown = $formfile->numoffiles;
3814 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'invoice_supplier'));
3815 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
3817 print
'</div><div class="fichehalfright">';
3820 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3822 $somethingshown =
$formactions->showactions($object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
3824 print
'</div></div>';
3830 if (
GETPOST(
'modelselected')) {
3831 $action =
'presend';
3835 $modelmail =
'invoice_supplier_send';
3836 $defaulttopic =
'SendBillRef';
3837 $diroutput = $conf->fournisseur->facture->dir_output;
3838 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
3839 $trackid =
'sinv'.$object->id;
3841 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';