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;
1327 $tva_tx = $lines[$i]->tva_tx;
1328 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
1329 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1333 $object->special_code = $lines[$i]->special_code;
1336 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
1338 $pu_currency = $lines[$i]->multicurrency_subprice;
1340 $pu = $lines[$i]->subprice;
1345 $result = $object->addline(
1349 $lines[$i]->localtax1_tx,
1350 $lines[$i]->localtax2_tx,
1352 $lines[$i]->fk_product,
1353 $lines[$i]->remise_percent,
1357 $lines[$i]->info_bits,
1362 $lines[$i]->array_options,
1363 $lines[$i]->fk_unit,
1366 $lines[$i]->ref_supplier,
1367 $lines[$i]->special_code
1377 $object->fetch_lines();
1384 } elseif (!$error) {
1385 $id = $object->create($user);
1394 $langs->load(
"errors");
1399 $_GET[
'socid'] = $_POST[
'socid'];
1404 $outputlangs = $langs;
1405 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1412 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1415 } elseif ($action ==
'updateline' && $usercancreate) {
1419 if (! $object->fetch($id) > 0) {
1422 $object->fetch_thirdparty();
1425 $tva_tx = str_replace(
'*',
'', $tva_tx);
1427 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_subprice') !=
'') {
1429 $price_base_type =
'HT';
1432 $price_base_type =
'TTC';
1435 if (
GETPOST(
'productid') > 0) {
1439 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1444 $prod->fetch(
GETPOST(
'productid'));
1445 $label = $prod->description;
1446 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1447 $label =
GETPOST(
'product_desc',
'restricthtml');
1450 $type = $prod->type;
1452 $label =
GETPOST(
'product_desc',
'restricthtml');
1461 if (preg_match(
'/\*/', $tva_tx)) {
1466 $tva_tx = str_replace(
'*',
'', $tva_tx);
1467 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1468 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1474 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1475 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1477 if (is_array($extralabelsline)) {
1478 foreach ($extralabelsline as $key => $value) {
1479 unset($_POST[
"options_".$key]);
1483 $result = $object->updateline(
1505 unset($_POST[
'label']);
1506 unset($_POST[
'fourn_ref']);
1507 unset($_POST[
'date_starthour']);
1508 unset($_POST[
'date_startmin']);
1509 unset($_POST[
'date_startsec']);
1510 unset($_POST[
'date_startday']);
1511 unset($_POST[
'date_startmonth']);
1512 unset($_POST[
'date_startyear']);
1513 unset($_POST[
'date_endhour']);
1514 unset($_POST[
'date_endmin']);
1515 unset($_POST[
'date_endsec']);
1516 unset($_POST[
'date_endday']);
1517 unset($_POST[
'date_endmonth']);
1518 unset($_POST[
'date_endyear']);
1519 unset($_POST[
'price_ttc']);
1520 unset($_POST[
'price_ht']);
1527 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !=
'' && $usercancreate) {
1529 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1530 $vat_rate = str_replace(
'*',
'', $vat_rate);
1531 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1532 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1533 foreach ($object->lines as $line) {
1534 $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);
1536 } elseif ($action ==
'addline' && $usercancreate) {
1540 $ret = $object->fetch($id);
1545 $ret = $object->fetch_thirdparty();
1547 $langs->load(
'errors');
1552 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
1556 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1557 if ($prod_entry_mode ==
'free') {
1560 $idprod =
GETPOST(
'idprod',
'int');
1568 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
1571 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
1572 if (empty($remise_percent)) {
1573 $remise_percent = 0;
1577 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1578 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
1580 if (is_array($extralabelsline)) {
1582 foreach ($extralabelsline as $key => $value) {
1583 unset($_POST[
"options_".$key]);
1587 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
1588 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1591 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
1592 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
1595 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
1596 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
1599 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
1600 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
1603 if (!
GETPOST(
'qty',
'alpha')) {
1604 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1608 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
1609 if ($combinations =
GETPOST(
'combinations',
'array')) {
1613 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1614 $idprod = $res->fk_product_child;
1616 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
1622 if ($prod_entry_mode !=
'free' && empty($error)) {
1626 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
1631 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
1633 $res = $productsupplier->fetch($idprod);
1636 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
1638 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1639 if ($productsupplier->fourn_socid != $socid) {
1640 $productsupplier->ref_supplier =
'';
1643 $fksoctosearch = $object->thirdparty->id;
1644 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1646 } elseif (
GETPOST(
'idprodfournprice',
'alpha') > 0) {
1647 $qtytosearch = $qty;
1649 $idprod = $productsupplier->get_buyprice(
GETPOST(
'idprodfournprice',
'alpha'), $qtytosearch);
1650 $res = $productsupplier->fetch($idprod);
1654 $label = $productsupplier->label;
1657 $outputlangs = $langs;
1659 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1660 $newlang =
GETPOST(
'lang_id',
'aZ09');
1662 if (empty($newlang)) {
1663 $newlang = $object->thirdparty->default_lang;
1665 if (!empty($newlang)) {
1666 $outputlangs =
new Translate(
"", $conf);
1667 $outputlangs->setDefaultLang($newlang);
1669 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
1671 $desc = $productsupplier->description;
1674 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
1675 $desc = $productsupplier->desc_supplier;
1679 if (trim($product_desc) == trim($desc) &&
getDolGlobalString(
'PRODUIT_AUTOFILL_DESC')) {
1683 $desc = $product_desc;
1685 if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
1689 $ref_supplier = $productsupplier->ref_supplier;
1692 if (!GETPOSTISSET(
'tva_tx')) {
1693 $tva_tx =
get_default_tva($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
1694 $tva_npr =
get_default_npr($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
1696 if (empty($tva_tx) || empty($tva_npr)) {
1699 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
1700 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
1702 $type = $productsupplier->type;
1703 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1704 $price_base_type =
'HT';
1706 $pu_devise =
price2num($price_ht_devise,
'CU');
1707 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
1708 $price_base_type =
'TTC';
1710 $pu_devise =
price2num($price_ttc_devise,
'CU');
1712 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
1713 if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) {
1714 $pu = $productsupplier->fourn_pu;
1717 $pu = $productsupplier->fourn_pu;
1718 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
1722 $ref_supplier = $productsupplier->ref_supplier;
1728 $result = $object->addline(
1743 min($rank, count($object->lines) + 1),
1746 $productsupplier->fk_unit,
1749 GETPOST(
'fourn_ref',
'alpha'),
1753 if ($idprod == -99 || $idprod == 0) {
1756 $langs->load(
"errors");
1757 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
1759 if ($idprod == -1) {
1762 $langs->load(
"errors");
1763 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
1765 } elseif (empty($error)) {
1766 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1767 $tva_tx = str_replace(
'*',
'', $tva_tx);
1768 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1769 $desc = $product_desc;
1771 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
1773 $fk_unit =
GETPOST(
'units',
'alpha');
1775 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1780 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1781 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1783 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1787 $pu_ht =
price2num($pu_ttc / (1 + ($tva_tx / 100)),
'MU');
1789 $price_base_type =
'HT';
1790 $pu_devise =
price2num($price_ht_devise,
'CU');
1792 $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);
1796 if (!$error && $result > 0) {
1801 $outputlangs = $langs;
1804 $newlang =
GETPOST(
'lang_id',
'aZ09');
1807 $newlang = $object->thirdparty->default_lang;
1809 if (!empty($newlang)) {
1810 $outputlangs =
new Translate(
"", $conf);
1811 $outputlangs->setDefaultLang($newlang);
1813 $model = $object->model_pdf;
1814 $ret = $object->fetch($id);
1816 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1822 unset($_POST [
'prod_entry_mode']);
1824 unset($_POST[
'qty']);
1825 unset($_POST[
'type']);
1826 unset($_POST[
'remise_percent']);
1827 unset($_POST[
'pu']);
1828 unset($_POST[
'price_ht']);
1829 unset($_POST[
'multicurrency_price_ht']);
1830 unset($_POST[
'price_ttc']);
1831 unset($_POST[
'fourn_ref']);
1832 unset($_POST[
'tva_tx']);
1833 unset($_POST[
'label']);
1834 unset($localtax1_tx);
1835 unset($localtax2_tx);
1836 unset($_POST[
'np_marginRate']);
1837 unset($_POST[
'np_markRate']);
1838 unset($_POST[
'dp_desc']);
1839 unset($_POST[
'idprodfournprice']);
1840 unset($_POST[
'units']);
1842 unset($_POST[
'date_starthour']);
1843 unset($_POST[
'date_startmin']);
1844 unset($_POST[
'date_startsec']);
1845 unset($_POST[
'date_startday']);
1846 unset($_POST[
'date_startmonth']);
1847 unset($_POST[
'date_startyear']);
1848 unset($_POST[
'date_endhour']);
1849 unset($_POST[
'date_endmin']);
1850 unset($_POST[
'date_endsec']);
1851 unset($_POST[
'date_endday']);
1852 unset($_POST[
'date_endmonth']);
1853 unset($_POST[
'date_endyear']);
1860 } elseif ($action ==
'classin' && $usercancreate) {
1861 $object->fetch($id);
1862 $result = $object->setProject($projectid);
1863 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
1865 $object->fetch($id);
1867 $totalpaid = $object->getSommePaiement();
1868 $resteapayer = $object->total_ttc - $totalpaid;
1871 $ventilExportCompta = $object->getVentilExportCompta();
1873 if (!$ventilExportCompta) {
1876 $idwarehouse =
GETPOST(
'idwarehouse');
1878 $object->fetch_thirdparty();
1880 $qualified_for_stock_change = 0;
1882 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1884 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1888 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
1889 $langs->load(
"stocks");
1890 if (!$idwarehouse || $idwarehouse == -1) {
1892 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1897 $object->setDraft($user, $idwarehouse);
1901 $outputlangs = $langs;
1904 $newlang =
GETPOST(
'lang_id',
'aZ09');
1907 $newlang = $object->thirdparty->default_lang;
1909 if (!empty($newlang)) {
1910 $outputlangs =
new Translate(
"", $conf);
1911 $outputlangs->setDefaultLang($newlang);
1913 $model = $object->model_pdf;
1914 $ret = $object->fetch($id);
1916 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1925 } elseif ($action ==
'reopen' && $usercancreate) {
1927 $result = $object->fetch($id);
1930 $result = $object->setUnpaid($user);
1932 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
1941 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1944 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
1946 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
1947 $trackid =
'sinv'.$object->id;
1948 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1951 $upload_dir = $conf->fournisseur->facture->dir_output;
1952 $permissiontoadd = $usercancreate;
1953 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1956 if ($action ==
'calculate') {
1957 $calculationrule =
GETPOST(
'calculationrule');
1959 $object->fetch($id);
1960 $object->fetch_thirdparty();
1961 $result = $object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0, $object->thirdparty);
1967 if ($action ==
'update_extras') {
1968 $object->oldcopy =
dol_clone($object, 2);
1971 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1979 $result = $object->insertExtraFields(
'BILL_SUPPLIER_MODIFY');
1987 $action =
'edit_extras';
1992 if ($action ==
'addcontact') {
1993 $result = $object->fetch($id);
1995 if ($result > 0 && $id > 0) {
1998 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2002 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2005 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2006 $langs->load(
"errors");
2007 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2012 } elseif ($action ==
'swapstatut') {
2014 if ($object->fetch($id)) {
2015 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
2019 } elseif ($action ==
'deletecontact') {
2021 $object->fetch($id);
2022 $result = $object->delete_contact(
GETPOST(
"lineid",
'int'));
2025 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2039$form =
new Form($db);
2041$bankaccountstatic =
new Account($db);
2043if (isModEnabled(
'project')) {
2049$title = $object->ref.
" - ".$langs->trans(
'Card');
2050if ($action ==
'create') {
2051 $title = $langs->trans(
"NewSupplierInvoice");
2053$help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
2057if ($action ==
'create') {
2060 print
load_fiche_titre($langs->trans(
'NewSupplierInvoice'),
'',
'supplier_invoice');
2064 $currency_code = $conf->currency;
2067 if (
GETPOST(
'socid',
'int') > 0) {
2069 $societe->fetch(
GETPOST(
'socid',
'int'));
2070 if (isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2071 $currency_code = $societe->multicurrency_code;
2075 if (!empty($origin) && !empty($originid)) {
2077 $element = $subelement = $origin;
2079 if ($element ==
'project') {
2080 $projectid = $originid;
2081 $element =
'projet';
2085 if ($element ==
'order') {
2086 $element = $subelement =
'commande';
2088 if ($element ==
'propal') {
2089 $element =
'comm/propal';
2090 $subelement =
'propal';
2092 if ($element ==
'contract') {
2093 $element = $subelement =
'contrat';
2095 if ($element ==
'order_supplier') {
2097 $subelement =
'fournisseur.commande';
2100 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
2101 $classname = ucfirst($subelement);
2102 if ($classname ==
'Fournisseur.commande') {
2103 $classname =
'CommandeFournisseur';
2105 $objectsrc =
new $classname($db);
2106 $objectsrc->fetch($originid);
2107 $objectsrc->fetch_thirdparty();
2109 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
2111 $soc = $objectsrc->thirdparty;
2113 $cond_reglement_id = 0;
2114 $mode_reglement_id = 0;
2118 $transport_mode_id = 0;
2121 if (!empty($objectsrc->cond_reglement_id)) {
2122 $cond_reglement_id = $objectsrc->cond_reglement_id;
2124 if (!empty($objectsrc->mode_reglement_id)) {
2125 $mode_reglement_id = $objectsrc->mode_reglement_id;
2127 if (!empty($objectsrc->fk_account)) {
2128 $fk_account = $objectsrc->fk_account;
2130 if (!empty($objectsrc->transport_mode_id)) {
2131 $transport_mode_id = $objectsrc->transport_mode_id;
2134 if (empty($cond_reglement_id)
2135 || empty($mode_reglement_id)
2136 || empty($fk_account)
2137 || empty($transport_mode_id)
2139 if ($origin ==
'reception') {
2141 if (!isset($objectsrc->supplier_order)) {
2142 $objectsrc->fetch_origin();
2145 if (!empty($objectsrc->commandeFournisseur)) {
2146 $supplierOrder = $objectsrc->commandeFournisseur;
2147 if (empty($cond_reglement_id) && !empty($supplierOrder->cond_reglement_id)) {
2148 $cond_reglement_id = $supplierOrder->cond_reglement_id;
2150 if (empty($mode_reglement_id) && !empty($supplierOrder->mode_reglement_id)) {
2151 $mode_reglement_id = $supplierOrder->mode_reglement_id;
2153 if (empty($fk_account) && !empty($supplierOrder->fk_account)) {
2154 $fk_account = $supplierOrder->fk_account;
2156 if (empty($transport_mode_id) && !empty($supplierOrder->transport_mode_id)) {
2157 $transport_mode_id = $supplierOrder->transport_mode_id;
2164 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
2165 $cond_reglement_id = $soc->cond_reglement_supplier_id;
2167 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
2168 $mode_reglement_id = $soc->mode_reglement_supplier_id;
2170 if (empty($fk_account) && !empty($soc->fk_account)) {
2171 $fk_account = $soc->fk_account;
2173 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
2174 $transport_mode_id = $soc->transport_mode_id;
2179 if (isModEnabled(
"multicurrency")) {
2180 if (!empty($objectsrc->multicurrency_code)) {
2181 $currency_code = $objectsrc->multicurrency_code;
2183 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
2184 $currency_tx = $objectsrc->multicurrency_tx;
2189 $dateinvoice = ($datetmp ==
'' ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $datetmp);
2191 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2194 $objectsrc->fetch_optionals();
2195 $object->array_options = $objectsrc->array_options;
2197 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2198 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2199 $vat_reverse_charge = (empty($societe) ?
'' : $societe->vat_reverse_charge);
2200 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2201 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2203 $dateinvoice = ($datetmp ==
'' ? (
getDolGlobalInt(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datetmp);
2205 $datedue = ($datetmp ==
'' ? -1 : $datetmp);
2207 if (isModEnabled(
"multicurrency") && !empty($soc->multicurrency_code)) {
2208 $currency_code = $soc->multicurrency_code;
2213 if (empty($cond_reglement_id)) {
2214 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2218 if (empty($mode_reglement_id)) {
2219 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2223 if (!
GETPOST(
'changecompany')) {
2224 if (GETPOSTISSET(
'cond_reglement_id')) {
2225 $cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
2227 if (GETPOSTISSET(
'mode_reglement_id')) {
2228 $mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
2230 if (GETPOSTISSET(
'cond_reglement_id')) {
2231 $fk_account =
GETPOST(
'fk_account',
'int');
2235 $note_public = $object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
2236 $note_private = $object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
2238 if ($origin ==
'contrat') {
2239 $langs->load(
"admin");
2240 $text = $langs->trans(
"ToCreateARecurringInvoice");
2241 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"SupplierBills"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
2243 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
2245 print
info_admin($text, 0, 0, 0,
'opacitymedium').
'<br>';
2248 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2249 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2250 print
'<input type="hidden" name="action" value="add">';
2251 print
'<input type="hidden" name="changecompany" value="0">';
2253 if (!empty($societe->id) && $societe->id > 0) {
2254 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2256 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2257 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2258 if (!empty($currency_tx)) {
2259 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2261 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2266 $parameters = array();
2268 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierInvoice', $parameters, $object, $action);
2269 if (empty($reshook)) {
2270 print
'<table class="border centpercent">';
2273 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
2277 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2278 $invoice_predefined->fetch($fac_recid);
2282 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2285 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2286 $absolute_discount = $societe->getAvailableDiscounts(
'',
'', 0, 1);
2287 print $societe->getNomUrl(1,
'supplier');
2288 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2290 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2291 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');
2294 print
'<script type="text/javascript">
2295 $(document).ready(function() {
2296 $("#socid").change(function() {
2297 console.log("We have changed the company - Reload page");
2299 $("input[name=action]").val("create");
2300 $("input[name=changecompany]").val("1");
2301 $("form[name=add]").submit();
2306 if ($fac_recid <= 0) {
2307 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>';
2313 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2314 $invoice_predefined->fetch($fac_recid);
2316 $dateinvoice = $invoice_predefined->date_when;
2317 if (empty($projectid)) {
2318 $projectid = $invoice_predefined->fk_project;
2320 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2321 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2322 $fk_account = $invoice_predefined->fk_account;
2323 $note_public = $invoice_predefined->note_public;
2324 $note_private = $invoice_predefined->note_private;
2326 if (!empty($invoice_predefined->multicurrency_code)) {
2327 $currency_code = $invoice_predefined->multicurrency_code;
2329 if (!empty($invoice_predefined->multicurrency_tx)) {
2330 $currency_tx = $invoice_predefined->multicurrency_tx;
2333 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2334 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2335 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2337 $resql = $db->query($sql);
2339 $num = $db->num_rows($resql);
2343 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2345 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2346 print
'<option value="0" selected></option>';
2348 $objp = $db->fetch_object($resql);
2349 print
'<option value="'.$objp->rowid.
'"';
2350 if ($fac_recid == $objp->rowid) {
2352 $exampletemplateinvoice->fetch($fac_recid);
2354 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2360 print
'<script type="text/javascript">
2361 $(document).ready(function() {
2362 $("#fac_rec").change(function() {
2363 console.log("We have changed the template invoice - Reload page");
2365 $("input[name=action]").val("create");
2366 $("form[name=add]").submit();
2380 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"';
2381 if (!empty($societe->id) && $societe->id > 0) {
2387 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2389 print
'<div class="tagtable">'.
"\n";
2392 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2393 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOST(
'type',
'int') ?
'' :
'checked').
'> ';
2394 $desc = $form->textwithpicto($tmp.
'<label for="radio_standard">'.$langs->trans(
"InvoiceStandardAsk").
'</label>', $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2396 print
'</div></div>';
2398 if (empty($origin) || ($origin ==
'order_supplier' && !empty($originid))) {
2401 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2402 $tmp=
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOST(
'type') == 3 ?
' checked' :
'') .
'> ';
2403 print
'<script type="text/javascript">
2404 jQuery(document).ready(function() {
2405 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2406 jQuery("#radio_standard").prop("checked", true);
2408 jQuery("#typedeposit, #valuedeposit").click(function() {
2409 jQuery("#radio_deposit").prop("checked", true);
2411 jQuery("#typedeposit").change(function() {
2412 console.log("We change type of down payment");
2413 jQuery("#radio_deposit").prop("checked", true);
2414 setRadioForTypeOfInvoice();
2416 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2417 setRadioForTypeOfInvoice();
2419 function setRadioForTypeOfInvoice() {
2420 console.log("Change radio");
2421 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2422 jQuery(".checkforselect").prop("disabled", true);
2423 jQuery(".checkforselect").prop("checked", false);
2425 jQuery(".checkforselect").prop("disabled", false);
2426 jQuery(".checkforselect").prop("checked", true);
2432 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2433 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2434 print
'<table class="nobordernopadding"><tr>';
2438 if ($origin ==
'order_supplier') {
2439 print
'<td class="nowrap" style="padding-left: 15px">';
2441 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2442 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2443 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2445 print $form->selectarray(
'typedeposit', $arraylist,
GETPOST(
'typedeposit',
'aZ09'), 0, 0, 0,
'', 1);
2447 print
'<td class="nowrap" style="padding-left: 5px">';
2448 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' .
GETPOST(
'valuedeposit',
'int') .
'"/>';
2451 print
'</tr></table>';
2453 print
'</div></div>';
2522 if (empty($origin)) {
2523 if (!empty($societe->id) && $societe->id > 0) {
2527 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2534 foreach ($facids as $key => $valarray) {
2535 $newinvoice_static->id = $key;
2536 $newinvoice_static->ref = $valarray [
'ref'];
2537 $newinvoice_static->statut = $valarray [
'status'];
2538 $newinvoice_static->type = $valarray [
'type'];
2539 $newinvoice_static->paye = $valarray [
'paye'];
2541 $optionsav .=
'<option value="'.$key.
'"';
2542 if ($key ==
GETPOST(
'fac_avoir',
'int')) {
2543 $optionsav .=
' selected';
2546 $optionsav .= $newinvoice_static->ref;
2547 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
2548 $optionsav .=
'</option>';
2551 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2552 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
2554 $tmp .=
' disabled';
2558 print
'<script type="text/javascript">
2559 jQuery(document).ready(function() {
2560 if (! jQuery("#radio_creditnote").is(":checked"))
2562 jQuery("#credit_note_options").hide();
2564 jQuery("#radio_creditnote").click(function() {
2565 jQuery("#credit_note_options").show();
2567 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2568 jQuery("#credit_note_options").hide();
2572 $text = $tmp.
'<label for="radio_creditnote">'.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
2574 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2576 $text .=
' disabled';
2580 $text .=
'<option value="-1"></option>';
2581 $text .= $optionsav;
2583 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
2585 $text .=
'</select>';
2586 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2589 print
'<div id="credit_note_options" class="clearboth">';
2590 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' :
'').
' /> ';
2591 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
2592 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' :
'').
' /> ';
2593 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
2596 print
'</div></div>';
2599 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2601 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2603 $tmp=
'<input type="radio" name="type" id="radio_creditnote" value="2"> ';
2605 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
2606 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
2607 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2609 print
'</div></div>'.
"\n";
2620 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
2621 print $form->getSelectInvoiceSubtype(
GETPOST(
'subtype'),
'subtype', 1, 0,
'');
2625 if (!empty($societe->id) && $societe->id > 0) {
2627 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2629 $thirdparty = $societe;
2631 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2632 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2638 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth200" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
2641 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
2642 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2643 print $form->selectDate($dateinvoice,
'',
'',
'',
'',
"add", 1, 1);
2647 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2648 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
2649 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1);
2654 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
2655 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2656 print $form->selectDate($datedue,
'ech',
'',
'',
'',
"add", 1, 1);
2660 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2661 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2662 $form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'DBIT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
2666 if (isModEnabled(
"banque")) {
2667 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2669 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
2674 if (isModEnabled(
'project')) {
2677 $langs->load(
'projects');
2678 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2679 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');
2680 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>';
2685 if (isModEnabled(
'incoterm')) {
2687 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
2688 print
'<td colspan="3" class="maxwidthonsmartphone">';
2689 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2690 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 :
''));
2696 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
2697 print
'<tr><td>' . $langs->trans(
'VATReverseCharge') .
'</td><td>';
2699 if (GETPOSTISSET(
'vat_reverse_charge')) {
2700 $vat_reverse_charge = (
GETPOST(
'vat_reverse_charge',
'alpha') ==
'on' ||
GETPOST(
'vat_reverse_charge',
'alpha') ==
'1') ? 1 : 0;
2701 } elseif ($vat_reverse_charge == 1 || $societe->vat_reverse_charge == 1 || ($societe->country_code !=
'FR' &&
isInEEC($societe) && !empty($societe->tva_intra))) {
2702 $vat_reverse_charge = 1;
2704 $vat_reverse_charge = 0;
2707 print
'<input type="checkbox" name="vat_reverse_charge"'. (!empty($vat_reverse_charge) ?
' checked ' :
'') .
'>';
2712 if (isModEnabled(
"multicurrency")) {
2714 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
2715 print
'<td class="maxwidthonsmartphone">';
2716 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
2717 $used_currency_code = $currency_code;
2718 if (!
GETPOST(
'changecompany')) {
2719 $used_currency_code = GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code;
2721 print $form->selectMultiCurrency($used_currency_code,
'multicurrency_code');
2727 if ($fac_recid > 0) {
2728 $dateexample = $dateinvoice;
2729 if (empty($dateexample)) {
2732 $substitutionarray = array(
2733 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
2734 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
2735 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
2736 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
2737 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
2738 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
2739 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
2740 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
2741 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
2742 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
2743 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
2746 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
2747 foreach ($substitutionarray as $key => $val) {
2748 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
2750 $htmltext .=
'</i>';
2754 if (isModEnabled(
'intracommreport')) {
2755 $langs->loadLangs(array(
"intracommreport"));
2756 print
'<!-- If module intracomm on -->'.
"\n";
2757 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
2758 $form->selectTransportMode(GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
2762 if (empty($reshook)) {
2763 print $object->showOptionals($extrafields,
'create');
2767 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2769 $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%');
2770 print $doleditor->Create(1);
2776 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
2778 $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%');
2779 print $doleditor->Create(1);
2785 if (!empty($objectsrc) && is_object($objectsrc)) {
2786 print
"\n<!-- ".$classname.
" info -->";
2788 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2789 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2790 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2791 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2792 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2794 $txt = $langs->trans($classname);
2795 if ($classname ==
'CommandeFournisseur') {
2796 $langs->load(
'orders');
2797 $txt = $langs->trans(
"SupplierOrder");
2799 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
2801 $objectsrc->fetchObjectLinked($originid, $origin,
'',
'invoice_supplier');
2803 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
2806 if (is_array($invoice_supplier)) {
2807 $cntinvoice = count($invoice_supplier);
2809 if ($cntinvoice >= 1) {
2811 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
2816 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2817 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2818 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2819 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2822 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2823 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2825 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2827 if (isModEnabled(
"multicurrency")) {
2828 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2829 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2830 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2835 $parameters = array();
2836 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
2837 print $hookmanager->resPrint;
2845 print $form->buttonsSaveCancel(
"CreateDraft");
2848 if (!empty($objectsrc) && is_object($objectsrc)) {
2851 $title = $langs->trans(
'ProductsAndServices');
2854 print
'<div class="div-table-responsive-no-min">';
2855 print
'<table class="noborder centpercent">';
2857 $objectsrc->printOriginLinesList(
'', $selectedLines);
2865 if ($id > 0 || !empty($ref)) {
2871 $productstatic =
new Product($db);
2873 $result = $object->fetch($id, $ref);
2875 $langs->load(
"errors");
2876 print $langs->trans(
"ErrorRecordNotFound");
2882 $result = $object->fetch_thirdparty();
2888 $societe = $object->thirdparty;
2890 $totalpaid = $object->getSommePaiement();
2891 $totalcreditnotes = $object->getSumCreditNotesUsed();
2892 $totaldeposits = $object->getSumDepositsUsed();
2900 $resteapayer =
price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
2903 $multicurrency_resteapayer = 0;
2904 if (isModEnabled(
"multicurrency")) {
2905 $multicurrency_totalpaid = $object->getSommePaiement(1);
2906 $multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
2907 $multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
2908 $multicurrency_resteapayer =
price2num($object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
2912 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 && $object->multicurrency_code != $conf->currency) {
2913 $resteapayer =
price2num($multicurrency_resteapayer / $object->multicurrency_tx,
'MT');
2917 if ($object->paye) {
2920 $resteapayeraffiche = $resteapayer;
2923 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2924 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2926 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2927 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2930 $absolute_discount = $societe->getAvailableDiscounts(
'', $filterabsolutediscount, 0, 1);
2931 $absolute_creditnote = $societe->getAvailableDiscounts(
'', $filtercreditnote, 0, 1);
2932 $absolute_discount =
price2num($absolute_discount,
'MT');
2933 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2938 $objectidnext = $object->getIdReplacingInvoice();
2941 $titre = $langs->trans(
'SupplierInvoice');
2943 print
dol_get_fiche_head($head,
'card', $titre, -1,
'supplier_invoice', 0,
'',
'', 0,
'', 1);
2948 if ($action ==
'converttoreduc') {
2951 $type_fac =
'ExcessPaid';
2953 $type_fac =
'CreditNote';
2955 $type_fac =
'Deposit';
2957 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
2958 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
2959 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
2963 if ($action ==
'clone') {
2965 $formquestion = array(
2966 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplierBill"),
'value' => $langs->trans(
"CopyOf").
' '.$object->ref_supplier),
2967 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
2970 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
2974 if ($action ==
'valid') {
2976 if (preg_match(
'/^[\(]?PROV/i', $object->ref) || empty($object->ref)) {
2978 $numref = $object->getNextNumRef($societe);
2980 $numref = $object->ref;
2987 $text = $langs->trans(
'ConfirmValidateBill', $numref);
2995 $formquestion = array();
2997 $qualified_for_stock_change = 0;
2999 $qualified_for_stock_change = $object->hasProductsOrServices(2);
3001 $qualified_for_stock_change = $object->hasProductsOrServices(1);
3004 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
3005 $langs->load(
"stocks");
3006 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3009 $warehouse_array = $warehouse->list_array();
3010 if (count($warehouse_array) == 1) {
3011 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
3012 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3015 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3017 $formquestion = array(
3018 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3022 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
3027 if ($action ==
'edit') {
3028 $formquestion = array();
3030 $qualified_for_stock_change = 0;
3032 $qualified_for_stock_change = $object->hasProductsOrServices(2);
3034 $qualified_for_stock_change = $object->hasProductsOrServices(1);
3036 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
3037 $langs->load(
"stocks");
3038 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3041 $warehouse_array = $warehouse->list_array();
3042 if (count($warehouse_array) == 1) {
3043 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
3044 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3047 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3049 $formquestion = array(
3050 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
3053 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill', $object->ref),
'confirm_edit', $formquestion, 1, 1);
3057 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer == $object->total_ttc))) {
3058 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill', $object->ref),
'confirm_paid',
'', 0, 1);
3061 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer != $object->total_ttc)) {
3065 $close[$i][
'code'] =
'discount_vat';
3067 $close[$i][
'code'] =
'badsupplier';
3069 $close[$i][
'code'] =
'other';
3073 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
3075 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3077 $close[$i][
'label'] = $langs->trans(
"Other");
3081 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3083 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3085 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
3088 foreach ($close as $key => $val) {
3089 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
3093 $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'));
3095 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially', $object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
3099 if ($action ==
'canceled') {
3101 $close[1][
'code'] =
'badsupplier';
3102 $close[2][
'code'] =
'abandon';
3104 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3105 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
3107 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier", $object->ref), $close[1][
'label'], 1);
3108 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
3110 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
3111 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
3114 $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'));
3116 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill', $object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 250);
3120 if ($action ==
'delete') {
3121 $formquestion = array();
3123 $qualified_for_stock_change = 0;
3125 $qualified_for_stock_change = $object->hasProductsOrServices(2);
3127 $qualified_for_stock_change = $object->hasProductsOrServices(1);
3130 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) {
3131 $langs->load(
"stocks");
3132 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3135 $warehouse_array = $warehouse->list_array();
3137 $selectwarehouse =
'<span class="questionrevertstock hidden">';
3138 if (count($warehouse_array) == 1) {
3139 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
3140 $selectwarehouse .=
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3143 $selectwarehouse .= $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3145 $selectwarehouse .=
'</span>';
3147 $selectyesno = array(0 => $langs->trans(
'No'), 1 => $langs->trans(
'Yes'));
3149 print
'<script type="text/javascript">
3150 $(document).ready(function() {
3151 $("#revertstock").change(function() {
3152 if(this.value > 0) {
3153 $(".questionrevertstock").removeClass("hidden");
3155 $(".questionrevertstock").addClass("hidden");
3161 $formquestion = array(
3162 array(
'type' =>
'select',
'name' =>
'revertstock',
'label' => $langs->trans(
"RevertProductsToStock"),
'select_show_empty' => 0,
'values' => $selectyesno),
3163 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $selectwarehouse,
'tdclass' =>
'questionrevertstock hidden')
3167 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete', $formquestion, 1, 1);
3169 if ($action ==
'deletepayment') {
3170 $payment_id =
GETPOST(
'paiement_id');
3171 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
3175 if ($action ==
'ask_deleteline') {
3176 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
3179 $parameters = array(
'formConfirm' => $formconfirm,
'lineid'=>$lineid);
3180 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
3181 if (empty($reshook)) {
3182 $formconfirm .= $hookmanager->resPrint;
3183 } elseif ($reshook > 0) {
3184 $formconfirm = $hookmanager->resPrint;
3192 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
3194 $morehtmlref =
'<div class="refidno">';
3196 $morehtmlref .= $form->editfieldkey(
"RefSupplierBill",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'', 0, 1);
3197 $morehtmlref .= $form->editfieldval(
"RefSupplierBill",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
3199 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'supplier');
3201 $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>';
3204 if (isModEnabled(
'project')) {
3205 $langs->load(
"projects");
3206 $morehtmlref .=
'<br>';
3207 if ($permissiontoadd) {
3208 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
3209 if ($action !=
'classify') {
3210 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.newToken().
'&id='.((int) $object->id).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
3212 $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');
3214 if (!empty($object->fk_project)) {
3216 $proj->fetch($object->fk_project);
3217 $morehtmlref .= $proj->getNomUrl(1);
3219 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
3224 $morehtmlref .=
'</div>';
3226 $object->totalpaid = $totalpaid;
3228 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
3231 $parameters = array();
3233 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierInvoice', $parameters, $object, $action);
3234 if (empty($reshook)) {
3235 print
'<div class="fichecenter">';
3236 print
'<div class="fichehalfleft">';
3237 print
'<div class="underbanner clearboth"></div>';
3239 print
'<table class="border tableforfield centpercent">';
3242 print
'<tr><td class="titlefield">'.$langs->trans(
'Type').
'</td><td>';
3243 print
'<span class="badgeneutral">';
3244 print $object->getLibType();
3246 if ($object->subtype > 0) {
3247 print
' '.$object->getSubtypeLabel(
'facture_fourn');
3251 $facreplaced->fetch($object->fk_facture_source);
3252 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
3255 if ($object->fk_facture_source > 0) {
3257 $facusing->fetch($object->fk_facture_source);
3258 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
3260 $langs->load(
"errors");
3261 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"WarningCorrectedInvoiceNotFound").
'</span>';
3265 $facidavoir = $object->getListIdAvoirFromInvoice();
3266 if (count($facidavoir) > 0) {
3267 $invoicecredits = array();
3268 foreach ($facidavoir as $id) {
3270 $facavoir->fetch($id);
3271 $invoicecredits[] = $facavoir->getNomUrl(1);
3273 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
3276 if (isset($objectidnext) && $objectidnext > 0) {
3279 $facthatreplace->fetch($objectidnext);
3280 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
3284 $result = $discount->fetch(0, 0, $object->id);
3286 print
' <span class="opacitymediumbycolor paddingleft">';
3287 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
3288 $s = str_replace(
'{s1}', $object->getLibType(1), $s);
3289 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
3291 print
'</span><br>';
3295 if ($object->fk_fac_rec_source > 0) {
3297 $result = $tmptemplate->fetch($object->fk_fac_rec_source);
3299 print
' <span class="opacitymediumbycolor paddingleft">';
3300 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->title).
'</a>';
3301 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
3311 print
'<!-- Discounts -->'.
"\n";
3312 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
3315 $thirdparty = $societe;
3317 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3323 print
'<td>'.$form->editfieldkey(
"Label",
'label', $object->label, $object, $usercancreate).
'</td>';
3324 print
'<td>'.$form->editfieldval(
"Label",
'label', $object->label, $object, $usercancreate).
'</td>';
3332 print $form->editfieldkey(
"DateInvoice",
'datef', $object->date, $object, $form_permission,
'datepicker');
3333 print
'</td><td colspan="3">';
3334 print $form->editfieldval(
"Date",
'datef', $object->date, $object, $form_permission,
'datepicker');
3338 $langs->load(
'bills');
3339 print
'<tr><td class="nowrap">';
3340 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3341 print $langs->trans(
'PaymentConditions');
3343 if ($action !=
'editconditions' && $form_permission) {
3344 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>';
3346 print
'</tr></table>';
3348 if ($action ==
'editconditions') {
3349 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
3351 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none');
3358 print $form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', $object->date_echeance, $object, $form_permission,
'datepicker');
3360 print $form->editfieldval(
"DateMaxPayment",
'date_lim_reglement', $object->date_echeance, $object, $form_permission,
'datepicker');
3361 if ($action !=
'editdate_lim_reglement' && $object->hasDelay()) {
3367 $langs->load(
'bills');
3368 print
'<tr><td class="nowrap">';
3369 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3370 print $langs->trans(
'PaymentMode');
3372 if ($action !=
'editmode' && $form_permission) {
3373 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>';
3375 print
'</tr></table>';
3377 if ($action ==
'editmode') {
3378 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3380 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
3385 if (isModEnabled(
"multicurrency")) {
3389 print
'<table class="nobordernopadding" width="100%"><tr><td>';
3390 print $form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
3392 if ($action !=
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT) {
3393 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>';
3395 print
'</tr></table>';
3397 if ($action ==
'editmulticurrencycode') {
3398 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
3400 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
3405 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3408 print
'<table class="nobordernopadding centpercent"><tr><td>';
3409 print $form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
3411 if ($action !=
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3412 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>';
3414 print
'</tr></table>';
3416 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
3417 if ($action ==
'actualizemulticurrencyrate') {
3420 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
3422 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
3423 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3424 print
'<div class="inline-block"> ';
3425 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
3434 if (isModEnabled(
"banque")) {
3435 print
'<tr><td class="nowrap">';
3436 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3437 print $langs->trans(
'BankAccount');
3439 if ($action !=
'editbankaccount' && $usercancreate) {
3440 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>';
3442 print
'</tr></table>';
3444 if ($action ==
'editbankaccount') {
3445 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
3447 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
3455 print
'<tr><td class="nowrap">';
3456 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3457 print $langs->trans(
'VATReverseCharge');
3459 if ($action !=
'editvatreversecharge' && $usercancreate) {
3460 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editvatreversecharge&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetVATReverseCharge'), 1).
'</a></td>';
3462 print
'</tr></table>';
3464 if ($action ==
'editvatreversecharge') {
3465 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
3466 print
'<input type="hidden" name="action" value="setvatreversecharge">';
3467 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3469 print
'<input type="checkbox" name="vat_reverse_charge"' . ($object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
'>';
3471 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
3474 print
'<input type="checkbox" name="vat_reverse_charge"'. ($object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
' disabled>';
3480 if (isModEnabled(
'incoterm')) {
3482 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3483 print $langs->trans(
'IncotermLabel');
3484 print
'<td><td class="right">';
3485 if ($usercancreate) {
3486 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$object->id.
'&action=editincoterm&token='.newToken().
'">'.
img_edit().
'</a>';
3490 print
'</td></tr></table>';
3493 if ($action !=
'editincoterm') {
3494 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
3496 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
3502 if (isModEnabled(
'intracommreport')) {
3503 $langs->loadLangs(array(
"intracommreport"));
3504 print
'<!-- If module intracomm on -->'.
"\n";
3506 print
'<table class="nobordernopadding centpercent"><tr><td>';
3507 print $langs->trans(
'IntracommReportTransportMode');
3509 if ($action !=
'edittransportmode' && ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"))) {
3510 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edittransportmode&token='.newToken().
'&id='.$object->id.
'">'.
img_edit().
'</a></td>';
3512 print
'</tr></table>';
3515 if ($action ==
'edittransportmode') {
3516 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->transport_mode_id,
'transport_mode_id', 1, 1);
3518 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->transport_mode_id,
'none');
3525 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
3530 print
'<div class="fichehalfright">';
3531 print
'<div class="underbanner clearboth"></div>';
3533 print
'<table class="border tableforfield centpercent">';
3536 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
3537 print
'<td class="nowrap amountcard right">' .
price($object->total_ht,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
3538 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
3539 print
'<td class="nowrap amountcard right">' .
price($object->multicurrency_total_ht,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
3544 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
3545 print
'<td class="nowrap amountcard right">';
3546 if (
GETPOST(
'calculationrule')) {
3547 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
3549 $calculationrule = (!
getDolGlobalString(
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND') ?
'totalofround' :
'roundoftotal');
3551 if ($calculationrule ==
'totalofround') {
3552 $calculationrulenum = 1;
3554 $calculationrulenum = 2;
3557 if ($object->getVentilExportCompta() == 0) {
3558 $s =
'<span class="hideonsmartphone opacitymedium">' . $langs->trans(
"ReCalculate") .
' </span>';
3559 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'&action=calculate&calculationrule=totalofround">' . $langs->trans(
"Mode1") .
'</a>';
3561 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'&action=calculate&calculationrule=roundoftotal">' . $langs->trans(
"Mode2") .
'</a>';
3562 print
'<div class="inline-block">';
3563 print $form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum) .
'<br>' . $langs->trans(
"CalculationRuleDescSupplier"), 2, 1,
img_picto(
'',
'help'),
'', 3,
'', 0,
'recalculate');
3564 print
' ';
3567 print
price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency);
3569 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
3570 print
'<td class="nowrap amountcard right">' .
price($object->multicurrency_total_tva,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
3574 if ($societe->localtax1_assuj ==
"1") {
3576 print
'<td>' . $langs->transcountry(
"AmountLT1", $societe->country_code) .
'</td>';
3577 print
'<td class="nowrap amountcard right">' .
price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency) .
'</td>';
3580 if ($societe->localtax2_assuj ==
"1") {
3582 print
'<td>' . $langs->transcountry(
"AmountLT2", $societe->country_code) .
'</td>';
3583 print
'<td class="nowrap amountcard right">' .
price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency) .
'</td>';
3588 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
3589 print
'<td class="nowrap amountcard right">' .
price($object->total_ttc,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
3590 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
3591 print
'<td class="nowrap amountcard right">' .
price($object->multicurrency_total_ttc,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
3609 if (isModEnabled(
'project')) {
3612 if (isModEnabled(
"banque")) {
3616 if (isModEnabled(
'incoterm')) {
3619 if (isModEnabled(
"multicurrency")) {
3624 if ($societe->localtax1_assuj ==
"1") {
3627 if ($societe->localtax2_assuj ==
"1") {
3631 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
3632 $sql .=
' c.id as payment_type, c.code as payment_code,';
3633 $sql .=
' pf.amount,';
3634 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
3635 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
3636 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
3637 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
3638 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
3639 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
3640 $sql .=
' WHERE pf.fk_facturefourn = '.((int) $object->id);
3641 $sql .=
' ORDER BY p.datep, p.tms';
3643 $result = $db->query($sql);
3645 $num = $db->num_rows($result);
3648 print
'<div class="div-table-responsive-no-min">';
3649 print
'<table class="noborder paymenttable centpercent">';
3650 print
'<tr class="liste_titre">';
3652 print
'<td>'.$langs->trans(
'Date').
'</td>';
3653 print
'<td>'.$langs->trans(
'Type').
'</td>';
3654 if (isModEnabled(
"banque")) {
3655 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
3657 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
3658 print
'<td width="18"> </td>';
3663 $objp = $db->fetch_object($result);
3665 $paymentstatic->id = $objp->rowid;
3666 $paymentstatic->datepaye = $db->jdate($objp->dp);
3667 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
3668 $paymentstatic->num_payment = $objp->num_payment;
3670 $paymentstatic->paiementcode = $objp->payment_code;
3671 $paymentstatic->type_code = $objp->payment_code;
3672 $paymentstatic->type_label = $objp->payment_type;
3674 print
'<tr class="oddeven">';
3675 print
'<td class="nowraponall">';
3676 print $paymentstatic->getNomUrl(1);
3678 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
'</td>';
3679 $s = $form->form_modes_reglement(
null, $objp->payment_type,
'none',
'', 1, 0,
'', 1).
' '.$objp->num_payment;
3680 print
'<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).
'">';
3683 if (isModEnabled(
"banque")) {
3684 $bankaccountstatic->id = $objp->baid;
3685 $bankaccountstatic->ref = $objp->baref;
3686 $bankaccountstatic->label = $objp->baref;
3687 $bankaccountstatic->number = $objp->banumber;
3689 if (isModEnabled(
'accounting')) {
3690 $bankaccountstatic->account_number = $objp->account_number;
3693 $accountingjournal->fetch($objp->fk_accountancy_journal);
3694 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
3697 print
'<td class="right">';
3698 if ($objp->baid > 0) {
3699 print $bankaccountstatic->getNomUrl(1,
'transactions');
3703 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
3704 print
'<td class="center">';
3706 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=deletepayment&token='.newToken().
'&paiement_id='.$objp->rowid.
'">';
3712 $totalpaid += $objp->amount;
3716 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td><td></td><td></td></tr>';
3739 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3740 print
'<span class="opacitymedium">';
3742 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
3744 print $langs->trans(
'AlreadyPaid');
3747 print
'</td><td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td><td> </td></tr>';
3750 $resteapayeraffiche = $resteapayer;
3752 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
3755 $creditnoteamount = 0;
3758 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
3759 $sql .=
" re.description, re.fk_invoice_supplier_source";
3760 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
3761 $sql .=
" WHERE fk_invoice_supplier = ".((int) $object->id);
3762 $resql = $db->query($sql);
3764 $num = $db->num_rows($resql);
3768 $obj = $db->fetch_object($resql);
3769 $invoice->fetch($obj->fk_invoice_supplier_source);
3770 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3772 print $langs->trans(
"CreditNote").
' ';
3775 print $langs->trans(
"Deposit").
' ';
3777 print $invoice->getNomUrl(0);
3779 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
3780 print
'<td class="right">';
3781 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=unlinkdiscount&discountid='.$obj->rowid.
'">';
3782 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
3787 $creditnoteamount += $obj->amount_ttc;
3790 $depositamount += $obj->amount_ttc;
3799 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3800 print
'<span class="opacitymedium">';
3801 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
3803 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3804 $resteapayeraffiche = 0;
3805 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3809 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3810 print
'<span class="opacitymedium">';
3811 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
3813 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3815 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3819 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3820 print
'<span class="opacitymedium">';
3821 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
3823 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3824 $resteapayeraffiche = 0;
3825 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3829 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3830 $text = $langs->trans(
"HelpAbandonOther");
3831 if ($object->close_note) {
3832 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.$object->close_note;
3834 print
'<span class="opacitymedium">';
3835 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
3837 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3838 $resteapayeraffiche = 0;
3839 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3843 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3844 print
'<span class="opacitymedium">';
3845 print $langs->trans(
"Billed");
3847 print
'</td><td class="right">'.price($object->total_ttc).
'</td><td> </td></tr>';
3850 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3851 print
'<span class="opacitymedium">';
3852 print $langs->trans(
'RemainderToPay');
3853 if ($resteapayeraffiche < 0) {
3854 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3858 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
3861 if (isModEnabled(
'multicurrency') && $object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3862 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3863 print
'<span class="opacitymedium">';
3864 print $langs->trans(
'RemainderToPayMulticurrency');
3865 if ($resteapayeraffiche < 0) {
3866 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3870 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>';
3873 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3876 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3877 print $langs->trans(
'AlreadyPaidBack');
3878 print
' :</td><td class="right">'.price($sign * $totalpaid).
'</td><td> </td></tr>';
3881 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"Billed").
' :</td><td class="right">'.
price($sign * $object->total_ttc).
'</td><td> </td></tr>';
3884 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3885 print
'<span class="opacitymedium">';
3886 print $langs->trans(
'RemainderToPayBack');
3887 if ($resteapayeraffiche > 0) {
3888 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3892 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td><td> </td></tr>';
3895 if (isModEnabled(
'multicurrency') && $object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3896 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3897 print
'<span class="opacitymedium">';
3898 print $langs->trans(
'RemainderToPayBackMulticurrency');
3899 if ($resteapayeraffiche> 0) {
3900 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3904 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>';
3919 print
'<div class="clearboth"></div><br>';
3922 $blocname =
'contacts';
3923 $title = $langs->trans(
'ContactsAddresses');
3924 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3929 $blocname =
'notes';
3930 $title = $langs->trans(
'Notes');
3931 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3938 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
3939 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3940 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
3941 print
'<input type="hidden" name="mode" value="">';
3942 print
'<input type="hidden" name="page_y" value="">';
3943 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
3944 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
3945 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3948 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
3951 print
'<div class="div-table-responsive-no-min">';
3952 print
'<table id="tablelines" class="noborder noshadow centpercent">';
3954 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
3957 $inputalsopricewithtax = 1;
3958 $senderissupplier = 2;
3961 $senderissupplier = 1;
3965 if (!empty($object->lines)) {
3966 $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
3969 $num = count($object->lines);
3973 if ($action !=
'editline') {
3976 $parameters = array();
3977 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
3981 if (empty($reshook)) {
3982 $object->formAddObjectLine(1, $societe, $mysoc);
3995 if ($action !=
'presend') {
4000 print
'<div class="tabsAction">';
4002 $parameters = array();
4003 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
4005 if (empty($reshook)) {
4009 $ventilExportCompta = $object->getVentilExportCompta();
4011 if ($ventilExportCompta == 0) {
4012 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=edit&token='.newToken().
'">'.$langs->trans(
'Modify').
'</a>';
4014 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
4019 $result = $discount->fetch(0, 0, $object->id);
4026 if (!$objectidnext && $object->close_code !=
'replaced' && $usercancreate) {
4027 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=reopen&token='.newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
4029 if ($usercancreate) {
4030 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
4032 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
4039 if (count($object->lines)) {
4040 if ($usercanvalidate) {
4041 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid"';
4042 print
'>'.$langs->trans(
'Validate').
'</a>';
4044 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
4045 print
'>'.$langs->trans(
'Validate').
'</a>';
4051 if (empty($user->socid)) {
4054 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
4056 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'SendMail').
'</span>';
4063 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>';
4070 if ($resteapayer == 0) {
4071 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
4073 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>';
4078 if ($object->type ==
FactureFournisseur::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) < 0 && $usercancreate && empty($discount->id)) {
4079 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
4083 && (
getDolGlobalString(
'SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $object->getSommePaiement() == 0)
4085 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>';
4089 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertToReduc').
'</a>';
4100 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaid').
'</a>';
4105 if ($totalpaid > 0 || $totalcreditnotes > 0) {
4107 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
4110 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
4123 if (!$objectidnext) {
4124 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>';
4129 if ($action !=
'edit' && $usercancreate) {
4130 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=clone&socid='.$object->socid.
'">'.$langs->trans(
'ToClone').
'</a>';
4135 if (!$objectidnext && count($object->lines) > 0) {
4136 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
4141 $isErasable = $object->is_erasable();
4142 if ($action !=
'confirm_edit' && ($usercandelete || ($usercancreate && $isErasable == 1))) {
4143 $enableDelete =
false;
4145 $params = (empty($conf->use_javascript_ajax) ? array() : array(
'attr' => array(
'class' =>
'reposition')));
4147 if ($isErasable == -4) {
4148 $htmltooltip = $langs->trans(
"DisabledBecausePayments");
4149 } elseif ($isErasable == -3) {
4150 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastSituationInvoice");
4151 } elseif ($isErasable == -2) {
4152 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastInvoice");
4153 } elseif ($isErasable == -1) {
4154 $htmltooltip = $langs->trans(
"DisabledBecauseDispatchedInBookkeeping");
4155 } elseif ($isErasable <= 0) {
4156 $htmltooltip = $langs->trans(
"DisabledBecauseNotErasable");
4158 $enableDelete =
true;
4161 print
dolGetButtonAction($htmltooltip, $langs->trans(
"Delete"),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.newToken(), $object->id, $enableDelete, $params);
4165 if ($action !=
'confirm_edit') {
4166 print
'<div class="fichecenter"><div class="fichehalfleft">';
4172 $subdir =
get_exdir($object->id, 2, 0, 0, $object,
'invoice_supplier').$ref;
4173 $filedir = $conf->fournisseur->facture->dir_output.
'/'.$subdir;
4174 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.$object->id;
4175 $genallowed = $usercanread;
4176 $delallowed = $usercancreate;
4177 $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (!
getDolGlobalString(
'INVOICE_SUPPLIER_ADDON_PDF') ?
'' : $conf->global->INVOICE_SUPPLIER_ADDON_PDF));
4179 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
4180 $somethingshown = $formfile->numoffiles;
4183 $linktoelem = $form->showLinkToObjectBlock($object,
null, array(
'invoice_supplier'));
4184 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
4186 print
'</div><div class="fichehalfright">';
4189 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
4191 $somethingshown =
$formactions->showactions($object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
4193 print
'</div></div>';
4199 if (
GETPOST(
'modelselected')) {
4200 $action =
'presend';
4204 $modelmail =
'invoice_supplier_send';
4205 $defaulttopic =
'SendBillRef';
4206 $diroutput = $conf->fournisseur->facture->dir_output;
4207 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
4208 $trackid =
'sinv'.$object->id;
4210 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.