46require
'../../main.inc.php';
47require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
55require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
56require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
57require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
58require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
59require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
60require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
61if (isModEnabled(
'order')) {
62 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
64if (isModEnabled(
'project')) {
65 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
66 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
68require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
70if (isModEnabled(
'variants')) {
71 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
73if (isModEnabled(
'accounting')) {
74 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
87$langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
88if (isModEnabled(
'incoterm')) {
89 $langs->load(
'incoterm');
91if (isModEnabled(
'margin')) {
92 $langs->load(
'margins');
99$action =
GETPOST(
'action',
'aZ09');
100$confirm =
GETPOST(
'confirm',
'alpha');
101$cancel =
GETPOST(
'cancel',
'alpha');
102$backtopage =
GETPOST(
'backtopage',
'alpha');
103$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
106$search_ref =
GETPOST(
'sf_ref',
'alpha') ?
GETPOST(
'sf_ref',
'alpha') :
GETPOST(
'search_ref',
'alpha');
107$search_societe =
GETPOST(
'search_societe',
'alpha');
108$search_montant_ht =
GETPOST(
'search_montant_ht',
'alpha');
109$search_montant_ttc =
GETPOST(
'search_montant_ttc',
'alpha');
110$origin =
GETPOST(
'origin',
'alpha');
114$ref_client =
GETPOST(
'ref_client',
'alpha');
115$inputReasonId =
GETPOSTINT(
'input_reason_id');
118$selectedLines =
GETPOST(
'toselect',
'array');
134$extrafields->fetch_name_optionals_label(
$object->table_element);
137$total_global_ttc = 0;
138$displayWarranty =
false;
139$statusreplacement = 0;
141$price_base_type =
'';
142$array_options = array();
145if ($id > 0 || !empty($ref)) {
146 if ($action !=
'add') {
148 $fetch_situation =
false;
150 $fetch_situation =
true;
152 $ret =
$object->fetch($id, $ref,
'', 0, $fetch_situation);
153 if ($ret > 0 && isset(
$object->fk_project)) {
154 $ret =
$object->fetchProject();
160$hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
163$usercanread = $user->hasRight(
"facture",
"lire");
164$usercancreate = $user->hasRight(
"facture",
"creer");
165$usercanissuepayment = $user->hasRight(
"facture",
"paiement");
166$usercandelete = $user->hasRight(
"facture",
"supprimer") || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
167$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
170$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'validate')));
171$usercansend = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercanread) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'send')));
172$usercanreopen = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'reopen')));
174 $usercanreopen =
false;
176$usercanunvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'unvalidate')));
177$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
180$usercancreatemargin = $user->hasRight(
'margins',
'creer');
181$usercanreadallmargin = $user->hasRight(
'margins',
'liretous');
182$usercancreatewithdrarequest = $user->hasRight(
'prelevement',
'bons',
'creer');
184$permissionnote = $usercancreate;
185$permissiondellink = $usercancreate;
186$permissiontoedit = $usercancreate;
187$permissiontoadd = $usercancreate;
188$permissiontoeditextra = $usercancreate;
189if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
191 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
195$retainedWarrantyInvoiceAvailableType = array();
197 $retainedWarrantyInvoiceAvailableType = explode(
'+',
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY'));
202 $socid = $user->socid;
215$parameters = array(
'socid' => $socid);
216$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
221if (empty($reshook)) {
222 $backurlforlist = DOL_URL_ROOT.
'/compta/facture/list.php';
224 if (empty($backtopage) || ($cancel && empty($id))) {
225 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
226 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
227 $backtopage = $backurlforlist;
229 $backtopage = DOL_URL_ROOT.
'/compta/facture/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
235 if (!empty($backtopageforcancel)) {
236 header(
"Location: ".$backtopageforcancel);
238 } elseif (!empty($backtopage)) {
239 header(
"Location: ".$backtopage);
245 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
247 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
249 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
252 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
254 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'IdThirdParty')),
null,
'errors');
257 '@phan-var-force Facture $objectutil';
260 $objectutil->socid = $socid;
261 $result = $objectutil->createFromClone($user, $id, (GETPOSTISSET(
'entity') ?
GETPOSTINT(
'entity') : null));
263 $warningMsgLineList = array();
265 foreach ($objectutil->lines as $line) {
266 if (!is_object($line->product)) {
267 $line->fetch_product();
269 if (is_object($line->product) && $line->product->id > 0) {
270 if (empty($line->product->status)) {
271 $warningMsgLineList[$line->id] = $langs->trans(
'WarningLineProductNotToSell', $line->product->ref);
275 if (!empty($warningMsgLineList)) {
279 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?facid=' . $result);
282 $langs->load(
"errors");
287 } elseif ($action ==
'reopen' && $usercanreopen) {
291 $result =
$object->setUnpaid($user);
293 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
299 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
304 $idwarehouse =
GETPOST(
'idwarehouse');
306 $qualified_for_stock_change = 0;
308 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
310 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
313 $isErasable =
$object->is_erasable();
315 if (($isErasable > 0) || ($usercancreate && $isErasable == 1)) {
316 $result =
$object->delete($user, 0, (
int) $idwarehouse);
318 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
325 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
335 $outputlangs = $langs;
341 $newlang =
$object->thirdparty->default_lang;
343 if (!empty($newlang)) {
345 $outputlangs->setDefaultLang($newlang);
346 $outputlangs->load(
'products');
350 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
353 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
360 } elseif ($action ==
'confirm_delete_subtotalline' && $confirm ==
'yes' && $usercancreate) {
365 $result =
$object->deleteSubtotalLine($langs,
GETPOSTINT(
'lineid'), (
bool)
GETPOST(
'deletecorrespondingsubtotalline'));
370 $outputlangs = $langs;
376 $newlang =
$object->thirdparty->default_lang;
378 if (!empty($newlang)) {
380 $outputlangs->setDefaultLang($newlang);
381 $outputlangs->load(
'products');
385 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
388 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
395 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
398 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
399 $discount->unlink_invoice();
400 } elseif ($action ==
'valid' && $usercancreate) {
404 if ((preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) &&
411 $last_of_type =
$object->willBeLastOfSameType(
true);
412 if (empty(
$object->date_validation) && !$last_of_type[0]) {
422 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
431 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
440 $array_of_total_ht_per_vat_rate = array();
441 $array_of_total_ht_devise_per_vat_rate = array();
442 foreach (
$object->lines as $line) {
444 $vat_src_code_for_line =
'';
445 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
446 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
448 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
449 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
451 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
452 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
456 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
457 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
458 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
460 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
461 if (
$object->type == $object::TYPE_DEPOSIT) {
462 $langs->load(
"errors");
464 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
468 $tmpvatratetoshow = explode(
'_', $vatrate);
469 $tmpvatratetoshow[0] = round((
float) $tmpvatratetoshow[0], 2);
471 if ($tmpvatratetoshow[0] != 0) {
472 $langs->load(
"errors");
473 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", (
string) $tmpvatratetoshow[0]),
null,
'errors');
481 } elseif ($action ==
'classin' && $usercancreate) {
484 } elseif ($action ==
'setposinfo' && $usercancreate) {
488 $result =
$object->update($user);
492 } elseif ($action ==
'setmode' && $usercancreate) {
498 } elseif ($action ==
'setretainedwarrantyconditions' && $usercancreate) {
500 $object->retained_warranty_fk_cond_reglement = 0;
501 $result =
$object->setRetainedWarrantyPaymentTerms(
GETPOSTINT(
'retained_warranty_fk_cond_reglement'));
506 $old_rw_date_lim_reglement =
$object->retained_warranty_date_limit;
507 $new_rw_date_lim_reglement =
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
508 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
509 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
514 $result =
$object->update($user);
518 } elseif ($action ==
'setretainedwarranty' && $usercancreate) {
524 } elseif ($action ==
'setretainedwarrantydatelimit' && $usercancreate) {
526 $result =
$object->setRetainedWarrantyDateLimit(
GETPOSTINT(
'retained_warranty_date_limit'));
530 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
531 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
532 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
534 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
536 $old_date_lim_reglement =
$object->date_lim_reglement;
538 if (empty($newdate)) {
539 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
540 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.
$id.
'&action=editinvoicedate&token='.
newToken());
545 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
547 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
552 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
553 if ($new_date_lim_reglement) {
554 $object->date_lim_reglement = $new_date_lim_reglement;
559 $result =
$object->update($user);
562 $action =
'editinvoicedate';
564 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
569 $object->date_pointoftax = $date_pointoftax;
570 $result =
$object->update($user);
574 } elseif ($action ==
'setconditions' && $usercancreate) {
576 $object->cond_reglement_code = 0;
577 $object->cond_reglement_id = 0;
590 $old_date_lim_reglement =
$object->date_lim_reglement;
591 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
592 if ($new_date_lim_reglement) {
593 $object->date_lim_reglement = $new_date_lim_reglement;
598 $result =
$object->update($user);
610 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
614 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
615 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
617 $result =
$object->update($user);
621 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
624 $result =
$object->update($user);
631 $outputlangs = $langs;
634 $newlang =
GETPOST(
'lang_id',
'aZ09');
637 $newlang =
$object->thirdparty->default_lang;
639 if (!empty($newlang)) {
641 $outputlangs->setDefaultLang($newlang);
642 $outputlangs->load(
'products');
647 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
653 } elseif ($action ==
'set_incoterms' && isModEnabled(
'incoterm') && $usercancreate) {
655 } elseif ($action ==
'settags' && isModEnabled(
'category') && $usercancreate) {
657 } elseif ($action ==
'setbankaccount' && $usercancreate) {
659 } elseif ($action ==
'setremisepercent' && $usercancreate) {
662 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
681 $newremaintopay =
$object->getRemainToPay(0);
682 if ($newremaintopay == 0) {
689 if (
GETPOSTINT(
"remise_id_for_payment") > 0) {
690 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
692 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
696 $remaintopay =
$object->getRemainToPay(0);
700 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
704 $result = $discount->link_to_invoice(0, $id);
712 $newremaintopay =
$object->getRemainToPay(0);
713 if ($newremaintopay == 0) {
726 $outputlangs = $langs;
729 $newlang =
GETPOST(
'lang_id',
'aZ09');
733 $newlang =
$object->thirdparty->default_lang;
735 if (!empty($newlang)) {
737 $outputlangs->setDefaultLang($newlang);
741 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
746 } elseif ($action ==
'setref' && $usercancreate) {
748 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', 0,
'',
'', $user,
'BILL_MODIFY');
749 } elseif ($action ==
'setref_client' && $usercancreate) {
752 } elseif ($action ==
'setdemandreason' && $usercancreate) {
753 $result =
$object->setInputReason($inputReasonId);
757 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
766 $qualified_for_stock_change = 0;
768 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
770 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
773 if ($qualified_for_stock_change) {
774 if (!$idwarehouse || $idwarehouse == - 1) {
776 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
783 $result =
$object->validate($user,
'', $idwarehouse);
787 $outputlangs = $langs;
790 $newlang =
GETPOST(
'lang_id',
'aZ09');
793 $newlang =
$object->thirdparty->default_lang;
795 if (!empty($newlang)) {
797 $outputlangs->setDefaultLang($newlang);
798 $outputlangs->load(
'products');
804 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
817 } elseif ($action ==
'confirm_modif' && $usercanunvalidate && !
getDolGlobalString(
'INVOICE_CAN_NEVER_BE_EDITED')) {
826 $qualified_for_stock_change = 0;
828 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
830 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
833 if ($qualified_for_stock_change) {
834 if (!$idwarehouse || $idwarehouse == -1) {
836 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
845 $sql =
'SELECT pf.amount';
846 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'paiement_facture as pf';
847 $sql .=
' WHERE pf.fk_facture = ' . ((int)
$object->id);
849 $result = $db->query($sql);
852 $num = $db->num_rows($result);
855 $objp = $db->fetch_object($result);
856 $totalpaid += $objp->amount;
863 $resteapayer =
$object->total_ttc - $totalpaid;
866 $ventilExportCompta =
$object->getVentilExportCompta();
869 if ($ventilExportCompta == 0) {
871 $result =
$object->setDraft($user, $idwarehouse);
878 $outputlangs = $langs;
881 $newlang =
GETPOST(
'lang_id',
'aZ09');
884 $newlang =
$object->thirdparty->default_lang;
886 if (!empty($newlang)) {
888 $outputlangs->setDefaultLang($newlang);
889 $outputlangs->load(
'products');
894 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
899 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
902 $result =
$object->setPaid($user);
906 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
909 $close_code =
GETPOST(
"close_code",
'restricthtml');
910 $close_note =
GETPOST(
"close_note",
'restricthtml');
912 $result =
$object->setPaid($user, $close_code, $close_note);
919 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
921 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
924 $close_code =
GETPOST(
"close_code",
'restricthtml');
925 $close_note =
GETPOST(
"close_note",
'restricthtml');
927 $result =
$object->setCanceled($user, $close_code, $close_note);
934 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
936 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
944 $result = $discountcheck->fetch(0,
$object->id);
957 $amount_ht = $amount_tva = $amount_ttc = array();
958 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
962 foreach (
$object->lines as $line) {
963 if ($line->product_type < 9 && $line->total_ht != 0) {
964 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
966 if (!isset($amount_ht[$keyforvatrate])) {
967 $amount_ht[$keyforvatrate] = 0;
969 $amount_ht[$keyforvatrate] += $line->total_ht;
970 if (!isset($amount_tva[$keyforvatrate])) {
971 $amount_tva[$keyforvatrate] = 0;
973 $amount_tva[$keyforvatrate] += $line->total_tva;
974 if (!isset($amount_ttc[$keyforvatrate])) {
975 $amount_ttc[$keyforvatrate] = 0;
977 $amount_ttc[$keyforvatrate] += $line->total_ttc;
978 if (!isset($multicurrency_amount_ht[$keyforvatrate])) {
979 $multicurrency_amount_ht[$keyforvatrate] = 0;
981 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
982 if (!isset($multicurrency_amount_tva[$keyforvatrate])) {
983 $multicurrency_amount_tva[$keyforvatrate] = 0;
985 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
986 if (!isset($multicurrency_amount_ttc[$keyforvatrate])) {
987 $multicurrency_amount_ttc[$keyforvatrate] = 0;
989 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
993 '@phan-var-force array<string,float> $amount_ht
994 @phan-var-force array<string,float> $amount_tva
995 @phan-var-force array<string,float> $amount_ttc
996 @phan-var-force array<string,float> $multicurrency_amount_ht
997 @phan-var-force array<string,float> $multicurrency_amount_tva
998 @phan-var-force array<string,float> $multicurrency_amount_ttc';
1002 $alreadypaid =
$object->getSommePaiement();
1003 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
1004 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
1005 foreach ($amount_ht as $vatrate => $val) {
1006 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
1007 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
1008 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
1009 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
1010 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
1011 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
1020 $discount->description =
'(CREDIT_NOTE)';
1022 $discount->description =
'(DEPOSIT)';
1024 $discount->description =
'(EXCESS RECEIVED)';
1026 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
1028 $discount->fk_soc =
$object->socid;
1029 $discount->socid =
$object->socid;
1030 $discount->fk_facture_source =
$object->id;
1039 $discount->description =
'(EXCESS RECEIVED)';
1042 $sql =
'SELECT SUM(pf.amount) as total_paiements';
1043 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
1044 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
1045 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
1046 $sql .=
' AND pf.fk_paiement = p.rowid';
1047 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
1048 $resql = $db->query($sql);
1053 $res = $db->fetch_object($resql);
1054 $total_paiements = $res->total_paiements;
1057 $total_creditnote_and_deposit = 0;
1058 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1059 $sql .=
" re.description, re.fk_facture_source";
1060 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1061 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
1062 $resql = $db->query($sql);
1063 if (!empty($resql)) {
1064 while ($obj = $db->fetch_object($resql)) {
1065 $total_creditnote_and_deposit += $obj->amount_ttc;
1071 $discount->amount_ttc =
price2num($total_paiements + $total_creditnote_and_deposit -
$object->total_ttc,
'MT');
1072 $discount->amount_tva = 0;
1073 $discount->amount_ht = $discount->amount_ttc;
1074 $discount->tva_tx = 0;
1075 $discount->vat_src_code =
'';
1077 if ($discount->amount_ttc > 0) {
1078 $result = $discount->create($user);
1088 $discount->description =
'(CREDIT_NOTE)';
1090 $discount->description =
'(DEPOSIT)';
1093 foreach ($amount_ht as $tva_tx => $xxx) {
1095 $discount->amount_ht = -((float) $amount_ht[$tva_tx]);
1096 $discount->amount_tva = -((float) $amount_tva[$tva_tx]);
1097 $discount->amount_ttc = -((float) $amount_ttc[$tva_tx]);
1098 $discount->total_ht = -((float) $amount_ht[$tva_tx]);
1099 $discount->total_tva = -((float) $amount_tva[$tva_tx]);
1100 $discount->total_ttc = -((float) $amount_ttc[$tva_tx]);
1101 $discount->multicurrency_amount_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1102 $discount->multicurrency_amount_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1103 $discount->multicurrency_amount_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1104 $discount->multicurrency_total_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1105 $discount->multicurrency_total_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1106 $discount->multicurrency_total_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1109 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
1110 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
1111 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
1112 $discount->total_ht = abs((
float) $amount_ht[$tva_tx]);
1113 $discount->total_tva = abs((
float) $amount_tva[$tva_tx]);
1114 $discount->total_ttc = abs((
float) $amount_ttc[$tva_tx]);
1115 $discount->multicurrency_amount_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1116 $discount->multicurrency_amount_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1117 $discount->multicurrency_amount_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1118 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1119 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1120 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1126 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
1127 $vat_src_code = $reg[1];
1128 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
1131 $discount->tva_tx = abs((
float) $tva_tx);
1132 $discount->vat_src_code = $vat_src_code;
1134 $result = $discount->create($user);
1142 if (empty($error)) {
1152 $result =
$object->setPaid($user);
1166 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
1171 $result = $paiement->fetch(
GETPOSTINT(
'paiement_id'));
1173 $result = $paiement->delete($user);
1175 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1183 } elseif ($action ==
'add' && $usercancreate) {
1190 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1196 $object->demand_reason_id = $inputReasonId;
1198 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
1208 if (empty($dateinvoice)) {
1210 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1220 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1230 $object->date_pointoftax = $date_pointoftax;
1231 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1232 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1243 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1244 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1261 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1263 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1267 if (empty($dateinvoice)) {
1269 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1279 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1284 if (!empty($originentity)) {
1285 $object->entity = $originentity;
1291 $object->date_pointoftax = $date_pointoftax;
1292 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1293 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1298 $object->cond_reglement_id = 0;
1304 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1305 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1309 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1312 $facture_source =
new Facture($db);
1313 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1314 if ($facture_source->isSituationInvoice()) {
1315 $object->situation_counter = $facture_source->situation_counter;
1316 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1317 $facture_source->fetchPreviousNextSituationInvoice();
1327 if (
$object->copy_linked_contact($facture_source,
'internal') < 0) {
1329 } elseif ($facture_source->socid ==
$object->socid) {
1331 if (
$object->copy_linked_contact($facture_source,
'external') < 0) {
1342 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1343 if (!empty($facture_source->lines)) {
1344 $fk_parent_line = 0;
1346 foreach ($facture_source->lines as $line) {
1348 if (method_exists($line,
'fetch_optionals')) {
1350 $line->fetch_optionals();
1354 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1355 $fk_parent_line = 0;
1359 if ($facture_source->isSituationInvoice()) {
1360 $source_fk_prev_id = $line->fk_prev_id;
1361 $line->fk_prev_id = $line->id;
1363 if (!empty($facture_source->tab_previous_situation_invoice)) {
1366 $tab_jumped_credit_notes = array();
1367 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1368 $searchPreviousInvoice =
true;
1369 while ($searchPreviousInvoice) {
1370 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1371 $searchPreviousInvoice =
false;
1375 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1381 $maxPrevSituationPercent = 0;
1382 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1383 if ($prevLine->id == $source_fk_prev_id) {
1384 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1387 $line->total_ht -= $prevLine->total_ht;
1388 $line->total_tva -= $prevLine->total_tva;
1389 $line->total_ttc -= $prevLine->total_ttc;
1390 $line->total_localtax1 -= $prevLine->total_localtax1;
1391 $line->total_localtax2 -= $prevLine->total_localtax2;
1393 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1394 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1395 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1396 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1401 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1406 $maxPrevSituationPercent = 0;
1407 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1408 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1409 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1410 $maxPrevSituationPercent = $prevLine->situation_percent;
1412 $line->total_ht -= $prevLine->total_ht;
1413 $line->total_tva -= $prevLine->total_tva;
1414 $line->total_ttc -= $prevLine->total_ttc;
1415 $line->total_localtax1 -= $prevLine->total_localtax1;
1416 $line->total_localtax2 -= $prevLine->total_localtax2;
1418 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1419 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1420 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1421 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1427 $line->situation_percent += $maxPrevSituationPercent;
1433 $line->fk_facture =
$object->id;
1434 $line->fk_parent_line = $fk_parent_line;
1436 $line->subprice = -$line->subprice;
1438 $line->total_ht = -$line->total_ht;
1439 $line->total_tva = -$line->total_tva;
1440 $line->total_ttc = -$line->total_ttc;
1441 $line->total_localtax1 = -$line->total_localtax1;
1442 $line->total_localtax2 = -$line->total_localtax2;
1444 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1445 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1446 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1447 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1449 $line->context[
'createcreditnotefrominvoice'] = 1;
1450 $result = $line->insert(0, 1);
1455 if ($result > 0 && $line->product_type == 9) {
1456 $fk_parent_line = $result;
1464 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1465 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1466 $totalpaid = $facture_source->getSommePaiement();
1467 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1468 $totaldeposits = $facture_source->getSumDepositsUsed();
1469 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1471 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1472 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1475 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1480 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1481 $tva_tx = (float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY');
1486 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), 0, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC', $remain_to_pay);
1491 if (!empty(
$object->fk_facture_source) &&
$id > 0) {
1492 $facture_source->fetch(
$object->fk_facture_source);
1493 $facture_source->fetchObjectLinked();
1495 if (!empty($facture_source->linkedObjectsIds)) {
1496 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1497 $object->add_object_linked($sourcetype, current($TIds));
1506 if (empty($dateinvoice)) {
1508 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1519 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1529 $object->date_pointoftax = $date_pointoftax;
1530 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1531 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1544 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1545 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1561 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1562 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1563 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1567 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1571 if (empty($dateinvoice)) {
1573 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1583 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1584 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1589 if ($typeamount && !empty($origin) && !empty($originid)) {
1590 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1591 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1595 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1596 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1600 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1601 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1611 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1621 $object->date_pointoftax = $date_pointoftax;
1622 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1623 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1635 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1636 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1640 $object->situation_counter = 1;
1645 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1647 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1649 $object->retained_warranty = 0;
1650 $object->retained_warranty_fk_cond_reglement = 0;
1653 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1654 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1657 $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);
1662 if (!empty($origin) && !empty($originid)) {
1665 $element = $subelement = $origin;
1666 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1667 $element = $regs[1];
1668 $subelement = $regs[2];
1672 if ($element ==
'order') {
1673 $element = $subelement =
'commande';
1675 if ($element ==
'propal') {
1676 $element =
'comm/propal';
1677 $subelement =
'propal';
1679 if ($element ==
'contract') {
1680 $element = $subelement =
'contrat';
1682 if ($element ==
'inter') {
1683 $element = $subelement =
'fichinter';
1685 if ($element ==
'shipping') {
1686 $element = $subelement =
'expedition';
1690 $object->origin_type = $origin;
1691 $object->origin_id = $originid;
1696 if (
$object->origin ==
'shipping') {
1697 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1699 $exp->fetch(
$object->origin_id);
1700 $exp->fetchObjectLinked();
1701 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1702 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1703 $object->linked_objects[
'commande'] = $value;
1709 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
1717 $classname = ucfirst($subelement);
1718 $srcobject =
new $classname($db);
1719 '@phan-var-force CommonObject $srcobject';
1721 dol_syslog(
"Try to find source object origin=".
$object->origin.
" originid=".
$object->origin_id.
" to add lines or deposit lines");
1722 $result = $srcobject->fetch(
$object->origin_id);
1728 $amountdeposit = array();
1731 if ($typeamount ==
'amount') {
1732 $amount = (float) $valuedeposit;
1734 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1737 $TTotalByTva = array();
1738 foreach ($srcobject->lines as &$line) {
1739 if (empty($line->qty)) {
1742 if (!empty($line->special_code)) {
1745 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1747 '@phan-var-force array<string,float> $TTotalByTva';
1749 $amount_ttc_diff = 0.;
1750 foreach ($TTotalByTva as $tva => &$total) {
1751 if (empty($amountdeposit[$tva])) {
1752 $amountdeposit[$tva] = 0;
1754 $coef = $total / $srcobject->total_ttc;
1755 $am = $amount * $coef;
1756 $amount_ttc_diff += $am;
1757 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1760 if ($typeamount ==
'amount') {
1761 $amountdeposit[0] = $valuedeposit;
1762 } elseif ($typeamount ==
'variable') {
1765 $lines = $srcobject->lines;
1766 $numlines = count($lines);
1767 for ($i = 0; $i < $numlines; $i++) {
1769 if (empty($lines[$i]->qty)) {
1772 if (!empty($lines[$i]->special_code)) {
1776 $totalamount += $lines[$i]->total_ht;
1777 $tva_tx = $lines[$i]->tva_tx;
1779 if (empty($amountdeposit[$tva_tx])) {
1780 $amountdeposit[$tva_tx] = 0;
1782 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1786 if ($totalamount == 0) {
1787 $amountdeposit[0] = 0;
1795 $amount_ttc_diff = $amountdeposit[0];
1798 foreach ($amountdeposit as $tva => $amount) {
1799 if (empty($amount)) {
1804 'amount' =>
'FixAmount',
1805 'variable' =>
'VarAmount'
1807 $descline =
'(DEPOSIT)';
1809 if ($typeamount ==
'amount') {
1810 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1811 } elseif ($typeamount ==
'variable') {
1812 $descline .=
' ('.$valuedeposit.
'%)';
1815 $descline .=
' - '.$srcobject->ref;
1828 $i >= 0 ? $lines[$i]->info_bits : 0,
1834 $i >= 0 ? $lines[$i]->special_code : 0,
1847 (!empty(
$conf->global->MAIN_DEPOSIT_MULTI_TVA) ? 0 : 1)
1851 $diff =
$object->total_ttc - $amount_ttc_diff;
1855 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1856 $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);
1865 $lines = $srcobject->lines;
1866 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1867 $srcobject->fetch_lines();
1868 $lines = $srcobject->lines;
1873 if (is_array($lines)) {
1874 foreach ($lines as $line) {
1876 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuestandardinvoice / 100,
'MS');
1882 if (is_array($lines)) {
1883 foreach ($lines as $line) {
1885 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuedeposit / 100,
'MS');
1890 $fk_parent_line = 0;
1891 $num = count($lines);
1893 for ($i = 0; $i < $num; $i++) {
1894 if (!in_array($lines[$i]->
id, $selectedLines)) {
1899 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
1903 if (!isset(
$conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1904 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1906 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
1910 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1911 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1913 if (
$object->situation_counter == 1) {
1914 $lines[$i]->situation_percent = 0;
1917 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
1920 $desc = $label ? $label : $langs->trans(
'Discount');
1924 $discount->fk_soc =
$object->socid;
1925 $discount->socid =
$object->socid;
1926 $discount->amount_ht = abs($lines[$i]->total_ht);
1927 $discount->amount_tva = abs($lines[$i]->total_tva);
1928 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1929 $discount->total_ht = abs($lines[$i]->total_ht);
1930 $discount->total_tva = abs($lines[$i]->total_tva);
1931 $discount->total_ttc = abs($lines[$i]->total_ttc);
1932 $discount->tva_tx = $lines[$i]->tva_tx;
1933 $discount->fk_user = $user->id;
1934 $discount->description = $desc;
1935 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1936 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1937 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1938 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1939 $discount->multicurrency_total_ht = abs($lines[$i]->multicurrency_total_ht);
1940 $discount->multicurrency_total_tva = abs($lines[$i]->multicurrency_total_tva);
1941 $discount->multicurrency_total_ttc = abs($lines[$i]->multicurrency_total_ttc);
1943 $discountid = $discount->create($user);
1944 if ($discountid > 0) {
1945 $result =
$object->insert_discount($discountid);
1957 $date_start =
false;
1958 if (isset($lines[$i]->date_debut_prevue)) {
1959 $date_start = $lines[$i]->date_debut_prevue;
1961 if (isset($lines[$i]->date_debut_reel)) {
1962 $date_start = $lines[$i]->date_debut_reel;
1964 if (isset($lines[$i]->date_start)) {
1965 $date_start = $lines[$i]->date_start;
1970 if (isset($lines[$i]->date_fin_prevue)) {
1971 $date_end = $lines[$i]->date_fin_prevue;
1973 if (isset($lines[$i]->date_fin_reel)) {
1974 $date_end = $lines[$i]->date_fin_reel;
1976 if (isset($lines[$i]->date_end)) {
1977 $date_end = $lines[$i]->date_end;
1981 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1982 $fk_parent_line = 0;
1985 $array_options = array();
1987 if (method_exists($lines[$i],
'fetch_optionals')) {
1988 $lines[$i]->fetch_optionals();
1989 $array_options = $lines[$i]->array_options;
1992 $tva_tx = $lines[$i]->tva_tx;
1993 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
1994 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
2004 $lines[$i]->subprice,
2009 $lines[$i]->fk_product,
2010 $lines[$i]->remise_percent,
2014 $lines[$i]->info_bits,
2015 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except : null,
2020 $lines[$i]->special_code,
2024 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice : null,
2028 $lines[$i]->situation_percent ?? 100,
2029 $lines[$i]->fk_prev_id ?? 0,
2030 $lines[$i]->fk_unit,
2037 foreach (
$object->lines as $line) {
2038 if ($line->id == $result) {
2039 $line->extraparams = $lines[$i]->extraparams;
2040 $line->setExtraParameters();
2052 if ($result > 0 && $lines[$i]->product_type == 9) {
2053 $fk_parent_line = $result;
2063 $object->update_price(1,
'auto', 0, $mysoc);
2065 $object->line_order(
true,
'DESC');
2093 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id,
'objFrom' => $srcobject);
2094 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
2107 for ($i = 1; $i <= $NBLINES; $i++) {
2113 $result =
$object->addline($product->description, $product->price, (
float)
price2num(
GETPOST(
'qty'.$i),
'MS'), $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx,
GETPOSTINT(
'idprod'.$i), (
float)
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);
2117 $object->update_price(1,
'auto', 0, $mysoc);
2124 if (empty($dateinvoice)) {
2126 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
2136 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
2146 if (!empty($origin) && !empty($originid)) {
2147 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2150 $object->origin_type = $origin;
2151 $object->origin_id = $originid;
2155 $retained_warranty =
GETPOSTINT(
'retained_warranty');
2156 if (
price2num($retained_warranty) > 0) {
2160 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
2161 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
2164 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
2165 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
2166 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
2168 $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);
2171 foreach (
$object->lines as $i => &$line) {
2172 $line->fk_prev_id = $line->id;
2173 $line->fetch_optionals();
2175 $line->situation_percent = 0;
2177 $line->situation_percent = $line->get_prev_progress(
$object->id);
2181 $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);
2182 $line->total_ht = (float) $tabprice[0];
2183 $line->total_tva = (float) $tabprice[1];
2184 $line->total_ttc = (float) $tabprice[2];
2185 $line->total_localtax1 = (float) $tabprice[9];
2186 $line->total_localtax2 = (float) $tabprice[10];
2187 $line->multicurrency_total_ht = (float) $tabprice[16];
2188 $line->multicurrency_total_tva = (float) $tabprice[17];
2189 $line->multicurrency_total_ttc = (float) $tabprice[18];
2192 if ($line->fk_remise_except) {
2194 $result = $discount->fetch($line->fk_remise_except);
2197 if ($discount->fk_facture_line > 0) {
2198 $line->fk_remise_except = 0;
2207 $object->date_pointoftax = $date_pointoftax;
2208 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2224 $object->situation_counter += 1;
2230 $nextSituationInvoice =
new Facture($db);
2231 $nextSituationInvoice->fetch($id);
2234 $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
2235 $ret = $extrafields->setOptionalsFromPost(
null, $nextSituationInvoice);
2237 $nextSituationInvoice->insertExtraFields();
2241 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id);
2242 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $nextSituationInvoice, $action);
2253 if ($id > 0 && !$error) {
2254 if (isModEnabled(
'category')) {
2255 $categories =
GETPOST(
'categories',
'array');
2256 if (method_exists(
$object,
'setCategories')) {
2257 $object->setCategories($categories);
2265 $outputlangs = $langs;
2268 $newlang =
GETPOST(
'lang_id',
'aZ09');
2271 if (empty(
$object->thirdparty)) {
2274 $newlang =
$object->thirdparty->default_lang;
2276 if (!empty($newlang)) {
2278 $outputlangs->setDefaultLang($newlang);
2279 $outputlangs->load(
'products');
2284 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2290 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2295 $_GET[
"origin"] = $_POST[
"origin"];
2296 $_GET[
"originid"] = $_POST[
"originid"];
2299 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2303 foreach (
$object->lines as $line) {
2304 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2307 if ($line->product_type == 1) {
2308 $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);
2311 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2313 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2314 $vat_rate = str_replace(
'*',
'', $vat_rate);
2317 foreach (
$object->lines as $line) {
2318 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2321 $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);
2323 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2325 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2326 $remise_percent = str_replace(
'*',
'', $remise_percent);
2327 foreach (
$object->lines as $line) {
2328 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2331 $tvatx = $line->tva_tx;
2332 if (!empty($line->vat_src_code)) {
2333 $tvatx .=
' ('.$line->vat_src_code.
')';
2335 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, (
float) $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);
2337 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
2340 $langs->load(
'subtotals');
2342 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
2343 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
2345 $subtotal_options = array();
2347 foreach (Facture::$TITLE_OPTIONS as $option) {
2348 $value =
GETPOST($option,
'alphanohtml');
2350 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2355 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2366 $outputlangs = $langs;
2367 $newlang =
GETPOST(
'lang_id',
'alpha');
2369 $newlang =
$object->thirdparty->default_lang;
2371 if (!empty($newlang)) {
2373 $outputlangs->setDefaultLang($newlang);
2376 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2381 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2383 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
2386 $langs->load(
'subtotals');
2388 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
2389 foreach (
$object->lines as $line) {
2390 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
2391 $desc = $line->desc;
2392 $depth = -$line->qty;
2396 $subtotal_options = array();
2398 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
2399 $value =
GETPOST($option,
'alphanohtml');
2401 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2406 if (isset($desc) && isset($depth)) {
2407 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2409 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
2412 if (isset($result) && $result >= 0) {
2418 $outputlangs = $langs;
2419 $newlang =
GETPOST(
'lang_id',
'alpha');
2421 $newlang =
$object->thirdparty->default_lang;
2423 if (!empty($newlang)) {
2425 $outputlangs->setDefaultLang($newlang);
2428 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2433 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2435 } elseif ($action ==
'addline' &&
GETPOST(
'updateallvatlinesblock',
'alpha') &&
GETPOST(
'vatforblocklines',
'alpha') !==
'' && $usercancreate) {
2436 $tx_tva =
GETPOST(
'vatforblocklines') ?
GETPOST(
'vatforblocklines') : 0;
2437 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'tva', $tx_tva);
2438 } elseif ($action ==
'addline' &&
GETPOST(
'updatealldiscountlinesblock',
'alpha') &&
GETPOST(
'discountforblocklines',
'alpha') !==
'' && $usercancreate) {
2439 $discount =
GETPOST(
'discountforblocklines') ?
GETPOST(
'discountforblocklines') : 0;
2440 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'discount', $discount);
2441 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && !
GETPOST(
'submitforallmark',
'alpha') && $usercancreate) {
2442 $langs->load(
'errors');
2447 $line_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
2450 $price_ht_devise =
'';
2452 $price_ttc_devise =
'';
2455 $price_min_ttc =
'';
2457 if (
GETPOST(
'price_ht') !==
'') {
2460 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2463 if (
GETPOST(
'price_ttc') !==
'') {
2466 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2467 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2470 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2471 if ($prod_entry_mode ==
'free') {
2477 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2482 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2485 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
2486 if (empty($remise_percent)) {
2487 $remise_percent = 0;
2491 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2492 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2494 if (is_array($extralabelsline)) {
2496 foreach ($extralabelsline as $key => $value) {
2497 unset($_POST[
"options_".$key.$predef]);
2501 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2502 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2505 if (!$prod_entry_mode) {
2507 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2511 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2512 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2517 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0)
2518 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
2519 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
2520 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
2521 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
2522 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
2523 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2524 $langs->load(
"errors");
2525 if (
$object->type == $object::TYPE_DEPOSIT) {
2527 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2529 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2534 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
2535 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
2539 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
2540 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2544 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2548 $langs->load(
"errors");
2549 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2553 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2554 if ($combinations =
GETPOST(
'combinations',
'array')) {
2558 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2559 $idprod = $res->fk_product_child;
2561 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2567 $price_base_type =
null;
2568 if (!$error && ($qty >= 0) && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
2574 $ret =
$object->fetch_thirdparty();
2579 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2590 if (!empty($idprod) && $idprod > 0) {
2592 $prod->fetch($idprod);
2594 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2599 $datapriceofproduct = $prod->getSellPrice($mysoc,
$object->thirdparty, $pqp);
2601 $pu_ht = $datapriceofproduct[
'pu_ht'];
2602 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2603 $price_min = $datapriceofproduct[
'price_min'];
2604 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2605 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2609 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2610 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $prod->tva_tx));
2614 if (!empty($price_ht) || $price_ht ===
'0') {
2616 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2617 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2618 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2621 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2623 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2624 } elseif ($tmpvat != $tmpprodvat) {
2626 if ($price_base_type !=
'HT') {
2627 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2629 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2633 $outputlangs = $langs;
2639 if (
GETPOST(
'lang_id',
'aZ09')) {
2640 $newlang =
GETPOST(
'lang_id',
'aZ09');
2642 if (empty($newlang)) {
2643 $newlang =
$object->thirdparty->default_lang;
2645 if (!empty($newlang)) {
2647 $outputlangs->setDefaultLang($newlang);
2648 $outputlangs->load(
'products');
2651 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->
description;
2653 $desc = $prod->description;
2665 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
2669 if (!empty($prod->customcode)) {
2670 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomsCode").
': '.$prod->customcode;
2672 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2675 if (!empty($prod->country_code)) {
2676 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $outputlangs, 0);
2679 if (!empty($prod->customcode)) {
2680 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomsCode").
': '.$prod->customcode;
2682 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2685 if (!empty($prod->country_code)) {
2686 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $langs, 0);
2693 $type = $prod->type;
2694 $fk_unit = $prod->fk_unit;
2696 if (!empty($price_ht)) {
2701 if (!empty($price_ttc)) {
2706 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2707 $tva_tx = str_replace(
'*',
'', $tva_tx);
2708 if (empty($tva_tx)) {
2711 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2714 $fk_unit =
GETPOST(
'units',
'alpha');
2716 if ($pu_ttc && !$pu_ht) {
2717 $price_base_type =
'TTC';
2731 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2732 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2735 $pu_equivalent = $pu_ht;
2736 $pu_equivalent_ttc = $pu_ttc;
2738 $currency_tx =
$object->multicurrency_tx;
2745 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2746 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
2748 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2749 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
2764 $fournprice = (int) (
GETPOST(
'fournprice'.$predef) ?
GETPOST(
'fournprice'.$predef) :
'');
2769 $price2num_remise_percent =
price2num($remise_percent);
2770 $price2num_price_min =
price2num($price_min);
2771 $price2num_price_min_ttc =
price2num($price_min_ttc);
2772 if (empty($price2num_pu_ht)) {
2773 $price2num_pu_ht = 0;
2775 if (empty($price2num_remise_percent)) {
2776 $price2num_remise_percent = 0;
2778 if (empty($price2num_price_min)) {
2779 $price2num_price_min = 0;
2781 if (empty($price2num_price_min_ttc)) {
2782 $price2num_price_min_ttc = 0;
2787 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2788 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2791 } 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') {
2792 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2799 '@phan-var-force CommonObjectLine[] $lines';
2801 if (isModEnabled(
'productbatch') && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) &&
getDolGlobalString(
'INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS')) {
2802 $langs->load(
'productbatch');
2803 foreach ($lines[$i]->detail_batch as $batchline) {
2804 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2808 $situation_percent = GETPOSTISSET(
'progress') ?
GETPOSTINT(
'progress') : 100;
2811 $result =
$object->addline($desc, $pu_ht, (
float) $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,
GETPOSTINT(
'fk_parent_line'), (
int) $fournprice, $buyingprice, $label, $array_options, $situation_percent, 0, $fk_unit, (
float) $pu_ht_devise);
2816 $outputlangs = $langs;
2819 $newlang =
GETPOST(
'lang_id',
'aZ09');
2822 $newlang =
$object->thirdparty->default_lang;
2824 if (!empty($newlang)) {
2826 $outputlangs->setDefaultLang($newlang);
2827 $outputlangs->load(
'products');
2832 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2838 unset($_POST[
'prod_entry_mode']);
2839 unset($_POST[
'qty']);
2840 unset($_POST[
'type']);
2841 unset($_POST[
'remise_percent']);
2842 unset($_POST[
'price_ht']);
2843 unset($_POST[
'multicurrency_price_ht']);
2844 unset($_POST[
'price_ttc']);
2845 unset($_POST[
'tva_tx']);
2846 unset($_POST[
'product_ref']);
2847 unset($_POST[
'product_label']);
2848 unset($_POST[
'product_desc']);
2849 unset($_POST[
'fournprice']);
2850 unset($_POST[
'buying_price']);
2851 unset($_POST[
'np_marginRate']);
2852 unset($_POST[
'np_markRate']);
2853 unset($_POST[
'dp_desc']);
2854 unset($_POST[
'idprod']);
2855 unset($_POST[
'units']);
2856 unset($_POST[
'date_starthour']);
2857 unset($_POST[
'date_startmin']);
2858 unset($_POST[
'date_startsec']);
2859 unset($_POST[
'date_startday']);
2860 unset($_POST[
'date_startmonth']);
2861 unset($_POST[
'date_startyear']);
2862 unset($_POST[
'date_endhour']);
2863 unset($_POST[
'date_endmin']);
2864 unset($_POST[
'date_endsec']);
2865 unset($_POST[
'date_endday']);
2866 unset($_POST[
'date_endmonth']);
2867 unset($_POST[
'date_endyear']);
2868 unset($_POST[
'situations']);
2869 unset($_POST[
'progress']);
2877 } elseif ($action ==
'addline' && $usercancreate && (
2878 (
GETPOST(
'submitforallmargins',
'alpha') &&
GETPOST(
'marginforalllines',
'alpha') !==
'') ||
2879 (
GETPOST(
'submitforallmark',
'alpha') &&
GETPOST(
'markforalllines',
'alpha') !==
''))) {
2881 $margin_rate = GETPOSTISSET(
'marginforalllines') ?
GETPOST(
'marginforalllines',
'int') :
'';
2882 $mark_rate = GETPOSTISSET(
'markforalllines') ?
GETPOST(
'markforalllines',
'int') :
'';
2883 foreach (
$object->lines as &$line)
if ($line->subprice > 0) {
2884 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2887 $subprice_multicurrency = $line->subprice;
2888 if (is_numeric($margin_rate) && $margin_rate > 0) {
2889 $line->subprice = floatval(
price2num(floatval($line->pa_ht) * (1 + floatval($margin_rate) / 100),
'MU'));
2890 } elseif (is_numeric($mark_rate) && $mark_rate > 0) {
2891 $line->subprice = floatval($line->pa_ht / (1 - (floatval($mark_rate) / 100)));
2893 $line->subprice = floatval($line->pa_ht);
2897 $res = $prod->fetch($line->fk_product);
2899 if ($prod->price_min > $line->subprice) {
2900 $price_subprice =
price($line->subprice, 0, $outlangs, 1, -1, -1,
'auto');
2901 $price_price_min =
price($prod->price_min, 0, $outlangs, 1, -1, -1,
'auto');
2902 setEventMessages($prod->ref .
' - ' . $prod->label .
' (' . $price_subprice .
' < ' . $price_price_min .
' ' . strtolower($langs->trans(
"MinPrice")) .
')' .
"\n",
null,
'warnings');
2910 $multicurrency_subprice = (float) $line->subprice * $line->multicurrency_subprice / $subprice_multicurrency;
2912 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->date_start, $line->date_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->product_ref, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $multicurrency_subprice);
2915 if (is_numeric($margin_rate) && empty($mark_rate)) {
2916 $line->marge_tx = $margin_rate;
2917 } elseif (is_numeric($mark_rate) && empty($margin_rate)) {
2918 $line->marque_tx = $mark_rate;
2920 $line->total_ht = $line->qty * (float) $line->subprice;
2921 $line->total_tva = $line->tva_tx * $line->qty * (float) $line->subprice;
2922 $line->total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $line->subprice;
2924 $line->multicurrency_total_ht = $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
2925 $line->multicurrency_total_tva = $line->tva_tx * $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
2926 $line->multicurrency_total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
2928 $line->multicurrency_subprice = $multicurrency_subprice;
2933 } elseif ($action ==
'updatetitleline' && GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2936 $langs->load(
'subtotals');
2938 $desc =
GETPOST(
'line_desc',
'alphanohtml') ?? $langs->trans(
"Title");
2941 $subtotal_options = array();
2943 foreach (Facture::$TITLE_OPTIONS as $option) {
2944 $value =
GETPOST($option,
'alphanohtml');
2946 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2951 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
2962 $outputlangs = $langs;
2963 $newlang =
GETPOST(
'lang_id',
'alpha');
2965 $newlang =
$object->thirdparty->default_lang;
2967 if (!empty($newlang)) {
2969 $outputlangs->setDefaultLang($newlang);
2972 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2977 } elseif ($action ==
'updatesubtotalline' && GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2980 $langs->load(
'subtotals');
2982 $desc =
GETPOST(
'line_desc',
'alphanohtml');
2985 $subtotal_options = array();
2987 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
2988 $value =
GETPOST($option,
'alphanohtml');
2990 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2995 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3003 $outputlangs = $langs;
3004 $newlang =
GETPOST(
'lang_id',
'alpha');
3006 $newlang =
$object->thirdparty->default_lang;
3008 if (!empty($newlang)) {
3010 $outputlangs->setDefaultLang($newlang);
3013 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3018 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3019 if (!
$object->fetch($id) > 0) {
3042 if (preg_match(
'/\*/', $vat_rate)) {
3047 $vat_rate = str_replace(
'*',
'', $vat_rate);
3052 $fournprice = (int) (
GETPOST(
'fournprice') ?
GETPOST(
'fournprice') :
'');
3056 $pu_equivalent = $pu_ht;
3057 $pu_equivalent_ttc = $pu_ttc;
3059 $currency_tx =
$object->multicurrency_tx;
3066 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
3067 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
3069 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
3070 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
3085 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
3086 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
3088 if (is_array($extralabelsline)) {
3090 foreach ($extralabelsline as $key => $value) {
3091 unset($_POST[
"options_".$key]);
3097 if ($special_code == 3) {
3103 $percent = $line->get_prev_progress(
$object->id);
3108 if ($progress >= 0) {
3109 $mesg = $langs->trans(
"CantBeNullOrPositive");
3113 } elseif ($progress < $line->situation_percent) {
3114 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
3118 } elseif ($progress < $percent) {
3119 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
3128 $price_base_type =
'HT';
3130 if (empty($pu) && !empty($pu_ttc)) {
3132 $price_base_type =
'TTC';
3137 if (!empty($productid)) {
3139 $product->fetch($productid);
3141 $type = $product->type;
3143 $price_min = $product->price_min;
3145 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
3147 $price_min_ttc = $product->price_min_ttc;
3149 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
3156 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
3157 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3160 $action =
'editline';
3161 } 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') {
3162 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3165 $action =
'editline';
3170 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
3174 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
3179 $langs->load(
"errors");
3180 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
3184 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
3185 $langs->load(
"errors");
3186 if (
$object->type == $object::TYPE_DEPOSIT) {
3188 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
3190 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
3194 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
3201 $previousprogress = $line->getAllPrevProgress($line->fk_facture);
3204 if ($fullprogress < $previousprogress) {
3206 setEventMessages($langs->trans(
'CantBeLessThanMinPercent'),
null,
'errors');
3210 if ($fullprogress > 100) {
3211 $fullprogress = 100;
3213 $addprogress = $fullprogress - $previousprogress;
3220 if (empty($usercancreatemargin)) {
3221 foreach (
$object->lines as &$line) {
3223 $fournprice = $line->fk_fournprice;
3224 $buyingprice = $line->pa_ht;
3230 $result =
$object->updateline(
3235 (
float) $remise_percent,
3253 (
float) $pu_ht_devise
3259 $outputlangs = $langs;
3262 $newlang =
GETPOST(
'lang_id',
'aZ09');
3265 $newlang =
$object->thirdparty->default_lang;
3267 if (!empty($newlang)) {
3269 $outputlangs->setDefaultLang($newlang);
3270 $outputlangs->load(
'products');
3274 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3277 unset($_POST[
'qty']);
3278 unset($_POST[
'type']);
3279 unset($_POST[
'productid']);
3280 unset($_POST[
'remise_percent']);
3281 unset($_POST[
'price_ht']);
3282 unset($_POST[
'multicurrency_price_ht']);
3283 unset($_POST[
'price_ttc']);
3284 unset($_POST[
'tva_tx']);
3285 unset($_POST[
'product_ref']);
3286 unset($_POST[
'product_label']);
3287 unset($_POST[
'product_desc']);
3288 unset($_POST[
'fournprice']);
3289 unset($_POST[
'buying_price']);
3290 unset($_POST[
'np_marginRate']);
3291 unset($_POST[
'np_markRate']);
3292 unset($_POST[
'dp_desc']);
3293 unset($_POST[
'idprod']);
3294 unset($_POST[
'units']);
3295 unset($_POST[
'date_starthour']);
3296 unset($_POST[
'date_startmin']);
3297 unset($_POST[
'date_startsec']);
3298 unset($_POST[
'date_startday']);
3299 unset($_POST[
'date_startmonth']);
3300 unset($_POST[
'date_startyear']);
3301 unset($_POST[
'date_endhour']);
3302 unset($_POST[
'date_endmin']);
3303 unset($_POST[
'date_endsec']);
3304 unset($_POST[
'date_endday']);
3305 unset($_POST[
'date_endmonth']);
3306 unset($_POST[
'date_endyear']);
3307 unset($_POST[
'situations']);
3308 unset($_POST[
'progress']);
3313 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modify')) {
3314 if (!
$object->fetch($id) > 0) {
3317 if (
GETPOST(
'all_progress') !=
"") {
3319 foreach (
$object->lines as $line) {
3321 $percent = $line->getAllPrevProgress(
$object->id);
3323 $percent = $line->get_prev_progress(
$object->id);
3325 if ((
float) $all_progress < (
float) $percent) {
3326 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
3335 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
3336 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
3338 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
3340 $object->fetch($id,
'',
'', 0,
true);
3343 &&
$object->isSituationInvoice()
3346 &&
$object->is_last_in_cycle()
3347 && $usercanunvalidate
3350 $newCycle =
$object->newCycle();
3351 if ($newCycle > 1) {
3353 $lastCycle =
$object->situation_cycle_ref;
3354 $lastSituationCounter =
$object->situation_counter;
3355 $linkedCreditNotesList = array();
3357 if (count(
$object->tab_next_situation_invoice) > 0) {
3358 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
3360 && $next_invoice->situation_counter ==
$object->situation_counter
3361 && $next_invoice->fk_facture_source ==
$object->id
3363 $linkedCreditNotesList[] = $next_invoice->id;
3368 $object->situation_cycle_ref = $newCycle;
3369 $object->situation_counter = 1;
3371 if (
$object->update($user) > 0) {
3373 if (count($linkedCreditNotesList) > 0) {
3375 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
3376 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
3377 $sql .=
' , situation_final=0';
3378 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
3379 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
3381 $resql = $db->query($sql);
3387 foreach (
$object->lines as $line) {
3389 if ($line->product_type == 9) {
3394 if (!empty(
$object->tab_previous_situation_invoice)) {
3396 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
3397 $searchPreviousInvoice =
true;
3398 while ($searchPreviousInvoice) {
3399 if (
$object->tab_previous_situation_invoice[$lineIndex]->isSituationInvoice() || $lineIndex < 1) {
3400 $searchPreviousInvoice =
false;
3408 $maxPrevSituationPercent = 0;
3409 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
3410 if ($prevLine->id == $line->fk_prev_id) {
3411 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
3416 $line->situation_percent -= $maxPrevSituationPercent;
3418 if ($line->update() < 0) {
3427 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
3429 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
3432 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
3435 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
3441 $fromElement =
GETPOST(
'fromelement');
3442 $fromElementid =
GETPOST(
'fromelementid');
3443 $importLines =
GETPOST(
'line_checkbox');
3445 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
3446 $lineClassName =
'';
3447 if ($fromElement ==
'commande') {
3449 $lineClassName =
'OrderLine';
3450 } elseif ($fromElement ==
'propal') {
3451 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
3452 $lineClassName =
'PropaleLigne';
3454 $nextRang = count(
$object->lines) + 1;
3457 foreach ($importLines as $lineId) {
3458 if ($lineClassName ===
'') {
3462 dol_syslog(
'compta/facture/card - No lineClassName - skip import', LOG_ERR);
3469 $lineId = intval($lineId);
3470 $originLine =
new $lineClassName($db);
3471 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
3472 $originLine->fetch_optionals();
3473 $desc = $originLine->desc;
3474 $pu_ht = $originLine->subprice;
3475 $qty = $originLine->qty;
3476 $txtva = $originLine->tva_tx;
3477 $txlocaltax1 = $originLine->localtax1_tx;
3478 $txlocaltax2 = $originLine->localtax2_tx;
3479 $fk_product = $originLine->fk_product;
3480 $remise_percent = $originLine->remise_percent;
3481 $date_start = $originLine->date_start;
3482 $date_end = $originLine->date_end;
3483 $fk_code_ventilation = 0;
3484 $info_bits = $originLine->info_bits;
3485 $fk_remise_except = $originLine->fk_remise_except;
3486 $price_base_type =
'HT';
3488 $type = $originLine->product_type;
3489 $rang = $nextRang++;
3490 $special_code = $originLine->special_code;
3491 $origin = $originLine->element;
3492 $origin_id = $originLine->id;
3493 $fk_parent_line = 0;
3494 $fk_fournprice = $originLine->fk_fournprice;
3495 $pa_ht = $originLine->pa_ht;
3496 $label = $originLine->label;
3497 $array_options = $originLine->array_options;
3498 if (
$object->isSituationInvoice()) {
3499 $situation_percent = 0;
3501 $situation_percent = 100;
3504 $fk_unit = $originLine->fk_unit;
3505 $pu_ht_devise = $originLine->multicurrency_subprice;
3507 $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);
3527 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3533 if (!empty(
$object->id) && $action ==
'send') {
3535 $object->getSommePaiement(-1);
3536 $object->getSumCreditNotesUsed(-1);
3537 $object->getSumDepositsUsed(-1);
3539 $triggersendname =
'BILL_SENTBYMAIL';
3541 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3542 $trackid =
'inv'.$object->id;
3543 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3547 $permissiontoadd = $usercancreate;
3548 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3551 if ($action ==
'update_extras' && $permissiontoeditextra) {
3554 $attribute_name =
GETPOST(
'attribute',
'aZ09');
3557 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute_name);
3564 $result =
$object->updateExtraField($attribute_name,
'BILL_MODIFY');
3572 $action =
'edit_extras';
3577 if ($action ==
'addcontact' && $usercancreate) {
3578 $result =
$object->fetch($id);
3580 if ($result > 0 && $id > 0) {
3583 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3587 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3590 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3591 $langs->load(
"errors");
3592 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3597 } elseif ($action ==
'swapstatut' && $usercancreate) {
3604 } elseif ($action ==
'deletecontact' && $usercancreate) {
3607 $result =
$object->delete_contact($lineid);
3610 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3618 $action =
'edit_extras';
3628$form =
new Form($db);
3634$bankaccountstatic =
new Account($db);
3636if (isModEnabled(
'project')) {
3642$title =
$object->ref.
" - ".$langs->trans(
'Card');
3643if ($action ==
'create') {
3644 $title = $langs->trans(
"NewBill");
3646$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3652if ($action ==
'create') {
3653 $facturestatic =
new Facture($db);
3654 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3659 $res = $soc->fetch($socid);
3662 $currency_code =
$conf->currency;
3664 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3665 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3671 if (!empty($origin) && !empty($originid)) {
3673 $element = $subelement = $origin;
3675 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3676 $element = $regs[1];
3677 $subelement = $regs[2];
3683 if ($element ==
'project') {
3684 $projectid = $originid;
3686 if (empty($cond_reglement_id)) {
3687 $cond_reglement_id = $soc->cond_reglement_id;
3689 if (empty($mode_reglement_id)) {
3690 $mode_reglement_id = $soc->mode_reglement_id;
3692 if (empty($fk_account)) {
3693 $fk_account = $soc->fk_account;
3695 if (empty($dateinvoice)) {
3701 if ($element ==
'order' || $element ==
'commande') {
3702 $element = $subelement =
'commande';
3704 if ($element ==
'propal') {
3705 $element =
'comm/propal';
3706 $subelement =
'propal';
3708 if ($element ==
'contract') {
3709 $element = $subelement =
'contrat';
3711 if ($element ==
'shipping') {
3712 $element = $subelement =
'expedition';
3717 $classname = ucfirst($subelement);
3718 $objectsrc =
new $classname($db);
3719 '@phan-var-force Commande|Propal|Contrat|Expedition $objectsrc';
3720 $objectsrc->fetch($originid);
3721 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3722 $objectsrc->fetch_lines();
3724 $objectsrc->fetch_thirdparty();
3726 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3732 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3736 if (empty($socid)) {
3737 $soc = $objectsrc->thirdparty;
3740 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3742 if ($element ==
'expedition') {
3743 $elem = $subelem = $objectsrc->origin;
3744 $expeoriginid = $objectsrc->origin_id;
3746 $classname = ucfirst($subelem);
3748 $expesrc =
new $classname($db);
3749 '@phan-var-force Expedition $expesrc';
3750 dol_syslog(
"Is type Facture|Commande or Expedition: $element...expesrc($classname)=".get_class($expesrc));
3751 $expesrc->fetch($expeoriginid);
3753 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3754 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3755 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3757 if (isModEnabled(
'multicurrency')) {
3758 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3759 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3763 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3766 $expesrc->fetch_optionals();
3767 $object->array_options = $expesrc->array_options;
3769 $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)));
3770 $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)));
3771 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : (!empty($fk_account) ? $fk_account : 0)));
3773 if (isModEnabled(
'multicurrency')) {
3774 if (!empty($objectsrc->multicurrency_code)) {
3775 $currency_code = $objectsrc->multicurrency_code;
3777 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
3778 $currency_tx = $objectsrc->multicurrency_tx;
3783 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3786 $objectsrc->fetch_optionals();
3787 $object->array_options = $objectsrc->array_options;
3791 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
3792 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
3793 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
3794 $inputReasonId = empty($soc->demand_reason_id) ? $inputReasonId : $soc->demand_reason_id;
3796 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3798 if (isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3799 $currency_code = $soc->multicurrency_code;
3804 if (!
GETPOST(
'changecompany')) {
3805 if (GETPOSTISSET(
'cond_reglement_id')) {
3806 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3808 if (GETPOSTISSET(
'mode_reglement_id')) {
3809 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3811 if (GETPOSTISSET(
'cond_reglement_id')) {
3817 if (empty($cond_reglement_id)) {
3818 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
3822 if (empty($mode_reglement_id)) {
3823 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
3833 if (!empty($soc->id)) {
3834 $absolute_discount = $soc->getAvailableDiscounts();
3836 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
3837 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
3839 if (!empty(
$conf->use_javascript_ajax)) {
3840 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3846 if ($origin ==
'contrat') {
3847 $langs->load(
"admin");
3848 $text = $langs->trans(
"ToCreateARecurringInvoice");
3849 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3851 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3853 print
info_admin($text, 0, 0,
'info',
'').
'<br>';
3856 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3857 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3858 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3859 print
'<input type="hidden" name="changecompany" value="0">';
3861 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3863 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3864 print
'<input name="ref" type="hidden" value="provisoire">';
3865 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3866 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3867 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3868 print
'<input name="force_fk_account" type="hidden" value="0">';
3869 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3870 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3871 print
'<input type="hidden" name="originentity" value="'.GETPOSTINT(
'originentity').
'">';
3872 if (!empty($currency_tx)) {
3873 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3879 $parameters = array();
3881 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters,
$object, $action);
3882 if (empty($reshook)) {
3883 print
'<table class="border centpercent">';
3885 $exampletemplateinvoice =
new FactureRec($db);
3887 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3888 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
3892 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
3894 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
'Customer').
'</td>';
3895 print
'<td colspan="2">';
3896 print $soc->getNomUrl(1,
'customer');
3897 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3899 $arrayoutstandingbills = $soc->getOutstandingBills();
3900 $outstandingBills = $arrayoutstandingbills[
'opened'];
3901 print
' - <span class="opacitymedium valignmiddle">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3902 print
'<span class="amount valignmiddle">'.price($outstandingBills, 0, $langs, 0, 0, -1,
$conf->currency).
'</span>';
3903 if ($soc->outstanding_limit !=
'') {
3904 if ($outstandingBills > $soc->outstanding_limit) {
3905 print
img_warning($langs->trans(
"OutstandingBillReached"));
3907 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1,
$conf->currency);
3912 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3913 print
'<td colspan="2">';
3914 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
3915 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3919 $(document).ready(function() {
3920 $("#socid").change(function() {
3922 console.log("Submit page");
3923 $(\'input[name="action"]\').val(\'create\');
3924 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3925 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3926 $(\'input[name="force_fk_account"]\').val(\'1\');
3927 $("#formtocreate").submit(); */
3929 // For company change, we must submit page with action=create instead of action=add
3930 console.log("We have changed the company - Resubmit page");
3931 jQuery("input[name=changecompany]").val("1");
3932 jQuery("#formtocreateaction").val("create");
3933 jQuery("#formtocreate").submit();
3939 print
' <a class="valignmiddle" href="'.DOL_URL_ROOT.
'/societe/card.php?action=create&customer=3&fournisseur=0&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create').
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddThirdParty").
'"></span></a>';
3946 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3948 foreach ($invoice_predefined->array_options as $key => $option) {
3949 if (!isset(
$object->array_options[$key])) {
3950 $object->array_options[$key] = $invoice_predefined->array_options[$key];
3954 $dateinvoice = $invoice_predefined->date_when;
3955 if (empty($projectid)) {
3956 $projectid = $invoice_predefined->fk_project;
3958 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
3959 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
3960 $fk_account = $invoice_predefined->fk_account;
3961 $note_public = $invoice_predefined->note_public;
3962 $note_private = $invoice_predefined->note_private;
3964 if (!empty($invoice_predefined->multicurrency_code)) {
3965 $currency_code = $invoice_predefined->multicurrency_code;
3967 if (!empty($invoice_predefined->multicurrency_tx)) {
3968 $currency_tx = $invoice_predefined->multicurrency_tx;
3971 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
3972 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
3973 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
3975 $resql = $db->query($sql);
3977 $num = $db->num_rows($resql);
3981 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
3983 print
'<select class="flat" id="fac_rec" name="fac_rec">';
3984 print
'<option value="0" selected></option>';
3986 $objp = $db->fetch_object($resql);
3987 print
'<option value="'.$objp->rowid.
'"';
3990 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
3992 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
4001 print
'<script type="text/javascript">
4002 $(document).ready(function() {
4003 $("#fac_rec").change(function() {
4004 console.log("We have changed the template invoice - Reload page");
4005 var fac_rec = $(this).val();
4006 var socid = $(\'#socid\').val();
4007 // 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.
4008 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
4021 print
'<tr><td class="tdtop fieldrequired titlefieldcreate">'.$langs->trans(
'Type').
'</td><td colspan="2">';
4022 print
'<div class="listofinvoicetypetable">'.
"\n";
4025 print
'<div class="listofinvoicetype"><div class="">';
4026 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
4027 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
4029 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'nowraponall', 0, 3,
'standardonsmartphone');
4031 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
4041 print
'<span class="opacitymedium marginleftonly">' . $langs->trans(
'PercentOfOriginalObject') .
'</span>:<input class="right" placeholder="100%" type="text" id="valuestandardinvoice" name="valuestandardinvoice" size="3" value="' . (GETPOSTISSET(
'valuestandardinvoice') ?
GETPOST(
'valuestandardinvoice',
'alpha') :
'100%') .
'"/>';
4044 print
'</div></div>'.
"\n";
4046 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
4049 print
'<div class="listofinvoicetype"><div class="">';
4050 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
4051 print
'<script type="text/javascript">
4052 jQuery(document).ready(function() {
4053 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
4054 jQuery("#radio_standard").prop("checked", true);
4056 jQuery("#typedeposit, #valuedeposit").click(function() {
4057 jQuery("#radio_deposit").prop("checked", true);
4059 jQuery("#typedeposit").change(function() {
4060 console.log("We change type of down payment: "+jQuery("#typedeposit").val());
4062 if (jQuery("#typedeposit").val() == "amount") {
4063 jQuery("#valuedeposit").attr("placeholder", "'.$langs->getCurrencySymbol(
$conf->currency).
'");
4064 jQuery("#valuedeposit").val("");
4066 jQuery("#valuedeposit").attr("placeholder", "50%");
4067 jQuery("#valuedeposit").val("");
4070 jQuery("#radio_deposit").prop("checked", true);
4071 setRadioForTypeOfInvoice();
4073 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
4074 setRadioForTypeOfInvoice();
4077 function setRadioForTypeOfInvoice() {
4078 console.log("Change radio for type of invoice");
4079 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
4080 jQuery("#checkforselects").prop("disabled", true);
4081 jQuery("#checkforselects").prop("checked", false);
4082 jQuery(".checkforselect").prop("disabled", true);
4083 jQuery(".checkforselect").prop("checked", false);
4085 jQuery("#checkforselects").prop("disabled", false);
4086 jQuery("#checkforselects").prop("checked", true);
4087 jQuery(".checkforselect").prop("disabled", false);
4088 jQuery(".checkforselect").prop("checked", true);
4094 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
4096 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
4098 if (($origin ==
'propal') || ($origin ==
'commande')) {
4101 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
4102 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
4103 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4107 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4111 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
4113 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
4114 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
4115 if (!empty($origin_payment_conditions_deposit_percent)) {
4116 $typedeposit =
'variable';
4119 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
4120 $valuedeposit = $objectsrc->deposit_percent;
4122 print
'<span class="marginleftonly">'.$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1).
'</span>';
4124 print
'<input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.($valuedeposit ? $valuedeposit :
'').
'"'.($valuedeposit ?
'' :
'placeholder="'.$langs->getCurrencySymbol(
$conf->currency).
'"').
'>';
4127 print
'</div></div>'.
"\n";
4134 print
'<div class="listofinvoicetype"><div class="">';
4135 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
4136 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
4138 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
4142 $opt = $form->selectSituationInvoices((
string)
GETPOSTINT(
'originid'), $socid);
4145 print
'</div></div><div class="listofinvoicetype"><div>';
4147 $tmp =
'<input id="radio_situation_bis" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
4148 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4149 $tmp .=
' disabled';
4152 $text = $tmp.
'<label for="radio_situation_bis">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4153 $text .=
'<select class="flat minwidth50" id="situations" name="situations"';
4154 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4155 $text .=
' disabled';
4159 $text .=
'</select>';
4160 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
4162 print
'</div></div>'.
"\n";
4168 $facids = $facturestatic->list_replacable_invoices($soc->id);
4174 if (is_array($facids)) {
4175 foreach ($facids as $facparam) {
4176 $options .=
'<option value="'.$facparam [
'id'].
'"';
4177 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
4178 $options .=
' selected';
4180 $options .=
'>'.$facparam[
'ref'];
4181 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
4182 $options .=
'</option>';
4186 print
'<!-- replacement line -->';
4187 print
'<div class="listofinvoicetype"><div class="">';
4188 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
4189 if (!$options || $invoice_predefined->id > 0) {
4190 $tmp .=
' disabled';
4193 print
'<script type="text/javascript">
4194 jQuery(document).ready(function() {
4195 jQuery("#fac_replacement").change(function() {
4196 console.log("We change fac_replacement");
4197 jQuery("#radio_replacement").prop("checked", true);
4201 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
4202 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
4203 if (!$options || $invoice_predefined->id > 0) {
4204 $text .=
' disabled';
4208 $text .=
'<option value="-1"> </option>';
4211 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
4213 $text .=
'</select>';
4214 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
4216 print
'</div></div>'.
"\n";
4220 print
'<div class="listofinvoicetype"><div class="">';
4221 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
4222 $text = $tmp.
'<label class="opacitymedium">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4223 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'firstsituationonsmartphone');
4225 print
'</div></div>'.
"\n";
4228 print
'<div class="listofinvoicetype"><div class="">';
4229 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
4230 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
4231 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'replacementonsmartphone');
4233 print
'</div></div>'.
"\n";
4236 if (empty($origin)) {
4241 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
4247 $newinvoice_static =
new Facture($db);
4248 foreach ($facids as $key => $valarray) {
4249 $newinvoice_static->id = $key;
4250 $newinvoice_static->ref = $valarray [
'ref'];
4251 $newinvoice_static->statut = $valarray [
'status'];
4252 $newinvoice_static->status = $valarray [
'status'];
4253 $newinvoice_static->type = $valarray [
'type'];
4254 $newinvoice_static->paye = $valarray [
'paye'];
4255 $newinvoice_static->paid = $valarray [
'paye'];
4257 $optionsav .=
'<option value="'.$key.
'"';
4258 if ($key ==
GETPOST(
'fac_avoir')) {
4259 $optionsav .=
' selected';
4262 $newinvoice_static->fetch_optionals($key);
4263 $object->array_options = $newinvoice_static->array_options;
4266 $optionsav .= $newinvoice_static->ref;
4267 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
4268 $optionsav .=
'</option>';
4271 print
'<div class="listofinvoicetype"><div class="">';
4272 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
4273 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
4274 $tmp .=
' disabled';
4278 print
'<script type="text/javascript">
4279 jQuery(document).ready(function() {
4280 if (jQuery("#radio_creditnote").is(":checked"))
4282 jQuery("#radio_standard").prop("disabled", true);
4284 jQuery("#radio_standard").prop("disabled", false);
4286 if (! jQuery("#radio_creditnote").is(":checked"))
4288 jQuery("#credit_note_options").hide();
4290 jQuery("#radio_creditnote").click(function() {
4292 jQuery("#credit_note_options").show();
4294 jQuery("#radio_standard, #radio_replacement, #radio_deposit, #radio_situation, #radio_situation_bis").click(function() {
4295 console.log("We click on a radio to close credit not options");
4296 jQuery("#credit_note_options").hide();
4300 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
4301 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
4302 if (!$optionsav || $invoice_predefined->id > 0) {
4303 $text .=
' disabled';
4307 $text .=
'<option value="-1">'.$langs->trans(
"InvoiceAvoirAskCombo").
'</option>';
4308 $text .= $optionsav;
4310 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
4312 $text .=
'</select>';
4313 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
4316 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
4317 print
'<div class="marginleftlarge"><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" class="small">'.$langs->trans(
'invoiceAvoirWithLines').
"</label></div>";
4319 print
'<div class="marginleftlarge"><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" class="small">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label></div>";
4322 print
'</div></div>'.
"\n";
4325 print
'<div class="listofinvoicetype"><div class="">';
4327 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
4329 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
4331 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
4333 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
4335 print
'</div></div>'.
"\n";
4340 print
'<div class="listofinvoicetype"><div class="">';
4341 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
4342 $text = $tmp.
'<label class="opacitymedium" for="radio_template">'.$langs->trans(
"RepeatableInvoice").
'</label> ';
4343 $desc = $form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3,
'templateonsmartphone');
4345 print
'</div></div>'.
"\n";
4354 foreach ($listtType as $type) {
4355 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
4357 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
4360 print
'<script type="text/javascript">
4361 $(document).ready(function() {
4362 var listType = {'.$jsListType.
'};
4363 $("[name=\'type\'").change(function() {
4364 console.log("change name=type");
4365 if ($( this ).prop("checked"))
4367 if(($( this ).val() in listType))
4369 $("#model").val(listType[$( this ).val()]);
4386 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
4387 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
4393 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
4397 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
4398 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
4407 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
4408 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4409 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
4414 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
4415 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4416 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
4421 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
4422 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
4423 print $form->getSelectConditionsPaiements((
int) $cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
4428 $rwStyle =
'display:none;';
4429 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
4433 $retained_warranty =
GETPOSTINT(
'retained_warranty');
4434 if (empty($retained_warranty)) {
4435 if ($objectsrc !==
null && property_exists($objectsrc,
'retained_warranty') && !empty($objectsrc->retained_warranty)) {
4437 $retained_warranty = $objectsrc->retained_warranty;
4440 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
4442 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
4443 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
4446 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
4447 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
4448 if (empty($retained_warranty_fk_cond_reglement)) {
4449 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4450 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
4451 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
4453 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4456 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4459 print
'<script type="text/javascript">
4460 $(document).ready(function() {
4461 $("[name=\'type\']").change(function() {
4462 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
4464 $(".retained-warranty-line").show();
4465 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
4468 $(".retained-warranty-line").hide();
4469 $("#new-situation-invoice-retained-warranty").val("");
4473 $("[name=\'type\']:checked").trigger("change");
4479 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
4480 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
4481 print $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth250 widthcentpercentminusx', 1);
4485 if (isModEnabled(
"bank")) {
4486 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td colspan="2">';
4487 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4488 print $form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth250 widthcentpercentminusx', 1);
4494 print
'<tr><td>'.$langs->trans(
'Source').
'</td><td>';
4495 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
4496 $form->selectInputReason((
string) $inputReasonId,
'input_reason_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
4500 if (isModEnabled(
'project') && is_object($formproject)) {
4501 $langs->load(
'projects');
4502 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
4503 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
4505 print $formproject->select_projects((($socid > 0 && !
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_CUSTOMERS')) ? $socid : -1), (string) $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
4506 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>';
4511 if (isModEnabled(
'incoterm')) {
4513 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
4514 print
'<td colspan="2" class="maxwidthonsmartphone">';
4515 $incoterm_id =
GETPOST(
'incoterm_id');
4516 $location_incoterms =
GETPOST(
'location_incoterms');
4517 if (empty($incoterm_id)) {
4518 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
4519 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
4521 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
4522 print $form->select_incoterms($incoterm_id, $location_incoterms);
4527 if (isModEnabled(
'category')) {
4529 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
4530 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories',
$object);
4535 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
4536 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
4537 print $hookmanager->resPrint;
4538 if (empty($reshook)) {
4539 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
4542 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
4543 if ($soc->fetch_optionals() > 0) {
4544 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
4548 print
$object->showOptionals($extrafields,
'create', $parameters);
4552 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
4553 print
'<td colspan="2">';
4554 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
4555 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
4560 $paramkey =
'FACTURE_ADDON_PDF_'.$type;
4565 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
4569 if (isModEnabled(
'multicurrency')) {
4571 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0).
'</td>';
4572 print
'<td colspan="2" class="maxwidthonsmartphone">';
4573 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
4574 print $form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth200 widthcentpercentminusx');
4581 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
4582 if (empty($dateexample)) {
4585 $substitutionarray = array(
4586 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
4587 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
4588 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
4589 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
4590 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
4591 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
4592 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
4593 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
4594 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
4595 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
4596 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
4599 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
4600 foreach ($substitutionarray as $key => $val) {
4601 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
4603 $htmltext .=
'</i>';
4608 print
'<td class="tdtop">';
4609 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
4611 print
'<td valign="top" colspan="2">';
4612 $doleditor =
new DolEditor(
'note_public', (
string) $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
4613 print $doleditor->Create(1);
4616 if (empty($user->socid)) {
4618 print
'<td class="tdtop">';
4619 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4621 print
'<td valign="top" colspan="2">';
4622 $doleditor =
new DolEditor(
'note_private', (
string) $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4623 print $doleditor->Create(1);
4629 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4630 $langs->loadLangs(array(
'orders',
'propal'));
4633 if ($origin ==
'contrat') {
4634 '@phan-var-force Contrat $objectsrc';
4636 $objectsrc->update_price(1,
'auto', 1);
4639 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4640 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4641 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4642 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4647 switch (get_class($objectsrc)) {
4649 $newclassname =
'CommercialProposal';
4652 $newclassname =
'Order';
4655 $newclassname =
'Sending';
4658 $newclassname =
'Contract';
4661 $newclassname =
'Intervention';
4664 $newclassname = get_class($objectsrc);
4668 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4669 print
'<td colspan="2">';
4670 print $objectsrc->getNomUrl(1);
4672 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
4673 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4675 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4679 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht, 1, $langs, 1, -1,
'',
$conf->currency).
'</td></tr>';
4680 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
4681 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4682 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax1, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
4685 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4686 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax2, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
4688 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
4690 if (isModEnabled(
'multicurrency') && $objectsrc->multicurrency_code !=
$conf->currency) {
4692 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
'</td></tr>';
4693 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4694 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4702 print $form->buttonsSaveCancel(
"CreateDraft");
4705 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4708 $title = $langs->trans(
'ProductsAndServices');
4711 print
'<div class="div-table-responsive-no-min">';
4712 print
'<table class="noborder centpercent">';
4714 $objectsrc->printOriginLinesList(
'', $selectedLines);
4721} elseif ($id > 0 || !empty($ref)) {
4723 $langs->load(
'errors');
4724 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4733 if ($user->socid > 0 && $user->socid !=
$object->socid) {
4737 $result =
$object->fetch_thirdparty();
4739 $result = $soc->fetch(
$object->socid);
4743 $selleruserevenustamp = $mysoc->useRevenueStamp();
4745 $totalpaid =
$object->getSommePaiement();
4746 $totalcreditnotes =
$object->getSumCreditNotesUsed();
4747 $totaldeposits =
$object->getSumDepositsUsed();
4753 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4756 if (isModEnabled(
'multicurrency')) {
4757 $multicurrency_totalpaid =
$object->getSommePaiement(1);
4758 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
4759 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
4760 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4764 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
4765 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
4769 if (
$object->paye ||
$object->status == $object::STATUS_CLOSED) {
4772 $resteapayeraffiche = $resteapayer;
4775 $filterabsolutediscount =
"fk_facture_source IS NULL";
4776 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4778 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4779 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4782 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
4783 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
4784 $absolute_discount =
price2num($absolute_discount,
'MT');
4785 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4787 $author =
new User($db);
4788 if (
$object->user_creation_id) {
4789 $author->fetch(
$object->user_creation_id);
4792 $objectidnext =
$object->getIdReplacingInvoice();
4796 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
'bill');
4801 if ($action ==
'converttoreduc') {
4803 $type_fac =
'ExcessReceived';
4805 $type_fac =
'CreditNote';
4807 $type_fac =
'Deposit';
4811 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4812 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4813 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4817 if ($action ==
'delete') {
4818 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
4819 $formquestion = array();
4822 $qualified_for_stock_change = 0;
4824 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4826 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4829 if ($qualified_for_stock_change) {
4830 $langs->load(
"stocks");
4831 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4835 if (
$conf->browser->name ==
'ie') {
4838 $formquestion = array(
4842 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4844 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4846 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4849 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4854 if ($action ==
'situationout') {
4855 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
4856 $label = $langs->trans(
"ConfirmOuting");
4857 $formquestion = array();
4862 &&
$object->is_last_in_cycle()
4863 && $usercanunvalidate
4865 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4870 if ($action ==
'valid') {
4872 $objectref = substr(
$object->ref, 1, 4);
4873 if ($objectref ==
'PROV') {
4877 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
4879 $numref =
$object->getNextNumRef($soc);
4885 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4887 $text .=
'<br><br>';
4888 $text .=
img_picto(
'',
'warning',
'class="pictofixedwidth"').
' '.$langs->trans(
'WarningInvoiceCanNeverBeEdited');
4890 if (isModEnabled(
'notification')) {
4891 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4892 $notify =
new Notify($db);
4894 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid,
$object);
4896 $formquestion = array();
4899 $qualified_for_stock_change = 0;
4901 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4903 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4906 if ($qualified_for_stock_change) {
4907 $langs->load(
"stocks");
4908 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4909 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4912 $warehouse_array = $warehouse->list_array();
4913 if (count($warehouse_array) == 1) {
4914 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4915 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4918 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4920 $formquestion = array(
4926 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4930 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
4935 foreach (
$object->lines as $line) {
4936 $res = $line->fetch_product();
4938 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
4944 if ($nbMandated > 0) {
4946 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
4949 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
4954 $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, 260);
4959 if ($action ==
'modif') {
4960 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
4961 $formquestion = array();
4964 $qualified_for_stock_change = 0;
4966 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4968 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4971 if ($qualified_for_stock_change) {
4972 $langs->load(
"stocks");
4973 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4974 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4977 $warehouse_array = $warehouse->list_array();
4978 if (count($warehouse_array) == 1) {
4979 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
4980 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4983 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4985 $formquestion = array(
4991 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4995 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
4999 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
5000 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
5002 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
5006 $close[$i][
'code'] = $object::CLOSECODE_DISCOUNTVAT;
5008 $close[$i][
'code'] = $object::CLOSECODE_BADDEBT;
5010 $close[$i][
'code'] = $object::CLOSECODE_BANKCHARGE;
5012 $close[$i][
'code'] = $object::CLOSECODE_WITHHOLDINGTAX;
5014 $close[$i][
'code'] = $object::CLOSECODE_OTHER;
5018 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
5020 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5022 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
5024 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
5026 $close[$i][
'label'] = $langs->trans(
"Other");
5030 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5032 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5034 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5036 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
5038 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
5042 foreach ($close as $key => $val) {
5043 $arrayreasons[$close[$key][
'code']] =
'<span class="small">'.$close[$key][
'reason'].
'</span>';
5047 $formquestion = array(
5048 'text' => $langs->trans(
"ConfirmClassifyPaidPartiallyQuestion"),
5049 0 => array(
'type' =>
'radio',
'name' =>
'close_code',
'label' =>
'',
'values' => $arrayreasons),
5050 1 => array(
'type' =>
'text',
'name' =>
'close_note',
'moreattr' =>
'placeholder = "'.$langs->trans(
"Comment").
'"',
'value' =>
'',
'morecss' =>
'minwidth300'),
5051 2 => array(
'type' =>
'separator')
5054 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 400, 600);
5058 if ($action ==
'canceled') {
5062 $statusreplacement = 0;
5064 if ($objectidnext) {
5065 $facturereplacement =
new Facture($db);
5066 $facturereplacement->fetch($objectidnext);
5067 $statusreplacement = $facturereplacement->status;
5069 if ($objectidnext && $statusreplacement == 0) {
5070 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
5073 $close[1][
'code'] =
'badcustomer';
5074 $close[2][
'code'] =
'abandon';
5076 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5077 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
5079 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
5080 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
5083 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
5084 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
5087 $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'));
5089 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 270);
5093 if ($action ==
'deletepayment') {
5094 $payment_id =
GETPOST(
'paiement_id');
5095 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
5099 if ($action ==
'ask_deleteline') {
5100 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
5104 if ($action ==
'ask_subtotal_deleteline') {
5105 $langs->load(
"subtotals");
5106 $title =
"DeleteSubtotalLine";
5107 $question =
"ConfirmDeleteSubtotalLine";
5108 if (
GETPOST(
'type') ==
'title') {
5109 $formconfirm = array(array(
'type' =>
'checkbox',
'name' =>
'deletecorrespondingsubtotalline',
'label' => $langs->trans(
"DeleteCorrespondingSubtotalLine"),
'value' => 0));
5110 $title =
"DeleteTitleLine";
5111 $question =
"ConfirmDeleteTitleLine";
5113 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans($title), $langs->trans($question),
'confirm_delete_subtotalline', $formconfirm,
'no', 1);
5117 if ($action ==
'clone') {
5118 $filter =
'(s.client:IN:1,2,3)';
5120 $formquestion = array(
5121 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
$object->socid,
'socid', $filter, 1)),
5122 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
5125 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
5129 if ($action ==
'add_title_line') {
5130 $langs->load(
'subtotals');
5132 $depth_array =
$object->getPossibleLevels($langs);
5134 } elseif ($action ==
'add_subtotal_line') {
5135 $langs->load(
'subtotals');
5137 $titles =
$object->getPossibleTitles();
5141 if ($action ==
"remove_file_comfirm") {
5142 $file =
GETPOST(
'file',
'alpha');
5144 $formconfirm = $form->formconfirm(
5145 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
5146 $langs->trans(
'DeleteFileHeader'),
5147 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
5156 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
5157 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
5158 if (empty($reshook)) {
5159 $formconfirm .= $hookmanager->resPrint;
5160 } elseif ($reshook > 0) {
5161 $formconfirm = $hookmanager->resPrint;
5169 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
5171 $morehtmlref =
'<div class="refidno">';
5174 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref',
$object->ref,
$object, (
int) $usercancreate,
'string',
'', 0, 1);
5175 $morehtmlref .= $form->editfieldval(
"Ref",
'ref',
$object->ref,
$object, (
int) $usercancreate,
'string',
'',
null,
null,
'', 1);
5176 $morehtmlref .=
'<br>';
5179 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer,
$object, (
int) $usercancreate,
'string',
'', 0, 1);
5180 $morehtmlref .= $form->editfieldval(
"RefCustomer",
'ref_client',
$object->ref_customer,
$object, (
int) $usercancreate,
'string'.(getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') ?
':' .
getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') :
''),
'', null, null,
'', 1);
5182 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
5184 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'&search_societe='.urlencode(
$object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
5187 if (isModEnabled(
'project')) {
5188 $langs->load(
"projects");
5189 $morehtmlref .=
'<br>';
5190 if ($usercancreate) {
5191 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
5192 if ($action !=
'classify') {
5193 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
5195 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->socid, (
string)
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
5197 if (!empty(
$object->fk_project)) {
5199 $proj->fetch(
$object->fk_project);
5200 $morehtmlref .= $proj->getNomUrl(1);
5202 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
5207 $morehtmlref .=
'</div>';
5209 $object->totalpaid = $totalpaid;
5210 $object->totalcreditnotes = $totalcreditnotes;
5211 $object->totaldeposits = $totaldeposits;
5214 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
5217 $parameters = array();
5219 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters,
$object, $action);
5220 if (empty($reshook)) {
5221 print
'<div class="fichecenter">';
5222 print
'<div class="fichehalfleft">';
5223 print
'<div class="underbanner clearboth"></div>';
5225 print
'<table class="border centpercent tableforfield">';
5228 print
'<tr><td class="fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
5231 print
' '.$object->getSubtypeLabel(
'facture');
5234 $facreplaced =
new Facture($db);
5235 $facreplaced->fetch(
$object->fk_facture_source);
5236 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
5240 $facusing->fetch(
$object->fk_facture_source);
5241 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
5245 $object->getListIdAvoirFromInvoice();
5247 if (!empty(
$object->creditnote_ids)) {
5248 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
5250 foreach (
$object->creditnote_ids as $invoiceid) {
5256 $creditnote =
new Facture($db);
5257 $creditnote->fetch($invoiceid);
5258 print $creditnote->getNomUrl(1,
'', 32);
5262 if ($objectidnext > 0) {
5263 $facthatreplace =
new Facture($db);
5264 $facthatreplace->fetch($objectidnext);
5265 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
5270 $result = $discount->fetch(0,
$object->id);
5272 print
' <span class="opacitymediumbycolor paddingleft">';
5273 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
5274 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
5275 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
5277 print
'</span><br>';
5281 if (
$object->fk_fac_rec_source > 0) {
5283 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
5285 print
' <span class="opacitymediumbycolor paddingleft">';
5286 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
5287 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
5291 print
' <span class="opacitymediumbycolor paddingleft">';
5292 print $langs->transnoentities(
"GeneratedFromTemplate", $langs->trans(
"ObjectDeleted"));
5300 $langs->load(
"cashdesk");
5301 print
'<tr><td class="fieldname_type">';
5302 print
'<table class="nobordernopadding centpercent"><tr><td>';
5303 print $form->textwithpicto($langs->trans(
'PointOfSale'), $langs->trans(
'POSInfo'));
5305 if ($action !=
'editposinfo' && $usercancreate) {
5306 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editposinfo&token='.
newToken().
'&facid='.
$object->id.
'">'.
img_edit($langs->trans(
'SetPOSInfo'), 1).
'</a></td>';
5308 print
'</tr></table>';
5309 print
'</td><td class="valuefield fieldname_type">';
5310 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" name="formposinfo">';
5311 print
'<input type="hidden" name="action" value="setposinfo">';
5312 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5313 if ($action ==
'editposinfo') {
5314 print
'<input type="text" class="maxwidth150" name="posmodule" placeholder="'.$langs->trans(
"POSModule").
'" value="'.
$object->module_source.
'"> ';
5315 print
'<input type="text" class="maxwidth100" name="posterminal" placeholder="'.$langs->trans(
"Terminal").
'" value="'.
$object->pos_source.
'">';
5316 print
'<input type="submit" class="button" name="submitposinfo" value="'.$langs->trans(
"Submit").
'">';
5319 print
'<span class="opacitymediumbycolor paddingleft">'.dolPrintHTML(ucfirst(
$object->module_source).
' - '.$langs->transnoentitiesnoconv(
"Terminal").
' '.
$object->pos_source).
'</span>';
5327 print
'<!-- Discounts -->'.
"\n";
5328 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
5332 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
5333 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
5338 print
'<table class="nobordernopadding centpercent"><tr><td>';
5339 print $langs->trans(
'DateInvoice');
5341 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
5342 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>';
5344 print
'</tr></table>';
5346 if ($action ==
'editinvoicedate') {
5347 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
5349 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
5364 print
'<table class="nobordernopadding centpercent"><tr><td>';
5365 print $langs->trans(
'DatePointOfTax');
5368 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>';
5370 print
'</tr></table>';
5372 if ($action ==
'editdate_pointoftax' && $editable) {
5373 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
5375 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
5382 print $form->editfieldkey(
'Source',
'input_reason',
'',
$object, (
int) $usercancreate);
5383 print
'</td><td class="valuefield">';
5384 if ($action ==
'editinput_reason') {
5385 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'input_reason_id', 1);
5387 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'none');
5393 print
'<table class="nobordernopadding centpercent"><tr><td>';
5394 print $langs->trans(
'PaymentConditionsShort');
5397 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>';
5399 print
'</tr></table>';
5402 if ($action ==
'editconditions') {
5403 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
5405 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
5414 print
'<table class="nobordernopadding centpercent"><tr><td>';
5415 print $langs->trans(
'DateMaxPayment');
5418 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>';
5420 print
'</tr></table>';
5423 if ($action ==
'editpaymentterm') {
5424 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
5426 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
5438 print
'<table class="nobordernopadding centpercent"><tr><td>';
5439 print $langs->trans(
'PaymentMode');
5441 if ($action !=
'editmode' && $usercancreate) {
5442 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>';
5444 print
'</tr></table>';
5446 if ($action ==
'editmode') {
5447 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
5449 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'none',
'CRDT');
5454 if (isModEnabled(
"bank")) {
5455 print
'<tr><td class="nowrap">';
5456 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
5457 print $langs->trans(
'BankAccount');
5459 if (($action !=
'editbankaccount') && $usercancreate) {
5460 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>';
5462 print
'</tr></table>';
5464 if ($action ==
'editbankaccount') {
5465 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
5467 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
5474 if (isModEnabled(
'incoterm')) {
5476 print
'<table class="nobordernopadding centpercent"><tr><td>';
5477 print $langs->trans(
'IncotermLabel');
5478 print
'<td><td class="right">';
5479 if ($usercancreate) {
5480 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
5484 print
'</td></tr></table>';
5487 if ($action !=
'editincoterm') {
5488 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
5490 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
5496 if (isModEnabled(
'category')) {
5498 print
'<table class="nobordernopadding centpercent"><tr><td>';
5499 print $langs->trans(
"Categories");
5500 print
'<td><td class="right">';
5501 if ($usercancreate) {
5502 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
5506 print
'</td></tr></table>';
5509 if ($action ==
'edittags') {
5510 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5511 print
'<input type="hidden" name="action" value="settags">';
5512 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5513 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories',
$object);
5514 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5517 print $form->showCategories(
$object->id, Categorie::TYPE_INVOICE, 1);
5522 $displayWarranty =
false;
5525 $displayWarranty =
true;
5526 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
5527 $displayWarranty =
false;
5530 if ($displayWarranty) {
5532 print
'<tr class="retained-warranty-lines" ><td>';
5533 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
5534 print $langs->trans(
'RetainedWarranty');
5537 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>';
5540 print
'</tr></table>';
5543 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5544 print
'<input type="hidden" name="action" value="setretainedwarranty">';
5545 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5546 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5547 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
5548 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5556 print
'<tr class="retained-warranty-lines" ><td>';
5557 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
5558 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
5560 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
5561 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>';
5564 print
'</tr></table>';
5566 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5567 if (
$object->date > $defaultDate) {
5573 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5574 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
5575 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5576 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5577 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
5578 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
5579 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
5580 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
5581 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5584 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->retained_warranty_fk_cond_reglement,
'none');
5585 if (!$displayWarranty) {
5586 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning.png',
'class="pictowarning valignmiddle" ');
5592 print
'<tr class="retained-warranty-lines" ><td>';
5593 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
5594 print $langs->trans(
'RetainedWarrantyDateLimit');
5597 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>';
5600 print
'</tr></table>';
5602 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5603 if (
$object->date > $defaultDate) {
5609 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5610 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
5611 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5612 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5613 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').
'" >';
5614 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5626 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
5631 print
'<div class="fichehalfright">';
5633 print
'<!-- amounts -->'.
"\n";
5634 print
'<div class="underbanner clearboth"></div>'.
"\n";
5636 print
'<table class="border tableforfield centpercent">';
5638 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
5646 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
5647 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5648 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5650 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5656 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
5657 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5658 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5660 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5665 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
5667 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
5668 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5669 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5672 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5677 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
5679 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
5680 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5681 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5684 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5690 if ($selleruserevenustamp) {
5691 print
'<tr><td class="titlefieldmiddle">';
5692 print
'<table class="nobordernopadding centpercent"><tr><td>';
5693 print $langs->trans(
'RevenueStamp');
5695 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
5696 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>';
5698 print
'</tr></table>';
5699 print
'</td><td class="nowrap amountcard right">';
5700 if ($action ==
'editrevenuestamp') {
5701 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
5702 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5703 print
'<input type="hidden" name="action" value="setrevenuestamp">';
5704 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
5705 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5706 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
5707 print
' → <span id="revenuestamp_span"></span>';
5708 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
5711 $(document).ready(function(){
5712 js_recalculate_revenuestamp();
5713 $('select[name=revenuestamp_type]').on('change',function(){
5714 js_recalculate_revenuestamp();
5717 function js_recalculate_revenuestamp(){
5718 var valselected = $('select[name=revenuestamp_type]').val();
5719 console.log('Calculate revenue stamp from '+valselected);
5721 if (valselected.indexOf('%') == -1)
5723 revenue = valselected;
5727 var revenue_type = parseFloat(valselected);
5728 var amount_net = ".round(
$object->total_ht, 2).
";
5729 revenue = revenue_type * amount_net / 100;
5730 revenue = revenue.toFixed(2);
5732 $('#revenuestamp_val').val(revenue);
5733 $('#revenuestamp_span').html(revenue);
5744 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
5745 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5746 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5748 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5756 if (isModEnabled(
'project')) {
5759 if (isModEnabled(
"bank")) {
5763 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
5766 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
5769 if ($selleruserevenustamp) {
5772 if (isModEnabled(
'multicurrency')) {
5775 if (isModEnabled(
'incoterm')) {
5779 $total_prev_ht = $total_prev_ttc = 0;
5780 $total_global_ht = $total_global_ttc = 0;
5784 print
'<!-- List of situation invoices -->';
5785 print
'<div class="div-table-responsive-no-min">';
5786 print
'<table class="noborder paymenttable centpercent situationstable">';
5788 print
'<tr class="liste_titre">';
5789 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
5791 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
5793 if (isModEnabled(
"bank")) {
5794 print
'<td class="right"></td>';
5796 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
5797 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
5798 print
'<td width="18"> </td>';
5801 if (count(
$object->tab_previous_situation_invoice) > 0) {
5804 $current_situation_counter = array();
5805 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
5806 $tmptotalallpayments = $prev_invoice->getSommePaiement(0);
5807 $tmptotalallpayments += $prev_invoice->getSumDepositsUsed(0);
5808 $tmptotalallpayments += $prev_invoice->getSumCreditNotesUsed(0);
5810 $total_prev_ht += $prev_invoice->total_ht;
5811 $total_prev_ttc += $prev_invoice->total_ttc;
5813 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
5814 print
'<tr class="oddeven">';
5815 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
5817 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
5818 if (isModEnabled(
"bank")) {
5819 print
'<td class="right"></td>';
5821 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
5822 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
5823 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalallpayments).
'</td>';
5828 $totalallpayments =
$object->getSommePaiement(0);
5829 $totalallpayments +=
$object->getSumCreditNotesUsed(0);
5830 $totalallpayments +=
$object->getSumDepositsUsed(0);
5832 $total_global_ht += $total_prev_ht;
5833 $total_global_ttc += $total_prev_ttc;
5834 $total_global_ht +=
$object->total_ht;
5835 $total_global_ttc +=
$object->total_ttc;
5839 print
'<tr class="oddeven">';
5840 print
'<td>'.$object->getNomUrl(1).
'</td>';
5842 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
5843 if (isModEnabled(
"bank")) {
5844 print
'<td class="right"></td>';
5846 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
5847 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
5848 print
'<td class="right">'.$object->getLibStatut(3, $totalallpayments).
'</td>';
5852 print
'<tr class="oddeven">';
5853 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'CurrentSituationTotal').
'</b></td>';
5856 foreach ($current_situation_counter as $sit) {
5857 $curSign = $sit > 0 ?
'+' :
'-';
5858 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
5860 print
' '.$curSign.
' ';
5862 print $curType.abs($sit);
5866 if (isModEnabled(
"bank")) {
5869 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5870 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5871 print
'<td width="18"> </td>';
5875 if (count(
$object->tab_next_situation_invoice) > 0) {
5887 $total_next_ht = $total_next_ttc = 0;
5889 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
5890 $totalpaid = $next_invoice->getSommePaiement(0);
5891 $totalcreditnotes = $next_invoice->getSumCreditNotesUsed(0);
5892 $totaldeposits = $next_invoice->getSumDepositsUsed(0);
5893 $total_next_ht += $next_invoice->total_ht;
5894 $total_next_ttc += $next_invoice->total_ttc;
5896 print
'<tr class="oddeven">';
5897 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
5899 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
5900 if (isModEnabled(
"bank")) {
5901 print
'<td class="right"></td>';
5903 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
5904 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
5905 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid + $totalcreditnotes + $totaldeposits).
'</td>';
5909 $total_global_ht += $total_next_ht;
5910 $total_global_ttc += $total_next_ttc;
5912 print
'<tr class="oddeven">';
5913 print
'<td colspan="3" class="right"></td>';
5914 if (isModEnabled(
"bank")) {
5915 print
'<td class="right"></td>';
5917 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5918 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5919 print
'<td width="18"> </td>';
5928 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
5934 print
'<!-- List of payments already done -->';
5935 print
'<div class="div-table-responsive-no-min">';
5936 print
'<table class="noborder paymenttable centpercent">';
5938 print
'<tr class="liste_titre">';
5939 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
5940 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
5941 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
5942 if (isModEnabled(
"bank")) {
5943 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
5945 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
5946 print
'<td class="liste_titre" width="18"> </td>';
5950 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
5951 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
5952 $sql .=
' pf.amount,';
5953 $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';
5954 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
5955 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
5956 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
5957 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
5958 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
5959 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
5960 $sql .=
' ORDER BY p.datep, p.tms';
5962 $result = $db->query($sql);
5964 $num = $db->num_rows($result);
5969 $objp = $db->fetch_object($result);
5971 $paymentstatic->id = $objp->rowid;
5972 $paymentstatic->datepaye = $db->jdate($objp->dp);
5973 $paymentstatic->ref = $objp->ref;
5974 $paymentstatic->num_payment = $objp->num_payment;
5975 $paymentstatic->paiementcode = $objp->payment_code;
5977 print
'<tr class="oddeven"><td class="nowraponall">';
5978 print $paymentstatic->getNomUrl(1);
5981 $dateofpayment = $db->jdate($objp->dp);
5983 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
5990 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
5991 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
5992 if (isModEnabled(
"bank")) {
5993 $bankaccountstatic->id = $objp->baid;
5994 $bankaccountstatic->ref = $objp->baref;
5995 $bankaccountstatic->label = $objp->baref;
5996 $bankaccountstatic->number = $objp->banumber;
5997 $bankaccountstatic->currency_code = $objp->bacurrency_code;
5999 if (isModEnabled(
'accounting')) {
6000 $bankaccountstatic->account_number = $objp->account_number;
6003 $accountingjournal->fetch($objp->fk_accountancy_journal);
6004 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
6007 print
'<td class="nowraponall">';
6008 if ($bankaccountstatic->id) {
6009 print $bankaccountstatic->getNomUrl(1,
'transactions');
6013 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
6014 print
'<td class="center">';
6017 $paiement->fetch($objp->rowid);
6019 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
6036 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6037 print
'<span class="opacitymedium">';
6039 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
6041 print $langs->trans(
'AlreadyPaid');
6043 print
'</span></td><td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td><td> </td></tr>';
6045 $resteapayeraffiche = $resteapayer;
6046 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
6049 $creditnoteamount = 0;
6051 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
6052 $sql .=
" re.description, re.fk_facture_source";
6053 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
6054 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
6055 $resql = $db->query($sql);
6057 $num = $db->num_rows($resql);
6061 $obj = $db->fetch_object($resql);
6062 $invoice->fetch($obj->fk_facture_source);
6063 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6064 print
'<span class="opacitymedium">';
6066 print $langs->trans(
"CreditNote").
' ';
6069 print $langs->trans(
"Deposit").
' ';
6071 print $invoice->getNomUrl(0);
6074 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
6075 print
'<td class="right">';
6076 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
6077 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
6082 $creditnoteamount += $obj->amount_ttc;
6085 $depositamount += $obj->amount_ttc;
6094 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
6095 print
'<span class="opacitymedium">';
6096 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
6098 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
6099 $resteapayeraffiche = 0;
6100 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6104 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
6105 print
'<span class="opacitymedium">';
6106 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
6108 print
'</td><td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td><td> </td></tr>';
6110 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6114 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
6115 print
'<span class="opacitymedium">';
6116 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
6118 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
6119 $resteapayeraffiche = 0;
6120 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6124 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
6125 $text = $langs->trans(
"HelpAbandonOther");
6127 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
6129 print
'<span class="opacitymedium">';
6131 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
6133 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
6134 $resteapayeraffiche = 0;
6135 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6139 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6140 print
'<span class="opacitymedium">';
6141 print $langs->trans(
"Billed");
6142 print
'</td><td class="right">'.price(
$object->total_ttc).
'</td><td> </td></tr>';
6144 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6145 print
'<span class="opacitymedium">';
6146 print $langs->trans(
'RemainderToPay');
6147 if ($resteapayeraffiche < 0) {
6148 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6152 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
6156 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6157 print
'<span class="opacitymedium">';
6158 print $langs->trans(
'RemainderToPayMulticurrency');
6159 if ($resteapayeraffiche < 0) {
6160 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6164 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">';
6166 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>';
6170 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
6172 if (
$object->isSituationInvoice()) {
6173 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
6176 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
6179 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
6181 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>';
6184 print
'<tr><td colspan="'.$nbcols.
'" align="right">';
6185 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
6186 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
6187 print
' :</td><td align="right">'.price($retainedWarranty).
'</td><td> </td></tr>';
6190 $resteapayeraffiche = $resteapayer;
6191 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6194 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6195 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
6196 print
'</td><td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td><td> </td></tr>';
6199 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>';
6202 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6203 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
6204 if ($resteapayeraffiche > 0) {
6205 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6207 print
'</span></td>';
6208 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
6209 print
'<td class="nowrap"> </td></tr>';
6213 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6214 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
6215 if ($resteapayeraffiche > 0) {
6216 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6220 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>';
6233 if (isModEnabled(
'margin')) {
6234 $formmargin->displayMarginInfos(
$object);
6240 print
'<div class="clearboth"></div><br>';
6243 $blocname =
'contacts';
6244 $title = $langs->trans(
'ContactsAddresses');
6245 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6249 $blocname =
'notes';
6250 $title = $langs->trans(
'Notes');
6251 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6255 $result =
$object->getLinesArray();
6259 global $inputalsopricewithtax;
6260 $inputalsopricewithtax = 1;
6265 print
'<!-- Area to change globally the situation percent -->'.
"\n";
6266 print
'<div class="div-table-responsive-no-min">';
6268 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'#updatealllines" method="POST">';
6269 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
6270 print
'<input type="hidden" name="action" value="updatealllines" />';
6271 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
6272 print
'<input type="hidden" name="page_y" value="" />';
6273 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
6275 print
'<table id="tablelines_all_progress" class="noborder noshadow centpercent">';
6277 print
'<tr class="liste_titre nodrag nodrop">';
6281 print
'<td align="center" width="5"> </td>';
6283 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
6284 print
'<td class="right">'.$langs->trans(
'Progress').
'</td>';
6285 print
'<td> </td>';
6288 print
'<tr class="nodrag nodrop">';
6291 print
'<td align="center" width="5"> </td>';
6293 print
'<td> </td>';
6294 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
6295 print
'<td class="right"><input type="submit" class="button reposition small" name="all_percent" value="'.$langs->trans(
"Modify").
'" /></td>';
6306 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
6307 <input type="hidden" name="token" value="' .
newToken().
'">
6308 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
6309 <input type="hidden" name="mode" value="">
6310 <input type="hidden" name="page_y" value="">
6311 <input type="hidden" name="id" value="' .
$object->id.
'">
6312 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
6315 if (!empty(
$conf->use_javascript_ajax) &&
$object->status == 0) {
6316 if (isModEnabled(
'subtotals')) {
6317 include DOL_DOCUMENT_ROOT.
'/core/tpl/subtotal_ajaxrow.tpl.php';
6319 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
6323 print
'<div class="div-table-responsive-no-min">';
6324 print
'<table id="tablelines" class="noborder noshadow centpercent nomarginbottom">';
6328 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
6332 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
6333 if ($action !=
'editline' && $action !=
'selectlines') {
6336 $parameters = array();
6337 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
6341 if (empty($reshook)) {
6342 $object->formAddObjectLine(1, $mysoc, $soc);
6345 $parameters = array();
6346 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters,
$object, $action);
6360 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
6361 print
'<div class="tabsAction">';
6363 $parameters = array();
6364 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
6365 if (empty($reshook)) {
6368 'class' =>
'classfortooltip',
6375 $ventilExportCompta =
$object->getVentilExportCompta();
6377 if ($ventilExportCompta == 0) {
6379 if (!$objectidnext &&
$object->is_last_in_cycle()) {
6380 if ($usercanunvalidate) {
6381 unset($params[
'attr'][
'title']);
6382 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
true, $params);
6384 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
6385 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
false, $params);
6387 } elseif (!
$object->is_last_in_cycle()) {
6388 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
6389 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6391 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
6392 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6396 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6397 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6402 $result = $discount->fetch(0,
$object->id);
6410 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
6411 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
6412 unset($params[
'attr'][
'title']);
6413 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
6415 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6416 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
6423 $langs->load(
"contracts");
6425 if ($usercancreatecontract) {
6426 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>';
6434 $langs->load(
"subtotals");
6436 $url_button = array();
6438 $url_button[] = array(
6439 'lang' =>
'subtotals',
6441 'perm' => (
bool) $usercancreate,
6442 'label' => $langs->trans(
'AddTitleLine'),
6443 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_title_line&token='.
newToken()
6446 $url_button[] = array(
6447 'lang' =>
'subtotals',
6449 'perm' => (
bool) $usercancreate,
6450 'label' => $langs->trans(
'AddSubtotalLine'),
6451 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_subtotal_line&token='.
newToken()
6453 print
dolGetButtonAction(
'', $langs->trans(
'Subtotal'),
'default', $url_button,
'',
true);
6460 if ($usercanvalidate) {
6461 unset($params[
'attr'][
'title']);
6462 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
6467 if (empty($user->socid)) {
6469 if ($objectidnext) {
6470 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'SendMail').
'</span>';
6473 unset($params[
'attr'][
'title']);
6474 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
6476 unset($params[
'attr'][
'title']);
6477 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
6485 if ($resteapayer > 0) {
6486 if ($usercancreatewithdrarequest) {
6487 if (!$objectidnext &&
$object->close_code !=
'replaced') {
6488 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>';
6490 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
6501 if (isModEnabled(
'takepos') &&
$object->module_source ==
'takepos') {
6502 $langs->load(
"cashdesk");
6503 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
6504 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
6509 if ($objectidnext) {
6510 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
6514 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
6515 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
6519 unset($params[
'attr'][
'title']);
6520 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);
6525 $sumofpayment = $totalpaid;
6526 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
6532 if ($resteapayer == 0) {
6533 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
6535 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
6541 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
6545 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
6547 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>';
6554 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
6556 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
6570 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
6571 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
6573 unset($params[
'attr'][
'title']);
6574 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken(),
'',
true, $params);
6580 if ($totalpaid > 0 || $totalcreditnotes > 0) {
6582 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
6585 if ($objectidnext) {
6586 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
6588 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
6596 if (!$objectidnext) {
6597 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>';
6603 &&
$object->isSituationInvoice()
6604 && (
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
6607 &&
$object->is_last_in_cycle()
6610 if ($usercanunvalidate) {
6611 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>';
6613 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
6619 unset($params[
'attr'][
'title']);
6620 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice&token='.
newToken(),
'',
true, $params);
6625 if (!$objectidnext && count(
$object->lines) > 0) {
6626 unset($params[
'attr'][
'title']);
6627 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
6633 &&
$object->isSituationInvoice()
6636 &&
$object->situation_counter > 1
6637 &&
$object->is_last_in_cycle()
6638 && $usercanunvalidate
6640 if ((
$object->total_ttc - $totalcreditnotes) == 0) {
6641 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6643 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6649 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
6650 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6651 } elseif (!
$object->is_last_in_cycle()) {
6652 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6654 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6659 $isErasable =
$object->is_erasable();
6661 if ($isErasable == -4) {
6662 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
6663 } elseif ($isErasable == -3) {
6664 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
6665 } elseif ($isErasable == -2) {
6666 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
6667 } elseif ($isErasable == -1) {
6668 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6669 } elseif ($isErasable <= 0) {
6670 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable');
6671 } elseif ($objectidnext) {
6672 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
6674 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
6675 $enableDelete =
false;
6677 if ($isErasable > 0 && ! $objectidnext) {
6678 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
6679 $enableDelete =
true;
6681 unset($params[
'attr'][
'title']);
6682 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
6684 unset($params[
'attr'][
'title']);
6685 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
6692 if (
GETPOST(
'modelselected',
'alpha')) {
6693 $action =
'presend';
6695 if ($action !=
'prerelance' && $action !=
'presend') {
6696 print
'<div class="fichecenter"><div class="fichehalfleft">';
6697 print
'<a name="builddoc"></a>';
6702 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
6703 $genallowed = $usercanread;
6704 $delallowed = $usercancreate;
6706 print $formfile->showdocuments(
6726 'remove_file_comfirm'
6729 $somethingshown = $formfile->numoffiles;
6732 $tmparray = $form->showLinkToObjectBlock(
$object, array(), array(
'invoice'), 1);
6733 $linktoelem = $tmparray[
'linktoelem'];
6734 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
6735 print $htmltoenteralink;
6737 $compatibleImportElementsList =
false;
6741 $compatibleImportElementsList = array(
'commande',
'propal',
'subscription');
6743 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem, $compatibleImportElementsList);
6747 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6748 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
6749 $useonlinepayment = count($validpaymentmethod);
6752 print
'<br><!-- Link to pay -->'.
"\n";
6753 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6754 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
6757 print
'</div><div class="fichehalfright">';
6761 $morehtmlcenter =
'<div class="nowraponall">';
6762 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullConversation'),
'',
'fa fa-comments imgforviewmode', DOL_URL_ROOT.
'/compta/facture/messaging.php?id='.
$object->id);
6763 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
6764 $morehtmlcenter .=
'</div>';
6767 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
6769 $somethingshown = $formactions->showactions(
$object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
6771 print
'</div></div>';
6776 $modelmail =
'facture_send';
6777 $defaulttopic =
'SendBillRef';
6778 $diroutput =
$conf->invoice->multidir_output[
$object->entity];
6779 $trackid =
'inv'.$object->id;
6781 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
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.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
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 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.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return 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, $morecssdiv='')
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.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
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'.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
if(preg_match('/(crypted|dolcrypt):/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.