49require
'../../main.inc.php';
59require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
60require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
61require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
62require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
63require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
64require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
65require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
66require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
67require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
68require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
69require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
70require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
71require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
72require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
74 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
77 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
78 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
80require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
83 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
86 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
90$langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
92 $langs->load(
'incoterm');
95 $langs->load(
'margins');
99$action =
GETPOST(
'action',
'aZ09');
100$confirm =
GETPOST(
'confirm',
'alpha');
101$cancel =
GETPOST(
'cancel',
'alpha');
102$backtopage =
GETPOST(
'backtopage',
'alpha');
103$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
109$origin =
GETPOST(
'origin',
'alpha');
113$ref_client =
GETPOST(
'ref_client',
'alpha');
114$inputReasonId =
GETPOSTINT(
'input_reason_id');
117$selectedLines =
GETPOST(
'toselect',
'array:int');
130$extrafields->fetch_name_optionals_label(
$object->table_element);
133$total_global_ttc = 0;
134$displayWarranty =
false;
135$statusreplacement = 0;
137$price_base_type =
'';
138$array_options = array();
141if ($id > 0 || !empty($ref)) {
142 if ($action !=
'add') {
144 $fetch_situation =
false;
146 $fetch_situation =
true;
148 $ret =
$object->fetch($id, $ref,
'', 0, $fetch_situation);
149 if ($ret > 0 && isset(
$object->fk_project)) {
150 $ret =
$object->fetchProject();
156$hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
159$usercanread = $user->hasRight(
"facture",
"lire");
160$usercancreate = $user->hasRight(
"facture",
"creer");
161$usercanissuepayment = $user->hasRight(
"facture",
"paiement");
162$usercandelete = $user->hasRight(
"facture",
"supprimer") || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
163$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
166$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'validate')));
167$usercansend = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercanread) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'send')));
168$usercanreopen = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'reopen')));
170 $usercanreopen =
false;
172$usercanunvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'facture',
'invoice_advance',
'unvalidate')));
173$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
176$usercancreatemargin = $user->hasRight(
'margins',
'creer');
177$usercanreadallmargin = $user->hasRight(
'margins',
'liretous');
178$usercancreatewithdrarequest = $user->hasRight(
'prelevement',
'bons',
'creer');
180$permissionnote = $usercancreate;
181$permissiondellink = $usercancreate;
182$permissiontoedit = $usercancreate;
183$permissiontoadd = $usercancreate;
184$permissiontoeditextra = $usercancreate;
185if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
187 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
191$retainedWarrantyInvoiceAvailableType = array();
193 $retainedWarrantyInvoiceAvailableType = explode(
'+',
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY'));
198 $socid = $user->socid;
211$parameters = array(
'socid' => $socid);
212$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
217if (empty($reshook)) {
218 $backurlforlist =
dolBuildUrl(DOL_URL_ROOT.
'/compta/facture/list.php');
220 if (empty($backtopage) || ($cancel && empty($id))) {
221 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
222 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
223 $backtopage = $backurlforlist;
225 $backtopage =
dolBuildUrl(DOL_URL_ROOT.
'/compta/facture/card.php', [
'id' => ((!empty($id) && $id > 0) ? $id :
'__ID__')]);
231 if (!empty($backtopageforcancel)) {
232 header(
"Location: ".$backtopageforcancel);
234 } elseif (!empty($backtopage)) {
235 header(
"Location: ".$backtopage);
241 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
243 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
245 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
248 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
250 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'IdThirdParty')),
null,
'errors');
253 '@phan-var-force Facture $objectutil';
256 $objectutil->socid = $socid;
257 $result = $objectutil->createFromClone($user, $id, (GETPOSTISSET(
'entity') ?
GETPOSTINT(
'entity') : null));
259 $warningMsgLineList = array();
261 foreach ($objectutil->lines as $line) {
262 if (!is_object($line->product)) {
263 $line->fetch_product();
265 if (is_object($line->product) && $line->product->id > 0) {
266 if (empty($line->product->status)) {
267 $warningMsgLineList[$line->id] = $langs->trans(
'WarningLineProductNotToSell', $line->product->ref);
271 if (!empty($warningMsgLineList)) {
275 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?facid=' . $result);
278 $langs->load(
"errors");
283 } elseif ($action ==
'reopen' && $usercanreopen) {
287 $result =
$object->setUnpaid($user);
289 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
295 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
300 $idwarehouse =
GETPOST(
'idwarehouse');
302 $qualified_for_stock_change = 0;
304 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
306 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
309 $isErasable =
$object->is_erasable();
311 if (($isErasable > 0) || ($usercancreate && $isErasable == 1)) {
312 $result =
$object->delete($user, 0, (
int) $idwarehouse);
314 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
321 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
331 $outputlangs = $langs;
337 $newlang =
$object->thirdparty->default_lang;
339 if (!empty($newlang)) {
341 $outputlangs->setDefaultLang($newlang);
342 $outputlangs->load(
'products');
346 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
349 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
356 } elseif ($action ==
'confirm_delete_subtotalline' && $confirm ==
'yes' && $usercancreate) {
361 $result =
$object->deleteSubtotalLine($langs,
GETPOSTINT(
'lineid'), (
bool)
GETPOST(
'deletecorrespondingsubtotalline'));
366 $outputlangs = $langs;
372 $newlang =
$object->thirdparty->default_lang;
374 if (!empty($newlang)) {
376 $outputlangs->setDefaultLang($newlang);
377 $outputlangs->load(
'products');
381 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
384 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
391 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
394 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
395 $discount->unlink_invoice();
397 if (
$object->paye == 1 && (
float)
$object->getRemainToPay() > 0) {
400 } elseif ($action ==
'valid' && $usercancreate) {
404 if ((preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) &&
411 $last_of_type =
$object->willBeLastOfSameType(
true);
412 if (empty(
$object->date_validation) && !$last_of_type[0]) {
422 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
431 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
440 $array_of_total_ht_per_vat_rate = array();
441 $array_of_total_ht_devise_per_vat_rate = array();
442 foreach (
$object->lines as $line) {
444 $vat_src_code_for_line =
'';
445 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
446 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
448 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
449 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
451 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
452 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
456 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
457 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
458 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
460 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
461 if (
$object->type == $object::TYPE_DEPOSIT) {
462 $langs->load(
"errors");
464 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
468 $tmpvatratetoshow = explode(
'_', $vatrate);
469 $tmpvatratetoshow[0] = round((
float) $tmpvatratetoshow[0], 2);
471 if ($tmpvatratetoshow[0] != 0) {
472 $langs->load(
"errors");
473 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", (
string) $tmpvatratetoshow[0]),
null,
'errors');
481 } elseif ($action ==
'classin' && $usercancreate) {
487 } elseif ($action ==
'setposinfo' && $usercancreate) {
491 $result =
$object->update($user);
495 } elseif ($action ==
'setmode' && $usercancreate) {
501 } elseif ($action ==
'setretainedwarrantyconditions' && $usercancreate) {
504 $object->retained_warranty_fk_cond_reglement = 0;
505 $result =
$object->setRetainedWarrantyPaymentTerms(
GETPOSTINT(
'retained_warranty_fk_cond_reglement'));
510 $old_rw_date_lim_reglement =
$object->retained_warranty_date_limit;
511 $new_rw_date_lim_reglement =
$object->calculate_date_lim_reglement(
$object->retained_warranty_fk_cond_reglement);
512 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
513 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
518 $result =
$object->update($user);
522 } elseif ($action ==
'setretainedwarranty' && $usercancreate) {
528 } elseif ($action ==
'setretainedwarrantydatelimit' && $usercancreate) {
530 $result =
$object->setRetainedWarrantyDateLimit(
GETPOSTDATE(
'retained_warranty_date_limit'));
534 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
535 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
536 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
538 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
540 $old_date_lim_reglement =
$object->date_lim_reglement;
542 if (empty($newdate)) {
543 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
544 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.
$id.
'&action=editinvoicedate&token='.
newToken());
549 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
551 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
556 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
557 if ($new_date_lim_reglement) {
558 $object->date_lim_reglement = $new_date_lim_reglement;
563 $result =
$object->update($user);
566 $action =
'editinvoicedate';
568 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
573 $object->date_pointoftax = $date_pointoftax;
574 $result =
$object->update($user);
578 } elseif ($action ==
'setconditions' && $usercancreate) {
580 $object->cond_reglement_code = 0;
581 $object->cond_reglement_id = 0;
594 $old_date_lim_reglement =
$object->date_lim_reglement;
595 $new_date_lim_reglement =
$object->calculate_date_lim_reglement();
596 if ($new_date_lim_reglement) {
597 $object->date_lim_reglement = $new_date_lim_reglement;
602 $result =
$object->update($user);
614 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
618 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
619 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
621 $result =
$object->update($user);
625 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
628 $result =
$object->update($user);
635 $outputlangs = $langs;
638 $newlang =
GETPOST(
'lang_id',
'aZ09');
641 $newlang =
$object->thirdparty->default_lang;
643 if (!empty($newlang)) {
645 $outputlangs->setDefaultLang($newlang);
646 $outputlangs->load(
'products');
651 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
657 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm') && $usercancreate) {
662 } elseif ($action ==
'set_dispute_status' && $usercancreate) {
663 $result =
$object->setStatut(
GETPOSTINT(
'dispute_status'),
null,
'facture',
'FACTURE_MODIFY',
'dispute_status');
667 } elseif ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
672 } elseif ($action ==
'setbankaccount' && $usercancreate) {
677 } elseif ($action ==
'setremisepercent' && $usercancreate) {
683 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
702 $newremaintopay =
$object->getRemainToPay(0);
703 if ($newremaintopay == 0) {
710 if (
GETPOSTINT(
"remise_id_for_payment") > 0) {
711 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
713 $discount->fetch(
GETPOSTINT(
"remise_id_for_payment"));
717 $remaintopay =
$object->getRemainToPay(0);
721 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
725 $result = $discount->link_to_invoice(0, $id);
738 $newremaintopay =
$object->getRemainToPay(0);
739 if ($newremaintopay == 0) {
753 $outputlangs = $langs;
756 $newlang =
GETPOST(
'lang_id',
'aZ09');
760 $newlang =
$object->thirdparty->default_lang;
762 if (!empty($newlang)) {
764 $outputlangs->setDefaultLang($newlang);
768 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
773 } elseif ($action ==
'setref' && $usercancreate) {
775 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', 0,
'',
'', $user,
'BILL_MODIFY');
779 } elseif ($action ==
'setref_client' && $usercancreate) {
785 } elseif ($action ==
'setdemandreason' && $usercancreate) {
786 $result =
$object->setInputReason($inputReasonId);
790 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
799 $qualified_for_stock_change = 0;
801 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
803 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
806 if ($qualified_for_stock_change) {
807 if (!$idwarehouse || $idwarehouse == - 1) {
809 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
816 $result =
$object->validate($user,
'', $idwarehouse);
820 $outputlangs = $langs;
823 $newlang =
GETPOST(
'lang_id',
'aZ09');
826 $newlang =
$object->thirdparty->default_lang;
828 if (!empty($newlang)) {
830 $outputlangs->setDefaultLang($newlang);
831 $outputlangs->load(
'products');
837 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
850 } elseif ($action ==
'confirm_modif' && $usercanunvalidate && !
getDolGlobalString(
'INVOICE_CAN_NEVER_BE_EDITED')) {
859 $qualified_for_stock_change = 0;
861 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
863 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
866 if ($qualified_for_stock_change) {
867 if (!$idwarehouse || $idwarehouse == -1) {
869 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
878 $sql =
'SELECT pf.amount';
879 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'paiement_facture as pf';
880 $sql .=
' WHERE pf.fk_facture = ' . ((int)
$object->id);
882 $result =
$db->query($sql);
885 $num =
$db->num_rows($result);
888 $objp =
$db->fetch_object($result);
889 $totalpaid += $objp->amount;
896 $resteapayer =
$object->total_ttc - $totalpaid;
899 $ventilExportCompta =
$object->getVentilExportCompta();
902 if ($ventilExportCompta == 0) {
905 $result =
$object->setDraft($user, $idwarehouse);
912 $outputlangs = $langs;
915 $newlang =
GETPOST(
'lang_id',
'aZ09');
918 $newlang =
$object->thirdparty->default_lang;
920 if (!empty($newlang)) {
922 $outputlangs->setDefaultLang($newlang);
923 $outputlangs->load(
'products');
928 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
934 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
937 $result =
$object->setPaid($user);
941 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
944 $close_code =
GETPOST(
"close_code",
'restricthtml');
945 $close_note =
GETPOST(
"close_note",
'restricthtml');
948 if (
isModEnabled(
'tax') && $close_code == $object::CLOSECODE_WITHHOLDINGTAX) {
949 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
951 $amount = (float) ($resteapayer > 0 ? $resteapayer * -1 : $resteapayer);
955 $tempTva->datev =
$object->date;
956 $tempTva->datep =
$object->date;
957 $tempTva->amount = $amount;
958 $tempTva->label = $langs->trans(
'WithholdingTax') .
' - ' .
$object->ref;
960 $valid = $tempTva->getIdForLabel($tempTva->label);
962 $ret = $tempTva->create($user);
966 $tempTva->setPaid($user);
976 setEventMessages($langs->trans(
'LabelWithholdingExist'), $tempTva->errors,
'errors');
982 $result =
$object->setPaid($user, $close_code, $close_note);
990 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
992 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes' && $usercancreate) {
995 $close_code =
GETPOST(
"close_code",
'restricthtml');
996 $close_note =
GETPOST(
"close_note",
'restricthtml');
998 $result =
$object->setCanceled($user, $close_code, $close_note);
1005 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
1007 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
1015 $result = $discountcheck->fetch(0,
$object->id);
1028 $amount_ht = $amount_tva = $amount_ttc = $amount_localtax1 = $amount_localtax2 = array();
1029 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
1033 foreach (
$object->lines as $line) {
1034 if ($line->product_type < 9 && $line->total_ht != 0) {
1035 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
1037 if (!isset($amount_ht[$keyforvatrate])) {
1038 $amount_ht[$keyforvatrate] = 0;
1040 $amount_ht[$keyforvatrate] += $line->total_ht;
1041 if (!isset($amount_tva[$keyforvatrate])) {
1042 $amount_tva[$keyforvatrate] = 0;
1044 $amount_tva[$keyforvatrate] += $line->total_tva;
1045 if (!isset($amount_localtax1[$keyforvatrate])) {
1046 $amount_localtax1[$keyforvatrate] = 0;
1048 $amount_localtax1[$keyforvatrate] += $line->total_localtax1;
1049 if (!isset($amount_localtax2[$keyforvatrate])) {
1050 $amount_localtax2[$keyforvatrate] = 0;
1052 $amount_localtax2[$keyforvatrate] += $line->total_localtax2;
1053 if (!isset($amount_ttc[$keyforvatrate])) {
1054 $amount_ttc[$keyforvatrate] = 0;
1056 $amount_ttc[$keyforvatrate] += $line->total_ttc;
1057 if (!isset($multicurrency_amount_ht[$keyforvatrate])) {
1058 $multicurrency_amount_ht[$keyforvatrate] = 0;
1060 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
1061 if (!isset($multicurrency_amount_tva[$keyforvatrate])) {
1062 $multicurrency_amount_tva[$keyforvatrate] = 0;
1064 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
1065 if (!isset($multicurrency_amount_ttc[$keyforvatrate])) {
1066 $multicurrency_amount_ttc[$keyforvatrate] = 0;
1068 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
1072 '@phan-var-force array<string,float> $amount_ht
1073 @phan-var-force array<string,float> $amount_tva
1074 @phan-var-force array<string,float> $amount_ttc
1075 @phan-var-force array<string,float> $amount_localtax1
1076 @phan-var-force array<string,float> $amount_localtax2
1077 @phan-var-force array<string,float> $multicurrency_amount_ht
1078 @phan-var-force array<string,float> $multicurrency_amount_tva
1079 @phan-var-force array<string,float> $multicurrency_amount_ttc';
1083 $alreadypaid =
$object->getSommePaiement();
1084 if ($alreadypaid && abs($alreadypaid) < abs(
$object->total_ttc)) {
1085 $ratio = abs((
$object->total_ttc - $alreadypaid) /
$object->total_ttc);
1086 foreach ($amount_ht as $vatrate => $val) {
1087 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
1088 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
1089 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
1090 $amount_localtax1[$vatrate] =
price2num($amount_localtax1[$vatrate] * $ratio,
'MU');
1091 $amount_localtax2[$vatrate] =
price2num($amount_localtax2[$vatrate] * $ratio,
'MU');
1092 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
1093 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
1094 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
1103 $discount->description =
'(CREDIT_NOTE)';
1105 $discount->description =
'(DEPOSIT)';
1107 $discount->description =
'(EXCESS RECEIVED)';
1109 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
1111 $discount->fk_soc =
$object->socid;
1112 $discount->socid =
$object->socid;
1113 $discount->fk_facture_source =
$object->id;
1122 $discount->description =
'(EXCESS RECEIVED)';
1125 $sql =
'SELECT SUM(pf.amount) as total_paiements';
1126 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
1127 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
1128 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id);
1129 $sql .=
' AND pf.fk_paiement = p.rowid';
1130 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
1131 $resql =
$db->query($sql);
1136 $res =
$db->fetch_object($resql);
1137 $total_paiements = $res->total_paiements;
1140 $total_creditnote_and_deposit = 0;
1141 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1142 $sql .=
" re.description, re.fk_facture_source";
1143 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1144 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
1145 $resql =
$db->query($sql);
1146 if (!empty($resql)) {
1147 while ($obj =
$db->fetch_object($resql)) {
1148 $total_creditnote_and_deposit += $obj->amount_ttc;
1154 $discount->amount_ttc =
price2num($total_paiements + $total_creditnote_and_deposit -
$object->total_ttc,
'MT');
1155 $discount->amount_tva = 0;
1156 $discount->amount_ht = $discount->amount_ttc;
1157 $discount->tva_tx = 0;
1158 $discount->localtax1_tx = 0;
1159 $discount->localtax1_type = 0;
1160 $discount->localtax2_tx = 0;
1161 $discount->localtax2_type = 0;
1162 $discount->vat_src_code =
'';
1164 if ($discount->amount_ttc > 0) {
1165 $result = $discount->create($user);
1175 $discount->description =
'(CREDIT_NOTE)';
1177 $discount->description =
'(DEPOSIT)';
1180 foreach ($amount_ht as $tva_tx => $xxx) {
1185 $discount->amount_ht = -((float) $amount_ht[$tva_tx]);
1186 $discount->amount_tva = -((float) $amount_tva[$tva_tx]);
1187 $discount->amount_ttc = -((float) $amount_ttc[$tva_tx]);
1188 $discount->total_ht = -((float) $amount_ht[$tva_tx]);
1189 $discount->total_tva = -((float) $amount_tva[$tva_tx]);
1190 $discount->total_localtax1 = -((float) $amount_localtax1[$tva_tx]);
1191 $discount->total_localtax2 = -((float) $amount_localtax2[$tva_tx]);
1192 $discount->total_ttc = -((float) $amount_ttc[$tva_tx]);
1193 $discount->multicurrency_amount_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1194 $discount->multicurrency_amount_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1195 $discount->multicurrency_amount_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1196 $discount->multicurrency_total_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
1197 $discount->multicurrency_total_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
1198 $discount->multicurrency_total_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
1201 $discount->amount_ht = abs((
float) $amount_ht[$tva_tx]);
1202 $discount->amount_tva = abs((
float) $amount_tva[$tva_tx]);
1203 $discount->amount_ttc = abs((
float) $amount_ttc[$tva_tx]);
1204 $discount->total_ht = abs((
float) $amount_ht[$tva_tx]);
1205 $discount->total_tva = abs((
float) $amount_tva[$tva_tx]);
1206 $discount->total_localtax1 = abs((
float) $amount_localtax1[$tva_tx]);
1207 $discount->total_localtax2 = abs((
float) $amount_localtax2[$tva_tx]);
1208 $discount->total_ttc = abs((
float) $amount_ttc[$tva_tx]);
1209 $discount->multicurrency_amount_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1210 $discount->multicurrency_amount_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1211 $discount->multicurrency_amount_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1212 $discount->multicurrency_total_ht = abs((
float) $multicurrency_amount_ht[$tva_tx]);
1213 $discount->multicurrency_total_tva = abs((
float) $multicurrency_amount_tva[$tva_tx]);
1214 $discount->multicurrency_total_ttc = abs((
float) $multicurrency_amount_ttc[$tva_tx]);
1220 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
1221 $vat_src_code = $reg[1];
1222 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
1225 $discount->tva_tx = abs((
float) $tva_tx);
1226 $discount->localtax1_tx = $taxes[
'localtax1'];
1227 $discount->localtax1_type = $taxes[
'localtax1_type'];
1228 $discount->localtax2_tx = $taxes[
'localtax2'];
1229 $discount->localtax2_type = $taxes[
'localtax2_type'];
1230 $discount->vat_src_code = $vat_src_code;
1232 $result = $discount->create($user);
1240 if (empty($error)) {
1250 $result =
$object->setPaid($user);
1264 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
1269 $result = $paiement->fetch(
GETPOSTINT(
'paiement_id'));
1271 $result = $paiement->delete($user);
1273 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1281 } elseif ($action ==
'add' && $usercancreate) {
1288 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1294 $object->demand_reason_id = $inputReasonId;
1297 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1310 if (empty($dateinvoice)) {
1312 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1322 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1332 $object->date_pointoftax = $date_pointoftax;
1333 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1334 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1343 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1344 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1361 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1363 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceAvoirAskCombo")),
null,
'errors');
1367 if (empty($dateinvoice)) {
1369 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1379 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1384 if (!empty($originentity)) {
1385 $object->entity = $originentity;
1391 $object->date_pointoftax = $date_pointoftax;
1392 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1393 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1398 $object->cond_reglement_id = 0;
1402 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1403 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1407 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1411 if (
$object->fk_facture_source > 0 && $facture_source->fetch(
$object->fk_facture_source) > 0) {
1412 if ($facture_source->isSituationInvoice()) {
1413 $object->situation_counter = $facture_source->situation_counter;
1414 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1415 $facture_source->fetchPreviousNextSituationInvoice();
1418 $object->pos_source = $facture_source->pos_source;
1419 $object->module_source = $facture_source->module_source;
1427 if (
$object->copy_linked_contact($facture_source,
'internal') < 0) {
1429 } elseif ($facture_source->socid ==
$object->socid) {
1431 if (
$object->copy_linked_contact($facture_source,
'external') < 0) {
1442 if (
GETPOSTINT(
'invoiceAvoirWithLines') == 1 && $id > 0) {
1443 if (!empty($facture_source->lines)) {
1444 $fk_parent_line = 0;
1446 foreach ($facture_source->lines as $line) {
1448 if (method_exists($line,
'fetch_optionals')) {
1450 $line->fetch_optionals();
1454 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1455 $fk_parent_line = 0;
1459 if ($facture_source->isSituationInvoice()) {
1460 $source_fk_prev_id = $line->fk_prev_id;
1461 $line->fk_prev_id = $line->id;
1466 if (
getDolGlobalInt(
'INVOICE_USE_SITUATION') != 2 && !empty($facture_source->tab_previous_situation_invoice)) {
1469 $tab_jumped_credit_notes = array();
1470 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1471 $searchPreviousInvoice =
true;
1472 while ($searchPreviousInvoice) {
1473 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1474 $searchPreviousInvoice =
false;
1478 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1484 $maxPrevSituationPercent = 0;
1485 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1486 if ($prevLine->id == $source_fk_prev_id) {
1487 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1490 $line->total_ht -= $prevLine->total_ht;
1491 $line->total_tva -= $prevLine->total_tva;
1492 $line->total_ttc -= $prevLine->total_ttc;
1493 $line->total_localtax1 -= $prevLine->total_localtax1;
1494 $line->total_localtax2 -= $prevLine->total_localtax2;
1496 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1497 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1498 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1499 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1504 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1509 $maxPrevSituationPercent = 0;
1510 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1511 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1512 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1513 $maxPrevSituationPercent = $prevLine->situation_percent;
1515 $line->total_ht -= $prevLine->total_ht;
1516 $line->total_tva -= $prevLine->total_tva;
1517 $line->total_ttc -= $prevLine->total_ttc;
1518 $line->total_localtax1 -= $prevLine->total_localtax1;
1519 $line->total_localtax2 -= $prevLine->total_localtax2;
1521 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1522 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1523 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1524 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1530 $line->situation_percent += $maxPrevSituationPercent;
1536 $line->fk_facture =
$object->id;
1537 $line->fk_parent_line = $fk_parent_line;
1539 $line->subprice = -$line->subprice;
1540 $line->subprice_ttc = -$line->subprice_ttc;
1542 $line->total_ht = -$line->total_ht;
1543 $line->total_tva = -$line->total_tva;
1544 $line->total_ttc = -$line->total_ttc;
1545 $line->total_localtax1 = -$line->total_localtax1;
1546 $line->total_localtax2 = -$line->total_localtax2;
1548 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1549 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1550 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1551 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1553 $line->context[
'createcreditnotefrominvoice'] = 1;
1554 $result = $line->insert(0, 1);
1559 if ($result > 0 && $line->product_type == 9) {
1560 $fk_parent_line = $result;
1568 if (
GETPOSTINT(
'invoiceAvoirWithPaymentRestAmount') == 1 && $id > 0) {
1569 if ($facture_source->fetch(
$object->fk_facture_source) > 0) {
1570 $totalpaid = $facture_source->getSommePaiement();
1571 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1572 $totaldeposits = $facture_source->getSumDepositsUsed();
1573 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1575 if (
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') ==
'default') {
1576 if ((empty(
$object->thirdparty) || !is_object(
$object->thirdparty) || get_class(
$object->thirdparty) !=
'Societe')) {
1579 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty) && get_class(
$object->thirdparty) ==
'Societe') {
1584 } elseif ((
float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY') > 0) {
1585 $tva_tx = (float)
getDolGlobalString(
'INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY');
1592 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), 0, 1, $tva_tx, 0, 0, 0, 0,
'',
'', 0, 0, 0,
'TTC', -$remain_to_pay);
1597 if (!empty(
$object->fk_facture_source) &&
$id > 0) {
1598 $facture_source->fetch(
$object->fk_facture_source);
1599 $facture_source->fetchObjectLinked();
1601 if (!empty($facture_source->linkedObjectsIds)) {
1602 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1603 $object->add_object_linked($sourcetype, current($TIds));
1612 if (empty($dateinvoice)) {
1614 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1625 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1635 $object->date_pointoftax = $date_pointoftax;
1636 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1637 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1648 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1649 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1665 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1666 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1667 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1671 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1675 if (empty($dateinvoice)) {
1677 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1687 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1688 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1693 if ($typeamount && !empty($origin) && !empty($originid)) {
1694 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1695 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1699 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1700 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1704 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1705 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1715 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1725 $object->date_pointoftax = $date_pointoftax;
1726 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1727 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1737 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1738 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1742 $object->situation_counter = 1;
1747 if (in_array(
$object->type, $retainedWarrantyInvoiceAvailableType)) {
1749 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
1751 $object->retained_warranty = 0;
1752 $object->retained_warranty_fk_cond_reglement = 0;
1755 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1756 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1759 $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);
1764 if (!empty($origin) && !empty($originid)) {
1767 $element = $subelement = $origin;
1768 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1769 $element = $regs[1];
1770 $subelement = $regs[2];
1774 if ($element ==
'order') {
1775 $element = $subelement =
'commande';
1777 if ($element ==
'propal') {
1778 $element =
'comm/propal';
1779 $subelement =
'propal';
1781 if ($element ==
'contract') {
1782 $element = $subelement =
'contrat';
1784 if ($element ==
'inter') {
1785 $element = $subelement =
'fichinter';
1787 if ($element ==
'shipping') {
1788 $element = $subelement =
'expedition';
1792 $object->origin_type = $origin;
1793 $object->origin_id = $originid;
1798 if (
$object->origin ==
'shipping') {
1799 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1801 $exp->fetch(
$object->origin_id);
1802 $exp->fetchObjectLinked();
1803 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1804 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1805 $object->linked_objects[
'commande'] = $value;
1811 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
1819 $classname = ucfirst($subelement);
1820 $srcobject =
new $classname(
$db);
1821 '@phan-var-force CommonObject $srcobject';
1823 dol_syslog(
"Try to find source object origin_type=".
$object->origin_type.
" origin_id=".
$object->origin_id.
" to add lines or deposit lines");
1824 $result = $srcobject->fetch(
$object->origin_id);
1830 $amountdeposit = array();
1833 if ($typeamount ==
'amount') {
1834 $amount = (float) $valuedeposit;
1836 $amount = $srcobject->total_ttc * ((float) $valuedeposit / 100);
1839 $TTotalByTva = array();
1840 foreach ($srcobject->lines as &$line) {
1841 if (empty($line->qty)) {
1844 if (!empty($line->special_code)) {
1847 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1849 '@phan-var-force array<string,float> $TTotalByTva';
1851 $amount_ttc_diff = 0.;
1852 foreach ($TTotalByTva as $tva => &$total) {
1853 if (empty($amountdeposit[$tva])) {
1854 $amountdeposit[$tva] = 0;
1856 $coef = $total / $srcobject->total_ttc;
1857 $am = $amount * $coef;
1858 $amount_ttc_diff += $am;
1859 $amountdeposit[$tva] += $am / (1 + (float) $tva / 100);
1862 if ($typeamount ==
'amount') {
1863 $amountdeposit[0] = $valuedeposit;
1864 } elseif ($typeamount ==
'variable') {
1867 $lines = $srcobject->lines;
1868 $numlines = count($lines);
1869 for ($i = 0; $i < $numlines; $i++) {
1871 if (empty($lines[$i]->qty)) {
1874 if (!empty($lines[$i]->special_code)) {
1878 $totalamount += $lines[$i]->total_ht;
1879 $tva_tx = $lines[$i]->tva_tx;
1881 if (empty($amountdeposit[$tva_tx])) {
1882 $amountdeposit[$tva_tx] = 0;
1884 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * (float) $valuedeposit) / 100;
1888 if ($totalamount == 0) {
1889 $amountdeposit[0] = 0;
1897 $amount_ttc_diff = $amountdeposit[0];
1900 foreach ($amountdeposit as $tva => $amount) {
1901 if (empty($amount)) {
1906 'amount' =>
'FixAmount',
1907 'variable' =>
'VarAmount'
1909 $descline =
'(DEPOSIT)';
1911 if ($typeamount ==
'amount') {
1912 $descline .=
' ('.price($valuedeposit, 0, $langs, 0, - 1, - 1, (!empty(
$object->multicurrency_code) ?
$object->multicurrency_code :
$conf->currency)).
')';
1913 } elseif ($typeamount ==
'variable') {
1914 $descline .=
' ('.$valuedeposit.
'%)';
1917 $descline .=
' - '.$srcobject->ref;
1930 $i >= 0 ? $lines[$i]->info_bits : 0,
1936 $i >= 0 ? $lines[$i]->special_code : 0,
1953 $diff =
$object->total_ttc - $amount_ttc_diff;
1957 $subprice_diff =
$object->lines[0]->subprice - $diff / (1 +
$object->lines[0]->tva_tx / 100);
1958 $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);
1967 $lines = $srcobject->lines;
1968 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1969 $srcobject->fetch_lines();
1970 $lines = $srcobject->lines;
1975 if (is_array($lines)) {
1976 foreach ($lines as $line) {
1978 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuestandardinvoice / 100,
'MS');
1984 if (is_array($lines)) {
1985 foreach ($lines as $line) {
1987 $line->qty = (float)
price2num((
float) $line->qty * (float) $valuedeposit / 100,
'MS');
1992 $fk_parent_line = 0;
1993 $num = count($lines);
1995 for ($i = 0; $i < $num; $i++) {
1996 if (!in_array($lines[$i]->
id, $selectedLines)) {
2001 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
2005 if (!isset(
$conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
2006 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
2008 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
2012 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
2013 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
2015 if (
$object->situation_counter == 1) {
2016 $lines[$i]->situation_percent = 0;
2019 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
2022 $desc = $label ? $label : $langs->trans(
'Discount');
2026 $discount->fk_soc =
$object->socid;
2027 $discount->socid =
$object->socid;
2028 $discount->amount_ht = abs($lines[$i]->total_ht);
2029 $discount->amount_tva = abs($lines[$i]->total_tva);
2030 $discount->amount_ttc = abs($lines[$i]->total_ttc);
2031 $discount->total_ht = abs($lines[$i]->total_ht);
2032 $discount->total_tva = abs($lines[$i]->total_tva);
2033 $discount->total_ttc = abs($lines[$i]->total_ttc);
2034 $discount->tva_tx = $lines[$i]->tva_tx;
2035 $discount->localtax1_tx = $lines[$i]->localtax1_tx;
2036 $discount->localtax2_tx = $lines[$i]->localtax2_tx;
2037 $discount->localtax1_type = $lines[$i]->localtax1_type;
2038 $discount->localtax2_type = $lines[$i]->localtax2_type;
2039 $discount->total_localtax1 = abs($lines[$i]->total_localtax1);
2040 $discount->total_localtax2 = abs($lines[$i]->total_localtax2);
2041 $discount->fk_user = $user->id;
2042 $discount->description = $desc;
2043 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
2044 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
2045 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
2046 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
2047 $discount->multicurrency_total_ht = abs($lines[$i]->multicurrency_total_ht);
2048 $discount->multicurrency_total_tva = abs($lines[$i]->multicurrency_total_tva);
2049 $discount->multicurrency_total_ttc = abs($lines[$i]->multicurrency_total_ttc);
2051 $discountid = $discount->create($user);
2052 if ($discountid > 0) {
2053 $result =
$object->insert_discount($discountid);
2066 if (isset($lines[$i]->date_debut_prevue)) {
2069 if (isset($lines[$i]->date_debut_reel)) {
2072 if (isset($lines[$i]->date_start)) {
2078 if (isset($lines[$i]->date_fin_prevue)) {
2079 $date_end = $lines[$i]->date_fin_prevue;
2081 if (isset($lines[$i]->date_fin_reel)) {
2082 $date_end = $lines[$i]->date_fin_reel;
2084 if (isset($lines[$i]->date_end)) {
2085 $date_end = $lines[$i]->date_end;
2089 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
2090 $fk_parent_line = 0;
2093 $array_options = array();
2095 if (method_exists($lines[$i],
'fetch_optionals')) {
2096 $lines[$i]->fetch_optionals();
2097 $array_options = $lines[$i]->array_options;
2100 $tva_tx = $lines[$i]->tva_tx;
2101 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
2102 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
2111 $line_price_base_type = $lines[$i]->getPriceBaseType();
2114 $lines[$i]->subprice,
2119 $lines[$i]->fk_product,
2120 $lines[$i]->remise_percent,
2124 (
int) $lines[$i]->info_bits,
2125 isset($lines[$i]->fk_remise_except) ? $lines[$i]->fk_remise_except : null,
2126 $line_price_base_type,
2127 (float) $lines[$i]->subprice_ttc,
2130 $lines[$i]->special_code,
2134 isset($lines[$i]->fk_fournprice) ? $lines[$i]->fk_fournprice : null,
2138 $lines[$i]->situation_percent ?? 100,
2139 $lines[$i]->fk_prev_id ?? 0,
2140 $lines[$i]->fk_unit,
2147 foreach (
$object->lines as $line) {
2148 if ($line->id == $result) {
2149 $line->extraparams = $lines[$i]->extraparams;
2150 $line->setExtraParameters();
2162 if ($result > 0 && $lines[$i]->product_type == 9) {
2163 $fk_parent_line = $result;
2175 $object->line_order(
true,
'DESC');
2203 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id,
'objFrom' => $srcobject);
2204 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
2217 for ($i = 1; $i <= $NBLINES; $i++) {
2223 $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);
2234 if (empty($dateinvoice)) {
2236 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
2246 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
2256 if (!empty($origin) && !empty($originid)) {
2257 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2260 $object->origin_type = $origin;
2261 $object->origin_id = $originid;
2265 $retained_warranty =
GETPOSTINT(
'retained_warranty');
2266 if (
price2num($retained_warranty) > 0) {
2270 if (
GETPOSTINT(
'retained_warranty_fk_cond_reglement') > 0) {
2271 $object->retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
2274 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
2275 if (!empty($retained_warranty_date_limit) &&
$db->jdate($retained_warranty_date_limit)) {
2276 $object->retained_warranty_date_limit =
$db->jdate($retained_warranty_date_limit);
2278 $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);
2281 foreach (
$object->lines as $i => &$line) {
2282 $line->fk_prev_id = $line->id;
2283 $line->fetch_optionals();
2285 $line->situation_percent = 0;
2287 $line->situation_percent = $line->get_prev_progress(
$object->id);
2291 $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);
2292 $line->total_ht = (float) $tabprice[0];
2293 $line->total_tva = (float) $tabprice[1];
2294 $line->total_ttc = (float) $tabprice[2];
2295 $line->total_localtax1 = (float) $tabprice[9];
2296 $line->total_localtax2 = (float) $tabprice[10];
2297 $line->multicurrency_total_ht = (float) $tabprice[16];
2298 $line->multicurrency_total_tva = (float) $tabprice[17];
2299 $line->multicurrency_total_ttc = (float) $tabprice[18];
2302 if ($line->fk_remise_except) {
2304 $result = $discount->fetch((
int) $line->fk_remise_except);
2307 if ($discount->fk_facture_line > 0) {
2308 $line->fk_remise_except = 0;
2317 $object->date_pointoftax = $date_pointoftax;
2318 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
2332 $object->situation_counter += 1;
2337 $extrafields->fetch_name_optionals_label(
$object->table_element);
2338 $extrafields->setOptionalsFromPost(
null, $object);
2345 $nextSituationInvoice->fetch($id);
2348 $parameters = array(
'origin_type' =>
$object->origin_type,
'origin_id' =>
$object->origin_id);
2349 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $nextSituationInvoice, $action);
2360 if ($id > 0 && !$error) {
2362 $categories =
GETPOST(
'categories',
'array');
2363 if (method_exists($object,
'setCategories')) {
2364 $object->setCategories($categories);
2372 $outputlangs = $langs;
2375 $newlang =
GETPOST(
'lang_id',
'aZ09');
2378 if (empty(
$object->thirdparty)) {
2381 $newlang =
$object->thirdparty->default_lang;
2383 if (!empty($newlang)) {
2385 $outputlangs->setDefaultLang($newlang);
2386 $outputlangs->load(
'products');
2391 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2397 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2402 $_GET[
"origin"] =
GETPOST(
"origin",
'alpha');
2406 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
2410 foreach (
$object->lines as $line) {
2411 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2414 if ($line->product_type == 1) {
2416 $line_price_base_type = $line->getPriceBaseType();
2417 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
2418 $result =
$object->updateline($line->id, $line->desc, $line_pu, $line->qty, $line->remise_percent, $alldate_start, $alldate_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line_price_base_type, $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);
2421 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
2423 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2424 $vat_rate = str_replace(
'*',
'', $vat_rate);
2427 foreach (
$object->lines as $line) {
2428 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2432 $line_price_base_type = $line->getPriceBaseType();
2433 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
2434 $result =
$object->updateline($line->id, $line->desc, $line_pu, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $vat_rate, $localtax1_rate, $localtax2_rate, $line_price_base_type, $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);
2436 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2438 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2439 $remise_percent = str_replace(
'*',
'', $remise_percent);
2440 foreach (
$object->lines as $line) {
2441 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
2444 $tvatx = $line->tva_tx;
2445 if (!empty($line->vat_src_code)) {
2446 $tvatx .=
' ('.$line->vat_src_code.
')';
2449 $line_price_base_type = $line->getPriceBaseType();
2450 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
2451 $result =
$object->updateline($line->id, $line->desc, $line_pu, $line->qty, (
float) $remise_percent, $line->date_start, $line->date_end, $tvatx, $line->localtax1_tx, $line->localtax2_tx, $line_price_base_type, $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);
2453 } elseif ($action ==
'confirm_addtextline' && $usercancreate) {
2456 $langs->load(
'subtotals');
2458 $desc =
GETPOST(
'subtotaltextcontent',
'restricthtml');
2461 $result =
$object->addSubtotalLine($langs, $desc, 0, array());
2472 $outputlangs = $langs;
2473 $newlang =
GETPOST(
'lang_id',
'alpha');
2475 $newlang =
$object->thirdparty->default_lang;
2477 if (!empty($newlang)) {
2479 $outputlangs->setDefaultLang($newlang);
2482 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2487 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2489 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
2492 $langs->load(
'subtotals');
2494 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
2495 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
2497 $subtotal_options = array();
2499 foreach (Facture::$TITLE_OPTIONS as $option) {
2500 $value =
GETPOST($option,
'alphanohtml');
2502 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2507 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2518 $outputlangs = $langs;
2519 $newlang =
GETPOST(
'lang_id',
'alpha');
2521 $newlang =
$object->thirdparty->default_lang;
2523 if (!empty($newlang)) {
2525 $outputlangs->setDefaultLang($newlang);
2528 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2533 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2535 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
2538 $langs->load(
'subtotals');
2540 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
2541 foreach (
$object->lines as $line) {
2542 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
2543 $desc = $line->desc;
2544 $depth = -$line->qty;
2548 $subtotal_options = array();
2550 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
2551 $value =
GETPOST($option,
'alphanohtml');
2553 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
2558 if (isset($desc) && isset($depth)) {
2559 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
2562 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
2571 $outputlangs = $langs;
2572 $newlang =
GETPOST(
'lang_id',
'alpha');
2574 $newlang =
$object->thirdparty->default_lang;
2576 if (!empty($newlang)) {
2578 $outputlangs->setDefaultLang($newlang);
2581 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2586 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2588 } elseif ($action ==
'addline' &&
GETPOST(
'updateallvatlinesblock',
'alpha') &&
GETPOST(
'vatforblocklines',
'alpha') !==
'' && $usercancreate) {
2589 $tx_tva =
GETPOST(
'vatforblocklines') ?
GETPOST(
'vatforblocklines') : 0;
2590 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'tva', $tx_tva);
2591 } elseif ($action ==
'addline' &&
GETPOST(
'updatealldiscountlinesblock',
'alpha') &&
GETPOST(
'discountforblocklines',
'alpha') !==
'' && $usercancreate) {
2592 $discount =
GETPOST(
'discountforblocklines') ?
GETPOST(
'discountforblocklines') : 0;
2593 $object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'discount', $discount);
2594 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && !
GETPOST(
'submitforallmargins',
'alpha') && !
GETPOST(
'submitforallmark',
'alpha') && $usercancreate) {
2595 $langs->load(
'errors');
2600 $line_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
2603 $price_ht_devise =
'';
2605 $price_ttc_devise =
'';
2608 $price_min_ttc =
'';
2610 if (
GETPOST(
'price_ht') !==
'') {
2613 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2616 if (
GETPOST(
'price_ttc') !==
'') {
2619 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2620 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2623 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2624 if ($prod_entry_mode ==
'free') {
2630 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2635 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2638 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
2639 if (empty($remise_percent)) {
2640 $remise_percent = 0;
2644 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
2645 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
2647 if (is_array($extralabelsline)) {
2649 foreach ($extralabelsline as $key => $value) {
2650 unset($_POST[
"options_".$key.$predef]);
2654 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2655 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2658 if (!$prod_entry_mode) {
2660 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2664 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2665 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2670 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0)
2671 && (((
float) $price_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht ===
'')
2672 && (((
float) $price_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ===
'')
2673 && ((
float) $price_ttc < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc ===
'')
2674 && ((
float) $price_ttc_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES') || $price_ttc_devise ===
'')
2675 &&
$object->type != $object::TYPE_CREDIT_NOTE) {
2676 if (((
float) $price_ht < 0 || (
float) $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2677 $langs->load(
"errors");
2678 if (
$object->type == $object::TYPE_DEPOSIT) {
2680 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2682 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2687 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
2688 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
2692 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
2693 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2697 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2701 $langs->load(
"errors");
2702 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2706 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2707 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
2711 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2712 $idprod = $res->fk_product_child;
2714 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2720 $price_base_type =
null;
2721 if (!$error && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
2727 $ret =
$object->fetch_thirdparty();
2732 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2743 if (!empty($idprod) && $idprod > 0) {
2745 $prod->fetch($idprod);
2754 $pu_ht = $datapriceofproduct[
'pu_ht'];
2755 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2756 $price_min = $datapriceofproduct[
'price_min'];
2757 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2758 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2762 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2763 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string)
$prod->tva_tx));
2768 if (!empty($price_ht) || $price_ht ===
'0') {
2770 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
2771 $price_base_type =
'HT';
2772 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2773 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2774 $pu_ttc_devise = (float)
price2num((
float) $pu_ht_devise * (1 + ((float) $tmpvat / 100)),
'MU');
2777 $price_base_type =
'HT';
2778 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2780 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2781 $price_base_type =
'TTC';
2782 } elseif (!empty($price_ttc_devise) || (
string) $price_ttc_devise ===
'0') {
2783 $pu_ttc_devise = (float)
price2num($price_ttc_devise,
'MU');
2784 $pu_ht_devise = (float)
price2num((
float) $pu_ttc_devise / (1 + ((float) $tmpvat / 100)),
'MU');
2787 $price_base_type =
'TTC';
2788 } elseif ($tmpvat != $tmpprodvat) {
2790 if ($price_base_type !=
'HT') {
2791 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2793 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2797 $outputlangs = $langs;
2803 if (
GETPOST(
'lang_id',
'aZ09')) {
2804 $newlang =
GETPOST(
'lang_id',
'aZ09');
2806 if (empty($newlang)) {
2807 $newlang =
$object->thirdparty->default_lang;
2809 if (!empty($newlang)) {
2811 $outputlangs->setDefaultLang($newlang);
2812 $outputlangs->load(
'products');
2815 $desc = (!empty(
$prod->multilangs [$outputlangs->defaultlang] [
"description"])) ?
$prod->multilangs [$outputlangs->defaultlang] [
"description"] :
$prod->
description;
2817 $desc =
$prod->description;
2833 if (!empty(
$prod->customcode)) {
2834 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomsCode").
': '.
$prod->customcode;
2836 if (!empty(
$prod->customcode) && !empty(
$prod->country_code)) {
2839 if (!empty(
$prod->country_code)) {
2840 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry(
$prod->country_code,
'',
$db, $outputlangs, 0);
2843 if (!empty(
$prod->customcode)) {
2844 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomsCode").
': '.
$prod->customcode;
2846 if (!empty(
$prod->customcode) && !empty(
$prod->country_code)) {
2849 if (!empty(
$prod->country_code)) {
2850 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry(
$prod->country_code,
'',
$db, $langs, 0);
2857 $type =
$prod->type;
2858 $fk_unit =
$prod->fk_unit;
2860 if (!empty($price_ht)) {
2865 if (!empty($price_ttc)) {
2870 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2871 $tva_tx = str_replace(
'*',
'', $tva_tx);
2872 if (empty($tva_tx)) {
2875 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2878 $fk_unit =
GETPOST(
'units',
'alpha');
2880 if ($pu_ttc && !$pu_ht) {
2881 $price_base_type =
'TTC';
2895 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2896 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2899 $pu_equivalent = $pu_ht;
2900 $pu_equivalent_ttc = $pu_ttc;
2902 $currency_tx =
$object->multicurrency_tx;
2906 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
2907 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
2909 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
2910 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
2925 $fournprice = (int) (
GETPOST(
'fournprice'.$predef) ?
GETPOST(
'fournprice'.$predef) :
'');
2930 $price2num_remise_percent =
price2num($remise_percent);
2931 $price2num_price_min =
price2num($price_min);
2932 $price2num_price_min_ttc =
price2num($price_min_ttc);
2933 if (empty($price2num_pu_ht)) {
2934 $price2num_pu_ht = 0;
2936 if (empty($price2num_remise_percent)) {
2937 $price2num_remise_percent = 0;
2939 if (empty($price2num_price_min)) {
2940 $price2num_price_min = 0;
2942 if (empty($price2num_price_min_ttc)) {
2943 $price2num_price_min_ttc = 0;
2948 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2949 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2952 } 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') {
2953 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
2972 $situation_percent = (GETPOSTISSET(
'progress') ?
GETPOSTINT(
'progress') : 100);
2974 $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);
2980 $outputlangs = $langs;
2983 $newlang =
GETPOST(
'lang_id',
'aZ09');
2986 $newlang =
$object->thirdparty->default_lang;
2988 if (!empty($newlang)) {
2990 $outputlangs->setDefaultLang($newlang);
2991 $outputlangs->load(
'products');
2994 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
3000 unset($_POST[
'prod_entry_mode']);
3001 unset($_POST[
'qty']);
3002 unset($_POST[
'type']);
3003 unset($_POST[
'remise_percent']);
3004 unset($_POST[
'price_ht']);
3005 unset($_POST[
'multicurrency_price_ht']);
3006 unset($_POST[
'price_ttc']);
3007 unset($_POST[
'tva_tx']);
3008 unset($_POST[
'product_ref']);
3009 unset($_POST[
'product_label']);
3010 unset($_POST[
'product_desc']);
3011 unset($_POST[
'fournprice']);
3012 unset($_POST[
'buying_price']);
3013 unset($_POST[
'np_marginRate']);
3014 unset($_POST[
'np_markRate']);
3015 unset($_POST[
'dp_desc']);
3016 unset($_POST[
'idprod']);
3017 unset($_POST[
'units']);
3018 unset($_POST[
'date_starthour']);
3019 unset($_POST[
'date_startmin']);
3020 unset($_POST[
'date_startsec']);
3021 unset($_POST[
'date_startday']);
3022 unset($_POST[
'date_startmonth']);
3023 unset($_POST[
'date_startyear']);
3024 unset($_POST[
'date_endhour']);
3025 unset($_POST[
'date_endmin']);
3026 unset($_POST[
'date_endsec']);
3027 unset($_POST[
'date_endday']);
3028 unset($_POST[
'date_endmonth']);
3029 unset($_POST[
'date_endyear']);
3030 unset($_POST[
'situations']);
3031 unset($_POST[
'progress']);
3033 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
3042 } elseif ($action ==
'addline' && $usercancreate && (
3043 (
GETPOST(
'submitforallmargins',
'alpha') &&
GETPOST(
'marginforalllines',
'alpha') !==
'') ||
3044 (
GETPOST(
'submitforallmark',
'alpha') &&
GETPOST(
'markforalllines',
'alpha') !==
'')
3047 $margin_rate = GETPOSTISSET(
'marginforalllines') ?
GETPOST(
'marginforalllines',
'int') :
'';
3048 $mark_rate = GETPOSTISSET(
'markforalllines') ?
GETPOST(
'markforalllines',
'int') :
'';
3049 foreach (
$object->lines as &$line) {
3050 if ($line->subprice > 0) {
3051 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
3054 $subprice_multicurrency = $line->subprice;
3055 if (is_numeric($margin_rate) && $margin_rate > 0) {
3056 $line->subprice = (float)
price2num((
float) $line->pa_ht * (1 + (float) $margin_rate / 100),
'MU');
3057 } elseif (is_numeric($mark_rate) && $mark_rate > 0) {
3058 $line->subprice = (float) ($line->pa_ht / (1 - ((
float) $mark_rate / 100)));
3060 $line->subprice = (float) $line->pa_ht;
3063 if ($line->fk_product > 0) {
3065 $res =
$prod->fetch($line->fk_product);
3067 if (
$prod->price_min > $line->subprice) {
3068 $price_subprice =
price($line->subprice, 0, $outlangs, 1, -1, -1,
'auto');
3069 $price_price_min =
price(
$prod->price_min, 0, $outlangs, 1, -1, -1,
'auto');
3070 setEventMessages(
$prod->ref .
' - ' .
$prod->label .
' (' . $price_subprice .
' < ' . $price_price_min .
' ' . strtolower($langs->trans(
"MinPrice")) .
')' .
"\n",
null,
'warnings');
3079 $multicurrency_subprice = (float) $line->subprice * $line->multicurrency_subprice / $subprice_multicurrency;
3081 $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);
3084 if (is_numeric($margin_rate) && empty($mark_rate)) {
3085 $line->marge_tx = $margin_rate;
3086 } elseif (is_numeric($mark_rate) && empty($margin_rate)) {
3087 $line->marque_tx = $mark_rate;
3089 $line->total_ht = $line->qty * (float) $line->subprice;
3090 $line->total_tva = $line->tva_tx * $line->qty * (float) $line->subprice;
3091 $line->total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $line->subprice;
3093 $line->multicurrency_total_ht = $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
3094 $line->multicurrency_total_tva = $line->tva_tx * $line->qty * (float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
3095 $line->multicurrency_total_ttc = (1 + $line->tva_tx) * $line->qty * (
float) $subprice_multicurrency * $line->multicurrency_subprice / $line->subprice;
3097 $line->multicurrency_subprice = $multicurrency_subprice;
3103 } elseif ($action ==
'updatetitleline' && GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3106 $langs->load(
'subtotals');
3108 $desc =
GETPOST(
'line_desc',
'alphanohtml') ?? $langs->trans(
"Title");
3111 $subtotal_options = array();
3113 foreach (Facture::$TITLE_OPTIONS as $option) {
3114 $value =
GETPOST($option,
'alphanohtml');
3116 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
3121 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3132 $outputlangs = $langs;
3133 $newlang =
GETPOST(
'lang_id',
'alpha');
3135 $newlang =
$object->thirdparty->default_lang;
3137 if (!empty($newlang)) {
3139 $outputlangs->setDefaultLang($newlang);
3142 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3147 } elseif ($action ==
'updatetextline' && GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3150 $langs->load(
'subtotals');
3152 $desc =
GETPOST(
'line_desc',
'restricthtml');
3155 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, 0, array());
3166 $outputlangs = $langs;
3167 $newlang =
GETPOST(
'lang_id',
'alpha');
3169 $newlang =
$object->thirdparty->default_lang;
3171 if (!empty($newlang)) {
3173 $outputlangs->setDefaultLang($newlang);
3176 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3181 } elseif ($action ==
'updatesubtotalline' && GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3184 $langs->load(
'subtotals');
3186 $desc =
GETPOST(
'line_desc',
'alphanohtml');
3189 $subtotal_options = array();
3191 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
3192 $value =
GETPOST($option,
'alphanohtml');
3194 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
3199 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
3207 $outputlangs = $langs;
3208 $newlang =
GETPOST(
'lang_id',
'alpha');
3210 $newlang =
$object->thirdparty->default_lang;
3212 if (!empty($newlang)) {
3214 $outputlangs->setDefaultLang($newlang);
3217 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3222 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
3223 if (!
$object->fetch($id) > 0) {
3246 if (preg_match(
'/\*/', $vat_rate)) {
3251 $vat_rate = str_replace(
'*',
'', $vat_rate);
3256 $fournprice = (int) (
GETPOST(
'fournprice') ?
GETPOST(
'fournprice') :
'');
3260 $pu_equivalent = $pu_ht;
3261 $pu_equivalent_ttc = $pu_ttc;
3263 $currency_tx =
$object->multicurrency_tx;
3267 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3268 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
3270 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'' && !empty((
float) $currency_tx)) {
3271 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
3286 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
3287 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
3289 if (is_array($extralabelsline)) {
3291 foreach ($extralabelsline as $key => $value) {
3292 unset($_POST[
"options_".$key]);
3298 if ($special_code == 3) {
3304 $percent = $line->get_prev_progress(
$object->id);
3309 if ($progress >= 0) {
3310 $mesg = $langs->trans(
"CantBeNullOrPositive");
3314 } elseif ($progress < $line->situation_percent) {
3315 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
3319 } elseif ($progress < $percent) {
3320 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
3328 if (empty($remise_percent)) {
3329 $remise_percent = 0;
3336 $price_base_type =
'HT';
3337 if (empty($pu_ht) && !empty($pu_ttc)) {
3339 $price_base_type =
'TTC';
3340 } elseif (!empty($pu_ht) && !empty($pu_ttc)) {
3341 foreach (
$object->lines as $line_obj) {
3344 if ($line_obj->wasEnteredIncludingTax()) {
3346 $price_base_type =
'TTC';
3355 if (!empty($productid)) {
3357 $product->fetch($productid);
3359 $type = $product->type;
3361 $price_min = $product->price_min;
3363 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
3365 $price_min_ttc = $product->price_min_ttc;
3367 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
3374 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
3375 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3378 $action =
'editline';
3379 } 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') {
3380 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
3383 $action =
'editline';
3388 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
3392 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
3397 $langs->load(
"errors");
3398 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
3402 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
3403 $langs->load(
"errors");
3404 if (
$object->type == $object::TYPE_DEPOSIT) {
3406 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
3408 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
3412 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
3419 $previousprogress = $line->getAllPrevProgress($line->fk_facture);
3422 if ($fullprogress < $previousprogress) {
3424 setEventMessages($langs->trans(
'CantBeLessThanMinPercent'),
null,
'errors');
3428 if ($fullprogress > 100) {
3429 $fullprogress = 100;
3431 $addprogress = $fullprogress - $previousprogress;
3438 if (empty($usercancreatemargin)) {
3439 foreach (
$object->lines as &$line) {
3441 $fournprice = $line->fk_fournprice;
3442 $buyingprice = $line->pa_ht;
3448 $result =
$object->updateline(
3453 (
float) $remise_percent,
3471 (
float) $pu_ht_devise
3478 $outputlangs = $langs;
3481 $newlang =
GETPOST(
'lang_id',
'aZ09');
3484 $newlang =
$object->thirdparty->default_lang;
3486 if (!empty($newlang)) {
3488 $outputlangs->setDefaultLang($newlang);
3489 $outputlangs->load(
'products');
3491 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
3494 unset($_POST[
'qty']);
3495 unset($_POST[
'type']);
3496 unset($_POST[
'productid']);
3497 unset($_POST[
'remise_percent']);
3498 unset($_POST[
'price_ht']);
3499 unset($_POST[
'multicurrency_price_ht']);
3500 unset($_POST[
'price_ttc']);
3501 unset($_POST[
'tva_tx']);
3502 unset($_POST[
'product_ref']);
3503 unset($_POST[
'product_label']);
3504 unset($_POST[
'product_desc']);
3505 unset($_POST[
'fournprice']);
3506 unset($_POST[
'buying_price']);
3507 unset($_POST[
'np_marginRate']);
3508 unset($_POST[
'np_markRate']);
3509 unset($_POST[
'dp_desc']);
3510 unset($_POST[
'idprod']);
3511 unset($_POST[
'units']);
3512 unset($_POST[
'date_starthour']);
3513 unset($_POST[
'date_startmin']);
3514 unset($_POST[
'date_startsec']);
3515 unset($_POST[
'date_startday']);
3516 unset($_POST[
'date_startmonth']);
3517 unset($_POST[
'date_startyear']);
3518 unset($_POST[
'date_endhour']);
3519 unset($_POST[
'date_endmin']);
3520 unset($_POST[
'date_endsec']);
3521 unset($_POST[
'date_endday']);
3522 unset($_POST[
'date_endmonth']);
3523 unset($_POST[
'date_endyear']);
3524 unset($_POST[
'situations']);
3525 unset($_POST[
'progress']);
3530 } elseif ($action ==
'updatealllines' && $usercancreate && GETPOSTISSET(
'all_percent')) {
3531 if (!
$object->fetch($id) > 0) {
3534 if (
GETPOST(
'all_progress') !=
"") {
3536 if ($all_progress > 100) {
3537 $all_progress = 100;
3540 foreach (
$object->lines as $line) {
3542 $percent = $line->getAllPrevProgress(
$object->id);
3544 $percent = $line->get_prev_progress(
$object->id);
3546 if (
$object->type != $object::TYPE_CREDIT_NOTE && (
float) $all_progress < (
float) $percent) {
3547 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
3550 } elseif (
$object->type == $object::TYPE_CREDIT_NOTE && (
float) $all_progress > (
float) $percent) {
3551 $mesg = $langs->trans(
"Line").
' '.$line->rang.
' : '.$langs->trans(
"CantBeMoreThanMinPercent");
3555 $object->update_percent($line, $all_progress,
false);
3560 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
3561 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
3563 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
3565 $object->fetch($id,
'',
'', 0,
true);
3568 &&
$object->isSituationInvoice()
3571 &&
$object->is_last_in_cycle()
3572 && $usercanunvalidate
3575 $newCycle =
$object->newCycle();
3576 if ($newCycle > 1) {
3578 $lastCycle =
$object->situation_cycle_ref;
3579 $lastSituationCounter =
$object->situation_counter;
3580 $linkedCreditNotesList = array();
3582 if (count(
$object->tab_next_situation_invoice) > 0) {
3583 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
3585 && $next_invoice->situation_counter ==
$object->situation_counter
3586 && $next_invoice->fk_facture_source ==
$object->id
3588 $linkedCreditNotesList[] = $next_invoice->id;
3593 $object->situation_cycle_ref = $newCycle;
3594 $object->situation_counter = 1;
3596 if (
$object->update($user) > 0) {
3598 if (count($linkedCreditNotesList) > 0) {
3600 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
3601 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
3602 $sql .=
' , situation_final=0';
3603 $sql .=
' , situation_counter='.((int)
$object->situation_counter);
3604 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
3606 $resql =
$db->query($sql);
3612 foreach (
$object->lines as $line) {
3614 if ($line->product_type == 9) {
3619 if (!empty(
$object->tab_previous_situation_invoice)) {
3621 $lineIndex = count(
$object->tab_previous_situation_invoice) - 1;
3622 $searchPreviousInvoice =
true;
3623 while ($searchPreviousInvoice) {
3624 if (
$object->tab_previous_situation_invoice[$lineIndex]->isSituationInvoice() || $lineIndex < 1) {
3625 $searchPreviousInvoice =
false;
3633 $maxPrevSituationPercent = 0;
3634 foreach (
$object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
3635 if ($prevLine->id == $line->fk_prev_id) {
3636 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
3641 $line->situation_percent -= $maxPrevSituationPercent;
3643 if ($line->update() < 0) {
3652 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
3654 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
3657 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
3660 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
3666 $fromElement =
GETPOST(
'fromelement');
3667 $fromElementid =
GETPOST(
'fromelementid');
3668 $importLines =
GETPOST(
'line_checkbox');
3670 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
3671 $lineClassName =
'';
3672 if ($fromElement ==
'commande') {
3674 $lineClassName =
'OrderLine';
3675 } elseif ($fromElement ==
'propal') {
3676 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
3677 $lineClassName =
'PropaleLigne';
3679 $nextRang = count(
$object->lines) + 1;
3682 foreach ($importLines as $lineId) {
3683 if ($lineClassName ===
'') {
3687 dol_syslog(
'compta/facture/card - No lineClassName - skip import', LOG_ERR);
3694 $lineId = intval($lineId);
3695 $originLine =
new $lineClassName(
$db);
3696 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
3697 $originLine->fetch_optionals();
3698 $desc = $originLine->desc;
3699 $pu_ht = $originLine->subprice;
3700 $qty = $originLine->qty;
3701 $txtva = $originLine->tva_tx;
3702 $txlocaltax1 = $originLine->localtax1_tx;
3703 $txlocaltax2 = $originLine->localtax2_tx;
3704 $fk_product = $originLine->fk_product;
3705 $remise_percent = $originLine->remise_percent;
3707 $date_end = $originLine->date_end;
3708 $fk_code_ventilation = 0;
3709 $info_bits = $originLine->info_bits;
3710 $fk_remise_except = $originLine->fk_remise_except;
3711 $price_base_type =
'HT';
3713 $type = $originLine->product_type;
3714 $rang = $nextRang++;
3715 $special_code = $originLine->special_code;
3716 $origin = $originLine->element;
3717 $origin_id = $originLine->id;
3718 $fk_parent_line = 0;
3719 $fk_fournprice = $originLine->fk_fournprice;
3720 $pa_ht = $originLine->pa_ht;
3721 $label = $originLine->label;
3722 $array_options = $originLine->array_options;
3723 if (
$object->isSituationInvoice()) {
3724 $situation_percent = 0;
3726 $situation_percent = 100;
3729 $fk_unit = $originLine->fk_unit;
3730 $pu_ht_devise = $originLine->multicurrency_subprice;
3732 $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);
3752 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
3758 if (!empty(
$object->id) && $action ==
'send') {
3760 $object->getSommePaiement(-1);
3761 $object->getSumCreditNotesUsed(-1);
3762 $object->getSumDepositsUsed(-1);
3764 $triggersendname =
'BILL_SENTBYMAIL';
3766 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
3767 $trackid =
'inv'.$object->id;
3768 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
3772 $permissiontoadd = $usercancreate;
3773 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
3776 if ($action ==
'update_extras' && $permissiontoeditextra) {
3779 $attribute_name =
GETPOST(
'attribute',
'aZ09');
3782 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
3789 $result =
$object->updateExtraField($attribute_name,
'BILL_MODIFY');
3797 $action =
'edit_extras';
3802 if ($action ==
'addcontact' && $usercancreate) {
3803 $result =
$object->fetch($id);
3805 if ($result > 0 && $id > 0) {
3808 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3812 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3815 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3816 $langs->load(
"errors");
3817 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3822 } elseif ($action ==
'swapstatut' && $usercancreate) {
3829 } elseif ($action ==
'deletecontact' && $usercancreate) {
3832 $result =
$object->delete_contact($lineid);
3835 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
3843 $action =
'edit_extras';
3867$title =
$object->ref.
" - ".$langs->trans(
'Card');
3868if ($action ==
'create') {
3869 $title = $langs->trans(
"NewBill");
3871$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3877if ($action ==
'create') {
3879 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3884 $res = $soc->fetch($socid);
3887 $currency_code =
$conf->currency;
3889 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
3890 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
3894 if (empty($dateinvoice)) {
3900 if (!empty($origin) && !empty($originid)) {
3902 $element = $subelement = $origin;
3904 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3905 $element = $regs[1];
3906 $subelement = $regs[2];
3911 if ($element ==
'project') {
3912 $projectid = $originid;
3914 if (empty($cond_reglement_id)) {
3915 $cond_reglement_id = $soc->cond_reglement_id;
3917 if (empty($mode_reglement_id)) {
3918 $mode_reglement_id = $soc->mode_reglement_id;
3920 if (empty($fk_account)) {
3921 $fk_account = $soc->fk_account;
3925 if ($element ==
'order' || $element ==
'commande') {
3926 $element = $subelement =
'commande';
3928 if ($element ==
'propal') {
3929 $element =
'comm/propal';
3930 $subelement =
'propal';
3932 if ($element ==
'contract') {
3933 $element = $subelement =
'contrat';
3935 if ($element ==
'shipping') {
3936 $element = $subelement =
'expedition';
3941 $classname = ucfirst($subelement);
3942 $objectsrc =
new $classname(
$db);
3943 '@phan-var-force Commande|Propal|Contrat|Expedition|Facture $objectsrc';
3945 $objectsrc->fetch($originid);
3946 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3947 $objectsrc->fetch_lines();
3949 $objectsrc->fetch_thirdparty();
3951 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3957 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3961 if (empty($socid)) {
3962 $soc = $objectsrc->thirdparty;
3965 if ($element ==
'expedition') {
3966 $elem = $subelem = $objectsrc->origin_type;
3967 $expeoriginid = $objectsrc->origin_id;
3969 $classname = ucfirst($subelem);
3971 $expesrc =
new $classname(
$db);
3972 '@phan-var-force Expedition $expesrc';
3974 dol_syslog(
"Is type Facture|Commande or Expedition: $element...expesrc($classname)=".get_class($expesrc));
3975 $expesrc->fetch($expeoriginid);
3977 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3978 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3979 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3982 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3983 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3987 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
3990 $expesrc->fetch_optionals();
3991 $object->array_options = $expesrc->array_options;
3993 $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)));
3994 $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)));
3995 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : (!empty($fk_account) ? $fk_account : 0)));
3998 if (!empty($objectsrc->multicurrency_code)) {
3999 $currency_code = $objectsrc->multicurrency_code;
4001 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
4002 $currency_tx = $objectsrc->multicurrency_tx;
4007 $inputReasonId = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
4010 $objectsrc->fetch_optionals();
4011 $object->array_options = $objectsrc->array_options;
4015 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
4016 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
4017 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
4018 $inputReasonId = empty($soc->demand_reason_id) ? $inputReasonId : $soc->demand_reason_id;
4020 if (
isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
4021 $currency_code = $soc->multicurrency_code;
4026 if (!
GETPOST(
'changecompany')) {
4027 if (GETPOSTISSET(
'cond_reglement_id')) {
4028 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
4030 if (GETPOSTISSET(
'mode_reglement_id')) {
4031 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
4033 if (GETPOSTISSET(
'cond_reglement_id')) {
4039 if (empty($cond_reglement_id)) {
4040 $cond_reglement_id =
GETPOSTINT(
"cond_reglement_id");
4044 if (empty($mode_reglement_id)) {
4045 $mode_reglement_id =
GETPOSTINT(
"mode_reglement_id");
4055 if (!empty($soc->id)) {
4056 $absolute_discount = $soc->getAvailableDiscounts();
4058 $note_public =
$object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
4059 $note_private =
$object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
4061 if (!empty(
$conf->use_javascript_ajax)) {
4062 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
4068 if ($origin ==
'contrat') {
4069 $langs->load(
"admin");
4070 $text = $langs->trans(
"ToCreateARecurringInvoice");
4071 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
4073 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
4075 print
info_admin($text, 0, 0,
'info',
'').
'<br>';
4078 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
4079 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4080 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
4081 print
'<input type="hidden" name="changecompany" value="0">';
4083 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
4085 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4086 print
'<input name="ref" type="hidden" value="provisoire">';
4087 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
4088 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
4089 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
4090 print
'<input name="force_fk_account" type="hidden" value="0">';
4091 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
4092 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
4093 print
'<input type="hidden" name="originentity" value="'.GETPOSTINT(
'originentity').
'">';
4094 if (!empty($currency_tx)) {
4095 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
4101 $parameters = array();
4103 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters, $object, $action);
4104 if (empty($reshook)) {
4105 print
'<table class="border centpercent">';
4109 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
4110 $invoice_predefined->fetch(
GETPOSTINT(
'fac_rec'));
4123 if ($soc->id > 0 && (!
GETPOSTINT(
'fac_rec') || !empty($invoice_predefined->frequency))) {
4125 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
'Customer').
'</td>';
4126 print
'<td colspan="2">';
4127 print $soc->getNomUrl(1,
'customer');
4128 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
4130 $arrayoutstandingbills = $soc->getOutstandingBills();
4131 $outstandingBills = $arrayoutstandingbills[
'opened'];
4132 print
' - <span class="opacitymedium valignmiddle">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
4133 print
'<span class="amount valignmiddle">'.price($outstandingBills, 0, $langs, 0, 0, -1,
$conf->currency).
'</span>';
4134 if ($soc->outstanding_limit !=
'') {
4135 if ($outstandingBills > $soc->outstanding_limit) {
4136 print
img_warning($langs->trans(
"OutstandingBillReached"));
4138 print
' / '.price($soc->outstanding_limit, 0, $langs, 0, 0, -1,
$conf->currency);
4143 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
4144 print
'<td colspan="2">';
4145 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
4146 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
4150 $(document).ready(function() {
4151 $("#socid").change(function() {
4153 console.log("Submit page");
4154 $(\'input[name="action"]\').val(\'create\');
4155 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
4156 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
4157 $(\'input[name="force_fk_account"]\').val(\'1\');
4158 $("#formtocreate").submit(); */
4160 // For company change, we must submit page with action=create instead of action=add
4161 console.log("We have changed the company - Resubmit page");
4162 jQuery("input[name=changecompany]").val("1");
4163 jQuery("#formtocreateaction").val("create");
4164 jQuery("#formtocreate").submit();
4170 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>';
4177 if (empty($origin) && empty($originid) &&
GETPOSTINT(
'fac_rec') > 0) {
4179 foreach ($invoice_predefined->array_options as $key => $option) {
4180 if (!isset(
$object->array_options[$key])) {
4181 $object->array_options[$key] = $invoice_predefined->array_options[$key];
4185 $dateinvoice = $invoice_predefined->date_when;
4186 if (empty($projectid)) {
4187 $projectid = $invoice_predefined->fk_project;
4189 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
4190 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
4191 $fk_account = $invoice_predefined->fk_account;
4192 $note_public = $invoice_predefined->note_public;
4193 $note_private = $invoice_predefined->note_private;
4195 if (!empty($invoice_predefined->multicurrency_code)) {
4196 $currency_code = $invoice_predefined->multicurrency_code;
4198 if (!empty($invoice_predefined->multicurrency_tx)) {
4199 $currency_tx = $invoice_predefined->multicurrency_tx;
4202 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
4203 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
4204 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
4206 $resql =
$db->query($sql);
4208 $num =
$db->num_rows($resql);
4212 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
4214 print
'<select class="flat" id="fac_rec" name="fac_rec">';
4215 print
'<option value="0" selected></option>';
4217 $objp =
$db->fetch_object($resql);
4218 print
'<option value="'.$objp->rowid.
'"';
4221 $exampletemplateinvoice->fetch(
GETPOSTINT(
'fac_rec'));
4223 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
4232 print
'<script type="text/javascript">
4233 $(document).ready(function() {
4234 $("#fac_rec").change(function() {
4235 console.log("We have changed the template invoice - Reload page");
4236 var fac_rec = $(this).val();
4237 var socid = $(\'#socid\').val();
4238 // 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.
4239 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
4252 print
'<tr><td class="tdtop fieldrequired titlefieldcreate">'.$langs->trans(
'Type').
'</td><td colspan="2">';
4253 print
'<div class="listofinvoicetypetable">'.
"\n";
4256 print
'<div class="listofinvoicetype"><div class="">';
4257 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOSTINT(
'type') ?
'' :
' checked').
'> ';
4258 $tmp .=
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk");
4259 $tmp .=
' <span class="opacitymedium">'.$langs->trans(
"InvoiceStandardAsk2").
'</span>';
4262 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc").
'<br><br>'.$langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'nowraponall', 0, 3,
'standardonsmartphone');
4264 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
4274 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%') .
'"/>';
4277 print
'</div></div>'.
"\n";
4279 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
4282 print
'<div class="listofinvoicetype"><div class="">';
4283 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOSTINT(
'type') == 3 ?
' checked' :
'').
'> ';
4284 print
'<script type="text/javascript">
4285 jQuery(document).ready(function() {
4286 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
4287 jQuery("#radio_standard").prop("checked", true);
4289 jQuery("#typedeposit, #valuedeposit").click(function() {
4290 jQuery("#radio_deposit").prop("checked", true);
4292 jQuery("#typedeposit").change(function() {
4293 console.log("We change type of down payment: "+jQuery("#typedeposit").val());
4295 if (jQuery("#typedeposit").val() == "amount") {
4296 jQuery("#valuedeposit").attr("placeholder", "'.$langs->getCurrencySymbol(
$conf->currency).
'");
4297 jQuery("#valuedeposit").val("");
4299 jQuery("#valuedeposit").attr("placeholder", "50%");
4300 jQuery("#valuedeposit").val("");
4303 jQuery("#radio_deposit").prop("checked", true);
4304 setRadioForTypeOfInvoice();
4306 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
4307 setRadioForTypeOfInvoice();
4310 function setRadioForTypeOfInvoice() {
4311 console.log("Change radio for type of invoice");
4312 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
4313 jQuery("#checkforselects").prop("disabled", true);
4314 jQuery("#checkforselects").prop("checked", false);
4315 jQuery(".checkforselect").prop("disabled", true);
4316 jQuery(".checkforselect").prop("checked", false);
4318 jQuery("#checkforselects").prop("disabled", false);
4319 jQuery("#checkforselects").prop("checked", true);
4320 jQuery(".checkforselect").prop("disabled", false);
4321 jQuery(".checkforselect").prop("checked", true);
4327 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
4329 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
4331 if (($origin ==
'propal') || ($origin ==
'commande')) {
4334 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
4335 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
4336 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4340 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
4344 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
4346 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
4347 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
4348 if (!empty($origin_payment_conditions_deposit_percent)) {
4349 $typedeposit =
'variable';
4352 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
4353 $valuedeposit = $objectsrc->deposit_percent;
4355 print
'<span class="marginleftonly">'.$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1).
'</span>';
4357 print
'<input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.($valuedeposit ? $valuedeposit :
'').
'"'.($valuedeposit ?
'' :
'placeholder="'.$langs->getCurrencySymbol(
$conf->currency).
'"').
'>';
4360 print
'</div></div>'.
"\n";
4367 print
'<div class="listofinvoicetype"><div class="">';
4368 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
4369 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
4371 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
4375 $opt = $form->selectSituationInvoices((
string)
GETPOSTINT(
'originid'), $socid);
4378 print
'</div></div><div class="listofinvoicetype"><div>';
4380 $tmp =
'<input id="radio_situation_bis" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOSTINT(
'originid') ?
' checked' :
'');
4381 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4382 $tmp .=
' disabled';
4385 $text = $tmp.
'<label for="radio_situation_bis">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4387 $text .=
'<select class="flat minwidth125" id="situations" name="situations"';
4388 if ($opt == (
'<option value="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
4389 $text .=
' disabled';
4393 $text .=
'</select>';
4394 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
4396 print
'</div></div>'.
"\n";
4402 $facids = $facturestatic->list_replacable_invoices($soc->id);
4408 if (is_array($facids)) {
4409 foreach ($facids as $facparam) {
4410 $options .=
'<option value="'.$facparam [
'id'].
'"';
4411 if ($facparam[
'id'] ==
GETPOSTINT(
'fac_replacement')) {
4412 $options .=
' selected';
4414 $options .=
'>'.$facparam[
'ref'];
4415 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
4416 $options .=
'</option>';
4420 print
'<!-- replacement line -->';
4421 print
'<div class="listofinvoicetype"><div class="">';
4422 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
4423 if (!$options || $invoice_predefined->id > 0) {
4424 $tmp .=
' disabled';
4427 print
'<script type="text/javascript">
4428 jQuery(document).ready(function() {
4429 jQuery("#fac_replacement").change(function() {
4430 console.log("We change fac_replacement");
4431 jQuery("#radio_replacement").prop("checked", true);
4435 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
4436 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
4437 if (!$options || $invoice_predefined->id > 0) {
4438 $text .=
' disabled';
4442 $text .=
'<option value="-1"> </option>';
4445 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
4447 $text .=
'</select>';
4448 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
4450 print
'</div></div>'.
"\n";
4454 print
'<div class="listofinvoicetype"><div class="">';
4455 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
4456 $text = $tmp.
'<label class="opacitymedium">'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
4457 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'firstsituationonsmartphone');
4459 print
'</div></div>'.
"\n";
4462 print
'<div class="listofinvoicetype"><div class="">';
4463 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
4464 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
4465 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'nowraponall', 0, 3,
'replacementonsmartphone');
4467 print
'</div></div>'.
"\n";
4470 if (empty($origin)) {
4475 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
4482 foreach ($facids as $key => $valarray) {
4483 $newinvoice_static->id = $key;
4484 $newinvoice_static->ref = $valarray [
'ref'];
4485 $newinvoice_static->statut = $valarray [
'status'];
4486 $newinvoice_static->status = $valarray [
'status'];
4487 $newinvoice_static->type = $valarray [
'type'];
4488 $newinvoice_static->paye = $valarray [
'paye'];
4489 $newinvoice_static->paid = $valarray [
'paye'];
4490 $newinvoice_static->multicurrency_code = (
string) $valarray[
'multicurrency_code'];
4492 $optionsav .=
'<option value="'.$key.
'"';
4493 if ($key ==
GETPOST(
'fac_avoir')) {
4494 $optionsav .=
' selected';
4497 $newinvoice_static->fetch_optionals($key);
4498 $object->array_options = $newinvoice_static->array_options;
4501 $currency_code = $newinvoice_static->multicurrency_code;
4504 $optionsav .= $newinvoice_static->ref;
4505 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
4506 $optionsav .=
'</option>';
4509 print
'<div class="listofinvoicetype"><div class="">';
4510 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
4511 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
4512 $tmp .=
' disabled';
4516 print
'<script type="text/javascript">
4517 jQuery(document).ready(function() {
4518 if (jQuery("#radio_creditnote").is(":checked")) {
4519 jQuery("#radio_standard").prop("disabled", true);
4520 jQuery("#radio_deposit").prop("disabled", true);
4522 jQuery("#radio_standard").prop("disabled", false);
4523 jQuery("#radio_deposit").prop("disabled", false);
4525 if (! jQuery("#radio_creditnote").is(":checked")) {
4526 jQuery("#credit_note_options").hide();
4528 jQuery("#radio_creditnote").click(function() {
4529 jQuery("#credit_note_options").show();
4531 jQuery("#radio_standard, #radio_replacement, #radio_deposit, #radio_situation, #radio_situation_bis").click(function() {
4532 console.log("We click on a radio to close credit not options");
4533 jQuery("#credit_note_options").hide();
4537 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
4538 $text .=
'<select class="flat valignmiddle minwidth200" name="fac_avoir" id="fac_avoir"';
4539 if (!$optionsav || $invoice_predefined->id > 0) {
4540 $text .=
' disabled';
4544 $text .=
'<option value="-1">'.$langs->trans(
"InvoiceAvoirAskCombo").
'</option>';
4545 $text .= $optionsav;
4547 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
4549 $text .=
'</select>';
4550 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
4553 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
4554 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>";
4555 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>";
4560 print
'</div></div>'.
"\n";
4563 print
'<div class="listofinvoicetype"><div class="">';
4565 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
4567 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
4569 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
4571 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
4573 print
'</div></div>'.
"\n";
4594 foreach ($listtType as $type) {
4595 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
4597 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$current.
'"';
4600 print
'<script type="text/javascript">
4601 $(document).ready(function() {
4602 var listType = {'.$jsListType.
'};
4603 $("[name=\'type\']").change(function() {
4604 console.log("change name=type");
4605 if ($( this ).prop("checked"))
4607 if(($( this ).val() in listType))
4609 $("#model").val(listType[$( this ).val()]).trigger("change");
4626 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
4627 print $form->getSelectInvoiceSubtype(
GETPOSTINT(
'subtype'),
'subtype', 1, 0,
'');
4633 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
4637 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
4640 $defaulttpldir =
'/core/tpl';
4641 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array($defaulttpldir));
4642 foreach ($dirtpls as $module => $reldir) {
4644 if (!empty($module)) {
4647 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
4649 if (file_exists($tpl)) {
4650 if (empty(
$conf->file->strict_mode)) {
4651 $res = @include $tpl;
4653 $res = include $tpl;
4668 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
4669 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4670 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'', 0, 0, 0,
"add", 1, 1);
4675 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
4676 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
4677 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax', 0, 0, 0,
"add", 1, 1);
4682 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
4683 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
4684 print $form->getSelectConditionsPaiements((
int) $cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
4689 $rwStyle =
'display:none;';
4690 if (in_array(
GETPOSTINT(
'type'), $retainedWarrantyInvoiceAvailableType)) {
4694 $retained_warranty =
GETPOSTINT(
'retained_warranty');
4695 if (empty($retained_warranty)) {
4696 if ($objectsrc !==
null && property_exists($objectsrc,
'retained_warranty') && !empty($objectsrc->retained_warranty)) {
4698 $retained_warranty = $objectsrc->retained_warranty;
4701 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT');
4703 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
4704 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
4707 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
4708 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
4709 if (empty($retained_warranty_fk_cond_reglement)) {
4710 $retained_warranty_fk_cond_reglement =
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
4711 if ($objectsrc instanceOf
Facture && !empty($objectsrc->retained_warranty_fk_cond_reglement)) {
4713 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
4716 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4719 print
'<script type="text/javascript">
4720 $(document).ready(function() {
4721 $("[name=\'type\']").change(function() {
4722 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
4724 $(".retained-warranty-line").show();
4725 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
4728 $(".retained-warranty-line").hide();
4729 $("#new-situation-invoice-retained-warranty").val("");
4733 $("[name=\'type\']:checked").trigger("change");
4739 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
4740 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
4741 print $form->select_types_paiements((
string) $mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth250 widthcentpercentminusx', 1);
4746 print
'<tr><td>'.$langs->trans(
'DefaultBankAccount').
'</td><td colspan="2">';
4747 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4748 print $form->select_comptes((
int) $fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth250 widthcentpercentminusx', 1);
4754 print
'<tr><td>'.$langs->trans(
'Source').
'</td><td>';
4755 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
4756 $form->selectInputReason((
string) $inputReasonId,
'input_reason_id',
'', 1,
'maxwidth250 widthcentpercentminusx');
4759 print
'<input type="hidden" name="input_reason_id" value="'.((string) $inputReasonId).
'">';
4763 if (
isModEnabled(
'project') && is_object($formproject)) {
4764 $langs->load(
'projects');
4765 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
4766 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
4768 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');
4769 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>';
4776 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
4777 print
'<td colspan="2" class="maxwidthonsmartphone">';
4778 $incoterm_id =
GETPOST(
'incoterm_id');
4779 $location_incoterms =
GETPOST(
'location_incoterms');
4780 if (empty($incoterm_id)) {
4781 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
4782 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
4784 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
4785 print $form->select_incoterms($incoterm_id, $location_incoterms);
4799 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
4800 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
4805 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid' => $socid);
4806 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
4807 print $hookmanager->resPrint;
4808 if (empty($reshook)) {
4809 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
4812 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
4813 if ($soc->fetch_optionals() > 0) {
4814 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
4818 print
$object->showOptionals($extrafields,
'create', $parameters);
4822 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
4824 if (is_array($list) && count($list) > 0) {
4828 $paramkey =
'FACTURE_ADDON_PDF_'.$type;
4833 if (count($list) > 1) {
4834 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
4835 print
'<td colspan="2">';
4836 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
4837 print $form->selectarray(
'model', $list, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
4840 print
'<input type="hidden" name="model" value="'.$preselected.
'">';
4847 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
4848 print
'<td colspan="2" class="maxwidthonsmartphone">';
4849 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
4850 print $form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth200 widthcentpercentminusx');
4857 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
4858 if (empty($dateexample)) {
4861 $substitutionarray = array(
4862 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
4863 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
4864 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
4865 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
4866 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
4867 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
4868 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
4869 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
4870 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
4871 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
4872 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
4875 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
4876 foreach ($substitutionarray as $key => $val) {
4877 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
4879 $htmltext .=
'</i>';
4884 print
'<td class="tdtop">';
4885 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
4887 print
'<td valign="top" colspan="2">';
4888 $doleditor =
new DolEditor(
'note_public', (
string) $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
4889 print $doleditor->Create(1);
4892 if (empty($user->socid)) {
4894 print
'<td class="tdtop">';
4895 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4897 print
'<td valign="top" colspan="2">';
4898 $doleditor =
new DolEditor(
'note_private', (
string) $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4899 print $doleditor->Create(1);
4905 if (!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($classname)) {
4906 $langs->loadLangs(array(
'orders',
'propal'));
4909 if ($origin ==
'contrat') {
4910 '@phan-var-force Contrat $objectsrc';
4912 $objectsrc->update_price(1,
'auto', 1);
4915 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4916 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4917 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4918 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4923 switch (get_class($objectsrc)) {
4925 $newclassname =
'CommercialProposal';
4928 $newclassname =
'Order';
4931 $newclassname =
'Sending';
4934 $newclassname =
'Contract';
4937 $newclassname =
'Intervention';
4940 $newclassname = get_class($objectsrc);
4944 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4945 print
'<td colspan="2">';
4946 print $objectsrc->getNomUrl(1);
4948 $objectsrc->fetchObjectLinked($originid, $origin,
null,
'facture');
4949 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4951 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4955 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht, 1, $langs, 1, -1,
'',
$conf->currency).
'</td></tr>';
4956 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
4957 if (
$mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4958 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>";
4961 if (
$mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4962 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>";
4964 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc, 1, $langs, 1, -1,
'',
$conf->currency).
"</td></tr>";
4966 if (
isModEnabled(
'multicurrency') && $objectsrc->multicurrency_code !=
$conf->currency) {
4968 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
'</td></tr>';
4969 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4970 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc, 1, $langs, 1, -1,
'', $objectsrc->multicurrency_code).
"</td></tr>";
4978 print $form->buttonsSaveCancel(
"CreateDraft");
4981 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4984 $title = $langs->trans(
'ProductsAndServices');
4987 print
'<div class="div-table-responsive-no-min">';
4988 print
'<table class="noborder centpercent">';
4990 $objectsrc->printOriginLinesList(
'', $selectedLines);
4997} elseif ($id > 0 || !empty($ref)) {
4999 $langs->load(
'errors');
5000 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
5009 if ($user->socid > 0 && $user->socid !=
$object->socid) {
5013 $result =
$object->fetch_thirdparty();
5015 $result = $soc->fetch(
$object->socid);
5019 $selleruserevenustamp =
$mysoc->useRevenueStamp();
5021 $totalpaid =
$object->getSommePaiement();
5022 $totalcreditnotes =
$object->getSumCreditNotesUsed();
5023 $totaldeposits =
$object->getSumDepositsUsed();
5029 $resteapayer =
price2num(
$object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
5033 $multicurrency_totalpaid =
$object->getSommePaiement(1);
5034 $multicurrency_totalcreditnotes =
$object->getSumCreditNotesUsed(1);
5035 $multicurrency_totaldeposits =
$object->getSumDepositsUsed(1);
5036 $multicurrency_resteapayer =
price2num(
$object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
5040 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 &&
$object->multicurrency_code !=
$conf->currency) {
5041 $resteapayer =
price2num((
float) $multicurrency_resteapayer /
$object->multicurrency_tx,
'MT');
5045 if (
$object->paye ||
$object->status == $object::STATUS_CLOSED) {
5048 $resteapayeraffiche = $resteapayer;
5051 $filterabsolutediscount =
"fk_facture_source IS NULL";
5052 $filtercreditnote =
"fk_facture_source IS NOT NULL";
5054 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
5055 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
5058 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
5059 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
5060 $absolute_discount =
price2num($absolute_discount,
'MT');
5061 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
5063 $nb_creditnote_notyetavailable = $soc->getOpenCreditNotesNotYetConvertedIntoDiscount(0);
5066 if (
$object->user_creation_id) {
5067 $author->fetch(
$object->user_creation_id);
5070 $objectidnext =
$object->getIdReplacingInvoice();
5074 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
$object->picto, 0,
'',
'', 0,
'', 1);
5079 if ($action ==
'converttoreduc') {
5081 $type_fac =
'ExcessReceived';
5083 $type_fac =
'CreditNote';
5085 $type_fac =
'Deposit';
5089 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
5090 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
5091 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
5095 if ($action ==
'delete') {
5096 $text = $langs->trans(
'ConfirmDeleteBill',
$object->ref);
5097 $formquestion = array();
5100 $qualified_for_stock_change = 0;
5102 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5104 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5107 if ($qualified_for_stock_change) {
5108 $langs->load(
"stocks");
5109 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5113 if (
$conf->browser->name ==
'ie') {
5116 $formquestion = array(
5120 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
5122 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
5124 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
5127 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
5132 if ($action ==
'situationout') {
5133 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle',
$object->ref);
5134 $label = $langs->trans(
"ConfirmOuting");
5135 $formquestion = array();
5140 &&
$object->is_last_in_cycle()
5141 && $usercanunvalidate
5143 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
5148 if ($action ==
'valid') {
5150 $objectref = substr(
$object->ref, 1, 4);
5151 if ($objectref ==
'PROV') {
5155 $object->date_lim_reglement =
$object->calculate_date_lim_reglement();
5157 $numref =
$object->getNextNumRef($soc);
5163 $text = $langs->trans(
'ConfirmValidateBill', $numref);
5165 $text .=
'<br><br>';
5166 $text .=
img_picto(
'',
'warning',
'class="pictofixedwidth"').
' '.$langs->trans(
'WarningInvoiceCanNeverBeEdited');
5169 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
5172 $text .= $notify->confirmMessage(
'BILL_VALIDATE',
$object->socid, $object);
5174 $formquestion = array();
5177 $qualified_for_stock_change = 0;
5179 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5181 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5184 if ($qualified_for_stock_change) {
5185 $langs->load(
"stocks");
5186 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5187 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
5190 $warehouse_array = $warehouse->list_array();
5191 if (count($warehouse_array) == 1) {
5192 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
5193 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5196 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5198 $formquestion = array(
5204 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5208 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
5213 foreach (
$object->lines as $line) {
5214 $res = $line->fetch_product();
5216 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
5222 if ($nbMandated > 0) {
5224 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
5227 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
5232 $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);
5237 if ($action ==
'modif') {
5240 $testvalue =
$object->isEditable();
5241 if ($testvalue < 0) {
5242 switch ($testvalue) {
5245 setEventMessages($langs->trans(
"DisabledBecauseDispatchedInBookkeeping"),
null,
'errors');
5249 setEventMessages($langs->trans(
"DisabledBecauseNotLastInvoice"),
null,
'errors');
5253 setEventMessages($langs->trans(
"DisabledBecauseNotLastSituationInvoice"),
null,
'errors');
5257 setEventMessages($langs->trans(
"DisabledBecauseThereIsAPayment"),
null,
'errors');
5261 setEventMessages($langs->trans(
"DisabledBecauseAlreadySentByEmail"),
null,
'errors');
5265 setEventMessages($langs->trans(
"DisabledBecauseAlreadyPrintedOnce"),
null,
'errors');
5281 $text = $langs->trans(
'ConfirmUnvalidateBill',
$object->ref);
5282 $formquestion = array();
5285 $qualified_for_stock_change = 0;
5287 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
5289 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
5292 if ($qualified_for_stock_change) {
5293 $langs->load(
"stocks");
5294 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
5295 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
5298 $warehouse_array = $warehouse->list_array();
5299 if (count($warehouse_array) == 1) {
5300 $label =
$object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
5301 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
5304 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
5306 $formquestion = array(
5312 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
5316 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
5321 if ($action ==
'canceled') {
5325 $statusreplacement = 0;
5327 if ($objectidnext) {
5329 $facturereplacement->fetch($objectidnext);
5330 $statusreplacement = $facturereplacement->status;
5332 if ($objectidnext && $statusreplacement == 0) {
5333 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
5337 $close[1][
'code'] =
'badcustomer';
5338 $close[2][
'code'] =
'abandon';
5340 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5341 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
5343 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer",
$object->ref), $close[1][
'label'], 1);
5344 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
5347 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
5348 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
5351 $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'));
5353 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill',
$object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 300);
5358 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer ==
$object->total_ttc))) {
5359 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill',
$object->ref),
'confirm_paid',
'',
"yes", 1);
5361 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer !=
$object->total_ttc)) {
5365 $close[$i][
'code'] = $object::CLOSECODE_DISCOUNTVAT;
5367 $close[$i][
'code'] = $object::CLOSECODE_BADDEBT;
5369 $close[$i][
'code'] = $object::CLOSECODE_BANKCHARGE;
5371 $close[$i][
'code'] = $object::CLOSECODE_WITHHOLDINGTAX;
5373 $close[$i][
'code'] = $object::CLOSECODE_OTHER;
5377 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
5379 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
5381 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
5383 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
5385 $close[$i][
'label'] = $langs->trans(
"Other");
5389 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5391 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5393 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
5395 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
5397 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
5401 foreach ($close as $key => $val) {
5402 $arrayreasons[$close[$key][
'code']] =
'<span class="small">'.$close[$key][
'reason'].
'</span>';
5406 $formquestion = array(
5407 'text' => $langs->trans(
"ConfirmClassifyPaidPartiallyQuestion"),
5408 0 => array(
'type' =>
'radio',
'name' =>
'close_code',
'label' =>
'',
'values' => $arrayreasons),
5409 1 => array(
'type' =>
'text',
'name' =>
'close_note',
'moreattr' =>
'placeholder = "'.$langs->trans(
"Comment").
'"',
'value' =>
'',
'morecss' =>
'minwidth300'),
5410 2 => array(
'type' =>
'separator')
5413 $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);
5416 if ($action ==
'deletepayment') {
5417 $payment_id =
GETPOST(
'paiement_id');
5418 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
5422 if ($action ==
'ask_deleteline') {
5423 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
5427 if ($action ==
'ask_subtotal_deleteline') {
5428 $langs->load(
"subtotals");
5429 $title =
"DeleteSubtotalLine";
5430 $question =
"ConfirmDeleteSubtotalLine";
5431 if (
GETPOST(
'type') ==
'title') {
5432 $formconfirm = array(array(
'type' =>
'checkbox',
'name' =>
'deletecorrespondingsubtotalline',
'label' => $langs->trans(
"DeleteCorrespondingSubtotalLine"),
'value' => 0));
5433 $title =
"DeleteTitleLine";
5434 $question =
"ConfirmDeleteTitleLine";
5436 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&lineid='.$lineid, $langs->trans($title), $langs->trans($question),
'confirm_delete_subtotalline', $formconfirm,
'no', 1);
5440 if ($action ==
'clone') {
5441 $filter =
'(s.client:IN:1,2,3)';
5443 $formquestion = array(
5444 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
$object->socid,
'socid', $filter, 1)),
5445 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
5448 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
5452 if ($action ==
'add_title_line') {
5453 $langs->load(
'subtotals');
5455 $depth_array =
$object->getPossibleLevels($langs);
5457 } elseif ($action ==
'add_subtotal_line') {
5458 $langs->load(
'subtotals');
5460 $titles =
$object->getPossibleTitles();
5462 } elseif ($action ==
'add_text_line') {
5463 $langs->load(
'subtotals');
5468 if ($action ==
"remove_file_comfirm") {
5469 $file =
GETPOST(
'file',
'alpha');
5471 $formconfirm = $form->formconfirm(
5472 $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&file='.urlencode($file),
5473 $langs->trans(
'DeleteFileHeader'),
5474 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
5483 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
5484 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
5485 if (empty($reshook)) {
5486 $formconfirm .= $hookmanager->resPrint;
5487 } elseif ($reshook > 0) {
5488 $formconfirm = $hookmanager->resPrint;
5496 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
5498 $morehtmlref =
'<div class="refidno">';
5501 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5502 $morehtmlref .= $form->editfieldval(
"Ref",
'ref',
$object->ref, $object, (
int) $usercancreate,
'string',
'',
null,
null,
'', 1);
5503 $morehtmlref .=
'<br>';
5506 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_customer, $object, (
int) $usercancreate,
'string',
'', 0, 1);
5507 $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);
5509 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
5511 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.
$object->thirdparty->id.
'">'.$langs->trans(
"OtherBills").
'</a>)';
5515 $langs->load(
"projects");
5516 $morehtmlref .=
'<br>';
5517 if ($usercancreate) {
5518 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
5519 if ($action !=
'classify') {
5520 $morehtmlref .=
'<a class="editfielda" href="'.dolBuildUrl($_SERVER[
'PHP_SELF'], [
'action' =>
'classify',
'id' =>
$object->id],
true).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
5522 $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');
5524 if (!empty(
$object->fk_project)) {
5526 $proj->fetch(
$object->fk_project);
5527 $morehtmlref .= $proj->getNomUrl(1);
5529 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
5534 $morehtmlref .=
'</div>';
5536 $object->totalpaid = $totalpaid;
5537 $object->totalcreditnotes = $totalcreditnotes;
5538 $object->totaldeposits = $totaldeposits;
5541 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
5544 $parameters = array();
5546 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters, $object, $action);
5547 if (empty($reshook)) {
5548 print
'<div class="fichecenter">';
5549 print
'<div class="fichehalfleft">';
5550 print
'<div class="underbanner clearboth"></div>';
5552 print
'<table class="border centpercent tableforfield">';
5555 print
'<tr><td class="fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
5558 print
' '.$object->getSubtypeLabel(
'facture');
5562 $facreplaced->fetch(
$object->fk_facture_source);
5563 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
5567 $facusing->fetch(
$object->fk_facture_source);
5568 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
5572 $object->getListIdAvoirFromInvoice();
5574 if (!empty(
$object->creditnote_ids)) {
5575 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
5577 foreach (
$object->creditnote_ids as $invoiceid) {
5584 $creditnote->fetch($invoiceid);
5585 print $creditnote->getNomUrl(1,
'', 32);
5589 if ($objectidnext > 0) {
5591 $facthatreplace->fetch($objectidnext);
5592 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
5597 $result = $discount->fetch(0,
$object->id);
5599 print
' <span class="opacitymediumbycolor paddingleft">';
5600 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
5601 $s = str_replace(
'{s1}',
$object->getLibType(0), $s);
5602 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
5604 print
'</span><br>';
5608 if (
$object->fk_fac_rec_source > 0) {
5610 $result = $tmptemplate->fetch(
$object->fk_fac_rec_source);
5612 print
' <span class="opacitymediumbycolor paddingleft">';
5613 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
5614 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
5618 print
' <span class="opacitymediumbycolor paddingleft">';
5619 print $langs->transnoentities(
"GeneratedFromTemplate", $langs->trans(
"ObjectDeleted"));
5627 $langs->load(
"cashdesk");
5628 print
'<tr><td class="fieldname_type">';
5629 print
'<table class="nobordernopadding centpercent"><tr><td>';
5630 print $form->textwithpicto($langs->trans(
'PointOfSale'), $langs->trans(
'POSInfo'));
5632 if ($action !=
'editposinfo' && $usercancreate) {
5633 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>';
5635 print
'</tr></table>';
5636 print
'</td><td class="valuefield fieldname_type">';
5637 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" name="formposinfo">';
5638 print
'<input type="hidden" name="action" value="setposinfo">';
5639 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
5640 if ($action ==
'editposinfo') {
5641 print
'<input type="text" class="maxwidth150" name="posmodule" placeholder="'.$langs->trans(
"POSModule").
'" value="'.
$object->module_source.
'"> ';
5642 print
'<input type="text" class="maxwidth100" name="posterminal" placeholder="'.$langs->trans(
"Terminal").
'" value="'.
$object->pos_source.
'">';
5643 print
'<input type="submit" class="button" name="submitposinfo" value="'.$langs->trans(
"Submit").
'">';
5646 print
'<span class="opacitymediumbycolor paddingleft">'.dolPrintHTML(ucfirst(
$object->module_source).
' - '.$langs->transnoentitiesnoconv(
"Terminal").
' '.
$object->pos_source).
'</span>';
5654 print
'<!-- Discounts -->'.
"\n";
5655 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
5659 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id;
5660 $defaulttpldir =
'/core/tpl';
5662 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array($defaulttpldir));
5663 foreach ($dirtpls as $module => $reldir) {
5665 if (!empty($module)) {
5668 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/object_discounts.tpl.php';
5670 if (file_exists($tpl)) {
5671 if (empty(
$conf->file->strict_mode)) {
5672 $res = @include $tpl;
5674 $res = include $tpl;
5686 print
'<table class="nobordernopadding centpercent"><tr><td>';
5687 print $langs->trans(
'DateInvoice');
5689 if ($action !=
'editinvoicedate' &&
$object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
5690 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>';
5692 print
'</tr></table>';
5694 if ($action ==
'editinvoicedate') {
5695 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date,
'invoicedate');
5697 print
'<span class="valuedate">'.dol_print_date(
$object->date,
'day').
'</span>';
5712 print
'<table class="nobordernopadding centpercent"><tr><td>';
5713 print $langs->trans(
'DatePointOfTax');
5716 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>';
5718 print
'</tr></table>';
5720 if ($action ==
'editdate_pointoftax' && $editable) {
5721 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_pointoftax,
'date_pointoftax');
5723 print
'<span class="valuedate">'.dol_print_date(
$object->date_pointoftax,
'day').
'</span>';
5731 print $form->editfieldkey(
'Source',
'input_reason',
'', $object, (
int) $usercancreate);
5732 print
'</td><td class="valuefield">';
5733 if ($action ==
'editinput_reason') {
5734 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'input_reason_id', 1,
'maxwidth250 widthcentpercentminusx');
5736 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->demand_reason_id,
'none');
5743 print
'<table class="nobordernopadding centpercent"><tr><td>';
5744 print $langs->trans(
'PaymentConditionsShort');
5747 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>';
5749 print
'</tr></table>';
5752 if ($action ==
'editconditions') {
5753 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
5755 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
5762 print
'<table class="nobordernopadding centpercent"><tr><td>';
5763 print $langs->trans(
'DateMaxPayment');
5766 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>';
5768 print
'</tr></table>';
5771 if ($action ==
'editpaymentterm') {
5772 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id,
$object->date_lim_reglement,
'paymentterm');
5774 print
'<span class="valuedate">'.dol_print_date(
$object->date_lim_reglement,
'day').
'</span>';
5784 print
'<table class="nobordernopadding centpercent"><tr><td>';
5785 print $langs->trans(
'PaymentMode');
5787 if ($action !=
'editmode' && $usercancreate) {
5788 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>';
5790 print
'</tr></table>';
5792 if ($action ==
'editmode') {
5793 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
5795 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->mode_reglement_id,
'none',
'CRDT');
5801 print
'<tr><td class="nowrap">';
5802 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
5803 print $langs->trans(
'DefaultBankAccount');
5805 if (($action !=
'editbankaccount') && $usercancreate) {
5806 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>';
5808 print
'</tr></table>';
5810 if ($action ==
'editbankaccount') {
5811 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
5813 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
5822 print
'<table class="nobordernopadding centpercent"><tr><td>';
5823 print $langs->trans(
'IncotermLabel');
5824 print
'<td><td class="right">';
5825 if ($usercancreate) {
5826 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
5828 print
'</td></tr></table>';
5831 if ($action !=
'editincoterm') {
5832 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
5834 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
5841 print
'<table class="nobordernopadding centpercent"><tr><td>';
5842 print $langs->trans(
'Dispute');
5843 print
'<td><td class="right">';
5844 if ($usercancreate) {
5845 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=editdispute_status&token='.
newToken().
'">'.
img_edit().
'</a>';
5847 print
'</td></tr></table>';
5849 $liststatus = Facture::ARRAY_OF_DISPUTE_STATUS;
5850 if ($action !=
'editdispute_status') {
5851 if (
$object->dispute_status) {
5852 print $langs->trans($liststatus[
$object->dispute_status][
'label']);
5855 print
'<form enctype="multipart/form-data" action="'.DOL_URL_ROOT.
'/compta/facture/card.php" method="POST">';
5856 print
'<input type="hidden" name="action" value="set_dispute_status">';
5857 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5858 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
5859 print
'<input type="hidden" name="page_y" value="">';
5860 print $form->selectarray(
'dispute_status', $liststatus,
$object->dispute_status, 0, 0, 0,
'', 1);
5861 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Save").
'">';
5869 print
'<table class="nobordernopadding centpercent"><tr><td>';
5870 print $langs->trans(
"Categories");
5871 print
'<td><td class="right">';
5872 if ($usercancreate) {
5873 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
5877 print
'</td></tr></table>';
5880 if ($action ==
'edittags') {
5881 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5882 print
'<input type="hidden" name="action" value="settags">';
5883 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5884 print $form->selectCategories(Categorie::TYPE_INVOICE,
'categories', $object);
5885 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5888 print $form->showCategories(
$object->id, Categorie::TYPE_INVOICE, 1);
5893 $displayWarranty =
false;
5896 $displayWarranty =
true;
5897 if (!in_array(
$object->type, $retainedWarrantyInvoiceAvailableType) && empty(
$object->retained_warranty)) {
5898 $displayWarranty =
false;
5901 if ($displayWarranty) {
5903 print
'<tr class="retained-warranty-lines" ><td>';
5904 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
5905 print $langs->trans(
'RetainedWarranty');
5908 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>';
5911 print
'</tr></table>';
5914 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5915 print
'<input type="hidden" name="action" value="setretainedwarranty">';
5916 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5917 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5918 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
5919 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5927 print
'<tr class="retained-warranty-lines" ><td>';
5928 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
5929 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
5931 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') &&
$object->status ==
Facture::STATUS_DRAFT) {
5932 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>';
5935 print
'</tr></table>';
5937 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5938 if (
$object->date > $defaultDate) {
5944 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5945 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
5946 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5947 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5948 $retained_warranty_fk_cond_reglement =
GETPOSTINT(
'retained_warranty_fk_cond_reglement');
5949 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
$object->retained_warranty_fk_cond_reglement;
5950 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement :
getDolGlobalString(
'INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID');
5951 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
5952 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5955 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id, (
string)
$object->retained_warranty_fk_cond_reglement,
'none');
5956 if (!$displayWarranty) {
5957 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning',
'class="pictowarning valignmiddle" ');
5963 print
'<tr class="retained-warranty-lines" ><td>';
5964 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
5965 print $langs->trans(
'RetainedWarrantyDateLimit');
5968 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>';
5971 print
'</tr></table>';
5973 $defaultDate = !empty(
$object->retained_warranty_date_limit) ?
$object->retained_warranty_date_limit : strtotime(
'-1 years',
$object->date_lim_reglement);
5974 if (
$object->date > $defaultDate) {
5979 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'">';
5980 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
5981 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5982 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5984 print $form->selectDate($defaultDate,
'retained_warranty_date_limit');
5985 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5997 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
6002 print
'<div class="fichehalfright">';
6004 print
'<!-- amounts -->'.
"\n";
6005 print
'<div class="underbanner clearboth"></div>'.
"\n";
6007 print
'<table class="border tableforfield centpercent">';
6009 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
6017 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
6018 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
6021 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
6027 print
'<td>' . $langs->trans(
'AmountVAT') .
'</td>';
6028 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
6031 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
6036 if ((
$mysoc->localtax1_assuj ==
"1" &&
$mysoc->useLocalTax(1)) ||
$object->total_localtax1 != 0) {
6038 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1",
$mysoc->country_code) .
'</td>';
6039 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
6043 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
6048 if ((
$mysoc->localtax2_assuj ==
"1" &&
$mysoc->useLocalTax(2)) ||
$object->total_localtax2 != 0) {
6050 print
'<td>' . $langs->transcountry(
"AmountLT2",
$mysoc->country_code) .
'</td>';
6051 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
6055 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
6061 if ($selleruserevenustamp) {
6062 print
'<tr><td class="titlefieldmiddle">';
6063 print
'<table class="nobordernopadding centpercent"><tr><td>';
6064 print $langs->trans(
'RevenueStamp');
6066 if ($action !=
'editrevenuestamp' &&
$object->status == $object::STATUS_DRAFT && $usercancreate) {
6067 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>';
6069 print
'</tr></table>';
6070 print
'</td><td class="nowrap amountcard right">';
6071 if ($action ==
'editrevenuestamp') {
6072 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
6073 print
'<input type="hidden" name="token" value="'.newToken().
'">';
6074 print
'<input type="hidden" name="action" value="setrevenuestamp">';
6075 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num(
$object->revenuestamp).
'">';
6076 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
6077 print $formother->select_revenue_stamp(
'',
'revenuestamp_type',
$mysoc->country_code);
6078 print
' → <span id="revenuestamp_span"></span>';
6079 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
6082 $(document).ready(function(){
6083 js_recalculate_revenuestamp();
6084 $('select[name=revenuestamp_type]').on('change',function(){
6085 js_recalculate_revenuestamp();
6088 function js_recalculate_revenuestamp(){
6089 var valselected = $('select[name=revenuestamp_type]').val();
6090 console.log('Calculate revenue stamp from '+valselected);
6092 if (valselected.indexOf('%') == -1)
6094 revenue = valselected;
6098 var revenue_type = parseFloat(valselected);
6099 var amount_net = ".round(
$object->total_ht, 2).
";
6100 revenue = revenue_type * amount_net / 100;
6101 revenue = revenue.toFixed(2);
6103 $('#revenuestamp_val').val(revenue);
6104 $('#revenuestamp_span').html(revenue);
6115 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
6116 print
'<td class="nowraponall amountcard right">' .
price($sign *
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
6119 print
'<td class="nowrap amountcard right">' .
price($sign *
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
6134 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
6137 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
6140 if ($selleruserevenustamp) {
6150 $total_prev_ht = $total_prev_ttc = 0;
6151 $total_global_ht = $total_global_ttc = 0;
6155 print
'<!-- List of situation invoices -->';
6156 print
'<div class="div-table-responsive-no-min">';
6157 print
'<table class="noborder paymenttable centpercent situationstable">';
6159 print
'<tr class="liste_titre">';
6160 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
6162 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
6165 print
'<td class="right"></td>';
6167 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
6168 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
6169 print
'<td width="18"> </td>';
6172 if (count(
$object->tab_previous_situation_invoice) > 0) {
6175 $current_situation_counter = array();
6176 foreach (
$object->tab_previous_situation_invoice as $prev_invoice) {
6177 $tmptotalallpayments = $prev_invoice->getSommePaiement(0);
6178 $tmptotalallpayments += $prev_invoice->getSumDepositsUsed(0);
6179 $tmptotalallpayments += $prev_invoice->getSumCreditNotesUsed(0);
6181 $total_prev_ht += $prev_invoice->total_ht;
6182 $total_prev_ttc += $prev_invoice->total_ttc;
6184 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
6185 print
'<tr class="oddeven">';
6186 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
6188 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
6190 print
'<td class="right"></td>';
6192 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
6193 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
6194 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalallpayments).
'</td>';
6199 $totalallpayments =
$object->getSommePaiement(0);
6200 $totalallpayments +=
$object->getSumCreditNotesUsed(0);
6201 $totalallpayments +=
$object->getSumDepositsUsed(0);
6203 $total_global_ht += $total_prev_ht;
6204 $total_global_ttc += $total_prev_ttc;
6205 $total_global_ht +=
$object->total_ht;
6206 $total_global_ttc +=
$object->total_ttc;
6210 print
'<tr class="oddeven">';
6211 print
'<td>'.$object->getNomUrl(1).
'</td>';
6213 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).
$object->situation_counter.
'</td>';
6215 print
'<td class="right"></td>';
6217 print
'<td class="right"><span class="amount">'.price(
$object->total_ht).
'</span></td>';
6218 print
'<td class="right"><span class="amount">'.price(
$object->total_ttc).
'</span></td>';
6219 print
'<td class="right">'.$object->getLibStatut(3, $totalallpayments).
'</td>';
6223 print
'<tr class="oddeven">';
6224 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'SituationTotalAfterInvoice').
'</b></td>';
6227 foreach ($current_situation_counter as $sit) {
6228 $curSign = $sit > 0 ?
'+' :
'-';
6229 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
6231 print
' '.$curSign.
' ';
6233 print $curType.abs($sit);
6240 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6241 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6242 print
'<td width="18"> </td>';
6246 if (count(
$object->tab_next_situation_invoice) > 0) {
6248 $total_next_ht = $total_next_ttc = 0;
6250 foreach (
$object->tab_next_situation_invoice as $next_invoice) {
6251 $next_totalpaid = $next_invoice->getSommePaiement(0);
6252 $next_totalcreditnotes = $next_invoice->getSumCreditNotesUsed(0);
6253 $next_totaldeposits = $next_invoice->getSumDepositsUsed(0);
6254 $total_next_ht += $next_invoice->total_ht;
6255 $total_next_ttc += $next_invoice->total_ttc;
6257 print
'<tr class="oddeven">';
6258 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
6260 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
6262 print
'<td class="right"></td>';
6264 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
6265 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
6266 print
'<td class="right">'.$next_invoice->getLibStatut(3, $next_totalpaid + $next_totalcreditnotes + $next_totaldeposits).
'</td>';
6270 $total_global_ht += $total_next_ht;
6271 $total_global_ttc += $total_next_ttc;
6273 print
'<tr class="oddeven">';
6274 print
'<td colspan="3" class="right"></td>';
6276 print
'<td class="right"></td>';
6278 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
6279 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
6280 print
'<td width="18"> </td>';
6289 if (
$object->type == $object::TYPE_CREDIT_NOTE) {
6295 print
'<!-- List of payments already done -->';
6296 print
'<div class="div-table-responsive-no-min">';
6297 print
'<table class="noborder paymenttable centpercent">';
6299 print
'<tr class="liste_titre">';
6300 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
6301 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
6302 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
6304 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
6306 print
'<td class="liste_titre"></td>';
6307 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
6311 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
6312 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
6313 $sql .=
' pf.amount,';
6314 $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';
6315 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
6316 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
6317 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
6318 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
6319 $sql .=
' WHERE pf.fk_facture = '.((int)
$object->id).
' AND pf.fk_paiement = p.rowid';
6320 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
6321 $sql .=
' ORDER BY p.datep, p.tms';
6323 $result =
$db->query($sql);
6325 $num =
$db->num_rows($result);
6330 $objp =
$db->fetch_object($result);
6332 $paymentstatic->id = $objp->rowid;
6333 $paymentstatic->datepaye =
$db->jdate($objp->dp);
6334 $paymentstatic->ref = $objp->ref;
6335 $paymentstatic->num_payment = $objp->num_payment;
6336 $paymentstatic->paiementcode = $objp->payment_code;
6338 print
'<tr class="oddeven">';
6339 print
'<td class="nowraponall">';
6340 print $paymentstatic->getNomUrl(1);
6343 $dateofpayment =
$db->jdate($objp->dp);
6345 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
6352 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
6353 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
6355 $bankaccountstatic->id = $objp->baid;
6356 $bankaccountstatic->ref = $objp->baref;
6357 $bankaccountstatic->label = $objp->baref;
6358 $bankaccountstatic->number = $objp->banumber;
6359 $bankaccountstatic->currency_code = $objp->bacurrency_code;
6362 $bankaccountstatic->account_number = $objp->account_number;
6365 $accountingjournal->fetch($objp->fk_accountancy_journal);
6366 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
6369 print
'<td class="nowraponall">';
6370 if ($bankaccountstatic->id) {
6371 print $bankaccountstatic->getNomUrl(1,
'transactions');
6377 print
'<td class="center">';
6379 $paiement->fetch($objp->rowid);
6381 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
6388 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
6403 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6404 print
'<span class="opacitymedium">';
6406 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
6408 print $langs->trans(
'AlreadyPaid');
6410 print
'</span></td>';
6412 print
'<td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td>';
6415 $resteapayeraffiche = $resteapayer;
6416 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
6417 $cssforamountpaymentcompletenoresize =
'amountpaymentcompletenoresize';
6420 $creditnoteamount = 0;
6422 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
6423 $sql .=
" re.description, re.fk_facture_source";
6424 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
6425 $sql .=
" WHERE fk_facture = ".((int)
$object->id);
6426 $resql =
$db->query($sql);
6428 $num =
$db->num_rows($resql);
6432 $obj =
$db->fetch_object($resql);
6433 $invoice->fetch($obj->fk_facture_source);
6435 print
'<td colspan="'.$nbcols.
'" class="right">';
6436 print
'<span class="opacitymedium">';
6438 print $langs->trans(
"CreditNote").
' ';
6441 print $langs->trans(
"Deposit").
' ';
6443 print $invoice->getNomUrl(0);
6447 print
'<td class="right">';
6448 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
6449 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
6453 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
6457 $creditnoteamount += $obj->amount_ttc;
6460 $depositamount += $obj->amount_ttc;
6470 print
'<td colspan="'.$nbcols.
'" class="nowrap right">';
6471 print
'<span class="opacitymedium">';
6472 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
6476 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6478 $resteapayeraffiche = 0;
6479 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6480 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6485 print
'<td colspan="'.($nbcols + 1).
'" class="nowrap right">';
6486 print
'<span class="opacitymedium">';
6487 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
6491 print
'<td class="right">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td>';
6494 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6495 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6500 print
'<td colspan="'.($nbcols + 1).
'" class="nowrap right">';
6501 print
'<span class="opacitymedium">';
6502 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
6506 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6508 $resteapayeraffiche = 0;
6509 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6510 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6515 print
'<td colspan="'.($nbcols + 1).
'" class="nowrap right">';
6516 $text = $langs->trans(
"HelpAbandonOther");
6518 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.
$object->close_note;
6520 print
'<span class="opacitymedium">';
6522 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
6526 print
'<td class="right"><span class="amount">'.price(
price2num(
$object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td>';
6528 $resteapayeraffiche = 0;
6529 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6530 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6535 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6536 print
'<span class="opacitymedium">';
6537 print $langs->trans(
"Billed");
6540 print
'<td class="right">'.price(
$object->total_ttc).
'</td>';
6545 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6546 print
'<span class="opacitymedium">';
6547 print $langs->trans(
'RemainderToPay');
6548 if ($resteapayeraffiche < 0) {
6549 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6554 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
6560 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6561 print
'<span class="opacitymedium">';
6562 print $langs->trans(
'RemainderToPayMulticurrency');
6563 if ($resteapayeraffiche < 0) {
6564 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
6569 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopaynoresize' : (
' '.$cssforamountpaymentcompletenoresize)).
'">';
6576 if (!empty(
$object->situation_final) && !empty(
$object->retained_warranty) && $displayWarranty) {
6578 if (
$object->isSituationInvoice()) {
6579 $retainedWarranty = $total_global_ttc *
$object->retained_warranty / 100;
6582 $retainedWarranty =
$object->total_ttc *
$object->retained_warranty / 100;
6585 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
6588 print
'<td colspan="'.($nbcols + 1).
'" class="right">'.$langs->trans(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')).
' :</td>';
6590 print
'<td class="right">'.price($billedWithRetainedWarranty).
'</td>';
6595 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6596 print $langs->trans(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
6597 print !empty(
$object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
6600 print
'<td class="right">'.price($retainedWarranty).
'</td>';
6604 $resteapayeraffiche = $resteapayer;
6605 $cssforamountpaymentcomplete =
'amountpaymentneutral';
6606 $cssforamountpaymentcompletenoresize =
'amountpaymentneutralnoresize';
6610 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6611 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
6614 print
'<td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td>';
6619 print
'<td colspan="'.($nbcols + 1).
'" class="right"><span class="opacitymedium">'.$langs->trans(
"Billed").
'</span></td>';
6621 print
'<td class="right">'.price($sign *
$object->total_ttc).
'</td>';
6625 print
'<tr><td colspan="'.($nbcols + 1).
'" class="right">';
6626 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
6627 if ($resteapayeraffiche > 0) {
6628 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6630 print
'</span></td>';
6632 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche);
6641 print
'<td colspan="'.($nbcols + 1).
'" class="right">';
6642 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
6643 if ($resteapayeraffiche > 0) {
6644 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
6649 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>';
6664 $formmargin->displayMarginInfos($object);
6670 print
'<div class="clearboth"></div><br>';
6673 $blocname =
'contacts';
6674 $title = $langs->trans(
'ContactsAddresses');
6675 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6679 $blocname =
'notes';
6680 $title = $langs->trans(
'Notes');
6681 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
6685 $result =
$object->getLinesArray();
6689 global $inputalsopricewithtax;
6690 $inputalsopricewithtax = 1;
6695 print
'<!-- Area to change globally the situation percent -->'.
"\n";
6696 print
'<div class="div-table-responsive-no-min">';
6698 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'#updatealllines" method="POST">';
6699 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
6700 print
'<input type="hidden" name="action" value="updatealllines" />';
6701 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
6702 print
'<input type="hidden" name="page_y" value="" />';
6703 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
6705 print
'<table id="tablelines_all_progress" class="noborder noshadow centpercent">';
6707 print
'<tr class="liste_titre nodrag nodrop">';
6711 print
'<td align="center" width="5"> </td>';
6713 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
6714 print
'<td class="right">'.$langs->trans(
'CumulativeProgression').
'</td>';
6715 print
'<td> </td>';
6718 print
'<tr class="nodrag nodrop">';
6721 print
'<td align="center" width="5"> </td>';
6723 print
'<td> </td>';
6724 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
6725 print
'<td class="right"><input type="submit" class="button reposition small" name="all_percent" value="'.$langs->trans(
"Modify").
'" /></td>';
6736 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
6737 <input type="hidden" name="token" value="' .
newToken().
'">
6738 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
6739 <input type="hidden" name="mode" value="">
6740 <input type="hidden" name="page_y" value="">
6741 <input type="hidden" name="id" value="' .
$object->id.
'">
6742 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
6745 if (!empty(
$conf->use_javascript_ajax) &&
$object->status == 0) {
6747 include DOL_DOCUMENT_ROOT.
'/core/tpl/subtotal_ajaxrow.tpl.php';
6749 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
6753 print
'<div class="div-table-responsive-no-min">';
6754 print
'<table id="tablelines" class="noborder noshadow centpercent nomarginbottom">';
6758 $object->printObjectLines($action,
$mysoc, $soc, $lineid, 1);
6762 if (
$object->status == 0 && $usercancreate && $action !=
'valid') {
6763 if ($action !=
'editline' && $action !=
'selectlines') {
6766 $parameters = array();
6767 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
6771 if (empty($reshook)) {
6775 $parameters = array();
6776 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters, $object, $action);
6790 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
6791 print
'<div class="tabsAction">';
6793 $parameters = array();
6794 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
6795 if (empty($reshook)) {
6798 'class' =>
'classfortooltip',
6805 $ventilExportCompta =
$object->getVentilExportCompta();
6807 if ($ventilExportCompta == 0) {
6809 if (!$objectidnext &&
$object->is_last_in_cycle()) {
6810 if ($usercanunvalidate) {
6811 unset($params[
'attr'][
'title']);
6812 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
true, $params);
6814 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
6815 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?facid=' .
$object->id .
'&action=modif&token=' .
newToken(),
'',
false, $params);
6817 } elseif (!
$object->is_last_in_cycle()) {
6818 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
6819 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6821 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
6822 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6826 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
6827 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
6832 $result = $discount->fetch(0,
$object->id);
6840 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
6841 if (
$object->close_code !=
'replaced' || (!$objectidnext)) {
6842 unset($params[
'attr'][
'title']);
6843 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
6845 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6846 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
6853 $langs->load(
"contracts");
6855 if ($usercancreatecontract) {
6856 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>';
6864 $langs->load(
"subtotals");
6866 $url_button = array();
6868 $url_button[] = array(
6869 'lang' =>
'subtotals',
6871 'perm' => (
bool) $usercancreate,
6872 'label' => $langs->trans(
'AddTitleLine'),
6873 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_title_line&token='.
newToken()
6876 $url_button[] = array(
6877 'lang' =>
'subtotals',
6879 'perm' => (
bool) $usercancreate,
6880 'label' => $langs->trans(
'AddSubtotalLine'),
6881 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_subtotal_line&token='.
newToken()
6884 $url_button[] = array(
6885 'lang' =>
'subtotals',
6887 'perm' => (
bool) $usercancreate,
6888 'label' => $langs->trans(
'AddTextLine'),
6889 'url' =>
'/compta/facture/card.php?facid='.$object->id.
'&action=add_text_line&token='.
newToken()
6891 print
dolGetButtonAction(
'', $langs->trans(
'SubTotal'),
'default', $url_button,
'',
true);
6898 if ($usercanvalidate) {
6899 unset($params[
'attr'][
'title']);
6900 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
6905 if (empty($user->socid)) {
6907 if ($objectidnext) {
6908 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
6909 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
6912 unset($params[
'attr'][
'title']);
6913 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
6915 unset($params[
'attr'][
'title']);
6916 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
'#',
'',
false, $params);
6924 if ($resteapayer > 0) {
6925 if ($usercancreatewithdrarequest) {
6926 if (!$objectidnext &&
$object->close_code !=
'replaced') {
6927 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>';
6929 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
6941 $langs->load(
"cashdesk");
6942 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
6943 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int)
$object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
6948 if ($objectidnext) {
6949 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
6953 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
6954 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
6958 unset($params[
'attr'][
'title']);
6959 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);
6964 $sumofpayment = $totalpaid;
6965 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
6971 if ($resteapayer == 0) {
6972 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
6974 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.
$object->id.
'&action=create&accountid='.
$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
6980 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
6984 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) &&
$object->total_ht < 0
6986 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>';
6993 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=converttoreduc&token='.
newToken().
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
6995 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
7009 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
7010 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
7012 unset($params[
'attr'][
'title']);
7013 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken(),
'',
true, $params);
7019 if ($totalpaid > 0 || $totalcreditnotes > 0) {
7021 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=paid&token='.
newToken().
'">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
7024 if ($objectidnext) {
7025 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
7027 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=canceled&token='.
newToken().
'">'.$langs->trans(
'ClassifyCanceled').
'</a>';
7034 if ($usercancreate &&
$object->isSituationInvoice() && (
$object->status == 1 ||
$object->status == 2)) {
7035 if (
$object->is_last_in_cycle() &&
$object->situation_final != 1) {
7036 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.
$object->id.
'&socid='.
$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
7037 } elseif (!
$object->is_last_in_cycle()) {
7038 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
7040 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
7046 if (!$objectidnext) {
7047 print
'<!-- button create credit note -->';
7048 if (
$object->module_source ==
'takepos') {
7049 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseInvoiceGeneratedBy", $langs->transnoentitiesnoconv(
'TakePOS')).
'">'.$langs->trans(
"CreateCreditNote").
'</a>';
7051 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>';
7058 &&
$object->isSituationInvoice()
7061 &&
$object->is_last_in_cycle()
7064 if ($usercanunvalidate) {
7065 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>';
7067 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
7073 if (!$objectidnext && count(
$object->lines) > 0) {
7074 unset($params[
'attr'][
'title']);
7075 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.
$object->id.
'&action=create',
'',
true, $params);
7081 unset($params[
'attr'][
'title']);
7082 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'clone', $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=clone&object=invoice&token='.
newToken(),
'',
true, $params);
7087 &&
$object->isSituationInvoice()
7090 &&
$object->situation_counter > 1
7091 &&
$object->is_last_in_cycle()
7092 && $usercanunvalidate
7095 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&action=situationout&token='.
newToken().
'">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
7097 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
7102 $isErasable =
$object->is_erasable();
7105 if ($isErasable == -6) {
7106 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadySentByEmail');
7107 } elseif ($isErasable == -5) {
7108 $htmltooltip = $langs->trans(
'DisabledBecauseAlreadyPrintedOnce');
7109 } elseif ($isErasable == -4) {
7110 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
7111 } elseif ($isErasable == -3) {
7112 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
7113 } elseif ($isErasable == -2) {
7114 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
7115 } elseif ($isErasable == -1) {
7116 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
7117 } elseif ($isErasable <= 0) {
7118 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable').(empty(
$object->error) ?
': UnknownReason' :
': '.$object->error);
7119 } elseif ($objectidnext) {
7120 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
7122 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
7123 $enableDelete =
false;
7125 if ($isErasable > 0 && ! $objectidnext) {
7126 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.
$object->id.
'&action=delete&token='.
newToken();
7127 $enableDelete =
true;
7129 unset($params[
'attr'][
'title']);
7130 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
7132 unset($params[
'attr'][
'title']);
7133 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
7140 if (
GETPOST(
'modelselected',
'alpha')) {
7141 $action =
'presend';
7143 if ($action !=
'prerelance' && $action !=
'presend') {
7144 print
'<div class="fichecenter"><div class="fichehalfleft">';
7145 print
'<a name="builddoc"></a>';
7150 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.
$object->id;
7151 $genallowed = $usercanread;
7152 $delallowed = $usercancreate;
7153 $tooltipAfterComboOfModels =
'';
7155 $tooltipAfterComboOfModels = $langs->trans(
"AccordingToYourSetupTheFileWillBeConcatenated",
getDolGlobalString(
'MAIN_INFO_INVOICE_TERMSOFSALE'));
7158 print $formfile->showdocuments(
7178 'remove_file_comfirm',
7179 $tooltipAfterComboOfModels
7182 $somethingshown = $formfile->numoffiles;
7185 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'invoice'), 1);
7186 $linktoelem = $tmparray[
'linktoelem'];
7187 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
7188 print $htmltoenteralink;
7190 $compatibleImportElementsList =
false;
7194 $compatibleImportElementsList = array(
'commande',
'propal',
'subscription');
7196 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
7200 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
7201 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
7202 $useonlinepayment = count($validpaymentmethod);
7205 print
'<br><!-- Link to pay -->'.
"\n";
7206 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
7207 print showOnlinePaymentUrl(
'invoice',
$object->ref).
'<br>';
7210 print
'</div><div class="fichehalfright">';
7214 $morehtmlcenter =
'<div class="nowraponall">';
7215 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullConversation'),
'',
'fa fa-comments imgforviewmode', DOL_URL_ROOT.
'/compta/facture/messaging.php?id='.
$object->id);
7216 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.
$object->id);
7217 $morehtmlcenter .=
'</div>';
7220 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
7222 $somethingshown = $formactions->showactions($object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
7224 print
'</div></div>';
7229 $modelmail =
'facture_send';
7230 $defaulttopic =
'SendBillRef';
7232 $trackid =
'inv'.$object->id;
7234 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage bank accounts.
Class to manage accounting journals.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_DRAFT
Draft status.
const TYPE_STANDARD
Standard invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_PROFORMA
Proforma invoice (should not be used.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_DEPOSIT
Deposit invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const TYPE_CREDIT_NOTE
Credit note invoice.
const STATUS_CLOSED
Classified paid.
Class to manage invoice lines.
Class to manage invoice templates.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage the table of subscription to notifications.
Class to manage payments of customer invoices.
Class ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage VAT - Value-added tax (also known in French as TVA)
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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.
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.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
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.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $notused, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $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.