40 require
'../../main.inc.php';
41 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
46 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
49 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
51 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
52 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
53 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
55 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
58 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
59 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
61 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
64 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
67 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
71 $langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
73 $langs->load(
'incoterm');
76 $langs->load(
'margins');
79 $projectid = (
GETPOST(
'projectid',
'int') ?
GETPOST(
'projectid',
'int') : 0);
83 $socid =
GETPOST(
'socid',
'int');
84 $action =
GETPOST(
'action',
'aZ09');
85 $confirm =
GETPOST(
'confirm',
'alpha');
86 $cancel =
GETPOST(
'cancel',
'alpha');
87 $lineid =
GETPOST(
'lineid',
'int');
88 $userid =
GETPOST(
'userid',
'int');
89 $search_ref =
GETPOST(
'sf_ref',
'alpha') ?
GETPOST(
'sf_ref',
'alpha') :
GETPOST(
'search_ref',
'alpha');
90 $search_societe =
GETPOST(
'search_societe',
'alpha');
91 $search_montant_ht =
GETPOST(
'search_montant_ht',
'alpha');
92 $search_montant_ttc =
GETPOST(
'search_montant_ttc',
'alpha');
93 $origin =
GETPOST(
'origin',
'alpha');
95 $fac_rec =
GETPOST(
'fac_rec',
'int');
96 $facid =
GETPOST(
'facid',
'int');
97 $ref_client =
GETPOST(
'ref_client',
'int');
98 $rank = (
GETPOST(
'rank',
'int') > 0) ?
GETPOST(
'rank',
'int') : -1;
101 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
102 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
103 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
108 $usehm = (!empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : 0);
114 $extrafields->fetch_name_optionals_label($object->table_element);
117 if ($id > 0 || !empty($ref)) {
118 if ($action !=
'add') {
119 if (empty($conf->global->INVOICE_USE_SITUATION)) {
120 $fetch_situation =
false;
122 $fetch_situation =
true;
124 $ret = $object->fetch($id, $ref,
'',
'', $fetch_situation);
129 $hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
131 $usercanread = $user->hasRight(
"facture",
"lire");
132 $usercancreate = $user->hasRight(
"facture",
"creer");
133 $usercanissuepayment = $user->hasRight(
"facture",
"paiement");
134 $usercandelete = $user->hasRight(
"facture",
"supprimer");
135 $usercancreatecontract = $user->hasRight(
"contrat",
"creer");
136 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->validate)));
137 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->send)));
138 $usercanreopen = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->reopen)));
139 if (!empty($conf->global->INVOICE_DISALLOW_REOPEN)) {
140 $usercanreopen =
false;
142 $usercanunvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->unvalidate)));
144 $usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
145 $usercancreatemargin = (!empty($user->rights->margins->creer) ? $user->rights->margins->creer : 0);
146 $usercanreadallmargin = (!empty($user->rights->margins->liretous) ? $user->rights->margins->liretous : 0);
147 $usercancreatewithdrarequest = (!empty($user->rights->prelevement->bons->creer) ? $user->rights->prelevement->bons->creer : 0);
149 $permissionnote = $usercancreate;
150 $permissiondellink = $usercancreate;
151 $permissiontoedit = $usercancreate;
152 $permissiontoadd = $usercancreate;
155 $retainedWarrantyInvoiceAvailableType = array();
156 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
157 $retainedWarrantyInvoiceAvailableType = explode(
'+', $conf->global->INVOICE_USE_RETAINED_WARRANTY);
162 $socid = $user->socid;
166 $result =
restrictedArea($user,
'facture', $object->id,
'',
'',
'fk_soc',
'rowid', $isdraft);
174 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
179 if (empty($reshook)) {
180 $backurlforlist = DOL_URL_ROOT.
'/compta/facture/list.php';
182 if (empty($backtopage) || ($cancel && empty($id))) {
183 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
184 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
185 $backtopage = $backurlforlist;
187 $backtopage = DOL_URL_ROOT.
'/compta/facture/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
193 if (!empty($backtopageforcancel)) {
194 header(
"Location: ".$backtopageforcancel);
196 } elseif (!empty($backtopage)) {
197 header(
"Location: ".$backtopage);
203 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
205 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
207 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
210 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
214 $objectutil->socid = $socid;
215 $result = $objectutil->createFromClone($user, $id);
217 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?facid='.$result);
220 $langs->load(
"errors");
224 } elseif ($action ==
'reopen' && $usercanreopen) {
225 $result = $object->fetch($id);
228 $result = $object->setUnpaid($user);
230 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
236 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
238 $result = $object->fetch($id);
239 $object->fetch_thirdparty();
241 $idwarehouse =
GETPOST(
'idwarehouse');
243 $qualified_for_stock_change = 0;
244 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
245 $qualified_for_stock_change = $object->hasProductsOrServices(2);
247 $qualified_for_stock_change = $object->hasProductsOrServices(1);
250 $isErasable = $object->is_erasable();
252 if (($usercandelete && $isErasable > 0)
253 || ($usercancreate && $isErasable == 1)) {
254 $result = $object->delete($user, 0, $idwarehouse);
256 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
263 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
266 $object->fetch_thirdparty();
268 $result = $object->deleteline(
GETPOST(
'lineid',
'int'));
271 $object->line_order(
true);
273 $outputlangs = $langs;
275 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id')) {
278 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
279 $newlang = $object->thirdparty->default_lang;
281 if (!empty($newlang)) {
283 $outputlangs->setDefaultLang($newlang);
284 $outputlangs->load(
'products');
286 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
287 $ret = $object->fetch($id);
288 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
291 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
298 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
301 $result = $discount->fetch(
GETPOST(
"discountid"));
302 $discount->unlink_invoice();
303 } elseif ($action ==
'valid' && $usercancreate) {
307 if (!empty($conf->global-> INVOICE_CHECK_POSTERIOR_DATE)) {
308 $last_of_type = $object->willBeLastOfSameType(
true);
309 if (empty($object->date_validation) && !$last_of_type[0]) {
318 if ($object->total_ht >= 0) {
319 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
327 if (empty($conf->global->FACTURE_ENABLE_NEGATIVE) && $object->total_ttc < 0) {
328 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
337 $array_of_total_ht_per_vat_rate = array();
338 $array_of_total_ht_devise_per_vat_rate = array();
339 foreach ($object->lines as $line) {
341 $vat_src_code_for_line =
'';
342 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
343 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
345 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
346 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
348 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
349 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
353 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
354 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
355 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
357 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
358 if ($object->type == $object::TYPE_DEPOSIT) {
359 $langs->load(
"errors");
361 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
365 $tmpvatratetoshow = explode(
'_', $vatrate);
366 $tmpvatratetoshow[0] = round($tmpvatratetoshow[0], 2);
368 if ($tmpvatratetoshow[0] != 0) {
369 $langs->load(
"errors");
370 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", $tmpvatratetoshow[0]),
null,
'errors');
378 } elseif ($action ==
'classin' && $usercancreate) {
380 $object->setProject(
GETPOST(
'projectid',
'int'));
381 } elseif ($action ==
'setmode' && $usercancreate) {
383 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
387 } elseif ($action ==
'setretainedwarrantyconditions' && $user->rights->facture->creer) {
389 $object->retained_warranty_fk_cond_reglement = 0;
390 $result = $object->setRetainedWarrantyPaymentTerms(
GETPOST(
'retained_warranty_fk_cond_reglement',
'int'));
395 $old_rw_date_lim_reglement = $object->retained_warranty_date_limit;
396 $new_rw_date_lim_reglement = $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement);
397 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
398 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
400 if ($object->retained_warranty_date_limit < $object->date) {
401 $object->retained_warranty_date_limit = $object->date;
403 $result = $object->update($user);
407 } elseif ($action ==
'setretainedwarranty' && $user->rights->facture->creer) {
409 $result = $object->setRetainedWarranty(
GETPOST(
'retained_warranty',
'float'));
413 } elseif ($action ==
'setretainedwarrantydatelimit' && $user->rights->facture->creer) {
415 $result = $object->setRetainedWarrantyDateLimit(
GETPOST(
'retained_warranty_date_limit',
'float'));
419 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
420 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
421 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
422 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
423 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
425 $old_date_lim_reglement = $object->date_lim_reglement;
427 if (empty($newdate)) {
428 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
429 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id.
'&action=editinvoicedate&token='.
newToken());
432 if ($newdate > (
dol_now(
'tzuserrel') + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
433 if (empty($conf->global->INVOICE_MAX_FUTURE_DELAY)) {
434 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
436 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
440 $object->date = $newdate;
441 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
442 if ($new_date_lim_reglement > $old_date_lim_reglement) {
443 $object->date_lim_reglement = $new_date_lim_reglement;
445 if ($object->date_lim_reglement < $object->date) {
446 $object->date_lim_reglement = $object->date;
448 $result = $object->update($user);
452 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
455 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
457 $object->date_pointoftax = $date_pointoftax;
458 $result = $object->update($user);
462 } elseif ($action ==
'setconditions' && $usercancreate) {
464 $object->cond_reglement_code = 0;
465 $object->cond_reglement_id = 0;
472 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
480 $old_date_lim_reglement = $object->date_lim_reglement;
481 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
482 if ($new_date_lim_reglement > $old_date_lim_reglement) {
483 $object->date_lim_reglement = $new_date_lim_reglement;
485 if ($object->date_lim_reglement < $object->date) {
486 $object->date_lim_reglement = $object->date;
488 $result = $object->update($user);
500 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
502 $object->date_lim_reglement =
dol_mktime(12, 0, 0,
GETPOST(
'paymenttermmonth',
'int'),
GETPOST(
'paymenttermday',
'int'),
GETPOST(
'paymenttermyear',
'int'));
503 if ($object->date_lim_reglement < $object->date) {
504 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
505 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
507 $result = $object->update($user);
511 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
513 $object->revenuestamp =
GETPOST(
'revenuestamp');
514 $result = $object->update($user);
515 $object->update_price(1);
520 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
521 $outputlangs = $langs;
523 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
524 $newlang =
GETPOST(
'lang_id',
'aZ09');
526 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
527 $newlang = $object->thirdparty->default_lang;
529 if (!empty($newlang)) {
531 $outputlangs->setDefaultLang($newlang);
532 $outputlangs->load(
'products');
534 $model = $object->model_pdf;
535 $ret = $object->fetch($id);
537 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
543 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm')) {
544 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
545 } elseif ($action ==
'setbankaccount' && $usercancreate) {
546 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
547 } elseif ($action ==
'setremisepercent' && $usercancreate) {
549 $result = $object->setDiscount($user,
price2num(
GETPOST(
'remise_percent'),
'', 2));
550 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
555 if (
GETPOST(
"remise_id",
'int') > 0) {
556 $ret = $object->fetch($id);
558 $result = $object->insert_discount(
GETPOST(
"remise_id",
'int'));
568 if (
GETPOST(
"remise_id_for_payment",
'int') > 0) {
569 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
571 $discount->fetch(
GETPOST(
"remise_id_for_payment",
'int'));
575 $remaintopay = $object->getRemainToPay(0);
579 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
583 $result = $discount->link_to_invoice(0, $id);
591 $newremaintopay = $object->getRemainToPay(0);
592 if ($newremaintopay == 0) {
593 $object->setPaid($user);
604 if (empty($error) && empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
605 $outputlangs = $langs;
607 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
608 $newlang =
GETPOST(
'lang_id',
'aZ09');
610 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
611 $newlang = $object->thirdparty->default_lang;
613 if (!empty($newlang)) {
615 $outputlangs->setDefaultLang($newlang);
617 $ret = $object->fetch($id);
619 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
624 } elseif ($action ==
'setref' && $usercancreate) {
626 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'',
null,
'',
'', $user,
'BILL_MODIFY');
627 } elseif ($action ==
'setref_client' && $usercancreate) {
629 $object->set_ref_client(
GETPOST(
'ref_client'));
630 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
632 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
635 $object->fetch_thirdparty();
639 $qualified_for_stock_change = 0;
640 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
641 $qualified_for_stock_change = $object->hasProductsOrServices(2);
643 $qualified_for_stock_change = $object->hasProductsOrServices(1);
646 if ($qualified_for_stock_change) {
647 if (!$idwarehouse || $idwarehouse == - 1) {
649 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
656 $result = $object->validate($user,
'', $idwarehouse);
659 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
660 $outputlangs = $langs;
662 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
663 $newlang =
GETPOST(
'lang_id',
'aZ09');
665 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) {
666 $newlang = $object->thirdparty->default_lang;
668 if (!empty($newlang)) {
670 $outputlangs->setDefaultLang($newlang);
671 $outputlangs->load(
'products');
673 $model = $object->model_pdf;
675 $ret = $object->fetch($id);
677 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
683 if (count($object->errors)) {
690 } elseif ($action ==
'confirm_modif' && $usercanunvalidate) {
692 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
695 $object->fetch_thirdparty();
699 $qualified_for_stock_change = 0;
700 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
701 $qualified_for_stock_change = $object->hasProductsOrServices(2);
703 $qualified_for_stock_change = $object->hasProductsOrServices(1);
706 if ($qualified_for_stock_change) {
707 if (!$idwarehouse || $idwarehouse == - 1) {
709 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
717 $sql =
'SELECT pf.amount';
718 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf';
719 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id);
721 $result = $db->query($sql);
724 $num = $db->num_rows($result);
727 $objp = $db->fetch_object($result);
728 $totalpaid += $objp->amount;
735 $resteapayer = $object->total_ttc - $totalpaid;
738 $ventilExportCompta = $object->getVentilExportCompta();
741 if ($ventilExportCompta == 0) {
742 if (!empty($conf->global->INVOICE_CAN_BE_EDITED_EVEN_IF_PAYMENT_DONE) || ($resteapayer == $object->total_ttc && empty($object->paye))) {
743 $result = $object->setDraft($user, $idwarehouse);
749 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
750 $outputlangs = $langs;
752 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
753 $newlang =
GETPOST(
'lang_id',
'aZ09');
755 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
756 $newlang = $object->thirdparty->default_lang;
758 if (!empty($newlang)) {
760 $outputlangs->setDefaultLang($newlang);
761 $outputlangs->load(
'products');
763 $model = $object->model_pdf;
764 $ret = $object->fetch($id);
766 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
771 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
774 $result = $object->setPaid($user);
778 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
781 $close_code =
GETPOST(
"close_code",
'restricthtml');
782 $close_note =
GETPOST(
"close_note",
'restricthtml');
784 $result = $object->setPaid($user, $close_code, $close_note);
789 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
791 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes') {
794 $close_code =
GETPOST(
"close_code",
'restricthtml');
795 $close_note =
GETPOST(
"close_note",
'restricthtml');
797 $result = $object->setCanceled($user, $close_code, $close_note);
802 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
804 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
807 $object->fetch_thirdparty();
812 $result = $discountcheck->fetch(0, $object->id);
825 $amount_ht = $amount_tva = $amount_ttc = array();
826 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
830 foreach ($object->lines as $line) {
831 if ($line->product_type < 9 && $line->total_ht != 0) {
832 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
834 $amount_ht[$keyforvatrate] += $line->total_ht;
835 $amount_tva[$keyforvatrate] += $line->total_tva;
836 $amount_ttc[$keyforvatrate] += $line->total_ttc;
837 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
838 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
839 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
845 if (!empty($conf->global->INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) && $object->type ==
Facture::TYPE_CREDIT_NOTE) {
846 $alreadypaid = $object->getSommePaiement();
847 if ($alreadypaid && abs($alreadypaid) < abs($object->total_ttc)) {
848 $ratio = abs(($object->total_ttc - $alreadypaid) / $object->total_ttc);
849 foreach ($amount_ht as $vatrate => $val) {
850 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
851 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
852 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
853 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
854 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
855 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
864 $discount->description =
'(CREDIT_NOTE)';
866 $discount->description =
'(DEPOSIT)';
868 $discount->description =
'(EXCESS RECEIVED)';
870 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
872 $discount->fk_soc = $object->socid;
873 $discount->fk_facture_source = $object->id;
881 $sql =
'SELECT SUM(pf.amount) as total_paiements';
882 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
883 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
884 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id);
885 $sql .=
' AND pf.fk_paiement = p.rowid';
886 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
887 $resql = $db->query($sql);
892 $res = $db->fetch_object(
$resql);
893 $total_paiements = $res->total_paiements;
896 $total_creditnote_and_deposit = 0;
897 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
898 $sql .=
" re.description, re.fk_facture_source";
899 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
900 $sql .=
" WHERE fk_facture = ".((int) $object->id);
901 $resql = $db->query($sql);
903 while ($obj = $db->fetch_object(
$resql)) {
904 $total_creditnote_and_deposit += $obj->amount_ttc;
910 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object->total_ttc;
911 $discount->amount_tva = 0;
912 $discount->tva_tx = 0;
913 $discount->vat_src_code =
'';
915 $result = $discount->create($user);
921 foreach ($amount_ht as $tva_tx => $xxx) {
922 $discount->amount_ht = abs($amount_ht[$tva_tx]);
923 $discount->amount_tva = abs($amount_tva[$tva_tx]);
924 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
925 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
926 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
927 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
932 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
933 $vat_src_code = $reg[1];
934 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
937 $discount->tva_tx = abs($tva_tx);
938 $discount->vat_src_code = $vat_src_code;
940 $result = $discount->create($user);
951 $result = $object->setPaid($user);
966 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
971 $result = $paiement->fetch(
GETPOST(
'paiement_id',
'int'));
973 $result = $paiement->delete();
975 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
983 } elseif ($action ==
'add' && $usercancreate) {
986 $object->socid =
GETPOST(
'socid',
'int');
988 $selectedLines =
GETPOST(
'toselect',
'array');
990 if (
GETPOST(
'type',
'int') ===
'') {
991 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
997 $originentity =
GETPOST(
'originentity');
999 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1005 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
1009 if (empty($dateinvoice)) {
1011 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1013 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1019 if (!(
GETPOST(
'fac_replacement',
'int') > 0)) {
1021 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1027 $result = $object->fetch(
GETPOST(
'fac_replacement',
'int'));
1028 $object->fetch_thirdparty();
1030 $object->date = $dateinvoice;
1031 $object->date_pointoftax = $date_pointoftax;
1032 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1033 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1034 $object->ref_client =
GETPOST(
'ref_client',
'alphanohtml');
1035 $object->model_pdf =
GETPOST(
'model',
'alphanohtml');
1036 $object->fk_project =
GETPOST(
'projectid',
'int');
1037 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1038 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1039 $object->fk_account =
GETPOST(
'fk_account',
'int');
1042 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1043 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1044 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1045 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1048 $object->fk_facture_source =
GETPOST(
'fac_replacement',
'int');
1051 $id = $object->createFromCurrent($user);
1060 $sourceinvoice =
GETPOST(
'fac_avoir',
'int');
1061 if (!($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
1063 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1067 if (empty($dateinvoice)) {
1069 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1071 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1078 if (!empty($originentity)) {
1079 $object->entity = $originentity;
1081 $object->socid =
GETPOST(
'socid',
'int');
1082 $object->ref =
GETPOST(
'ref');
1083 $object->date = $dateinvoice;
1084 $object->date_pointoftax = $date_pointoftax;
1085 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1086 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1087 $object->ref_client =
GETPOST(
'ref_client');
1088 $object->model_pdf =
GETPOST(
'model');
1089 $object->fk_project =
GETPOST(
'projectid',
'int');
1090 $object->cond_reglement_id = 0;
1091 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1092 $object->fk_account =
GETPOST(
'fk_account',
'int');
1095 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1096 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1097 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1098 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1101 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1104 $facture_source =
new Facture($db);
1105 if ($facture_source->fetch($object->fk_facture_source) > 0) {
1107 $object->situation_counter = $facture_source->situation_counter;
1108 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1109 $facture_source->fetchPreviousNextSituationInvoice();
1114 $id = $object->create($user);
1119 if ($object->copy_linked_contact($facture_source,
'internal') < 0) {
1121 } elseif ($facture_source->socid == $object->socid) {
1123 if ($object->copy_linked_contact($facture_source,
'external') < 0) {
1134 if (
GETPOST(
'invoiceAvoirWithLines',
'int') == 1 && $id > 0) {
1135 if (!empty($facture_source->lines)) {
1136 $fk_parent_line = 0;
1138 foreach ($facture_source->lines as $line) {
1140 if (method_exists($line,
'fetch_optionals')) {
1142 $line->fetch_optionals();
1146 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1147 $fk_parent_line = 0;
1152 $source_fk_prev_id = $line->fk_prev_id;
1153 $line->fk_prev_id = $line->id;
1155 if (!empty($facture_source->tab_previous_situation_invoice)) {
1158 $tab_jumped_credit_notes = array();
1159 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1160 $searchPreviousInvoice =
true;
1161 while ($searchPreviousInvoice) {
1162 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1163 $searchPreviousInvoice =
false;
1167 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1173 $maxPrevSituationPercent = 0;
1174 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1175 if ($prevLine->id == $source_fk_prev_id) {
1176 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1179 $line->total_ht = $line->total_ht - $prevLine->total_ht;
1180 $line->total_tva = $line->total_tva - $prevLine->total_tva;
1181 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
1182 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
1183 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
1185 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
1186 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
1187 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
1188 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
1193 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1198 $maxPrevSituationPercent = 0;
1199 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1200 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1201 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1202 $maxPrevSituationPercent = $prevLine->situation_percent;
1204 $line->total_ht -= $prevLine->total_ht;
1205 $line->total_tva -= $prevLine->total_tva;
1206 $line->total_ttc -= $prevLine->total_ttc;
1207 $line->total_localtax1 -= $prevLine->total_localtax1;
1208 $line->total_localtax2 -= $prevLine->total_localtax2;
1210 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1211 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1212 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1213 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1219 $line->situation_percent += $maxPrevSituationPercent;
1225 $line->fk_facture = $object->id;
1226 $line->fk_parent_line = $fk_parent_line;
1228 $line->subprice = -$line->subprice;
1229 $line->pa_ht = $line->pa_ht;
1230 $line->total_ht = -$line->total_ht;
1231 $line->total_tva = -$line->total_tva;
1232 $line->total_ttc = -$line->total_ttc;
1233 $line->total_localtax1 = -$line->total_localtax1;
1234 $line->total_localtax2 = -$line->total_localtax2;
1236 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1237 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1238 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1239 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1241 $line->context[
'createcreditnotefrominvoice'] = 1;
1242 $result = $line->insert(0, 1);
1244 $object->lines[] = $line;
1247 if ($result > 0 && $line->product_type == 9) {
1248 $fk_parent_line = $result;
1252 $object->update_price(1);
1256 if (
GETPOST(
'invoiceAvoirWithPaymentRestAmount',
'int') == 1 && $id > 0) {
1257 if ($facture_source->fetch($object->fk_facture_source) > 0) {
1258 $totalpaid = $facture_source->getSommePaiement();
1259 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1260 $totaldeposits = $facture_source->getSumDepositsUsed();
1261 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1263 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 1, 0, 0, 0, 0, 0,
'',
'',
'TTC');
1268 if (!empty($object->fk_facture_source) && $id > 0) {
1269 $facture_source->fetch($object->fk_facture_source);
1270 $facture_source->fetchObjectLinked();
1272 if (!empty($facture_source->linkedObjectsIds)) {
1273 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1274 $object->add_object_linked($sourcetype, current($TIds));
1283 if (empty($dateinvoice)) {
1285 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1287 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1294 $object->socid =
GETPOST(
'socid',
'int');
1295 $object->type =
GETPOST(
'type');
1296 $object->ref =
GETPOST(
'ref');
1297 $object->date = $dateinvoice;
1298 $object->date_pointoftax = $date_pointoftax;
1299 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1300 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1301 $object->ref_client =
GETPOST(
'ref_client');
1302 $object->model_pdf =
GETPOST(
'model');
1303 $object->fk_project =
GETPOST(
'projectid',
'int');
1304 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
1305 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1306 $object->fk_account =
GETPOST(
'fk_account',
'int');
1310 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1311 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1312 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1313 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1316 $object->fac_rec =
GETPOST(
'fac_rec',
'int');
1318 $id = $object->create($user);
1324 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1325 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1326 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1328 if (
GETPOST(
'socid',
'int') < 1) {
1330 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1334 if (empty($dateinvoice)) {
1336 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1338 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1346 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1347 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1352 if ($typeamount && !empty($origin) && !empty($originid)) {
1353 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1354 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1358 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1359 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1363 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1364 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1373 $object->socid =
GETPOST(
'socid',
'int');
1374 $object->type =
GETPOST(
'type');
1375 $object->ref =
GETPOST(
'ref');
1376 $object->date = $dateinvoice;
1377 $object->date_pointoftax = $date_pointoftax;
1378 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1379 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1380 $object->ref_client =
GETPOST(
'ref_client');
1381 $object->model_pdf =
GETPOST(
'model');
1382 $object->fk_project =
GETPOST(
'projectid',
'int');
1383 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
1384 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
1385 $object->fk_account =
GETPOST(
'fk_account',
'int');
1389 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1390 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1391 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1392 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1395 $object->situation_counter = 1;
1396 $object->situation_final = 0;
1397 $object->situation_cycle_ref = $object->newCycle();
1400 if (in_array($object->type, $retainedWarrantyInvoiceAvailableType)) {
1401 $object->retained_warranty =
GETPOST(
'retained_warranty',
'int');
1402 $object->retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
1404 $object->retained_warranty = 0;
1405 $object->retained_warranty_fk_cond_reglement = 0;
1408 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1409 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1410 $object->retained_warranty_date_limit =
dol_stringtotime($retained_warranty_date_limit);
1412 $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);
1414 $object->fetch_thirdparty();
1417 if (!empty($origin) && !empty($originid)) {
1420 $element = $subelement = $origin;
1421 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1422 $element = $regs[1];
1423 $subelement = $regs[2];
1427 if ($element ==
'order') {
1428 $element = $subelement =
'commande';
1430 if ($element ==
'propal') {
1431 $element =
'comm/propal';
1432 $subelement =
'propal';
1434 if ($element ==
'contract') {
1435 $element = $subelement =
'contrat';
1437 if ($element ==
'inter') {
1438 $element = $subelement =
'ficheinter';
1440 if ($element ==
'shipping') {
1441 $element = $subelement =
'expedition';
1444 $object->origin = $origin;
1445 $object->origin_id = $originid;
1448 $object->linked_objects[$object->origin] = $object->origin_id;
1450 if ($object->origin ==
'shipping') {
1451 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1453 $exp->fetch($object->origin_id);
1454 $exp->fetchObjectLinked();
1455 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1456 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1457 $object->linked_objects[
'commande'] = $value;
1462 if (is_array($_POST[
'other_linked_objects']) && !empty($_POST[
'other_linked_objects'])) {
1463 $object->linked_objects = array_merge($object->linked_objects, $_POST[
'other_linked_objects']);
1466 $id = $object->create($user);
1471 $classname = ucfirst($subelement);
1472 $srcobject =
new $classname($db);
1474 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines or deposit lines");
1475 $result = $srcobject->fetch($object->origin_id);
1480 $amountdeposit = array();
1481 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)) {
1482 if ($typeamount ==
'amount') {
1483 $amount = $valuedeposit;
1485 $amount = $srcobject->total_ttc * ($valuedeposit / 100);
1488 $TTotalByTva = array();
1489 foreach ($srcobject->lines as &$line) {
1490 if (!empty($line->special_code)) {
1493 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1496 foreach ($TTotalByTva as $tva => &$total) {
1497 $coef = $total / $srcobject->total_ttc;
1498 $am = $amount * $coef;
1499 $amount_ttc_diff += $am;
1500 $amountdeposit[$tva] += $am / (1 + $tva / 100);
1503 if ($typeamount ==
'amount') {
1504 $amountdeposit[0] = $valuedeposit;
1505 } elseif ($typeamount ==
'variable') {
1508 $lines = $srcobject->lines;
1509 $numlines = count($lines);
1510 for ($i = 0; $i < $numlines; $i++) {
1512 if (empty($lines[$i]->qty)) {
1515 if (!empty($lines[$i]->special_code)) {
1519 $totalamount += $lines[$i]->total_ht;
1520 $tva_tx = $lines[$i]->tva_tx;
1521 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $valuedeposit) / 100;
1525 if ($totalamount == 0) {
1526 $amountdeposit[0] = 0;
1534 $amount_ttc_diff = $amountdeposit[0];
1537 foreach ($amountdeposit as $tva => $amount) {
1538 if (empty($amount)) {
1543 'amount' =>
'FixAmount',
1544 'variable' =>
'VarAmount'
1546 $descline =
'(DEPOSIT)';
1548 if ($typeamount ==
'amount') {
1549 $descline .=
' ('.price($valuedeposit,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
')';
1550 } elseif ($typeamount ==
'variable') {
1551 $descline .=
' ('.$valuedeposit.
'%)';
1554 $descline .=
' - '.$srcobject->ref;
1555 $result = $object->addline(
1562 (empty($conf->global->INVOICE_PRODUCTID_DEPOSIT) ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT),
1567 $lines[$i]->info_bits,
1573 $lines[$i]->special_code,
1590 $diff = $object->total_ttc - $amount_ttc_diff;
1592 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0) {
1593 $object->fetch_lines();
1594 $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100);
1595 $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);
1602 $lines = $srcobject->lines;
1603 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1604 $srcobject->fetch_lines();
1605 $lines = $srcobject->lines;
1610 if (is_array($lines)) {
1611 foreach ($lines as $line) {
1613 $line->qty =
price2num($line->qty * $valuestandardinvoice / 100,
'MS');
1619 if (is_array($lines)) {
1620 foreach ($lines as $line) {
1622 $line->qty =
price2num($line->qty * $valuedeposit / 100,
'MS');
1627 $fk_parent_line = 0;
1628 $num = count($lines);
1630 for ($i = 0; $i < $num; $i++) {
1631 if (!in_array($lines[$i]->
id, $selectedLines)) {
1636 if ($srcobject->element ==
'shipping' && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS && $lines[$i]->qty == 0) {
1640 if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1641 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1643 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',', $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE))) {
1647 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1648 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->libelle);
1649 if ($object->situation_counter == 1) {
1650 $lines[$i]->situation_percent = 0;
1653 if ($lines[$i]->subprice < 0 && empty($conf->global->INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN)) {
1656 $discount->fk_soc = $object->socid;
1657 $discount->amount_ht = abs($lines[$i]->total_ht);
1658 $discount->amount_tva = abs($lines[$i]->total_tva);
1659 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1660 $discount->tva_tx = $lines[$i]->tva_tx;
1661 $discount->fk_user = $user->id;
1662 $discount->description = $desc;
1663 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1664 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1665 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1666 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1668 $discountid = $discount->create($user);
1669 if ($discountid > 0) {
1670 $result = $object->insert_discount($discountid);
1678 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1681 $date_start =
false;
1682 if ($lines[$i]->date_debut_prevue) {
1683 $date_start = $lines[$i]->date_debut_prevue;
1685 if ($lines[$i]->date_debut_reel) {
1686 $date_start = $lines[$i]->date_debut_reel;
1688 if ($lines[$i]->date_start) {
1689 $date_start = $lines[$i]->date_start;
1694 if ($lines[$i]->date_fin_prevue) {
1695 $date_end = $lines[$i]->date_fin_prevue;
1697 if ($lines[$i]->date_fin_reel) {
1698 $date_end = $lines[$i]->date_fin_reel;
1700 if ($lines[$i]->date_end) {
1701 $date_end = $lines[$i]->date_end;
1705 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1706 $fk_parent_line = 0;
1710 if (method_exists($lines[$i],
'fetch_optionals')) {
1711 $lines[$i]->fetch_optionals();
1712 $array_options = $lines[$i]->array_options;
1715 $tva_tx = $lines[$i]->tva_tx;
1716 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
1717 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1722 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty);
1723 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty);
1725 $result = $object->addline(
1727 $lines[$i]->subprice,
1732 $lines[$i]->fk_product,
1733 $lines[$i]->remise_percent,
1737 $lines[$i]->info_bits,
1738 $lines[$i]->fk_remise_except,
1743 $lines[$i]->special_code,
1747 $lines[$i]->fk_fournprice,
1751 $lines[$i]->situation_percent,
1752 $lines[$i]->fk_prev_id,
1753 $lines[$i]->fk_unit,
1768 if ($result > 0 && $lines[$i]->product_type == 9) {
1769 $fk_parent_line = $result;
1779 $object->update_price(1,
'auto', 0, $mysoc);
1809 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
1820 $id = $object->create($user);
1822 for ($i = 1; $i <= $NBLINES; $i++) {
1823 if (
GETPOST(
'idprod'.$i,
'int')) {
1825 $product->fetch(
GETPOST(
'idprod'.$i,
'int'));
1828 $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);
1832 $object->update_price(1,
'auto', 0, $mysoc);
1839 if (empty($dateinvoice)) {
1841 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
1843 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1849 if (!(
GETPOST(
'situations',
'int') > 0)) {
1851 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
1857 $result = $object->fetch(
GETPOST(
'situations',
'int'));
1858 $object->fk_facture_source =
GETPOST(
'situations',
'int');
1861 if (!empty($origin) && !empty($originid)) {
1862 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1864 $object->origin = $origin;
1865 $object->origin_id = $originid;
1868 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
1869 $retained_warranty =
GETPOST(
'retained_warranty',
'int');
1870 if (
price2num($retained_warranty) > 0) {
1871 $object->retained_warranty =
price2num($retained_warranty);
1874 if (
GETPOST(
'retained_warranty_fk_cond_reglement',
'int') > 0) {
1875 $object->retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
1878 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1879 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
1880 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
1882 $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);
1885 foreach ($object->lines as $i => &$line) {
1886 $line->origin = $object->origin;
1887 $line->origin_id = $line->id;
1888 $line->fk_prev_id = $line->id;
1889 $line->fetch_optionals();
1890 $line->situation_percent = $line->get_prev_progress($object->id);
1893 $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);
1894 $line->total_ht = $tabprice[0];
1895 $line->total_tva = $tabprice[1];
1896 $line->total_ttc = $tabprice[2];
1897 $line->total_localtax1 = $tabprice[9];
1898 $line->total_localtax2 = $tabprice[10];
1899 $line->multicurrency_total_ht = $tabprice[16];
1900 $line->multicurrency_total_tva = $tabprice[17];
1901 $line->multicurrency_total_ttc = $tabprice[18];
1904 if ($line->fk_remise_except) {
1906 $result = $discount->fetch($line->fk_remise_except);
1909 if ($discount->fk_facture_line > 0) {
1910 $line->fk_remise_except = 0;
1917 $object->fetch_thirdparty();
1918 $object->date = $dateinvoice;
1919 $object->date_pointoftax = $date_pointoftax;
1920 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1921 $object->note = trim(
GETPOST(
'note',
'restricthtml'));
1922 $object->note_private = trim(
GETPOST(
'note',
'restricthtml'));
1923 $object->ref_client =
GETPOST(
'ref_client',
'alpha');
1924 $object->model_pdf =
GETPOST(
'model',
'alpha');
1925 $object->fk_project =
GETPOST(
'projectid',
'int');
1926 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1927 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1930 $object->fk_account =
GETPOST(
'fk_account',
'int');
1935 $object->situation_counter = $object->situation_counter + 1;
1936 $id = $object->createFromCurrent($user);
1938 $mesg = $object->error;
1940 $nextSituationInvoice =
new Facture($db);
1941 $nextSituationInvoice->fetch($id);
1944 $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
1945 $ret = $extrafields->setOptionalsFromPost(
null, $nextSituationInvoice);
1947 $nextSituationInvoice->insertExtraFields();
1954 if ($id > 0 && !$error) {
1958 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && count($object->lines)) {
1959 $outputlangs = $langs;
1961 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1962 $newlang =
GETPOST(
'lang_id',
'aZ09');
1964 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1965 $newlang = $object->thirdparty->default_lang;
1967 if (!empty($newlang)) {
1968 $outputlangs =
new Translate(
"", $conf);
1969 $outputlangs->setDefaultLang($newlang);
1970 $outputlangs->load(
'products');
1972 $model = $object->model_pdf;
1973 $ret = $object->fetch($id);
1975 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1981 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
1986 $_GET[
"origin"] = $_POST[
"origin"];
1987 $_GET[
"originid"] = $_POST[
"originid"];
1990 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'') {
1992 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1993 $vat_rate = str_replace(
'*',
'', $vat_rate);
1994 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1995 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1996 foreach ($object->lines as $line) {
1997 $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);
1999 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2001 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2002 $remise_percent = str_replace(
'*',
'', $remise_percent);
2003 foreach ($object->lines as $line) {
2004 $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);
2006 } elseif ($action ==
'addline' && $usercancreate) {
2007 $langs->load(
'errors');
2015 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'alpha');
2016 if ($prod_entry_mode ==
'free') {
2018 $tva_tx = (
GETPOST(
'tva_tx',
'alpha') ?
GETPOST(
'tva_tx',
'alpha') : 0);
2020 $idprod =
GETPOST(
'idprod',
'int');
2028 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
2029 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
2031 if (is_array($extralabelsline)) {
2033 foreach ($extralabelsline as $key => $value) {
2034 unset($_POST[
"options_".$key.$predef]);
2038 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2039 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2042 if (!$prod_entry_mode) {
2044 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2048 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2049 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2052 if (($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && (($price_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) || $price_ht ==
'') && $price_ht_devise ==
'') && $object->type !=
Facture::TYPE_CREDIT_NOTE) {
2053 if ($price_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
2054 $langs->load(
"errors");
2055 if ($object->type == $object::TYPE_DEPOSIT) {
2057 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2059 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2063 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2068 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2071 if ($prod_entry_mode ==
'free' && empty($idprod) && empty($product_desc)) {
2072 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2076 $langs->load(
"errors");
2077 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2081 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2082 if ($combinations =
GETPOST(
'combinations',
'array')) {
2086 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2087 $idprod = $res->fk_product_child;
2089 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2095 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
2096 $ret = $object->fetch($id);
2101 $ret = $object->fetch_thirdparty();
2106 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2117 if (!empty($idprod) && $idprod > 0) {
2119 $prod->fetch($idprod);
2121 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2126 $datapriceofproduct = $prod->getSellPrice($mysoc, $object->thirdparty, $pqp);
2128 $pu_ht = $datapriceofproduct[
'pu_ht'];
2129 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2130 $price_min = $datapriceofproduct[
'price_min'];
2131 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2132 $tva_tx = $datapriceofproduct[
'tva_tx'];
2133 $tva_npr = $datapriceofproduct[
'tva_npr'];
2135 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2136 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
2139 if (!empty($price_ht) || $price_ht ===
'0') {
2141 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2142 } elseif ($tmpvat != $tmpprodvat) {
2145 if ($price_base_type !=
'HT') {
2146 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2148 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2155 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
2156 $outputlangs = $langs;
2158 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
2159 $newlang =
GETPOST(
'lang_id',
'aZ09');
2161 if (empty($newlang)) {
2162 $newlang = $object->thirdparty->default_lang;
2164 if (!empty($newlang)) {
2165 $outputlangs =
new Translate(
"", $conf);
2166 $outputlangs->setDefaultLang($newlang);
2167 $outputlangs->load(
'products');
2170 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->description;
2172 $desc = $prod->description;
2176 if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
2180 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
2181 $desc = $product_desc;
2183 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
2187 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
2190 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
2191 $outputlangs = $langs;
2193 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
2194 $newlang =
GETPOST(
'lang_id',
'alpha');
2196 if (empty($newlang)) {
2197 $newlang = $object->thirdparty->default_lang;
2199 if (!empty($newlang)) {
2200 $outputlangs =
new Translate(
"", $conf);
2201 $outputlangs->setDefaultLang($newlang);
2202 $outputlangs->load(
'products');
2204 if (!empty($prod->customcode)) {
2205 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2207 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2210 if (!empty($prod->country_code)) {
2211 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
2214 if (!empty($prod->customcode)) {
2215 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2217 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2220 if (!empty($prod->country_code)) {
2221 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
2228 $type = $prod->type;
2229 $fk_unit = $prod->fk_unit;
2233 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2234 $tva_tx = str_replace(
'*',
'', $tva_tx);
2235 if (empty($tva_tx)) {
2238 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2239 $desc = $product_desc;
2241 $fk_unit =
GETPOST(
'units',
'alpha');
2244 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2251 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
2252 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
2260 $price2num_remise_percent =
price2num($remise_percent);
2261 $price2num_price_min =
price2num($price_min);
2262 if (empty($price2num_pu_ht)) {
2263 $price2num_pu_ht = 0;
2265 if (empty($price2num_remise_percent)) {
2266 $price2num_remise_percent = 0;
2268 if (empty($price2num_price_min)) {
2269 $price2num_price_min = 0;
2272 if ($usercanproductignorepricemin && (!empty($price_min) && ($price2num_pu_ht * (1 - $price2num_remise_percent / 100) < $price2num_price_min))) {
2273 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
2277 if (!empty($conf->productbatch->enabled) && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) && !empty($conf->global->INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS)) {
2278 $langs->load(
'productbatch');
2279 foreach ($lines[$i]->detail_batch as $batchline) {
2280 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2285 $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);
2289 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2290 $outputlangs = $langs;
2292 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
2293 $newlang =
GETPOST(
'lang_id',
'aZ09');
2295 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) {
2296 $newlang = $object->thirdparty->default_lang;
2298 if (!empty($newlang)) {
2299 $outputlangs =
new Translate(
"", $conf);
2300 $outputlangs->setDefaultLang($newlang);
2301 $outputlangs->load(
'products');
2303 $model = $object->model_pdf;
2304 $ret = $object->fetch($id);
2306 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2312 unset($_POST[
'prod_entry_mode']);
2314 unset($_POST[
'qty']);
2315 unset($_POST[
'type']);
2316 unset($_POST[
'remise_percent']);
2317 unset($_POST[
'price_ht']);
2318 unset($_POST[
'multicurrency_price_ht']);
2319 unset($_POST[
'price_ttc']);
2320 unset($_POST[
'tva_tx']);
2321 unset($_POST[
'product_ref']);
2322 unset($_POST[
'product_label']);
2323 unset($_POST[
'product_desc']);
2324 unset($_POST[
'fournprice']);
2325 unset($_POST[
'buying_price']);
2326 unset($_POST[
'np_marginRate']);
2327 unset($_POST[
'np_markRate']);
2328 unset($_POST[
'dp_desc']);
2329 unset($_POST[
'idprod']);
2330 unset($_POST[
'units']);
2332 unset($_POST[
'date_starthour']);
2333 unset($_POST[
'date_startmin']);
2334 unset($_POST[
'date_startsec']);
2335 unset($_POST[
'date_startday']);
2336 unset($_POST[
'date_startmonth']);
2337 unset($_POST[
'date_startyear']);
2338 unset($_POST[
'date_endhour']);
2339 unset($_POST[
'date_endmin']);
2340 unset($_POST[
'date_endsec']);
2341 unset($_POST[
'date_endday']);
2342 unset($_POST[
'date_endmonth']);
2343 unset($_POST[
'date_endyear']);
2345 unset($_POST[
'situations']);
2346 unset($_POST[
'progress']);
2354 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2355 if (!$object->fetch($id) > 0) {
2358 $object->fetch_thirdparty();
2373 if (preg_match(
'/\*/', $vat_rate)) {
2378 $vat_rate = str_replace(
'*',
'', $vat_rate);
2379 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty);
2380 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty);
2387 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
2388 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
2390 if (is_array($extralabelsline)) {
2392 foreach ($extralabelsline as $key => $value) {
2393 unset($_POST[
"options_".$key]);
2398 $special_code =
GETPOST(
'special_code',
'int');
2399 if ($special_code == 3) {
2404 $line->fetch(
GETPOST(
'lineid',
'int'));
2405 $percent = $line->get_prev_progress($object->id);
2410 if ($progress >= 0) {
2411 $mesg = $langs->trans(
"CantBeNullOrPositive");
2415 } elseif ($progress < $line->situation_percent) {
2416 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
2420 } elseif ($progress < $percent) {
2421 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
2431 $productid =
GETPOST(
'productid',
'int');
2432 if (!empty($productid)) {
2434 $product->fetch($productid);
2436 $type = $product->type;
2438 $price_min = $product->price_min;
2439 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
2440 $price_min = $product->multiprices_min [$object->thirdparty->price_level];
2447 setEventMessages($langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency)),
null,
'errors');
2452 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2456 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
2461 $langs->load(
"errors");
2462 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2465 if ((empty($productid) && (($pu_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) || $pu_ht ==
'') && $pu_ht_devise ==
'') && $object->type !=
Facture::TYPE_CREDIT_NOTE) {
2466 if ($pu_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
2467 $langs->load(
"errors");
2468 if ($object->type == $object::TYPE_DEPOSIT) {
2470 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2472 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2476 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2484 if (empty($usercancreatemargin)) {
2485 foreach ($object->lines as &$line) {
2486 if ($line->id ==
GETPOST(
'lineid',
'int')) {
2487 $fournprice = $line->fk_fournprice;
2488 $buyingprice = $line->pa_ht;
2494 $result = $object->updateline(
2508 GETPOST(
'fk_parent_line',
'int'),
2521 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2523 $outputlangs = $langs;
2525 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
2526 $newlang =
GETPOST(
'lang_id',
'aZ09');
2528 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
2529 $newlang = $object->thirdparty->default_lang;
2531 if (!empty($newlang)) {
2532 $outputlangs =
new Translate(
"", $conf);
2533 $outputlangs->setDefaultLang($newlang);
2534 $outputlangs->load(
'products');
2537 $ret = $object->fetch($id);
2538 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2541 unset($_POST[
'qty']);
2542 unset($_POST[
'type']);
2543 unset($_POST[
'productid']);
2544 unset($_POST[
'remise_percent']);
2545 unset($_POST[
'price_ht']);
2546 unset($_POST[
'multicurrency_price_ht']);
2547 unset($_POST[
'price_ttc']);
2548 unset($_POST[
'tva_tx']);
2549 unset($_POST[
'product_ref']);
2550 unset($_POST[
'product_label']);
2551 unset($_POST[
'product_desc']);
2552 unset($_POST[
'fournprice']);
2553 unset($_POST[
'buying_price']);
2554 unset($_POST[
'np_marginRate']);
2555 unset($_POST[
'np_markRate']);
2557 unset($_POST[
'dp_desc']);
2558 unset($_POST[
'idprod']);
2559 unset($_POST[
'units']);
2561 unset($_POST[
'date_starthour']);
2562 unset($_POST[
'date_startmin']);
2563 unset($_POST[
'date_startsec']);
2564 unset($_POST[
'date_startday']);
2565 unset($_POST[
'date_startmonth']);
2566 unset($_POST[
'date_startyear']);
2567 unset($_POST[
'date_endhour']);
2568 unset($_POST[
'date_endmin']);
2569 unset($_POST[
'date_endsec']);
2570 unset($_POST[
'date_endday']);
2571 unset($_POST[
'date_endmonth']);
2572 unset($_POST[
'date_endyear']);
2574 unset($_POST[
'situations']);
2575 unset($_POST[
'progress']);
2580 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modifier')) {
2581 if (!$object->fetch($id) > 0) {
2584 if (
GETPOST(
'all_progress') !=
"") {
2585 $all_progress =
GETPOST(
'all_progress',
'int');
2586 foreach ($object->lines as $line) {
2587 $percent = $line->get_prev_progress($object->id);
2588 if (floatval($all_progress) < floatval($percent)) {
2589 $mesg = $langs->trans(
"Line").
' '.$i.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
2593 $object->update_percent($line,
GETPOST(
'all_progress'),
false);
2596 $object->update_price(1);
2598 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
2599 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2601 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
2603 $object->fetch($id,
'',
'',
'',
true);
2609 && $object->is_last_in_cycle()
2610 && $usercanunvalidate
2613 $newCycle = $object->newCycle();
2614 if ($newCycle > 1) {
2616 $lastCycle = $object->situation_cycle_ref;
2617 $lastSituationCounter = $object->situation_counter;
2618 $linkedCreditNotesList = array();
2620 if (count($object->tab_next_situation_invoice) > 0) {
2621 foreach ($object->tab_next_situation_invoice as $next_invoice) {
2623 && $next_invoice->situation_counter == $object->situation_counter
2624 && $next_invoice->fk_facture_source == $object->id
2626 $linkedCreditNotesList[] = $next_invoice->id;
2631 $object->situation_cycle_ref = $newCycle;
2632 $object->situation_counter = 1;
2633 $object->situation_final = 0;
2634 if ($object->update($user) > 0) {
2636 if (count($linkedCreditNotesList) > 0) {
2638 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
2639 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
2640 $sql .=
' , situation_final=0';
2641 $sql .=
' , situation_counter='.((int) $object->situation_counter);
2642 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
2644 $resql = $db->query($sql);
2650 foreach ($object->lines as $line) {
2652 if ($line->product_type == 9) {
2657 if (!empty($object->tab_previous_situation_invoice)) {
2659 $lineIndex = count($object->tab_previous_situation_invoice) - 1;
2660 $searchPreviousInvoice =
true;
2661 while ($searchPreviousInvoice) {
2663 $searchPreviousInvoice =
false;
2671 $maxPrevSituationPercent = 0;
2672 foreach ($object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
2673 if ($prevLine->id == $line->fk_prev_id) {
2674 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
2679 $line->situation_percent = $line->situation_percent - $maxPrevSituationPercent;
2681 if ($line->update() < 0) {
2690 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
2692 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
2695 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
2698 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
2701 } elseif ($action ==
'import_lines_from_object'
2706 $fromElement =
GETPOST(
'fromelement');
2707 $fromElementid =
GETPOST(
'fromelementid');
2708 $importLines =
GETPOST(
'line_checkbox');
2710 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
2711 if ($fromElement ==
'commande') {
2713 $lineClassName =
'OrderLine';
2714 } elseif ($fromElement ==
'propal') {
2715 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
2716 $lineClassName =
'PropaleLigne';
2718 $nextRang = count($object->lines) + 1;
2721 foreach ($importLines as $lineId) {
2722 $lineId = intval($lineId);
2723 $originLine =
new $lineClassName($db);
2724 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
2725 $originLine->fetch_optionals();
2726 $desc = $originLine->desc;
2727 $pu_ht = $originLine->subprice;
2728 $qty = $originLine->qty;
2729 $txtva = $originLine->tva_tx;
2730 $txlocaltax1 = $originLine->localtax1_tx;
2731 $txlocaltax2 = $originLine->localtax2_tx;
2732 $fk_product = $originLine->fk_product;
2733 $remise_percent = $originLine->remise_percent;
2734 $date_start = $originLine->date_start;
2735 $date_end = $originLine->date_end;
2737 $info_bits = $originLine->info_bits;
2738 $fk_remise_except = $originLine->fk_remise_except;
2739 $price_base_type =
'HT';
2741 $type = $originLine->product_type;
2742 $rang = $nextRang++;
2743 $special_code = $originLine->special_code;
2744 $origin = $originLine->element;
2745 $origin_id = $originLine->id;
2746 $fk_parent_line = 0;
2747 $fk_fournprice = $originLine->fk_fournprice;
2748 $pa_ht = $originLine->pa_ht;
2749 $label = $originLine->label;
2750 $array_options = $originLine->array_options;
2752 $situation_percent = 0;
2754 $situation_percent = 100;
2757 $fk_unit = $originLine->fk_unit;
2758 $pu_ht_devise = $originLine->multicurrency_subprice;
2760 $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);
2779 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2785 $triggersendname =
'BILL_SENTBYMAIL';
2787 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
2788 $trackid =
'inv'.$object->id;
2789 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2792 $upload_dir = $conf->facture->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity];
2793 $permissiontoadd = $usercancreate;
2794 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2797 if ($action ==
'update_extras') {
2798 $object->oldcopy =
dol_clone($object, 2);
2801 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
2808 $result = $object->insertExtraFields(
'BILL_MODIFY');
2816 $action =
'edit_extras';
2820 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
2821 if ($action ==
'addcontact') {
2822 $result = $object->fetch($id);
2824 if ($result > 0 && $id > 0) {
2827 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2831 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2834 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2835 $langs->load(
"errors");
2836 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2841 } elseif ($action ==
'swapstatut') {
2843 if ($object->fetch($id)) {
2844 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
2848 } elseif ($action ==
'deletecontact') {
2850 $object->fetch($id);
2851 $result = $object->delete_contact($lineid);
2854 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2862 $action =
'edit_extras';
2878 $paymentstatic =
new Paiement($db);
2879 $bankaccountstatic =
new Account($db);
2886 $title = $langs->trans(
'InvoiceCustomer').
" - ".$langs->trans(
'Card');
2888 $help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
2894 if ($action ==
'create') {
2895 $facturestatic =
new Facture($db);
2896 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
2901 $res = $soc->fetch($socid);
2904 $currency_code = $conf->currency;
2908 $remise_absolue = 0;
2909 if (!empty($origin) && !empty($originid)) {
2911 $element = $subelement = $origin;
2913 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
2914 $element = $regs[1];
2915 $subelement = $regs[2];
2918 if ($element ==
'project') {
2919 $projectid = $originid;
2921 if (empty($cond_reglement_id)) {
2922 $cond_reglement_id = $soc->cond_reglement_id;
2924 if (empty($mode_reglement_id)) {
2925 $mode_reglement_id = $soc->mode_reglement_id;
2927 if (empty($fk_account)) {
2928 $fk_account = $soc->fk_account;
2930 if (!$remise_percent) {
2931 $remise_percent = $soc->remise_percent;
2933 if (!$dateinvoice) {
2935 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
2939 if ($element ==
'order' || $element ==
'commande') {
2940 $element = $subelement =
'commande';
2942 if ($element ==
'propal') {
2943 $element =
'comm/propal';
2944 $subelement =
'propal';
2946 if ($element ==
'contract') {
2947 $element = $subelement =
'contrat';
2949 if ($element ==
'shipping') {
2950 $element = $subelement =
'expedition';
2955 $classname = ucfirst($subelement);
2956 $objectsrc =
new $classname($db);
2957 $objectsrc->fetch($originid);
2958 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
2959 $objectsrc->fetch_lines();
2961 $objectsrc->fetch_thirdparty();
2963 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
2964 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
2967 if (empty($socid)) {
2968 $soc = $objectsrc->thirdparty;
2971 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
2973 if ($element ==
'expedition') {
2974 $ref_client = (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
'');
2976 $elem = $subelem = $objectsrc->origin;
2977 $expeoriginid = $objectsrc->origin_id;
2979 $classname = ucfirst($subelem);
2981 $expesrc =
new $classname($db);
2982 $expesrc->fetch($expeoriginid);
2984 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
2985 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
2986 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
2987 $remise_percent = (!empty($expesrc->remise_percent) ? $expesrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
2988 $remise_absolue = (!empty($expesrc->remise_absolue) ? $expesrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
2990 if (!empty($conf->multicurrency->enabled)) {
2991 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
2992 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
2996 $expesrc->fetch_optionals();
2997 $object->array_options = $expesrc->array_options;
2999 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
3000 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3001 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3002 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
3003 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
3006 if (!empty($objectsrc->multicurrency_code)) {
3007 $currency_code = $objectsrc->multicurrency_code;
3009 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
3010 $currency_tx = $objectsrc->multicurrency_tx;
3015 $objectsrc->fetch_optionals();
3016 $object->array_options = $objectsrc->array_options;
3020 $cond_reglement_id = $soc->cond_reglement_id;
3021 $mode_reglement_id = $soc->mode_reglement_id;
3022 $fk_account = $soc->fk_account;
3023 $remise_percent = $soc->remise_percent;
3024 $remise_absolue = 0;
3025 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
3027 if (
isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3028 $currency_code = $soc->multicurrency_code;
3033 if (empty($cond_reglement_id)) {
3034 $cond_reglement_id =
GETPOST(
"cond_reglement_id",
'int');
3038 if (empty($mode_reglement_id)) {
3039 $mode_reglement_id =
GETPOST(
"mode_reglement_id",
'int');
3043 if ($socid > 0 && $fk_account) {
3046 $fk_account =
GETPOST(
"fk_account",
'int');
3049 if (!empty($soc->id)) {
3050 $absolute_discount = $soc->getAvailableDiscounts();
3052 $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));
3053 $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));
3055 if (!empty($conf->use_javascript_ajax)) {
3056 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3062 if ($origin ==
'contrat') {
3063 $langs->load(
"admin");
3064 $text = $langs->trans(
"ToCreateARecurringInvoice");
3065 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3066 if (empty($conf->global->INVOICE_DISABLE_AUTOMATIC_RECURRING_INVOICE)) {
3067 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3069 print
info_admin($text, 0, 0, 0,
'opacitymedium').
'<br>';
3072 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3073 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3074 print
'<input type="hidden" name="action" value="add">';
3076 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3078 print
'<input name="ref" type="hidden" value="provisoire">';
3079 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3080 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3081 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3082 print
'<input name="force_fk_account" type="hidden" value="0">';
3083 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3084 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3085 print
'<input type="hidden" name="originentity" value="'.GETPOST(
'originentity').
'">';
3086 if (!empty($currency_tx)) {
3087 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3092 print
'<table class="border centpercent">';
3097 $exampletemplateinvoice =
new FactureRec($db);
3099 if (empty($origin) && empty($originid) &&
GETPOST(
'fac_rec',
'int') > 0) {
3100 $invoice_predefined->fetch(
GETPOST(
'fac_rec',
'int'));
3104 if ($soc->id > 0 && (!
GETPOST(
'fac_rec',
'int') || !empty($invoice_predefined->frequency))) {
3106 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3107 print
'<td colspan="2">';
3108 print $soc->getNomUrl(1,
'customer');
3109 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3111 $arrayoutstandingbills = $soc->getOutstandingBills();
3112 $outstandingBills = $arrayoutstandingbills[
'opened'];
3113 print
' - <span class="opacitymedium">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3114 print
price($outstandingBills,
'', $langs, 0, 0, -1, $conf->currency);
3115 if ($soc->outstanding_limit !=
'') {
3116 if ($outstandingBills > $soc->outstanding_limit) {
3117 print
img_warning($langs->trans(
"OutstandingBillReached"));
3119 print
' / '.price($soc->outstanding_limit,
'', $langs, 0, 0, -1, $conf->currency);
3124 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3125 print
'<td colspan="2">';
3126 print
img_picto(
'',
'company').$form->select_company($soc->id,
'socid',
'((s.client = 1 OR s.client = 3) AND s.status = 1)',
'SelectThirdParty', 0, 0,
null, 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3128 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
3129 print
'<script type="text/javascript">
3130 $(document).ready(function() {
3131 $("#socid").change(function() {
3133 console.log("Submit page");
3134 $(\'input[name="action"]\').val(\'create\');
3135 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3136 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3137 $(\'input[name="force_fk_account"]\').val(\'1\');
3138 $("#formtocreate").submit(); */
3140 // 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.
3141 console.log("We have changed the company - Reload page");
3142 var socid = $(this).val();
3143 var fac_rec = $(\'#fac_rec\').val();
3144 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3149 if (!
GETPOST(
'fac_rec',
'int')) {
3150 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>';
3157 if (empty($origin) && empty($originid) &&
GETPOST(
'fac_rec',
'int') > 0) {
3158 $invoice_predefined->fetch(
GETPOST(
'fac_rec',
'int'));
3160 $dateinvoice = $invoice_predefined->date_when;
3161 if (empty($projectid)) {
3162 $projectid = $invoice_predefined->fk_project;
3164 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
3165 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
3166 $fk_account = $invoice_predefined->fk_account;
3167 $note_public = $invoice_predefined->note_public;
3168 $note_private = $invoice_predefined->note_private;
3170 if (!empty($invoice_predefined->multicurrency_code)) {
3171 $currency_code = $invoice_predefined->multicurrency_code;
3173 if (!empty($invoice_predefined->multicurrency_tx)) {
3174 $currency_tx = $invoice_predefined->multicurrency_tx;
3177 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
3178 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
3179 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
3181 $resql = $db->query($sql);
3183 $num = $db->num_rows(
$resql);
3187 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
3189 print
'<select class="flat" id="fac_rec" name="fac_rec">';
3190 print
'<option value="0" selected></option>';
3192 $objp = $db->fetch_object(
$resql);
3193 print
'<option value="'.$objp->rowid.
'"';
3194 if (
GETPOST(
'fac_rec',
'int') == $objp->rowid) {
3196 $exampletemplateinvoice->fetch(
GETPOST(
'fac_rec',
'int'));
3198 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
3206 if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED)) {
3207 print
'<script type="text/javascript">
3208 $(document).ready(function() {
3209 $("#fac_rec").change(function() {
3210 console.log("We have changed the template invoice - Reload page");
3211 var fac_rec = $(this).val();
3212 var socid = $(\'#socid\').val();
3213 // 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.
3214 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3227 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td colspan="2">';
3228 print
'<div class="tagtable">'.
"\n";
3231 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3232 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOST(
'type',
'int') ?
'' :
' checked').
'> ';
3233 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
3234 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
3235 print
'<table class="nobordernopadding"><tr>';
3239 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
3248 print
'<td class="nowrap" style="padding-left: 15px">';
3249 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%').
'"/>';
3252 print
'</tr></table>';
3253 print
'</div></div>';
3255 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
3257 if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) {
3258 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3259 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOST(
'type') == 3 ?
' checked' :
'').
'> ';
3260 print
'<script type="text/javascript">
3261 jQuery(document).ready(function() {
3262 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
3263 jQuery("#radio_standard").prop("checked", true);
3265 jQuery("#typedeposit, #valuedeposit").click(function() {
3266 jQuery("#radio_deposit").prop("checked", true);
3268 jQuery("#typedeposit").change(function() {
3269 console.log("We change type of down payment");
3270 jQuery("#radio_deposit").prop("checked", true);
3271 setRadioForTypeOfIncoice();
3273 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
3274 setRadioForTypeOfIncoice();
3276 function setRadioForTypeOfIncoice() {
3277 console.log("Change radio");
3278 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
3279 jQuery(".checkforselect").prop("disabled", true);
3280 jQuery(".checkforselect").prop("checked", false);
3282 jQuery(".checkforselect").prop("disabled", false);
3283 jQuery(".checkforselect").prop("checked", true);
3289 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
3290 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
3291 print
'<table class="nobordernopadding"><tr>';
3295 if (($origin ==
'propal') || ($origin ==
'commande')) {
3296 print
'<td class="nowrap" style="padding-left: 15px">';
3298 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
3299 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
3300 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
3302 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
3303 $valuedeposit =
GETPOST(
'valuedeposit',
'int');
3304 if (empty($typedeposit) && ! empty($objectsrc->deposit_percent)) {
3305 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
3306 if (! empty($origin_payment_conditions_deposit_percent)) {
3307 $typedeposit =
'variable';
3310 if (empty($valuedeposit) && $typedeposit ==
'variable' && ! empty($objectsrc->deposit_percent)) {
3311 $valuedeposit = $objectsrc->deposit_percent;
3313 print
$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
3315 print
'<td class="nowrap" style="padding-left: 5px">';
3316 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.$valuedeposit.
'"/>';
3319 print
'</tr></table>';
3321 print
'</div></div>';
3326 if (!empty($conf->global->INVOICE_USE_SITUATION)) {
3328 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3329 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
3330 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
3331 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3);
3333 print
'</div></div>';
3336 $opt =
$form->selectSituationInvoices(
GETPOST(
'originid',
'int'), $socid);
3338 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3339 $tmp =
'<input type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOST(
'originid',
'int') ?
' checked' :
'');
3340 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3341 $tmp .=
' disabled';
3344 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3345 $text .=
'<select class="flat" id="situations" name="situations"';
3346 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3347 $text .=
' disabled';
3351 $text .=
'</select>';
3352 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
3354 print
'</div></div>';
3358 if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT)) {
3360 $facids = $facturestatic->list_replacable_invoices($soc->id);
3366 if (is_array($facids)) {
3367 foreach ($facids as $facparam) {
3368 $options .=
'<option value="'.$facparam [
'id'].
'"';
3369 if ($facparam[
'id'] ==
GETPOST(
'fac_replacement',
'int')) {
3370 $options .=
' selected';
3372 $options .=
'>'.$facparam[
'ref'];
3373 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
3374 $options .=
'</option>';
3378 print
'<!-- replacement line -->';
3379 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3380 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
3381 if (!$options || $invoice_predefined->id > 0) {
3382 $tmp .=
' disabled';
3385 print
'<script type="text/javascript">
3386 jQuery(document).ready(function() {
3387 jQuery("#fac_replacement").change(function() {
3388 jQuery("#radio_replacement").prop("checked", true);
3392 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
3393 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
3394 if (!$options || $invoice_predefined->id > 0) {
3395 $text .=
' disabled';
3399 $text .=
'<option value="-1"> </option>';
3402 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
3404 $text .=
'</select>';
3405 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3407 print
'</div></div>';
3410 if (!empty($conf->global->INVOICE_USE_SITUATION)) {
3411 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3412 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3413 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceFirstSituationAsk").
'</label> ';
3414 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3415 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3);
3417 print
'</div></div>';
3419 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3420 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3421 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3422 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3423 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3);
3425 print
'</div></div>';
3428 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3429 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
3430 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceReplacement").
'</label> ';
3431 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3432 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3434 print
'</div></div>';
3437 if (empty($origin)) {
3440 if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) {
3442 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
3448 $newinvoice_static =
new Facture($db);
3449 foreach ($facids as $key => $valarray) {
3450 $newinvoice_static->id = $key;
3451 $newinvoice_static->ref = $valarray [
'ref'];
3452 $newinvoice_static->statut = $valarray [
'status'];
3453 $newinvoice_static->type = $valarray [
'type'];
3454 $newinvoice_static->paye = $valarray [
'paye'];
3456 $optionsav .=
'<option value="'.$key.
'"';
3457 if ($key ==
GETPOST(
'fac_avoir')) {
3458 $optionsav .=
' selected';
3461 $newinvoice_static->fetch_optionals($key);
3462 $object->array_options = $newinvoice_static->array_options;
3465 $optionsav .= $newinvoice_static->ref;
3466 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
3467 $optionsav .=
'</option>';
3470 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3471 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
3472 if ((!$optionsav && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) || $invoice_predefined->id > 0) {
3473 $tmp .=
' disabled';
3477 print
'<script type="text/javascript">
3478 jQuery(document).ready(function() {
3479 if (! jQuery("#radio_creditnote").is(":checked"))
3481 jQuery("#credit_note_options").hide();
3483 jQuery("#radio_creditnote").click(function() {
3484 jQuery("#credit_note_options").show();
3486 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
3487 jQuery("#credit_note_options").hide();
3491 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
3493 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3494 if (!$optionsav || $invoice_predefined->id > 0) {
3495 $text .=
' disabled';
3499 $text .=
'<option value="-1"></option>';
3500 $text .= $optionsav;
3502 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
3504 $text .=
'</select>';
3505 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3508 print
'<div id="credit_note_options" class="clearboth">';
3509 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>";
3510 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>";
3513 print
'</div></div>';
3516 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3517 if (empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
3518 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3520 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
3522 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceAvoir").
'</label> ';
3523 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3524 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3526 print
'</div></div>'.
"\n";
3531 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3532 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
3533 $text =
'<label>'.$tmp.$langs->trans(
"RepeatableInvoice").
'</label> ';
3535 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3);
3537 print
'</div></div>';
3542 if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) {
3546 foreach ($listtType as $type) {
3547 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
3548 $curent = !empty($conf->global->{$thisTypeConfName}) ? $conf->global->{$thisTypeConfName}:$conf->global->FACTURE_ADDON_PDF;
3549 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$curent.
'"';
3552 print
'<script type="text/javascript">
3553 $(document).ready(function() {
3554 var listType = {'.$jsListType.
'};
3555 $("[name=\'type\'").change(function() {
3556 if($( this ).prop("checked"))
3558 if(($( this ).val() in listType))
3560 $("#model").val(listType[$( this ).val()]);
3564 $("#model").val("'.$conf->global->FACTURE_ADDON_PDF.
'");
3577 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
3581 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin',
'alpha').
'&originid='.
GETPOST(
'originid',
'int'));
3582 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3588 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
3591 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
3592 print
$form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'',
'',
'',
'',
"add", 1, 1);
3596 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
3597 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
3598 print
$form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax',
'',
'',
'',
"add", 1, 1);
3603 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
3604 $form->select_conditions_paiements(
GETPOSTISSET(
'cond_reglement_id') ?
GETPOST(
'cond_reglement_id',
'int') : $cond_reglement_id,
'cond_reglement_id');
3608 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
3609 $rwStyle =
'display:none;';
3610 if (in_array(
GETPOST(
'type',
'int'), $retainedWarrantyInvoiceAvailableType)) {
3614 $retained_warranty =
GETPOST(
'retained_warranty',
'int');
3615 if (empty($retained_warranty)) {
3616 if (!empty($objectsrc->retained_warranty)) {
3617 $retained_warranty = $objectsrc->retained_warranty;
3620 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT;
3622 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
3623 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
3626 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
3627 $retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
3628 if (empty($retained_warranty_fk_cond_reglement)) {
3629 $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
3630 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
3631 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
3633 $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
3636 $form->select_conditions_paiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
3639 print
'<script type="text/javascript">
3640 $(document).ready(function() {
3641 $("[name=\'type\']").change(function() {
3642 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
3644 $(".retained-warranty-line").show();
3645 $("#new-situation-invoice-retained-warranty").val("'.floatval($retained_warranty_js_default).
'");
3648 $(".retained-warranty-line").hide();
3649 $("#new-situation-invoice-retained-warranty").val("");
3653 $("[name=\'type\']:checked").trigger("change");
3659 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
3660 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
3661 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);
3666 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td colspan="2">';
3667 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
3668 print
$form->select_comptes(($fk_account < 0 ?
'' : $fk_account),
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
3674 $langs->load(
'projects');
3675 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
3676 print
img_picto(
'',
'project').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
3677 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>';
3684 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
3685 print
'<td colspan="2" class="maxwidthonsmartphone">';
3686 $incoterm_id =
GETPOST(
'incoterm_id');
3687 $incoterm_location =
GETPOST(
'location_incoterms');
3688 if (empty($incoterm_id)) {
3689 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
3690 $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
3692 print
$form->select_incoterms($incoterm_id, $incoterm_location);
3697 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid'=>$socid);
3698 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
3699 print $hookmanager->resPrint;
3700 if (empty($reshook)) {
3701 if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE) && !empty($soc->id)) {
3703 $tpExtrafields =
new Extrafields($db);
3704 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
3705 if ($soc->fetch_optionals() > 0) {
3706 $object->array_options = array_merge($object->array_options, $soc->array_options);
3710 print $object->showOptionals($extrafields,
'create',
$parameters);
3714 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
3715 print
'<td colspan="2">';
3716 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
3717 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
3719 if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) {
3721 $paramkey =
'FACTURE_ADDON_PDF_'.$object->type;
3722 $preselected = !empty($conf->global->$paramkey) ? $conf->global->$paramkey : $conf->global->FACTURE_ADDON_PDF;
3724 $preselected = $conf->global->FACTURE_ADDON_PDF;
3726 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
3732 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
3733 print
'<td colspan="2" class="maxwidthonsmartphone">';
3734 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
3735 print
$form->selectMultiCurrency($currency_code,
'multicurrency_code');
3741 if (
GETPOST(
'fac_rec',
'int') > 0) {
3742 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
3743 if (empty($dateexample)) {
3746 $substitutionarray = array(
3747 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
3748 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
3749 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
3750 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
3751 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
3752 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
3753 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
3754 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
3755 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
3756 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
3757 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
3760 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
3761 foreach ($substitutionarray as $key => $val) {
3762 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
3764 $htmltext .=
'</i>';
3769 print
'<td class="tdtop">';
3770 print
$form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
3772 print
'<td valign="top" colspan="2">';
3773 $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%');
3774 print $doleditor->Create(1);
3777 if (empty($user->socid)) {
3779 print
'<td class="tdtop">';
3780 print
$form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
3782 print
'<td valign="top" colspan="2">';
3783 $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%');
3784 print $doleditor->Create(1);
3790 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
3791 $langs->loadLangs(array(
'orders',
'propal'));
3794 if ($origin ==
'contrat') {
3796 $objectsrc->remise_absolue = $remise_absolue;
3797 $objectsrc->remise_percent = $remise_percent;
3798 $objectsrc->update_price(1, - 1, 1);
3801 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
3802 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
3803 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
3804 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
3809 switch (get_class($objectsrc)) {
3811 $newclassname =
'CommercialProposal';
3814 $newclassname =
'Order';
3817 $newclassname =
'Sending';
3820 $newclassname =
'Contract';
3823 $newclassname =
'Intervention';
3826 $newclassname = get_class($objectsrc);
3830 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
3831 print
'<td colspan="2">';
3832 print $objectsrc->getNomUrl(1);
3834 $objectsrc->fetchObjectLinked($originid, $origin,
'',
'facture');
3835 if (is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
3837 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
3840 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht).
'</td></tr>';
3841 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva).
"</td></tr>";
3842 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
3843 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax1).
"</td></tr>";
3846 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
3847 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax2).
"</td></tr>";
3849 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc).
"</td></tr>";
3852 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
3853 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
3854 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
3862 print
$form->buttonsSaveCancel(
"CreateDraft");
3865 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
3868 $title = $langs->trans(
'ProductsAndServices');
3871 print
'<div class="div-table-responsive-no-min">';
3872 print
'<table class="noborder centpercent">';
3874 $objectsrc->printOriginLinesList(
'', $selectedLines);
3881 } elseif ($id > 0 || !empty($ref)) {
3882 if (empty($object->id)) {
3883 $langs->load(
'errors');
3884 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
3893 $result = $object->fetch($id, $ref);
3900 $extrafields->fetch_name_optionals_label($object->table_element);
3902 if ($user->socid > 0 && $user->socid != $object->socid) {
3906 $result = $object->fetch_thirdparty();
3908 $result = $soc->fetch($object->socid);
3912 $selleruserevenustamp = $mysoc->useRevenueStamp();
3914 $totalpaid = $object->getSommePaiement();
3915 $totalcreditnotes = $object->getSumCreditNotesUsed();
3916 $totaldeposits = $object->getSumDepositsUsed();
3924 $resteapayer =
price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
3928 $multicurrency_totalpaid = $object->getSommePaiement(1);
3929 $multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
3930 $multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
3931 $multicurrency_resteapayer =
price2num($object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
3935 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 && $object->multicurrency_code != $conf->currency) {
3936 $resteapayer =
price2num($multicurrency_resteapayer / $object->multicurrency_tx,
'MT');
3940 if ($object->paye) {
3943 $resteapayeraffiche = $resteapayer;
3945 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
3946 $filterabsolutediscount =
"fk_facture_source IS NULL";
3947 $filtercreditnote =
"fk_facture_source IS NOT NULL";
3949 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
3950 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
3953 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
3954 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
3955 $absolute_discount =
price2num($absolute_discount,
'MT');
3956 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
3958 $author =
new User($db);
3959 if ($object->user_author) {
3960 $author->fetch($object->user_author);
3963 $objectidnext = $object->getIdReplacingInvoice();
3967 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
'bill');
3972 if ($action ==
'converttoreduc') {
3974 $type_fac =
'ExcessReceived';
3976 $type_fac =
'CreditNote';
3978 $type_fac =
'Deposit';
3980 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
3981 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
3982 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
3986 if ($action ==
'delete') {
3987 $text = $langs->trans(
'ConfirmDeleteBill', $object->ref);
3988 $formquestion = array();
3990 if ($object->type !=
Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->statut >= 1) {
3991 $qualified_for_stock_change = 0;
3992 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
3993 $qualified_for_stock_change = $object->hasProductsOrServices(2);
3995 $qualified_for_stock_change = $object->hasProductsOrServices(1);
3998 if ($qualified_for_stock_change) {
3999 $langs->load(
"stocks");
4000 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4002 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
4004 if ($conf->browser->name ==
'ie') {
4007 $formquestion = array(
4011 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4013 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4015 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4018 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4023 if ($action ==
'situationout') {
4024 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle', $object->ref);
4025 $label = $langs->trans(
"ConfirmOuting");
4026 $formquestion = array();
4031 && $object->is_last_in_cycle()
4032 && $usercanunvalidate
4034 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4039 if ($action ==
'valid') {
4041 $objectref = substr($object->ref, 1, 4);
4042 if ($objectref ==
'PROV') {
4043 $savdate = $object->date;
4044 if (!empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
4046 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
4048 $numref = $object->getNextNumRef($soc);
4051 $numref = $object->ref;
4054 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4055 if (!empty($conf->notification->enabled)) {
4056 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4057 $notify =
new Notify($db);
4059 $text .= $notify->confirmMessage(
'BILL_VALIDATE', $object->socid, $object);
4061 $formquestion = array();
4064 $qualified_for_stock_change = 0;
4065 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
4066 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4068 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4071 if ($qualified_for_stock_change) {
4072 $langs->load(
"stocks");
4073 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4074 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4077 $warehouse_array = $warehouse->list_array();
4078 if (count($warehouse_array) == 1) {
4079 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4080 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4082 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockIncrease") : $langs->trans(
"SelectWarehouseForStockDecrease");
4083 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4085 $formquestion = array(
4091 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4095 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
4100 foreach ($object->lines as $line) {
4101 $res = $line->fetch_product();
4103 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
4109 if ($nbMandated > 0 ) $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
4112 $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);
4116 if ($action ==
'modif') {
4117 $text = $langs->trans(
'ConfirmUnvalidateBill', $object->ref);
4118 $formquestion = array();
4121 $qualified_for_stock_change = 0;
4122 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
4123 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4125 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4128 if ($qualified_for_stock_change) {
4129 $langs->load(
"stocks");
4130 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4131 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4134 $warehouse_array = $warehouse->list_array();
4135 if (count($warehouse_array) == 1) {
4136 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
4137 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4139 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
4140 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4142 $formquestion = array(
4148 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4152 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
4156 if ($action ==
'paid' && ($resteapayer <= 0 || (!empty($conf->global->INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) && $resteapayer == $object->total_ttc))) {
4157 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill', $object->ref),
'confirm_paid',
'',
"yes", 1);
4159 if ($action ==
'paid' && $resteapayer > 0 && (empty($conf->global->INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $resteapayer != $object->total_ttc)) {
4163 $close[$i][
'code'] =
'discount_vat';
4165 $close[$i][
'code'] =
'badcustomer';
4167 $close[$i][
'code'] =
'bankcharge';
4169 $close[$i][
'code'] =
'other';
4173 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
4175 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4177 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
4179 $close[$i][
'label'] = $langs->trans(
"Other");
4183 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4185 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4187 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4189 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
4192 foreach ($close as $key => $val) {
4193 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
4197 $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'));
4199 $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);
4203 if ($action ==
'canceled') {
4206 if ($objectidnext) {
4207 $facturereplacement =
new Facture($db);
4208 $facturereplacement->fetch($objectidnext);
4209 $statusreplacement = $facturereplacement->statut;
4211 if ($objectidnext && $statusreplacement == 0) {
4212 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
4215 $close[1][
'code'] =
'badcustomer';
4216 $close[2][
'code'] =
'abandon';
4218 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4219 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
4221 $close[1][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $object->ref), $close[1][
'label'], 1);
4222 $close[2][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
4224 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
4225 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
4228 $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'));
4230 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill', $object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 270);
4234 if ($action ==
'deletepayment') {
4235 $payment_id =
GETPOST(
'paiement_id');
4236 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
4240 if ($action ==
'ask_deleteline') {
4241 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
4245 if ($action ==
'clone') {
4247 $formquestion = array(
4248 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)),
4249 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
4252 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
4255 if ($action ==
"remove_file_comfirm") {
4256 $file =
GETPOST(
'file',
'alpha');
4259 $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&file='.$file,
4260 $langs->trans(
'DeleteFileHeader'),
4261 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
4271 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
4272 if (empty($reshook)) {
4274 } elseif ($reshook > 0) {
4283 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
4285 $morehtmlref =
'<div class="refidno">';
4287 if ($object->status == $object::STATUS_DRAFT && !$mysoc->isInEEC() && !empty($conf->global->INVOICE_ALLOW_FREE_REF)) {
4288 $morehtmlref .=
$form->editfieldkey(
"Ref",
'ref', $object->ref, $object, $usercancreate,
'string',
'', 0, 1);
4289 $morehtmlref .=
$form->editfieldval(
"Ref",
'ref', $object->ref, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
4290 $morehtmlref .=
'<br>';
4293 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
4294 $morehtmlref .=
$form->editfieldval(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
4296 $morehtmlref .=
'<br>'.$langs->trans(
'ThirdParty').
' : '.$object->thirdparty->getNomUrl(1,
'customer');
4297 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
4298 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
4302 $langs->load(
"projects");
4303 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
4304 if ($usercancreate) {
4305 if ($action !=
'classify') {
4306 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
4308 if ($action ==
'classify') {
4310 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
4311 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
4312 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
4313 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
4314 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4315 $morehtmlref .=
'</form>';
4317 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
4320 if (!empty($object->fk_project)) {
4322 $proj->fetch($object->fk_project);
4323 $morehtmlref .=
' : '.$proj->getNomUrl(1);
4325 $morehtmlref .=
' - '.$proj->title;
4332 $morehtmlref .=
'</div>';
4334 $object->totalpaid = $totalpaid;
4336 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
4338 print
'<div class="fichecenter">';
4339 print
'<div class="fichehalfleft">';
4340 print
'<div class="underbanner clearboth"></div>';
4342 print
'<table class="border centpercent tableforfield">';
4345 print
'<tr><td class="titlefield fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
4346 print
'<span class="badgeneutral">';
4347 print $object->getLibType();
4349 if ($object->module_source) {
4350 print
' <span class="opacitymediumbycolor paddingleft">('.$langs->trans(
"POS").
' '.ucfirst($object->module_source).
' - '.$langs->trans(
"Terminal").
' '.$object->pos_source.
')</span>';
4353 $facreplaced =
new Facture($db);
4354 $facreplaced->fetch($object->fk_facture_source);
4355 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
4359 $facusing->fetch($object->fk_facture_source);
4360 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
4363 $facidavoir = $object->getListIdAvoirFromInvoice();
4364 if (count($facidavoir) > 0) {
4365 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
4367 foreach ($facidavoir as $id) {
4374 $facavoir->fetch($id);
4375 print $facavoir->getNomUrl(1);
4379 if ($objectidnext > 0) {
4380 $facthatreplace =
new Facture($db);
4381 $facthatreplace->fetch($objectidnext);
4382 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
4387 $result = $discount->fetch(0, $object->id);
4389 print
' <span class="opacitymediumbycolor paddingleft">';
4390 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
4391 $s = str_replace(
'{s1}', $object->getLibType(1), $s);
4392 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
4394 print
'</span><br>';
4398 if ($object->fk_fac_rec_source > 0) {
4400 $result = $tmptemplate->fetch($object->fk_fac_rec_source);
4402 print
' <span class="opacitymediumbycolor paddingleft">';
4403 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
4404 $s = str_replace(
'{s1}',
'<a href="'.DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->ref).
'</a>', $s);
4412 print
'<!-- Discounts -->'.
"\n";
4413 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
4417 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?facid='.$object->id);
4418 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
4423 print
'<table class="nobordernopadding centpercent"><tr><td>';
4424 print $langs->trans(
'DateInvoice');
4426 if ($action !=
'editinvoicedate' && !empty($object->brouillon) && $usercancreate && empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
4427 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>';
4429 print
'</tr></table>';
4432 if ($action ==
'editinvoicedate') {
4433 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date,
'invoicedate');
4435 print
'<span class="valuedate">'.dol_print_date($object->date,
'day').
'</span>';
4441 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
4444 print
'<table class="nobordernopadding centpercent"><tr><td>';
4445 print $langs->trans(
'DatePointOfTax');
4447 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>';
4448 print
'</tr></table>';
4450 if ($action ==
'editdate_pointoftax') {
4451 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date_pointoftax,
'date_pointoftax');
4453 print
'<span class="valuedate">'.dol_print_date($object->date_pointoftax,
'day').
'</span>';
4460 print
'<table class="nobordernopadding centpercent"><tr><td>';
4461 print $langs->trans(
'PaymentConditionsShort');
4464 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>';
4466 print
'</tr></table>';
4469 if ($action ==
'editconditions') {
4470 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
4472 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'none');
4481 print
'<table class="nobordernopadding centpercent"><tr><td>';
4482 print $langs->trans(
'DateMaxPayment');
4485 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>';
4487 print
'</tr></table>';
4490 if ($action ==
'editpaymentterm') {
4491 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date_lim_reglement,
'paymentterm');
4493 print
'<span class="valuedate">'.dol_print_date($object->date_lim_reglement,
'day').
'</span>';
4494 if ($object->hasDelay()) {
4505 print
'<table class="nobordernopadding centpercent"><tr><td>';
4506 print $langs->trans(
'PaymentMode');
4508 if ($action !=
'editmode' && $usercancreate) {
4509 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>';
4511 print
'</tr></table>';
4513 if ($action ==
'editmode') {
4514 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
4516 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'none',
'CRDT');
4525 print
'<table class="nobordernopadding centpercent"><tr><td>';
4526 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
4528 if ($usercancreate && $action !=
'editmulticurrencycode' && !empty($object->brouillon)) {
4529 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>';
4531 print
'</tr></table>';
4533 $htmlname = (($usercancreate && $action ==
'editmulticurrencycode') ?
'multicurrency_code' :
'none');
4534 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code, $htmlname);
4538 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
4541 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4542 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
4544 if ($usercancreate && $action !=
'editmulticurrencyrate' && !empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
4545 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>';
4547 print
'</tr></table>';
4549 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
4550 if ($action ==
'actualizemulticurrencyrate') {
4553 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx, ($usercancreate ?
'multicurrency_tx' :
'none'), $object->multicurrency_code);
4555 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
4556 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
4557 print
'<div class="inline-block"> ';
4558 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
4568 print
'<tr><td class="nowrap">';
4569 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
4570 print $langs->trans(
'BankAccount');
4572 if (($action !=
'editbankaccount') && $usercancreate) {
4573 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>';
4575 print
'</tr></table>';
4577 if ($action ==
'editbankaccount') {
4578 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
4580 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
4589 print
'<table class="nobordernopadding centpercent"><tr><td>';
4590 print $langs->trans(
'IncotermLabel');
4591 print
'<td><td class="right">';
4592 if ($usercancreate) {
4593 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
4597 print
'</td></tr></table>';
4600 if ($action !=
'editincoterm') {
4601 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
4603 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
4610 if (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
4611 $displayWarranty =
true;
4612 if (!in_array($object->type, $retainedWarrantyInvoiceAvailableType) && empty($object->retained_warranty)) {
4613 $displayWarranty =
false;
4616 if ($displayWarranty) {
4618 print
'<tr class="retained-warranty-lines" ><td>';
4619 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
4620 print $langs->trans(
'RetainedWarranty');
4622 if ($action !=
'editretainedwarranty' && $user->rights->facture->creer && $object->statut ==
Facture::STATUS_DRAFT) {
4623 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>';
4626 print
'</tr></table>';
4629 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4630 print
'<input type="hidden" name="action" value="setretainedwarranty">';
4631 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4632 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
4633 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4636 print
price($object->retained_warranty).
'%';
4641 print
'<tr class="retained-warranty-lines" ><td>';
4642 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
4643 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
4645 if ($action !=
'editretainedwarrantypaymentterms' && $user->rights->facture->creer && $object->statut ==
Facture::STATUS_DRAFT) {
4646 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>';
4649 print
'</tr></table>';
4651 $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime(
'-1 years', $object->date_lim_reglement);
4652 if ($object->date > $defaultDate) {
4653 $defaultDate = $object->date;
4658 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4659 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
4660 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4661 $retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
4662 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $object->retained_warranty_fk_cond_reglement;
4663 $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;
4664 $form->select_conditions_paiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4665 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4668 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->retained_warranty_fk_cond_reglement,
'none');
4669 if (!$displayWarranty) {
4670 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning.png',
'class="pictowarning valignmiddle" ');
4676 print
'<tr class="retained-warranty-lines" ><td>';
4677 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
4678 print $langs->trans(
'RetainedWarrantyDateLimit');
4680 if ($action !=
'editretainedwarrantydatelimit' && $user->rights->facture->creer && $object->statut ==
Facture::STATUS_DRAFT) {
4681 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>';
4684 print
'</tr></table>';
4686 $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime(
'-1 years', $object->date_lim_reglement);
4687 if ($object->date > $defaultDate) {
4688 $defaultDate = $object->date;
4693 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4694 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
4695 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4696 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').
'" >';
4697 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4700 print
dol_print_date($object->retained_warranty_date_limit,
'day');
4709 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
4714 print
'<div class="fichehalfright">';
4716 print
'<!-- amounts -->'.
"\n";
4717 print
'<div class="underbanner clearboth"></div>'.
"\n";
4718 print
'<table class="border tableforfield centpercent">';
4721 if (!empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE_SCREEN) && $object->type == $object::TYPE_CREDIT_NOTE) {
4725 if (
isModEnabled(
'multicurrency') && ($object->multicurrency_code != $conf->currency)) {
4727 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
4728 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>';
4732 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
4733 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>';
4737 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
4738 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>';
4743 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
'AmountHT').
'</td>';
4744 print
'<td class="nowrap right amountcard">'.price($sign * $object->total_ht, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4747 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>';
4751 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) {
4752 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
4753 print
'<td class="nowrap right amountcard">'.price($sign * $object->total_localtax1, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4755 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) {
4756 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
4757 print
'<td class="nowrap right amountcard">'.price($sign * $object->total_localtax2, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4761 if ($selleruserevenustamp) {
4763 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4764 print $langs->trans(
'RevenueStamp');
4766 if ($action !=
'editrevenuestamp' && !empty($object->brouillon) && $usercancreate) {
4767 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>';
4769 print
'</tr></table>';
4771 if ($action ==
'editrevenuestamp') {
4772 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
4773 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4774 print
'<input type="hidden" name="action" value="setrevenuestamp">';
4775 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num($object->revenuestamp).
'">';
4776 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
4777 print
' → <span id="revenuestamp_span"></span>';
4778 print
' <input type="submit" class="button buttongen button-save" value="'.$langs->trans(
'Modify').
'">';
4781 $(document).ready(function(){
4782 js_recalculate_revenuestamp();
4783 $('select[name=revenuestamp_type]').on('change',function(){
4784 js_recalculate_revenuestamp();
4787 function js_recalculate_revenuestamp(){
4788 var valselected = $('select[name=revenuestamp_type]').val();
4789 console.log('Calculate revenue stamp from '+valselected);
4791 if (valselected.indexOf('%') == -1)
4793 revenue = valselected;
4797 var revenue_type = parseFloat(valselected);
4798 var amount_net = ".round($object->total_ht, 2).
";
4799 revenue = revenue_type * amount_net / 100;
4800 revenue = revenue.toFixed(2);
4802 $('#revenuestamp_val').val(revenue);
4803 $('#revenuestamp_span').html(revenue);
4807 print
price($object->revenuestamp, 1,
'', 1, - 1, - 1, $conf->currency);
4813 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>';
4827 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
4830 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
4833 if ($selleruserevenustamp) {
4844 if (($object->situation_cycle_ref > 0) && !empty($conf->global->INVOICE_USE_SITUATION)) {
4845 print
'<!-- List of situation invoices -->';
4846 print
'<table class="noborder situationstable" width="100%">';
4848 print
'<tr class="liste_titre">';
4849 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
4851 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
4853 print
'<td class="right"></td>';
4855 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
4856 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
4857 print
'<td width="18"> </td>';
4860 $total_prev_ht = $total_prev_ttc = 0;
4861 $total_global_ht = $total_global_ttc = 0;
4863 if (count($object->tab_previous_situation_invoice) > 0) {
4866 $current_situation_counter = array();
4867 foreach ($object->tab_previous_situation_invoice as $prev_invoice) {
4868 $tmptotalpaidforthisinvoice = $prev_invoice->getSommePaiement();
4869 $total_prev_ht += $prev_invoice->total_ht;
4870 $total_prev_ttc += $prev_invoice->total_ttc;
4871 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ?-1 : 1) * $prev_invoice->situation_counter;
4872 print
'<tr class="oddeven">';
4873 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
4875 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
4877 print
'<td class="right"></td>';
4879 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
4880 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
4881 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).
'</td>';
4887 $total_global_ht += $total_prev_ht;
4888 $total_global_ttc += $total_prev_ttc;
4889 $total_global_ht += $object->total_ht;
4890 $total_global_ttc += $object->total_ttc;
4892 print
'<tr class="oddeven">';
4893 print
'<td>'.$object->getNomUrl(1).
'</td>';
4895 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$object->situation_counter.
'</td>';
4897 print
'<td class="right"></td>';
4899 print
'<td class="right"><span class="amount">'.price($object->total_ht).
'</span></td>';
4900 print
'<td class="right"><span class="amount">'.price($object->total_ttc).
'</span></td>';
4901 print
'<td class="right">'.$object->getLibStatut(3, $object->getSommePaiement()).
'</td>';
4905 print
'<tr class="oddeven">';
4906 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'CurrentSituationTotal').
'</b></td>';
4909 foreach ($current_situation_counter as $sit) {
4910 $curSign = $sit > 0 ?
'+' :
'-';
4911 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
4913 print
' '.$curSign.
' ';
4915 print $curType.abs($sit);
4922 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
4923 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
4924 print
'<td width="18"> </td>';
4928 if (count($object->tab_next_situation_invoice) > 0) {
4940 $total_next_ht = $total_next_ttc = 0;
4942 foreach ($object->tab_next_situation_invoice as $next_invoice) {
4943 $totalpaid = $next_invoice->getSommePaiement();
4944 $total_next_ht += $next_invoice->total_ht;
4945 $total_next_ttc += $next_invoice->total_ttc;
4947 print
'<tr class="oddeven">';
4948 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
4950 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
4952 print
'<td class="right"></td>';
4954 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
4955 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
4956 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid).
'</td>';
4960 $total_global_ht += $total_next_ht;
4961 $total_global_ttc += $total_next_ttc;
4963 print
'<tr class="oddeven">';
4964 print
'<td colspan="3" class="right"></td>';
4966 print
'<td class="right"></td>';
4968 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
4969 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
4970 print
'<td width="18"> </td>';
4978 if ($object->type == $object::TYPE_CREDIT_NOTE) {
4984 print
'<!-- List of payments already done -->';
4985 print
'<div class="div-table-responsive-no-min">';
4986 print
'<table class="noborder paymenttable centpercent">';
4988 print
'<tr class="liste_titre">';
4989 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
4990 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
4991 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
4993 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
4995 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
4996 print
'<td class="liste_titre" width="18"> </td>';
5000 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
5001 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
5002 $sql .=
' pf.amount,';
5003 $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';
5004 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
5005 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
5006 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
5007 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
5008 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id).
' AND pf.fk_paiement = p.rowid';
5009 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
5010 $sql .=
' ORDER BY p.datep, p.tms';
5012 $result = $db->query($sql);
5014 $num = $db->num_rows($result);
5019 $objp = $db->fetch_object($result);
5021 $paymentstatic->id = $objp->rowid;
5022 $paymentstatic->datepaye = $db->jdate($objp->dp);
5023 $paymentstatic->ref = $objp->ref;
5024 $paymentstatic->num_payment = $objp->num_payment;
5025 $paymentstatic->paiementcode = $objp->payment_code;
5027 print
'<tr class="oddeven"><td class="nowraponall">';
5028 print $paymentstatic->getNomUrl(1);
5031 $dateofpayment = $db->jdate($objp->dp);
5033 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
5039 $label = ($langs->trans(
"PaymentType".$objp->payment_code) != (
"PaymentType".$objp->payment_code)) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
5040 print
'<td>'.$label.
' '.$objp->num_payment.
'</td>';
5042 $bankaccountstatic->id = $objp->baid;
5043 $bankaccountstatic->ref = $objp->baref;
5044 $bankaccountstatic->label = $objp->baref;
5045 $bankaccountstatic->number = $objp->banumber;
5046 $bankaccountstatic->currency_code = $objp->bacurrency_code;
5049 $bankaccountstatic->account_number = $objp->account_number;
5052 $accountingjournal->fetch($objp->fk_accountancy_journal);
5053 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
5056 print
'<td class="nowraponall">';
5057 if ($bankaccountstatic->id) {
5058 print $bankaccountstatic->getNomUrl(1,
'transactions');
5062 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
5063 print
'<td class="center">';
5065 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
5082 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5083 print
'<span class="opacitymedium">';
5085 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
5087 print $langs->trans(
'AlreadyPaid');
5089 print
'</span></td><td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td><td> </td></tr>';
5091 $resteapayeraffiche = $resteapayer;
5092 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
5095 $creditnoteamount = 0;
5097 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
5098 $sql .=
" re.description, re.fk_facture_source";
5099 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
5100 $sql .=
" WHERE fk_facture = ".((int) $object->id);
5101 $resql = $db->query($sql);
5103 $num = $db->num_rows(
$resql);
5107 $obj = $db->fetch_object(
$resql);
5108 $invoice->fetch($obj->fk_facture_source);
5109 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5110 print
'<span class="opacitymedium">';
5112 print $langs->trans(
"CreditNote").
' ';
5115 print $langs->trans(
"Deposit").
' ';
5117 print $invoice->getNomUrl(0);
5120 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
5121 print
'<td class="right">';
5122 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">'.
img_delete().
'</a>';
5126 $creditnoteamount += $obj->amount_ttc;
5129 $depositamount += $obj->amount_ttc;
5138 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5139 print
'<span class="opacitymedium">';
5140 print
$form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
5142 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5143 $resteapayeraffiche = 0;
5144 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5148 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5149 print
'<span class="opacitymedium">';
5150 print
$form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
5152 print
'</td><td class="right">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td><td> </td></tr>';
5154 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5158 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5159 print
'<span class="opacitymedium">';
5160 print
$form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
5162 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5163 $resteapayeraffiche = 0;
5164 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5168 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5169 $text = $langs->trans(
"HelpAbandonOther");
5170 if ($object->close_note) {
5171 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.$object->close_note;
5173 print
'<span class="opacitymedium">';
5174 print
$form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
5176 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5177 $resteapayeraffiche = 0;
5178 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5182 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5183 print
'<span class="opacitymedium">';
5184 print $langs->trans(
"Billed");
5185 print
'</td><td class="right">'.price($object->total_ttc).
'</td><td> </td></tr>';
5187 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5188 print
'<span class="opacitymedium">';
5189 print $langs->trans(
'RemainderToPay');
5190 if ($resteapayeraffiche < 0) {
5191 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5195 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
5198 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
5199 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5200 print
'<span class="opacitymedium">';
5201 print $langs->trans(
'RemainderToPayMulticurrency');
5202 if ($resteapayeraffiche < 0) {
5203 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5207 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">';
5209 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>';
5213 if (!empty($object->situation_final) && !empty($object->retained_warranty) && $displayWarranty) {
5216 $retainedWarranty = $total_global_ttc * $object->retained_warranty / 100;
5219 $retainedWarranty = $object->total_ttc * $object->retained_warranty / 100;
5222 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
5224 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>';
5227 print
'<tr><td colspan="'.$nbcols.
'" align="right">';
5228 print $langs->trans(
"RetainedWarranty").
' ('.$object->retained_warranty.
'%)';
5229 print !empty($object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date($object->retained_warranty_date_limit,
'day')) :
'';
5230 print
' :</td><td align="right">'.price($retainedWarranty).
'</td><td> </td></tr>';
5233 $resteapayeraffiche = $resteapayer;
5234 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5237 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5238 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
5239 print
'</td><td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td><td> </td></tr>';
5242 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>';
5245 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5246 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
5247 if ($resteapayeraffiche > 0) {
5248 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5250 print
'</span></td>';
5251 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
5252 print
'<td class="nowrap"> </td></tr>';
5255 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
5256 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5257 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
5258 if ($resteapayeraffiche > 0) {
5259 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5263 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>';
5277 $formmargin->displayMarginInfos($object);
5283 print
'<div class="clearboth"></div><br><br>';
5285 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
5286 $blocname =
'contacts';
5287 $title = $langs->trans(
'ContactsAddresses');
5288 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5291 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
5292 $blocname =
'notes';
5293 $title = $langs->trans(
'Notes');
5294 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5298 $result = $object->getLinesArray();
5301 if (!empty($conf->global->INVOICE_USE_SITUATION)) {
5302 if ($object->situation_cycle_ref && $object->statut == 0) {
5303 print
'<!-- Area to change globally the situation percent -->'.
"\n";
5304 print
'<div class="div-table-responsive">';
5306 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'#updatealllines" method="POST">';
5307 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
5308 print
'<input type="hidden" name="action" value="updatealllines" />';
5309 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
5311 print
'<table id="tablelines_all_progress" class="noborder noshadow" width="100%">';
5313 print
'<tr class="liste_titre nodrag nodrop">';
5316 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
5317 print
'<td align="center" width="5"> </td>';
5319 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
5320 print
'<td class="right">'.$langs->trans(
'Progress').
'</td>';
5321 print
'<td> </td>';
5324 print
'<tr class="nodrag nodrop">';
5326 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
5327 print
'<td align="center" width="5"> </td>';
5329 print
'<td> </td>';
5330 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
5331 print
'<td class="right"><input type="submit" class="button" name="all_percent" value="Modifier" /></td>';
5342 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
5343 <input type="hidden" name="token" value="' .
newToken().
'">
5344 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
5345 <input type="hidden" name="mode" value="">
5346 <input type="hidden" name="page_y" value="">
5347 <input type="hidden" name="id" value="' . $object->id.
'">
5350 if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
5351 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
5354 print
'<div class="div-table-responsive-no-min">';
5355 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
5358 if (!empty($object->lines)) {
5359 $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
5363 if ($object->statut == 0 && $usercancreate && $action !=
'valid' && $action !=
'editline') {
5364 if ($action !=
'editline' && $action !=
'selectlines') {
5368 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
5369 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
5370 if (empty($reshook))
5371 $object->formAddObjectLine(1, $mysoc, $soc);