46require
'../../main.inc.php';
55require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
56require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
57require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
58require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
59require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
60require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
61require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
62require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
63require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
64require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
65require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
66require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
67require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
68require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
70 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
73 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
74 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
76require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
79 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
82 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
86$langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
88 $langs->load(
'incoterm');
91 $langs->load(
'margins');
95$action =
GETPOST(
'action',
'aZ09');
96$confirm =
GETPOST(
'confirm',
'alpha');
97$cancel =
GETPOST(
'cancel',
'alpha');
98$backtopage =
GETPOST(
'backtopage',
'alpha');
99$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
105$origin =
GETPOST(
'origin',
'alpha');
109$ref_client =
GETPOST(
'ref_client',
'alpha');
110$inputReasonId =
GETPOSTINT(
'input_reason_id');
113$selectedLines =
GETPOST(
'toselect',
'array:int');
127$extrafields->fetch_name_optionals_label(
$object->table_element);
130$total_global_ttc = 0;
131$displayWarranty =
false;
132$statusreplacement = 0;
134$price_base_type =
'';
135$array_options = array();
138if ($id > 0 || !empty($ref)) {
139 if ($action !=
'add') {
141 $fetch_situation =
false;
143 $fetch_situation =
true;
145 $ret =
$object->fetch($id, $ref,
'', 0, $fetch_situation);
146 if ($ret > 0 && isset(
$object->fk_project)) {
147 $ret =
$object->fetchProject();
153$hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
156$usercanread = $user->hasRight(
"facture",
"lire");
157$usercancreate = $user->hasRight(
"facture",
"creer");
158$usercanissuepayment = $user->hasRight(
"facture",
"paiement");
159$usercandelete = $user->hasRight(
"facture",
"supprimer") || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
160$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
163$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'validate')));
164$usercansend = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercanread) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'send')));
165$usercanreopen = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'reopen')));
167 $usercanreopen =
false;
169$usercanunvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'unvalidate')));
170$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
173$usercancreatemargin = $user->hasRight(
'margins',
'creer');
174$usercanreadallmargin = $user->hasRight(
'margins',
'liretous');
175$usercancreatewithdrarequest = $user->hasRight(
'prelevement',
'bons',
'creer');
177$permissionnote = $usercancreate;
178$permissiondellink = $usercancreate;
179$permissiontoedit = $usercancreate;
180$permissiontoadd = $usercancreate;
181$permissiontoeditextra = $usercancreate;
182if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
184 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
188$retainedWarrantyInvoiceAvailableType = array();
190 $retainedWarrantyInvoiceAvailableType = explode(
'+',
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY'));
195 $socid = $user->socid;
208$parameters = array(
'socid' => $socid);
209$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
214if (empty($reshook)) {
215 $backurlforlist = DOL_URL_ROOT.
'/compta/facture/list.php';
217 if (empty($backtopage) || ($cancel && empty($id))) {
218 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
219 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
220 $backtopage = $backurlforlist;
222 $backtopage = DOL_URL_ROOT.
'/compta/facture/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
228 if (!empty($backtopageforcancel)) {
229 header(
"Location: ".$backtopageforcancel);
231 } elseif (!empty($backtopage)) {
232 header(
"Location: ".$backtopage);
238 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
240 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
242 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
245 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
247 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'IdThirdParty')),
null,
'errors');
250 '@phan-var-force Facture $objectutil';
253 $objectutil->socid = $socid;
254 $result = $objectutil->createFromClone($user, $id, (GETPOSTISSET(
'entity') ?
GETPOSTINT(
'entity') : null));
256 $warningMsgLineList = array();
258 foreach ($objectutil->lines as $line) {
259 if (!is_object($line->product)) {
260 $line->fetch_product();
262 if (is_object($line->product) && $line->product->id > 0) {
263 if (empty($line->product->status)) {
264 $warningMsgLineList[$line->id] = $langs->trans(
'WarningLineProductNotToSell', $line->product->ref);
268 if (!empty($warningMsgLineList)) {
272 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?facid=' . $result);
275 $langs->load(
"errors");
280 } elseif ($action ==
'reopen' && $usercanreopen) {
284 $result =
$object->setUnpaid($user);
286 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
292 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
297 $idwarehouse =
GETPOST(
'idwarehouse');
299 $qualified_for_stock_change = 0;
301 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
303 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
306 $isErasable =
$object->is_erasable();
308 if (($isErasable > 0) || ($usercancreate && $isErasable == 1)) {
309 $result =
$object->delete($user, 0, (
int) $idwarehouse);
311 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
318 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
328 $outputlangs = $langs;
334 $newlang =
$object->thirdparty->default_lang;
336 if (!empty($newlang)) {
338 $outputlangs->setDefaultLang($newlang);
339 $outputlangs->load(
'products');
343 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
346 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
353 } elseif ($action ==
'confirm_delete_subtotalline' && $confirm ==
'yes' && $usercancreate) {
358 $result =
$object->deleteSubtotalLine($langs,
GETPOSTINT(
'lineid'), (
bool)
GETPOST(
'deletecorrespondingsubtotalline'));
363 $outputlangs = $langs;
369 $newlang =
$object->thirdparty->default_lang;
371 if (!empty($newlang)) {
373 $outputlangs->setDefaultLang($newlang);
374 $outputlangs->load(
'products');
378 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
381 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
388 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
391 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
392 if ($result > 0 && $discount->fk_facture ==
$object->id) {
393 $discount->unlink_invoice();
397 } elseif ($action ==
'valid' && $usercancreate) {
401 if ((preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) &&
408 $last_of_type =
$object->willBeLastOfSameType(
true);
409 if (empty(
$object->date_validation) && !$last_of_type[0]) {
419 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
428 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
437 $array_of_total_ht_per_vat_rate = array();
438 $array_of_total_ht_devise_per_vat_rate = array();
439 foreach (
$object->lines as $line) {
441 $vat_src_code_for_line =
'';
442 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
443 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
445 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
446 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
448 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
449 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
453 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
454 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
455 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
457 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
458 if (
$object->type == $object::TYPE_DEPOSIT) {
459 $langs->load(
"errors");
461 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
465 $tmpvatratetoshow = explode(
'_', $vatrate);
466 $tmpvatratetoshow[0] = round((
float) $tmpvatratetoshow[0], 2);
468 if ($tmpvatratetoshow[0] != 0) {
469 $langs->load(
"errors");
470 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", (
string) $tmpvatratetoshow[0]),
null,
'errors');
478 } elseif ($action ==
'classin' && $usercancreate) {
481 } elseif ($action ==
'setposinfo' && $usercancreate) {
485 $result =
$object->update($user);
489 } elseif ($action ==
'setmode' && $usercancreate) {
495 } elseif ($action ==
'setretainedwarrantyconditions' && $usercancreate) {
497 $object->retained_warranty_fk_cond_reglement = 0;
498 $result =
$object->setRetainedWarrantyPaymentTerms(
GETPOSTINT(
'retained_warranty_fk_cond_reglement'));
503 $old_rw_date_lim_reglement =
$object->retained_warranty_date_limit;
504 $new_rw_date_lim_reglement =
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
505 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
506 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
511 $result =
$object->update($user);
515 } elseif ($action ==
'setretainedwarranty' && $usercancreate) {
521 } elseif ($action ==
'setretainedwarrantydatelimit' && $usercancreate) {
523 $result =
$object->setRetainedWarrantyDateLimit(
GETPOSTDATE(
'retained_warranty_date_limit'));
527 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
528 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
529 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
531 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
533 $old_date_lim_reglement =
$object->date_lim_reglement;
535 if (empty($newdate)) {
536 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
537 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.
$id.
'&action=editinvoicedate&token='.
newToken());
542 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
544 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
549 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
550 if ($new_date_lim_reglement) {
551 $object->date_lim_reglement = $new_date_lim_reglement;
556 $result =
$object->update($user);
559 $action =
'editinvoicedate';
561 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
566 $object->date_pointoftax = $date_pointoftax;
567 $result =
$object->update($user);
571 } elseif ($action ==
'setconditions' && $usercancreate) {
573 $object->cond_reglement_code = 0;
574 $object->cond_reglement_id = 0;
587 $old_date_lim_reglement =
$object->date_lim_reglement;
588 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
589 if ($new_date_lim_reglement) {
590 $object->date_lim_reglement = $new_date_lim_reglement;
595 $result =
$object->update($user);
607 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
611 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
612 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
614 $result =
$object->update($user);
618 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
621 $result =
$object->update($user);
628 $outputlangs = $langs;
631 $newlang =
GETPOST(
'lang_id',
'aZ09');
634 $newlang =
$object->thirdparty->default_lang;
636 if (!empty($newlang)) {
638 $outputlangs->setDefaultLang($newlang);
639 $outputlangs->load(
'products');
644 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
650 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
652 } elseif ($action ==
'set_dispute_status' && $usercancreate) {
653 $result =
$object->setStatut(
GETPOSTINT(
'dispute_status'),
null,
'facture',
'FACTURE_MODIFY',
'dispute_status');
654 } elseif ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
656 } elseif ($action ==
'setbankaccount' && $usercancreate) {
658 } elseif ($action ==
'setremisepercent' && $usercancreate) {
661 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
680 $newremaintopay =
$object->getRemainToPay(0);
681 if ($newremaintopay == 0) {
688 if (
GETPOSTINT(
"remise_id_for_payment") > 0) {
689 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
691 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
695 $remaintopay =
$object->getRemainToPay(0);
699 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
703 $result = $discount->link_to_invoice(0, $id);
716 $newremaintopay =
$object->getRemainToPay(0);
717 if ($newremaintopay == 0) {
731 $outputlangs = $langs;
734 $newlang =
GETPOST(
'lang_id',
'aZ09');
738 $newlang =
$object->thirdparty->default_lang;
740 if (!empty($newlang)) {
742 $outputlangs->setDefaultLang($newlang);
746 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
751 } elseif ($action ==
'setref' && $usercancreate) {
753 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', 0,
'',
'', $user,
'BILL_MODIFY');
754 } elseif ($action ==
'setref_client' && $usercancreate) {
757 } elseif ($action ==
'setdemandreason' && $usercancreate) {
758 $result =
$object->setInputReason($inputReasonId);
762 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
771 $qualified_for_stock_change = 0;
773 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
775 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
778 if ($qualified_for_stock_change) {
779 if (!$idwarehouse || $idwarehouse == - 1) {
781 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
788 $result =
$object->validate($user,
'', $idwarehouse);
792 $outputlangs = $langs;
795 $newlang =
GETPOST(
'lang_id',
'aZ09');
798 $newlang =
$object->thirdparty->default_lang;
800 if (!empty($newlang)) {
802 $outputlangs->setDefaultLang($newlang);
803 $outputlangs->load(
'products');
809 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
822 } elseif ($action ==
'confirm_modif' && $usercanunvalidate && !
getDolGlobalString(
'INVOICE_CAN_NEVER_BE_EDITED')) {
831 $qualified_for_stock_change = 0;
833 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
835 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
838 if ($qualified_for_stock_change) {
839 if (!$idwarehouse || $idwarehouse == -1) {
841 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
850 $sql =
'SELECT pf.amount';
851 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'paiement_facture as pf';
852 $sql .=
' WHERE pf.fk_facture = ' . ((int)
$object->id);
854 $result = $db->query($sql);
857 $num = $db->num_rows($result);
860 $objp = $db->fetch_object($result);
861 $totalpaid += $objp->amount;
868 $resteapayer =
$object->total_ttc - $totalpaid;
871 $ventilExportCompta =
$object->getVentilExportCompta();
874 if ($ventilExportCompta == 0) {
876 $result =
$object->setDraft($user, $idwarehouse);
883 $outputlangs = $langs;
886 $newlang =
GETPOST(
'lang_id',
'aZ09');
889 $newlang =
$object->thirdparty->default_lang;
891 if (!empty($newlang)) {
893 $outputlangs->setDefaultLang($newlang);
894 $outputlangs->load(
'products');
899 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
904 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
907 $result =
$object->setPaid($user);
911 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
914 $close_code =
GETPOST(
"close_code",
'restricthtml');
915 $close_note =
GETPOST(
"close_note",
'restricthtml');
918 if (
isModEnabled(
'tax') && $close_code == $object::CLOSECODE_WITHHOLDINGTAX) {
919 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
921 $amount = (double) ($resteapayer > 0 ? $resteapayer * -1 : $resteapayer);
924 $tempTva =
new Tva($db);
925 $tempTva->datev =
$object->date;
926 $tempTva->datep =
$object->date;
927 $tempTva->amount = $amount;
928 $tempTva->label = $langs->trans(
'WithholdingTax') .
' - ' .
$object->ref;
930 $valid = $tempTva->getIdForLabel($tempTva->label);
932 $ret = $tempTva->create($user);
936 $tempTva->setPaid($user);
946 setEventMessages($langs->trans(
'LabelWithholdingExist'), $tempTva->errors,
'errors');
952 $result =
$object->setPaid($user, $close_code, $close_note);
960 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
962 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
965 $close_code =
GETPOST(
"close_code",
'restricthtml');
966 $close_note =
GETPOST(
"close_note",
'restricthtml');
968 $result =
$object->setCanceled($user, $close_code, $close_note);
975 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
977 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
985 $result = $discountcheck->fetch(0,
$object->id);
998 $amount_ht = $amount_tva = $amount_ttc = array();
999 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
1003 foreach (
$object->lines as $line) {
1004 if ($line->product_type < 9 && $line->total_ht != 0) {
1005 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
1007 if (!isset($amount_ht[$keyforvatrate])) {
1008 $amount_ht[$keyforvatrate] = 0;
1010 $amount_ht[$keyforvatrate] += $line->total_ht;
1011 if (!isset($amount_tva[$keyforvatrate])) {
1012 $amount_tva[$keyforvatrate] = 0;
1014 $amount_tva[$keyforvatrate] += $line->total_tva;
1015 if (!isset($amount_ttc[$keyforvatrate])) {
1016 $amount_ttc[$keyforvatrate] = 0;
1018 $amount_ttc[$keyforvatrate] += $line->total_ttc;
1019 if (!isset($multicurrency_amount_ht[$keyforvatrate])) {
1020 $multicurrency_amount_ht[$keyforvatrate] = 0;
1022 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
1023 if (!isset($multicurrency_amount_tva[$keyforvatrate])) {
1024 $multicurrency_amount_tva[$keyforvatrate] = 0;
1026 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
1027 if (!isset($multicurrency_amount_ttc[$keyforvatrate])) {
1028 $multicurrency_amount_ttc[$keyforvatrate] = 0;
1030 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
1034 '@phan-var-force array<string,float> $amount_ht
1035 @phan-var-force array<string,float> $amount_tva
1036 @phan-var-force array<string,float> $amount_ttc
1037 @phan-var-force array<string,float> $multicurrency_amount_ht
1038 @phan-var-force array<string,float> $multicurrency_amount_tva
1039 @phan-var-force array<string,float> $multicurrency_amount_ttc';
1043 $alreadypaid =
$object->getSommePaiement();
1044 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
1045 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
1046 foreach ($amount_ht as $vatrate => $val) {
1047 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
1048 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
1049 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
1050 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
1051 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
1052 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
1061 $discount->description =
'(CREDIT_NOTE)';
1063 $discount->description =
'(DEPOSIT)';
1065 $discount->description =
'(EXCESS RECEIVED)';
1067 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
1069 $discount->fk_soc =
$object->socid;
1070 $discount->socid =
$object->socid;
1071 $discount->fk_facture_source =
$object->id;
1080 $discount->description =
'(EXCESS RECEIVED)';
1083 $sql =
'SELECT SUM(pf.amount) as total_paiements';
1084 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
1085 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
1086 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
1087 $sql .=
' AND pf.fk_paiement = p.rowid';
1088 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
1089 $resql = $db->query($sql);
1094 $res = $db->fetch_object($resql);
1095 $total_paiements = $res->total_paiements;
1098 $total_creditnote_and_deposit = 0;
1099 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1100 $sql .=
" re.description, re.fk_facture_source";
1101 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1102 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
1103 $resql = $db->query($sql);
1104 if (!empty($resql)) {
1105 while ($obj = $db->fetch_object($resql)) {
1106 $total_creditnote_and_deposit += $obj->amount_ttc;
1112 $discount->amount_ttc =
price2num($total_paiements + $total_creditnote_and_deposit -
$object->total_ttc,
'MT');
1113 $discount->amount_tva = 0;
1114 $discount->amount_ht = $discount->amount_ttc;
1115 $discount->tva_tx = 0;
1116 $discount->vat_src_code =
'';
1118 if ($discount->amount_ttc > 0) {
1119 $result = $discount->create($user);
1129 $discount->description =
'(CREDIT_NOTE)';
1131 $discount->description =
'(DEPOSIT)';
1134 foreach ($amount_ht as $tva_tx => $xxx) {
1136 $discount->amount_ht = -((float) $amount_ht[$tva_tx]);
1137 $discount->amount_tva = -((float) $amount_tva[$tva_tx]);
1138 $discount->amount_ttc = -((float) $amount_ttc[$tva_tx]);
1139 $discount->total_ht = -((float) $amount_ht[$tva_tx]);
1140 $discount->total_tva = -((float) $amount_tva[$tva_tx]);
1141 $discount->total_ttc = -((float) $amount_ttc[$tva_tx]);
1142 $discount->multicurrency_amount_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1143 $discount->multicurrency_amount_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1144 $discount->multicurrency_amount_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1145 $discount->multicurrency_total_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1146 $discount->multicurrency_total_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1147 $discount->multicurrency_total_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1150 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
1151 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
1152 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
1153 $discount->total_ht = abs((
float) $amount_ht[$tva_tx]);
1154 $discount->total_tva = abs((
float) $amount_tva[$tva_tx]);
1155 $discount->total_ttc = abs((
float) $amount_ttc[$tva_tx]);
1156 $discount->multicurrency_amount_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1157 $discount->multicurrency_amount_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1158 $discount->multicurrency_amount_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1159 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1160 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1161 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1167 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
1168 $vat_src_code = $reg[1];
1169 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
1172 $discount->tva_tx = abs((
float) $tva_tx);
1173 $discount->vat_src_code = $vat_src_code;
1175 $result = $discount->create($user);
1183 if (empty($error)) {
1193 $result =
$object->setPaid($user);
1207 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
1212 $result = $paiement->fetch(
GETPOSTINT(
'paiement_id'));
1213 $paymentbills = ($result > 0) ? $paiement->getBillsArray() : array();
1214 if ($result > 0 && is_array($paymentbills) && in_array(
$object->id, $paymentbills)) {
1215 $result = $paiement->delete($user);
1217 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1227 } elseif ($action ==
'add' && $usercancreate) {
1234 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1240 $object->demand_reason_id = $inputReasonId;
1242 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1252 if (empty($dateinvoice)) {
1254 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1264 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1274 $object->date_pointoftax = $date_pointoftax;
1275 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1276 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1287 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1288 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1305 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1307 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceAvoirAskCombo")),
null,
'errors');
1311 if (empty($dateinvoice)) {
1313 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1323 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1328 if (!empty($originentity)) {
1329 $object->entity = $originentity;
1335 $object->date_pointoftax = $date_pointoftax;
1336 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1337 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1342 $object->cond_reglement_id = 0;
1348 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1349 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1353 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1356 $facture_source =
new Facture($db);
1357 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1358 if ($facture_source->isSituationInvoice()) {
1359 $object->situation_counter = $facture_source->situation_counter;
1360 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1361 $facture_source->fetchPreviousNextSituationInvoice();
1371 if (
$object->copy_linked_contact($facture_source,
'internal') < 0) {
1373 } elseif ($facture_source->socid ==
$object->socid) {
1375 if (
$object->copy_linked_contact($facture_source,
'external') < 0) {
1386 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1387 if (!empty($facture_source->lines)) {
1388 $fk_parent_line = 0;
1390 foreach ($facture_source->lines as $line) {
1392 if (method_exists($line,
'fetch_optionals')) {
1394 $line->fetch_optionals();
1398 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1399 $fk_parent_line = 0;
1403 if ($facture_source->isSituationInvoice()) {
1404 $source_fk_prev_id = $line->fk_prev_id;
1405 $line->fk_prev_id = $line->id;
1410 if (
getDolGlobalInt(
'INVOICE_USE_SITUATION') == 1 && !empty($facture_source->tab_previous_situation_invoice)) {
1413 $tab_jumped_credit_notes = array();
1414 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1415 $searchPreviousInvoice =
true;
1416 while ($searchPreviousInvoice) {
1417 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1418 $searchPreviousInvoice =
false;
1422 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1428 $maxPrevSituationPercent = 0;
1429 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1430 if ($prevLine->id == $source_fk_prev_id) {
1431 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1434 $line->total_ht -= $prevLine->total_ht;
1435 $line->total_tva -= $prevLine->total_tva;
1436 $line->total_ttc -= $prevLine->total_ttc;
1437 $line->total_localtax1 -= $prevLine->total_localtax1;
1438 $line->total_localtax2 -= $prevLine->total_localtax2;
1440 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1441 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1442 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1443 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1448 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1453 $maxPrevSituationPercent = 0;
1454 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1455 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1456 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1457 $maxPrevSituationPercent = $prevLine->situation_percent;
1459 $line->total_ht -= $prevLine->total_ht;
1460 $line->total_tva -= $prevLine->total_tva;
1461 $line->total_ttc -= $prevLine->total_ttc;
1462 $line->total_localtax1 -= $prevLine->total_localtax1;
1463 $line->total_localtax2 -= $prevLine->total_localtax2;
1465 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1466 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1467 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1468 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1474 $line->situation_percent += $maxPrevSituationPercent;
1480 $line->fk_facture =
$object->id;
1481 $line->fk_parent_line = $fk_parent_line;
1483 $line->subprice = -$line->subprice;
1485 $line->total_ht = -$line->total_ht;
1486 $line->total_tva = -$line->total_tva;
1487 $line->total_ttc = -$line->total_ttc;
1488 $line->total_localtax1 = -$line->total_localtax1;
1489 $line->total_localtax2 = -$line->total_localtax2;
1491 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1492 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1493 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1494 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1496 $line->context[
'createcreditnotefrominvoice'] = 1;
1497 $result = $line->insert(0, 1);
1502 if ($result > 0 && $line->product_type == 9) {
1503 $fk_parent_line = $result;
1511 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1512 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1513 $totalpaid = $facture_source->getSommePaiement();
1514 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1515 $totaldeposits = $facture_source->getSumDepositsUsed();
1516 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1518 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1519 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1522 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1527 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1528 $tva_tx = (float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY');
1533 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), 0, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC', $remain_to_pay);
1538 if (!empty(
$object->fk_facture_source) &&
$id > 0) {
1539 $facture_source->fetch(
$object->fk_facture_source);
1540 $facture_source->fetchObjectLinked();
1542 if (!empty($facture_source->linkedObjectsIds)) {
1543 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1544 $object->add_object_linked($sourcetype, current($TIds));
1553 if (empty($dateinvoice)) {
1555 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1566 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1576 $object->date_pointoftax = $date_pointoftax;
1577 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1578 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1591 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1592 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1608 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1609 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1610 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1614 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1618 if (empty($dateinvoice)) {
1620 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1630 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1631 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1636 if ($typeamount && !empty($origin) && !empty($originid)) {
1637 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1638 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1642 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1643 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1647 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1648 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1658 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1668 $object->date_pointoftax = $date_pointoftax;
1669 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1670 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1682 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1683 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1687 $object->situation_counter = 1;
1692 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1694 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1696 $object->retained_warranty = 0;
1697 $object->retained_warranty_fk_cond_reglement = 0;
1700 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1701 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1704 $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);
1709 if (!empty($origin) && !empty($originid)) {
1712 $element = $subelement = $origin;
1713 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1714 $element = $regs[1];
1715 $subelement = $regs[2];
1719 if ($element ==
'order') {
1720 $element = $subelement =
'commande';
1722 if ($element ==
'propal') {
1723 $element =
'comm/propal';
1724 $subelement =
'propal';
1726 if ($element ==
'contract') {
1727 $element = $subelement =
'contrat';
1729 if ($element ==
'inter') {
1730 $element = $subelement =
'fichinter';
1732 if ($element ==
'shipping') {
1733 $element = $subelement =
'expedition';
1737 $object->origin_type = $origin;
1738 $object->origin_id = $originid;
1743 if (
$object->origin ==
'shipping') {
1744 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1746 $exp->fetch(
$object->origin_id);
1747 $exp->fetchObjectLinked();
1748 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1749 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1750 $object->linked_objects[
'commande'] = $value;
1756 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
1764 $classname = ucfirst($subelement);
1765 $srcobject =
new $classname($db);
1766 '@phan-var-force CommonObject $srcobject';
1768 dol_syslog(
"Try to find source object origin_type=".
$object->origin_type.
" origin_id=".
$object->origin_id.
" to add lines or deposit lines");
1769 $result = $srcobject->fetch(
$object->origin_id);
1775 $amountdeposit = array();
1778 if ($typeamount ==
'amount') {
1779 $amount = (float) $valuedeposit;
1781 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1784 $TTotalByTva = array();
1785 foreach ($srcobject->lines as &$line) {
1786 if (empty($line->qty)) {
1789 if (!empty($line->special_code)) {
1792 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1794 '@phan-var-force array<string,float> $TTotalByTva';
1796 $amount_ttc_diff = 0.;
1797 foreach ($TTotalByTva as $tva => &$total) {
1798 if (empty($amountdeposit[$tva])) {
1799 $amountdeposit[$tva] = 0;
1801 $coef = $total / $srcobject->total_ttc;
1802 $am = $amount * $coef;
1803 $amount_ttc_diff += $am;
1804 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1807 if ($typeamount ==
'amount') {
1808 $amountdeposit[0] = $valuedeposit;
1809 } elseif ($typeamount ==
'variable') {
1812 $lines = $srcobject->lines;
1813 $numlines = count($lines);
1814 for ($i = 0; $i < $numlines; $i++) {
1816 if (empty($lines[$i]->qty)) {
1819 if (!empty($lines[$i]->special_code)) {
1823 $totalamount += $lines[$i]->total_ht;
1824 $tva_tx = $lines[$i]->tva_tx;
1826 if (empty($amountdeposit[$tva_tx])) {
1827 $amountdeposit[$tva_tx] = 0;
1829 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1833 if ($totalamount == 0) {
1834 $amountdeposit[0] = 0;
1842 $amount_ttc_diff = $amountdeposit[0];
1845 foreach ($amountdeposit as $tva => $amount) {
1846 if (empty($amount)) {
1851 'amount' =>
'FixAmount',
1852 'variable' =>
'VarAmount'
1854 $descline =
'(DEPOSIT)';
1856 if ($typeamount ==
'amount') {
1857 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code : $conf->currency)).
')';
1858 } elseif ($typeamount ==
'variable') {
1859 $descline .=
' ('.$valuedeposit.
'%)';
1862 $descline .=
' - '.$srcobject->ref;
1875 $i >= 0 ? $lines[$i]->info_bits : 0,
1881 $i >= 0 ? $lines[$i]->special_code : 0,
1898 $diff =
$object->total_ttc - $amount_ttc_diff;
1902 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1903 $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);
1912 $lines = $srcobject->lines;
1913 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1914 $srcobject->fetch_lines();
1915 $lines = $srcobject->lines;
1920 if (is_array($lines)) {
1921 foreach ($lines as $line) {
1923 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuestandardinvoice / 100,
'MS');
1929 if (is_array($lines)) {
1930 foreach ($lines as $line) {
1932 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuedeposit / 100,
'MS');
1937 $fk_parent_line = 0;
1938 $num = count($lines);
1940 for ($i = 0; $i < $num; $i++) {
1941 if (!in_array($lines[$i]->
id, $selectedLines)) {
1946 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
1950 if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1951 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1953 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
1957 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1958 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1960 if (
$object->situation_counter == 1) {
1961 $lines[$i]->situation_percent = 0;
1964 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
1967 $desc = $label ? $label : $langs->trans(
'Discount');
1971 $discount->fk_soc =
$object->socid;
1972 $discount->socid =
$object->socid;
1973 $discount->amount_ht = abs($lines[$i]->total_ht);
1974 $discount->amount_tva = abs($lines[$i]->total_tva);
1975 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1976 $discount->total_ht = abs($lines[$i]->total_ht);
1977 $discount->total_tva = abs($lines[$i]->total_tva);
1978 $discount->total_ttc = abs($lines[$i]->total_ttc);
1979 $discount->tva_tx = $lines[$i]->tva_tx;
1980 $discount->fk_user = $user->id;
1981 $discount->description = $desc;
1982 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1983 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1984 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1985 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1986 $discount->multicurrency_total_ht = abs($lines[$i]->multicurrency_total_ht);
1987 $discount->multicurrency_total_tva = abs($lines[$i]->multicurrency_total_tva);
1988 $discount->multicurrency_total_ttc = abs($lines[$i]->multicurrency_total_ttc);
1990 $discountid = $discount->create($user);
1991 if ($discountid > 0) {
1992 $result =
$object->insert_discount($discountid);
2004 $date_start =
false;
2005 if (isset($lines[$i]->date_debut_prevue)) {
2006 $date_start = $lines[$i]->date_debut_prevue;
2008 if (isset($lines[$i]->date_debut_reel)) {
2009 $date_start = $lines[$i]->date_debut_reel;
2011 if (isset($lines[$i]->date_start)) {
2012 $date_start = $lines[$i]->date_start;
2017 if (isset($lines[$i]->date_fin_prevue)) {
2018 $date_end = $lines[$i]->date_fin_prevue;
2020 if (isset($lines[$i]->date_fin_reel)) {
2021 $date_end = $lines[$i]->date_fin_reel;
2023 if (isset($lines[$i]->date_end)) {
2024 $date_end = $lines[$i]->date_end;
2028 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
2029 $fk_parent_line = 0;
2032 $array_options = array();
2034 if (method_exists($lines[$i],
'fetch_optionals')) {
2035 $lines[$i]->fetch_optionals();
2036 $array_options = $lines[$i]->array_options;
2039 $tva_tx = $lines[$i]->tva_tx;
2040 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
2041 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
2051 $lines[$i]->subprice,
2056 $lines[$i]->fk_product,
2057 $lines[$i]->remise_percent,
2061 (
int) $lines[$i]->info_bits,
2062 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except : null,
2067 $lines[$i]->special_code,
2071 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice : null,
2075 $lines[$i]->situation_percent ?? 100,
2076 $lines[$i]->fk_prev_id ?? 0,
2077 $lines[$i]->fk_unit,
2084 foreach (
$object->lines as $line) {
2085 if ($line->id == $result) {
2086 $line->extraparams = $lines[$i]->extraparams;
2087 $line->setExtraParameters();
2099 if ($result > 0 && $lines[$i]->product_type == 9) {
2100 $fk_parent_line = $result;
2112 $object->line_order(
true,
'DESC');
2140 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id,
'objFrom' => $srcobject);
2141 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
2154 for ($i = 1; $i <= $NBLINES; $i++) {
2160 $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);
2171 if (empty($dateinvoice)) {
2173 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
2183 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
2193 if (!empty($origin) && !empty($originid)) {
2194 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2197 $object->origin_type = $origin;
2198 $object->origin_id = $originid;
2202 $retained_warranty =
GETPOSTINT(
'retained_warranty');
2203 if (
price2num($retained_warranty) > 0) {
2207 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
2208 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
2211 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
2212 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
2213 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
2215 $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);
2218 foreach (
$object->lines as $i => &$line) {
2219 $line->fk_prev_id = $line->id;
2220 $line->fetch_optionals();
2222 $line->situation_percent = 0;
2224 $line->situation_percent = $line->get_prev_progress(
$object->id);
2228 $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);
2229 $line->total_ht = (float) $tabprice[0];
2230 $line->total_tva = (float) $tabprice[1];
2231 $line->total_ttc = (float) $tabprice[2];
2232 $line->total_localtax1 = (float) $tabprice[9];
2233 $line->total_localtax2 = (float) $tabprice[10];
2234 $line->multicurrency_total_ht = (float) $tabprice[16];
2235 $line->multicurrency_total_tva = (float) $tabprice[17];
2236 $line->multicurrency_total_ttc = (float) $tabprice[18];
2239 if ($line->fk_remise_except) {
2241 $result = $discount->fetch($line->fk_remise_except);
2244 if ($discount->fk_facture_line > 0) {
2245 $line->fk_remise_except = 0;
2254 $object->date_pointoftax = $date_pointoftax;
2255 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2271 $object->situation_counter += 1;
2276 $extrafields->fetch_name_optionals_label(
$object->table_element);
2277 $extrafields->setOptionalsFromPost(
null, $object);
2283 $nextSituationInvoice =
new Facture($db);
2284 $nextSituationInvoice->fetch($id);
2287 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id);
2288 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $nextSituationInvoice, $action);
2299 if ($id > 0 && !$error) {
2301 $categories =
GETPOST(
'categories',
'array');
2302 if (method_exists($object,
'setCategories')) {
2303 $object->setCategories($categories);
2311 $outputlangs = $langs;
2314 $newlang =
GETPOST(
'lang_id',
'aZ09');
2317 if (empty(
$object->thirdparty)) {
2320 $newlang =
$object->thirdparty->default_lang;
2322 if (!empty($newlang)) {
2323 $outputlangs =
new Translate(
"", $conf);
2324 $outputlangs->setDefaultLang($newlang);
2325 $outputlangs->load(
'products');
2330 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2336 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2341 $_GET[
"origin"] = $_POST[
"origin"];
2342 $_GET[
"originid"] = $_POST[
"originid"];
2345 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2349 foreach (
$object->lines as $line) {
2350 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2353 if ($line->product_type == 1) {
2354 $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);
2357 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2359 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2360 $vat_rate = str_replace(
'*',
'', $vat_rate);
2363 foreach (
$object->lines as $line) {
2364 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2367 $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);
2369 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2371 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2372 $remise_percent = str_replace(
'*',
'', $remise_percent);
2373 foreach (
$object->lines as $line) {
2374 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2377 $tvatx = $line->tva_tx;
2378 if (!empty($line->vat_src_code)) {
2379 $tvatx .=
' ('.$line->vat_src_code.
')';
2381 $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);
2383 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
2386 $langs->load(
'subtotals');
2388 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
2389 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
2391 $subtotal_options = array();
2393 foreach (Facture::$TITLE_OPTIONS as $option) {
2394 $value =
GETPOST($option,
'alphanohtml');
2396 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2401 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2412 $outputlangs = $langs;
2413 $newlang =
GETPOST(
'lang_id',
'alpha');
2415 $newlang =
$object->thirdparty->default_lang;
2417 if (!empty($newlang)) {
2418 $outputlangs =
new Translate(
"", $conf);
2419 $outputlangs->setDefaultLang($newlang);
2422 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2427 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2429 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
2432 $langs->load(
'subtotals');
2434 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
2435 foreach (
$object->lines as $line) {
2436 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
2437 $desc = $line->desc;
2438 $depth = -$line->qty;
2442 $subtotal_options = array();
2444 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
2445 $value =
GETPOST($option,
'alphanohtml');
2447 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2452 if (isset($desc) && isset($depth)) {
2453 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2455 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
2458 if (isset($result) && $result >= 0) {
2464 $outputlangs = $langs;
2465 $newlang =
GETPOST(
'lang_id',
'alpha');
2467 $newlang =
$object->thirdparty->default_lang;
2469 if (!empty($newlang)) {
2470 $outputlangs =
new Translate(
"", $conf);
2471 $outputlangs->setDefaultLang($newlang);
2474 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2479 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2481 } elseif ($action ==
'addline' &&
GETPOST(
'updateallvatlinesblock',
'alpha') &&
GETPOST(
'vatforblocklines',
'alpha') !==
'' && $usercancreate) {
2482 $tx_tva =
GETPOST(
'vatforblocklines') ?
GETPOST(
'vatforblocklines') : 0;
2483 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'tva', $tx_tva);
2484 } elseif ($action ==
'addline' &&
GETPOST(
'updatealldiscountlinesblock',
'alpha') &&
GETPOST(
'discountforblocklines',
'alpha') !==
'' && $usercancreate) {
2485 $discount =
GETPOST(
'discountforblocklines') ?
GETPOST(
'discountforblocklines') : 0;
2486 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'discount', $discount);
2487 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && !
GETPOST(
'submitforallmark',
'alpha') && $usercancreate) {
2488 $langs->load(
'errors');
2493 $line_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
2496 $price_ht_devise =
'';
2498 $price_ttc_devise =
'';
2501 $price_min_ttc =
'';
2503 if (
GETPOST(
'price_ht') !==
'') {
2506 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2509 if (
GETPOST(
'price_ttc') !==
'') {
2512 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2513 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2516 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2517 if ($prod_entry_mode ==
'free') {
2523 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2528 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2531 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
2532 if (empty($remise_percent)) {
2533 $remise_percent = 0;
2537 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2538 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2540 if (is_array($extralabelsline)) {
2542 foreach ($extralabelsline as $key => $value) {
2543 unset($_POST[
"options_".$key.$predef]);
2547 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2548 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2551 if (!$prod_entry_mode) {
2553 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2557 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2558 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2563 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0)
2564 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
2565 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
2566 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
2567 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
2568 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
2569 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2570 $langs->load(
"errors");
2571 if (
$object->type == $object::TYPE_DEPOSIT) {
2573 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2575 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2580 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
2581 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
2585 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
2586 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2590 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2594 $langs->load(
"errors");
2595 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2599 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2600 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
2604 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2605 $idprod = $res->fk_product_child;
2607 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2613 $price_base_type =
null;
2614 if (!$error && ($qty >= 0) && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
2620 $ret =
$object->fetch_thirdparty();
2625 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2636 if (!empty($idprod) && $idprod > 0) {
2638 $prod->fetch($idprod);
2640 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2645 $datapriceofproduct = $prod->getSellPrice(
$mysoc,
$object->thirdparty, $pqp);
2647 $pu_ht = $datapriceofproduct[
'pu_ht'];
2648 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2649 $price_min = $datapriceofproduct[
'price_min'];
2650 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2651 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2655 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2656 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $prod->tva_tx));
2660 if (!empty($price_ht) || $price_ht ===
'0') {
2662 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2663 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2664 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2665 $pu_ttc_devise = (float)
price2num((
float) $pu_ht_devise * (1 + ((float) $tmpvat / 100)),
'MU');
2668 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2670 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2671 } elseif (!empty($price_ttc_devise) || (
string) $price_ttc_devise ===
'0') {
2672 $pu_ttc_devise = (float)
price2num($price_ttc_devise,
'MU');
2673 $pu_ht_devise = (float)
price2num((
float) $pu_ttc_devise / (1 + ((float) $tmpvat / 100)),
'MU');
2676 } elseif ($tmpvat != $tmpprodvat) {
2678 if ($price_base_type !=
'HT') {
2679 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2681 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2685 $outputlangs = $langs;
2691 if (
GETPOST(
'lang_id',
'aZ09')) {
2692 $newlang =
GETPOST(
'lang_id',
'aZ09');
2694 if (empty($newlang)) {
2695 $newlang =
$object->thirdparty->default_lang;
2697 if (!empty($newlang)) {
2698 $outputlangs =
new Translate(
"", $conf);
2699 $outputlangs->setDefaultLang($newlang);
2700 $outputlangs->load(
'products');
2703 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->
description;
2705 $desc = $prod->description;
2717 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
2721 if (!empty($prod->customcode)) {
2722 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomsCode").
': '.$prod->customcode;
2724 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2727 if (!empty($prod->country_code)) {
2728 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $outputlangs, 0);
2731 if (!empty($prod->customcode)) {
2732 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomsCode").
': '.$prod->customcode;
2734 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2737 if (!empty($prod->country_code)) {
2738 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $langs, 0);
2745 $type = $prod->type;
2746 $fk_unit = $prod->fk_unit;
2748 if (!empty($price_ht)) {
2753 if (!empty($price_ttc)) {
2758 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2759 $tva_tx = str_replace(
'*',
'', $tva_tx);
2760 if (empty($tva_tx)) {
2763 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2766 $fk_unit =
GETPOST(
'units',
'alpha');
2768 if ($pu_ttc && !$pu_ht) {
2769 $price_base_type =
'TTC';
2783 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2784 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2787 $pu_equivalent = $pu_ht;
2788 $pu_equivalent_ttc = $pu_ttc;
2790 $currency_tx =
$object->multicurrency_tx;
2794 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
2795 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
2797 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
2798 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
2813 $fournprice = (int) (
GETPOST(
'fournprice'.$predef) ?
GETPOST(
'fournprice'.$predef) :
'');
2818 $price2num_remise_percent =
price2num($remise_percent);
2819 $price2num_price_min =
price2num($price_min);
2820 $price2num_price_min_ttc =
price2num($price_min_ttc);
2821 if (empty($price2num_pu_ht)) {
2822 $price2num_pu_ht = 0;
2824 if (empty($price2num_remise_percent)) {
2825 $price2num_remise_percent = 0;
2827 if (empty($price2num_price_min)) {
2828 $price2num_price_min = 0;
2830 if (empty($price2num_price_min_ttc)) {
2831 $price2num_price_min_ttc = 0;
2836 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2837 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2840 } 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') {
2841 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2848 '@phan-var-force CommonObjectLine[] $lines';
2850 if (
isModEnabled(
'productbatch') && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) &&
getDolGlobalString(
'INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS')) {
2851 $langs->load(
'productbatch');
2852 foreach ($lines[$i]->detail_batch as $batchline) {
2853 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2858 $situation_percent = (GETPOSTISSET(
'progress') ?
GETPOSTINT(
'progress') : 100);
2860 $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);
2865 $outputlangs = $langs;
2868 $newlang =
GETPOST(
'lang_id',
'aZ09');
2871 $newlang =
$object->thirdparty->default_lang;
2873 if (!empty($newlang)) {
2874 $outputlangs =
new Translate(
"", $conf);
2875 $outputlangs->setDefaultLang($newlang);
2876 $outputlangs->load(
'products');
2881 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2887 unset($_POST[
'prod_entry_mode']);
2888 unset($_POST[
'qty']);
2889 unset($_POST[
'type']);
2890 unset($_POST[
'remise_percent']);
2891 unset($_POST[
'price_ht']);
2892 unset($_POST[
'multicurrency_price_ht']);
2893 unset($_POST[
'price_ttc']);
2894 unset($_POST[
'tva_tx']);
2895 unset($_POST[
'product_ref']);
2896 unset($_POST[
'product_label']);
2897 unset($_POST[
'product_desc']);
2898 unset($_POST[
'fournprice']);
2899 unset($_POST[
'buying_price']);
2900 unset($_POST[
'np_marginRate']);
2901 unset($_POST[
'np_markRate']);
2902 unset($_POST[
'dp_desc']);
2903 unset($_POST[
'idprod']);
2904 unset($_POST[
'units']);
2905 unset($_POST[
'date_starthour']);
2906 unset($_POST[
'date_startmin']);
2907 unset($_POST[
'date_startsec']);
2908 unset($_POST[
'date_startday']);
2909 unset($_POST[
'date_startmonth']);
2910 unset($_POST[
'date_startyear']);
2911 unset($_POST[
'date_endhour']);
2912 unset($_POST[
'date_endmin']);
2913 unset($_POST[
'date_endsec']);
2914 unset($_POST[
'date_endday']);
2915 unset($_POST[
'date_endmonth']);
2916 unset($_POST[
'date_endyear']);
2917 unset($_POST[
'situations']);
2918 unset($_POST[
'progress']);
2926 } elseif ($action ==
'addline' && $usercancreate && (
2927 (
GETPOST(
'submitforallmargins',
'alpha') &&
GETPOST(
'marginforalllines',
'alpha') !==
'') ||
2928 (
GETPOST(
'submitforallmark',
'alpha') &&
GETPOST(
'markforalllines',
'alpha') !==
''))) {
2930 $margin_rate = GETPOSTISSET(
'marginforalllines') ?
GETPOST(
'marginforalllines',
'int') :
'';
2931 $mark_rate = GETPOSTISSET(
'markforalllines') ?
GETPOST(
'markforalllines',
'int') :
'';
2932 foreach (
$object->lines as &$line)
if ($line->subprice > 0) {
2933 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2936 $subprice_multicurrency = $line->subprice;
2937 if (is_numeric($margin_rate) && $margin_rate > 0) {
2938 $line->subprice = (float)
price2num((
float) $line->pa_ht * (1 + (float) $margin_rate / 100),
'MU');
2939 } elseif (is_numeric($mark_rate) && $mark_rate > 0) {
2940 $line->subprice = (float) ($line->pa_ht / (1 - ((
float) $mark_rate / 100)));
2942 $line->subprice = (float) $line->pa_ht;
2946 $res = $prod->fetch($line->fk_product);
2948 if ($prod->price_min > $line->subprice) {
2949 $price_subprice =
price($line->subprice, 0, $outlangs, 1, -1, -1,
'auto');
2950 $price_price_min =
price($prod->price_min, 0, $outlangs, 1, -1, -1,
'auto');
2951 setEventMessages($prod->ref .
' - ' . $prod->label .
' (' . $price_subprice .
' < ' . $price_price_min .
' ' . strtolower($langs->trans(
"MinPrice")) .
')' .
"\n",
null,
'warnings');
2955 } elseif ($line->fk_product) {
2959 $multicurrency_subprice = (float) $line->subprice * $line->multicurrency_subprice / $subprice_multicurrency;
2961 $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);
2964 if (is_numeric($margin_rate) && empty($mark_rate)) {
2965 $line->marge_tx = $margin_rate;
2966 } elseif (is_numeric($mark_rate) && empty($margin_rate)) {
2967 $line->marque_tx = $mark_rate;
2969 $line->total_ht = $line->qty * (float) $line->subprice;
2970 $line->total_tva = $line->tva_tx * $line->qty * (float) $line->subprice;
2971 $line->total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $line->subprice;
2973 $line->multicurrency_total_ht = $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
2974 $line->multicurrency_total_tva = $line->tva_tx * $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
2975 $line->multicurrency_total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
2977 $line->multicurrency_subprice = $multicurrency_subprice;
2982 } elseif ($action ==
'updatetitleline' && GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2985 $langs->load(
'subtotals');
2987 $desc =
GETPOST(
'line_desc',
'alphanohtml') ?? $langs->trans(
"Title");
2990 $subtotal_options = array();
2992 foreach (Facture::$TITLE_OPTIONS as $option) {
2993 $value =
GETPOST($option,
'alphanohtml');
2995 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
3000 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3011 $outputlangs = $langs;
3012 $newlang =
GETPOST(
'lang_id',
'alpha');
3014 $newlang =
$object->thirdparty->default_lang;
3016 if (!empty($newlang)) {
3017 $outputlangs =
new Translate(
"", $conf);
3018 $outputlangs->setDefaultLang($newlang);
3021 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3026 } elseif ($action ==
'updatesubtotalline' && GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3029 $langs->load(
'subtotals');
3031 $desc =
GETPOST(
'line_desc',
'alphanohtml');
3034 $subtotal_options = array();
3036 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
3037 $value =
GETPOST($option,
'alphanohtml');
3039 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
3044 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3052 $outputlangs = $langs;
3053 $newlang =
GETPOST(
'lang_id',
'alpha');
3055 $newlang =
$object->thirdparty->default_lang;
3057 if (!empty($newlang)) {
3058 $outputlangs =
new Translate(
"", $conf);
3059 $outputlangs->setDefaultLang($newlang);
3062 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3067 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3068 if (!
$object->fetch($id) > 0) {
3091 if (preg_match(
'/\*/', $vat_rate)) {
3096 $vat_rate = str_replace(
'*',
'', $vat_rate);
3101 $fournprice = (int) (
GETPOST(
'fournprice') ?
GETPOST(
'fournprice') :
'');
3105 $pu_equivalent = $pu_ht;
3106 $pu_equivalent_ttc = $pu_ttc;
3108 $currency_tx =
$object->multicurrency_tx;
3112 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3113 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
3115 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3116 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
3131 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
3132 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
3134 if (is_array($extralabelsline)) {
3136 foreach ($extralabelsline as $key => $value) {
3137 unset($_POST[
"options_".$key]);
3143 if ($special_code == 3) {
3149 $percent = $line->get_prev_progress(
$object->id);
3154 if ($progress >= 0) {
3155 $mesg = $langs->trans(
"CantBeNullOrPositive");
3159 } elseif ($progress < $line->situation_percent) {
3160 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
3164 } elseif ($progress < $percent) {
3165 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
3173 if (empty($remise_percent)) {
3174 $remise_percent = 0;
3177 $price_base_type =
'HT';
3179 if (empty($pu) && !empty($pu_ttc)) {
3181 $price_base_type =
'TTC';
3186 if (!empty($productid)) {
3188 $product->fetch($productid);
3190 $type = $product->type;
3192 $price_min = $product->price_min;
3194 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
3196 $price_min_ttc = $product->price_min_ttc;
3198 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
3205 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
3206 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
3209 $action =
'editline';
3210 } 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') {
3211 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
3214 $action =
'editline';
3219 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
3223 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
3228 $langs->load(
"errors");
3229 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
3233 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
3234 $langs->load(
"errors");
3235 if (
$object->type == $object::TYPE_DEPOSIT) {
3237 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
3239 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
3243 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
3250 $previousprogress = $line->getAllPrevProgress($line->fk_facture);
3253 if ($fullprogress < $previousprogress) {
3255 setEventMessages($langs->trans(
'CantBeLessThanMinPercent'),
null,
'errors');
3259 if ($fullprogress > 100) {
3260 $fullprogress = 100;
3262 $addprogress = $fullprogress - $previousprogress;
3269 if (empty($usercancreatemargin)) {
3270 foreach (
$object->lines as &$line) {
3272 $fournprice = $line->fk_fournprice;
3273 $buyingprice = $line->pa_ht;
3279 $result =
$object->updateline(
3284 (
float) $remise_percent,
3302 (
float) $pu_ht_devise
3308 $outputlangs = $langs;
3311 $newlang =
GETPOST(
'lang_id',
'aZ09');
3314 $newlang =
$object->thirdparty->default_lang;
3316 if (!empty($newlang)) {
3317 $outputlangs =
new Translate(
"", $conf);
3318 $outputlangs->setDefaultLang($newlang);
3319 $outputlangs->load(
'products');
3323 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3326 unset($_POST[
'qty']);
3327 unset($_POST[
'type']);
3328 unset($_POST[
'productid']);
3329 unset($_POST[
'remise_percent']);
3330 unset($_POST[
'price_ht']);
3331 unset($_POST[
'multicurrency_price_ht']);
3332 unset($_POST[
'price_ttc']);
3333 unset($_POST[
'tva_tx']);
3334 unset($_POST[
'product_ref']);
3335 unset($_POST[
'product_label']);
3336 unset($_POST[
'product_desc']);
3337 unset($_POST[
'fournprice']);
3338 unset($_POST[
'buying_price']);
3339 unset($_POST[
'np_marginRate']);
3340 unset($_POST[
'np_markRate']);
3341 unset($_POST[
'dp_desc']);
3342 unset($_POST[
'idprod']);
3343 unset($_POST[
'units']);
3344 unset($_POST[
'date_starthour']);
3345 unset($_POST[
'date_startmin']);
3346 unset($_POST[
'date_startsec']);
3347 unset($_POST[
'date_startday']);
3348 unset($_POST[
'date_startmonth']);
3349 unset($_POST[
'date_startyear']);
3350 unset($_POST[
'date_endhour']);
3351 unset($_POST[
'date_endmin']);
3352 unset($_POST[
'date_endsec']);
3353 unset($_POST[
'date_endday']);
3354 unset($_POST[
'date_endmonth']);
3355 unset($_POST[
'date_endyear']);
3356 unset($_POST[
'situations']);
3357 unset($_POST[
'progress']);
3362 } elseif ($action ==
'updatealllines' && $usercancreate && GETPOSTISSET(
'all_percent')) {
3363 if (!
$object->fetch($id) > 0) {
3366 if (
GETPOST(
'all_progress') !=
"") {
3368 foreach (
$object->lines as $line) {
3370 $percent = $line->getAllPrevProgress(
$object->id);
3372 $percent = $line->get_prev_progress(
$object->id);
3374 if (
$object->type != $object::TYPE_CREDIT_NOTE && (
float) $all_progress < (
float) $percent) {
3375 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
3378 } elseif (
$object->type == $object::TYPE_CREDIT_NOTE && (
float) $all_progress > (
float) $percent) {
3379 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeMoreThanMinPercent");
3388 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
3389 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
3391 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
3393 $object->fetch($id,
'',
'', 0,
true);
3396 &&
$object->isSituationInvoice()
3399 &&
$object->is_last_in_cycle()
3400 && $usercanunvalidate
3403 $newCycle =
$object->newCycle();
3404 if ($newCycle > 1) {
3406 $lastCycle =
$object->situation_cycle_ref;
3407 $lastSituationCounter =
$object->situation_counter;
3408 $linkedCreditNotesList = array();
3410 if (count(
$object->tab_next_situation_invoice) > 0) {
3411 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
3413 && $next_invoice->situation_counter ==
$object->situation_counter
3414 && $next_invoice->fk_facture_source ==
$object->id
3416 $linkedCreditNotesList[] = $next_invoice->id;
3421 $object->situation_cycle_ref = $newCycle;
3422 $object->situation_counter = 1;
3424 if (
$object->update($user) > 0) {
3426 if (count($linkedCreditNotesList) > 0) {
3428 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
3429 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
3430 $sql .=
' , situation_final=0';
3431 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
3432 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
3434 $resql = $db->query($sql);
3440 foreach (
$object->lines as $line) {
3442 if ($line->product_type == 9) {
3447 if (!empty(
$object->tab_previous_situation_invoice)) {
3449 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
3450 $searchPreviousInvoice =
true;
3451 while ($searchPreviousInvoice) {
3452 if (
$object->tab_previous_situation_invoice[$lineIndex]->isSituationInvoice() || $lineIndex < 1) {
3453 $searchPreviousInvoice =
false;
3461 $maxPrevSituationPercent = 0;
3462 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
3463 if ($prevLine->id == $line->fk_prev_id) {
3464 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
3469 $line->situation_percent -= $maxPrevSituationPercent;
3471 if ($line->update() < 0) {
3480 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
3482 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
3485 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
3488 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
3494 $fromElement =
GETPOST(
'fromelement');
3495 $fromElementid =
GETPOST(
'fromelementid');
3496 $importLines =
GETPOST(
'line_checkbox');
3498 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
3499 $lineClassName =
'';
3500 if ($fromElement ==
'commande') {
3502 $lineClassName =
'OrderLine';
3503 } elseif ($fromElement ==
'propal') {
3504 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
3505 $lineClassName =
'PropaleLigne';
3507 $nextRang = count(
$object->lines) + 1;
3510 foreach ($importLines as $lineId) {
3511 if ($lineClassName ===
'') {
3515 dol_syslog(
'compta/facture/card - No lineClassName - skip import', LOG_ERR);
3522 $lineId = intval($lineId);
3523 $originLine =
new $lineClassName($db);
3524 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
3525 $originLine->fetch_optionals();
3526 $desc = $originLine->desc;
3527 $pu_ht = $originLine->subprice;
3528 $qty = $originLine->qty;
3529 $txtva = $originLine->tva_tx;
3530 $txlocaltax1 = $originLine->localtax1_tx;
3531 $txlocaltax2 = $originLine->localtax2_tx;
3532 $fk_product = $originLine->fk_product;
3533 $remise_percent = $originLine->remise_percent;
3534 $date_start = $originLine->date_start;
3535 $date_end = $originLine->date_end;
3536 $fk_code_ventilation = 0;
3537 $info_bits = $originLine->info_bits;
3538 $fk_remise_except = $originLine->fk_remise_except;
3539 $price_base_type =
'HT';
3541 $type = $originLine->product_type;
3542 $rang = $nextRang++;
3543 $special_code = $originLine->special_code;
3544 $origin = $originLine->element;
3545 $origin_id = $originLine->id;
3546 $fk_parent_line = 0;
3547 $fk_fournprice = $originLine->fk_fournprice;
3548 $pa_ht = $originLine->pa_ht;
3549 $label = $originLine->label;
3550 $array_options = $originLine->array_options;
3551 if (
$object->isSituationInvoice()) {
3552 $situation_percent = 0;
3554 $situation_percent = 100;
3557 $fk_unit = $originLine->fk_unit;
3558 $pu_ht_devise = $originLine->multicurrency_subprice;
3560 $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);
3580 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3586 if (!empty(
$object->id) && $action ==
'send') {
3588 $object->getSommePaiement(-1);
3589 $object->getSumCreditNotesUsed(-1);
3590 $object->getSumDepositsUsed(-1);
3592 $triggersendname =
'BILL_SENTBYMAIL';
3594 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3595 $trackid =
'inv'.$object->id;
3596 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3599 $upload_dir = $conf->invoice->multidir_output[!empty(
$object->entity) ?
$object->entity : $conf->entity];
3600 $permissiontoadd = $usercancreate;
3601 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3604 if ($action ==
'update_extras' && $permissiontoeditextra) {
3607 $attribute_name =
GETPOST(
'attribute',
'aZ09');
3610 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
3617 $result =
$object->updateExtraField($attribute_name,
'BILL_MODIFY');
3625 $action =
'edit_extras';
3630 if ($action ==
'addcontact' && $usercancreate) {
3631 $result =
$object->fetch($id);
3633 if ($result > 0 && $id > 0) {
3636 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3640 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3643 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3644 $langs->load(
"errors");
3645 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3650 } elseif ($action ==
'swapstatut' && $usercancreate) {
3657 } elseif ($action ==
'deletecontact' && $usercancreate) {
3660 $result =
$object->delete_contact($lineid);
3663 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3671 $action =
'edit_extras';
3681$form =
new Form($db);
3687$bankaccountstatic =
new Account($db);
3695$title =
$object->ref.
" - ".$langs->trans(
'Card');
3696if ($action ==
'create') {
3697 $title = $langs->trans(
"NewBill");
3699$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3705if ($action ==
'create') {
3706 $facturestatic =
new Facture($db);
3707 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3712 $res = $soc->fetch($socid);
3715 $currency_code = $conf->currency;
3717 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3718 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3722 if (empty($dateinvoice)) {
3729 if (!empty($origin) && !empty($originid)) {
3731 $element = $subelement = $origin;
3733 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3734 $element = $regs[1];
3735 $subelement = $regs[2];
3740 if ($element ==
'project') {
3741 $projectid = $originid;
3743 if (empty($cond_reglement_id)) {
3744 $cond_reglement_id = $soc->cond_reglement_id;
3746 if (empty($mode_reglement_id)) {
3747 $mode_reglement_id = $soc->mode_reglement_id;
3749 if (empty($fk_account)) {
3750 $fk_account = $soc->fk_account;
3754 if ($element ==
'order' || $element ==
'commande') {
3755 $element = $subelement =
'commande';
3757 if ($element ==
'propal') {
3758 $element =
'comm/propal';
3759 $subelement =
'propal';
3761 if ($element ==
'contract') {
3762 $element = $subelement =
'contrat';
3764 if ($element ==
'shipping') {
3765 $element = $subelement =
'expedition';
3770 $classname = ucfirst($subelement);
3771 $objectsrc =
new $classname($db);
3772 '@phan-var-force Commande|Propal|Contrat|Expedition $objectsrc';
3774 $objectsrc->fetch($originid);
3775 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3776 $objectsrc->fetch_lines();
3778 $objectsrc->fetch_thirdparty();
3780 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3786 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3790 if (empty($socid)) {
3791 $soc = $objectsrc->thirdparty;
3794 if ($element ==
'expedition') {
3795 $elem = $subelem = $objectsrc->origin_type;
3796 $expeoriginid = $objectsrc->origin_id;
3798 $classname = ucfirst($subelem);
3800 $expesrc =
new $classname($db);
3801 '@phan-var-force Expedition $expesrc';
3803 dol_syslog(
"Is type Facture|Commande or Expedition: $element...expesrc($classname)=".get_class($expesrc));
3804 $expesrc->fetch($expeoriginid);
3806 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3807 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3808 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3811 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3812 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3816 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3819 $expesrc->fetch_optionals();
3820 $object->array_options = $expesrc->array_options;
3822 $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)));
3823 $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)));
3824 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : (!empty($fk_account) ? $fk_account : 0)));
3827 if (!empty($objectsrc->multicurrency_code)) {
3828 $currency_code = $objectsrc->multicurrency_code;
3830 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
3831 $currency_tx = $objectsrc->multicurrency_tx;
3836 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3839 $objectsrc->fetch_optionals();
3840 $object->array_options = $objectsrc->array_options;
3844 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
3845 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
3846 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
3847 $inputReasonId = empty($soc->demand_reason_id) ? $inputReasonId : $soc->demand_reason_id;
3849 if (
isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3850 $currency_code = $soc->multicurrency_code;
3855 if (!
GETPOST(
'changecompany')) {
3856 if (GETPOSTISSET(
'cond_reglement_id')) {
3857 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3859 if (GETPOSTISSET(
'mode_reglement_id')) {
3860 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3862 if (GETPOSTISSET(
'cond_reglement_id')) {
3868 if (empty($cond_reglement_id)) {
3869 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
3873 if (empty($mode_reglement_id)) {
3874 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
3884 if (!empty($soc->id)) {
3885 $absolute_discount = $soc->getAvailableDiscounts();
3887 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
3888 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
3890 if (!empty($conf->use_javascript_ajax)) {
3891 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3897 if ($origin ==
'contrat') {
3898 $langs->load(
"admin");
3899 $text = $langs->trans(
"ToCreateARecurringInvoice");
3900 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3902 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3904 print
info_admin($text, 0, 0,
'info',
'').
'<br>';
3907 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3908 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3909 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3910 print
'<input type="hidden" name="changecompany" value="0">';
3912 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3914 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3915 print
'<input name="ref" type="hidden" value="provisoire">';
3916 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3917 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3918 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3919 print
'<input name="force_fk_account" type="hidden" value="0">';
3920 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3921 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3922 print
'<input type="hidden" name="originentity" value="'.GETPOSTINT(
'originentity').
'">';
3923 if (!empty($currency_tx)) {
3924 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3930 $parameters = array();
3932 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters, $object, $action);
3933 if (empty($reshook)) {
3934 print
'<table class="border centpercent">';
3936 $exampletemplateinvoice =
new FactureRec($db);
3938 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
3939 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
3943 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
'Ref').
'</td>';
3944 print
'<td colspan="2">';
3945 print $langs->trans(
"Draft");
3950 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
3952 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
'Customer').
'</td>';
3953 print
'<td colspan="2">';
3954 print $soc->getNomUrl(1,
'customer');
3955 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3957 $arrayoutstandingbills = $soc->getOutstandingBills();
3958 $outstandingBills = $arrayoutstandingbills[
'opened'];
3959 print
' - <span class="opacitymedium valignmiddle">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3960 print
'<span class="amount valignmiddle">'.price($outstandingBills, 0, $langs, 0, 0, -1, $conf->currency).
'</span>';
3961 if ($soc->outstanding_limit !=
'') {
3962 if ($outstandingBills > $soc->outstanding_limit) {
3963 print
img_warning($langs->trans(
"OutstandingBillReached"));
3965 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1, $conf->currency);
3970 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3971 print
'<td colspan="2">';
3972 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
3973 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3977 $(document).ready(function() {
3978 $("#socid").change(function() {
3980 console.log("Submit page");
3981 $(\'input[name="action"]\').val(\'create\');
3982 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3983 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3984 $(\'input[name="force_fk_account"]\').val(\'1\');
3985 $("#formtocreate").submit(); */
3987 // For company change, we must submit page with action=create instead of action=add
3988 console.log("We have changed the company - Resubmit page");
3989 jQuery("input[name=changecompany]").val("1");
3990 jQuery("#formtocreateaction").val("create");
3991 jQuery("#formtocreate").submit();
3997 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>';
4004 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
4006 foreach ($invoice_predefined->array_options as $key => $option) {
4007 if (!isset(
$object->array_options[$key])) {
4008 $object->array_options[$key] = $invoice_predefined->array_options[$key];
4012 $dateinvoice = $invoice_predefined->date_when;
4013 if (empty($projectid)) {
4014 $projectid = $invoice_predefined->fk_project;
4016 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
4017 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
4018 $fk_account = $invoice_predefined->fk_account;
4019 $note_public = $invoice_predefined->note_public;
4020 $note_private = $invoice_predefined->note_private;
4022 if (!empty($invoice_predefined->multicurrency_code)) {
4023 $currency_code = $invoice_predefined->multicurrency_code;
4025 if (!empty($invoice_predefined->multicurrency_tx)) {
4026 $currency_tx = $invoice_predefined->multicurrency_tx;
4029 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
4030 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
4031 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
4033 $resql = $db->query($sql);
4035 $num = $db->num_rows($resql);
4039 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
4041 print
'<select class="flat" id="fac_rec" name="fac_rec">';
4042 print
'<option value="0" selected></option>';
4044 $objp = $db->fetch_object($resql);
4045 print
'<option value="'.$objp->rowid.
'"';
4048 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
4050 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
4059 print
'<script type="text/javascript">
4060 $(document).ready(function() {
4061 $("#fac_rec").change(function() {
4062 console.log("We have changed the template invoice - Reload page");
4063 var fac_rec = $(this).val();
4064 var socid = $(\'#socid\').val();
4065 // 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.
4066 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
4079 print
'<tr><td class="tdtop fieldrequired titlefieldcreate">'.$langs->trans(
'Type').
'</td><td colspan="2">';
4080 print
'<div class="listofinvoicetypetable">'.
"\n";
4083 print
'<div class="listofinvoicetype"><div class="">';
4084 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
4085 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
4087 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'nowraponall', 0, 3,
'standardonsmartphone');
4089 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
4099 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%') .
'"/>';
4102 print
'</div></div>'.
"\n";
4104 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
4107 print
'<div class="listofinvoicetype"><div class="">';
4108 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
4109 print
'<script type="text/javascript">
4110 jQuery(document).ready(function() {
4111 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
4112 jQuery("#radio_standard").prop("checked", true);
4114 jQuery("#typedeposit, #valuedeposit").click(function() {
4115 jQuery("#radio_deposit").prop("checked", true);
4117 jQuery("#typedeposit").change(function() {
4118 console.log("We change type of down payment: "+jQuery("#typedeposit").val());
4120 if (jQuery("#typedeposit").val() == "amount") {
4121 jQuery("#valuedeposit").attr("placeholder", "'.$langs->getCurrencySymbol($conf->currency).
'");
4122 jQuery("#valuedeposit").val("");
4124 jQuery("#valuedeposit").attr("placeholder", "50%");
4125 jQuery("#valuedeposit").val("");
4128 jQuery("#radio_deposit").prop("checked", true);
4129 setRadioForTypeOfInvoice();
4131 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
4132 setRadioForTypeOfInvoice();
4135 function setRadioForTypeOfInvoice() {
4136 console.log("Change radio for type of invoice");
4137 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
4138 jQuery("#checkforselects").prop("disabled", true);
4139 jQuery("#checkforselects").prop("checked", false);
4140 jQuery(".checkforselect").prop("disabled", true);
4141 jQuery(".checkforselect").prop("checked", false);
4143 jQuery("#checkforselects").prop("disabled", false);
4144 jQuery("#checkforselects").prop("checked", true);
4145 jQuery(".checkforselect").prop("disabled", false);
4146 jQuery(".checkforselect").prop("checked", true);
4152 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
4154 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
4156 if (($origin ==
'propal') || ($origin ==
'commande')) {
4159 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
4160 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
4161 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4165 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4169 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
4171 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
4172 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
4173 if (!empty($origin_payment_conditions_deposit_percent)) {
4174 $typedeposit =
'variable';
4177 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
4178 $valuedeposit = $objectsrc->deposit_percent;
4180 print
'<span class="marginleftonly">'.$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1).
'</span>';
4182 print
'<input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.($valuedeposit ? $valuedeposit :
'').
'"'.($valuedeposit ?
'' :
'placeholder="'.$langs->getCurrencySymbol($conf->currency).
'"').
'>';
4185 print
'</div></div>'.
"\n";
4192 print
'<div class="listofinvoicetype"><div class="">';
4193 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
4194 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
4196 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
4200 $opt = $form->selectSituationInvoices((
string)
GETPOSTINT(
'originid'), $socid);
4203 print
'</div></div><div class="listofinvoicetype"><div>';
4205 $tmp =
'<input id="radio_situation_bis" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
4206 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4207 $tmp .=
' disabled';
4210 $text = $tmp.
'<label for="radio_situation_bis">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4212 $text .=
'<select class="flat minwidth125" id="situations" name="situations"';
4213 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4214 $text .=
' disabled';
4218 $text .=
'</select>';
4219 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
4221 print
'</div></div>'.
"\n";
4227 $facids = $facturestatic->list_replacable_invoices($soc->id);
4233 if (is_array($facids)) {
4234 foreach ($facids as $facparam) {
4235 $options .=
'<option value="'.$facparam [
'id'].
'"';
4236 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
4237 $options .=
' selected';
4239 $options .=
'>'.$facparam[
'ref'];
4240 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
4241 $options .=
'</option>';
4245 print
'<!-- replacement line -->';
4246 print
'<div class="listofinvoicetype"><div class="">';
4247 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
4248 if (!$options || $invoice_predefined->id > 0) {
4249 $tmp .=
' disabled';
4252 print
'<script type="text/javascript">
4253 jQuery(document).ready(function() {
4254 jQuery("#fac_replacement").change(function() {
4255 console.log("We change fac_replacement");
4256 jQuery("#radio_replacement").prop("checked", true);
4260 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
4261 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
4262 if (!$options || $invoice_predefined->id > 0) {
4263 $text .=
' disabled';
4267 $text .=
'<option value="-1"> </option>';
4270 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
4272 $text .=
'</select>';
4273 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
4275 print
'</div></div>'.
"\n";
4279 print
'<div class="listofinvoicetype"><div class="">';
4280 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
4281 $text = $tmp.
'<label class="opacitymedium">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4282 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'firstsituationonsmartphone');
4284 print
'</div></div>'.
"\n";
4287 print
'<div class="listofinvoicetype"><div class="">';
4288 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
4289 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
4290 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'replacementonsmartphone');
4292 print
'</div></div>'.
"\n";
4295 if (empty($origin)) {
4300 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
4306 $newinvoice_static =
new Facture($db);
4307 foreach ($facids as $key => $valarray) {
4308 $newinvoice_static->id = $key;
4309 $newinvoice_static->ref = $valarray [
'ref'];
4310 $newinvoice_static->statut = $valarray [
'status'];
4311 $newinvoice_static->status = $valarray [
'status'];
4312 $newinvoice_static->type = $valarray [
'type'];
4313 $newinvoice_static->paye = $valarray [
'paye'];
4314 $newinvoice_static->paid = $valarray [
'paye'];
4316 $optionsav .=
'<option value="'.$key.
'"';
4317 if ($key ==
GETPOST(
'fac_avoir')) {
4318 $optionsav .=
' selected';
4321 $newinvoice_static->fetch_optionals($key);
4322 $object->array_options = $newinvoice_static->array_options;
4325 $optionsav .= $newinvoice_static->ref;
4326 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
4327 $optionsav .=
'</option>';
4330 print
'<div class="listofinvoicetype"><div class="">';
4331 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
4332 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
4333 $tmp .=
' disabled';
4337 print
'<script type="text/javascript">
4338 jQuery(document).ready(function() {
4339 if (jQuery("#radio_creditnote").is(":checked"))
4341 jQuery("#radio_standard").prop("disabled", true);
4343 jQuery("#radio_standard").prop("disabled", false);
4345 if (! jQuery("#radio_creditnote").is(":checked"))
4347 jQuery("#credit_note_options").hide();
4349 jQuery("#radio_creditnote").click(function() {
4351 jQuery("#credit_note_options").show();
4353 jQuery("#radio_standard, #radio_replacement, #radio_deposit, #radio_situation, #radio_situation_bis").click(function() {
4354 console.log("We click on a radio to close credit not options");
4355 jQuery("#credit_note_options").hide();
4359 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
4360 $text .=
'<select class="flat valignmiddle minwidth200" name="fac_avoir" id="fac_avoir"';
4361 if (!$optionsav || $invoice_predefined->id > 0) {
4362 $text .=
' disabled';
4366 $text .=
'<option value="-1">'.$langs->trans(
"InvoiceAvoirAskCombo").
'</option>';
4367 $text .= $optionsav;
4369 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
4371 $text .=
'</select>';
4372 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
4375 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
4376 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>";
4377 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>";
4382 print
'</div></div>'.
"\n";
4385 print
'<div class="listofinvoicetype"><div class="">';
4387 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
4389 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
4391 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
4393 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
4395 print
'</div></div>'.
"\n";
4400 print
'<div class="listofinvoicetype"><div class="">';
4401 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
4402 $text = $tmp.
'<label class="opacitymedium" for="radio_template">'.$langs->trans(
"RepeatableInvoice").
'</label> ';
4403 $desc = $form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3,
'templateonsmartphone');
4405 print
'</div></div>'.
"\n";
4414 foreach ($listtType as $type) {
4415 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
4417 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
4420 print
'<script type="text/javascript">
4421 $(document).ready(function() {
4422 var listType = {'.$jsListType.
'};
4423 $("[name=\'type\']").change(function() {
4424 console.log("change name=type");
4425 if ($( this ).prop("checked"))
4427 if(($( this ).val() in listType))
4429 $("#model").val(listType[$( this ).val()]).trigger("change");
4446 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
4447 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
4453 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
4457 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
4460 $defaulttpldir =
'/core/tpl';
4461 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
4462 foreach ($dirtpls as $module => $reldir) {
4464 if (!empty($module)) {
4467 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
4469 if (file_exists($tpl)) {
4470 if (empty($conf->file->strict_mode)) {
4471 $res = @include $tpl;
4473 $res = include $tpl;
4476 if ($res) {
break; }
4486 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
4487 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4488 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
4493 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
4494 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4495 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
4500 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
4501 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
4502 print $form->getSelectConditionsPaiements((
int) $cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
4507 $rwStyle =
'display:none;';
4508 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
4512 $retained_warranty =
GETPOSTINT(
'retained_warranty');
4513 if (empty($retained_warranty)) {
4514 if ($objectsrc !==
null && property_exists($objectsrc,
'retained_warranty') && !empty($objectsrc->retained_warranty)) {
4516 $retained_warranty = $objectsrc->retained_warranty;
4519 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
4521 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
4522 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
4525 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
4526 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
4527 if (empty($retained_warranty_fk_cond_reglement)) {
4528 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4529 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
4530 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
4532 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4535 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4538 print
'<script type="text/javascript">
4539 $(document).ready(function() {
4540 $("[name=\'type\']").change(function() {
4541 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
4543 $(".retained-warranty-line").show();
4544 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
4547 $(".retained-warranty-line").hide();
4548 $("#new-situation-invoice-retained-warranty").val("");
4552 $("[name=\'type\']:checked").trigger("change");
4558 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
4559 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
4560 print $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth250 widthcentpercentminusx', 1);
4565 print
'<tr><td>'.$langs->trans(
'DefaultBankAccount').
'</td><td colspan="2">';
4566 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4567 print $form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth250 widthcentpercentminusx', 1);
4573 print
'<tr><td>'.$langs->trans(
'Source').
'</td><td>';
4574 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
4575 $form->selectInputReason((
string) $inputReasonId,
'input_reason_id',
'', 1,
'maxwidth250 widthcentpercentminusx');
4578 print
'<input type="hidden" name="input_reason_id" value="'.((string) $inputReasonId).
'">';
4582 if (
isModEnabled(
'project') && is_object($formproject)) {
4583 $langs->load(
'projects');
4584 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
4585 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
4587 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');
4588 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>';
4595 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
4596 print
'<td colspan="2" class="maxwidthonsmartphone">';
4597 $incoterm_id =
GETPOST(
'incoterm_id');
4598 $location_incoterms =
GETPOST(
'location_incoterms');
4599 if (empty($incoterm_id)) {
4600 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
4601 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
4603 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
4604 print $form->select_incoterms($incoterm_id, $location_incoterms);
4618 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
4619 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
4624 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
4625 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
4626 print $hookmanager->resPrint;
4627 if (empty($reshook)) {
4628 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
4631 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
4632 if ($soc->fetch_optionals() > 0) {
4633 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
4637 print
$object->showOptionals($extrafields,
'create', $parameters);
4641 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
4642 print
'<td colspan="2">';
4643 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
4644 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
4649 $paramkey =
'FACTURE_ADDON_PDF_'.$type;
4654 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
4660 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
4661 print
'<td colspan="2" class="maxwidthonsmartphone">';
4662 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
4663 print $form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth200 widthcentpercentminusx');
4670 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
4671 if (empty($dateexample)) {
4674 $substitutionarray = array(
4675 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
4676 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
4677 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
4678 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
4679 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
4680 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
4681 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
4682 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
4683 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
4684 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
4685 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
4688 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
4689 foreach ($substitutionarray as $key => $val) {
4690 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
4692 $htmltext .=
'</i>';
4697 print
'<td class="tdtop">';
4698 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
4700 print
'<td valign="top" colspan="2">';
4701 $doleditor =
new DolEditor(
'note_public', (
string) $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
4702 print $doleditor->Create(1);
4705 if (empty($user->socid)) {
4707 print
'<td class="tdtop">';
4708 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4710 print
'<td valign="top" colspan="2">';
4711 $doleditor =
new DolEditor(
'note_private', (
string) $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4712 print $doleditor->Create(1);
4718 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4719 $langs->loadLangs(array(
'orders',
'propal'));
4722 if ($origin ==
'contrat') {
4723 '@phan-var-force Contrat $objectsrc';
4725 $objectsrc->update_price(1,
'auto', 1);
4728 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4729 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4730 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4731 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4736 switch (get_class($objectsrc)) {
4738 $newclassname =
'CommercialProposal';
4741 $newclassname =
'Order';
4744 $newclassname =
'Sending';
4747 $newclassname =
'Contract';
4750 $newclassname =
'Intervention';
4753 $newclassname = get_class($objectsrc);
4757 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4758 print
'<td colspan="2">';
4759 print $objectsrc->getNomUrl(1);
4761 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
4762 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4764 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4768 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht, 1, $langs, 1, -1,
'', $conf->currency).
'</td></tr>';
4769 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva, 1, $langs, 1, -1,
'', $conf->currency).
"</td></tr>";
4770 if (
$mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4771 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>";
4774 if (
$mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4775 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>";
4777 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc, 1, $langs, 1, -1,
'', $conf->currency).
"</td></tr>";
4779 if (
isModEnabled(
'multicurrency') && $objectsrc->multicurrency_code != $conf->currency) {
4781 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
'</td></tr>';
4782 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4783 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4791 print $form->buttonsSaveCancel(
"CreateDraft");
4794 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4797 $title = $langs->trans(
'ProductsAndServices');
4800 print
'<div class="div-table-responsive-no-min">';
4801 print
'<table class="noborder centpercent">';
4803 $objectsrc->printOriginLinesList(
'', $selectedLines);
4810} elseif ($id > 0 || !empty($ref)) {
4812 $langs->load(
'errors');
4813 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4822 if ($user->socid > 0 && $user->socid !=
$object->socid) {
4826 $result =
$object->fetch_thirdparty();
4828 $result = $soc->fetch(
$object->socid);
4832 $selleruserevenustamp =
$mysoc->useRevenueStamp();
4834 $totalpaid =
$object->getSommePaiement();
4835 $totalcreditnotes =
$object->getSumCreditNotesUsed();
4836 $totaldeposits =
$object->getSumDepositsUsed();
4842 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4846 $multicurrency_totalpaid =
$object->getSommePaiement(1);
4847 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
4848 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
4849 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4853 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code != $conf->currency) {
4854 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
4858 if (
$object->paye ||
$object->status == $object::STATUS_CLOSED) {
4861 $resteapayeraffiche = $resteapayer;
4864 $filterabsolutediscount =
"fk_facture_source IS NULL";
4865 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4867 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4868 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4871 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
4872 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
4873 $absolute_discount =
price2num($absolute_discount,
'MT');
4874 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4876 $nb_creditnote_notyetavailable = $soc->getOpenCreditNotesNotYetConvertedIntoDiscount(0);
4878 $author =
new User($db);
4879 if (
$object->user_creation_id) {
4880 $author->fetch(
$object->user_creation_id);
4883 $objectidnext =
$object->getIdReplacingInvoice();
4887 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
$object->picto, 0,
'',
'', 0,
'', 1);
4892 if ($action ==
'converttoreduc') {
4894 $type_fac =
'ExcessReceived';
4896 $type_fac =
'CreditNote';
4898 $type_fac =
'Deposit';
4902 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4903 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4904 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4908 if ($action ==
'delete') {
4909 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
4910 $formquestion = array();
4913 $qualified_for_stock_change = 0;
4915 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4917 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4920 if ($qualified_for_stock_change) {
4921 $langs->load(
"stocks");
4922 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4926 if ($conf->browser->name ==
'ie') {
4929 $formquestion = array(
4933 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4935 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4937 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4940 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4945 if ($action ==
'situationout') {
4946 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
4947 $label = $langs->trans(
"ConfirmOuting");
4948 $formquestion = array();
4953 &&
$object->is_last_in_cycle()
4954 && $usercanunvalidate
4956 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4961 if ($action ==
'valid') {
4963 $objectref = substr(
$object->ref, 1, 4);
4964 if ($objectref ==
'PROV') {
4968 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
4970 $numref =
$object->getNextNumRef($soc);
4973 $numref = (string)
$object->ref;
4976 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4978 $text .=
'<br><br>';
4979 $text .=
img_picto(
'',
'warning',
'class="pictofixedwidth"').
' '.$langs->trans(
'WarningInvoiceCanNeverBeEdited');
4982 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4983 $notify =
new Notify($db);
4985 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid, $object);
4987 $formquestion = array();
4990 $qualified_for_stock_change = 0;
4992 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
4994 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
4997 if ($qualified_for_stock_change) {
4998 $langs->load(
"stocks");
4999 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5000 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
5003 $warehouse_array = $warehouse->list_array();
5004 if (count($warehouse_array) == 1) {
5005 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
5006 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5009 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5011 $formquestion = array(
5017 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5021 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
5026 foreach (
$object->lines as $line) {
5027 $res = $line->fetch_product();
5029 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
5035 if ($nbMandated > 0) {
5037 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
5040 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
5045 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ValidateBill'), $text,
'confirm_valid', $formquestion, ((
$object->type !=
Facture::TYPE_CREDIT_NOTE &&
$object->total_ttc < 0) ?
"no" :
"yes"), 2, 260);
5050 if ($action ==
'modif') {
5053 $testvalue =
$object->isEditable();
5054 if ($testvalue < 0) {
5055 switch ($testvalue) {
5058 setEventMessages($langs->trans(
"DisabledBecauseDispatchedInBookkeeping"),
null,
'errors');
5062 setEventMessages($langs->trans(
"DisabledBecauseNotLastInvoice"),
null,
'errors');
5066 setEventMessages($langs->trans(
"DisabledBecauseNotLastSituationInvoice"),
null,
'errors');
5070 setEventMessages($langs->trans(
"DisabledBecauseThereIsAPayment"),
null,
'errors');
5074 setEventMessages($langs->trans(
"DisabledBecauseAlreadySentByEmail"),
null,
'errors');
5078 setEventMessages($langs->trans(
"DisabledBecauseAlreadyPrintedOnce"),
null,
'errors');
5094 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
5095 $formquestion = array();
5098 $qualified_for_stock_change = 0;
5100 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5102 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5105 if ($qualified_for_stock_change) {
5106 $langs->load(
"stocks");
5107 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5108 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
5111 $warehouse_array = $warehouse->list_array();
5112 if (count($warehouse_array) == 1) {
5113 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
5114 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5117 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5119 $formquestion = array(
5125 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5129 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
5134 if ($action ==
'canceled') {
5138 $statusreplacement = 0;
5140 if ($objectidnext) {
5141 $facturereplacement =
new Facture($db);
5142 $facturereplacement->fetch($objectidnext);
5143 $statusreplacement = $facturereplacement->status;
5145 if ($objectidnext && $statusreplacement == 0) {
5146 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
5150 $close[1][
'code'] =
'badcustomer';
5151 $close[2][
'code'] =
'abandon';
5153 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5154 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
5156 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
5157 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
5160 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
5161 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
5164 $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'));
5166 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 300);
5171 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
5172 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
5174 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
5178 $close[$i][
'code'] = $object::CLOSECODE_DISCOUNTVAT;
5180 $close[$i][
'code'] = $object::CLOSECODE_BADDEBT;
5182 $close[$i][
'code'] = $object::CLOSECODE_BANKCHARGE;
5184 $close[$i][
'code'] = $object::CLOSECODE_WITHHOLDINGTAX;
5186 $close[$i][
'code'] = $object::CLOSECODE_OTHER;
5190 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
5192 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5194 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
5196 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
5198 $close[$i][
'label'] = $langs->trans(
"Other");
5202 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5204 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5206 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5208 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
5210 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
5214 foreach ($close as $key => $val) {
5215 $arrayreasons[$close[$key][
'code']] =
'<span class="small">'.$close[$key][
'reason'].
'</span>';
5219 $formquestion = array(
5220 'text' => $langs->trans(
"ConfirmClassifyPaidPartiallyQuestion"),
5221 0 => array(
'type' =>
'radio',
'name' =>
'close_code',
'label' =>
'',
'values' => $arrayreasons),
5222 1 => array(
'type' =>
'text',
'name' =>
'close_note',
'moreattr' =>
'placeholder = "'.$langs->trans(
"Comment").
'"',
'value' =>
'',
'morecss' =>
'minwidth300'),
5223 2 => array(
'type' =>
'separator')
5226 $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);
5229 if ($action ==
'deletepayment') {
5230 $payment_id =
GETPOST(
'paiement_id');
5231 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
5235 if ($action ==
'ask_deleteline') {
5236 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
5240 if ($action ==
'ask_subtotal_deleteline') {
5241 $langs->load(
"subtotals");
5242 $title =
"DeleteSubtotalLine";
5243 $question =
"ConfirmDeleteSubtotalLine";
5244 if (
GETPOST(
'type') ==
'title') {
5245 $formconfirm = array(array(
'type' =>
'checkbox',
'name' =>
'deletecorrespondingsubtotalline',
'label' => $langs->trans(
"DeleteCorrespondingSubtotalLine"),
'value' => 0));
5246 $title =
"DeleteTitleLine";
5247 $question =
"ConfirmDeleteTitleLine";
5249 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans($title), $langs->trans($question),
'confirm_delete_subtotalline', $formconfirm,
'no', 1);
5253 if ($action ==
'clone') {
5254 $filter =
'(s.client:IN:1,2,3)';
5256 $formquestion = array(
5257 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
$object->socid,
'socid', $filter, 1)),
5258 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
5261 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
5265 if ($action ==
'add_title_line') {
5266 $langs->load(
'subtotals');
5268 $depth_array =
$object->getPossibleLevels($langs);
5270 } elseif ($action ==
'add_subtotal_line') {
5271 $langs->load(
'subtotals');
5273 $titles =
$object->getPossibleTitles();
5277 if ($action ==
"remove_file_comfirm") {
5278 $file =
GETPOST(
'file',
'alpha');
5280 $formconfirm = $form->formconfirm(
5281 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
5282 $langs->trans(
'DeleteFileHeader'),
5283 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
5292 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
5293 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
5294 if (empty($reshook)) {
5295 $formconfirm .= $hookmanager->resPrint;
5296 } elseif ($reshook > 0) {
5297 $formconfirm = $hookmanager->resPrint;
5305 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
5307 $morehtmlref =
'<div class="refidno">';
5310 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5311 $morehtmlref .= $form->editfieldval(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'',
null,
null,
'', 1);
5312 $morehtmlref .=
'<br>';
5315 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5316 $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);
5318 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
5320 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'">'.$langs->trans(
"OtherBills").
'</a>)';
5324 $langs->load(
"projects");
5325 $morehtmlref .=
'<br>';
5326 if ($usercancreate) {
5327 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
5328 if ($action !=
'classify') {
5329 $morehtmlref .=
'<a class="editfielda" href="'.dolBuildUrl($_SERVER[
'PHP_SELF'], [
'action' =>
'classify',
'id' =>
$object->id],
true).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
5331 $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');
5333 if (!empty(
$object->fk_project)) {
5335 $proj->fetch(
$object->fk_project);
5336 $morehtmlref .= $proj->getNomUrl(1);
5338 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
5343 $morehtmlref .=
'</div>';
5345 $object->totalpaid = $totalpaid;
5346 $object->totalcreditnotes = $totalcreditnotes;
5347 $object->totaldeposits = $totaldeposits;
5350 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
5353 $parameters = array();
5355 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters, $object, $action);
5356 if (empty($reshook)) {
5357 print
'<div class="fichecenter">';
5358 print
'<div class="fichehalfleft">';
5359 print
'<div class="underbanner clearboth"></div>';
5361 print
'<table class="border centpercent tableforfield">';
5364 print
'<tr><td class="fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
5367 print
' '.$object->getSubtypeLabel(
'facture');
5370 $facreplaced =
new Facture($db);
5371 $facreplaced->fetch(
$object->fk_facture_source);
5372 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
5376 $facusing->fetch(
$object->fk_facture_source);
5377 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
5381 $object->getListIdAvoirFromInvoice();
5383 if (!empty(
$object->creditnote_ids)) {
5384 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
5386 foreach (
$object->creditnote_ids as $invoiceid) {
5392 $creditnote =
new Facture($db);
5393 $creditnote->fetch($invoiceid);
5394 print $creditnote->getNomUrl(1,
'', 32);
5398 if ($objectidnext > 0) {
5399 $facthatreplace =
new Facture($db);
5400 $facthatreplace->fetch($objectidnext);
5401 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
5406 $result = $discount->fetch(0,
$object->id);
5408 print
' <span class="opacitymediumbycolor paddingleft">';
5409 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
5410 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
5411 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
5413 print
'</span><br>';
5417 if (
$object->fk_fac_rec_source > 0) {
5419 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
5421 print
' <span class="opacitymediumbycolor paddingleft">';
5422 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
5423 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
5427 print
' <span class="opacitymediumbycolor paddingleft">';
5428 print $langs->transnoentities(
"GeneratedFromTemplate", $langs->trans(
"ObjectDeleted"));
5436 $langs->load(
"cashdesk");
5437 print
'<tr><td class="fieldname_type">';
5438 print
'<table class="nobordernopadding centpercent"><tr><td>';
5439 print $form->textwithpicto($langs->trans(
'PointOfSale'), $langs->trans(
'POSInfo'));
5441 if ($action !=
'editposinfo' && $usercancreate) {
5442 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>';
5444 print
'</tr></table>';
5445 print
'</td><td class="valuefield fieldname_type">';
5446 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" name="formposinfo">';
5447 print
'<input type="hidden" name="action" value="setposinfo">';
5448 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5449 if ($action ==
'editposinfo') {
5450 print
'<input type="text" class="maxwidth150" name="posmodule" placeholder="'.$langs->trans(
"POSModule").
'" value="'.
$object->module_source.
'"> ';
5451 print
'<input type="text" class="maxwidth100" name="posterminal" placeholder="'.$langs->trans(
"Terminal").
'" value="'.
$object->pos_source.
'">';
5452 print
'<input type="submit" class="button" name="submitposinfo" value="'.$langs->trans(
"Submit").
'">';
5455 print
'<span class="opacitymediumbycolor paddingleft">'.dolPrintHTML(ucfirst(
$object->module_source).
' - '.$langs->transnoentitiesnoconv(
"Terminal").
' '.
$object->pos_source).
'</span>';
5463 print
'<!-- Discounts -->'.
"\n";
5464 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
5468 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
5469 $defaulttpldir =
'/core/tpl';
5471 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5472 foreach ($dirtpls as $module => $reldir) {
5474 if (!empty($module)) {
5477 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
5479 if (file_exists($tpl)) {
5480 if (empty($conf->file->strict_mode)) {
5481 $res = @include $tpl;
5483 $res = include $tpl;
5486 if ($res) {
break; }
5493 print
'<table class="nobordernopadding centpercent"><tr><td>';
5494 print $langs->trans(
'DateInvoice');
5496 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
5497 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>';
5499 print
'</tr></table>';
5501 if ($action ==
'editinvoicedate') {
5502 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
5504 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
5519 print
'<table class="nobordernopadding centpercent"><tr><td>';
5520 print $langs->trans(
'DatePointOfTax');
5523 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>';
5525 print
'</tr></table>';
5527 if ($action ==
'editdate_pointoftax' && $editable) {
5528 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
5530 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
5538 print $form->editfieldkey(
'Source',
'input_reason',
'', $object, (
int) $usercancreate);
5539 print
'</td><td class="valuefield">';
5540 if ($action ==
'editinput_reason') {
5541 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'input_reason_id', 1,
'maxwidth250 widthcentpercentminusx');
5543 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'none');
5550 print
'<table class="nobordernopadding centpercent"><tr><td>';
5551 print $langs->trans(
'PaymentConditionsShort');
5554 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>';
5556 print
'</tr></table>';
5559 if ($action ==
'editconditions') {
5560 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
5562 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
5569 print
'<table class="nobordernopadding centpercent"><tr><td>';
5570 print $langs->trans(
'DateMaxPayment');
5573 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>';
5575 print
'</tr></table>';
5578 if ($action ==
'editpaymentterm') {
5579 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
5581 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
5591 print
'<table class="nobordernopadding centpercent"><tr><td>';
5592 print $langs->trans(
'PaymentMode');
5594 if ($action !=
'editmode' && $usercancreate) {
5595 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>';
5597 print
'</tr></table>';
5599 if ($action ==
'editmode') {
5600 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
5602 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'none',
'CRDT');
5608 print
'<tr><td class="nowrap">';
5609 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
5610 print $langs->trans(
'DefaultBankAccount');
5612 if (($action !=
'editbankaccount') && $usercancreate) {
5613 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>';
5615 print
'</tr></table>';
5617 if ($action ==
'editbankaccount') {
5618 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
5620 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
5629 print
'<table class="nobordernopadding centpercent"><tr><td>';
5630 print $langs->trans(
'IncotermLabel');
5631 print
'<td><td class="right">';
5632 if ($usercancreate) {
5633 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
5635 print
'</td></tr></table>';
5638 if ($action !=
'editincoterm') {
5639 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
5641 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
5648 print
'<table class="nobordernopadding centpercent"><tr><td>';
5649 print $langs->trans(
'Dispute');
5650 print
'<td><td class="right">';
5651 if ($usercancreate) {
5652 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editdispute_status&token='.
newToken().
'">'.
img_edit().
'</a>';
5654 print
'</td></tr></table>';
5656 $liststatus = array(
'0' =>
"None",
'1' =>
"DisputeOpen",
'8' =>
"DisputeLost",
'9' =>
"DisputeWon");
5657 if ($action !=
'editdispute_status') {
5658 if (
$object->dispute_status) {
5659 print $langs->trans($liststatus[
$object->dispute_status]);
5662 print
'<form enctype="multipart/form-data" action="'.DOL_URL_ROOT.
'/compta/facture/card.php" method="POST">';
5663 print
'<input type="hidden" name="action" value="set_dispute_status">';
5664 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5665 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
5666 print
'<input type="hidden" name="page_y" value="">';
5667 print $form->selectarray(
'dispute_status', $liststatus,
$object->dispute_status, 0, 0, 0,
'', 1);
5668 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Save").
'">';
5676 print
'<table class="nobordernopadding centpercent"><tr><td>';
5677 print $langs->trans(
"Categories");
5678 print
'<td><td class="right">';
5679 if ($usercancreate) {
5680 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
5684 print
'</td></tr></table>';
5687 if ($action ==
'edittags') {
5688 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5689 print
'<input type="hidden" name="action" value="settags">';
5690 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5691 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
5692 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5695 print $form->showCategories(
$object->id, Categorie::TYPE_INVOICE, 1);
5700 $displayWarranty =
false;
5703 $displayWarranty =
true;
5704 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
5705 $displayWarranty =
false;
5708 if ($displayWarranty) {
5710 print
'<tr class="retained-warranty-lines" ><td>';
5711 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
5712 print $langs->trans(
'RetainedWarranty');
5715 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>';
5718 print
'</tr></table>';
5721 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5722 print
'<input type="hidden" name="action" value="setretainedwarranty">';
5723 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5724 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5725 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
5726 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5734 print
'<tr class="retained-warranty-lines" ><td>';
5735 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
5736 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
5738 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
5739 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>';
5742 print
'</tr></table>';
5744 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5745 if (
$object->date > $defaultDate) {
5751 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5752 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
5753 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5754 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5755 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
5756 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
5757 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
5758 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
5759 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5762 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->retained_warranty_fk_cond_reglement,
'none');
5763 if (!$displayWarranty) {
5764 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning',
'class="pictowarning valignmiddle" ');
5770 print
'<tr class="retained-warranty-lines" ><td>';
5771 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
5772 print $langs->trans(
'RetainedWarrantyDateLimit');
5775 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>';
5778 print
'</tr></table>';
5780 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5781 if (
$object->date > $defaultDate) {
5786 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5787 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
5788 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5789 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5791 print $form->selectDate($defaultDate,
'retained_warranty_date_limit');
5792 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5804 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
5809 print
'<div class="fichehalfright">';
5811 print
'<!-- amounts -->'.
"\n";
5812 print
'<div class="underbanner clearboth"></div>'.
"\n";
5814 print
'<table class="border tableforfield centpercent">';
5816 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
5824 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
5825 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5828 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5834 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
5835 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5838 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5843 if ((
$mysoc->localtax1_assuj ==
"1" &&
$mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
5845 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1",
$mysoc->country_code) .
'</td>';
5846 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5850 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5855 if ((
$mysoc->localtax2_assuj ==
"1" &&
$mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
5857 print
'<td>' . $langs->transcountry(
"AmountLT2",
$mysoc->country_code) .
'</td>';
5858 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5862 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5868 if ($selleruserevenustamp) {
5869 print
'<tr><td class="titlefieldmiddle">';
5870 print
'<table class="nobordernopadding centpercent"><tr><td>';
5871 print $langs->trans(
'RevenueStamp');
5873 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
5874 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>';
5876 print
'</tr></table>';
5877 print
'</td><td class="nowrap amountcard right">';
5878 if ($action ==
'editrevenuestamp') {
5879 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
5880 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5881 print
'<input type="hidden" name="action" value="setrevenuestamp">';
5882 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
5883 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5884 print $formother->select_revenue_stamp(
'',
'revenuestamp_type',
$mysoc->country_code);
5885 print
' → <span id="revenuestamp_span"></span>';
5886 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
5889 $(document).ready(function(){
5890 js_recalculate_revenuestamp();
5891 $('select[name=revenuestamp_type]').on('change',function(){
5892 js_recalculate_revenuestamp();
5895 function js_recalculate_revenuestamp(){
5896 var valselected = $('select[name=revenuestamp_type]').val();
5897 console.log('Calculate revenue stamp from '+valselected);
5899 if (valselected.indexOf('%') == -1)
5901 revenue = valselected;
5905 var revenue_type = parseFloat(valselected);
5906 var amount_net = ".round(
$object->total_ht, 2).
";
5907 revenue = revenue_type * amount_net / 100;
5908 revenue = revenue.toFixed(2);
5910 $('#revenuestamp_val').val(revenue);
5911 $('#revenuestamp_span').html(revenue);
5915 print
price(
$object->revenuestamp, 1,
'', 1, -1, -1, $conf->currency);
5922 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
5923 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
5926 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
5941 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
5944 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
5947 if ($selleruserevenustamp) {
5957 $total_prev_ht = $total_prev_ttc = 0;
5958 $total_global_ht = $total_global_ttc = 0;
5962 print
'<!-- List of situation invoices -->';
5963 print
'<div class="div-table-responsive-no-min">';
5964 print
'<table class="noborder paymenttable centpercent situationstable">';
5966 print
'<tr class="liste_titre">';
5967 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
5969 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
5972 print
'<td class="right"></td>';
5974 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
5975 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
5976 print
'<td width="18"> </td>';
5979 if (count(
$object->tab_previous_situation_invoice) > 0) {
5982 $current_situation_counter = array();
5983 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
5984 $tmptotalallpayments = $prev_invoice->getSommePaiement(0);
5985 $tmptotalallpayments += $prev_invoice->getSumDepositsUsed(0);
5986 $tmptotalallpayments += $prev_invoice->getSumCreditNotesUsed(0);
5988 $total_prev_ht += $prev_invoice->total_ht;
5989 $total_prev_ttc += $prev_invoice->total_ttc;
5991 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
5992 print
'<tr class="oddeven">';
5993 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
5995 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
5997 print
'<td class="right"></td>';
5999 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
6000 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
6001 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalallpayments).
'</td>';
6006 $totalallpayments =
$object->getSommePaiement(0);
6007 $totalallpayments +=
$object->getSumCreditNotesUsed(0);
6008 $totalallpayments +=
$object->getSumDepositsUsed(0);
6010 $total_global_ht += $total_prev_ht;
6011 $total_global_ttc += $total_prev_ttc;
6012 $total_global_ht +=
$object->total_ht;
6013 $total_global_ttc +=
$object->total_ttc;
6017 print
'<tr class="oddeven">';
6018 print
'<td>'.$object->getNomUrl(1).
'</td>';
6020 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
6022 print
'<td class="right"></td>';
6024 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
6025 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
6026 print
'<td class="right">'.$object->getLibStatut(3, $totalallpayments).
'</td>';
6030 print
'<tr class="oddeven">';
6031 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'SituationTotalAfterInvoice').
'</b></td>';
6034 foreach ($current_situation_counter as $sit) {
6035 $curSign = $sit > 0 ?
'+' :
'-';
6036 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
6038 print
' '.$curSign.
' ';
6040 print $curType.abs($sit);
6047 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6048 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6049 print
'<td width="18"> </td>';
6053 if (count(
$object->tab_next_situation_invoice) > 0) {
6055 $total_next_ht = $total_next_ttc = 0;
6057 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
6058 $next_totalpaid = $next_invoice->getSommePaiement(0);
6059 $next_totalcreditnotes = $next_invoice->getSumCreditNotesUsed(0);
6060 $next_totaldeposits = $next_invoice->getSumDepositsUsed(0);
6061 $total_next_ht += $next_invoice->total_ht;
6062 $total_next_ttc += $next_invoice->total_ttc;
6064 print
'<tr class="oddeven">';
6065 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
6067 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
6069 print
'<td class="right"></td>';
6071 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
6072 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
6073 print
'<td class="right">'.$next_invoice->getLibStatut(3, $next_totalpaid + $next_totalcreditnotes + $next_totaldeposits).
'</td>';
6077 $total_global_ht += $total_next_ht;
6078 $total_global_ttc += $total_next_ttc;
6080 print
'<tr class="oddeven">';
6081 print
'<td colspan="3" class="right"></td>';
6083 print
'<td class="right"></td>';
6085 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6086 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6087 print
'<td width="18"> </td>';
6096 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
6102 print
'<!-- List of payments already done -->';
6103 print
'<div class="div-table-responsive-no-min">';
6104 print
'<table class="noborder paymenttable centpercent">';
6106 print
'<tr class="liste_titre">';
6107 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
6108 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
6109 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
6111 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
6113 print
'<td class="liste_titre"></td>';
6114 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
6118 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
6119 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
6120 $sql .=
' pf.amount,';
6121 $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';
6122 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
6123 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
6124 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
6125 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
6126 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
6127 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
6128 $sql .=
' ORDER BY p.datep, p.tms';
6130 $result = $db->query($sql);
6132 $num = $db->num_rows($result);
6137 $objp = $db->fetch_object($result);
6139 $paymentstatic->id = $objp->rowid;
6140 $paymentstatic->datepaye = $db->jdate($objp->dp);
6141 $paymentstatic->ref = $objp->ref;
6142 $paymentstatic->num_payment = $objp->num_payment;
6143 $paymentstatic->paiementcode = $objp->payment_code;
6145 print
'<tr class="oddeven">';
6146 print
'<td class="nowraponall">';
6147 print $paymentstatic->getNomUrl(1);
6150 $dateofpayment = $db->jdate($objp->dp);
6152 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
6159 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
6160 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
6162 $bankaccountstatic->id = $objp->baid;
6163 $bankaccountstatic->ref = $objp->baref;
6164 $bankaccountstatic->label = $objp->baref;
6165 $bankaccountstatic->number = $objp->banumber;
6166 $bankaccountstatic->currency_code = $objp->bacurrency_code;
6169 $bankaccountstatic->account_number = $objp->account_number;
6172 $accountingjournal->fetch($objp->fk_accountancy_journal);
6173 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
6176 print
'<td class="nowraponall">';
6177 if ($bankaccountstatic->id) {
6178 print $bankaccountstatic->getNomUrl(1,
'transactions');
6184 print
'<td class="center">';
6186 $paiement->fetch($objp->rowid);
6188 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
6195 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
6210 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6211 print
'<span class="opacitymedium">';
6213 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
6215 print $langs->trans(
'AlreadyPaid');
6217 print
'</span></td>';
6219 print
'<td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td>';
6222 $resteapayeraffiche = $resteapayer;
6223 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
6224 $cssforamountpaymentcompletenoresize =
'amountpaymentcompletenoresize';
6227 $creditnoteamount = 0;
6229 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
6230 $sql .=
" re.description, re.fk_facture_source";
6231 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
6232 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
6233 $resql = $db->query($sql);
6235 $num = $db->num_rows($resql);
6239 $obj = $db->fetch_object($resql);
6240 $invoice->fetch($obj->fk_facture_source);
6242 print
'<td colspan="'.$nbcols.
'" class="right">';
6243 print
'<span class="opacitymedium">';
6245 print $langs->trans(
"CreditNote").
' ';
6248 print $langs->trans(
"Deposit").
' ';
6250 print $invoice->getNomUrl(0);
6254 print
'<td class="right">';
6255 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
6256 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
6260 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
6264 $creditnoteamount += $obj->amount_ttc;
6267 $depositamount += $obj->amount_ttc;
6277 print
'<td colspan="'.$nbcols.
'" class="nowrap right">';
6278 print
'<span class="opacitymedium">';
6279 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
6283 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6285 $resteapayeraffiche = 0;
6286 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6287 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6292 print
'<td colspan="'.($nbcols+1).
'" class="nowrap right">';
6293 print
'<span class="opacitymedium">';
6294 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
6298 print
'<td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td>';
6301 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6302 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6307 print
'<td colspan="'.($nbcols+1).
'" class="nowrap right">';
6308 print
'<span class="opacitymedium">';
6309 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
6313 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6315 $resteapayeraffiche = 0;
6316 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6317 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6322 print
'<td colspan="'.($nbcols+1).
'" class="nowrap right">';
6323 $text = $langs->trans(
"HelpAbandonOther");
6325 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
6327 print
'<span class="opacitymedium">';
6329 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
6333 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6335 $resteapayeraffiche = 0;
6336 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6337 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6342 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6343 print
'<span class="opacitymedium">';
6344 print $langs->trans(
"Billed");
6347 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
6352 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6353 print
'<span class="opacitymedium">';
6354 print $langs->trans(
'RemainderToPay');
6355 if ($resteapayeraffiche < 0) {
6356 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6361 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
6367 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6368 print
'<span class="opacitymedium">';
6369 print $langs->trans(
'RemainderToPayMulticurrency');
6370 if ($resteapayeraffiche < 0) {
6371 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6376 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcompletenoresize)).
'">';
6378 print
price(
price2num(
$object->multicurrency_tx * $resteapayeraffiche,
'MT'), 1, $langs, 1, -1, -1, (empty(
$object->multicurrency_code) ? $conf->currency :
$object->multicurrency_code)).
'</td>';
6383 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
6385 if (
$object->isSituationInvoice()) {
6386 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
6389 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
6392 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
6395 print
'<td colspan="'.($nbcols+1).
'" class="right">'.$langs->trans(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')).
' :</td>';
6397 print
'<td class="right">'.price($billedWithRetainedWarranty).
'</td>';
6402 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6403 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
6404 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
6407 print
'<td class="right">'.price($retainedWarranty).
'</td>';
6411 $resteapayeraffiche = $resteapayer;
6412 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6413 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6417 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6418 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
6421 print
'<td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td>';
6426 print
'<td colspan="'.($nbcols+1).
'" class="right"><span class="opacitymedium">'.$langs->trans(
"Billed").
'</span></td>';
6428 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
6432 print
'<tr><td colspan="'.($nbcols+1).
'" class="right">';
6433 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
6434 if ($resteapayeraffiche > 0) {
6435 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6437 print
'</span></td>';
6439 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche);
6448 print
'<td colspan="'.($nbcols+1).
'" class="right">';
6449 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
6450 if ($resteapayeraffiche > 0) {
6451 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6456 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>';
6471 $formmargin->displayMarginInfos($object);
6477 print
'<div class="clearboth"></div><br>';
6480 $blocname =
'contacts';
6481 $title = $langs->trans(
'ContactsAddresses');
6482 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6486 $blocname =
'notes';
6487 $title = $langs->trans(
'Notes');
6488 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6492 $result =
$object->getLinesArray();
6496 global $inputalsopricewithtax;
6497 $inputalsopricewithtax = 1;
6502 print
'<!-- Area to change globally the situation percent -->'.
"\n";
6503 print
'<div class="div-table-responsive-no-min">';
6505 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'#updatealllines" method="POST">';
6506 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
6507 print
'<input type="hidden" name="action" value="updatealllines" />';
6508 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
6509 print
'<input type="hidden" name="page_y" value="" />';
6510 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
6512 print
'<table id="tablelines_all_progress" class="noborder noshadow centpercent">';
6514 print
'<tr class="liste_titre nodrag nodrop">';
6518 print
'<td align="center" width="5"> </td>';
6520 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
6521 print
'<td class="right">'.$langs->trans(
'CumulativeProgression').
'</td>';
6522 print
'<td> </td>';
6525 print
'<tr class="nodrag nodrop">';
6528 print
'<td align="center" width="5"> </td>';
6530 print
'<td> </td>';
6531 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
6532 print
'<td class="right"><input type="submit" class="button reposition small" name="all_percent" value="'.$langs->trans(
"Modify").
'" /></td>';
6543 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
6544 <input type="hidden" name="token" value="' .
newToken().
'">
6545 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
6546 <input type="hidden" name="mode" value="">
6547 <input type="hidden" name="page_y" value="">
6548 <input type="hidden" name="id" value="' .
$object->id.
'">
6549 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
6552 if (!empty($conf->use_javascript_ajax) &&
$object->status == 0) {
6554 include DOL_DOCUMENT_ROOT.
'/core/tpl/subtotal_ajaxrow.tpl.php';
6556 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
6560 print
'<div class="div-table-responsive-no-min">';
6561 print
'<table id="tablelines" class="noborder noshadow centpercent nomarginbottom">';
6565 $object->printObjectLines($action,
$mysoc, $soc, $lineid, 1);
6569 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
6570 if ($action !=
'editline' && $action !=
'selectlines') {
6573 $parameters = array();
6574 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
6578 if (empty($reshook)) {
6582 $parameters = array();
6583 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters, $object, $action);
6597 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
6598 print
'<div class="tabsAction">';
6600 $parameters = array();
6601 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
6602 if (empty($reshook)) {
6605 'class' =>
'classfortooltip',
6612 $ventilExportCompta =
$object->getVentilExportCompta();
6614 if ($ventilExportCompta == 0) {
6616 if (!$objectidnext &&
$object->is_last_in_cycle()) {
6617 if ($usercanunvalidate) {
6618 unset($params[
'attr'][
'title']);
6619 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
true, $params);
6621 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
6622 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
false, $params);
6624 } elseif (!
$object->is_last_in_cycle()) {
6625 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
6626 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6628 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
6629 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6633 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6634 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6639 $result = $discount->fetch(0,
$object->id);
6647 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
6648 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
6649 unset($params[
'attr'][
'title']);
6650 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
6652 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6653 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
6660 $langs->load(
"contracts");
6662 if ($usercancreatecontract) {
6663 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>';
6671 $langs->load(
"subtotals");
6673 $url_button = array();
6675 $url_button[] = array(
6676 'lang' =>
'subtotals',
6678 'perm' => (
bool) $usercancreate,
6679 'label' => $langs->trans(
'AddTitleLine'),
6680 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_title_line&token='.
newToken()
6683 $url_button[] = array(
6684 'lang' =>
'subtotals',
6686 'perm' => (
bool) $usercancreate,
6687 'label' => $langs->trans(
'AddSubtotalLine'),
6688 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_subtotal_line&token='.
newToken()
6690 print
dolGetButtonAction(
'', $langs->trans(
'SubTotal'),
'default', $url_button,
'',
true);
6697 if ($usercanvalidate) {
6698 unset($params[
'attr'][
'title']);
6699 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
6704 if (empty($user->socid)) {
6706 if ($objectidnext) {
6707 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6708 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
6711 unset($params[
'attr'][
'title']);
6712 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
6714 unset($params[
'attr'][
'title']);
6715 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
6723 if ($resteapayer > 0) {
6724 if ($usercancreatewithdrarequest) {
6725 if (!$objectidnext &&
$object->close_code !=
'replaced') {
6726 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>';
6728 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
6740 $langs->load(
"cashdesk");
6741 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
6742 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
6747 if ($objectidnext) {
6748 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
6752 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
6753 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
6757 unset($params[
'attr'][
'title']);
6758 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);
6763 $sumofpayment = $totalpaid;
6764 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
6770 if ($resteapayer == 0) {
6771 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
6773 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
6779 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
6783 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
6785 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>';
6792 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
6794 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
6808 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
6809 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
6811 unset($params[
'attr'][
'title']);
6812 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken(),
'',
true, $params);
6818 if ($totalpaid > 0 || $totalcreditnotes > 0) {
6820 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
6823 if ($objectidnext) {
6824 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
6826 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled&token='.
newToken().
'">'.$langs->trans(
'ClassifyCanceled').
'</a>';
6834 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
6835 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6836 } elseif (!
$object->is_last_in_cycle()) {
6837 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6839 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
6845 if (!$objectidnext) {
6846 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>';
6852 &&
$object->isSituationInvoice()
6853 && (
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
6856 &&
$object->is_last_in_cycle()
6859 if ($usercanunvalidate) {
6860 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>';
6862 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
6868 if (!$objectidnext && count(
$object->lines) > 0) {
6869 unset($params[
'attr'][
'title']);
6870 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
6876 unset($params[
'attr'][
'title']);
6877 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'clone', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice&token='.
newToken(),
'',
true, $params);
6882 &&
$object->isSituationInvoice()
6885 &&
$object->situation_counter > 1
6886 &&
$object->is_last_in_cycle()
6887 && $usercanunvalidate
6890 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6892 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
6897 $isErasable =
$object->is_erasable();
6900 if ($isErasable == -6) {
6901 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadySentByEmail');
6902 } elseif ($isErasable == -5) {
6903 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadyPrintedOnce');
6904 } elseif ($isErasable == -4) {
6905 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
6906 } elseif ($isErasable == -3) {
6907 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
6908 } elseif ($isErasable == -2) {
6909 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
6910 } elseif ($isErasable == -1) {
6911 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6912 } elseif ($isErasable <= 0) {
6913 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable').(empty(
$object->error) ?
': UnknownReason' :
': '.$object->error);
6914 } elseif ($objectidnext) {
6915 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
6917 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
6918 $enableDelete =
false;
6920 if ($isErasable > 0 && ! $objectidnext) {
6921 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
6922 $enableDelete =
true;
6924 unset($params[
'attr'][
'title']);
6925 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
6927 unset($params[
'attr'][
'title']);
6928 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
6935 if (
GETPOST(
'modelselected',
'alpha')) {
6936 $action =
'presend';
6938 if ($action !=
'prerelance' && $action !=
'presend') {
6939 print
'<div class="fichecenter"><div class="fichehalfleft">';
6940 print
'<a name="builddoc"></a>';
6945 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
6946 $genallowed = $usercanread;
6947 $delallowed = $usercancreate;
6948 $tooltipAfterComboOfModels =
'';
6950 $tooltipAfterComboOfModels = $langs->trans(
"AccordingToYourSetupTheFileWillBeConcatenated",
getDolGlobalString(
'MAIN_INFO_INVOICE_TERMSOFSALE'));
6953 print $formfile->showdocuments(
6973 'remove_file_comfirm',
6974 $tooltipAfterComboOfModels
6977 $somethingshown = $formfile->numoffiles;
6980 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice'), 1);
6981 $linktoelem = $tmparray[
'linktoelem'];
6982 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
6983 print $htmltoenteralink;
6985 $compatibleImportElementsList =
false;
6989 $compatibleImportElementsList = array(
'commande',
'propal',
'subscription');
6991 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
6995 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6996 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
6997 $useonlinepayment = count($validpaymentmethod);
7000 print
'<br><!-- Link to pay -->'.
"\n";
7001 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
7002 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
7005 print
'</div><div class="fichehalfright">';
7009 $morehtmlcenter =
'<div class="nowraponall">';
7010 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullConversation'),
'',
'fa fa-comments imgforviewmode', DOL_URL_ROOT.
'/compta/facture/messaging.php?id='.
$object->id);
7011 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
7012 $morehtmlcenter .=
'</div>';
7015 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
7017 $somethingshown = $formactions->showactions($object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
7019 print
'</div></div>';
7024 $modelmail =
'facture_send';
7025 $defaulttopic =
'SendBillRef';
7026 $diroutput = $conf->invoice->multidir_output[
$object->entity ?? $conf->entity];
7027 $trackid =
'inv'.$object->id;
7029 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 - Taxe sur la valeur ajoutée)
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.
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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'.
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT 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.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.