47require
'../../main.inc.php';
57require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
58require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
59require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
60require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
61require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
62require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
63require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
64require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
65require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
66require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
67require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
68require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
69require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
70require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
72 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
75 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
76 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
78require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
81 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
84 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
88$langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
90 $langs->load(
'incoterm');
93 $langs->load(
'margins');
97$action =
GETPOST(
'action',
'aZ09');
98$confirm =
GETPOST(
'confirm',
'alpha');
99$cancel =
GETPOST(
'cancel',
'alpha');
100$backtopage =
GETPOST(
'backtopage',
'alpha');
101$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
107$origin =
GETPOST(
'origin',
'alpha');
111$ref_client =
GETPOST(
'ref_client',
'alpha');
112$inputReasonId =
GETPOSTINT(
'input_reason_id');
115$selectedLines =
GETPOST(
'toselect',
'array:int');
128$extrafields->fetch_name_optionals_label(
$object->table_element);
131$total_global_ttc = 0;
132$displayWarranty =
false;
133$statusreplacement = 0;
135$price_base_type =
'';
136$array_options = array();
139if ($id > 0 || !empty($ref)) {
140 if ($action !=
'add') {
142 $fetch_situation =
false;
144 $fetch_situation =
true;
146 $ret =
$object->fetch($id, $ref,
'', 0, $fetch_situation);
147 if ($ret > 0 && isset(
$object->fk_project)) {
148 $ret =
$object->fetchProject();
154$hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
157$usercanread = $user->hasRight(
"facture",
"lire");
158$usercancreate = $user->hasRight(
"facture",
"creer");
159$usercanissuepayment = $user->hasRight(
"facture",
"paiement");
160$usercandelete = $user->hasRight(
"facture",
"supprimer") || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
161$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
164$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'validate')));
165$usercansend = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercanread) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'send')));
166$usercanreopen = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'reopen')));
168 $usercanreopen =
false;
170$usercanunvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'unvalidate')));
171$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
174$usercancreatemargin = $user->hasRight(
'margins',
'creer');
175$usercanreadallmargin = $user->hasRight(
'margins',
'liretous');
176$usercancreatewithdrarequest = $user->hasRight(
'prelevement',
'bons',
'creer');
178$permissionnote = $usercancreate;
179$permissiondellink = $usercancreate;
180$permissiontoedit = $usercancreate;
181$permissiontoadd = $usercancreate;
182$permissiontoeditextra = $usercancreate;
183if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
185 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
189$retainedWarrantyInvoiceAvailableType = array();
191 $retainedWarrantyInvoiceAvailableType = explode(
'+',
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY'));
196 $socid = $user->socid;
209$parameters = array(
'socid' => $socid);
210$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
215if (empty($reshook)) {
216 $backurlforlist =
dolBuildUrl(DOL_URL_ROOT.
'/compta/facture/list.php');
218 if (empty($backtopage) || ($cancel && empty($id))) {
219 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
220 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
221 $backtopage = $backurlforlist;
223 $backtopage =
dolBuildUrl(DOL_URL_ROOT.
'/compta/facture/card.php', [
'id' => ((!empty($id) && $id > 0) ? $id :
'__ID__')]);
229 if (!empty($backtopageforcancel)) {
230 header(
"Location: ".$backtopageforcancel);
232 } elseif (!empty($backtopage)) {
233 header(
"Location: ".$backtopage);
239 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
241 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
243 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
246 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
248 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'IdThirdParty')),
null,
'errors');
251 '@phan-var-force Facture $objectutil';
254 $objectutil->socid = $socid;
255 $result = $objectutil->createFromClone($user, $id, (
GETPOSTISSET(
'entity') ?
GETPOSTINT(
'entity') : null));
257 $warningMsgLineList = array();
259 foreach ($objectutil->lines as $line) {
260 if (!is_object($line->product)) {
261 $line->fetch_product();
263 if (is_object($line->product) && $line->product->id > 0) {
264 if (empty($line->product->status)) {
265 $warningMsgLineList[$line->id] = $langs->trans(
'WarningLineProductNotToSell', $line->product->ref);
269 if (!empty($warningMsgLineList)) {
273 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?facid=' . $result);
276 $langs->load(
"errors");
281 } elseif ($action ==
'reopen' && $usercanreopen) {
285 $result =
$object->setUnpaid($user);
287 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
293 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
298 $idwarehouse =
GETPOST(
'idwarehouse');
300 $qualified_for_stock_change = 0;
302 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
304 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
307 $isErasable =
$object->is_erasable();
309 if (($isErasable > 0) || ($usercancreate && $isErasable == 1)) {
310 $result =
$object->delete($user, 0, (
int) $idwarehouse);
312 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
319 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
329 $outputlangs = $langs;
335 $newlang =
$object->thirdparty->default_lang;
337 if (!empty($newlang)) {
339 $outputlangs->setDefaultLang($newlang);
340 $outputlangs->load(
'products');
344 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
347 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
354 } elseif ($action ==
'confirm_delete_subtotalline' && $confirm ==
'yes' && $usercancreate) {
359 $result =
$object->deleteSubtotalLine($langs,
GETPOSTINT(
'lineid'), (
bool)
GETPOST(
'deletecorrespondingsubtotalline'));
364 $outputlangs = $langs;
370 $newlang =
$object->thirdparty->default_lang;
372 if (!empty($newlang)) {
374 $outputlangs->setDefaultLang($newlang);
375 $outputlangs->load(
'products');
379 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
382 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
389 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
392 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
393 if ($result > 0 && $discount->fk_facture ==
$object->id) {
394 $discount->unlink_invoice();
398 } elseif ($action ==
'valid' && $usercancreate) {
402 if ((preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) &&
409 $last_of_type =
$object->willBeLastOfSameType(
true);
410 if (empty(
$object->date_validation) && !$last_of_type[0]) {
420 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
429 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
438 $array_of_total_ht_per_vat_rate = array();
439 $array_of_total_ht_devise_per_vat_rate = array();
440 foreach (
$object->lines as $line) {
442 $vat_src_code_for_line =
'';
443 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
444 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
446 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
447 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
449 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
450 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
454 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
455 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
456 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
458 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
459 if (
$object->type == $object::TYPE_DEPOSIT) {
460 $langs->load(
"errors");
462 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
466 $tmpvatratetoshow = explode(
'_', $vatrate);
467 $tmpvatratetoshow[0] = round((
float) $tmpvatratetoshow[0], 2);
469 if ($tmpvatratetoshow[0] != 0) {
470 $langs->load(
"errors");
471 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", (
string) $tmpvatratetoshow[0]),
null,
'errors');
479 } elseif ($action ==
'classin' && $usercancreate) {
485 } elseif ($action ==
'setposinfo' && $usercancreate) {
489 $result =
$object->update($user);
493 } elseif ($action ==
'setmode' && $usercancreate) {
499 } elseif ($action ==
'setretainedwarrantyconditions' && $usercancreate) {
502 $object->retained_warranty_fk_cond_reglement = 0;
503 $result =
$object->setRetainedWarrantyPaymentTerms(
GETPOSTINT(
'retained_warranty_fk_cond_reglement'));
508 $old_rw_date_lim_reglement =
$object->retained_warranty_date_limit;
509 $new_rw_date_lim_reglement =
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
510 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
511 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
516 $result =
$object->update($user);
520 } elseif ($action ==
'setretainedwarranty' && $usercancreate) {
526 } elseif ($action ==
'setretainedwarrantydatelimit' && $usercancreate) {
528 $result =
$object->setRetainedWarrantyDateLimit(
GETPOSTDATE(
'retained_warranty_date_limit'));
532 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
533 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
534 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
536 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
538 $old_date_lim_reglement =
$object->date_lim_reglement;
540 if (empty($newdate)) {
541 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
542 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.
$id.
'&action=editinvoicedate&token='.
newToken());
547 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
549 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
554 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
555 if ($new_date_lim_reglement) {
556 $object->date_lim_reglement = $new_date_lim_reglement;
561 $result =
$object->update($user);
564 $action =
'editinvoicedate';
566 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
571 $object->date_pointoftax = $date_pointoftax;
572 $result =
$object->update($user);
576 } elseif ($action ==
'setconditions' && $usercancreate) {
578 $object->cond_reglement_code = 0;
579 $object->cond_reglement_id = 0;
592 $old_date_lim_reglement =
$object->date_lim_reglement;
593 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
594 if ($new_date_lim_reglement) {
595 $object->date_lim_reglement = $new_date_lim_reglement;
600 $result =
$object->update($user);
612 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
616 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
617 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
619 $result =
$object->update($user);
623 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
626 $result =
$object->update($user);
634 $outputlangs = $langs;
637 $newlang =
GETPOST(
'lang_id',
'aZ09');
640 $newlang =
$object->thirdparty->default_lang;
642 if (!empty($newlang)) {
644 $outputlangs->setDefaultLang($newlang);
645 $outputlangs->load(
'products');
650 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
656 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
661 } elseif ($action ==
'set_dispute_status' && $usercancreate) {
662 $result =
$object->setStatut(
GETPOSTINT(
'dispute_status'),
null,
'facture',
'FACTURE_MODIFY',
'dispute_status');
666 } elseif ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
671 } elseif ($action ==
'setbankaccount' && $usercancreate) {
676 } elseif ($action ==
'setremisepercent' && $usercancreate) {
682 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
701 $newremaintopay =
$object->getRemainToPay(0);
702 if ($newremaintopay == 0) {
709 if (
GETPOSTINT(
"remise_id_for_payment") > 0) {
710 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
712 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
716 $remaintopay =
$object->getRemainToPay(0);
720 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
724 $result = $discount->link_to_invoice(0, $id);
737 $newremaintopay =
$object->getRemainToPay(0);
738 if ($newremaintopay == 0) {
752 $outputlangs = $langs;
755 $newlang =
GETPOST(
'lang_id',
'aZ09');
759 $newlang =
$object->thirdparty->default_lang;
761 if (!empty($newlang)) {
763 $outputlangs->setDefaultLang($newlang);
767 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
772 } elseif ($action ==
'setref' && $usercancreate) {
774 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', 0,
'',
'', $user,
'BILL_MODIFY');
778 } elseif ($action ==
'setref_client' && $usercancreate) {
780 $result =
$object->set_ref_client(
GETPOST(
'ref_client',
'alpha'));
784 } elseif ($action ==
'setdemandreason' && $usercancreate) {
785 $result =
$object->setInputReason($inputReasonId);
789 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
798 $qualified_for_stock_change = 0;
800 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
802 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
805 if ($qualified_for_stock_change) {
806 if (!$idwarehouse || $idwarehouse == - 1) {
808 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
815 $result =
$object->validate($user,
'', $idwarehouse);
819 $outputlangs = $langs;
822 $newlang =
GETPOST(
'lang_id',
'aZ09');
825 $newlang =
$object->thirdparty->default_lang;
827 if (!empty($newlang)) {
829 $outputlangs->setDefaultLang($newlang);
830 $outputlangs->load(
'products');
836 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
849 } elseif ($action ==
'confirm_modif' && $usercanunvalidate && !
getDolGlobalString(
'INVOICE_CAN_NEVER_BE_EDITED')) {
858 $qualified_for_stock_change = 0;
860 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
862 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
865 if ($qualified_for_stock_change) {
866 if (!$idwarehouse || $idwarehouse == -1) {
868 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
877 $sql =
'SELECT pf.amount';
878 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'paiement_facture as pf';
879 $sql .=
' WHERE pf.fk_facture = ' . ((int)
$object->id);
881 $result =
$db->query($sql);
884 $num =
$db->num_rows($result);
887 $objp =
$db->fetch_object($result);
888 $totalpaid += $objp->amount;
895 $resteapayer =
$object->total_ttc - $totalpaid;
898 $ventilExportCompta =
$object->getVentilExportCompta();
901 if ($ventilExportCompta == 0) {
904 $result =
$object->setDraft($user, $idwarehouse);
911 $outputlangs = $langs;
914 $newlang =
GETPOST(
'lang_id',
'aZ09');
917 $newlang =
$object->thirdparty->default_lang;
919 if (!empty($newlang)) {
921 $outputlangs->setDefaultLang($newlang);
922 $outputlangs->load(
'products');
927 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
933 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
936 $result =
$object->setPaid($user);
940 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
943 $close_code =
GETPOST(
"close_code",
'restricthtml');
944 $close_note =
GETPOST(
"close_note",
'restricthtml');
947 if (
isModEnabled(
'tax') && $close_code == $object::CLOSECODE_WITHHOLDINGTAX) {
948 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
950 $amount = (float) ($resteapayer > 0 ? $resteapayer * -1 : $resteapayer);
954 $tempTva->datev =
$object->date;
955 $tempTva->datep =
$object->date;
956 $tempTva->amount = $amount;
957 $tempTva->label = $langs->trans(
'WithholdingTax') .
' - ' .
$object->ref;
959 $valid = $tempTva->getIdForLabel($tempTva->label);
961 $ret = $tempTva->create($user);
965 $tempTva->setPaid($user);
975 setEventMessages($langs->trans(
'LabelWithholdingExist'), $tempTva->errors,
'errors');
981 $result =
$object->setPaid($user, $close_code, $close_note);
989 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
991 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
994 $close_code =
GETPOST(
"close_code",
'restricthtml');
995 $close_note =
GETPOST(
"close_note",
'restricthtml');
997 $result =
$object->setCanceled($user, $close_code, $close_note);
1004 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
1006 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
1014 $result = $discountcheck->fetch(0,
$object->id);
1027 $amount_ht = $amount_tva = $amount_ttc = $amount_localtax1 = $amount_localtax2 = array();
1028 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
1032 foreach (
$object->lines as $line) {
1033 if ($line->product_type < 9 && $line->total_ht != 0) {
1034 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
1036 if (!isset($amount_ht[$keyforvatrate])) {
1037 $amount_ht[$keyforvatrate] = 0;
1039 $amount_ht[$keyforvatrate] += $line->total_ht;
1040 if (!isset($amount_tva[$keyforvatrate])) {
1041 $amount_tva[$keyforvatrate] = 0;
1043 $amount_tva[$keyforvatrate] += $line->total_tva;
1044 if (!isset($amount_localtax1[$keyforvatrate])) {
1045 $amount_localtax1[$keyforvatrate] = 0;
1047 $amount_localtax1[$keyforvatrate] += $line->total_localtax1;
1048 if (!isset($amount_localtax2[$keyforvatrate])) {
1049 $amount_localtax2[$keyforvatrate] = 0;
1051 $amount_localtax2[$keyforvatrate] += $line->total_localtax2;
1052 if (!isset($amount_ttc[$keyforvatrate])) {
1053 $amount_ttc[$keyforvatrate] = 0;
1055 $amount_ttc[$keyforvatrate] += $line->total_ttc;
1056 if (!isset($multicurrency_amount_ht[$keyforvatrate])) {
1057 $multicurrency_amount_ht[$keyforvatrate] = 0;
1059 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
1060 if (!isset($multicurrency_amount_tva[$keyforvatrate])) {
1061 $multicurrency_amount_tva[$keyforvatrate] = 0;
1063 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
1064 if (!isset($multicurrency_amount_ttc[$keyforvatrate])) {
1065 $multicurrency_amount_ttc[$keyforvatrate] = 0;
1067 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
1071 '@phan-var-force array<string,float> $amount_ht
1072 @phan-var-force array<string,float> $amount_tva
1073 @phan-var-force array<string,float> $amount_ttc
1074 @phan-var-force array<string,float> $amount_localtax1
1075 @phan-var-force array<string,float> $amount_localtax2
1076 @phan-var-force array<string,float> $multicurrency_amount_ht
1077 @phan-var-force array<string,float> $multicurrency_amount_tva
1078 @phan-var-force array<string,float> $multicurrency_amount_ttc';
1082 $alreadypaid =
$object->getSommePaiement();
1083 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
1084 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
1085 foreach ($amount_ht as $vatrate => $val) {
1086 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
1087 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
1088 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
1089 $amount_localtax1[$vatrate] =
price2num($amount_localtax1[$vatrate] * $ratio,
'MU');
1090 $amount_localtax2[$vatrate] =
price2num($amount_localtax2[$vatrate] * $ratio,
'MU');
1091 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
1092 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
1093 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
1102 $discount->description =
'(CREDIT_NOTE)';
1104 $discount->description =
'(DEPOSIT)';
1106 $discount->description =
'(EXCESS RECEIVED)';
1108 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
1110 $discount->fk_soc =
$object->socid;
1111 $discount->socid =
$object->socid;
1112 $discount->fk_facture_source =
$object->id;
1121 $discount->description =
'(EXCESS RECEIVED)';
1124 $sql =
'SELECT SUM(pf.amount) as total_paiements';
1125 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
1126 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
1127 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
1128 $sql .=
' AND pf.fk_paiement = p.rowid';
1129 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
1130 $resql =
$db->query($sql);
1135 $res =
$db->fetch_object($resql);
1136 $total_paiements = $res->total_paiements;
1139 $total_creditnote_and_deposit = 0;
1140 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1141 $sql .=
" re.description, re.fk_facture_source";
1142 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1143 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
1144 $resql =
$db->query($sql);
1145 if (!empty($resql)) {
1146 while ($obj =
$db->fetch_object($resql)) {
1147 $total_creditnote_and_deposit += $obj->amount_ttc;
1153 $discount->amount_ttc =
price2num($total_paiements + $total_creditnote_and_deposit -
$object->total_ttc,
'MT');
1154 $discount->amount_tva = 0;
1155 $discount->amount_ht = $discount->amount_ttc;
1156 $discount->tva_tx = 0;
1157 $discount->localtax1_tx = 0;
1158 $discount->localtax1_type = 0;
1159 $discount->localtax2_tx = 0;
1160 $discount->localtax2_type = 0;
1161 $discount->vat_src_code =
'';
1163 if ($discount->amount_ttc > 0) {
1164 $result = $discount->create($user);
1174 $discount->description =
'(CREDIT_NOTE)';
1176 $discount->description =
'(DEPOSIT)';
1179 foreach ($amount_ht as $tva_tx => $xxx) {
1184 $discount->amount_ht = -((float) $amount_ht[$tva_tx]);
1185 $discount->amount_tva = -((float) $amount_tva[$tva_tx]);
1186 $discount->amount_ttc = -((float) $amount_ttc[$tva_tx]);
1187 $discount->total_ht = -((float) $amount_ht[$tva_tx]);
1188 $discount->total_tva = -((float) $amount_tva[$tva_tx]);
1189 $discount->total_localtax1 = -((float) $amount_localtax1[$tva_tx]);
1190 $discount->total_localtax2 = -((float) $amount_localtax2[$tva_tx]);
1191 $discount->total_ttc = -((float) $amount_ttc[$tva_tx]);
1192 $discount->multicurrency_amount_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1193 $discount->multicurrency_amount_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1194 $discount->multicurrency_amount_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1195 $discount->multicurrency_total_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1196 $discount->multicurrency_total_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1197 $discount->multicurrency_total_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1200 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
1201 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
1202 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
1203 $discount->total_ht = abs((
float) $amount_ht[$tva_tx]);
1204 $discount->total_tva = abs((
float) $amount_tva[$tva_tx]);
1205 $discount->total_localtax1 = abs((
float) $amount_localtax1[$tva_tx]);
1206 $discount->total_localtax2 = abs((
float) $amount_localtax2[$tva_tx]);
1207 $discount->total_ttc = abs((
float) $amount_ttc[$tva_tx]);
1208 $discount->multicurrency_amount_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1209 $discount->multicurrency_amount_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1210 $discount->multicurrency_amount_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1211 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1212 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1213 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1219 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
1220 $vat_src_code = $reg[1];
1221 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
1224 $discount->tva_tx = abs((
float) $tva_tx);
1225 $discount->localtax1_tx = $taxes[
'localtax1'];
1226 $discount->localtax1_type = $taxes[
'localtax1_type'];
1227 $discount->localtax2_tx = $taxes[
'localtax2'];
1228 $discount->localtax2_type = $taxes[
'localtax2_type'];
1229 $discount->vat_src_code = $vat_src_code;
1231 $result = $discount->create($user);
1239 if (empty($error)) {
1249 $result =
$object->setPaid($user);
1263 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
1268 $result = $paiement->fetch(
GETPOSTINT(
'paiement_id'));
1269 $paymentbills = ($result > 0) ? $paiement->getBillsArray() : array();
1270 if ($result > 0 && is_array($paymentbills) && in_array(
$object->id, $paymentbills)) {
1271 $result = $paiement->delete($user);
1273 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1283 } elseif ($action ==
'add' && $usercancreate) {
1290 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1296 $object->demand_reason_id = $inputReasonId;
1299 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1312 if (empty($dateinvoice)) {
1314 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1324 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1334 $object->date_pointoftax = $date_pointoftax;
1335 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1336 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1345 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1346 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1363 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1365 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceAvoirAskCombo")),
null,
'errors');
1369 if (empty($dateinvoice)) {
1371 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1381 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1386 if (!empty($originentity)) {
1387 $object->entity = $originentity;
1393 $object->date_pointoftax = $date_pointoftax;
1394 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1395 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1400 $object->cond_reglement_id = 0;
1404 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1405 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1409 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1413 if (
$object->fk_facture_source > 0 && $facture_source->fetch(
$object->fk_facture_source) > 0) {
1414 if ($facture_source->isSituationInvoice()) {
1415 $object->situation_counter = $facture_source->situation_counter;
1416 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1417 $facture_source->fetchPreviousNextSituationInvoice();
1420 $object->pos_source = $facture_source->pos_source;
1421 $object->module_source = $facture_source->module_source;
1429 if (
$object->copy_linked_contact($facture_source,
'internal') < 0) {
1431 } elseif ($facture_source->socid ==
$object->socid) {
1433 if (
$object->copy_linked_contact($facture_source,
'external') < 0) {
1444 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1445 if (!empty($facture_source->lines)) {
1446 $fk_parent_line = 0;
1448 foreach ($facture_source->lines as $line) {
1450 if (method_exists($line,
'fetch_optionals')) {
1452 $line->fetch_optionals();
1456 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1457 $fk_parent_line = 0;
1461 if ($facture_source->isSituationInvoice()) {
1462 $source_fk_prev_id = $line->fk_prev_id;
1463 $line->fk_prev_id = $line->id;
1468 if (
getDolGlobalInt(
'INVOICE_USE_SITUATION') == 1 && !empty($facture_source->tab_previous_situation_invoice)) {
1471 $tab_jumped_credit_notes = array();
1472 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1473 $searchPreviousInvoice =
true;
1474 while ($searchPreviousInvoice) {
1475 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1476 $searchPreviousInvoice =
false;
1480 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1486 $maxPrevSituationPercent = 0;
1487 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1488 if ($prevLine->id == $source_fk_prev_id) {
1489 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1492 $line->total_ht -= $prevLine->total_ht;
1493 $line->total_tva -= $prevLine->total_tva;
1494 $line->total_ttc -= $prevLine->total_ttc;
1495 $line->total_localtax1 -= $prevLine->total_localtax1;
1496 $line->total_localtax2 -= $prevLine->total_localtax2;
1498 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1499 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1500 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1501 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1506 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1511 $maxPrevSituationPercent = 0;
1512 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1513 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1514 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1515 $maxPrevSituationPercent = $prevLine->situation_percent;
1517 $line->total_ht -= $prevLine->total_ht;
1518 $line->total_tva -= $prevLine->total_tva;
1519 $line->total_ttc -= $prevLine->total_ttc;
1520 $line->total_localtax1 -= $prevLine->total_localtax1;
1521 $line->total_localtax2 -= $prevLine->total_localtax2;
1523 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1524 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1525 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1526 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1532 $line->situation_percent += $maxPrevSituationPercent;
1538 $line->fk_facture =
$object->id;
1539 $line->fk_parent_line = $fk_parent_line;
1541 $line->subprice = -$line->subprice;
1543 $line->total_ht = -$line->total_ht;
1544 $line->total_tva = -$line->total_tva;
1545 $line->total_ttc = -$line->total_ttc;
1546 $line->total_localtax1 = -$line->total_localtax1;
1547 $line->total_localtax2 = -$line->total_localtax2;
1549 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1550 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1551 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1552 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1554 $line->context[
'createcreditnotefrominvoice'] = 1;
1555 $result = $line->insert(0, 1);
1560 if ($result > 0 && $line->product_type == 9) {
1561 $fk_parent_line = $result;
1569 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1570 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1571 $totalpaid = $facture_source->getSommePaiement();
1572 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1573 $totaldeposits = $facture_source->getSumDepositsUsed();
1574 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1576 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1577 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1580 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1585 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1586 $tva_tx = (float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY');
1593 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), 0, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC', -$remain_to_pay);
1598 if (!empty(
$object->fk_facture_source) &&
$id > 0) {
1599 $facture_source->fetch(
$object->fk_facture_source);
1600 $facture_source->fetchObjectLinked();
1602 if (!empty($facture_source->linkedObjectsIds)) {
1603 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1604 $object->add_object_linked($sourcetype, current($TIds));
1613 if (empty($dateinvoice)) {
1615 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1626 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1636 $object->date_pointoftax = $date_pointoftax;
1637 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1638 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1649 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1650 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1666 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1667 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1668 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1672 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1676 if (empty($dateinvoice)) {
1678 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1688 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1689 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1694 if ($typeamount && !empty($origin) && !empty($originid)) {
1695 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1696 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1700 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1701 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1705 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1706 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1716 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1726 $object->date_pointoftax = $date_pointoftax;
1727 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1728 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1738 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1739 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1743 $object->situation_counter = 1;
1748 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1750 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1752 $object->retained_warranty = 0;
1753 $object->retained_warranty_fk_cond_reglement = 0;
1756 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1757 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1760 $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);
1765 if (!empty($origin) && !empty($originid)) {
1768 $element = $subelement = $origin;
1769 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1770 $element = $regs[1];
1771 $subelement = $regs[2];
1775 if ($element ==
'order') {
1776 $element = $subelement =
'commande';
1778 if ($element ==
'propal') {
1779 $element =
'comm/propal';
1780 $subelement =
'propal';
1782 if ($element ==
'contract') {
1783 $element = $subelement =
'contrat';
1785 if ($element ==
'inter') {
1786 $element = $subelement =
'fichinter';
1788 if ($element ==
'shipping') {
1789 $element = $subelement =
'expedition';
1793 $object->origin_type = $origin;
1794 $object->origin_id = $originid;
1799 if (
$object->origin ==
'shipping') {
1800 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1802 $exp->fetch(
$object->origin_id);
1803 $exp->fetchObjectLinked();
1804 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1805 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1806 $object->linked_objects[
'commande'] = $value;
1812 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
1820 $classname = ucfirst($subelement);
1821 $srcobject =
new $classname(
$db);
1822 '@phan-var-force CommonObject $srcobject';
1824 dol_syslog(
"Try to find source object origin_type=".
$object->origin_type.
" origin_id=".
$object->origin_id.
" to add lines or deposit lines");
1825 $result = $srcobject->fetch(
$object->origin_id);
1831 $amountdeposit = array();
1834 if ($typeamount ==
'amount') {
1835 $amount = (float) $valuedeposit;
1837 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1840 $TTotalByTva = array();
1841 foreach ($srcobject->lines as &$line) {
1842 if (empty($line->qty)) {
1845 if (!empty($line->special_code)) {
1848 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1850 '@phan-var-force array<string,float> $TTotalByTva';
1852 $amount_ttc_diff = 0.;
1853 foreach ($TTotalByTva as $tva => &$total) {
1854 if (empty($amountdeposit[$tva])) {
1855 $amountdeposit[$tva] = 0;
1857 $coef = $total / $srcobject->total_ttc;
1858 $am = $amount * $coef;
1859 $amount_ttc_diff += $am;
1860 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1863 if ($typeamount ==
'amount') {
1864 $amountdeposit[0] = $valuedeposit;
1865 } elseif ($typeamount ==
'variable') {
1868 $lines = $srcobject->lines;
1869 $numlines = count($lines);
1870 for ($i = 0; $i < $numlines; $i++) {
1872 if (empty($lines[$i]->qty)) {
1875 if (!empty($lines[$i]->special_code)) {
1879 $totalamount += $lines[$i]->total_ht;
1880 $tva_tx = $lines[$i]->tva_tx;
1882 if (empty($amountdeposit[$tva_tx])) {
1883 $amountdeposit[$tva_tx] = 0;
1885 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1889 if ($totalamount == 0) {
1890 $amountdeposit[0] = 0;
1898 $amount_ttc_diff = $amountdeposit[0];
1901 foreach ($amountdeposit as $tva => $amount) {
1902 if (empty($amount)) {
1908 $totalhtofsource = 0;
1909 $totalcostofsource = 0;
1910 foreach ((is_array($srcobject->lines) ? $srcobject->lines : array()) as $srcline) {
1911 if (empty($srcline->qty) || !empty($srcline->special_code)) {
1914 if (($typeamount ==
'amount' && !
getDolGlobalString(
'MAIN_DEPOSIT_MULTI_TVA')) ||
price2num($srcline->tva_tx) ==
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $tva))) {
1915 $totalhtofsource += (float) $srcline->total_ht;
1916 $totalcostofsource += (float) $srcline->qty * (
float) $srcline->pa_ht;
1919 $pa_ht = ($totalhtofsource != 0 ? (float)
price2num($amount * $totalcostofsource / $totalhtofsource,
'MU') : 0);
1922 'amount' =>
'FixAmount',
1923 'variable' =>
'VarAmount'
1925 $descline =
'(DEPOSIT)';
1927 if ($typeamount ==
'amount') {
1928 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1929 } elseif ($typeamount ==
'variable') {
1930 $descline .=
' ('.$valuedeposit.
'%)';
1933 $descline .=
' - '.$srcobject->ref;
1946 isset($lines[$i]) ? $lines[$i]->info_bits : 0,
1952 isset($lines[$i]) ? $lines[$i]->special_code : 0,
1969 $diff =
$object->total_ttc - $amount_ttc_diff;
1973 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1974 $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);
1983 $lines = $srcobject->lines;
1984 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1985 $srcobject->fetch_lines();
1986 $lines = $srcobject->lines;
1991 if (is_array($lines)) {
1992 foreach ($lines as $line) {
1994 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuestandardinvoice / 100,
'MS');
2000 if (is_array($lines)) {
2001 foreach ($lines as $line) {
2003 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuedeposit / 100,
'MS');
2008 $fk_parent_line = 0;
2009 $num = count($lines);
2011 for ($i = 0; $i < $num; $i++) {
2012 if (!in_array($lines[$i]->
id, $selectedLines)) {
2017 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
2021 if (!isset(
$conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
2022 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
2024 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
2028 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
2029 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
2031 if (
$object->situation_counter == 1) {
2032 $lines[$i]->situation_percent = 0;
2035 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
2038 $desc = $label ? $label : $langs->trans(
'Discount');
2042 $discount->fk_soc =
$object->socid;
2043 $discount->socid =
$object->socid;
2044 $discount->amount_ht = abs($lines[$i]->total_ht);
2045 $discount->amount_tva = abs($lines[$i]->total_tva);
2046 $discount->amount_ttc = abs($lines[$i]->total_ttc);
2047 $discount->total_ht = abs($lines[$i]->total_ht);
2048 $discount->total_tva = abs($lines[$i]->total_tva);
2049 $discount->total_ttc = abs($lines[$i]->total_ttc);
2050 $discount->tva_tx = $lines[$i]->tva_tx;
2051 $discount->localtax1_tx = $lines[$i]->localtax1_tx;
2052 $discount->localtax2_tx = $lines[$i]->localtax2_tx;
2053 $discount->localtax1_type = $lines[$i]->localtax1_type;
2054 $discount->localtax2_type = $lines[$i]->localtax2_type;
2055 $discount->total_localtax1 = abs($lines[$i]->total_localtax1);
2056 $discount->total_localtax2 = abs($lines[$i]->total_localtax2);
2057 $discount->fk_user = $user->id;
2058 $discount->description = $desc;
2059 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
2060 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
2061 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
2062 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
2063 $discount->multicurrency_total_ht = abs($lines[$i]->multicurrency_total_ht);
2064 $discount->multicurrency_total_tva = abs($lines[$i]->multicurrency_total_tva);
2065 $discount->multicurrency_total_ttc = abs($lines[$i]->multicurrency_total_ttc);
2067 $discountid = $discount->create($user);
2068 if ($discountid > 0) {
2069 $result =
$object->insert_discount($discountid);
2082 if (isset($lines[$i]->date_debut_prevue)) {
2085 if (isset($lines[$i]->date_debut_reel)) {
2088 if (isset($lines[$i]->date_start)) {
2094 if (isset($lines[$i]->date_fin_prevue)) {
2095 $date_end = $lines[$i]->date_fin_prevue;
2097 if (isset($lines[$i]->date_fin_reel)) {
2098 $date_end = $lines[$i]->date_fin_reel;
2100 if (isset($lines[$i]->date_end)) {
2101 $date_end = $lines[$i]->date_end;
2105 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
2106 $fk_parent_line = 0;
2109 $array_options = array();
2111 if (method_exists($lines[$i],
'fetch_optionals')) {
2112 $lines[$i]->fetch_optionals();
2113 $array_options = $lines[$i]->array_options;
2116 $tva_tx = $lines[$i]->tva_tx;
2117 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
2118 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
2128 $lines[$i]->subprice,
2133 $lines[$i]->fk_product,
2134 $lines[$i]->remise_percent,
2138 (
int) $lines[$i]->info_bits,
2139 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except : null,
2144 $lines[$i]->special_code,
2148 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice : null,
2152 $lines[$i]->situation_percent ?? 100,
2153 $lines[$i]->fk_prev_id ?? 0,
2154 $lines[$i]->fk_unit,
2161 foreach (
$object->lines as $line) {
2162 if ($line->id == $result) {
2163 $line->extraparams = $lines[$i]->extraparams;
2164 $line->setExtraParameters();
2176 if ($result > 0 && $lines[$i]->product_type == 9) {
2177 $fk_parent_line = $result;
2189 $object->line_order(
true,
'DESC');
2217 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id,
'objFrom' => $srcobject);
2218 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
2231 for ($i = 1; $i <= $NBLINES; $i++) {
2237 $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);
2248 if (empty($dateinvoice)) {
2250 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
2260 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
2270 if (!empty($origin) && !empty($originid)) {
2271 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2274 $object->origin_type = $origin;
2275 $object->origin_id = $originid;
2279 $retained_warranty =
GETPOSTINT(
'retained_warranty');
2280 if (
price2num($retained_warranty) > 0) {
2284 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
2285 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
2288 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
2289 if (!empty($retained_warranty_date_limit) &&
$db->jdate($retained_warranty_date_limit)) {
2290 $object->retained_warranty_date_limit =
$db->jdate($retained_warranty_date_limit);
2292 $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);
2295 foreach (
$object->lines as $i => &$line) {
2296 $line->fk_prev_id = $line->id;
2297 $line->fetch_optionals();
2299 $line->situation_percent = 0;
2301 $line->situation_percent = $line->get_prev_progress(
$object->id);
2305 $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);
2306 $line->total_ht = (float) $tabprice[0];
2307 $line->total_tva = (float) $tabprice[1];
2308 $line->total_ttc = (float) $tabprice[2];
2309 $line->total_localtax1 = (float) $tabprice[9];
2310 $line->total_localtax2 = (float) $tabprice[10];
2311 $line->multicurrency_total_ht = (float) $tabprice[16];
2312 $line->multicurrency_total_tva = (float) $tabprice[17];
2313 $line->multicurrency_total_ttc = (float) $tabprice[18];
2316 if ($line->fk_remise_except) {
2318 $result = $discount->fetch($line->fk_remise_except);
2321 if ($discount->fk_facture_line > 0) {
2322 $line->fk_remise_except = 0;
2331 $object->date_pointoftax = $date_pointoftax;
2332 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2346 $object->situation_counter += 1;
2351 $extrafields->fetch_name_optionals_label(
$object->table_element);
2352 $extrafields->setOptionalsFromPost(
null, $object);
2359 $nextSituationInvoice->fetch($id);
2362 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id);
2363 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $nextSituationInvoice, $action);
2374 if ($id > 0 && !$error) {
2376 $categories =
GETPOST(
'categories',
'array');
2377 if (method_exists($object,
'setCategories')) {
2378 $object->setCategories($categories);
2386 $outputlangs = $langs;
2389 $newlang =
GETPOST(
'lang_id',
'aZ09');
2392 if (empty(
$object->thirdparty)) {
2395 $newlang =
$object->thirdparty->default_lang;
2397 if (!empty($newlang)) {
2399 $outputlangs->setDefaultLang($newlang);
2400 $outputlangs->load(
'products');
2405 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2411 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2416 $_GET[
"origin"] =
GETPOST(
"origin",
'alpha');
2420 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2424 foreach (
$object->lines as $line) {
2425 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2428 if ($line->product_type == 1) {
2429 $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);
2432 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2434 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2435 $vat_rate = str_replace(
'*',
'', $vat_rate);
2438 foreach (
$object->lines as $line) {
2439 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2442 $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);
2444 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2446 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2447 $remise_percent = str_replace(
'*',
'', $remise_percent);
2448 foreach (
$object->lines as $line) {
2449 if ($line->special_code == SUBTOTALS_SPECIAL_CODE || !empty($line->fk_remise_except)) {
2452 $tvatx = $line->tva_tx;
2453 if (!empty($line->vat_src_code)) {
2454 $tvatx .=
' ('.$line->vat_src_code.
')';
2456 $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);
2458 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
2461 $langs->load(
'subtotals');
2463 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
2464 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
2466 $subtotal_options = array();
2468 foreach (Facture::$TITLE_OPTIONS as $option) {
2469 $value =
GETPOST($option,
'alphanohtml');
2471 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2476 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2487 $outputlangs = $langs;
2488 $newlang =
GETPOST(
'lang_id',
'alpha');
2490 $newlang =
$object->thirdparty->default_lang;
2492 if (!empty($newlang)) {
2494 $outputlangs->setDefaultLang($newlang);
2497 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2502 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2504 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
2507 $langs->load(
'subtotals');
2509 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
2510 foreach (
$object->lines as $line) {
2511 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
2512 $desc = $line->desc;
2513 $depth = -$line->qty;
2517 $subtotal_options = array();
2519 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
2520 $value =
GETPOST($option,
'alphanohtml');
2522 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2527 if (isset($desc) && isset($depth)) {
2528 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2531 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
2540 $outputlangs = $langs;
2541 $newlang =
GETPOST(
'lang_id',
'alpha');
2543 $newlang =
$object->thirdparty->default_lang;
2545 if (!empty($newlang)) {
2547 $outputlangs->setDefaultLang($newlang);
2550 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2555 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2557 } elseif ($action ==
'addline' &&
GETPOST(
'updateallvatlinesblock',
'alpha') &&
GETPOST(
'vatforblocklines',
'alpha') !==
'' && $usercancreate) {
2558 $tx_tva =
GETPOST(
'vatforblocklines') ?
GETPOST(
'vatforblocklines') : 0;
2559 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'tva', $tx_tva);
2560 } elseif ($action ==
'addline' &&
GETPOST(
'updatealldiscountlinesblock',
'alpha') &&
GETPOST(
'discountforblocklines',
'alpha') !==
'' && $usercancreate) {
2561 $discount =
GETPOST(
'discountforblocklines') ?
GETPOST(
'discountforblocklines') : 0;
2562 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'discount', $discount);
2563 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && !
GETPOST(
'submitforallmark',
'alpha') && $usercancreate) {
2564 $langs->load(
'errors');
2572 $price_ht_devise =
'';
2574 $price_ttc_devise =
'';
2577 $price_min_ttc =
'';
2579 if (
GETPOST(
'price_ht') !==
'') {
2582 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2585 if (
GETPOST(
'price_ttc') !==
'') {
2588 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2589 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2592 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2593 if ($prod_entry_mode ==
'free') {
2599 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2604 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2608 if (empty($remise_percent)) {
2609 $remise_percent = 0;
2613 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2614 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2616 if (is_array($extralabelsline)) {
2618 foreach ($extralabelsline as $key => $value) {
2619 unset($_POST[
"options_".$key.$predef]);
2623 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2624 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2627 if (!$prod_entry_mode) {
2629 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2633 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2634 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2639 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0)
2640 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
2641 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
2642 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
2643 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
2644 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
2645 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2646 $langs->load(
"errors");
2647 if (
$object->type == $object::TYPE_DEPOSIT) {
2649 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2651 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2656 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
2657 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
2661 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
2662 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2666 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2670 $langs->load(
"errors");
2671 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2675 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2676 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
2680 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2681 $idprod = $res->fk_product_child;
2683 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2689 $price_base_type =
null;
2690 if (!$error && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
2696 $ret =
$object->fetch_thirdparty();
2701 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2712 if (!empty($idprod) && $idprod > 0) {
2714 $prod->fetch($idprod);
2723 $pu_ht = $datapriceofproduct[
'pu_ht'];
2724 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2725 $price_min = $datapriceofproduct[
'price_min'];
2726 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2727 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2731 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2732 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string)
$prod->tva_tx));
2736 if (!empty($price_ht) || $price_ht ===
'0') {
2738 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2739 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2740 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2741 $pu_ttc_devise = (float)
price2num((
float) $pu_ht_devise * (1 + ((float) $tmpvat / 100)),
'MU');
2744 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2746 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2747 } elseif (!empty($price_ttc_devise) || (
string) $price_ttc_devise ===
'0') {
2748 $pu_ttc_devise = (float)
price2num($price_ttc_devise,
'MU');
2749 $pu_ht_devise = (float)
price2num((
float) $pu_ttc_devise / (1 + ((float) $tmpvat / 100)),
'MU');
2752 } elseif ($tmpvat != $tmpprodvat) {
2754 if ($price_base_type !=
'HT') {
2755 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2757 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2761 $outputlangs = $langs;
2767 if (
GETPOST(
'lang_id',
'aZ09')) {
2768 $newlang =
GETPOST(
'lang_id',
'aZ09');
2770 if (empty($newlang)) {
2771 $newlang =
$object->thirdparty->default_lang;
2773 if (!empty($newlang)) {
2775 $outputlangs->setDefaultLang($newlang);
2776 $outputlangs->load(
'products');
2779 $desc = (!empty(
$prod->multilangs [$outputlangs->defaultlang] [
"description"])) ?
$prod->multilangs [$outputlangs->defaultlang] [
"description"] :
$prod->
description;
2781 $desc =
$prod->description;
2797 if (!empty(
$prod->customcode)) {
2798 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomsCode").
': '.
$prod->customcode;
2800 if (!empty(
$prod->customcode) && !empty(
$prod->country_code)) {
2803 if (!empty(
$prod->country_code)) {
2804 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry(
$prod->country_code,
'',
$db, $outputlangs, 0);
2807 if (!empty(
$prod->customcode)) {
2808 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomsCode").
': '.
$prod->customcode;
2810 if (!empty(
$prod->customcode) && !empty(
$prod->country_code)) {
2813 if (!empty(
$prod->country_code)) {
2814 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry(
$prod->country_code,
'',
$db, $langs, 0);
2821 $type =
$prod->type;
2822 $fk_unit =
$prod->fk_unit;
2824 if (!empty($price_ht)) {
2829 if (!empty($price_ttc)) {
2834 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2835 $tva_tx = str_replace(
'*',
'', $tva_tx);
2836 if (empty($tva_tx)) {
2839 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2842 $fk_unit =
GETPOST(
'units',
'alpha');
2844 if ($pu_ttc && !$pu_ht) {
2845 $price_base_type =
'TTC';
2859 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2860 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2863 $pu_equivalent = $pu_ht;
2864 $pu_equivalent_ttc = $pu_ttc;
2866 $currency_tx =
$object->multicurrency_tx;
2870 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
2871 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
2873 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
2874 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
2889 $fournprice = (int) (
GETPOST(
'fournprice'.$predef) ?
GETPOST(
'fournprice'.$predef) :
'');
2894 $price2num_remise_percent =
price2num($remise_percent);
2895 $price2num_price_min =
price2num($price_min);
2896 $price2num_price_min_ttc =
price2num($price_min_ttc);
2897 if (empty($price2num_pu_ht)) {
2898 $price2num_pu_ht = 0;
2900 if (empty($price2num_remise_percent)) {
2901 $price2num_remise_percent = 0;
2903 if (empty($price2num_price_min)) {
2904 $price2num_price_min = 0;
2906 if (empty($price2num_price_min_ttc)) {
2907 $price2num_price_min_ttc = 0;
2912 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2913 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2916 } 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') {
2917 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2938 $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);
2945 $outputlangs = $langs;
2948 $newlang =
GETPOST(
'lang_id',
'aZ09');
2951 $newlang =
$object->thirdparty->default_lang;
2953 if (!empty($newlang)) {
2955 $outputlangs->setDefaultLang($newlang);
2956 $outputlangs->load(
'products');
2959 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2965 unset($_POST[
'prod_entry_mode']);
2966 unset($_POST[
'qty']);
2967 unset($_POST[
'type']);
2968 unset($_POST[
'remise_percent']);
2969 unset($_POST[
'price_ht']);
2970 unset($_POST[
'multicurrency_price_ht']);
2971 unset($_POST[
'price_ttc']);
2972 unset($_POST[
'tva_tx']);
2973 unset($_POST[
'product_ref']);
2974 unset($_POST[
'product_label']);
2975 unset($_POST[
'product_desc']);
2976 unset($_POST[
'fournprice']);
2977 unset($_POST[
'buying_price']);
2978 unset($_POST[
'np_marginRate']);
2979 unset($_POST[
'np_markRate']);
2980 unset($_POST[
'dp_desc']);
2981 unset($_POST[
'idprod']);
2982 unset($_POST[
'units']);
2983 unset($_POST[
'date_starthour']);
2984 unset($_POST[
'date_startmin']);
2985 unset($_POST[
'date_startsec']);
2986 unset($_POST[
'date_startday']);
2987 unset($_POST[
'date_startmonth']);
2988 unset($_POST[
'date_startyear']);
2989 unset($_POST[
'date_endhour']);
2990 unset($_POST[
'date_endmin']);
2991 unset($_POST[
'date_endsec']);
2992 unset($_POST[
'date_endday']);
2993 unset($_POST[
'date_endmonth']);
2994 unset($_POST[
'date_endyear']);
2995 unset($_POST[
'situations']);
2996 unset($_POST[
'progress']);
3004 } elseif ($action ==
'addline' && $usercancreate && (
3005 (
GETPOST(
'submitforallmargins',
'alpha') &&
GETPOST(
'marginforalllines',
'alpha') !==
'') ||
3006 (
GETPOST(
'submitforallmark',
'alpha') &&
GETPOST(
'markforalllines',
'alpha') !==
'')
3009 $margin_rate =
GETPOSTISSET(
'marginforalllines') ?
GETPOST(
'marginforalllines',
'int') :
'';
3011 foreach (
$object->lines as &$line) {
3012 if ($line->subprice > 0) {
3013 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
3016 $subprice_multicurrency = $line->subprice;
3017 if (is_numeric($margin_rate) && $margin_rate > 0) {
3018 $line->subprice = (float)
price2num((
float) $line->pa_ht * (1 + (float) $margin_rate / 100),
'MU');
3019 } elseif (is_numeric($mark_rate) && $mark_rate > 0) {
3020 $line->subprice = (float) ($line->pa_ht / (1 - ((
float) $mark_rate / 100)));
3022 $line->subprice = (float) $line->pa_ht;
3025 if ($line->fk_product > 0) {
3027 $res =
$prod->fetch($line->fk_product);
3029 if (
$prod->price_min > $line->subprice) {
3030 $price_subprice =
price($line->subprice, 0, $outlangs, 1, -1, -1,
'auto');
3031 $price_price_min =
price(
$prod->price_min, 0, $outlangs, 1, -1, -1,
'auto');
3032 setEventMessages(
$prod->ref .
' - ' .
$prod->label .
' (' . $price_subprice .
' < ' . $price_price_min .
' ' . strtolower($langs->trans(
"MinPrice")) .
')' .
"\n",
null,
'warnings');
3041 $multicurrency_subprice = (float) $line->subprice * $line->multicurrency_subprice / $subprice_multicurrency;
3043 $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);
3046 if (is_numeric($margin_rate) && empty($mark_rate)) {
3047 $line->marge_tx = $margin_rate;
3048 } elseif (is_numeric($mark_rate) && empty($margin_rate)) {
3049 $line->marque_tx = $mark_rate;
3051 $line->total_ht = $line->qty * (float) $line->subprice;
3052 $line->total_tva = $line->tva_tx * $line->qty * (float) $line->subprice;
3053 $line->total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $line->subprice;
3055 $line->multicurrency_total_ht = $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
3056 $line->multicurrency_total_tva = $line->tva_tx * $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
3057 $line->multicurrency_total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
3059 $line->multicurrency_subprice = $multicurrency_subprice;
3065 } elseif ($action ==
'updatetitleline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3068 $langs->load(
'subtotals');
3070 $desc =
GETPOST(
'line_desc',
'alphanohtml') ?? $langs->trans(
"Title");
3073 $subtotal_options = array();
3075 foreach (Facture::$TITLE_OPTIONS as $option) {
3076 $value =
GETPOST($option,
'alphanohtml');
3078 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
3083 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3094 $outputlangs = $langs;
3095 $newlang =
GETPOST(
'lang_id',
'alpha');
3097 $newlang =
$object->thirdparty->default_lang;
3099 if (!empty($newlang)) {
3101 $outputlangs->setDefaultLang($newlang);
3104 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3109 } elseif ($action ==
'updatesubtotalline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3112 $langs->load(
'subtotals');
3114 $desc =
GETPOST(
'line_desc',
'alphanohtml');
3117 $subtotal_options = array();
3119 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
3120 $value =
GETPOST($option,
'alphanohtml');
3122 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
3127 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3135 $outputlangs = $langs;
3136 $newlang =
GETPOST(
'lang_id',
'alpha');
3138 $newlang =
$object->thirdparty->default_lang;
3140 if (!empty($newlang)) {
3142 $outputlangs->setDefaultLang($newlang);
3145 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3150 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3151 if (!
$object->fetch($id) > 0) {
3174 if (preg_match(
'/\*/', $vat_rate)) {
3179 $vat_rate = str_replace(
'*',
'', $vat_rate);
3184 $fournprice = (int) (
GETPOST(
'fournprice') ?
GETPOST(
'fournprice') :
'');
3188 $pu_equivalent = $pu_ht;
3189 $pu_equivalent_ttc = $pu_ttc;
3191 $currency_tx =
$object->multicurrency_tx;
3195 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3196 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
3198 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3199 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
3214 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
3215 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
3217 if (is_array($extralabelsline)) {
3219 foreach ($extralabelsline as $key => $value) {
3220 unset($_POST[
"options_".$key]);
3226 if ($special_code == 3) {
3232 $percent = $line->get_prev_progress(
$object->id);
3237 if ($progress >= 0) {
3238 $mesg = $langs->trans(
"CantBeNullOrPositive");
3242 } elseif ($progress < $line->situation_percent) {
3243 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
3247 } elseif ($progress < $percent) {
3248 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
3256 if (empty($remise_percent)) {
3257 $remise_percent = 0;
3260 $price_base_type =
'HT';
3262 if (empty($pu) && !empty($pu_ttc)) {
3264 $price_base_type =
'TTC';
3269 if (!empty($productid)) {
3271 $product->fetch($productid);
3273 $type = $product->type;
3275 $price_min = $product->price_min;
3277 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
3279 $price_min_ttc = $product->price_min_ttc;
3281 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
3288 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
3289 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3292 $action =
'editline';
3293 } 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') {
3294 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3297 $action =
'editline';
3302 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
3306 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
3311 $langs->load(
"errors");
3312 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
3316 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
3317 $langs->load(
"errors");
3318 if (
$object->type == $object::TYPE_DEPOSIT) {
3320 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
3322 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
3326 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
3333 $previousprogress = $line->getAllPrevProgress($line->fk_facture);
3336 if ($fullprogress < $previousprogress) {
3338 setEventMessages($langs->trans(
'CantBeLessThanMinPercent'),
null,
'errors');
3342 if ($fullprogress > 100) {
3343 $fullprogress = 100;
3345 $addprogress = $fullprogress - $previousprogress;
3352 if (empty($usercancreatemargin)) {
3353 foreach (
$object->lines as &$line) {
3355 $fournprice = $line->fk_fournprice;
3356 $buyingprice = $line->pa_ht;
3362 $result =
$object->updateline(
3367 (
float) $remise_percent,
3385 (
float) $pu_ht_devise
3393 $outputlangs = $langs;
3396 $newlang =
GETPOST(
'lang_id',
'aZ09');
3399 $newlang =
$object->thirdparty->default_lang;
3401 if (!empty($newlang)) {
3403 $outputlangs->setDefaultLang($newlang);
3404 $outputlangs->load(
'products');
3406 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3409 unset($_POST[
'qty']);
3410 unset($_POST[
'type']);
3411 unset($_POST[
'productid']);
3412 unset($_POST[
'remise_percent']);
3413 unset($_POST[
'price_ht']);
3414 unset($_POST[
'multicurrency_price_ht']);
3415 unset($_POST[
'price_ttc']);
3416 unset($_POST[
'tva_tx']);
3417 unset($_POST[
'product_ref']);
3418 unset($_POST[
'product_label']);
3419 unset($_POST[
'product_desc']);
3420 unset($_POST[
'fournprice']);
3421 unset($_POST[
'buying_price']);
3422 unset($_POST[
'np_marginRate']);
3423 unset($_POST[
'np_markRate']);
3424 unset($_POST[
'dp_desc']);
3425 unset($_POST[
'idprod']);
3426 unset($_POST[
'units']);
3427 unset($_POST[
'date_starthour']);
3428 unset($_POST[
'date_startmin']);
3429 unset($_POST[
'date_startsec']);
3430 unset($_POST[
'date_startday']);
3431 unset($_POST[
'date_startmonth']);
3432 unset($_POST[
'date_startyear']);
3433 unset($_POST[
'date_endhour']);
3434 unset($_POST[
'date_endmin']);
3435 unset($_POST[
'date_endsec']);
3436 unset($_POST[
'date_endday']);
3437 unset($_POST[
'date_endmonth']);
3438 unset($_POST[
'date_endyear']);
3439 unset($_POST[
'situations']);
3440 unset($_POST[
'progress']);
3445 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOSTISSET(
'all_percent')) {
3446 if (!
$object->fetch($id) > 0) {
3449 if (
GETPOST(
'all_progress') !=
"") {
3451 if ($all_progress > 100) {
3452 $all_progress = 100;
3455 foreach (
$object->lines as $line) {
3457 $percent = $line->getAllPrevProgress(
$object->id);
3459 $percent = $line->get_prev_progress(
$object->id);
3461 if (
$object->type != $object::TYPE_CREDIT_NOTE && (
float) $all_progress < (
float) $percent) {
3462 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
3465 } elseif (
$object->type == $object::TYPE_CREDIT_NOTE && (
float) $all_progress > (
float) $percent) {
3466 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeMoreThanMinPercent");
3470 $object->update_percent($line, $all_progress,
false);
3475 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
3476 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
3478 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
3480 $object->fetch($id,
'',
'', 0,
true);
3483 &&
$object->isSituationInvoice()
3486 &&
$object->is_last_in_cycle()
3487 && $usercanunvalidate
3490 $newCycle =
$object->newCycle();
3491 if ($newCycle > 1) {
3493 $lastCycle =
$object->situation_cycle_ref;
3494 $lastSituationCounter =
$object->situation_counter;
3495 $linkedCreditNotesList = array();
3497 if (count(
$object->tab_next_situation_invoice) > 0) {
3498 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
3500 && $next_invoice->situation_counter ==
$object->situation_counter
3501 && $next_invoice->fk_facture_source ==
$object->id
3503 $linkedCreditNotesList[] = $next_invoice->id;
3508 $object->situation_cycle_ref = $newCycle;
3509 $object->situation_counter = 1;
3511 if (
$object->update($user) > 0) {
3513 if (count($linkedCreditNotesList) > 0) {
3515 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
3516 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
3517 $sql .=
' , situation_final=0';
3518 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
3519 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
3521 $resql =
$db->query($sql);
3527 foreach (
$object->lines as $line) {
3529 if ($line->product_type == 9) {
3534 if (!empty(
$object->tab_previous_situation_invoice)) {
3536 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
3537 $searchPreviousInvoice =
true;
3538 while ($searchPreviousInvoice) {
3539 if (
$object->tab_previous_situation_invoice[$lineIndex]->isSituationInvoice() || $lineIndex < 1) {
3540 $searchPreviousInvoice =
false;
3548 $maxPrevSituationPercent = 0;
3549 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
3550 if ($prevLine->id == $line->fk_prev_id) {
3551 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
3556 $line->situation_percent -= $maxPrevSituationPercent;
3558 if ($line->update() < 0) {
3567 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
3569 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
3572 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
3575 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
3581 $fromElement =
GETPOST(
'fromelement');
3582 $fromElementid =
GETPOSTINT(
'fromelementid');
3583 $importLines =
GETPOST(
'line_checkbox');
3585 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
3586 $lineClassName =
'';
3587 $lineParentField =
'';
3588 if ($fromElement ==
'commande') {
3590 $lineClassName =
'OrderLine';
3591 $lineParentField =
'fk_commande';
3592 } elseif ($fromElement ==
'propal') {
3593 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
3594 $lineClassName =
'PropaleLigne';
3595 $lineParentField =
'fk_propal';
3597 $nextRang = count(
$object->lines) + 1;
3601 $fromElementAllowed = ($lineParentField && $fromElementid > 0 &&
restrictedArea($user, $fromElement, $fromElementid,
'',
'',
'fk_soc',
'rowid', 0, 1));
3602 foreach ($importLines as $lineId) {
3603 if ($lineClassName ===
'') {
3607 dol_syslog(
'compta/facture/card - No lineClassName - skip import', LOG_ERR);
3614 $lineId = intval($lineId);
3615 $originLine =
new $lineClassName(
$db);
3616 if ($fromElementAllowed && $originLine->fetch($lineId) > 0 && $originLine->$lineParentField == $fromElementid) {
3617 $originLine->fetch_optionals();
3618 $desc = $originLine->desc;
3619 $pu_ht = $originLine->subprice;
3620 $qty = $originLine->qty;
3621 $txtva = $originLine->tva_tx;
3622 $txlocaltax1 = $originLine->localtax1_tx;
3623 $txlocaltax2 = $originLine->localtax2_tx;
3624 $fk_product = $originLine->fk_product;
3625 $remise_percent = $originLine->remise_percent;
3627 $date_end = $originLine->date_end;
3628 $fk_code_ventilation = 0;
3629 $info_bits = $originLine->info_bits;
3630 $fk_remise_except = $originLine->fk_remise_except;
3631 $price_base_type =
'HT';
3633 $type = $originLine->product_type;
3634 $rang = $nextRang++;
3635 $special_code = $originLine->special_code;
3636 $origin = $originLine->element;
3637 $origin_id = $originLine->id;
3638 $fk_parent_line = 0;
3639 $fk_fournprice = $originLine->fk_fournprice;
3640 $pa_ht = $originLine->pa_ht;
3641 $label = $originLine->label;
3642 $array_options = $originLine->array_options;
3643 if (
$object->isSituationInvoice()) {
3644 $situation_percent = 0;
3646 $situation_percent = 100;
3649 $fk_unit = $originLine->fk_unit;
3650 $pu_ht_devise = $originLine->multicurrency_subprice;
3652 $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);
3672 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3678 if (!empty(
$object->id) && $action ==
'send') {
3680 $object->getSommePaiement(-1);
3681 $object->getSumCreditNotesUsed(-1);
3682 $object->getSumDepositsUsed(-1);
3684 $triggersendname =
'BILL_SENTBYMAIL';
3686 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3687 $trackid =
'inv'.$object->id;
3688 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3692 $permissiontoadd = $usercancreate;
3693 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3696 if ($action ==
'update_extras' && $permissiontoeditextra) {
3699 $attribute_name =
GETPOST(
'attribute',
'aZ09');
3702 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
3709 $result =
$object->updateExtraField($attribute_name,
'BILL_MODIFY');
3717 $action =
'edit_extras';
3722 if ($action ==
'addcontact' && $usercancreate) {
3723 $result =
$object->fetch($id);
3725 if ($result > 0 && $id > 0) {
3728 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3732 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3735 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3736 $langs->load(
"errors");
3737 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3742 } elseif ($action ==
'swapstatut' && $usercancreate) {
3749 } elseif ($action ==
'deletecontact' && $usercancreate) {
3752 $result =
$object->delete_contact($lineid);
3755 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3763 $action =
'edit_extras';
3787$title =
$object->ref.
" - ".$langs->trans(
'Card');
3788if ($action ==
'create') {
3789 $title = $langs->trans(
"NewBill");
3791$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3797if ($action ==
'create') {
3799 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3804 $res = $soc->fetch($socid);
3807 $currency_code =
$conf->currency;
3809 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3810 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3814 if (empty($dateinvoice)) {
3820 if (!empty($origin) && !empty($originid)) {
3822 $element = $subelement = $origin;
3824 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3825 $element = $regs[1];
3826 $subelement = $regs[2];
3831 if ($element ==
'project') {
3832 $projectid = $originid;
3834 if (empty($cond_reglement_id)) {
3835 $cond_reglement_id = $soc->cond_reglement_id;
3837 if (empty($mode_reglement_id)) {
3838 $mode_reglement_id = $soc->mode_reglement_id;
3840 if (empty($fk_account)) {
3841 $fk_account = $soc->fk_account;
3845 if ($element ==
'order' || $element ==
'commande') {
3846 $element = $subelement =
'commande';
3848 if ($element ==
'propal') {
3849 $element =
'comm/propal';
3850 $subelement =
'propal';
3852 if ($element ==
'contract') {
3853 $element = $subelement =
'contrat';
3855 if ($element ==
'shipping') {
3856 $element = $subelement =
'expedition';
3861 $classname = ucfirst($subelement);
3862 $objectsrc =
new $classname(
$db);
3863 '@phan-var-force Commande|Propal|Contrat|Expedition|Facture $objectsrc';
3865 $objectsrc->fetch($originid);
3866 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3867 $objectsrc->fetch_lines();
3869 $objectsrc->fetch_thirdparty();
3871 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3877 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3881 if (empty($socid)) {
3882 $soc = $objectsrc->thirdparty;
3885 if ($element ==
'expedition') {
3886 $elem = $subelem = $objectsrc->origin_type;
3887 $expeoriginid = $objectsrc->origin_id;
3889 $classname = ucfirst($subelem);
3891 $expesrc =
new $classname(
$db);
3892 '@phan-var-force Expedition $expesrc';
3894 dol_syslog(
"Is type Facture|Commande or Expedition: $element...expesrc($classname)=".get_class($expesrc));
3895 $expesrc->fetch($expeoriginid);
3897 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3898 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3899 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3902 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3903 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3907 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3910 $expesrc->fetch_optionals();
3911 $object->array_options = $expesrc->array_options;
3913 $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)));
3914 $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)));
3915 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : (!empty($fk_account) ? $fk_account : 0)));
3918 if (!empty($objectsrc->multicurrency_code)) {
3919 $currency_code = $objectsrc->multicurrency_code;
3921 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
3922 $currency_tx = $objectsrc->multicurrency_tx;
3927 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3930 $objectsrc->fetch_optionals();
3931 $object->array_options = $objectsrc->array_options;
3935 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
3936 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
3937 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
3938 $inputReasonId = empty($soc->demand_reason_id) ? $inputReasonId : $soc->demand_reason_id;
3940 if (
isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3941 $currency_code = $soc->multicurrency_code;
3946 if (!
GETPOST(
'changecompany')) {
3948 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3951 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3959 if (empty($cond_reglement_id)) {
3960 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
3964 if (empty($mode_reglement_id)) {
3965 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
3975 if (!empty($soc->id)) {
3976 $absolute_discount = $soc->getAvailableDiscounts();
3978 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
3979 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
3981 if (!empty(
$conf->use_javascript_ajax)) {
3982 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3988 if ($origin ==
'contrat') {
3989 $langs->load(
"admin");
3990 $text = $langs->trans(
"ToCreateARecurringInvoice");
3991 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3993 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3995 print
info_admin($text, 0, 0,
'info',
'').
'<br>';
3998 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3999 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4000 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
4001 print
'<input type="hidden" name="changecompany" value="0">';
4003 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
4005 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4006 print
'<input name="ref" type="hidden" value="provisoire">';
4007 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
4008 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
4009 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
4010 print
'<input name="force_fk_account" type="hidden" value="0">';
4011 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
4012 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
4013 print
'<input type="hidden" name="originentity" value="'.GETPOSTINT(
'originentity').
'">';
4014 if (!empty($currency_tx)) {
4015 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
4021 $parameters = array();
4023 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters, $object, $action);
4024 if (empty($reshook)) {
4025 print
'<table class="border centpercent">';
4029 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
4030 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
4043 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
4045 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
'Customer').
'</td>';
4046 print
'<td colspan="2">';
4047 print $soc->getNomUrl(1,
'customer');
4048 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
4050 $arrayoutstandingbills = $soc->getOutstandingBills();
4051 $outstandingBills = $arrayoutstandingbills[
'opened'];
4052 print
' - <span class="opacitymedium valignmiddle">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
4053 print
'<span class="amount valignmiddle">'.price($outstandingBills, 0, $langs, 0, 0, -1,
$conf->currency).
'</span>';
4054 if ($soc->outstanding_limit !=
'') {
4055 if ($outstandingBills > $soc->outstanding_limit) {
4056 print
img_warning($langs->trans(
"OutstandingBillReached"));
4058 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1,
$conf->currency);
4063 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
4064 print
'<td colspan="2">';
4065 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
4066 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
4070 $(document).ready(function() {
4071 $("#socid").change(function() {
4073 console.log("Submit page");
4074 $(\'input[name="action"]\').val(\'create\');
4075 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
4076 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
4077 $(\'input[name="force_fk_account"]\').val(\'1\');
4078 $("#formtocreate").submit(); */
4080 // For company change, we must submit page with action=create instead of action=add
4081 console.log("We have changed the company - Resubmit page");
4082 jQuery("input[name=changecompany]").val("1");
4083 jQuery("#formtocreateaction").val("create");
4084 jQuery("#formtocreate").submit();
4090 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>';
4097 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
4099 foreach ($invoice_predefined->array_options as $key => $option) {
4100 if (!isset(
$object->array_options[$key])) {
4101 $object->array_options[$key] = $invoice_predefined->array_options[$key];
4105 $dateinvoice = $invoice_predefined->date_when;
4106 if (empty($projectid)) {
4107 $projectid = $invoice_predefined->fk_project;
4109 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
4110 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
4111 $fk_account = $invoice_predefined->fk_account;
4112 $note_public = $invoice_predefined->note_public;
4113 $note_private = $invoice_predefined->note_private;
4115 if (!empty($invoice_predefined->multicurrency_code)) {
4116 $currency_code = $invoice_predefined->multicurrency_code;
4118 if (!empty($invoice_predefined->multicurrency_tx)) {
4119 $currency_tx = $invoice_predefined->multicurrency_tx;
4122 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
4123 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
4124 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
4126 $resql =
$db->query($sql);
4128 $num =
$db->num_rows($resql);
4132 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
4134 print
'<select class="flat" id="fac_rec" name="fac_rec">';
4135 print
'<option value="0" selected></option>';
4137 $objp =
$db->fetch_object($resql);
4138 print
'<option value="'.$objp->rowid.
'"';
4141 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
4143 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
4152 print
'<script type="text/javascript">
4153 $(document).ready(function() {
4154 $("#fac_rec").change(function() {
4155 console.log("We have changed the template invoice - Reload page");
4156 var fac_rec = $(this).val();
4157 var socid = $(\'#socid\').val();
4158 // 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.
4159 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
4172 print
'<tr><td class="tdtop fieldrequired titlefieldcreate">'.$langs->trans(
'Type').
'</td><td colspan="2">';
4173 print
'<div class="listofinvoicetypetable">'.
"\n";
4176 print
'<div class="listofinvoicetype"><div class="">';
4177 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
4178 $tmp .=
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk");
4179 $tmp .=
' <span class="opacitymedium">'.$langs->trans(
"InvoiceStandardAsk2").
'</span>';
4182 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc").
'<br><br>'.$langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'nowraponall', 0, 3,
'standardonsmartphone');
4184 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
4194 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%') .
'"/>';
4197 print
'</div></div>'.
"\n";
4199 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
4202 print
'<div class="listofinvoicetype"><div class="">';
4203 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
4204 print
'<script type="text/javascript">
4205 jQuery(document).ready(function() {
4206 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
4207 jQuery("#radio_standard").prop("checked", true);
4209 jQuery("#typedeposit, #valuedeposit").click(function() {
4210 jQuery("#radio_deposit").prop("checked", true);
4212 jQuery("#typedeposit").change(function() {
4213 console.log("We change type of down payment: "+jQuery("#typedeposit").val());
4215 if (jQuery("#typedeposit").val() == "amount") {
4216 jQuery("#valuedeposit").attr("placeholder", "'.$langs->getCurrencySymbol(
$conf->currency).
'");
4217 jQuery("#valuedeposit").val("");
4219 jQuery("#valuedeposit").attr("placeholder", "50%");
4220 jQuery("#valuedeposit").val("");
4223 jQuery("#radio_deposit").prop("checked", true);
4224 setRadioForTypeOfInvoice();
4226 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
4227 setRadioForTypeOfInvoice();
4230 function setRadioForTypeOfInvoice() {
4231 console.log("Change radio for type of invoice");
4232 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
4233 jQuery("#checkforselects").prop("disabled", true);
4234 jQuery("#checkforselects").prop("checked", false);
4235 jQuery(".checkforselect").prop("disabled", true);
4236 jQuery(".checkforselect").prop("checked", false);
4238 jQuery("#checkforselects").prop("disabled", false);
4239 jQuery("#checkforselects").prop("checked", true);
4240 jQuery(".checkforselect").prop("disabled", false);
4241 jQuery(".checkforselect").prop("checked", true);
4247 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
4249 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
4251 if (($origin ==
'propal') || ($origin ==
'commande')) {
4254 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
4255 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
4256 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4260 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4264 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
4266 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
4267 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
4268 if (!empty($origin_payment_conditions_deposit_percent)) {
4269 $typedeposit =
'variable';
4272 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
4273 $valuedeposit = $objectsrc->deposit_percent;
4275 print
'<span class="marginleftonly">'.$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1).
'</span>';
4277 print
'<input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.($valuedeposit ? $valuedeposit :
'').
'"'.($valuedeposit ?
'' :
'placeholder="'.$langs->getCurrencySymbol(
$conf->currency).
'"').
'>';
4280 print
'</div></div>'.
"\n";
4287 print
'<div class="listofinvoicetype"><div class="">';
4288 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
4289 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
4291 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
4295 $opt = $form->selectSituationInvoices((
string)
GETPOSTINT(
'originid'), $socid);
4298 print
'</div></div><div class="listofinvoicetype"><div>';
4300 $tmp =
'<input id="radio_situation_bis" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
4301 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4302 $tmp .=
' disabled';
4305 $text = $tmp.
'<label for="radio_situation_bis">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4307 $text .=
'<select class="flat minwidth125" id="situations" name="situations"';
4308 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4309 $text .=
' disabled';
4313 $text .=
'</select>';
4314 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
4316 print
'</div></div>'.
"\n";
4322 $facids = $facturestatic->list_replacable_invoices($soc->id);
4328 if (is_array($facids)) {
4329 foreach ($facids as $facparam) {
4330 $options .=
'<option value="'.$facparam [
'id'].
'"';
4331 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
4332 $options .=
' selected';
4334 $options .=
'>'.$facparam[
'ref'];
4335 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
4336 $options .=
'</option>';
4340 print
'<!-- replacement line -->';
4341 print
'<div class="listofinvoicetype"><div class="">';
4342 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
4343 if (!$options || $invoice_predefined->id > 0) {
4344 $tmp .=
' disabled';
4347 print
'<script type="text/javascript">
4348 jQuery(document).ready(function() {
4349 jQuery("#fac_replacement").change(function() {
4350 console.log("We change fac_replacement");
4351 jQuery("#radio_replacement").prop("checked", true);
4355 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
4356 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
4357 if (!$options || $invoice_predefined->id > 0) {
4358 $text .=
' disabled';
4362 $text .=
'<option value="-1"> </option>';
4365 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
4367 $text .=
'</select>';
4368 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
4370 print
'</div></div>'.
"\n";
4374 print
'<div class="listofinvoicetype"><div class="">';
4375 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
4376 $text = $tmp.
'<label class="opacitymedium">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4377 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'firstsituationonsmartphone');
4379 print
'</div></div>'.
"\n";
4382 print
'<div class="listofinvoicetype"><div class="">';
4383 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
4384 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
4385 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'replacementonsmartphone');
4387 print
'</div></div>'.
"\n";
4390 if (empty($origin)) {
4395 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
4402 foreach ($facids as $key => $valarray) {
4403 $newinvoice_static->id = $key;
4404 $newinvoice_static->ref = $valarray [
'ref'];
4405 $newinvoice_static->statut = $valarray [
'status'];
4406 $newinvoice_static->status = $valarray [
'status'];
4407 $newinvoice_static->type = $valarray [
'type'];
4408 $newinvoice_static->paye = $valarray [
'paye'];
4409 $newinvoice_static->paid = $valarray [
'paye'];
4411 $optionsav .=
'<option value="'.$key.
'"';
4412 if ($key ==
GETPOST(
'fac_avoir')) {
4413 $optionsav .=
' selected';
4416 $newinvoice_static->fetch_optionals($key);
4417 $object->array_options = $newinvoice_static->array_options;
4420 $optionsav .= $newinvoice_static->ref;
4421 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
4422 $optionsav .=
'</option>';
4425 print
'<div class="listofinvoicetype"><div class="">';
4426 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
4427 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
4428 $tmp .=
' disabled';
4432 print
'<script type="text/javascript">
4433 jQuery(document).ready(function() {
4434 if (jQuery("#radio_creditnote").is(":checked")) {
4435 jQuery("#radio_standard").prop("disabled", true);
4436 jQuery("#radio_deposit").prop("disabled", true);
4438 jQuery("#radio_standard").prop("disabled", false);
4439 jQuery("#radio_deposit").prop("disabled", false);
4441 if (! jQuery("#radio_creditnote").is(":checked")) {
4442 jQuery("#credit_note_options").hide();
4444 jQuery("#radio_creditnote").click(function() {
4445 jQuery("#credit_note_options").show();
4447 jQuery("#radio_standard, #radio_replacement, #radio_deposit, #radio_situation, #radio_situation_bis").click(function() {
4448 console.log("We click on a radio to close credit not options");
4449 jQuery("#credit_note_options").hide();
4453 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
4454 $text .=
'<select class="flat valignmiddle minwidth200" name="fac_avoir" id="fac_avoir"';
4455 if (!$optionsav || $invoice_predefined->id > 0) {
4456 $text .=
' disabled';
4460 $text .=
'<option value="-1">'.$langs->trans(
"InvoiceAvoirAskCombo").
'</option>';
4461 $text .= $optionsav;
4463 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
4465 $text .=
'</select>';
4466 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
4469 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
4470 print
'<div class="marginleftlargeondesktop"><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>";
4471 print
'<div class="marginleftlargeondesktop"><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>";
4476 print
'</div></div>'.
"\n";
4479 print
'<div class="listofinvoicetype"><div class="">';
4481 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
4483 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
4485 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
4487 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
4489 print
'</div></div>'.
"\n";
4510 foreach ($listtType as $type) {
4511 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
4513 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
4516 print
'<script type="text/javascript">
4517 $(document).ready(function() {
4518 var listType = {'.$jsListType.
'};
4519 $("[name=\'type\']").change(function() {
4520 console.log("change name=type");
4521 if ($( this ).prop("checked"))
4523 if(($( this ).val() in listType))
4525 $("#model").val(listType[$( this ).val()]).trigger("change");
4542 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
4543 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
4549 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
4553 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
4556 $defaulttpldir =
'/core/tpl';
4557 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array($defaulttpldir));
4558 foreach ($dirtpls as $module => $reldir) {
4560 if (!empty($module)) {
4563 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
4565 if (file_exists($tpl)) {
4566 if (empty(
$conf->file->strict_mode)) {
4567 $res = @include $tpl;
4569 $res = include $tpl;
4584 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
4585 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4586 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
4591 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
4592 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4593 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
4598 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
4599 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
4600 print $form->getSelectConditionsPaiements((
int) $cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
4605 $rwStyle =
'display:none;';
4606 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
4610 $retained_warranty =
GETPOSTINT(
'retained_warranty');
4611 if (empty($retained_warranty)) {
4612 if ($objectsrc !==
null && property_exists($objectsrc,
'retained_warranty') && !empty($objectsrc->retained_warranty)) {
4614 $retained_warranty = $objectsrc->retained_warranty;
4617 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
4619 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
4620 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
4623 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
4624 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
4625 if (empty($retained_warranty_fk_cond_reglement)) {
4626 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4627 if ($objectsrc instanceOf
Facture && !empty($objectsrc->retained_warranty_fk_cond_reglement)) {
4629 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
4632 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4635 print
'<script type="text/javascript">
4636 $(document).ready(function() {
4637 $("[name=\'type\']").change(function() {
4638 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
4640 $(".retained-warranty-line").show();
4641 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
4644 $(".retained-warranty-line").hide();
4645 $("#new-situation-invoice-retained-warranty").val("");
4649 $("[name=\'type\']:checked").trigger("change");
4655 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
4656 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
4657 print $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth250 widthcentpercentminusx', 1);
4662 print
'<tr><td>'.$langs->trans(
'DefaultBankAccount').
'</td><td colspan="2">';
4663 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4664 print $form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth250 widthcentpercentminusx', 1);
4670 print
'<tr><td>'.$langs->trans(
'Source').
'</td><td>';
4671 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
4672 $form->selectInputReason((
string) $inputReasonId,
'input_reason_id',
'', 1,
'maxwidth250 widthcentpercentminusx');
4675 print
'<input type="hidden" name="input_reason_id" value="'.((string) $inputReasonId).
'">';
4679 if (
isModEnabled(
'project') && is_object($formproject)) {
4680 $langs->load(
'projects');
4681 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
4682 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
4684 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');
4685 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>';
4692 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
4693 print
'<td colspan="2" class="maxwidthonsmartphone">';
4694 $incoterm_id =
GETPOST(
'incoterm_id');
4695 $location_incoterms =
GETPOST(
'location_incoterms');
4696 if (empty($incoterm_id)) {
4697 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
4698 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
4700 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
4701 print $form->select_incoterms($incoterm_id, $location_incoterms);
4715 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
4716 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
4721 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
4722 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
4723 print $hookmanager->resPrint;
4724 if (empty($reshook)) {
4725 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
4728 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
4729 if ($soc->fetch_optionals() > 0) {
4730 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
4734 print
$object->showOptionals($extrafields,
'create', $parameters);
4738 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
4740 if (is_array($list) && count($list) > 0) {
4744 $paramkey =
'FACTURE_ADDON_PDF_'.$type;
4749 if (count($list) > 1) {
4750 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
4751 print
'<td colspan="2">';
4752 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
4753 print $form->selectarray(
'model', $list, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
4756 print
'<input type="hidden" name="model" value="'.$preselected.
'">';
4763 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
4764 print
'<td colspan="2" class="maxwidthonsmartphone">';
4765 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
4766 print $form->selectMultiCurrency(((
GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth200 widthcentpercentminusx');
4773 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
4774 if (empty($dateexample)) {
4777 $substitutionarray = array(
4778 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
4779 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
4780 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
4781 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
4782 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
4783 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
4784 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
4785 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
4786 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
4787 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
4788 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
4791 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
4792 foreach ($substitutionarray as $key => $val) {
4793 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
4795 $htmltext .=
'</i>';
4800 print
'<td class="tdtop">';
4801 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
4803 print
'<td valign="top" colspan="2">';
4804 $doleditor =
new DolEditor(
'note_public', (
string) $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
4805 print $doleditor->Create(1);
4808 if (empty($user->socid)) {
4810 print
'<td class="tdtop">';
4811 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4813 print
'<td valign="top" colspan="2">';
4814 $doleditor =
new DolEditor(
'note_private', (
string) $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4815 print $doleditor->Create(1);
4821 if (!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($classname)) {
4822 $langs->loadLangs(array(
'orders',
'propal'));
4825 if ($origin ==
'contrat') {
4826 '@phan-var-force Contrat $objectsrc';
4828 $objectsrc->update_price(1,
'auto', 1);
4831 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4832 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4833 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4834 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4839 switch (get_class($objectsrc)) {
4841 $newclassname =
'CommercialProposal';
4844 $newclassname =
'Order';
4847 $newclassname =
'Sending';
4850 $newclassname =
'Contract';
4853 $newclassname =
'Intervention';
4856 $newclassname = get_class($objectsrc);
4860 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4861 print
'<td colspan="2">';
4862 print $objectsrc->getNomUrl(1);
4864 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
4865 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4867 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4871 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht, 1, $langs, 1, -1,
'',
$conf->currency).
'</td></tr>';
4872 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
4873 if (
$mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4874 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>";
4877 if (
$mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4878 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>";
4880 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
4882 if (
isModEnabled(
'multicurrency') && $objectsrc->multicurrency_code !=
$conf->currency) {
4884 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
'</td></tr>';
4885 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4886 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4894 print $form->buttonsSaveCancel(
"CreateDraft");
4897 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4900 $title = $langs->trans(
'ProductsAndServices');
4903 print
'<div class="div-table-responsive-no-min">';
4904 print
'<table class="noborder centpercent">';
4906 $objectsrc->printOriginLinesList(
'', $selectedLines);
4913} elseif ($id > 0 || !empty($ref)) {
4915 $langs->load(
'errors');
4916 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4925 if ($user->socid > 0 && $user->socid !=
$object->socid) {
4929 $result =
$object->fetch_thirdparty();
4931 $result = $soc->fetch(
$object->socid);
4935 $selleruserevenustamp =
$mysoc->useRevenueStamp();
4937 $totalpaid =
$object->getSommePaiement();
4938 $totalcreditnotes =
$object->getSumCreditNotesUsed();
4939 $totaldeposits =
$object->getSumDepositsUsed();
4945 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4949 $multicurrency_totalpaid =
$object->getSommePaiement(1);
4950 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
4951 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
4952 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4956 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
4957 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
4961 if (
$object->paye ||
$object->status == $object::STATUS_CLOSED) {
4964 $resteapayeraffiche = $resteapayer;
4967 $filterabsolutediscount =
"fk_facture_source IS NULL";
4968 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4970 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4971 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4974 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
4975 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
4976 $absolute_discount =
price2num($absolute_discount,
'MT');
4977 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4979 $nb_creditnote_notyetavailable = $soc->getOpenCreditNotesNotYetConvertedIntoDiscount(0);
4982 if (
$object->user_creation_id) {
4983 $author->fetch(
$object->user_creation_id);
4986 $objectidnext =
$object->getIdReplacingInvoice();
4990 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
$object->picto, 0,
'',
'', 0,
'', 1);
4995 if ($action ==
'converttoreduc') {
4997 $type_fac =
'ExcessReceived';
4999 $type_fac =
'CreditNote';
5001 $type_fac =
'Deposit';
5005 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
5006 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
5007 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
5011 if ($action ==
'delete') {
5012 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
5013 $formquestion = array();
5016 $qualified_for_stock_change = 0;
5018 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5020 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5023 if ($qualified_for_stock_change) {
5024 $langs->load(
"stocks");
5025 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5029 if (
$conf->browser->name ==
'ie') {
5032 $formquestion = array(
5036 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
5038 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
5040 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
5043 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
5048 if ($action ==
'situationout') {
5049 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
5050 $label = $langs->trans(
"ConfirmOuting");
5051 $formquestion = array();
5056 &&
$object->is_last_in_cycle()
5057 && $usercanunvalidate
5059 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
5064 if ($action ==
'valid') {
5066 $objectref = substr(
$object->ref, 1, 4);
5067 if ($objectref ==
'PROV') {
5071 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
5073 $numref =
$object->getNextNumRef($soc);
5079 $text = $langs->trans(
'ConfirmValidateBill', $numref);
5081 $text .=
'<br><br>';
5082 $text .=
img_picto(
'',
'warning',
'class="pictofixedwidth"').
' '.$langs->trans(
'WarningInvoiceCanNeverBeEdited');
5085 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
5088 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid, $object);
5090 $formquestion = array();
5093 $qualified_for_stock_change = 0;
5095 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5097 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5100 if ($qualified_for_stock_change) {
5101 $langs->load(
"stocks");
5102 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5103 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
5106 $warehouse_array = $warehouse->list_array();
5107 if (count($warehouse_array) == 1) {
5108 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
5109 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5112 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5114 $formquestion = array(
5120 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5124 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
5129 foreach (
$object->lines as $line) {
5130 $res = $line->fetch_product();
5132 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
5138 if ($nbMandated > 0) {
5140 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
5143 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
5148 $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, 0);
5153 if ($action ==
'modif') {
5156 $testvalue =
$object->isEditable();
5157 if ($testvalue < 0) {
5158 switch ($testvalue) {
5161 setEventMessages($langs->trans(
"DisabledBecauseDispatchedInBookkeeping"),
null,
'errors');
5165 setEventMessages($langs->trans(
"DisabledBecauseNotLastInvoice"),
null,
'errors');
5169 setEventMessages($langs->trans(
"DisabledBecauseNotLastSituationInvoice"),
null,
'errors');
5173 setEventMessages($langs->trans(
"DisabledBecauseThereIsAPayment"),
null,
'errors');
5177 setEventMessages($langs->trans(
"DisabledBecauseAlreadySentByEmail"),
null,
'errors');
5181 setEventMessages($langs->trans(
"DisabledBecauseAlreadyPrintedOnce"),
null,
'errors');
5197 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
5198 $formquestion = array();
5201 $qualified_for_stock_change = 0;
5203 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5205 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5208 if ($qualified_for_stock_change) {
5209 $langs->load(
"stocks");
5210 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5211 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
5214 $warehouse_array = $warehouse->list_array();
5215 if (count($warehouse_array) == 1) {
5216 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
5217 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5220 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5222 $formquestion = array(
5228 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5232 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
5237 if ($action ==
'canceled') {
5241 $statusreplacement = 0;
5243 if ($objectidnext) {
5245 $facturereplacement->fetch($objectidnext);
5246 $statusreplacement = $facturereplacement->status;
5248 if ($objectidnext && $statusreplacement == 0) {
5249 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
5253 $close[1][
'code'] =
'badcustomer';
5254 $close[2][
'code'] =
'abandon';
5256 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5257 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
5259 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
5260 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
5263 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
5264 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
5267 $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'));
5269 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 300);
5274 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
5275 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
5277 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
5281 $close[$i][
'code'] = $object::CLOSECODE_DISCOUNTVAT;
5283 $close[$i][
'code'] = $object::CLOSECODE_BADDEBT;
5285 $close[$i][
'code'] = $object::CLOSECODE_BANKCHARGE;
5287 $close[$i][
'code'] = $object::CLOSECODE_WITHHOLDINGTAX;
5289 $close[$i][
'code'] = $object::CLOSECODE_OTHER;
5293 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
5295 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5297 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
5299 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
5301 $close[$i][
'label'] = $langs->trans(
"Other");
5305 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5307 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5309 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5311 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
5313 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
5317 foreach ($close as $key => $val) {
5318 $arrayreasons[$close[$key][
'code']] =
'<span class="small">'.$close[$key][
'reason'].
'</span>';
5322 $formquestion = array(
5323 'text' => $langs->trans(
"ConfirmClassifyPaidPartiallyQuestion"),
5324 0 => array(
'type' =>
'radio',
'name' =>
'close_code',
'label' =>
'',
'values' => $arrayreasons),
5325 1 => array(
'type' =>
'text',
'name' =>
'close_note',
'moreattr' =>
'placeholder = "'.$langs->trans(
"Comment").
'"',
'value' =>
'',
'morecss' =>
'minwidth300'),
5326 2 => array(
'type' =>
'separator')
5329 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&resteapayer='.((
float) $resteapayer), $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially',
$object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 420, 600);
5332 if ($action ==
'deletepayment') {
5333 $payment_id =
GETPOST(
'paiement_id');
5334 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
5338 if ($action ==
'ask_deleteline') {
5339 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
5343 if ($action ==
'ask_subtotal_deleteline') {
5344 $langs->load(
"subtotals");
5345 $title =
"DeleteSubtotalLine";
5346 $question =
"ConfirmDeleteSubtotalLine";
5347 if (
GETPOST(
'type') ==
'title') {
5348 $formconfirm = array(array(
'type' =>
'checkbox',
'name' =>
'deletecorrespondingsubtotalline',
'label' => $langs->trans(
"DeleteCorrespondingSubtotalLine"),
'value' => 0));
5349 $title =
"DeleteTitleLine";
5350 $question =
"ConfirmDeleteTitleLine";
5352 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans($title), $langs->trans($question),
'confirm_delete_subtotalline', $formconfirm,
'no', 1);
5356 if ($action ==
'clone') {
5357 $filter =
'(s.client:IN:1,2,3)';
5359 $formquestion = array(
5360 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
$object->socid,
'socid', $filter, 1)),
5361 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
5364 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 0);
5368 if ($action ==
'add_title_line') {
5369 $langs->load(
'subtotals');
5371 $depth_array =
$object->getPossibleLevels($langs);
5373 } elseif ($action ==
'add_subtotal_line') {
5374 $langs->load(
'subtotals');
5376 $titles =
$object->getPossibleTitles();
5380 if ($action ==
"remove_file_comfirm") {
5381 $file =
GETPOST(
'file',
'alpha');
5383 $formconfirm = $form->formconfirm(
5384 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
5385 $langs->trans(
'DeleteFileHeader'),
5386 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
5395 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
5396 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
5397 if (empty($reshook)) {
5398 $formconfirm .= $hookmanager->resPrint;
5399 } elseif ($reshook > 0) {
5400 $formconfirm = $hookmanager->resPrint;
5408 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
5410 $morehtmlref =
'<div class="refidno">';
5413 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5414 $morehtmlref .= $form->editfieldval(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'',
null,
null,
'', 1);
5415 $morehtmlref .=
'<br>';
5418 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5419 $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);
5421 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
5423 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'">'.$langs->trans(
"OtherBills").
'</a>)';
5427 $langs->load(
"projects");
5428 $morehtmlref .=
'<br>';
5429 if ($usercancreate) {
5430 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
5431 if ($action !=
'classify') {
5432 $morehtmlref .=
'<a class="editfielda" href="'.dolBuildUrl($_SERVER[
'PHP_SELF'], [
'action' =>
'classify',
'id' =>
$object->id],
true).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
5434 $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');
5436 if (!empty(
$object->fk_project)) {
5438 $proj->fetch(
$object->fk_project);
5439 $morehtmlref .= $proj->getNomUrl(1);
5441 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
5446 $morehtmlref .=
'</div>';
5448 $object->totalpaid = $totalpaid;
5449 $object->totalcreditnotes = $totalcreditnotes;
5450 $object->totaldeposits = $totaldeposits;
5453 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
5456 $parameters = array();
5458 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters, $object, $action);
5459 if (empty($reshook)) {
5460 print
'<div class="fichecenter">';
5461 print
'<div class="fichehalfleft">';
5462 print
'<div class="underbanner clearboth"></div>';
5464 print
'<table class="border centpercent tableforfield">';
5467 print
'<tr><td class="fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
5470 print
' '.$object->getSubtypeLabel(
'facture');
5474 $facreplaced->fetch(
$object->fk_facture_source);
5475 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
5479 $facusing->fetch(
$object->fk_facture_source);
5480 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
5484 $object->getListIdAvoirFromInvoice();
5486 if (!empty(
$object->creditnote_ids)) {
5487 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
5489 foreach (
$object->creditnote_ids as $invoiceid) {
5496 $creditnote->fetch($invoiceid);
5497 print $creditnote->getNomUrl(1,
'', 32);
5501 if ($objectidnext > 0) {
5503 $facthatreplace->fetch($objectidnext);
5504 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
5509 $result = $discount->fetch(0,
$object->id);
5511 print
' <span class="opacitymediumbycolor paddingleft">';
5512 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
5513 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
5514 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
5516 print
'</span><br>';
5520 if (
$object->fk_fac_rec_source > 0) {
5522 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
5524 print
' <span class="opacitymediumbycolor paddingleft">';
5525 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
5526 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
5530 print
' <span class="opacitymediumbycolor paddingleft">';
5531 print $langs->transnoentities(
"GeneratedFromTemplate", $langs->trans(
"ObjectDeleted"));
5539 $langs->load(
"cashdesk");
5540 print
'<tr><td class="fieldname_type">';
5541 print
'<table class="nobordernopadding centpercent"><tr><td>';
5542 print $form->textwithpicto($langs->trans(
'PointOfSale'), $langs->trans(
'POSInfo'));
5544 if ($action !=
'editposinfo' && $usercancreate) {
5545 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>';
5547 print
'</tr></table>';
5548 print
'</td><td class="valuefield fieldname_type">';
5549 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" name="formposinfo">';
5550 print
'<input type="hidden" name="action" value="setposinfo">';
5551 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5552 if ($action ==
'editposinfo') {
5553 print
'<input type="text" class="maxwidth150" name="posmodule" placeholder="'.$langs->trans(
"POSModule").
'" value="'.
$object->module_source.
'"> ';
5554 print
'<input type="text" class="maxwidth100" name="posterminal" placeholder="'.$langs->trans(
"Terminal").
'" value="'.
$object->pos_source.
'">';
5555 print
'<input type="submit" class="button" name="submitposinfo" value="'.$langs->trans(
"Submit").
'">';
5558 print
'<span class="opacitymediumbycolor paddingleft">'.dolPrintHTML(ucfirst(
$object->module_source).
' - '.$langs->transnoentitiesnoconv(
"Terminal").
' '.
$object->pos_source).
'</span>';
5566 print
'<!-- Discounts -->'.
"\n";
5567 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
5571 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
5572 $defaulttpldir =
'/core/tpl';
5574 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array($defaulttpldir));
5575 foreach ($dirtpls as $module => $reldir) {
5577 if (!empty($module)) {
5580 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
5582 if (file_exists($tpl)) {
5583 if (empty(
$conf->file->strict_mode)) {
5584 $res = @include $tpl;
5586 $res = include $tpl;
5598 print
'<table class="nobordernopadding centpercent"><tr><td>';
5599 print $langs->trans(
'DateInvoice');
5601 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
5602 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>';
5604 print
'</tr></table>';
5606 if ($action ==
'editinvoicedate') {
5607 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
5609 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
5624 print
'<table class="nobordernopadding centpercent"><tr><td>';
5625 print $langs->trans(
'DatePointOfTax');
5628 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>';
5630 print
'</tr></table>';
5632 if ($action ==
'editdate_pointoftax' && $editable) {
5633 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
5635 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
5643 print $form->editfieldkey(
'Source',
'input_reason',
'', $object, (
int) $usercancreate);
5644 print
'</td><td class="valuefield">';
5645 if ($action ==
'editinput_reason') {
5646 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'input_reason_id', 1,
'maxwidth250 widthcentpercentminusx');
5648 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'none');
5655 print
'<table class="nobordernopadding centpercent"><tr><td>';
5656 print $langs->trans(
'PaymentConditionsShort');
5659 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>';
5661 print
'</tr></table>';
5664 if ($action ==
'editconditions') {
5665 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
5667 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
5674 print
'<table class="nobordernopadding centpercent"><tr><td>';
5675 print $langs->trans(
'DateMaxPayment');
5678 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>';
5680 print
'</tr></table>';
5683 if ($action ==
'editpaymentterm') {
5684 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
5686 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
5696 print
'<table class="nobordernopadding centpercent"><tr><td>';
5697 print $langs->trans(
'PaymentMode');
5699 if ($action !=
'editmode' && $usercancreate) {
5700 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>';
5702 print
'</tr></table>';
5704 if ($action ==
'editmode') {
5705 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
5707 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'none',
'CRDT');
5713 print
'<tr><td class="nowrap">';
5714 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
5715 print $langs->trans(
'DefaultBankAccount');
5717 if (($action !=
'editbankaccount') && $usercancreate) {
5718 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>';
5720 print
'</tr></table>';
5722 if ($action ==
'editbankaccount') {
5723 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
5725 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
5734 print
'<table class="nobordernopadding centpercent"><tr><td>';
5735 print $langs->trans(
'IncotermLabel');
5736 print
'<td><td class="right">';
5737 if ($usercancreate) {
5738 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
5740 print
'</td></tr></table>';
5743 if ($action !=
'editincoterm') {
5744 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
5746 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
5753 print
'<table class="nobordernopadding centpercent"><tr><td>';
5754 print $langs->trans(
'Dispute');
5755 print
'<td><td class="right">';
5756 if ($usercancreate) {
5757 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editdispute_status&token='.
newToken().
'">'.
img_edit().
'</a>';
5759 print
'</td></tr></table>';
5761 $liststatus = Facture::ARRAY_OF_DISPUTE_STATUS;
5762 if ($action !=
'editdispute_status') {
5763 if (
$object->dispute_status) {
5764 print $langs->trans($liststatus[
$object->dispute_status][
'label']);
5767 print
'<form enctype="multipart/form-data" action="'.DOL_URL_ROOT.
'/compta/facture/card.php" method="POST">';
5768 print
'<input type="hidden" name="action" value="set_dispute_status">';
5769 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5770 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
5771 print
'<input type="hidden" name="page_y" value="">';
5772 print $form->selectarray(
'dispute_status', $liststatus,
$object->dispute_status, 0, 0, 0,
'', 1);
5773 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Save").
'">';
5781 print
'<table class="nobordernopadding centpercent"><tr><td>';
5782 print $langs->trans(
"Categories");
5783 print
'<td><td class="right">';
5784 if ($usercancreate) {
5785 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
5789 print
'</td></tr></table>';
5792 if ($action ==
'edittags') {
5793 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5794 print
'<input type="hidden" name="action" value="settags">';
5795 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5796 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
5797 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5800 print $form->showCategories(
$object->id, Categorie::TYPE_INVOICE, 1);
5805 $displayWarranty =
false;
5808 $displayWarranty =
true;
5809 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
5810 $displayWarranty =
false;
5813 if ($displayWarranty) {
5815 print
'<tr class="retained-warranty-lines" ><td>';
5816 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
5817 print $langs->trans(
'RetainedWarranty');
5820 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>';
5823 print
'</tr></table>';
5826 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5827 print
'<input type="hidden" name="action" value="setretainedwarranty">';
5828 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5829 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5830 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
5831 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5839 print
'<tr class="retained-warranty-lines" ><td>';
5840 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
5841 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
5843 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
5844 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>';
5847 print
'</tr></table>';
5849 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5850 if (
$object->date > $defaultDate) {
5856 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5857 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
5858 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5859 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5860 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
5861 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
5862 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
5863 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
5864 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5867 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->retained_warranty_fk_cond_reglement,
'none');
5868 if (!$displayWarranty) {
5869 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning',
'class="pictowarning valignmiddle" ');
5875 print
'<tr class="retained-warranty-lines" ><td>';
5876 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
5877 print $langs->trans(
'RetainedWarrantyDateLimit');
5880 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>';
5883 print
'</tr></table>';
5885 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5886 if (
$object->date > $defaultDate) {
5891 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5892 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
5893 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5894 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5896 print $form->selectDate($defaultDate,
'retained_warranty_date_limit');
5897 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5909 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
5914 print
'<div class="fichehalfright">';
5916 print
'<!-- amounts -->'.
"\n";
5917 print
'<div class="underbanner clearboth"></div>'.
"\n";
5919 print
'<table class="border tableforfield centpercent">';
5921 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
5929 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
5930 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5933 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5939 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
5940 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5943 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5948 if ((
$mysoc->localtax1_assuj ==
"1" &&
$mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
5950 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1",
$mysoc->country_code) .
'</td>';
5951 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5955 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5960 if ((
$mysoc->localtax2_assuj ==
"1" &&
$mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
5962 print
'<td>' . $langs->transcountry(
"AmountLT2",
$mysoc->country_code) .
'</td>';
5963 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
5967 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5973 if ($selleruserevenustamp) {
5974 print
'<tr><td class="titlefieldmiddle">';
5975 print
'<table class="nobordernopadding centpercent"><tr><td>';
5976 print $langs->trans(
'RevenueStamp');
5978 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
5979 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>';
5981 print
'</tr></table>';
5982 print
'</td><td class="nowrap amountcard right">';
5983 if ($action ==
'editrevenuestamp') {
5984 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
5985 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5986 print
'<input type="hidden" name="action" value="setrevenuestamp">';
5987 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
5988 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5989 print $formother->select_revenue_stamp(
'',
'revenuestamp_type',
$mysoc->country_code);
5990 print
' → <span id="revenuestamp_span"></span>';
5991 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
5994 $(document).ready(function(){
5995 js_recalculate_revenuestamp();
5996 $('select[name=revenuestamp_type]').on('change',function(){
5997 js_recalculate_revenuestamp();
6000 function js_recalculate_revenuestamp(){
6001 var valselected = $('select[name=revenuestamp_type]').val();
6002 console.log('Calculate revenue stamp from '+valselected);
6004 if (valselected.indexOf('%') == -1)
6006 revenue = valselected;
6010 var revenue_type = parseFloat(valselected);
6011 var amount_net = ".round(
$object->total_ht, 2).
";
6012 revenue = revenue_type * amount_net / 100;
6013 revenue = revenue.toFixed(2);
6015 $('#revenuestamp_val').val(revenue);
6016 $('#revenuestamp_span').html(revenue);
6027 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
6028 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
6031 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
6046 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
6049 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
6052 if ($selleruserevenustamp) {
6062 $total_prev_ht = $total_prev_ttc = 0;
6063 $total_global_ht = $total_global_ttc = 0;
6067 print
'<!-- List of situation invoices -->';
6068 print
'<div class="div-table-responsive-no-min">';
6069 print
'<table class="noborder paymenttable centpercent situationstable">';
6071 print
'<tr class="liste_titre">';
6072 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
6074 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
6077 print
'<td class="right"></td>';
6079 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
6080 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
6081 print
'<td width="18"> </td>';
6084 if (count(
$object->tab_previous_situation_invoice) > 0) {
6087 $current_situation_counter = array();
6088 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
6089 $tmptotalallpayments = $prev_invoice->getSommePaiement(0);
6090 $tmptotalallpayments += $prev_invoice->getSumDepositsUsed(0);
6091 $tmptotalallpayments += $prev_invoice->getSumCreditNotesUsed(0);
6093 $total_prev_ht += $prev_invoice->total_ht;
6094 $total_prev_ttc += $prev_invoice->total_ttc;
6096 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
6097 print
'<tr class="oddeven">';
6098 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
6100 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
6102 print
'<td class="right"></td>';
6104 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
6105 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
6106 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalallpayments).
'</td>';
6111 $totalallpayments =
$object->getSommePaiement(0);
6112 $totalallpayments +=
$object->getSumCreditNotesUsed(0);
6113 $totalallpayments +=
$object->getSumDepositsUsed(0);
6115 $total_global_ht += $total_prev_ht;
6116 $total_global_ttc += $total_prev_ttc;
6117 $total_global_ht +=
$object->total_ht;
6118 $total_global_ttc +=
$object->total_ttc;
6122 print
'<tr class="oddeven">';
6123 print
'<td>'.$object->getNomUrl(1).
'</td>';
6125 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
6127 print
'<td class="right"></td>';
6129 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
6130 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
6131 print
'<td class="right">'.$object->getLibStatut(3, $totalallpayments).
'</td>';
6135 print
'<tr class="oddeven">';
6136 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'SituationTotalAfterInvoice').
'</b></td>';
6139 foreach ($current_situation_counter as $sit) {
6140 $curSign = $sit > 0 ?
'+' :
'-';
6141 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
6143 print
' '.$curSign.
' ';
6145 print $curType.abs($sit);
6152 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6153 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6154 print
'<td width="18"> </td>';
6158 if (count(
$object->tab_next_situation_invoice) > 0) {
6160 $total_next_ht = $total_next_ttc = 0;
6162 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
6163 $next_totalpaid = $next_invoice->getSommePaiement(0);
6164 $next_totalcreditnotes = $next_invoice->getSumCreditNotesUsed(0);
6165 $next_totaldeposits = $next_invoice->getSumDepositsUsed(0);
6166 $total_next_ht += $next_invoice->total_ht;
6167 $total_next_ttc += $next_invoice->total_ttc;
6169 print
'<tr class="oddeven">';
6170 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
6172 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
6174 print
'<td class="right"></td>';
6176 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
6177 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
6178 print
'<td class="right">'.$next_invoice->getLibStatut(3, $next_totalpaid + $next_totalcreditnotes + $next_totaldeposits).
'</td>';
6182 $total_global_ht += $total_next_ht;
6183 $total_global_ttc += $total_next_ttc;
6185 print
'<tr class="oddeven">';
6186 print
'<td colspan="3" class="right"></td>';
6188 print
'<td class="right"></td>';
6190 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6191 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6192 print
'<td width="18"> </td>';
6201 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
6207 print
'<!-- List of payments already done -->';
6208 print
'<div class="div-table-responsive-no-min">';
6209 print
'<table class="noborder paymenttable centpercent">';
6211 print
'<tr class="liste_titre">';
6212 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
6213 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
6214 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
6216 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
6218 print
'<td class="liste_titre"></td>';
6219 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
6223 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
6224 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
6225 $sql .=
' pf.amount,';
6226 $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';
6227 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
6228 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
6229 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
6230 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
6231 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
6232 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
6233 $sql .=
' ORDER BY p.datep, p.tms';
6235 $result =
$db->query($sql);
6237 $num =
$db->num_rows($result);
6242 $objp =
$db->fetch_object($result);
6244 $paymentstatic->id = $objp->rowid;
6245 $paymentstatic->datepaye =
$db->jdate($objp->dp);
6246 $paymentstatic->ref = $objp->ref;
6247 $paymentstatic->num_payment = $objp->num_payment;
6248 $paymentstatic->paiementcode = $objp->payment_code;
6250 print
'<tr class="oddeven">';
6251 print
'<td class="nowraponall">';
6252 print $paymentstatic->getNomUrl(1);
6255 $dateofpayment =
$db->jdate($objp->dp);
6257 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
6264 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
6265 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
6267 $bankaccountstatic->id = $objp->baid;
6268 $bankaccountstatic->ref = $objp->baref;
6269 $bankaccountstatic->label = $objp->baref;
6270 $bankaccountstatic->number = $objp->banumber;
6271 $bankaccountstatic->currency_code = $objp->bacurrency_code;
6274 $bankaccountstatic->account_number = $objp->account_number;
6277 $accountingjournal->fetch($objp->fk_accountancy_journal);
6278 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
6281 print
'<td class="nowraponall">';
6282 if ($bankaccountstatic->id) {
6283 print $bankaccountstatic->getNomUrl(1,
'transactions');
6289 print
'<td class="center">';
6291 $paiement->fetch($objp->rowid);
6293 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
6300 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
6315 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6316 print
'<span class="opacitymedium">';
6318 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
6320 print $langs->trans(
'AlreadyPaid');
6322 print
'</span></td>';
6324 print
'<td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td>';
6327 $resteapayeraffiche = $resteapayer;
6328 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
6329 $cssforamountpaymentcompletenoresize =
'amountpaymentcompletenoresize';
6332 $creditnoteamount = 0;
6334 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
6335 $sql .=
" re.description, re.fk_facture_source";
6336 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
6337 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
6338 $resql =
$db->query($sql);
6340 $num =
$db->num_rows($resql);
6344 $obj =
$db->fetch_object($resql);
6345 $invoice->fetch($obj->fk_facture_source);
6347 print
'<td colspan="'.$nbcols.
'" class="right">';
6348 print
'<span class="opacitymedium">';
6350 print $langs->trans(
"CreditNote").
' ';
6353 print $langs->trans(
"Deposit").
' ';
6355 print $invoice->getNomUrl(0);
6359 print
'<td class="right">';
6360 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
6361 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
6365 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
6369 $creditnoteamount += $obj->amount_ttc;
6372 $depositamount += $obj->amount_ttc;
6382 print
'<td colspan="'.$nbcols.
'" class="nowrap right">';
6383 print
'<span class="opacitymedium">';
6384 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
6388 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6390 $resteapayeraffiche = 0;
6391 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6392 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6397 print
'<td colspan="'.($nbcols + 1).
'" class="nowrap right">';
6398 print
'<span class="opacitymedium">';
6399 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
6403 print
'<td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td>';
6406 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6407 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6412 print
'<td colspan="'.($nbcols + 1).
'" class="nowrap right">';
6413 print
'<span class="opacitymedium">';
6414 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
6418 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6420 $resteapayeraffiche = 0;
6421 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6422 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6427 print
'<td colspan="'.($nbcols + 1).
'" class="nowrap right">';
6428 $text = $langs->trans(
"HelpAbandonOther");
6430 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
6432 print
'<span class="opacitymedium">';
6434 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
6438 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6440 $resteapayeraffiche = 0;
6441 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6442 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6447 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6448 print
'<span class="opacitymedium">';
6449 print $langs->trans(
"Billed");
6452 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
6457 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6458 print
'<span class="opacitymedium">';
6459 print $langs->trans(
'RemainderToPay');
6460 if ($resteapayeraffiche < 0) {
6461 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6466 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
6472 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6473 print
'<span class="opacitymedium">';
6474 print $langs->trans(
'RemainderToPayMulticurrency');
6475 if ($resteapayeraffiche < 0) {
6476 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6481 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcompletenoresize)).
'">';
6488 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
6490 if (
$object->isSituationInvoice()) {
6491 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
6494 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
6497 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
6500 print
'<td colspan="'.($nbcols + 1).
'" class="right">'.$langs->trans(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')).
' :</td>';
6502 print
'<td class="right">'.price($billedWithRetainedWarranty).
'</td>';
6507 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6508 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
6509 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
6512 print
'<td class="right">'.price($retainedWarranty).
'</td>';
6516 $resteapayeraffiche = $resteapayer;
6517 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6518 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6522 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6523 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
6526 print
'<td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td>';
6531 print
'<td colspan="'.($nbcols + 1).
'" class="right"><span class="opacitymedium">'.$langs->trans(
"Billed").
'</span></td>';
6533 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
6537 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
6538 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
6539 if ($resteapayeraffiche > 0) {
6540 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6542 print
'</span></td>';
6544 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche);
6553 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6554 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
6555 if ($resteapayeraffiche > 0) {
6556 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6561 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaybacknoresize' : (
' '.$cssforamountpaymentcompletenoresize)).
'">'.
price(
price2num($sign *
$object->multicurrency_tx * $resteapayeraffiche,
'MT'), 1, $langs, 1, -1, -1, (empty(
$object->multicurrency_code) ?
$conf->currency :
$object->multicurrency_code)).
'</td>';
6576 $formmargin->displayMarginInfos($object);
6582 print
'<div class="clearboth"></div><br>';
6585 $blocname =
'contacts';
6586 $title = $langs->trans(
'ContactsAddresses');
6587 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6591 $blocname =
'notes';
6592 $title = $langs->trans(
'Notes');
6593 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6597 $result =
$object->getLinesArray();
6601 global $inputalsopricewithtax;
6602 $inputalsopricewithtax = 1;
6607 print
'<!-- Area to change globally the situation percent -->'.
"\n";
6608 print
'<div class="div-table-responsive-no-min">';
6610 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'#updatealllines" method="POST">';
6611 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
6612 print
'<input type="hidden" name="action" value="updatealllines" />';
6613 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
6614 print
'<input type="hidden" name="page_y" value="" />';
6615 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
6617 print
'<table id="tablelines_all_progress" class="noborder noshadow centpercent">';
6619 print
'<tr class="liste_titre nodrag nodrop">';
6623 print
'<td align="center" width="5"> </td>';
6625 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
6626 print
'<td class="right">'.$langs->trans(
'CumulativeProgression').
'</td>';
6627 print
'<td> </td>';
6630 print
'<tr class="nodrag nodrop">';
6633 print
'<td align="center" width="5"> </td>';
6635 print
'<td> </td>';
6636 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
6637 print
'<td class="right"><input type="submit" class="button reposition small" name="all_percent" value="'.$langs->trans(
"Modify").
'" /></td>';
6648 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
6649 <input type="hidden" name="token" value="' .
newToken().
'">
6650 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
6651 <input type="hidden" name="mode" value="">
6652 <input type="hidden" name="page_y" value="">
6653 <input type="hidden" name="id" value="' .
$object->id.
'">
6654 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
6657 if (!empty(
$conf->use_javascript_ajax) &&
$object->status == 0) {
6659 include DOL_DOCUMENT_ROOT.
'/core/tpl/subtotal_ajaxrow.tpl.php';
6661 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
6665 print
'<div class="div-table-responsive-no-min">';
6666 print
'<table id="tablelines" class="noborder noshadow centpercent nomarginbottom">';
6670 $object->printObjectLines($action,
$mysoc, $soc, $lineid, 1);
6674 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
6675 if ($action !=
'editline' && $action !=
'selectlines') {
6678 $parameters = array();
6679 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
6683 if (empty($reshook)) {
6687 $parameters = array();
6688 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters, $object, $action);
6702 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
6703 print
'<div class="tabsAction">';
6705 $parameters = array();
6706 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
6707 if (empty($reshook)) {
6710 'class' =>
'classfortooltip',
6717 $ventilExportCompta =
$object->getVentilExportCompta();
6719 if ($ventilExportCompta == 0) {
6721 if (!$objectidnext &&
$object->is_last_in_cycle()) {
6722 if ($usercanunvalidate) {
6723 unset($params[
'attr'][
'title']);
6724 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
true, $params);
6726 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
6727 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
false, $params);
6729 } elseif (!
$object->is_last_in_cycle()) {
6730 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
6731 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6733 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
6734 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6738 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6739 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6744 $result = $discount->fetch(0,
$object->id);
6752 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
6753 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
6754 unset($params[
'attr'][
'title']);
6755 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
6757 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6758 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
6765 $langs->load(
"contracts");
6767 if ($usercancreatecontract) {
6768 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>';
6776 $langs->load(
"subtotals");
6778 $url_button = array();
6780 $url_button[] = array(
6781 'lang' =>
'subtotals',
6783 'perm' => (
bool) $usercancreate,
6784 'label' => $langs->trans(
'AddTitleLine'),
6785 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_title_line&token='.
newToken()
6788 $url_button[] = array(
6789 'lang' =>
'subtotals',
6791 'perm' => (
bool) $usercancreate,
6792 'label' => $langs->trans(
'AddSubtotalLine'),
6793 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_subtotal_line&token='.
newToken()
6795 print
dolGetButtonAction(
'', $langs->trans(
'SubTotal'),
'default', $url_button,
'',
true);
6802 if ($usercanvalidate) {
6803 unset($params[
'attr'][
'title']);
6804 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
6809 if (empty($user->socid)) {
6811 if ($objectidnext) {
6812 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6813 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
6816 unset($params[
'attr'][
'title']);
6817 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
6819 unset($params[
'attr'][
'title']);
6820 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
6828 if ($resteapayer > 0) {
6829 if ($usercancreatewithdrarequest) {
6830 if (!$objectidnext &&
$object->close_code !=
'replaced') {
6831 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>';
6833 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
6845 $langs->load(
"cashdesk");
6846 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
6847 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
6852 if ($objectidnext) {
6853 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
6857 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
6858 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
6862 unset($params[
'attr'][
'title']);
6863 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);
6868 $sumofpayment = $totalpaid;
6869 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
6875 if ($resteapayer == 0) {
6876 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
6878 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
6884 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
6888 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
6890 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>';
6897 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
6899 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
6913 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
6914 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
6916 unset($params[
'attr'][
'title']);
6917 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken(),
'',
true, $params);
6923 if ($totalpaid > 0 || $totalcreditnotes > 0) {
6925 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
6928 if ($objectidnext) {
6929 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
6931 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled&token='.
newToken().
'">'.$langs->trans(
'ClassifyCanceled').
'</a>';
6939 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
6940 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6941 } elseif (!
$object->is_last_in_cycle()) {
6942 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6944 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6950 if (!$objectidnext) {
6951 print
'<!-- button create credit note -->';
6952 if (
$object->module_source ==
'takepos') {
6953 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseInvoiceGeneratedBy", $langs->transnoentitiesnoconv(
'TakePOS')).
'">'.$langs->trans(
"CreateCreditNote").
'</a>';
6955 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>';
6962 &&
$object->isSituationInvoice()
6965 &&
$object->is_last_in_cycle()
6968 if ($usercanunvalidate) {
6969 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>';
6971 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
6977 if (!$objectidnext && count(
$object->lines) > 0) {
6978 unset($params[
'attr'][
'title']);
6979 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
6985 unset($params[
'attr'][
'title']);
6986 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'clone', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice&token='.
newToken(),
'',
true, $params);
6991 &&
$object->isSituationInvoice()
6994 &&
$object->situation_counter > 1
6995 &&
$object->is_last_in_cycle()
6996 && $usercanunvalidate
6999 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout&token='.
newToken().
'">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
7001 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
7006 $isErasable =
$object->is_erasable();
7009 if ($isErasable == -6) {
7010 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadySentByEmail');
7011 } elseif ($isErasable == -5) {
7012 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadyPrintedOnce');
7013 } elseif ($isErasable == -4) {
7014 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
7015 } elseif ($isErasable == -3) {
7016 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
7017 } elseif ($isErasable == -2) {
7018 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
7019 } elseif ($isErasable == -1) {
7020 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
7021 } elseif ($isErasable <= 0) {
7022 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable').(empty(
$object->error) ?
': UnknownReason' :
': '.$object->error);
7023 } elseif ($objectidnext) {
7024 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
7026 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
7027 $enableDelete =
false;
7029 if ($isErasable > 0 && ! $objectidnext) {
7030 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
7031 $enableDelete =
true;
7033 unset($params[
'attr'][
'title']);
7034 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
7036 unset($params[
'attr'][
'title']);
7037 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
7044 if (
GETPOST(
'modelselected',
'alpha')) {
7045 $action =
'presend';
7047 if ($action !=
'prerelance' && $action !=
'presend') {
7048 print
'<div class="fichecenter"><div class="fichehalfleft">';
7049 print
'<a name="builddoc"></a>';
7054 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
7055 $genallowed = $usercanread;
7056 $delallowed = $usercancreate;
7057 $tooltipAfterComboOfModels =
'';
7059 $tooltipAfterComboOfModels = $langs->trans(
"AccordingToYourSetupTheFileWillBeConcatenated",
getDolGlobalString(
'MAIN_INFO_INVOICE_TERMSOFSALE'));
7062 print $formfile->showdocuments(
7082 'remove_file_comfirm',
7083 $tooltipAfterComboOfModels
7086 $somethingshown = $formfile->numoffiles;
7089 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice'), 1);
7090 $linktoelem = $tmparray[
'linktoelem'];
7091 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
7092 print $htmltoenteralink;
7094 $compatibleImportElementsList =
false;
7098 $compatibleImportElementsList = array(
'commande',
'propal',
'subscription');
7100 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
7104 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
7105 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
7106 $useonlinepayment = count($validpaymentmethod);
7109 print
'<br><!-- Link to pay -->'.
"\n";
7110 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
7111 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
7114 print
'</div><div class="fichehalfright">';
7118 $morehtmlcenter =
'<div class="nowraponall">';
7119 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullConversation'),
'',
'fa fa-comments imgforviewmode', DOL_URL_ROOT.
'/compta/facture/messaging.php?id='.
$object->id);
7120 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
7121 $morehtmlcenter .=
'</div>';
7124 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
7126 $somethingshown = $formactions->showactions($object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
7128 print
'</div></div>';
7133 $modelmail =
'facture_send';
7134 $defaulttopic =
'SendBillRef';
7136 $trackid =
'inv'.$object->id;
7138 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $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 VAT - Value-added tax (also known in French as TVA)
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_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...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
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.
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.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
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...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, 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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $notused, $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
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
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.