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');
83 $projectid = (
GETPOST(
'projectid',
'int') ?
GETPOST(
'projectid',
'int') : 0);
87 $socid =
GETPOST(
'socid',
'int');
88 $action =
GETPOST(
'action',
'aZ09');
89 $confirm =
GETPOST(
'confirm',
'alpha');
90 $cancel =
GETPOST(
'cancel',
'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;
105 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
106 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
107 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
112 $usehm = (!empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : 0);
118 $extrafields->fetch_name_optionals_label($object->table_element);
121 if ($id > 0 || !empty($ref)) {
122 if ($action !=
'add') {
123 if (empty($conf->global->INVOICE_USE_SITUATION)) {
124 $fetch_situation =
false;
126 $fetch_situation =
true;
128 $ret = $object->fetch($id, $ref,
'',
'', $fetch_situation);
133 $hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
136 $usercanread = $user->hasRight(
"facture",
"lire");
137 $usercancreate = $user->hasRight(
"facture",
"creer");
138 $usercanissuepayment = $user->hasRight(
"facture",
"paiement");
139 $usercandelete = $user->hasRight(
"facture",
"supprimer");
140 $usercancreatecontract = $user->hasRight(
"contrat",
"creer");
143 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->validate)));
144 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->send)));
145 $usercanreopen = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->reopen)));
146 if (!empty($conf->global->INVOICE_DISALLOW_REOPEN)) {
147 $usercanreopen =
false;
149 $usercanunvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->unvalidate)));
151 $usermustrespectpricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
152 $usercancreatemargin = (!empty($user->rights->margins->creer) ? $user->rights->margins->creer : 0);
153 $usercanreadallmargin = (!empty($user->rights->margins->liretous) ? $user->rights->margins->liretous : 0);
154 $usercancreatewithdrarequest = (!empty($user->rights->prelevement->bons->creer) ? $user->rights->prelevement->bons->creer : 0);
156 $permissionnote = $usercancreate;
157 $permissiondellink = $usercancreate;
158 $permissiontoedit = $usercancreate;
159 $permissiontoadd = $usercancreate;
162 $retainedWarrantyInvoiceAvailableType = array();
163 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
164 $retainedWarrantyInvoiceAvailableType = explode(
'+', $conf->global->INVOICE_USE_RETAINED_WARRANTY);
169 $socid = $user->socid;
173 $result =
restrictedArea($user,
'facture', $object->id,
'',
'',
'fk_soc',
'rowid', $isdraft);
181 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
186 if (empty($reshook)) {
187 $backurlforlist = DOL_URL_ROOT.
'/compta/facture/list.php';
189 if (empty($backtopage) || ($cancel && empty($id))) {
190 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
191 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
192 $backtopage = $backurlforlist;
194 $backtopage = DOL_URL_ROOT.
'/compta/facture/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
200 if (!empty($backtopageforcancel)) {
201 header(
"Location: ".$backtopageforcancel);
203 } elseif (!empty($backtopage)) {
204 header(
"Location: ".$backtopage);
210 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
212 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
214 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
217 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
221 $objectutil->socid = $socid;
222 $result = $objectutil->createFromClone($user, $id);
224 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?facid='.$result);
227 $langs->load(
"errors");
231 } elseif ($action ==
'reopen' && $usercanreopen) {
232 $result = $object->fetch($id);
235 $result = $object->setUnpaid($user);
237 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
243 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
245 $result = $object->fetch($id);
246 $object->fetch_thirdparty();
248 $idwarehouse =
GETPOST(
'idwarehouse');
250 $qualified_for_stock_change = 0;
251 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
252 $qualified_for_stock_change = $object->hasProductsOrServices(2);
254 $qualified_for_stock_change = $object->hasProductsOrServices(1);
257 $isErasable = $object->is_erasable();
259 if (($usercandelete && $isErasable > 0)
260 || ($usercancreate && $isErasable == 1)) {
261 $result = $object->delete($user, 0, $idwarehouse);
263 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
270 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
273 $object->fetch_thirdparty();
275 $result = $object->deleteline(
GETPOST(
'lineid',
'int'));
278 $object->line_order(
true);
280 $outputlangs = $langs;
286 $newlang = $object->thirdparty->default_lang;
288 if (!empty($newlang)) {
290 $outputlangs->setDefaultLang($newlang);
291 $outputlangs->load(
'products');
293 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
294 $ret = $object->fetch($id);
295 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
298 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
305 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
308 $result = $discount->fetch(
GETPOST(
"discountid"));
309 $discount->unlink_invoice();
310 } elseif ($action ==
'valid' && $usercancreate) {
314 if (!empty($conf->global-> INVOICE_CHECK_POSTERIOR_DATE)) {
315 $last_of_type = $object->willBeLastOfSameType(
true);
316 if (empty($object->date_validation) && !$last_of_type[0]) {
325 if ($object->total_ht >= 0) {
326 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
334 if (empty($conf->global->FACTURE_ENABLE_NEGATIVE) && $object->total_ttc < 0) {
335 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
344 $array_of_total_ht_per_vat_rate = array();
345 $array_of_total_ht_devise_per_vat_rate = array();
346 foreach ($object->lines as $line) {
348 $vat_src_code_for_line =
'';
349 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
350 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
352 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
353 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
355 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
356 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
360 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
361 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
362 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
364 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
365 if ($object->type == $object::TYPE_DEPOSIT) {
366 $langs->load(
"errors");
368 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
372 $tmpvatratetoshow = explode(
'_', $vatrate);
373 $tmpvatratetoshow[0] = round($tmpvatratetoshow[0], 2);
375 if ($tmpvatratetoshow[0] != 0) {
376 $langs->load(
"errors");
377 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", $tmpvatratetoshow[0]),
null,
'errors');
385 } elseif ($action ==
'classin' && $usercancreate) {
387 $object->setProject(
GETPOST(
'projectid',
'int'));
388 } elseif ($action ==
'setmode' && $usercancreate) {
390 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
394 } elseif ($action ==
'setretainedwarrantyconditions' && $user->rights->facture->creer) {
396 $object->retained_warranty_fk_cond_reglement = 0;
397 $result = $object->setRetainedWarrantyPaymentTerms(
GETPOST(
'retained_warranty_fk_cond_reglement',
'int'));
402 $old_rw_date_lim_reglement = $object->retained_warranty_date_limit;
403 $new_rw_date_lim_reglement = $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement);
404 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
405 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
407 if ($object->retained_warranty_date_limit < $object->date) {
408 $object->retained_warranty_date_limit = $object->date;
410 $result = $object->update($user);
414 } elseif ($action ==
'setretainedwarranty' && $user->rights->facture->creer) {
416 $result = $object->setRetainedWarranty(
GETPOST(
'retained_warranty',
'float'));
420 } elseif ($action ==
'setretainedwarrantydatelimit' && $user->rights->facture->creer) {
422 $result = $object->setRetainedWarrantyDateLimit(
GETPOST(
'retained_warranty_date_limit',
'float'));
426 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
427 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
428 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
429 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
430 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
432 $old_date_lim_reglement = $object->date_lim_reglement;
434 if (empty($newdate)) {
435 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
436 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id.
'&action=editinvoicedate&token='.
newToken());
439 if ($newdate > (
dol_now(
'tzuserrel') + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
440 if (empty($conf->global->INVOICE_MAX_FUTURE_DELAY)) {
441 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
443 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
447 $object->date = $newdate;
448 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
449 if ($new_date_lim_reglement > $old_date_lim_reglement) {
450 $object->date_lim_reglement = $new_date_lim_reglement;
452 if ($object->date_lim_reglement < $object->date) {
453 $object->date_lim_reglement = $object->date;
455 $result = $object->update($user);
459 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
462 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
464 $object->date_pointoftax = $date_pointoftax;
465 $result = $object->update($user);
469 } elseif ($action ==
'setconditions' && $usercancreate) {
471 $object->cond_reglement_code = 0;
472 $object->cond_reglement_id = 0;
479 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
487 $old_date_lim_reglement = $object->date_lim_reglement;
488 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
489 if ($new_date_lim_reglement > $old_date_lim_reglement) {
490 $object->date_lim_reglement = $new_date_lim_reglement;
492 if ($object->date_lim_reglement < $object->date) {
493 $object->date_lim_reglement = $object->date;
495 $result = $object->update($user);
507 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
509 $object->date_lim_reglement =
dol_mktime(12, 0, 0,
GETPOST(
'paymenttermmonth',
'int'),
GETPOST(
'paymenttermday',
'int'),
GETPOST(
'paymenttermyear',
'int'));
510 if ($object->date_lim_reglement < $object->date) {
511 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
512 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
514 $result = $object->update($user);
518 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
520 $object->revenuestamp =
GETPOST(
'revenuestamp');
521 $result = $object->update($user);
522 $object->update_price(1);
527 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
528 $outputlangs = $langs;
531 $newlang =
GETPOST(
'lang_id',
'aZ09');
534 $newlang = $object->thirdparty->default_lang;
536 if (!empty($newlang)) {
538 $outputlangs->setDefaultLang($newlang);
539 $outputlangs->load(
'products');
541 $model = $object->model_pdf;
542 $ret = $object->fetch($id);
544 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
550 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm')) {
551 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
552 } elseif ($action ==
'setbankaccount' && $usercancreate) {
553 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
554 } elseif ($action ==
'setremisepercent' && $usercancreate) {
556 $result = $object->setDiscount($user,
price2num(
GETPOST(
'remise_percent'),
'', 2));
557 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
562 if (
GETPOST(
"remise_id",
'int') > 0) {
563 $ret = $object->fetch($id);
565 $result = $object->insert_discount(
GETPOST(
"remise_id",
'int'));
575 if (
GETPOST(
"remise_id_for_payment",
'int') > 0) {
576 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
578 $discount->fetch(
GETPOST(
"remise_id_for_payment",
'int'));
582 $remaintopay = $object->getRemainToPay(0);
586 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
590 $result = $discount->link_to_invoice(0, $id);
598 $newremaintopay = $object->getRemainToPay(0);
599 if ($newremaintopay == 0) {
600 $object->setPaid($user);
611 if (empty($error) && empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
612 $outputlangs = $langs;
615 $newlang =
GETPOST(
'lang_id',
'aZ09');
618 $newlang = $object->thirdparty->default_lang;
620 if (!empty($newlang)) {
622 $outputlangs->setDefaultLang($newlang);
624 $ret = $object->fetch($id);
626 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
631 } elseif ($action ==
'setref' && $usercancreate) {
633 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'',
null,
'',
'', $user,
'BILL_MODIFY');
634 } elseif ($action ==
'setref_client' && $usercancreate) {
636 $object->set_ref_client(
GETPOST(
'ref_client'));
637 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
639 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
642 $object->fetch_thirdparty();
646 $qualified_for_stock_change = 0;
647 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
648 $qualified_for_stock_change = $object->hasProductsOrServices(2);
650 $qualified_for_stock_change = $object->hasProductsOrServices(1);
653 if ($qualified_for_stock_change) {
654 if (!$idwarehouse || $idwarehouse == - 1) {
656 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
663 $result = $object->validate($user,
'', $idwarehouse);
666 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
667 $outputlangs = $langs;
670 $newlang =
GETPOST(
'lang_id',
'aZ09');
673 $newlang = $object->thirdparty->default_lang;
675 if (!empty($newlang)) {
677 $outputlangs->setDefaultLang($newlang);
678 $outputlangs->load(
'products');
680 $model = $object->model_pdf;
682 $ret = $object->fetch($id);
684 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
690 if (count($object->errors)) {
697 } elseif ($action ==
'confirm_modif' && $usercanunvalidate) {
699 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
702 $object->fetch_thirdparty();
706 $qualified_for_stock_change = 0;
707 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
708 $qualified_for_stock_change = $object->hasProductsOrServices(2);
710 $qualified_for_stock_change = $object->hasProductsOrServices(1);
713 if ($qualified_for_stock_change) {
714 if (!$idwarehouse || $idwarehouse == - 1) {
716 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
724 $sql =
'SELECT pf.amount';
725 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf';
726 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id);
728 $result = $db->query($sql);
731 $num = $db->num_rows($result);
734 $objp = $db->fetch_object($result);
735 $totalpaid += $objp->amount;
742 $resteapayer = $object->total_ttc - $totalpaid;
745 $ventilExportCompta = $object->getVentilExportCompta();
748 if ($ventilExportCompta == 0) {
749 if (!empty($conf->global->INVOICE_CAN_BE_EDITED_EVEN_IF_PAYMENT_DONE) || ($resteapayer == $object->total_ttc && empty($object->paye))) {
750 $result = $object->setDraft($user, $idwarehouse);
756 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
757 $outputlangs = $langs;
760 $newlang =
GETPOST(
'lang_id',
'aZ09');
763 $newlang = $object->thirdparty->default_lang;
765 if (!empty($newlang)) {
767 $outputlangs->setDefaultLang($newlang);
768 $outputlangs->load(
'products');
770 $model = $object->model_pdf;
771 $ret = $object->fetch($id);
773 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
778 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
781 $result = $object->setPaid($user);
785 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
788 $close_code =
GETPOST(
"close_code",
'restricthtml');
789 $close_note =
GETPOST(
"close_note",
'restricthtml');
791 $result = $object->setPaid($user, $close_code, $close_note);
796 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
798 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes') {
801 $close_code =
GETPOST(
"close_code",
'restricthtml');
802 $close_note =
GETPOST(
"close_note",
'restricthtml');
804 $result = $object->setCanceled($user, $close_code, $close_note);
809 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
811 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
814 $object->fetch_thirdparty();
819 $result = $discountcheck->fetch(0, $object->id);
832 $amount_ht = $amount_tva = $amount_ttc = array();
833 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
837 foreach ($object->lines as $line) {
838 if ($line->product_type < 9 && $line->total_ht != 0) {
839 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
841 $amount_ht[$keyforvatrate] += $line->total_ht;
842 $amount_tva[$keyforvatrate] += $line->total_tva;
843 $amount_ttc[$keyforvatrate] += $line->total_ttc;
844 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
845 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
846 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
852 if (!empty($conf->global->INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) && $object->type ==
Facture::TYPE_CREDIT_NOTE) {
853 $alreadypaid = $object->getSommePaiement();
854 if ($alreadypaid && abs($alreadypaid) < abs($object->total_ttc)) {
855 $ratio = abs(($object->total_ttc - $alreadypaid) / $object->total_ttc);
856 foreach ($amount_ht as $vatrate => $val) {
857 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
858 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
859 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
860 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
861 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
862 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
871 $discount->description =
'(CREDIT_NOTE)';
873 $discount->description =
'(DEPOSIT)';
875 $discount->description =
'(EXCESS RECEIVED)';
877 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
879 $discount->fk_soc = $object->socid;
880 $discount->fk_facture_source = $object->id;
888 $sql =
'SELECT SUM(pf.amount) as total_paiements';
889 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
890 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
891 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id);
892 $sql .=
' AND pf.fk_paiement = p.rowid';
893 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
894 $resql = $db->query($sql);
899 $res = $db->fetch_object(
$resql);
900 $total_paiements = $res->total_paiements;
903 $total_creditnote_and_deposit = 0;
904 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
905 $sql .=
" re.description, re.fk_facture_source";
906 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
907 $sql .=
" WHERE fk_facture = ".((int) $object->id);
908 $resql = $db->query($sql);
910 while ($obj = $db->fetch_object(
$resql)) {
911 $total_creditnote_and_deposit += $obj->amount_ttc;
917 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object->total_ttc;
918 $discount->amount_tva = 0;
919 $discount->tva_tx = 0;
920 $discount->vat_src_code =
'';
922 $result = $discount->create($user);
928 foreach ($amount_ht as $tva_tx => $xxx) {
929 $discount->amount_ht = abs($amount_ht[$tva_tx]);
930 $discount->amount_tva = abs($amount_tva[$tva_tx]);
931 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
932 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
933 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
934 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
939 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
940 $vat_src_code = $reg[1];
941 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
944 $discount->tva_tx = abs($tva_tx);
945 $discount->vat_src_code = $vat_src_code;
947 $result = $discount->create($user);
958 $result = $object->setPaid($user);
973 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
978 $result = $paiement->fetch(
GETPOST(
'paiement_id',
'int'));
980 $result = $paiement->delete();
982 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
990 } elseif ($action ==
'add' && $usercancreate) {
993 $object->socid =
GETPOST(
'socid',
'int');
995 $selectedLines =
GETPOST(
'toselect',
'array');
997 if (
GETPOST(
'type',
'int') ===
'') {
998 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1004 $originentity =
GETPOST(
'originentity');
1006 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1012 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
1016 if (empty($dateinvoice)) {
1018 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1020 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1026 if (!(
GETPOST(
'fac_replacement',
'int') > 0)) {
1028 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1034 $result = $object->fetch(
GETPOST(
'fac_replacement',
'int'));
1035 $object->fetch_thirdparty();
1037 $object->date = $dateinvoice;
1038 $object->date_pointoftax = $date_pointoftax;
1039 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1040 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1041 $object->ref_client =
GETPOST(
'ref_client',
'alphanohtml');
1042 $object->model_pdf =
GETPOST(
'model',
'alphanohtml');
1043 $object->fk_project =
GETPOST(
'projectid',
'int');
1044 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1045 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1046 $object->fk_account =
GETPOST(
'fk_account',
'int');
1049 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1050 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1051 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1052 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1055 $object->fk_facture_source =
GETPOST(
'fac_replacement',
'int');
1058 $id = $object->createFromCurrent($user);
1067 $sourceinvoice =
GETPOST(
'fac_avoir',
'int');
1068 if (!($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
1070 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1074 if (empty($dateinvoice)) {
1076 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1078 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1085 if (!empty($originentity)) {
1086 $object->entity = $originentity;
1088 $object->socid =
GETPOST(
'socid',
'int');
1089 $object->ref =
GETPOST(
'ref');
1090 $object->date = $dateinvoice;
1091 $object->date_pointoftax = $date_pointoftax;
1092 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1093 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1094 $object->ref_client =
GETPOST(
'ref_client');
1095 $object->model_pdf =
GETPOST(
'model');
1096 $object->fk_project =
GETPOST(
'projectid',
'int');
1097 $object->cond_reglement_id = 0;
1098 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1099 $object->fk_account =
GETPOST(
'fk_account',
'int');
1102 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1103 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1104 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1105 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1108 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1111 $facture_source =
new Facture($db);
1112 if ($facture_source->fetch($object->fk_facture_source) > 0) {
1114 $object->situation_counter = $facture_source->situation_counter;
1115 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1116 $facture_source->fetchPreviousNextSituationInvoice();
1121 $id = $object->create($user);
1126 if ($object->copy_linked_contact($facture_source,
'internal') < 0) {
1128 } elseif ($facture_source->socid == $object->socid) {
1130 if ($object->copy_linked_contact($facture_source,
'external') < 0) {
1141 if (
GETPOST(
'invoiceAvoirWithLines',
'int') == 1 && $id > 0) {
1142 if (!empty($facture_source->lines)) {
1143 $fk_parent_line = 0;
1145 foreach ($facture_source->lines as $line) {
1147 if (method_exists($line,
'fetch_optionals')) {
1149 $line->fetch_optionals();
1153 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1154 $fk_parent_line = 0;
1159 $source_fk_prev_id = $line->fk_prev_id;
1160 $line->fk_prev_id = $line->id;
1162 if (!empty($facture_source->tab_previous_situation_invoice)) {
1165 $tab_jumped_credit_notes = array();
1166 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1167 $searchPreviousInvoice =
true;
1168 while ($searchPreviousInvoice) {
1169 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1170 $searchPreviousInvoice =
false;
1174 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1180 $maxPrevSituationPercent = 0;
1181 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1182 if ($prevLine->id == $source_fk_prev_id) {
1183 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1186 $line->total_ht = $line->total_ht - $prevLine->total_ht;
1187 $line->total_tva = $line->total_tva - $prevLine->total_tva;
1188 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
1189 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
1190 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
1192 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
1193 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
1194 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
1195 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
1200 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1205 $maxPrevSituationPercent = 0;
1206 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1207 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1208 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1209 $maxPrevSituationPercent = $prevLine->situation_percent;
1211 $line->total_ht -= $prevLine->total_ht;
1212 $line->total_tva -= $prevLine->total_tva;
1213 $line->total_ttc -= $prevLine->total_ttc;
1214 $line->total_localtax1 -= $prevLine->total_localtax1;
1215 $line->total_localtax2 -= $prevLine->total_localtax2;
1217 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1218 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1219 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1220 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1226 $line->situation_percent += $maxPrevSituationPercent;
1232 $line->fk_facture = $object->id;
1233 $line->fk_parent_line = $fk_parent_line;
1235 $line->subprice = -$line->subprice;
1236 $line->pa_ht = $line->pa_ht;
1237 $line->total_ht = -$line->total_ht;
1238 $line->total_tva = -$line->total_tva;
1239 $line->total_ttc = -$line->total_ttc;
1240 $line->total_localtax1 = -$line->total_localtax1;
1241 $line->total_localtax2 = -$line->total_localtax2;
1243 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1244 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1245 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1246 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1248 $line->context[
'createcreditnotefrominvoice'] = 1;
1249 $result = $line->insert(0, 1);
1251 $object->lines[] = $line;
1254 if ($result > 0 && $line->product_type == 9) {
1255 $fk_parent_line = $result;
1259 $object->update_price(1);
1263 if (
GETPOST(
'invoiceAvoirWithPaymentRestAmount',
'int') == 1 && $id > 0) {
1264 if ($facture_source->fetch($object->fk_facture_source) > 0) {
1265 $totalpaid = $facture_source->getSommePaiement();
1266 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1267 $totaldeposits = $facture_source->getSumDepositsUsed();
1268 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1270 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 1, 0, 0, 0, 0, 0,
'',
'',
'TTC');
1275 if (!empty($object->fk_facture_source) && $id > 0) {
1276 $facture_source->fetch($object->fk_facture_source);
1277 $facture_source->fetchObjectLinked();
1279 if (!empty($facture_source->linkedObjectsIds)) {
1280 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1281 $object->add_object_linked($sourcetype, current($TIds));
1290 if (empty($dateinvoice)) {
1292 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1294 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1301 $object->socid =
GETPOST(
'socid',
'int');
1302 $object->type =
GETPOST(
'type');
1303 $object->ref =
GETPOST(
'ref');
1304 $object->date = $dateinvoice;
1305 $object->date_pointoftax = $date_pointoftax;
1306 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1307 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1308 $object->ref_client =
GETPOST(
'ref_client');
1309 $object->model_pdf =
GETPOST(
'model');
1310 $object->fk_project =
GETPOST(
'projectid',
'int');
1311 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
1312 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1313 $object->fk_account =
GETPOST(
'fk_account',
'int');
1317 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1318 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1319 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1320 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1323 $object->fac_rec =
GETPOST(
'fac_rec',
'int');
1325 $id = $object->create($user);
1331 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1332 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1333 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1335 if (
GETPOST(
'socid',
'int') < 1) {
1337 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1341 if (empty($dateinvoice)) {
1343 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1345 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1353 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1354 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1359 if ($typeamount && !empty($origin) && !empty($originid)) {
1360 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1361 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1365 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1366 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1370 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1371 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1380 $object->socid =
GETPOST(
'socid',
'int');
1381 $object->type =
GETPOST(
'type');
1382 $object->ref =
GETPOST(
'ref');
1383 $object->date = $dateinvoice;
1384 $object->date_pointoftax = $date_pointoftax;
1385 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1386 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1387 $object->ref_client =
GETPOST(
'ref_client');
1388 $object->ref_customer =
GETPOST(
'ref_client');
1389 $object->model_pdf =
GETPOST(
'model');
1390 $object->fk_project =
GETPOST(
'projectid',
'int');
1391 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
1392 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
1393 $object->fk_account =
GETPOST(
'fk_account',
'int');
1397 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1398 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1399 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1400 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1403 $object->situation_counter = 1;
1404 $object->situation_final = 0;
1405 $object->situation_cycle_ref = $object->newCycle();
1408 if (in_array($object->type, $retainedWarrantyInvoiceAvailableType)) {
1409 $object->retained_warranty =
GETPOST(
'retained_warranty',
'int');
1410 $object->retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
1412 $object->retained_warranty = 0;
1413 $object->retained_warranty_fk_cond_reglement = 0;
1416 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1417 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1418 $object->retained_warranty_date_limit =
dol_stringtotime($retained_warranty_date_limit);
1420 $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);
1422 $object->fetch_thirdparty();
1425 if (!empty($origin) && !empty($originid)) {
1428 $element = $subelement = $origin;
1429 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1430 $element = $regs[1];
1431 $subelement = $regs[2];
1435 if ($element ==
'order') {
1436 $element = $subelement =
'commande';
1438 if ($element ==
'propal') {
1439 $element =
'comm/propal';
1440 $subelement =
'propal';
1442 if ($element ==
'contract') {
1443 $element = $subelement =
'contrat';
1445 if ($element ==
'inter') {
1446 $element = $subelement =
'ficheinter';
1448 if ($element ==
'shipping') {
1449 $element = $subelement =
'expedition';
1452 $object->origin = $origin;
1453 $object->origin_id = $originid;
1456 $object->linked_objects[$object->origin] = $object->origin_id;
1458 if ($object->origin ==
'shipping') {
1459 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1461 $exp->fetch($object->origin_id);
1462 $exp->fetchObjectLinked();
1463 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1464 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1465 $object->linked_objects[
'commande'] = $value;
1470 if (is_array($_POST[
'other_linked_objects']) && !empty($_POST[
'other_linked_objects'])) {
1471 $object->linked_objects = array_merge($object->linked_objects, $_POST[
'other_linked_objects']);
1474 $id = $object->create($user);
1479 $classname = ucfirst($subelement);
1480 $srcobject =
new $classname($db);
1482 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines or deposit lines");
1483 $result = $srcobject->fetch($object->origin_id);
1488 $amountdeposit = array();
1489 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)) {
1490 if ($typeamount ==
'amount') {
1491 $amount = $valuedeposit;
1493 $amount = $srcobject->total_ttc * ($valuedeposit / 100);
1496 $TTotalByTva = array();
1497 foreach ($srcobject->lines as &$line) {
1498 if (!empty($line->special_code)) {
1501 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1504 foreach ($TTotalByTva as $tva => &$total) {
1505 $coef = $total / $srcobject->total_ttc;
1506 $am = $amount * $coef;
1507 $amount_ttc_diff += $am;
1508 $amountdeposit[$tva] += $am / (1 + $tva / 100);
1511 if ($typeamount ==
'amount') {
1512 $amountdeposit[0] = $valuedeposit;
1513 } elseif ($typeamount ==
'variable') {
1516 $lines = $srcobject->lines;
1517 $numlines = count($lines);
1518 for ($i = 0; $i < $numlines; $i++) {
1520 if (empty($lines[$i]->qty)) {
1523 if (!empty($lines[$i]->special_code)) {
1527 $totalamount += $lines[$i]->total_ht;
1528 $tva_tx = $lines[$i]->tva_tx;
1529 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $valuedeposit) / 100;
1533 if ($totalamount == 0) {
1534 $amountdeposit[0] = 0;
1542 $amount_ttc_diff = $amountdeposit[0];
1545 foreach ($amountdeposit as $tva => $amount) {
1546 if (empty($amount)) {
1551 'amount' =>
'FixAmount',
1552 'variable' =>
'VarAmount'
1554 $descline =
'(DEPOSIT)';
1556 if ($typeamount ==
'amount') {
1557 $descline .=
' ('.price($valuedeposit,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
')';
1558 } elseif ($typeamount ==
'variable') {
1559 $descline .=
' ('.$valuedeposit.
'%)';
1562 $descline .=
' - '.$srcobject->ref;
1563 $result = $object->addline(
1570 (empty($conf->global->INVOICE_PRODUCTID_DEPOSIT) ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT),
1575 $lines[$i]->info_bits,
1581 $lines[$i]->special_code,
1598 $diff = $object->total_ttc - $amount_ttc_diff;
1600 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0) {
1601 $object->fetch_lines();
1602 $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100);
1603 $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);
1610 $lines = $srcobject->lines;
1611 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1612 $srcobject->fetch_lines();
1613 $lines = $srcobject->lines;
1618 if (is_array($lines)) {
1619 foreach ($lines as $line) {
1621 $line->qty =
price2num($line->qty * $valuestandardinvoice / 100,
'MS');
1627 if (is_array($lines)) {
1628 foreach ($lines as $line) {
1630 $line->qty =
price2num($line->qty * $valuedeposit / 100,
'MS');
1635 $fk_parent_line = 0;
1636 $num = count($lines);
1638 for ($i = 0; $i < $num; $i++) {
1639 if (!in_array($lines[$i]->
id, $selectedLines)) {
1644 if ($srcobject->element ==
'shipping' && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS && $lines[$i]->qty == 0) {
1648 if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1649 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1651 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',', $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE))) {
1655 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1656 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->libelle);
1657 if ($object->situation_counter == 1) {
1658 $lines[$i]->situation_percent = 0;
1661 if ($lines[$i]->subprice < 0 && empty($conf->global->INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN)) {
1664 $discount->fk_soc = $object->socid;
1665 $discount->amount_ht = abs($lines[$i]->total_ht);
1666 $discount->amount_tva = abs($lines[$i]->total_tva);
1667 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1668 $discount->tva_tx = $lines[$i]->tva_tx;
1669 $discount->fk_user = $user->id;
1670 $discount->description = $desc;
1671 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1672 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1673 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1674 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1676 $discountid = $discount->create($user);
1677 if ($discountid > 0) {
1678 $result = $object->insert_discount($discountid);
1686 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1689 $date_start =
false;
1690 if ($lines[$i]->date_debut_prevue) {
1691 $date_start = $lines[$i]->date_debut_prevue;
1693 if ($lines[$i]->date_debut_reel) {
1694 $date_start = $lines[$i]->date_debut_reel;
1696 if ($lines[$i]->date_start) {
1697 $date_start = $lines[$i]->date_start;
1702 if ($lines[$i]->date_fin_prevue) {
1703 $date_end = $lines[$i]->date_fin_prevue;
1705 if ($lines[$i]->date_fin_reel) {
1706 $date_end = $lines[$i]->date_fin_reel;
1708 if ($lines[$i]->date_end) {
1709 $date_end = $lines[$i]->date_end;
1713 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1714 $fk_parent_line = 0;
1718 if (method_exists($lines[$i],
'fetch_optionals')) {
1719 $lines[$i]->fetch_optionals();
1720 $array_options = $lines[$i]->array_options;
1723 $tva_tx = $lines[$i]->tva_tx;
1724 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
1725 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1730 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty);
1731 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty);
1733 $result = $object->addline(
1735 $lines[$i]->subprice,
1740 $lines[$i]->fk_product,
1741 $lines[$i]->remise_percent,
1745 $lines[$i]->info_bits,
1746 $lines[$i]->fk_remise_except,
1751 $lines[$i]->special_code,
1755 $lines[$i]->fk_fournprice,
1759 $lines[$i]->situation_percent,
1760 $lines[$i]->fk_prev_id,
1761 $lines[$i]->fk_unit,
1776 if ($result > 0 && $lines[$i]->product_type == 9) {
1777 $fk_parent_line = $result;
1787 $object->update_price(1,
'auto', 0, $mysoc);
1817 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
1828 $id = $object->create($user);
1830 for ($i = 1; $i <= $NBLINES; $i++) {
1831 if (
GETPOST(
'idprod'.$i,
'int')) {
1833 $product->fetch(
GETPOST(
'idprod'.$i,
'int'));
1836 $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);
1840 $object->update_price(1,
'auto', 0, $mysoc);
1847 if (empty($dateinvoice)) {
1849 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
1851 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1857 if (!(
GETPOST(
'situations',
'int') > 0)) {
1859 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
1865 $result = $object->fetch(
GETPOST(
'situations',
'int'));
1866 $object->fk_facture_source =
GETPOST(
'situations',
'int');
1869 if (!empty($origin) && !empty($originid)) {
1870 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1872 $object->origin = $origin;
1873 $object->origin_id = $originid;
1876 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
1877 $retained_warranty =
GETPOST(
'retained_warranty',
'int');
1878 if (
price2num($retained_warranty) > 0) {
1879 $object->retained_warranty =
price2num($retained_warranty);
1882 if (
GETPOST(
'retained_warranty_fk_cond_reglement',
'int') > 0) {
1883 $object->retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
1886 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1887 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
1888 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
1890 $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);
1893 foreach ($object->lines as $i => &$line) {
1894 $line->origin = $object->origin;
1895 $line->origin_id = $line->id;
1896 $line->fk_prev_id = $line->id;
1897 $line->fetch_optionals();
1898 $line->situation_percent = $line->get_prev_progress($object->id);
1901 $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);
1902 $line->total_ht = $tabprice[0];
1903 $line->total_tva = $tabprice[1];
1904 $line->total_ttc = $tabprice[2];
1905 $line->total_localtax1 = $tabprice[9];
1906 $line->total_localtax2 = $tabprice[10];
1907 $line->multicurrency_total_ht = $tabprice[16];
1908 $line->multicurrency_total_tva = $tabprice[17];
1909 $line->multicurrency_total_ttc = $tabprice[18];
1912 if ($line->fk_remise_except) {
1914 $result = $discount->fetch($line->fk_remise_except);
1917 if ($discount->fk_facture_line > 0) {
1918 $line->fk_remise_except = 0;
1925 $object->fetch_thirdparty();
1926 $object->date = $dateinvoice;
1927 $object->date_pointoftax = $date_pointoftax;
1928 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1929 $object->note = trim(
GETPOST(
'note',
'restricthtml'));
1930 $object->note_private = trim(
GETPOST(
'note',
'restricthtml'));
1931 $object->ref_client =
GETPOST(
'ref_client',
'alpha');
1932 $object->model_pdf =
GETPOST(
'model',
'alpha');
1933 $object->fk_project =
GETPOST(
'projectid',
'int');
1934 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1935 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1941 $object->situation_counter = $object->situation_counter + 1;
1942 $id = $object->createFromCurrent($user);
1944 $mesg = $object->error;
1946 $nextSituationInvoice =
new Facture($db);
1947 $nextSituationInvoice->fetch($id);
1950 $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
1951 $ret = $extrafields->setOptionalsFromPost(
null, $nextSituationInvoice);
1953 $nextSituationInvoice->insertExtraFields();
1960 if ($id > 0 && !$error) {
1964 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && count($object->lines)) {
1965 $outputlangs = $langs;
1968 $newlang =
GETPOST(
'lang_id',
'aZ09');
1971 $newlang = $object->thirdparty->default_lang;
1973 if (!empty($newlang)) {
1974 $outputlangs =
new Translate(
"", $conf);
1975 $outputlangs->setDefaultLang($newlang);
1976 $outputlangs->load(
'products');
1978 $model = $object->model_pdf;
1979 $ret = $object->fetch($id);
1981 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1987 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
1992 $_GET[
"origin"] = $_POST[
"origin"];
1993 $_GET[
"originid"] = $_POST[
"originid"];
1996 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'') {
1998 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1999 $vat_rate = str_replace(
'*',
'', $vat_rate);
2000 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
2001 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
2002 foreach ($object->lines as $line) {
2003 $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);
2005 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2007 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2008 $remise_percent = str_replace(
'*',
'', $remise_percent);
2009 foreach ($object->lines as $line) {
2010 $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);
2012 } elseif ($action ==
'addline' && $usercancreate) {
2013 $langs->load(
'errors');
2021 $price_ht_devise =
'';
2023 $price_ttc_devise =
'';
2025 if (
GETPOST(
'price_ht') !==
'') {
2028 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2031 if (
GETPOST(
'price_ttc') !==
'') {
2034 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2035 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2038 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2039 if ($prod_entry_mode ==
'free') {
2041 $tva_tx = (
GETPOST(
'tva_tx',
'alpha') ?
price2num(preg_replace(
'/\s*\(.*\)/',
'',
GETPOST(
'tva_tx',
'alpha'))) : 0);
2043 $idprod =
GETPOST(
'idprod',
'int');
2049 if (empty($remise_percent)) {
2050 $remise_percent = 0;
2054 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
2055 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
2057 if (is_array($extralabelsline)) {
2059 foreach ($extralabelsline as $key => $value) {
2060 unset($_POST[
"options_".$key.$predef]);
2064 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2065 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2068 if (!$prod_entry_mode) {
2070 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2074 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2075 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2078 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) {
2079 if (($price_ht < 0 || $price_ttc < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
2080 $langs->load(
"errors");
2081 if ($object->type == $object::TYPE_DEPOSIT) {
2083 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2085 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2089 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2094 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2097 if ($prod_entry_mode ==
'free' && empty($idprod) && empty($product_desc)) {
2098 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2102 $langs->load(
"errors");
2103 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2107 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2108 if ($combinations =
GETPOST(
'combinations',
'array')) {
2112 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2113 $idprod = $res->fk_product_child;
2115 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2121 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
2122 $ret = $object->fetch($id);
2127 $ret = $object->fetch_thirdparty();
2132 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2143 if (!empty($idprod) && $idprod > 0) {
2145 $prod->fetch($idprod);
2147 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2152 $datapriceofproduct = $prod->getSellPrice($mysoc, $object->thirdparty, $pqp);
2154 $pu_ht = $datapriceofproduct[
'pu_ht'];
2155 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2156 $price_min = $datapriceofproduct[
'price_min'];
2157 $price_min_ttc = $datapriceofproduct[
'price_min_ttc'];
2158 $price_base_type = $datapriceofproduct[
'price_base_type'];
2160 $tva_tx = $datapriceofproduct[
'tva_tx'];
2161 $tva_npr = $datapriceofproduct[
'tva_npr'];
2163 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2164 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
2167 if (!empty($price_ht) || $price_ht ===
'0') {
2169 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2170 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2172 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2173 } elseif ($tmpvat != $tmpprodvat) {
2175 if ($price_base_type !=
'HT') {
2176 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2178 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2185 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
2186 $outputlangs = $langs;
2188 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
2189 $newlang =
GETPOST(
'lang_id',
'aZ09');
2191 if (empty($newlang)) {
2192 $newlang = $object->thirdparty->default_lang;
2194 if (!empty($newlang)) {
2195 $outputlangs =
new Translate(
"", $conf);
2196 $outputlangs->setDefaultLang($newlang);
2197 $outputlangs->load(
'products');
2200 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->description;
2202 $desc = $prod->description;
2206 if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
2210 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
2211 $desc = $product_desc;
2213 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
2217 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
2220 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
2221 $outputlangs = $langs;
2223 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
2224 $newlang =
GETPOST(
'lang_id',
'alpha');
2226 if (empty($newlang)) {
2227 $newlang = $object->thirdparty->default_lang;
2229 if (!empty($newlang)) {
2230 $outputlangs =
new Translate(
"", $conf);
2231 $outputlangs->setDefaultLang($newlang);
2232 $outputlangs->load(
'products');
2234 if (!empty($prod->customcode)) {
2235 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2237 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2240 if (!empty($prod->country_code)) {
2241 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
2244 if (!empty($prod->customcode)) {
2245 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2247 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2250 if (!empty($prod->country_code)) {
2251 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
2258 $type = $prod->type;
2259 $fk_unit = $prod->fk_unit;
2263 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2264 $tva_tx = str_replace(
'*',
'', $tva_tx);
2265 if (empty($tva_tx)) {
2268 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2269 $desc = $product_desc;
2271 $fk_unit =
GETPOST(
'units',
'alpha');
2273 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2274 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
2276 if ($pu_ttc && !$pu_ht) {
2277 $price_base_type =
'TTC';
2281 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2288 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
2289 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
2297 $price2num_remise_percent =
price2num($remise_percent);
2298 $price2num_price_min =
price2num($price_min);
2299 $price2num_price_min_ttc =
price2num($price_min_ttc);
2300 if (empty($price2num_pu_ht)) {
2301 $price2num_pu_ht = 0;
2303 if (empty($price2num_remise_percent)) {
2304 $price2num_remise_percent = 0;
2306 if (empty($price2num_price_min)) {
2307 $price2num_price_min = 0;
2309 if (empty($price2num_price_min_ttc)) {
2310 $price2num_price_min_ttc = 0;
2315 if ($pu_ht && $price_min && ((
price2num($pu_ht) * (1 - $remise_percent / 100)) <
price2num($price_min))) {
2316 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2319 } elseif ($pu_ttc && $price_min_ttc && ((
price2num($pu_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc))) {
2320 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2328 if (
isModEnabled(
'productbatch') && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) && !empty($conf->global->INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS)) {
2329 $langs->load(
'productbatch');
2330 foreach ($lines[$i]->detail_batch as $batchline) {
2331 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2336 $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);
2340 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2341 $outputlangs = $langs;
2344 $newlang =
GETPOST(
'lang_id',
'aZ09');
2347 $newlang = $object->thirdparty->default_lang;
2349 if (!empty($newlang)) {
2350 $outputlangs =
new Translate(
"", $conf);
2351 $outputlangs->setDefaultLang($newlang);
2352 $outputlangs->load(
'products');
2354 $model = $object->model_pdf;
2355 $ret = $object->fetch($id);
2357 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2363 unset($_POST[
'prod_entry_mode']);
2365 unset($_POST[
'qty']);
2366 unset($_POST[
'type']);
2367 unset($_POST[
'remise_percent']);
2368 unset($_POST[
'price_ht']);
2369 unset($_POST[
'multicurrency_price_ht']);
2370 unset($_POST[
'price_ttc']);
2371 unset($_POST[
'tva_tx']);
2372 unset($_POST[
'product_ref']);
2373 unset($_POST[
'product_label']);
2374 unset($_POST[
'product_desc']);
2375 unset($_POST[
'fournprice']);
2376 unset($_POST[
'buying_price']);
2377 unset($_POST[
'np_marginRate']);
2378 unset($_POST[
'np_markRate']);
2379 unset($_POST[
'dp_desc']);
2380 unset($_POST[
'idprod']);
2381 unset($_POST[
'units']);
2383 unset($_POST[
'date_starthour']);
2384 unset($_POST[
'date_startmin']);
2385 unset($_POST[
'date_startsec']);
2386 unset($_POST[
'date_startday']);
2387 unset($_POST[
'date_startmonth']);
2388 unset($_POST[
'date_startyear']);
2389 unset($_POST[
'date_endhour']);
2390 unset($_POST[
'date_endmin']);
2391 unset($_POST[
'date_endsec']);
2392 unset($_POST[
'date_endday']);
2393 unset($_POST[
'date_endmonth']);
2394 unset($_POST[
'date_endyear']);
2396 unset($_POST[
'situations']);
2397 unset($_POST[
'progress']);
2405 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2406 if (!$object->fetch($id) > 0) {
2409 $object->fetch_thirdparty();
2418 $vat_rate = str_replace(
'*',
'', $vat_rate);
2430 if (preg_match(
'/\*/', $vat_rate)) {
2435 $vat_rate = str_replace(
'*',
'', $vat_rate);
2436 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty);
2437 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty);
2444 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
2445 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
2447 if (is_array($extralabelsline)) {
2449 foreach ($extralabelsline as $key => $value) {
2450 unset($_POST[
"options_".$key]);
2455 $special_code =
GETPOST(
'special_code',
'int');
2456 if ($special_code == 3) {
2461 $line->fetch(
GETPOST(
'lineid',
'int'));
2462 $percent = $line->get_prev_progress($object->id);
2467 if ($progress >= 0) {
2468 $mesg = $langs->trans(
"CantBeNullOrPositive");
2472 } elseif ($progress < $line->situation_percent) {
2473 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
2477 } elseif ($progress < $percent) {
2478 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
2488 $productid =
GETPOST(
'productid',
'int');
2489 if (!empty($productid)) {
2491 $product->fetch($productid);
2493 $type = $product->type;
2495 $price_min = $product->price_min;
2496 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
2497 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
2499 $price_min_ttc = $product->price_min_ttc;
2500 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
2501 $price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
2508 if ($pu_ht && $price_min && (((
float)
price2num($pu_ht) * (1 - (
float) $remise_percent / 100)) < (
float)
price2num($price_min))) {
2509 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2512 $action =
'editline';
2513 } elseif ($pu_ttc && $price_min_ttc && ((
price2num($pu_ttc) * (1 - (
float) $remise_percent / 100)) <
price2num($price_min_ttc))) {
2514 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2517 $action =
'editline';
2522 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2526 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
2531 $langs->load(
"errors");
2532 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2535 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) {
2536 if (($pu_ht < 0 || $pu_ttc < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
2537 $langs->load(
"errors");
2538 if ($object->type == $object::TYPE_DEPOSIT) {
2540 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2542 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2546 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2554 if (empty($usercancreatemargin)) {
2555 foreach ($object->lines as &$line) {
2556 if ($line->id ==
GETPOST(
'lineid',
'int')) {
2557 $fournprice = $line->fk_fournprice;
2558 $buyingprice = $line->pa_ht;
2564 $price_base_type =
'HT';
2566 if (empty($pu) && !empty($pu_ttc)) {
2568 $price_base_type =
'TTC';
2571 $result = $object->updateline(
2585 GETPOST(
'fk_parent_line',
'int'),
2598 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2600 $outputlangs = $langs;
2603 $newlang =
GETPOST(
'lang_id',
'aZ09');
2606 $newlang = $object->thirdparty->default_lang;
2608 if (!empty($newlang)) {
2609 $outputlangs =
new Translate(
"", $conf);
2610 $outputlangs->setDefaultLang($newlang);
2611 $outputlangs->load(
'products');
2614 $ret = $object->fetch($id);
2615 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2618 unset($_POST[
'qty']);
2619 unset($_POST[
'type']);
2620 unset($_POST[
'productid']);
2621 unset($_POST[
'remise_percent']);
2622 unset($_POST[
'price_ht']);
2623 unset($_POST[
'multicurrency_price_ht']);
2624 unset($_POST[
'price_ttc']);
2625 unset($_POST[
'tva_tx']);
2626 unset($_POST[
'product_ref']);
2627 unset($_POST[
'product_label']);
2628 unset($_POST[
'product_desc']);
2629 unset($_POST[
'fournprice']);
2630 unset($_POST[
'buying_price']);
2631 unset($_POST[
'np_marginRate']);
2632 unset($_POST[
'np_markRate']);
2634 unset($_POST[
'dp_desc']);
2635 unset($_POST[
'idprod']);
2636 unset($_POST[
'units']);
2638 unset($_POST[
'date_starthour']);
2639 unset($_POST[
'date_startmin']);
2640 unset($_POST[
'date_startsec']);
2641 unset($_POST[
'date_startday']);
2642 unset($_POST[
'date_startmonth']);
2643 unset($_POST[
'date_startyear']);
2644 unset($_POST[
'date_endhour']);
2645 unset($_POST[
'date_endmin']);
2646 unset($_POST[
'date_endsec']);
2647 unset($_POST[
'date_endday']);
2648 unset($_POST[
'date_endmonth']);
2649 unset($_POST[
'date_endyear']);
2651 unset($_POST[
'situations']);
2652 unset($_POST[
'progress']);
2657 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modifier')) {
2658 if (!$object->fetch($id) > 0) {
2661 if (
GETPOST(
'all_progress') !=
"") {
2662 $all_progress =
GETPOST(
'all_progress',
'int');
2663 foreach ($object->lines as $line) {
2664 $percent = $line->get_prev_progress($object->id);
2665 if (floatval($all_progress) < floatval($percent)) {
2666 $mesg = $langs->trans(
"Line").
' '.$i.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
2670 $object->update_percent($line,
GETPOST(
'all_progress'),
false);
2673 $object->update_price(1);
2675 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
2676 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2678 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
2680 $object->fetch($id,
'',
'',
'',
true);
2686 && $object->is_last_in_cycle()
2687 && $usercanunvalidate
2690 $newCycle = $object->newCycle();
2691 if ($newCycle > 1) {
2693 $lastCycle = $object->situation_cycle_ref;
2694 $lastSituationCounter = $object->situation_counter;
2695 $linkedCreditNotesList = array();
2697 if (count($object->tab_next_situation_invoice) > 0) {
2698 foreach ($object->tab_next_situation_invoice as $next_invoice) {
2700 && $next_invoice->situation_counter == $object->situation_counter
2701 && $next_invoice->fk_facture_source == $object->id
2703 $linkedCreditNotesList[] = $next_invoice->id;
2708 $object->situation_cycle_ref = $newCycle;
2709 $object->situation_counter = 1;
2710 $object->situation_final = 0;
2711 if ($object->update($user) > 0) {
2713 if (count($linkedCreditNotesList) > 0) {
2715 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
2716 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
2717 $sql .=
' , situation_final=0';
2718 $sql .=
' , situation_counter='.((int) $object->situation_counter);
2719 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
2721 $resql = $db->query($sql);
2727 foreach ($object->lines as $line) {
2729 if ($line->product_type == 9) {
2734 if (!empty($object->tab_previous_situation_invoice)) {
2736 $lineIndex = count($object->tab_previous_situation_invoice) - 1;
2737 $searchPreviousInvoice =
true;
2738 while ($searchPreviousInvoice) {
2740 $searchPreviousInvoice =
false;
2748 $maxPrevSituationPercent = 0;
2749 foreach ($object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
2750 if ($prevLine->id == $line->fk_prev_id) {
2751 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
2756 $line->situation_percent = $line->situation_percent - $maxPrevSituationPercent;
2758 if ($line->update() < 0) {
2767 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
2769 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
2772 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
2775 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
2778 } elseif ($action ==
'import_lines_from_object'
2783 $fromElement =
GETPOST(
'fromelement');
2784 $fromElementid =
GETPOST(
'fromelementid');
2785 $importLines =
GETPOST(
'line_checkbox');
2787 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
2788 if ($fromElement ==
'commande') {
2790 $lineClassName =
'OrderLine';
2791 } elseif ($fromElement ==
'propal') {
2792 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
2793 $lineClassName =
'PropaleLigne';
2795 $nextRang = count($object->lines) + 1;
2798 foreach ($importLines as $lineId) {
2799 $lineId = intval($lineId);
2800 $originLine =
new $lineClassName($db);
2801 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
2802 $originLine->fetch_optionals();
2803 $desc = $originLine->desc;
2804 $pu_ht = $originLine->subprice;
2805 $qty = $originLine->qty;
2806 $txtva = $originLine->tva_tx;
2807 $txlocaltax1 = $originLine->localtax1_tx;
2808 $txlocaltax2 = $originLine->localtax2_tx;
2809 $fk_product = $originLine->fk_product;
2810 $remise_percent = $originLine->remise_percent;
2811 $date_start = $originLine->date_start;
2812 $date_end = $originLine->date_end;
2814 $info_bits = $originLine->info_bits;
2815 $fk_remise_except = $originLine->fk_remise_except;
2816 $price_base_type =
'HT';
2818 $type = $originLine->product_type;
2819 $rang = $nextRang++;
2820 $special_code = $originLine->special_code;
2821 $origin = $originLine->element;
2822 $origin_id = $originLine->id;
2823 $fk_parent_line = 0;
2824 $fk_fournprice = $originLine->fk_fournprice;
2825 $pa_ht = $originLine->pa_ht;
2826 $label = $originLine->label;
2827 $array_options = $originLine->array_options;
2829 $situation_percent = 0;
2831 $situation_percent = 100;
2834 $fk_unit = $originLine->fk_unit;
2835 $pu_ht_devise = $originLine->multicurrency_subprice;
2837 $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);
2856 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2862 $triggersendname =
'BILL_SENTBYMAIL';
2864 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
2865 $trackid =
'inv'.$object->id;
2866 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2869 $upload_dir = $conf->facture->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity];
2870 $permissiontoadd = $usercancreate;
2871 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2874 if ($action ==
'update_extras') {
2878 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
2885 $result = $object->insertExtraFields(
'BILL_MODIFY');
2893 $action =
'edit_extras';
2897 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
2898 if ($action ==
'addcontact') {
2899 $result = $object->fetch($id);
2901 if ($result > 0 && $id > 0) {
2904 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2908 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2911 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2912 $langs->load(
"errors");
2913 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2918 } elseif ($action ==
'swapstatut') {
2920 if ($object->fetch($id)) {
2921 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
2925 } elseif ($action ==
'deletecontact') {
2927 $object->fetch($id);
2928 $result = $object->delete_contact($lineid);
2931 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2939 $action =
'edit_extras';
2955 $paymentstatic =
new Paiement($db);
2956 $bankaccountstatic =
new Account($db);
2963 $title = $object->ref.
" - ".$langs->trans(
'Card');
2964 if ($action ==
'create') {
2965 $title = $langs->trans(
"NewBill");
2967 $help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
2973 if ($action ==
'create') {
2974 $facturestatic =
new Facture($db);
2975 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
2980 $res = $soc->fetch($socid);
2983 $currency_code = $conf->currency;
2987 $remise_absolue = 0;
2988 if (!empty($origin) && !empty($originid)) {
2990 $element = $subelement = $origin;
2992 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
2993 $element = $regs[1];
2994 $subelement = $regs[2];
2997 if ($element ==
'project') {
2998 $projectid = $originid;
3000 if (empty($cond_reglement_id)) {
3001 $cond_reglement_id = $soc->cond_reglement_id;
3003 if (empty($mode_reglement_id)) {
3004 $mode_reglement_id = $soc->mode_reglement_id;
3006 if (empty($fk_account)) {
3007 $fk_account = $soc->fk_account;
3009 if (!$remise_percent) {
3010 $remise_percent = $soc->remise_percent;
3012 if (!$dateinvoice) {
3014 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
3018 if ($element ==
'order' || $element ==
'commande') {
3019 $element = $subelement =
'commande';
3021 if ($element ==
'propal') {
3022 $element =
'comm/propal';
3023 $subelement =
'propal';
3025 if ($element ==
'contract') {
3026 $element = $subelement =
'contrat';
3028 if ($element ==
'shipping') {
3029 $element = $subelement =
'expedition';
3034 $classname = ucfirst($subelement);
3035 $objectsrc =
new $classname($db);
3036 $objectsrc->fetch($originid);
3037 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3038 $objectsrc->fetch_lines();
3040 $objectsrc->fetch_thirdparty();
3042 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3043 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3046 if (empty($socid)) {
3047 $soc = $objectsrc->thirdparty;
3050 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
3052 if ($element ==
'expedition') {
3053 $ref_client = (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
'');
3055 $elem = $subelem = $objectsrc->origin;
3056 $expeoriginid = $objectsrc->origin_id;
3058 $classname = ucfirst($subelem);
3060 $expesrc =
new $classname($db);
3061 $expesrc->fetch($expeoriginid);
3063 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3064 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3065 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3066 $remise_percent = (!empty($expesrc->remise_percent) ? $expesrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
3067 $remise_absolue = (!empty($expesrc->remise_absolue) ? $expesrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
3070 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3071 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3075 $expesrc->fetch_optionals();
3076 $object->array_options = $expesrc->array_options;
3078 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
3079 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3080 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3081 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
3082 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
3085 if (!empty($objectsrc->multicurrency_code)) {
3086 $currency_code = $objectsrc->multicurrency_code;
3088 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
3089 $currency_tx = $objectsrc->multicurrency_tx;
3094 $objectsrc->fetch_optionals();
3095 $object->array_options = $objectsrc->array_options;
3099 $cond_reglement_id = $soc->cond_reglement_id;
3100 $mode_reglement_id = $soc->mode_reglement_id;
3101 $fk_account = $soc->fk_account;
3102 $remise_percent = $soc->remise_percent;
3103 $remise_absolue = 0;
3104 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
3106 if (
isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3107 $currency_code = $soc->multicurrency_code;
3112 if (empty($cond_reglement_id)) {
3113 $cond_reglement_id =
GETPOST(
"cond_reglement_id",
'int');
3117 if (empty($mode_reglement_id)) {
3118 $mode_reglement_id =
GETPOST(
"mode_reglement_id",
'int');
3124 if (!empty($soc->id)) {
3125 $absolute_discount = $soc->getAvailableDiscounts();
3127 $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));
3128 $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));
3130 if (!empty($conf->use_javascript_ajax)) {
3131 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3137 if ($origin ==
'contrat') {
3138 $langs->load(
"admin");
3139 $text = $langs->trans(
"ToCreateARecurringInvoice");
3140 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3141 if (empty($conf->global->INVOICE_DISABLE_AUTOMATIC_RECURRING_INVOICE)) {
3142 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3144 print
info_admin($text, 0, 0, 0,
'opacitymedium').
'<br>';
3147 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3148 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3149 print
'<input type="hidden" name="action" value="add">';
3151 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3153 print
'<input name="ref" type="hidden" value="provisoire">';
3154 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3155 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3156 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3157 print
'<input name="force_fk_account" type="hidden" value="0">';
3158 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3159 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3160 print
'<input type="hidden" name="originentity" value="'.GETPOST(
'originentity').
'">';
3161 if (!empty($currency_tx)) {
3162 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3167 print
'<table class="border centpercent">';
3172 $exampletemplateinvoice =
new FactureRec($db);
3174 if (empty($origin) && empty($originid) &&
GETPOST(
'fac_rec',
'int') > 0) {
3175 $invoice_predefined->fetch(
GETPOST(
'fac_rec',
'int'));
3179 if ($soc->id > 0 && (!
GETPOST(
'fac_rec',
'int') || !empty($invoice_predefined->frequency))) {
3181 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3182 print
'<td colspan="2">';
3183 print $soc->getNomUrl(1,
'customer');
3184 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3186 $arrayoutstandingbills = $soc->getOutstandingBills();
3187 $outstandingBills = $arrayoutstandingbills[
'opened'];
3188 print
' - <span class="opacitymedium">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3189 print
price($outstandingBills,
'', $langs, 0, 0, -1, $conf->currency);
3190 if ($soc->outstanding_limit !=
'') {
3191 if ($outstandingBills > $soc->outstanding_limit) {
3192 print
img_warning($langs->trans(
"OutstandingBillReached"));
3194 print
' / '.price($soc->outstanding_limit,
'', $langs, 0, 0, -1, $conf->currency);
3199 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3200 print
'<td colspan="2">';
3201 print
img_picto(
'',
'company').$form->select_company($soc->id,
'socid',
'((s.client = 1 OR s.client = 3) AND s.status = 1)',
'SelectThirdParty', 1, 0,
null, 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3203 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
3204 print
'<script type="text/javascript">
3205 $(document).ready(function() {
3206 $("#socid").change(function() {
3208 console.log("Submit page");
3209 $(\'input[name="action"]\').val(\'create\');
3210 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3211 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3212 $(\'input[name="force_fk_account"]\').val(\'1\');
3213 $("#formtocreate").submit(); */
3215 // For company change, we must reuse data of comany, not input already done, so we call a GET with action=create, not a POST submit.
3216 console.log("We have changed the company - Reload page");
3217 var socid = $(this).val();
3218 var fac_rec = $(\'#fac_rec\').val();
3219 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3224 if (!
GETPOST(
'fac_rec',
'int')) {
3225 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>';
3232 if (empty($origin) && empty($originid) &&
GETPOST(
'fac_rec',
'int') > 0) {
3233 $invoice_predefined->fetch(
GETPOST(
'fac_rec',
'int'));
3235 $dateinvoice = $invoice_predefined->date_when;
3236 if (empty($projectid)) {
3237 $projectid = $invoice_predefined->fk_project;
3239 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
3240 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
3241 $fk_account = $invoice_predefined->fk_account;
3242 $note_public = $invoice_predefined->note_public;
3243 $note_private = $invoice_predefined->note_private;
3245 if (!empty($invoice_predefined->multicurrency_code)) {
3246 $currency_code = $invoice_predefined->multicurrency_code;
3248 if (!empty($invoice_predefined->multicurrency_tx)) {
3249 $currency_tx = $invoice_predefined->multicurrency_tx;
3252 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
3253 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
3254 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
3256 $resql = $db->query($sql);
3258 $num = $db->num_rows(
$resql);
3262 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
3264 print
'<select class="flat" id="fac_rec" name="fac_rec">';
3265 print
'<option value="0" selected></option>';
3267 $objp = $db->fetch_object(
$resql);
3268 print
'<option value="'.$objp->rowid.
'"';
3269 if (
GETPOST(
'fac_rec',
'int') == $objp->rowid) {
3271 $exampletemplateinvoice->fetch(
GETPOST(
'fac_rec',
'int'));
3273 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
3281 if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED)) {
3282 print
'<script type="text/javascript">
3283 $(document).ready(function() {
3284 $("#fac_rec").change(function() {
3285 console.log("We have changed the template invoice - Reload page");
3286 var fac_rec = $(this).val();
3287 var socid = $(\'#socid\').val();
3288 // 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.
3289 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3302 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td colspan="2">';
3303 print
'<div class="tagtable">'.
"\n";
3306 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3307 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOST(
'type',
'int') ?
'' :
' checked').
'> ';
3308 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
3309 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
3310 print
'<table class="nobordernopadding"><tr>';
3314 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
3323 print
'<td class="nowrap" style="padding-left: 15px">';
3324 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%').
'"/>';
3327 print
'</tr></table>';
3328 print
'</div></div>';
3330 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
3332 if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) {
3333 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3334 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOST(
'type') == 3 ?
' checked' :
'').
'> ';
3335 print
'<script type="text/javascript">
3336 jQuery(document).ready(function() {
3337 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
3338 jQuery("#radio_standard").prop("checked", true);
3340 jQuery("#typedeposit, #valuedeposit").click(function() {
3341 jQuery("#radio_deposit").prop("checked", true);
3343 jQuery("#typedeposit").change(function() {
3344 console.log("We change type of down payment");
3345 jQuery("#radio_deposit").prop("checked", true);
3346 setRadioForTypeOfIncoice();
3348 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
3349 setRadioForTypeOfIncoice();
3351 function setRadioForTypeOfIncoice() {
3352 console.log("Change radio");
3353 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
3354 jQuery(".checkforselect").prop("disabled", true);
3355 jQuery(".checkforselect").prop("checked", false);
3357 jQuery(".checkforselect").prop("disabled", false);
3358 jQuery(".checkforselect").prop("checked", true);
3364 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
3365 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
3366 print
'<table class="nobordernopadding"><tr>';
3370 if (($origin ==
'propal') || ($origin ==
'commande')) {
3371 print
'<td class="nowrap" style="padding-left: 15px">';
3373 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
3374 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
3375 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
3377 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
3378 $valuedeposit =
GETPOST(
'valuedeposit',
'int');
3379 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
3380 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
3381 if (!empty($origin_payment_conditions_deposit_percent)) {
3382 $typedeposit =
'variable';
3385 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
3386 $valuedeposit = $objectsrc->deposit_percent;
3388 print
$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
3390 print
'<td class="nowrap" style="padding-left: 5px">';
3391 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.$valuedeposit.
'"/>';
3394 print
'</tr></table>';
3396 print
'</div></div>';
3401 if (!empty($conf->global->INVOICE_USE_SITUATION)) {
3403 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3404 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
3405 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
3406 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3);
3408 print
'</div></div>';
3411 $opt =
$form->selectSituationInvoices(
GETPOST(
'originid',
'int'), $socid);
3413 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3414 $tmp =
'<input type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOST(
'originid',
'int') ?
' checked' :
'');
3415 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3416 $tmp .=
' disabled';
3419 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3420 $text .=
'<select class="flat" id="situations" name="situations"';
3421 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3422 $text .=
' disabled';
3426 $text .=
'</select>';
3427 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
3429 print
'</div></div>';
3433 if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT)) {
3435 $facids = $facturestatic->list_replacable_invoices($soc->id);
3441 if (is_array($facids)) {
3442 foreach ($facids as $facparam) {
3443 $options .=
'<option value="'.$facparam [
'id'].
'"';
3444 if ($facparam[
'id'] ==
GETPOST(
'fac_replacement',
'int')) {
3445 $options .=
' selected';
3447 $options .=
'>'.$facparam[
'ref'];
3448 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
3449 $options .=
'</option>';
3453 print
'<!-- replacement line -->';
3454 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3455 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
3456 if (!$options || $invoice_predefined->id > 0) {
3457 $tmp .=
' disabled';
3460 print
'<script type="text/javascript">
3461 jQuery(document).ready(function() {
3462 jQuery("#fac_replacement").change(function() {
3463 jQuery("#radio_replacement").prop("checked", true);
3467 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
3468 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
3469 if (!$options || $invoice_predefined->id > 0) {
3470 $text .=
' disabled';
3474 $text .=
'<option value="-1"> </option>';
3477 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
3479 $text .=
'</select>';
3480 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3482 print
'</div></div>';
3485 if (!empty($conf->global->INVOICE_USE_SITUATION)) {
3486 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3487 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3488 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceFirstSituationAsk").
'</label> ';
3489 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3490 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3);
3492 print
'</div></div>';
3494 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3495 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3496 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3497 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3498 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3);
3500 print
'</div></div>';
3503 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3504 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
3505 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceReplacement").
'</label> ';
3506 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3507 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3509 print
'</div></div>';
3512 if (empty($origin)) {
3515 if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) {
3517 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
3523 $newinvoice_static =
new Facture($db);
3524 foreach ($facids as $key => $valarray) {
3525 $newinvoice_static->id = $key;
3526 $newinvoice_static->ref = $valarray [
'ref'];
3527 $newinvoice_static->statut = $valarray [
'status'];
3528 $newinvoice_static->type = $valarray [
'type'];
3529 $newinvoice_static->paye = $valarray [
'paye'];
3531 $optionsav .=
'<option value="'.$key.
'"';
3532 if ($key ==
GETPOST(
'fac_avoir')) {
3533 $optionsav .=
' selected';
3536 $newinvoice_static->fetch_optionals($key);
3537 $object->array_options = $newinvoice_static->array_options;
3540 $optionsav .= $newinvoice_static->ref;
3541 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
3542 $optionsav .=
'</option>';
3545 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3546 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
3547 if ((!$optionsav && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) || $invoice_predefined->id > 0) {
3548 $tmp .=
' disabled';
3552 print
'<script type="text/javascript">
3553 jQuery(document).ready(function() {
3554 if (! jQuery("#radio_creditnote").is(":checked"))
3556 jQuery("#credit_note_options").hide();
3558 jQuery("#radio_creditnote").click(function() {
3559 jQuery("#credit_note_options").show();
3561 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
3562 jQuery("#credit_note_options").hide();
3566 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
3568 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3569 if (!$optionsav || $invoice_predefined->id > 0) {
3570 $text .=
' disabled';
3574 $text .=
'<option value="-1"></option>';
3575 $text .= $optionsav;
3577 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
3579 $text .=
'</select>';
3580 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3583 print
'<div id="credit_note_options" class="clearboth">';
3584 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>";
3585 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>";
3588 print
'</div></div>';
3591 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3592 if (empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
3593 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3595 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
3597 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceAvoir").
'</label> ';
3598 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3599 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3601 print
'</div></div>'.
"\n";
3606 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3607 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
3608 $text =
'<label>'.$tmp.$langs->trans(
"RepeatableInvoice").
'</label> ';
3610 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3);
3612 print
'</div></div>';
3617 if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) {
3621 foreach ($listtType as $type) {
3622 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
3623 $curent = !empty($conf->global->{$thisTypeConfName}) ? $conf->global->{$thisTypeConfName}:$conf->global->FACTURE_ADDON_PDF;
3624 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$curent.
'"';
3627 print
'<script type="text/javascript">
3628 $(document).ready(function() {
3629 var listType = {'.$jsListType.
'};
3630 $("[name=\'type\'").change(function() {
3631 if($( this ).prop("checked"))
3633 if(($( this ).val() in listType))
3635 $("#model").val(listType[$( this ).val()]);
3639 $("#model").val("'.$conf->global->FACTURE_ADDON_PDF.
'");
3652 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
3656 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin',
'alpha').
'&originid='.
GETPOST(
'originid',
'int'));
3657 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3663 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
3666 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
3667 print
$form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'',
'',
'',
'',
"add", 1, 1);
3671 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
3672 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
3673 print
$form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax',
'',
'',
'',
"add", 1, 1);
3678 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
3679 print
$form->getSelectConditionsPaiements(
GETPOSTISSET(
'cond_reglement_id') ?
GETPOST(
'cond_reglement_id',
'int') : $cond_reglement_id,
'cond_reglement_id');
3683 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
3684 $rwStyle =
'display:none;';
3685 if (in_array(
GETPOST(
'type',
'int'), $retainedWarrantyInvoiceAvailableType)) {
3689 $retained_warranty =
GETPOST(
'retained_warranty',
'int');
3690 if (empty($retained_warranty)) {
3691 if (!empty($objectsrc->retained_warranty)) {
3692 $retained_warranty = $objectsrc->retained_warranty;
3695 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT;
3697 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
3698 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
3701 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
3702 $retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
3703 if (empty($retained_warranty_fk_cond_reglement)) {
3704 $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
3705 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
3706 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
3708 $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
3711 print
$form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
3714 print
'<script type="text/javascript">
3715 $(document).ready(function() {
3716 $("[name=\'type\']").change(function() {
3717 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
3719 $(".retained-warranty-line").show();
3720 $("#new-situation-invoice-retained-warranty").val("'.floatval($retained_warranty_js_default).
'");
3723 $(".retained-warranty-line").hide();
3724 $("#new-situation-invoice-retained-warranty").val("");
3728 $("[name=\'type\']:checked").trigger("change");
3734 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
3735 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
3736 print
$form->select_types_paiements(
GETPOSTISSET(
'mode_reglement_id') ?
GETPOST(
'mode_reglement_id') : $mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
3741 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td colspan="2">';
3742 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
3743 print
$form->select_comptes(($fk_account < 0 ?
'' : $fk_account),
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
3749 $langs->load(
'projects');
3750 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
3751 print
img_picto(
'',
'project').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
3752 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>';
3759 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
3760 print
'<td colspan="2" class="maxwidthonsmartphone">';
3761 $incoterm_id =
GETPOST(
'incoterm_id');
3762 $incoterm_location =
GETPOST(
'location_incoterms');
3763 if (empty($incoterm_id)) {
3764 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
3765 $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
3767 print
$form->select_incoterms($incoterm_id, $incoterm_location);
3772 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid'=>$socid);
3773 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
3774 print $hookmanager->resPrint;
3775 if (empty($reshook)) {
3776 if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE) && !empty($soc->id)) {
3778 $tpExtrafields =
new Extrafields($db);
3779 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
3780 if ($soc->fetch_optionals() > 0) {
3781 $object->array_options = array_merge($object->array_options, $soc->array_options);
3785 print $object->showOptionals($extrafields,
'create',
$parameters);
3789 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
3790 print
'<td colspan="2">';
3791 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
3792 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
3794 if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) {
3796 $paramkey =
'FACTURE_ADDON_PDF_'.$object->type;
3797 $preselected = !empty($conf->global->$paramkey) ? $conf->global->$paramkey : $conf->global->FACTURE_ADDON_PDF;
3799 $preselected = $conf->global->FACTURE_ADDON_PDF;
3801 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
3807 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
3808 print
'<td colspan="2" class="maxwidthonsmartphone">';
3809 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
3810 print
$form->selectMultiCurrency($currency_code,
'multicurrency_code');
3816 if (
GETPOST(
'fac_rec',
'int') > 0) {
3817 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
3818 if (empty($dateexample)) {
3821 $substitutionarray = array(
3822 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
3823 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
3824 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
3825 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
3826 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
3827 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
3828 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
3829 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
3830 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
3831 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
3832 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
3835 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
3836 foreach ($substitutionarray as $key => $val) {
3837 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
3839 $htmltext .=
'</i>';
3844 print
'<td class="tdtop">';
3845 print
$form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
3847 print
'<td valign="top" colspan="2">';
3848 $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%');
3849 print $doleditor->Create(1);
3852 if (empty($user->socid)) {
3854 print
'<td class="tdtop">';
3855 print
$form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
3857 print
'<td valign="top" colspan="2">';
3858 $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%');
3859 print $doleditor->Create(1);
3865 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
3866 $langs->loadLangs(array(
'orders',
'propal'));
3869 if ($origin ==
'contrat') {
3871 $objectsrc->remise_absolue = $remise_absolue;
3872 $objectsrc->remise_percent = $remise_percent;
3873 $objectsrc->update_price(1,
'auto', 1);
3876 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
3877 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
3878 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
3879 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
3884 switch (get_class($objectsrc)) {
3886 $newclassname =
'CommercialProposal';
3889 $newclassname =
'Order';
3892 $newclassname =
'Sending';
3895 $newclassname =
'Contract';
3898 $newclassname =
'Intervention';
3901 $newclassname = get_class($objectsrc);
3905 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
3906 print
'<td colspan="2">';
3907 print $objectsrc->getNomUrl(1);
3909 $objectsrc->fetchObjectLinked($originid, $origin,
'',
'facture');
3910 if (is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
3912 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
3915 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht).
'</td></tr>';
3916 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva).
"</td></tr>";
3917 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
3918 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax1).
"</td></tr>";
3921 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
3922 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax2).
"</td></tr>";
3924 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc).
"</td></tr>";
3927 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
3928 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
3929 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
3937 print
$form->buttonsSaveCancel(
"CreateDraft");
3940 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
3943 $title = $langs->trans(
'ProductsAndServices');
3946 print
'<div class="div-table-responsive-no-min">';
3947 print
'<table class="noborder centpercent">';
3949 $objectsrc->printOriginLinesList(
'', $selectedLines);
3956 } elseif ($id > 0 || !empty($ref)) {
3957 if (empty($object->id)) {
3958 $langs->load(
'errors');
3959 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
3968 $result = $object->fetch($id, $ref);
3975 $extrafields->fetch_name_optionals_label($object->table_element);
3977 if ($user->socid > 0 && $user->socid != $object->socid) {
3981 $result = $object->fetch_thirdparty();
3983 $result = $soc->fetch($object->socid);
3987 $selleruserevenustamp = $mysoc->useRevenueStamp();
3989 $totalpaid = $object->getSommePaiement();
3990 $totalcreditnotes = $object->getSumCreditNotesUsed();
3991 $totaldeposits = $object->getSumDepositsUsed();
3999 $resteapayer =
price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4003 $multicurrency_totalpaid = $object->getSommePaiement(1);
4004 $multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
4005 $multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
4006 $multicurrency_resteapayer =
price2num($object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4010 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 && $object->multicurrency_code != $conf->currency) {
4011 $resteapayer =
price2num($multicurrency_resteapayer / $object->multicurrency_tx,
'MT');
4015 if ($object->paye) {
4018 $resteapayeraffiche = $resteapayer;
4020 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
4021 $filterabsolutediscount =
"fk_facture_source IS NULL";
4022 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4024 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4025 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4028 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
4029 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
4030 $absolute_discount =
price2num($absolute_discount,
'MT');
4031 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4033 $author =
new User($db);
4034 if ($object->user_author) {
4035 $author->fetch($object->user_author);
4038 $objectidnext = $object->getIdReplacingInvoice();
4042 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
'bill');
4047 if ($action ==
'converttoreduc') {
4049 $type_fac =
'ExcessReceived';
4051 $type_fac =
'CreditNote';
4053 $type_fac =
'Deposit';
4055 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4056 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4057 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4061 if ($action ==
'delete') {
4062 $text = $langs->trans(
'ConfirmDeleteBill', $object->ref);
4063 $formquestion = array();
4065 if ($object->type !=
Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->statut >= 1) {
4066 $qualified_for_stock_change = 0;
4067 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
4068 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4070 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4073 if ($qualified_for_stock_change) {
4074 $langs->load(
"stocks");
4075 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4077 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
4079 if ($conf->browser->name ==
'ie') {
4082 $formquestion = array(
4086 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4088 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4090 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4093 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4098 if ($action ==
'situationout') {
4099 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle', $object->ref);
4100 $label = $langs->trans(
"ConfirmOuting");
4101 $formquestion = array();
4106 && $object->is_last_in_cycle()
4107 && $usercanunvalidate
4109 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4114 if ($action ==
'valid') {
4116 $objectref = substr($object->ref, 1, 4);
4117 if ($objectref ==
'PROV') {
4118 $savdate = $object->date;
4119 if (!empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
4121 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
4123 $numref = $object->getNextNumRef($soc);
4126 $numref = $object->ref;
4129 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4131 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4132 $notify =
new Notify($db);
4134 $text .= $notify->confirmMessage(
'BILL_VALIDATE', $object->socid, $object);
4136 $formquestion = array();
4139 $qualified_for_stock_change = 0;
4140 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
4141 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4143 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4146 if ($qualified_for_stock_change) {
4147 $langs->load(
"stocks");
4148 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4149 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4152 $warehouse_array = $warehouse->list_array();
4153 if (count($warehouse_array) == 1) {
4154 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4155 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4157 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockIncrease") : $langs->trans(
"SelectWarehouseForStockDecrease");
4158 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4160 $formquestion = array(
4166 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4170 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
4175 foreach ($object->lines as $line) {
4176 $res = $line->fetch_product();
4178 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
4184 if ($nbMandated > 0 ) $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
4187 $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);
4191 if ($action ==
'modif') {
4192 $text = $langs->trans(
'ConfirmUnvalidateBill', $object->ref);
4193 $formquestion = array();
4196 $qualified_for_stock_change = 0;
4197 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
4198 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4200 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4203 if ($qualified_for_stock_change) {
4204 $langs->load(
"stocks");
4205 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4206 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4209 $warehouse_array = $warehouse->list_array();
4210 if (count($warehouse_array) == 1) {
4211 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
4212 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4214 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
4215 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4217 $formquestion = array(
4223 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4227 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
4231 if ($action ==
'paid' && ($resteapayer <= 0 || (!empty($conf->global->INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) && $resteapayer == $object->total_ttc))) {
4232 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill', $object->ref),
'confirm_paid',
'',
"yes", 1);
4234 if ($action ==
'paid' && $resteapayer > 0 && (empty($conf->global->INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $resteapayer != $object->total_ttc)) {
4238 $close[$i][
'code'] =
'discount_vat';
4240 $close[$i][
'code'] =
'badcustomer';
4242 $close[$i][
'code'] =
'bankcharge';
4244 $close[$i][
'code'] =
'other';
4248 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
4250 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4252 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
4254 $close[$i][
'label'] = $langs->trans(
"Other");
4258 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4260 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4262 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4264 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
4267 foreach ($close as $key => $val) {
4268 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
4272 $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'));
4274 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially', $object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 340, 600);
4278 if ($action ==
'canceled') {
4281 if ($objectidnext) {
4282 $facturereplacement =
new Facture($db);
4283 $facturereplacement->fetch($objectidnext);
4284 $statusreplacement = $facturereplacement->statut;
4286 if ($objectidnext && $statusreplacement == 0) {
4287 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
4290 $close[1][
'code'] =
'badcustomer';
4291 $close[2][
'code'] =
'abandon';
4293 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4294 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
4296 $close[1][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $object->ref), $close[1][
'label'], 1);
4297 $close[2][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
4299 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
4300 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
4303 $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'));
4305 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill', $object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 270);
4309 if ($action ==
'deletepayment') {
4310 $payment_id =
GETPOST(
'paiement_id');
4311 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
4315 if ($action ==
'ask_deleteline') {
4316 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
4320 if ($action ==
'clone') {
4322 $formquestion = array(
4323 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' =>
$form->select_company($object->socid,
'socid',
'(s.client=1 OR s.client=2 OR s.client=3)', 1)),
4324 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
4327 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
4330 if ($action ==
"remove_file_comfirm") {
4331 $file =
GETPOST(
'file',
'alpha');
4334 $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&file='.$file,
4335 $langs->trans(
'DeleteFileHeader'),
4336 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
4346 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
4347 if (empty($reshook)) {
4349 } elseif ($reshook > 0) {
4358 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
4360 $morehtmlref =
'<div class="refidno">';
4362 if ($object->status == $object::STATUS_DRAFT && !$mysoc->isInEEC() && !empty($conf->global->INVOICE_ALLOW_FREE_REF)) {
4363 $morehtmlref .=
$form->editfieldkey(
"Ref",
'ref', $object->ref, $object, $usercancreate,
'string',
'', 0, 1);
4364 $morehtmlref .=
$form->editfieldval(
"Ref",
'ref', $object->ref, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
4365 $morehtmlref .=
'<br>';
4368 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
4369 $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);
4371 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
4372 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
4373 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
4377 $langs->load(
"projects");
4378 $morehtmlref .=
'<br>';
4379 if ($usercancreate) {
4380 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
4381 if ($action !=
'classify') {
4382 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
4384 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, ($action ==
'classify' ? 1 : 0), 0, 1,
'');
4386 if (!empty($object->fk_project)) {
4388 $proj->fetch($object->fk_project);
4389 $morehtmlref .= $proj->getNomUrl(1);
4391 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
4396 $morehtmlref .=
'</div>';
4398 $object->totalpaid = $totalpaid;
4400 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
4402 print
'<div class="fichecenter">';
4403 print
'<div class="fichehalfleft">';
4404 print
'<div class="underbanner clearboth"></div>';
4406 print
'<table class="border centpercent tableforfield">';
4409 print
'<tr><td class="titlefield fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
4410 print $object->getLibType(2);
4411 if ($object->module_source) {
4412 print
' <span class="opacitymediumbycolor paddingleft">('.$langs->trans(
"POS").
' '.ucfirst($object->module_source).
' - '.$langs->trans(
"Terminal").
' '.$object->pos_source.
')</span>';
4415 $facreplaced =
new Facture($db);
4416 $facreplaced->fetch($object->fk_facture_source);
4417 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
4421 $facusing->fetch($object->fk_facture_source);
4422 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
4425 $facidavoir = $object->getListIdAvoirFromInvoice();
4426 if (count($facidavoir) > 0) {
4427 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
4429 foreach ($facidavoir as $id) {
4436 $facavoir->fetch($id);
4437 print $facavoir->getNomUrl(1);
4441 if ($objectidnext > 0) {
4442 $facthatreplace =
new Facture($db);
4443 $facthatreplace->fetch($objectidnext);
4444 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
4449 $result = $discount->fetch(0, $object->id);
4451 print
' <span class="opacitymediumbycolor paddingleft">';
4452 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
4453 $s = str_replace(
'{s1}', $object->getLibType(0), $s);
4454 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
4456 print
'</span><br>';
4460 if ($object->fk_fac_rec_source > 0) {
4462 $result = $tmptemplate->fetch($object->fk_fac_rec_source);
4464 print
' <span class="opacitymediumbycolor paddingleft">';
4465 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
4466 $s = str_replace(
'{s1}',
'<a href="'.DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->ref).
'</a>', $s);
4474 print
'<!-- Discounts -->'.
"\n";
4475 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
4479 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?facid='.$object->id);
4480 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
4485 print
'<table class="nobordernopadding centpercent"><tr><td>';
4486 print $langs->trans(
'DateInvoice');
4488 if ($action !=
'editinvoicedate' && !empty($object->brouillon) && $usercancreate && empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
4489 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>';
4491 print
'</tr></table>';
4494 if ($action ==
'editinvoicedate') {
4495 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date,
'invoicedate');
4497 print
'<span class="valuedate">'.dol_print_date($object->date,
'day').
'</span>';
4503 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
4506 print
'<table class="nobordernopadding centpercent"><tr><td>';
4507 print $langs->trans(
'DatePointOfTax');
4509 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>';
4510 print
'</tr></table>';
4512 if ($action ==
'editdate_pointoftax') {
4513 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date_pointoftax,
'date_pointoftax');
4515 print
'<span class="valuedate">'.dol_print_date($object->date_pointoftax,
'day').
'</span>';
4522 print
'<table class="nobordernopadding centpercent"><tr><td>';
4523 print $langs->trans(
'PaymentConditionsShort');
4526 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>';
4528 print
'</tr></table>';
4531 if ($action ==
'editconditions') {
4532 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
4534 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'none');
4543 print
'<table class="nobordernopadding centpercent"><tr><td>';
4544 print $langs->trans(
'DateMaxPayment');
4547 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>';
4549 print
'</tr></table>';
4552 if ($action ==
'editpaymentterm') {
4553 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date_lim_reglement,
'paymentterm');
4555 print
'<span class="valuedate">'.dol_print_date($object->date_lim_reglement,
'day').
'</span>';
4556 if ($object->hasDelay()) {
4567 print
'<table class="nobordernopadding centpercent"><tr><td>';
4568 print $langs->trans(
'PaymentMode');
4570 if ($action !=
'editmode' && $usercancreate) {
4571 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>';
4573 print
'</tr></table>';
4575 if ($action ==
'editmode') {
4576 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
4578 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'none',
'CRDT');
4587 print
'<table class="nobordernopadding centpercent"><tr><td>';
4588 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
4590 if ($usercancreate && $action !=
'editmulticurrencycode' && !empty($object->brouillon)) {
4591 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>';
4593 print
'</tr></table>';
4595 $htmlname = (($usercancreate && $action ==
'editmulticurrencycode') ?
'multicurrency_code' :
'none');
4596 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code, $htmlname);
4600 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
4603 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4604 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
4606 if ($usercancreate && $action !=
'editmulticurrencyrate' && !empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
4607 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>';
4609 print
'</tr></table>';
4611 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
4612 if ($action ==
'actualizemulticurrencyrate') {
4615 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx, ($usercancreate ?
'multicurrency_tx' :
'none'), $object->multicurrency_code);
4617 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
4618 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
4619 print
'<div class="inline-block"> ';
4620 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
4630 print
'<tr><td class="nowrap">';
4631 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
4632 print $langs->trans(
'BankAccount');
4634 if (($action !=
'editbankaccount') && $usercancreate) {
4635 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>';
4637 print
'</tr></table>';
4639 if ($action ==
'editbankaccount') {
4640 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
4642 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
4651 print
'<table class="nobordernopadding centpercent"><tr><td>';
4652 print $langs->trans(
'IncotermLabel');
4653 print
'<td><td class="right">';
4654 if ($usercancreate) {
4655 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
4659 print
'</td></tr></table>';
4662 if ($action !=
'editincoterm') {
4663 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
4665 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
4672 if (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
4673 $displayWarranty =
true;
4674 if (!in_array($object->type, $retainedWarrantyInvoiceAvailableType) && empty($object->retained_warranty)) {
4675 $displayWarranty =
false;
4678 if ($displayWarranty) {
4680 print
'<tr class="retained-warranty-lines" ><td>';
4681 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
4682 print $langs->trans(
'RetainedWarranty');
4684 if ($action !=
'editretainedwarranty' && $user->rights->facture->creer && $object->statut ==
Facture::STATUS_DRAFT) {
4685 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>';
4688 print
'</tr></table>';
4691 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4692 print
'<input type="hidden" name="action" value="setretainedwarranty">';
4693 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4694 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
4695 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4698 print
price($object->retained_warranty).
'%';
4703 print
'<tr class="retained-warranty-lines" ><td>';
4704 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
4705 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
4707 if ($action !=
'editretainedwarrantypaymentterms' && $user->rights->facture->creer && $object->statut ==
Facture::STATUS_DRAFT) {
4708 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>';
4711 print
'</tr></table>';
4713 $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime(
'-1 years', $object->date_lim_reglement);
4714 if ($object->date > $defaultDate) {
4715 $defaultDate = $object->date;
4720 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4721 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
4722 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4723 $retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
4724 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $object->retained_warranty_fk_cond_reglement;
4725 $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;
4726 print
$form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4727 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4730 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->retained_warranty_fk_cond_reglement,
'none');
4731 if (!$displayWarranty) {
4732 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning.png',
'class="pictowarning valignmiddle" ');
4738 print
'<tr class="retained-warranty-lines" ><td>';
4739 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
4740 print $langs->trans(
'RetainedWarrantyDateLimit');
4742 if ($action !=
'editretainedwarrantydatelimit' && $user->rights->facture->creer && $object->statut ==
Facture::STATUS_DRAFT) {
4743 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>';
4746 print
'</tr></table>';
4748 $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime(
'-1 years', $object->date_lim_reglement);
4749 if ($object->date > $defaultDate) {
4750 $defaultDate = $object->date;
4755 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4756 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
4757 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4758 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').
'" >';
4759 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4762 print
dol_print_date($object->retained_warranty_date_limit,
'day');
4771 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
4776 print
'<div class="fichehalfright">';
4778 print
'<!-- amounts -->'.
"\n";
4779 print
'<div class="underbanner clearboth"></div>'.
"\n";
4780 print
'<table class="border tableforfield centpercent">';
4783 if (!empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE_SCREEN) && $object->type == $object::TYPE_CREDIT_NOTE) {
4787 if (
isModEnabled(
'multicurrency') && ($object->multicurrency_code != $conf->currency)) {
4789 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
4790 print
'<td class="nowrap right amountcard">'.price($sign * $object->multicurrency_total_ht,
'', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
4794 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
4795 print
'<td class="nowrap right amountcard">'.price($sign * $object->multicurrency_total_tva,
'', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
4799 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
4800 print
'<td class="nowrap right amountcard">'.price($sign * $object->multicurrency_total_ttc,
'', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
4805 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
'AmountHT').
'</td>';
4806 print
'<td class="nowrap right amountcard">'.price($sign * $object->total_ht, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4809 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="3" class="nowrap right amountcard">'.
price($sign * $object->total_tva, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4813 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) {
4814 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
4815 print
'<td class="nowrap right amountcard">'.price($sign * $object->total_localtax1, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4817 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) {
4818 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
4819 print
'<td class="nowrap right amountcard">'.price($sign * $object->total_localtax2, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4823 if ($selleruserevenustamp) {
4825 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4826 print $langs->trans(
'RevenueStamp');
4828 if ($action !=
'editrevenuestamp' && !empty($object->brouillon) && $usercancreate) {
4829 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>';
4831 print
'</tr></table>';
4833 if ($action ==
'editrevenuestamp') {
4834 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
4835 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4836 print
'<input type="hidden" name="action" value="setrevenuestamp">';
4837 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num($object->revenuestamp).
'">';
4838 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
4839 print
' → <span id="revenuestamp_span"></span>';
4840 print
' <input type="submit" class="button buttongen button-save" value="'.$langs->trans(
'Modify').
'">';
4843 $(document).ready(function(){
4844 js_recalculate_revenuestamp();
4845 $('select[name=revenuestamp_type]').on('change',function(){
4846 js_recalculate_revenuestamp();
4849 function js_recalculate_revenuestamp(){
4850 var valselected = $('select[name=revenuestamp_type]').val();
4851 console.log('Calculate revenue stamp from '+valselected);
4853 if (valselected.indexOf('%') == -1)
4855 revenue = valselected;
4859 var revenue_type = parseFloat(valselected);
4860 var amount_net = ".round($object->total_ht, 2).
";
4861 revenue = revenue_type * amount_net / 100;
4862 revenue = revenue.toFixed(2);
4864 $('#revenuestamp_val').val(revenue);
4865 $('#revenuestamp_span').html(revenue);
4869 print
price($object->revenuestamp, 1,
'', 1, - 1, - 1, $conf->currency);
4875 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td class="nowrap right amountcard">'.
price($sign * $object->total_ttc, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4889 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
4892 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
4895 if ($selleruserevenustamp) {
4906 if (($object->situation_cycle_ref > 0) && !empty($conf->global->INVOICE_USE_SITUATION)) {
4907 print
'<!-- List of situation invoices -->';
4908 print
'<table class="noborder situationstable" width="100%">';
4910 print
'<tr class="liste_titre">';
4911 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
4913 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
4915 print
'<td class="right"></td>';
4917 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
4918 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
4919 print
'<td width="18"> </td>';
4922 $total_prev_ht = $total_prev_ttc = 0;
4923 $total_global_ht = $total_global_ttc = 0;
4925 if (count($object->tab_previous_situation_invoice) > 0) {
4928 $current_situation_counter = array();
4929 foreach ($object->tab_previous_situation_invoice as $prev_invoice) {
4930 $tmptotalpaidforthisinvoice = $prev_invoice->getSommePaiement();
4931 $total_prev_ht += $prev_invoice->total_ht;
4932 $total_prev_ttc += $prev_invoice->total_ttc;
4933 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ?-1 : 1) * $prev_invoice->situation_counter;
4934 print
'<tr class="oddeven">';
4935 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
4937 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
4939 print
'<td class="right"></td>';
4941 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
4942 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
4943 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).
'</td>';
4949 $total_global_ht += $total_prev_ht;
4950 $total_global_ttc += $total_prev_ttc;
4951 $total_global_ht += $object->total_ht;
4952 $total_global_ttc += $object->total_ttc;
4954 print
'<tr class="oddeven">';
4955 print
'<td>'.$object->getNomUrl(1).
'</td>';
4957 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$object->situation_counter.
'</td>';
4959 print
'<td class="right"></td>';
4961 print
'<td class="right"><span class="amount">'.price($object->total_ht).
'</span></td>';
4962 print
'<td class="right"><span class="amount">'.price($object->total_ttc).
'</span></td>';
4963 print
'<td class="right">'.$object->getLibStatut(3, $object->getSommePaiement()).
'</td>';
4967 print
'<tr class="oddeven">';
4968 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'CurrentSituationTotal').
'</b></td>';
4971 foreach ($current_situation_counter as $sit) {
4972 $curSign = $sit > 0 ?
'+' :
'-';
4973 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
4975 print
' '.$curSign.
' ';
4977 print $curType.abs($sit);
4984 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
4985 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
4986 print
'<td width="18"> </td>';
4990 if (count($object->tab_next_situation_invoice) > 0) {
5002 $total_next_ht = $total_next_ttc = 0;
5004 foreach ($object->tab_next_situation_invoice as $next_invoice) {
5005 $totalpaid = $next_invoice->getSommePaiement();
5006 $total_next_ht += $next_invoice->total_ht;
5007 $total_next_ttc += $next_invoice->total_ttc;
5009 print
'<tr class="oddeven">';
5010 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
5012 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
5014 print
'<td class="right"></td>';
5016 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
5017 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
5018 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid).
'</td>';
5022 $total_global_ht += $total_next_ht;
5023 $total_global_ttc += $total_next_ttc;
5025 print
'<tr class="oddeven">';
5026 print
'<td colspan="3" class="right"></td>';
5028 print
'<td class="right"></td>';
5030 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5031 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5032 print
'<td width="18"> </td>';
5040 if ($object->type == $object::TYPE_CREDIT_NOTE) {
5046 print
'<!-- List of payments already done -->';
5047 print
'<div class="div-table-responsive-no-min">';
5048 print
'<table class="noborder paymenttable centpercent">';
5050 print
'<tr class="liste_titre">';
5051 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
5052 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
5053 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
5055 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
5057 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
5058 print
'<td class="liste_titre" width="18"> </td>';
5062 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
5063 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
5064 $sql .=
' pf.amount,';
5065 $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';
5066 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
5067 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
5068 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
5069 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
5070 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id).
' AND pf.fk_paiement = p.rowid';
5071 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
5072 $sql .=
' ORDER BY p.datep, p.tms';
5074 $result = $db->query($sql);
5076 $num = $db->num_rows($result);
5081 $objp = $db->fetch_object($result);
5083 $paymentstatic->id = $objp->rowid;
5084 $paymentstatic->datepaye = $db->jdate($objp->dp);
5085 $paymentstatic->ref = $objp->ref;
5086 $paymentstatic->num_payment = $objp->num_payment;
5087 $paymentstatic->paiementcode = $objp->payment_code;
5089 print
'<tr class="oddeven"><td class="nowraponall">';
5090 print $paymentstatic->getNomUrl(1);
5093 $dateofpayment = $db->jdate($objp->dp);
5095 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
5101 $label = ($langs->trans(
"PaymentType".$objp->payment_code) != (
"PaymentType".$objp->payment_code)) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
5102 print
'<td>'.$label.
' '.$objp->num_payment.
'</td>';
5104 $bankaccountstatic->id = $objp->baid;
5105 $bankaccountstatic->ref = $objp->baref;
5106 $bankaccountstatic->label = $objp->baref;
5107 $bankaccountstatic->number = $objp->banumber;
5108 $bankaccountstatic->currency_code = $objp->bacurrency_code;
5111 $bankaccountstatic->account_number = $objp->account_number;
5114 $accountingjournal->fetch($objp->fk_accountancy_journal);
5115 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
5118 print
'<td class="nowraponall">';
5119 if ($bankaccountstatic->id) {
5120 print $bankaccountstatic->getNomUrl(1,
'transactions');
5124 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
5125 print
'<td class="center">';
5127 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
5144 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5145 print
'<span class="opacitymedium">';
5147 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
5149 print $langs->trans(
'AlreadyPaid');
5151 print
'</span></td><td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td><td> </td></tr>';
5153 $resteapayeraffiche = $resteapayer;
5154 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
5157 $creditnoteamount = 0;
5159 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
5160 $sql .=
" re.description, re.fk_facture_source";
5161 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
5162 $sql .=
" WHERE fk_facture = ".((int) $object->id);
5163 $resql = $db->query($sql);
5165 $num = $db->num_rows(
$resql);
5169 $obj = $db->fetch_object(
$resql);
5170 $invoice->fetch($obj->fk_facture_source);
5171 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5172 print
'<span class="opacitymedium">';
5174 print $langs->trans(
"CreditNote").
' ';
5177 print $langs->trans(
"Deposit").
' ';
5179 print $invoice->getNomUrl(0);
5182 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
5183 print
'<td class="right">';
5184 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">'.
img_delete().
'</a>';
5188 $creditnoteamount += $obj->amount_ttc;
5191 $depositamount += $obj->amount_ttc;
5200 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5201 print
'<span class="opacitymedium">';
5202 print
$form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
5204 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5205 $resteapayeraffiche = 0;
5206 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5210 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5211 print
'<span class="opacitymedium">';
5212 print
$form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
5214 print
'</td><td class="right">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td><td> </td></tr>';
5216 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5220 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5221 print
'<span class="opacitymedium">';
5222 print
$form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
5224 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5225 $resteapayeraffiche = 0;
5226 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5230 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5231 $text = $langs->trans(
"HelpAbandonOther");
5232 if ($object->close_note) {
5233 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.$object->close_note;
5235 print
'<span class="opacitymedium">';
5236 print
$form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
5238 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5239 $resteapayeraffiche = 0;
5240 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5244 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5245 print
'<span class="opacitymedium">';
5246 print $langs->trans(
"Billed");
5247 print
'</td><td class="right">'.price($object->total_ttc).
'</td><td> </td></tr>';
5249 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5250 print
'<span class="opacitymedium">';
5251 print $langs->trans(
'RemainderToPay');
5252 if ($resteapayeraffiche < 0) {
5253 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5257 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
5260 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
5261 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5262 print
'<span class="opacitymedium">';
5263 print $langs->trans(
'RemainderToPayMulticurrency');
5264 if ($resteapayeraffiche < 0) {
5265 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5269 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">';
5271 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>';
5275 if (!empty($object->situation_final) && !empty($object->retained_warranty) && $displayWarranty) {
5278 $retainedWarranty = $total_global_ttc * $object->retained_warranty / 100;
5281 $retainedWarranty = $object->total_ttc * $object->retained_warranty / 100;
5284 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
5286 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>';
5289 print
'<tr><td colspan="'.$nbcols.
'" align="right">';
5290 print $langs->trans(
"RetainedWarranty").
' ('.$object->retained_warranty.
'%)';
5291 print !empty($object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date($object->retained_warranty_date_limit,
'day')) :
'';
5292 print
' :</td><td align="right">'.price($retainedWarranty).
'</td><td> </td></tr>';
5295 $resteapayeraffiche = $resteapayer;
5296 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5299 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5300 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
5301 print
'</td><td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td><td> </td></tr>';
5304 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>';
5307 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5308 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
5309 if ($resteapayeraffiche > 0) {
5310 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5312 print
'</span></td>';
5313 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
5314 print
'<td class="nowrap"> </td></tr>';
5317 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
5318 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5319 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
5320 if ($resteapayeraffiche > 0) {
5321 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5325 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>';
5339 $formmargin->displayMarginInfos($object);
5345 print
'<div class="clearboth"></div><br><br>';
5347 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
5348 $blocname =
'contacts';
5349 $title = $langs->trans(
'ContactsAddresses');
5350 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5353 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
5354 $blocname =
'notes';
5355 $title = $langs->trans(
'Notes');
5356 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5360 $result = $object->getLinesArray();
5364 global $inputalsopricewithtax;
5365 $inputalsopricewithtax = 1;
5368 if (!empty($conf->global->INVOICE_USE_SITUATION)) {
5369 if ($object->situation_cycle_ref && $object->statut == 0) {
5370 print
'<!-- Area to change globally the situation percent -->'.
"\n";
5371 print
'<div class="div-table-responsive">';
5373 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'#updatealllines" method="POST">';
5374 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
5375 print
'<input type="hidden" name="action" value="updatealllines" />';
5376 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
5378 print
'<table id="tablelines_all_progress" class="noborder noshadow" width="100%">';
5380 print
'<tr class="liste_titre nodrag nodrop">';
5383 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
5384 print
'<td align="center" width="5"> </td>';
5386 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
5387 print
'<td class="right">'.$langs->trans(
'Progress').
'</td>';
5388 print
'<td> </td>';
5391 print
'<tr class="nodrag nodrop">';
5393 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
5394 print
'<td align="center" width="5"> </td>';
5396 print
'<td> </td>';
5397 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
5398 print
'<td class="right"><input type="submit" class="button" name="all_percent" value="Modifier" /></td>';
5409 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">
5410 <input type="hidden" name="token" value="' .
newToken().
'">
5411 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
5412 <input type="hidden" name="mode" value="">
5413 <input type="hidden" name="page_y" value="">
5414 <input type="hidden" name="id" value="' . $object->id.
'">
5417 if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
5418 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
5421 print
'<div class="div-table-responsive-no-min">';
5422 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
5425 if (!empty($object->lines)) {
5426 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
5430 if ($object->statut == 0 && $usercancreate && $action !=
'valid' && $action !=
'editline') {
5431 if ($action !=
'editline' && $action !=
'selectlines') {
5435 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
5436 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
5437 if (empty($reshook))
5438 $object->formAddObjectLine(1, $mysoc, $soc);
5452 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
5453 print
'<div class="tabsAction">';
5456 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
5457 if (empty($reshook)) {
5460 'class' =>
'classfortooltip'
5466 $ventilExportCompta = $object->getVentilExportCompta();
5468 if ($ventilExportCompta == 0) {
5469 if (!empty($conf->global->INVOICE_CAN_BE_EDITED_EVEN_IF_PAYMENT_DONE) || ($resteapayer ==
price2num($object->total_ttc,
'MT', 1) && empty($object->paye))) {
5470 if (!$objectidnext && $object->is_last_in_cycle()) {
5471 if ($usercanunvalidate) {
5472 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=modif&token='.
newToken(),
'',
true, $params);
5474 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
5475 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=modif&token='.
newToken(),
'',
false, $params);
5477 } elseif (!$object->is_last_in_cycle()) {
5478 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
5479 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5481 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
5482 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5486 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5487 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5492 $result = $discount->fetch(0, $object->id);
5500 && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || $usercanreopen)) {
5501 if ($object->close_code !=
'replaced' || (!$objectidnext)) {
5502 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
5504 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
5505 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
5510 if (!empty($conf->global->CONTRACT_CREATE_FROM_INVOICE)) {
5512 $langs->load(
"contracts");
5514 if ($usercancreatecontract) {
5515 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>';
5522 if ($usercanvalidate) {
5523 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
5528 if (empty($user->socid)) {
5530 if ($objectidnext) {
5531 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'SendMail').
'</span>';
5534 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
5536 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
5544 if ($resteapayer > 0) {
5545 if ($usercancreatewithdrarequest) {
5546 if (!$objectidnext && $object->close_code !=
'replaced') {
5547 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>';
5549 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
5560 if (
isModEnabled(
'takepos') && $object->module_source ==
'takepos') {
5561 $langs->load(
"cashdesk");
5562 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
5563 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int) $object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
5568 if ($objectidnext) {
5569 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
5573 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
5574 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
5578 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default', DOL_URL_ROOT.
'/compta/paiement.php?facid='.$object->id.
'&action=create&accountid='.$object->fk_account,
'',
true, $params);
5583 $sumofpayment = $totalpaid;
5584 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
5590 if ($resteapayer == 0) {
5591 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
5593 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.$object->id.
'&action=create&accountid='.$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
5599 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
5603 && (!empty($conf->global->INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) || $sumofpayment == 0)
5605 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>';
5611 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertToReduc').
'</a>';
5613 print
'<span class="butActionRefused" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
5627 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
5628 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
5630 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=paid',
'',
true, $params);
5635 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) {
5636 if ($totalpaid > 0 || $totalcreditnotes > 0) {
5638 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
5640 if (empty($conf->global->INVOICE_CAN_NEVER_BE_CANCELED)) {
5641 if ($objectidnext) {
5642 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
5644 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
5652 if (!$objectidnext) {
5653 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>';
5660 && ($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
5663 && $object->is_last_in_cycle()
5666 if ($usercanunvalidate) {
5667 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>';
5669 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
5675 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=clone&object=invoice',
'',
true, $params);
5680 if (!$objectidnext && count($object->lines) > 0) {
5681 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$object->id.
'&action=create',
'',
true, $params);
5690 && $object->situation_counter > 1
5691 && $object->is_last_in_cycle()
5692 && $usercanunvalidate
5694 if (($object->total_ttc - $totalcreditnotes) == 0) {
5695 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
5697 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
5702 if ($usercancreate && ($object->type == 5) && ($object->statut == 1 || $object->statut == 2)) {
5703 if ($object->is_last_in_cycle() && $object->situation_final != 1) {
5704 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.$object->id.
'&socid='.$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5705 } elseif (!$object->is_last_in_cycle()) {
5706 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5708 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5713 $isErasable = $object->is_erasable();
5716 'class' =>
'classfortooltip'
5719 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
5720 $enableDelete =
false;
5723 if ($isErasable == -4) {
5724 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
5725 } elseif ($isErasable == -3) {
5726 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
5727 } elseif ($isErasable == -2) {
5728 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
5729 } elseif ($isErasable == -1) {
5730 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5731 } elseif ($isErasable <= 0) {
5732 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable');
5733 } elseif ($objectidnext) {
5734 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
5736 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=delete&token='.
newToken();
5737 $enableDelete =
true;
5739 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
5741 print
dolGetButtonAction($langs->trans(
'Delete'), $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
5748 if (
GETPOST(
'modelselected',
'alpha')) {
5749 $action =
'presend';
5751 if ($action !=
'prerelance' && $action !=
'presend') {
5752 print
'<div class="fichecenter"><div class="fichehalfleft">';
5753 print
'<a name="builddoc"></a>';
5757 $filedir = $conf->facture->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($object->ref);
5758 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.$object->id;
5759 $genallowed = $usercanread;
5760 $delallowed = $usercancreate;
5762 print $formfile->showdocuments(
5782 'remove_file_comfirm'
5785 $somethingshown = $formfile->numoffiles;
5788 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'invoice'));
5790 $compatibleImportElementsList =
false;
5794 $compatibleImportElementsList = array(
'commande',
'propal');
5796 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
5803 print
'<br><!-- Link to pay -->'.
"\n";
5804 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
5805 print showOnlinePaymentUrl(
'invoice', $object->ref).
'<br>';
5808 print
'</div><div class="fichehalfright">';
5811 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
5813 $somethingshown =
$formactions->showactions($object,
'invoice', $socid, 1);
5815 print
'</div></div>';
5820 $modelmail =
'facture_send';
5821 $defaulttopic =
'SendBillRef';
5822 $diroutput = $conf->facture->multidir_output[$object->entity];
5823 $trackid =
'inv'.$object->id;
5825 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage bank accounts.
Class to manage accounting accounts.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage shipments.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_DRAFT
Draft status.
const TYPE_STANDARD
Standard invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_PROFORMA
Proforma invoice (should not be used.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_DEPOSIT
Deposit invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const TYPE_CREDIT_NOTE
Credit note invoice.
const STATUS_CLOSED
Classified paid.
Class to manage invoice lines.
Class to manage invoice templates.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage notifications.
Class to manage payments of customer invoices.
Class ProductCombination Used to represent a product combination.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
$formconfirm
if ($action == 'delbookkeepingyear') {
div float
Buy price without taxes.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array='', $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.