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 $backtopage =
GETPOST(
'backtopage',
'alpha');
91 $lineid =
GETPOST(
'lineid',
'int');
92 $userid =
GETPOST(
'userid',
'int');
93 $search_ref =
GETPOST(
'sf_ref',
'alpha') ?
GETPOST(
'sf_ref',
'alpha') :
GETPOST(
'search_ref',
'alpha');
94 $search_societe =
GETPOST(
'search_societe',
'alpha');
95 $search_montant_ht =
GETPOST(
'search_montant_ht',
'alpha');
96 $search_montant_ttc =
GETPOST(
'search_montant_ttc',
'alpha');
97 $origin =
GETPOST(
'origin',
'alpha');
99 $fac_rec =
GETPOST(
'fac_rec',
'int');
100 $facid =
GETPOST(
'facid',
'int');
101 $ref_client =
GETPOST(
'ref_client',
'int');
102 $rank = (
GETPOST(
'rank',
'int') > 0) ?
GETPOST(
'rank',
'int') : -1;
103 $projectid = (
GETPOST(
'projectid',
'int') ?
GETPOST(
'projectid',
'int') : 0);
106 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
107 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
108 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
113 $usehm = (!empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : 0);
119 $extrafields->fetch_name_optionals_label($object->table_element);
122 if ($id > 0 || !empty($ref)) {
123 if ($action !=
'add') {
124 if (empty($conf->global->INVOICE_USE_SITUATION)) {
125 $fetch_situation =
false;
127 $fetch_situation =
true;
129 $ret = $object->fetch($id, $ref,
'',
'', $fetch_situation);
134 $hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
137 $usercanread = $user->hasRight(
"facture",
"lire");
138 $usercancreate = $user->hasRight(
"facture",
"creer");
139 $usercanissuepayment = $user->hasRight(
"facture",
"paiement");
140 $usercandelete = $user->hasRight(
"facture",
"supprimer");
141 $usercancreatecontract = $user->hasRight(
"contrat",
"creer");
144 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->validate)));
145 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->send)));
146 $usercanreopen = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->reopen)));
147 if (!empty($conf->global->INVOICE_DISALLOW_REOPEN)) {
148 $usercanreopen =
false;
150 $usercanunvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->unvalidate)));
152 $usermustrespectpricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
153 $usercancreatemargin = (!empty($user->rights->margins->creer) ? $user->rights->margins->creer : 0);
154 $usercanreadallmargin = (!empty($user->rights->margins->liretous) ? $user->rights->margins->liretous : 0);
155 $usercancreatewithdrarequest = (!empty($user->rights->prelevement->bons->creer) ? $user->rights->prelevement->bons->creer : 0);
157 $permissionnote = $usercancreate;
158 $permissiondellink = $usercancreate;
159 $permissiontoedit = $usercancreate;
160 $permissiontoadd = $usercancreate;
163 $retainedWarrantyInvoiceAvailableType = array();
164 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
165 $retainedWarrantyInvoiceAvailableType = explode(
'+', $conf->global->INVOICE_USE_RETAINED_WARRANTY);
170 $socid = $user->socid;
174 $result =
restrictedArea($user,
'facture', $object->id,
'',
'',
'fk_soc',
'rowid', $isdraft);
182 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
187 if (empty($reshook)) {
188 $backurlforlist = DOL_URL_ROOT.
'/compta/facture/list.php';
190 if (empty($backtopage) || ($cancel && empty($id))) {
191 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
192 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
193 $backtopage = $backurlforlist;
195 $backtopage = DOL_URL_ROOT.
'/compta/facture/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
201 if (!empty($backtopageforcancel)) {
202 header(
"Location: ".$backtopageforcancel);
204 } elseif (!empty($backtopage)) {
205 header(
"Location: ".$backtopage);
211 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
213 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
215 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
218 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
222 $objectutil->socid = $socid;
223 $result = $objectutil->createFromClone($user, $id);
225 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?facid='.$result);
228 $langs->load(
"errors");
232 } elseif ($action ==
'reopen' && $usercanreopen) {
233 $result = $object->fetch($id);
236 $result = $object->setUnpaid($user);
238 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
244 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
246 $result = $object->fetch($id);
247 $object->fetch_thirdparty();
249 $idwarehouse =
GETPOST(
'idwarehouse');
251 $qualified_for_stock_change = 0;
252 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
253 $qualified_for_stock_change = $object->hasProductsOrServices(2);
255 $qualified_for_stock_change = $object->hasProductsOrServices(1);
258 $isErasable = $object->is_erasable();
260 if (($usercandelete && $isErasable > 0)
261 || ($usercancreate && $isErasable == 1)) {
262 $result = $object->delete($user, 0, $idwarehouse);
264 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
271 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
274 $object->fetch_thirdparty();
276 $result = $object->deleteline(
GETPOST(
'lineid',
'int'));
279 $object->line_order(
true);
281 $outputlangs = $langs;
287 $newlang = $object->thirdparty->default_lang;
289 if (!empty($newlang)) {
291 $outputlangs->setDefaultLang($newlang);
292 $outputlangs->load(
'products');
294 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
295 $ret = $object->fetch($id);
296 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
299 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
306 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
309 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
310 $discount->unlink_invoice();
311 } elseif ($action ==
'valid' && $usercancreate) {
315 if (!empty($conf->global-> INVOICE_CHECK_POSTERIOR_DATE)) {
316 $last_of_type = $object->willBeLastOfSameType(
true);
317 if (empty($object->date_validation) && !$last_of_type[0]) {
326 if ($object->total_ht >= 0) {
327 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
335 if (empty($conf->global->FACTURE_ENABLE_NEGATIVE) && $object->total_ttc < 0) {
336 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
345 $array_of_total_ht_per_vat_rate = array();
346 $array_of_total_ht_devise_per_vat_rate = array();
347 foreach ($object->lines as $line) {
349 $vat_src_code_for_line =
'';
350 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
351 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
353 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
354 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
356 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
357 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
361 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
362 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
363 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
365 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
366 if ($object->type == $object::TYPE_DEPOSIT) {
367 $langs->load(
"errors");
369 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
373 $tmpvatratetoshow = explode(
'_', $vatrate);
374 $tmpvatratetoshow[0] = round($tmpvatratetoshow[0], 2);
376 if ($tmpvatratetoshow[0] != 0) {
377 $langs->load(
"errors");
378 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", $tmpvatratetoshow[0]),
null,
'errors');
386 } elseif ($action ==
'classin' && $usercancreate) {
388 $object->setProject(
GETPOST(
'projectid',
'int'));
389 } elseif ($action ==
'setmode' && $usercancreate) {
391 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
395 } elseif ($action ==
'setretainedwarrantyconditions' && $user->hasRight(
'facture',
'creer')) {
397 $object->retained_warranty_fk_cond_reglement = 0;
398 $result = $object->setRetainedWarrantyPaymentTerms(
GETPOST(
'retained_warranty_fk_cond_reglement',
'int'));
403 $old_rw_date_lim_reglement = $object->retained_warranty_date_limit;
404 $new_rw_date_lim_reglement = $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement);
405 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
406 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
408 if ($object->retained_warranty_date_limit < $object->date) {
409 $object->retained_warranty_date_limit = $object->date;
411 $result = $object->update($user);
415 } elseif ($action ==
'setretainedwarranty' && $user->hasRight(
'facture',
'creer')) {
417 $result = $object->setRetainedWarranty(
GETPOST(
'retained_warranty',
'float'));
421 } elseif ($action ==
'setretainedwarrantydatelimit' && $user->hasRight(
'facture',
'creer')) {
423 $result = $object->setRetainedWarrantyDateLimit(
GETPOST(
'retained_warranty_date_limit',
'float'));
427 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
428 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
429 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
430 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
431 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
433 $old_date_lim_reglement = $object->date_lim_reglement;
435 if (empty($newdate)) {
436 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
437 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id.
'&action=editinvoicedate&token='.
newToken());
440 if ($newdate > (
dol_now(
'tzuserrel') + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
441 if (empty($conf->global->INVOICE_MAX_FUTURE_DELAY)) {
442 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
444 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
448 $object->date = $newdate;
449 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
450 if ($new_date_lim_reglement > $old_date_lim_reglement) {
451 $object->date_lim_reglement = $new_date_lim_reglement;
453 if ($object->date_lim_reglement < $object->date) {
454 $object->date_lim_reglement = $object->date;
456 $result = $object->update($user);
460 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
463 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
465 $object->date_pointoftax = $date_pointoftax;
466 $result = $object->update($user);
470 } elseif ($action ==
'setconditions' && $usercancreate) {
472 $object->cond_reglement_code = 0;
473 $object->cond_reglement_id = 0;
480 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
488 $old_date_lim_reglement = $object->date_lim_reglement;
489 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
490 if ($new_date_lim_reglement > $old_date_lim_reglement) {
491 $object->date_lim_reglement = $new_date_lim_reglement;
493 if ($object->date_lim_reglement < $object->date) {
494 $object->date_lim_reglement = $object->date;
496 $result = $object->update($user);
508 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
510 $object->date_lim_reglement =
dol_mktime(12, 0, 0,
GETPOST(
'paymenttermmonth',
'int'),
GETPOST(
'paymenttermday',
'int'),
GETPOST(
'paymenttermyear',
'int'));
511 if ($object->date_lim_reglement < $object->date) {
512 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
513 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
515 $result = $object->update($user);
519 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
521 $object->revenuestamp =
GETPOST(
'revenuestamp');
522 $result = $object->update($user);
523 $object->update_price(1);
528 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
529 $outputlangs = $langs;
532 $newlang =
GETPOST(
'lang_id',
'aZ09');
535 $newlang = $object->thirdparty->default_lang;
537 if (!empty($newlang)) {
539 $outputlangs->setDefaultLang($newlang);
540 $outputlangs->load(
'products');
542 $model = $object->model_pdf;
543 $ret = $object->fetch($id);
545 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
551 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm')) {
552 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
553 } elseif ($action ==
'setbankaccount' && $usercancreate) {
554 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
555 } elseif ($action ==
'setremisepercent' && $usercancreate) {
557 $result = $object->setDiscount($user,
price2num(
GETPOST(
'remise_percent'),
'', 2));
558 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
563 if (
GETPOST(
"remise_id",
'int') > 0) {
564 $ret = $object->fetch($id);
566 $result = $object->insert_discount(
GETPOST(
"remise_id",
'int'));
576 if (
GETPOST(
"remise_id_for_payment",
'int') > 0) {
577 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
579 $discount->fetch(
GETPOST(
"remise_id_for_payment",
'int'));
583 $remaintopay = $object->getRemainToPay(0);
587 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
591 $result = $discount->link_to_invoice(0, $id);
599 $newremaintopay = $object->getRemainToPay(0);
600 if ($newremaintopay == 0) {
601 $object->setPaid($user);
612 if (empty($error) && empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
613 $outputlangs = $langs;
616 $newlang =
GETPOST(
'lang_id',
'aZ09');
619 $newlang = $object->thirdparty->default_lang;
621 if (!empty($newlang)) {
623 $outputlangs->setDefaultLang($newlang);
625 $ret = $object->fetch($id);
627 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
632 } elseif ($action ==
'setref' && $usercancreate) {
634 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'',
null,
'',
'', $user,
'BILL_MODIFY');
635 } elseif ($action ==
'setref_client' && $usercancreate) {
637 $object->set_ref_client(
GETPOST(
'ref_client'));
638 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
640 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
643 $object->fetch_thirdparty();
647 $qualified_for_stock_change = 0;
648 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
649 $qualified_for_stock_change = $object->hasProductsOrServices(2);
651 $qualified_for_stock_change = $object->hasProductsOrServices(1);
654 if ($qualified_for_stock_change) {
655 if (!$idwarehouse || $idwarehouse == - 1) {
657 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
664 $result = $object->validate($user,
'', $idwarehouse);
667 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
668 $outputlangs = $langs;
671 $newlang =
GETPOST(
'lang_id',
'aZ09');
674 $newlang = $object->thirdparty->default_lang;
676 if (!empty($newlang)) {
678 $outputlangs->setDefaultLang($newlang);
679 $outputlangs->load(
'products');
681 $model = $object->model_pdf;
683 $ret = $object->fetch($id);
685 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
691 if (count($object->errors)) {
698 } elseif ($action ==
'confirm_modif' && $usercanunvalidate) {
700 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
703 $object->fetch_thirdparty();
707 $qualified_for_stock_change = 0;
708 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
709 $qualified_for_stock_change = $object->hasProductsOrServices(2);
711 $qualified_for_stock_change = $object->hasProductsOrServices(1);
714 if ($qualified_for_stock_change) {
715 if (!$idwarehouse || $idwarehouse == - 1) {
717 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
725 $sql =
'SELECT pf.amount';
726 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf';
727 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id);
729 $result = $db->query(
$sql);
732 $num = $db->num_rows($result);
735 $objp = $db->fetch_object($result);
736 $totalpaid += $objp->amount;
743 $resteapayer = $object->total_ttc - $totalpaid;
746 $ventilExportCompta = $object->getVentilExportCompta();
749 if ($ventilExportCompta == 0) {
750 if (!empty($conf->global->INVOICE_CAN_BE_EDITED_EVEN_IF_PAYMENT_DONE) || ($resteapayer == $object->total_ttc && empty($object->paye))) {
751 $result = $object->setDraft($user, $idwarehouse);
757 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
758 $outputlangs = $langs;
761 $newlang =
GETPOST(
'lang_id',
'aZ09');
764 $newlang = $object->thirdparty->default_lang;
766 if (!empty($newlang)) {
768 $outputlangs->setDefaultLang($newlang);
769 $outputlangs->load(
'products');
771 $model = $object->model_pdf;
772 $ret = $object->fetch($id);
774 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
779 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
782 $result = $object->setPaid($user);
786 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
789 $close_code =
GETPOST(
"close_code",
'restricthtml');
790 $close_note =
GETPOST(
"close_note",
'restricthtml');
792 $result = $object->setPaid($user, $close_code, $close_note);
797 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
799 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes') {
802 $close_code =
GETPOST(
"close_code",
'restricthtml');
803 $close_note =
GETPOST(
"close_note",
'restricthtml');
805 $result = $object->setCanceled($user, $close_code, $close_note);
810 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
812 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
815 $object->fetch_thirdparty();
820 $result = $discountcheck->fetch(0, $object->id);
833 $amount_ht = $amount_tva = $amount_ttc = array();
834 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
838 foreach ($object->lines as $line) {
839 if ($line->product_type < 9 && $line->total_ht != 0) {
840 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
842 $amount_ht[$keyforvatrate] += $line->total_ht;
843 $amount_tva[$keyforvatrate] += $line->total_tva;
844 $amount_ttc[$keyforvatrate] += $line->total_ttc;
845 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
846 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
847 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
853 if (!empty($conf->global->INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) && $object->type ==
Facture::TYPE_CREDIT_NOTE) {
854 $alreadypaid = $object->getSommePaiement();
855 if ($alreadypaid && abs($alreadypaid) < abs($object->total_ttc)) {
856 $ratio = abs(($object->total_ttc - $alreadypaid) / $object->total_ttc);
857 foreach ($amount_ht as $vatrate => $val) {
858 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
859 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
860 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
861 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
862 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
863 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
872 $discount->description =
'(CREDIT_NOTE)';
874 $discount->description =
'(DEPOSIT)';
876 $discount->description =
'(EXCESS RECEIVED)';
878 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
880 $discount->fk_soc = $object->socid;
881 $discount->fk_facture_source = $object->id;
889 $sql =
'SELECT SUM(pf.amount) as total_paiements';
890 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
891 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
892 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id);
893 $sql .=
' AND pf.fk_paiement = p.rowid';
894 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
895 $resql = $db->query(
$sql);
900 $res = $db->fetch_object($resql);
901 $total_paiements = $res->total_paiements;
904 $total_creditnote_and_deposit = 0;
905 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
906 $sql .=
" re.description, re.fk_facture_source";
907 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
908 $sql .=
" WHERE fk_facture = ".((int) $object->id);
909 $resql = $db->query(
$sql);
910 if (!empty($resql)) {
911 while ($obj = $db->fetch_object($resql)) {
912 $total_creditnote_and_deposit += $obj->amount_ttc;
918 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object->total_ttc;
919 $discount->amount_tva = 0;
920 $discount->tva_tx = 0;
921 $discount->vat_src_code =
'';
923 $result = $discount->create($user);
929 foreach ($amount_ht as $tva_tx => $xxx) {
930 $discount->amount_ht = abs($amount_ht[$tva_tx]);
931 $discount->amount_tva = abs($amount_tva[$tva_tx]);
932 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
933 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
934 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
935 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
940 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
941 $vat_src_code = $reg[1];
942 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
945 $discount->tva_tx = abs($tva_tx);
946 $discount->vat_src_code = $vat_src_code;
948 $result = $discount->create($user);
959 $result = $object->setPaid($user);
974 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
979 $result = $paiement->fetch(
GETPOST(
'paiement_id',
'int'));
981 $result = $paiement->delete();
983 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
991 } elseif ($action ==
'add' && $usercancreate) {
994 $object->socid =
GETPOST(
'socid',
'int');
996 $selectedLines =
GETPOST(
'toselect',
'array');
998 if (
GETPOST(
'type',
'int') ===
'') {
999 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1005 $originentity =
GETPOST(
'originentity');
1007 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1013 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
1017 if (empty($dateinvoice)) {
1019 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1021 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1027 if (!(
GETPOST(
'fac_replacement',
'int') > 0)) {
1029 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1035 $result = $object->fetch(
GETPOST(
'fac_replacement',
'int'));
1036 $object->fetch_thirdparty();
1038 $object->date = $dateinvoice;
1039 $object->date_pointoftax = $date_pointoftax;
1040 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1041 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1042 $object->ref_client =
GETPOST(
'ref_client',
'alphanohtml');
1043 $object->model_pdf =
GETPOST(
'model',
'alphanohtml');
1044 $object->fk_project =
GETPOST(
'projectid',
'int');
1045 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1046 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1047 $object->fk_account =
GETPOST(
'fk_account',
'int');
1050 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1051 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1052 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1053 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1056 $object->fk_facture_source =
GETPOST(
'fac_replacement',
'int');
1059 $id = $object->createFromCurrent($user);
1068 $sourceinvoice =
GETPOST(
'fac_avoir',
'int');
1069 if (!($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
1071 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1075 if (empty($dateinvoice)) {
1077 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1079 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1086 if (!empty($originentity)) {
1087 $object->entity = $originentity;
1089 $object->socid =
GETPOST(
'socid',
'int');
1090 $object->ref =
GETPOST(
'ref');
1091 $object->date = $dateinvoice;
1092 $object->date_pointoftax = $date_pointoftax;
1093 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1094 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1095 $object->ref_client =
GETPOST(
'ref_client');
1096 $object->model_pdf =
GETPOST(
'model');
1097 $object->fk_project =
GETPOST(
'projectid',
'int');
1098 $object->cond_reglement_id = 0;
1099 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1100 $object->fk_account =
GETPOST(
'fk_account',
'int');
1103 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1104 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1105 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1106 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1109 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1112 $facture_source =
new Facture($db);
1113 if ($facture_source->fetch($object->fk_facture_source) > 0) {
1115 $object->situation_counter = $facture_source->situation_counter;
1116 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1117 $facture_source->fetchPreviousNextSituationInvoice();
1122 $id = $object->create($user);
1127 if ($object->copy_linked_contact($facture_source,
'internal') < 0) {
1129 } elseif ($facture_source->socid == $object->socid) {
1131 if ($object->copy_linked_contact($facture_source,
'external') < 0) {
1142 if (
GETPOST(
'invoiceAvoirWithLines',
'int') == 1 && $id > 0) {
1143 if (!empty($facture_source->lines)) {
1144 $fk_parent_line = 0;
1146 foreach ($facture_source->lines as $line) {
1148 if (method_exists($line,
'fetch_optionals')) {
1150 $line->fetch_optionals();
1154 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1155 $fk_parent_line = 0;
1160 $source_fk_prev_id = $line->fk_prev_id;
1161 $line->fk_prev_id = $line->id;
1163 if (!empty($facture_source->tab_previous_situation_invoice)) {
1166 $tab_jumped_credit_notes = array();
1167 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1168 $searchPreviousInvoice =
true;
1169 while ($searchPreviousInvoice) {
1170 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1171 $searchPreviousInvoice =
false;
1175 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1181 $maxPrevSituationPercent = 0;
1182 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1183 if ($prevLine->id == $source_fk_prev_id) {
1184 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1187 $line->total_ht = $line->total_ht - $prevLine->total_ht;
1188 $line->total_tva = $line->total_tva - $prevLine->total_tva;
1189 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
1190 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
1191 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
1193 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
1194 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
1195 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
1196 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
1201 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1206 $maxPrevSituationPercent = 0;
1207 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1208 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1209 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1210 $maxPrevSituationPercent = $prevLine->situation_percent;
1212 $line->total_ht -= $prevLine->total_ht;
1213 $line->total_tva -= $prevLine->total_tva;
1214 $line->total_ttc -= $prevLine->total_ttc;
1215 $line->total_localtax1 -= $prevLine->total_localtax1;
1216 $line->total_localtax2 -= $prevLine->total_localtax2;
1218 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1219 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1220 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1221 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1227 $line->situation_percent += $maxPrevSituationPercent;
1233 $line->fk_facture = $object->id;
1234 $line->fk_parent_line = $fk_parent_line;
1236 $line->subprice = -$line->subprice;
1237 $line->pa_ht = $line->pa_ht;
1238 $line->total_ht = -$line->total_ht;
1239 $line->total_tva = -$line->total_tva;
1240 $line->total_ttc = -$line->total_ttc;
1241 $line->total_localtax1 = -$line->total_localtax1;
1242 $line->total_localtax2 = -$line->total_localtax2;
1244 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1245 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1246 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1247 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1249 $line->context[
'createcreditnotefrominvoice'] = 1;
1250 $result = $line->insert(0, 1);
1252 $object->lines[] = $line;
1255 if ($result > 0 && $line->product_type == 9) {
1256 $fk_parent_line = $result;
1260 $object->update_price(1);
1264 if (
GETPOST(
'invoiceAvoirWithPaymentRestAmount',
'int') == 1 && $id > 0) {
1265 if ($facture_source->fetch($object->fk_facture_source) > 0) {
1266 $totalpaid = $facture_source->getSommePaiement();
1267 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1268 $totaldeposits = $facture_source->getSumDepositsUsed();
1269 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1271 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 1, 0, 0, 0, 0, 0,
'',
'',
'TTC');
1276 if (!empty($object->fk_facture_source) && $id > 0) {
1277 $facture_source->fetch($object->fk_facture_source);
1278 $facture_source->fetchObjectLinked();
1280 if (!empty($facture_source->linkedObjectsIds)) {
1281 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1282 $object->add_object_linked($sourcetype, current($TIds));
1291 if (empty($dateinvoice)) {
1293 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1295 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1302 $object->socid =
GETPOST(
'socid',
'int');
1303 $object->type =
GETPOST(
'type');
1304 $object->ref =
GETPOST(
'ref');
1305 $object->date = $dateinvoice;
1306 $object->date_pointoftax = $date_pointoftax;
1307 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1308 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1309 $object->ref_customer =
GETPOST(
'ref_client');
1310 $object->ref_client = $object->ref_customer;
1311 $object->model_pdf =
GETPOST(
'model');
1312 $object->fk_project =
GETPOST(
'projectid',
'int');
1313 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
1314 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1315 $object->fk_account =
GETPOST(
'fk_account',
'int');
1319 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1320 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1321 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1322 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1325 $object->fac_rec =
GETPOST(
'fac_rec',
'int');
1327 $id = $object->create($user);
1333 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1334 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1335 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1337 if (
GETPOST(
'socid',
'int') < 1) {
1339 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1343 if (empty($dateinvoice)) {
1345 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1347 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1355 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1356 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1361 if ($typeamount && !empty($origin) && !empty($originid)) {
1362 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1363 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1367 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1368 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1372 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1373 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1382 $object->socid =
GETPOST(
'socid',
'int');
1383 $object->type =
GETPOST(
'type');
1384 $object->ref =
GETPOST(
'ref');
1385 $object->date = $dateinvoice;
1386 $object->date_pointoftax = $date_pointoftax;
1387 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1388 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1389 $object->ref_client =
GETPOST(
'ref_client');
1390 $object->ref_customer =
GETPOST(
'ref_client');
1391 $object->model_pdf =
GETPOST(
'model');
1392 $object->fk_project =
GETPOST(
'projectid',
'int');
1393 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
1394 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
1395 $object->fk_account =
GETPOST(
'fk_account',
'int');
1399 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1400 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1401 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1402 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1405 $object->situation_counter = 1;
1406 $object->situation_final = 0;
1407 $object->situation_cycle_ref = $object->newCycle();
1410 if (in_array($object->type, $retainedWarrantyInvoiceAvailableType)) {
1411 $object->retained_warranty =
GETPOST(
'retained_warranty',
'int');
1412 $object->retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
1414 $object->retained_warranty = 0;
1415 $object->retained_warranty_fk_cond_reglement = 0;
1418 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1419 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1420 $object->retained_warranty_date_limit =
dol_stringtotime($retained_warranty_date_limit);
1422 $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);
1424 $object->fetch_thirdparty();
1427 if (!empty($origin) && !empty($originid)) {
1430 $element = $subelement = $origin;
1431 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1432 $element = $regs[1];
1433 $subelement = $regs[2];
1437 if ($element ==
'order') {
1438 $element = $subelement =
'commande';
1440 if ($element ==
'propal') {
1441 $element =
'comm/propal';
1442 $subelement =
'propal';
1444 if ($element ==
'contract') {
1445 $element = $subelement =
'contrat';
1447 if ($element ==
'inter') {
1448 $element = $subelement =
'ficheinter';
1450 if ($element ==
'shipping') {
1451 $element = $subelement =
'expedition';
1454 $object->origin = $origin;
1455 $object->origin_id = $originid;
1458 $object->linked_objects[$object->origin] = $object->origin_id;
1460 if ($object->origin ==
'shipping') {
1461 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1463 $exp->fetch($object->origin_id);
1464 $exp->fetchObjectLinked();
1465 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1466 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1467 $object->linked_objects[
'commande'] = $value;
1472 if (is_array($_POST[
'other_linked_objects']) && !empty($_POST[
'other_linked_objects'])) {
1473 $object->linked_objects = array_merge($object->linked_objects, $_POST[
'other_linked_objects']);
1476 $id = $object->create($user);
1481 $classname = ucfirst($subelement);
1482 $srcobject =
new $classname($db);
1484 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines or deposit lines");
1485 $result = $srcobject->fetch($object->origin_id);
1490 $amountdeposit = array();
1491 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)) {
1492 if ($typeamount ==
'amount') {
1493 $amount = $valuedeposit;
1495 $amount = $srcobject->total_ttc * ($valuedeposit / 100);
1498 $TTotalByTva = array();
1499 foreach ($srcobject->lines as &$line) {
1500 if (!empty($line->special_code)) {
1503 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1506 foreach ($TTotalByTva as $tva => &$total) {
1507 $coef = $total / $srcobject->total_ttc;
1508 $am = $amount * $coef;
1509 $amount_ttc_diff += $am;
1510 $amountdeposit[$tva] += $am / (1 + $tva / 100);
1513 if ($typeamount ==
'amount') {
1514 $amountdeposit[0] = $valuedeposit;
1515 } elseif ($typeamount ==
'variable') {
1518 $lines = $srcobject->lines;
1519 $numlines = count($lines);
1520 for ($i = 0; $i < $numlines; $i++) {
1522 if (empty($lines[$i]->qty)) {
1525 if (!empty($lines[$i]->special_code)) {
1529 $totalamount += $lines[$i]->total_ht;
1530 $tva_tx = $lines[$i]->tva_tx;
1531 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $valuedeposit) / 100;
1535 if ($totalamount == 0) {
1536 $amountdeposit[0] = 0;
1544 $amount_ttc_diff = $amountdeposit[0];
1547 foreach ($amountdeposit as $tva => $amount) {
1548 if (empty($amount)) {
1553 'amount' =>
'FixAmount',
1554 'variable' =>
'VarAmount'
1556 $descline =
'(DEPOSIT)';
1558 if ($typeamount ==
'amount') {
1559 $descline .=
' ('.price($valuedeposit,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
')';
1560 } elseif ($typeamount ==
'variable') {
1561 $descline .=
' ('.$valuedeposit.
'%)';
1564 $descline .=
' - '.$srcobject->ref;
1565 $result = $object->addline(
1572 (empty($conf->global->INVOICE_PRODUCTID_DEPOSIT) ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT),
1577 $lines[$i]->info_bits,
1583 $lines[$i]->special_code,
1600 $diff = $object->total_ttc - $amount_ttc_diff;
1602 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0) {
1603 $object->fetch_lines();
1604 $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100);
1605 $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);
1612 $lines = $srcobject->lines;
1613 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1614 $srcobject->fetch_lines();
1615 $lines = $srcobject->lines;
1620 if (is_array($lines)) {
1621 foreach ($lines as $line) {
1623 $line->qty =
price2num($line->qty * $valuestandardinvoice / 100,
'MS');
1629 if (is_array($lines)) {
1630 foreach ($lines as $line) {
1632 $line->qty =
price2num($line->qty * $valuedeposit / 100,
'MS');
1637 $fk_parent_line = 0;
1638 $num = count($lines);
1640 for ($i = 0; $i < $num; $i++) {
1641 if (!in_array($lines[$i]->
id, $selectedLines)) {
1646 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
1650 if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1651 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1653 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',', $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE))) {
1657 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1658 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->libelle);
1659 if ($object->situation_counter == 1) {
1660 $lines[$i]->situation_percent = 0;
1663 if ($lines[$i]->subprice < 0 && empty($conf->global->INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN)) {
1666 $discount->fk_soc = $object->socid;
1667 $discount->amount_ht = abs($lines[$i]->total_ht);
1668 $discount->amount_tva = abs($lines[$i]->total_tva);
1669 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1670 $discount->tva_tx = $lines[$i]->tva_tx;
1671 $discount->fk_user = $user->id;
1672 $discount->description = $desc;
1673 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1674 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1675 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1676 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1678 $discountid = $discount->create($user);
1679 if ($discountid > 0) {
1680 $result = $object->insert_discount($discountid);
1688 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1691 $date_start =
false;
1692 if ($lines[$i]->date_debut_prevue) {
1693 $date_start = $lines[$i]->date_debut_prevue;
1695 if ($lines[$i]->date_debut_reel) {
1696 $date_start = $lines[$i]->date_debut_reel;
1698 if ($lines[$i]->date_start) {
1699 $date_start = $lines[$i]->date_start;
1704 if ($lines[$i]->date_fin_prevue) {
1705 $date_end = $lines[$i]->date_fin_prevue;
1707 if ($lines[$i]->date_fin_reel) {
1708 $date_end = $lines[$i]->date_fin_reel;
1710 if ($lines[$i]->date_end) {
1711 $date_end = $lines[$i]->date_end;
1715 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1716 $fk_parent_line = 0;
1720 if (method_exists($lines[$i],
'fetch_optionals')) {
1721 $lines[$i]->fetch_optionals();
1722 $array_options = $lines[$i]->array_options;
1725 $tva_tx = $lines[$i]->tva_tx;
1726 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
1727 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1732 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty);
1733 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty);
1735 $result = $object->addline(
1737 $lines[$i]->subprice,
1742 $lines[$i]->fk_product,
1743 $lines[$i]->remise_percent,
1747 $lines[$i]->info_bits,
1748 $lines[$i]->fk_remise_except,
1753 $lines[$i]->special_code,
1757 $lines[$i]->fk_fournprice,
1761 $lines[$i]->situation_percent,
1762 $lines[$i]->fk_prev_id,
1763 $lines[$i]->fk_unit,
1778 if ($result > 0 && $lines[$i]->product_type == 9) {
1779 $fk_parent_line = $result;
1789 $object->update_price(1,
'auto', 0, $mysoc);
1819 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
1830 $id = $object->create($user);
1832 for ($i = 1; $i <= $NBLINES; $i++) {
1833 if (
GETPOST(
'idprod'.$i,
'int')) {
1835 $product->fetch(
GETPOST(
'idprod'.$i,
'int'));
1838 $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);
1842 $object->update_price(1,
'auto', 0, $mysoc);
1849 if (empty($dateinvoice)) {
1851 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
1853 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1859 if (!(
GETPOST(
'situations',
'int') > 0)) {
1861 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
1867 $result = $object->fetch(
GETPOST(
'situations',
'int'));
1868 $object->fk_facture_source =
GETPOST(
'situations',
'int');
1871 if (!empty($origin) && !empty($originid)) {
1872 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1874 $object->origin = $origin;
1875 $object->origin_id = $originid;
1878 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
1879 $retained_warranty =
GETPOST(
'retained_warranty',
'int');
1880 if (
price2num($retained_warranty) > 0) {
1881 $object->retained_warranty =
price2num($retained_warranty);
1884 if (
GETPOST(
'retained_warranty_fk_cond_reglement',
'int') > 0) {
1885 $object->retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
1888 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1889 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
1890 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
1892 $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);
1895 foreach ($object->lines as $i => &$line) {
1896 $line->origin = $object->origin;
1897 $line->origin_id = $line->id;
1898 $line->fk_prev_id = $line->id;
1899 $line->fetch_optionals();
1900 $line->situation_percent = $line->get_prev_progress($object->id);
1903 $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);
1904 $line->total_ht = $tabprice[0];
1905 $line->total_tva = $tabprice[1];
1906 $line->total_ttc = $tabprice[2];
1907 $line->total_localtax1 = $tabprice[9];
1908 $line->total_localtax2 = $tabprice[10];
1909 $line->multicurrency_total_ht = $tabprice[16];
1910 $line->multicurrency_total_tva = $tabprice[17];
1911 $line->multicurrency_total_ttc = $tabprice[18];
1914 if ($line->fk_remise_except) {
1916 $result = $discount->fetch($line->fk_remise_except);
1919 if ($discount->fk_facture_line > 0) {
1920 $line->fk_remise_except = 0;
1927 $object->fetch_thirdparty();
1928 $object->date = $dateinvoice;
1929 $object->date_pointoftax = $date_pointoftax;
1930 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1931 $object->note = trim(
GETPOST(
'note',
'restricthtml'));
1932 $object->note_private = trim(
GETPOST(
'note',
'restricthtml'));
1933 $object->ref_client =
GETPOST(
'ref_client',
'alpha');
1934 $object->model_pdf =
GETPOST(
'model',
'alpha');
1935 $object->fk_project =
GETPOST(
'projectid',
'int');
1936 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1937 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1943 $object->situation_counter = $object->situation_counter + 1;
1944 $id = $object->createFromCurrent($user);
1946 $mesg = $object->error;
1948 $nextSituationInvoice =
new Facture($db);
1949 $nextSituationInvoice->fetch($id);
1952 $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
1953 $ret = $extrafields->setOptionalsFromPost(
null, $nextSituationInvoice);
1955 $nextSituationInvoice->insertExtraFields();
1962 if ($id > 0 && !$error) {
1966 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && count($object->lines)) {
1967 $outputlangs = $langs;
1970 $newlang =
GETPOST(
'lang_id',
'aZ09');
1973 $newlang = $object->thirdparty->default_lang;
1975 if (!empty($newlang)) {
1976 $outputlangs =
new Translate(
"", $conf);
1977 $outputlangs->setDefaultLang($newlang);
1978 $outputlangs->load(
'products');
1980 $model = $object->model_pdf;
1981 $ret = $object->fetch($id);
1983 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1989 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
1994 $_GET[
"origin"] = $_POST[
"origin"];
1995 $_GET[
"originid"] = $_POST[
"originid"];
1998 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'') {
2000 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2001 $vat_rate = str_replace(
'*',
'', $vat_rate);
2002 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
2003 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
2004 foreach ($object->lines as $line) {
2005 $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);
2007 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2009 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2010 $remise_percent = str_replace(
'*',
'', $remise_percent);
2011 foreach ($object->lines as $line) {
2012 $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);
2014 } elseif ($action ==
'addline' && $usercancreate) {
2015 $langs->load(
'errors');
2023 $price_ht_devise =
'';
2025 $price_ttc_devise =
'';
2027 if (
GETPOST(
'price_ht') !==
'') {
2030 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2033 if (
GETPOST(
'price_ttc') !==
'') {
2036 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2037 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2040 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2041 if ($prod_entry_mode ==
'free') {
2044 $idprod =
GETPOST(
'idprod',
'int');
2046 if (!empty($conf->global->MAIN_DISABLE_FREE_LINES) && $idprod <= 0) {
2047 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2052 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2056 if (empty($remise_percent)) {
2057 $remise_percent = 0;
2061 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
2062 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
2064 if (is_array($extralabelsline)) {
2066 foreach ($extralabelsline as $key => $value) {
2067 unset($_POST[
"options_".$key.$predef]);
2071 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2072 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2075 if (!$prod_entry_mode) {
2077 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2081 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2082 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2085 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) {
2086 if (($price_ht < 0 || $price_ttc < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
2087 $langs->load(
"errors");
2088 if ($object->type == $object::TYPE_DEPOSIT) {
2090 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2092 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2096 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2101 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2104 if ($prod_entry_mode ==
'free' && empty($idprod) && empty($product_desc)) {
2105 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2109 $langs->load(
"errors");
2110 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2114 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2115 if ($combinations =
GETPOST(
'combinations',
'array')) {
2119 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2120 $idprod = $res->fk_product_child;
2122 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2128 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
2129 $ret = $object->fetch($id);
2134 $ret = $object->fetch_thirdparty();
2139 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2150 if (!empty($idprod) && $idprod > 0) {
2152 $prod->fetch($idprod);
2154 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2159 $datapriceofproduct = $prod->getSellPrice($mysoc, $object->thirdparty, $pqp);
2161 $pu_ht = $datapriceofproduct[
'pu_ht'];
2162 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2163 $price_min = $datapriceofproduct[
'price_min'];
2164 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] :
null;
2165 $price_base_type = $datapriceofproduct[
'price_base_type'];
2169 $tmpvat = (
float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2170 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
2173 if (!empty($price_ht) || $price_ht ===
'0') {
2175 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2176 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2178 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2179 } elseif ($tmpvat != $tmpprodvat) {
2181 if ($price_base_type !=
'HT') {
2182 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2184 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2191 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
2192 $outputlangs = $langs;
2194 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
2195 $newlang =
GETPOST(
'lang_id',
'aZ09');
2197 if (empty($newlang)) {
2198 $newlang = $object->thirdparty->default_lang;
2200 if (!empty($newlang)) {
2201 $outputlangs =
new Translate(
"", $conf);
2202 $outputlangs->setDefaultLang($newlang);
2203 $outputlangs->load(
'products');
2206 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->description;
2208 $desc = $prod->description;
2212 if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
2216 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
2217 $desc = $product_desc;
2219 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
2223 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
2226 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
2227 $outputlangs = $langs;
2229 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
2230 $newlang =
GETPOST(
'lang_id',
'alpha');
2232 if (empty($newlang)) {
2233 $newlang = $object->thirdparty->default_lang;
2235 if (!empty($newlang)) {
2236 $outputlangs =
new Translate(
"", $conf);
2237 $outputlangs->setDefaultLang($newlang);
2238 $outputlangs->load(
'products');
2240 if (!empty($prod->customcode)) {
2241 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2243 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2246 if (!empty($prod->country_code)) {
2247 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
2250 if (!empty($prod->customcode)) {
2251 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2253 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2256 if (!empty($prod->country_code)) {
2257 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
2264 $type = $prod->type;
2265 $fk_unit = $prod->fk_unit;
2269 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2270 $tva_tx = str_replace(
'*',
'', $tva_tx);
2271 if (empty($tva_tx)) {
2274 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2275 $desc = $product_desc;
2277 $fk_unit =
GETPOST(
'units',
'alpha');
2279 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2280 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
2282 if ($pu_ttc && !$pu_ht) {
2283 $price_base_type =
'TTC';
2287 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2294 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
2295 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
2303 $price2num_remise_percent =
price2num($remise_percent);
2304 $price2num_price_min =
price2num($price_min);
2305 $price2num_price_min_ttc =
price2num($price_min_ttc);
2306 if (empty($price2num_pu_ht)) {
2307 $price2num_pu_ht = 0;
2309 if (empty($price2num_remise_percent)) {
2310 $price2num_remise_percent = 0;
2312 if (empty($price2num_price_min)) {
2313 $price2num_price_min = 0;
2315 if (empty($price2num_price_min_ttc)) {
2316 $price2num_price_min_ttc = 0;
2321 if ($pu_ht && $price_min && ((
price2num($pu_ht) * (1 - $remise_percent / 100)) <
price2num($price_min))) {
2322 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2325 } elseif ($pu_ttc && $price_min_ttc && ((
price2num($pu_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc))) {
2326 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2334 if (
isModEnabled(
'productbatch') && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) && !empty($conf->global->INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS)) {
2335 $langs->load(
'productbatch');
2336 foreach ($lines[$i]->detail_batch as $batchline) {
2337 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2342 $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);
2346 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2347 $outputlangs = $langs;
2350 $newlang =
GETPOST(
'lang_id',
'aZ09');
2353 $newlang = $object->thirdparty->default_lang;
2355 if (!empty($newlang)) {
2356 $outputlangs =
new Translate(
"", $conf);
2357 $outputlangs->setDefaultLang($newlang);
2358 $outputlangs->load(
'products');
2360 $model = $object->model_pdf;
2361 $ret = $object->fetch($id);
2363 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2369 unset($_POST[
'prod_entry_mode']);
2371 unset($_POST[
'qty']);
2372 unset($_POST[
'type']);
2373 unset($_POST[
'remise_percent']);
2374 unset($_POST[
'price_ht']);
2375 unset($_POST[
'multicurrency_price_ht']);
2376 unset($_POST[
'price_ttc']);
2377 unset($_POST[
'tva_tx']);
2378 unset($_POST[
'product_ref']);
2379 unset($_POST[
'product_label']);
2380 unset($_POST[
'product_desc']);
2381 unset($_POST[
'fournprice']);
2382 unset($_POST[
'buying_price']);
2383 unset($_POST[
'np_marginRate']);
2384 unset($_POST[
'np_markRate']);
2385 unset($_POST[
'dp_desc']);
2386 unset($_POST[
'idprod']);
2387 unset($_POST[
'units']);
2389 unset($_POST[
'date_starthour']);
2390 unset($_POST[
'date_startmin']);
2391 unset($_POST[
'date_startsec']);
2392 unset($_POST[
'date_startday']);
2393 unset($_POST[
'date_startmonth']);
2394 unset($_POST[
'date_startyear']);
2395 unset($_POST[
'date_endhour']);
2396 unset($_POST[
'date_endmin']);
2397 unset($_POST[
'date_endsec']);
2398 unset($_POST[
'date_endday']);
2399 unset($_POST[
'date_endmonth']);
2400 unset($_POST[
'date_endyear']);
2402 unset($_POST[
'situations']);
2403 unset($_POST[
'progress']);
2411 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2412 if (!$object->fetch($id) > 0) {
2415 $object->fetch_thirdparty();
2424 $vat_rate = str_replace(
'*',
'', $vat_rate);
2436 if (preg_match(
'/\*/', $vat_rate)) {
2441 $vat_rate = str_replace(
'*',
'', $vat_rate);
2442 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty);
2443 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty);
2450 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
2451 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
2453 if (is_array($extralabelsline)) {
2455 foreach ($extralabelsline as $key => $value) {
2456 unset($_POST[
"options_".$key]);
2461 $special_code =
GETPOST(
'special_code',
'int');
2462 if ($special_code == 3) {
2467 $line->fetch(
GETPOST(
'lineid',
'int'));
2468 $percent = $line->get_prev_progress($object->id);
2473 if ($progress >= 0) {
2474 $mesg = $langs->trans(
"CantBeNullOrPositive");
2478 } elseif ($progress < $line->situation_percent) {
2479 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
2483 } elseif ($progress < $percent) {
2484 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
2494 $productid =
GETPOST(
'productid',
'int');
2495 if (!empty($productid)) {
2497 $product->fetch($productid);
2499 $type = $product->type;
2501 $price_min = $product->price_min;
2502 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
2503 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
2505 $price_min_ttc = $product->price_min_ttc;
2506 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
2507 $price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
2514 if ($pu_ht && $price_min && (((
float)
price2num($pu_ht) * (1 - (
float) $remise_percent / 100)) < (
float)
price2num($price_min))) {
2515 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2518 $action =
'editline';
2519 } elseif ($pu_ttc && $price_min_ttc && ((
price2num($pu_ttc) * (1 - (
float) $remise_percent / 100)) <
price2num($price_min_ttc))) {
2520 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2523 $action =
'editline';
2528 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2532 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
2537 $langs->load(
"errors");
2538 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2541 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) {
2542 if (($pu_ht < 0 || $pu_ttc < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
2543 $langs->load(
"errors");
2544 if ($object->type == $object::TYPE_DEPOSIT) {
2546 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2548 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2552 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2560 if (empty($usercancreatemargin)) {
2561 foreach ($object->lines as &$line) {
2562 if ($line->id ==
GETPOST(
'lineid',
'int')) {
2563 $fournprice = $line->fk_fournprice;
2564 $buyingprice = $line->pa_ht;
2570 $price_base_type =
'HT';
2572 if (empty($pu) && !empty($pu_ttc)) {
2574 $price_base_type =
'TTC';
2577 $result = $object->updateline(
2591 GETPOST(
'fk_parent_line',
'int'),
2604 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2606 $outputlangs = $langs;
2609 $newlang =
GETPOST(
'lang_id',
'aZ09');
2612 $newlang = $object->thirdparty->default_lang;
2614 if (!empty($newlang)) {
2615 $outputlangs =
new Translate(
"", $conf);
2616 $outputlangs->setDefaultLang($newlang);
2617 $outputlangs->load(
'products');
2620 $ret = $object->fetch($id);
2621 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2624 unset($_POST[
'qty']);
2625 unset($_POST[
'type']);
2626 unset($_POST[
'productid']);
2627 unset($_POST[
'remise_percent']);
2628 unset($_POST[
'price_ht']);
2629 unset($_POST[
'multicurrency_price_ht']);
2630 unset($_POST[
'price_ttc']);
2631 unset($_POST[
'tva_tx']);
2632 unset($_POST[
'product_ref']);
2633 unset($_POST[
'product_label']);
2634 unset($_POST[
'product_desc']);
2635 unset($_POST[
'fournprice']);
2636 unset($_POST[
'buying_price']);
2637 unset($_POST[
'np_marginRate']);
2638 unset($_POST[
'np_markRate']);
2640 unset($_POST[
'dp_desc']);
2641 unset($_POST[
'idprod']);
2642 unset($_POST[
'units']);
2644 unset($_POST[
'date_starthour']);
2645 unset($_POST[
'date_startmin']);
2646 unset($_POST[
'date_startsec']);
2647 unset($_POST[
'date_startday']);
2648 unset($_POST[
'date_startmonth']);
2649 unset($_POST[
'date_startyear']);
2650 unset($_POST[
'date_endhour']);
2651 unset($_POST[
'date_endmin']);
2652 unset($_POST[
'date_endsec']);
2653 unset($_POST[
'date_endday']);
2654 unset($_POST[
'date_endmonth']);
2655 unset($_POST[
'date_endyear']);
2657 unset($_POST[
'situations']);
2658 unset($_POST[
'progress']);
2663 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modifier')) {
2664 if (!$object->fetch($id) > 0) {
2667 if (
GETPOST(
'all_progress') !=
"") {
2668 $all_progress =
GETPOST(
'all_progress',
'int');
2669 foreach ($object->lines as $line) {
2670 $percent = $line->get_prev_progress($object->id);
2671 if (floatval($all_progress) < floatval($percent)) {
2672 $mesg = $langs->trans(
"Line").
' '.$i.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
2676 $object->update_percent($line,
GETPOST(
'all_progress'),
false);
2679 $object->update_price(1);
2681 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
2682 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2684 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
2686 $object->fetch($id,
'',
'',
'',
true);
2692 && $object->is_last_in_cycle()
2693 && $usercanunvalidate
2696 $newCycle = $object->newCycle();
2697 if ($newCycle > 1) {
2699 $lastCycle = $object->situation_cycle_ref;
2700 $lastSituationCounter = $object->situation_counter;
2701 $linkedCreditNotesList = array();
2703 if (count($object->tab_next_situation_invoice) > 0) {
2704 foreach ($object->tab_next_situation_invoice as $next_invoice) {
2706 && $next_invoice->situation_counter == $object->situation_counter
2707 && $next_invoice->fk_facture_source == $object->id
2709 $linkedCreditNotesList[] = $next_invoice->id;
2714 $object->situation_cycle_ref = $newCycle;
2715 $object->situation_counter = 1;
2716 $object->situation_final = 0;
2717 if ($object->update($user) > 0) {
2719 if (count($linkedCreditNotesList) > 0) {
2721 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
2722 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
2723 $sql .=
' , situation_final=0';
2724 $sql .=
' , situation_counter='.((int) $object->situation_counter);
2725 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
2727 $resql = $db->query(
$sql);
2733 foreach ($object->lines as $line) {
2735 if ($line->product_type == 9) {
2740 if (!empty($object->tab_previous_situation_invoice)) {
2742 $lineIndex = count($object->tab_previous_situation_invoice) - 1;
2743 $searchPreviousInvoice =
true;
2744 while ($searchPreviousInvoice) {
2746 $searchPreviousInvoice =
false;
2754 $maxPrevSituationPercent = 0;
2755 foreach ($object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
2756 if ($prevLine->id == $line->fk_prev_id) {
2757 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
2762 $line->situation_percent = $line->situation_percent - $maxPrevSituationPercent;
2764 if ($line->update() < 0) {
2773 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
2775 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
2778 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
2781 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
2784 } elseif ($action ==
'import_lines_from_object'
2789 $fromElement =
GETPOST(
'fromelement');
2790 $fromElementid =
GETPOST(
'fromelementid');
2791 $importLines =
GETPOST(
'line_checkbox');
2793 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
2794 if ($fromElement ==
'commande') {
2796 $lineClassName =
'OrderLine';
2797 } elseif ($fromElement ==
'propal') {
2798 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
2799 $lineClassName =
'PropaleLigne';
2801 $nextRang = count($object->lines) + 1;
2804 foreach ($importLines as $lineId) {
2805 $lineId = intval($lineId);
2806 $originLine =
new $lineClassName($db);
2807 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
2808 $originLine->fetch_optionals();
2809 $desc = $originLine->desc;
2810 $pu_ht = $originLine->subprice;
2811 $qty = $originLine->qty;
2812 $txtva = $originLine->tva_tx;
2813 $txlocaltax1 = $originLine->localtax1_tx;
2814 $txlocaltax2 = $originLine->localtax2_tx;
2815 $fk_product = $originLine->fk_product;
2816 $remise_percent = $originLine->remise_percent;
2817 $date_start = $originLine->date_start;
2818 $date_end = $originLine->date_end;
2820 $info_bits = $originLine->info_bits;
2821 $fk_remise_except = $originLine->fk_remise_except;
2822 $price_base_type =
'HT';
2824 $type = $originLine->product_type;
2825 $rang = $nextRang++;
2826 $special_code = $originLine->special_code;
2827 $origin = $originLine->element;
2828 $origin_id = $originLine->id;
2829 $fk_parent_line = 0;
2830 $fk_fournprice = $originLine->fk_fournprice;
2831 $pa_ht = $originLine->pa_ht;
2832 $label = $originLine->label;
2833 $array_options = $originLine->array_options;
2835 $situation_percent = 0;
2837 $situation_percent = 100;
2840 $fk_unit = $originLine->fk_unit;
2841 $pu_ht_devise = $originLine->multicurrency_subprice;
2843 $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);
2862 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2868 $triggersendname =
'BILL_SENTBYMAIL';
2870 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
2871 $trackid =
'inv'.$object->id;
2872 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2875 $upload_dir = $conf->facture->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity];
2876 $permissiontoadd = $usercancreate;
2877 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2880 if ($action ==
'update_extras') {
2884 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
2891 $result = $object->insertExtraFields(
'BILL_MODIFY');
2899 $action =
'edit_extras';
2903 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
2904 if ($action ==
'addcontact') {
2905 $result = $object->fetch($id);
2907 if ($result > 0 && $id > 0) {
2910 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2914 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2917 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2918 $langs->load(
"errors");
2919 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2924 } elseif ($action ==
'swapstatut') {
2926 if ($object->fetch($id)) {
2927 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
2931 } elseif ($action ==
'deletecontact') {
2933 $object->fetch($id);
2934 $result = $object->delete_contact($lineid);
2937 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2945 $action =
'edit_extras';
2961 $paymentstatic =
new Paiement($db);
2962 $bankaccountstatic =
new Account($db);
2969 $title = $object->ref.
" - ".$langs->trans(
'Card');
2970 if ($action ==
'create') {
2971 $title = $langs->trans(
"NewBill");
2973 $help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
2979 if ($action ==
'create') {
2980 $facturestatic =
new Facture($db);
2981 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
2986 $res = $soc->fetch($socid);
2989 $currency_code = $conf->currency;
2993 $remise_absolue = 0;
2994 if (!empty($origin) && !empty($originid)) {
2996 $element = $subelement = $origin;
2998 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
2999 $element = $regs[1];
3000 $subelement = $regs[2];
3003 if ($element ==
'project') {
3004 $projectid = $originid;
3006 if (empty($cond_reglement_id)) {
3007 $cond_reglement_id = $soc->cond_reglement_id;
3009 if (empty($mode_reglement_id)) {
3010 $mode_reglement_id = $soc->mode_reglement_id;
3012 if (empty($fk_account)) {
3013 $fk_account = $soc->fk_account;
3015 if (!$remise_percent) {
3016 $remise_percent = $soc->remise_percent;
3018 if (!$dateinvoice) {
3020 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
3024 if ($element ==
'order' || $element ==
'commande') {
3025 $element = $subelement =
'commande';
3027 if ($element ==
'propal') {
3028 $element =
'comm/propal';
3029 $subelement =
'propal';
3031 if ($element ==
'contract') {
3032 $element = $subelement =
'contrat';
3034 if ($element ==
'shipping') {
3035 $element = $subelement =
'expedition';
3040 $classname = ucfirst($subelement);
3041 $objectsrc =
new $classname($db);
3042 $objectsrc->fetch($originid);
3043 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3044 $objectsrc->fetch_lines();
3046 $objectsrc->fetch_thirdparty();
3048 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3049 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3052 if (empty($socid)) {
3053 $soc = $objectsrc->thirdparty;
3056 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
3058 if ($element ==
'expedition') {
3059 $ref_client = (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
'');
3061 $elem = $subelem = $objectsrc->origin;
3062 $expeoriginid = $objectsrc->origin_id;
3064 $classname = ucfirst($subelem);
3066 $expesrc =
new $classname($db);
3067 $expesrc->fetch($expeoriginid);
3069 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3070 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3071 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3072 $remise_percent = (!empty($expesrc->remise_percent) ? $expesrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
3073 $remise_absolue = (!empty($expesrc->remise_absolue) ? $expesrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
3076 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3077 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3081 $expesrc->fetch_optionals();
3082 $object->array_options = $expesrc->array_options;
3084 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
3085 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3086 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3087 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
3088 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
3091 if (!empty($objectsrc->multicurrency_code)) {
3092 $currency_code = $objectsrc->multicurrency_code;
3094 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
3095 $currency_tx = $objectsrc->multicurrency_tx;
3100 $objectsrc->fetch_optionals();
3101 $object->array_options = $objectsrc->array_options;
3105 $cond_reglement_id = $soc->cond_reglement_id;
3106 $mode_reglement_id = $soc->mode_reglement_id;
3107 $fk_account = $soc->fk_account;
3108 $remise_percent = $soc->remise_percent;
3109 $remise_absolue = 0;
3110 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
3112 if (
isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3113 $currency_code = $soc->multicurrency_code;
3118 if (empty($cond_reglement_id)) {
3119 $cond_reglement_id =
GETPOST(
"cond_reglement_id",
'int');
3123 if (empty($mode_reglement_id)) {
3124 $mode_reglement_id =
GETPOST(
"mode_reglement_id",
'int');
3128 if ($socid > 0 && $fk_account) {
3131 $fk_account =
GETPOST(
"fk_account",
'int');
3134 if (!empty($soc->id)) {
3135 $absolute_discount = $soc->getAvailableDiscounts();
3137 $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));
3138 $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));
3140 if (!empty($conf->use_javascript_ajax)) {
3141 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3147 if ($origin ==
'contrat') {
3148 $langs->load(
"admin");
3149 $text = $langs->trans(
"ToCreateARecurringInvoice");
3150 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3151 if (empty($conf->global->INVOICE_DISABLE_AUTOMATIC_RECURRING_INVOICE)) {
3152 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3154 print
info_admin($text, 0, 0, 0,
'opacitymedium').
'<br>';
3157 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3158 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3159 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3161 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3163 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3164 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3165 print
'<input name="ref" type="hidden" value="provisoire">';
3166 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3167 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3168 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3169 print
'<input name="force_fk_account" type="hidden" value="0">';
3170 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3171 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3172 print
'<input type="hidden" name="originentity" value="'.GETPOST(
'originentity').
'">';
3173 if (!empty($currency_tx)) {
3174 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3179 print
'<table class="border centpercent">';
3184 $exampletemplateinvoice =
new FactureRec($db);
3186 if (empty($origin) && empty($originid) &&
GETPOST(
'fac_rec',
'int') > 0) {
3187 $invoice_predefined->fetch(
GETPOST(
'fac_rec',
'int'));
3191 if ($soc->id > 0 && (!
GETPOST(
'fac_rec',
'int') || !empty($invoice_predefined->frequency))) {
3193 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3194 print
'<td colspan="2">';
3195 print $soc->getNomUrl(1,
'customer');
3196 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3198 $arrayoutstandingbills = $soc->getOutstandingBills();
3199 $outstandingBills = $arrayoutstandingbills[
'opened'];
3200 print
' - <span class="opacitymedium">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3201 print
'<span class="amount">'.price($outstandingBills,
'', $langs, 0, 0, -1, $conf->currency).
'</span>';
3202 if ($soc->outstanding_limit !=
'') {
3203 if ($outstandingBills > $soc->outstanding_limit) {
3204 print
img_warning($langs->trans(
"OutstandingBillReached"));
3206 print
' / '.price($soc->outstanding_limit,
'', $langs, 0, 0, -1, $conf->currency);
3211 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3212 print
'<td colspan="2">';
3213 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
3214 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0,
null, 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3216 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
3218 $(document).ready(function() {
3219 $("#socid").change(function() {
3221 console.log("Submit page");
3222 $(\'input[name="action"]\').val(\'create\');
3223 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3224 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3225 $(\'input[name="force_fk_account"]\').val(\'1\');
3226 $("#formtocreate").submit(); */
3228 // For company change, we must submit page with action=create instead of action=add
3229 console.log("We have changed the company - Resubmit page");
3230 jQuery("#formtocreateaction").val("create");
3231 jQuery("#formtocreate").submit();
3236 if (!
GETPOST(
'fac_rec',
'int')) {
3237 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>';
3244 if (empty($origin) && empty($originid) &&
GETPOST(
'fac_rec',
'int') > 0) {
3245 $invoice_predefined->fetch(
GETPOST(
'fac_rec',
'int'));
3247 $dateinvoice = $invoice_predefined->date_when;
3248 if (empty($projectid)) {
3249 $projectid = $invoice_predefined->fk_project;
3251 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
3252 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
3253 $fk_account = $invoice_predefined->fk_account;
3254 $note_public = $invoice_predefined->note_public;
3255 $note_private = $invoice_predefined->note_private;
3257 if (!empty($invoice_predefined->multicurrency_code)) {
3258 $currency_code = $invoice_predefined->multicurrency_code;
3260 if (!empty($invoice_predefined->multicurrency_tx)) {
3261 $currency_tx = $invoice_predefined->multicurrency_tx;
3264 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
3265 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
3266 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
3268 $resql = $db->query(
$sql);
3270 $num = $db->num_rows($resql);
3274 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
3276 print
'<select class="flat" id="fac_rec" name="fac_rec">';
3277 print
'<option value="0" selected></option>';
3279 $objp = $db->fetch_object($resql);
3280 print
'<option value="'.$objp->rowid.
'"';
3281 if (
GETPOST(
'fac_rec',
'int') == $objp->rowid) {
3283 $exampletemplateinvoice->fetch(
GETPOST(
'fac_rec',
'int'));
3285 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
3293 if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED)) {
3294 print
'<script type="text/javascript">
3295 $(document).ready(function() {
3296 $("#fac_rec").change(function() {
3297 console.log("We have changed the template invoice - Reload page");
3298 var fac_rec = $(this).val();
3299 var socid = $(\'#socid\').val();
3300 // 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.
3301 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3314 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td colspan="2">';
3315 print
'<div class="tagtable">'.
"\n";
3318 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3319 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOST(
'type',
'int') ?
'' :
' checked').
'> ';
3320 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
3321 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3,
'standardonsmartphone');
3322 print
'<table class="nobordernopadding"><tr>';
3326 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
3335 print
'<td class="nowrap" style="padding-left: 15px">';
3336 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%').
'"/>';
3339 print
'</tr></table>';
3340 print
'</div></div>';
3342 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
3344 if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) {
3345 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3346 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOST(
'type') == 3 ?
' checked' :
'').
'> ';
3347 print
'<script type="text/javascript">
3348 jQuery(document).ready(function() {
3349 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
3350 jQuery("#radio_standard").prop("checked", true);
3352 jQuery("#typedeposit, #valuedeposit").click(function() {
3353 jQuery("#radio_deposit").prop("checked", true);
3355 jQuery("#typedeposit").change(function() {
3356 console.log("We change type of down payment");
3357 jQuery("#radio_deposit").prop("checked", true);
3358 setRadioForTypeOfIncoice();
3360 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
3361 setRadioForTypeOfIncoice();
3363 function setRadioForTypeOfIncoice() {
3364 console.log("Change radio");
3365 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
3366 jQuery(".checkforselect").prop("disabled", true);
3367 jQuery(".checkforselect").prop("checked", false);
3369 jQuery(".checkforselect").prop("disabled", false);
3370 jQuery(".checkforselect").prop("checked", true);
3376 print
'<table class="nobordernopadding"><tr>';
3378 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
3379 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
3382 if (($origin ==
'propal') || ($origin ==
'commande')) {
3383 print
'<td class="nowrap" style="padding-left: 15px">';
3385 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
3386 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
3387 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
3389 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
3390 $valuedeposit =
GETPOST(
'valuedeposit',
'int');
3391 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
3392 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
3393 if (!empty($origin_payment_conditions_deposit_percent)) {
3394 $typedeposit =
'variable';
3397 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
3398 $valuedeposit = $objectsrc->deposit_percent;
3400 print
$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
3402 print
'<td class="nowrap" style="padding-left: 5px">';
3403 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.$valuedeposit.
'"/>';
3406 print
'</tr></table>';
3408 print
'</div></div>';
3413 if (!empty($conf->global->INVOICE_USE_SITUATION)) {
3415 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3416 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
3417 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
3418 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
3420 print
'</div></div>';
3423 $opt =
$form->selectSituationInvoices(
GETPOST(
'originid',
'int'), $socid);
3425 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3426 $tmp =
'<input type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOST(
'originid',
'int') ?
' checked' :
'');
3427 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3428 $tmp .=
' disabled';
3431 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3432 $text .=
'<select class="flat" id="situations" name="situations"';
3433 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3434 $text .=
' disabled';
3438 $text .=
'</select>';
3439 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
3441 print
'</div></div>';
3445 if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT)) {
3447 $facids = $facturestatic->list_replacable_invoices($soc->id);
3453 if (is_array($facids)) {
3454 foreach ($facids as $facparam) {
3455 $options .=
'<option value="'.$facparam [
'id'].
'"';
3456 if ($facparam[
'id'] ==
GETPOST(
'fac_replacement',
'int')) {
3457 $options .=
' selected';
3459 $options .=
'>'.$facparam[
'ref'];
3460 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
3461 $options .=
'</option>';
3465 print
'<!-- replacement line -->';
3466 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3467 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
3468 if (!$options || $invoice_predefined->id > 0) {
3469 $tmp .=
' disabled';
3472 print
'<script type="text/javascript">
3473 jQuery(document).ready(function() {
3474 jQuery("#fac_replacement").change(function() {
3475 jQuery("#radio_replacement").prop("checked", true);
3479 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
3480 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
3481 if (!$options || $invoice_predefined->id > 0) {
3482 $text .=
' disabled';
3486 $text .=
'<option value="-1"> </option>';
3489 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
3491 $text .=
'</select>';
3492 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3494 print
'</div></div>';
3497 if (!empty($conf->global->INVOICE_USE_SITUATION)) {
3498 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3499 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3500 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3501 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3502 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
3504 print
'</div></div>';
3507 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3508 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
3509 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
3511 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'', 0, 3,
'replacementonsmartphone');
3513 print
'</div></div>';
3516 if (empty($origin)) {
3519 if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) {
3521 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
3527 $newinvoice_static =
new Facture($db);
3528 foreach ($facids as $key => $valarray) {
3529 $newinvoice_static->id = $key;
3530 $newinvoice_static->ref = $valarray [
'ref'];
3531 $newinvoice_static->statut = $valarray [
'status'];
3532 $newinvoice_static->type = $valarray [
'type'];
3533 $newinvoice_static->paye = $valarray [
'paye'];
3535 $optionsav .=
'<option value="'.$key.
'"';
3536 if ($key ==
GETPOST(
'fac_avoir')) {
3537 $optionsav .=
' selected';
3540 $newinvoice_static->fetch_optionals($key);
3541 $object->array_options = $newinvoice_static->array_options;
3544 $optionsav .= $newinvoice_static->ref;
3545 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
3546 $optionsav .=
'</option>';
3549 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3550 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
3551 if ((!$optionsav && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) || $invoice_predefined->id > 0) {
3552 $tmp .=
' disabled';
3556 print
'<script type="text/javascript">
3557 jQuery(document).ready(function() {
3558 if (jQuery("#radio_creditnote").is(":checked"))
3560 jQuery("#radio_standard").prop("disabled", true);
3562 jQuery("#radio_standard").prop("disabled", false);
3564 if (! jQuery("#radio_creditnote").is(":checked"))
3566 jQuery("#credit_note_options").hide();
3568 jQuery("#radio_creditnote").click(function() {
3569 jQuery("#credit_note_options").show();
3571 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
3572 jQuery("#credit_note_options").hide();
3576 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
3577 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3578 if (!$optionsav || $invoice_predefined->id > 0) {
3579 $text .=
' disabled';
3583 $text .=
'<option value="-1"></option>';
3584 $text .= $optionsav;
3586 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
3588 $text .=
'</select>';
3589 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3592 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
3593 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>";
3594 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>";
3597 print
'</div></div>';
3600 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3601 if (empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
3602 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3604 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
3606 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
3608 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
3610 print
'</div></div>'.
"\n";
3615 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3616 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
3617 $text = $tmp.
'<label class="opacitymedium" for="radio_template">'.$langs->trans(
"RepeatableInvoice").
'</label> ';
3618 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3,
'templateonsmartphone');
3620 print
'</div></div>';
3625 if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) {
3629 foreach ($listtType as $type) {
3630 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
3632 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$curent.
'"';
3635 print
'<script type="text/javascript">
3636 $(document).ready(function() {
3637 var listType = {'.$jsListType.
'};
3638 $("[name=\'type\'").change(function() {
3639 console.log("change name=type");
3640 if ($( this ).prop("checked"))
3642 if(($( this ).val() in listType))
3644 $("#model").val(listType[$( this ).val()]);
3648 $("#model").val("'.$conf->global->FACTURE_ADDON_PDF.
'");
3661 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
3665 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin',
'alpha').
'&originid='.
GETPOST(
'originid',
'int'));
3666 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3672 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
3675 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
3676 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3677 print
$form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'',
'',
'',
'',
"add", 1, 1);
3681 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
3682 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
3683 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3684 print
$form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax',
'',
'',
'',
"add", 1, 1);
3689 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
3690 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
3691 print
$form->getSelectConditionsPaiements((
GETPOSTISSET(
'cond_reglement_id') &&
GETPOST(
'cond_reglement_id',
'int') != 0) ?
GETPOST(
'cond_reglement_id',
'int') : $cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
3695 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
3696 $rwStyle =
'display:none;';
3697 if (in_array(
GETPOST(
'type',
'int'), $retainedWarrantyInvoiceAvailableType)) {
3701 $retained_warranty =
GETPOST(
'retained_warranty',
'int');
3702 if (empty($retained_warranty)) {
3703 if (!empty($objectsrc->retained_warranty)) {
3704 $retained_warranty = $objectsrc->retained_warranty;
3707 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT;
3709 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
3710 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
3713 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
3714 $retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
3715 if (empty($retained_warranty_fk_cond_reglement)) {
3716 $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
3717 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
3718 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
3720 $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
3723 print
$form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
3726 print
'<script type="text/javascript">
3727 $(document).ready(function() {
3728 $("[name=\'type\']").change(function() {
3729 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
3731 $(".retained-warranty-line").show();
3732 $("#new-situation-invoice-retained-warranty").val("'.floatval($retained_warranty_js_default).
'");
3735 $(".retained-warranty-line").hide();
3736 $("#new-situation-invoice-retained-warranty").val("");
3740 $("[name=\'type\']:checked").trigger("change");
3746 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
3747 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
3748 print
$form->select_types_paiements((
GETPOSTISSET(
'mode_reglement_id') &&
GETPOST(
'mode_reglement_id') != 0)?
GETPOST(
'mode_reglement_id') : $mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
3753 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td colspan="2">';
3754 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
3755 print
$form->select_comptes(($fk_account < 0 ?
'' : $fk_account),
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
3761 $langs->load(
'projects');
3762 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
3763 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
3764 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>';
3771 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
3772 print
'<td colspan="2" class="maxwidthonsmartphone">';
3773 $incoterm_id =
GETPOST(
'incoterm_id');
3774 $incoterm_location =
GETPOST(
'location_incoterms');
3775 if (empty($incoterm_id)) {
3776 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
3777 $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
3779 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
3780 print
$form->select_incoterms($incoterm_id, $incoterm_location);
3785 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid'=>$socid);
3786 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
3787 print $hookmanager->resPrint;
3788 if (empty($reshook)) {
3789 if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE) && !empty($soc->id)) {
3792 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
3793 if ($soc->fetch_optionals() > 0) {
3794 $object->array_options = array_merge($object->array_options, $soc->array_options);
3798 print $object->showOptionals($extrafields,
'create',
$parameters);
3802 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
3803 print
'<td colspan="2">';
3804 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
3805 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
3807 if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) {
3809 $paramkey =
'FACTURE_ADDON_PDF_'.$object->type;
3810 $preselected = !empty($conf->global->$paramkey) ? $conf->global->$paramkey : $conf->global->FACTURE_ADDON_PDF;
3812 $preselected = $conf->global->FACTURE_ADDON_PDF;
3814 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
3820 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
3821 print
'<td colspan="2" class="maxwidthonsmartphone">';
3822 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
3823 print
$form->selectMultiCurrency($currency_code,
'multicurrency_code');
3829 if (
GETPOST(
'fac_rec',
'int') > 0) {
3830 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
3831 if (empty($dateexample)) {
3834 $substitutionarray = array(
3835 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
3836 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
3837 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
3838 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
3839 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
3840 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
3841 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
3842 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
3843 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
3844 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
3845 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
3848 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
3849 foreach ($substitutionarray as $key => $val) {
3850 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
3852 $htmltext .=
'</i>';
3857 print
'<td class="tdtop">';
3858 print
$form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
3860 print
'<td valign="top" colspan="2">';
3861 $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%');
3862 print $doleditor->Create(1);
3865 if (empty($user->socid)) {
3867 print
'<td class="tdtop">';
3868 print
$form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
3870 print
'<td valign="top" colspan="2">';
3871 $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%');
3872 print $doleditor->Create(1);
3878 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
3879 $langs->loadLangs(array(
'orders',
'propal'));
3882 if ($origin ==
'contrat') {
3884 $objectsrc->remise_absolue = $remise_absolue;
3885 $objectsrc->remise_percent = $remise_percent;
3886 $objectsrc->update_price(1,
'auto', 1);
3889 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
3890 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
3891 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
3892 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
3897 switch (get_class($objectsrc)) {
3899 $newclassname =
'CommercialProposal';
3902 $newclassname =
'Order';
3905 $newclassname =
'Sending';
3908 $newclassname =
'Contract';
3911 $newclassname =
'Intervention';
3914 $newclassname = get_class($objectsrc);
3918 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
3919 print
'<td colspan="2">';
3920 print $objectsrc->getNomUrl(1);
3922 $objectsrc->fetchObjectLinked($originid, $origin,
'',
'facture');
3923 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
3925 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
3928 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht).
'</td></tr>';
3929 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva).
"</td></tr>";
3930 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
3931 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax1).
"</td></tr>";
3934 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
3935 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax2).
"</td></tr>";
3937 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc).
"</td></tr>";
3940 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
3941 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
3942 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
3950 print
$form->buttonsSaveCancel(
"CreateDraft");
3953 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
3956 $title = $langs->trans(
'ProductsAndServices');
3959 print
'<div class="div-table-responsive-no-min">';
3960 print
'<table class="noborder centpercent">';
3962 $objectsrc->printOriginLinesList(
'', $selectedLines);
3969 } elseif ($id > 0 || !empty($ref)) {
3970 if (empty($object->id)) {
3971 $langs->load(
'errors');
3972 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
3981 $result = $object->fetch($id, $ref);
3988 $extrafields->fetch_name_optionals_label($object->table_element);
3990 if ($user->socid > 0 && $user->socid != $object->socid) {
3994 $result = $object->fetch_thirdparty();
3996 $result = $soc->fetch($object->socid);
4000 $selleruserevenustamp = $mysoc->useRevenueStamp();
4002 $totalpaid = $object->getSommePaiement();
4003 $totalcreditnotes = $object->getSumCreditNotesUsed();
4004 $totaldeposits = $object->getSumDepositsUsed();
4012 $resteapayer =
price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4016 $multicurrency_totalpaid = $object->getSommePaiement(1);
4017 $multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
4018 $multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
4019 $multicurrency_resteapayer =
price2num($object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4023 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 && $object->multicurrency_code != $conf->currency) {
4024 $resteapayer =
price2num($multicurrency_resteapayer / $object->multicurrency_tx,
'MT');
4028 if ($object->paye) {
4031 $resteapayeraffiche = $resteapayer;
4033 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
4034 $filterabsolutediscount =
"fk_facture_source IS NULL";
4035 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4037 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4038 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4041 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
4042 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
4043 $absolute_discount =
price2num($absolute_discount,
'MT');
4044 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4046 $author =
new User($db);
4047 if ($object->user_author) {
4048 $author->fetch($object->user_author);
4051 $objectidnext = $object->getIdReplacingInvoice();
4055 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
'bill');
4060 if ($action ==
'converttoreduc') {
4062 $type_fac =
'ExcessReceived';
4064 $type_fac =
'CreditNote';
4066 $type_fac =
'Deposit';
4068 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4069 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4070 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4074 if ($action ==
'delete') {
4075 $text = $langs->trans(
'ConfirmDeleteBill', $object->ref);
4076 $formquestion = array();
4078 if ($object->type !=
Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->statut >= 1) {
4079 $qualified_for_stock_change = 0;
4080 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
4081 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4083 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4086 if ($qualified_for_stock_change) {
4087 $langs->load(
"stocks");
4088 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4090 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
4092 if ($conf->browser->name ==
'ie') {
4095 $formquestion = array(
4099 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4101 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4103 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4106 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4111 if ($action ==
'situationout') {
4112 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle', $object->ref);
4113 $label = $langs->trans(
"ConfirmOuting");
4114 $formquestion = array();
4119 && $object->is_last_in_cycle()
4120 && $usercanunvalidate
4122 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4127 if ($action ==
'valid') {
4129 $objectref = substr($object->ref, 1, 4);
4130 if ($objectref ==
'PROV') {
4131 $savdate = $object->date;
4132 if (!empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
4134 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
4136 $numref = $object->getNextNumRef($soc);
4139 $numref = $object->ref;
4142 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4144 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4145 $notify =
new Notify($db);
4147 $text .= $notify->confirmMessage(
'BILL_VALIDATE', $object->socid, $object);
4149 $formquestion = array();
4152 $qualified_for_stock_change = 0;
4153 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
4154 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4156 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4159 if ($qualified_for_stock_change) {
4160 $langs->load(
"stocks");
4161 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4162 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4165 $warehouse_array = $warehouse->list_array();
4166 if (count($warehouse_array) == 1) {
4167 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4168 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4170 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockIncrease") : $langs->trans(
"SelectWarehouseForStockDecrease");
4171 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4173 $formquestion = array(
4179 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4183 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
4188 foreach ($object->lines as $line) {
4189 $res = $line->fetch_product();
4191 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
4197 if ($nbMandated > 0 ) $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
4200 $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);
4204 if ($action ==
'modif') {
4205 $text = $langs->trans(
'ConfirmUnvalidateBill', $object->ref);
4206 $formquestion = array();
4209 $qualified_for_stock_change = 0;
4210 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
4211 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4213 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4216 if ($qualified_for_stock_change) {
4217 $langs->load(
"stocks");
4218 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4219 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4222 $warehouse_array = $warehouse->list_array();
4223 if (count($warehouse_array) == 1) {
4224 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
4225 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4227 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
4228 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4230 $formquestion = array(
4236 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4240 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
4244 if ($action ==
'paid' && ($resteapayer <= 0 || (!empty($conf->global->INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) && $resteapayer == $object->total_ttc))) {
4245 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill', $object->ref),
'confirm_paid',
'',
"yes", 1);
4247 if ($action ==
'paid' && $resteapayer > 0 && (empty($conf->global->INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $resteapayer != $object->total_ttc)) {
4251 $close[$i][
'code'] =
'discount_vat';
4253 $close[$i][
'code'] =
'badcustomer';
4255 $close[$i][
'code'] =
'bankcharge';
4257 $close[$i][
'code'] =
'withholdingtax';
4259 $close[$i][
'code'] =
'other';
4263 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
4265 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4267 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
4269 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
4271 $close[$i][
'label'] = $langs->trans(
"Other");
4275 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4277 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4279 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4281 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
4283 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
4286 foreach ($close as $key => $val) {
4287 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
4291 $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'));
4293 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially', $object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 380, 600);
4297 if ($action ==
'canceled') {
4300 if ($objectidnext) {
4301 $facturereplacement =
new Facture($db);
4302 $facturereplacement->fetch($objectidnext);
4303 $statusreplacement = $facturereplacement->statut;
4305 if ($objectidnext && $statusreplacement == 0) {
4306 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
4309 $close[1][
'code'] =
'badcustomer';
4310 $close[2][
'code'] =
'abandon';
4312 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4313 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
4315 $close[1][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $object->ref), $close[1][
'label'], 1);
4316 $close[2][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
4318 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
4319 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
4322 $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'));
4324 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill', $object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 270);
4328 if ($action ==
'deletepayment') {
4329 $payment_id =
GETPOST(
'paiement_id');
4330 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
4334 if ($action ==
'ask_deleteline') {
4335 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
4339 if ($action ==
'clone') {
4340 $filter =
'(s.client:IN:1,2,3)';
4342 $formquestion = array(
4343 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' =>
$form->select_company($object->socid,
'socid', $filter, 1)),
4344 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
4347 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
4350 if ($action ==
"remove_file_comfirm") {
4351 $file =
GETPOST(
'file',
'alpha');
4354 $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&file='.$file,
4355 $langs->trans(
'DeleteFileHeader'),
4356 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
4366 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
4367 if (empty($reshook)) {
4369 } elseif ($reshook > 0) {
4378 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
4380 $morehtmlref =
'<div class="refidno">';
4382 if ($object->status == $object::STATUS_DRAFT && !$mysoc->isInEEC() && !empty($conf->global->INVOICE_ALLOW_FREE_REF)) {
4383 $morehtmlref .=
$form->editfieldkey(
"Ref",
'ref', $object->ref, $object, $usercancreate,
'string',
'', 0, 1);
4384 $morehtmlref .=
$form->editfieldval(
"Ref",
'ref', $object->ref, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
4385 $morehtmlref .=
'<br>';
4388 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
4389 $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);
4391 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
4392 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
4393 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
4397 $langs->load(
"projects");
4398 $morehtmlref .=
'<br>';
4399 if ($usercancreate) {
4400 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
4401 if ($action !=
'classify') {
4402 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
4404 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
4406 if (!empty($object->fk_project)) {
4408 $proj->fetch($object->fk_project);
4409 $morehtmlref .= $proj->getNomUrl(1);
4411 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
4416 $morehtmlref .=
'</div>';
4418 $object->totalpaid = $totalpaid;
4420 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
4422 print
'<div class="fichecenter">';
4423 print
'<div class="fichehalfleft">';
4424 print
'<div class="underbanner clearboth"></div>';
4426 print
'<table class="border centpercent tableforfield">';
4429 print
'<tr><td class="titlefield fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
4430 print $object->getLibType(2);
4431 if ($object->module_source) {
4432 print
' <span class="opacitymediumbycolor paddingleft">('.$langs->trans(
"POS").
' '.
dol_escape_htmltag(ucfirst($object->module_source)).
' - '.$langs->trans(
"Terminal").
' '.
dol_escape_htmltag($object->pos_source).
')</span>';
4435 $facreplaced =
new Facture($db);
4436 $facreplaced->fetch($object->fk_facture_source);
4437 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
4441 $facusing->fetch($object->fk_facture_source);
4442 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
4445 $facidavoir = $object->getListIdAvoirFromInvoice();
4446 if (count($facidavoir) > 0) {
4447 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
4449 foreach ($facidavoir as $id) {
4456 $facavoir->fetch($id);
4457 print $facavoir->getNomUrl(1,
'', 32);
4461 if ($objectidnext > 0) {
4462 $facthatreplace =
new Facture($db);
4463 $facthatreplace->fetch($objectidnext);
4464 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
4469 $result = $discount->fetch(0, $object->id);
4471 print
' <span class="opacitymediumbycolor paddingleft">';
4472 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
4473 $s = str_replace(
'{s1}', $object->getLibType(0), $s);
4474 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
4476 print
'</span><br>';
4480 if ($object->fk_fac_rec_source > 0) {
4482 $result = $tmptemplate->fetch($object->fk_fac_rec_source);
4484 print
' <span class="opacitymediumbycolor paddingleft">';
4485 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
4486 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
4494 print
'<!-- Discounts -->'.
"\n";
4495 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
4499 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?facid='.$object->id);
4500 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
4505 print
'<table class="nobordernopadding centpercent"><tr><td>';
4506 print $langs->trans(
'DateInvoice');
4508 if ($action !=
'editinvoicedate' && !empty($object->brouillon) && $usercancreate && empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
4509 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>';
4511 print
'</tr></table>';
4514 if ($action ==
'editinvoicedate') {
4515 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date,
'invoicedate');
4517 print
'<span class="valuedate">'.dol_print_date($object->date,
'day').
'</span>';
4523 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
4526 print
'<table class="nobordernopadding centpercent"><tr><td>';
4527 print $langs->trans(
'DatePointOfTax');
4529 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>';
4530 print
'</tr></table>';
4532 if ($action ==
'editdate_pointoftax') {
4533 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date_pointoftax,
'date_pointoftax');
4535 print
'<span class="valuedate">'.dol_print_date($object->date_pointoftax,
'day').
'</span>';
4542 print
'<table class="nobordernopadding centpercent"><tr><td>';
4543 print $langs->trans(
'PaymentConditionsShort');
4546 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>';
4548 print
'</tr></table>';
4551 if ($action ==
'editconditions') {
4552 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
4554 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'none');
4563 print
'<table class="nobordernopadding centpercent"><tr><td>';
4564 print $langs->trans(
'DateMaxPayment');
4567 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>';
4569 print
'</tr></table>';
4572 if ($action ==
'editpaymentterm') {
4573 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date_lim_reglement,
'paymentterm');
4575 print
'<span class="valuedate">'.dol_print_date($object->date_lim_reglement,
'day').
'</span>';
4576 if ($object->hasDelay()) {
4587 print
'<table class="nobordernopadding centpercent"><tr><td>';
4588 print $langs->trans(
'PaymentMode');
4590 if ($action !=
'editmode' && $usercancreate) {
4591 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>';
4593 print
'</tr></table>';
4595 if ($action ==
'editmode') {
4596 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
4598 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'none',
'CRDT');
4607 print
'<table class="nobordernopadding centpercent"><tr><td>';
4608 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
4610 if ($usercancreate && $action !=
'editmulticurrencycode' && !empty($object->brouillon)) {
4611 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>';
4613 print
'</tr></table>';
4615 $htmlname = (($usercancreate && $action ==
'editmulticurrencycode') ?
'multicurrency_code' :
'none');
4616 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code, $htmlname);
4620 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
4623 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4624 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
4626 if ($usercancreate && $action !=
'editmulticurrencyrate' && !empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
4627 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>';
4629 print
'</tr></table>';
4631 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
4632 if ($action ==
'actualizemulticurrencyrate') {
4635 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx, ($usercancreate ?
'multicurrency_tx' :
'none'), $object->multicurrency_code);
4637 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
4638 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
4639 print
'<div class="inline-block"> ';
4640 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
4650 print
'<tr><td class="nowrap">';
4651 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
4652 print $langs->trans(
'BankAccount');
4654 if (($action !=
'editbankaccount') && $usercancreate) {
4655 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>';
4657 print
'</tr></table>';
4659 if ($action ==
'editbankaccount') {
4660 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
4662 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
4671 print
'<table class="nobordernopadding centpercent"><tr><td>';
4672 print $langs->trans(
'IncotermLabel');
4673 print
'<td><td class="right">';
4674 if ($usercancreate) {
4675 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
4679 print
'</td></tr></table>';
4682 if ($action !=
'editincoterm') {
4683 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
4685 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
4692 if (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
4693 $displayWarranty =
true;
4694 if (!in_array($object->type, $retainedWarrantyInvoiceAvailableType) && empty($object->retained_warranty)) {
4695 $displayWarranty =
false;
4698 if ($displayWarranty) {
4700 print
'<tr class="retained-warranty-lines" ><td>';
4701 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
4702 print $langs->trans(
'RetainedWarranty');
4704 if ($action !=
'editretainedwarranty' && $user->hasRight(
'facture',
'creer') && $object->statut ==
Facture::STATUS_DRAFT) {
4705 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>';
4708 print
'</tr></table>';
4711 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4712 print
'<input type="hidden" name="action" value="setretainedwarranty">';
4713 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4714 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4715 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
4716 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4719 print
price($object->retained_warranty).
'%';
4724 print
'<tr class="retained-warranty-lines" ><td>';
4725 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
4726 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
4728 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') && $object->statut ==
Facture::STATUS_DRAFT) {
4729 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>';
4732 print
'</tr></table>';
4734 $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime(
'-1 years', $object->date_lim_reglement);
4735 if ($object->date > $defaultDate) {
4736 $defaultDate = $object->date;
4741 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4742 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
4743 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4744 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4745 $retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
4746 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $object->retained_warranty_fk_cond_reglement;
4747 $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;
4748 print
$form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4749 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4752 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->retained_warranty_fk_cond_reglement,
'none');
4753 if (!$displayWarranty) {
4754 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning.png',
'class="pictowarning valignmiddle" ');
4760 print
'<tr class="retained-warranty-lines" ><td>';
4761 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
4762 print $langs->trans(
'RetainedWarrantyDateLimit');
4764 if ($action !=
'editretainedwarrantydatelimit' && $user->hasRight(
'facture',
'creer') && $object->statut ==
Facture::STATUS_DRAFT) {
4765 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>';
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="setretainedwarrantydatelimit">';
4779 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4780 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4781 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').
'" >';
4782 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4785 print
dol_print_date($object->retained_warranty_date_limit,
'day');
4794 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
4799 print
'<div class="fichehalfright">';
4801 print
'<!-- amounts -->'.
"\n";
4802 print
'<div class="underbanner clearboth"></div>'.
"\n";
4804 print
'<table class="border tableforfield centpercent">';
4807 if (!empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE_SCREEN) && $object->type == $object::TYPE_CREDIT_NOTE) {
4812 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
4813 print
'<td class="nowrap amountcard right">' .
price($sign * $object->total_ht,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
4814 if (
isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
4816 print
'<td class="nowrap amountcard right">' .
price($sign * $object->multicurrency_total_ht,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
4822 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountVAT') .
'</td>';
4823 print
'<td class="nowrap amountcard right">' .
price($sign * $object->total_tva,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
4824 if (
isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
4826 print
'<td class="nowrap amountcard right">' .
price($sign * $object->multicurrency_total_tva,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
4831 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) {
4833 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
4834 print
'<td class="nowrap amountcard right">' .
price($sign * $object->total_localtax1,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
4835 if (
isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
4836 print
'<td class="nowrap amountcard right">' .
price($sign * $object->total_localtax1,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
4840 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) {
4842 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
4843 print
'<td class="nowrap amountcard right">' .
price($sign * $object->total_localtax2,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
4844 if (
isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
4845 print
'<td class="nowrap amountcard right">' .
price($sign * $object->total_localtax2,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
4853 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
4854 print
'<td class="nowrap amountcard right">' .
price($sign * $object->total_ttc,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
4855 if (
isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
4857 print
'<td class="nowrap amountcard right">' .
price($sign * $object->multicurrency_total_ttc,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
4864 if ($selleruserevenustamp) {
4865 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4866 print $langs->trans(
'RevenueStamp');
4868 if ($action !=
'editrevenuestamp' && !empty($object->brouillon) && $usercancreate) {
4869 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>';
4871 print
'</tr></table>';
4873 if ($action ==
'editrevenuestamp') {
4874 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
4875 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4876 print
'<input type="hidden" name="action" value="setrevenuestamp">';
4877 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num($object->revenuestamp).
'">';
4878 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4879 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
4880 print
' → <span id="revenuestamp_span"></span>';
4881 print
' <input type="submit" class="button buttongen button-save" value="'.$langs->trans(
'Modify').
'">';
4884 $(document).ready(function(){
4885 js_recalculate_revenuestamp();
4886 $('select[name=revenuestamp_type]').on('change',function(){
4887 js_recalculate_revenuestamp();
4890 function js_recalculate_revenuestamp(){
4891 var valselected = $('select[name=revenuestamp_type]').val();
4892 console.log('Calculate revenue stamp from '+valselected);
4894 if (valselected.indexOf('%') == -1)
4896 revenue = valselected;
4900 var revenue_type = parseFloat(valselected);
4901 var amount_net = ".round($object->total_ht, 2).
";
4902 revenue = revenue_type * amount_net / 100;
4903 revenue = revenue.toFixed(2);
4905 $('#revenuestamp_val').val(revenue);
4906 $('#revenuestamp_span').html(revenue);
4910 print
price($object->revenuestamp, 1,
'', 1, -1, -1, $conf->currency);
4924 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
4927 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
4930 if ($selleruserevenustamp) {
4941 if (($object->situation_cycle_ref > 0) && !empty($conf->global->INVOICE_USE_SITUATION)) {
4942 print
'<!-- List of situation invoices -->';
4943 print
'<table class="noborder situationstable" width="100%">';
4945 print
'<tr class="liste_titre">';
4946 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
4948 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
4950 print
'<td class="right"></td>';
4952 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
4953 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
4954 print
'<td width="18"> </td>';
4957 $total_prev_ht = $total_prev_ttc = 0;
4958 $total_global_ht = $total_global_ttc = 0;
4960 if (count($object->tab_previous_situation_invoice) > 0) {
4963 $current_situation_counter = array();
4964 foreach ($object->tab_previous_situation_invoice as $prev_invoice) {
4965 $tmptotalpaidforthisinvoice = $prev_invoice->getSommePaiement();
4966 $total_prev_ht += $prev_invoice->total_ht;
4967 $total_prev_ttc += $prev_invoice->total_ttc;
4968 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ?-1 : 1) * $prev_invoice->situation_counter;
4969 print
'<tr class="oddeven">';
4970 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
4972 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
4974 print
'<td class="right"></td>';
4976 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
4977 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
4978 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).
'</td>';
4984 $total_global_ht += $total_prev_ht;
4985 $total_global_ttc += $total_prev_ttc;
4986 $total_global_ht += $object->total_ht;
4987 $total_global_ttc += $object->total_ttc;
4989 print
'<tr class="oddeven">';
4990 print
'<td>'.$object->getNomUrl(1).
'</td>';
4992 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$object->situation_counter.
'</td>';
4994 print
'<td class="right"></td>';
4996 print
'<td class="right"><span class="amount">'.price($object->total_ht).
'</span></td>';
4997 print
'<td class="right"><span class="amount">'.price($object->total_ttc).
'</span></td>';
4998 print
'<td class="right">'.$object->getLibStatut(3, $object->getSommePaiement()).
'</td>';
5002 print
'<tr class="oddeven">';
5003 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'CurrentSituationTotal').
'</b></td>';
5006 foreach ($current_situation_counter as $sit) {
5007 $curSign = $sit > 0 ?
'+' :
'-';
5008 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
5010 print
' '.$curSign.
' ';
5012 print $curType.abs($sit);
5019 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5020 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5021 print
'<td width="18"> </td>';
5025 if (count($object->tab_next_situation_invoice) > 0) {
5037 $total_next_ht = $total_next_ttc = 0;
5039 foreach ($object->tab_next_situation_invoice as $next_invoice) {
5040 $totalpaid = $next_invoice->getSommePaiement();
5041 $total_next_ht += $next_invoice->total_ht;
5042 $total_next_ttc += $next_invoice->total_ttc;
5044 print
'<tr class="oddeven">';
5045 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
5047 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
5049 print
'<td class="right"></td>';
5051 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
5052 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
5053 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid).
'</td>';
5057 $total_global_ht += $total_next_ht;
5058 $total_global_ttc += $total_next_ttc;
5060 print
'<tr class="oddeven">';
5061 print
'<td colspan="3" class="right"></td>';
5063 print
'<td class="right"></td>';
5065 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5066 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5067 print
'<td width="18"> </td>';
5075 if ($object->type == $object::TYPE_CREDIT_NOTE) {
5081 print
'<!-- List of payments already done -->';
5082 print
'<div class="div-table-responsive-no-min">';
5083 print
'<table class="noborder paymenttable centpercent">';
5085 print
'<tr class="liste_titre">';
5086 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
5087 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
5088 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
5090 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
5092 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
5093 print
'<td class="liste_titre" width="18"> </td>';
5097 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
5098 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
5099 $sql .=
' pf.amount,';
5100 $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';
5101 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
5102 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
5103 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
5104 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
5105 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id).
' AND pf.fk_paiement = p.rowid';
5106 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
5107 $sql .=
' ORDER BY p.datep, p.tms';
5109 $result = $db->query(
$sql);
5111 $num = $db->num_rows($result);
5116 $objp = $db->fetch_object($result);
5118 $paymentstatic->id = $objp->rowid;
5119 $paymentstatic->datepaye = $db->jdate($objp->dp);
5120 $paymentstatic->ref = $objp->ref;
5121 $paymentstatic->num_payment = $objp->num_payment;
5122 $paymentstatic->paiementcode = $objp->payment_code;
5124 print
'<tr class="oddeven"><td class="nowraponall">';
5125 print $paymentstatic->getNomUrl(1);
5128 $dateofpayment = $db->jdate($objp->dp);
5130 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
5136 $label = ($langs->trans(
"PaymentType".$objp->payment_code) != (
"PaymentType".$objp->payment_code)) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
5137 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
5139 $bankaccountstatic->id = $objp->baid;
5140 $bankaccountstatic->ref = $objp->baref;
5141 $bankaccountstatic->label = $objp->baref;
5142 $bankaccountstatic->number = $objp->banumber;
5143 $bankaccountstatic->currency_code = $objp->bacurrency_code;
5146 $bankaccountstatic->account_number = $objp->account_number;
5149 $accountingjournal->fetch($objp->fk_accountancy_journal);
5150 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
5153 print
'<td class="nowraponall">';
5154 if ($bankaccountstatic->id) {
5155 print $bankaccountstatic->getNomUrl(1,
'transactions');
5159 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
5160 print
'<td class="center">';
5162 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
5179 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5180 print
'<span class="opacitymedium">';
5182 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
5184 print $langs->trans(
'AlreadyPaid');
5186 print
'</span></td><td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td><td> </td></tr>';
5188 $resteapayeraffiche = $resteapayer;
5189 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
5192 $creditnoteamount = 0;
5194 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
5195 $sql .=
" re.description, re.fk_facture_source";
5196 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
5197 $sql .=
" WHERE fk_facture = ".((int) $object->id);
5198 $resql = $db->query(
$sql);
5200 $num = $db->num_rows($resql);
5204 $obj = $db->fetch_object($resql);
5205 $invoice->fetch($obj->fk_facture_source);
5206 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5207 print
'<span class="opacitymedium">';
5209 print $langs->trans(
"CreditNote").
' ';
5212 print $langs->trans(
"Deposit").
' ';
5214 print $invoice->getNomUrl(0);
5217 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
5218 print
'<td class="right">';
5219 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">';
5220 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
5225 $creditnoteamount += $obj->amount_ttc;
5228 $depositamount += $obj->amount_ttc;
5237 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5238 print
'<span class="opacitymedium">';
5239 print
$form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
5241 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5242 $resteapayeraffiche = 0;
5243 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5247 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5248 print
'<span class="opacitymedium">';
5249 print
$form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
5251 print
'</td><td class="right">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td><td> </td></tr>';
5253 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5257 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5258 print
'<span class="opacitymedium">';
5259 print
$form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 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 $text = $langs->trans(
"HelpAbandonOther");
5269 if ($object->close_note) {
5270 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.$object->close_note;
5272 print
'<span class="opacitymedium">';
5273 print
$form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
5275 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5276 $resteapayeraffiche = 0;
5277 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5281 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5282 print
'<span class="opacitymedium">';
5283 print $langs->trans(
"Billed");
5284 print
'</td><td class="right">'.price($object->total_ttc).
'</td><td> </td></tr>';
5286 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5287 print
'<span class="opacitymedium">';
5288 print $langs->trans(
'RemainderToPay');
5289 if ($resteapayeraffiche < 0) {
5290 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5294 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
5297 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
5298 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5299 print
'<span class="opacitymedium">';
5300 print $langs->trans(
'RemainderToPayMulticurrency');
5301 if ($resteapayeraffiche < 0) {
5302 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5306 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">';
5308 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>';
5312 if (!empty($object->situation_final) && !empty($object->retained_warranty) && $displayWarranty) {
5315 $retainedWarranty = $total_global_ttc * $object->retained_warranty / 100;
5318 $retainedWarranty = $object->total_ttc * $object->retained_warranty / 100;
5321 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
5323 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>';
5326 print
'<tr><td colspan="'.$nbcols.
'" align="right">';
5327 print $langs->trans(
"RetainedWarranty").
' ('.$object->retained_warranty.
'%)';
5328 print !empty($object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date($object->retained_warranty_date_limit,
'day')) :
'';
5329 print
' :</td><td align="right">'.price($retainedWarranty).
'</td><td> </td></tr>';
5332 $resteapayeraffiche = $resteapayer;
5333 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5336 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5337 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
5338 print
'</td><td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td><td> </td></tr>';
5341 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>';
5344 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5345 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
5346 if ($resteapayeraffiche > 0) {
5347 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5349 print
'</span></td>';
5350 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
5351 print
'<td class="nowrap"> </td></tr>';
5354 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
5355 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5356 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
5357 if ($resteapayeraffiche > 0) {
5358 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5362 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>';
5376 $formmargin->displayMarginInfos($object);
5382 print
'<div class="clearboth"></div><br><br>';
5384 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
5385 $blocname =
'contacts';
5386 $title = $langs->trans(
'ContactsAddresses');
5387 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5390 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
5391 $blocname =
'notes';
5392 $title = $langs->trans(
'Notes');
5393 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5397 $result = $object->getLinesArray();
5401 global $inputalsopricewithtax;
5402 $inputalsopricewithtax = 1;
5405 if (!empty($conf->global->INVOICE_USE_SITUATION)) {
5406 if ($object->situation_cycle_ref && $object->statut == 0) {
5407 print
'<!-- Area to change globally the situation percent -->'.
"\n";
5408 print
'<div class="div-table-responsive">';
5410 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'#updatealllines" method="POST">';
5411 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
5412 print
'<input type="hidden" name="action" value="updatealllines" />';
5413 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
5414 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5416 print
'<table id="tablelines_all_progress" class="noborder noshadow" width="100%">';
5418 print
'<tr class="liste_titre nodrag nodrop">';
5421 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
5422 print
'<td align="center" width="5"> </td>';
5424 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
5425 print
'<td class="right">'.$langs->trans(
'Progress').
'</td>';
5426 print
'<td> </td>';
5429 print
'<tr class="nodrag nodrop">';
5431 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
5432 print
'<td align="center" width="5"> </td>';
5434 print
'<td> </td>';
5435 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
5436 print
'<td class="right"><input type="submit" class="button" name="all_percent" value="Modifier" /></td>';
5447 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">
5448 <input type="hidden" name="token" value="' .
newToken().
'">
5449 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
5450 <input type="hidden" name="mode" value="">
5451 <input type="hidden" name="page_y" value="">
5452 <input type="hidden" name="id" value="' . $object->id.
'">
5453 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
5456 if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
5457 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
5460 print
'<div class="div-table-responsive-no-min">';
5461 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
5464 if (!empty($object->lines)) {
5465 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
5469 if ($object->statut == 0 && $usercancreate && $action !=
'valid' && $action !=
'editline') {
5470 if ($action !=
'editline' && $action !=
'selectlines') {
5474 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
5475 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
5476 if (empty($reshook))
5477 $object->formAddObjectLine(1, $mysoc, $soc);
5491 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
5492 print
'<div class="tabsAction">';
5495 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
5496 if (empty($reshook)) {
5499 'class' =>
'classfortooltip'
5505 $ventilExportCompta = $object->getVentilExportCompta();
5507 if ($ventilExportCompta == 0) {
5508 if (!empty($conf->global->INVOICE_CAN_BE_EDITED_EVEN_IF_PAYMENT_DONE) || ($resteapayer ==
price2num($object->total_ttc,
'MT', 1) && empty($object->paye))) {
5509 if (!$objectidnext && $object->is_last_in_cycle()) {
5510 if ($usercanunvalidate) {
5511 $params[
'attr'][
'title'] =
'';
5512 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=modif&token='.
newToken(),
'',
true, $params);
5514 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
5515 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=modif&token='.
newToken(),
'',
false, $params);
5517 } elseif (!$object->is_last_in_cycle()) {
5518 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
5519 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5521 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
5522 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5526 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5527 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5532 $result = $discount->fetch(0, $object->id);
5540 && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || $usercanreopen)) {
5541 if ($object->close_code !=
'replaced' || (!$objectidnext)) {
5542 $params[
'attr'][
'title'] =
'';
5543 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
5545 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
5546 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
5551 if (!empty($conf->global->CONTRACT_CREATE_FROM_INVOICE)) {
5553 $langs->load(
"contracts");
5555 if ($usercancreatecontract) {
5556 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>';
5563 if ($usercanvalidate) {
5564 $params[
'attr'][
'title'] =
'';
5565 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
5570 if (empty($user->socid)) {
5572 if ($objectidnext) {
5573 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'SendMail').
'</span>';
5576 $params[
'attr'][
'title'] =
'';
5577 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
5579 $params[
'attr'][
'title'] =
'';
5580 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
5588 if ($resteapayer > 0) {
5589 if ($usercancreatewithdrarequest) {
5590 if (!$objectidnext && $object->close_code !=
'replaced') {
5591 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>';
5593 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
5604 if (
isModEnabled(
'takepos') && $object->module_source ==
'takepos') {
5605 $langs->load(
"cashdesk");
5606 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
5607 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int) $object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
5612 if ($objectidnext) {
5613 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
5617 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
5618 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
5622 $params[
'attr'][
'title'] =
'';
5623 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default', DOL_URL_ROOT.
'/compta/paiement.php?facid='.$object->id.
'&action=create&accountid='.$object->fk_account,
'',
true, $params);
5628 $sumofpayment = $totalpaid;
5629 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
5635 if ($resteapayer == 0) {
5636 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
5638 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.$object->id.
'&action=create&accountid='.$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
5644 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
5648 && (!empty($conf->global->INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) || $sumofpayment == 0)
5650 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>';
5656 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertToReduc').
'</a>';
5658 print
'<span class="butActionRefused" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
5672 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
5673 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
5675 $params[
'attr'][
'title'] =
'';
5676 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=paid',
'',
true, $params);
5681 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) {
5682 if ($totalpaid > 0 || $totalcreditnotes > 0) {
5684 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
5686 if (empty($conf->global->INVOICE_CAN_NEVER_BE_CANCELED)) {
5687 if ($objectidnext) {
5688 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
5690 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
5698 if (!$objectidnext) {
5699 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>';
5706 && ($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
5709 && $object->is_last_in_cycle()
5712 if ($usercanunvalidate) {
5713 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>';
5715 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
5721 $params[
'attr'][
'title'] =
'';
5722 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=clone&object=invoice',
'',
true, $params);
5727 if (!$objectidnext && count($object->lines) > 0) {
5728 $params[
'attr'][
'title'] =
'';
5729 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$object->id.
'&action=create',
'',
true, $params);
5738 && $object->situation_counter > 1
5739 && $object->is_last_in_cycle()
5740 && $usercanunvalidate
5742 if (($object->total_ttc - $totalcreditnotes) == 0) {
5743 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
5745 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
5750 if ($usercancreate && ($object->type == 5) && ($object->statut == 1 || $object->statut == 2)) {
5751 if ($object->is_last_in_cycle() && $object->situation_final != 1) {
5752 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.$object->id.
'&socid='.$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5753 } elseif (!$object->is_last_in_cycle()) {
5754 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5756 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5761 $isErasable = $object->is_erasable();
5762 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
5763 $enableDelete =
false;
5766 if ($isErasable == -4) {
5767 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
5768 } elseif ($isErasable == -3) {
5769 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
5770 } elseif ($isErasable == -2) {
5771 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
5772 } elseif ($isErasable == -1) {
5773 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5774 } elseif ($isErasable <= 0) {
5775 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable');
5776 } elseif ($objectidnext) {
5777 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
5779 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=delete&token='.
newToken();
5780 $enableDelete =
true;
5782 $params[
'attr'][
'title'] =
'';
5783 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
5785 $params[
'attr'][
'title'] =
'';
5786 print
dolGetButtonAction($langs->trans(
'Delete'), $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
5793 if (
GETPOST(
'modelselected',
'alpha')) {
5794 $action =
'presend';
5796 if ($action !=
'prerelance' && $action !=
'presend') {
5797 print
'<div class="fichecenter"><div class="fichehalfleft">';
5798 print
'<a name="builddoc"></a>';
5802 $filedir = $conf->facture->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($object->ref);
5803 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.$object->id;
5804 $genallowed = $usercanread;
5805 $delallowed = $usercancreate;
5807 print $formfile->showdocuments(
5827 'remove_file_comfirm'
5830 $somethingshown = $formfile->numoffiles;
5833 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'invoice'));
5835 $compatibleImportElementsList =
false;
5839 $compatibleImportElementsList = array(
'commande',
'propal');
5841 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
5848 print
'<br><!-- Link to pay -->'.
"\n";
5849 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
5850 print showOnlinePaymentUrl(
'invoice', $object->ref).
'<br>';
5853 print
'</div><div class="fichehalfright">';
5857 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.$object->id);
5860 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
5862 $somethingshown =
$formactions->showactions($object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
5864 print
'</div></div>';
5869 $modelmail =
'facture_send';
5870 $defaulttopic =
'SendBillRef';
5871 $diroutput = $conf->facture->multidir_output[$object->entity];
5872 $trackid =
'inv'.$object->id;
5874 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 journals.
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') && $user->hasRight('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') && $user->hasRight('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)) $sql
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.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
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...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
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.