38require
'../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_invoice/modules_facturefournisseur.php';
42require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture-rec.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
50if (isModEnabled(
"product")) {
51 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
52 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
54if (isModEnabled(
'project')) {
55 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
56 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
59if (isModEnabled(
'variants')) {
60 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
62if (isModEnabled(
'accounting')) {
63 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
67$langs->loadLangs(array(
'bills',
'compta',
'suppliers',
'companies',
'products',
'banks',
'admin'));
68if (isModEnabled(
'incoterm')) {
69 $langs->load(
'incoterm');
74$action =
GETPOST(
'action',
'aZ09');
77$cancel =
GETPOST(
'cancel',
'alpha');
78$backtopage =
GETPOST(
'backtopage',
'alpha');
79$backtopageforcancel =
'';
81$lineid =
GETPOST(
'lineid',
'int');
82$projectid =
GETPOST(
'projectid',
'int');
83$origin =
GETPOST(
'origin',
'alpha');
84$originid =
GETPOST(
'originid',
'int');
85$fac_recid =
GETPOST(
'fac_rec',
'int');
94$hookmanager->initHooks(array(
'invoicesuppliercard',
'globalcard'));
100$extrafields->fetch_name_optionals_label($object->table_element);
103if ($id > 0 || !empty($ref)) {
104 $ret = $object->fetch($id, $ref);
108 $ret = $object->fetch_thirdparty();
115$socid =
GETPOST(
'socid',
'int');
116if (!empty($user->socid)) {
117 $socid = $user->socid;
121$result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture',
'fk_soc',
'rowid', $isdraft);
124$usercanread = ($user->hasRight(
"fournisseur",
"facture",
"lire") || $user->hasRight(
"supplier_invoice",
"lire"));
125$usercancreate = ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"));
126$usercandelete = ($user->hasRight(
"fournisseur",
"facture",
"supprimer") || $user->hasRight(
"supplier_invoice",
"supprimer"));
127$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
130$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"validate")));
131$usercansend = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"send"));
134$permissionnote = $usercancreate;
135$permissiondellink = $usercancreate;
136$permissiontoedit = $usercancreate;
137$permissiontoadd = $usercancreate;
146$parameters = array(
'socid'=>$socid);
147$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
152if (empty($reshook)) {
153 $backurlforlist = DOL_URL_ROOT.
'/fourn/facture/list.php';
155 if (empty($backtopage) || ($cancel && empty($id))) {
156 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
157 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
158 $backtopage = $backurlforlist;
160 $backtopage = DOL_URL_ROOT.
'/fourn/facture/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
166 if (!empty($backtopageforcancel)) {
167 header(
"Location: ".$backtopageforcancel);
169 } elseif (!empty($backtopage)) {
170 header(
"Location: ".$backtopage);
176 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
178 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
180 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
183 if (
GETPOST(
'linkedOrder') && empty($cancel) && $id > 0) {
185 $object->fetch_thirdparty();
186 $result = $object->add_object_linked(
'order_supplier',
GETPOST(
'linkedOrder'));
190 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
193 if (
GETPOST(
'newsupplierref',
'alphanohtml')) {
194 $objectutil->ref_supplier =
GETPOST(
'newsupplierref',
'alphanohtml');
198 $result = $objectutil->createFromClone($user, $id);
200 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
203 $langs->load(
"errors");
207 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
208 $idwarehouse =
GETPOST(
'idwarehouse');
211 $object->fetch_thirdparty();
213 $qualified_for_stock_change = 0;
215 $qualified_for_stock_change = $object->hasProductsOrServices(2);
217 $qualified_for_stock_change = $object->hasProductsOrServices(1);
221 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
222 $langs->load(
"stocks");
223 if (!$idwarehouse || $idwarehouse == -1) {
225 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
233 $result = $object->validate($user,
'', $idwarehouse);
243 $outputlangs = $langs;
246 $newlang =
GETPOST(
'lang_id',
'aZ09');
249 $newlang = $object->thirdparty->default_lang;
251 if (!empty($newlang)) {
253 $outputlangs->setDefaultLang($newlang);
255 $model = $object->model_pdf;
256 $ret = $object->fetch($id);
258 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
265 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
267 $object->fetch_thirdparty();
269 $isErasable = $object->is_erasable();
271 if (($usercandelete && $isErasable > 0) || ($usercancreate && $isErasable == 1)) {
272 $revertstock =
GETPOST(
'revertstock');
275 $idwarehouse =
GETPOST(
'idwarehouse');
277 $qualified_for_stock_change = 0;
279 $qualified_for_stock_change = $object->hasProductsOrServices(2);
281 $qualified_for_stock_change = $object->hasProductsOrServices(1);
285 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
286 $langs->load(
"stocks");
287 if (!$idwarehouse || $idwarehouse == -1) {
289 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
292 $result = $object->setDraft($user, $idwarehouse);
301 $result = $object->delete($user);
303 header(
'Location: list.php?restore_lastsearch_values=1');
310 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
312 $result = $object->deleteline($lineid);
315 $object->line_order(
true);
332 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
339 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
342 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
343 $discount->unlink_invoice();
344 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercancreate) {
346 $result = $object->setPaid($user);
350 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes') {
353 $close_code =
GETPOST(
"close_code",
'restricthtml');
354 $close_note =
GETPOST(
"close_note",
'restricthtml');
356 $result = $object->setPaid($user, $close_code, $close_note);
361 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
363 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes') {
366 $close_code =
GETPOST(
"close_code",
'restricthtml');
367 $close_note =
GETPOST(
"close_note",
'restricthtml');
369 $result = $object->setCanceled($user, $close_code, $close_note);
374 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
379 if ($action ==
'setref_supplier' && $usercancreate) {
380 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alpha');
382 if ($object->update($user) < 0) {
386 $outputlangs = $langs;
389 $newlang =
GETPOST(
'lang_id',
'aZ09');
392 $newlang = $object->thirdparty->default_lang;
394 if (!empty($newlang)) {
396 $outputlangs->setDefaultLang($newlang);
399 $ret = $object->fetch($object->id);
400 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
406 if ($action ==
'setconditions' && $usercancreate) {
408 $object->cond_reglement_code = 0;
409 $object->cond_reglement_id = 0;
416 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
424 $new_date_echeance = $object->calculate_date_lim_reglement();
425 if ($new_date_echeance) {
426 $object->date_echeance = $new_date_echeance;
428 if ($object->date_echeance < $object->date) {
429 $object->date_echeance = $object->date;
431 $result = $object->update($user);
443 } elseif ($action ==
'set_incoterms' && isModEnabled(
'incoterm')) {
445 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
446 } elseif ($action ==
'setmode' && $usercancreate) {
448 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
449 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
451 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
452 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
454 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx',
'alpha')),
GETPOST(
'calculation_mode',
'int'));
455 } elseif ($action ==
'setbankaccount' && $usercancreate) {
457 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
458 } elseif ($action ==
'setvatreversecharge' && $usercancreate) {
460 $vatreversecharge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
461 $result = $object->setVATReverseCharge($vatreversecharge);
464 if ($action ==
'settransportmode' && ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"))) {
466 $result = $object->setTransportMode(
GETPOST(
'transport_mode_id',
'int'));
467 } elseif ($action ==
'setlabel' && $usercancreate) {
470 $object->label =
GETPOST(
'label');
471 $result = $object->update($user);
475 } elseif ($action ==
'setdatef' && $usercancreate) {
477 if ($newdate > (
dol_now(
'tzuserrel') + (!
getDolGlobalString(
'INVOICE_MAX_FUTURE_DELAY') ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
479 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
481 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
487 $object->date = $newdate;
488 $date_echence_calc = $object->calculate_date_lim_reglement();
489 if (!empty($object->date_echeance)) {
490 $object->date_echeance = $date_echence_calc;
492 if ($object->date_echeance && $object->date_echeance < $object->date) {
493 $object->date_echeance = $object->date;
496 $result = $object->update($user);
500 } elseif ($action ==
'setdate_lim_reglement' && $usercancreate) {
502 $object->date_echeance =
dol_mktime(12, 0, 0,
GETPOST(
'date_lim_reglementmonth',
'int'),
GETPOST(
'date_lim_reglementday',
'int'),
GETPOST(
'date_lim_reglementyear',
'int'));
503 if (!empty($object->date_echeance) && $object->date_echeance < $object->date) {
504 $object->date_echeance = $object->date;
505 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
507 $result = $object->update($user);
511 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
514 if (
GETPOST(
"remise_id",
"int")) {
515 $ret = $object->fetch($id);
517 $result = $object->insert_discount(
GETPOST(
"remise_id",
"int"));
526 if (
GETPOST(
"remise_id_for_payment",
"int")) {
527 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
529 $discount->fetch(
GETPOST(
"remise_id_for_payment",
"int"));
533 $remaintopay = $object->getRemainToPay(0);
537 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
541 $result = $discount->link_to_invoice(0, $id);
548 $newremaintopay = $object->getRemainToPay(0);
549 if ($newremaintopay == 0) {
550 $object->setPaid($user);
560 $outputlangs = $langs;
563 $newlang =
GETPOST(
'lang_id',
'aZ09');
566 $newlang = $object->thirdparty->default_lang;
568 if (!empty($newlang)) {
570 $outputlangs->setDefaultLang($newlang);
572 $ret = $object->fetch($id);
574 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
579 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
582 $object->fetch_thirdparty();
587 $result = $discountcheck->fetch(0, 0, $object->id);
599 $amount_ht = $amount_tva = $amount_ttc = array();
600 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
604 foreach ($object->lines as $line) {
605 if ($line->product_type < 9 && $line->total_ht != 0) {
606 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
608 $amount_ht[$keyforvatrate] += $line->total_ht;
609 $amount_tva[$keyforvatrate] += $line->total_tva;
610 $amount_ttc[$keyforvatrate] += $line->total_ttc;
611 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
612 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
613 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
620 $alreadypaid = $object->getSommePaiement();
621 if ($alreadypaid && abs($alreadypaid) < abs($object->total_ttc)) {
622 $ratio = abs(($object->total_ttc - $alreadypaid) / $object->total_ttc);
623 foreach ($amount_ht as $vatrate => $val) {
624 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
625 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
626 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
627 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
628 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
629 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
638 $discount->description =
'(CREDIT_NOTE)';
640 $discount->description =
'(DEPOSIT)';
642 $discount->description =
'(EXCESS PAID)';
644 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
646 $discount->discount_type = 1;
647 $discount->fk_soc = $object->socid;
648 $discount->fk_invoice_supplier_source = $object->id;
656 $sql =
'SELECT SUM(pf.amount) as total_paiements';
657 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'paiementfourn as p';
658 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN ('.
getEntity(
'c_paiement').
')';
659 $sql .=
' WHERE pf.fk_facturefourn = '.((int) $object->id);
660 $sql .=
' AND pf.fk_paiementfourn = p.rowid';
661 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
663 $resql = $db->query($sql);
668 $res = $db->fetch_object($resql);
669 $total_paiements = $res->total_paiements;
672 $total_creditnote_and_deposit = 0;
673 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
674 $sql .=
" re.description, re.fk_invoice_supplier_source";
675 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
676 $sql .=
" WHERE fk_invoice_supplier = ".((int) $object->id);
677 $resql = $db->query($sql);
678 if (!empty($resql)) {
679 while ($obj = $db->fetch_object($resql)) {
680 $total_creditnote_and_deposit += $obj->amount_ttc;
686 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object->total_ttc;
687 $discount->amount_tva = 0;
688 $discount->tva_tx = 0;
689 $discount->vat_src_code =
'';
691 $result = $discount->create($user);
697 foreach ($amount_ht as $tva_tx => $xxx) {
698 $discount->amount_ht = abs($amount_ht[$tva_tx]);
699 $discount->amount_tva = abs($amount_tva[$tva_tx]);
700 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
701 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
702 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
703 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
708 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
709 $vat_src_code = $reg[1];
710 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
713 $discount->tva_tx = abs($tva_tx);
714 $discount->vat_src_code = $vat_src_code;
716 $result = $discount->create($user);
727 $result = $object->setPaid($user);
742 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate) {
747 $result = $paiementfourn->fetch(
GETPOST(
'paiement_id'));
749 $result = $paiementfourn->delete();
751 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
759 } elseif ($action ==
'add' && $usercancreate) {
762 $object->socid =
GETPOST(
'socid',
'int');
764 $selectedLines =
GETPOST(
'toselect',
'array');
771 $ret = $extrafields->setOptionalsFromPost(
null, $object);
784 if (
GETPOST(
'type',
'int') ===
'') {
785 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
790 if (empty($dateinvoice)) {
791 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
793 $_GET[
'socid'] = $_POST[
'socid'];
801 if (!(
GETPOST(
'fac_replacement',
'int') > 0)) {
803 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
808 $result = $object->fetch(
GETPOST(
'fac_replacement',
'int'));
809 $object->fetch_thirdparty();
811 $object->ref =
GETPOST(
'ref',
'alphanohtml');
812 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alpha');
813 $object->socid =
GETPOST(
'socid',
'int');
814 $object->libelle =
GETPOST(
'label',
'alphanohtml');
815 $object->label =
GETPOST(
'label',
'alphanohtml');
816 $object->date = $dateinvoice;
817 $object->date_echeance = $datedue;
818 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
819 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
820 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
821 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
822 $object->fk_account =
GETPOST(
'fk_account',
'int');
823 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
824 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
825 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
826 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
827 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
828 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
829 $object->transport_mode_id =
GETPOST(
'transport_mode_id',
'int');
832 $object->fk_facture_source =
GETPOST(
'fac_replacement',
'int');
835 $id = $object->createFromCurrent($user);
845 $sourceinvoice =
GETPOST(
'fac_avoir',
'int');
848 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
850 if (
GETPOST(
'socid',
'int') < 1) {
851 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
856 if (empty($dateinvoice)) {
857 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
859 $_GET[
'socid'] = $_POST[
'socid'];
867 if (!
GETPOST(
'ref_supplier')) {
868 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
870 $_GET[
'socid'] = $_POST[
'socid'];
876 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
881 $tmpproject =
GETPOST(
'projectid',
'int');
884 $object->ref =
GETPOST(
'ref',
'alphanohtml');
885 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
886 $object->subtype =
GETPOST(
'subtype',
'alphanohtml');
887 $object->socid =
GETPOST(
'socid',
'int');
888 $object->libelle =
GETPOST(
'label',
'alphanohtml');
889 $object->label =
GETPOST(
'label',
'alphanohtml');
890 $object->date = $dateinvoice;
891 $object->date_echeance = $datedue;
892 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
893 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
894 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
895 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
896 $object->fk_account =
GETPOST(
'fk_account',
'int');
897 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
898 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
899 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
900 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
901 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
902 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
903 $object->transport_mode_id =
GETPOST(
'transport_mode_id',
'int');
906 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
909 $id = $object->create($user);
915 if (
GETPOST(
'invoiceAvoirWithLines',
'int') == 1 && $id > 0) {
917 if ($facture_source->fetch($object->fk_facture_source) > 0) {
920 foreach ($facture_source->lines as $line) {
922 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
926 $line->fk_facture_fourn = $object->id;
927 $line->fk_parent_line = $fk_parent_line;
929 $line->subprice = -$line->subprice;
930 $line->pa_ht = -$line->pa_ht;
931 $line->total_ht = -$line->total_ht;
932 $line->total_tva = -$line->total_tva;
933 $line->total_ttc = -$line->total_ttc;
934 $line->total_localtax1 = -$line->total_localtax1;
935 $line->total_localtax2 = -$line->total_localtax2;
937 $result = $line->insert();
939 $object->lines[] = $line;
942 if ($result > 0 && $line->product_type == 9) {
943 $fk_parent_line = $result;
947 $object->update_price(1);
951 if (
GETPOST(
'invoiceAvoirWithPaymentRestAmount',
'int') == 1 && $id > 0) {
953 if ($facture_source->fetch($object->fk_facture_source) > 0) {
954 $totalpaid = $facture_source->getSommePaiement();
955 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
956 $totaldeposits = $facture_source->getSumDepositsUsed();
957 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
958 $desc = $langs->trans(
'invoiceAvoirLineWithPaymentRestAmount');
959 $retAddLine = $object->addline($desc, $remain_to_pay, 0, 0, 0, 1, 0, 0,
'',
'', 0,
'',
'TTC');
961 if ($retAddLine < 0) {
969 if (empty($dateinvoice)) {
971 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
981 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
986 $object->socid =
GETPOST(
'socid',
'int');
987 $object->type =
GETPOST(
'type',
'alphanohtml');
988 $object->subtype =
GETPOST(
'subtype',
'alphanohtml');
989 $object->ref =
GETPOST(
'ref',
'alphanohtml');
990 $object->date = $dateinvoice;
991 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
992 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
993 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
994 $object->model_pdf =
GETPOST(
'model',
'alphanohtml');
995 $object->fk_project =
GETPOST(
'projectid',
'int');
996 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
997 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
998 $object->fk_account =
GETPOST(
'fk_account',
'int');
1002 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1003 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1004 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1005 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1008 $object->fac_rec = $fac_recid;
1010 $fac_rec->fetch($object->fac_rec);
1011 $fac_rec->fetch_lines();
1012 $object->lines = $fac_rec->lines;
1014 $id = $object->create($user);
1018 if (
GETPOST(
'socid',
'int') < 1) {
1019 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1024 if (empty($dateinvoice)) {
1025 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
1027 $_GET[
'socid'] = $_POST[
'socid'];
1035 if (!
GETPOST(
'ref_supplier')) {
1036 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplierBill')),
null,
'errors');
1038 $_GET[
'socid'] = $_POST[
'socid'];
1044 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1049 $tmpproject =
GETPOST(
'projectid',
'int');
1052 $object->socid =
GETPOST(
'socid',
'int');
1053 $object->type =
GETPOST(
'type',
'alphanohtml');
1054 $object->subtype =
GETPOST(
'subtype',
'alphanohtml');
1055 $object->ref =
GETPOST(
'ref',
'alphanohtml');
1056 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
1057 $object->socid =
GETPOST(
'socid',
'int');
1058 $object->libelle =
GETPOST(
'label',
'alphanohtml');
1059 $object->label =
GETPOST(
'label',
'alphanohtml');
1060 $object->date = $dateinvoice;
1061 $object->date_echeance = $datedue;
1062 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
1063 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
1064 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
1065 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
1066 $object->fk_account =
GETPOST(
'fk_account',
'int');
1067 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1068 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1069 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1070 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1071 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1072 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1073 $object->transport_mode_id =
GETPOST(
'transport_mode_id');
1076 if (empty($object->date_echeance)) {
1077 $object->date_echeance = $object->calculate_date_lim_reglement();
1080 $object->fetch_thirdparty();
1083 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
1085 $element = $subelement =
GETPOST(
'origin',
'alpha');
1093 if ($element ==
'order') {
1094 $element = $subelement =
'commande';
1096 if ($element ==
'propal') {
1097 $element =
'comm/propal';
1098 $subelement =
'propal';
1100 if ($element ==
'contract') {
1101 $element = $subelement =
'contrat';
1103 if ($element ==
'order_supplier') {
1105 $subelement =
'fournisseur.commande';
1107 if ($element ==
'project') {
1108 $element =
'projet';
1110 $object->origin =
GETPOST(
'origin',
'alpha');
1111 $object->origin_id =
GETPOST(
'originid',
'int');
1114 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
1115 $classname = ucfirst($subelement);
1116 if ($classname ==
'Fournisseur.commande') {
1117 $classname =
'CommandeFournisseur';
1119 $objectsrc =
new $classname($db);
1120 $objectsrc->fetch($originid);
1121 $objectsrc->fetch_thirdparty();
1123 if (!empty($object->origin) && !empty($object->origin_id)) {
1124 $object->linkedObjectsIds[$object->origin] = $object->origin_id;
1128 if ($object->origin ==
'reception') {
1129 $objectsrc->fetchObjectLinked();
1131 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1132 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1133 $object->linkedObjectsIds[
'order_supplier'] = $value;
1138 $id = $object->create($user);
1142 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
1143 $classname = ucfirst($subelement);
1144 if ($classname ==
'Fournisseur.commande') {
1145 $classname =
'CommandeFournisseur';
1147 $srcobject =
new $classname($db);
1149 $result = $srcobject->fetch(
GETPOST(
'originid',
'int'));
1152 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1157 $amountdeposit = array();
1159 if ($typeamount ==
'amount') {
1160 $amount = $valuedeposit;
1162 $amount = $srcobject->total_ttc * ($valuedeposit / 100);
1165 $TTotalByTva = array();
1166 foreach ($srcobject->lines as &$line) {
1167 if (!empty($line->special_code)) {
1170 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1173 foreach ($TTotalByTva as $tva => &$total) {
1174 $coef = $total / $srcobject->total_ttc;
1175 $am = $amount * $coef;
1176 $amount_ttc_diff += $am;
1177 $amountdeposit[$tva] += $am / (1 + $tva / 100);
1180 if ($typeamount ==
'amount') {
1181 $amountdeposit[0] = $valuedeposit;
1182 } elseif ($typeamount ==
'variable') {
1185 $lines = $srcobject->lines;
1186 $numlines = count($lines);
1187 for ($i = 0; $i < $numlines; $i++) {
1189 if (empty($lines[$i]->qty)) {
1192 if (!empty($lines[$i]->special_code)) {
1196 $totalamount += $lines[$i]->total_ht;
1197 $tva_tx = $lines[$i]->tva_tx;
1198 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $valuedeposit) / 100;
1202 if ($totalamount == 0) {
1203 $amountdeposit[0] = 0;
1211 $amount_ttc_diff = $amountdeposit[0];
1214 foreach ($amountdeposit as $tva => $amount) {
1215 if (empty($amount)) {
1220 'amount' =>
'FixAmount',
1221 'variable' =>
'VarAmount'
1223 $descline =
'(DEPOSIT)';
1225 if ($typeamount ==
'amount') {
1226 $descline .=
' ('.price($valuedeposit,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
')';
1227 } elseif ($typeamount ==
'variable') {
1228 $descline .=
' ('.$valuedeposit.
'%)';
1231 $descline .=
' - '.$srcobject->ref;
1232 $result = $object->addline(
1239 (!
getDolGlobalString(
'INVOICE_PRODUCTID_DEPOSIT') ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT),
1244 $lines[$i]->info_bits,
1254 $lines[$i]->special_code,
1261 $diff = $object->total_ttc - $amount_ttc_diff;
1264 $object->fetch_lines();
1265 $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100);
1266 $object->updateline(
1267 $object->lines[0]->id,
1268 $object->lines[0]->desc,
1270 $object->lines[0]->tva_tx,
1271 $object->lines[0]->localtax1_tx,
1272 $object->lines[0]->localtax2_tx,
1273 $object->lines[0]->qty,
1274 $object->lines[0]->fk_product,
1276 $object->lines[0]->info_bits,
1277 $object->lines[0]->product_type,
1278 $object->lines[0]->remise_percent,
1280 $object->lines[0]->date_start,
1281 $object->lines[0]->date_end,
1289 } elseif ($result > 0) {
1290 $lines = $srcobject->lines;
1291 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1292 $srcobject->fetch_lines();
1293 $lines = $srcobject->lines;
1296 $num = count($lines);
1297 for ($i = 0; $i < $num; $i++) {
1298 if (!in_array($lines[$i]->
id, $selectedLines)) {
1302 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
1303 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1306 if (method_exists($lines[$i],
'fetch_optionals')) {
1307 $lines[$i]->fetch_optionals();
1312 $date_start = $lines[$i]->date_debut_prevue;
1313 if ($lines[$i]->date_debut_reel) {
1314 $date_start = $lines[$i]->date_debut_reel;
1316 if ($lines[$i]->date_start) {
1317 $date_start = $lines[$i]->date_start;
1319 $date_end = $lines[$i]->date_fin_prevue;
1320 if ($lines[$i]->date_fin_reel) {
1321 $date_end = $lines[$i]->date_fin_reel;
1323 if ($lines[$i]->date_end) {
1324 $date_end = $lines[$i]->date_end;
1328 $object->special_code = $lines[$i]->special_code;
1331 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
1333 $pu_currency = $lines[$i]->multicurrency_subprice;
1335 $pu = $lines[$i]->subprice;
1340 $result = $object->addline(
1344 $lines[$i]->localtax1_tx,
1345 $lines[$i]->localtax2_tx,
1347 $lines[$i]->fk_product,
1348 $lines[$i]->remise_percent,
1352 $lines[$i]->info_bits,
1357 $lines[$i]->array_options,
1358 $lines[$i]->fk_unit,
1361 $lines[$i]->ref_supplier,
1362 $lines[$i]->special_code
1372 $object->fetch_lines();
1379 } elseif (!$error) {
1380 $id = $object->create($user);
1389 $langs->load(
"errors");
1394 $_GET[
'socid'] = $_POST[
'socid'];
1399 $outputlangs = $langs;
1400 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1407 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1410 } elseif ($action ==
'updateline' && $usercancreate) {
1414 if (! $object->fetch($id) > 0) {
1417 $object->fetch_thirdparty();
1420 $tva_tx = str_replace(
'*',
'', $tva_tx);
1422 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_subprice') !=
'') {
1424 $price_base_type =
'HT';
1427 $price_base_type =
'TTC';
1430 if (
GETPOST(
'productid') > 0) {
1434 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1439 $prod->fetch(
GETPOST(
'productid'));
1440 $label = $prod->description;
1441 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1442 $label =
GETPOST(
'product_desc',
'restricthtml');
1445 $type = $prod->type;
1447 $label =
GETPOST(
'product_desc',
'restricthtml');
1456 if (preg_match(
'/\*/', $tva_tx)) {
1461 $tva_tx = str_replace(
'*',
'', $tva_tx);
1462 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1463 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1469 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1470 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1472 if (is_array($extralabelsline)) {
1473 foreach ($extralabelsline as $key => $value) {
1474 unset($_POST[
"options_".$key]);
1478 $result = $object->updateline(
1500 unset($_POST[
'label']);
1501 unset($_POST[
'fourn_ref']);
1502 unset($_POST[
'date_starthour']);
1503 unset($_POST[
'date_startmin']);
1504 unset($_POST[
'date_startsec']);
1505 unset($_POST[
'date_startday']);
1506 unset($_POST[
'date_startmonth']);
1507 unset($_POST[
'date_startyear']);
1508 unset($_POST[
'date_endhour']);
1509 unset($_POST[
'date_endmin']);
1510 unset($_POST[
'date_endsec']);
1511 unset($_POST[
'date_endday']);
1512 unset($_POST[
'date_endmonth']);
1513 unset($_POST[
'date_endyear']);
1514 unset($_POST[
'price_ttc']);
1515 unset($_POST[
'price_ht']);
1522 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !=
'' && $usercancreate) {
1524 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1525 $vat_rate = str_replace(
'*',
'', $vat_rate);
1526 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1527 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1528 foreach ($object->lines as $line) {
1529 $result = $object->updateline($line->id, $line->desc, $line->subprice, $vat_rate, $localtax1_rate, $localtax2_rate, $line->qty, $line->fk_product,
'HT', $line->info_bits, $line->product_type, $line->remise_percent, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier, $line->rang);
1531 } elseif ($action ==
'addline' && $usercancreate) {
1535 $ret = $object->fetch($id);
1540 $ret = $object->fetch_thirdparty();
1542 $langs->load(
'errors');
1547 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
1551 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1552 if ($prod_entry_mode ==
'free') {
1555 $idprod =
GETPOST(
'idprod',
'int');
1563 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
1566 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
1567 if (empty($remise_percent)) {
1568 $remise_percent = 0;
1572 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1573 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
1575 if (is_array($extralabelsline)) {
1577 foreach ($extralabelsline as $key => $value) {
1578 unset($_POST[
"options_".$key]);
1582 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
1583 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1586 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
1587 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
1590 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
1591 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
1594 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
1595 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
1598 if (!
GETPOST(
'qty',
'alpha')) {
1599 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1603 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
1604 if ($combinations =
GETPOST(
'combinations',
'array')) {
1608 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1609 $idprod = $res->fk_product_child;
1611 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
1617 if ($prod_entry_mode !=
'free' && empty($error)) {
1621 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
1626 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
1628 $res = $productsupplier->fetch($idprod);
1631 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
1633 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1634 if ($productsupplier->fourn_socid != $socid) {
1635 $productsupplier->ref_supplier =
'';
1638 $fksoctosearch = $object->thirdparty->id;
1639 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1641 } elseif (
GETPOST(
'idprodfournprice',
'alpha') > 0) {
1642 $qtytosearch = $qty;
1644 $idprod = $productsupplier->get_buyprice(
GETPOST(
'idprodfournprice',
'alpha'), $qtytosearch);
1645 $res = $productsupplier->fetch($idprod);
1649 $label = $productsupplier->label;
1652 $outputlangs = $langs;
1654 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1655 $newlang =
GETPOST(
'lang_id',
'aZ09');
1657 if (empty($newlang)) {
1658 $newlang = $object->thirdparty->default_lang;
1660 if (!empty($newlang)) {
1661 $outputlangs =
new Translate(
"", $conf);
1662 $outputlangs->setDefaultLang($newlang);
1664 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
1666 $desc = $productsupplier->description;
1669 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
1670 $desc = $productsupplier->desc_supplier;
1674 if (trim($product_desc) == trim($desc) &&
getDolGlobalString(
'PRODUIT_AUTOFILL_DESC')) {
1678 $desc = $product_desc;
1680 if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
1684 $ref_supplier = $productsupplier->ref_supplier;
1687 if (!GETPOSTISSET(
'tva_tx')) {
1688 $tva_tx =
get_default_tva($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
1689 $tva_npr =
get_default_npr($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
1691 if (empty($tva_tx) || empty($tva_npr)) {
1694 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
1695 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
1697 $type = $productsupplier->type;
1698 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1699 $price_base_type =
'HT';
1701 $pu_devise =
price2num($price_ht_devise,
'CU');
1702 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
1703 $price_base_type =
'TTC';
1705 $pu_devise =
price2num($price_ttc_devise,
'CU');
1707 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
1708 if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) {
1709 $pu = $productsupplier->fourn_pu;
1712 $pu = $productsupplier->fourn_pu;
1713 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
1717 $ref_supplier = $productsupplier->ref_supplier;
1723 $result = $object->addline(
1738 min($rank, count($object->lines) + 1),
1741 $productsupplier->fk_unit,
1744 GETPOST(
'fourn_ref',
'alpha'),
1748 if ($idprod == -99 || $idprod == 0) {
1751 $langs->load(
"errors");
1752 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
1754 if ($idprod == -1) {
1757 $langs->load(
"errors");
1758 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
1760 } elseif (empty($error)) {
1761 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1762 $tva_tx = str_replace(
'*',
'', $tva_tx);
1763 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1764 $desc = $product_desc;
1766 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
1768 $fk_unit =
GETPOST(
'units',
'alpha');
1770 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1775 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1776 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1778 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1782 $pu_ht =
price2num($pu_ttc / (1 + ($tva_tx / 100)),
'MU');
1784 $price_base_type =
'HT';
1785 $pu_devise =
price2num($price_ht_devise,
'CU');
1787 $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);
1791 if (!$error && $result > 0) {
1796 $outputlangs = $langs;
1799 $newlang =
GETPOST(
'lang_id',
'aZ09');
1802 $newlang = $object->thirdparty->default_lang;
1804 if (!empty($newlang)) {
1805 $outputlangs =
new Translate(
"", $conf);
1806 $outputlangs->setDefaultLang($newlang);
1808 $model = $object->model_pdf;
1809 $ret = $object->fetch($id);
1811 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1817 unset($_POST [
'prod_entry_mode']);
1819 unset($_POST[
'qty']);
1820 unset($_POST[
'type']);
1821 unset($_POST[
'remise_percent']);
1822 unset($_POST[
'pu']);
1823 unset($_POST[
'price_ht']);
1824 unset($_POST[
'multicurrency_price_ht']);
1825 unset($_POST[
'price_ttc']);
1826 unset($_POST[
'fourn_ref']);
1827 unset($_POST[
'tva_tx']);
1828 unset($_POST[
'label']);
1829 unset($localtax1_tx);
1830 unset($localtax2_tx);
1831 unset($_POST[
'np_marginRate']);
1832 unset($_POST[
'np_markRate']);
1833 unset($_POST[
'dp_desc']);
1834 unset($_POST[
'idprodfournprice']);
1835 unset($_POST[
'units']);
1837 unset($_POST[
'date_starthour']);
1838 unset($_POST[
'date_startmin']);
1839 unset($_POST[
'date_startsec']);
1840 unset($_POST[
'date_startday']);
1841 unset($_POST[
'date_startmonth']);
1842 unset($_POST[
'date_startyear']);
1843 unset($_POST[
'date_endhour']);
1844 unset($_POST[
'date_endmin']);
1845 unset($_POST[
'date_endsec']);
1846 unset($_POST[
'date_endday']);
1847 unset($_POST[
'date_endmonth']);
1848 unset($_POST[
'date_endyear']);
1855 } elseif ($action ==
'classin' && $usercancreate) {
1856 $object->fetch($id);
1857 $result = $object->setProject($projectid);
1858 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
1860 $object->fetch($id);
1862 $totalpaid = $object->getSommePaiement();
1863 $resteapayer = $object->total_ttc - $totalpaid;
1866 $ventilExportCompta = $object->getVentilExportCompta();
1868 if (!$ventilExportCompta) {
1871 $idwarehouse =
GETPOST(
'idwarehouse');
1873 $object->fetch_thirdparty();
1875 $qualified_for_stock_change = 0;
1877 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1879 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1883 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
1884 $langs->load(
"stocks");
1885 if (!$idwarehouse || $idwarehouse == -1) {
1887 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1892 $object->setDraft($user, $idwarehouse);
1896 $outputlangs = $langs;
1899 $newlang =
GETPOST(
'lang_id',
'aZ09');
1902 $newlang = $object->thirdparty->default_lang;
1904 if (!empty($newlang)) {
1905 $outputlangs =
new Translate(
"", $conf);
1906 $outputlangs->setDefaultLang($newlang);
1908 $model = $object->model_pdf;
1909 $ret = $object->fetch($id);
1911 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1920 } elseif ($action ==
'reopen' && $usercancreate) {
1922 $result = $object->fetch($id);
1925 $result = $object->setUnpaid($user);
1927 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
1936 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1939 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
1941 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
1942 $trackid =
'sinv'.$object->id;
1943 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1946 $upload_dir = $conf->fournisseur->facture->dir_output;
1947 $permissiontoadd = $usercancreate;
1948 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1951 if ($action ==
'calculate') {
1952 $calculationrule =
GETPOST(
'calculationrule');
1954 $object->fetch($id);
1955 $object->fetch_thirdparty();
1956 $result = $object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0, $object->thirdparty);
1962 if ($action ==
'update_extras') {
1963 $object->oldcopy =
dol_clone($object, 2);
1966 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1974 $result = $object->insertExtraFields(
'BILL_SUPPLIER_MODIFY');
1982 $action =
'edit_extras';
1987 if ($action ==
'addcontact') {
1988 $result = $object->fetch($id);
1990 if ($result > 0 && $id > 0) {
1993 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1997 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2000 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2001 $langs->load(
"errors");
2002 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2007 } elseif ($action ==
'swapstatut') {
2009 if ($object->fetch($id)) {
2010 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
2014 } elseif ($action ==
'deletecontact') {
2016 $object->fetch($id);
2017 $result = $object->delete_contact(
GETPOST(
"lineid",
'int'));
2020 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2034$form =
new Form($db);
2036$bankaccountstatic =
new Account($db);
2038if (isModEnabled(
'project')) {
2044$title = $object->ref.
" - ".$langs->trans(
'Card');
2045if ($action ==
'create') {
2046 $title = $langs->trans(
"NewSupplierInvoice");
2048$help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
2052if ($action ==
'create') {
2055 print
load_fiche_titre($langs->trans(
'NewSupplierInvoice'),
'',
'supplier_invoice');
2059 $currency_code = $conf->currency;
2062 if (
GETPOST(
'socid',
'int') > 0) {
2064 $societe->fetch(
GETPOST(
'socid',
'int'));
2065 if (isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2066 $currency_code = $societe->multicurrency_code;
2070 if (!empty($origin) && !empty($originid)) {
2072 $element = $subelement = $origin;
2074 if ($element ==
'project') {
2075 $projectid = $originid;
2076 $element =
'projet';
2080 if ($element ==
'order') {
2081 $element = $subelement =
'commande';
2083 if ($element ==
'propal') {
2084 $element =
'comm/propal';
2085 $subelement =
'propal';
2087 if ($element ==
'contract') {
2088 $element = $subelement =
'contrat';
2090 if ($element ==
'order_supplier') {
2092 $subelement =
'fournisseur.commande';
2095 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
2096 $classname = ucfirst($subelement);
2097 if ($classname ==
'Fournisseur.commande') {
2098 $classname =
'CommandeFournisseur';
2100 $objectsrc =
new $classname($db);
2101 $objectsrc->fetch($originid);
2102 $objectsrc->fetch_thirdparty();
2104 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
2106 $soc = $objectsrc->thirdparty;
2108 $cond_reglement_id = 0;
2109 $mode_reglement_id = 0;
2113 $transport_mode_id = 0;
2116 if (!empty($objectsrc->cond_reglement_id)) {
2117 $cond_reglement_id = $objectsrc->cond_reglement_id;
2119 if (!empty($objectsrc->mode_reglement_id)) {
2120 $mode_reglement_id = $objectsrc->mode_reglement_id;
2122 if (!empty($objectsrc->fk_account)) {
2123 $fk_account = $objectsrc->fk_account;
2125 if (!empty($objectsrc->transport_mode_id)) {
2126 $transport_mode_id = $objectsrc->transport_mode_id;
2129 if (empty($cond_reglement_id)
2130 || empty($mode_reglement_id)
2131 || empty($fk_account)
2132 || empty($transport_mode_id)
2134 if ($origin ==
'reception') {
2136 if (!isset($objectsrc->supplier_order)) {
2137 $objectsrc->fetch_origin();
2140 if (!empty($objectsrc->commandeFournisseur)) {
2141 $supplierOrder = $objectsrc->commandeFournisseur;
2142 if (empty($cond_reglement_id) && !empty($supplierOrder->cond_reglement_id)) {
2143 $cond_reglement_id = $supplierOrder->cond_reglement_id;
2145 if (empty($mode_reglement_id) && !empty($supplierOrder->mode_reglement_id)) {
2146 $mode_reglement_id = $supplierOrder->mode_reglement_id;
2148 if (empty($fk_account) && !empty($supplierOrder->fk_account)) {
2149 $fk_account = $supplierOrder->fk_account;
2151 if (empty($transport_mode_id) && !empty($supplierOrder->transport_mode_id)) {
2152 $transport_mode_id = $supplierOrder->transport_mode_id;
2159 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
2160 $cond_reglement_id = $soc->cond_reglement_supplier_id;
2162 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
2163 $mode_reglement_id = $soc->mode_reglement_supplier_id;
2165 if (empty($fk_account) && !empty($soc->fk_account)) {
2166 $fk_account = $soc->fk_account;
2168 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
2169 $transport_mode_id = $soc->transport_mode_id;
2174 if (isModEnabled(
"multicurrency")) {
2175 if (!empty($objectsrc->multicurrency_code)) {
2176 $currency_code = $objectsrc->multicurrency_code;
2178 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
2179 $currency_tx = $objectsrc->multicurrency_tx;
2184 $dateinvoice = ($datetmp ==
'' ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $datetmp);
2186 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2189 $objectsrc->fetch_optionals();
2190 $object->array_options = $objectsrc->array_options;
2192 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2193 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2194 $vat_reverse_charge = (empty($societe) ?
'' : $societe->vat_reverse_charge);
2195 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2196 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2198 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalInt(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2200 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2202 if (isModEnabled(
"multicurrency") && !empty($soc->multicurrency_code)) {
2203 $currency_code = $soc->multicurrency_code;
2208 if (empty($cond_reglement_id)) {
2209 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2213 if (empty($mode_reglement_id)) {
2214 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2218 if (!
GETPOST(
'changecompany')) {
2219 if (GETPOSTISSET(
'cond_reglement_id')) {
2220 $cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
2222 if (GETPOSTISSET(
'mode_reglement_id')) {
2223 $mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
2225 if (GETPOSTISSET(
'cond_reglement_id')) {
2226 $fk_account =
GETPOST(
'fk_account',
'int');
2230 $note_public = $object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
2231 $note_private = $object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
2233 if ($origin ==
'contrat') {
2234 $langs->load(
"admin");
2235 $text = $langs->trans(
"ToCreateARecurringInvoice");
2236 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"SupplierBills"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
2238 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
2240 print
info_admin($text, 0, 0, 0,
'opacitymedium').
'<br>';
2243 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2244 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2245 print
'<input type="hidden" name="action" value="add">';
2246 print
'<input type="hidden" name="changecompany" value="0">';
2248 if (!empty($societe->id) && $societe->id > 0) {
2249 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2251 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2252 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2253 if (!empty($currency_tx)) {
2254 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2256 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2261 $parameters = array();
2263 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierInvoice', $parameters, $object, $action);
2264 if (empty($reshook)) {
2265 print
'<table class="border centpercent">';
2268 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
2272 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2273 $invoice_predefined->fetch($fac_recid);
2277 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2280 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2281 $absolute_discount = $societe->getAvailableDiscounts(
'',
'', 0, 1);
2282 print $societe->getNomUrl(1,
'supplier');
2283 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2285 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2286 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company(empty($societe->id) ? 0 : $societe->id,
'socid', $filter,
'SelectThirdParty', 1, 0, null, 0,
'minwidth175 widthcentpercentminusxx maxwidth500');
2289 print
'<script type="text/javascript">
2290 $(document).ready(function() {
2291 $("#socid").change(function() {
2292 console.log("We have changed the company - Reload page");
2294 $("input[name=action]").val("create");
2295 $("input[name=changecompany]").val("1");
2296 $("form[name=add]").submit();
2301 if ($fac_recid <= 0) {
2302 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>';
2308 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2309 $invoice_predefined->fetch($fac_recid);
2311 $dateinvoice = $invoice_predefined->date_when;
2312 if (empty($projectid)) {
2313 $projectid = $invoice_predefined->fk_project;
2315 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2316 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2317 $fk_account = $invoice_predefined->fk_account;
2318 $note_public = $invoice_predefined->note_public;
2319 $note_private = $invoice_predefined->note_private;
2321 if (!empty($invoice_predefined->multicurrency_code)) {
2322 $currency_code = $invoice_predefined->multicurrency_code;
2324 if (!empty($invoice_predefined->multicurrency_tx)) {
2325 $currency_tx = $invoice_predefined->multicurrency_tx;
2328 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2329 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2330 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2332 $resql = $db->query($sql);
2334 $num = $db->num_rows($resql);
2338 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2340 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2341 print
'<option value="0" selected></option>';
2343 $objp = $db->fetch_object($resql);
2344 print
'<option value="'.$objp->rowid.
'"';
2345 if ($fac_recid == $objp->rowid) {
2347 $exampletemplateinvoice->fetch($fac_recid);
2349 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2355 print
'<script type="text/javascript">
2356 $(document).ready(function() {
2357 $("#fac_rec").change(function() {
2358 console.log("We have changed the template invoice - Reload page");
2360 $("input[name=action]").val("create");
2361 $("form[name=add]").submit();
2375 print
'<tr><td class="fieldrequired">'.$langs->trans(
'RefSupplierBill').
'</td><td><input name="ref_supplier" value="'.(GETPOSTISSET(
'ref_supplier') ?
GETPOST(
'ref_supplier') : (!empty($objectsrc->ref_supplier) ? $objectsrc->ref_supplier :
'')).
'" type="text"';
2376 if (!empty($societe->id) && $societe->id > 0) {
2382 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2384 print
'<div class="tagtable">'.
"\n";
2387 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2388 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOST(
'type',
'int') ?
'' :
'checked').
'> ';
2389 $desc = $form->textwithpicto($tmp.
'<label for="radio_standard">'.$langs->trans(
"InvoiceStandardAsk").
'</label>', $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2391 print
'</div></div>';
2393 if (empty($origin) || ($origin ==
'order_supplier' && !empty($originid))) {
2396 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2397 $tmp=
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOST(
'type') == 3 ?
' checked' :
'') .
'> ';
2398 print
'<script type="text/javascript">
2399 jQuery(document).ready(function() {
2400 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2401 jQuery("#radio_standard").prop("checked", true);
2403 jQuery("#typedeposit, #valuedeposit").click(function() {
2404 jQuery("#radio_deposit").prop("checked", true);
2406 jQuery("#typedeposit").change(function() {
2407 console.log("We change type of down payment");
2408 jQuery("#radio_deposit").prop("checked", true);
2409 setRadioForTypeOfInvoice();
2411 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2412 setRadioForTypeOfInvoice();
2414 function setRadioForTypeOfInvoice() {
2415 console.log("Change radio");
2416 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2417 jQuery(".checkforselect").prop("disabled", true);
2418 jQuery(".checkforselect").prop("checked", false);
2420 jQuery(".checkforselect").prop("disabled", false);
2421 jQuery(".checkforselect").prop("checked", true);
2427 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2428 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2429 print
'<table class="nobordernopadding"><tr>';
2433 if ($origin ==
'order_supplier') {
2434 print
'<td class="nowrap" style="padding-left: 15px">';
2436 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2437 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2438 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2440 print $form->selectarray(
'typedeposit', $arraylist,
GETPOST(
'typedeposit',
'aZ09'), 0, 0, 0,
'', 1);
2442 print
'<td class="nowrap" style="padding-left: 5px">';
2443 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' .
GETPOST(
'valuedeposit',
'int') .
'"/>';
2446 print
'</tr></table>';
2448 print
'</div></div>';
2517 if (empty($origin)) {
2518 if (!empty($societe->id) && $societe->id > 0) {
2522 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2529 foreach ($facids as $key => $valarray) {
2530 $newinvoice_static->id = $key;
2531 $newinvoice_static->ref = $valarray [
'ref'];
2532 $newinvoice_static->statut = $valarray [
'status'];
2533 $newinvoice_static->type = $valarray [
'type'];
2534 $newinvoice_static->paye = $valarray [
'paye'];
2536 $optionsav .=
'<option value="'.$key.
'"';
2537 if ($key ==
GETPOST(
'fac_avoir',
'int')) {
2538 $optionsav .=
' selected';
2541 $optionsav .= $newinvoice_static->ref;
2542 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
2543 $optionsav .=
'</option>';
2546 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2547 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
2549 $tmp .=
' disabled';
2553 print
'<script type="text/javascript">
2554 jQuery(document).ready(function() {
2555 if (! jQuery("#radio_creditnote").is(":checked"))
2557 jQuery("#credit_note_options").hide();
2559 jQuery("#radio_creditnote").click(function() {
2560 jQuery("#credit_note_options").show();
2562 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2563 jQuery("#credit_note_options").hide();
2567 $text = $tmp.
'<label for="radio_creditnote">'.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
2569 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2571 $text .=
' disabled';
2575 $text .=
'<option value="-1"></option>';
2576 $text .= $optionsav;
2578 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
2580 $text .=
'</select>';
2581 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2584 print
'<div id="credit_note_options" class="clearboth">';
2585 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' :
'').
' /> ';
2586 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
2587 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' :
'').
' /> ';
2588 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
2591 print
'</div></div>';
2594 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2596 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2598 $tmp=
'<input type="radio" name="type" id="radio_creditnote" value="2"> ';
2600 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
2601 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
2602 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2604 print
'</div></div>'.
"\n";
2615 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
2616 print $form->getSelectInvoiceSubtype(
GETPOST(
'subtype'),
'subtype', 1, 0,
'');
2620 if (!empty($societe->id) && $societe->id > 0) {
2622 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2624 $thirdparty = $societe;
2626 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2627 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2633 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth200" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
2636 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
2637 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2638 print $form->selectDate($dateinvoice,
'',
'',
'',
'',
"add", 1, 1);
2642 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2643 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
2644 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1);
2649 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
2650 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2651 print $form->selectDate($datedue,
'ech',
'',
'',
'',
"add", 1, 1);
2655 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2656 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2657 $form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'DBIT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
2661 if (isModEnabled(
"banque")) {
2662 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2664 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
2669 if (isModEnabled(
'project')) {
2672 $langs->load(
'projects');
2673 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2674 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects((!
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $societe->id : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
2675 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>';
2680 if (isModEnabled(
'incoterm')) {
2682 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
2683 print
'<td colspan="3" class="maxwidthonsmartphone">';
2684 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2685 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 :
''));
2691 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
2692 print
'<tr><td>' . $langs->trans(
'VATReverseCharge') .
'</td><td>';
2694 if ($vat_reverse_charge == 1 || $societe->vat_reverse_charge == 1 || ($societe->country_code !=
'FR' &&
isInEEC($societe) && !empty($societe->tva_intra))) {
2695 $vat_reverse_charge = 1;
2697 $vat_reverse_charge = 0;
2700 print
'<input type="checkbox" name="vat_reverse_charge"'. (!empty($vat_reverse_charge) ?
' checked ' :
'') .
'>';
2705 if (isModEnabled(
"multicurrency")) {
2707 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
2708 print
'<td class="maxwidthonsmartphone">';
2709 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
2710 $used_currency_code = $currency_code;
2711 if (!
GETPOST(
'changecompany')) {
2712 $used_currency_code = GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code;
2714 print $form->selectMultiCurrency($used_currency_code,
'multicurrency_code');
2720 if ($fac_recid > 0) {
2721 $dateexample = $dateinvoice;
2722 if (empty($dateexample)) {
2725 $substitutionarray = array(
2726 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
2727 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
2728 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
2729 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
2730 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
2731 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
2732 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
2733 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
2734 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
2735 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
2736 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
2739 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
2740 foreach ($substitutionarray as $key => $val) {
2741 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
2743 $htmltext .=
'</i>';
2747 if (isModEnabled(
'intracommreport')) {
2748 $langs->loadLangs(array(
"intracommreport"));
2749 print
'<!-- If module intracomm on -->'.
"\n";
2750 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
2751 $form->selectTransportMode(GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
2755 if (empty($reshook)) {
2756 print $object->showOptionals($extrafields,
'create');
2760 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2762 $doleditor =
new DolEditor(
'note_public', (GETPOSTISSET(
'note_public') ?
GETPOST(
'note_public',
'restricthtml') : $note_public),
'', 80,
'dolibarr_notes',
'In', 0, false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
2763 print $doleditor->Create(1);
2769 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
2771 $doleditor =
new DolEditor(
'note_private', (GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') : $note_private),
'', 80,
'dolibarr_notes',
'In', 0, false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
2772 print $doleditor->Create(1);
2778 if (!empty($objectsrc) && is_object($objectsrc)) {
2779 print
"\n<!-- ".$classname.
" info -->";
2781 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2782 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2783 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2784 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2785 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2787 $txt = $langs->trans($classname);
2788 if ($classname ==
'CommandeFournisseur') {
2789 $langs->load(
'orders');
2790 $txt = $langs->trans(
"SupplierOrder");
2792 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
2794 $objectsrc->fetchObjectLinked($originid, $origin,
'',
'invoice_supplier');
2796 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
2799 if (is_array($invoice_supplier)) {
2800 $cntinvoice = count($invoice_supplier);
2802 if ($cntinvoice >= 1) {
2804 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
2809 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2810 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2811 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2812 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2815 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2816 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2818 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2820 if (isModEnabled(
"multicurrency")) {
2821 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2822 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2823 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2828 $parameters = array();
2829 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
2830 print $hookmanager->resPrint;
2838 print $form->buttonsSaveCancel(
"CreateDraft");
2841 if (!empty($objectsrc) && is_object($objectsrc)) {
2844 $title = $langs->trans(
'ProductsAndServices');
2847 print
'<div class="div-table-responsive-no-min">';
2848 print
'<table class="noborder centpercent">';
2850 $objectsrc->printOriginLinesList(
'', $selectedLines);
2858 if ($id > 0 || !empty($ref)) {
2864 $productstatic =
new Product($db);
2866 $result = $object->fetch($id, $ref);
2868 $langs->load(
"errors");
2869 print $langs->trans(
"ErrorRecordNotFound");
2875 $result = $object->fetch_thirdparty();
2881 $societe = $object->thirdparty;
2883 $totalpaid = $object->getSommePaiement();
2884 $totalcreditnotes = $object->getSumCreditNotesUsed();
2885 $totaldeposits = $object->getSumDepositsUsed();
2893 $resteapayer =
price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
2896 $multicurrency_resteapayer = 0;
2897 if (isModEnabled(
"multicurrency")) {
2898 $multicurrency_totalpaid = $object->getSommePaiement(1);
2899 $multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
2900 $multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
2901 $multicurrency_resteapayer =
price2num($object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
2905 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 && $object->multicurrency_code != $conf->currency) {
2906 $resteapayer =
price2num($multicurrency_resteapayer / $object->multicurrency_tx,
'MT');
2910 if ($object->paye) {
2913 $resteapayeraffiche = $resteapayer;
2916 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2917 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2919 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2920 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2923 $absolute_discount = $societe->getAvailableDiscounts(
'', $filterabsolutediscount, 0, 1);
2924 $absolute_creditnote = $societe->getAvailableDiscounts(
'', $filtercreditnote, 0, 1);
2925 $absolute_discount =
price2num($absolute_discount,
'MT');
2926 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2931 $objectidnext = $object->getIdReplacingInvoice();
2934 $titre = $langs->trans(
'SupplierInvoice');
2936 print
dol_get_fiche_head($head,
'card', $titre, -1,
'supplier_invoice', 0,
'',
'', 0,
'', 1);
2941 if ($action ==
'converttoreduc') {
2944 $type_fac =
'ExcessPaid';
2946 $type_fac =
'CreditNote';
2948 $type_fac =
'Deposit';
2950 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
2951 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
2952 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
2956 if ($action ==
'clone') {
2958 $formquestion = array(
2959 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplierBill"),
'value' => $langs->trans(
"CopyOf").
' '.$object->ref_supplier),
2960 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
2963 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
2967 if ($action ==
'valid') {
2969 if (preg_match(
'/^[\(]?PROV/i', $object->ref) || empty($object->ref)) {
2971 $numref = $object->getNextNumRef($societe);
2973 $numref = $object->ref;
2980 $text = $langs->trans(
'ConfirmValidateBill', $numref);
2988 $formquestion = array();
2990 $qualified_for_stock_change = 0;
2992 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2994 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2997 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
2998 $langs->load(
"stocks");
2999 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3002 $warehouse_array = $warehouse->list_array();
3003 if (count($warehouse_array) == 1) {
3004 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
3005 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3008 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3010 $formquestion = array(
3011 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3015 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
3020 if ($action ==
'edit') {
3021 $formquestion = array();
3023 $qualified_for_stock_change = 0;
3025 $qualified_for_stock_change = $object->hasProductsOrServices(2);
3027 $qualified_for_stock_change = $object->hasProductsOrServices(1);
3029 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
3030 $langs->load(
"stocks");
3031 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3034 $warehouse_array = $warehouse->list_array();
3035 if (count($warehouse_array) == 1) {
3036 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
3037 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3040 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3042 $formquestion = array(
3043 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3046 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill', $object->ref),
'confirm_edit', $formquestion, 1, 1);
3050 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer == $object->total_ttc))) {
3051 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill', $object->ref),
'confirm_paid',
'', 0, 1);
3054 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer != $object->total_ttc)) {
3058 $close[$i][
'code'] =
'discount_vat';
3060 $close[$i][
'code'] =
'badsupplier';
3062 $close[$i][
'code'] =
'other';
3066 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
3068 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3070 $close[$i][
'label'] = $langs->trans(
"Other");
3074 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3076 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3078 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
3081 foreach ($close as $key => $val) {
3082 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
3086 $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'));
3088 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially', $object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
3092 if ($action ==
'canceled') {
3094 $close[1][
'code'] =
'badsupplier';
3095 $close[2][
'code'] =
'abandon';
3097 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3098 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
3100 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier", $object->ref), $close[1][
'label'], 1);
3101 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
3103 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
3104 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
3107 $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'));
3109 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill', $object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 250);
3113 if ($action ==
'delete') {
3114 $formquestion = array();
3116 $qualified_for_stock_change = 0;
3118 $qualified_for_stock_change = $object->hasProductsOrServices(2);
3120 $qualified_for_stock_change = $object->hasProductsOrServices(1);
3123 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
3124 $langs->load(
"stocks");
3125 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3128 $warehouse_array = $warehouse->list_array();
3130 $selectwarehouse =
'<span class="questionrevertstock hidden">';
3131 if (count($warehouse_array) == 1) {
3132 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
3133 $selectwarehouse .=
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3136 $selectwarehouse .= $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3138 $selectwarehouse .=
'</span>';
3140 $selectyesno = array(0 => $langs->trans(
'No'), 1 => $langs->trans(
'Yes'));
3142 print
'<script type="text/javascript">
3143 $(document).ready(function() {
3144 $("#revertstock").change(function() {
3145 if(this.value > 0) {
3146 $(".questionrevertstock").removeClass("hidden");
3148 $(".questionrevertstock").addClass("hidden");
3154 $formquestion = array(
3155 array(
'type' =>
'select',
'name' =>
'revertstock',
'label' => $langs->trans(
"RevertProductsToStock"),
'select_show_empty' => 0,
'values' => $selectyesno),
3156 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $selectwarehouse,
'tdclass' =>
'questionrevertstock hidden')
3160 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete', $formquestion, 1, 1);
3162 if ($action ==
'deletepayment') {
3163 $payment_id =
GETPOST(
'paiement_id');
3164 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
3168 if ($action ==
'ask_deleteline') {
3169 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
3172 if (!$formconfirm) {
3173 $parameters = array(
'formConfirm' => $formconfirm,
'lineid'=>$lineid);
3174 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
3175 if (empty($reshook)) {
3176 $formconfirm .= $hookmanager->resPrint;
3177 } elseif ($reshook > 0) {
3178 $formconfirm = $hookmanager->resPrint;
3187 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
3189 $morehtmlref =
'<div class="refidno">';
3191 $morehtmlref .= $form->editfieldkey(
"RefSupplierBill",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'', 0, 1);
3192 $morehtmlref .= $form->editfieldval(
"RefSupplierBill",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
3194 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'supplier');
3196 $morehtmlref .=
' <div class="inline-block valignmiddle">(<a class="valignmiddle" href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.((int) $object->thirdparty->id).
'&search_company='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)</div>';
3199 if (isModEnabled(
'project')) {
3200 $langs->load(
"projects");
3201 $morehtmlref .=
'<br>';
3202 if ($permissiontoadd) {
3203 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
3204 if ($action !=
'classify') {
3205 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.newToken().
'&id='.((int) $object->id).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
3207 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, (!
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
3209 if (!empty($object->fk_project)) {
3211 $proj->fetch($object->fk_project);
3212 $morehtmlref .= $proj->getNomUrl(1);
3214 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
3219 $morehtmlref .=
'</div>';
3221 $object->totalpaid = $totalpaid;
3223 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
3226 $parameters = array();
3228 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierInvoice', $parameters, $object, $action);
3229 if (empty($reshook)) {
3230 print
'<div class="fichecenter">';
3231 print
'<div class="fichehalfleft">';
3232 print
'<div class="underbanner clearboth"></div>';
3234 print
'<table class="border tableforfield centpercent">';
3237 print
'<tr><td class="titlefield">'.$langs->trans(
'Type').
'</td><td>';
3238 print
'<span class="badgeneutral">';
3239 print $object->getLibType();
3241 if ($object->subtype > 0) {
3242 print
' '.$object->getSubtypeLabel(
'facture_fourn');
3246 $facreplaced->fetch($object->fk_facture_source);
3247 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
3250 if ($object->fk_facture_source > 0) {
3252 $facusing->fetch($object->fk_facture_source);
3253 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
3255 $langs->load(
"errors");
3256 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"WarningCorrectedInvoiceNotFound").
'</span>';
3260 $facidavoir = $object->getListIdAvoirFromInvoice();
3261 if (count($facidavoir) > 0) {
3262 $invoicecredits = array();
3263 foreach ($facidavoir as $id) {
3265 $facavoir->fetch($id);
3266 $invoicecredits[] = $facavoir->getNomUrl(1);
3268 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
3271 if (isset($objectidnext) && $objectidnext > 0) {
3274 $facthatreplace->fetch($objectidnext);
3275 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
3279 $result = $discount->fetch(0, 0, $object->id);
3281 print
' <span class="opacitymediumbycolor paddingleft">';
3282 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
3283 $s = str_replace(
'{s1}', $object->getLibType(1), $s);
3284 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
3286 print
'</span><br>';
3290 if ($object->fk_fac_rec_source > 0) {
3292 $result = $tmptemplate->fetch($object->fk_fac_rec_source);
3294 print
' <span class="opacitymediumbycolor paddingleft">';
3295 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->title).
'</a>';
3296 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
3306 print
'<!-- Discounts -->'.
"\n";
3307 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
3310 $thirdparty = $societe;
3312 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3318 print
'<td>'.$form->editfieldkey(
"Label",
'label', $object->label, $object, $usercancreate).
'</td>';
3319 print
'<td>'.$form->editfieldval(
"Label",
'label', $object->label, $object, $usercancreate).
'</td>';
3327 print $form->editfieldkey(
"DateInvoice",
'datef', $object->date, $object, $form_permission,
'datepicker');
3328 print
'</td><td colspan="3">';
3329 print $form->editfieldval(
"Date",
'datef', $object->date, $object, $form_permission,
'datepicker');
3333 $langs->load(
'bills');
3334 print
'<tr><td class="nowrap">';
3335 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3336 print $langs->trans(
'PaymentConditions');
3338 if ($action !=
'editconditions' && $form_permission) {
3339 print
'<td class="right"><a class="editfielda reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=editconditions&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetConditions'), 1).
'</a></td>';
3341 print
'</tr></table>';
3343 if ($action ==
'editconditions') {
3344 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
3346 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none');
3353 print $form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', $object->date_echeance, $object, $form_permission,
'datepicker');
3355 print $form->editfieldval(
"DateMaxPayment",
'date_lim_reglement', $object->date_echeance, $object, $form_permission,
'datepicker');
3356 if ($action !=
'editdate_lim_reglement' && $object->hasDelay()) {
3362 $langs->load(
'bills');
3363 print
'<tr><td class="nowrap">';
3364 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3365 print $langs->trans(
'PaymentMode');
3367 if ($action !=
'editmode' && $form_permission) {
3368 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>';
3370 print
'</tr></table>';
3372 if ($action ==
'editmode') {
3373 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3375 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
3380 if (isModEnabled(
"multicurrency")) {
3384 print
'<table class="nobordernopadding" width="100%"><tr><td>';
3385 print $form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
3387 if ($action !=
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT) {
3388 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>';
3390 print
'</tr></table>';
3392 if ($action ==
'editmulticurrencycode') {
3393 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
3395 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
3400 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3403 print
'<table class="nobordernopadding centpercent"><tr><td>';
3404 print $form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
3406 if ($action !=
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3407 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>';
3409 print
'</tr></table>';
3411 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
3412 if ($action ==
'actualizemulticurrencyrate') {
3415 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
3417 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
3418 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3419 print
'<div class="inline-block"> ';
3420 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
3429 if (isModEnabled(
"banque")) {
3430 print
'<tr><td class="nowrap">';
3431 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3432 print $langs->trans(
'BankAccount');
3434 if ($action !=
'editbankaccount' && $usercancreate) {
3435 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>';
3437 print
'</tr></table>';
3439 if ($action ==
'editbankaccount') {
3440 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
3442 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
3450 print
'<tr><td class="nowrap">';
3451 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3452 print $langs->trans(
'VATReverseCharge');
3454 if ($action !=
'editvatreversecharge' && $usercancreate) {
3455 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editvatreversecharge&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetVATReverseCharge'), 1).
'</a></td>';
3457 print
'</tr></table>';
3459 if ($action ==
'editvatreversecharge') {
3460 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
3461 print
'<input type="hidden" name="action" value="setvatreversecharge">';
3462 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3464 print
'<input type="checkbox" name="vat_reverse_charge"' . ($object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
'>';
3466 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
3469 print
'<input type="checkbox" name="vat_reverse_charge"'. ($object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
' disabled>';
3475 if (isModEnabled(
'incoterm')) {
3477 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3478 print $langs->trans(
'IncotermLabel');
3479 print
'<td><td class="right">';
3480 if ($usercancreate) {
3481 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$object->id.
'&action=editincoterm&token='.newToken().
'">'.
img_edit().
'</a>';
3485 print
'</td></tr></table>';
3488 if ($action !=
'editincoterm') {
3489 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
3491 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
3497 if (isModEnabled(
'intracommreport')) {
3498 $langs->loadLangs(array(
"intracommreport"));
3499 print
'<!-- If module intracomm on -->'.
"\n";
3501 print
'<table class="nobordernopadding centpercent"><tr><td>';
3502 print $langs->trans(
'IntracommReportTransportMode');
3504 if ($action !=
'edittransportmode' && ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"))) {
3505 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edittransportmode&token='.newToken().
'&id='.$object->id.
'">'.
img_edit().
'</a></td>';
3507 print
'</tr></table>';
3510 if ($action ==
'edittransportmode') {
3511 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->transport_mode_id,
'transport_mode_id', 1, 1);
3513 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->transport_mode_id,
'none');
3520 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
3525 print
'<div class="fichehalfright">';
3526 print
'<div class="underbanner clearboth"></div>';
3528 print
'<table class="border tableforfield centpercent">';
3531 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
3532 print
'<td class="nowrap amountcard right">' .
price($object->total_ht,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
3533 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
3534 print
'<td class="nowrap amountcard right">' .
price($object->multicurrency_total_ht,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
3539 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
3540 print
'<td class="nowrap amountcard right">';
3541 if (
GETPOST(
'calculationrule')) {
3542 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
3544 $calculationrule = (!
getDolGlobalString(
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND') ?
'totalofround' :
'roundoftotal');
3546 if ($calculationrule ==
'totalofround') {
3547 $calculationrulenum = 1;
3549 $calculationrulenum = 2;
3552 if ($object->getVentilExportCompta() == 0) {
3553 $s =
'<span class="hideonsmartphone opacitymedium">' . $langs->trans(
"ReCalculate") .
' </span>';
3554 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'&action=calculate&calculationrule=totalofround">' . $langs->trans(
"Mode1") .
'</a>';
3556 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'&action=calculate&calculationrule=roundoftotal">' . $langs->trans(
"Mode2") .
'</a>';
3557 print
'<div class="inline-block">';
3558 print $form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum) .
'<br>' . $langs->trans(
"CalculationRuleDescSupplier"), 2, 1,
img_picto(
'',
'help'),
'', 3,
'', 0,
'recalculate');
3559 print
' ';
3562 print
price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency);
3564 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
3565 print
'<td class="nowrap amountcard right">' .
price($object->multicurrency_total_tva,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
3569 if ($societe->localtax1_assuj ==
"1") {
3571 print
'<td>' . $langs->transcountry(
"AmountLT1", $societe->country_code) .
'</td>';
3572 print
'<td class="nowrap amountcard right">' .
price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency) .
'</td>';
3575 if ($societe->localtax2_assuj ==
"1") {
3577 print
'<td>' . $langs->transcountry(
"AmountLT2", $societe->country_code) .
'</td>';
3578 print
'<td class="nowrap amountcard right">' .
price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency) .
'</td>';
3583 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
3584 print
'<td class="nowrap amountcard right">' .
price($object->total_ttc,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
3585 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
3586 print
'<td class="nowrap amountcard right">' .
price($object->multicurrency_total_ttc,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
3604 if (isModEnabled(
'project')) {
3607 if (isModEnabled(
"banque")) {
3611 if (isModEnabled(
'incoterm')) {
3614 if (isModEnabled(
"multicurrency")) {
3619 if ($societe->localtax1_assuj ==
"1") {
3622 if ($societe->localtax2_assuj ==
"1") {
3626 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
3627 $sql .=
' c.id as payment_type, c.code as payment_code,';
3628 $sql .=
' pf.amount,';
3629 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
3630 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
3631 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
3632 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
3633 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
3634 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
3635 $sql .=
' WHERE pf.fk_facturefourn = '.((int) $object->id);
3636 $sql .=
' ORDER BY p.datep, p.tms';
3638 $result = $db->query($sql);
3640 $num = $db->num_rows($result);
3643 print
'<div class="div-table-responsive-no-min">';
3644 print
'<table class="noborder paymenttable centpercent">';
3645 print
'<tr class="liste_titre">';
3647 print
'<td>'.$langs->trans(
'Date').
'</td>';
3648 print
'<td>'.$langs->trans(
'Type').
'</td>';
3649 if (isModEnabled(
"banque")) {
3650 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
3652 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
3653 print
'<td width="18"> </td>';
3658 $objp = $db->fetch_object($result);
3660 $paymentstatic->id = $objp->rowid;
3661 $paymentstatic->datepaye = $db->jdate($objp->dp);
3662 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
3663 $paymentstatic->num_payment = $objp->num_payment;
3665 $paymentstatic->paiementcode = $objp->payment_code;
3666 $paymentstatic->type_code = $objp->payment_code;
3667 $paymentstatic->type_label = $objp->payment_type;
3669 print
'<tr class="oddeven">';
3670 print
'<td class="nowraponall">';
3671 print $paymentstatic->getNomUrl(1);
3673 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
'</td>';
3674 $s = $form->form_modes_reglement(
null, $objp->payment_type,
'none',
'', 1, 0,
'', 1).
' '.$objp->num_payment;
3675 print
'<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).
'">';
3678 if (isModEnabled(
"banque")) {
3679 $bankaccountstatic->id = $objp->baid;
3680 $bankaccountstatic->ref = $objp->baref;
3681 $bankaccountstatic->label = $objp->baref;
3682 $bankaccountstatic->number = $objp->banumber;
3684 if (isModEnabled(
'accounting')) {
3685 $bankaccountstatic->account_number = $objp->account_number;
3688 $accountingjournal->fetch($objp->fk_accountancy_journal);
3689 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
3692 print
'<td class="right">';
3693 if ($objp->baid > 0) {
3694 print $bankaccountstatic->getNomUrl(1,
'transactions');
3698 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
3699 print
'<td class="center">';
3701 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=deletepayment&token='.newToken().
'&paiement_id='.$objp->rowid.
'">';
3707 $totalpaid += $objp->amount;
3711 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td><td></td><td></td></tr>';
3734 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3735 print
'<span class="opacitymedium">';
3737 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
3739 print $langs->trans(
'AlreadyPaid');
3742 print
'</td><td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td><td> </td></tr>';
3745 $resteapayeraffiche = $resteapayer;
3747 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
3750 $creditnoteamount = 0;
3753 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
3754 $sql .=
" re.description, re.fk_invoice_supplier_source";
3755 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
3756 $sql .=
" WHERE fk_invoice_supplier = ".((int) $object->id);
3757 $resql = $db->query($sql);
3759 $num = $db->num_rows($resql);
3763 $obj = $db->fetch_object($resql);
3764 $invoice->fetch($obj->fk_invoice_supplier_source);
3765 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3767 print $langs->trans(
"CreditNote").
' ';
3770 print $langs->trans(
"Deposit").
' ';
3772 print $invoice->getNomUrl(0);
3774 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
3775 print
'<td class="right">';
3776 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=unlinkdiscount&discountid='.$obj->rowid.
'">';
3777 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
3782 $creditnoteamount += $obj->amount_ttc;
3785 $depositamount += $obj->amount_ttc;
3794 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3795 print
'<span class="opacitymedium">';
3796 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
3798 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3799 $resteapayeraffiche = 0;
3800 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3804 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3805 print
'<span class="opacitymedium">';
3806 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
3808 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3810 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3814 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3815 print
'<span class="opacitymedium">';
3816 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
3818 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3819 $resteapayeraffiche = 0;
3820 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3824 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3825 $text = $langs->trans(
"HelpAbandonOther");
3826 if ($object->close_note) {
3827 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.$object->close_note;
3829 print
'<span class="opacitymedium">';
3830 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
3832 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3833 $resteapayeraffiche = 0;
3834 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3838 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3839 print
'<span class="opacitymedium">';
3840 print $langs->trans(
"Billed");
3842 print
'</td><td class="right">'.price($object->total_ttc).
'</td><td> </td></tr>';
3845 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3846 print
'<span class="opacitymedium">';
3847 print $langs->trans(
'RemainderToPay');
3848 if ($resteapayeraffiche < 0) {
3849 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3853 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
3856 if (isModEnabled(
'multicurrency') && $object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3857 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3858 print
'<span class="opacitymedium">';
3859 print $langs->trans(
'RemainderToPayMulticurrency');
3860 if ($resteapayeraffiche < 0) {
3861 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3865 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.(!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency).
' '.
price(
price2num($multicurrency_resteapayer,
'MT')).
'</td><td> </td></tr>';
3868 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3871 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3872 print $langs->trans(
'AlreadyPaidBack');
3873 print
' :</td><td class="right">'.price($sign * $totalpaid).
'</td><td> </td></tr>';
3876 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"Billed").
' :</td><td class="right">'.
price($sign * $object->total_ttc).
'</td><td> </td></tr>';
3879 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3880 print
'<span class="opacitymedium">';
3881 print $langs->trans(
'RemainderToPayBack');
3882 if ($resteapayeraffiche > 0) {
3883 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3887 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td><td> </td></tr>';
3890 if (isModEnabled(
'multicurrency') && $object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3891 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3892 print
'<span class="opacitymedium">';
3893 print $langs->trans(
'RemainderToPayBackMulticurrency');
3894 if ($resteapayeraffiche> 0) {
3895 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3899 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>';
3914 print
'<div class="clearboth"></div><br>';
3917 $blocname =
'contacts';
3918 $title = $langs->trans(
'ContactsAddresses');
3919 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3924 $blocname =
'notes';
3925 $title = $langs->trans(
'Notes');
3926 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3933 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
3934 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3935 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
3936 print
'<input type="hidden" name="mode" value="">';
3937 print
'<input type="hidden" name="page_y" value="">';
3938 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
3939 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
3940 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3943 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
3946 print
'<div class="div-table-responsive-no-min">';
3947 print
'<table id="tablelines" class="noborder noshadow centpercent">';
3949 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
3952 $inputalsopricewithtax = 1;
3953 $senderissupplier = 2;
3956 $senderissupplier = 1;
3960 if (!empty($object->lines)) {
3961 $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
3964 $num = count($object->lines);
3968 if ($action !=
'editline') {
3971 $parameters = array();
3972 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
3976 if (empty($reshook)) {
3977 $object->formAddObjectLine(1, $societe, $mysoc);
3990 if ($action !=
'presend') {
3995 print
'<div class="tabsAction">';
3997 $parameters = array();
3998 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
4000 if (empty($reshook)) {
4004 $ventilExportCompta = $object->getVentilExportCompta();
4006 if ($ventilExportCompta == 0) {
4007 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=edit&token='.newToken().
'">'.$langs->trans(
'Modify').
'</a>';
4009 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
4014 $result = $discount->fetch(0, 0, $object->id);
4021 if (!$objectidnext && $object->close_code !=
'replaced' && $usercancreate) {
4022 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=reopen&token='.newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
4024 if ($usercancreate) {
4025 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
4027 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
4034 if (count($object->lines)) {
4035 if ($usercanvalidate) {
4036 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid"';
4037 print
'>'.$langs->trans(
'Validate').
'</a>';
4039 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
4040 print
'>'.$langs->trans(
'Validate').
'</a>';
4046 if (empty($user->socid)) {
4049 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
4051 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'SendMail').
'</span>';
4058 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>';
4065 if ($resteapayer == 0) {
4066 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
4068 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>';
4073 if ($object->type ==
FactureFournisseur::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) < 0 && $usercancreate && empty($discount->id)) {
4074 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
4078 && (
getDolGlobalString(
'SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $object->getSommePaiement() == 0)
4080 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>';
4084 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertToReduc').
'</a>';
4095 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaid').
'</a>';
4100 if ($totalpaid > 0 || $totalcreditnotes > 0) {
4102 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
4105 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
4118 if (!$objectidnext) {
4119 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>';
4124 if ($action !=
'edit' && $usercancreate) {
4125 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=clone&socid='.$object->socid.
'">'.$langs->trans(
'ToClone').
'</a>';
4130 if (!$objectidnext && count($object->lines) > 0) {
4131 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
4136 $isErasable = $object->is_erasable();
4137 if ($action !=
'confirm_edit' && ($usercandelete || ($usercancreate && $isErasable == 1))) {
4138 $enableDelete =
false;
4140 $params = (empty($conf->use_javascript_ajax) ? array() : array(
'attr' => array(
'class' =>
'reposition')));
4142 if ($isErasable == -4) {
4143 $htmltooltip = $langs->trans(
"DisabledBecausePayments");
4144 } elseif ($isErasable == -3) {
4145 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastSituationInvoice");
4146 } elseif ($isErasable == -2) {
4147 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastInvoice");
4148 } elseif ($isErasable == -1) {
4149 $htmltooltip = $langs->trans(
"DisabledBecauseDispatchedInBookkeeping");
4150 } elseif ($isErasable <= 0) {
4151 $htmltooltip = $langs->trans(
"DisabledBecauseNotErasable");
4153 $enableDelete =
true;
4156 print
dolGetButtonAction($htmltooltip, $langs->trans(
"Delete"),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.newToken(), $object->id, $enableDelete, $params);
4160 if ($action !=
'confirm_edit') {
4161 print
'<div class="fichecenter"><div class="fichehalfleft">';
4167 $subdir =
get_exdir($object->id, 2, 0, 0, $object,
'invoice_supplier').$ref;
4168 $filedir = $conf->fournisseur->facture->dir_output.
'/'.$subdir;
4169 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.$object->id;
4170 $genallowed = $usercanread;
4171 $delallowed = $usercancreate;
4172 $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (!
getDolGlobalString(
'INVOICE_SUPPLIER_ADDON_PDF') ?
'' : $conf->global->INVOICE_SUPPLIER_ADDON_PDF));
4174 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
4175 $somethingshown = $formfile->numoffiles;
4178 $linktoelem = $form->showLinkToObjectBlock($object,
null, array(
'invoice_supplier'));
4179 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
4181 print
'</div><div class="fichehalfright">';
4184 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
4186 $somethingshown =
$formactions->showactions($object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
4188 print
'</div></div>';
4194 if (
GETPOST(
'modelselected')) {
4195 $action =
'presend';
4199 $modelmail =
'invoice_supplier_send';
4200 $defaulttopic =
'SendBillRef';
4201 $diroutput = $conf->fournisseur->facture->dir_output;
4202 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
4203 $trackid =
'sinv'.$object->id;
4205 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif( $action=='specimen') elseif($action=='setmodel') elseif( $action=='del') elseif($action=='setdoc') $formactions
View.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage bank accounts.
Class to manage accounting journals.
const TYPE_SITUATION
Situation invoice.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_STANDARD
Standard invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const STATUS_CLOSED
Classified paid.
Class to manage invoice templates.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage payments for supplier invoices.
Class ProductCombination Used to represent a product combination.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
facturefourn_prepare_head(FactureFournisseur $object)
Prepare array with list of tabs.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated messages to output (Used to show messages on html output).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.