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;
139 $parameters = array(
'socid'=>$socid);
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);
888 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 0, 0, 0, 1, 0, 0,
'',
'',
'TTC');
894 if (empty($dateinvoice)) {
896 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")), null,
'errors');
898 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
905 $object->socid =
GETPOST(
'socid',
'int');
906 $object->type =
GETPOST(
'type',
'alphanohtml');
907 $object->ref =
GETPOST(
'ref',
'alphanohtml');
908 $object->date = $dateinvoice;
909 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
910 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
911 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
912 $object->model_pdf =
GETPOST(
'model',
'alphanohtml');
913 $object->fk_project =
GETPOST(
'projectid',
'int');
914 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
915 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
916 $object->fk_account =
GETPOST(
'fk_account',
'int');
920 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
921 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
922 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
923 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
926 $object->fac_rec = $fac_recid;
928 $fac_rec->fetch($object->fac_rec);
929 $fac_rec->fetch_lines();
930 $object->lines = $fac_rec->lines;
932 $id = $object->create($user);
936 if (
GETPOST(
'socid',
'int') < 1) {
937 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')), null,
'errors');
942 if (empty($dateinvoice)) {
943 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')), null,
'errors');
945 $_GET[
'socid'] = $_POST[
'socid'];
947 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
953 if (!
GETPOST(
'ref_supplier')) {
954 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplier')), null,
'errors');
956 $_GET[
'socid'] = $_POST[
'socid'];
961 $tmpproject =
GETPOST(
'projectid',
'int');
964 $object->socid =
GETPOST(
'socid',
'int');
965 $object->type =
GETPOST(
'type',
'alphanohtml');
966 $object->ref =
GETPOST(
'ref',
'alphanohtml');
967 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
968 $object->socid =
GETPOST(
'socid',
'int');
969 $object->libelle =
GETPOST(
'label',
'alphanohtml');
970 $object->label =
GETPOST(
'label',
'alphanohtml');
971 $object->date = $dateinvoice;
972 $object->date_echeance = $datedue;
973 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
974 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
975 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
976 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
977 $object->fk_account =
GETPOST(
'fk_account',
'int');
978 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
979 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
980 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
981 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
982 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
983 $object->transport_mode_id =
GETPOST(
'transport_mode_id');
986 if (empty($object->date_echeance)) {
987 $object->date_echeance = $object->calculate_date_lim_reglement();
990 $object->fetch_thirdparty();
993 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
995 $element = $subelement =
GETPOST(
'origin',
'alpha');
1003 if ($element ==
'order') {
1004 $element = $subelement =
'commande';
1006 if ($element ==
'propal') {
1007 $element =
'comm/propal'; $subelement =
'propal';
1009 if ($element ==
'contract') {
1010 $element = $subelement =
'contrat';
1012 if ($element ==
'order_supplier') {
1013 $element =
'fourn'; $subelement =
'fournisseur.commande';
1015 if ($element ==
'project') {
1016 $element =
'projet';
1018 $object->origin =
GETPOST(
'origin',
'alpha');
1019 $object->origin_id =
GETPOST(
'originid',
'int');
1022 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
1023 $classname = ucfirst($subelement);
1024 if ($classname ==
'Fournisseur.commande') {
1025 $classname =
'CommandeFournisseur';
1027 $objectsrc =
new $classname($db);
1028 $objectsrc->fetch($originid);
1029 $objectsrc->fetch_thirdparty();
1031 if (!empty($object->origin) && !empty($object->origin_id)) {
1032 $object->linkedObjectsIds[$object->origin] = $object->origin_id;
1036 if ($object->origin ==
'reception') {
1037 $objectsrc->fetchObjectLinked();
1039 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1040 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1041 $object->linkedObjectsIds[
'order_supplier'] = $value;
1046 $id = $object->create($user);
1050 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
1051 $classname = ucfirst($subelement);
1052 if ($classname ==
'Fournisseur.commande') {
1053 $classname =
'CommandeFournisseur';
1055 $srcobject =
new $classname($db);
1057 $result = $srcobject->fetch(
GETPOST(
'originid',
'int'));
1060 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1065 $amountdeposit = array();
1066 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)) {
1067 if ($typeamount ==
'amount') {
1068 $amount = $valuedeposit;
1070 $amount = $srcobject->total_ttc * ($valuedeposit / 100);
1073 $TTotalByTva = array();
1074 foreach ($srcobject->lines as &$line) {
1075 if (!empty($line->special_code)) {
1078 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1081 foreach ($TTotalByTva as $tva => &$total) {
1082 $coef = $total / $srcobject->total_ttc;
1083 $am = $amount * $coef;
1084 $amount_ttc_diff += $am;
1085 $amountdeposit[$tva] += $am / (1 + $tva / 100);
1088 if ($typeamount ==
'amount') {
1089 $amountdeposit[0] = $valuedeposit;
1090 } elseif ($typeamount ==
'variable') {
1093 $lines = $srcobject->lines;
1094 $numlines = count($lines);
1095 for ($i = 0; $i < $numlines; $i++) {
1097 if (empty($lines[$i]->qty)) {
1100 if (!empty($lines[$i]->special_code)) {
1104 $totalamount += $lines[$i]->total_ht;
1105 $tva_tx = $lines[$i]->tva_tx;
1106 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $valuedeposit) / 100;
1110 if ($totalamount == 0) {
1111 $amountdeposit[0] = 0;
1119 $amount_ttc_diff = $amountdeposit[0];
1122 foreach ($amountdeposit as $tva => $amount) {
1123 if (empty($amount)) {
1128 'amount' =>
'FixAmount',
1129 'variable' =>
'VarAmount'
1131 $descline =
'(DEPOSIT)';
1133 if ($typeamount ==
'amount') {
1134 $descline .=
' ('.price($valuedeposit,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
')';
1135 } elseif ($typeamount ==
'variable') {
1136 $descline .=
' ('.$valuedeposit.
'%)';
1139 $descline .=
' - '.$srcobject->ref;
1140 $result = $object->addline(
1147 (empty($conf->global->INVOICE_PRODUCTID_DEPOSIT) ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT),
1152 $lines[$i]->info_bits,
1162 $lines[$i]->special_code,
1169 $diff = $object->total_ttc - $amount_ttc_diff;
1171 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0) {
1172 $object->fetch_lines();
1173 $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100);
1174 $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);
1176 } elseif ($result > 0) {
1177 $lines = $srcobject->lines;
1178 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1179 $srcobject->fetch_lines();
1180 $lines = $srcobject->lines;
1183 $num = count($lines);
1184 for ($i = 0; $i < $num; $i++) {
1185 if (!in_array($lines[$i]->
id, $selectedLines)) {
1189 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
1190 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1193 if (method_exists($lines[$i],
'fetch_optionals')) {
1194 $lines[$i]->fetch_optionals();
1199 $date_start = $lines[$i]->date_debut_prevue;
1200 if ($lines[$i]->date_debut_reel) {
1201 $date_start = $lines[$i]->date_debut_reel;
1203 if ($lines[$i]->date_start) {
1204 $date_start = $lines[$i]->date_start;
1206 $date_end = $lines[$i]->date_fin_prevue;
1207 if ($lines[$i]->date_fin_reel) {
1208 $date_end = $lines[$i]->date_fin_reel;
1210 if ($lines[$i]->date_end) {
1211 $date_end = $lines[$i]->date_end;
1215 $object->special_code = $lines[$i]->special_code;
1218 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
1220 $pu_currency = $lines[$i]->multicurrency_subprice;
1222 $pu = $lines[$i]->subprice;
1227 $result = $object->addline(
1231 $lines[$i]->localtax1_tx,
1232 $lines[$i]->localtax2_tx,
1234 $lines[$i]->fk_product,
1235 $lines[$i]->remise_percent,
1239 $lines[$i]->info_bits,
1244 $lines[$i]->array_options,
1245 $lines[$i]->fk_unit,
1248 $lines[$i]->ref_supplier,
1249 $lines[$i]->special_code
1259 $object->fetch_lines();
1266 } elseif (!$error) {
1267 $id = $object->create($user);
1276 $langs->load(
"errors");
1281 $_GET[
'socid'] = $_POST[
'socid'];
1285 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1286 $outputlangs = $langs;
1287 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1294 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1297 } elseif ($action ==
'updateline' && $usercancreate) {
1302 $object->fetch_thirdparty();
1306 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_subprice') !=
'') {
1308 $price_base_type =
'HT';
1311 $price_base_type =
'TTC';
1314 if (
GETPOST(
'productid') > 0) {
1316 if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
1318 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"), null,
'warnings');
1323 $prod->fetch(
GETPOST(
'productid'));
1324 $label = $prod->description;
1325 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1326 $label =
GETPOST(
'product_desc',
'restricthtml');
1329 $type = $prod->type;
1331 $label =
GETPOST(
'product_desc',
'restricthtml');
1340 if (preg_match(
'/\*/', $tva_tx)) {
1345 $tva_tx = str_replace(
'*',
'', $tva_tx);
1346 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1347 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1353 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1354 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1356 if (is_array($extralabelsline)) {
1357 foreach ($extralabelsline as $key => $value) {
1358 unset($_POST[
"options_".$key]);
1362 $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'));
1364 unset($_POST[
'label']);
1365 unset($_POST[
'fourn_ref']);
1366 unset($_POST[
'date_starthour']);
1367 unset($_POST[
'date_startmin']);
1368 unset($_POST[
'date_startsec']);
1369 unset($_POST[
'date_startday']);
1370 unset($_POST[
'date_startmonth']);
1371 unset($_POST[
'date_startyear']);
1372 unset($_POST[
'date_endhour']);
1373 unset($_POST[
'date_endmin']);
1374 unset($_POST[
'date_endsec']);
1375 unset($_POST[
'date_endday']);
1376 unset($_POST[
'date_endmonth']);
1377 unset($_POST[
'date_endyear']);
1378 unset($_POST[
'price_ttc']);
1379 unset($_POST[
'price_ht']);
1386 } elseif ($action ==
'addline' && $usercancreate) {
1390 $ret = $object->fetch($id);
1395 $ret = $object->fetch_thirdparty();
1397 $langs->load(
'errors');
1406 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1407 if ($prod_entry_mode ==
'free') {
1410 $idprod =
GETPOST(
'idprod',
'int');
1418 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
1422 if (empty($remise_percent)) {
1423 $remise_percent = 0;
1427 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1428 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
1430 if (is_array($extralabelsline)) {
1432 foreach ($extralabelsline as $key => $value) {
1433 unset($_POST[
"options_".$key]);
1437 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
1438 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
1441 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
1442 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')), null,
'errors');
1445 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
1446 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')), null,
'errors');
1449 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
1450 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')), null,
'errors');
1453 if (!
GETPOST(
'qty',
'alpha')) {
1454 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
1458 if (!$error && !empty($conf->variants->enabled) && $prod_entry_mode !=
'free') {
1459 if ($combinations =
GETPOST(
'combinations',
'array')) {
1463 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1464 $idprod = $res->fk_product_child;
1466 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'), null,
'errors');
1472 if ($prod_entry_mode !=
'free' && empty($error)) {
1476 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
1481 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
1483 $res = $productsupplier->fetch($idprod);
1486 if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) {
1488 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1489 if ($productsupplier->fourn_socid != $socid) {
1490 $productsupplier->ref_supplier =
'';
1493 $fksoctosearch = $object->thirdparty->id;
1494 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1496 } elseif (
GETPOST(
'idprodfournprice',
'alpha') > 0) {
1497 $qtytosearch = $qty;
1499 $idprod = $productsupplier->get_buyprice(
GETPOST(
'idprodfournprice',
'alpha'), $qtytosearch);
1500 $res = $productsupplier->fetch($idprod);
1504 $label = $productsupplier->label;
1506 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1507 $outputlangs = $langs;
1509 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1510 $newlang =
GETPOST(
'lang_id',
'aZ09');
1512 if (empty($newlang)) {
1513 $newlang = $object->thirdparty->default_lang;
1515 if (!empty($newlang)) {
1516 $outputlangs =
new Translate(
"", $conf);
1517 $outputlangs->setDefaultLang($newlang);
1519 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->description;
1521 $desc = $productsupplier->description;
1524 if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
1525 $desc = $productsupplier->desc_supplier;
1529 if (trim($product_desc) == trim($desc) && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
1532 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
1533 $desc = $product_desc;
1535 if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
1536 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
1539 $ref_supplier = $productsupplier->ref_supplier;
1543 $tva_tx =
get_default_tva($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
1544 $tva_npr =
get_default_npr($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
1546 if (empty($tva_tx)) {
1549 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
1550 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
1552 $type = $productsupplier->type;
1553 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'price_ht_devise') !=
'') {
1554 $price_base_type =
'HT';
1556 $pu_devise =
price2num($price_ht_devise,
'CU');
1557 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'price_ttc_devise') !=
'') {
1558 $price_base_type =
'TTC';
1560 $pu_devise =
price2num($price_ttc_devise,
'CU');
1562 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
1563 if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) {
1564 $pu = $productsupplier->fourn_pu;
1567 $pu = $productsupplier->fourn_pu;
1568 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
1576 $result = $object->addline(
1591 min($rank, count($object->lines) + 1),
1594 $productsupplier->fk_unit,
1601 if ($idprod == -99 || $idprod == 0) {
1604 $langs->load(
"errors");
1605 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")), null,
'errors');
1607 if ($idprod == -1) {
1610 $langs->load(
"errors");
1611 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"), null,
'errors');
1613 } elseif (empty($error)) {
1614 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1615 $tva_tx = str_replace(
'*',
'', $tva_tx);
1616 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1617 $desc = $product_desc;
1619 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
1621 $fk_unit =
GETPOST(
'units',
'alpha');
1623 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1628 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1629 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1631 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'price_ht_devise') !=
'') {
1635 $pu_ht =
price2num($pu_ttc / (1 + ($tva_tx / 100)),
'MU');
1637 $price_base_type =
'HT';
1638 $pu_devise =
price2num($price_devise,
'CU');
1640 $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);
1644 if (!$error && $result > 0) {
1648 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1649 $outputlangs = $langs;
1651 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1652 $newlang =
GETPOST(
'lang_id',
'aZ09');
1654 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1655 $newlang = $object->thirdparty->default_lang;
1657 if (!empty($newlang)) {
1658 $outputlangs =
new Translate(
"", $conf);
1659 $outputlangs->setDefaultLang($newlang);
1661 $model = $object->model_pdf;
1662 $ret = $object->fetch($id);
1664 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1670 unset($_POST [
'prod_entry_mode']);
1672 unset($_POST[
'qty']);
1673 unset($_POST[
'type']);
1674 unset($_POST[
'remise_percent']);
1675 unset($_POST[
'pu']);
1676 unset($_POST[
'price_ht']);
1677 unset($_POST[
'multicurrency_price_ht']);
1678 unset($_POST[
'price_ttc']);
1679 unset($_POST[
'fourn_ref']);
1680 unset($_POST[
'tva_tx']);
1681 unset($_POST[
'label']);
1682 unset($localtax1_tx);
1683 unset($localtax2_tx);
1684 unset($_POST[
'np_marginRate']);
1685 unset($_POST[
'np_markRate']);
1686 unset($_POST[
'dp_desc']);
1687 unset($_POST[
'idprodfournprice']);
1688 unset($_POST[
'units']);
1690 unset($_POST[
'date_starthour']);
1691 unset($_POST[
'date_startmin']);
1692 unset($_POST[
'date_startsec']);
1693 unset($_POST[
'date_startday']);
1694 unset($_POST[
'date_startmonth']);
1695 unset($_POST[
'date_startyear']);
1696 unset($_POST[
'date_endhour']);
1697 unset($_POST[
'date_endmin']);
1698 unset($_POST[
'date_endsec']);
1699 unset($_POST[
'date_endday']);
1700 unset($_POST[
'date_endmonth']);
1701 unset($_POST[
'date_endyear']);
1708 } elseif ($action ==
'classin' && $usercancreate) {
1709 $object->fetch($id);
1710 $result = $object->setProject($projectid);
1711 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
1713 $object->fetch($id);
1715 $totalpaid = $object->getSommePaiement();
1716 $resteapayer = $object->total_ttc - $totalpaid;
1719 $ventilExportCompta = $object->getVentilExportCompta();
1721 if (!$ventilExportCompta) {
1724 $idwarehouse =
GETPOST(
'idwarehouse');
1726 $object->fetch_thirdparty();
1728 $qualified_for_stock_change = 0;
1729 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1730 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1732 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1736 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
1737 $langs->load(
"stocks");
1738 if (!$idwarehouse || $idwarehouse == -1) {
1740 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")), null,
'errors');
1745 $object->setDraft($user, $idwarehouse);
1748 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1749 $outputlangs = $langs;
1751 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1752 $newlang =
GETPOST(
'lang_id',
'aZ09');
1754 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1755 $newlang = $object->thirdparty->default_lang;
1757 if (!empty($newlang)) {
1758 $outputlangs =
new Translate(
"", $conf);
1759 $outputlangs->setDefaultLang($newlang);
1761 $model = $object->model_pdf;
1762 $ret = $object->fetch($id);
1764 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1773 } elseif ($action ==
'reopen' && $usercancreate) {
1775 $result = $object->fetch($id);
1778 $result = $object->setUnpaid($user);
1780 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
1789 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1792 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
1794 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
1795 $trackid =
'sinv'.$object->id;
1796 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1799 $upload_dir = $conf->fournisseur->facture->dir_output;
1800 $permissiontoadd = $usercancreate;
1801 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1804 if ($action ==
'calculate') {
1805 $calculationrule =
GETPOST(
'calculationrule');
1807 $object->fetch($id);
1808 $object->fetch_thirdparty();
1809 $result = $object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0, $object->thirdparty);
1815 if ($action ==
'update_extras') {
1819 $ret = $extrafields->setOptionalsFromPost(null, $object,
GETPOST(
'attribute',
'restricthtml'));
1827 $result = $object->insertExtraFields(
'BILL_SUPPLIER_MODIFY');
1835 $action =
'edit_extras';
1839 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1840 if ($action ==
'addcontact') {
1841 $result = $object->fetch($id);
1843 if ($result > 0 && $id > 0) {
1846 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1850 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1853 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1854 $langs->load(
"errors");
1855 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"), null,
'errors');
1860 } elseif ($action ==
'swapstatut') {
1862 if ($object->fetch($id)) {
1863 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1867 } elseif ($action ==
'deletecontact') {
1869 $object->fetch($id);
1870 $result = $object->delete_contact(
GETPOST(
"lineid",
'int'));
1873 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1889 $bankaccountstatic =
new Account($db);
1891 if (!empty($conf->project->enabled)) {
1897 $title = $langs->trans(
'SupplierInvoice').
" - ".$langs->trans(
'Card');
1898 $help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
1902 if ($action ==
'create') {
1909 $currency_code = $conf->currency;
1912 if (
GETPOST(
'socid',
'int') > 0) {
1914 $societe->fetch(
GETPOST(
'socid',
'int'));
1915 if (!empty($conf->multicurrency->enabled) && !empty($societe->multicurrency_code)) {
1916 $currency_code = $societe->multicurrency_code;
1920 if (!empty($origin) && !empty($originid)) {
1922 $element = $subelement = $origin;
1924 if ($element ==
'project') {
1925 $projectid = $originid;
1926 $element =
'projet';
1930 if ($element ==
'order') {
1931 $element = $subelement =
'commande';
1933 if ($element ==
'propal') {
1934 $element =
'comm/propal'; $subelement =
'propal';
1936 if ($element ==
'contract') {
1937 $element = $subelement =
'contrat';
1939 if ($element ==
'order_supplier') {
1940 $element =
'fourn'; $subelement =
'fournisseur.commande';
1943 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
1944 $classname = ucfirst($subelement);
1945 if ($classname ==
'Fournisseur.commande') {
1946 $classname =
'CommandeFournisseur';
1948 $objectsrc =
new $classname($db);
1949 $objectsrc->fetch($originid);
1950 $objectsrc->fetch_thirdparty();
1952 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1955 $soc = $objectsrc->thirdparty;
1956 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_supplier_id) ? $soc->cond_reglement_supplier_id : 0));
1957 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_supplier_id) ? $soc->mode_reglement_supplier_id : 0));
1958 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1959 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_supplier_percent) ? $soc->remise_supplier_percent : 0));
1960 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1961 $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'';
1962 $transport_mode_id = (!empty($objectsrc->transport_mode_id) ? $objectsrc->transport_mode_id : (!empty($soc->transport_mode_id) ? $soc->transport_mode_id : 0));
1964 if (!empty($conf->multicurrency->enabled)) {
1965 if (!empty($objectsrc->multicurrency_code)) {
1966 $currency_code = $objectsrc->multicurrency_code;
1968 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1969 $currency_tx = $objectsrc->multicurrency_tx;
1974 $dateinvoice = ($datetmp ==
'' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $datetmp);
1976 $datedue = ($datetmp ==
'' ?-1 : $datetmp);
1979 $objectsrc->fetch_optionals();
1980 $object->array_options = $objectsrc->array_options;
1982 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
1983 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
1984 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
1985 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
1987 $dateinvoice = ($datetmp ==
'' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $datetmp);
1989 $datedue = ($datetmp ==
'' ?-1 : $datetmp);
1991 if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) {
1992 $currency_code = $soc->multicurrency_code;
1997 if (empty($cond_reglement_id)) {
1998 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2002 if (empty($mode_reglement_id)) {
2003 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2006 $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));
2007 $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));
2009 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2010 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2011 print
'<input type="hidden" name="action" value="add">';
2012 if (!empty($societe->id) && $societe->id > 0) {
2013 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2015 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2016 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2017 if (!empty($currency_tx)) {
2018 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2023 print
'<table class="border centpercent">';
2026 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
2030 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2031 $invoice_predefined->fetch($fac_recid);
2035 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2038 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2039 $absolute_discount = $societe->getAvailableDiscounts(
'',
'', 0, 1);
2040 print $societe->getNomUrl(1,
'supplier');
2041 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2043 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');
2045 if (!empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE)) {
2046 print
'<script type="text/javascript">
2047 $(document).ready(function() {
2048 $("#socid").change(function() {
2049 var socid = $(this).val();
2050 var fac_rec = $(\'#fac_rec\').val();
2051 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
2056 if ($fac_recid <= 0) {
2057 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>';
2063 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2064 $invoice_predefined->fetch($fac_recid);
2066 $dateinvoice = $invoice_predefined->date_when;
2067 if (empty($projectid)) {
2068 $projectid = $invoice_predefined->fk_project;
2070 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2071 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2072 $fk_account = $invoice_predefined->fk_account;
2073 $note_public = $invoice_predefined->note_public;
2074 $note_private = $invoice_predefined->note_private;
2076 if (!empty($invoice_predefined->multicurrency_code)) {
2077 $currency_code = $invoice_predefined->multicurrency_code;
2079 if (!empty($invoice_predefined->multicurrency_tx)) {
2080 $currency_tx = $invoice_predefined->multicurrency_tx;
2083 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2084 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2085 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2087 $resql = $db->query($sql);
2089 $num = $db->num_rows(
$resql);
2093 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2095 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2096 print
'<option value="0" selected></option>';
2098 $objp = $db->fetch_object(
$resql);
2099 print
'<option value="'.$objp->rowid.
'"';
2100 if ($fac_recid == $objp->rowid) {
2102 $exampletemplateinvoice->fetch($fac_recid);
2104 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2109 if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED)) {
2110 print
'<script type="text/javascript">
2111 $(document).ready(function() {
2112 $("#fac_rec").change(function() {
2113 console.log("We have changed the template invoice - Reload page");
2114 var fac_rec = $(this).val();
2115 var socid = $(\'#socid\').val();
2116 // 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.
2117 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
2131 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"';
2132 if (!empty($societe->id) && $societe->id > 0) {
2138 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2140 print
'<div class="tagtable">'.
"\n";
2143 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2144 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOST(
'type',
'int')?
'' :
'checked').
'> ';
2145 $desc =
$form->textwithpicto($tmp.$langs->trans(
"InvoiceStandardAsk"), $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2147 print
'</div></div>';
2149 if (empty($origin) || ($origin ==
'order_supplier' && !empty($originid))) {
2151 if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) {
2152 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2153 $tmp=
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOST(
'type') == 3 ?
' checked' :
'') .
'> ';
2154 print
'<script type="text/javascript">
2155 jQuery(document).ready(function() {
2156 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2157 jQuery("#radio_standard").prop("checked", true);
2159 jQuery("#typedeposit, #valuedeposit").click(function() {
2160 jQuery("#radio_deposit").prop("checked", true);
2162 jQuery("#typedeposit").change(function() {
2163 console.log("We change type of down payment");
2164 jQuery("#radio_deposit").prop("checked", true);
2165 setRadioForTypeOfInvoice();
2167 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2168 setRadioForTypeOfInvoice();
2170 function setRadioForTypeOfInvoice() {
2171 console.log("Change radio");
2172 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2173 jQuery(".checkforselect").prop("disabled", true);
2174 jQuery(".checkforselect").prop("checked", false);
2176 jQuery(".checkforselect").prop("disabled", false);
2177 jQuery(".checkforselect").prop("checked", true);
2183 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2184 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2185 print
'<table class="nobordernopadding"><tr>';
2189 if ($origin ==
'order_supplier') {
2190 print
'<td class="nowrap" style="padding-left: 15px">';
2192 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2193 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2194 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2196 print
$form->selectarray(
'typedeposit', $arraylist,
GETPOST(
'typedeposit',
'aZ09'), 0, 0, 0,
'', 1);
2198 print
'<td class="nowrap" style="padding-left: 5px">';
2199 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' .
GETPOST(
'valuedeposit',
'int') .
'"/>';
2202 print
'</tr></table>';
2204 print
'</div></div>';
2273 if (empty($origin)) {
2274 if (!empty($societe->id) && $societe->id > 0) {
2276 if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) {
2278 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2285 foreach ($facids as $key => $valarray) {
2286 $newinvoice_static->id = $key;
2287 $newinvoice_static->ref = $valarray [
'ref'];
2288 $newinvoice_static->statut = $valarray [
'status'];
2289 $newinvoice_static->type = $valarray [
'type'];
2290 $newinvoice_static->paye = $valarray [
'paye'];
2292 $optionsav .=
'<option value="'.$key.
'"';
2293 if ($key ==
GETPOST(
'fac_avoir',
'int')) {
2294 $optionsav .=
' selected';
2297 $optionsav .= $newinvoice_static->ref;
2298 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
2299 $optionsav .=
'</option>';
2302 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2303 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
2305 $tmp .=
' disabled';
2309 print
'<script type="text/javascript">
2310 jQuery(document).ready(function() {
2311 if (! jQuery("#radio_creditnote").is(":checked"))
2313 jQuery("#credit_note_options").hide();
2315 jQuery("#radio_creditnote").click(function() {
2316 jQuery("#credit_note_options").show();
2318 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2319 jQuery("#credit_note_options").hide();
2323 $text = $tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
' ';
2325 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2327 $text .=
' disabled';
2331 $text .=
'<option value="-1"></option>';
2332 $text .= $optionsav;
2334 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
2336 $text .=
'</select>';
2337 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2340 print
'<div id="credit_note_options" class="clearboth">';
2341 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' :
'').
' /> ';
2342 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
2343 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' :
'').
' /> ';
2344 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
2347 print
'</div></div>';
2350 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2351 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2352 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
2353 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
2354 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2356 print
'</div></div>'.
"\n";
2364 if (!empty($societe->id) && $societe->id > 0) {
2366 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2368 $thirdparty = $societe;
2370 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2371 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2377 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth200" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
2380 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
2381 print
$form->selectDate($dateinvoice,
'',
'',
'',
'',
"add", 1, 1);
2385 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
2386 print
$form->selectDate($datedue,
'ech',
'',
'',
'',
"add", 1, 1);
2390 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2391 $form->select_conditions_paiements(
GETPOSTISSET(
'cond_reglement_id') ?
GETPOST(
'cond_reglement_id',
'int') : $cond_reglement_id,
'cond_reglement_id');
2395 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2396 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2397 $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');
2401 if (!empty($conf->banque->enabled)) {
2402 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2403 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);
2408 if (!empty($conf->project->enabled)) {
2411 $langs->load(
'projects');
2412 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2413 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');
2414 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>';
2419 if (!empty($conf->incoterm->enabled)) {
2421 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
2422 print
'<td colspan="3" class="maxwidthonsmartphone">';
2423 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 :
''));
2428 if (!empty($conf->multicurrency->enabled)) {
2430 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
2431 print
'<td class="maxwidthonsmartphone">';
2432 print
$form->selectMultiCurrency((
GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code),
'multicurrency_code');
2438 if ($fac_recid > 0) {
2439 $dateexample = $newdateinvoice ? $newdateinvoice : $dateinvoice;
2440 if (empty($dateexample)) {
2443 $substitutionarray = array(
2444 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
2445 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
2446 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
2447 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
2448 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
2449 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
2450 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
2451 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
2452 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
2453 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
2454 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
2457 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
2458 foreach ($substitutionarray as $key => $val) {
2459 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
2461 $htmltext .=
'</i>';
2465 if (!empty($conf->intracommreport->enabled)) {
2466 $langs->loadLangs(array(
"intracommreport"));
2467 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
2468 $form->selectTransportMode(
GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
2472 if (empty($reshook)) {
2473 print $object->showOptionals($extrafields,
'create');
2477 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2479 $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%');
2480 print $doleditor->Create(1);
2486 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
2488 $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%');
2489 print $doleditor->Create(1);
2495 if (!empty($objectsrc) && is_object($objectsrc)) {
2496 print
"\n<!-- ".$classname.
" info -->";
2498 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2499 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2500 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2501 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2502 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2504 $txt = $langs->trans($classname);
2505 if ($classname ==
'CommandeFournisseur') {
2506 $langs->load(
'orders');
2507 $txt = $langs->trans(
"SupplierOrder");
2509 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
2511 $objectsrc->fetchObjectLinked($originid, $origin,
'',
'invoice_supplier');
2513 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
2516 if (is_array($invoice_supplier)) {
2517 $cntinvoice = count($invoice_supplier);
2519 if ($cntinvoice >= 1) {
2521 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
2526 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2527 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2528 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2529 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2532 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2533 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2535 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2537 if (!empty($conf->multicurrency->enabled)) {
2538 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2539 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2540 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2545 $parameters = array();
2546 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
2547 print $hookmanager->resPrint;
2554 print
$form->buttonsSaveCancel(
"CreateDraft");
2557 if (!empty($objectsrc) && is_object($objectsrc)) {
2560 $title = $langs->trans(
'ProductsAndServices');
2563 print
'<div class="div-table-responsive-no-min">';
2564 print
'<table class="noborder centpercent">';
2566 $objectsrc->printOriginLinesList(
'', $selectedLines);
2574 if ($id > 0 || !empty($ref)) {
2581 $productstatic =
new Product($db);
2583 $result = $object->fetch($id, $ref);
2585 $langs->load(
"errors");
2586 print $langs->trans(
"ErrorRecordNotFound");
2592 $result = $object->fetch_thirdparty();
2598 $societe = $object->thirdparty;
2600 $totalpaid = $object->getSommePaiement();
2601 $totalcreditnotes = $object->getSumCreditNotesUsed();
2602 $totaldeposits = $object->getSumDepositsUsed();
2610 $resteapayer =
price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
2613 if (!empty($conf->multicurrency->enabled)) {
2614 $multicurrency_totalpaid = $object->getSommePaiement(1);
2615 $multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
2616 $multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
2617 $multicurrency_resteapayer =
price2num($object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
2621 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 && $object->multicurrency_code != $conf->currency) {
2622 $resteapayer =
price2num($multicurrency_resteapayer / $object->multicurrency_tx,
'MT');
2626 if ($object->paye) {
2629 $resteapayeraffiche = $resteapayer;
2631 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
2632 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2633 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2635 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2636 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2639 $absolute_discount = $societe->getAvailableDiscounts(
'', $filterabsolutediscount, 0, 1);
2640 $absolute_creditnote = $societe->getAvailableDiscounts(
'', $filtercreditnote, 0, 1);
2641 $absolute_discount =
price2num($absolute_discount,
'MT');
2642 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2647 $objectidnext = $object->getIdReplacingInvoice();
2650 $titre = $langs->trans(
'SupplierInvoice');
2657 if ($action ==
'converttoreduc') {
2659 $type_fac =
'ExcessPaid';
2661 $type_fac =
'CreditNote';
2663 $type_fac =
'Deposit';
2665 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
2666 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
2667 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
2671 if ($action ==
'clone') {
2673 $formquestion = array(
2674 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplier"),
'value' => $langs->trans(
"CopyOf").
' '.$object->ref_supplier),
2675 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
2678 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
2682 if ($action ==
'valid') {
2684 if (preg_match(
'/^[\(]?PROV/i', $object->ref) || empty($object->ref)) {
2686 $numref = $object->getNextNumRef($societe);
2688 $numref = $object->ref;
2695 $text = $langs->trans(
'ConfirmValidateBill', $numref);
2703 $formquestion = array();
2705 $qualified_for_stock_change = 0;
2706 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2707 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2709 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2712 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
2713 $langs->load(
"stocks");
2714 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2717 $warehouse_array = $warehouse->list_array();
2718 if (count($warehouse_array) == 1) {
2719 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
2720 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
2723 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
2725 $formquestion = array(
2726 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
2730 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
2735 if ($action ==
'edit') {
2736 $formquestion = array();
2738 $qualified_for_stock_change = 0;
2739 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2740 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2742 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2744 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
2745 $langs->load(
"stocks");
2746 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2749 $warehouse_array = $warehouse->list_array();
2750 if (count($warehouse_array) == 1) {
2751 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
2752 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
2755 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
2757 $formquestion = array(
2758 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
2761 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill', $object->ref),
'confirm_edit', $formquestion, 1, 1);
2765 if ($action ==
'paid' && ($resteapayer <= 0 || (!empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) && $resteapayer == $object->total_ttc))) {
2766 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill', $object->ref),
'confirm_paid',
'', 0, 1);
2769 if ($action ==
'paid' && $resteapayer > 0 && (empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $resteapayer != $object->total_ttc)) {
2773 $close[$i][
'code'] =
'discount_vat';
2775 $close[$i][
'code'] =
'badsupplier';
2777 $close[$i][
'code'] =
'other';
2781 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
2783 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
2785 $close[$i][
'label'] = $langs->trans(
"Other");
2789 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
2791 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
2793 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
2796 foreach ($close as $key => $val) {
2797 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
2801 $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'));
2803 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially', $object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
2807 if ($action ==
'canceled') {
2809 $close[1][
'code'] =
'badsupplier';
2810 $close[2][
'code'] =
'abandon';
2812 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
2813 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
2815 $close[1][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier", $object->ref), $close[1][
'label'], 1);
2816 $close[2][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
2818 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
2819 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
2822 $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'));
2824 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill', $object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 250);
2828 if ($action ==
'delete') {
2829 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete',
'', 0, 1);
2831 if ($action ==
'deletepayment') {
2832 $payment_id =
GETPOST(
'paiement_id');
2833 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
2837 if ($action ==
'ask_deleteline') {
2838 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2842 $parameters = array(
'formConfirm' =>
$formconfirm,
'lineid'=>$lineid);
2843 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
2844 if (empty($reshook)) {
2846 } elseif ($reshook > 0) {
2856 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2858 $morehtmlref =
'<div class="refidno">';
2860 $morehtmlref .=
$form->editfieldkey(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'', 0, 1);
2861 $morehtmlref .=
$form->editfieldval(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'', null, null,
'', 1);
2863 $morehtmlref .=
'<br>'.$langs->trans(
'ThirdParty').
' : '.$object->thirdparty->getNomUrl(1,
'supplier');
2864 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2865 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$object->thirdparty->id.
'&search_company='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
2868 if (!empty($conf->project->enabled)) {
2869 $langs->load(
"projects");
2870 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
2871 if ($usercancreate) {
2872 if ($action !=
'classify') {
2873 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
2875 if ($action ==
'classify') {
2877 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
2878 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
2879 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2880 $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);
2881 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2882 $morehtmlref .=
'</form>';
2884 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
2887 if (!empty($object->fk_project)) {
2889 $proj->fetch($object->fk_project);
2890 $morehtmlref .=
' : '.$proj->getNomUrl(1);
2892 $morehtmlref .=
' - '.$proj->title;
2899 $morehtmlref .=
'</div>';
2901 $object->totalpaid = $totalpaid;
2903 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2905 print
'<div class="fichecenter">';
2906 print
'<div class="fichehalfleft">';
2907 print
'<div class="underbanner clearboth"></div>';
2909 print
'<table class="border tableforfield" width="100%">';
2912 print
'<tr><td class="titlefield">'.$langs->trans(
'Type').
'</td><td>';
2913 print
'<span class="badgeneutral">';
2914 print $object->getLibType();
2918 $facreplaced->fetch($object->fk_facture_source);
2919 print
' '.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1));
2923 if ($object->fk_facture_source > 0) {
2924 $facusing->fetch($object->fk_facture_source);
2925 print
' '.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1));
2927 print
' '.$langs->transnoentities(
"CorrectedInvoiceNotFound");
2931 $facidavoir = $object->getListIdAvoirFromInvoice();
2932 if (count($facidavoir) > 0) {
2933 $invoicecredits = array();
2934 foreach ($facidavoir as $id) {
2936 $facavoir->fetch($id);
2937 $invoicecredits[] = $facavoir->getNomUrl(1);
2939 print
' ('.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits) .
')';
2941 if (isset($objectidnext) && $objectidnext > 0) {
2943 $facthatreplace->fetch($facidnext);
2944 print
' ('.$langs->transnoentities(
"ReplacedByInvoice", $facthatreplace->getNomUrl(1)).
')';
2948 $result = $discount->fetch(0, 0, $object->id);
2950 print
' <span class="opacitymediumbycolor paddingleft">';
2951 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
2952 $s = str_replace(
'{s1}', $object->getLibType(1), $s);
2953 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
2955 print
'</span><br>';
2959 if ($object->fk_fac_rec_source > 0) {
2961 $result = $tmptemplate->fetch($object->fk_fac_rec_source);
2963 print
' <span class="opacitymediumbycolor paddingleft">';
2964 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->titre).
'</a>';
2965 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
2975 print
'<!-- Discounts -->'.
"\n";
2976 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
2979 $thirdparty = $societe;
2981 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?facid='.$object->id);
2982 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2988 print
'<td>'.$form->editfieldkey(
"Label",
'label', $object->label, $object, $usercancreate).
'</td>';
2989 print
'<td>'.$form->editfieldval(
"Label",
'label', $object->label, $object, $usercancreate).
'</td>';
2997 print
$form->editfieldkey(
"DateInvoice",
'datef', $object->datep, $object, $form_permission,
'datepicker');
2998 print
'</td><td colspan="3">';
2999 print
$form->editfieldval(
"Date",
'datef', $object->datep, $object, $form_permission,
'datepicker');
3003 $langs->load(
'bills');
3004 print
'<tr><td class="nowrap">';
3005 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3006 print $langs->trans(
'PaymentConditions');
3008 if ($action !=
'editconditions' && $form_permission) {
3009 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>';
3011 print
'</tr></table>';
3013 if ($action ==
'editconditions') {
3014 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
3016 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none');
3023 print
$form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', $object->date_echeance, $object, $form_permission2,
'datepicker');
3025 print
$form->editfieldval(
"DateMaxPayment",
'date_lim_reglement', $object->date_echeance, $object, $form_permission2,
'datepicker');
3026 if ($action !=
'editdate_lim_reglement' && $object->hasDelay()) {
3032 $langs->load(
'bills');
3033 print
'<tr><td class="nowrap">';
3034 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3035 print $langs->trans(
'PaymentMode');
3037 if ($action !=
'editmode' && $form_permission2) {
3038 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>';
3040 print
'</tr></table>';
3042 if ($action ==
'editmode') {
3043 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3045 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
3050 if (!empty($conf->multicurrency->enabled)) {
3054 print
'<table class="nobordernopadding" width="100%"><tr><td>';
3055 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
3057 if ($action !=
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT) {
3058 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>';
3060 print
'</tr></table>';
3062 if ($action ==
'editmulticurrencycode') {
3063 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
3065 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
3070 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3073 print
'<table class="nobordernopadding centpercent"><tr><td>';
3074 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
3076 if ($action !=
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3077 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>';
3079 print
'</tr></table>';
3081 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
3082 if ($action ==
'actualizemulticurrencyrate') {
3085 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
3087 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
3088 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3089 print
'<div class="inline-block"> ';
3090 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
3099 if (!empty($conf->banque->enabled)) {
3100 print
'<tr><td class="nowrap">';
3101 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3102 print $langs->trans(
'BankAccount');
3104 if ($action !=
'editbankaccount' && $usercancreate) {
3105 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>';
3107 print
'</tr></table>';
3109 if ($action ==
'editbankaccount') {
3110 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
3112 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
3119 if (!empty($conf->incoterm->enabled)) {
3121 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3122 print $langs->trans(
'IncotermLabel');
3123 print
'<td><td class="right">';
3124 if ($usercancreate) {
3125 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
3129 print
'</td></tr></table>';
3132 if ($action !=
'editincoterm') {
3133 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
3135 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
3141 if (!empty($conf->intracommreport->enabled)) {
3142 $langs->loadLangs(array(
"intracommreport"));
3144 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3145 print $langs->trans(
'IntracommReportTransportMode');
3147 if ($action !=
'editmode' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
3148 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit().
'</a></td>';
3150 print
'</tr></table>';
3153 if ($action ==
'editmode') {
3154 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->transport_mode_id,
'transport_mode_id', 1, 1);
3156 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->transport_mode_id,
'none');
3163 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
3168 print
'<div class="fichehalfright">';
3169 print
'<div class="underbanner clearboth"></div>';
3171 print
'<table class="border tableforfield centpercent">';
3173 if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) {
3175 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
3176 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>';
3180 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
3181 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>';
3185 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
3186 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>';
3191 print
'<tr><td class="titlefield">'.$langs->trans(
'AmountHT').
'</td>';
3192 print
'<td class="nowrap right amountcard">'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3196 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td>';
3197 print
'<td class="nowrap right amountcard">';
3198 if (
GETPOST(
'calculationrule')) {
3199 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
3201 $calculationrule = (empty($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND) ?
'totalofround' :
'roundoftotal');
3203 if ($calculationrule ==
'totalofround') {
3204 $calculationrulenum = 1;
3206 $calculationrulenum = 2;
3209 if ($object->getVentilExportCompta() == 0) {
3210 $s =
'<span class="hideonsmartphone opacitymedium">'.$langs->trans(
"ReCalculate").
' </span>';
3211 $s .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=calculate&calculationrule=totalofround">'.$langs->trans(
"Mode1").
'</a>';
3213 $s .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=calculate&calculationrule=roundoftotal">'.$langs->trans(
"Mode2").
'</a>';
3214 print
'<div class="inline-block">';
3215 print
$form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum).
'<br>'.$langs->trans(
"CalculationRuleDescSupplier"), 2, 1,
img_picto(
'',
'help'),
'', 3,
'', 0,
'recalculate');
3216 print
' ';
3219 print
price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency);
3224 if ($societe->localtax1_assuj ==
"1") {
3225 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $societe->country_code).
'</td>';
3226 print
'<td class="nowrap right amountcard">'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3229 if ($societe->localtax2_assuj ==
"1") {
3230 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $societe->country_code).
'</td>';
3231 print
'<td class="nowrap right amountcard">'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3234 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td>';
3235 print
'<td colspan="3" class="nowrap right amountcard">'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).
'</td>';
3250 $nbrows = 9; $nbcols = 3;
3251 if (!empty($conf->project->enabled)) {
3254 if (!empty($conf->banque->enabled)) {
3255 $nbrows++; $nbcols++;
3257 if (!empty($conf->incoterm->enabled)) {
3260 if (!empty($conf->multicurrency->enabled)) {
3265 if ($societe->localtax1_assuj ==
"1") {
3268 if ($societe->localtax2_assuj ==
"1") {
3272 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
3273 $sql .=
' c.id as paiement_type, c.code as payment_code,';
3274 $sql .=
' pf.amount,';
3275 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
3276 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
3277 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
3278 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
3279 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
3280 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
3281 $sql .=
' WHERE pf.fk_facturefourn = '.((int) $object->id);
3282 $sql .=
' ORDER BY p.datep, p.tms';
3284 $result = $db->query($sql);
3286 $num = $db->num_rows($result);
3289 print
'<div class="div-table-responsive-no-min">';
3290 print
'<table class="noborder paymenttable" width="100%">';
3291 print
'<tr class="liste_titre">';
3293 print
'<td>'.$langs->trans(
'Date').
'</td>';
3294 print
'<td>'.$langs->trans(
'Type').
'</td>';
3295 if (!empty($conf->banque->enabled)) {
3296 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
3298 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
3299 print
'<td width="18"> </td>';
3304 $objp = $db->fetch_object($result);
3306 $paymentstatic->id = $objp->rowid;
3307 $paymentstatic->datepaye = $db->jdate($objp->dp);
3308 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
3309 $paymentstatic->num_payment = $objp->num_payment;
3311 $paymentstatic->paiementcode = $objp->payment_code;
3312 $paymentstatic->type_code = $objp->payment_code;
3313 $paymentstatic->type_label = $objp->payment_type;
3315 print
'<tr class="oddeven">';
3317 print $paymentstatic->getNomUrl(1);
3319 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
'</td>';
3321 print
$form->form_modes_reglement(null, $objp->paiement_type,
'none').
' '.$objp->num_payment;
3323 if (!empty($conf->banque->enabled)) {
3324 $bankaccountstatic->id = $objp->baid;
3325 $bankaccountstatic->ref = $objp->baref;
3326 $bankaccountstatic->label = $objp->baref;
3327 $bankaccountstatic->number = $objp->banumber;
3329 if (!empty($conf->accounting->enabled)) {
3330 $bankaccountstatic->account_number = $objp->account_number;
3333 $accountingjournal->fetch($objp->fk_accountancy_journal);
3334 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
3337 print
'<td class="right">';
3338 if ($objp->baid > 0) {
3339 print $bankaccountstatic->getNomUrl(1,
'transactions');
3343 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
3344 print
'<td class="center">';
3346 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
3352 $totalpaid += $objp->amount;
3356 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td><td></td><td></td></tr>';
3379 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3380 print
'<span class="opacitymedium">';
3382 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
3384 print $langs->trans(
'AlreadyPaid');
3387 print
'</td><td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td><td> </td></tr>';
3390 $resteapayeraffiche = $resteapayer;
3392 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
3395 $creditnoteamount = 0;
3398 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
3399 $sql .=
" re.description, re.fk_invoice_supplier_source";
3400 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
3401 $sql .=
" WHERE fk_invoice_supplier = ".((int) $object->id);
3402 $resql = $db->query($sql);
3404 $num = $db->num_rows(
$resql);
3408 $obj = $db->fetch_object(
$resql);
3409 $invoice->fetch($obj->fk_invoice_supplier_source);
3410 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3412 print $langs->trans(
"CreditNote").
' ';
3415 print $langs->trans(
"Deposit").
' ';
3417 print $invoice->getNomUrl(0);
3419 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
3420 print
'<td class="right">';
3421 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=unlinkdiscount&discountid='.$obj->rowid.
'">'.
img_delete().
'</a>';
3425 $creditnoteamount += $obj->amount_ttc;
3428 $depositamount += $obj->amount_ttc;
3437 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3438 print
'<span class="opacitymedium">';
3439 print
$form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
3441 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3442 $resteapayeraffiche = 0;
3443 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3447 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3448 print
'<span class="opacitymedium">';
3449 print
$form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
3451 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3453 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3457 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3458 print
'<span class="opacitymedium">';
3459 print
$form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
3461 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3462 $resteapayeraffiche = 0;
3463 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3467 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3468 $text = $langs->trans(
"HelpAbandonOther");
3469 if ($object->close_note) {
3470 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.$object->close_note;
3472 print
'<span class="opacitymedium">';
3473 print
$form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
3475 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3476 $resteapayeraffiche = 0;
3477 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3481 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3482 print
'<span class="opacitymedium">';
3483 print $langs->trans(
"Billed");
3485 print
'</td><td class="right">'.price($object->total_ttc).
'</td><td> </td></tr>';
3488 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3489 print
'<span class="opacitymedium">';
3490 print $langs->trans(
'RemainderToPay');
3491 if ($resteapayeraffiche < 0) {
3492 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3496 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
3499 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3500 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3501 print
'<span class="opacitymedium">';
3502 print $langs->trans(
'RemainderToPayMulticurrency');
3503 if ($resteapayeraffiche < 0) {
3504 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3508 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.(!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency).
' '.
price(
price2num($object->multicurrency_tx*$resteapayeraffiche,
'MT')).
'</td><td> </td></tr>';
3512 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3515 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3516 print $langs->trans(
'AlreadyPaidBack');
3517 print
' :</td><td class="right">'.price($sign * $totalpaid).
'</td><td> </td></tr>';
3520 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"Billed").
' :</td><td class="right">'.
price($sign * $object->total_ttc).
'</td><td> </td></tr>';
3523 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3524 print
'<span class="opacitymedium">';
3525 print $langs->trans(
'RemainderToPayBack');
3526 if ($resteapayeraffiche > 0) {
3527 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3531 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td><td> </td></tr>';
3534 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3535 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3536 print
'<span class="opacitymedium">';
3537 print $langs->trans(
'RemainderToPayBackMulticurrency');
3538 if ($resteapayeraffiche> 0) {
3539 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3543 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>';
3558 print
'<div class="clearboth"></div><br>';
3560 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
3561 $blocname =
'contacts';
3562 $title = $langs->trans(
'ContactsAddresses');
3563 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3566 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
3568 $blocname =
'notes';
3569 $title = $langs->trans(
'Notes');
3570 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3577 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">';
3578 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3579 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
3580 print
'<input type="hidden" name="mode" value="">';
3581 print
'<input type="hidden" name="page_y" value="">';
3582 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
3583 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
3586 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
3589 print
'<div class="div-table-responsive-no-min">';
3590 print
'<table id="tablelines" class="noborder noshadow centpercent">';
3592 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
3593 $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
3594 $senderissupplier = 2;
3596 if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
3597 $senderissupplier = 1;
3601 if (!empty($object->lines)) {
3602 $ret = $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
3605 $num = count($object->lines);
3609 if ($action !=
'editline') {
3612 $parameters = array();
3613 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
3614 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
3615 if (empty($reshook))
3616 $object->formAddObjectLine(1, $societe, $mysoc);
3627 if ($action !=
'presend') {
3632 print
'<div class="tabsAction">';
3634 $parameters = array();
3635 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
3637 if (empty($reshook)) {
3641 $ventilExportCompta = $object->getVentilExportCompta();
3643 if ($ventilExportCompta == 0) {
3644 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=edit&token='.
newToken().
'">'.$langs->trans(
'Modify').
'</a>';
3646 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
3651 $result = $discount->fetch(0, 0, $object->id);
3658 if (!$objectidnext && $object->close_code !=
'replaced' && $usercancreate) {
3659 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
3661 if ($usercancreate) {
3662 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
3663 } elseif (empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
3664 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
3671 if (count($object->lines)) {
3672 if ($usercanvalidate) {
3673 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid"';
3674 print
'>'.$langs->trans(
'Validate').
'</a>';
3676 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
3677 print
'>'.$langs->trans(
'Validate').
'</a>';
3683 if (empty($user->socid)) {
3686 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
3688 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'SendMail').
'</span>';
3695 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>';
3702 if ($resteapayer == 0) {
3703 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
3705 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>';
3710 if ($object->type ==
FactureFournisseur::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) < 0 && $usercancreate && empty($discount->id)) {
3711 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
3715 && (!empty($conf->global->SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) || $object->getSommePaiement() == 0)
3717 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>';
3721 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertToReduc').
'</a>';
3729 ($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)))
3732 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaid').
'</a>';
3736 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)) {
3737 if ($totalpaid > 0 || $totalcreditnotes > 0) {
3739 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
3741 if (empty($conf->global->INVOICE_CAN_NEVER_BE_CANCELED)) {
3742 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
3755 if (!$objectidnext) {
3756 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>';
3761 if ($action !=
'edit' && $usercancreate) {
3762 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=clone&socid='.$object->socid.
'">'.$langs->trans(
'ToClone').
'</a>';
3767 if (!$objectidnext && count($object->lines) > 0) {
3768 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
3773 $isErasable = $object->is_erasable();
3774 if ($action !=
'confirm_edit' && ($user->rights->fournisseur->facture->supprimer || ($usercancreate && $isErasable == 1))) {
3776 if ($isErasable == -4) {
3777 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecausePayments").
'">'.$langs->trans(
'Delete').
'</a>';
3778 } elseif ($isErasable == -3) {
3779 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastSituationInvoice").
'">'.$langs->trans(
'Delete').
'</a>';
3780 } elseif ($isErasable == -2) {
3781 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInvoice").
'">'.$langs->trans(
'Delete').
'</a>';
3782 } elseif ($isErasable == -1) {
3783 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Delete').
'</a>';
3784 } elseif ($isErasable <= 0) {
3785 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotErasable").
'">'.$langs->trans(
'Delete').
'</a>';
3787 print
'<a class="butActionDelete'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
'Delete').
'</a>';
3792 if ($action !=
'confirm_edit') {
3793 print
'<div class="fichecenter"><div class="fichehalfleft">';
3799 $subdir =
get_exdir($object->id, 2, 0, 0, $object,
'invoice_supplier').$ref;
3800 $filedir = $conf->fournisseur->facture->dir_output.
'/'.$subdir;
3801 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.$object->id;
3802 $genallowed = $usercanread;
3803 $delallowed = $usercancreate;
3804 $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF) ?
'' : $conf->global->INVOICE_SUPPLIER_ADDON_PDF));
3806 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
3807 $somethingshown = $formfile->numoffiles;
3810 $linktoelem =
$form->showLinkToObjectBlock($object, null, array(
'invoice_supplier'));
3811 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
3813 print
'</div><div class="fichehalfright">';
3816 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3818 $somethingshown =
$formactions->showactions($object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
3820 print
'</div></div>';
3826 if (
GETPOST(
'modelselected')) {
3827 $action =
'presend';
3831 $modelmail =
'invoice_supplier_send';
3832 $defaulttopic =
'SendBillRef';
3833 $diroutput = $conf->fournisseur->facture->dir_output;
3834 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
3835 $trackid =
'sinv'.$object->id;
3837 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
const TYPE_STANDARD
Standard invoice.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action== 'set') elseif($action== 'specimen') elseif($action== 'setmodel') elseif($action== 'del') elseif($action== 'setdoc') $formactions
View.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated messages to output (Used to show messages on html output).
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
const TYPE_DEPOSIT
Deposit invoice.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_VALIDATED
Validated (need to be paid)
Class to manage suppliers invoices.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate, from a $thirdparty_buyer to a $thirdparty_seller Note: This function applies same rules than get_default_tva.
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save"&&empty($cancel)) $help_url
View.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Class to manage bank accounts.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
static getIdAndTxFromCode($dbs, $code, $date_document= '')
Get id and rate of currency from code.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form...
dol_get_last_hour($date, $gm= 'tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
Class to manage third parties objects (customers, suppliers, prospects...)
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart= '')
Return a path to have a the directory according to object where files are stored. ...
Class to manage invoice templates.
Class to manage translations.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class ProductCombination Used to represent a product combination.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
facturefourn_prepare_head($object)
Prepare array with list of tabs.
const STATUS_CLOSED
Classified paid.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
const TYPE_CREDIT_NOTE
Credit note invoice.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
const TYPE_SITUATION
Situation invoice.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Class to manage absolute discounts.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
const STATUS_ABANDONED
Classified abandoned and no payment done.
Class to manage a WYSIWYG editor.
Class to manage accounting accounts.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
Class to manage payments for supplier invoices.
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
$formconfirm
if ($action == 'delbookkeepingyear') {
Class to manage predefined suppliers products.
Class to manage warehouses.