41 require
'../../main.inc.php';
42 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
48 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
49 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
51 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
52 require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
53 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
54 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
55 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
58 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
61 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
62 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
64 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
67 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
70 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
74 $langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
76 $langs->load(
'incoterm');
79 $langs->load(
'margins');
85 $socid =
GETPOST(
'socid',
'int');
86 $action =
GETPOST(
'action',
'aZ09');
87 $confirm =
GETPOST(
'confirm',
'alpha');
88 $cancel =
GETPOST(
'cancel',
'alpha');
89 $lineid =
GETPOST(
'lineid',
'int');
90 $userid =
GETPOST(
'userid',
'int');
91 $search_ref =
GETPOST(
'sf_ref',
'alpha') ?
GETPOST(
'sf_ref',
'alpha') :
GETPOST(
'search_ref',
'alpha');
92 $search_societe =
GETPOST(
'search_societe',
'alpha');
93 $search_montant_ht =
GETPOST(
'search_montant_ht',
'alpha');
94 $search_montant_ttc =
GETPOST(
'search_montant_ttc',
'alpha');
95 $origin =
GETPOST(
'origin',
'alpha');
97 $fac_rec =
GETPOST(
'fac_rec',
'int');
98 $facid =
GETPOST(
'facid',
'int');
99 $ref_client =
GETPOST(
'ref_client',
'int');
100 $rank = (
GETPOST(
'rank',
'int') > 0) ?
GETPOST(
'rank',
'int') : -1;
101 $projectid = (
GETPOST(
'projectid',
'int') ?
GETPOST(
'projectid',
'int') : 0);
104 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
105 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
106 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
111 $usehm = (!empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : 0);
117 $extrafields->fetch_name_optionals_label($object->table_element);
120 if ($id > 0 || !empty($ref)) {
121 if ($action !=
'add') {
122 if (empty($conf->global->INVOICE_USE_SITUATION)) {
123 $fetch_situation =
false;
125 $fetch_situation =
true;
127 $ret = $object->fetch($id, $ref,
'',
'', $fetch_situation);
128 if ($ret > 0 && isset($object->fk_project)) {
129 $ret = $object->fetch_project();
135 $hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
138 $usercanread = $user->hasRight(
"facture",
"lire");
139 $usercancreate = $user->hasRight(
"facture",
"creer");
140 $usercanissuepayment = $user->hasRight(
"facture",
"paiement");
141 $usercandelete = $user->hasRight(
"facture",
"supprimer");
142 $usercancreatecontract = $user->hasRight(
"contrat",
"creer");
145 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->validate)));
146 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->send)));
147 $usercanreopen = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->reopen)));
148 if (!empty($conf->global->INVOICE_DISALLOW_REOPEN)) {
149 $usercanreopen =
false;
151 $usercanunvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->unvalidate)));
153 $usermustrespectpricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
154 $usercancreatemargin = (!empty($user->rights->margins->creer) ? $user->rights->margins->creer : 0);
155 $usercanreadallmargin = (!empty($user->rights->margins->liretous) ? $user->rights->margins->liretous : 0);
156 $usercancreatewithdrarequest = (!empty($user->rights->prelevement->bons->creer) ? $user->rights->prelevement->bons->creer : 0);
158 $permissionnote = $usercancreate;
159 $permissiondellink = $usercancreate;
160 $permissiontoedit = $usercancreate;
161 $permissiontoadd = $usercancreate;
164 $retainedWarrantyInvoiceAvailableType = array();
165 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
166 $retainedWarrantyInvoiceAvailableType = explode(
'+', $conf->global->INVOICE_USE_RETAINED_WARRANTY);
171 $socid = $user->socid;
175 $result =
restrictedArea($user,
'facture', $object->id,
'',
'',
'fk_soc',
'rowid', $isdraft);
183 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
188 if (empty($reshook)) {
189 $backurlforlist = DOL_URL_ROOT.
'/compta/facture/list.php';
191 if (empty($backtopage) || ($cancel && empty($id))) {
192 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
193 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
194 $backtopage = $backurlforlist;
196 $backtopage = DOL_URL_ROOT.
'/compta/facture/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
202 if (!empty($backtopageforcancel)) {
203 header(
"Location: ".$backtopageforcancel);
205 } elseif (!empty($backtopage)) {
206 header(
"Location: ".$backtopage);
212 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
214 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
216 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
219 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
223 $objectutil->socid = $socid;
224 $result = $objectutil->createFromClone($user, $id);
226 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?facid='.$result);
229 $langs->load(
"errors");
233 } elseif ($action ==
'reopen' && $usercanreopen) {
234 $result = $object->fetch($id);
237 $result = $object->setUnpaid($user);
239 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
245 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
247 $result = $object->fetch($id);
248 $object->fetch_thirdparty();
250 $idwarehouse =
GETPOST(
'idwarehouse');
252 $qualified_for_stock_change = 0;
253 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
254 $qualified_for_stock_change = $object->hasProductsOrServices(2);
256 $qualified_for_stock_change = $object->hasProductsOrServices(1);
259 $isErasable = $object->is_erasable();
261 if (($usercandelete && $isErasable > 0)
262 || ($usercancreate && $isErasable == 1)) {
263 $result = $object->delete($user, 0, $idwarehouse);
265 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
272 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
275 $object->fetch_thirdparty();
277 $result = $object->deleteline(
GETPOST(
'lineid',
'int'));
280 $object->line_order(
true);
282 $outputlangs = $langs;
288 $newlang = $object->thirdparty->default_lang;
290 if (!empty($newlang)) {
292 $outputlangs->setDefaultLang($newlang);
293 $outputlangs->load(
'products');
295 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
296 $ret = $object->fetch($id);
297 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
300 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
307 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
310 $result = $discount->fetch(
GETPOST(
"discountid"));
311 $discount->unlink_invoice();
312 } elseif ($action ==
'valid' && $usercancreate) {
316 if (!empty($conf->global-> INVOICE_CHECK_POSTERIOR_DATE)) {
317 $last_of_type = $object->willBeLastOfSameType(
true);
318 if (empty($object->date_validation) && !$last_of_type[0]) {
327 if ($object->total_ht >= 0) {
328 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
336 if (empty($conf->global->FACTURE_ENABLE_NEGATIVE) && $object->total_ttc < 0) {
337 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
346 $array_of_total_ht_per_vat_rate = array();
347 $array_of_total_ht_devise_per_vat_rate = array();
348 foreach ($object->lines as $line) {
350 $vat_src_code_for_line =
'';
351 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
352 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
354 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
355 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
357 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
358 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
362 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
363 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
364 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
366 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
367 if ($object->type == $object::TYPE_DEPOSIT) {
368 $langs->load(
"errors");
370 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
374 $tmpvatratetoshow = explode(
'_', $vatrate);
375 $tmpvatratetoshow[0] = round($tmpvatratetoshow[0], 2);
377 if ($tmpvatratetoshow[0] != 0) {
378 $langs->load(
"errors");
379 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", $tmpvatratetoshow[0]),
null,
'errors');
387 } elseif ($action ==
'classin' && $usercancreate) {
389 $object->setProject(
GETPOST(
'projectid',
'int'));
390 } elseif ($action ==
'setmode' && $usercancreate) {
392 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
396 } elseif ($action ==
'setretainedwarrantyconditions' && $user->rights->facture->creer) {
398 $object->retained_warranty_fk_cond_reglement = 0;
399 $result = $object->setRetainedWarrantyPaymentTerms(
GETPOST(
'retained_warranty_fk_cond_reglement',
'int'));
404 $old_rw_date_lim_reglement = $object->retained_warranty_date_limit;
405 $new_rw_date_lim_reglement = $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement);
406 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
407 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
409 if ($object->retained_warranty_date_limit < $object->date) {
410 $object->retained_warranty_date_limit = $object->date;
412 $result = $object->update($user);
416 } elseif ($action ==
'setretainedwarranty' && $user->rights->facture->creer) {
418 $result = $object->setRetainedWarranty(
GETPOST(
'retained_warranty',
'float'));
422 } elseif ($action ==
'setretainedwarrantydatelimit' && $user->rights->facture->creer) {
424 $result = $object->setRetainedWarrantyDateLimit(
GETPOST(
'retained_warranty_date_limit',
'float'));
428 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
429 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
430 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
431 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
432 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
434 $old_date_lim_reglement = $object->date_lim_reglement;
436 if (empty($newdate)) {
437 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
438 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id.
'&action=editinvoicedate&token='.
newToken());
441 if ($newdate > (
dol_now(
'tzuserrel') + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
442 if (empty($conf->global->INVOICE_MAX_FUTURE_DELAY)) {
443 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
445 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
449 $object->date = $newdate;
450 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
451 if ($new_date_lim_reglement > $old_date_lim_reglement) {
452 $object->date_lim_reglement = $new_date_lim_reglement;
454 if ($object->date_lim_reglement < $object->date) {
455 $object->date_lim_reglement = $object->date;
457 $result = $object->update($user);
461 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
464 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
466 $object->date_pointoftax = $date_pointoftax;
467 $result = $object->update($user);
471 } elseif ($action ==
'setconditions' && $usercancreate) {
473 $object->cond_reglement_code = 0;
474 $object->cond_reglement_id = 0;
481 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
489 $old_date_lim_reglement = $object->date_lim_reglement;
490 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
491 if ($new_date_lim_reglement > $old_date_lim_reglement) {
492 $object->date_lim_reglement = $new_date_lim_reglement;
494 if ($object->date_lim_reglement < $object->date) {
495 $object->date_lim_reglement = $object->date;
497 $result = $object->update($user);
509 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
511 $object->date_lim_reglement =
dol_mktime(12, 0, 0,
GETPOST(
'paymenttermmonth',
'int'),
GETPOST(
'paymenttermday',
'int'),
GETPOST(
'paymenttermyear',
'int'));
512 if ($object->date_lim_reglement < $object->date) {
513 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
514 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
516 $result = $object->update($user);
520 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
522 $object->revenuestamp =
GETPOST(
'revenuestamp');
523 $result = $object->update($user);
524 $object->update_price(1);
529 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
530 $outputlangs = $langs;
533 $newlang =
GETPOST(
'lang_id',
'aZ09');
536 $newlang = $object->thirdparty->default_lang;
538 if (!empty($newlang)) {
540 $outputlangs->setDefaultLang($newlang);
541 $outputlangs->load(
'products');
543 $model = $object->model_pdf;
544 $ret = $object->fetch($id);
546 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
552 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm')) {
553 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
554 } elseif ($action ==
'setbankaccount' && $usercancreate) {
555 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
556 } elseif ($action ==
'setremisepercent' && $usercancreate) {
558 $result = $object->setDiscount($user,
price2num(
GETPOST(
'remise_percent'),
'', 2));
559 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
564 if (
GETPOST(
"remise_id",
'int') > 0) {
565 $ret = $object->fetch($id);
567 $result = $object->insert_discount(
GETPOST(
"remise_id",
'int'));
577 if (
GETPOST(
"remise_id_for_payment",
'int') > 0) {
578 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
580 $discount->fetch(
GETPOST(
"remise_id_for_payment",
'int'));
584 $remaintopay = $object->getRemainToPay(0);
588 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
592 $result = $discount->link_to_invoice(0, $id);
600 $newremaintopay = $object->getRemainToPay(0);
601 if ($newremaintopay == 0) {
602 $object->setPaid($user);
613 if (empty($error) && empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
614 $outputlangs = $langs;
617 $newlang =
GETPOST(
'lang_id',
'aZ09');
620 $newlang = $object->thirdparty->default_lang;
622 if (!empty($newlang)) {
624 $outputlangs->setDefaultLang($newlang);
626 $ret = $object->fetch($id);
628 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
633 } elseif ($action ==
'setref' && $usercancreate) {
635 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'',
null,
'',
'', $user,
'BILL_MODIFY');
636 } elseif ($action ==
'setref_client' && $usercancreate) {
638 $object->set_ref_client(
GETPOST(
'ref_client'));
639 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
641 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
644 $object->fetch_thirdparty();
648 $qualified_for_stock_change = 0;
649 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
650 $qualified_for_stock_change = $object->hasProductsOrServices(2);
652 $qualified_for_stock_change = $object->hasProductsOrServices(1);
655 if ($qualified_for_stock_change) {
656 if (!$idwarehouse || $idwarehouse == - 1) {
658 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
665 $result = $object->validate($user,
'', $idwarehouse);
668 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
669 $outputlangs = $langs;
672 $newlang =
GETPOST(
'lang_id',
'aZ09');
675 $newlang = $object->thirdparty->default_lang;
677 if (!empty($newlang)) {
679 $outputlangs->setDefaultLang($newlang);
680 $outputlangs->load(
'products');
682 $model = $object->model_pdf;
684 $ret = $object->fetch($id);
686 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
692 if (count($object->errors)) {
699 } elseif ($action ==
'confirm_modif' && $usercanunvalidate) {
701 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
704 $object->fetch_thirdparty();
708 $qualified_for_stock_change = 0;
709 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
710 $qualified_for_stock_change = $object->hasProductsOrServices(2);
712 $qualified_for_stock_change = $object->hasProductsOrServices(1);
715 if ($qualified_for_stock_change) {
716 if (!$idwarehouse || $idwarehouse == - 1) {
718 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
726 $sql =
'SELECT pf.amount';
727 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf';
728 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id);
730 $result = $db->query($sql);
733 $num = $db->num_rows($result);
736 $objp = $db->fetch_object($result);
737 $totalpaid += $objp->amount;
744 $resteapayer = $object->total_ttc - $totalpaid;
747 $ventilExportCompta = $object->getVentilExportCompta();
750 if ($ventilExportCompta == 0) {
751 if (!empty($conf->global->INVOICE_CAN_BE_EDITED_EVEN_IF_PAYMENT_DONE) || ($resteapayer == $object->total_ttc && empty($object->paye))) {
752 $result = $object->setDraft($user, $idwarehouse);
758 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
759 $outputlangs = $langs;
762 $newlang =
GETPOST(
'lang_id',
'aZ09');
765 $newlang = $object->thirdparty->default_lang;
767 if (!empty($newlang)) {
769 $outputlangs->setDefaultLang($newlang);
770 $outputlangs->load(
'products');
772 $model = $object->model_pdf;
773 $ret = $object->fetch($id);
775 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
780 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
783 $result = $object->setPaid($user);
787 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
790 $close_code =
GETPOST(
"close_code",
'restricthtml');
791 $close_note =
GETPOST(
"close_note",
'restricthtml');
793 $result = $object->setPaid($user, $close_code, $close_note);
798 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
800 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes') {
803 $close_code =
GETPOST(
"close_code",
'restricthtml');
804 $close_note =
GETPOST(
"close_note",
'restricthtml');
806 $result = $object->setCanceled($user, $close_code, $close_note);
811 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
813 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
816 $object->fetch_thirdparty();
821 $result = $discountcheck->fetch(0, $object->id);
834 $amount_ht = $amount_tva = $amount_ttc = array();
835 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
839 foreach ($object->lines as $line) {
840 if ($line->product_type < 9 && $line->total_ht != 0) {
841 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
843 $amount_ht[$keyforvatrate] += $line->total_ht;
844 $amount_tva[$keyforvatrate] += $line->total_tva;
845 $amount_ttc[$keyforvatrate] += $line->total_ttc;
846 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
847 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
848 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
854 if (!empty($conf->global->INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) && $object->type ==
Facture::TYPE_CREDIT_NOTE) {
855 $alreadypaid = $object->getSommePaiement();
856 if ($alreadypaid && abs($alreadypaid) < abs($object->total_ttc)) {
857 $ratio = abs(($object->total_ttc - $alreadypaid) / $object->total_ttc);
858 foreach ($amount_ht as $vatrate => $val) {
859 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
860 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
861 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
862 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
863 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
864 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
873 $discount->description =
'(CREDIT_NOTE)';
875 $discount->description =
'(DEPOSIT)';
877 $discount->description =
'(EXCESS RECEIVED)';
879 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
881 $discount->fk_soc = $object->socid;
882 $discount->fk_facture_source = $object->id;
890 $sql =
'SELECT SUM(pf.amount) as total_paiements';
891 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
892 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
893 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id);
894 $sql .=
' AND pf.fk_paiement = p.rowid';
895 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
896 $resql = $db->query($sql);
901 $res = $db->fetch_object(
$resql);
902 $total_paiements = $res->total_paiements;
905 $total_creditnote_and_deposit = 0;
906 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
907 $sql .=
" re.description, re.fk_facture_source";
908 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
909 $sql .=
" WHERE fk_facture = ".((int) $object->id);
910 $resql = $db->query($sql);
912 while ($obj = $db->fetch_object(
$resql)) {
913 $total_creditnote_and_deposit += $obj->amount_ttc;
919 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object->total_ttc;
920 $discount->amount_tva = 0;
921 $discount->tva_tx = 0;
922 $discount->vat_src_code =
'';
924 $result = $discount->create($user);
930 foreach ($amount_ht as $tva_tx => $xxx) {
931 $discount->amount_ht = abs($amount_ht[$tva_tx]);
932 $discount->amount_tva = abs($amount_tva[$tva_tx]);
933 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
934 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
935 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
936 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
941 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
942 $vat_src_code = $reg[1];
943 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
946 $discount->tva_tx = abs($tva_tx);
947 $discount->vat_src_code = $vat_src_code;
949 $result = $discount->create($user);
960 $result = $object->setPaid($user);
975 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
980 $result = $paiement->fetch(
GETPOST(
'paiement_id',
'int'));
982 $result = $paiement->delete();
984 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
992 } elseif ($action ==
'add' && $usercancreate) {
995 $object->socid =
GETPOST(
'socid',
'int');
997 $selectedLines =
GETPOST(
'toselect',
'array');
999 if (
GETPOST(
'type',
'int') ===
'') {
1000 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1006 $originentity =
GETPOST(
'originentity');
1008 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1014 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
1018 if (empty($dateinvoice)) {
1020 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1022 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1028 if (!(
GETPOST(
'fac_replacement',
'int') > 0)) {
1030 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1036 $result = $object->fetch(
GETPOST(
'fac_replacement',
'int'));
1037 $object->fetch_thirdparty();
1039 $object->date = $dateinvoice;
1040 $object->date_pointoftax = $date_pointoftax;
1041 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1042 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1043 $object->ref_client =
GETPOST(
'ref_client',
'alphanohtml');
1044 $object->ref_customer =
GETPOST(
'ref_client',
'alphanohtml');
1045 $object->model_pdf =
GETPOST(
'model',
'alphanohtml');
1046 $object->fk_project =
GETPOST(
'projectid',
'int');
1047 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1048 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1049 $object->fk_account =
GETPOST(
'fk_account',
'int');
1052 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1053 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1054 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1055 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1058 $object->fk_facture_source =
GETPOST(
'fac_replacement',
'int');
1061 $id = $object->createFromCurrent($user);
1070 $sourceinvoice =
GETPOST(
'fac_avoir',
'int');
1071 if (!($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
1073 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1077 if (empty($dateinvoice)) {
1079 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1081 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1088 if (!empty($originentity)) {
1089 $object->entity = $originentity;
1091 $object->socid =
GETPOST(
'socid',
'int');
1092 $object->ref =
GETPOST(
'ref');
1093 $object->date = $dateinvoice;
1094 $object->date_pointoftax = $date_pointoftax;
1095 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1096 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1097 $object->ref_client =
GETPOST(
'ref_client',
'alphanohtml');
1098 $object->ref_customer =
GETPOST(
'ref_client',
'alphanohtml');
1099 $object->model_pdf =
GETPOST(
'model');
1100 $object->fk_project =
GETPOST(
'projectid',
'int');
1101 $object->cond_reglement_id = 0;
1102 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1103 $object->fk_account =
GETPOST(
'fk_account',
'int');
1106 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1107 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1108 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1109 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1112 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1115 $facture_source =
new Facture($db);
1116 if ($facture_source->fetch($object->fk_facture_source) > 0) {
1118 $object->situation_counter = $facture_source->situation_counter;
1119 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1120 $facture_source->fetchPreviousNextSituationInvoice();
1125 $id = $object->create($user);
1130 if ($object->copy_linked_contact($facture_source,
'internal') < 0) {
1132 } elseif ($facture_source->socid == $object->socid) {
1134 if ($object->copy_linked_contact($facture_source,
'external') < 0) {
1145 if (
GETPOST(
'invoiceAvoirWithLines',
'int') == 1 && $id > 0) {
1146 if (!empty($facture_source->lines)) {
1147 $fk_parent_line = 0;
1149 foreach ($facture_source->lines as $line) {
1151 if (method_exists($line,
'fetch_optionals')) {
1153 $line->fetch_optionals();
1157 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1158 $fk_parent_line = 0;
1163 $source_fk_prev_id = $line->fk_prev_id;
1164 $line->fk_prev_id = $line->id;
1166 if (!empty($facture_source->tab_previous_situation_invoice)) {
1169 $tab_jumped_credit_notes = array();
1170 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1171 $searchPreviousInvoice =
true;
1172 while ($searchPreviousInvoice) {
1173 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1174 $searchPreviousInvoice =
false;
1178 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1184 $maxPrevSituationPercent = 0;
1185 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1186 if ($prevLine->id == $source_fk_prev_id) {
1187 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1190 $line->total_ht = $line->total_ht - $prevLine->total_ht;
1191 $line->total_tva = $line->total_tva - $prevLine->total_tva;
1192 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
1193 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
1194 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
1196 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
1197 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
1198 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
1199 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
1204 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1209 $maxPrevSituationPercent = 0;
1210 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1211 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1212 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1213 $maxPrevSituationPercent = $prevLine->situation_percent;
1215 $line->total_ht -= $prevLine->total_ht;
1216 $line->total_tva -= $prevLine->total_tva;
1217 $line->total_ttc -= $prevLine->total_ttc;
1218 $line->total_localtax1 -= $prevLine->total_localtax1;
1219 $line->total_localtax2 -= $prevLine->total_localtax2;
1221 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1222 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1223 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1224 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1230 $line->situation_percent += $maxPrevSituationPercent;
1236 $line->fk_facture = $object->id;
1237 $line->fk_parent_line = $fk_parent_line;
1239 $line->subprice = -$line->subprice;
1240 $line->pa_ht = $line->pa_ht;
1241 $line->total_ht = -$line->total_ht;
1242 $line->total_tva = -$line->total_tva;
1243 $line->total_ttc = -$line->total_ttc;
1244 $line->total_localtax1 = -$line->total_localtax1;
1245 $line->total_localtax2 = -$line->total_localtax2;
1247 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1248 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1249 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1250 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1252 $line->context[
'createcreditnotefrominvoice'] = 1;
1253 $result = $line->insert(0, 1);
1255 $object->lines[] = $line;
1258 if ($result > 0 && $line->product_type == 9) {
1259 $fk_parent_line = $result;
1263 $object->update_price(1);
1267 if (
GETPOST(
'invoiceAvoirWithPaymentRestAmount',
'int') == 1 && $id > 0) {
1268 if ($facture_source->fetch($object->fk_facture_source) > 0) {
1269 $totalpaid = $facture_source->getSommePaiement();
1270 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1271 $totaldeposits = $facture_source->getSumDepositsUsed();
1272 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1274 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 1, 0, 0, 0, 0, 0,
'',
'',
'TTC');
1279 if (!empty($object->fk_facture_source) && $id > 0) {
1280 $facture_source->fetch($object->fk_facture_source);
1281 $facture_source->fetchObjectLinked();
1283 if (!empty($facture_source->linkedObjectsIds)) {
1284 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1285 $object->add_object_linked($sourcetype, current($TIds));
1294 if (empty($dateinvoice)) {
1296 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1298 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1305 $object->socid =
GETPOST(
'socid',
'int');
1306 $object->type =
GETPOST(
'type');
1307 $object->ref =
GETPOST(
'ref');
1308 $object->date = $dateinvoice;
1309 $object->date_pointoftax = $date_pointoftax;
1310 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1311 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1312 $object->ref_customer =
GETPOST(
'ref_client');
1313 $object->ref_client = $object->ref_customer;
1314 $object->model_pdf =
GETPOST(
'model');
1315 $object->fk_project =
GETPOST(
'projectid',
'int');
1316 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
1317 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1318 $object->fk_account =
GETPOST(
'fk_account',
'int');
1322 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1323 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1324 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1325 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1328 $object->fac_rec =
GETPOST(
'fac_rec',
'int');
1330 $id = $object->create($user);
1336 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1337 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1338 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1340 if (
GETPOST(
'socid',
'int') < 1) {
1342 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1346 if (empty($dateinvoice)) {
1348 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1350 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1358 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1359 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1364 if ($typeamount && !empty($origin) && !empty($originid)) {
1365 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1366 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1370 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1371 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1375 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1376 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1385 $object->socid =
GETPOST(
'socid',
'int');
1386 $object->type =
GETPOST(
'type');
1387 $object->ref =
GETPOST(
'ref');
1388 $object->date = $dateinvoice;
1389 $object->date_pointoftax = $date_pointoftax;
1390 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1391 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1392 $object->ref_client =
GETPOST(
'ref_client');
1393 $object->ref_customer =
GETPOST(
'ref_client');
1394 $object->model_pdf =
GETPOST(
'model');
1395 $object->fk_project =
GETPOST(
'projectid',
'int');
1396 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
1397 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
1398 $object->fk_account =
GETPOST(
'fk_account',
'int');
1402 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1403 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1404 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1405 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1408 $object->situation_counter = 1;
1409 $object->situation_final = 0;
1410 $object->situation_cycle_ref = $object->newCycle();
1413 if (in_array($object->type, $retainedWarrantyInvoiceAvailableType)) {
1414 $object->retained_warranty =
GETPOST(
'retained_warranty',
'int');
1415 $object->retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
1417 $object->retained_warranty = 0;
1418 $object->retained_warranty_fk_cond_reglement = 0;
1421 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1422 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1423 $object->retained_warranty_date_limit =
dol_stringtotime($retained_warranty_date_limit);
1425 $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);
1427 $object->fetch_thirdparty();
1430 if (!empty($origin) && !empty($originid)) {
1433 $element = $subelement = $origin;
1434 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1435 $element = $regs[1];
1436 $subelement = $regs[2];
1440 if ($element ==
'order') {
1441 $element = $subelement =
'commande';
1443 if ($element ==
'propal') {
1444 $element =
'comm/propal';
1445 $subelement =
'propal';
1447 if ($element ==
'contract') {
1448 $element = $subelement =
'contrat';
1450 if ($element ==
'inter') {
1451 $element = $subelement =
'ficheinter';
1453 if ($element ==
'shipping') {
1454 $element = $subelement =
'expedition';
1457 $object->origin = $origin;
1458 $object->origin_id = $originid;
1461 $object->linked_objects[$object->origin] = $object->origin_id;
1463 if ($object->origin ==
'shipping') {
1464 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1466 $exp->fetch($object->origin_id);
1467 $exp->fetchObjectLinked();
1468 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1469 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1470 $object->linked_objects[
'commande'] = $value;
1475 if (is_array($_POST[
'other_linked_objects']) && !empty($_POST[
'other_linked_objects'])) {
1476 $object->linked_objects = array_merge($object->linked_objects, $_POST[
'other_linked_objects']);
1479 $id = $object->create($user);
1484 $classname = ucfirst($subelement);
1485 $srcobject =
new $classname($db);
1487 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines or deposit lines");
1488 $result = $srcobject->fetch($object->origin_id);
1493 $amountdeposit = array();
1494 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)) {
1495 if ($typeamount ==
'amount') {
1496 $amount = $valuedeposit;
1498 $amount = $srcobject->total_ttc * ($valuedeposit / 100);
1501 $TTotalByTva = array();
1502 foreach ($srcobject->lines as &$line) {
1503 if (!empty($line->special_code)) {
1506 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1509 foreach ($TTotalByTva as $tva => &$total) {
1510 $coef = $total / $srcobject->total_ttc;
1511 $am = $amount * $coef;
1512 $amount_ttc_diff += $am;
1513 $amountdeposit[$tva] += $am / (1 + $tva / 100);
1516 if ($typeamount ==
'amount') {
1517 $amountdeposit[0] = $valuedeposit;
1518 } elseif ($typeamount ==
'variable') {
1521 $lines = $srcobject->lines;
1522 $numlines = count($lines);
1523 for ($i = 0; $i < $numlines; $i++) {
1525 if (empty($lines[$i]->qty)) {
1528 if (!empty($lines[$i]->special_code)) {
1532 $totalamount += $lines[$i]->total_ht;
1533 $tva_tx = $lines[$i]->tva_tx;
1534 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $valuedeposit) / 100;
1538 if ($totalamount == 0) {
1539 $amountdeposit[0] = 0;
1547 $amount_ttc_diff = $amountdeposit[0];
1550 foreach ($amountdeposit as $tva => $amount) {
1551 if (empty($amount)) {
1556 'amount' =>
'FixAmount',
1557 'variable' =>
'VarAmount'
1559 $descline =
'(DEPOSIT)';
1561 if ($typeamount ==
'amount') {
1562 $descline .=
' ('.price($valuedeposit,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
')';
1563 } elseif ($typeamount ==
'variable') {
1564 $descline .=
' ('.$valuedeposit.
'%)';
1567 $descline .=
' - '.$srcobject->ref;
1568 $result = $object->addline(
1575 (empty($conf->global->INVOICE_PRODUCTID_DEPOSIT) ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT),
1580 $lines[$i]->info_bits,
1586 $lines[$i]->special_code,
1603 $diff = $object->total_ttc - $amount_ttc_diff;
1605 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0) {
1606 $object->fetch_lines();
1607 $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100);
1608 $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);
1615 $lines = $srcobject->lines;
1616 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1617 $srcobject->fetch_lines();
1618 $lines = $srcobject->lines;
1623 if (is_array($lines)) {
1624 foreach ($lines as $line) {
1626 $line->qty =
price2num($line->qty * $valuestandardinvoice / 100,
'MS');
1632 if (is_array($lines)) {
1633 foreach ($lines as $line) {
1635 $line->qty =
price2num($line->qty * $valuedeposit / 100,
'MS');
1640 $fk_parent_line = 0;
1641 $num = count($lines);
1643 for ($i = 0; $i < $num; $i++) {
1644 if (!in_array($lines[$i]->
id, $selectedLines)) {
1649 if ($srcobject->element ==
'shipping' && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS && $lines[$i]->qty == 0) {
1653 if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1654 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1656 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',', $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE))) {
1660 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1661 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->label);
1662 if ($object->situation_counter == 1) {
1663 $lines[$i]->situation_percent = 0;
1666 if ($lines[$i]->subprice < 0 && empty($conf->global->INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN)) {
1669 $desc = $label ? $label : $langs->trans(
'Discount');
1673 $discount->fk_soc = $object->socid;
1674 $discount->amount_ht = abs($lines[$i]->total_ht);
1675 $discount->amount_tva = abs($lines[$i]->total_tva);
1676 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1677 $discount->tva_tx = $lines[$i]->tva_tx;
1678 $discount->fk_user = $user->id;
1679 $discount->description = $desc;
1680 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1681 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1682 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1683 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1685 $discountid = $discount->create($user);
1686 if ($discountid > 0) {
1687 $result = $object->insert_discount($discountid);
1695 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1698 $date_start =
false;
1699 if ($lines[$i]->date_debut_prevue) {
1700 $date_start = $lines[$i]->date_debut_prevue;
1702 if ($lines[$i]->date_debut_reel) {
1703 $date_start = $lines[$i]->date_debut_reel;
1705 if ($lines[$i]->date_start) {
1706 $date_start = $lines[$i]->date_start;
1711 if ($lines[$i]->date_fin_prevue) {
1712 $date_end = $lines[$i]->date_fin_prevue;
1714 if ($lines[$i]->date_fin_reel) {
1715 $date_end = $lines[$i]->date_fin_reel;
1717 if ($lines[$i]->date_end) {
1718 $date_end = $lines[$i]->date_end;
1722 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1723 $fk_parent_line = 0;
1727 if (method_exists($lines[$i],
'fetch_optionals')) {
1728 $lines[$i]->fetch_optionals();
1729 $array_options = $lines[$i]->array_options;
1732 $tva_tx = $lines[$i]->tva_tx;
1733 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
1734 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1739 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty);
1740 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty);
1742 $result = $object->addline(
1744 $lines[$i]->subprice,
1749 $lines[$i]->fk_product,
1750 $lines[$i]->remise_percent,
1754 $lines[$i]->info_bits,
1755 $lines[$i]->fk_remise_except,
1760 $lines[$i]->special_code,
1764 $lines[$i]->fk_fournprice,
1768 $lines[$i]->situation_percent,
1769 $lines[$i]->fk_prev_id,
1770 $lines[$i]->fk_unit,
1785 if ($result > 0 && $lines[$i]->product_type == 9) {
1786 $fk_parent_line = $result;
1796 $object->update_price(1,
'auto', 0, $mysoc);
1826 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
1837 $id = $object->create($user);
1839 for ($i = 1; $i <= $NBLINES; $i++) {
1840 if (
GETPOST(
'idprod'.$i,
'int')) {
1842 $product->fetch(
GETPOST(
'idprod'.$i,
'int'));
1845 $result = $object->addline($product->description, $product->price,
price2num(
GETPOST(
'qty'.$i),
'MS'), $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx,
GETPOST(
'idprod'.$i,
'int'),
price2num(
GETPOST(
'remise_percent'.$i),
'', 2), $startday, $endday, 0, 0,
'', $product->price_base_type, $product->price_ttc, $product->type, -1, 0,
'', 0, 0,
null, 0,
'', 0, 100,
'', $product->fk_unit, 0,
'', 1);
1849 $object->update_price(1,
'auto', 0, $mysoc);
1856 if (empty($dateinvoice)) {
1858 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
1860 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1866 if (!(
GETPOST(
'situations',
'int') > 0)) {
1868 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
1874 $result = $object->fetch(
GETPOST(
'situations',
'int'));
1875 $object->fk_facture_source =
GETPOST(
'situations',
'int');
1878 if (!empty($origin) && !empty($originid)) {
1879 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1881 $object->origin = $origin;
1882 $object->origin_id = $originid;
1885 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
1886 $retained_warranty =
GETPOST(
'retained_warranty',
'int');
1887 if (
price2num($retained_warranty) > 0) {
1888 $object->retained_warranty =
price2num($retained_warranty);
1891 if (
GETPOST(
'retained_warranty_fk_cond_reglement',
'int') > 0) {
1892 $object->retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
1895 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1896 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
1897 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
1899 $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);
1902 foreach ($object->lines as $i => &$line) {
1903 $line->origin = $object->origin;
1904 $line->origin_id = $line->id;
1905 $line->fk_prev_id = $line->id;
1906 $line->fetch_optionals();
1907 $line->situation_percent = $line->get_prev_progress($object->id);
1910 $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,
'', $line->situation_percent);
1911 $line->total_ht = $tabprice[0];
1912 $line->total_tva = $tabprice[1];
1913 $line->total_ttc = $tabprice[2];
1914 $line->total_localtax1 = $tabprice[9];
1915 $line->total_localtax2 = $tabprice[10];
1916 $line->multicurrency_total_ht = $tabprice[16];
1917 $line->multicurrency_total_tva = $tabprice[17];
1918 $line->multicurrency_total_ttc = $tabprice[18];
1921 if ($line->fk_remise_except) {
1923 $result = $discount->fetch($line->fk_remise_except);
1926 if ($discount->fk_facture_line > 0) {
1927 $line->fk_remise_except = 0;
1934 $object->fetch_thirdparty();
1935 $object->date = $dateinvoice;
1936 $object->date_pointoftax = $date_pointoftax;
1937 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1938 $object->note = trim(
GETPOST(
'note',
'restricthtml'));
1939 $object->note_private = trim(
GETPOST(
'note',
'restricthtml'));
1940 $object->ref_client =
GETPOST(
'ref_client',
'alpha');
1941 $object->model_pdf =
GETPOST(
'model',
'alpha');
1942 $object->fk_project =
GETPOST(
'projectid',
'int');
1943 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1944 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1947 $object->fk_account =
GETPOST(
'fk_account',
'int');
1952 $object->situation_counter = $object->situation_counter + 1;
1953 $id = $object->createFromCurrent($user);
1955 $mesg = $object->error;
1957 $nextSituationInvoice =
new Facture($db);
1958 $nextSituationInvoice->fetch($id);
1961 $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
1962 $ret = $extrafields->setOptionalsFromPost(
null, $nextSituationInvoice);
1964 $nextSituationInvoice->insertExtraFields();
1971 if ($id > 0 && !$error) {
1975 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && count($object->lines)) {
1976 $outputlangs = $langs;
1979 $newlang =
GETPOST(
'lang_id',
'aZ09');
1982 $newlang = $object->thirdparty->default_lang;
1984 if (!empty($newlang)) {
1985 $outputlangs =
new Translate(
"", $conf);
1986 $outputlangs->setDefaultLang($newlang);
1987 $outputlangs->load(
'products');
1989 $model = $object->model_pdf;
1990 $ret = $object->fetch($id);
1992 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1998 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2003 $_GET[
"origin"] = $_POST[
"origin"];
2004 $_GET[
"originid"] = $_POST[
"originid"];
2007 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'') {
2009 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2010 $vat_rate = str_replace(
'*',
'', $vat_rate);
2011 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
2012 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
2013 foreach ($object->lines as $line) {
2014 $result = $object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $vat_rate, $localtax1_rate, $localtax2_rate,
'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice);
2016 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2018 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2019 $remise_percent = str_replace(
'*',
'', $remise_percent);
2020 foreach ($object->lines as $line) {
2021 $result = $object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $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->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice);
2023 } elseif ($action ==
'addline' && $usercancreate) {
2024 $langs->load(
'errors');
2032 $price_ht_devise =
'';
2034 $price_ttc_devise =
'';
2036 if (
GETPOST(
'price_ht') !==
'') {
2039 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2042 if (
GETPOST(
'price_ttc') !==
'') {
2045 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2046 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2049 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2050 if ($prod_entry_mode ==
'free') {
2054 $idprod =
GETPOST(
'idprod',
'int');
2060 if (empty($remise_percent)) {
2061 $remise_percent = 0;
2065 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
2066 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
2068 if (is_array($extralabelsline)) {
2070 foreach ($extralabelsline as $key => $value) {
2071 unset($_POST[
"options_".$key.$predef]);
2075 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2076 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2079 if (!$prod_entry_mode) {
2081 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2085 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2086 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2089 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && (($price_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) || $price_ht ==
'') && (($price_ht_devise < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) || $price_ht_devise ==
'') && $price_ttc ===
'' && $price_ttc_devise ===
'' && $object->type !=
Facture::TYPE_CREDIT_NOTE) {
2090 if (($price_ht < 0 || $price_ttc < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
2091 $langs->load(
"errors");
2092 if ($object->type == $object::TYPE_DEPOSIT) {
2094 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2096 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2100 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2105 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2108 if ($prod_entry_mode ==
'free' && empty($idprod) && empty($product_desc)) {
2109 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2113 $langs->load(
"errors");
2114 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2118 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2119 if ($combinations =
GETPOST(
'combinations',
'array')) {
2123 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2124 $idprod = $res->fk_product_child;
2126 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2132 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
2133 $ret = $object->fetch($id);
2138 $ret = $object->fetch_thirdparty();
2143 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2154 if (!empty($idprod) && $idprod > 0) {
2156 $prod->fetch($idprod);
2158 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2163 $datapriceofproduct = $prod->getSellPrice($mysoc, $object->thirdparty, $pqp);
2165 $pu_ht = $datapriceofproduct[
'pu_ht'];
2166 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2167 $price_min = $datapriceofproduct[
'price_min'];
2168 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] :
null;
2169 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2170 $tva_tx = $datapriceofproduct[
'tva_tx'];
2171 $tva_npr = $datapriceofproduct[
'tva_npr'];
2173 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2174 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
2178 if (!empty($price_ht) || $price_ht ===
'0') {
2180 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2181 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2183 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2184 } elseif ($tmpvat != $tmpprodvat) {
2186 if ($price_base_type !=
'HT') {
2187 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2189 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2196 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
2197 $outputlangs = $langs;
2199 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
2200 $newlang =
GETPOST(
'lang_id',
'aZ09');
2202 if (empty($newlang)) {
2203 $newlang = $object->thirdparty->default_lang;
2205 if (!empty($newlang)) {
2206 $outputlangs =
new Translate(
"", $conf);
2207 $outputlangs->setDefaultLang($newlang);
2208 $outputlangs->load(
'products');
2211 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->description;
2213 $desc = $prod->description;
2217 if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
2221 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
2222 $desc = $product_desc;
2224 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
2228 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
2231 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
2232 $outputlangs = $langs;
2234 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
2235 $newlang =
GETPOST(
'lang_id',
'alpha');
2237 if (empty($newlang)) {
2238 $newlang = $object->thirdparty->default_lang;
2240 if (!empty($newlang)) {
2241 $outputlangs =
new Translate(
"", $conf);
2242 $outputlangs->setDefaultLang($newlang);
2243 $outputlangs->load(
'products');
2245 if (!empty($prod->customcode)) {
2246 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2248 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2251 if (!empty($prod->country_code)) {
2252 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
2255 if (!empty($prod->customcode)) {
2256 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2258 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2261 if (!empty($prod->country_code)) {
2262 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
2269 $type = $prod->type;
2270 $fk_unit = $prod->fk_unit;
2274 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2275 $tva_tx = str_replace(
'*',
'', $tva_tx);
2276 if (empty($tva_tx)) {
2279 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2280 $desc = $product_desc;
2282 $fk_unit =
GETPOST(
'units',
'alpha');
2284 if ($pu_ttc && !$pu_ht) {
2285 $price_base_type =
'TTC';
2296 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
2297 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
2303 $pu_equivalent = $pu_ht;
2304 $pu_equivalent_ttc = $pu_ttc;
2306 $currency_tx = $object->multicurrency_tx;
2310 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2311 $pu_equivalent = $pu_ht_devise * $currency_tx;
2313 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2314 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
2334 $price2num_remise_percent =
price2num($remise_percent);
2335 $price2num_price_min =
price2num($price_min);
2336 $price2num_price_min_ttc =
price2num($price_min_ttc);
2337 if (empty($price2num_pu_ht)) {
2338 $price2num_pu_ht = 0;
2340 if (empty($price2num_remise_percent)) {
2341 $price2num_remise_percent = 0;
2343 if (empty($price2num_price_min)) {
2344 $price2num_price_min = 0;
2346 if (empty($price2num_price_min_ttc)) {
2347 $price2num_price_min_ttc = 0;
2352 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min)) && $price_base_type ==
'HT') {
2353 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2356 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
2357 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2365 if (
isModEnabled(
'productbatch') && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) && !empty($conf->global->INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS)) {
2366 $langs->load(
'productbatch');
2367 foreach ($lines[$i]->detail_batch as $batchline) {
2368 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2373 $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $date_start, $date_end, 0, $info_bits,
'', $price_base_type, $pu_ttc, $type, min($rank, count($object->lines) + 1), $special_code,
'', 0,
GETPOST(
'fk_parent_line'), $fournprice, $buyingprice, $label, $array_options,
GETPOST(
'progress'),
'', $fk_unit, $pu_ht_devise);
2377 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2378 $outputlangs = $langs;
2381 $newlang =
GETPOST(
'lang_id',
'aZ09');
2384 $newlang = $object->thirdparty->default_lang;
2386 if (!empty($newlang)) {
2387 $outputlangs =
new Translate(
"", $conf);
2388 $outputlangs->setDefaultLang($newlang);
2389 $outputlangs->load(
'products');
2391 $model = $object->model_pdf;
2392 $ret = $object->fetch($id);
2394 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2400 unset($_POST[
'prod_entry_mode']);
2402 unset($_POST[
'qty']);
2403 unset($_POST[
'type']);
2404 unset($_POST[
'remise_percent']);
2405 unset($_POST[
'price_ht']);
2406 unset($_POST[
'multicurrency_price_ht']);
2407 unset($_POST[
'price_ttc']);
2408 unset($_POST[
'tva_tx']);
2409 unset($_POST[
'product_ref']);
2410 unset($_POST[
'product_label']);
2411 unset($_POST[
'product_desc']);
2412 unset($_POST[
'fournprice']);
2413 unset($_POST[
'buying_price']);
2414 unset($_POST[
'np_marginRate']);
2415 unset($_POST[
'np_markRate']);
2416 unset($_POST[
'dp_desc']);
2417 unset($_POST[
'idprod']);
2418 unset($_POST[
'units']);
2420 unset($_POST[
'date_starthour']);
2421 unset($_POST[
'date_startmin']);
2422 unset($_POST[
'date_startsec']);
2423 unset($_POST[
'date_startday']);
2424 unset($_POST[
'date_startmonth']);
2425 unset($_POST[
'date_startyear']);
2426 unset($_POST[
'date_endhour']);
2427 unset($_POST[
'date_endmin']);
2428 unset($_POST[
'date_endsec']);
2429 unset($_POST[
'date_endday']);
2430 unset($_POST[
'date_endmonth']);
2431 unset($_POST[
'date_endyear']);
2433 unset($_POST[
'situations']);
2434 unset($_POST[
'progress']);
2442 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2443 if (!$object->fetch($id) > 0) {
2446 $object->fetch_thirdparty();
2455 $vat_rate = str_replace(
'*',
'', $vat_rate);
2467 if (preg_match(
'/\*/', $vat_rate)) {
2472 $vat_rate = str_replace(
'*',
'', $vat_rate);
2473 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty);
2474 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty);
2481 $pu_equivalent = $pu_ht;
2482 $pu_equivalent_ttc = $pu_ttc;
2484 $currency_tx = $object->multicurrency_tx;
2488 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2489 $pu_equivalent = $pu_ht_devise * $currency_tx;
2491 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2492 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
2507 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
2508 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
2510 if (is_array($extralabelsline)) {
2512 foreach ($extralabelsline as $key => $value) {
2513 unset($_POST[
"options_".$key]);
2518 $special_code =
GETPOST(
'special_code',
'int');
2519 if ($special_code == 3) {
2524 $line->fetch(
GETPOST(
'lineid',
'int'));
2525 $percent = $line->get_prev_progress($object->id);
2530 if ($progress >= 0) {
2531 $mesg = $langs->trans(
"CantBeNullOrPositive");
2535 } elseif ($progress < $line->situation_percent) {
2536 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
2540 } elseif ($progress < $percent) {
2541 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
2551 $productid =
GETPOST(
'productid',
'int');
2552 if (!empty($productid)) {
2554 $product->fetch($productid);
2556 $type = $product->type;
2558 $price_min = $product->price_min;
2559 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
2560 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
2562 $price_min_ttc = $product->price_min_ttc;
2563 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
2564 $price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
2571 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
2572 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2575 $action =
'editline';
2576 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - (
float) $remise_percent / 100)) <
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
2577 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2580 $action =
'editline';
2585 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2589 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
2594 $langs->load(
"errors");
2595 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2598 if (empty($productid) && (($pu_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) || $pu_ht ==
'') && (($pu_ht_devise < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) || $pu_ht_devise ==
'') && $pu_ttc ===
'' && $pu_ttc_devise ===
'' && $object->type !=
Facture::TYPE_CREDIT_NOTE) {
2599 if (($pu_ht < 0 || $pu_ttc < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
2600 $langs->load(
"errors");
2601 if ($object->type == $object::TYPE_DEPOSIT) {
2603 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2605 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2609 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2617 if (empty($usercancreatemargin)) {
2618 foreach ($object->lines as &$line) {
2619 if ($line->id ==
GETPOST(
'lineid',
'int')) {
2620 $fournprice = $line->fk_fournprice;
2621 $buyingprice = $line->pa_ht;
2627 $price_base_type =
'HT';
2629 if (empty($pu) && !empty($pu_ttc)) {
2631 $price_base_type =
'TTC';
2634 $result = $object->updateline(
2648 GETPOST(
'fk_parent_line',
'int'),
2661 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2663 $outputlangs = $langs;
2666 $newlang =
GETPOST(
'lang_id',
'aZ09');
2669 $newlang = $object->thirdparty->default_lang;
2671 if (!empty($newlang)) {
2672 $outputlangs =
new Translate(
"", $conf);
2673 $outputlangs->setDefaultLang($newlang);
2674 $outputlangs->load(
'products');
2677 $ret = $object->fetch($id);
2678 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2681 unset($_POST[
'qty']);
2682 unset($_POST[
'type']);
2683 unset($_POST[
'productid']);
2684 unset($_POST[
'remise_percent']);
2685 unset($_POST[
'price_ht']);
2686 unset($_POST[
'multicurrency_price_ht']);
2687 unset($_POST[
'price_ttc']);
2688 unset($_POST[
'tva_tx']);
2689 unset($_POST[
'product_ref']);
2690 unset($_POST[
'product_label']);
2691 unset($_POST[
'product_desc']);
2692 unset($_POST[
'fournprice']);
2693 unset($_POST[
'buying_price']);
2694 unset($_POST[
'np_marginRate']);
2695 unset($_POST[
'np_markRate']);
2697 unset($_POST[
'dp_desc']);
2698 unset($_POST[
'idprod']);
2699 unset($_POST[
'units']);
2701 unset($_POST[
'date_starthour']);
2702 unset($_POST[
'date_startmin']);
2703 unset($_POST[
'date_startsec']);
2704 unset($_POST[
'date_startday']);
2705 unset($_POST[
'date_startmonth']);
2706 unset($_POST[
'date_startyear']);
2707 unset($_POST[
'date_endhour']);
2708 unset($_POST[
'date_endmin']);
2709 unset($_POST[
'date_endsec']);
2710 unset($_POST[
'date_endday']);
2711 unset($_POST[
'date_endmonth']);
2712 unset($_POST[
'date_endyear']);
2714 unset($_POST[
'situations']);
2715 unset($_POST[
'progress']);
2720 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modifier')) {
2721 if (!$object->fetch($id) > 0) {
2724 if (
GETPOST(
'all_progress') !=
"") {
2725 $all_progress =
GETPOST(
'all_progress',
'int');
2726 foreach ($object->lines as $line) {
2727 $percent = $line->get_prev_progress($object->id);
2728 if (floatval($all_progress) < floatval($percent)) {
2729 $mesg = $langs->trans(
"Line").
' '.$i.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
2733 $object->update_percent($line,
GETPOST(
'all_progress'),
false);
2736 $object->update_price(1);
2738 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
2739 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2741 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
2743 $object->fetch($id,
'',
'',
'',
true);
2749 && $object->is_last_in_cycle()
2750 && $usercanunvalidate
2753 $newCycle = $object->newCycle();
2754 if ($newCycle > 1) {
2756 $lastCycle = $object->situation_cycle_ref;
2757 $lastSituationCounter = $object->situation_counter;
2758 $linkedCreditNotesList = array();
2760 if (count($object->tab_next_situation_invoice) > 0) {
2761 foreach ($object->tab_next_situation_invoice as $next_invoice) {
2763 && $next_invoice->situation_counter == $object->situation_counter
2764 && $next_invoice->fk_facture_source == $object->id
2766 $linkedCreditNotesList[] = $next_invoice->id;
2771 $object->situation_cycle_ref = $newCycle;
2772 $object->situation_counter = 1;
2773 $object->situation_final = 0;
2774 if ($object->update($user) > 0) {
2776 if (count($linkedCreditNotesList) > 0) {
2778 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
2779 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
2780 $sql .=
' , situation_final=0';
2781 $sql .=
' , situation_counter='.((int) $object->situation_counter);
2782 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
2784 $resql = $db->query($sql);
2790 foreach ($object->lines as $line) {
2792 if ($line->product_type == 9) {
2797 if (!empty($object->tab_previous_situation_invoice)) {
2799 $lineIndex = count($object->tab_previous_situation_invoice) - 1;
2800 $searchPreviousInvoice =
true;
2801 while ($searchPreviousInvoice) {
2803 $searchPreviousInvoice =
false;
2811 $maxPrevSituationPercent = 0;
2812 foreach ($object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
2813 if ($prevLine->id == $line->fk_prev_id) {
2814 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
2819 $line->situation_percent = $line->situation_percent - $maxPrevSituationPercent;
2821 if ($line->update() < 0) {
2830 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
2832 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
2835 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
2838 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
2841 } elseif ($action ==
'import_lines_from_object'
2846 $fromElement =
GETPOST(
'fromelement');
2847 $fromElementid =
GETPOST(
'fromelementid');
2848 $importLines =
GETPOST(
'line_checkbox');
2850 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
2851 if ($fromElement ==
'commande') {
2853 $lineClassName =
'OrderLine';
2854 } elseif ($fromElement ==
'propal') {
2855 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
2856 $lineClassName =
'PropaleLigne';
2858 $nextRang = count($object->lines) + 1;
2861 foreach ($importLines as $lineId) {
2862 $lineId = intval($lineId);
2863 $originLine =
new $lineClassName($db);
2864 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
2865 $originLine->fetch_optionals();
2866 $desc = $originLine->desc;
2867 $pu_ht = $originLine->subprice;
2868 $qty = $originLine->qty;
2869 $txtva = $originLine->tva_tx;
2870 $txlocaltax1 = $originLine->localtax1_tx;
2871 $txlocaltax2 = $originLine->localtax2_tx;
2872 $fk_product = $originLine->fk_product;
2873 $remise_percent = $originLine->remise_percent;
2874 $date_start = $originLine->date_start;
2875 $date_end = $originLine->date_end;
2877 $info_bits = $originLine->info_bits;
2878 $fk_remise_except = $originLine->fk_remise_except;
2879 $price_base_type =
'HT';
2881 $type = $originLine->product_type;
2882 $rang = $nextRang++;
2883 $special_code = $originLine->special_code;
2884 $origin = $originLine->element;
2885 $origin_id = $originLine->id;
2886 $fk_parent_line = 0;
2887 $fk_fournprice = $originLine->fk_fournprice;
2888 $pa_ht = $originLine->pa_ht;
2889 $label = $originLine->label;
2890 $array_options = $originLine->array_options;
2892 $situation_percent = 0;
2894 $situation_percent = 100;
2897 $fk_unit = $originLine->fk_unit;
2898 $pu_ht_devise = $originLine->multicurrency_subprice;
2900 $res = $object->addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $ventil, $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);
2919 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2925 $triggersendname =
'BILL_SENTBYMAIL';
2927 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
2928 $trackid =
'inv'.$object->id;
2929 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2932 $upload_dir = $conf->facture->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity];
2933 $permissiontoadd = $usercancreate;
2934 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2937 if ($action ==
'update_extras') {
2938 $object->oldcopy =
dol_clone($object, 2);
2941 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
2948 $result = $object->insertExtraFields(
'BILL_MODIFY');
2956 $action =
'edit_extras';
2960 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
2961 if ($action ==
'addcontact') {
2962 $result = $object->fetch($id);
2964 if ($result > 0 && $id > 0) {
2967 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2971 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2974 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2975 $langs->load(
"errors");
2976 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2981 } elseif ($action ==
'swapstatut') {
2983 if ($object->fetch($id)) {
2984 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
2988 } elseif ($action ==
'deletecontact') {
2990 $object->fetch($id);
2991 $result = $object->delete_contact($lineid);
2994 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
3002 $action =
'edit_extras';
3018 $paymentstatic =
new Paiement($db);
3019 $bankaccountstatic =
new Account($db);
3026 $title = $object->ref.
" - ".$langs->trans(
'Card');
3027 if ($action ==
'create') {
3028 $title = $langs->trans(
"NewBill");
3030 $help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3036 if ($action ==
'create') {
3037 $facturestatic =
new Facture($db);
3038 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3043 $res = $soc->fetch($socid);
3046 $currency_code = $conf->currency;
3050 $remise_absolue = 0;
3051 if (!empty($origin) && !empty($originid)) {
3053 $element = $subelement = $origin;
3055 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3056 $element = $regs[1];
3057 $subelement = $regs[2];
3060 if ($element ==
'project') {
3061 $projectid = $originid;
3063 if (empty($cond_reglement_id)) {
3064 $cond_reglement_id = $soc->cond_reglement_id;
3066 if (empty($mode_reglement_id)) {
3067 $mode_reglement_id = $soc->mode_reglement_id;
3069 if (empty($fk_account)) {
3070 $fk_account = $soc->fk_account;
3072 if (!$remise_percent) {
3073 $remise_percent = $soc->remise_percent;
3075 if (!$dateinvoice) {
3077 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
3081 if ($element ==
'order' || $element ==
'commande') {
3082 $element = $subelement =
'commande';
3084 if ($element ==
'propal') {
3085 $element =
'comm/propal';
3086 $subelement =
'propal';
3088 if ($element ==
'contract') {
3089 $element = $subelement =
'contrat';
3091 if ($element ==
'shipping') {
3092 $element = $subelement =
'expedition';
3097 $classname = ucfirst($subelement);
3098 $objectsrc =
new $classname($db);
3099 $objectsrc->fetch($originid);
3100 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3101 $objectsrc->fetch_lines();
3103 $objectsrc->fetch_thirdparty();
3105 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3106 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3109 if (empty($socid)) {
3110 $soc = $objectsrc->thirdparty;
3113 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
3115 if ($element ==
'expedition') {
3116 $ref_client = (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
'');
3118 $elem = $subelem = $objectsrc->origin;
3119 $expeoriginid = $objectsrc->origin_id;
3121 $classname = ucfirst($subelem);
3123 $expesrc =
new $classname($db);
3124 $expesrc->fetch($expeoriginid);
3126 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3127 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3128 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3129 $remise_percent = (!empty($expesrc->remise_percent) ? $expesrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
3130 $remise_absolue = (!empty($expesrc->remise_absolue) ? $expesrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
3132 if (!empty($conf->multicurrency->enabled)) {
3133 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3134 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3138 $expesrc->fetch_optionals();
3139 $object->array_options = $expesrc->array_options;
3141 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
3142 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3143 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3144 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
3145 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
3148 if (!empty($objectsrc->multicurrency_code)) {
3149 $currency_code = $objectsrc->multicurrency_code;
3151 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
3152 $currency_tx = $objectsrc->multicurrency_tx;
3157 $objectsrc->fetch_optionals();
3158 $object->array_options = $objectsrc->array_options;
3162 $cond_reglement_id = $soc->cond_reglement_id;
3163 $mode_reglement_id = $soc->mode_reglement_id;
3164 $fk_account = $soc->fk_account;
3165 $remise_percent = $soc->remise_percent;
3166 $remise_absolue = 0;
3167 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
3169 if (
isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3170 $currency_code = $soc->multicurrency_code;
3175 if (empty($cond_reglement_id)) {
3176 $cond_reglement_id =
GETPOST(
"cond_reglement_id",
'int');
3180 if (empty($mode_reglement_id)) {
3181 $mode_reglement_id =
GETPOST(
"mode_reglement_id",
'int');
3185 if ($socid > 0 && $fk_account) {
3188 $fk_account =
GETPOST(
"fk_account",
'int');
3191 if (!empty($soc->id)) {
3192 $absolute_discount = $soc->getAvailableDiscounts();
3194 $note_public = $object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($conf->global->FACTURE_REUSE_NOTES_ON_CREATE_FROM)) ? $objectsrc->note_public :
null));
3195 $note_private = $object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($conf->global->FACTURE_REUSE_NOTES_ON_CREATE_FROM)) ? $objectsrc->note_private :
null));
3197 if (!empty($conf->use_javascript_ajax)) {
3198 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3204 if ($origin ==
'contrat') {
3205 $langs->load(
"admin");
3206 $text = $langs->trans(
"ToCreateARecurringInvoice");
3207 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3208 if (empty($conf->global->INVOICE_DISABLE_AUTOMATIC_RECURRING_INVOICE)) {
3209 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3211 print
info_admin($text, 0, 0, 0,
'opacitymedium').
'<br>';
3214 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3215 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3216 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3218 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3220 print
'<input name="ref" type="hidden" value="provisoire">';
3221 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3222 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3223 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3224 print
'<input name="force_fk_account" type="hidden" value="0">';
3225 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3226 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3227 print
'<input type="hidden" name="originentity" value="'.GETPOST(
'originentity').
'">';
3228 if (!empty($currency_tx)) {
3229 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3234 print
'<table class="border centpercent">';
3239 $exampletemplateinvoice =
new FactureRec($db);
3241 if (empty($origin) && empty($originid) &&
GETPOST(
'fac_rec',
'int') > 0) {
3242 $invoice_predefined->fetch(
GETPOST(
'fac_rec',
'int'));
3246 if ($soc->id > 0 && (!
GETPOST(
'fac_rec',
'int') || !empty($invoice_predefined->frequency))) {
3248 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3249 print
'<td colspan="2">';
3250 print $soc->getNomUrl(1,
'customer');
3251 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3253 $arrayoutstandingbills = $soc->getOutstandingBills();
3254 $outstandingBills = $arrayoutstandingbills[
'opened'];
3255 print
' - <span class="opacitymedium">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3256 print
'<span class="amount">'.price($outstandingBills,
'', $langs, 0, 0, -1, $conf->currency).
'</span>';
3257 if ($soc->outstanding_limit !=
'') {
3258 if ($outstandingBills > $soc->outstanding_limit) {
3259 print
img_warning($langs->trans(
"OutstandingBillReached"));
3261 print
' / '.price($soc->outstanding_limit,
'', $langs, 0, 0, -1, $conf->currency);
3266 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3267 print
'<td colspan="2">';
3268 print
img_picto(
'',
'company').$form->select_company($soc->id,
'socid',
'((s.client = 1 OR s.client = 3) AND s.status = 1)',
'SelectThirdParty', 1, 0,
null, 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3270 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
3271 print
'<script type="text/javascript">
3272 $(document).ready(function() {
3273 $("#socid").change(function() {
3275 console.log("Submit page");
3276 $(\'input[name="action"]\').val(\'create\');
3277 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3278 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3279 $(\'input[name="force_fk_account"]\').val(\'1\');
3280 $("#formtocreate").submit(); */
3282 // For company change, we must submit page with action=create instead of action=add
3283 console.log("We have changed the company - Resubmit page");
3284 jQuery("#formtocreateaction").val("create");
3285 jQuery("#formtocreate").submit();
3290 if (!
GETPOST(
'fac_rec',
'int')) {
3291 print
' <a href="'.DOL_URL_ROOT.
'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create').
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddThirdParty").
'"></span></a>';
3298 if (empty($origin) && empty($originid) &&
GETPOST(
'fac_rec',
'int') > 0) {
3299 $invoice_predefined->fetch(
GETPOST(
'fac_rec',
'int'));
3301 $dateinvoice = $invoice_predefined->date_when;
3302 if (empty($projectid)) {
3303 $projectid = $invoice_predefined->fk_project;
3305 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
3306 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
3307 $fk_account = $invoice_predefined->fk_account;
3308 $note_public = $invoice_predefined->note_public;
3309 $note_private = $invoice_predefined->note_private;
3311 if (!empty($invoice_predefined->multicurrency_code)) {
3312 $currency_code = $invoice_predefined->multicurrency_code;
3314 if (!empty($invoice_predefined->multicurrency_tx)) {
3315 $currency_tx = $invoice_predefined->multicurrency_tx;
3318 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
3319 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
3320 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
3322 $resql = $db->query($sql);
3324 $num = $db->num_rows(
$resql);
3328 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
3330 print
'<select class="flat" id="fac_rec" name="fac_rec">';
3331 print
'<option value="0" selected></option>';
3333 $objp = $db->fetch_object(
$resql);
3334 print
'<option value="'.$objp->rowid.
'"';
3335 if (
GETPOST(
'fac_rec',
'int') == $objp->rowid) {
3337 $exampletemplateinvoice->fetch(
GETPOST(
'fac_rec',
'int'));
3339 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
3347 if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED)) {
3348 print
'<script type="text/javascript">
3349 $(document).ready(function() {
3350 $("#fac_rec").change(function() {
3351 console.log("We have changed the template invoice - Reload page");
3352 var fac_rec = $(this).val();
3353 var socid = $(\'#socid\').val();
3354 // 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.
3355 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3368 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td colspan="2">';
3369 print
'<div class="tagtable">'.
"\n";
3372 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3373 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOST(
'type',
'int') ?
'' :
' checked').
'> ';
3374 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
3375 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3,
'standardonsmartphone');
3376 print
'<table class="nobordernopadding"><tr>';
3380 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
3389 print
'<td class="nowrap" style="padding-left: 15px">';
3390 print
'<span class="opacitymedium">'.$langs->trans(
'PercentOfOriginalObject').
'</span>:<input class="right" placeholder="100%" type="text" id="valuestandardinvoice" name="valuestandardinvoice" size="3" value="'.(
GETPOSTISSET(
'valuestandardinvoice') ?
GETPOST(
'valuestandardinvoice',
'alpha') :
'100%').
'"/>';
3393 print
'</tr></table>';
3394 print
'</div></div>';
3396 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
3398 if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) {
3399 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3400 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOST(
'type') == 3 ?
' checked' :
'').
'> ';
3401 print
'<script type="text/javascript">
3402 jQuery(document).ready(function() {
3403 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
3404 jQuery("#radio_standard").prop("checked", true);
3406 jQuery("#typedeposit, #valuedeposit").click(function() {
3407 jQuery("#radio_deposit").prop("checked", true);
3409 jQuery("#typedeposit").change(function() {
3410 console.log("We change type of down payment");
3411 jQuery("#radio_deposit").prop("checked", true);
3412 setRadioForTypeOfIncoice();
3414 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
3415 setRadioForTypeOfIncoice();
3417 function setRadioForTypeOfIncoice() {
3418 console.log("Change radio");
3419 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
3420 jQuery(".checkforselect").prop("disabled", true);
3421 jQuery(".checkforselect").prop("checked", false);
3423 jQuery(".checkforselect").prop("disabled", false);
3424 jQuery(".checkforselect").prop("checked", true);
3430 print
'<table class="nobordernopadding"><tr>';
3432 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
3433 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
3436 if (($origin ==
'propal') || ($origin ==
'commande')) {
3437 print
'<td class="nowrap" style="padding-left: 15px">';
3439 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
3440 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
3441 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
3443 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
3444 $valuedeposit =
GETPOST(
'valuedeposit',
'int');
3445 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
3446 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
3447 if (!empty($origin_payment_conditions_deposit_percent)) {
3448 $typedeposit =
'variable';
3451 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
3452 $valuedeposit = $objectsrc->deposit_percent;
3454 print
$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
3456 print
'<td class="nowrap" style="padding-left: 5px">';
3457 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.$valuedeposit.
'"/>';
3460 print
'</tr></table>';
3462 print
'</div></div>';
3467 if (!empty($conf->global->INVOICE_USE_SITUATION)) {
3469 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3470 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
3471 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
3472 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
3474 print
'</div></div>';
3477 $opt =
$form->selectSituationInvoices(
GETPOST(
'originid',
'int'), $socid);
3479 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3480 $tmp =
'<input type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOST(
'originid',
'int') ?
' checked' :
'');
3481 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3482 $tmp .=
' disabled';
3485 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3486 $text .=
'<select class="flat" id="situations" name="situations"';
3487 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3488 $text .=
' disabled';
3492 $text .=
'</select>';
3493 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
3495 print
'</div></div>';
3499 if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT)) {
3501 $facids = $facturestatic->list_replacable_invoices($soc->id);
3507 if (is_array($facids)) {
3508 foreach ($facids as $facparam) {
3509 $options .=
'<option value="'.$facparam [
'id'].
'"';
3510 if ($facparam[
'id'] ==
GETPOST(
'fac_replacement',
'int')) {
3511 $options .=
' selected';
3513 $options .=
'>'.$facparam[
'ref'];
3514 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
3515 $options .=
'</option>';
3519 print
'<!-- replacement line -->';
3520 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3521 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
3522 if (!$options || $invoice_predefined->id > 0) {
3523 $tmp .=
' disabled';
3526 print
'<script type="text/javascript">
3527 jQuery(document).ready(function() {
3528 jQuery("#fac_replacement").change(function() {
3529 jQuery("#radio_replacement").prop("checked", true);
3533 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
3534 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
3535 if (!$options || $invoice_predefined->id > 0) {
3536 $text .=
' disabled';
3540 $text .=
'<option value="-1"> </option>';
3543 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
3545 $text .=
'</select>';
3546 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3548 print
'</div></div>';
3551 if (!empty($conf->global->INVOICE_USE_SITUATION)) {
3552 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3553 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3554 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3555 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3556 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
3558 print
'</div></div>';
3561 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3562 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
3563 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
3565 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'', 0, 3,
'replacementonsmartphone');
3567 print
'</div></div>';
3570 if (empty($origin)) {
3573 if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) {
3575 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
3581 $newinvoice_static =
new Facture($db);
3582 foreach ($facids as $key => $valarray) {
3583 $newinvoice_static->id = $key;
3584 $newinvoice_static->ref = $valarray [
'ref'];
3585 $newinvoice_static->statut = $valarray [
'status'];
3586 $newinvoice_static->type = $valarray [
'type'];
3587 $newinvoice_static->paye = $valarray [
'paye'];
3589 $optionsav .=
'<option value="'.$key.
'"';
3590 if ($key ==
GETPOST(
'fac_avoir')) {
3591 $optionsav .=
' selected';
3594 $newinvoice_static->fetch_optionals($key);
3595 $object->array_options = $newinvoice_static->array_options;
3598 $optionsav .= $newinvoice_static->ref;
3599 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
3600 $optionsav .=
'</option>';
3603 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3604 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
3605 if ((!$optionsav && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) || $invoice_predefined->id > 0) {
3606 $tmp .=
' disabled';
3610 print
'<script type="text/javascript">
3611 jQuery(document).ready(function() {
3612 if (! jQuery("#radio_creditnote").is(":checked"))
3614 jQuery("#credit_note_options").hide();
3616 jQuery("#radio_creditnote").click(function() {
3617 jQuery("#credit_note_options").show();
3619 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
3620 jQuery("#credit_note_options").hide();
3624 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
3625 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3626 if (!$optionsav || $invoice_predefined->id > 0) {
3627 $text .=
' disabled';
3631 $text .=
'<option value="-1"></option>';
3632 $text .= $optionsav;
3634 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
3636 $text .=
'</select>';
3637 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3640 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
3641 print
' <input type="checkbox" name="invoiceAvoirWithLines" id="invoiceAvoirWithLines" value="1" onclick="$(\'#credit_note_options input[type=checkbox]\').not(this).prop(\'checked\', false);" '.(GETPOST(
'invoiceAvoirWithLines',
'int') > 0 ?
'checked' :
'').
' /> <label for="invoiceAvoirWithLines">'.$langs->trans(
'invoiceAvoirWithLines').
"</label>";
3642 print
'<br> <input type="checkbox" name="invoiceAvoirWithPaymentRestAmount" id="invoiceAvoirWithPaymentRestAmount" value="1" onclick="$(\'#credit_note_options input[type=checkbox]\').not(this).prop(\'checked\', false);" '.(GETPOST(
'invoiceAvoirWithPaymentRestAmount',
'int') > 0 ?
'checked' :
'').
' /> <label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans(
'invoiceAvoirWithPaymentRestAmount').
"</label>";
3645 print
'</div></div>';
3648 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3649 if (empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
3650 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3652 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
3654 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
3656 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
3658 print
'</div></div>'.
"\n";
3663 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3664 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
3665 $text = $tmp.
'<label class="opacitymedium" for="radio_template">'.$langs->trans(
"RepeatableInvoice").
'</label> ';
3666 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3,
'templateonsmartphone');
3668 print
'</div></div>';
3673 if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) {
3677 foreach ($listtType as $type) {
3678 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
3679 $curent = !empty($conf->global->{$thisTypeConfName}) ? $conf->global->{$thisTypeConfName}:$conf->global->FACTURE_ADDON_PDF;
3680 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$curent.
'"';
3683 print
'<script type="text/javascript">
3684 $(document).ready(function() {
3685 var listType = {'.$jsListType.
'};
3686 $("[name=\'type\'").change(function() {
3687 console.log("change name=type");
3688 if ($( this ).prop("checked"))
3690 if(($( this ).val() in listType))
3692 $("#model").val(listType[$( this ).val()]);
3696 $("#model").val("'.$conf->global->FACTURE_ADDON_PDF.
'");
3709 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
3713 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin',
'alpha').
'&originid='.
GETPOST(
'originid',
'int'));
3714 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3720 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
3723 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
3724 print
$form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'',
'',
'',
'',
"add", 1, 1);
3728 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
3729 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
3730 print
$form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax',
'',
'',
'',
"add", 1, 1);
3735 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
3736 print
$form->getSelectConditionsPaiements(
GETPOSTISSET(
'cond_reglement_id') ?
GETPOST(
'cond_reglement_id',
'int') : $cond_reglement_id,
'cond_reglement_id');
3740 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
3741 $rwStyle =
'display:none;';
3742 if (in_array(
GETPOST(
'type',
'int'), $retainedWarrantyInvoiceAvailableType)) {
3746 $retained_warranty =
GETPOST(
'retained_warranty',
'int');
3747 if (empty($retained_warranty)) {
3748 if (!empty($objectsrc->retained_warranty)) {
3749 $retained_warranty = $objectsrc->retained_warranty;
3752 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT;
3754 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
3755 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
3758 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
3759 $retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
3760 if (empty($retained_warranty_fk_cond_reglement)) {
3761 $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
3762 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
3763 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
3765 $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
3768 print
$form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
3771 print
'<script type="text/javascript">
3772 $(document).ready(function() {
3773 $("[name=\'type\']").change(function() {
3774 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
3776 $(".retained-warranty-line").show();
3777 $("#new-situation-invoice-retained-warranty").val("'.floatval($retained_warranty_js_default).
'");
3780 $(".retained-warranty-line").hide();
3781 $("#new-situation-invoice-retained-warranty").val("");
3785 $("[name=\'type\']:checked").trigger("change");
3791 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
3792 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
3793 print
$form->select_types_paiements(
GETPOSTISSET(
'mode_reglement_id') ?
GETPOST(
'mode_reglement_id') : $mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
3798 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td colspan="2">';
3799 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
3800 print
$form->select_comptes(($fk_account < 0 ?
'' : $fk_account),
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
3806 $langs->load(
'projects');
3807 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
3808 print
img_picto(
'',
'project').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
3809 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>';
3816 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
3817 print
'<td colspan="2" class="maxwidthonsmartphone">';
3818 $incoterm_id =
GETPOST(
'incoterm_id');
3819 $incoterm_location =
GETPOST(
'location_incoterms');
3820 if (empty($incoterm_id)) {
3821 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
3822 $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
3824 print
$form->select_incoterms($incoterm_id, $incoterm_location);
3829 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid'=>$socid);
3830 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
3831 print $hookmanager->resPrint;
3832 if (empty($reshook)) {
3833 if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE) && !empty($soc->id)) {
3835 $tpExtrafields =
new Extrafields($db);
3836 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
3837 if ($soc->fetch_optionals() > 0) {
3838 $object->array_options = array_merge($object->array_options, $soc->array_options);
3842 print $object->showOptionals($extrafields,
'create',
$parameters);
3846 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
3847 print
'<td colspan="2">';
3848 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
3849 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
3851 if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) {
3853 $paramkey =
'FACTURE_ADDON_PDF_'.$object->type;
3854 $preselected = !empty($conf->global->$paramkey) ? $conf->global->$paramkey : $conf->global->FACTURE_ADDON_PDF;
3856 $preselected = $conf->global->FACTURE_ADDON_PDF;
3858 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
3864 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
3865 print
'<td colspan="2" class="maxwidthonsmartphone">';
3866 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
3867 print
$form->selectMultiCurrency($currency_code,
'multicurrency_code');
3873 if (
GETPOST(
'fac_rec',
'int') > 0) {
3874 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
3875 if (empty($dateexample)) {
3878 $substitutionarray = array(
3879 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
3880 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
3881 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
3882 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
3883 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
3884 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
3885 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
3886 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
3887 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
3888 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
3889 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
3892 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
3893 foreach ($substitutionarray as $key => $val) {
3894 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
3896 $htmltext .=
'</i>';
3901 print
'<td class="tdtop">';
3902 print
$form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
3904 print
'<td valign="top" colspan="2">';
3905 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3,
'90%');
3906 print $doleditor->Create(1);
3909 if (empty($user->socid)) {
3911 print
'<td class="tdtop">';
3912 print
$form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
3914 print
'<td valign="top" colspan="2">';
3915 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3,
'90%');
3916 print $doleditor->Create(1);
3922 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
3923 $langs->loadLangs(array(
'orders',
'propal'));
3926 if ($origin ==
'contrat') {
3928 $objectsrc->remise_absolue = $remise_absolue;
3929 $objectsrc->remise_percent = $remise_percent;
3930 $objectsrc->update_price(1,
'auto', 1);
3933 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
3934 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
3935 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
3936 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
3941 switch (get_class($objectsrc)) {
3943 $newclassname =
'CommercialProposal';
3946 $newclassname =
'Order';
3949 $newclassname =
'Sending';
3952 $newclassname =
'Contract';
3955 $newclassname =
'Intervention';
3958 $newclassname = get_class($objectsrc);
3962 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
3963 print
'<td colspan="2">';
3964 print $objectsrc->getNomUrl(1);
3966 $objectsrc->fetchObjectLinked($originid, $origin,
'',
'facture');
3967 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
3969 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
3972 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht).
'</td></tr>';
3973 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva).
"</td></tr>";
3974 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
3975 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax1).
"</td></tr>";
3978 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
3979 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax2).
"</td></tr>";
3981 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc).
"</td></tr>";
3984 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
3985 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
3986 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
3994 print
$form->buttonsSaveCancel(
"CreateDraft");
3997 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4000 $title = $langs->trans(
'ProductsAndServices');
4003 print
'<div class="div-table-responsive-no-min">';
4004 print
'<table class="noborder centpercent">';
4006 $objectsrc->printOriginLinesList(
'', $selectedLines);
4013 } elseif ($id > 0 || !empty($ref)) {
4014 if (empty($object->id)) {
4015 $langs->load(
'errors');
4016 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4025 $result = $object->fetch($id, $ref);
4032 $extrafields->fetch_name_optionals_label($object->table_element);
4034 if ($user->socid > 0 && $user->socid != $object->socid) {
4038 $result = $object->fetch_thirdparty();
4040 $result = $soc->fetch($object->socid);
4044 $selleruserevenustamp = $mysoc->useRevenueStamp();
4046 $totalpaid = $object->getSommePaiement();
4047 $totalcreditnotes = $object->getSumCreditNotesUsed();
4048 $totaldeposits = $object->getSumDepositsUsed();
4056 $resteapayer =
price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4060 $multicurrency_totalpaid = $object->getSommePaiement(1);
4061 $multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
4062 $multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
4063 $multicurrency_resteapayer =
price2num($object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4067 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 && $object->multicurrency_code != $conf->currency) {
4068 $resteapayer =
price2num($multicurrency_resteapayer / $object->multicurrency_tx,
'MT');
4072 if ($object->paye) {
4075 $resteapayeraffiche = $resteapayer;
4077 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
4078 $filterabsolutediscount =
"fk_facture_source IS NULL";
4079 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4081 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4082 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4085 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
4086 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
4087 $absolute_discount =
price2num($absolute_discount,
'MT');
4088 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4090 $author =
new User($db);
4091 if ($object->user_author) {
4092 $author->fetch($object->user_author);
4095 $objectidnext = $object->getIdReplacingInvoice();
4099 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
'bill');
4104 if ($action ==
'converttoreduc') {
4106 $type_fac =
'ExcessReceived';
4108 $type_fac =
'CreditNote';
4110 $type_fac =
'Deposit';
4112 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4113 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4114 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4118 if ($action ==
'delete') {
4119 $text = $langs->trans(
'ConfirmDeleteBill', $object->ref);
4120 $formquestion = array();
4122 if ($object->type !=
Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->statut >= 1) {
4123 $qualified_for_stock_change = 0;
4124 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
4125 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4127 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4130 if ($qualified_for_stock_change) {
4131 $langs->load(
"stocks");
4132 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4134 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
4136 if ($conf->browser->name ==
'ie') {
4139 $formquestion = array(
4143 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4145 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4147 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4150 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4155 if ($action ==
'situationout') {
4156 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle', $object->ref);
4157 $label = $langs->trans(
"ConfirmOuting");
4158 $formquestion = array();
4163 && $object->is_last_in_cycle()
4164 && $usercanunvalidate
4166 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4171 if ($action ==
'valid') {
4173 $objectref = substr($object->ref, 1, 4);
4174 if ($objectref ==
'PROV') {
4175 $savdate = $object->date;
4176 if (!empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
4178 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
4180 $numref = $object->getNextNumRef($soc);
4183 $numref = $object->ref;
4186 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4188 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4189 $notify =
new Notify($db);
4191 $text .= $notify->confirmMessage(
'BILL_VALIDATE', $object->socid, $object);
4193 $formquestion = array();
4196 $qualified_for_stock_change = 0;
4197 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
4198 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4200 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4203 if ($qualified_for_stock_change) {
4204 $langs->load(
"stocks");
4205 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4206 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4209 $warehouse_array = $warehouse->list_array();
4210 if (count($warehouse_array) == 1) {
4211 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4212 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4214 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockIncrease") : $langs->trans(
"SelectWarehouseForStockDecrease");
4215 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4217 $formquestion = array(
4223 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4227 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
4232 foreach ($object->lines as $line) {
4233 $res = $line->fetch_product();
4235 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
4241 if ($nbMandated > 0 ) $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
4244 $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);
4248 if ($action ==
'modif') {
4249 $text = $langs->trans(
'ConfirmUnvalidateBill', $object->ref);
4250 $formquestion = array();
4253 $qualified_for_stock_change = 0;
4254 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
4255 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4257 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4260 if ($qualified_for_stock_change) {
4261 $langs->load(
"stocks");
4262 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4263 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4266 $warehouse_array = $warehouse->list_array();
4267 if (count($warehouse_array) == 1) {
4268 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
4269 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4271 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
4272 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4274 $formquestion = array(
4280 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4284 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
4288 if ($action ==
'paid' && ($resteapayer <= 0 || (!empty($conf->global->INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) && $resteapayer == $object->total_ttc))) {
4289 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill', $object->ref),
'confirm_paid',
'',
"yes", 1);
4291 if ($action ==
'paid' && $resteapayer > 0 && (empty($conf->global->INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $resteapayer != $object->total_ttc)) {
4295 $close[$i][
'code'] =
'discount_vat';
4297 $close[$i][
'code'] =
'badcustomer';
4299 $close[$i][
'code'] =
'bankcharge';
4301 $close[$i][
'code'] =
'other';
4305 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
4307 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4309 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
4311 $close[$i][
'label'] = $langs->trans(
"Other");
4315 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4317 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4319 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4321 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
4324 foreach ($close as $key => $val) {
4325 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
4329 $formquestion = array(
'text' => $langs->trans(
"ConfirmClassifyPaidPartiallyQuestion"), array(
'type' =>
'radio',
'name' =>
'close_code',
'label' => $langs->trans(
"Reason"),
'values' => $arrayreasons), array(
'type' =>
'text',
'name' =>
'close_note',
'label' => $langs->trans(
"Comment"),
'value' =>
'',
'morecss' =>
'minwidth300'));
4331 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially', $object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 340, 600);
4335 if ($action ==
'canceled') {
4338 if ($objectidnext) {
4339 $facturereplacement =
new Facture($db);
4340 $facturereplacement->fetch($objectidnext);
4341 $statusreplacement = $facturereplacement->statut;
4343 if ($objectidnext && $statusreplacement == 0) {
4344 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
4347 $close[1][
'code'] =
'badcustomer';
4348 $close[2][
'code'] =
'abandon';
4350 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4351 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
4353 $close[1][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $object->ref), $close[1][
'label'], 1);
4354 $close[2][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
4356 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
4357 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
4360 $formquestion = array(
'text' => $langs->trans(
"ConfirmCancelBillQuestion"), array(
'type' =>
'radio',
'name' =>
'close_code',
'label' => $langs->trans(
"Reason"),
'values' => $arrayreasons), array(
'type' =>
'text',
'name' =>
'close_note',
'label' => $langs->trans(
"Comment"),
'value' =>
'',
'morecss' =>
'minwidth300'));
4362 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill', $object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 270);
4366 if ($action ==
'deletepayment') {
4367 $payment_id =
GETPOST(
'paiement_id');
4368 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
4372 if ($action ==
'ask_deleteline') {
4373 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
4377 if ($action ==
'clone') {
4379 $formquestion = array(
4380 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' =>
$form->select_company($object->socid,
'socid',
'(s.client=1 OR s.client=2 OR s.client=3)', 1)),
4381 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
4384 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
4387 if ($action ==
"remove_file_comfirm") {
4388 $file =
GETPOST(
'file',
'alpha');
4391 $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&file='.$file,
4392 $langs->trans(
'DeleteFileHeader'),
4393 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
4403 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
4404 if (empty($reshook)) {
4406 } elseif ($reshook > 0) {
4415 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
4417 $morehtmlref =
'<div class="refidno">';
4419 if ($object->status == $object::STATUS_DRAFT && !$mysoc->isInEEC() && !empty($conf->global->INVOICE_ALLOW_FREE_REF)) {
4420 $morehtmlref .=
$form->editfieldkey(
"Ref",
'ref', $object->ref, $object, $usercancreate,
'string',
'', 0, 1);
4421 $morehtmlref .=
$form->editfieldval(
"Ref",
'ref', $object->ref, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
4422 $morehtmlref .=
'<br>';
4425 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
4426 $morehtmlref .=
$form->editfieldval(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ?
':'.$conf->global->THIRDPARTY_REF_INPUT_SIZE :
''),
'',
null,
null,
'', 1);
4428 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
4429 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
4430 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
4434 $langs->load(
"projects");
4435 $morehtmlref .=
'<br>';
4436 if ($usercancreate) {
4437 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
4438 if ($action !=
'classify') {
4439 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
4441 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
4443 if (!empty($object->fk_project)) {
4445 $proj->fetch($object->fk_project);
4446 $morehtmlref .= $proj->getNomUrl(1);
4448 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
4453 $morehtmlref .=
'</div>';
4455 $object->totalpaid = $totalpaid;
4457 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
4459 print
'<div class="fichecenter">';
4460 print
'<div class="fichehalfleft">';
4461 print
'<div class="underbanner clearboth"></div>';
4463 print
'<table class="border centpercent tableforfield">';
4466 print
'<tr><td class="titlefield fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
4467 print $object->getLibType(2);
4468 if ($object->module_source) {
4469 print
' <span class="opacitymediumbycolor paddingleft">('.$langs->trans(
"POS").
' '.ucfirst($object->module_source).
' - '.$langs->trans(
"Terminal").
' '.$object->pos_source.
')</span>';
4472 $facreplaced =
new Facture($db);
4473 $facreplaced->fetch($object->fk_facture_source);
4474 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
4478 $facusing->fetch($object->fk_facture_source);
4479 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
4482 $facidavoir = $object->getListIdAvoirFromInvoice();
4483 if (count($facidavoir) > 0) {
4484 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
4486 foreach ($facidavoir as $id) {
4493 $facavoir->fetch($id);
4494 print $facavoir->getNomUrl(1);
4498 if ($objectidnext > 0) {
4499 $facthatreplace =
new Facture($db);
4500 $facthatreplace->fetch($objectidnext);
4501 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
4506 $result = $discount->fetch(0, $object->id);
4508 print
' <span class="opacitymediumbycolor paddingleft">';
4509 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
4510 $s = str_replace(
'{s1}', $object->getLibType(0), $s);
4511 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
4513 print
'</span><br>';
4517 if ($object->fk_fac_rec_source > 0) {
4519 $result = $tmptemplate->fetch($object->fk_fac_rec_source);
4521 print
' <span class="opacitymediumbycolor paddingleft">';
4522 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
4523 $s = str_replace(
'{s1}',
'<a href="'.DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->ref).
'</a>', $s);
4531 print
'<!-- Discounts -->'.
"\n";
4532 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
4536 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?facid='.$object->id);
4537 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
4542 print
'<table class="nobordernopadding centpercent"><tr><td>';
4543 print $langs->trans(
'DateInvoice');
4545 if ($action !=
'editinvoicedate' && !empty($object->brouillon) && $usercancreate && empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
4546 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>';
4548 print
'</tr></table>';
4551 if ($action ==
'editinvoicedate') {
4552 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date,
'invoicedate');
4554 print
'<span class="valuedate">'.dol_print_date($object->date,
'day').
'</span>';
4560 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
4563 print
'<table class="nobordernopadding centpercent"><tr><td>';
4564 print $langs->trans(
'DatePointOfTax');
4566 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>';
4567 print
'</tr></table>';
4569 if ($action ==
'editdate_pointoftax') {
4570 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date_pointoftax,
'date_pointoftax');
4572 print
'<span class="valuedate">'.dol_print_date($object->date_pointoftax,
'day').
'</span>';
4579 print
'<table class="nobordernopadding centpercent"><tr><td>';
4580 print $langs->trans(
'PaymentConditionsShort');
4583 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>';
4585 print
'</tr></table>';
4588 if ($action ==
'editconditions') {
4589 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
4591 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'none');
4600 print
'<table class="nobordernopadding centpercent"><tr><td>';
4601 print $langs->trans(
'DateMaxPayment');
4604 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>';
4606 print
'</tr></table>';
4609 if ($action ==
'editpaymentterm') {
4610 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date_lim_reglement,
'paymentterm');
4612 print
'<span class="valuedate">'.dol_print_date($object->date_lim_reglement,
'day').
'</span>';
4613 if ($object->hasDelay()) {
4624 print
'<table class="nobordernopadding centpercent"><tr><td>';
4625 print $langs->trans(
'PaymentMode');
4627 if ($action !=
'editmode' && $usercancreate) {
4628 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>';
4630 print
'</tr></table>';
4632 if ($action ==
'editmode') {
4633 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
4635 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'none',
'CRDT');
4644 print
'<table class="nobordernopadding centpercent"><tr><td>';
4645 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
4647 if ($usercancreate && $action !=
'editmulticurrencycode' && !empty($object->brouillon)) {
4648 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencycode&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
4650 print
'</tr></table>';
4652 $htmlname = (($usercancreate && $action ==
'editmulticurrencycode') ?
'multicurrency_code' :
'none');
4653 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code, $htmlname);
4657 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
4660 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4661 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
4663 if ($usercancreate && $action !=
'editmulticurrencyrate' && !empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
4664 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencyrate&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
4666 print
'</tr></table>';
4668 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
4669 if ($action ==
'actualizemulticurrencyrate') {
4672 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx, ($usercancreate ?
'multicurrency_tx' :
'none'), $object->multicurrency_code);
4674 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
4675 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
4676 print
'<div class="inline-block"> ';
4677 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
4687 print
'<tr><td class="nowrap">';
4688 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
4689 print $langs->trans(
'BankAccount');
4691 if (($action !=
'editbankaccount') && $usercancreate) {
4692 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>';
4694 print
'</tr></table>';
4696 if ($action ==
'editbankaccount') {
4697 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
4699 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
4708 print
'<table class="nobordernopadding centpercent"><tr><td>';
4709 print $langs->trans(
'IncotermLabel');
4710 print
'<td><td class="right">';
4711 if ($usercancreate) {
4712 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
4716 print
'</td></tr></table>';
4719 if ($action !=
'editincoterm') {
4720 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
4722 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
4729 if (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
4730 $displayWarranty =
true;
4731 if (!in_array($object->type, $retainedWarrantyInvoiceAvailableType) && empty($object->retained_warranty)) {
4732 $displayWarranty =
false;
4735 if ($displayWarranty) {
4737 print
'<tr class="retained-warranty-lines" ><td>';
4738 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
4739 print $langs->trans(
'RetainedWarranty');
4741 if ($action !=
'editretainedwarranty' && $user->rights->facture->creer && $object->statut ==
Facture::STATUS_DRAFT) {
4742 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>';
4745 print
'</tr></table>';
4748 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4749 print
'<input type="hidden" name="action" value="setretainedwarranty">';
4750 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4751 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
4752 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4755 print
price($object->retained_warranty).
'%';
4760 print
'<tr class="retained-warranty-lines" ><td>';
4761 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
4762 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
4764 if ($action !=
'editretainedwarrantypaymentterms' && $user->rights->facture->creer && $object->statut ==
Facture::STATUS_DRAFT) {
4765 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>';
4768 print
'</tr></table>';
4770 $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime(
'-1 years', $object->date_lim_reglement);
4771 if ($object->date > $defaultDate) {
4772 $defaultDate = $object->date;
4777 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4778 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
4779 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4780 $retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
4781 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $object->retained_warranty_fk_cond_reglement;
4782 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
4783 print
$form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4784 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4787 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->retained_warranty_fk_cond_reglement,
'none');
4788 if (!$displayWarranty) {
4789 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning.png',
'class="pictowarning valignmiddle" ');
4795 print
'<tr class="retained-warranty-lines" ><td>';
4796 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
4797 print $langs->trans(
'RetainedWarrantyDateLimit');
4799 if ($action !=
'editretainedwarrantydatelimit' && $user->rights->facture->creer && $object->statut ==
Facture::STATUS_DRAFT) {
4800 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>';
4803 print
'</tr></table>';
4805 $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime(
'-1 years', $object->date_lim_reglement);
4806 if ($object->date > $defaultDate) {
4807 $defaultDate = $object->date;
4812 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4813 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
4814 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4815 print
'<input name="retained_warranty_date_limit" type="date" step="1" min="'.dol_print_date($object->date,
'%Y-%m-%d').
'" value="'.
dol_print_date($defaultDate,
'%Y-%m-%d').
'" >';
4816 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4819 print
dol_print_date($object->retained_warranty_date_limit,
'day');
4828 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
4833 print
'<div class="fichehalfright">';
4835 print
'<!-- amounts -->'.
"\n";
4836 print
'<div class="underbanner clearboth"></div>'.
"\n";
4837 print
'<table class="border tableforfield centpercent">';
4840 if (!empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE_SCREEN) && $object->type == $object::TYPE_CREDIT_NOTE) {
4844 if (
isModEnabled(
'multicurrency') && ($object->multicurrency_code != $conf->currency)) {
4846 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
4847 print
'<td class="nowrap right amountcard">'.price($sign * $object->multicurrency_total_ht,
'', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
4851 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
4852 print
'<td class="nowrap right amountcard">'.price($sign * $object->multicurrency_total_tva,
'', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
4856 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
4857 print
'<td class="nowrap right amountcard">'.price($sign * $object->multicurrency_total_ttc,
'', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
4862 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
'AmountHT').
'</td>';
4863 print
'<td class="nowrap right amountcard">'.price($sign * $object->total_ht, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4866 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="3" class="nowrap right amountcard">'.
price($sign * $object->total_tva, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4870 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) {
4871 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
4872 print
'<td class="nowrap right amountcard">'.price($sign * $object->total_localtax1, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4874 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) {
4875 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
4876 print
'<td class="nowrap right amountcard">'.price($sign * $object->total_localtax2, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4880 if ($selleruserevenustamp) {
4882 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4883 print $langs->trans(
'RevenueStamp');
4885 if ($action !=
'editrevenuestamp' && !empty($object->brouillon) && $usercancreate) {
4886 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>';
4888 print
'</tr></table>';
4890 if ($action ==
'editrevenuestamp') {
4891 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
4892 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4893 print
'<input type="hidden" name="action" value="setrevenuestamp">';
4894 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num($object->revenuestamp).
'">';
4895 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
4896 print
' → <span id="revenuestamp_span"></span>';
4897 print
' <input type="submit" class="button buttongen button-save" value="'.$langs->trans(
'Modify').
'">';
4900 $(document).ready(function(){
4901 js_recalculate_revenuestamp();
4902 $('select[name=revenuestamp_type]').on('change',function(){
4903 js_recalculate_revenuestamp();
4906 function js_recalculate_revenuestamp(){
4907 var valselected = $('select[name=revenuestamp_type]').val();
4908 console.log('Calculate revenue stamp from '+valselected);
4910 if (valselected.indexOf('%') == -1)
4912 revenue = valselected;
4916 var revenue_type = parseFloat(valselected);
4917 var amount_net = ".round($object->total_ht, 2).
";
4918 revenue = revenue_type * amount_net / 100;
4919 revenue = revenue.toFixed(2);
4921 $('#revenuestamp_val').val(revenue);
4922 $('#revenuestamp_span').html(revenue);
4926 print
price($object->revenuestamp, 1,
'', 1, - 1, - 1, $conf->currency);
4932 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td class="nowrap right amountcard">'.
price($sign * $object->total_ttc, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4946 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
4949 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
4952 if ($selleruserevenustamp) {
4963 if (($object->situation_cycle_ref > 0) && !empty($conf->global->INVOICE_USE_SITUATION)) {
4964 print
'<!-- List of situation invoices -->';
4965 print
'<table class="noborder situationstable" width="100%">';
4967 print
'<tr class="liste_titre">';
4968 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
4970 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
4972 print
'<td class="right"></td>';
4974 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
4975 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
4976 print
'<td width="18"> </td>';
4979 $total_prev_ht = $total_prev_ttc = 0;
4980 $total_global_ht = $total_global_ttc = 0;
4982 if (count($object->tab_previous_situation_invoice) > 0) {
4985 $current_situation_counter = array();
4986 foreach ($object->tab_previous_situation_invoice as $prev_invoice) {
4987 $tmptotalpaidforthisinvoice = $prev_invoice->getSommePaiement();
4988 $total_prev_ht += $prev_invoice->total_ht;
4989 $total_prev_ttc += $prev_invoice->total_ttc;
4990 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ?-1 : 1) * $prev_invoice->situation_counter;
4991 print
'<tr class="oddeven">';
4992 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
4994 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
4996 print
'<td class="right"></td>';
4998 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
4999 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
5000 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).
'</td>';
5006 $total_global_ht += $total_prev_ht;
5007 $total_global_ttc += $total_prev_ttc;
5008 $total_global_ht += $object->total_ht;
5009 $total_global_ttc += $object->total_ttc;
5011 print
'<tr class="oddeven">';
5012 print
'<td>'.$object->getNomUrl(1).
'</td>';
5014 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$object->situation_counter.
'</td>';
5016 print
'<td class="right"></td>';
5018 print
'<td class="right"><span class="amount">'.price($object->total_ht).
'</span></td>';
5019 print
'<td class="right"><span class="amount">'.price($object->total_ttc).
'</span></td>';
5020 print
'<td class="right">'.$object->getLibStatut(3, $object->getSommePaiement()).
'</td>';
5024 print
'<tr class="oddeven">';
5025 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'CurrentSituationTotal').
'</b></td>';
5028 foreach ($current_situation_counter as $sit) {
5029 $curSign = $sit > 0 ?
'+' :
'-';
5030 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
5032 print
' '.$curSign.
' ';
5034 print $curType.abs($sit);
5041 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5042 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5043 print
'<td width="18"> </td>';
5047 if (count($object->tab_next_situation_invoice) > 0) {
5059 $total_next_ht = $total_next_ttc = 0;
5061 foreach ($object->tab_next_situation_invoice as $next_invoice) {
5062 $totalpaid = $next_invoice->getSommePaiement();
5063 $total_next_ht += $next_invoice->total_ht;
5064 $total_next_ttc += $next_invoice->total_ttc;
5066 print
'<tr class="oddeven">';
5067 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
5069 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
5071 print
'<td class="right"></td>';
5073 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
5074 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
5075 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid).
'</td>';
5079 $total_global_ht += $total_next_ht;
5080 $total_global_ttc += $total_next_ttc;
5082 print
'<tr class="oddeven">';
5083 print
'<td colspan="3" class="right"></td>';
5085 print
'<td class="right"></td>';
5087 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5088 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5089 print
'<td width="18"> </td>';
5097 if ($object->type == $object::TYPE_CREDIT_NOTE) {
5103 print
'<!-- List of payments already done -->';
5104 print
'<div class="div-table-responsive-no-min">';
5105 print
'<table class="noborder paymenttable centpercent">';
5107 print
'<tr class="liste_titre">';
5108 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
5109 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
5110 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
5112 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
5114 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
5115 print
'<td class="liste_titre" width="18"> </td>';
5119 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
5120 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
5121 $sql .=
' pf.amount,';
5122 $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';
5123 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
5124 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
5125 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
5126 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
5127 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id).
' AND pf.fk_paiement = p.rowid';
5128 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
5129 $sql .=
' ORDER BY p.datep, p.tms';
5131 $result = $db->query($sql);
5133 $num = $db->num_rows($result);
5138 $objp = $db->fetch_object($result);
5140 $paymentstatic->id = $objp->rowid;
5141 $paymentstatic->datepaye = $db->jdate($objp->dp);
5142 $paymentstatic->ref = $objp->ref;
5143 $paymentstatic->num_payment = $objp->num_payment;
5144 $paymentstatic->paiementcode = $objp->payment_code;
5146 print
'<tr class="oddeven"><td class="nowraponall">';
5147 print $paymentstatic->getNomUrl(1);
5150 $dateofpayment = $db->jdate($objp->dp);
5152 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
5158 $label = ($langs->trans(
"PaymentType".$objp->payment_code) != (
"PaymentType".$objp->payment_code)) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
5159 print
'<td>'.$label.
' '.$objp->num_payment.
'</td>';
5161 $bankaccountstatic->id = $objp->baid;
5162 $bankaccountstatic->ref = $objp->baref;
5163 $bankaccountstatic->label = $objp->baref;
5164 $bankaccountstatic->number = $objp->banumber;
5165 $bankaccountstatic->currency_code = $objp->bacurrency_code;
5168 $bankaccountstatic->account_number = $objp->account_number;
5171 $accountingjournal->fetch($objp->fk_accountancy_journal);
5172 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
5175 print
'<td class="nowraponall">';
5176 if ($bankaccountstatic->id) {
5177 print $bankaccountstatic->getNomUrl(1,
'transactions');
5181 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
5182 print
'<td class="center">';
5184 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
5201 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5202 print
'<span class="opacitymedium">';
5204 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
5206 print $langs->trans(
'AlreadyPaid');
5208 print
'</span></td><td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td><td> </td></tr>';
5210 $resteapayeraffiche = $resteapayer;
5211 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
5214 $creditnoteamount = 0;
5216 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
5217 $sql .=
" re.description, re.fk_facture_source";
5218 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
5219 $sql .=
" WHERE fk_facture = ".((int) $object->id);
5220 $resql = $db->query($sql);
5222 $num = $db->num_rows(
$resql);
5226 $obj = $db->fetch_object(
$resql);
5227 $invoice->fetch($obj->fk_facture_source);
5228 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5229 print
'<span class="opacitymedium">';
5231 print $langs->trans(
"CreditNote").
' ';
5234 print $langs->trans(
"Deposit").
' ';
5236 print $invoice->getNomUrl(0);
5239 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
5240 print
'<td class="right">';
5241 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">'.
img_delete().
'</a>';
5245 $creditnoteamount += $obj->amount_ttc;
5248 $depositamount += $obj->amount_ttc;
5257 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5258 print
'<span class="opacitymedium">';
5259 print
$form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
5261 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5262 $resteapayeraffiche = 0;
5263 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5267 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5268 print
'<span class="opacitymedium">';
5269 print
$form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
5271 print
'</td><td class="right">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td><td> </td></tr>';
5273 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5277 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5278 print
'<span class="opacitymedium">';
5279 print
$form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
5281 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5282 $resteapayeraffiche = 0;
5283 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5287 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5288 $text = $langs->trans(
"HelpAbandonOther");
5289 if ($object->close_note) {
5290 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.$object->close_note;
5292 print
'<span class="opacitymedium">';
5293 print
$form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
5295 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5296 $resteapayeraffiche = 0;
5297 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5301 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5302 print
'<span class="opacitymedium">';
5303 print $langs->trans(
"Billed");
5304 print
'</td><td class="right">'.price($object->total_ttc).
'</td><td> </td></tr>';
5306 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5307 print
'<span class="opacitymedium">';
5308 print $langs->trans(
'RemainderToPay');
5309 if ($resteapayeraffiche < 0) {
5310 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5314 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
5317 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
5318 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5319 print
'<span class="opacitymedium">';
5320 print $langs->trans(
'RemainderToPayMulticurrency');
5321 if ($resteapayeraffiche < 0) {
5322 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5326 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">';
5328 print
price(
price2num($object->multicurrency_tx*$resteapayeraffiche,
'MT'), 1, $langs, 1, -1, -1, (empty($object->multicurrency_code) ? $conf->currency : $object->multicurrency_code)).
'</td><td> </td></tr>';
5332 if (!empty($object->situation_final) && !empty($object->retained_warranty) && $displayWarranty) {
5335 $retainedWarranty = $total_global_ttc * $object->retained_warranty / 100;
5338 $retainedWarranty = $object->total_ttc * $object->retained_warranty / 100;
5341 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
5343 print
'<tr><td colspan="'.$nbcols.
'" align="right">'.$langs->trans(
"ToPayOn",
dol_print_date($object->date_lim_reglement,
'day')).
' :</td><td align="right">'.
price($billedWithRetainedWarranty).
'</td><td> </td></tr>';
5346 print
'<tr><td colspan="'.$nbcols.
'" align="right">';
5347 print $langs->trans(
"RetainedWarranty").
' ('.$object->retained_warranty.
'%)';
5348 print !empty($object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date($object->retained_warranty_date_limit,
'day')) :
'';
5349 print
' :</td><td align="right">'.price($retainedWarranty).
'</td><td> </td></tr>';
5352 $resteapayeraffiche = $resteapayer;
5353 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5356 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5357 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
5358 print
'</td><td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td><td> </td></tr>';
5361 print
'<tr><td colspan="'.$nbcols.
'" class="right"><span class="opacitymedium">'.$langs->trans(
"Billed").
'</span></td><td class="right">'.
price($sign * $object->total_ttc).
'</td><td> </td></tr>';
5364 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5365 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
5366 if ($resteapayeraffiche > 0) {
5367 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5369 print
'</span></td>';
5370 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
5371 print
'<td class="nowrap"> </td></tr>';
5374 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
5375 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5376 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
5377 if ($resteapayeraffiche > 0) {
5378 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5382 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.(!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency).
' '.
price(
price2num($sign * $object->multicurrency_tx * $resteapayeraffiche,
'MT')).
'</td><td> </td></tr>';
5396 $formmargin->displayMarginInfos($object);
5402 print
'<div class="clearboth"></div><br><br>';
5404 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
5405 $blocname =
'contacts';
5406 $title = $langs->trans(
'ContactsAddresses');
5407 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5410 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
5411 $blocname =
'notes';
5412 $title = $langs->trans(
'Notes');
5413 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5417 $result = $object->getLinesArray();
5421 global $inputalsopricewithtax;
5422 $inputalsopricewithtax = 1;
5425 if (!empty($conf->global->INVOICE_USE_SITUATION)) {
5426 if ($object->situation_cycle_ref && $object->statut == 0) {
5427 print
'<!-- Area to change globally the situation percent -->'.
"\n";
5428 print
'<div class="div-table-responsive">';
5430 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'#updatealllines" method="POST">';
5431 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
5432 print
'<input type="hidden" name="action" value="updatealllines" />';
5433 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
5435 print
'<table id="tablelines_all_progress" class="noborder noshadow" width="100%">';
5437 print
'<tr class="liste_titre nodrag nodrop">';
5440 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
5441 print
'<td align="center" width="5"> </td>';
5443 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
5444 print
'<td class="right">'.$langs->trans(
'Progress').
'</td>';
5445 print
'<td> </td>';
5448 print
'<tr class="nodrag nodrop">';
5450 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
5451 print
'<td align="center" width="5"> </td>';
5453 print
'<td> </td>';
5454 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
5455 print
'<td class="right"><input type="submit" class="button" name="all_percent" value="Modifier" /></td>';
5466 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">
5467 <input type="hidden" name="token" value="' .
newToken().
'">
5468 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
5469 <input type="hidden" name="mode" value="">
5470 <input type="hidden" name="page_y" value="">
5471 <input type="hidden" name="id" value="' . $object->id.
'">
5474 if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
5475 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
5478 print
'<div class="div-table-responsive-no-min">';
5479 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
5482 if (!empty($object->lines)) {
5483 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
5487 if ($object->statut == 0 && $usercancreate && $action !=
'valid' && $action !=
'editline') {
5488 if ($action !=
'editline' && $action !=
'selectlines') {
5492 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
5493 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
5494 if (empty($reshook))
5495 $object->formAddObjectLine(1, $mysoc, $soc);
5509 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
5510 print
'<div class="tabsAction">';
5513 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
5514 if (empty($reshook)) {
5517 'class' =>
'classfortooltip'
5523 $ventilExportCompta = $object->getVentilExportCompta();
5525 if ($ventilExportCompta == 0) {
5526 if (!empty($conf->global->INVOICE_CAN_BE_EDITED_EVEN_IF_PAYMENT_DONE) || ($resteapayer ==
price2num($object->total_ttc,
'MT', 1) && empty($object->paye))) {
5527 if (!$objectidnext && $object->is_last_in_cycle()) {
5528 if ($usercanunvalidate) {
5529 $params[
'attr'][
'title'] =
'';
5530 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=modif&token='.
newToken(),
'',
true, $params);
5532 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
5533 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=modif&token='.
newToken(),
'',
false, $params);
5535 } elseif (!$object->is_last_in_cycle()) {
5536 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
5537 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5539 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
5540 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5544 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5545 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5550 $result = $discount->fetch(0, $object->id);
5558 && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || $usercanreopen)) {
5559 if ($object->close_code !=
'replaced' || (!$objectidnext)) {
5560 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
5562 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
5563 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
5568 if (!empty($conf->global->CONTRACT_CREATE_FROM_INVOICE)) {
5570 $langs->load(
"contracts");
5572 if ($usercancreatecontract) {
5573 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>';
5580 if ($usercanvalidate) {
5581 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
5586 if (empty($user->socid)) {
5588 if ($objectidnext) {
5589 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'SendMail').
'</span>';
5592 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
5594 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
5602 if ($resteapayer > 0) {
5603 if ($usercancreatewithdrarequest) {
5604 if (!$objectidnext && $object->close_code !=
'replaced') {
5605 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>';
5607 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
5618 if (
isModEnabled(
'takepos') && $object->module_source ==
'takepos') {
5619 $langs->load(
"cashdesk");
5620 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
5621 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int) $object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
5626 if ($objectidnext) {
5627 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
5631 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
5632 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
5636 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default', DOL_URL_ROOT.
'/compta/paiement.php?facid='.$object->id.
'&action=create&accountid='.$object->fk_account,
'',
true, $params);
5641 $sumofpayment = $totalpaid;
5642 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
5648 if ($resteapayer == 0) {
5649 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
5651 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.$object->id.
'&action=create&accountid='.$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
5657 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
5661 && (!empty($conf->global->INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) || $sumofpayment == 0)
5663 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc" title="'.
dol_escape_htmltag($langs->trans(
"ConfirmConvertToReduc2")).
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
5669 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertToReduc').
'</a>';
5671 print
'<span class="butActionRefused" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
5685 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
5686 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
5688 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=paid',
'',
true, $params);
5693 if ($object->statut ==
Facture::STATUS_VALIDATED && $object->paye == 0 && $resteapayer > 0 && (empty($conf->global->INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $resteapayer != $object->total_ttc) && $usercanissuepayment) {
5694 if ($totalpaid > 0 || $totalcreditnotes > 0) {
5696 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
5698 if (empty($conf->global->INVOICE_CAN_NEVER_BE_CANCELED)) {
5699 if ($objectidnext) {
5700 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
5702 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
5710 if (!$objectidnext) {
5711 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>';
5718 && ($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
5721 && $object->is_last_in_cycle()
5724 if ($usercanunvalidate) {
5725 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>';
5727 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
5733 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=clone&object=invoice',
'',
true, $params);
5738 if (!$objectidnext && count($object->lines) > 0) {
5739 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$object->id.
'&action=create',
'',
true, $params);
5748 && $object->situation_counter > 1
5749 && $object->is_last_in_cycle()
5750 && $usercanunvalidate
5752 if (($object->total_ttc - $totalcreditnotes) == 0) {
5753 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
5755 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
5760 if ($usercancreate && ($object->type == 5) && ($object->statut == 1 || $object->statut == 2)) {
5761 if ($object->is_last_in_cycle() && $object->situation_final != 1) {
5762 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.$object->id.
'&socid='.$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5763 } elseif (!$object->is_last_in_cycle()) {
5764 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5766 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5771 $isErasable = $object->is_erasable();
5774 'class' =>
'classfortooltip'
5777 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
5778 $enableDelete =
false;
5781 if ($isErasable == -4) {
5782 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
5783 } elseif ($isErasable == -3) {
5784 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
5785 } elseif ($isErasable == -2) {
5786 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
5787 } elseif ($isErasable == -1) {
5788 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5789 } elseif ($isErasable <= 0) {
5790 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable');
5791 } elseif ($objectidnext) {
5792 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
5794 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=delete&token='.
newToken();
5795 $enableDelete =
true;
5797 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
5799 print
dolGetButtonAction($langs->trans(
'Delete'), $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
5806 if (
GETPOST(
'modelselected',
'alpha')) {
5807 $action =
'presend';
5809 if ($action !=
'prerelance' && $action !=
'presend') {
5810 print
'<div class="fichecenter"><div class="fichehalfleft">';
5811 print
'<a name="builddoc"></a>';
5815 $filedir = $conf->facture->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($object->ref);
5816 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.$object->id;
5817 $genallowed = $usercanread;
5818 $delallowed = $usercancreate;
5820 print $formfile->showdocuments(
5840 'remove_file_comfirm'
5843 $somethingshown = $formfile->numoffiles;
5846 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'invoice'));
5848 $compatibleImportElementsList =
false;
5852 $compatibleImportElementsList = array(
'commande',
'propal');
5854 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
5861 print
'<br><!-- Link to pay -->'.
"\n";
5862 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
5863 print showOnlinePaymentUrl(
'invoice', $object->ref).
'<br>';
5866 print
'</div><div class="fichehalfright">';
5869 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
5871 $somethingshown =
$formactions->showactions($object,
'invoice', $socid, 1);
5873 print
'</div></div>';
5878 $modelmail =
'facture_send';
5879 $defaulttopic =
'SendBillRef';
5880 $diroutput = $conf->facture->multidir_output[$object->entity];
5881 $trackid =
'inv'.$object->id;
5883 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage bank accounts.
Class to manage accounting accounts.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage shipments.
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.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage notifications.
Class to manage payments of customer invoices.
Class ProductCombination Used to represent a product combination.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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...
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
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.
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
$formconfirm
if ($action == 'delbookkeepingyear') {
div float
Buy price without taxes.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array='', $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
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.