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 if ($result > 0 && $discount->fk_facture ==
$object->id) {
400 $discount->unlink_invoice();
404 } elseif ($action ==
'valid' && $usercancreate) {
408 if ((preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) &&
415 $last_of_type =
$object->willBeLastOfSameType(
true);
416 if (empty(
$object->date_validation) && !$last_of_type[0]) {
426 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
435 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
444 $array_of_total_ht_per_vat_rate = array();
445 $array_of_total_ht_devise_per_vat_rate = array();
446 foreach (
$object->lines as $line) {
448 $vat_src_code_for_line =
'';
449 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
450 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
452 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
453 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
455 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
456 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
460 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
461 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
462 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
464 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
465 if (
$object->type == $object::TYPE_DEPOSIT) {
466 $langs->load(
"errors");
468 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
472 $tmpvatratetoshow = explode(
'_', $vatrate);
473 $tmpvatratetoshow[0] = round((
float) $tmpvatratetoshow[0], 2);
475 if ($tmpvatratetoshow[0] != 0) {
476 $langs->load(
"errors");
477 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", (
string) $tmpvatratetoshow[0]),
null,
'errors');
485 } elseif ($action ==
'classin' && $usercancreate) {
488 } elseif ($action ==
'setposinfo' && $usercancreate) {
492 $result =
$object->update($user);
496 } elseif ($action ==
'setmode' && $usercancreate) {
502 } elseif ($action ==
'setretainedwarrantyconditions' && $usercancreate) {
504 $object->retained_warranty_fk_cond_reglement = 0;
505 $result =
$object->setRetainedWarrantyPaymentTerms(
GETPOSTINT(
'retained_warranty_fk_cond_reglement'));
510 $old_rw_date_lim_reglement =
$object->retained_warranty_date_limit;
511 $new_rw_date_lim_reglement =
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
512 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
513 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
518 $result =
$object->update($user);
522 } elseif ($action ==
'setretainedwarranty' && $usercancreate) {
528 } elseif ($action ==
'setretainedwarrantydatelimit' && $usercancreate) {
530 $result =
$object->setRetainedWarrantyDateLimit(
GETPOSTINT(
'retained_warranty_date_limit'));
534 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
535 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
536 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
538 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
540 $old_date_lim_reglement =
$object->date_lim_reglement;
542 if (empty($newdate)) {
543 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
544 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.
$id.
'&action=editinvoicedate&token='.
newToken());
549 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
551 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
556 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
557 if ($new_date_lim_reglement) {
558 $object->date_lim_reglement = $new_date_lim_reglement;
563 $result =
$object->update($user);
566 $action =
'editinvoicedate';
568 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
573 $object->date_pointoftax = $date_pointoftax;
574 $result =
$object->update($user);
578 } elseif ($action ==
'setconditions' && $usercancreate) {
580 $object->cond_reglement_code = 0;
581 $object->cond_reglement_id = 0;
594 $old_date_lim_reglement =
$object->date_lim_reglement;
595 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
596 if ($new_date_lim_reglement) {
597 $object->date_lim_reglement = $new_date_lim_reglement;
602 $result =
$object->update($user);
614 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
618 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
619 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
621 $result =
$object->update($user);
625 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
628 $result =
$object->update($user);
635 $outputlangs = $langs;
638 $newlang =
GETPOST(
'lang_id',
'aZ09');
641 $newlang =
$object->thirdparty->default_lang;
643 if (!empty($newlang)) {
645 $outputlangs->setDefaultLang($newlang);
646 $outputlangs->load(
'products');
651 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
657 } elseif ($action ==
'set_incoterms' && isModEnabled(
'incoterm') && $usercancreate) {
659 } elseif ($action ==
'settags' && isModEnabled(
'category') && $usercancreate) {
661 } elseif ($action ==
'setbankaccount' && $usercancreate) {
663 } elseif ($action ==
'setremisepercent' && $usercancreate) {
666 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
685 $newremaintopay =
$object->getRemainToPay(0);
686 if ($newremaintopay == 0) {
693 if (
GETPOSTINT(
"remise_id_for_payment") > 0) {
694 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
696 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
700 $remaintopay =
$object->getRemainToPay(0);
704 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
708 $result = $discount->link_to_invoice(0, $id);
716 $newremaintopay =
$object->getRemainToPay(0);
717 if ($newremaintopay == 0) {
730 $outputlangs = $langs;
733 $newlang =
GETPOST(
'lang_id',
'aZ09');
737 $newlang =
$object->thirdparty->default_lang;
739 if (!empty($newlang)) {
741 $outputlangs->setDefaultLang($newlang);
745 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
750 } elseif ($action ==
'setref' && $usercancreate) {
752 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', 0,
'',
'', $user,
'BILL_MODIFY');
753 } elseif ($action ==
'setref_client' && $usercancreate) {
756 } elseif ($action ==
'setdemandreason' && $usercancreate) {
757 $result =
$object->setInputReason($inputReasonId);
761 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
770 $qualified_for_stock_change = 0;
772 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
774 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
777 if ($qualified_for_stock_change) {
778 if (!$idwarehouse || $idwarehouse == - 1) {
780 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
787 $result =
$object->validate($user,
'', $idwarehouse);
791 $outputlangs = $langs;
794 $newlang =
GETPOST(
'lang_id',
'aZ09');
797 $newlang =
$object->thirdparty->default_lang;
799 if (!empty($newlang)) {
801 $outputlangs->setDefaultLang($newlang);
802 $outputlangs->load(
'products');
808 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
821 } elseif ($action ==
'confirm_modif' && $usercanunvalidate && !
getDolGlobalString(
'INVOICE_CAN_NEVER_BE_EDITED')) {
830 $qualified_for_stock_change = 0;
832 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
834 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
837 if ($qualified_for_stock_change) {
838 if (!$idwarehouse || $idwarehouse == -1) {
840 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
849 $sql =
'SELECT pf.amount';
850 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'paiement_facture as pf';
851 $sql .=
' WHERE pf.fk_facture = ' . ((int)
$object->id);
853 $result = $db->query($sql);
856 $num = $db->num_rows($result);
859 $objp = $db->fetch_object($result);
860 $totalpaid += $objp->amount;
867 $resteapayer =
$object->total_ttc - $totalpaid;
870 $ventilExportCompta =
$object->getVentilExportCompta();
873 if ($ventilExportCompta == 0) {
875 $result =
$object->setDraft($user, $idwarehouse);
882 $outputlangs = $langs;
885 $newlang =
GETPOST(
'lang_id',
'aZ09');
888 $newlang =
$object->thirdparty->default_lang;
890 if (!empty($newlang)) {
892 $outputlangs->setDefaultLang($newlang);
893 $outputlangs->load(
'products');
898 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
903 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
906 $result =
$object->setPaid($user);
910 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
913 $close_code =
GETPOST(
"close_code",
'restricthtml');
914 $close_note =
GETPOST(
"close_note",
'restricthtml');
916 $result =
$object->setPaid($user, $close_code, $close_note);
923 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
925 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
928 $close_code =
GETPOST(
"close_code",
'restricthtml');
929 $close_note =
GETPOST(
"close_note",
'restricthtml');
931 $result =
$object->setCanceled($user, $close_code, $close_note);
938 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
940 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
948 $result = $discountcheck->fetch(0,
$object->id);
961 $amount_ht = $amount_tva = $amount_ttc = array();
962 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
966 foreach (
$object->lines as $line) {
967 if ($line->product_type < 9 && $line->total_ht != 0) {
968 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
970 if (!isset($amount_ht[$keyforvatrate])) {
971 $amount_ht[$keyforvatrate] = 0;
973 $amount_ht[$keyforvatrate] += $line->total_ht;
974 if (!isset($amount_tva[$keyforvatrate])) {
975 $amount_tva[$keyforvatrate] = 0;
977 $amount_tva[$keyforvatrate] += $line->total_tva;
978 if (!isset($amount_ttc[$keyforvatrate])) {
979 $amount_ttc[$keyforvatrate] = 0;
981 $amount_ttc[$keyforvatrate] += $line->total_ttc;
982 if (!isset($multicurrency_amount_ht[$keyforvatrate])) {
983 $multicurrency_amount_ht[$keyforvatrate] = 0;
985 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
986 if (!isset($multicurrency_amount_tva[$keyforvatrate])) {
987 $multicurrency_amount_tva[$keyforvatrate] = 0;
989 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
990 if (!isset($multicurrency_amount_ttc[$keyforvatrate])) {
991 $multicurrency_amount_ttc[$keyforvatrate] = 0;
993 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
997 '@phan-var-force array<string,float> $amount_ht
998 @phan-var-force array<string,float> $amount_tva
999 @phan-var-force array<string,float> $amount_ttc
1000 @phan-var-force array<string,float> $multicurrency_amount_ht
1001 @phan-var-force array<string,float> $multicurrency_amount_tva
1002 @phan-var-force array<string,float> $multicurrency_amount_ttc';
1006 $alreadypaid =
$object->getSommePaiement();
1007 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
1008 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
1009 foreach ($amount_ht as $vatrate => $val) {
1010 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
1011 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
1012 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
1013 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
1014 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
1015 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
1024 $discount->description =
'(CREDIT_NOTE)';
1026 $discount->description =
'(DEPOSIT)';
1028 $discount->description =
'(EXCESS RECEIVED)';
1030 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
1032 $discount->fk_soc =
$object->socid;
1033 $discount->socid =
$object->socid;
1034 $discount->fk_facture_source =
$object->id;
1043 $discount->description =
'(EXCESS RECEIVED)';
1046 $sql =
'SELECT SUM(pf.amount) as total_paiements';
1047 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
1048 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
1049 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
1050 $sql .=
' AND pf.fk_paiement = p.rowid';
1051 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
1052 $resql = $db->query($sql);
1057 $res = $db->fetch_object($resql);
1058 $total_paiements = $res->total_paiements;
1061 $total_creditnote_and_deposit = 0;
1062 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1063 $sql .=
" re.description, re.fk_facture_source";
1064 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1065 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
1066 $resql = $db->query($sql);
1067 if (!empty($resql)) {
1068 while ($obj = $db->fetch_object($resql)) {
1069 $total_creditnote_and_deposit += $obj->amount_ttc;
1075 $discount->amount_ttc =
price2num($total_paiements + $total_creditnote_and_deposit -
$object->total_ttc,
'MT');
1076 $discount->amount_tva = 0;
1077 $discount->amount_ht = $discount->amount_ttc;
1078 $discount->tva_tx = 0;
1079 $discount->vat_src_code =
'';
1081 if ($discount->amount_ttc > 0) {
1082 $result = $discount->create($user);
1092 $discount->description =
'(CREDIT_NOTE)';
1094 $discount->description =
'(DEPOSIT)';
1097 foreach ($amount_ht as $tva_tx => $xxx) {
1099 $discount->amount_ht = -((float) $amount_ht[$tva_tx]);
1100 $discount->amount_tva = -((float) $amount_tva[$tva_tx]);
1101 $discount->amount_ttc = -((float) $amount_ttc[$tva_tx]);
1102 $discount->total_ht = -((float) $amount_ht[$tva_tx]);
1103 $discount->total_tva = -((float) $amount_tva[$tva_tx]);
1104 $discount->total_ttc = -((float) $amount_ttc[$tva_tx]);
1105 $discount->multicurrency_amount_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1106 $discount->multicurrency_amount_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1107 $discount->multicurrency_amount_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1108 $discount->multicurrency_total_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1109 $discount->multicurrency_total_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1110 $discount->multicurrency_total_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1113 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
1114 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
1115 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
1116 $discount->total_ht = abs((
float) $amount_ht[$tva_tx]);
1117 $discount->total_tva = abs((
float) $amount_tva[$tva_tx]);
1118 $discount->total_ttc = abs((
float) $amount_ttc[$tva_tx]);
1119 $discount->multicurrency_amount_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1120 $discount->multicurrency_amount_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1121 $discount->multicurrency_amount_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1122 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1123 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1124 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1130 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
1131 $vat_src_code = $reg[1];
1132 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
1135 $discount->tva_tx = abs((
float) $tva_tx);
1136 $discount->vat_src_code = $vat_src_code;
1138 $result = $discount->create($user);
1146 if (empty($error)) {
1156 $result =
$object->setPaid($user);
1170 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
1175 $result = $paiement->fetch(
GETPOSTINT(
'paiement_id'));
1176 $paymentbills = ($result > 0) ? $paiement->getBillsArray() : array();
1177 if ($result > 0 && is_array($paymentbills) && in_array(
$object->id, $paymentbills)) {
1178 $result = $paiement->delete($user);
1180 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1190 } elseif ($action ==
'add' && $usercancreate) {
1197 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1203 $object->demand_reason_id = $inputReasonId;
1205 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
1215 if (empty($dateinvoice)) {
1217 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1227 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1237 $object->date_pointoftax = $date_pointoftax;
1238 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1239 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1250 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1251 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1268 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1270 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1274 if (empty($dateinvoice)) {
1276 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1286 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1291 if (!empty($originentity)) {
1292 $object->entity = $originentity;
1298 $object->date_pointoftax = $date_pointoftax;
1299 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1300 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1305 $object->cond_reglement_id = 0;
1311 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1312 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1316 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1319 $facture_source =
new Facture($db);
1320 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1321 if ($facture_source->isSituationInvoice()) {
1322 $object->situation_counter = $facture_source->situation_counter;
1323 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1324 $facture_source->fetchPreviousNextSituationInvoice();
1334 if (
$object->copy_linked_contact($facture_source,
'internal') < 0) {
1336 } elseif ($facture_source->socid ==
$object->socid) {
1338 if (
$object->copy_linked_contact($facture_source,
'external') < 0) {
1349 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1350 if (!empty($facture_source->lines)) {
1351 $fk_parent_line = 0;
1353 foreach ($facture_source->lines as $line) {
1355 if (method_exists($line,
'fetch_optionals')) {
1357 $line->fetch_optionals();
1361 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1362 $fk_parent_line = 0;
1366 if ($facture_source->isSituationInvoice()) {
1367 $source_fk_prev_id = $line->fk_prev_id;
1368 $line->fk_prev_id = $line->id;
1370 if (!empty($facture_source->tab_previous_situation_invoice)) {
1373 $tab_jumped_credit_notes = array();
1374 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1375 $searchPreviousInvoice =
true;
1376 while ($searchPreviousInvoice) {
1377 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1378 $searchPreviousInvoice =
false;
1382 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1388 $maxPrevSituationPercent = 0;
1389 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1390 if ($prevLine->id == $source_fk_prev_id) {
1391 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1394 $line->total_ht -= $prevLine->total_ht;
1395 $line->total_tva -= $prevLine->total_tva;
1396 $line->total_ttc -= $prevLine->total_ttc;
1397 $line->total_localtax1 -= $prevLine->total_localtax1;
1398 $line->total_localtax2 -= $prevLine->total_localtax2;
1400 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1401 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1402 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1403 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1408 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1413 $maxPrevSituationPercent = 0;
1414 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1415 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1416 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1417 $maxPrevSituationPercent = $prevLine->situation_percent;
1419 $line->total_ht -= $prevLine->total_ht;
1420 $line->total_tva -= $prevLine->total_tva;
1421 $line->total_ttc -= $prevLine->total_ttc;
1422 $line->total_localtax1 -= $prevLine->total_localtax1;
1423 $line->total_localtax2 -= $prevLine->total_localtax2;
1425 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1426 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1427 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1428 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1434 $line->situation_percent += $maxPrevSituationPercent;
1440 $line->fk_facture =
$object->id;
1441 $line->fk_parent_line = $fk_parent_line;
1443 $line->subprice = -$line->subprice;
1445 $line->total_ht = -$line->total_ht;
1446 $line->total_tva = -$line->total_tva;
1447 $line->total_ttc = -$line->total_ttc;
1448 $line->total_localtax1 = -$line->total_localtax1;
1449 $line->total_localtax2 = -$line->total_localtax2;
1451 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1452 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1453 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1454 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1456 $line->context[
'createcreditnotefrominvoice'] = 1;
1457 $result = $line->insert(0, 1);
1462 if ($result > 0 && $line->product_type == 9) {
1463 $fk_parent_line = $result;
1471 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1472 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1473 $totalpaid = $facture_source->getSommePaiement();
1474 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1475 $totaldeposits = $facture_source->getSumDepositsUsed();
1476 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1478 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1479 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1482 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1487 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1488 $tva_tx = (float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY');
1493 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), 0, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC', $remain_to_pay);
1498 if (!empty(
$object->fk_facture_source) &&
$id > 0) {
1499 $facture_source->fetch(
$object->fk_facture_source);
1500 $facture_source->fetchObjectLinked();
1502 if (!empty($facture_source->linkedObjectsIds)) {
1503 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1504 $object->add_object_linked($sourcetype, current($TIds));
1513 if (empty($dateinvoice)) {
1515 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1526 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1536 $object->date_pointoftax = $date_pointoftax;
1537 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1538 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1551 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1552 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1568 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1569 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1570 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1574 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1578 if (empty($dateinvoice)) {
1580 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1590 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1591 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1596 if ($typeamount && !empty($origin) && !empty($originid)) {
1597 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1598 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1602 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1603 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1607 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1608 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1618 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1628 $object->date_pointoftax = $date_pointoftax;
1629 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1630 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1642 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1643 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1647 $object->situation_counter = 1;
1652 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1654 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1656 $object->retained_warranty = 0;
1657 $object->retained_warranty_fk_cond_reglement = 0;
1660 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1661 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1664 $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);
1669 if (!empty($origin) && !empty($originid)) {
1672 $element = $subelement = $origin;
1673 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1674 $element = $regs[1];
1675 $subelement = $regs[2];
1679 if ($element ==
'order') {
1680 $element = $subelement =
'commande';
1682 if ($element ==
'propal') {
1683 $element =
'comm/propal';
1684 $subelement =
'propal';
1686 if ($element ==
'contract') {
1687 $element = $subelement =
'contrat';
1689 if ($element ==
'inter') {
1690 $element = $subelement =
'fichinter';
1692 if ($element ==
'shipping') {
1693 $element = $subelement =
'expedition';
1697 $object->origin_type = $origin;
1698 $object->origin_id = $originid;
1703 if (
$object->origin ==
'shipping') {
1704 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1706 $exp->fetch(
$object->origin_id);
1707 $exp->fetchObjectLinked();
1708 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1709 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1710 $object->linked_objects[
'commande'] = $value;
1716 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
1724 $classname = ucfirst($subelement);
1725 $srcobject =
new $classname($db);
1726 '@phan-var-force CommonObject $srcobject';
1728 dol_syslog(
"Try to find source object origin=".
$object->origin.
" originid=".
$object->origin_id.
" to add lines or deposit lines");
1729 $result = $srcobject->fetch(
$object->origin_id);
1735 $amountdeposit = array();
1738 if ($typeamount ==
'amount') {
1739 $amount = (float) $valuedeposit;
1741 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1744 $TTotalByTva = array();
1745 foreach ($srcobject->lines as &$line) {
1746 if (empty($line->qty)) {
1749 if (!empty($line->special_code)) {
1752 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1754 '@phan-var-force array<string,float> $TTotalByTva';
1756 $amount_ttc_diff = 0.;
1757 foreach ($TTotalByTva as $tva => &$total) {
1758 if (empty($amountdeposit[$tva])) {
1759 $amountdeposit[$tva] = 0;
1761 $coef = $total / $srcobject->total_ttc;
1762 $am = $amount * $coef;
1763 $amount_ttc_diff += $am;
1764 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1767 if ($typeamount ==
'amount') {
1768 $amountdeposit[0] = $valuedeposit;
1769 } elseif ($typeamount ==
'variable') {
1772 $lines = $srcobject->lines;
1773 $numlines = count($lines);
1774 for ($i = 0; $i < $numlines; $i++) {
1776 if (empty($lines[$i]->qty)) {
1779 if (!empty($lines[$i]->special_code)) {
1783 $totalamount += $lines[$i]->total_ht;
1784 $tva_tx = $lines[$i]->tva_tx;
1786 if (empty($amountdeposit[$tva_tx])) {
1787 $amountdeposit[$tva_tx] = 0;
1789 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1793 if ($totalamount == 0) {
1794 $amountdeposit[0] = 0;
1802 $amount_ttc_diff = $amountdeposit[0];
1805 foreach ($amountdeposit as $tva => $amount) {
1806 if (empty($amount)) {
1811 'amount' =>
'FixAmount',
1812 'variable' =>
'VarAmount'
1814 $descline =
'(DEPOSIT)';
1816 if ($typeamount ==
'amount') {
1817 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1818 } elseif ($typeamount ==
'variable') {
1819 $descline .=
' ('.$valuedeposit.
'%)';
1822 $descline .=
' - '.$srcobject->ref;
1835 $i >= 0 ? $lines[$i]->info_bits : 0,
1841 $i >= 0 ? $lines[$i]->special_code : 0,
1854 (!empty(
$conf->global->MAIN_DEPOSIT_MULTI_TVA) ? 0 : 1)
1858 $diff =
$object->total_ttc - $amount_ttc_diff;
1862 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1863 $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);
1872 $lines = $srcobject->lines;
1873 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1874 $srcobject->fetch_lines();
1875 $lines = $srcobject->lines;
1880 if (is_array($lines)) {
1881 foreach ($lines as $line) {
1883 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuestandardinvoice / 100,
'MS');
1889 if (is_array($lines)) {
1890 foreach ($lines as $line) {
1892 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuedeposit / 100,
'MS');
1897 $fk_parent_line = 0;
1898 $num = count($lines);
1900 for ($i = 0; $i < $num; $i++) {
1901 if (!in_array($lines[$i]->
id, $selectedLines)) {
1906 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
1910 if (!isset(
$conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1911 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1913 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
1917 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1918 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1920 if (
$object->situation_counter == 1) {
1921 $lines[$i]->situation_percent = 0;
1924 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
1927 $desc = $label ? $label : $langs->trans(
'Discount');
1931 $discount->fk_soc =
$object->socid;
1932 $discount->socid =
$object->socid;
1933 $discount->amount_ht = abs($lines[$i]->total_ht);
1934 $discount->amount_tva = abs($lines[$i]->total_tva);
1935 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1936 $discount->total_ht = abs($lines[$i]->total_ht);
1937 $discount->total_tva = abs($lines[$i]->total_tva);
1938 $discount->total_ttc = abs($lines[$i]->total_ttc);
1939 $discount->tva_tx = $lines[$i]->tva_tx;
1940 $discount->fk_user = $user->id;
1941 $discount->description = $desc;
1942 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1943 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1944 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1945 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1946 $discount->multicurrency_total_ht = abs($lines[$i]->multicurrency_total_ht);
1947 $discount->multicurrency_total_tva = abs($lines[$i]->multicurrency_total_tva);
1948 $discount->multicurrency_total_ttc = abs($lines[$i]->multicurrency_total_ttc);
1950 $discountid = $discount->create($user);
1951 if ($discountid > 0) {
1952 $result =
$object->insert_discount($discountid);
1964 $date_start =
false;
1965 if (isset($lines[$i]->date_debut_prevue)) {
1966 $date_start = $lines[$i]->date_debut_prevue;
1968 if (isset($lines[$i]->date_debut_reel)) {
1969 $date_start = $lines[$i]->date_debut_reel;
1971 if (isset($lines[$i]->date_start)) {
1972 $date_start = $lines[$i]->date_start;
1977 if (isset($lines[$i]->date_fin_prevue)) {
1978 $date_end = $lines[$i]->date_fin_prevue;
1980 if (isset($lines[$i]->date_fin_reel)) {
1981 $date_end = $lines[$i]->date_fin_reel;
1983 if (isset($lines[$i]->date_end)) {
1984 $date_end = $lines[$i]->date_end;
1988 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1989 $fk_parent_line = 0;
1992 $array_options = array();
1994 if (method_exists($lines[$i],
'fetch_optionals')) {
1995 $lines[$i]->fetch_optionals();
1996 $array_options = $lines[$i]->array_options;
1999 $tva_tx = $lines[$i]->tva_tx;
2000 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
2001 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
2011 $lines[$i]->subprice,
2016 $lines[$i]->fk_product,
2017 $lines[$i]->remise_percent,
2021 $lines[$i]->info_bits,
2022 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except : null,
2027 $lines[$i]->special_code,
2031 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice : null,
2035 $lines[$i]->situation_percent ?? 100,
2036 $lines[$i]->fk_prev_id ?? 0,
2037 $lines[$i]->fk_unit,
2044 foreach (
$object->lines as $line) {
2045 if ($line->id == $result) {
2046 $line->extraparams = $lines[$i]->extraparams;
2047 $line->setExtraParameters();
2059 if ($result > 0 && $lines[$i]->product_type == 9) {
2060 $fk_parent_line = $result;
2070 $object->update_price(1,
'auto', 0, $mysoc);
2072 $object->line_order(
true,
'DESC');
2100 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id,
'objFrom' => $srcobject);
2101 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
2114 for ($i = 1; $i <= $NBLINES; $i++) {
2120 $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);
2124 $object->update_price(1,
'auto', 0, $mysoc);
2131 if (empty($dateinvoice)) {
2133 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
2143 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
2153 if (!empty($origin) && !empty($originid)) {
2154 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2157 $object->origin_type = $origin;
2158 $object->origin_id = $originid;
2162 $retained_warranty =
GETPOSTINT(
'retained_warranty');
2163 if (
price2num($retained_warranty) > 0) {
2167 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
2168 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
2171 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
2172 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
2173 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
2175 $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);
2178 foreach (
$object->lines as $i => &$line) {
2179 $line->fk_prev_id = $line->id;
2180 $line->fetch_optionals();
2182 $line->situation_percent = 0;
2184 $line->situation_percent = $line->get_prev_progress(
$object->id);
2188 $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);
2189 $line->total_ht = (float) $tabprice[0];
2190 $line->total_tva = (float) $tabprice[1];
2191 $line->total_ttc = (float) $tabprice[2];
2192 $line->total_localtax1 = (float) $tabprice[9];
2193 $line->total_localtax2 = (float) $tabprice[10];
2194 $line->multicurrency_total_ht = (float) $tabprice[16];
2195 $line->multicurrency_total_tva = (float) $tabprice[17];
2196 $line->multicurrency_total_ttc = (float) $tabprice[18];
2199 if ($line->fk_remise_except) {
2201 $result = $discount->fetch($line->fk_remise_except);
2204 if ($discount->fk_facture_line > 0) {
2205 $line->fk_remise_except = 0;
2214 $object->date_pointoftax = $date_pointoftax;
2215 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2231 $object->situation_counter += 1;
2236 $extrafields->fetch_name_optionals_label(
$object->table_element);
2237 $extrafields->setOptionalsFromPost(
null,
$object);
2243 $nextSituationInvoice =
new Facture($db);
2244 $nextSituationInvoice->fetch($id);
2247 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id);
2248 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $nextSituationInvoice, $action);
2259 if ($id > 0 && !$error) {
2260 if (isModEnabled(
'category')) {
2261 $categories =
GETPOST(
'categories',
'array');
2262 if (method_exists(
$object,
'setCategories')) {
2263 $object->setCategories($categories);
2271 $outputlangs = $langs;
2274 $newlang =
GETPOST(
'lang_id',
'aZ09');
2277 if (empty(
$object->thirdparty)) {
2280 $newlang =
$object->thirdparty->default_lang;
2282 if (!empty($newlang)) {
2284 $outputlangs->setDefaultLang($newlang);
2285 $outputlangs->load(
'products');
2290 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2296 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2301 $_GET[
"origin"] = $_POST[
"origin"];
2302 $_GET[
"originid"] = $_POST[
"originid"];
2305 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2309 foreach (
$object->lines as $line) {
2310 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2313 if ($line->product_type == 1) {
2314 $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);
2317 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2319 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2320 $vat_rate = str_replace(
'*',
'', $vat_rate);
2323 foreach (
$object->lines as $line) {
2324 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2327 $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);
2329 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2331 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2332 $remise_percent = str_replace(
'*',
'', $remise_percent);
2333 foreach (
$object->lines as $line) {
2334 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2337 $tvatx = $line->tva_tx;
2338 if (!empty($line->vat_src_code)) {
2339 $tvatx .=
' ('.$line->vat_src_code.
')';
2341 $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);
2343 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
2346 $langs->load(
'subtotals');
2348 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
2349 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
2351 $subtotal_options = array();
2353 foreach (Facture::$TITLE_OPTIONS as $option) {
2354 $value =
GETPOST($option,
'alphanohtml');
2356 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2361 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2372 $outputlangs = $langs;
2373 $newlang =
GETPOST(
'lang_id',
'alpha');
2375 $newlang =
$object->thirdparty->default_lang;
2377 if (!empty($newlang)) {
2379 $outputlangs->setDefaultLang($newlang);
2382 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2387 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2389 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
2392 $langs->load(
'subtotals');
2394 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
2395 foreach (
$object->lines as $line) {
2396 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
2397 $desc = $line->desc;
2398 $depth = -$line->qty;
2402 $subtotal_options = array();
2404 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
2405 $value =
GETPOST($option,
'alphanohtml');
2407 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2412 if (isset($desc) && isset($depth)) {
2413 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2415 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
2418 if (isset($result) && $result >= 0) {
2424 $outputlangs = $langs;
2425 $newlang =
GETPOST(
'lang_id',
'alpha');
2427 $newlang =
$object->thirdparty->default_lang;
2429 if (!empty($newlang)) {
2431 $outputlangs->setDefaultLang($newlang);
2434 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2439 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2441 } elseif ($action ==
'addline' &&
GETPOST(
'updateallvatlinesblock',
'alpha') &&
GETPOST(
'vatforblocklines',
'alpha') !==
'' && $usercancreate) {
2442 $tx_tva =
GETPOST(
'vatforblocklines') ?
GETPOST(
'vatforblocklines') : 0;
2443 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'tva', $tx_tva);
2444 } elseif ($action ==
'addline' &&
GETPOST(
'updatealldiscountlinesblock',
'alpha') &&
GETPOST(
'discountforblocklines',
'alpha') !==
'' && $usercancreate) {
2445 $discount =
GETPOST(
'discountforblocklines') ?
GETPOST(
'discountforblocklines') : 0;
2446 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'discount', $discount);
2447 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && !
GETPOST(
'submitforallmark',
'alpha') && $usercancreate) {
2448 $langs->load(
'errors');
2453 $line_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
2456 $price_ht_devise =
'';
2458 $price_ttc_devise =
'';
2461 $price_min_ttc =
'';
2463 if (
GETPOST(
'price_ht') !==
'') {
2466 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2469 if (
GETPOST(
'price_ttc') !==
'') {
2472 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2473 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2476 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2477 if ($prod_entry_mode ==
'free') {
2483 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2488 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2491 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
2492 if (empty($remise_percent)) {
2493 $remise_percent = 0;
2497 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2498 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2500 if (is_array($extralabelsline)) {
2502 foreach ($extralabelsline as $key => $value) {
2503 unset($_POST[
"options_".$key.$predef]);
2507 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2508 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2511 if (!$prod_entry_mode) {
2513 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2517 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2518 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2523 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0)
2524 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
2525 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
2526 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
2527 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
2528 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
2529 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2530 $langs->load(
"errors");
2531 if (
$object->type == $object::TYPE_DEPOSIT) {
2533 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2535 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2540 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
2541 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
2545 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
2546 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2550 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2554 $langs->load(
"errors");
2555 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2559 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2560 if ($combinations =
GETPOST(
'combinations',
'array')) {
2564 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2565 $idprod = $res->fk_product_child;
2567 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2573 $price_base_type =
null;
2574 if (!$error && ($qty >= 0) && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
2580 $ret =
$object->fetch_thirdparty();
2585 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2596 if (!empty($idprod) && $idprod > 0) {
2598 $prod->fetch($idprod);
2600 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2605 $datapriceofproduct = $prod->getSellPrice($mysoc,
$object->thirdparty, $pqp);
2607 $pu_ht = $datapriceofproduct[
'pu_ht'];
2608 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2609 $price_min = $datapriceofproduct[
'price_min'];
2610 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2611 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2615 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2616 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $prod->tva_tx));
2620 if (!empty($price_ht) || $price_ht ===
'0') {
2622 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2623 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2624 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2627 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2629 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2630 } elseif ($tmpvat != $tmpprodvat) {
2632 if ($price_base_type !=
'HT') {
2633 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2635 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2639 $outputlangs = $langs;
2645 if (
GETPOST(
'lang_id',
'aZ09')) {
2646 $newlang =
GETPOST(
'lang_id',
'aZ09');
2648 if (empty($newlang)) {
2649 $newlang =
$object->thirdparty->default_lang;
2651 if (!empty($newlang)) {
2653 $outputlangs->setDefaultLang($newlang);
2654 $outputlangs->load(
'products');
2657 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->
description;
2659 $desc = $prod->description;
2671 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
2675 if (!empty($prod->customcode)) {
2676 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomsCode").
': '.$prod->customcode;
2678 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2681 if (!empty($prod->country_code)) {
2682 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $outputlangs, 0);
2685 if (!empty($prod->customcode)) {
2686 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomsCode").
': '.$prod->customcode;
2688 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2691 if (!empty($prod->country_code)) {
2692 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $langs, 0);
2699 $type = $prod->type;
2700 $fk_unit = $prod->fk_unit;
2702 if (!empty($price_ht)) {
2707 if (!empty($price_ttc)) {
2712 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2713 $tva_tx = str_replace(
'*',
'', $tva_tx);
2714 if (empty($tva_tx)) {
2717 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2720 $fk_unit =
GETPOST(
'units',
'alpha');
2722 if ($pu_ttc && !$pu_ht) {
2723 $price_base_type =
'TTC';
2737 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2738 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2741 $pu_equivalent = $pu_ht;
2742 $pu_equivalent_ttc = $pu_ttc;
2744 $currency_tx =
$object->multicurrency_tx;
2751 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2752 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
2754 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2755 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
2770 $fournprice = (int) (
GETPOST(
'fournprice'.$predef) ?
GETPOST(
'fournprice'.$predef) :
'');
2775 $price2num_remise_percent =
price2num($remise_percent);
2776 $price2num_price_min =
price2num($price_min);
2777 $price2num_price_min_ttc =
price2num($price_min_ttc);
2778 if (empty($price2num_pu_ht)) {
2779 $price2num_pu_ht = 0;
2781 if (empty($price2num_remise_percent)) {
2782 $price2num_remise_percent = 0;
2784 if (empty($price2num_price_min)) {
2785 $price2num_price_min = 0;
2787 if (empty($price2num_price_min_ttc)) {
2788 $price2num_price_min_ttc = 0;
2793 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2794 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2797 } 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') {
2798 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2805 '@phan-var-force CommonObjectLine[] $lines';
2807 if (isModEnabled(
'productbatch') && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) &&
getDolGlobalString(
'INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS')) {
2808 $langs->load(
'productbatch');
2809 foreach ($lines[$i]->detail_batch as $batchline) {
2810 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2814 $situation_percent = GETPOSTISSET(
'progress') ?
GETPOSTINT(
'progress') : 100;
2817 $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);
2822 $outputlangs = $langs;
2825 $newlang =
GETPOST(
'lang_id',
'aZ09');
2828 $newlang =
$object->thirdparty->default_lang;
2830 if (!empty($newlang)) {
2832 $outputlangs->setDefaultLang($newlang);
2833 $outputlangs->load(
'products');
2838 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2844 unset($_POST[
'prod_entry_mode']);
2845 unset($_POST[
'qty']);
2846 unset($_POST[
'type']);
2847 unset($_POST[
'remise_percent']);
2848 unset($_POST[
'price_ht']);
2849 unset($_POST[
'multicurrency_price_ht']);
2850 unset($_POST[
'price_ttc']);
2851 unset($_POST[
'tva_tx']);
2852 unset($_POST[
'product_ref']);
2853 unset($_POST[
'product_label']);
2854 unset($_POST[
'product_desc']);
2855 unset($_POST[
'fournprice']);
2856 unset($_POST[
'buying_price']);
2857 unset($_POST[
'np_marginRate']);
2858 unset($_POST[
'np_markRate']);
2859 unset($_POST[
'dp_desc']);
2860 unset($_POST[
'idprod']);
2861 unset($_POST[
'units']);
2862 unset($_POST[
'date_starthour']);
2863 unset($_POST[
'date_startmin']);
2864 unset($_POST[
'date_startsec']);
2865 unset($_POST[
'date_startday']);
2866 unset($_POST[
'date_startmonth']);
2867 unset($_POST[
'date_startyear']);
2868 unset($_POST[
'date_endhour']);
2869 unset($_POST[
'date_endmin']);
2870 unset($_POST[
'date_endsec']);
2871 unset($_POST[
'date_endday']);
2872 unset($_POST[
'date_endmonth']);
2873 unset($_POST[
'date_endyear']);
2874 unset($_POST[
'situations']);
2875 unset($_POST[
'progress']);
2883 } elseif ($action ==
'addline' && $usercancreate && (
2884 (
GETPOST(
'submitforallmargins',
'alpha') &&
GETPOST(
'marginforalllines',
'alpha') !==
'') ||
2885 (
GETPOST(
'submitforallmark',
'alpha') &&
GETPOST(
'markforalllines',
'alpha') !==
''))) {
2887 $margin_rate = GETPOSTISSET(
'marginforalllines') ?
GETPOST(
'marginforalllines',
'int') :
'';
2888 $mark_rate = GETPOSTISSET(
'markforalllines') ?
GETPOST(
'markforalllines',
'int') :
'';
2889 foreach (
$object->lines as &$line)
if ($line->subprice > 0) {
2890 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2893 $subprice_multicurrency = $line->subprice;
2894 if (is_numeric($margin_rate) && $margin_rate > 0) {
2895 $line->subprice = floatval(
price2num(floatval($line->pa_ht) * (1 + floatval($margin_rate) / 100),
'MU'));
2896 } elseif (is_numeric($mark_rate) && $mark_rate > 0) {
2897 $line->subprice = floatval($line->pa_ht / (1 - (floatval($mark_rate) / 100)));
2899 $line->subprice = floatval($line->pa_ht);
2903 $res = $prod->fetch($line->fk_product);
2905 if ($prod->price_min > $line->subprice) {
2906 $price_subprice =
price($line->subprice, 0, $outlangs, 1, -1, -1,
'auto');
2907 $price_price_min =
price($prod->price_min, 0, $outlangs, 1, -1, -1,
'auto');
2908 setEventMessages($prod->ref .
' - ' . $prod->label .
' (' . $price_subprice .
' < ' . $price_price_min .
' ' . strtolower($langs->trans(
"MinPrice")) .
')' .
"\n",
null,
'warnings');
2912 } elseif ($line->fk_product) {
2916 $multicurrency_subprice = (float) $line->subprice * $line->multicurrency_subprice / $subprice_multicurrency;
2918 $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);
2921 if (is_numeric($margin_rate) && empty($mark_rate)) {
2922 $line->marge_tx = $margin_rate;
2923 } elseif (is_numeric($mark_rate) && empty($margin_rate)) {
2924 $line->marque_tx = $mark_rate;
2926 $line->total_ht = $line->qty * (float) $line->subprice;
2927 $line->total_tva = $line->tva_tx * $line->qty * (float) $line->subprice;
2928 $line->total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $line->subprice;
2930 $line->multicurrency_total_ht = $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
2931 $line->multicurrency_total_tva = $line->tva_tx * $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
2932 $line->multicurrency_total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
2934 $line->multicurrency_subprice = $multicurrency_subprice;
2939 } elseif ($action ==
'updatetitleline' && GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2942 $langs->load(
'subtotals');
2944 $desc =
GETPOST(
'line_desc',
'alphanohtml') ?? $langs->trans(
"Title");
2947 $subtotal_options = array();
2949 foreach (Facture::$TITLE_OPTIONS as $option) {
2950 $value =
GETPOST($option,
'alphanohtml');
2952 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2957 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
2968 $outputlangs = $langs;
2969 $newlang =
GETPOST(
'lang_id',
'alpha');
2971 $newlang =
$object->thirdparty->default_lang;
2973 if (!empty($newlang)) {
2975 $outputlangs->setDefaultLang($newlang);
2978 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2983 } elseif ($action ==
'updatesubtotalline' && GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2986 $langs->load(
'subtotals');
2988 $desc =
GETPOST(
'line_desc',
'alphanohtml');
2991 $subtotal_options = array();
2993 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
2994 $value =
GETPOST($option,
'alphanohtml');
2996 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
3001 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3009 $outputlangs = $langs;
3010 $newlang =
GETPOST(
'lang_id',
'alpha');
3012 $newlang =
$object->thirdparty->default_lang;
3014 if (!empty($newlang)) {
3016 $outputlangs->setDefaultLang($newlang);
3019 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3024 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3025 if (!
$object->fetch($id) > 0) {
3048 if (preg_match(
'/\*/', $vat_rate)) {
3053 $vat_rate = str_replace(
'*',
'', $vat_rate);
3058 $fournprice = (int) (
GETPOST(
'fournprice') ?
GETPOST(
'fournprice') :
'');
3062 $pu_equivalent = $pu_ht;
3063 $pu_equivalent_ttc = $pu_ttc;
3065 $currency_tx =
$object->multicurrency_tx;
3072 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
3073 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
3075 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
3076 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
3091 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
3092 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
3094 if (is_array($extralabelsline)) {
3096 foreach ($extralabelsline as $key => $value) {
3097 unset($_POST[
"options_".$key]);
3103 if ($special_code == 3) {
3109 $percent = $line->get_prev_progress(
$object->id);
3114 if ($progress >= 0) {
3115 $mesg = $langs->trans(
"CantBeNullOrPositive");
3119 } elseif ($progress < $line->situation_percent) {
3120 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
3124 } elseif ($progress < $percent) {
3125 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
3134 $price_base_type =
'HT';
3136 if (empty($pu) && !empty($pu_ttc)) {
3138 $price_base_type =
'TTC';
3143 if (!empty($productid)) {
3145 $product->fetch($productid);
3147 $type = $product->type;
3149 $price_min = $product->price_min;
3151 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
3153 $price_min_ttc = $product->price_min_ttc;
3155 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
3162 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
3163 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3166 $action =
'editline';
3167 } 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') {
3168 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3171 $action =
'editline';
3176 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
3180 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
3185 $langs->load(
"errors");
3186 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
3190 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
3191 $langs->load(
"errors");
3192 if (
$object->type == $object::TYPE_DEPOSIT) {
3194 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
3196 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
3200 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
3207 $previousprogress = $line->getAllPrevProgress($line->fk_facture);
3210 if ($fullprogress < $previousprogress) {
3212 setEventMessages($langs->trans(
'CantBeLessThanMinPercent'),
null,
'errors');
3216 if ($fullprogress > 100) {
3217 $fullprogress = 100;
3219 $addprogress = $fullprogress - $previousprogress;
3226 if (empty($usercancreatemargin)) {
3227 foreach (
$object->lines as &$line) {
3229 $fournprice = $line->fk_fournprice;
3230 $buyingprice = $line->pa_ht;
3236 $result =
$object->updateline(
3241 (
float) $remise_percent,
3259 (
float) $pu_ht_devise
3265 $outputlangs = $langs;
3268 $newlang =
GETPOST(
'lang_id',
'aZ09');
3271 $newlang =
$object->thirdparty->default_lang;
3273 if (!empty($newlang)) {
3275 $outputlangs->setDefaultLang($newlang);
3276 $outputlangs->load(
'products');
3280 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3283 unset($_POST[
'qty']);
3284 unset($_POST[
'type']);
3285 unset($_POST[
'productid']);
3286 unset($_POST[
'remise_percent']);
3287 unset($_POST[
'price_ht']);
3288 unset($_POST[
'multicurrency_price_ht']);
3289 unset($_POST[
'price_ttc']);
3290 unset($_POST[
'tva_tx']);
3291 unset($_POST[
'product_ref']);
3292 unset($_POST[
'product_label']);
3293 unset($_POST[
'product_desc']);
3294 unset($_POST[
'fournprice']);
3295 unset($_POST[
'buying_price']);
3296 unset($_POST[
'np_marginRate']);
3297 unset($_POST[
'np_markRate']);
3298 unset($_POST[
'dp_desc']);
3299 unset($_POST[
'idprod']);
3300 unset($_POST[
'units']);
3301 unset($_POST[
'date_starthour']);
3302 unset($_POST[
'date_startmin']);
3303 unset($_POST[
'date_startsec']);
3304 unset($_POST[
'date_startday']);
3305 unset($_POST[
'date_startmonth']);
3306 unset($_POST[
'date_startyear']);
3307 unset($_POST[
'date_endhour']);
3308 unset($_POST[
'date_endmin']);
3309 unset($_POST[
'date_endsec']);
3310 unset($_POST[
'date_endday']);
3311 unset($_POST[
'date_endmonth']);
3312 unset($_POST[
'date_endyear']);
3313 unset($_POST[
'situations']);
3314 unset($_POST[
'progress']);
3319 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modify')) {
3320 if (!
$object->fetch($id) > 0) {
3323 if (
GETPOST(
'all_progress') !=
"") {
3325 foreach (
$object->lines as $line) {
3327 $percent = $line->getAllPrevProgress(
$object->id);
3329 $percent = $line->get_prev_progress(
$object->id);
3331 if ((
float) $all_progress < (
float) $percent) {
3332 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
3341 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
3342 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
3344 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
3346 $object->fetch($id,
'',
'', 0,
true);
3349 &&
$object->isSituationInvoice()
3352 &&
$object->is_last_in_cycle()
3353 && $usercanunvalidate
3356 $newCycle =
$object->newCycle();
3357 if ($newCycle > 1) {
3359 $lastCycle =
$object->situation_cycle_ref;
3360 $lastSituationCounter =
$object->situation_counter;
3361 $linkedCreditNotesList = array();
3363 if (count(
$object->tab_next_situation_invoice) > 0) {
3364 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
3366 && $next_invoice->situation_counter ==
$object->situation_counter
3367 && $next_invoice->fk_facture_source ==
$object->id
3369 $linkedCreditNotesList[] = $next_invoice->id;
3374 $object->situation_cycle_ref = $newCycle;
3375 $object->situation_counter = 1;
3377 if (
$object->update($user) > 0) {
3379 if (count($linkedCreditNotesList) > 0) {
3381 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
3382 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
3383 $sql .=
' , situation_final=0';
3384 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
3385 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
3387 $resql = $db->query($sql);
3393 foreach (
$object->lines as $line) {
3395 if ($line->product_type == 9) {
3400 if (!empty(
$object->tab_previous_situation_invoice)) {
3402 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
3403 $searchPreviousInvoice =
true;
3404 while ($searchPreviousInvoice) {
3405 if (
$object->tab_previous_situation_invoice[$lineIndex]->isSituationInvoice() || $lineIndex < 1) {
3406 $searchPreviousInvoice =
false;
3414 $maxPrevSituationPercent = 0;
3415 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
3416 if ($prevLine->id == $line->fk_prev_id) {
3417 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
3422 $line->situation_percent -= $maxPrevSituationPercent;
3424 if ($line->update() < 0) {
3433 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
3435 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
3438 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
3441 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
3447 $fromElement =
GETPOST(
'fromelement');
3448 $fromElementid =
GETPOST(
'fromelementid');
3449 $importLines =
GETPOST(
'line_checkbox');
3451 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
3452 $lineClassName =
'';
3453 if ($fromElement ==
'commande') {
3455 $lineClassName =
'OrderLine';
3456 } elseif ($fromElement ==
'propal') {
3457 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
3458 $lineClassName =
'PropaleLigne';
3460 $nextRang = count(
$object->lines) + 1;
3463 foreach ($importLines as $lineId) {
3464 if ($lineClassName ===
'') {
3468 dol_syslog(
'compta/facture/card - No lineClassName - skip import', LOG_ERR);
3475 $lineId = intval($lineId);
3476 $originLine =
new $lineClassName($db);
3477 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
3478 $originLine->fetch_optionals();
3479 $desc = $originLine->desc;
3480 $pu_ht = $originLine->subprice;
3481 $qty = $originLine->qty;
3482 $txtva = $originLine->tva_tx;
3483 $txlocaltax1 = $originLine->localtax1_tx;
3484 $txlocaltax2 = $originLine->localtax2_tx;
3485 $fk_product = $originLine->fk_product;
3486 $remise_percent = $originLine->remise_percent;
3487 $date_start = $originLine->date_start;
3488 $date_end = $originLine->date_end;
3489 $fk_code_ventilation = 0;
3490 $info_bits = $originLine->info_bits;
3491 $fk_remise_except = $originLine->fk_remise_except;
3492 $price_base_type =
'HT';
3494 $type = $originLine->product_type;
3495 $rang = $nextRang++;
3496 $special_code = $originLine->special_code;
3497 $origin = $originLine->element;
3498 $origin_id = $originLine->id;
3499 $fk_parent_line = 0;
3500 $fk_fournprice = $originLine->fk_fournprice;
3501 $pa_ht = $originLine->pa_ht;
3502 $label = $originLine->label;
3503 $array_options = $originLine->array_options;
3504 if (
$object->isSituationInvoice()) {
3505 $situation_percent = 0;
3507 $situation_percent = 100;
3510 $fk_unit = $originLine->fk_unit;
3511 $pu_ht_devise = $originLine->multicurrency_subprice;
3513 $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);
3533 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3539 if (!empty(
$object->id) && $action ==
'send') {
3541 $object->getSommePaiement(-1);
3542 $object->getSumCreditNotesUsed(-1);
3543 $object->getSumDepositsUsed(-1);
3545 $triggersendname =
'BILL_SENTBYMAIL';
3547 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3548 $trackid =
'inv'.$object->id;
3549 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3553 $permissiontoadd = $usercancreate;
3554 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3557 if ($action ==
'update_extras' && $permissiontoeditextra) {
3560 $attribute_name =
GETPOST(
'attribute',
'aZ09');
3563 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute_name);
3570 $result =
$object->updateExtraField($attribute_name,
'BILL_MODIFY');
3578 $action =
'edit_extras';
3583 if ($action ==
'addcontact' && $usercancreate) {
3584 $result =
$object->fetch($id);
3586 if ($result > 0 && $id > 0) {
3589 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3593 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3596 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3597 $langs->load(
"errors");
3598 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3603 } elseif ($action ==
'swapstatut' && $usercancreate) {
3610 } elseif ($action ==
'deletecontact' && $usercancreate) {
3613 $result =
$object->delete_contact($lineid);
3616 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3624 $action =
'edit_extras';
3634$form =
new Form($db);
3640$bankaccountstatic =
new Account($db);
3642if (isModEnabled(
'project')) {
3648$title =
$object->ref.
" - ".$langs->trans(
'Card');
3649if ($action ==
'create') {
3650 $title = $langs->trans(
"NewBill");
3652$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3658if ($action ==
'create') {
3659 $facturestatic =
new Facture($db);
3660 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3665 $res = $soc->fetch($socid);
3668 $currency_code =
$conf->currency;
3670 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3671 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3677 if (!empty($origin) && !empty($originid)) {
3679 $element = $subelement = $origin;
3681 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3682 $element = $regs[1];
3683 $subelement = $regs[2];
3689 if ($element ==
'project') {
3690 $projectid = $originid;
3692 if (empty($cond_reglement_id)) {
3693 $cond_reglement_id = $soc->cond_reglement_id;
3695 if (empty($mode_reglement_id)) {
3696 $mode_reglement_id = $soc->mode_reglement_id;
3698 if (empty($fk_account)) {
3699 $fk_account = $soc->fk_account;
3701 if (empty($dateinvoice)) {
3707 if ($element ==
'order' || $element ==
'commande') {
3708 $element = $subelement =
'commande';
3710 if ($element ==
'propal') {
3711 $element =
'comm/propal';
3712 $subelement =
'propal';
3714 if ($element ==
'contract') {
3715 $element = $subelement =
'contrat';
3717 if ($element ==
'shipping') {
3718 $element = $subelement =
'expedition';
3723 $classname = ucfirst($subelement);
3724 $objectsrc =
new $classname($db);
3725 '@phan-var-force Commande|Propal|Contrat|Expedition $objectsrc';
3726 $objectsrc->fetch($originid);
3727 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3728 $objectsrc->fetch_lines();
3730 $objectsrc->fetch_thirdparty();
3732 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3738 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3742 if (empty($socid)) {
3743 $soc = $objectsrc->thirdparty;
3746 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3748 if ($element ==
'expedition') {
3749 $elem = $subelem = $objectsrc->origin;
3750 $expeoriginid = $objectsrc->origin_id;
3752 $classname = ucfirst($subelem);
3754 $expesrc =
new $classname($db);
3755 '@phan-var-force Expedition $expesrc';
3756 dol_syslog(
"Is type Facture|Commande or Expedition: $element...expesrc($classname)=".get_class($expesrc));
3757 $expesrc->fetch($expeoriginid);
3759 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3760 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3761 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3763 if (isModEnabled(
'multicurrency')) {
3764 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3765 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3769 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3772 $expesrc->fetch_optionals();
3773 $object->array_options = $expesrc->array_options;
3775 $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)));
3776 $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)));
3777 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : (!empty($fk_account) ? $fk_account : 0)));
3779 if (isModEnabled(
'multicurrency')) {
3780 if (!empty($objectsrc->multicurrency_code)) {
3781 $currency_code = $objectsrc->multicurrency_code;
3783 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
3784 $currency_tx = $objectsrc->multicurrency_tx;
3789 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3792 $objectsrc->fetch_optionals();
3793 $object->array_options = $objectsrc->array_options;
3797 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
3798 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
3799 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
3800 $inputReasonId = empty($soc->demand_reason_id) ? $inputReasonId : $soc->demand_reason_id;
3802 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3804 if (isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3805 $currency_code = $soc->multicurrency_code;
3810 if (!
GETPOST(
'changecompany')) {
3811 if (GETPOSTISSET(
'cond_reglement_id')) {
3812 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3814 if (GETPOSTISSET(
'mode_reglement_id')) {
3815 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3817 if (GETPOSTISSET(
'cond_reglement_id')) {
3823 if (empty($cond_reglement_id)) {
3824 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
3828 if (empty($mode_reglement_id)) {
3829 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
3839 if (!empty($soc->id)) {
3840 $absolute_discount = $soc->getAvailableDiscounts();
3842 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
3843 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
3845 if (!empty(
$conf->use_javascript_ajax)) {
3846 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3852 if ($origin ==
'contrat') {
3853 $langs->load(
"admin");
3854 $text = $langs->trans(
"ToCreateARecurringInvoice");
3855 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3857 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3859 print
info_admin($text, 0, 0,
'info',
'').
'<br>';
3862 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3863 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3864 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3865 print
'<input type="hidden" name="changecompany" value="0">';
3867 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3869 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3870 print
'<input name="ref" type="hidden" value="provisoire">';
3871 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3872 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3873 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3874 print
'<input name="force_fk_account" type="hidden" value="0">';
3875 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3876 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3877 print
'<input type="hidden" name="originentity" value="'.GETPOSTINT(
'originentity').
'">';
3878 if (!empty($currency_tx)) {
3879 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3885 $parameters = array();
3887 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters,
$object, $action);
3888 if (empty($reshook)) {
3889 print
'<table class="border centpercent">';
3891 $exampletemplateinvoice =
new FactureRec($db);
3893 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3894 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
3898 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
3900 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
'Customer').
'</td>';
3901 print
'<td colspan="2">';
3902 print $soc->getNomUrl(1,
'customer');
3903 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3905 $arrayoutstandingbills = $soc->getOutstandingBills();
3906 $outstandingBills = $arrayoutstandingbills[
'opened'];
3907 print
' - <span class="opacitymedium valignmiddle">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3908 print
'<span class="amount valignmiddle">'.price($outstandingBills, 0, $langs, 0, 0, -1,
$conf->currency).
'</span>';
3909 if ($soc->outstanding_limit !=
'') {
3910 if ($outstandingBills > $soc->outstanding_limit) {
3911 print
img_warning($langs->trans(
"OutstandingBillReached"));
3913 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1,
$conf->currency);
3918 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3919 print
'<td colspan="2">';
3920 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
3921 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3925 $(document).ready(function() {
3926 $("#socid").change(function() {
3928 console.log("Submit page");
3929 $(\'input[name="action"]\').val(\'create\');
3930 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3931 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3932 $(\'input[name="force_fk_account"]\').val(\'1\');
3933 $("#formtocreate").submit(); */
3935 // For company change, we must submit page with action=create instead of action=add
3936 console.log("We have changed the company - Resubmit page");
3937 jQuery("input[name=changecompany]").val("1");
3938 jQuery("#formtocreateaction").val("create");
3939 jQuery("#formtocreate").submit();
3945 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>';
3952 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3954 foreach ($invoice_predefined->array_options as $key => $option) {
3955 if (!isset(
$object->array_options[$key])) {
3956 $object->array_options[$key] = $invoice_predefined->array_options[$key];
3960 $dateinvoice = $invoice_predefined->date_when;
3961 if (empty($projectid)) {
3962 $projectid = $invoice_predefined->fk_project;
3964 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
3965 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
3966 $fk_account = $invoice_predefined->fk_account;
3967 $note_public = $invoice_predefined->note_public;
3968 $note_private = $invoice_predefined->note_private;
3970 if (!empty($invoice_predefined->multicurrency_code)) {
3971 $currency_code = $invoice_predefined->multicurrency_code;
3973 if (!empty($invoice_predefined->multicurrency_tx)) {
3974 $currency_tx = $invoice_predefined->multicurrency_tx;
3977 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
3978 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
3979 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
3981 $resql = $db->query($sql);
3983 $num = $db->num_rows($resql);
3987 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
3989 print
'<select class="flat" id="fac_rec" name="fac_rec">';
3990 print
'<option value="0" selected></option>';
3992 $objp = $db->fetch_object($resql);
3993 print
'<option value="'.$objp->rowid.
'"';
3996 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
3998 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
4007 print
'<script type="text/javascript">
4008 $(document).ready(function() {
4009 $("#fac_rec").change(function() {
4010 console.log("We have changed the template invoice - Reload page");
4011 var fac_rec = $(this).val();
4012 var socid = $(\'#socid\').val();
4013 // 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.
4014 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
4027 print
'<tr><td class="tdtop fieldrequired titlefieldcreate">'.$langs->trans(
'Type').
'</td><td colspan="2">';
4028 print
'<div class="listofinvoicetypetable">'.
"\n";
4031 print
'<div class="listofinvoicetype"><div class="">';
4032 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
4033 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
4035 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'nowraponall', 0, 3,
'standardonsmartphone');
4037 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
4047 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%') .
'"/>';
4050 print
'</div></div>'.
"\n";
4052 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
4055 print
'<div class="listofinvoicetype"><div class="">';
4056 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
4057 print
'<script type="text/javascript">
4058 jQuery(document).ready(function() {
4059 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
4060 jQuery("#radio_standard").prop("checked", true);
4062 jQuery("#typedeposit, #valuedeposit").click(function() {
4063 jQuery("#radio_deposit").prop("checked", true);
4065 jQuery("#typedeposit").change(function() {
4066 console.log("We change type of down payment: "+jQuery("#typedeposit").val());
4068 if (jQuery("#typedeposit").val() == "amount") {
4069 jQuery("#valuedeposit").attr("placeholder", "'.$langs->getCurrencySymbol(
$conf->currency).
'");
4070 jQuery("#valuedeposit").val("");
4072 jQuery("#valuedeposit").attr("placeholder", "50%");
4073 jQuery("#valuedeposit").val("");
4076 jQuery("#radio_deposit").prop("checked", true);
4077 setRadioForTypeOfInvoice();
4079 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
4080 setRadioForTypeOfInvoice();
4083 function setRadioForTypeOfInvoice() {
4084 console.log("Change radio for type of invoice");
4085 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
4086 jQuery("#checkforselects").prop("disabled", true);
4087 jQuery("#checkforselects").prop("checked", false);
4088 jQuery(".checkforselect").prop("disabled", true);
4089 jQuery(".checkforselect").prop("checked", false);
4091 jQuery("#checkforselects").prop("disabled", false);
4092 jQuery("#checkforselects").prop("checked", true);
4093 jQuery(".checkforselect").prop("disabled", false);
4094 jQuery(".checkforselect").prop("checked", true);
4100 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
4102 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
4104 if (($origin ==
'propal') || ($origin ==
'commande')) {
4107 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
4108 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
4109 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4113 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4117 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
4119 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
4120 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
4121 if (!empty($origin_payment_conditions_deposit_percent)) {
4122 $typedeposit =
'variable';
4125 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
4126 $valuedeposit = $objectsrc->deposit_percent;
4128 print
'<span class="marginleftonly">'.$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1).
'</span>';
4130 print
'<input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.($valuedeposit ? $valuedeposit :
'').
'"'.($valuedeposit ?
'' :
'placeholder="'.$langs->getCurrencySymbol(
$conf->currency).
'"').
'>';
4133 print
'</div></div>'.
"\n";
4140 print
'<div class="listofinvoicetype"><div class="">';
4141 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
4142 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
4144 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
4148 $opt = $form->selectSituationInvoices((
string)
GETPOSTINT(
'originid'), $socid);
4151 print
'</div></div><div class="listofinvoicetype"><div>';
4153 $tmp =
'<input id="radio_situation_bis" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
4154 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4155 $tmp .=
' disabled';
4158 $text = $tmp.
'<label for="radio_situation_bis">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4159 $text .=
'<select class="flat minwidth50" id="situations" name="situations"';
4160 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4161 $text .=
' disabled';
4165 $text .=
'</select>';
4166 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
4168 print
'</div></div>'.
"\n";
4174 $facids = $facturestatic->list_replacable_invoices($soc->id);
4180 if (is_array($facids)) {
4181 foreach ($facids as $facparam) {
4182 $options .=
'<option value="'.$facparam [
'id'].
'"';
4183 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
4184 $options .=
' selected';
4186 $options .=
'>'.$facparam[
'ref'];
4187 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
4188 $options .=
'</option>';
4192 print
'<!-- replacement line -->';
4193 print
'<div class="listofinvoicetype"><div class="">';
4194 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
4195 if (!$options || $invoice_predefined->id > 0) {
4196 $tmp .=
' disabled';
4199 print
'<script type="text/javascript">
4200 jQuery(document).ready(function() {
4201 jQuery("#fac_replacement").change(function() {
4202 console.log("We change fac_replacement");
4203 jQuery("#radio_replacement").prop("checked", true);
4207 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
4208 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
4209 if (!$options || $invoice_predefined->id > 0) {
4210 $text .=
' disabled';
4214 $text .=
'<option value="-1"> </option>';
4217 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
4219 $text .=
'</select>';
4220 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
4222 print
'</div></div>'.
"\n";
4226 print
'<div class="listofinvoicetype"><div class="">';
4227 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
4228 $text = $tmp.
'<label class="opacitymedium">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4229 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'firstsituationonsmartphone');
4231 print
'</div></div>'.
"\n";
4234 print
'<div class="listofinvoicetype"><div class="">';
4235 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
4236 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
4237 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'replacementonsmartphone');
4239 print
'</div></div>'.
"\n";
4242 if (empty($origin)) {
4247 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
4253 $newinvoice_static =
new Facture($db);
4254 foreach ($facids as $key => $valarray) {
4255 $newinvoice_static->id = $key;
4256 $newinvoice_static->ref = $valarray [
'ref'];
4257 $newinvoice_static->statut = $valarray [
'status'];
4258 $newinvoice_static->status = $valarray [
'status'];
4259 $newinvoice_static->type = $valarray [
'type'];
4260 $newinvoice_static->paye = $valarray [
'paye'];
4261 $newinvoice_static->paid = $valarray [
'paye'];
4263 $optionsav .=
'<option value="'.$key.
'"';
4264 if ($key ==
GETPOST(
'fac_avoir')) {
4265 $optionsav .=
' selected';
4268 $newinvoice_static->fetch_optionals($key);
4269 $object->array_options = $newinvoice_static->array_options;
4272 $optionsav .= $newinvoice_static->ref;
4273 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
4274 $optionsav .=
'</option>';
4277 print
'<div class="listofinvoicetype"><div class="">';
4278 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
4279 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
4280 $tmp .=
' disabled';
4284 print
'<script type="text/javascript">
4285 jQuery(document).ready(function() {
4286 if (jQuery("#radio_creditnote").is(":checked"))
4288 jQuery("#radio_standard").prop("disabled", true);
4290 jQuery("#radio_standard").prop("disabled", false);
4292 if (! jQuery("#radio_creditnote").is(":checked"))
4294 jQuery("#credit_note_options").hide();
4296 jQuery("#radio_creditnote").click(function() {
4298 jQuery("#credit_note_options").show();
4300 jQuery("#radio_standard, #radio_replacement, #radio_deposit, #radio_situation, #radio_situation_bis").click(function() {
4301 console.log("We click on a radio to close credit not options");
4302 jQuery("#credit_note_options").hide();
4306 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
4307 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
4308 if (!$optionsav || $invoice_predefined->id > 0) {
4309 $text .=
' disabled';
4313 $text .=
'<option value="-1">'.$langs->trans(
"InvoiceAvoirAskCombo").
'</option>';
4314 $text .= $optionsav;
4316 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
4318 $text .=
'</select>';
4319 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
4322 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
4323 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>";
4325 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>";
4328 print
'</div></div>'.
"\n";
4331 print
'<div class="listofinvoicetype"><div class="">';
4333 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
4335 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
4337 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
4339 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
4341 print
'</div></div>'.
"\n";
4346 print
'<div class="listofinvoicetype"><div class="">';
4347 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
4348 $text = $tmp.
'<label class="opacitymedium" for="radio_template">'.$langs->trans(
"RepeatableInvoice").
'</label> ';
4349 $desc = $form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3,
'templateonsmartphone');
4351 print
'</div></div>'.
"\n";
4360 foreach ($listtType as $type) {
4361 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
4363 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
4366 print
'<script type="text/javascript">
4367 $(document).ready(function() {
4368 var listType = {'.$jsListType.
'};
4369 $("[name=\'type\'").change(function() {
4370 console.log("change name=type");
4371 if ($( this ).prop("checked"))
4373 if(($( this ).val() in listType))
4375 $("#model").val(listType[$( this ).val()]);
4392 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
4393 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
4399 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
4403 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
4404 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
4413 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
4414 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4415 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
4420 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
4421 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4422 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
4427 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
4428 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
4429 print $form->getSelectConditionsPaiements((
int) $cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
4434 $rwStyle =
'display:none;';
4435 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
4439 $retained_warranty =
GETPOSTINT(
'retained_warranty');
4440 if (empty($retained_warranty)) {
4441 if ($objectsrc !==
null && property_exists($objectsrc,
'retained_warranty') && !empty($objectsrc->retained_warranty)) {
4443 $retained_warranty = $objectsrc->retained_warranty;
4446 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
4448 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
4449 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
4452 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
4453 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
4454 if (empty($retained_warranty_fk_cond_reglement)) {
4455 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4456 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
4457 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
4459 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4462 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4465 print
'<script type="text/javascript">
4466 $(document).ready(function() {
4467 $("[name=\'type\']").change(function() {
4468 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
4470 $(".retained-warranty-line").show();
4471 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
4474 $(".retained-warranty-line").hide();
4475 $("#new-situation-invoice-retained-warranty").val("");
4479 $("[name=\'type\']:checked").trigger("change");
4485 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
4486 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
4487 print $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth250 widthcentpercentminusx', 1);
4491 if (isModEnabled(
"bank")) {
4492 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td colspan="2">';
4493 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4494 print $form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth250 widthcentpercentminusx', 1);
4500 print
'<tr><td>'.$langs->trans(
'Source').
'</td><td>';
4501 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
4502 $form->selectInputReason((
string) $inputReasonId,
'input_reason_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
4506 if (isModEnabled(
'project') && is_object($formproject)) {
4507 $langs->load(
'projects');
4508 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
4509 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
4511 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');
4512 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>';
4517 if (isModEnabled(
'incoterm')) {
4519 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
4520 print
'<td colspan="2" class="maxwidthonsmartphone">';
4521 $incoterm_id =
GETPOST(
'incoterm_id');
4522 $location_incoterms =
GETPOST(
'location_incoterms');
4523 if (empty($incoterm_id)) {
4524 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
4525 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
4527 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
4528 print $form->select_incoterms($incoterm_id, $location_incoterms);
4533 if (isModEnabled(
'category')) {
4535 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
4536 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories',
$object);
4541 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
4542 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
4543 print $hookmanager->resPrint;
4544 if (empty($reshook)) {
4545 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
4548 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
4549 if ($soc->fetch_optionals() > 0) {
4550 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
4554 print
$object->showOptionals($extrafields,
'create', $parameters);
4558 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
4559 print
'<td colspan="2">';
4560 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
4561 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
4566 $paramkey =
'FACTURE_ADDON_PDF_'.$type;
4571 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
4575 if (isModEnabled(
'multicurrency')) {
4577 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0).
'</td>';
4578 print
'<td colspan="2" class="maxwidthonsmartphone">';
4579 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
4580 print $form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth200 widthcentpercentminusx');
4587 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
4588 if (empty($dateexample)) {
4591 $substitutionarray = array(
4592 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
4593 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
4594 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
4595 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
4596 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
4597 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
4598 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
4599 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
4600 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
4601 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
4602 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
4605 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
4606 foreach ($substitutionarray as $key => $val) {
4607 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
4609 $htmltext .=
'</i>';
4614 print
'<td class="tdtop">';
4615 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
4617 print
'<td valign="top" colspan="2">';
4618 $doleditor =
new DolEditor(
'note_public', (
string) $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
4619 print $doleditor->Create(1);
4622 if (empty($user->socid)) {
4624 print
'<td class="tdtop">';
4625 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4627 print
'<td valign="top" colspan="2">';
4628 $doleditor =
new DolEditor(
'note_private', (
string) $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4629 print $doleditor->Create(1);
4635 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4636 $langs->loadLangs(array(
'orders',
'propal'));
4639 if ($origin ==
'contrat') {
4640 '@phan-var-force Contrat $objectsrc';
4642 $objectsrc->update_price(1,
'auto', 1);
4645 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4646 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4647 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4648 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4653 switch (get_class($objectsrc)) {
4655 $newclassname =
'CommercialProposal';
4658 $newclassname =
'Order';
4661 $newclassname =
'Sending';
4664 $newclassname =
'Contract';
4667 $newclassname =
'Intervention';
4670 $newclassname = get_class($objectsrc);
4674 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4675 print
'<td colspan="2">';
4676 print $objectsrc->getNomUrl(1);
4678 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
4679 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4681 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4685 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht, 1, $langs, 1, -1,
'',
$conf->currency).
'</td></tr>';
4686 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
4687 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4688 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>";
4691 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4692 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>";
4694 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
4696 if (isModEnabled(
'multicurrency') && $objectsrc->multicurrency_code !=
$conf->currency) {
4698 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
'</td></tr>';
4699 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4700 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4708 print $form->buttonsSaveCancel(
"CreateDraft");
4711 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4714 $title = $langs->trans(
'ProductsAndServices');
4717 print
'<div class="div-table-responsive-no-min">';
4718 print
'<table class="noborder centpercent">';
4720 $objectsrc->printOriginLinesList(
'', $selectedLines);
4727} elseif ($id > 0 || !empty($ref)) {
4729 $langs->load(
'errors');
4730 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4739 if ($user->socid > 0 && $user->socid !=
$object->socid) {
4743 $result =
$object->fetch_thirdparty();
4745 $result = $soc->fetch(
$object->socid);
4749 $selleruserevenustamp = $mysoc->useRevenueStamp();
4751 $totalpaid =
$object->getSommePaiement();
4752 $totalcreditnotes =
$object->getSumCreditNotesUsed();
4753 $totaldeposits =
$object->getSumDepositsUsed();
4759 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4762 if (isModEnabled(
'multicurrency')) {
4763 $multicurrency_totalpaid =
$object->getSommePaiement(1);
4764 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
4765 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
4766 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4770 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
4771 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
4775 if (
$object->paye ||
$object->status == $object::STATUS_CLOSED) {
4778 $resteapayeraffiche = $resteapayer;
4781 $filterabsolutediscount =
"fk_facture_source IS NULL";
4782 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4784 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4785 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4788 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
4789 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
4790 $absolute_discount =
price2num($absolute_discount,
'MT');
4791 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4793 $author =
new User($db);
4794 if (
$object->user_creation_id) {
4795 $author->fetch(
$object->user_creation_id);
4798 $objectidnext =
$object->getIdReplacingInvoice();
4802 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
'bill', 0,
'',
'', 0,
'', 1);
4807 if ($action ==
'converttoreduc') {
4809 $type_fac =
'ExcessReceived';
4811 $type_fac =
'CreditNote';
4813 $type_fac =
'Deposit';
4817 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4818 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4819 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4823 if ($action ==
'delete') {
4824 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
4825 $formquestion = array();
4828 $qualified_for_stock_change = 0;
4830 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4832 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4835 if ($qualified_for_stock_change) {
4836 $langs->load(
"stocks");
4837 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4841 if (
$conf->browser->name ==
'ie') {
4844 $formquestion = array(
4848 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4850 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4852 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4855 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4860 if ($action ==
'situationout') {
4861 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
4862 $label = $langs->trans(
"ConfirmOuting");
4863 $formquestion = array();
4868 &&
$object->is_last_in_cycle()
4869 && $usercanunvalidate
4871 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4876 if ($action ==
'valid') {
4878 $objectref = substr(
$object->ref, 1, 4);
4879 if ($objectref ==
'PROV') {
4883 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
4885 $numref =
$object->getNextNumRef($soc);
4891 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4893 $text .=
'<br><br>';
4894 $text .=
img_picto(
'',
'warning',
'class="pictofixedwidth"').
' '.$langs->trans(
'WarningInvoiceCanNeverBeEdited');
4896 if (isModEnabled(
'notification')) {
4897 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4898 $notify =
new Notify($db);
4900 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid,
$object);
4902 $formquestion = array();
4905 $qualified_for_stock_change = 0;
4907 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4909 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4912 if ($qualified_for_stock_change) {
4913 $langs->load(
"stocks");
4914 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4915 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4918 $warehouse_array = $warehouse->list_array();
4919 if (count($warehouse_array) == 1) {
4920 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4921 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4924 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4926 $formquestion = array(
4932 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4936 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
4941 foreach (
$object->lines as $line) {
4942 $res = $line->fetch_product();
4944 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
4950 if ($nbMandated > 0) {
4952 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
4955 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
4960 $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);
4965 if ($action ==
'modif') {
4966 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
4967 $formquestion = array();
4970 $qualified_for_stock_change = 0;
4972 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4974 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4977 if ($qualified_for_stock_change) {
4978 $langs->load(
"stocks");
4979 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4980 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4983 $warehouse_array = $warehouse->list_array();
4984 if (count($warehouse_array) == 1) {
4985 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
4986 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4989 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4991 $formquestion = array(
4997 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5001 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
5005 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
5006 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
5008 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
5012 $close[$i][
'code'] = $object::CLOSECODE_DISCOUNTVAT;
5014 $close[$i][
'code'] = $object::CLOSECODE_BADDEBT;
5016 $close[$i][
'code'] = $object::CLOSECODE_BANKCHARGE;
5018 $close[$i][
'code'] = $object::CLOSECODE_WITHHOLDINGTAX;
5020 $close[$i][
'code'] = $object::CLOSECODE_OTHER;
5024 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
5026 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5028 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
5030 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
5032 $close[$i][
'label'] = $langs->trans(
"Other");
5036 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5038 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5040 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5042 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
5044 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
5048 foreach ($close as $key => $val) {
5049 $arrayreasons[$close[$key][
'code']] =
'<span class="small">'.$close[$key][
'reason'].
'</span>';
5053 $formquestion = array(
5054 'text' => $langs->trans(
"ConfirmClassifyPaidPartiallyQuestion"),
5055 0 => array(
'type' =>
'radio',
'name' =>
'close_code',
'label' =>
'',
'values' => $arrayreasons),
5056 1 => array(
'type' =>
'text',
'name' =>
'close_note',
'moreattr' =>
'placeholder = "'.$langs->trans(
"Comment").
'"',
'value' =>
'',
'morecss' =>
'minwidth300'),
5057 2 => array(
'type' =>
'separator')
5060 $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);
5064 if ($action ==
'canceled') {
5068 $statusreplacement = 0;
5070 if ($objectidnext) {
5071 $facturereplacement =
new Facture($db);
5072 $facturereplacement->fetch($objectidnext);
5073 $statusreplacement = $facturereplacement->status;
5075 if ($objectidnext && $statusreplacement == 0) {
5076 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
5079 $close[1][
'code'] =
'badcustomer';
5080 $close[2][
'code'] =
'abandon';
5082 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5083 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
5085 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
5086 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
5089 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
5090 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
5093 $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'));
5095 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 270);
5099 if ($action ==
'deletepayment') {
5100 $payment_id =
GETPOST(
'paiement_id');
5101 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
5105 if ($action ==
'ask_deleteline') {
5106 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
5110 if ($action ==
'ask_subtotal_deleteline') {
5111 $langs->load(
"subtotals");
5112 $title =
"DeleteSubtotalLine";
5113 $question =
"ConfirmDeleteSubtotalLine";
5114 if (
GETPOST(
'type') ==
'title') {
5115 $formconfirm = array(array(
'type' =>
'checkbox',
'name' =>
'deletecorrespondingsubtotalline',
'label' => $langs->trans(
"DeleteCorrespondingSubtotalLine"),
'value' => 0));
5116 $title =
"DeleteTitleLine";
5117 $question =
"ConfirmDeleteTitleLine";
5119 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans($title), $langs->trans($question),
'confirm_delete_subtotalline', $formconfirm,
'no', 1);
5123 if ($action ==
'clone') {
5124 $filter =
'(s.client:IN:1,2,3)';
5126 $formquestion = array(
5127 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
$object->socid,
'socid', $filter, 1)),
5128 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
5131 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
5135 if ($action ==
'add_title_line') {
5136 $langs->load(
'subtotals');
5138 $depth_array =
$object->getPossibleLevels($langs);
5140 } elseif ($action ==
'add_subtotal_line') {
5141 $langs->load(
'subtotals');
5143 $titles =
$object->getPossibleTitles();
5147 if ($action ==
"remove_file_comfirm") {
5148 $file =
GETPOST(
'file',
'alpha');
5150 $formconfirm = $form->formconfirm(
5151 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
5152 $langs->trans(
'DeleteFileHeader'),
5153 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
5162 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
5163 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
5164 if (empty($reshook)) {
5165 $formconfirm .= $hookmanager->resPrint;
5166 } elseif ($reshook > 0) {
5167 $formconfirm = $hookmanager->resPrint;
5175 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
5177 $morehtmlref =
'<div class="refidno">';
5180 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref',
$object->ref,
$object, (
int) $usercancreate,
'string',
'', 0, 1);
5181 $morehtmlref .= $form->editfieldval(
"Ref",
'ref',
$object->ref,
$object, (
int) $usercancreate,
'string',
'',
null,
null,
'', 1);
5182 $morehtmlref .=
'<br>';
5185 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer,
$object, (
int) $usercancreate,
'string',
'', 0, 1);
5186 $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);
5188 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
5190 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'">'.$langs->trans(
"OtherBills").
'</a>)';
5193 if (isModEnabled(
'project')) {
5194 $langs->load(
"projects");
5195 $morehtmlref .=
'<br>';
5196 if ($usercancreate) {
5197 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
5198 if ($action !=
'classify') {
5199 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
5201 $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');
5203 if (!empty(
$object->fk_project)) {
5205 $proj->fetch(
$object->fk_project);
5206 $morehtmlref .= $proj->getNomUrl(1);
5208 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
5213 $morehtmlref .=
'</div>';
5215 $object->totalpaid = $totalpaid;
5216 $object->totalcreditnotes = $totalcreditnotes;
5217 $object->totaldeposits = $totaldeposits;
5220 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
5223 $parameters = array();
5225 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters,
$object, $action);
5226 if (empty($reshook)) {
5227 print
'<div class="fichecenter">';
5228 print
'<div class="fichehalfleft">';
5229 print
'<div class="underbanner clearboth"></div>';
5231 print
'<table class="border centpercent tableforfield">';
5234 print
'<tr><td class="fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
5237 print
' '.$object->getSubtypeLabel(
'facture');
5240 $facreplaced =
new Facture($db);
5241 $facreplaced->fetch(
$object->fk_facture_source);
5242 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
5246 $facusing->fetch(
$object->fk_facture_source);
5247 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
5251 $object->getListIdAvoirFromInvoice();
5253 if (!empty(
$object->creditnote_ids)) {
5254 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
5256 foreach (
$object->creditnote_ids as $invoiceid) {
5262 $creditnote =
new Facture($db);
5263 $creditnote->fetch($invoiceid);
5264 print $creditnote->getNomUrl(1,
'', 32);
5268 if ($objectidnext > 0) {
5269 $facthatreplace =
new Facture($db);
5270 $facthatreplace->fetch($objectidnext);
5271 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
5276 $result = $discount->fetch(0,
$object->id);
5278 print
' <span class="opacitymediumbycolor paddingleft">';
5279 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
5280 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
5281 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
5283 print
'</span><br>';
5287 if (
$object->fk_fac_rec_source > 0) {
5289 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
5291 print
' <span class="opacitymediumbycolor paddingleft">';
5292 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
5293 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
5297 print
' <span class="opacitymediumbycolor paddingleft">';
5298 print $langs->transnoentities(
"GeneratedFromTemplate", $langs->trans(
"ObjectDeleted"));
5306 $langs->load(
"cashdesk");
5307 print
'<tr><td class="fieldname_type">';
5308 print
'<table class="nobordernopadding centpercent"><tr><td>';
5309 print $form->textwithpicto($langs->trans(
'PointOfSale'), $langs->trans(
'POSInfo'));
5311 if ($action !=
'editposinfo' && $usercancreate) {
5312 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>';
5314 print
'</tr></table>';
5315 print
'</td><td class="valuefield fieldname_type">';
5316 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" name="formposinfo">';
5317 print
'<input type="hidden" name="action" value="setposinfo">';
5318 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5319 if ($action ==
'editposinfo') {
5320 print
'<input type="text" class="maxwidth150" name="posmodule" placeholder="'.$langs->trans(
"POSModule").
'" value="'.
$object->module_source.
'"> ';
5321 print
'<input type="text" class="maxwidth100" name="posterminal" placeholder="'.$langs->trans(
"Terminal").
'" value="'.
$object->pos_source.
'">';
5322 print
'<input type="submit" class="button" name="submitposinfo" value="'.$langs->trans(
"Submit").
'">';
5325 print
'<span class="opacitymediumbycolor paddingleft">'.dolPrintHTML(ucfirst(
$object->module_source).
' - '.$langs->transnoentitiesnoconv(
"Terminal").
' '.
$object->pos_source).
'</span>';
5333 print
'<!-- Discounts -->'.
"\n";
5334 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
5338 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
5339 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
5344 print
'<table class="nobordernopadding centpercent"><tr><td>';
5345 print $langs->trans(
'DateInvoice');
5347 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
5348 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>';
5350 print
'</tr></table>';
5352 if ($action ==
'editinvoicedate') {
5353 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
5355 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
5370 print
'<table class="nobordernopadding centpercent"><tr><td>';
5371 print $langs->trans(
'DatePointOfTax');
5374 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>';
5376 print
'</tr></table>';
5378 if ($action ==
'editdate_pointoftax' && $editable) {
5379 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
5381 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
5388 print $form->editfieldkey(
'Source',
'input_reason',
'',
$object, (
int) $usercancreate);
5389 print
'</td><td class="valuefield">';
5390 if ($action ==
'editinput_reason') {
5391 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'input_reason_id', 1);
5393 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'none');
5399 print
'<table class="nobordernopadding centpercent"><tr><td>';
5400 print $langs->trans(
'PaymentConditionsShort');
5403 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>';
5405 print
'</tr></table>';
5408 if ($action ==
'editconditions') {
5409 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
5411 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
5420 print
'<table class="nobordernopadding centpercent"><tr><td>';
5421 print $langs->trans(
'DateMaxPayment');
5424 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>';
5426 print
'</tr></table>';
5429 if ($action ==
'editpaymentterm') {
5430 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
5432 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
5444 print
'<table class="nobordernopadding centpercent"><tr><td>';
5445 print $langs->trans(
'PaymentMode');
5447 if ($action !=
'editmode' && $usercancreate) {
5448 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>';
5450 print
'</tr></table>';
5452 if ($action ==
'editmode') {
5453 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
5455 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'none',
'CRDT');
5460 if (isModEnabled(
"bank")) {
5461 print
'<tr><td class="nowrap">';
5462 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
5463 print $langs->trans(
'BankAccount');
5465 if (($action !=
'editbankaccount') && $usercancreate) {
5466 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>';
5468 print
'</tr></table>';
5470 if ($action ==
'editbankaccount') {
5471 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
5473 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
5480 if (isModEnabled(
'incoterm')) {
5482 print
'<table class="nobordernopadding centpercent"><tr><td>';
5483 print $langs->trans(
'IncotermLabel');
5484 print
'<td><td class="right">';
5485 if ($usercancreate) {
5486 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
5490 print
'</td></tr></table>';
5493 if ($action !=
'editincoterm') {
5494 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
5496 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
5502 if (isModEnabled(
'category')) {
5504 print
'<table class="nobordernopadding centpercent"><tr><td>';
5505 print $langs->trans(
"Categories");
5506 print
'<td><td class="right">';
5507 if ($usercancreate) {
5508 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
5512 print
'</td></tr></table>';
5515 if ($action ==
'edittags') {
5516 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5517 print
'<input type="hidden" name="action" value="settags">';
5518 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5519 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories',
$object);
5520 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5523 print $form->showCategories(
$object->id, Categorie::TYPE_INVOICE, 1);
5528 $displayWarranty =
false;
5531 $displayWarranty =
true;
5532 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
5533 $displayWarranty =
false;
5536 if ($displayWarranty) {
5538 print
'<tr class="retained-warranty-lines" ><td>';
5539 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
5540 print $langs->trans(
'RetainedWarranty');
5543 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>';
5546 print
'</tr></table>';
5549 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5550 print
'<input type="hidden" name="action" value="setretainedwarranty">';
5551 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5552 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5553 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
5554 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5562 print
'<tr class="retained-warranty-lines" ><td>';
5563 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
5564 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
5566 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
5567 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>';
5570 print
'</tr></table>';
5572 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5573 if (
$object->date > $defaultDate) {
5579 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5580 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
5581 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5582 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5583 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
5584 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
5585 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
5586 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
5587 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5590 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->retained_warranty_fk_cond_reglement,
'none');
5591 if (!$displayWarranty) {
5592 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning.png',
'class="pictowarning valignmiddle" ');
5598 print
'<tr class="retained-warranty-lines" ><td>';
5599 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
5600 print $langs->trans(
'RetainedWarrantyDateLimit');
5603 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>';
5606 print
'</tr></table>';
5608 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5609 if (
$object->date > $defaultDate) {
5615 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5616 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
5617 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5618 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5619 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').
'" >';
5620 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5632 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
5637 print
'<div class="fichehalfright">';
5639 print
'<!-- amounts -->'.
"\n";
5640 print
'<div class="underbanner clearboth"></div>'.
"\n";
5642 print
'<table class="border tableforfield centpercent">';
5644 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
5652 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
5653 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5654 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5656 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5662 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
5663 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5664 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5666 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5671 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
5673 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
5674 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5675 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5678 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5683 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
5685 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
5686 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5687 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5690 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5696 if ($selleruserevenustamp) {
5697 print
'<tr><td class="titlefieldmiddle">';
5698 print
'<table class="nobordernopadding centpercent"><tr><td>';
5699 print $langs->trans(
'RevenueStamp');
5701 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
5702 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>';
5704 print
'</tr></table>';
5705 print
'</td><td class="nowrap amountcard right">';
5706 if ($action ==
'editrevenuestamp') {
5707 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
5708 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5709 print
'<input type="hidden" name="action" value="setrevenuestamp">';
5710 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
5711 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5712 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
5713 print
' → <span id="revenuestamp_span"></span>';
5714 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
5717 $(document).ready(function(){
5718 js_recalculate_revenuestamp();
5719 $('select[name=revenuestamp_type]').on('change',function(){
5720 js_recalculate_revenuestamp();
5723 function js_recalculate_revenuestamp(){
5724 var valselected = $('select[name=revenuestamp_type]').val();
5725 console.log('Calculate revenue stamp from '+valselected);
5727 if (valselected.indexOf('%') == -1)
5729 revenue = valselected;
5733 var revenue_type = parseFloat(valselected);
5734 var amount_net = ".round(
$object->total_ht, 2).
";
5735 revenue = revenue_type * amount_net / 100;
5736 revenue = revenue.toFixed(2);
5738 $('#revenuestamp_val').val(revenue);
5739 $('#revenuestamp_span').html(revenue);
5750 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
5751 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5752 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
5754 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5762 if (isModEnabled(
'project')) {
5765 if (isModEnabled(
"bank")) {
5769 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
5772 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
5775 if ($selleruserevenustamp) {
5778 if (isModEnabled(
'multicurrency')) {
5781 if (isModEnabled(
'incoterm')) {
5785 $total_prev_ht = $total_prev_ttc = 0;
5786 $total_global_ht = $total_global_ttc = 0;
5790 print
'<!-- List of situation invoices -->';
5791 print
'<div class="div-table-responsive-no-min">';
5792 print
'<table class="noborder paymenttable centpercent situationstable">';
5794 print
'<tr class="liste_titre">';
5795 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
5797 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
5799 if (isModEnabled(
"bank")) {
5800 print
'<td class="right"></td>';
5802 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
5803 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
5804 print
'<td width="18"> </td>';
5807 if (count(
$object->tab_previous_situation_invoice) > 0) {
5810 $current_situation_counter = array();
5811 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
5812 $tmptotalallpayments = $prev_invoice->getSommePaiement(0);
5813 $tmptotalallpayments += $prev_invoice->getSumDepositsUsed(0);
5814 $tmptotalallpayments += $prev_invoice->getSumCreditNotesUsed(0);
5816 $total_prev_ht += $prev_invoice->total_ht;
5817 $total_prev_ttc += $prev_invoice->total_ttc;
5819 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
5820 print
'<tr class="oddeven">';
5821 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
5823 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
5824 if (isModEnabled(
"bank")) {
5825 print
'<td class="right"></td>';
5827 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
5828 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
5829 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalallpayments).
'</td>';
5834 $totalallpayments =
$object->getSommePaiement(0);
5835 $totalallpayments +=
$object->getSumCreditNotesUsed(0);
5836 $totalallpayments +=
$object->getSumDepositsUsed(0);
5838 $total_global_ht += $total_prev_ht;
5839 $total_global_ttc += $total_prev_ttc;
5840 $total_global_ht +=
$object->total_ht;
5841 $total_global_ttc +=
$object->total_ttc;
5845 print
'<tr class="oddeven">';
5846 print
'<td>'.$object->getNomUrl(1).
'</td>';
5848 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
5849 if (isModEnabled(
"bank")) {
5850 print
'<td class="right"></td>';
5852 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
5853 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
5854 print
'<td class="right">'.$object->getLibStatut(3, $totalallpayments).
'</td>';
5858 print
'<tr class="oddeven">';
5859 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'CurrentSituationTotal').
'</b></td>';
5862 foreach ($current_situation_counter as $sit) {
5863 $curSign = $sit > 0 ?
'+' :
'-';
5864 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
5866 print
' '.$curSign.
' ';
5868 print $curType.abs($sit);
5872 if (isModEnabled(
"bank")) {
5875 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5876 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5877 print
'<td width="18"> </td>';
5881 if (count(
$object->tab_next_situation_invoice) > 0) {
5893 $total_next_ht = $total_next_ttc = 0;
5895 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
5896 $next_totalpaid = $next_invoice->getSommePaiement(0);
5897 $next_totalcreditnotes = $next_invoice->getSumCreditNotesUsed(0);
5898 $next_totaldeposits = $next_invoice->getSumDepositsUsed(0);
5899 $total_next_ht += $next_invoice->total_ht;
5900 $total_next_ttc += $next_invoice->total_ttc;
5902 print
'<tr class="oddeven">';
5903 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
5905 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
5906 if (isModEnabled(
"bank")) {
5907 print
'<td class="right"></td>';
5909 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
5910 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
5911 print
'<td class="right">'.$next_invoice->getLibStatut(3, $next_totalpaid + $next_totalcreditnotes + $next_totaldeposits).
'</td>';
5915 $total_global_ht += $total_next_ht;
5916 $total_global_ttc += $total_next_ttc;
5918 print
'<tr class="oddeven">';
5919 print
'<td colspan="3" class="right"></td>';
5920 if (isModEnabled(
"bank")) {
5921 print
'<td class="right"></td>';
5923 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5924 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5925 print
'<td width="18"> </td>';
5934 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
5940 print
'<!-- List of payments already done -->';
5941 print
'<div class="div-table-responsive-no-min">';
5942 print
'<table class="noborder paymenttable centpercent">';
5944 print
'<tr class="liste_titre">';
5945 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
5946 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
5947 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
5948 if (isModEnabled(
"bank")) {
5949 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
5951 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
5952 print
'<td class="liste_titre" width="18"> </td>';
5956 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
5957 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
5958 $sql .=
' pf.amount,';
5959 $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';
5960 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
5961 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
5962 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
5963 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
5964 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
5965 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
5966 $sql .=
' ORDER BY p.datep, p.tms';
5968 $result = $db->query($sql);
5970 $num = $db->num_rows($result);
5975 $objp = $db->fetch_object($result);
5977 $paymentstatic->id = $objp->rowid;
5978 $paymentstatic->datepaye = $db->jdate($objp->dp);
5979 $paymentstatic->ref = $objp->ref;
5980 $paymentstatic->num_payment = $objp->num_payment;
5981 $paymentstatic->paiementcode = $objp->payment_code;
5983 print
'<tr class="oddeven"><td class="nowraponall">';
5984 print $paymentstatic->getNomUrl(1);
5987 $dateofpayment = $db->jdate($objp->dp);
5989 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
5996 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
5997 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
5998 if (isModEnabled(
"bank")) {
5999 $bankaccountstatic->id = $objp->baid;
6000 $bankaccountstatic->ref = $objp->baref;
6001 $bankaccountstatic->label = $objp->baref;
6002 $bankaccountstatic->number = $objp->banumber;
6003 $bankaccountstatic->currency_code = $objp->bacurrency_code;
6005 if (isModEnabled(
'accounting')) {
6006 $bankaccountstatic->account_number = $objp->account_number;
6009 $accountingjournal->fetch($objp->fk_accountancy_journal);
6010 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
6013 print
'<td class="nowraponall">';
6014 if ($bankaccountstatic->id) {
6015 print $bankaccountstatic->getNomUrl(1,
'transactions');
6019 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
6020 print
'<td class="center">';
6023 $paiement->fetch($objp->rowid);
6025 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
6042 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6043 print
'<span class="opacitymedium">';
6045 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
6047 print $langs->trans(
'AlreadyPaid');
6049 print
'</span></td><td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td><td> </td></tr>';
6051 $resteapayeraffiche = $resteapayer;
6052 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
6055 $creditnoteamount = 0;
6057 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
6058 $sql .=
" re.description, re.fk_facture_source";
6059 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
6060 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
6061 $resql = $db->query($sql);
6063 $num = $db->num_rows($resql);
6067 $obj = $db->fetch_object($resql);
6068 $invoice->fetch($obj->fk_facture_source);
6069 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6070 print
'<span class="opacitymedium">';
6072 print $langs->trans(
"CreditNote").
' ';
6075 print $langs->trans(
"Deposit").
' ';
6077 print $invoice->getNomUrl(0);
6080 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
6081 print
'<td class="right">';
6082 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
6083 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
6088 $creditnoteamount += $obj->amount_ttc;
6091 $depositamount += $obj->amount_ttc;
6100 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
6101 print
'<span class="opacitymedium">';
6102 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
6104 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
6105 $resteapayeraffiche = 0;
6106 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6110 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
6111 print
'<span class="opacitymedium">';
6112 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
6114 print
'</td><td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td><td> </td></tr>';
6116 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6120 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
6121 print
'<span class="opacitymedium">';
6122 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
6124 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
6125 $resteapayeraffiche = 0;
6126 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6130 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
6131 $text = $langs->trans(
"HelpAbandonOther");
6133 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
6135 print
'<span class="opacitymedium">';
6137 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
6139 print
'</td><td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
6140 $resteapayeraffiche = 0;
6141 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6145 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6146 print
'<span class="opacitymedium">';
6147 print $langs->trans(
"Billed");
6148 print
'</td><td class="right">'.price(
$object->total_ttc).
'</td><td> </td></tr>';
6150 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6151 print
'<span class="opacitymedium">';
6152 print $langs->trans(
'RemainderToPay');
6153 if ($resteapayeraffiche < 0) {
6154 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6158 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
6162 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6163 print
'<span class="opacitymedium">';
6164 print $langs->trans(
'RemainderToPayMulticurrency');
6165 if ($resteapayeraffiche < 0) {
6166 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6170 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">';
6172 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>';
6176 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
6178 if (
$object->isSituationInvoice()) {
6179 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
6182 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
6185 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
6187 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>';
6190 print
'<tr><td colspan="'.$nbcols.
'" align="right">';
6191 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
6192 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
6193 print
' :</td><td align="right">'.price($retainedWarranty).
'</td><td> </td></tr>';
6196 $resteapayeraffiche = $resteapayer;
6197 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6200 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6201 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
6202 print
'</td><td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td><td> </td></tr>';
6205 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>';
6208 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6209 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
6210 if ($resteapayeraffiche > 0) {
6211 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6213 print
'</span></td>';
6214 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
6215 print
'<td class="nowrap"> </td></tr>';
6219 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
6220 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
6221 if ($resteapayeraffiche > 0) {
6222 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6226 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>';
6239 if (isModEnabled(
'margin')) {
6240 $formmargin->displayMarginInfos(
$object);
6246 print
'<div class="clearboth"></div><br>';
6249 $blocname =
'contacts';
6250 $title = $langs->trans(
'ContactsAddresses');
6251 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6255 $blocname =
'notes';
6256 $title = $langs->trans(
'Notes');
6257 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6261 $result =
$object->getLinesArray();
6265 global $inputalsopricewithtax;
6266 $inputalsopricewithtax = 1;
6271 print
'<!-- Area to change globally the situation percent -->'.
"\n";
6272 print
'<div class="div-table-responsive-no-min">';
6274 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'#updatealllines" method="POST">';
6275 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
6276 print
'<input type="hidden" name="action" value="updatealllines" />';
6277 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
6278 print
'<input type="hidden" name="page_y" value="" />';
6279 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
6281 print
'<table id="tablelines_all_progress" class="noborder noshadow centpercent">';
6283 print
'<tr class="liste_titre nodrag nodrop">';
6287 print
'<td align="center" width="5"> </td>';
6289 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
6290 print
'<td class="right">'.$langs->trans(
'Progress').
'</td>';
6291 print
'<td> </td>';
6294 print
'<tr class="nodrag nodrop">';
6297 print
'<td align="center" width="5"> </td>';
6299 print
'<td> </td>';
6300 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
6301 print
'<td class="right"><input type="submit" class="button reposition small" name="all_percent" value="'.$langs->trans(
"Modify").
'" /></td>';
6312 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
6313 <input type="hidden" name="token" value="' .
newToken().
'">
6314 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
6315 <input type="hidden" name="mode" value="">
6316 <input type="hidden" name="page_y" value="">
6317 <input type="hidden" name="id" value="' .
$object->id.
'">
6318 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
6321 if (!empty(
$conf->use_javascript_ajax) &&
$object->status == 0) {
6322 if (isModEnabled(
'subtotals')) {
6323 include DOL_DOCUMENT_ROOT.
'/core/tpl/subtotal_ajaxrow.tpl.php';
6325 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
6329 print
'<div class="div-table-responsive-no-min">';
6330 print
'<table id="tablelines" class="noborder noshadow centpercent nomarginbottom">';
6334 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
6338 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
6339 if ($action !=
'editline' && $action !=
'selectlines') {
6342 $parameters = array();
6343 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
6347 if (empty($reshook)) {
6348 $object->formAddObjectLine(1, $mysoc, $soc);
6351 $parameters = array();
6352 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters,
$object, $action);
6366 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
6367 print
'<div class="tabsAction">';
6369 $parameters = array();
6370 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
6371 if (empty($reshook)) {
6374 'class' =>
'classfortooltip',
6381 $ventilExportCompta =
$object->getVentilExportCompta();
6383 if ($ventilExportCompta == 0) {
6385 if (!$objectidnext &&
$object->is_last_in_cycle()) {
6386 if ($usercanunvalidate) {
6387 unset($params[
'attr'][
'title']);
6388 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
true, $params);
6390 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
6391 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
false, $params);
6393 } elseif (!
$object->is_last_in_cycle()) {
6394 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
6395 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6397 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
6398 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6402 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6403 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6408 $result = $discount->fetch(0,
$object->id);
6416 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
6417 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
6418 unset($params[
'attr'][
'title']);
6419 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
6421 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6422 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
6429 $langs->load(
"contracts");
6431 if ($usercancreatecontract) {
6432 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>';
6440 $langs->load(
"subtotals");
6442 $url_button = array();
6444 $url_button[] = array(
6445 'lang' =>
'subtotals',
6447 'perm' => (
bool) $usercancreate,
6448 'label' => $langs->trans(
'AddTitleLine'),
6449 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_title_line&token='.
newToken()
6452 $url_button[] = array(
6453 'lang' =>
'subtotals',
6455 'perm' => (
bool) $usercancreate,
6456 'label' => $langs->trans(
'AddSubtotalLine'),
6457 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_subtotal_line&token='.
newToken()
6459 print
dolGetButtonAction(
'', $langs->trans(
'Subtotal'),
'default', $url_button,
'',
true);
6466 if ($usercanvalidate) {
6467 unset($params[
'attr'][
'title']);
6468 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
6473 if (empty($user->socid)) {
6475 if ($objectidnext) {
6476 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'SendMail').
'</span>';
6479 unset($params[
'attr'][
'title']);
6480 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
6482 unset($params[
'attr'][
'title']);
6483 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
6491 if ($resteapayer > 0) {
6492 if ($usercancreatewithdrarequest) {
6493 if (!$objectidnext &&
$object->close_code !=
'replaced') {
6494 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>';
6496 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
6507 if (isModEnabled(
'takepos') &&
$object->module_source ==
'takepos') {
6508 $langs->load(
"cashdesk");
6509 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
6510 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
6515 if ($objectidnext) {
6516 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
6520 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
6521 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
6525 unset($params[
'attr'][
'title']);
6526 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);
6531 $sumofpayment = $totalpaid;
6532 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
6538 if ($resteapayer == 0) {
6539 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
6541 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
6547 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
6551 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
6553 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>';
6560 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
6562 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
6576 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
6577 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
6579 unset($params[
'attr'][
'title']);
6580 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken(),
'',
true, $params);
6586 if ($totalpaid > 0 || $totalcreditnotes > 0) {
6588 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
6591 if ($objectidnext) {
6592 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
6594 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
6602 if (!$objectidnext) {
6603 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>';
6609 &&
$object->isSituationInvoice()
6610 && (
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
6613 &&
$object->is_last_in_cycle()
6616 if ($usercanunvalidate) {
6617 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>';
6619 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
6625 unset($params[
'attr'][
'title']);
6626 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice&token='.
newToken(),
'',
true, $params);
6631 if (!$objectidnext && count(
$object->lines) > 0) {
6632 unset($params[
'attr'][
'title']);
6633 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
6639 &&
$object->isSituationInvoice()
6642 &&
$object->situation_counter > 1
6643 &&
$object->is_last_in_cycle()
6644 && $usercanunvalidate
6647 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6649 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6655 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
6656 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6657 } elseif (!
$object->is_last_in_cycle()) {
6658 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6660 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6665 $isErasable =
$object->is_erasable();
6667 if ($isErasable == -4) {
6668 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
6669 } elseif ($isErasable == -3) {
6670 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
6671 } elseif ($isErasable == -2) {
6672 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
6673 } elseif ($isErasable == -1) {
6674 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6675 } elseif ($isErasable <= 0) {
6676 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable');
6677 } elseif ($objectidnext) {
6678 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
6680 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
6681 $enableDelete =
false;
6683 if ($isErasable > 0 && ! $objectidnext) {
6684 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
6685 $enableDelete =
true;
6687 unset($params[
'attr'][
'title']);
6688 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
6690 unset($params[
'attr'][
'title']);
6691 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
6698 if (
GETPOST(
'modelselected',
'alpha')) {
6699 $action =
'presend';
6701 if ($action !=
'prerelance' && $action !=
'presend') {
6702 print
'<div class="fichecenter"><div class="fichehalfleft">';
6703 print
'<a name="builddoc"></a>';
6708 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
6709 $genallowed = $usercanread;
6710 $delallowed = $usercancreate;
6712 print $formfile->showdocuments(
6732 'remove_file_comfirm'
6735 $somethingshown = $formfile->numoffiles;
6738 $tmparray = $form->showLinkToObjectBlock(
$object, array(), array(
'invoice'), 1);
6739 $linktoelem = $tmparray[
'linktoelem'];
6740 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
6741 print $htmltoenteralink;
6743 $compatibleImportElementsList =
false;
6747 $compatibleImportElementsList = array(
'commande',
'propal',
'subscription');
6749 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem, $compatibleImportElementsList);
6753 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6754 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
6755 $useonlinepayment = count($validpaymentmethod);
6758 print
'<br><!-- Link to pay -->'.
"\n";
6759 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6760 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
6763 print
'</div><div class="fichehalfright">';
6767 $morehtmlcenter =
'<div class="nowraponall">';
6768 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullConversation'),
'',
'fa fa-comments imgforviewmode', DOL_URL_ROOT.
'/compta/facture/messaging.php?id='.
$object->id);
6769 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
6770 $morehtmlcenter .=
'</div>';
6773 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
6775 $somethingshown = $formactions->showactions(
$object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
6777 print
'</div></div>';
6782 $modelmail =
'facture_send';
6783 $defaulttopic =
'SendBillRef';
6784 $diroutput =
$conf->invoice->multidir_output[
$object->entity];
6785 $trackid =
'inv'.$object->id;
6787 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.