37require
'../../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_invoice/modules_facturefournisseur.php';
41require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture-rec.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
49if (isModEnabled(
"product")) {
50 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
51 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
53if (isModEnabled(
'project')) {
54 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
55 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
58if (isModEnabled(
'variants')) {
59 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
61if (isModEnabled(
'accounting')) {
62 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
66$langs->loadLangs(array(
'bills',
'compta',
'suppliers',
'companies',
'products',
'banks',
'admin'));
67if (isModEnabled(
'incoterm')) {
68 $langs->load(
'incoterm');
73$action =
GETPOST(
'action',
'aZ09');
76$cancel =
GETPOST(
'cancel',
'alpha');
77$backtopage =
GETPOST(
'backtopage',
'alpha');
78$backtopageforcancel =
'';
80$lineid =
GETPOST(
'lineid',
'int');
81$projectid =
GETPOST(
'projectid',
'int');
82$origin =
GETPOST(
'origin',
'alpha');
83$originid =
GETPOST(
'originid',
'int');
84$fac_recid =
GETPOST(
'fac_rec',
'int');
88$hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
89$hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
90$hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
93$hookmanager->initHooks(array(
'invoicesuppliercard',
'globalcard'));
99$extrafields->fetch_name_optionals_label($object->table_element);
102if ($id > 0 || !empty($ref)) {
103 $ret = $object->fetch($id, $ref);
107 $ret = $object->fetch_thirdparty();
114$socid =
GETPOST(
'socid',
'int');
115if (!empty($user->socid)) {
116 $socid = $user->socid;
120$result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture',
'fk_soc',
'rowid', $isdraft);
123$usercanread = ($user->hasRight(
"fournisseur",
"facture",
"lire") || $user->hasRight(
"supplier_invoice",
"lire"));
124$usercancreate = ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"));
125$usercandelete = ($user->hasRight(
"fournisseur",
"facture",
"supprimer") || $user->hasRight(
"supplier_invoice",
"supprimer"));
128$usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"validate")));
129$usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->hasRight(
"fournisseur",
"supplier_invoice_advance",
"send"));
132$permissionnote = $usercancreate;
133$permissiondellink = $usercancreate;
134$permissiontoedit = $usercancreate;
135$permissiontoadd = $usercancreate;
144$parameters = array(
'socid'=>$socid);
145$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
150if (empty($reshook)) {
151 $backurlforlist = DOL_URL_ROOT.
'/fourn/facture/list.php';
153 if (empty($backtopage) || ($cancel && empty($id))) {
154 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
155 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
156 $backtopage = $backurlforlist;
158 $backtopage = DOL_URL_ROOT.
'/fourn/facture/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
164 if (!empty($backtopageforcancel)) {
165 header(
"Location: ".$backtopageforcancel);
167 } elseif (!empty($backtopage)) {
168 header(
"Location: ".$backtopage);
174 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
176 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
178 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
181 if (
GETPOST(
'linkedOrder') && empty($cancel) && $id > 0) {
183 $object->fetch_thirdparty();
184 $result = $object->add_object_linked(
'order_supplier',
GETPOST(
'linkedOrder'));
188 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
191 if (
GETPOST(
'newsupplierref',
'alphanohtml')) {
192 $objectutil->ref_supplier =
GETPOST(
'newsupplierref',
'alphanohtml');
196 $result = $objectutil->createFromClone($user, $id);
198 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
201 $langs->load(
"errors");
205 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
206 $idwarehouse =
GETPOST(
'idwarehouse');
209 $object->fetch_thirdparty();
211 $qualified_for_stock_change = 0;
212 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
213 $qualified_for_stock_change = $object->hasProductsOrServices(2);
215 $qualified_for_stock_change = $object->hasProductsOrServices(1);
219 if (isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
220 $langs->load(
"stocks");
221 if (!$idwarehouse || $idwarehouse == -1) {
223 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
231 $result = $object->validate($user,
'', $idwarehouse);
240 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
241 $outputlangs = $langs;
244 $newlang =
GETPOST(
'lang_id',
'aZ09');
247 $newlang = $object->thirdparty->default_lang;
249 if (!empty($newlang)) {
251 $outputlangs->setDefaultLang($newlang);
253 $model = $object->model_pdf;
254 $ret = $object->fetch($id);
256 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
263 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
265 $object->fetch_thirdparty();
267 $isErasable = $object->is_erasable();
269 if (($usercandelete && $isErasable > 0) || ($usercancreate && $isErasable == 1)) {
270 $result = $object->delete($user);
272 header(
'Location: list.php?restore_lastsearch_values=1');
278 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
280 $result = $object->deleteline($lineid);
283 $object->line_order(
true);
300 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
307 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
310 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
311 $discount->unlink_invoice();
312 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercancreate) {
314 $result = $object->setPaid($user);
318 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes') {
321 $close_code =
GETPOST(
"close_code",
'restricthtml');
322 $close_note =
GETPOST(
"close_note",
'restricthtml');
324 $result = $object->setPaid($user, $close_code, $close_note);
329 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
331 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes') {
334 $close_code =
GETPOST(
"close_code",
'restricthtml');
335 $close_note =
GETPOST(
"close_note",
'restricthtml');
337 $result = $object->setCanceled($user, $close_code, $close_note);
342 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
347 if ($action ==
'setref_supplier' && $usercancreate) {
348 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alpha');
350 if ($object->update($user) < 0) {
354 $outputlangs = $langs;
357 $newlang =
GETPOST(
'lang_id',
'aZ09');
360 $newlang = $object->thirdparty->default_lang;
362 if (!empty($newlang)) {
364 $outputlangs->setDefaultLang($newlang);
366 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
367 $ret = $object->fetch($object->id);
368 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
374 if ($action ==
'setconditions' && $usercancreate) {
376 $object->cond_reglement_code = 0;
377 $object->cond_reglement_id = 0;
384 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
392 $new_date_echeance = $object->calculate_date_lim_reglement();
393 if ($new_date_echeance) {
394 $object->date_echeance = $new_date_echeance;
396 if ($object->date_echeance < $object->date) {
397 $object->date_echeance = $object->date;
399 $result = $object->update($user);
411 } elseif ($action ==
'set_incoterms' && isModEnabled(
'incoterm')) {
413 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
414 } elseif ($action ==
'setmode' && $usercancreate) {
416 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
417 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
419 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
420 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
422 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx',
'alpha')),
GETPOST(
'calculation_mode',
'int'));
423 } elseif ($action ==
'setbankaccount' && $usercancreate) {
425 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
426 } elseif ($action ==
'setvatreversecharge' && $usercancreate) {
428 $vatreversecharge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
429 $result = $object->setVATReverseCharge($vatreversecharge);
432 if ($action ==
'settransportmode' && ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"))) {
434 $result = $object->setTransportMode(
GETPOST(
'transport_mode_id',
'int'));
435 } elseif ($action ==
'setlabel' && $usercancreate) {
438 $object->label =
GETPOST(
'label');
439 $result = $object->update($user);
443 } elseif ($action ==
'setdatef' && $usercancreate) {
445 if ($newdate > (
dol_now(
'tzuserrel') + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
446 if (empty($conf->global->INVOICE_MAX_FUTURE_DELAY)) {
447 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
449 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
455 $object->date = $newdate;
456 $date_echence_calc = $object->calculate_date_lim_reglement();
457 if (!empty($object->date_echeance)) {
458 $object->date_echeance = $date_echence_calc;
460 if ($object->date_echeance && $object->date_echeance < $object->date) {
461 $object->date_echeance = $object->date;
464 $result = $object->update($user);
468 } elseif ($action ==
'setdate_lim_reglement' && $usercancreate) {
470 $object->date_echeance =
dol_mktime(12, 0, 0,
GETPOST(
'date_lim_reglementmonth',
'int'),
GETPOST(
'date_lim_reglementday',
'int'),
GETPOST(
'date_lim_reglementyear',
'int'));
471 if (!empty($object->date_echeance) && $object->date_echeance < $object->date) {
472 $object->date_echeance = $object->date;
473 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
475 $result = $object->update($user);
479 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
481 if (
GETPOST(
"remise_id",
"int")) {
482 $ret = $object->fetch($id);
484 $result = $object->insert_discount(
GETPOST(
"remise_id",
"int"));
493 if (
GETPOST(
"remise_id_for_payment",
"int")) {
494 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
496 $discount->fetch(
GETPOST(
"remise_id_for_payment",
"int"));
503 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
507 $result = $discount->link_to_invoice(0, $id);
514 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
515 $outputlangs = $langs;
518 $newlang =
GETPOST(
'lang_id',
'aZ09');
521 $newlang = $object->thirdparty->default_lang;
523 if (!empty($newlang)) {
525 $outputlangs->setDefaultLang($newlang);
527 $ret = $object->fetch($id);
529 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
534 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
537 $object->fetch_thirdparty();
542 $result = $discountcheck->fetch(0, 0, $object->id);
554 $amount_ht = $amount_tva = $amount_ttc = array();
555 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
559 foreach ($object->lines as $line) {
560 if ($line->product_type < 9 && $line->total_ht != 0) {
561 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
563 $amount_ht[$keyforvatrate] += $line->total_ht;
564 $amount_tva[$keyforvatrate] += $line->total_tva;
565 $amount_ttc[$keyforvatrate] += $line->total_ttc;
566 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
567 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
568 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
575 $alreadypaid = $object->getSommePaiement();
576 if ($alreadypaid && abs($alreadypaid) < abs($object->total_ttc)) {
577 $ratio = abs(($object->total_ttc - $alreadypaid) / $object->total_ttc);
578 foreach ($amount_ht as $vatrate => $val) {
579 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
580 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
581 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
582 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
583 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
584 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
593 $discount->description =
'(CREDIT_NOTE)';
595 $discount->description =
'(DEPOSIT)';
597 $discount->description =
'(EXCESS PAID)';
599 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
601 $discount->discount_type = 1;
602 $discount->fk_soc = $object->socid;
603 $discount->fk_invoice_supplier_source = $object->id;
611 $sql =
'SELECT SUM(pf.amount) as total_paiements';
612 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'paiementfourn as p';
613 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN ('.
getEntity(
'c_paiement').
')';
614 $sql .=
' WHERE pf.fk_facturefourn = '.((int) $object->id);
615 $sql .=
' AND pf.fk_paiementfourn = p.rowid';
616 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
618 $resql = $db->query($sql);
623 $res = $db->fetch_object($resql);
624 $total_paiements = $res->total_paiements;
627 $total_creditnote_and_deposit = 0;
628 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
629 $sql .=
" re.description, re.fk_invoice_supplier_source";
630 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
631 $sql .=
" WHERE fk_invoice_supplier = ".((int) $object->id);
632 $resql = $db->query($sql);
633 if (!empty($resql)) {
634 while ($obj = $db->fetch_object($resql)) {
635 $total_creditnote_and_deposit += $obj->amount_ttc;
641 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object->total_ttc;
642 $discount->amount_tva = 0;
643 $discount->tva_tx = 0;
644 $discount->vat_src_code =
'';
646 $result = $discount->create($user);
652 foreach ($amount_ht as $tva_tx => $xxx) {
653 $discount->amount_ht = abs($amount_ht[$tva_tx]);
654 $discount->amount_tva = abs($amount_tva[$tva_tx]);
655 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
656 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
657 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
658 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
663 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
664 $vat_src_code = $reg[1];
665 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
668 $discount->tva_tx = abs($tva_tx);
669 $discount->vat_src_code = $vat_src_code;
671 $result = $discount->create($user);
682 $result = $object->setPaid($user);
697 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate) {
702 $result = $paiementfourn->fetch(
GETPOST(
'paiement_id'));
704 $result = $paiementfourn->delete();
706 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
714 } elseif ($action ==
'add' && $usercancreate) {
717 $object->socid =
GETPOST(
'socid',
'int');
719 $selectedLines =
GETPOST(
'toselect',
'array');
726 $ret = $extrafields->setOptionalsFromPost(
null, $object);
739 if (
GETPOST(
'type',
'int') ===
'') {
740 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
745 if (empty($dateinvoice)) {
746 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
748 $_GET[
'socid'] = $_POST[
'socid'];
750 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
756 if (!(
GETPOST(
'fac_replacement',
'int') > 0)) {
758 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
763 $result = $object->fetch(
GETPOST(
'fac_replacement',
'int'));
764 $object->fetch_thirdparty();
766 $object->ref =
GETPOST(
'ref',
'alphanohtml');
767 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alpha');
768 $object->socid =
GETPOST(
'socid',
'int');
769 $object->libelle =
GETPOST(
'label',
'alphanohtml');
770 $object->date = $dateinvoice;
771 $object->date_echeance = $datedue;
772 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
773 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
774 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
775 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
776 $object->fk_account =
GETPOST(
'fk_account',
'int');
777 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
778 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
779 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
780 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
781 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
782 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
783 $object->transport_mode_id =
GETPOST(
'transport_mode_id',
'int');
786 $object->fk_facture_source =
GETPOST(
'fac_replacement',
'int');
789 $id = $object->createFromCurrent($user);
799 $sourceinvoice =
GETPOST(
'fac_avoir',
'int');
800 if (!($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
802 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
804 if (
GETPOST(
'socid',
'int') < 1) {
805 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
810 if (empty($dateinvoice)) {
811 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
813 $_GET[
'socid'] = $_POST[
'socid'];
815 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
821 if (!
GETPOST(
'ref_supplier')) {
822 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplier')),
null,
'errors');
824 $_GET[
'socid'] = $_POST[
'socid'];
829 $tmpproject =
GETPOST(
'projectid',
'int');
832 $object->ref =
GETPOST(
'ref',
'alphanohtml');
833 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
834 $object->socid =
GETPOST(
'socid',
'int');
835 $object->libelle =
GETPOST(
'label',
'alphanohtml');
836 $object->label =
GETPOST(
'label',
'alphanohtml');
837 $object->date = $dateinvoice;
838 $object->date_echeance = $datedue;
839 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
840 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
841 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
842 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
843 $object->fk_account =
GETPOST(
'fk_account',
'int');
844 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
845 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
846 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
847 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
848 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
849 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
850 $object->transport_mode_id =
GETPOST(
'transport_mode_id',
'int');
853 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
856 $id = $object->create($user);
862 if (
GETPOST(
'invoiceAvoirWithLines',
'int') == 1 && $id > 0) {
864 if ($facture_source->fetch($object->fk_facture_source) > 0) {
867 foreach ($facture_source->lines as $line) {
869 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
873 $line->fk_facture_fourn = $object->id;
874 $line->fk_parent_line = $fk_parent_line;
876 $line->subprice = -$line->subprice;
877 $line->pa_ht = -$line->pa_ht;
878 $line->total_ht = -$line->total_ht;
879 $line->total_tva = -$line->total_tva;
880 $line->total_ttc = -$line->total_ttc;
881 $line->total_localtax1 = -$line->total_localtax1;
882 $line->total_localtax2 = -$line->total_localtax2;
884 $result = $line->insert();
886 $object->lines[] = $line;
889 if ($result > 0 && $line->product_type == 9) {
890 $fk_parent_line = $result;
894 $object->update_price(1);
898 if (
GETPOST(
'invoiceAvoirWithPaymentRestAmount',
'int') == 1 && $id > 0) {
900 if ($facture_source->fetch($object->fk_facture_source) > 0) {
901 $totalpaid = $facture_source->getSommePaiement();
902 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
903 $totaldeposits = $facture_source->getSumDepositsUsed();
904 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
905 $desc = $langs->trans(
'invoiceAvoirLineWithPaymentRestAmount');
906 $retAddLine = $object->addline($desc, $remain_to_pay, 0, 0, 0, 1, 0, 0,
'',
'', 0,
'',
'TTC');
908 if ($retAddLine < 0) {
916 if (empty($dateinvoice)) {
918 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
920 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
927 $object->socid =
GETPOST(
'socid',
'int');
928 $object->type =
GETPOST(
'type',
'alphanohtml');
929 $object->ref =
GETPOST(
'ref',
'alphanohtml');
930 $object->date = $dateinvoice;
931 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
932 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
933 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
934 $object->model_pdf =
GETPOST(
'model',
'alphanohtml');
935 $object->fk_project =
GETPOST(
'projectid',
'int');
936 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
937 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
938 $object->fk_account =
GETPOST(
'fk_account',
'int');
942 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
943 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
944 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
945 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
948 $object->fac_rec = $fac_recid;
950 $fac_rec->fetch($object->fac_rec);
951 $fac_rec->fetch_lines();
952 $object->lines = $fac_rec->lines;
954 $id = $object->create($user);
958 if (
GETPOST(
'socid',
'int') < 1) {
959 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
964 if (empty($dateinvoice)) {
965 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'DateInvoice')),
null,
'errors');
967 $_GET[
'socid'] = $_POST[
'socid'];
969 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
975 if (!
GETPOST(
'ref_supplier')) {
976 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'RefSupplier')),
null,
'errors');
978 $_GET[
'socid'] = $_POST[
'socid'];
983 $tmpproject =
GETPOST(
'projectid',
'int');
986 $object->socid =
GETPOST(
'socid',
'int');
987 $object->type =
GETPOST(
'type',
'alphanohtml');
988 $object->ref =
GETPOST(
'ref',
'alphanohtml');
989 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alphanohtml');
990 $object->socid =
GETPOST(
'socid',
'int');
991 $object->libelle =
GETPOST(
'label',
'alphanohtml');
992 $object->label =
GETPOST(
'label',
'alphanohtml');
993 $object->date = $dateinvoice;
994 $object->date_echeance = $datedue;
995 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
996 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
997 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
998 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
999 $object->fk_account =
GETPOST(
'fk_account',
'int');
1000 $object->vat_reverse_charge =
GETPOST(
'vat_reverse_charge') ==
'on' ? 1 : 0;
1001 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
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');
1006 $object->transport_mode_id =
GETPOST(
'transport_mode_id');
1009 if (empty($object->date_echeance)) {
1010 $object->date_echeance = $object->calculate_date_lim_reglement();
1013 $object->fetch_thirdparty();
1016 if (!$error &&
GETPOST(
'origin',
'alpha') &&
GETPOST(
'originid')) {
1018 $element = $subelement =
GETPOST(
'origin',
'alpha');
1026 if ($element ==
'order') {
1027 $element = $subelement =
'commande';
1029 if ($element ==
'propal') {
1030 $element =
'comm/propal'; $subelement =
'propal';
1032 if ($element ==
'contract') {
1033 $element = $subelement =
'contrat';
1035 if ($element ==
'order_supplier') {
1036 $element =
'fourn'; $subelement =
'fournisseur.commande';
1038 if ($element ==
'project') {
1039 $element =
'projet';
1041 $object->origin =
GETPOST(
'origin',
'alpha');
1042 $object->origin_id =
GETPOST(
'originid',
'int');
1045 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
1046 $classname = ucfirst($subelement);
1047 if ($classname ==
'Fournisseur.commande') {
1048 $classname =
'CommandeFournisseur';
1050 $objectsrc =
new $classname($db);
1051 $objectsrc->fetch($originid);
1052 $objectsrc->fetch_thirdparty();
1054 if (!empty($object->origin) && !empty($object->origin_id)) {
1055 $object->linkedObjectsIds[$object->origin] = $object->origin_id;
1059 if ($object->origin ==
'reception') {
1060 $objectsrc->fetchObjectLinked();
1062 if (count($objectsrc->linkedObjectsIds[
'order_supplier']) > 0) {
1063 foreach ($objectsrc->linkedObjectsIds[
'order_supplier'] as $key => $value) {
1064 $object->linkedObjectsIds[
'order_supplier'] = $value;
1069 $id = $object->create($user);
1073 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
1074 $classname = ucfirst($subelement);
1075 if ($classname ==
'Fournisseur.commande') {
1076 $classname =
'CommandeFournisseur';
1078 $srcobject =
new $classname($db);
1080 $result = $srcobject->fetch(
GETPOST(
'originid',
'int'));
1083 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1088 $amountdeposit = array();
1089 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)) {
1090 if ($typeamount ==
'amount') {
1091 $amount = $valuedeposit;
1093 $amount = $srcobject->total_ttc * ($valuedeposit / 100);
1096 $TTotalByTva = array();
1097 foreach ($srcobject->lines as &$line) {
1098 if (!empty($line->special_code)) {
1101 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1104 foreach ($TTotalByTva as $tva => &$total) {
1105 $coef = $total / $srcobject->total_ttc;
1106 $am = $amount * $coef;
1107 $amount_ttc_diff += $am;
1108 $amountdeposit[$tva] += $am / (1 + $tva / 100);
1111 if ($typeamount ==
'amount') {
1112 $amountdeposit[0] = $valuedeposit;
1113 } elseif ($typeamount ==
'variable') {
1116 $lines = $srcobject->lines;
1117 $numlines = count($lines);
1118 for ($i = 0; $i < $numlines; $i++) {
1120 if (empty($lines[$i]->qty)) {
1123 if (!empty($lines[$i]->special_code)) {
1127 $totalamount += $lines[$i]->total_ht;
1128 $tva_tx = $lines[$i]->tva_tx;
1129 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $valuedeposit) / 100;
1133 if ($totalamount == 0) {
1134 $amountdeposit[0] = 0;
1142 $amount_ttc_diff = $amountdeposit[0];
1145 foreach ($amountdeposit as $tva => $amount) {
1146 if (empty($amount)) {
1151 'amount' =>
'FixAmount',
1152 'variable' =>
'VarAmount'
1154 $descline =
'(DEPOSIT)';
1156 if ($typeamount ==
'amount') {
1157 $descline .=
' ('.price($valuedeposit,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
')';
1158 } elseif ($typeamount ==
'variable') {
1159 $descline .=
' ('.$valuedeposit.
'%)';
1162 $descline .=
' - '.$srcobject->ref;
1163 $result = $object->addline(
1170 (empty($conf->global->INVOICE_PRODUCTID_DEPOSIT) ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT),
1175 $lines[$i]->info_bits,
1185 $lines[$i]->special_code,
1192 $diff = $object->total_ttc - $amount_ttc_diff;
1194 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0) {
1195 $object->fetch_lines();
1196 $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100);
1197 $object->updateline(
1198 $object->lines[0]->id,
1199 $object->lines[0]->desc,
1201 $object->lines[0]->tva_tx,
1202 $object->lines[0]->localtax1_tx,
1203 $object->lines[0]->localtax2_tx,
1204 $object->lines[0]->qty,
1205 $object->lines[0]->fk_product,
1207 $object->lines[0]->info_bits,
1208 $object->lines[0]->product_type,
1209 $object->lines[0]->remise_percent,
1211 $object->lines[0]->date_start,
1212 $object->lines[0]->date_end,
1220 } elseif ($result > 0) {
1221 $lines = $srcobject->lines;
1222 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1223 $srcobject->fetch_lines();
1224 $lines = $srcobject->lines;
1227 $num = count($lines);
1228 for ($i = 0; $i < $num; $i++) {
1229 if (!in_array($lines[$i]->
id, $selectedLines)) {
1233 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
1234 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1237 if (method_exists($lines[$i],
'fetch_optionals')) {
1238 $lines[$i]->fetch_optionals();
1243 $date_start = $lines[$i]->date_debut_prevue;
1244 if ($lines[$i]->date_debut_reel) {
1245 $date_start = $lines[$i]->date_debut_reel;
1247 if ($lines[$i]->date_start) {
1248 $date_start = $lines[$i]->date_start;
1250 $date_end = $lines[$i]->date_fin_prevue;
1251 if ($lines[$i]->date_fin_reel) {
1252 $date_end = $lines[$i]->date_fin_reel;
1254 if ($lines[$i]->date_end) {
1255 $date_end = $lines[$i]->date_end;
1259 $object->special_code = $lines[$i]->special_code;
1262 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
1264 $pu_currency = $lines[$i]->multicurrency_subprice;
1266 $pu = $lines[$i]->subprice;
1271 $result = $object->addline(
1275 $lines[$i]->localtax1_tx,
1276 $lines[$i]->localtax2_tx,
1278 $lines[$i]->fk_product,
1279 $lines[$i]->remise_percent,
1283 $lines[$i]->info_bits,
1288 $lines[$i]->array_options,
1289 $lines[$i]->fk_unit,
1292 $lines[$i]->ref_supplier,
1293 $lines[$i]->special_code
1303 $object->fetch_lines();
1310 } elseif (!$error) {
1311 $id = $object->create($user);
1320 $langs->load(
"errors");
1325 $_GET[
'socid'] = $_POST[
'socid'];
1329 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1330 $outputlangs = $langs;
1331 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1338 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1341 } elseif ($action ==
'updateline' && $usercancreate) {
1345 if (! $object->fetch($id) > 0) {
1348 $object->fetch_thirdparty();
1351 $tva_tx = str_replace(
'*',
'', $tva_tx);
1353 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_subprice') !=
'') {
1355 $price_base_type =
'HT';
1358 $price_base_type =
'TTC';
1361 if (
GETPOST(
'productid') > 0) {
1363 if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
1365 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1370 $prod->fetch(
GETPOST(
'productid'));
1371 $label = $prod->description;
1372 if (trim(
GETPOST(
'product_desc',
'restricthtml')) != trim($label)) {
1373 $label =
GETPOST(
'product_desc',
'restricthtml');
1376 $type = $prod->type;
1378 $label =
GETPOST(
'product_desc',
'restricthtml');
1387 if (preg_match(
'/\*/', $tva_tx)) {
1392 $tva_tx = str_replace(
'*',
'', $tva_tx);
1393 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1394 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1400 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1401 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1403 if (is_array($extralabelsline)) {
1404 foreach ($extralabelsline as $key => $value) {
1405 unset($_POST[
"options_".$key]);
1409 $result = $object->updateline(
1431 unset($_POST[
'label']);
1432 unset($_POST[
'fourn_ref']);
1433 unset($_POST[
'date_starthour']);
1434 unset($_POST[
'date_startmin']);
1435 unset($_POST[
'date_startsec']);
1436 unset($_POST[
'date_startday']);
1437 unset($_POST[
'date_startmonth']);
1438 unset($_POST[
'date_startyear']);
1439 unset($_POST[
'date_endhour']);
1440 unset($_POST[
'date_endmin']);
1441 unset($_POST[
'date_endsec']);
1442 unset($_POST[
'date_endday']);
1443 unset($_POST[
'date_endmonth']);
1444 unset($_POST[
'date_endyear']);
1445 unset($_POST[
'price_ttc']);
1446 unset($_POST[
'price_ht']);
1453 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') && $usercancreate) {
1455 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1456 $vat_rate = str_replace(
'*',
'', $vat_rate);
1457 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1458 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1459 foreach ($object->lines as $line) {
1460 $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);
1462 } elseif ($action ==
'addline' && $usercancreate) {
1466 $ret = $object->fetch($id);
1471 $ret = $object->fetch_thirdparty();
1473 $langs->load(
'errors');
1478 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
1482 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
1483 if ($prod_entry_mode ==
'free') {
1486 $idprod =
GETPOST(
'idprod',
'int');
1494 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
1497 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
1498 if (empty($remise_percent)) {
1499 $remise_percent = 0;
1503 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1504 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
1506 if (is_array($extralabelsline)) {
1508 foreach ($extralabelsline as $key => $value) {
1509 unset($_POST[
"options_".$key]);
1513 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
1514 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1517 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
1518 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
1521 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
1522 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
1525 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
1526 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
1529 if (!
GETPOST(
'qty',
'alpha')) {
1530 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1534 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
1535 if ($combinations =
GETPOST(
'combinations',
'array')) {
1539 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1540 $idprod = $res->fk_product_child;
1542 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
1548 if ($prod_entry_mode !=
'free' && empty($error)) {
1552 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
1557 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
1559 $res = $productsupplier->fetch($idprod);
1562 if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) {
1564 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1565 if ($productsupplier->fourn_socid != $socid) {
1566 $productsupplier->ref_supplier =
'';
1569 $fksoctosearch = $object->thirdparty->id;
1570 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
1572 } elseif (
GETPOST(
'idprodfournprice',
'alpha') > 0) {
1573 $qtytosearch = $qty;
1575 $idprod = $productsupplier->get_buyprice(
GETPOST(
'idprodfournprice',
'alpha'), $qtytosearch);
1576 $res = $productsupplier->fetch($idprod);
1580 $label = $productsupplier->label;
1582 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1583 $outputlangs = $langs;
1585 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1586 $newlang =
GETPOST(
'lang_id',
'aZ09');
1588 if (empty($newlang)) {
1589 $newlang = $object->thirdparty->default_lang;
1591 if (!empty($newlang)) {
1592 $outputlangs =
new Translate(
"", $conf);
1593 $outputlangs->setDefaultLang($newlang);
1595 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
1597 $desc = $productsupplier->description;
1600 if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
1601 $desc = $productsupplier->desc_supplier;
1605 if (trim($product_desc) == trim($desc) && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
1608 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
1609 $desc = $product_desc;
1611 if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
1612 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
1615 $ref_supplier = $productsupplier->ref_supplier;
1618 if (!GETPOSTISSET(
'tva_tx')) {
1619 $tva_tx =
get_default_tva($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
1620 $tva_npr =
get_default_npr($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
1622 if (empty($tva_tx)) {
1625 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
1626 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
1628 $type = $productsupplier->type;
1629 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1630 $price_base_type =
'HT';
1632 $pu_devise =
price2num($price_ht_devise,
'CU');
1633 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
1634 $price_base_type =
'TTC';
1636 $pu_devise =
price2num($price_ttc_devise,
'CU');
1638 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
1639 if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) {
1640 $pu = $productsupplier->fourn_pu;
1643 $pu = $productsupplier->fourn_pu;
1644 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
1648 $ref_supplier = $productsupplier->ref_supplier;
1654 $result = $object->addline(
1669 min($rank, count($object->lines) + 1),
1672 $productsupplier->fk_unit,
1675 GETPOST(
'fourn_ref',
'alpha'),
1679 if ($idprod == -99 || $idprod == 0) {
1682 $langs->load(
"errors");
1683 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
1685 if ($idprod == -1) {
1688 $langs->load(
"errors");
1689 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
1691 } elseif (empty($error)) {
1692 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1693 $tva_tx = str_replace(
'*',
'', $tva_tx);
1694 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1695 $desc = $product_desc;
1697 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
1699 $fk_unit =
GETPOST(
'units',
'alpha');
1701 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
1706 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1707 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1709 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
1713 $pu_ht =
price2num($pu_ttc / (1 + ($tva_tx / 100)),
'MU');
1715 $price_base_type =
'HT';
1716 $pu_devise =
price2num($price_ht_devise,
'CU');
1718 $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);
1722 if (!$error && $result > 0) {
1726 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1727 $outputlangs = $langs;
1730 $newlang =
GETPOST(
'lang_id',
'aZ09');
1733 $newlang = $object->thirdparty->default_lang;
1735 if (!empty($newlang)) {
1736 $outputlangs =
new Translate(
"", $conf);
1737 $outputlangs->setDefaultLang($newlang);
1739 $model = $object->model_pdf;
1740 $ret = $object->fetch($id);
1742 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1748 unset($_POST [
'prod_entry_mode']);
1750 unset($_POST[
'qty']);
1751 unset($_POST[
'type']);
1752 unset($_POST[
'remise_percent']);
1753 unset($_POST[
'pu']);
1754 unset($_POST[
'price_ht']);
1755 unset($_POST[
'multicurrency_price_ht']);
1756 unset($_POST[
'price_ttc']);
1757 unset($_POST[
'fourn_ref']);
1758 unset($_POST[
'tva_tx']);
1759 unset($_POST[
'label']);
1760 unset($localtax1_tx);
1761 unset($localtax2_tx);
1762 unset($_POST[
'np_marginRate']);
1763 unset($_POST[
'np_markRate']);
1764 unset($_POST[
'dp_desc']);
1765 unset($_POST[
'idprodfournprice']);
1766 unset($_POST[
'units']);
1768 unset($_POST[
'date_starthour']);
1769 unset($_POST[
'date_startmin']);
1770 unset($_POST[
'date_startsec']);
1771 unset($_POST[
'date_startday']);
1772 unset($_POST[
'date_startmonth']);
1773 unset($_POST[
'date_startyear']);
1774 unset($_POST[
'date_endhour']);
1775 unset($_POST[
'date_endmin']);
1776 unset($_POST[
'date_endsec']);
1777 unset($_POST[
'date_endday']);
1778 unset($_POST[
'date_endmonth']);
1779 unset($_POST[
'date_endyear']);
1786 } elseif ($action ==
'classin' && $usercancreate) {
1787 $object->fetch($id);
1788 $result = $object->setProject($projectid);
1789 } elseif ($action ==
'confirm_edit' && $confirm ==
'yes' && $usercancreate) {
1791 $object->fetch($id);
1793 $totalpaid = $object->getSommePaiement();
1794 $resteapayer = $object->total_ttc - $totalpaid;
1797 $ventilExportCompta = $object->getVentilExportCompta();
1799 if (!$ventilExportCompta) {
1802 $idwarehouse =
GETPOST(
'idwarehouse');
1804 $object->fetch_thirdparty();
1806 $qualified_for_stock_change = 0;
1807 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1808 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1810 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1814 if (isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
1815 $langs->load(
"stocks");
1816 if (!$idwarehouse || $idwarehouse == -1) {
1818 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1823 $object->setDraft($user, $idwarehouse);
1826 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1827 $outputlangs = $langs;
1830 $newlang =
GETPOST(
'lang_id',
'aZ09');
1833 $newlang = $object->thirdparty->default_lang;
1835 if (!empty($newlang)) {
1836 $outputlangs =
new Translate(
"", $conf);
1837 $outputlangs->setDefaultLang($newlang);
1839 $model = $object->model_pdf;
1840 $ret = $object->fetch($id);
1842 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1851 } elseif ($action ==
'reopen' && $usercancreate) {
1853 $result = $object->fetch($id);
1856 $result = $object->setUnpaid($user);
1858 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
1867 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1870 $triggersendname =
'BILL_SUPPLIER_SENTBYMAIL';
1872 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
1873 $trackid =
'sinv'.$object->id;
1874 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1877 $upload_dir = $conf->fournisseur->facture->dir_output;
1878 $permissiontoadd = $usercancreate;
1879 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1882 if ($action ==
'calculate') {
1883 $calculationrule =
GETPOST(
'calculationrule');
1885 $object->fetch($id);
1886 $object->fetch_thirdparty();
1887 $result = $object->update_price(0, (($calculationrule ==
'totalofround') ?
'0' :
'1'), 0, $object->thirdparty);
1893 if ($action ==
'update_extras') {
1897 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1905 $result = $object->insertExtraFields(
'BILL_SUPPLIER_MODIFY');
1913 $action =
'edit_extras';
1917 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1918 if ($action ==
'addcontact') {
1919 $result = $object->fetch($id);
1921 if ($result > 0 && $id > 0) {
1924 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1928 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1931 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1932 $langs->load(
"errors");
1933 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1938 } elseif ($action ==
'swapstatut') {
1940 if ($object->fetch($id)) {
1941 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1945 } elseif ($action ==
'deletecontact') {
1947 $object->fetch($id);
1948 $result = $object->delete_contact(
GETPOST(
"lineid",
'int'));
1951 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1965$form =
new Form($db);
1967$bankaccountstatic =
new Account($db);
1969if (isModEnabled(
'project')) {
1975$title = $object->ref.
" - ".$langs->trans(
'Card');
1976if ($action ==
'create') {
1977 $title = $langs->trans(
"NewSupplierInvoice");
1979$help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
1983if ($action ==
'create') {
1986 print
load_fiche_titre($langs->trans(
'NewSupplierInvoice'),
'',
'supplier_invoice');
1990 $currency_code = $conf->currency;
1993 if (
GETPOST(
'socid',
'int') > 0) {
1995 $societe->fetch(
GETPOST(
'socid',
'int'));
1996 if (isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
1997 $currency_code = $societe->multicurrency_code;
2001 if (!empty($origin) && !empty($originid)) {
2003 $element = $subelement = $origin;
2005 if ($element ==
'project') {
2006 $projectid = $originid;
2007 $element =
'projet';
2011 if ($element ==
'order') {
2012 $element = $subelement =
'commande';
2014 if ($element ==
'propal') {
2015 $element =
'comm/propal'; $subelement =
'propal';
2017 if ($element ==
'contract') {
2018 $element = $subelement =
'contrat';
2020 if ($element ==
'order_supplier') {
2021 $element =
'fourn'; $subelement =
'fournisseur.commande';
2024 require_once DOL_DOCUMENT_ROOT.
'/'.$element.
'/class/'.$subelement.
'.class.php';
2025 $classname = ucfirst($subelement);
2026 if ($classname ==
'Fournisseur.commande') {
2027 $classname =
'CommandeFournisseur';
2029 $objectsrc =
new $classname($db);
2030 $objectsrc->fetch($originid);
2031 $objectsrc->fetch_thirdparty();
2033 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
2035 $soc = $objectsrc->thirdparty;
2037 $cond_reglement_id = 0;
2038 $mode_reglement_id = 0;
2040 $remise_percent = 0;
2041 $remise_absolue = 0;
2042 $transport_mode_id = 0;
2045 if (!empty($objectsrc->cond_reglement_id)) {
2046 $cond_reglement_id = $objectsrc->cond_reglement_id;
2048 if (!empty($objectsrc->mode_reglement_id)) {
2049 $mode_reglement_id = $objectsrc->mode_reglement_id;
2051 if (!empty($objectsrc->fk_account)) {
2052 $fk_account = $objectsrc->fk_account;
2054 if (!empty($objectsrc->remise_percent)) {
2055 $remise_percent = $objectsrc->remise_percent;
2057 if (!empty($objectsrc->remise_absolue)) {
2058 $remise_absolue = $objectsrc->remise_absolue;
2060 if (!empty($objectsrc->transport_mode_id)) {
2061 $transport_mode_id = $objectsrc->transport_mode_id;
2064 if (empty($cond_reglement_id)
2065 || empty($mode_reglement_id)
2066 || empty($fk_account)
2067 || empty($remise_percent)
2068 || empty($remise_absolue)
2069 || empty($transport_mode_id)
2071 if ($origin ==
'reception') {
2073 if (!isset($objectsrc->supplier_order)) {
2074 $objectsrc->fetch_origin();
2077 if (!empty($objectsrc->commandeFournisseur)) {
2078 $supplierOrder = $objectsrc->commandeFournisseur;
2079 if (empty($cond_reglement_id) && !empty($supplierOrder->cond_reglement_id)) {
2080 $cond_reglement_id = $supplierOrder->cond_reglement_id;
2082 if (empty($mode_reglement_id) && !empty($supplierOrder->mode_reglement_id)) {
2083 $mode_reglement_id = $supplierOrder->mode_reglement_id;
2085 if (empty($fk_account) && !empty($supplierOrder->fk_account)) {
2086 $fk_account = $supplierOrder->fk_account;
2088 if (empty($remise_percent) && !empty($supplierOrder->remise_percent)) {
2089 $remise_percent = $supplierOrder->remise_percent;
2091 if (empty($remise_absolue) && !empty($supplierOrder->remise_absolue)) {
2092 $remise_absolue = $supplierOrder->remise_absolue;
2094 if (empty($transport_mode_id) && !empty($supplierOrder->transport_mode_id)) {
2095 $transport_mode_id = $supplierOrder->transport_mode_id;
2102 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
2103 $cond_reglement_id = $soc->cond_reglement_supplier_id;
2105 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
2106 $mode_reglement_id = $soc->mode_reglement_supplier_id;
2108 if (empty($fk_account) && !empty($soc->fk_account)) {
2109 $fk_account = $soc->fk_account;
2111 if (empty($remise_percent) && !empty($soc->remise_supplier_percent)) {
2112 $remise_percent = $soc->remise_supplier_percent;
2114 if (empty($remise_absolue) && !empty($soc->remise_absolue)) {
2115 $remise_absolue = $soc->remise_absolue;
2117 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
2118 $transport_mode_id = $soc->transport_mode_id;
2123 if (isModEnabled(
"multicurrency")) {
2124 if (!empty($objectsrc->multicurrency_code)) {
2125 $currency_code = $objectsrc->multicurrency_code;
2127 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
2128 $currency_tx = $objectsrc->multicurrency_tx;
2133 $dateinvoice = ($datetmp ==
'' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ? -1 :
'') : $datetmp);
2135 $datedue = ($datetmp ==
'' ?-1 : $datetmp);
2138 $objectsrc->fetch_optionals();
2139 $object->array_options = $objectsrc->array_options;
2141 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2142 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2143 $vat_reverse_charge = $societe->vat_reverse_charge;
2144 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2145 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2147 $dateinvoice = ($datetmp ==
'' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $datetmp);
2149 $datedue = ($datetmp ==
'' ?-1 : $datetmp);
2151 if (isModEnabled(
"multicurrency") && !empty($soc->multicurrency_code)) {
2152 $currency_code = $soc->multicurrency_code;
2157 if (empty($cond_reglement_id)) {
2158 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2162 if (empty($mode_reglement_id)) {
2163 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2166 $note_public = $object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($conf->global->FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM)) ? $objectsrc->note_public : null));
2167 $note_private = $object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($conf->global->FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM)) ? $objectsrc->note_private : null));
2169 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2170 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2171 print
'<input type="hidden" name="action" value="add">';
2172 if (!empty($societe->id) && $societe->id > 0) {
2173 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">'.
"\n";
2175 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2176 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2177 if (!empty($currency_tx)) {
2178 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2180 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2184 print
'<table class="border centpercent">';
2187 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
2191 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2192 $invoice_predefined->fetch($fac_recid);
2196 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2199 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2200 $absolute_discount = $societe->getAvailableDiscounts(
'',
'', 0, 1);
2201 print $societe->getNomUrl(1,
'supplier');
2202 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2204 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2205 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');
2207 if (empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE_DISABLED)) {
2208 print
'<script type="text/javascript">
2209 $(document).ready(function() {
2210 $("#socid").change(function() {
2211 console.log("We have changed the company - Reload page");
2213 $("input[name=action]").val("create");
2214 $("form[name=add]").submit();
2219 if ($fac_recid <= 0) {
2220 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>';
2226 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2227 $invoice_predefined->fetch($fac_recid);
2229 $dateinvoice = $invoice_predefined->date_when;
2230 if (empty($projectid)) {
2231 $projectid = $invoice_predefined->fk_project;
2233 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2234 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2235 $fk_account = $invoice_predefined->fk_account;
2236 $note_public = $invoice_predefined->note_public;
2237 $note_private = $invoice_predefined->note_private;
2239 if (!empty($invoice_predefined->multicurrency_code)) {
2240 $currency_code = $invoice_predefined->multicurrency_code;
2242 if (!empty($invoice_predefined->multicurrency_tx)) {
2243 $currency_tx = $invoice_predefined->multicurrency_tx;
2246 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2247 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn_rec as r';
2248 $sql .=
' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2250 $resql = $db->query($sql);
2252 $num = $db->num_rows($resql);
2256 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2258 print
'<select class="flat" id="fac_rec" name="fac_rec">';
2259 print
'<option value="0" selected></option>';
2261 $objp = $db->fetch_object($resql);
2262 print
'<option value="'.$objp->rowid.
'"';
2263 if ($fac_recid == $objp->rowid) {
2265 $exampletemplateinvoice->fetch($fac_recid);
2267 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
2272 if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED)) {
2273 print
'<script type="text/javascript">
2274 $(document).ready(function() {
2275 $("#fac_rec").change(function() {
2276 console.log("We have changed the template invoice - Reload page");
2278 $("input[name=action]").val("create");
2279 $("form[name=add]").submit();
2293 print
'<tr><td class="fieldrequired">'.$langs->trans(
'RefSupplier').
'</td><td><input name="ref_supplier" value="'.(GETPOSTISSET(
'ref_supplier') ?
GETPOST(
'ref_supplier') : (!empty($objectsrc->ref_supplier) ? $objectsrc->ref_supplier :
'')).
'" type="text"';
2294 if (!empty($societe->id) && $societe->id > 0) {
2300 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
2302 print
'<div class="tagtable">'.
"\n";
2305 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2306 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOST(
'type',
'int')?
'' :
'checked').
'> ';
2307 $desc = $form->textwithpicto($tmp.
'<label for="radio_standard">'.$langs->trans(
"InvoiceStandardAsk").
'</label>', $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2309 print
'</div></div>';
2311 if (empty($origin) || ($origin ==
'order_supplier' && !empty($originid))) {
2313 if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) {
2314 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2315 $tmp=
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOST(
'type') == 3 ?
' checked' :
'') .
'> ';
2316 print
'<script type="text/javascript">
2317 jQuery(document).ready(function() {
2318 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2319 jQuery("#radio_standard").prop("checked", true);
2321 jQuery("#typedeposit, #valuedeposit").click(function() {
2322 jQuery("#radio_deposit").prop("checked", true);
2324 jQuery("#typedeposit").change(function() {
2325 console.log("We change type of down payment");
2326 jQuery("#radio_deposit").prop("checked", true);
2327 setRadioForTypeOfInvoice();
2329 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2330 setRadioForTypeOfInvoice();
2332 function setRadioForTypeOfInvoice() {
2333 console.log("Change radio");
2334 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2335 jQuery(".checkforselect").prop("disabled", true);
2336 jQuery(".checkforselect").prop("checked", false);
2338 jQuery(".checkforselect").prop("disabled", false);
2339 jQuery(".checkforselect").prop("checked", true);
2345 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2346 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2347 print
'<table class="nobordernopadding"><tr>';
2351 if ($origin ==
'order_supplier') {
2352 print
'<td class="nowrap" style="padding-left: 15px">';
2354 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
2355 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
2356 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
2358 print $form->selectarray(
'typedeposit', $arraylist,
GETPOST(
'typedeposit',
'aZ09'), 0, 0, 0,
'', 1);
2360 print
'<td class="nowrap" style="padding-left: 5px">';
2361 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' .
GETPOST(
'valuedeposit',
'int') .
'"/>';
2364 print
'</tr></table>';
2366 print
'</div></div>';
2435 if (empty($origin)) {
2436 if (!empty($societe->id) && $societe->id > 0) {
2438 if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) {
2440 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2447 foreach ($facids as $key => $valarray) {
2448 $newinvoice_static->id = $key;
2449 $newinvoice_static->ref = $valarray [
'ref'];
2450 $newinvoice_static->statut = $valarray [
'status'];
2451 $newinvoice_static->type = $valarray [
'type'];
2452 $newinvoice_static->paye = $valarray [
'paye'];
2454 $optionsav .=
'<option value="'.$key.
'"';
2455 if ($key ==
GETPOST(
'fac_avoir',
'int')) {
2456 $optionsav .=
' selected';
2459 $optionsav .= $newinvoice_static->ref;
2460 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
2461 $optionsav .=
'</option>';
2464 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2465 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
2466 if (!$optionsav && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
2467 $tmp .=
' disabled';
2471 print
'<script type="text/javascript">
2472 jQuery(document).ready(function() {
2473 if (! jQuery("#radio_creditnote").is(":checked"))
2475 jQuery("#credit_note_options").hide();
2477 jQuery("#radio_creditnote").click(function() {
2478 jQuery("#credit_note_options").show();
2480 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2481 jQuery("#credit_note_options").hide();
2485 $text = $tmp.
'<label for="radio_creditnote">'.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
2487 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2489 $text .=
' disabled';
2493 $text .=
'<option value="-1"></option>';
2494 $text .= $optionsav;
2496 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
2498 $text .=
'</select>';
2499 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2502 print
'<div id="credit_note_options" class="clearboth">';
2503 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' :
'').
' /> ';
2504 print
'<label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
2505 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' :
'').
' /> ';
2506 print
'<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
2509 print
'</div></div>';
2512 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2513 if (empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
2514 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2516 $tmp=
'<input type="radio" name="type" id="radio_creditnote" value="2"> ';
2518 $text = $tmp.$langs->trans(
"InvoiceAvoir").
' ';
2519 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromSupplierThird").
')</span> ';
2520 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
2522 print
'</div></div>'.
"\n";
2530 if (!empty($societe->id) && $societe->id > 0) {
2532 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2534 $thirdparty = $societe;
2536 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$societe->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2537 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2543 print
'<tr><td>'.$langs->trans(
'Label').
'</td><td><input class="minwidth200" name="label" value="'.
dol_escape_htmltag(
GETPOST(
'label')).
'" type="text"></td></tr>';
2546 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td>';
2547 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2548 print $form->selectDate($dateinvoice,
'',
'',
'',
'',
"add", 1, 1);
2552 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2553 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
2554 print $form->getSelectConditionsPaiements(GETPOSTISSET(
'cond_reglement_id') ?
GETPOST(
'cond_reglement_id',
'int') : $cond_reglement_id,
'cond_reglement_id');
2558 print
'<tr><td>'.$langs->trans(
'DateMaxPayment').
'</td><td>';
2559 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2560 print $form->selectDate($datedue,
'ech',
'',
'',
'',
"add", 1, 1);
2564 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2565 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2566 $form->select_types_paiements(GETPOSTISSET(
'mode_reglement_id') ?
GETPOST(
'mode_reglement_id',
'int') : $mode_reglement_id,
'mode_reglement_id',
'DBIT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
2570 if (isModEnabled(
"banque")) {
2571 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2572 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes((GETPOSTISSET(
'fk_account') ?
GETPOST(
'fk_account',
'alpha') : $fk_account),
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
2577 if (isModEnabled(
'project')) {
2580 $langs->load(
'projects');
2581 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2582 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $societe->id : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
2583 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>';
2588 if (isModEnabled(
'incoterm')) {
2590 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
2591 print
'<td colspan="3" class="maxwidthonsmartphone">';
2592 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2593 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 :
''));
2598 if (!empty($conf->global->ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE)) {
2599 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
2600 print
'<tr><td>' . $langs->trans(
'VATReverseCharge') .
'</td><td>';
2602 if ($vat_reverse_charge == 1 || $societe->vat_reverse_charge == 1 || ($societe->country_code !=
'FR' &&
isInEEC($societe) && !empty($societe->tva_intra))) {
2603 $vat_reverse_charge = 1;
2605 $vat_reverse_charge = 0;
2608 print
'<input type="checkbox" name="vat_reverse_charge"'. (!empty($vat_reverse_charge) ?
' checked ' :
'') .
'>';
2613 if (isModEnabled(
"multicurrency")) {
2615 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
2616 print
'<td class="maxwidthonsmartphone">';
2617 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
2618 print $form->selectMultiCurrency((GETPOSTISSET(
'multicurrency_code') ?
GETPOST(
'multicurrency_code',
'alpha') : $currency_code),
'multicurrency_code');
2624 if ($fac_recid > 0) {
2625 $dateexample = $newdateinvoice ? $newdateinvoice : $dateinvoice;
2626 if (empty($dateexample)) {
2629 $substitutionarray = array(
2630 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
2631 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
2632 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
2633 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
2634 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
2635 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
2636 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
2637 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
2638 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
2639 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
2640 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
2643 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
2644 foreach ($substitutionarray as $key => $val) {
2645 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
2647 $htmltext .=
'</i>';
2651 if (isModEnabled(
'intracommreport')) {
2652 $langs->loadLangs(array(
"intracommreport"));
2653 print
'<tr><td>'.$langs->trans(
'IntracommReportTransportMode').
'</td><td>';
2654 $form->selectTransportMode(GETPOSTISSET(
'transport_mode_id') ?
GETPOST(
'transport_mode_id') : $transport_mode_id,
'transport_mode_id');
2658 if (empty($reshook)) {
2659 print $object->showOptionals($extrafields,
'create');
2663 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2665 $doleditor =
new DolEditor(
'note_public', (GETPOSTISSET(
'note_public') ?
GETPOST(
'note_public',
'restricthtml') : $note_public),
'', 80,
'dolibarr_notes',
'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3,
'90%');
2666 print $doleditor->Create(1);
2672 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
2674 $doleditor =
new DolEditor(
'note_private', (GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') : $note_private),
'', 80,
'dolibarr_notes',
'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3,
'90%');
2675 print $doleditor->Create(1);
2681 if (!empty($objectsrc) && is_object($objectsrc)) {
2682 print
"\n<!-- ".$classname.
" info -->";
2684 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2685 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2686 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2687 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2688 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2690 $txt = $langs->trans($classname);
2691 if ($classname ==
'CommandeFournisseur') {
2692 $langs->load(
'orders');
2693 $txt = $langs->trans(
"SupplierOrder");
2695 print
'<tr><td>'.$txt.
'</td><td>'.$objectsrc->getNomUrl(1);
2697 $objectsrc->fetchObjectLinked($originid, $origin,
'',
'invoice_supplier');
2699 $invoice_supplier = $objectsrc->linkedObjects[
'invoice_supplier'];
2702 if (is_array($invoice_supplier)) {
2703 $cntinvoice = count($invoice_supplier);
2705 if ($cntinvoice >= 1) {
2707 echo
' ('.$langs->trans(
'LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).
')';
2712 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2713 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2714 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2715 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2718 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2719 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2721 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2723 if (isModEnabled(
"multicurrency")) {
2724 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2725 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2726 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2731 $parameters = array();
2732 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
2733 print $hookmanager->resPrint;
2740 print $form->buttonsSaveCancel(
"CreateDraft");
2743 if (!empty($objectsrc) && is_object($objectsrc)) {
2746 $title = $langs->trans(
'ProductsAndServices');
2749 print
'<div class="div-table-responsive-no-min">';
2750 print
'<table class="noborder centpercent">';
2752 $objectsrc->printOriginLinesList(
'', $selectedLines);
2760 if ($id > 0 || !empty($ref)) {
2766 $productstatic =
new Product($db);
2768 $result = $object->fetch($id, $ref);
2770 $langs->load(
"errors");
2771 print $langs->trans(
"ErrorRecordNotFound");
2777 $result = $object->fetch_thirdparty();
2783 $societe = $object->thirdparty;
2785 $totalpaid = $object->getSommePaiement();
2786 $totalcreditnotes = $object->getSumCreditNotesUsed();
2787 $totaldeposits = $object->getSumDepositsUsed();
2795 $resteapayer =
price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
2798 $multicurrency_resteapayer = 0;
2799 if (isModEnabled(
"multicurrency")) {
2800 $multicurrency_totalpaid = $object->getSommePaiement(1);
2801 $multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
2802 $multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
2803 $multicurrency_resteapayer =
price2num($object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
2807 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 && $object->multicurrency_code != $conf->currency) {
2808 $resteapayer =
price2num($multicurrency_resteapayer / $object->multicurrency_tx,
'MT');
2812 if ($object->paye) {
2815 $resteapayeraffiche = $resteapayer;
2817 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
2818 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2819 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2821 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2822 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2825 $absolute_discount = $societe->getAvailableDiscounts(
'', $filterabsolutediscount, 0, 1);
2826 $absolute_creditnote = $societe->getAvailableDiscounts(
'', $filtercreditnote, 0, 1);
2827 $absolute_discount =
price2num($absolute_discount,
'MT');
2828 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2833 $objectidnext = $object->getIdReplacingInvoice();
2836 $titre = $langs->trans(
'SupplierInvoice');
2838 print
dol_get_fiche_head($head,
'card', $titre, -1,
'supplier_invoice', 0,
'',
'', 0,
'', 1);
2843 if ($action ==
'converttoreduc') {
2846 $type_fac =
'ExcessPaid';
2848 $type_fac =
'CreditNote';
2850 $type_fac =
'Deposit';
2852 $text = $langs->trans(
'ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
2853 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReducSupplier2');
2854 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
2858 if ($action ==
'clone') {
2860 $formquestion = array(
2861 array(
'type' =>
'text',
'name' =>
'newsupplierref',
'label' => $langs->trans(
"RefSupplier"),
'value' => $langs->trans(
"CopyOf").
' '.$object->ref_supplier),
2862 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
2865 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
2869 if ($action ==
'valid') {
2871 if (preg_match(
'/^[\(]?PROV/i', $object->ref) || empty($object->ref)) {
2873 $numref = $object->getNextNumRef($societe);
2875 $numref = $object->ref;
2882 $text = $langs->trans(
'ConfirmValidateBill', $numref);
2890 $formquestion = array();
2892 $qualified_for_stock_change = 0;
2893 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2894 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2896 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2899 if (isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
2900 $langs->load(
"stocks");
2901 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2904 $warehouse_array = $warehouse->list_array();
2905 if (count($warehouse_array) == 1) {
2906 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
2907 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
2910 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
2912 $formquestion = array(
2913 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
2917 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, 1, 1);
2922 if ($action ==
'edit') {
2923 $formquestion = array();
2925 $qualified_for_stock_change = 0;
2926 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2927 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2929 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2931 if (isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
2932 $langs->load(
"stocks");
2933 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2936 $warehouse_array = $warehouse->list_array();
2937 if (count($warehouse_array) == 1) {
2938 $label = $object->type ==
FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
2939 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
2942 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
2944 $formquestion = array(
2945 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value)
2948 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'UnvalidateBill'), $langs->trans(
'ConfirmUnvalidateBill', $object->ref),
'confirm_edit', $formquestion, 1, 1);
2952 if ($action ==
'paid' && ($resteapayer <= 0 || (!empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) && $resteapayer == $object->total_ttc))) {
2953 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill', $object->ref),
'confirm_paid',
'', 0, 1);
2956 if ($action ==
'paid' && $resteapayer > 0 && (empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $resteapayer != $object->total_ttc)) {
2960 $close[$i][
'code'] =
'discount_vat';
2962 $close[$i][
'code'] =
'badsupplier';
2964 $close[$i][
'code'] =
'other';
2968 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
2970 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
2972 $close[$i][
'label'] = $langs->trans(
"Other");
2976 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
2978 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
2980 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
2983 foreach ($close as $key => $val) {
2984 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
2988 $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'));
2990 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially', $object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
2994 if ($action ==
'canceled') {
2996 $close[1][
'code'] =
'badsupplier';
2997 $close[2][
'code'] =
'abandon';
2999 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3000 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
3002 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadSupplier", $object->ref), $close[1][
'label'], 1);
3003 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
3005 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
3006 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
3009 $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'));
3011 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill', $object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 250);
3015 if ($action ==
'delete') {
3016 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteBill'), $langs->trans(
'ConfirmDeleteBill'),
'confirm_delete',
'', 0, 1);
3018 if ($action ==
'deletepayment') {
3019 $payment_id =
GETPOST(
'paiement_id');
3020 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'', 0, 1);
3024 if ($action ==
'ask_deleteline') {
3025 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
3028 if (!$formconfirm) {
3029 $parameters = array(
'formConfirm' => $formconfirm,
'lineid'=>$lineid);
3030 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
3031 if (empty($reshook)) {
3032 $formconfirm .= $hookmanager->resPrint;
3033 } elseif ($reshook > 0) {
3034 $formconfirm = $hookmanager->resPrint;
3043 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
3045 $morehtmlref =
'<div class="refidno">';
3047 $morehtmlref .= $form->editfieldkey(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'', 0, 1);
3048 $morehtmlref .= $form->editfieldval(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
3050 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'supplier');
3051 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
3052 $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>';
3055 if (isModEnabled(
'project')) {
3056 $langs->load(
"projects");
3057 $morehtmlref .=
'<br>';
3058 if ($permissiontoadd) {
3059 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
3060 if ($action !=
'classify') {
3061 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.newToken().
'&id='.((int) $object->id).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
3063 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
3065 if (!empty($object->fk_project)) {
3067 $proj->fetch($object->fk_project);
3068 $morehtmlref .= $proj->getNomUrl(1);
3070 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
3075 $morehtmlref .=
'</div>';
3077 $object->totalpaid = $totalpaid;
3079 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
3081 print
'<div class="fichecenter">';
3082 print
'<div class="fichehalfleft">';
3083 print
'<div class="underbanner clearboth"></div>';
3085 print
'<table class="border tableforfield centpercent">';
3088 print
'<tr><td class="titlefield">'.$langs->trans(
'Type').
'</td><td>';
3089 print
'<span class="badgeneutral">';
3090 print $object->getLibType();
3094 $facreplaced->fetch($object->fk_facture_source);
3095 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
3099 if ($object->fk_facture_source > 0) {
3100 $facusing->fetch($object->fk_facture_source);
3101 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
3103 $langs->load(
"errors");
3104 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"WarningCorrectedInvoiceNotFound").
'</span>';
3108 $facidavoir = $object->getListIdAvoirFromInvoice();
3109 if (count($facidavoir) > 0) {
3110 $invoicecredits = array();
3111 foreach ($facidavoir as $id) {
3113 $facavoir->fetch($id);
3114 $invoicecredits[] = $facavoir->getNomUrl(1);
3116 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir") . (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
3119 if (isset($objectidnext) && $objectidnext > 0) {
3122 $facthatreplace->fetch($objectidnext);
3123 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
3127 $result = $discount->fetch(0, 0, $object->id);
3129 print
' <span class="opacitymediumbycolor paddingleft">';
3130 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
3131 $s = str_replace(
'{s1}', $object->getLibType(1), $s);
3132 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
3134 print
'</span><br>';
3138 if ($object->fk_fac_rec_source > 0) {
3140 $result = $tmptemplate->fetch($object->fk_fac_rec_source);
3142 print
' <span class="opacitymediumbycolor paddingleft">';
3143 $link =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->titre).
'</a>';
3144 $s = $langs->transnoentities(
"GeneratedFromSupplierTemplate", $link);
3154 print
'<!-- Discounts -->'.
"\n";
3155 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining');
3158 $thirdparty = $societe;
3160 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3166 print
'<td>'.$form->editfieldkey(
"Label",
'label', $object->label, $object, $usercancreate).
'</td>';
3167 print
'<td>'.$form->editfieldval(
"Label",
'label', $object->label, $object, $usercancreate).
'</td>';
3175 print $form->editfieldkey(
"DateInvoice",
'datef', $object->datep, $object, $form_permission,
'datepicker');
3176 print
'</td><td colspan="3">';
3177 print $form->editfieldval(
"Date",
'datef', $object->datep, $object, $form_permission,
'datepicker');
3181 $langs->load(
'bills');
3182 print
'<tr><td class="nowrap">';
3183 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3184 print $langs->trans(
'PaymentConditions');
3186 if ($action !=
'editconditions' && $form_permission) {
3187 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>';
3189 print
'</tr></table>';
3191 if ($action ==
'editconditions') {
3192 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
3194 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none');
3201 print $form->editfieldkey(
"DateMaxPayment",
'date_lim_reglement', $object->date_echeance, $object, $form_permission,
'datepicker');
3203 print $form->editfieldval(
"DateMaxPayment",
'date_lim_reglement', $object->date_echeance, $object, $form_permission,
'datepicker');
3204 if ($action !=
'editdate_lim_reglement' && $object->hasDelay()) {
3210 $langs->load(
'bills');
3211 print
'<tr><td class="nowrap">';
3212 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3213 print $langs->trans(
'PaymentMode');
3215 if ($action !=
'editmode' && $form_permission) {
3216 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>';
3218 print
'</tr></table>';
3220 if ($action ==
'editmode') {
3221 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
3223 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
3228 if (isModEnabled(
"multicurrency")) {
3232 print
'<table class="nobordernopadding" width="100%"><tr><td>';
3233 print $form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
3235 if ($action !=
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT) {
3236 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>';
3238 print
'</tr></table>';
3240 if ($action ==
'editmulticurrencycode') {
3241 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
3243 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
3248 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3251 print
'<table class="nobordernopadding centpercent"><tr><td>';
3252 print $form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
3254 if ($action !=
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3255 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>';
3257 print
'</tr></table>';
3259 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
3260 if ($action ==
'actualizemulticurrencyrate') {
3263 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
3265 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
3266 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3267 print
'<div class="inline-block"> ';
3268 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
3277 if (isModEnabled(
"banque")) {
3278 print
'<tr><td class="nowrap">';
3279 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3280 print $langs->trans(
'BankAccount');
3282 if ($action !=
'editbankaccount' && $usercancreate) {
3283 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>';
3285 print
'</tr></table>';
3287 if ($action ==
'editbankaccount') {
3288 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
3290 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
3297 if (!empty($conf->global->ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE)) {
3298 print
'<tr><td class="nowrap">';
3299 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3300 print $langs->trans(
'VATReverseCharge');
3302 if ($action !=
'editvatreversecharge' && $usercancreate) {
3303 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editvatreversecharge&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetVATReverseCharge'), 1).
'</a></td>';
3305 print
'</tr></table>';
3307 if ($action ==
'editvatreversecharge') {
3308 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
3309 print
'<input type="hidden" name="action" value="setvatreversecharge">';
3310 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3312 print
'<input type="checkbox" name="vat_reverse_charge"' . ($object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
'>';
3314 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
3317 print
'<input type="checkbox" name="vat_reverse_charge"'. ($object->vat_reverse_charge ==
'1' ?
' checked ' :
'') .
' disabled>';
3323 if (isModEnabled(
'incoterm')) {
3325 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3326 print $langs->trans(
'IncotermLabel');
3327 print
'<td><td class="right">';
3328 if ($usercancreate) {
3329 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$object->id.
'&action=editincoterm&token='.newToken().
'">'.
img_edit().
'</a>';
3333 print
'</td></tr></table>';
3336 if ($action !=
'editincoterm') {
3337 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
3339 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
3345 if (isModEnabled(
'intracommreport')) {
3346 $langs->loadLangs(array(
"intracommreport"));
3348 print
'<table class="nobordernopadding centpercent"><tr><td>';
3349 print $langs->trans(
'IntracommReportTransportMode');
3351 if ($action !=
'edittransportmode' && ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"))) {
3352 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edittransportmode&token='.newToken().
'&id='.$object->id.
'">'.
img_edit().
'</a></td>';
3354 print
'</tr></table>';
3357 if ($action ==
'edittransportmode') {
3358 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->transport_mode_id,
'transport_mode_id', 1, 1);
3360 $form->formSelectTransportMode($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->transport_mode_id,
'none');
3367 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
3372 print
'<div class="fichehalfright">';
3373 print
'<div class="underbanner clearboth"></div>';
3375 print
'<table class="border tableforfield centpercent">';
3378 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
3379 print
'<td class="nowrap amountcard right">' .
price($object->total_ht,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
3380 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
3381 print
'<td class="nowrap amountcard right">' .
price($object->multicurrency_total_ht,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
3386 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
3387 print
'<td class="nowrap amountcard right">';
3388 if (
GETPOST(
'calculationrule')) {
3389 $calculationrule =
GETPOST(
'calculationrule',
'alpha');
3391 $calculationrule = (empty($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND) ?
'totalofround' :
'roundoftotal');
3393 if ($calculationrule ==
'totalofround') {
3394 $calculationrulenum = 1;
3396 $calculationrulenum = 2;
3399 if ($object->getVentilExportCompta() == 0) {
3400 $s =
'<span class="hideonsmartphone opacitymedium">' . $langs->trans(
"ReCalculate") .
' </span>';
3401 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'&action=calculate&calculationrule=totalofround">' . $langs->trans(
"Mode1") .
'</a>';
3403 $s .=
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'&action=calculate&calculationrule=roundoftotal">' . $langs->trans(
"Mode2") .
'</a>';
3404 print
'<div class="inline-block">';
3405 print $form->textwithtooltip($s, $langs->trans(
"CalculationRuleDesc", $calculationrulenum) .
'<br>' . $langs->trans(
"CalculationRuleDescSupplier"), 2, 1,
img_picto(
'',
'help'),
'', 3,
'', 0,
'recalculate');
3406 print
' ';
3409 print
price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency);
3411 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
3412 print
'<td class="nowrap amountcard right">' .
price($object->multicurrency_total_tva,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
3416 if ($societe->localtax1_assuj ==
"1") {
3418 print
'<td>' . $langs->transcountry(
"AmountLT1", $societe->country_code) .
'</td>';
3419 print
'<td class="nowrap amountcard right">' .
price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency) .
'</td>';
3422 if ($societe->localtax2_assuj ==
"1") {
3424 print
'<td>' . $langs->transcountry(
"AmountLT2", $societe->country_code) .
'</td>';
3425 print
'<td class="nowrap amountcard right">' .
price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency) .
'</td>';
3430 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
3431 print
'<td class="nowrap amountcard right">' .
price($object->total_ttc,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
3432 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
3433 print
'<td class="nowrap amountcard right">' .
price($object->multicurrency_total_ttc,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
3449 $nbrows = 9; $nbcols = 3;
3450 if (isModEnabled(
'project')) {
3453 if (isModEnabled(
"banque")) {
3454 $nbrows++; $nbcols++;
3456 if (isModEnabled(
'incoterm')) {
3459 if (isModEnabled(
"multicurrency")) {
3464 if ($societe->localtax1_assuj ==
"1") {
3467 if ($societe->localtax2_assuj ==
"1") {
3471 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
3472 $sql .=
' c.id as paiement_type, c.code as payment_code,';
3473 $sql .=
' pf.amount,';
3474 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
3475 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
3476 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
3477 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
3478 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
3479 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
3480 $sql .=
' WHERE pf.fk_facturefourn = '.((int) $object->id);
3481 $sql .=
' ORDER BY p.datep, p.tms';
3483 $result = $db->query($sql);
3485 $num = $db->num_rows($result);
3488 print
'<div class="div-table-responsive-no-min">';
3489 print
'<table class="noborder paymenttable centpercent">';
3490 print
'<tr class="liste_titre">';
3492 print
'<td>'.$langs->trans(
'Date').
'</td>';
3493 print
'<td>'.$langs->trans(
'Type').
'</td>';
3494 if (isModEnabled(
"banque")) {
3495 print
'<td class="right">'.$langs->trans(
'BankAccount').
'</td>';
3497 print
'<td class="right">'.$langs->trans(
'Amount').
'</td>';
3498 print
'<td width="18"> </td>';
3503 $objp = $db->fetch_object($result);
3505 $paymentstatic->id = $objp->rowid;
3506 $paymentstatic->datepaye = $db->jdate($objp->dp);
3507 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
3508 $paymentstatic->num_payment = $objp->num_payment;
3510 $paymentstatic->paiementcode = $objp->payment_code;
3511 $paymentstatic->type_code = $objp->payment_code;
3512 $paymentstatic->type_label = $objp->payment_type;
3514 print
'<tr class="oddeven">';
3515 print
'<td class="nowraponall">';
3516 print $paymentstatic->getNomUrl(1);
3518 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
'</td>';
3519 $s = $form->form_modes_reglement(
null, $objp->paiement_type,
'none',
'', 1, 0,
'', 1).
' '.$objp->num_payment;
3520 print
'<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).
'">';
3523 if (isModEnabled(
"banque")) {
3524 $bankaccountstatic->id = $objp->baid;
3525 $bankaccountstatic->ref = $objp->baref;
3526 $bankaccountstatic->label = $objp->baref;
3527 $bankaccountstatic->number = $objp->banumber;
3529 if (isModEnabled(
'accounting')) {
3530 $bankaccountstatic->account_number = $objp->account_number;
3533 $accountingjournal->fetch($objp->fk_accountancy_journal);
3534 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
3537 print
'<td class="right">';
3538 if ($objp->baid > 0) {
3539 print $bankaccountstatic->getNomUrl(1,
'transactions');
3543 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
3544 print
'<td class="center">';
3547 $paiementfourn->fetch($objp->rowid);
3549 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=deletepayment&token='.newToken().
'&paiement_id='.$objp->rowid.
'">';
3555 $totalpaid += $objp->amount;
3559 print
'<tr class="oddeven"><td colspan="'.$nbcols.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td><td></td><td></td></tr>';
3582 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3583 print
'<span class="opacitymedium">';
3585 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
3587 print $langs->trans(
'AlreadyPaid');
3590 print
'</td><td class="right"'.(($totalpaid > 0) ?
' class="amountalreadypaid"' :
'').
'>'.
price($totalpaid).
'</td><td> </td></tr>';
3593 $resteapayeraffiche = $resteapayer;
3595 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
3598 $creditnoteamount = 0;
3601 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
3602 $sql .=
" re.description, re.fk_invoice_supplier_source";
3603 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
3604 $sql .=
" WHERE fk_invoice_supplier = ".((int) $object->id);
3605 $resql = $db->query($sql);
3607 $num = $db->num_rows($resql);
3611 $obj = $db->fetch_object($resql);
3612 $invoice->fetch($obj->fk_invoice_supplier_source);
3613 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3615 print $langs->trans(
"CreditNote").
' ';
3618 print $langs->trans(
"Deposit").
' ';
3620 print $invoice->getNomUrl(0);
3622 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
3623 print
'<td class="right">';
3624 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=unlinkdiscount&discountid='.$obj->rowid.
'">';
3625 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
3630 $creditnoteamount += $obj->amount_ttc;
3633 $depositamount += $obj->amount_ttc;
3642 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3643 print
'<span class="opacitymedium">';
3644 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
3646 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3647 $resteapayeraffiche = 0;
3648 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3652 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3653 print
'<span class="opacitymedium">';
3654 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
3656 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3658 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3662 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3663 print
'<span class="opacitymedium">';
3664 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
3666 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3667 $resteapayeraffiche = 0;
3668 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3672 print
'<tr><td colspan="'.$nbcols.
'" class="right nowrap">';
3673 $text = $langs->trans(
"HelpAbandonOther");
3674 if ($object->close_note) {
3675 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.$object->close_note;
3677 print
'<span class="opacitymedium">';
3678 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
3680 print
'</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).
'</td><td> </td></tr>';
3681 $resteapayeraffiche = 0;
3682 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3686 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3687 print
'<span class="opacitymedium">';
3688 print $langs->trans(
"Billed");
3690 print
'</td><td class="right">'.price($object->total_ttc).
'</td><td> </td></tr>';
3693 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3694 print
'<span class="opacitymedium">';
3695 print $langs->trans(
'RemainderToPay');
3696 if ($resteapayeraffiche < 0) {
3697 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3701 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
3704 if (isModEnabled(
'multicurreny') && $object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3705 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3706 print
'<span class="opacitymedium">';
3707 print $langs->trans(
'RemainderToPayMulticurrency');
3708 if ($resteapayeraffiche < 0) {
3709 print
' ('.$langs->trans(
'NegativeIfExcessPaid').
')';
3713 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>';
3716 $cssforamountpaymentcomplete =
'amountpaymentneutral';
3719 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3720 print $langs->trans(
'AlreadyPaidBack');
3721 print
' :</td><td class="right">'.price($sign * $totalpaid).
'</td><td> </td></tr>';
3724 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"Billed").
' :</td><td class="right">'.
price($sign * $object->total_ttc).
'</td><td> </td></tr>';
3727 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3728 print
'<span class="opacitymedium">';
3729 print $langs->trans(
'RemainderToPayBack');
3730 if ($resteapayeraffiche > 0) {
3731 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3735 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td><td> </td></tr>';
3738 if (isModEnabled(
'multicurreny') && $object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3739 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
3740 print
'<span class="opacitymedium">';
3741 print $langs->trans(
'RemainderToPayBackMulticurrency');
3742 if ($resteapayeraffiche> 0) {
3743 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
3747 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>';
3762 print
'<div class="clearboth"></div><br>';
3764 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
3765 $blocname =
'contacts';
3766 $title = $langs->trans(
'ContactsAddresses');
3767 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3770 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
3772 $blocname =
'notes';
3773 $title = $langs->trans(
'Notes');
3774 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3781 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
3782 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3783 print
'<input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">';
3784 print
'<input type="hidden" name="mode" value="">';
3785 print
'<input type="hidden" name="page_y" value="">';
3786 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
3787 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
3788 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3791 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
3794 print
'<div class="div-table-responsive-no-min">';
3795 print
'<table id="tablelines" class="noborder noshadow centpercent">';
3797 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
3798 $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
3799 $senderissupplier = 2;
3801 if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
3802 $senderissupplier = 1;
3806 if (!empty($object->lines)) {
3807 $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
3810 $num = count($object->lines);
3814 if ($action !=
'editline') {
3817 $parameters = array();
3818 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
3819 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
3820 if (empty($reshook))
3821 $object->formAddObjectLine(1, $societe, $mysoc);
3832 if ($action !=
'presend') {
3837 print
'<div class="tabsAction">';
3839 $parameters = array();
3840 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
3842 if (empty($reshook)) {
3846 $ventilExportCompta = $object->getVentilExportCompta();
3848 if ($ventilExportCompta == 0) {
3849 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=edit&token='.newToken().
'">'.$langs->trans(
'Modify').
'</a>';
3851 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
3856 $result = $discount->fetch(0, 0, $object->id);
3863 if (!$objectidnext && $object->close_code !=
'replaced' && $usercancreate) {
3864 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=reopen&token='.newToken().
'">'.$langs->trans(
'ReOpen').
'</a>';
3866 if ($usercancreate) {
3867 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
3868 } elseif (empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
3869 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'ReOpen').
'</span>';
3876 if (count($object->lines)) {
3877 if ($usercanvalidate) {
3878 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid"';
3879 print
'>'.$langs->trans(
'Validate').
'</a>';
3881 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'"';
3882 print
'>'.$langs->trans(
'Validate').
'</a>';
3888 if (empty($user->socid)) {
3891 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
3893 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'SendMail').
'</span>';
3900 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>';
3907 if ($resteapayer == 0) {
3908 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
3910 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>';
3915 if ($object->type ==
FactureFournisseur::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) < 0 && $usercancreate && empty($discount->id)) {
3916 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertExcessPaidToReduc').
'</a>';
3920 && (!empty($conf->global->SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) || $object->getSommePaiement() == 0)
3922 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>';
3926 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertToReduc').
'</a>';
3934 ($object->type ==
FactureFournisseur::TYPE_DEPOSIT && $object->total_ttc > 0 && ($resteapayer == 0 || (!empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) && $object->total_ttc == $resteapayer)))
3937 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaid').
'</a>';
3941 if ($object->statut ==
FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && $resteapayer > 0 && (empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $object->total_ttc != $resteapayer)) {
3942 if ($totalpaid > 0 || $totalcreditnotes > 0) {
3944 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
3946 if (empty($conf->global->INVOICE_CAN_NEVER_BE_CANCELED)) {
3947 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
3960 if (!$objectidnext) {
3961 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>';
3966 if ($action !=
'edit' && $usercancreate) {
3967 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=clone&socid='.$object->socid.
'">'.$langs->trans(
'ToClone').
'</a>';
3972 if (!$objectidnext && count($object->lines) > 0) {
3973 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card-rec.php?facid='.$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
3978 $isErasable = $object->is_erasable();
3979 if ($action !=
'confirm_edit' && ($usercandelete || ($usercancreate && $isErasable == 1))) {
3980 $enableDelete =
false;
3982 $params = (empty($conf->use_javascript_ajax) ? array() : array(
'attr' => array(
'class' =>
'reposition')));
3984 if ($isErasable == -4) {
3985 $htmltooltip = $langs->trans(
"DisabledBecausePayments");
3986 } elseif ($isErasable == -3) {
3987 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastSituationInvoice");
3988 } elseif ($isErasable == -2) {
3989 $htmltooltip = $langs->trans(
"DisabledBecauseNotLastInvoice");
3990 } elseif ($isErasable == -1) {
3991 $htmltooltip = $langs->trans(
"DisabledBecauseDispatchedInBookkeeping");
3992 } elseif ($isErasable <= 0) {
3993 $htmltooltip = $langs->trans(
"DisabledBecauseNotErasable");
3995 $enableDelete =
true;
3998 print
dolGetButtonAction($htmltooltip, $langs->trans(
"Delete"),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.newToken(), $object->id, $enableDelete, $params);
4002 if ($action !=
'confirm_edit') {
4003 print
'<div class="fichecenter"><div class="fichehalfleft">';
4009 $subdir =
get_exdir($object->id, 2, 0, 0, $object,
'invoice_supplier').$ref;
4010 $filedir = $conf->fournisseur->facture->dir_output.
'/'.$subdir;
4011 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.$object->id;
4012 $genallowed = $usercanread;
4013 $delallowed = $usercancreate;
4014 $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF) ?
'' : $conf->global->INVOICE_SUPPLIER_ADDON_PDF));
4016 print $formfile->showdocuments(
'facture_fournisseur', $subdir, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
4017 $somethingshown = $formfile->numoffiles;
4020 $linktoelem = $form->showLinkToObjectBlock($object,
null, array(
'invoice_supplier'));
4021 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
4023 print
'</div><div class="fichehalfright">';
4026 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
4028 $somethingshown =
$formactions->showactions($object,
'invoice_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
4030 print
'</div></div>';
4036 if (
GETPOST(
'modelselected')) {
4037 $action =
'presend';
4041 $modelmail =
'invoice_supplier_send';
4042 $defaulttopic =
'SendBillRef';
4043 $diroutput = $conf->fournisseur->facture->dir_output;
4044 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
4045 $trackid =
'sinv'.$object->id;
4047 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 accounts.
const TYPE_SITUATION
Situation invoice.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_STANDARD
Standard invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const STATUS_CLOSED
Classified paid.
Class to manage invoice templates.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage payments for supplier invoices.
Class ProductCombination Used to represent a product combination.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
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 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.
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.
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.