44require
'../../main.inc.php';
45require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
55require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
56require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
57require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
58if (isModEnabled(
'order')) {
59 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
61if (isModEnabled(
'project')) {
62 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
63 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
65require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
67if (isModEnabled(
'variants')) {
68 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
70if (isModEnabled(
'accounting')) {
71 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
75$langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
76if (isModEnabled(
'incoterm')) {
77 $langs->load(
'incoterm');
79if (isModEnabled(
'margin')) {
80 $langs->load(
'margins');
87$action =
GETPOST(
'action',
'aZ09');
88$confirm =
GETPOST(
'confirm',
'alpha');
89$cancel =
GETPOST(
'cancel',
'alpha');
90$backtopage =
GETPOST(
'backtopage',
'alpha');
91$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
94$search_ref =
GETPOST(
'sf_ref',
'alpha') ?
GETPOST(
'sf_ref',
'alpha') :
GETPOST(
'search_ref',
'alpha');
95$search_societe =
GETPOST(
'search_societe',
'alpha');
96$search_montant_ht =
GETPOST(
'search_montant_ht',
'alpha');
97$search_montant_ttc =
GETPOST(
'search_montant_ttc',
'alpha');
98$origin =
GETPOST(
'origin',
'alpha');
102$ref_client =
GETPOST(
'ref_client',
'alpha');
105$selectedLines =
GETPOST(
'toselect',
'array');
121$extrafields->fetch_name_optionals_label(
$object->table_element);
124if ($id > 0 || !empty($ref)) {
125 if ($action !=
'add') {
127 $fetch_situation =
false;
129 $fetch_situation =
true;
131 $ret =
$object->fetch($id, $ref,
'', 0, $fetch_situation);
132 if ($ret > 0 && isset(
$object->fk_project)) {
133 $ret =
$object->fetch_project();
139$hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
142$usercanread = $user->hasRight(
"facture",
"lire");
143$usercancreate = $user->hasRight(
"facture",
"creer");
144$usercanissuepayment = $user->hasRight(
"facture",
"paiement");
145$usercandelete = $user->hasRight(
"facture",
"supprimer") || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
146$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
149$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'validate')));
151$usercanreopen = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'reopen')));
153 $usercanreopen =
false;
155$usercanunvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'unvalidate')));
156$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
159$usercancreatemargin = $user->hasRight(
'margins',
'creer');
160$usercanreadallmargin = $user->hasRight(
'margins',
'liretous');
161$usercancreatewithdrarequest = $user->hasRight(
'prelevement',
'bons',
'creer');
163$permissionnote = $usercancreate;
164$permissiondellink = $usercancreate;
165$permissiontoedit = $usercancreate;
166$permissiontoadd = $usercancreate;
169$retainedWarrantyInvoiceAvailableType = array();
171 $retainedWarrantyInvoiceAvailableType = explode(
'+',
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY'));
176 $socid = $user->socid;
187$parameters = array(
'socid' => $socid);
188$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
193if (empty($reshook)) {
194 $backurlforlist = DOL_URL_ROOT.
'/compta/facture/list.php';
196 if (empty($backtopage) || ($cancel && empty($id))) {
197 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
198 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
199 $backtopage = $backurlforlist;
201 $backtopage = DOL_URL_ROOT.
'/compta/facture/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
207 if (!empty($backtopageforcancel)) {
208 header(
"Location: ".$backtopageforcancel);
210 } elseif (!empty($backtopage)) {
211 header(
"Location: ".$backtopage);
217 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
219 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
221 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
224 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
226 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'IdThirdParty')),
null,
'errors');
229 '@phan-var-force Facture $objectutil';
232 $objectutil->socid = $socid;
233 $result = $objectutil->createFromClone($user, $id);
235 $warningMsgLineList = array();
237 foreach ($objectutil->lines as $line) {
238 if (!is_object($line->product)) {
239 $line->fetch_product();
241 if (is_object($line->product) && $line->product->id > 0) {
242 if (empty($line->product->status)) {
243 $warningMsgLineList[$line->id] = $langs->trans(
'WarningLineProductNotToSell', $line->product->ref);
247 if (!empty($warningMsgLineList)) {
251 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?facid=' . $result);
254 $langs->load(
"errors");
259 } elseif ($action ==
'reopen' && $usercanreopen) {
263 $result =
$object->setUnpaid($user);
265 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
271 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
276 $idwarehouse =
GETPOST(
'idwarehouse');
278 $qualified_for_stock_change = 0;
280 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
282 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
285 $isErasable =
$object->is_erasable();
287 if (($usercandelete && $isErasable > 0)
288 || ($usercancreate && $isErasable == 1)) {
289 $result =
$object->delete($user, 0, $idwarehouse);
291 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
298 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
308 $outputlangs = $langs;
314 $newlang =
$object->thirdparty->default_lang;
316 if (!empty($newlang)) {
318 $outputlangs->setDefaultLang($newlang);
319 $outputlangs->load(
'products');
323 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
326 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
333 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
336 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
337 $discount->unlink_invoice();
338 } elseif ($action ==
'valid' && $usercancreate) {
342 if ((preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) &&
349 $last_of_type =
$object->willBeLastOfSameType(
true);
350 if (empty(
$object->date_validation) && !$last_of_type[0]) {
360 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
369 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
378 $array_of_total_ht_per_vat_rate = array();
379 $array_of_total_ht_devise_per_vat_rate = array();
380 foreach (
$object->lines as $line) {
382 $vat_src_code_for_line =
'';
383 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
384 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
386 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
387 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
389 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
390 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
394 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
395 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
396 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
398 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
399 if (
$object->type == $object::TYPE_DEPOSIT) {
400 $langs->load(
"errors");
402 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
406 $tmpvatratetoshow = explode(
'_', $vatrate);
407 $tmpvatratetoshow[0] = round((
float) $tmpvatratetoshow[0], 2);
409 if ($tmpvatratetoshow[0] != 0) {
410 $langs->load(
"errors");
411 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", $tmpvatratetoshow[0]),
null,
'errors');
419 } elseif ($action ==
'classin' && $usercancreate) {
422 } elseif ($action ==
'setmode' && $usercancreate) {
428 } elseif ($action ==
'setretainedwarrantyconditions' && $usercancreate) {
430 $object->retained_warranty_fk_cond_reglement = 0;
431 $result =
$object->setRetainedWarrantyPaymentTerms(
GETPOSTINT(
'retained_warranty_fk_cond_reglement'));
436 $old_rw_date_lim_reglement =
$object->retained_warranty_date_limit;
437 $new_rw_date_lim_reglement =
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
438 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
439 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
444 $result =
$object->update($user);
448 } elseif ($action ==
'setretainedwarranty' && $usercancreate) {
454 } elseif ($action ==
'setretainedwarrantydatelimit' && $usercancreate) {
456 $result =
$object->setRetainedWarrantyDateLimit(
GETPOSTFLOAT(
'retained_warranty_date_limit'));
460 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
461 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
462 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
464 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
466 $old_date_lim_reglement =
$object->date_lim_reglement;
468 if (empty($newdate)) {
469 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
470 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id.
'&action=editinvoicedate&token='.
newToken());
475 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
477 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
482 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
483 if ($new_date_lim_reglement) {
484 $object->date_lim_reglement = $new_date_lim_reglement;
489 $result =
$object->update($user);
492 $action =
'editinvoicedate';
494 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
499 $object->date_pointoftax = $date_pointoftax;
500 $result =
$object->update($user);
504 } elseif ($action ==
'setconditions' && $usercancreate) {
506 $object->cond_reglement_code = 0;
507 $object->cond_reglement_id = 0;
522 $old_date_lim_reglement =
$object->date_lim_reglement;
523 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
524 if ($new_date_lim_reglement) {
525 $object->date_lim_reglement = $new_date_lim_reglement;
530 $result =
$object->update($user);
542 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
546 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
547 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
549 $result =
$object->update($user);
553 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
556 $result =
$object->update($user);
563 $outputlangs = $langs;
566 $newlang =
GETPOST(
'lang_id',
'aZ09');
569 $newlang =
$object->thirdparty->default_lang;
571 if (!empty($newlang)) {
573 $outputlangs->setDefaultLang($newlang);
574 $outputlangs->load(
'products');
579 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
585 } elseif ($action ==
'set_incoterms' && isModEnabled(
'incoterm') && $usercancreate) {
587 } elseif ($action ==
'setbankaccount' && $usercancreate) {
589 } elseif ($action ==
'setremisepercent' && $usercancreate) {
592 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
610 if (
GETPOSTINT(
"remise_id_for_payment") > 0) {
611 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
613 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
617 $remaintopay =
$object->getRemainToPay(0);
621 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
625 $result = $discount->link_to_invoice(0, $id);
633 $newremaintopay =
$object->getRemainToPay(0);
634 if ($newremaintopay == 0) {
647 $outputlangs = $langs;
650 $newlang =
GETPOST(
'lang_id',
'aZ09');
654 $newlang =
$object->thirdparty->default_lang;
656 if (!empty($newlang)) {
658 $outputlangs->setDefaultLang($newlang);
662 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
667 } elseif ($action ==
'setref' && $usercancreate) {
669 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', 0,
'',
'', $user,
'BILL_MODIFY');
670 } elseif ($action ==
'setref_client' && $usercancreate) {
673 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
682 $qualified_for_stock_change = 0;
684 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
686 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
689 if ($qualified_for_stock_change) {
690 if (!$idwarehouse || $idwarehouse == - 1) {
692 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
699 $result =
$object->validate($user,
'', $idwarehouse);
703 $outputlangs = $langs;
706 $newlang =
GETPOST(
'lang_id',
'aZ09');
709 $newlang =
$object->thirdparty->default_lang;
711 if (!empty($newlang)) {
713 $outputlangs->setDefaultLang($newlang);
714 $outputlangs->load(
'products');
720 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
733 } elseif ($action ==
'confirm_modif' && $usercanunvalidate) {
742 $qualified_for_stock_change = 0;
744 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
746 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
749 if ($qualified_for_stock_change) {
750 if (!$idwarehouse || $idwarehouse == - 1) {
752 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
761 $sql =
'SELECT pf.amount';
762 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf';
763 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
765 $result = $db->query($sql);
768 $num = $db->num_rows($result);
771 $objp = $db->fetch_object($result);
772 $totalpaid += $objp->amount;
779 $resteapayer =
$object->total_ttc - $totalpaid;
782 $ventilExportCompta =
$object->getVentilExportCompta();
785 if ($ventilExportCompta == 0) {
787 $result =
$object->setDraft($user, $idwarehouse);
794 $outputlangs = $langs;
797 $newlang =
GETPOST(
'lang_id',
'aZ09');
800 $newlang =
$object->thirdparty->default_lang;
802 if (!empty($newlang)) {
804 $outputlangs->setDefaultLang($newlang);
805 $outputlangs->load(
'products');
810 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
815 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
818 $result =
$object->setPaid($user);
822 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
825 $close_code =
GETPOST(
"close_code",
'restricthtml');
826 $close_note =
GETPOST(
"close_note",
'restricthtml');
828 $result =
$object->setPaid($user, $close_code, $close_note);
833 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
835 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
838 $close_code =
GETPOST(
"close_code",
'restricthtml');
839 $close_note =
GETPOST(
"close_note",
'restricthtml');
841 $result =
$object->setCanceled($user, $close_code, $close_note);
846 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
848 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
856 $result = $discountcheck->fetch(0,
$object->id);
869 $amount_ht = $amount_tva = $amount_ttc = array();
870 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
874 foreach (
$object->lines as $line) {
875 if ($line->product_type < 9 && $line->total_ht != 0) {
876 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
878 if (!isset($amount_ht[$keyforvatrate])) {
879 $amount_ht[$keyforvatrate]=0;
881 $amount_ht[$keyforvatrate] += $line->total_ht;
882 if (!isset($amount_tva[$keyforvatrate])) {
883 $amount_tva[$keyforvatrate]=0;
885 $amount_tva[$keyforvatrate] += $line->total_tva;
886 if (!isset($amount_ttc[$keyforvatrate])) {
887 $amount_ttc[$keyforvatrate]=0;
889 $amount_ttc[$keyforvatrate] += $line->total_ttc;
890 if (!isset($multicurrency_amount_ht[$keyforvatrate])) {
891 $multicurrency_amount_ht[$keyforvatrate]=0;
893 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
894 if (!isset($multicurrency_amount_tva[$keyforvatrate])) {
895 $multicurrency_amount_tva[$keyforvatrate]=0;
897 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
898 if (!isset($multicurrency_amount_ttc[$keyforvatrate])) {
899 $multicurrency_amount_ttc[$keyforvatrate]=0;
901 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
905 '@phan-var-force array<string,float> $amount_ht
906 @phan-var-force array<string,float> $amount_tva
907 @phan-var-force array<string,float> $amount_ttc
908 @phan-var-force array<string,float> $multicurrency_amount_ht
909 @phan-var-force array<string,float> $multicurrency_amount_tva
910 @phan-var-force array<string,float> $multicurrency_amount_ttc';
914 $alreadypaid =
$object->getSommePaiement();
915 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
916 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
917 foreach ($amount_ht as $vatrate => $val) {
918 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
919 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
920 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
921 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
922 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
923 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
932 $discount->description =
'(CREDIT_NOTE)';
934 $discount->description =
'(DEPOSIT)';
936 $discount->description =
'(EXCESS RECEIVED)';
938 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
940 $discount->fk_soc =
$object->socid;
941 $discount->socid =
$object->socid;
942 $discount->fk_facture_source =
$object->id;
950 $sql =
'SELECT SUM(pf.amount) as total_paiements';
951 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
952 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
953 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
954 $sql .=
' AND pf.fk_paiement = p.rowid';
955 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
956 $resql = $db->query($sql);
961 $res = $db->fetch_object($resql);
962 $total_paiements = $res->total_paiements;
965 $total_creditnote_and_deposit = 0;
966 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
967 $sql .=
" re.description, re.fk_facture_source";
968 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
969 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
970 $resql = $db->query($sql);
971 if (!empty($resql)) {
972 while ($obj = $db->fetch_object($resql)) {
973 $total_creditnote_and_deposit += $obj->amount_ttc;
979 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit -
$object->total_ttc;
980 $discount->amount_tva = 0;
981 $discount->tva_tx = 0;
982 $discount->vat_src_code =
'';
984 $result = $discount->create($user);
990 foreach ($amount_ht as $tva_tx => $xxx) {
991 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
992 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
993 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
994 $discount->multicurrency_amount_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
995 $discount->multicurrency_amount_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
996 $discount->multicurrency_amount_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1001 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
1002 $vat_src_code = $reg[1];
1003 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
1006 $discount->tva_tx = abs((
float) $tva_tx);
1007 $discount->vat_src_code = $vat_src_code;
1009 $result = $discount->create($user);
1017 if (empty($error)) {
1020 $result =
$object->setPaid($user);
1035 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
1040 $result = $paiement->fetch(
GETPOSTINT(
'paiement_id'));
1042 $result = $paiement->delete($user);
1044 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1052 } elseif ($action ==
'add' && $usercancreate) {
1059 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1065 $originentity =
GETPOST(
'originentity');
1067 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
1077 if (empty($dateinvoice)) {
1079 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1089 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1099 $object->date_pointoftax = $date_pointoftax;
1100 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1101 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1112 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1113 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1120 $id =
$object->createFromCurrent($user);
1130 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1132 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1136 if (empty($dateinvoice)) {
1138 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1148 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1153 if (!empty($originentity)) {
1154 $object->entity = $originentity;
1160 $object->date_pointoftax = $date_pointoftax;
1161 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1162 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1167 $object->cond_reglement_id = 0;
1173 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1174 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1178 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1181 $facture_source =
new Facture($db);
1182 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1184 $object->situation_counter = $facture_source->situation_counter;
1185 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1186 $facture_source->fetchPreviousNextSituationInvoice();
1196 if (
$object->copy_linked_contact($facture_source,
'internal') < 0) {
1198 } elseif ($facture_source->socid ==
$object->socid) {
1200 if (
$object->copy_linked_contact($facture_source,
'external') < 0) {
1211 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1212 if (!empty($facture_source->lines)) {
1213 $fk_parent_line = 0;
1215 foreach ($facture_source->lines as $line) {
1217 if (method_exists($line,
'fetch_optionals')) {
1219 $line->fetch_optionals();
1223 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1224 $fk_parent_line = 0;
1229 $source_fk_prev_id = $line->fk_prev_id;
1230 $line->fk_prev_id = $line->id;
1232 if (!empty($facture_source->tab_previous_situation_invoice)) {
1235 $tab_jumped_credit_notes = array();
1236 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1237 $searchPreviousInvoice =
true;
1238 while ($searchPreviousInvoice) {
1239 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1240 $searchPreviousInvoice =
false;
1244 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1250 $maxPrevSituationPercent = 0;
1251 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1252 if ($prevLine->id == $source_fk_prev_id) {
1253 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1256 $line->total_ht -= $prevLine->total_ht;
1257 $line->total_tva -= $prevLine->total_tva;
1258 $line->total_ttc -= $prevLine->total_ttc;
1259 $line->total_localtax1 -= $prevLine->total_localtax1;
1260 $line->total_localtax2 -= $prevLine->total_localtax2;
1262 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1263 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1264 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1265 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1270 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1275 $maxPrevSituationPercent = 0;
1276 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1277 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1278 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1279 $maxPrevSituationPercent = $prevLine->situation_percent;
1281 $line->total_ht -= $prevLine->total_ht;
1282 $line->total_tva -= $prevLine->total_tva;
1283 $line->total_ttc -= $prevLine->total_ttc;
1284 $line->total_localtax1 -= $prevLine->total_localtax1;
1285 $line->total_localtax2 -= $prevLine->total_localtax2;
1287 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1288 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1289 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1290 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1296 $line->situation_percent += $maxPrevSituationPercent;
1302 $line->fk_facture =
$object->id;
1303 $line->fk_parent_line = $fk_parent_line;
1305 $line->subprice = -$line->subprice;
1307 $line->total_ht = -$line->total_ht;
1308 $line->total_tva = -$line->total_tva;
1309 $line->total_ttc = -$line->total_ttc;
1310 $line->total_localtax1 = -$line->total_localtax1;
1311 $line->total_localtax2 = -$line->total_localtax2;
1313 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1314 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1315 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1316 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1318 $line->context[
'createcreditnotefrominvoice'] = 1;
1319 $result = $line->insert(0, 1);
1324 if ($result > 0 && $line->product_type == 9) {
1325 $fk_parent_line = $result;
1333 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1334 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1335 $totalpaid = $facture_source->getSommePaiement();
1336 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1337 $totaldeposits = $facture_source->getSumDepositsUsed();
1338 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1340 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1341 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1344 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1349 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1350 $tva_tx = (float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY');
1355 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC');
1360 if (!empty(
$object->fk_facture_source) && $id > 0) {
1361 $facture_source->fetch(
$object->fk_facture_source);
1362 $facture_source->fetchObjectLinked();
1364 if (!empty($facture_source->linkedObjectsIds)) {
1365 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1366 $object->add_object_linked($sourcetype, current($TIds));
1375 if (empty($dateinvoice)) {
1377 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1388 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1398 $object->date_pointoftax = $date_pointoftax;
1399 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1400 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1412 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1413 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1425 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1426 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1427 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1431 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1435 if (empty($dateinvoice)) {
1437 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1447 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1448 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1453 if ($typeamount && !empty($origin) && !empty($originid)) {
1454 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1455 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1459 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1460 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1464 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1465 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1475 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1485 $object->date_pointoftax = $date_pointoftax;
1486 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1487 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1499 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1500 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1504 $object->situation_counter = 1;
1509 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1511 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1513 $object->retained_warranty = 0;
1514 $object->retained_warranty_fk_cond_reglement = 0;
1517 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1518 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1521 $object->retained_warranty_date_limit = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit :
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
1526 if (!empty($origin) && !empty($originid)) {
1529 $element = $subelement = $origin;
1530 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1531 $element = $regs[1];
1532 $subelement = $regs[2];
1536 if ($element ==
'order') {
1537 $element = $subelement =
'commande';
1539 if ($element ==
'propal') {
1540 $element =
'comm/propal';
1541 $subelement =
'propal';
1543 if ($element ==
'contract') {
1544 $element = $subelement =
'contrat';
1546 if ($element ==
'inter') {
1547 $element = $subelement =
'ficheinter';
1549 if ($element ==
'shipping') {
1550 $element = $subelement =
'expedition';
1554 $object->origin_type = $origin;
1555 $object->origin_id = $originid;
1560 if (
$object->origin ==
'shipping') {
1561 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1563 $exp->fetch(
$object->origin_id);
1564 $exp->fetchObjectLinked();
1565 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1566 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1567 $object->linked_objects[
'commande'] = $value;
1573 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
1581 $classname = ucfirst($subelement);
1582 $srcobject =
new $classname($db);
1583 '@phan-var-force CommonObject $srcobject';
1585 dol_syslog(
"Try to find source object origin=".
$object->origin.
" originid=".
$object->origin_id.
" to add lines or deposit lines");
1586 $result = $srcobject->fetch(
$object->origin_id);
1591 $amountdeposit = array();
1593 if ($typeamount ==
'amount') {
1594 $amount = (float) $valuedeposit;
1596 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1599 $TTotalByTva = array();
1600 foreach ($srcobject->lines as &$line) {
1601 if (!empty($line->special_code)) {
1604 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1606 '@phan-var-force array<string,float> $TTotalByTva';
1608 $amount_ttc_diff = 0.;
1609 foreach ($TTotalByTva as $tva => &$total) {
1610 if (empty($amountdeposit[$tva])) {
1611 $amountdeposit[$tva] = 0;
1613 $coef = $total / $srcobject->total_ttc;
1614 $am = $amount * $coef;
1615 $amount_ttc_diff += $am;
1616 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1619 if ($typeamount ==
'amount') {
1620 $amountdeposit[0] = $valuedeposit;
1621 } elseif ($typeamount ==
'variable') {
1624 $lines = $srcobject->lines;
1625 $numlines = count($lines);
1626 for ($i = 0; $i < $numlines; $i++) {
1628 if (empty($lines[$i]->qty)) {
1631 if (!empty($lines[$i]->special_code)) {
1635 $totalamount += $lines[$i]->total_ht;
1636 $tva_tx = $lines[$i]->tva_tx;
1638 if (empty($amountdeposit[$tva_tx])) {
1639 $amountdeposit[$tva_tx] = 0;
1641 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1645 if ($totalamount == 0) {
1646 $amountdeposit[0] = 0;
1654 $amount_ttc_diff = $amountdeposit[0];
1657 foreach ($amountdeposit as $tva => $amount) {
1658 if (empty($amount)) {
1663 'amount' =>
'FixAmount',
1664 'variable' =>
'VarAmount'
1666 $descline =
'(DEPOSIT)';
1668 if ($typeamount ==
'amount') {
1669 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code : $conf->currency)).
')';
1670 } elseif ($typeamount ==
'variable') {
1671 $descline .=
' ('.$valuedeposit.
'%)';
1674 $descline .=
' - '.$srcobject->ref;
1687 $lines[$i]->info_bits,
1693 $lines[$i]->special_code,
1706 (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) ? 0 : 1)
1710 $diff =
$object->total_ttc - $amount_ttc_diff;
1714 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1715 $object->updateline(
$object->lines[0]->id,
$object->lines[0]->desc, $subprice_diff,
$object->lines[0]->qty,
$object->lines[0]->remise_percent,
$object->lines[0]->date_start,
$object->lines[0]->date_end,
$object->lines[0]->tva_tx, 0, 0,
'HT',
$object->lines[0]->info_bits,
$object->lines[0]->product_type, 0, 0, 0,
$object->lines[0]->pa_ht,
$object->lines[0]->label, 0, array(), 100);
1722 $lines = $srcobject->lines;
1723 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1724 $srcobject->fetch_lines();
1725 $lines = $srcobject->lines;
1730 if (is_array($lines)) {
1731 foreach ($lines as $line) {
1733 $line->qty =
price2num((
float) $line->qty * (
float) $valuestandardinvoice / 100,
'MS');
1739 if (is_array($lines)) {
1740 foreach ($lines as $line) {
1742 $line->qty =
price2num((
float) $line->qty * (
float) $valuedeposit / 100,
'MS');
1747 $fk_parent_line = 0;
1748 $num = count($lines);
1750 for ($i = 0; $i < $num; $i++) {
1751 if (!in_array($lines[$i]->
id, $selectedLines)) {
1756 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
1760 if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1761 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1763 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->
statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
1767 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1768 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1770 if (
$object->situation_counter == 1) {
1771 $lines[$i]->situation_percent = 0;
1774 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
1777 $desc = $label ? $label : $langs->trans(
'Discount');
1781 $discount->fk_soc =
$object->socid;
1782 $discount->socid =
$object->socid;
1783 $discount->amount_ht = abs($lines[$i]->total_ht);
1784 $discount->amount_tva = abs($lines[$i]->total_tva);
1785 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1786 $discount->tva_tx = $lines[$i]->tva_tx;
1787 $discount->fk_user = $user->id;
1788 $discount->description = $desc;
1789 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1790 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1791 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1792 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1794 $discountid = $discount->create($user);
1795 if ($discountid > 0) {
1796 $result =
$object->insert_discount($discountid);
1808 $date_start =
false;
1809 if (isset($lines[$i]->date_debut_prevue)) {
1810 $date_start = $lines[$i]->date_debut_prevue;
1812 if (isset($lines[$i]->date_debut_reel)) {
1813 $date_start = $lines[$i]->date_debut_reel;
1815 if (isset($lines[$i]->date_start)) {
1816 $date_start = $lines[$i]->date_start;
1821 if (isset($lines[$i]->date_fin_prevue)) {
1822 $date_end = $lines[$i]->date_fin_prevue;
1824 if (isset($lines[$i]->date_fin_reel)) {
1825 $date_end = $lines[$i]->date_fin_reel;
1827 if (isset($lines[$i]->date_end)) {
1828 $date_end = $lines[$i]->date_end;
1832 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1833 $fk_parent_line = 0;
1837 if (method_exists($lines[$i],
'fetch_optionals')) {
1838 $lines[$i]->fetch_optionals();
1839 $array_options = $lines[$i]->array_options;
1842 $tva_tx = $lines[$i]->tva_tx;
1843 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
1844 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1854 $lines[$i]->subprice,
1859 $lines[$i]->fk_product,
1860 $lines[$i]->remise_percent,
1864 $lines[$i]->info_bits,
1865 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except : null,
1870 $lines[$i]->special_code,
1874 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice : null,
1878 $lines[$i]->situation_percent ?? 100,
1879 $lines[$i]->fk_prev_id ?? 0,
1880 $lines[$i]->fk_unit,
1895 if ($result > 0 && $lines[$i]->product_type == 9) {
1896 $fk_parent_line = $result;
1906 $object->update_price(1,
'auto', 0, $mysoc);
1934 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id,
'objFrom' => $srcobject);
1935 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
1948 for ($i = 1; $i <= $NBLINES; $i++) {
1954 $result =
$object->addline($product->description, $product->price,
price2num(
GETPOST(
'qty'.$i),
'MS'), $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx,
GETPOSTINT(
'idprod'.$i),
price2num(
GETPOST(
'remise_percent'.$i),
'', 2), $startday, $endday, 0, 0, 0, $product->price_base_type, $product->price_ttc, $product->type, -1, 0,
'', 0, 0, 0, 0,
'', array(), 100, 0, $product->fk_unit, 0,
'', 1);
1958 $object->update_price(1,
'auto', 0, $mysoc);
1965 if (empty($dateinvoice)) {
1967 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
1977 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
1987 if (!empty($origin) && !empty($originid)) {
1988 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1991 $object->origin_type = $origin;
1992 $object->origin_id = $originid;
1996 $retained_warranty =
GETPOSTINT(
'retained_warranty');
1997 if (
price2num($retained_warranty) > 0) {
2001 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
2002 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
2005 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
2006 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
2007 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
2009 $object->retained_warranty_date_limit = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit :
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
2012 foreach (
$object->lines as $i => &$line) {
2013 $line->fk_prev_id = $line->id;
2014 $line->fetch_optionals();
2016 $line->situation_percent = 0;
2018 $line->situation_percent = $line->get_prev_progress(
$object->id);
2022 $tabprice =
calcul_price_total($line->qty, $line->subprice, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 0,
'HT', 0, $line->product_type, $mysoc, array(), $line->situation_percent);
2023 $line->total_ht = $tabprice[0];
2024 $line->total_tva = $tabprice[1];
2025 $line->total_ttc = $tabprice[2];
2026 $line->total_localtax1 = $tabprice[9];
2027 $line->total_localtax2 = $tabprice[10];
2028 $line->multicurrency_total_ht = $tabprice[16];
2029 $line->multicurrency_total_tva = $tabprice[17];
2030 $line->multicurrency_total_ttc = $tabprice[18];
2033 if ($line->fk_remise_except) {
2035 $result = $discount->fetch($line->fk_remise_except);
2038 if ($discount->fk_facture_line > 0) {
2039 $line->fk_remise_except = 0;
2048 $object->date_pointoftax = $date_pointoftax;
2049 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2065 $object->situation_counter += 1;
2067 $id =
$object->createFromCurrent($user);
2071 $nextSituationInvoice =
new Facture($db);
2072 $nextSituationInvoice->fetch($id);
2075 $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
2076 $ret = $extrafields->setOptionalsFromPost(
null, $nextSituationInvoice);
2078 $nextSituationInvoice->insertExtraFields();
2082 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id);
2083 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $nextSituationInvoice, $action);
2094 if ($id > 0 && !$error) {
2099 $outputlangs = $langs;
2102 $newlang =
GETPOST(
'lang_id',
'aZ09');
2105 $newlang =
$object->thirdparty->default_lang;
2107 if (!empty($newlang)) {
2108 $outputlangs =
new Translate(
"", $conf);
2109 $outputlangs->setDefaultLang($newlang);
2110 $outputlangs->load(
'products');
2115 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2121 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2126 $_GET[
"origin"] = $_POST[
"origin"];
2127 $_GET[
"originid"] = $_POST[
"originid"];
2130 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2134 foreach (
$object->lines as $line) {
2135 if ($line->product_type == 1) {
2136 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $alldate_start, $alldate_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx,
'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice);
2139 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2141 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2142 $vat_rate = str_replace(
'*',
'', $vat_rate);
2145 foreach (
$object->lines as $line) {
2146 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $vat_rate, $localtax1_rate, $localtax2_rate,
'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice);
2148 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2150 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2151 $remise_percent = str_replace(
'*',
'', $remise_percent);
2152 foreach (
$object->lines as $line) {
2153 $tvatx= $line->tva_tx;
2154 if (!empty($line->vat_src_code)) {
2155 $tvatx .=
' ('.$line->vat_src_code.
')';
2157 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $remise_percent, $line->date_start, $line->date_end, $tvatx, $line->localtax1_tx, $line->localtax2_tx,
'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice);
2159 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && $usercancreate) {
2160 $langs->load(
'errors');
2165 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
2168 $price_ht_devise =
'';
2170 $price_ttc_devise =
'';
2172 $price_min_ttc =
'';
2174 if (
GETPOST(
'price_ht') !==
'') {
2177 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2180 if (
GETPOST(
'price_ttc') !==
'') {
2183 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2184 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2187 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2188 if ($prod_entry_mode ==
'free') {
2194 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2199 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2202 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
2203 if (empty($remise_percent)) {
2204 $remise_percent = 0;
2208 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2209 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2211 if (is_array($extralabelsline)) {
2213 foreach ($extralabelsline as $key => $value) {
2214 unset($_POST[
"options_".$key.$predef]);
2218 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2219 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2222 if (!$prod_entry_mode) {
2224 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2228 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2229 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2232 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && (($price_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht ==
'') && (($price_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ==
'') && $price_ttc ===
'' && $price_ttc_devise ===
'' &&
$object->type !=
Facture::TYPE_CREDIT_NOTE) {
2233 if (($price_ht < 0 || $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2234 $langs->load(
"errors");
2235 if (
$object->type == $object::TYPE_DEPOSIT) {
2237 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2239 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2243 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2248 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2251 if ($prod_entry_mode ==
'free' && empty($idprod) && empty($product_desc)) {
2252 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2256 $langs->load(
"errors");
2257 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2261 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2262 if ($combinations =
GETPOST(
'combinations',
'array')) {
2266 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2267 $idprod = $res->fk_product_child;
2269 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2275 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
2281 $ret =
$object->fetch_thirdparty();
2286 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2297 if (!empty($idprod) && $idprod > 0) {
2299 $prod->fetch($idprod);
2301 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2306 $datapriceofproduct = $prod->getSellPrice($mysoc,
$object->thirdparty, $pqp);
2308 $pu_ht = $datapriceofproduct[
'pu_ht'];
2309 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2310 $price_min = $datapriceofproduct[
'price_min'];
2311 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2312 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2316 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2317 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $prod->tva_tx));
2321 if (!empty($price_ht) || $price_ht ===
'0') {
2323 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2324 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2325 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2328 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2330 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2331 } elseif ($tmpvat != $tmpprodvat) {
2333 if ($price_base_type !=
'HT') {
2334 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2336 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2344 $outputlangs = $langs;
2346 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
2347 $newlang =
GETPOST(
'lang_id',
'aZ09');
2349 if (empty($newlang)) {
2350 $newlang =
$object->thirdparty->default_lang;
2352 if (!empty($newlang)) {
2353 $outputlangs =
new Translate(
"", $conf);
2354 $outputlangs->setDefaultLang($newlang);
2355 $outputlangs->load(
'products');
2358 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->
description;
2360 $desc = $prod->description;
2369 $desc = $product_desc;
2375 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
2379 $outputlangs = $langs;
2381 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
2382 $newlang =
GETPOST(
'lang_id',
'alpha');
2384 if (empty($newlang)) {
2385 $newlang =
$object->thirdparty->default_lang;
2387 if (!empty($newlang)) {
2388 $outputlangs =
new Translate(
"", $conf);
2389 $outputlangs->setDefaultLang($newlang);
2390 $outputlangs->load(
'products');
2392 if (!empty($prod->customcode)) {
2393 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2395 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2398 if (!empty($prod->country_code)) {
2399 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
2402 if (!empty($prod->customcode)) {
2403 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2405 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2408 if (!empty($prod->country_code)) {
2409 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
2416 $type = $prod->type;
2417 $fk_unit = $prod->fk_unit;
2419 if (!empty($price_ht)) {
2424 if (!empty($price_ttc)) {
2429 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2430 $tva_tx = str_replace(
'*',
'', $tva_tx);
2431 if (empty($tva_tx)) {
2434 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2435 $desc = $product_desc;
2437 $fk_unit =
GETPOST(
'units',
'alpha');
2439 if ($pu_ttc && !$pu_ht) {
2440 $price_base_type =
'TTC';
2454 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2455 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2458 $pu_equivalent = $pu_ht;
2459 $pu_equivalent_ttc = $pu_ttc;
2461 $currency_tx =
$object->multicurrency_tx;
2465 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2466 $pu_equivalent = (float) $pu_ht_devise * $currency_tx;
2468 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2469 $pu_equivalent_ttc = (float) $pu_ttc_devise * $currency_tx;
2489 $price2num_remise_percent =
price2num($remise_percent);
2490 $price2num_price_min =
price2num($price_min);
2491 $price2num_price_min_ttc =
price2num($price_min_ttc);
2492 if (empty($price2num_pu_ht)) {
2493 $price2num_pu_ht = 0;
2495 if (empty($price2num_remise_percent)) {
2496 $price2num_remise_percent = 0;
2498 if (empty($price2num_price_min)) {
2499 $price2num_price_min = 0;
2501 if (empty($price2num_price_min_ttc)) {
2502 $price2num_price_min_ttc = 0;
2507 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2508 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2511 } elseif ($pu_equivalent_ttc && $price_min_ttc && (((
float)
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
2512 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2519 '@phan-var-force array<string,mixed> $lines';
2521 if (isModEnabled(
'productbatch') && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) &&
getDolGlobalString(
'INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS')) {
2522 $langs->load(
'productbatch');
2523 foreach ($lines[$i]->detail_batch as $batchline) {
2524 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2529 $result =
$object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $date_start, $date_end, 0, $info_bits, 0, $price_base_type, $pu_ttc, $type, min($rank, count(
$object->lines) + 1), $special_code,
'', 0,
GETPOST(
'fk_parent_line'), $fournprice, $buyingprice, $label, $array_options,
GETPOST(
'progress'), 0, $fk_unit, $pu_ht_devise);
2534 $outputlangs = $langs;
2537 $newlang =
GETPOST(
'lang_id',
'aZ09');
2540 $newlang =
$object->thirdparty->default_lang;
2542 if (!empty($newlang)) {
2543 $outputlangs =
new Translate(
"", $conf);
2544 $outputlangs->setDefaultLang($newlang);
2545 $outputlangs->load(
'products');
2550 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2556 unset($_POST[
'prod_entry_mode']);
2557 unset($_POST[
'qty']);
2558 unset($_POST[
'type']);
2559 unset($_POST[
'remise_percent']);
2560 unset($_POST[
'price_ht']);
2561 unset($_POST[
'multicurrency_price_ht']);
2562 unset($_POST[
'price_ttc']);
2563 unset($_POST[
'tva_tx']);
2564 unset($_POST[
'product_ref']);
2565 unset($_POST[
'product_label']);
2566 unset($_POST[
'product_desc']);
2567 unset($_POST[
'fournprice']);
2568 unset($_POST[
'buying_price']);
2569 unset($_POST[
'np_marginRate']);
2570 unset($_POST[
'np_markRate']);
2571 unset($_POST[
'dp_desc']);
2572 unset($_POST[
'idprod']);
2573 unset($_POST[
'units']);
2574 unset($_POST[
'date_starthour']);
2575 unset($_POST[
'date_startmin']);
2576 unset($_POST[
'date_startsec']);
2577 unset($_POST[
'date_startday']);
2578 unset($_POST[
'date_startmonth']);
2579 unset($_POST[
'date_startyear']);
2580 unset($_POST[
'date_endhour']);
2581 unset($_POST[
'date_endmin']);
2582 unset($_POST[
'date_endsec']);
2583 unset($_POST[
'date_endday']);
2584 unset($_POST[
'date_endmonth']);
2585 unset($_POST[
'date_endyear']);
2586 unset($_POST[
'situations']);
2587 unset($_POST[
'progress']);
2595 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2596 if (!
$object->fetch($id) > 0) {
2608 $vat_rate = str_replace(
'*',
'', $vat_rate);
2620 if (preg_match(
'/\*/', $vat_rate)) {
2625 $vat_rate = str_replace(
'*',
'', $vat_rate);
2634 $pu_equivalent = $pu_ht;
2635 $pu_equivalent_ttc = $pu_ttc;
2637 $currency_tx =
$object->multicurrency_tx;
2641 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2642 $pu_equivalent = (float) $pu_ht_devise * (
float) $currency_tx;
2644 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2645 $pu_equivalent_ttc = (float) $pu_ttc_devise * (
float) $currency_tx;
2660 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2661 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
2663 if (is_array($extralabelsline)) {
2665 foreach ($extralabelsline as $key => $value) {
2666 unset($_POST[
"options_".$key]);
2672 if ($special_code == 3) {
2678 $percent = $line->get_prev_progress(
$object->id);
2683 if ($progress >= 0) {
2684 $mesg = $langs->trans(
"CantBeNullOrPositive");
2688 } elseif ($progress < $line->situation_percent) {
2689 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
2693 } elseif ($progress < $percent) {
2694 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
2705 if (!empty($productid)) {
2707 $product->fetch($productid);
2709 $type = $product->type;
2711 $price_min = $product->price_min;
2713 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
2715 $price_min_ttc = $product->price_min_ttc;
2717 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
2724 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
2725 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2728 $action =
'editline';
2729 } elseif ($pu_equivalent_ttc && $price_min_ttc && (((
float)
price2num($pu_equivalent_ttc) * (1 - (
float) $remise_percent / 100)) < (
float)
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
2730 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2733 $action =
'editline';
2738 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2742 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
2747 $langs->load(
"errors");
2748 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2752 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2753 $langs->load(
"errors");
2754 if (
$object->type == $object::TYPE_DEPOSIT) {
2756 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2758 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2762 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2769 $previousprogress = $line->get_allprev_progress($line->fk_facture);
2772 if ($fullprogress < $previousprogress) {
2774 setEventMessages($langs->trans(
'CantBeLessThanMinPercent'),
null,
'errors');
2778 if ($fullprogress > 100) {
2779 $fullprogress = 100;
2781 $addprogress = $fullprogress - $previousprogress;
2788 if (empty($usercancreatemargin)) {
2789 foreach (
$object->lines as &$line) {
2791 $fournprice = $line->fk_fournprice;
2792 $buyingprice = $line->pa_ht;
2798 $price_base_type =
'HT';
2800 if (empty($pu) && !empty($pu_ttc)) {
2802 $price_base_type =
'TTC';
2805 $result =
$object->updateline(
2834 $outputlangs = $langs;
2837 $newlang =
GETPOST(
'lang_id',
'aZ09');
2840 $newlang =
$object->thirdparty->default_lang;
2842 if (!empty($newlang)) {
2843 $outputlangs =
new Translate(
"", $conf);
2844 $outputlangs->setDefaultLang($newlang);
2845 $outputlangs->load(
'products');
2849 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2852 unset($_POST[
'qty']);
2853 unset($_POST[
'type']);
2854 unset($_POST[
'productid']);
2855 unset($_POST[
'remise_percent']);
2856 unset($_POST[
'price_ht']);
2857 unset($_POST[
'multicurrency_price_ht']);
2858 unset($_POST[
'price_ttc']);
2859 unset($_POST[
'tva_tx']);
2860 unset($_POST[
'product_ref']);
2861 unset($_POST[
'product_label']);
2862 unset($_POST[
'product_desc']);
2863 unset($_POST[
'fournprice']);
2864 unset($_POST[
'buying_price']);
2865 unset($_POST[
'np_marginRate']);
2866 unset($_POST[
'np_markRate']);
2867 unset($_POST[
'dp_desc']);
2868 unset($_POST[
'idprod']);
2869 unset($_POST[
'units']);
2870 unset($_POST[
'date_starthour']);
2871 unset($_POST[
'date_startmin']);
2872 unset($_POST[
'date_startsec']);
2873 unset($_POST[
'date_startday']);
2874 unset($_POST[
'date_startmonth']);
2875 unset($_POST[
'date_startyear']);
2876 unset($_POST[
'date_endhour']);
2877 unset($_POST[
'date_endmin']);
2878 unset($_POST[
'date_endsec']);
2879 unset($_POST[
'date_endday']);
2880 unset($_POST[
'date_endmonth']);
2881 unset($_POST[
'date_endyear']);
2882 unset($_POST[
'situations']);
2883 unset($_POST[
'progress']);
2888 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modifier')) {
2889 if (!
$object->fetch($id) > 0) {
2892 if (
GETPOST(
'all_progress') !=
"") {
2894 foreach (
$object->lines as $line) {
2896 $percent = $line->get_allprev_progress(
$object->id);
2898 $percent = $line->get_prev_progress(
$object->id);
2900 if ((
float) $all_progress < (
float) $percent) {
2901 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
2910 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
2911 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2913 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
2915 $object->fetch($id,
'',
'', 0,
true);
2921 &&
$object->is_last_in_cycle()
2922 && $usercanunvalidate
2925 $newCycle =
$object->newCycle();
2926 if ($newCycle > 1) {
2928 $lastCycle =
$object->situation_cycle_ref;
2929 $lastSituationCounter =
$object->situation_counter;
2930 $linkedCreditNotesList = array();
2932 if (count(
$object->tab_next_situation_invoice) > 0) {
2933 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
2935 && $next_invoice->situation_counter ==
$object->situation_counter
2936 && $next_invoice->fk_facture_source ==
$object->id
2938 $linkedCreditNotesList[] = $next_invoice->id;
2943 $object->situation_cycle_ref = $newCycle;
2944 $object->situation_counter = 1;
2946 if (
$object->update($user) > 0) {
2948 if (count($linkedCreditNotesList) > 0) {
2950 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
2951 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
2952 $sql .=
' , situation_final=0';
2953 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
2954 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
2956 $resql = $db->query($sql);
2962 foreach (
$object->lines as $line) {
2964 if ($line->product_type == 9) {
2969 if (!empty(
$object->tab_previous_situation_invoice)) {
2971 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
2972 $searchPreviousInvoice =
true;
2973 while ($searchPreviousInvoice) {
2975 $searchPreviousInvoice =
false;
2983 $maxPrevSituationPercent = 0;
2984 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
2985 if ($prevLine->id == $line->fk_prev_id) {
2986 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
2991 $line->situation_percent -= $maxPrevSituationPercent;
2993 if ($line->update() < 0) {
3002 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
3004 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
3007 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
3010 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
3016 $fromElement =
GETPOST(
'fromelement');
3017 $fromElementid =
GETPOST(
'fromelementid');
3018 $importLines =
GETPOST(
'line_checkbox');
3020 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
3021 if ($fromElement ==
'commande') {
3023 $lineClassName =
'OrderLine';
3024 } elseif ($fromElement ==
'propal') {
3025 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
3026 $lineClassName =
'PropaleLigne';
3028 $nextRang = count(
$object->lines) + 1;
3031 foreach ($importLines as $lineId) {
3032 $lineId = intval($lineId);
3033 $originLine =
new $lineClassName($db);
3034 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
3035 $originLine->fetch_optionals();
3036 $desc = $originLine->desc;
3037 $pu_ht = $originLine->subprice;
3038 $qty = $originLine->qty;
3039 $txtva = $originLine->tva_tx;
3040 $txlocaltax1 = $originLine->localtax1_tx;
3041 $txlocaltax2 = $originLine->localtax2_tx;
3042 $fk_product = $originLine->fk_product;
3043 $remise_percent = $originLine->remise_percent;
3044 $date_start = $originLine->date_start;
3045 $date_end = $originLine->date_end;
3046 $fk_code_ventilation = 0;
3047 $info_bits = $originLine->info_bits;
3048 $fk_remise_except = $originLine->fk_remise_except;
3049 $price_base_type =
'HT';
3051 $type = $originLine->product_type;
3052 $rang = $nextRang++;
3053 $special_code = $originLine->special_code;
3054 $origin = $originLine->element;
3055 $origin_id = $originLine->id;
3056 $fk_parent_line = 0;
3057 $fk_fournprice = $originLine->fk_fournprice;
3058 $pa_ht = $originLine->pa_ht;
3059 $label = $originLine->label;
3060 $array_options = $originLine->array_options;
3062 $situation_percent = 0;
3064 $situation_percent = 100;
3067 $fk_unit = $originLine->fk_unit;
3068 $pu_ht_devise = $originLine->multicurrency_subprice;
3070 $res =
$object->addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $fk_code_ventilation, $info_bits, $fk_remise_except, $price_base_type, $pu_ttc, $type, $rang, $special_code, $origin, $origin_id, $fk_parent_line, $fk_fournprice, $pa_ht, $label, $array_options, $situation_percent, $fk_prev_id, $fk_unit, $pu_ht_devise);
3089 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3095 $triggersendname =
'BILL_SENTBYMAIL';
3097 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3098 $trackid =
'inv'.$object->id;
3099 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3102 $upload_dir = $conf->invoice->multidir_output[!empty(
$object->entity) ?
$object->entity : $conf->entity];
3103 $permissiontoadd = $usercancreate;
3104 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3107 if ($action ==
'update_extras' && $usercancreate) {
3111 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
GETPOST(
'attribute',
'restricthtml'));
3118 $result =
$object->insertExtraFields(
'BILL_MODIFY');
3126 $action =
'edit_extras';
3131 if ($action ==
'addcontact' && $usercancreate) {
3132 $result =
$object->fetch($id);
3134 if ($result > 0 && $id > 0) {
3137 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3141 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3144 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3145 $langs->load(
"errors");
3146 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3151 } elseif ($action ==
'swapstatut' && $usercancreate) {
3158 } elseif ($action ==
'deletecontact' && $usercancreate) {
3161 $result =
$object->delete_contact($lineid);
3164 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3172 $action =
'edit_extras';
3183$form =
new Form($db);
3189$bankaccountstatic =
new Account($db);
3190if (isModEnabled(
'project')) {
3196$title =
$object->ref.
" - ".$langs->trans(
'Card');
3197if ($action ==
'create') {
3198 $title = $langs->trans(
"NewBill");
3200$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3206if ($action ==
'create') {
3207 $facturestatic =
new Facture($db);
3208 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3213 $res = $soc->fetch($socid);
3216 $currency_code = $conf->currency;
3218 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3219 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3224 if (!empty($origin) && !empty($originid)) {
3226 $element = $subelement = $origin;
3228 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3229 $element = $regs[1];
3230 $subelement = $regs[2];
3236 if ($element ==
'project') {
3237 $projectid = $originid;
3239 if (empty($cond_reglement_id)) {
3240 $cond_reglement_id = $soc->cond_reglement_id;
3242 if (empty($mode_reglement_id)) {
3243 $mode_reglement_id = $soc->mode_reglement_id;
3245 if (empty($fk_account)) {
3246 $fk_account = $soc->fk_account;
3248 if (empty($dateinvoice)) {
3254 if ($element ==
'order' || $element ==
'commande') {
3255 $element = $subelement =
'commande';
3257 if ($element ==
'propal') {
3258 $element =
'comm/propal';
3259 $subelement =
'propal';
3261 if ($element ==
'contract') {
3262 $element = $subelement =
'contrat';
3264 if ($element ==
'shipping') {
3265 $element = $subelement =
'expedition';
3270 $classname = ucfirst($subelement);
3271 $objectsrc =
new $classname($db);
3272 $objectsrc->fetch($originid);
3273 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3274 $objectsrc->fetch_lines();
3276 $objectsrc->fetch_thirdparty();
3278 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3279 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3282 if (empty($socid)) {
3283 $soc = $objectsrc->thirdparty;
3286 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3288 if ($element ==
'expedition') {
3289 $ref_client = (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
'');
3291 $elem = $subelem = $objectsrc->origin;
3292 $expeoriginid = $objectsrc->origin_id;
3294 $classname = ucfirst($subelem);
3296 $expesrc =
new $classname($db);
3297 $expesrc->fetch($expeoriginid);
3299 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3300 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3301 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3303 if (isModEnabled(
'multicurrency')) {
3304 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3305 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3309 $expesrc->fetch_optionals();
3310 $object->array_options = $expesrc->array_options;
3312 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : (!empty($cond_reglement_id) ? $cond_reglement_id : 0)));
3313 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : (!empty($mode_reglement_id) ? $mode_reglement_id : 0)));
3314 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : (!empty($fk_account) ? $fk_account : 0)));
3316 if (isModEnabled(
'multicurrency')) {
3317 if (!empty($objectsrc->multicurrency_code)) {
3318 $currency_code = $objectsrc->multicurrency_code;
3320 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
3321 $currency_tx = $objectsrc->multicurrency_tx;
3326 $objectsrc->fetch_optionals();
3327 $object->array_options = $objectsrc->array_options;
3331 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
3332 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
3333 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
3335 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3337 if (isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3338 $currency_code = $soc->multicurrency_code;
3343 if (!
GETPOST(
'changecompany')) {
3344 if (GETPOSTISSET(
'cond_reglement_id')) {
3345 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3347 if (GETPOSTISSET(
'mode_reglement_id')) {
3348 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3350 if (GETPOSTISSET(
'cond_reglement_id')) {
3356 if (empty($cond_reglement_id)) {
3357 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
3361 if (empty($mode_reglement_id)) {
3362 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
3372 if (!empty($soc->id)) {
3373 $absolute_discount = $soc->getAvailableDiscounts();
3375 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
3376 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
3378 if (!empty($conf->use_javascript_ajax)) {
3379 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3385 if ($origin ==
'contrat') {
3386 $langs->load(
"admin");
3387 $text = $langs->trans(
"ToCreateARecurringInvoice");
3388 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3390 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3392 print
info_admin($text, 0, 0, 0,
'opacitymedium').
'<br>';
3395 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3396 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3397 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3398 print
'<input type="hidden" name="changecompany" value="0">';
3400 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3402 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3403 print
'<input name="ref" type="hidden" value="provisoire">';
3404 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3405 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3406 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3407 print
'<input name="force_fk_account" type="hidden" value="0">';
3408 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3409 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3410 print
'<input type="hidden" name="originentity" value="'.GETPOST(
'originentity').
'">';
3411 if (!empty($currency_tx)) {
3412 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3418 $parameters = array();
3420 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters,
$object, $action);
3421 if (empty($reshook)) {
3422 print
'<table class="border centpercent">';
3424 $exampletemplateinvoice =
new FactureRec($db);
3426 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3427 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
3431 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
3433 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3434 print
'<td colspan="2">';
3435 print $soc->getNomUrl(1,
'customer');
3436 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3438 $arrayoutstandingbills = $soc->getOutstandingBills();
3439 $outstandingBills = $arrayoutstandingbills[
'opened'];
3440 print
' - <span class="opacitymedium">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3441 print
'<span class="amount">'.price($outstandingBills, 0, $langs, 0, 0, -1, $conf->currency).
'</span>';
3442 if ($soc->outstanding_limit !=
'') {
3443 if ($outstandingBills > $soc->outstanding_limit) {
3444 print
img_warning($langs->trans(
"OutstandingBillReached"));
3446 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1, $conf->currency);
3451 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3452 print
'<td colspan="2">';
3453 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
3454 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3458 $(document).ready(function() {
3459 $("#socid").change(function() {
3461 console.log("Submit page");
3462 $(\'input[name="action"]\').val(\'create\');
3463 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3464 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3465 $(\'input[name="force_fk_account"]\').val(\'1\');
3466 $("#formtocreate").submit(); */
3468 // For company change, we must submit page with action=create instead of action=add
3469 console.log("We have changed the company - Resubmit page");
3470 jQuery("input[name=changecompany]").val("1");
3471 jQuery("#formtocreateaction").val("create");
3472 jQuery("#formtocreate").submit();
3478 print
' <a href="'.DOL_URL_ROOT.
'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create').
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddThirdParty").
'"></span></a>';
3485 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3487 foreach ($invoice_predefined->array_options as $key => $option) {
3488 if (!isset(
$object->array_options[$key])) {
3489 $object->array_options[$key] = $invoice_predefined->array_options[$key];
3493 $dateinvoice = $invoice_predefined->date_when;
3494 if (empty($projectid)) {
3495 $projectid = $invoice_predefined->fk_project;
3497 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
3498 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
3499 $fk_account = $invoice_predefined->fk_account;
3500 $note_public = $invoice_predefined->note_public;
3501 $note_private = $invoice_predefined->note_private;
3503 if (!empty($invoice_predefined->multicurrency_code)) {
3504 $currency_code = $invoice_predefined->multicurrency_code;
3506 if (!empty($invoice_predefined->multicurrency_tx)) {
3507 $currency_tx = $invoice_predefined->multicurrency_tx;
3510 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
3511 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
3512 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
3514 $resql = $db->query($sql);
3516 $num = $db->num_rows($resql);
3520 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
3522 print
'<select class="flat" id="fac_rec" name="fac_rec">';
3523 print
'<option value="0" selected></option>';
3525 $objp = $db->fetch_object($resql);
3526 print
'<option value="'.$objp->rowid.
'"';
3529 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
3531 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
3540 print
'<script type="text/javascript">
3541 $(document).ready(function() {
3542 $("#fac_rec").change(function() {
3543 console.log("We have changed the template invoice - Reload page");
3544 var fac_rec = $(this).val();
3545 var socid = $(\'#socid\').val();
3546 // For template invoice change, we must reuse data of template, not input already done, so we call a GET with action=create, not a POST submit.
3547 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3560 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td colspan="2">';
3561 print
'<div class="tagtable">'.
"\n";
3564 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3565 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
3566 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
3568 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'nowraponall', 0, 3,
'standardonsmartphone');
3569 print
'<table class="nobordernopadding"><tr>';
3573 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
3582 print
'<td class="nowrap" style="padding-left: 15px">';
3583 print
'<span class="opacitymedium">'.$langs->trans(
'PercentOfOriginalObject').
'</span>:<input class="right" placeholder="100%" type="text" id="valuestandardinvoice" name="valuestandardinvoice" size="3" value="'.(GETPOSTISSET(
'valuestandardinvoice') ?
GETPOST(
'valuestandardinvoice',
'alpha') :
'100%').
'"/>';
3586 print
'</tr></table>';
3587 print
'</div></div>';
3589 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
3592 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3593 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
3594 print
'<script type="text/javascript">
3595 jQuery(document).ready(function() {
3596 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
3597 jQuery("#radio_standard").prop("checked", true);
3599 jQuery("#typedeposit, #valuedeposit").click(function() {
3600 jQuery("#radio_deposit").prop("checked", true);
3602 jQuery("#typedeposit").change(function() {
3603 console.log("We change type of down payment");
3604 jQuery("#radio_deposit").prop("checked", true);
3605 setRadioForTypeOfInvoice();
3607 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
3608 setRadioForTypeOfInvoice();
3610 function setRadioForTypeOfInvoice() {
3611 console.log("Change radio for type of invoice");
3612 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
3613 jQuery("#checkforselects").prop("disabled", true);
3614 jQuery("#checkforselects").prop("checked", false);
3615 jQuery(".checkforselect").prop("disabled", true);
3616 jQuery(".checkforselect").prop("checked", false);
3618 jQuery("#checkforselects").prop("disabled", false);
3619 jQuery("#checkforselects").prop("checked", true);
3620 jQuery(".checkforselect").prop("disabled", false);
3621 jQuery(".checkforselect").prop("checked", true);
3627 print
'<table class="nobordernopadding"><tr>';
3629 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
3631 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
3634 if (($origin ==
'propal') || ($origin ==
'commande')) {
3635 print
'<td class="nowrap" style="padding-left: 15px">';
3637 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
3638 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
3639 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
3641 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
3643 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
3644 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
3645 if (!empty($origin_payment_conditions_deposit_percent)) {
3646 $typedeposit =
'variable';
3649 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
3650 $valuedeposit = $objectsrc->deposit_percent;
3652 print $form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
3654 print
'<td class="nowrap" style="padding-left: 5px">';
3655 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.$valuedeposit.
'"/>';
3658 print
'</tr></table>';
3660 print
'</div></div>';
3667 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3668 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
3669 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
3671 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
3673 print
'</div></div>';
3676 $opt = $form->selectSituationInvoices(
GETPOSTINT(
'originid'), $socid);
3678 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3679 $tmp =
'<input type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
3680 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3681 $tmp .=
' disabled';
3684 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3685 $text .=
'<select class="flat" id="situations" name="situations"';
3686 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3687 $text .=
' disabled';
3691 $text .=
'</select>';
3692 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
3694 print
'</div></div>';
3700 $facids = $facturestatic->list_replacable_invoices($soc->id);
3706 if (is_array($facids)) {
3707 foreach ($facids as $facparam) {
3708 $options .=
'<option value="'.$facparam [
'id'].
'"';
3709 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
3710 $options .=
' selected';
3712 $options .=
'>'.$facparam[
'ref'];
3713 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
3714 $options .=
'</option>';
3718 print
'<!-- replacement line -->';
3719 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3720 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
3721 if (!$options || $invoice_predefined->id > 0) {
3722 $tmp .=
' disabled';
3725 print
'<script type="text/javascript">
3726 jQuery(document).ready(function() {
3727 jQuery("#fac_replacement").change(function() {
3728 jQuery("#radio_replacement").prop("checked", true);
3732 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
3733 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
3734 if (!$options || $invoice_predefined->id > 0) {
3735 $text .=
' disabled';
3739 $text .=
'<option value="-1"> </option>';
3742 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
3744 $text .=
'</select>';
3745 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3747 print
'</div></div>';
3751 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3752 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3753 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3754 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3755 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'nowraponall', 0, 3,
'firstsituationonsmartphone');
3757 print
'</div></div>';
3760 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3761 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
3762 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
3764 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'replacementonsmartphone');
3766 print
'</div></div>';
3769 if (empty($origin)) {
3774 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
3780 $newinvoice_static =
new Facture($db);
3781 foreach ($facids as $key => $valarray) {
3782 $newinvoice_static->id = $key;
3783 $newinvoice_static->ref = $valarray [
'ref'];
3784 $newinvoice_static->statut = $valarray [
'status'];
3785 $newinvoice_static->status = $valarray [
'status'];
3786 $newinvoice_static->type = $valarray [
'type'];
3787 $newinvoice_static->paye = $valarray [
'paye'];
3789 $optionsav .=
'<option value="'.$key.
'"';
3790 if ($key ==
GETPOST(
'fac_avoir')) {
3791 $optionsav .=
' selected';
3794 $newinvoice_static->fetch_optionals($key);
3795 $object->array_options = $newinvoice_static->array_options;
3798 $optionsav .= $newinvoice_static->ref;
3799 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
3800 $optionsav .=
'</option>';
3803 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3804 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
3805 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
3806 $tmp .=
' disabled';
3810 print
'<script type="text/javascript">
3811 jQuery(document).ready(function() {
3812 if (jQuery("#radio_creditnote").is(":checked"))
3814 jQuery("#radio_standard").prop("disabled", true);
3816 jQuery("#radio_standard").prop("disabled", false);
3818 if (! jQuery("#radio_creditnote").is(":checked"))
3820 jQuery("#credit_note_options").hide();
3822 jQuery("#radio_creditnote").click(function() {
3823 jQuery("#credit_note_options").show();
3825 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
3826 jQuery("#credit_note_options").hide();
3830 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
3831 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3832 if (!$optionsav || $invoice_predefined->id > 0) {
3833 $text .=
' disabled';
3837 $text .=
'<option value="-1"></option>';
3838 $text .= $optionsav;
3840 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
3842 $text .=
'</select>';
3843 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3846 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
3847 print
' <input type="checkbox" name="invoiceAvoirWithLines" id="invoiceAvoirWithLines" value="1" onclick="$(\'#credit_note_options input[type=checkbox]\').not(this).prop(\'checked\', false);" '.(GETPOSTINT(
'invoiceAvoirWithLines') > 0 ?
'checked' :
'').
' /> <label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
3848 print
'<br> <input type="checkbox" name="invoiceAvoirWithPaymentRestAmount" id="invoiceAvoirWithPaymentRestAmount" value="1" onclick="$(\'#credit_note_options input[type=checkbox]\').not(this).prop(\'checked\', false);" '.(GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') > 0 ?
'checked' :
'').
' /> <label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
3851 print
'</div></div>';
3854 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3856 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3858 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
3860 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
3862 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
3864 print
'</div></div>'.
"\n";
3869 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3870 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
3871 $text = $tmp.
'<label class="opacitymedium" for="radio_template">'.$langs->trans(
"RepeatableInvoice").
'</label> ';
3872 $desc = $form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3,
'templateonsmartphone');
3874 print
'</div></div>';
3883 foreach ($listtType as $type) {
3884 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
3886 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
3889 print
'<script type="text/javascript">
3890 $(document).ready(function() {
3891 var listType = {'.$jsListType.
'};
3892 $("[name=\'type\'").change(function() {
3893 console.log("change name=type");
3894 if ($( this ).prop("checked"))
3896 if(($( this ).val() in listType))
3898 $("#model").val(listType[$( this ).val()]);
3915 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
3916 print $form->getSelectInvoiceSubtype(
GETPOST(
'subtype'),
'subtype', 1, 0,
'');
3922 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
3926 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
3927 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3936 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
3937 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3938 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
3943 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
3944 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3945 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
3950 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
3951 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
3952 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
3957 $rwStyle =
'display:none;';
3958 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
3962 $retained_warranty =
GETPOSTINT(
'retained_warranty');
3963 if (empty($retained_warranty)) {
3964 if (!empty($objectsrc->retained_warranty)) {
3965 $retained_warranty = $objectsrc->retained_warranty;
3968 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
3970 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
3971 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
3974 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
3975 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
3976 if (empty($retained_warranty_fk_cond_reglement)) {
3977 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
3978 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
3979 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
3981 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
3984 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
3987 print
'<script type="text/javascript">
3988 $(document).ready(function() {
3989 $("[name=\'type\']").change(function() {
3990 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
3992 $(".retained-warranty-line").show();
3993 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
3996 $(".retained-warranty-line").hide();
3997 $("#new-situation-invoice-retained-warranty").val("");
4001 $("[name=\'type\']:checked").trigger("change");
4007 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
4008 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
4009 print $form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
4013 if (isModEnabled(
"bank")) {
4014 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td colspan="2">';
4015 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4016 print $form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
4021 if (isModEnabled(
'project')) {
4022 $langs->load(
'projects');
4023 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
4024 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
4025 print
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?socid='.$soc->id.
'&action=create&status=1&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create&socid='.$soc->id.($fac_rec ?
'&fac_rec='.$fac_rec :
'')).
'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans(
"AddProject").
'"></span></a>';
4030 if (isModEnabled(
'incoterm')) {
4032 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
4033 print
'<td colspan="2" class="maxwidthonsmartphone">';
4034 $incoterm_id =
GETPOST(
'incoterm_id');
4035 $location_incoterms =
GETPOST(
'location_incoterms');
4036 if (empty($incoterm_id)) {
4037 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
4038 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
4040 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
4041 print $form->select_incoterms($incoterm_id, $location_incoterms);
4046 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
4047 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
4048 print $hookmanager->resPrint;
4049 if (empty($reshook)) {
4050 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
4053 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
4054 if ($soc->fetch_optionals() > 0) {
4055 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
4059 print
$object->showOptionals($extrafields,
'create', $parameters);
4063 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
4064 print
'<td colspan="2">';
4065 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
4066 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
4071 $paramkey =
'FACTURE_ADDON_PDF_'.$type;
4076 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
4080 if (isModEnabled(
'multicurrency')) {
4082 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0).
'</td>';
4083 print
'<td colspan="2" class="maxwidthonsmartphone">';
4084 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
4085 print $form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth100 widthcentpercentminusx');
4092 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
4093 if (empty($dateexample)) {
4096 $substitutionarray = array(
4097 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
4098 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
4099 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
4100 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
4101 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
4102 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
4103 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
4104 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
4105 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
4106 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
4107 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
4110 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
4111 foreach ($substitutionarray as $key => $val) {
4112 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
4114 $htmltext .=
'</i>';
4119 print
'<td class="tdtop">';
4120 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
4122 print
'<td valign="top" colspan="2">';
4123 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
4124 print $doleditor->Create(1);
4127 if (empty($user->socid)) {
4129 print
'<td class="tdtop">';
4130 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4132 print
'<td valign="top" colspan="2">';
4133 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4134 print $doleditor->Create(1);
4140 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4141 $langs->loadLangs(array(
'orders',
'propal'));
4144 if ($origin ==
'contrat') {
4146 $objectsrc->update_price(1,
'auto', 1);
4149 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4150 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4151 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4152 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4157 switch (get_class($objectsrc)) {
4159 $newclassname =
'CommercialProposal';
4162 $newclassname =
'Order';
4165 $newclassname =
'Sending';
4168 $newclassname =
'Contract';
4171 $newclassname =
'Intervention';
4174 $newclassname = get_class($objectsrc);
4178 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4179 print
'<td colspan="2">';
4180 print $objectsrc->getNomUrl(1);
4182 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
4183 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4185 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4188 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht).
'</td></tr>';
4189 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva).
"</td></tr>";
4190 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4191 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax1).
"</td></tr>";
4194 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4195 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax2).
"</td></tr>";
4197 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc).
"</td></tr>";
4199 if (isModEnabled(
'multicurrency')) {
4200 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
4201 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
4202 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
4210 print $form->buttonsSaveCancel(
"CreateDraft");
4213 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4216 $title = $langs->trans(
'ProductsAndServices');
4219 print
'<div class="div-table-responsive-no-min">';
4220 print
'<table class="noborder centpercent">';
4222 $objectsrc->printOriginLinesList(
'', $selectedLines);
4229} elseif ($id > 0 || !empty($ref)) {
4231 $langs->load(
'errors');
4232 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4241 $result =
$object->fetch($id, $ref);
4248 $extrafields->fetch_name_optionals_label(
$object->table_element);
4250 if ($user->socid > 0 && $user->socid !=
$object->socid) {
4254 $result =
$object->fetch_thirdparty();
4256 $result = $soc->fetch(
$object->socid);
4260 $selleruserevenustamp = $mysoc->useRevenueStamp();
4262 $totalpaid =
$object->getSommePaiement();
4263 $totalcreditnotes =
$object->getSumCreditNotesUsed();
4264 $totaldeposits =
$object->getSumDepositsUsed();
4270 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4273 if (isModEnabled(
'multicurrency')) {
4274 $multicurrency_totalpaid =
$object->getSommePaiement(1);
4275 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
4276 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
4277 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4281 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code != $conf->currency) {
4282 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
4289 $resteapayeraffiche = $resteapayer;
4292 $filterabsolutediscount =
"fk_facture_source IS NULL";
4293 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4295 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4296 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4299 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
4300 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
4301 $absolute_discount =
price2num($absolute_discount,
'MT');
4302 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4304 $author =
new User($db);
4305 if (
$object->user_creation_id) {
4306 $author->fetch(
$object->user_creation_id);
4309 $objectidnext =
$object->getIdReplacingInvoice();
4313 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
'bill');
4318 if ($action ==
'converttoreduc') {
4320 $type_fac =
'ExcessReceived';
4322 $type_fac =
'CreditNote';
4324 $type_fac =
'Deposit';
4326 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4327 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4328 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4332 if ($action ==
'delete') {
4333 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
4334 $formquestion = array();
4337 $qualified_for_stock_change = 0;
4339 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4341 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4344 if ($qualified_for_stock_change) {
4345 $langs->load(
"stocks");
4346 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4350 if ($conf->browser->name ==
'ie') {
4353 $formquestion = array(
4357 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4359 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4361 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4364 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4369 if ($action ==
'situationout') {
4370 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
4371 $label = $langs->trans(
"ConfirmOuting");
4372 $formquestion = array();
4377 &&
$object->is_last_in_cycle()
4378 && $usercanunvalidate
4380 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4385 if ($action ==
'valid') {
4387 $objectref = substr(
$object->ref, 1, 4);
4388 if ($objectref ==
'PROV') {
4392 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
4394 $numref =
$object->getNextNumRef($soc);
4400 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4401 if (isModEnabled(
'notification')) {
4402 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4403 $notify =
new Notify($db);
4405 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid,
$object);
4407 $formquestion = array();
4410 $qualified_for_stock_change = 0;
4412 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4414 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4417 if ($qualified_for_stock_change) {
4418 $langs->load(
"stocks");
4419 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4420 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4423 $warehouse_array = $warehouse->list_array();
4424 if (count($warehouse_array) == 1) {
4425 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4426 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4429 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4431 $formquestion = array(
4437 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4441 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
4446 foreach (
$object->lines as $line) {
4447 $res = $line->fetch_product();
4449 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
4455 if ($nbMandated > 0) {
4457 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
4460 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
4465 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, ((
$object->type !=
Facture::TYPE_CREDIT_NOTE &&
$object->total_ttc < 0) ?
"no" :
"yes"), 2, 240);
4470 if ($action ==
'modif') {
4471 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
4472 $formquestion = array();
4475 $qualified_for_stock_change = 0;
4477 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4479 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4482 if ($qualified_for_stock_change) {
4483 $langs->load(
"stocks");
4484 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4485 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4488 $warehouse_array = $warehouse->list_array();
4489 if (count($warehouse_array) == 1) {
4490 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
4491 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4494 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4496 $formquestion = array(
4502 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4506 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
4510 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
4511 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
4513 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
4517 $close[$i][
'code'] =
'discount_vat';
4519 $close[$i][
'code'] =
'badcustomer';
4521 $close[$i][
'code'] =
'bankcharge';
4523 $close[$i][
'code'] =
'withholdingtax';
4525 $close[$i][
'code'] =
'other';
4529 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
4531 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4533 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
4535 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
4537 $close[$i][
'label'] = $langs->trans(
"Other");
4541 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4543 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4545 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4547 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
4549 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
4553 foreach ($close as $key => $val) {
4554 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
4558 $formquestion = array(
'text' => $langs->trans(
"ConfirmClassifyPaidPartiallyQuestion"), 0 => array(
'type' =>
'radio',
'name' =>
'close_code',
'label' => $langs->trans(
"Reason"),
'values' => $arrayreasons), 1 => array(
'type' =>
'text',
'name' =>
'close_note',
'label' => $langs->trans(
"Comment"),
'value' =>
'',
'morecss' =>
'minwidth300'));
4560 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 380, 600);
4564 if ($action ==
'canceled') {
4567 if ($objectidnext) {
4568 $facturereplacement =
new Facture($db);
4569 $facturereplacement->fetch($objectidnext);
4570 $statusreplacement = $facturereplacement->status;
4572 if ($objectidnext && $statusreplacement == 0) {
4573 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
4576 $close[1][
'code'] =
'badcustomer';
4577 $close[2][
'code'] =
'abandon';
4579 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4580 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
4582 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
4583 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
4586 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
4587 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
4590 $formquestion = array(
'text' => $langs->trans(
"ConfirmCancelBillQuestion"), 0 => array(
'type' =>
'radio',
'name' =>
'close_code',
'label' => $langs->trans(
"Reason"),
'values' => $arrayreasons), 1 => array(
'type' =>
'text',
'name' =>
'close_note',
'label' => $langs->trans(
"Comment"),
'value' =>
'',
'morecss' =>
'minwidth300'));
4592 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 270);
4596 if ($action ==
'deletepayment') {
4597 $payment_id =
GETPOST(
'paiement_id');
4598 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
4602 if ($action ==
'ask_deleteline') {
4603 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
4607 if ($action ==
'clone') {
4608 $filter =
'(s.client:IN:1,2,3)';
4610 $formquestion = array(
4611 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
$object->socid,
'socid', $filter, 1)),
4612 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
4615 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
4618 if ($action ==
"remove_file_comfirm") {
4619 $file =
GETPOST(
'file',
'alpha');
4621 $formconfirm = $form->formconfirm(
4622 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
4623 $langs->trans(
'DeleteFileHeader'),
4624 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
4633 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
4634 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
4635 if (empty($reshook)) {
4636 $formconfirm .= $hookmanager->resPrint;
4637 } elseif ($reshook > 0) {
4638 $formconfirm = $hookmanager->resPrint;
4646 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
4648 $morehtmlref =
'<div class="refidno">';
4651 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref',
$object->ref,
$object, $usercancreate,
'string',
'', 0, 1);
4652 $morehtmlref .= $form->editfieldval(
"Ref",
'ref',
$object->ref,
$object, $usercancreate,
'string',
'',
null,
null,
'', 1);
4653 $morehtmlref .=
'<br>';
4656 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer,
$object, $usercancreate,
'string',
'', 0, 1);
4657 $morehtmlref .= $form->editfieldval(
"RefCustomer",
'ref_client',
$object->ref_customer,
$object, $usercancreate,
'string'.(getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') ?
':' .
getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') :
''),
'', null, null,
'', 1);
4659 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
4661 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'&search_societe='.urlencode(
$object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
4664 if (isModEnabled(
'project')) {
4665 $langs->load(
"projects");
4666 $morehtmlref .=
'<br>';
4667 if ($usercancreate) {
4668 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
4669 if ($action !=
'classify') {
4670 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
4672 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->socid,
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
4674 if (!empty(
$object->fk_project)) {
4676 $proj->fetch(
$object->fk_project);
4677 $morehtmlref .= $proj->getNomUrl(1);
4679 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
4684 $morehtmlref .=
'</div>';
4686 $object->totalpaid = $totalpaid;
4687 $object->totalcreditnotes = $totalcreditnotes;
4688 $object->totaldeposits = $totaldeposits;
4691 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
4694 $parameters = array();
4696 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters,
$object, $action);
4697 if (empty($reshook)) {
4698 print
'<div class="fichecenter">';
4699 print
'<div class="fichehalfleft">';
4700 print
'<div class="underbanner clearboth"></div>';
4702 print
'<table class="border centpercent tableforfield">';
4705 print
'<tr><td class="fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
4708 print
' '.$object->getSubtypeLabel(
'facture');
4714 $facreplaced =
new Facture($db);
4715 $facreplaced->fetch(
$object->fk_facture_source);
4716 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
4720 $facusing->fetch(
$object->fk_facture_source);
4721 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
4724 $facidavoir =
$object->getListIdAvoirFromInvoice();
4725 if (count($facidavoir) > 0) {
4726 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
4728 foreach ($facidavoir as $id) {
4735 $facavoir->fetch($id);
4736 print $facavoir->getNomUrl(1,
'', 32);
4740 if ($objectidnext > 0) {
4741 $facthatreplace =
new Facture($db);
4742 $facthatreplace->fetch($objectidnext);
4743 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
4748 $result = $discount->fetch(0,
$object->id);
4750 print
' <span class="opacitymediumbycolor paddingleft">';
4751 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
4752 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
4753 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
4755 print
'</span><br>';
4759 if (
$object->fk_fac_rec_source > 0) {
4761 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
4763 print
' <span class="opacitymediumbycolor paddingleft">';
4764 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
4765 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
4773 print
'<!-- Discounts -->'.
"\n";
4774 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
4778 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
4779 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
4784 print
'<table class="nobordernopadding centpercent"><tr><td>';
4785 print $langs->trans(
'DateInvoice');
4787 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
4788 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editinvoicedate&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'SetDate'), 1).
'</a></td>';
4790 print
'</tr></table>';
4793 if ($action ==
'editinvoicedate') {
4794 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
4796 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
4805 print
'<table class="nobordernopadding centpercent"><tr><td>';
4806 print $langs->trans(
'DatePointOfTax');
4808 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editdate_pointoftax&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'SetDate'), 1).
'</a></td>';
4809 print
'</tr></table>';
4811 if ($action ==
'editdate_pointoftax') {
4812 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
4814 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
4821 print
'<table class="nobordernopadding centpercent"><tr><td>';
4822 print $langs->trans(
'PaymentConditionsShort');
4825 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editconditions&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'SetConditions'), 1).
'</a></td>';
4827 print
'</tr></table>';
4830 if ($action ==
'editconditions') {
4831 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->cond_reglement_id,
'cond_reglement_id');
4833 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->cond_reglement_id,
'none');
4842 print
'<table class="nobordernopadding centpercent"><tr><td>';
4843 print $langs->trans(
'DateMaxPayment');
4846 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editpaymentterm&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'SetDate'), 1).
'</a></td>';
4848 print
'</tr></table>';
4851 if ($action ==
'editpaymentterm') {
4852 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
4854 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
4866 print
'<table class="nobordernopadding centpercent"><tr><td>';
4867 print $langs->trans(
'PaymentMode');
4869 if ($action !=
'editmode' && $usercancreate) {
4870 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'SetMode'), 1).
'</a></td>';
4872 print
'</tr></table>';
4874 if ($action ==
'editmode') {
4875 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
4877 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->mode_reglement_id,
'none',
'CRDT');
4882 if (isModEnabled(
'multicurrency')) {
4886 print
'<table class="nobordernopadding centpercent"><tr><td>';
4887 print $form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0);
4889 if ($usercancreate && $action !=
'editmulticurrencycode' &&
$object->status == $object::STATUS_DRAFT) {
4890 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>';
4892 print
'</tr></table>';
4894 $htmlname = (($usercancreate && $action ==
'editmulticurrencycode') ?
'multicurrency_code' :
'none');
4895 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_code, $htmlname);
4899 if (
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
4902 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4903 print $form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'',
$object, 0);
4905 if ($usercancreate && $action !=
'editmulticurrencyrate' &&
$object->status == $object::STATUS_DRAFT &&
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency) {
4906 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>';
4908 print
'</tr></table>';
4910 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
4911 if ($action ==
'actualizemulticurrencyrate') {
4914 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_tx, ($usercancreate ?
'multicurrency_tx' :
'none'),
$object->multicurrency_code);
4916 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_tx,
'none',
$object->multicurrency_code);
4917 if (
$object->status == $object::STATUS_DRAFT &&
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency) {
4918 print
'<div class="inline-block"> ';
4919 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
4928 if (isModEnabled(
"bank")) {
4929 print
'<tr><td class="nowrap">';
4930 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
4931 print $langs->trans(
'BankAccount');
4933 if (($action !=
'editbankaccount') && $usercancreate) {
4934 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>';
4936 print
'</tr></table>';
4938 if ($action ==
'editbankaccount') {
4939 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'fk_account', 1);
4941 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'none');
4948 if (isModEnabled(
'incoterm')) {
4950 print
'<table class="nobordernopadding centpercent"><tr><td>';
4951 print $langs->trans(
'IncotermLabel');
4952 print
'<td><td class="right">';
4953 if ($usercancreate) {
4954 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
4958 print
'</td></tr></table>';
4961 if ($action !=
'editincoterm') {
4962 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
4964 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
4972 $displayWarranty =
true;
4973 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
4974 $displayWarranty =
false;
4977 if ($displayWarranty) {
4979 print
'<tr class="retained-warranty-lines" ><td>';
4980 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
4981 print $langs->trans(
'RetainedWarranty');
4984 print
'<td align="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editretainedwarranty&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'setRetainedWarranty'), 1).
'</a></td>';
4987 print
'</tr></table>';
4990 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
4991 print
'<input type="hidden" name="action" value="setretainedwarranty">';
4992 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4993 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4994 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
4995 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5003 print
'<tr class="retained-warranty-lines" ><td>';
5004 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
5005 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
5007 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
5008 print
'<td align="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editretainedwarrantypaymentterms&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'setPaymentConditionsShortRetainedWarranty'), 1).
'</a></td>';
5011 print
'</tr></table>';
5013 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5014 if (
$object->date > $defaultDate) {
5020 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5021 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
5022 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5023 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5024 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
5025 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
5026 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
5027 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
5028 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5031 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->retained_warranty_fk_cond_reglement,
'none');
5032 if (!$displayWarranty) {
5033 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning.png',
'class="pictowarning valignmiddle" ');
5039 print
'<tr class="retained-warranty-lines" ><td>';
5040 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
5041 print $langs->trans(
'RetainedWarrantyDateLimit');
5044 print
'<td align="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editretainedwarrantydatelimit&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'setRetainedWarrantyDateLimit'), 1).
'</a></td>';
5047 print
'</tr></table>';
5049 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5050 if (
$object->date > $defaultDate) {
5056 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5057 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
5058 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5059 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5060 print
'<input name="retained_warranty_date_limit" type="date" step="1" min="'.dol_print_date(
$object->date,
'%Y-%m-%d').
'" value="'.
dol_print_date($defaultDate,
'%Y-%m-%d').
'" >';
5061 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5073 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
5078 print
'<div class="fichehalfright">';
5080 print
'<!-- amounts -->'.
"\n";
5081 print
'<div class="underbanner clearboth"></div>'.
"\n";
5083 print
'<table class="border tableforfield centpercent">';
5091 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
5092 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5093 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
5095 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5101 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountVAT') .
'</td>';
5102 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5103 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
5105 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5110 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
5112 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
5113 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5114 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
5117 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5122 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
5124 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
5125 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5126 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
5129 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5135 if ($selleruserevenustamp) {
5136 print
'<tr><td class="titlefieldmiddle">';
5137 print
'<table class="nobordernopadding centpercent"><tr><td>';
5138 print $langs->trans(
'RevenueStamp');
5140 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
5141 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editrevenuestamp&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'SetRevenuStamp'), 1).
'</a></td>';
5143 print
'</tr></table>';
5144 print
'</td><td class="nowrap amountcard right">';
5145 if ($action ==
'editrevenuestamp') {
5146 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
5147 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5148 print
'<input type="hidden" name="action" value="setrevenuestamp">';
5149 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
5150 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5151 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
5152 print
' → <span id="revenuestamp_span"></span>';
5153 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
5156 $(document).ready(function(){
5157 js_recalculate_revenuestamp();
5158 $('select[name=revenuestamp_type]').on('change',function(){
5159 js_recalculate_revenuestamp();
5162 function js_recalculate_revenuestamp(){
5163 var valselected = $('select[name=revenuestamp_type]').val();
5164 console.log('Calculate revenue stamp from '+valselected);
5166 if (valselected.indexOf('%') == -1)
5168 revenue = valselected;
5172 var revenue_type = parseFloat(valselected);
5173 var amount_net = ".round(
$object->total_ht, 2).
";
5174 revenue = revenue_type * amount_net / 100;
5175 revenue = revenue.toFixed(2);
5177 $('#revenuestamp_val').val(revenue);
5178 $('#revenuestamp_span').html(revenue);
5182 print
price(
$object->revenuestamp, 1,
'', 1, -1, -1, $conf->currency);
5189 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
5190 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5191 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
5193 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5201 if (isModEnabled(
'project')) {
5204 if (isModEnabled(
"bank")) {
5208 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
5211 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
5214 if ($selleruserevenustamp) {
5217 if (isModEnabled(
'multicurrency')) {
5220 if (isModEnabled(
'incoterm')) {
5226 print
'<!-- List of situation invoices -->';
5227 print
'<table class="noborder situationstable" width="100%">';
5229 print
'<tr class="liste_titre">';
5230 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
5232 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
5233 if (isModEnabled(
"bank")) {
5234 print
'<td class="right"></td>';
5236 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
5237 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
5238 print
'<td width="18"> </td>';
5241 $total_prev_ht = $total_prev_ttc = 0;
5242 $total_global_ht = $total_global_ttc = 0;
5244 if (count(
$object->tab_previous_situation_invoice) > 0) {
5247 $current_situation_counter = array();
5248 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
5249 $tmptotalpaidforthisinvoice = $prev_invoice->getSommePaiement();
5250 $total_prev_ht += $prev_invoice->total_ht;
5251 $total_prev_ttc += $prev_invoice->total_ttc;
5252 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
5253 print
'<tr class="oddeven">';
5254 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
5256 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
5257 if (isModEnabled(
"bank")) {
5258 print
'<td class="right"></td>';
5260 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
5261 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
5262 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).
'</td>';
5268 $total_global_ht += $total_prev_ht;
5269 $total_global_ttc += $total_prev_ttc;
5270 $total_global_ht +=
$object->total_ht;
5271 $total_global_ttc +=
$object->total_ttc;
5273 print
'<tr class="oddeven">';
5274 print
'<td>'.$object->getNomUrl(1).
'</td>';
5276 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
5277 if (isModEnabled(
"bank")) {
5278 print
'<td class="right"></td>';
5280 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
5281 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
5282 print
'<td class="right">'.$object->getLibStatut(3,
$object->getSommePaiement()).
'</td>';
5286 print
'<tr class="oddeven">';
5287 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'CurrentSituationTotal').
'</b></td>';
5290 foreach ($current_situation_counter as $sit) {
5291 $curSign = $sit > 0 ?
'+' :
'-';
5292 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
5294 print
' '.$curSign.
' ';
5296 print $curType.abs($sit);
5300 if (isModEnabled(
"bank")) {
5303 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5304 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5305 print
'<td width="18"> </td>';
5309 if (count(
$object->tab_next_situation_invoice) > 0) {
5321 $total_next_ht = $total_next_ttc = 0;
5323 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
5324 $totalpaid = $next_invoice->getSommePaiement();
5325 $total_next_ht += $next_invoice->total_ht;
5326 $total_next_ttc += $next_invoice->total_ttc;
5328 print
'<tr class="oddeven">';
5329 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
5331 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
5332 if (isModEnabled(
"bank")) {
5333 print
'<td class="right"></td>';
5335 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
5336 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
5337 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid).
'</td>';
5341 $total_global_ht += $total_next_ht;
5342 $total_global_ttc += $total_next_ttc;
5344 print
'<tr class="oddeven">';
5345 print
'<td colspan="3" class="right"></td>';
5346 if (isModEnabled(
"bank")) {
5347 print
'<td class="right"></td>';
5349 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5350 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5351 print
'<td width="18"> </td>';
5359 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
5365 print
'<!-- List of payments already done -->';
5366 print
'<div class="div-table-responsive-no-min">';
5367 print
'<table class="noborder paymenttable centpercent">';
5369 print
'<tr class="liste_titre">';
5370 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
5371 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
5372 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
5373 if (isModEnabled(
"bank")) {
5374 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
5376 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
5377 print
'<td class="liste_titre" width="18"> </td>';
5381 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
5382 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
5383 $sql .=
' pf.amount,';
5384 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal, ba.currency_code as bacurrency_code';
5385 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
5386 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
5387 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
5388 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
5389 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
5390 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
5391 $sql .=
' ORDER BY p.datep, p.tms';
5393 $result = $db->query($sql);
5395 $num = $db->num_rows($result);
5400 $objp = $db->fetch_object($result);
5402 $paymentstatic->id = $objp->rowid;
5403 $paymentstatic->datepaye = $db->jdate($objp->dp);
5404 $paymentstatic->ref = $objp->ref;
5405 $paymentstatic->num_payment = $objp->num_payment;
5406 $paymentstatic->paiementcode = $objp->payment_code;
5408 print
'<tr class="oddeven"><td class="nowraponall">';
5409 print $paymentstatic->getNomUrl(1);
5412 $dateofpayment = $db->jdate($objp->dp);
5414 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
5421 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
5422 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
5423 if (isModEnabled(
"bank")) {
5424 $bankaccountstatic->id = $objp->baid;
5425 $bankaccountstatic->ref = $objp->baref;
5426 $bankaccountstatic->label = $objp->baref;
5427 $bankaccountstatic->number = $objp->banumber;
5428 $bankaccountstatic->currency_code = $objp->bacurrency_code;
5430 if (isModEnabled(
'accounting')) {
5431 $bankaccountstatic->account_number = $objp->account_number;
5434 $accountingjournal->fetch($objp->fk_accountancy_journal);
5435 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
5438 print
'<td class="nowraponall">';
5439 if ($bankaccountstatic->id) {
5440 print $bankaccountstatic->getNomUrl(1,
'transactions');
5444 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
5445 print
'<td class="center">';
5448 $paiement->fetch($objp->rowid);
5450 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
5467 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5468 print
'<span class="opacitymedium">';
5470 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
5472 print $langs->trans(
'AlreadyPaid');
5474 print
'</span></td><td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td><td> </td></tr>';
5476 $resteapayeraffiche = $resteapayer;
5477 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
5480 $creditnoteamount = 0;
5482 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
5483 $sql .=
" re.description, re.fk_facture_source";
5484 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
5485 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
5486 $resql = $db->query($sql);
5488 $num = $db->num_rows($resql);
5492 $obj = $db->fetch_object($resql);
5493 $invoice->fetch($obj->fk_facture_source);
5494 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5495 print
'<span class="opacitymedium">';
5497 print $langs->trans(
"CreditNote").
' ';
5500 print $langs->trans(
"Deposit").
' ';
5502 print $invoice->getNomUrl(0);
5505 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
5506 print
'<td class="right">';
5507 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
5508 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
5513 $creditnoteamount += $obj->amount_ttc;
5516 $depositamount += $obj->amount_ttc;
5525 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5526 print
'<span class="opacitymedium">';
5527 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
5529 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5530 $resteapayeraffiche = 0;
5531 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5535 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5536 print
'<span class="opacitymedium">';
5537 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
5539 print
'</td><td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td><td> </td></tr>';
5541 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5545 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5546 print
'<span class="opacitymedium">';
5547 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
5549 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5550 $resteapayeraffiche = 0;
5551 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5555 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5556 $text = $langs->trans(
"HelpAbandonOther");
5558 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
5560 print
'<span class="opacitymedium">';
5562 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
5564 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5565 $resteapayeraffiche = 0;
5566 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5570 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5571 print
'<span class="opacitymedium">';
5572 print $langs->trans(
"Billed");
5573 print
'</td><td class="right">'.price(
$object->total_ttc).
'</td><td> </td></tr>';
5575 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5576 print
'<span class="opacitymedium">';
5577 print $langs->trans(
'RemainderToPay');
5578 if ($resteapayeraffiche < 0) {
5579 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5583 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
5586 if (
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
5587 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5588 print
'<span class="opacitymedium">';
5589 print $langs->trans(
'RemainderToPayMulticurrency');
5590 if ($resteapayeraffiche < 0) {
5591 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5595 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">';
5597 print
price(
price2num(
$object->multicurrency_tx * $resteapayeraffiche,
'MT'), 1, $langs, 1, -1, -1, (empty(
$object->multicurrency_code) ? $conf->currency :
$object->multicurrency_code)).
'</td><td> </td></tr>';
5601 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
5604 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
5607 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
5610 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
5612 print
'<tr><td colspan="'.$nbcols.
'" align="right">'.$langs->trans(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')).
' :</td><td align="right">'.
price($billedWithRetainedWarranty).
'</td><td> </td></tr>';
5615 print
'<tr><td colspan="'.$nbcols.
'" align="right">';
5616 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
5617 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
5618 print
' :</td><td align="right">'.price($retainedWarranty).
'</td><td> </td></tr>';
5621 $resteapayeraffiche = $resteapayer;
5622 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5625 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5626 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
5627 print
'</td><td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td><td> </td></tr>';
5630 print
'<tr><td colspan="'.$nbcols.
'" class="right"><span class="opacitymedium">'.$langs->trans(
"Billed").
'</span></td><td class="right">'.
price($sign *
$object->total_ttc).
'</td><td> </td></tr>';
5633 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5634 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
5635 if ($resteapayeraffiche > 0) {
5636 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5638 print
'</span></td>';
5639 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
5640 print
'<td class="nowrap"> </td></tr>';
5643 if (
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
5644 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5645 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
5646 if ($resteapayeraffiche > 0) {
5647 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5651 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.(!empty(
$object->multicurrency_code) ?
$object->multicurrency_code : $conf->currency).
' '.
price(
price2num($sign *
$object->multicurrency_tx * $resteapayeraffiche,
'MT')).
'</td><td> </td></tr>';
5664 if (isModEnabled(
'margin')) {
5665 $formmargin->displayMarginInfos(
$object);
5671 print
'<div class="clearboth"></div><br><br>';
5674 $blocname =
'contacts';
5675 $title = $langs->trans(
'ContactsAddresses');
5676 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5680 $blocname =
'notes';
5681 $title = $langs->trans(
'Notes');
5682 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5686 $result =
$object->getLinesArray();
5690 global $inputalsopricewithtax;
5691 $inputalsopricewithtax = 1;
5696 print
'<!-- Area to change globally the situation percent -->'.
"\n";
5697 print
'<div class="div-table-responsive">';
5699 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'#updatealllines" method="POST">';
5700 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
5701 print
'<input type="hidden" name="action" value="updatealllines" />';
5702 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
5703 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5705 print
'<table id="tablelines_all_progress" class="noborder noshadow" width="100%">';
5707 print
'<tr class="liste_titre nodrag nodrop">';
5711 print
'<td align="center" width="5"> </td>';
5713 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
5714 print
'<td class="right">'.$langs->trans(
'Progress').
'</td>';
5715 print
'<td> </td>';
5718 print
'<tr class="nodrag nodrop">';
5721 print
'<td align="center" width="5"> </td>';
5723 print
'<td> </td>';
5724 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
5725 print
'<td class="right"><input type="submit" class="button" name="all_percent" value="Modifier" /></td>';
5736 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
5737 <input type="hidden" name="token" value="' .
newToken().
'">
5738 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
5739 <input type="hidden" name="mode" value="">
5740 <input type="hidden" name="page_y" value="">
5741 <input type="hidden" name="id" value="' .
$object->id.
'">
5742 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
5745 if (!empty($conf->use_javascript_ajax) &&
$object->status == 0) {
5746 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
5749 print
'<div class="div-table-responsive-no-min">';
5750 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
5754 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
5758 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
5759 if ($action !=
'editline' && $action !=
'selectlines') {
5762 $parameters = array();
5763 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
5767 if (empty($reshook)) {
5768 $object->formAddObjectLine(1, $mysoc, $soc);
5771 $parameters = array();
5772 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters,
$object, $action);
5786 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
5787 print
'<div class="tabsAction">';
5789 $parameters = array();
5790 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
5791 if (empty($reshook)) {
5794 'class' =>
'classfortooltip',
5801 $ventilExportCompta =
$object->getVentilExportCompta();
5803 if ($ventilExportCompta == 0) {
5805 if (!$objectidnext &&
$object->is_last_in_cycle()) {
5806 if ($usercanunvalidate) {
5807 unset($params[
'attr'][
'title']);
5808 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=modif&token='.
newToken(),
'',
true, $params);
5810 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
5811 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=modif&token='.
newToken(),
'',
false, $params);
5813 } elseif (!
$object->is_last_in_cycle()) {
5814 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
5815 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5817 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
5818 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5822 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5823 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5828 $result = $discount->fetch(0,
$object->id);
5836 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
5837 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
5838 unset($params[
'attr'][
'title']);
5839 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
5841 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
5842 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
5849 $langs->load(
"contracts");
5851 if ($usercancreatecontract) {
5852 print
'<a class="butAction" href="' . DOL_URL_ROOT .
'/contrat/card.php?action=create&origin=' .
$object->element .
'&originid=' .
$object->id .
'&socid=' .
$object->socid .
'">' . $langs->trans(
'AddContract') .
'</a>';
5859 if ($usercanvalidate) {
5860 unset($params[
'attr'][
'title']);
5861 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
5866 if (empty($user->socid)) {
5868 if ($objectidnext) {
5869 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'SendMail').
'</span>';
5872 unset($params[
'attr'][
'title']);
5873 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
5875 unset($params[
'attr'][
'title']);
5876 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
5884 if ($resteapayer > 0) {
5885 if ($usercancreatewithdrarequest) {
5886 if (!$objectidnext &&
$object->close_code !=
'replaced') {
5887 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/facture/prelevement.php?facid='.
$object->id.
'" title="'.
dol_escape_htmltag($langs->trans(
"MakeWithdrawRequest")).
'">'.$langs->trans(
"MakeWithdrawRequest").
'</a>';
5889 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
5900 if (isModEnabled(
'takepos') &&
$object->module_source ==
'takepos') {
5901 $langs->load(
"cashdesk");
5902 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
5903 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
5908 if ($objectidnext) {
5909 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
5913 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
5914 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
5918 unset($params[
'attr'][
'title']);
5919 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default', DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create'.(
$object->fk_account > 0 ?
'&accountid='.$object->fk_account :
''),
'', true, $params);
5924 $sumofpayment = $totalpaid;
5925 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
5931 if ($resteapayer == 0) {
5932 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
5934 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
5940 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
5944 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
5946 print
'<a class="butAction classfortooltip'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'" title="'.
dol_escape_htmltag($langs->trans(
"ConfirmConvertToReduc2")).
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
5953 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
5955 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
5969 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
5970 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
5972 unset($params[
'attr'][
'title']);
5973 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken(),
'',
true, $params);
5979 if ($totalpaid > 0 || $totalcreditnotes > 0) {
5981 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
5984 if ($objectidnext) {
5985 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
5987 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
5995 if (!$objectidnext) {
5996 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 :
'').(
$object->entity > 0 ?
'&originentity='.$object->entity :
'').
'">'.$langs->trans(
"CreateCreditNote").
'</a>';
6003 && (
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
6006 &&
$object->is_last_in_cycle()
6009 if ($usercanunvalidate) {
6010 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?socid='.
$object->socid.
'&fac_avoir='.
$object->id.
'&invoiceAvoirWithLines=1&action=create&type=2'.(
$object->fk_project > 0 ?
'&projectid='.$object->fk_project :
'').
'">'.$langs->trans(
"CreateCreditNote").
'</a>';
6012 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
6018 unset($params[
'attr'][
'title']);
6019 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice&token='.
newToken(),
'',
true, $params);
6024 if (!$objectidnext && count(
$object->lines) > 0) {
6025 unset($params[
'attr'][
'title']);
6026 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
6035 &&
$object->situation_counter > 1
6036 &&
$object->is_last_in_cycle()
6037 && $usercanunvalidate
6039 if ((
$object->total_ttc - $totalcreditnotes) == 0) {
6040 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6042 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6048 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
6049 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6050 } elseif (!
$object->is_last_in_cycle()) {
6051 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6053 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6058 $isErasable =
$object->is_erasable();
6060 if ($isErasable == -4) {
6061 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
6062 } elseif ($isErasable == -3) {
6063 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
6064 } elseif ($isErasable == -2) {
6065 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
6066 } elseif ($isErasable == -1) {
6067 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6068 } elseif ($isErasable <= 0) {
6069 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable');
6070 } elseif ($objectidnext) {
6071 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
6073 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
6074 $enableDelete =
false;
6076 if ($isErasable > 0 && ! $objectidnext) {
6077 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
6078 $enableDelete =
true;
6080 unset($params[
'attr'][
'title']);
6081 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
6083 unset($params[
'attr'][
'title']);
6084 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
6091 if (
GETPOST(
'modelselected',
'alpha')) {
6092 $action =
'presend';
6094 if ($action !=
'prerelance' && $action !=
'presend') {
6095 print
'<div class="fichecenter"><div class="fichehalfleft">';
6096 print
'<a name="builddoc"></a>';
6101 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
6102 $genallowed = $usercanread;
6103 $delallowed = $usercancreate;
6105 print $formfile->showdocuments(
6125 'remove_file_comfirm'
6128 $somethingshown = $formfile->numoffiles;
6131 $linktoelem = $form->showLinkToObjectBlock(
$object, array(), array(
'invoice'));
6133 $compatibleImportElementsList =
false;
6137 $compatibleImportElementsList = array(
'commande',
'propal');
6139 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem, $compatibleImportElementsList);
6143 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6144 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
6145 $useonlinepayment = count($validpaymentmethod);
6148 print
'<br><!-- Link to pay -->'.
"\n";
6149 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6150 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
6153 print
'</div><div class="fichehalfright">';
6157 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
6160 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
6162 $somethingshown = $formactions->showactions(
$object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
6164 print
'</div></div>';
6169 $modelmail =
'facture_send';
6170 $defaulttopic =
'SendBillRef';
6171 $diroutput = $conf->invoice->multidir_output[
$object->entity];
6172 $trackid =
'inv'.$object->id;
6174 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage bank accounts.
Class to manage accounting journals.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage shipments.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_DRAFT
Draft status.
const TYPE_STANDARD
Standard invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_PROFORMA
Proforma invoice (should not be used.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_DEPOSIT
Deposit invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const TYPE_CREDIT_NOTE
Credit note invoice.
const STATUS_CLOSED
Classified paid.
Class to manage invoice lines.
Class to manage invoice templates.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage the table of subscription to notifications.
Class to manage payments of customer invoices.
Class ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
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.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
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.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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 '.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
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.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify 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...
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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...
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid