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);
125 if ($ret > 0 && isset($object->fk_project)) {
126 $ret = $object->fetch_project();
132 $hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
134 $usercanread = $user->hasRight(
"facture",
"lire");
135 $usercancreate = $user->hasRight(
"facture",
"creer");
136 $usercanissuepayment = $user->hasRight(
"facture",
"paiement");
137 $usercandelete = $user->hasRight(
"facture",
"supprimer");
138 $usercancreatecontract = $user->hasRight(
"contrat",
"creer");
139 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->validate)));
140 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->send)));
141 $usercanreopen = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->reopen)));
142 if (!empty($conf->global->INVOICE_DISALLOW_REOPEN)) {
143 $usercanreopen =
false;
145 $usercanunvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->unvalidate)));
147 $usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
148 $usercancreatemargin = (!empty($user->rights->margins->creer) ? $user->rights->margins->creer : 0);
149 $usercanreadallmargin = (!empty($user->rights->margins->liretous) ? $user->rights->margins->liretous : 0);
150 $usercancreatewithdrarequest = (!empty($user->rights->prelevement->bons->creer) ? $user->rights->prelevement->bons->creer : 0);
152 $permissionnote = $usercancreate;
153 $permissiondellink = $usercancreate;
154 $permissiontoedit = $usercancreate;
155 $permissiontoadd = $usercancreate;
158 $retainedWarrantyInvoiceAvailableType = array();
159 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
160 $retainedWarrantyInvoiceAvailableType = explode(
'+', $conf->global->INVOICE_USE_RETAINED_WARRANTY);
165 $socid = $user->socid;
169 $result =
restrictedArea($user,
'facture', $object->id,
'',
'',
'fk_soc',
'rowid', $isdraft);
177 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
182 if (empty($reshook)) {
183 $backurlforlist = DOL_URL_ROOT.
'/compta/facture/list.php';
185 if (empty($backtopage) || ($cancel && empty($id))) {
186 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
187 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
188 $backtopage = $backurlforlist;
190 $backtopage = DOL_URL_ROOT.
'/compta/facture/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
196 if (!empty($backtopageforcancel)) {
197 header(
"Location: ".$backtopageforcancel);
199 } elseif (!empty($backtopage)) {
200 header(
"Location: ".$backtopage);
206 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
208 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
210 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
213 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
217 $objectutil->socid = $socid;
218 $result = $objectutil->createFromClone($user, $id);
220 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?facid='.$result);
223 $langs->load(
"errors");
227 } elseif ($action ==
'reopen' && $usercanreopen) {
228 $result = $object->fetch($id);
231 $result = $object->setUnpaid($user);
233 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
239 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
241 $result = $object->fetch($id);
242 $object->fetch_thirdparty();
244 $idwarehouse =
GETPOST(
'idwarehouse');
246 $qualified_for_stock_change = 0;
247 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
248 $qualified_for_stock_change = $object->hasProductsOrServices(2);
250 $qualified_for_stock_change = $object->hasProductsOrServices(1);
253 $isErasable = $object->is_erasable();
255 if (($usercandelete && $isErasable > 0)
256 || ($usercancreate && $isErasable == 1)) {
257 $result = $object->delete($user, 0, $idwarehouse);
259 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
266 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
269 $object->fetch_thirdparty();
271 $result = $object->deleteline(
GETPOST(
'lineid',
'int'));
274 $object->line_order(
true);
276 $outputlangs = $langs;
278 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id')) {
281 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
282 $newlang = $object->thirdparty->default_lang;
284 if (!empty($newlang)) {
286 $outputlangs->setDefaultLang($newlang);
287 $outputlangs->load(
'products');
289 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
290 $ret = $object->fetch($id);
291 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
294 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
301 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
304 $result = $discount->fetch(
GETPOST(
"discountid"));
305 $discount->unlink_invoice();
306 } elseif ($action ==
'valid' && $usercancreate) {
310 if (!empty($conf->global-> INVOICE_CHECK_POSTERIOR_DATE)) {
311 $last_of_type = $object->willBeLastOfSameType(
true);
312 if (empty($object->date_validation) && !$last_of_type[0]) {
321 if ($object->total_ht >= 0) {
322 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
330 if (empty($conf->global->FACTURE_ENABLE_NEGATIVE) && $object->total_ttc < 0) {
331 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
340 $array_of_total_ht_per_vat_rate = array();
341 $array_of_total_ht_devise_per_vat_rate = array();
342 foreach ($object->lines as $line) {
344 $vat_src_code_for_line =
'';
345 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
346 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
348 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
349 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
351 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
352 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
356 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
357 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
358 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
360 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
361 if ($object->type == $object::TYPE_DEPOSIT) {
362 $langs->load(
"errors");
364 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
368 $tmpvatratetoshow = explode(
'_', $vatrate);
369 $tmpvatratetoshow[0] = round($tmpvatratetoshow[0], 2);
371 if ($tmpvatratetoshow[0] != 0) {
372 $langs->load(
"errors");
373 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", $tmpvatratetoshow[0]),
null,
'errors');
381 } elseif ($action ==
'classin' && $usercancreate) {
383 $object->setProject(
GETPOST(
'projectid',
'int'));
384 } elseif ($action ==
'setmode' && $usercancreate) {
386 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
390 } elseif ($action ==
'setretainedwarrantyconditions' && $user->rights->facture->creer) {
392 $object->retained_warranty_fk_cond_reglement = 0;
393 $result = $object->setRetainedWarrantyPaymentTerms(
GETPOST(
'retained_warranty_fk_cond_reglement',
'int'));
398 $old_rw_date_lim_reglement = $object->retained_warranty_date_limit;
399 $new_rw_date_lim_reglement = $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement);
400 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
401 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
403 if ($object->retained_warranty_date_limit < $object->date) {
404 $object->retained_warranty_date_limit = $object->date;
406 $result = $object->update($user);
410 } elseif ($action ==
'setretainedwarranty' && $user->rights->facture->creer) {
412 $result = $object->setRetainedWarranty(
GETPOST(
'retained_warranty',
'float'));
416 } elseif ($action ==
'setretainedwarrantydatelimit' && $user->rights->facture->creer) {
418 $result = $object->setRetainedWarrantyDateLimit(
GETPOST(
'retained_warranty_date_limit',
'float'));
422 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
423 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
424 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
425 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
426 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
428 $old_date_lim_reglement = $object->date_lim_reglement;
430 if (empty($newdate)) {
431 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
432 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id.
'&action=editinvoicedate&token='.
newToken());
435 if ($newdate > (
dol_now(
'tzuserrel') + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
436 if (empty($conf->global->INVOICE_MAX_FUTURE_DELAY)) {
437 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
439 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
443 $object->date = $newdate;
444 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
445 if ($new_date_lim_reglement > $old_date_lim_reglement) {
446 $object->date_lim_reglement = $new_date_lim_reglement;
448 if ($object->date_lim_reglement < $object->date) {
449 $object->date_lim_reglement = $object->date;
451 $result = $object->update($user);
455 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
458 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
460 $object->date_pointoftax = $date_pointoftax;
461 $result = $object->update($user);
465 } elseif ($action ==
'setconditions' && $usercancreate) {
467 $object->cond_reglement_code = 0;
468 $object->cond_reglement_id = 0;
475 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
483 $old_date_lim_reglement = $object->date_lim_reglement;
484 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
485 if ($new_date_lim_reglement > $old_date_lim_reglement) {
486 $object->date_lim_reglement = $new_date_lim_reglement;
488 if ($object->date_lim_reglement < $object->date) {
489 $object->date_lim_reglement = $object->date;
491 $result = $object->update($user);
503 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
505 $object->date_lim_reglement =
dol_mktime(12, 0, 0,
GETPOST(
'paymenttermmonth',
'int'),
GETPOST(
'paymenttermday',
'int'),
GETPOST(
'paymenttermyear',
'int'));
506 if ($object->date_lim_reglement < $object->date) {
507 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
508 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
510 $result = $object->update($user);
514 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
516 $object->revenuestamp =
GETPOST(
'revenuestamp');
517 $result = $object->update($user);
518 $object->update_price(1);
523 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
524 $outputlangs = $langs;
526 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
527 $newlang =
GETPOST(
'lang_id',
'aZ09');
529 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
530 $newlang = $object->thirdparty->default_lang;
532 if (!empty($newlang)) {
534 $outputlangs->setDefaultLang($newlang);
535 $outputlangs->load(
'products');
537 $model = $object->model_pdf;
538 $ret = $object->fetch($id);
540 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
546 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm')) {
547 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
548 } elseif ($action ==
'setbankaccount' && $usercancreate) {
549 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
550 } elseif ($action ==
'setremisepercent' && $usercancreate) {
552 $result = $object->setDiscount($user,
price2num(
GETPOST(
'remise_percent'),
'', 2));
553 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
558 if (
GETPOST(
"remise_id",
'int') > 0) {
559 $ret = $object->fetch($id);
561 $result = $object->insert_discount(
GETPOST(
"remise_id",
'int'));
571 if (
GETPOST(
"remise_id_for_payment",
'int') > 0) {
572 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
574 $discount->fetch(
GETPOST(
"remise_id_for_payment",
'int'));
578 $remaintopay = $object->getRemainToPay(0);
582 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
586 $result = $discount->link_to_invoice(0, $id);
594 $newremaintopay = $object->getRemainToPay(0);
595 if ($newremaintopay == 0) {
596 $object->setPaid($user);
607 if (empty($error) && empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
608 $outputlangs = $langs;
610 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
611 $newlang =
GETPOST(
'lang_id',
'aZ09');
613 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
614 $newlang = $object->thirdparty->default_lang;
616 if (!empty($newlang)) {
618 $outputlangs->setDefaultLang($newlang);
620 $ret = $object->fetch($id);
622 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
627 } elseif ($action ==
'setref' && $usercancreate) {
629 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'',
null,
'',
'', $user,
'BILL_MODIFY');
630 } elseif ($action ==
'setref_client' && $usercancreate) {
632 $object->set_ref_client(
GETPOST(
'ref_client'));
633 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
635 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
638 $object->fetch_thirdparty();
642 $qualified_for_stock_change = 0;
643 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
644 $qualified_for_stock_change = $object->hasProductsOrServices(2);
646 $qualified_for_stock_change = $object->hasProductsOrServices(1);
649 if ($qualified_for_stock_change) {
650 if (!$idwarehouse || $idwarehouse == - 1) {
652 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
659 $result = $object->validate($user,
'', $idwarehouse);
662 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
663 $outputlangs = $langs;
665 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
666 $newlang =
GETPOST(
'lang_id',
'aZ09');
668 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) {
669 $newlang = $object->thirdparty->default_lang;
671 if (!empty($newlang)) {
673 $outputlangs->setDefaultLang($newlang);
674 $outputlangs->load(
'products');
676 $model = $object->model_pdf;
678 $ret = $object->fetch($id);
680 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
686 if (count($object->errors)) {
693 } elseif ($action ==
'confirm_modif' && $usercanunvalidate) {
695 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
698 $object->fetch_thirdparty();
702 $qualified_for_stock_change = 0;
703 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
704 $qualified_for_stock_change = $object->hasProductsOrServices(2);
706 $qualified_for_stock_change = $object->hasProductsOrServices(1);
709 if ($qualified_for_stock_change) {
710 if (!$idwarehouse || $idwarehouse == - 1) {
712 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
720 $sql =
'SELECT pf.amount';
721 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf';
722 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id);
724 $result = $db->query($sql);
727 $num = $db->num_rows($result);
730 $objp = $db->fetch_object($result);
731 $totalpaid += $objp->amount;
738 $resteapayer = $object->total_ttc - $totalpaid;
741 $ventilExportCompta = $object->getVentilExportCompta();
744 if ($ventilExportCompta == 0) {
745 if (!empty($conf->global->INVOICE_CAN_BE_EDITED_EVEN_IF_PAYMENT_DONE) || ($resteapayer == $object->total_ttc && empty($object->paye))) {
746 $result = $object->setDraft($user, $idwarehouse);
752 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
753 $outputlangs = $langs;
755 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
756 $newlang =
GETPOST(
'lang_id',
'aZ09');
758 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
759 $newlang = $object->thirdparty->default_lang;
761 if (!empty($newlang)) {
763 $outputlangs->setDefaultLang($newlang);
764 $outputlangs->load(
'products');
766 $model = $object->model_pdf;
767 $ret = $object->fetch($id);
769 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
774 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
777 $result = $object->setPaid($user);
781 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
784 $close_code =
GETPOST(
"close_code",
'restricthtml');
785 $close_note =
GETPOST(
"close_note",
'restricthtml');
787 $result = $object->setPaid($user, $close_code, $close_note);
792 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
794 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes') {
797 $close_code =
GETPOST(
"close_code",
'restricthtml');
798 $close_note =
GETPOST(
"close_note",
'restricthtml');
800 $result = $object->setCanceled($user, $close_code, $close_note);
805 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
807 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
810 $object->fetch_thirdparty();
815 $result = $discountcheck->fetch(0, $object->id);
828 $amount_ht = $amount_tva = $amount_ttc = array();
829 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
833 foreach ($object->lines as $line) {
834 if ($line->product_type < 9 && $line->total_ht != 0) {
835 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
837 $amount_ht[$keyforvatrate] += $line->total_ht;
838 $amount_tva[$keyforvatrate] += $line->total_tva;
839 $amount_ttc[$keyforvatrate] += $line->total_ttc;
840 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
841 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
842 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
848 if (!empty($conf->global->INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) && $object->type ==
Facture::TYPE_CREDIT_NOTE) {
849 $alreadypaid = $object->getSommePaiement();
850 if ($alreadypaid && abs($alreadypaid) < abs($object->total_ttc)) {
851 $ratio = abs(($object->total_ttc - $alreadypaid) / $object->total_ttc);
852 foreach ($amount_ht as $vatrate => $val) {
853 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
854 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
855 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
856 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
857 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
858 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
867 $discount->description =
'(CREDIT_NOTE)';
869 $discount->description =
'(DEPOSIT)';
871 $discount->description =
'(EXCESS RECEIVED)';
873 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
875 $discount->fk_soc = $object->socid;
876 $discount->fk_facture_source = $object->id;
884 $sql =
'SELECT SUM(pf.amount) as total_paiements';
885 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
886 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
887 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id);
888 $sql .=
' AND pf.fk_paiement = p.rowid';
889 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
890 $resql = $db->query($sql);
895 $res = $db->fetch_object(
$resql);
896 $total_paiements = $res->total_paiements;
899 $total_creditnote_and_deposit = 0;
900 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
901 $sql .=
" re.description, re.fk_facture_source";
902 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
903 $sql .=
" WHERE fk_facture = ".((int) $object->id);
904 $resql = $db->query($sql);
906 while ($obj = $db->fetch_object(
$resql)) {
907 $total_creditnote_and_deposit += $obj->amount_ttc;
913 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object->total_ttc;
914 $discount->amount_tva = 0;
915 $discount->tva_tx = 0;
916 $discount->vat_src_code =
'';
918 $result = $discount->create($user);
924 foreach ($amount_ht as $tva_tx => $xxx) {
925 $discount->amount_ht = abs($amount_ht[$tva_tx]);
926 $discount->amount_tva = abs($amount_tva[$tva_tx]);
927 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
928 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
929 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
930 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
935 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
936 $vat_src_code = $reg[1];
937 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
940 $discount->tva_tx = abs($tva_tx);
941 $discount->vat_src_code = $vat_src_code;
943 $result = $discount->create($user);
954 $result = $object->setPaid($user);
969 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
974 $result = $paiement->fetch(
GETPOST(
'paiement_id',
'int'));
976 $result = $paiement->delete();
978 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
986 } elseif ($action ==
'add' && $usercancreate) {
989 $object->socid =
GETPOST(
'socid',
'int');
991 $selectedLines =
GETPOST(
'toselect',
'array');
993 if (
GETPOST(
'type',
'int') ===
'') {
994 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1000 $originentity =
GETPOST(
'originentity');
1002 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1008 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
1012 if (empty($dateinvoice)) {
1014 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1016 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1022 if (!(
GETPOST(
'fac_replacement',
'int') > 0)) {
1024 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1030 $result = $object->fetch(
GETPOST(
'fac_replacement',
'int'));
1031 $object->fetch_thirdparty();
1033 $object->date = $dateinvoice;
1034 $object->date_pointoftax = $date_pointoftax;
1035 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1036 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1037 $object->ref_client =
GETPOST(
'ref_client',
'alphanohtml');
1038 $object->model_pdf =
GETPOST(
'model',
'alphanohtml');
1039 $object->fk_project =
GETPOST(
'projectid',
'int');
1040 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1041 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1042 $object->fk_account =
GETPOST(
'fk_account',
'int');
1045 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1046 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1047 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1048 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1051 $object->fk_facture_source =
GETPOST(
'fac_replacement',
'int');
1054 $id = $object->createFromCurrent($user);
1063 $sourceinvoice =
GETPOST(
'fac_avoir',
'int');
1064 if (!($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
1066 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1070 if (empty($dateinvoice)) {
1072 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1074 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1081 if (!empty($originentity)) {
1082 $object->entity = $originentity;
1084 $object->socid =
GETPOST(
'socid',
'int');
1085 $object->ref =
GETPOST(
'ref');
1086 $object->date = $dateinvoice;
1087 $object->date_pointoftax = $date_pointoftax;
1088 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1089 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1090 $object->ref_client =
GETPOST(
'ref_client');
1091 $object->model_pdf =
GETPOST(
'model');
1092 $object->fk_project =
GETPOST(
'projectid',
'int');
1093 $object->cond_reglement_id = 0;
1094 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1095 $object->fk_account =
GETPOST(
'fk_account',
'int');
1098 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1099 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1100 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1101 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1104 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1107 $facture_source =
new Facture($db);
1108 if ($facture_source->fetch($object->fk_facture_source) > 0) {
1110 $object->situation_counter = $facture_source->situation_counter;
1111 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1112 $facture_source->fetchPreviousNextSituationInvoice();
1117 $id = $object->create($user);
1122 if ($object->copy_linked_contact($facture_source,
'internal') < 0) {
1124 } elseif ($facture_source->socid == $object->socid) {
1126 if ($object->copy_linked_contact($facture_source,
'external') < 0) {
1137 if (
GETPOST(
'invoiceAvoirWithLines',
'int') == 1 && $id > 0) {
1138 if (!empty($facture_source->lines)) {
1139 $fk_parent_line = 0;
1141 foreach ($facture_source->lines as $line) {
1143 if (method_exists($line,
'fetch_optionals')) {
1145 $line->fetch_optionals();
1149 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1150 $fk_parent_line = 0;
1155 $source_fk_prev_id = $line->fk_prev_id;
1156 $line->fk_prev_id = $line->id;
1158 if (!empty($facture_source->tab_previous_situation_invoice)) {
1161 $tab_jumped_credit_notes = array();
1162 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1163 $searchPreviousInvoice =
true;
1164 while ($searchPreviousInvoice) {
1165 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1166 $searchPreviousInvoice =
false;
1170 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1176 $maxPrevSituationPercent = 0;
1177 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1178 if ($prevLine->id == $source_fk_prev_id) {
1179 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1182 $line->total_ht = $line->total_ht - $prevLine->total_ht;
1183 $line->total_tva = $line->total_tva - $prevLine->total_tva;
1184 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
1185 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
1186 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
1188 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
1189 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
1190 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
1191 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
1196 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1201 $maxPrevSituationPercent = 0;
1202 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1203 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1204 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1205 $maxPrevSituationPercent = $prevLine->situation_percent;
1207 $line->total_ht -= $prevLine->total_ht;
1208 $line->total_tva -= $prevLine->total_tva;
1209 $line->total_ttc -= $prevLine->total_ttc;
1210 $line->total_localtax1 -= $prevLine->total_localtax1;
1211 $line->total_localtax2 -= $prevLine->total_localtax2;
1213 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1214 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1215 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1216 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1222 $line->situation_percent += $maxPrevSituationPercent;
1228 $line->fk_facture = $object->id;
1229 $line->fk_parent_line = $fk_parent_line;
1231 $line->subprice = -$line->subprice;
1232 $line->pa_ht = $line->pa_ht;
1233 $line->total_ht = -$line->total_ht;
1234 $line->total_tva = -$line->total_tva;
1235 $line->total_ttc = -$line->total_ttc;
1236 $line->total_localtax1 = -$line->total_localtax1;
1237 $line->total_localtax2 = -$line->total_localtax2;
1239 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1240 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1241 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1242 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1244 $line->context[
'createcreditnotefrominvoice'] = 1;
1245 $result = $line->insert(0, 1);
1247 $object->lines[] = $line;
1250 if ($result > 0 && $line->product_type == 9) {
1251 $fk_parent_line = $result;
1255 $object->update_price(1);
1259 if (
GETPOST(
'invoiceAvoirWithPaymentRestAmount',
'int') == 1 && $id > 0) {
1260 if ($facture_source->fetch($object->fk_facture_source) > 0) {
1261 $totalpaid = $facture_source->getSommePaiement();
1262 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1263 $totaldeposits = $facture_source->getSumDepositsUsed();
1264 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1266 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 1, 0, 0, 0, 0, 0,
'',
'',
'TTC');
1271 if (!empty($object->fk_facture_source) && $id > 0) {
1272 $facture_source->fetch($object->fk_facture_source);
1273 $facture_source->fetchObjectLinked();
1275 if (!empty($facture_source->linkedObjectsIds)) {
1276 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1277 $object->add_object_linked($sourcetype, current($TIds));
1286 if (empty($dateinvoice)) {
1288 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1290 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1297 $object->socid =
GETPOST(
'socid',
'int');
1298 $object->type =
GETPOST(
'type');
1299 $object->ref =
GETPOST(
'ref');
1300 $object->date = $dateinvoice;
1301 $object->date_pointoftax = $date_pointoftax;
1302 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1303 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1304 $object->ref_client =
GETPOST(
'ref_client');
1305 $object->model_pdf =
GETPOST(
'model');
1306 $object->fk_project =
GETPOST(
'projectid',
'int');
1307 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
1308 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1309 $object->fk_account =
GETPOST(
'fk_account',
'int');
1313 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1314 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1315 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1316 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1319 $object->fac_rec =
GETPOST(
'fac_rec',
'int');
1321 $id = $object->create($user);
1327 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1328 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1329 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1331 if (
GETPOST(
'socid',
'int') < 1) {
1333 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1337 if (empty($dateinvoice)) {
1339 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1341 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1349 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1350 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1355 if ($typeamount && !empty($origin) && !empty($originid)) {
1356 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1357 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1361 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1362 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1366 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1367 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1376 $object->socid =
GETPOST(
'socid',
'int');
1377 $object->type =
GETPOST(
'type');
1378 $object->ref =
GETPOST(
'ref');
1379 $object->date = $dateinvoice;
1380 $object->date_pointoftax = $date_pointoftax;
1381 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1382 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1383 $object->ref_client =
GETPOST(
'ref_client');
1384 $object->model_pdf =
GETPOST(
'model');
1385 $object->fk_project =
GETPOST(
'projectid',
'int');
1386 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
1387 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
1388 $object->fk_account =
GETPOST(
'fk_account',
'int');
1392 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1393 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1394 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1395 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1398 $object->situation_counter = 1;
1399 $object->situation_final = 0;
1400 $object->situation_cycle_ref = $object->newCycle();
1403 if (in_array($object->type, $retainedWarrantyInvoiceAvailableType)) {
1404 $object->retained_warranty =
GETPOST(
'retained_warranty',
'int');
1405 $object->retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
1407 $object->retained_warranty = 0;
1408 $object->retained_warranty_fk_cond_reglement = 0;
1411 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1412 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1413 $object->retained_warranty_date_limit =
dol_stringtotime($retained_warranty_date_limit);
1415 $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);
1417 $object->fetch_thirdparty();
1420 if (!empty($origin) && !empty($originid)) {
1423 $element = $subelement = $origin;
1424 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1425 $element = $regs[1];
1426 $subelement = $regs[2];
1430 if ($element ==
'order') {
1431 $element = $subelement =
'commande';
1433 if ($element ==
'propal') {
1434 $element =
'comm/propal';
1435 $subelement =
'propal';
1437 if ($element ==
'contract') {
1438 $element = $subelement =
'contrat';
1440 if ($element ==
'inter') {
1441 $element = $subelement =
'ficheinter';
1443 if ($element ==
'shipping') {
1444 $element = $subelement =
'expedition';
1447 $object->origin = $origin;
1448 $object->origin_id = $originid;
1451 $object->linked_objects[$object->origin] = $object->origin_id;
1453 if ($object->origin ==
'shipping') {
1454 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1456 $exp->fetch($object->origin_id);
1457 $exp->fetchObjectLinked();
1458 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1459 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1460 $object->linked_objects[
'commande'] = $value;
1465 if (is_array($_POST[
'other_linked_objects']) && !empty($_POST[
'other_linked_objects'])) {
1466 $object->linked_objects = array_merge($object->linked_objects, $_POST[
'other_linked_objects']);
1469 $id = $object->create($user);
1474 $classname = ucfirst($subelement);
1475 $srcobject =
new $classname($db);
1477 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines or deposit lines");
1478 $result = $srcobject->fetch($object->origin_id);
1483 $amountdeposit = array();
1484 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)) {
1485 if ($typeamount ==
'amount') {
1486 $amount = $valuedeposit;
1488 $amount = $srcobject->total_ttc * ($valuedeposit / 100);
1491 $TTotalByTva = array();
1492 foreach ($srcobject->lines as &$line) {
1493 if (!empty($line->special_code)) {
1496 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1499 foreach ($TTotalByTva as $tva => &$total) {
1500 $coef = $total / $srcobject->total_ttc;
1501 $am = $amount * $coef;
1502 $amount_ttc_diff += $am;
1503 $amountdeposit[$tva] += $am / (1 + $tva / 100);
1506 if ($typeamount ==
'amount') {
1507 $amountdeposit[0] = $valuedeposit;
1508 } elseif ($typeamount ==
'variable') {
1511 $lines = $srcobject->lines;
1512 $numlines = count($lines);
1513 for ($i = 0; $i < $numlines; $i++) {
1515 if (empty($lines[$i]->qty)) {
1518 if (!empty($lines[$i]->special_code)) {
1522 $totalamount += $lines[$i]->total_ht;
1523 $tva_tx = $lines[$i]->tva_tx;
1524 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $valuedeposit) / 100;
1528 if ($totalamount == 0) {
1529 $amountdeposit[0] = 0;
1537 $amount_ttc_diff = $amountdeposit[0];
1540 foreach ($amountdeposit as $tva => $amount) {
1541 if (empty($amount)) {
1546 'amount' =>
'FixAmount',
1547 'variable' =>
'VarAmount'
1549 $descline =
'(DEPOSIT)';
1551 if ($typeamount ==
'amount') {
1552 $descline .=
' ('.price($valuedeposit,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
')';
1553 } elseif ($typeamount ==
'variable') {
1554 $descline .=
' ('.$valuedeposit.
'%)';
1557 $descline .=
' - '.$srcobject->ref;
1558 $result = $object->addline(
1565 (empty($conf->global->INVOICE_PRODUCTID_DEPOSIT) ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT),
1570 $lines[$i]->info_bits,
1576 $lines[$i]->special_code,
1593 $diff = $object->total_ttc - $amount_ttc_diff;
1595 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0) {
1596 $object->fetch_lines();
1597 $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100);
1598 $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);
1605 $lines = $srcobject->lines;
1606 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1607 $srcobject->fetch_lines();
1608 $lines = $srcobject->lines;
1613 if (is_array($lines)) {
1614 foreach ($lines as $line) {
1616 $line->qty =
price2num($line->qty * $valuestandardinvoice / 100,
'MS');
1622 if (is_array($lines)) {
1623 foreach ($lines as $line) {
1625 $line->qty =
price2num($line->qty * $valuedeposit / 100,
'MS');
1630 $fk_parent_line = 0;
1631 $num = count($lines);
1633 for ($i = 0; $i < $num; $i++) {
1634 if (!in_array($lines[$i]->
id, $selectedLines)) {
1639 if ($srcobject->element ==
'shipping' && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS && $lines[$i]->qty == 0) {
1643 if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1644 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1646 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->statut, explode(
',', $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE))) {
1650 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1651 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->libelle);
1652 if ($object->situation_counter == 1) {
1653 $lines[$i]->situation_percent = 0;
1656 if ($lines[$i]->subprice < 0 && empty($conf->global->INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN)) {
1659 $discount->fk_soc = $object->socid;
1660 $discount->amount_ht = abs($lines[$i]->total_ht);
1661 $discount->amount_tva = abs($lines[$i]->total_tva);
1662 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1663 $discount->tva_tx = $lines[$i]->tva_tx;
1664 $discount->fk_user = $user->id;
1665 $discount->description = $desc;
1666 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1667 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1668 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1669 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1671 $discountid = $discount->create($user);
1672 if ($discountid > 0) {
1673 $result = $object->insert_discount($discountid);
1681 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1684 $date_start =
false;
1685 if ($lines[$i]->date_debut_prevue) {
1686 $date_start = $lines[$i]->date_debut_prevue;
1688 if ($lines[$i]->date_debut_reel) {
1689 $date_start = $lines[$i]->date_debut_reel;
1691 if ($lines[$i]->date_start) {
1692 $date_start = $lines[$i]->date_start;
1697 if ($lines[$i]->date_fin_prevue) {
1698 $date_end = $lines[$i]->date_fin_prevue;
1700 if ($lines[$i]->date_fin_reel) {
1701 $date_end = $lines[$i]->date_fin_reel;
1703 if ($lines[$i]->date_end) {
1704 $date_end = $lines[$i]->date_end;
1708 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1709 $fk_parent_line = 0;
1713 if (method_exists($lines[$i],
'fetch_optionals')) {
1714 $lines[$i]->fetch_optionals();
1715 $array_options = $lines[$i]->array_options;
1718 $tva_tx = $lines[$i]->tva_tx;
1719 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
1720 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1725 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty);
1726 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty);
1728 $result = $object->addline(
1730 $lines[$i]->subprice,
1735 $lines[$i]->fk_product,
1736 $lines[$i]->remise_percent,
1740 $lines[$i]->info_bits,
1741 $lines[$i]->fk_remise_except,
1746 $lines[$i]->special_code,
1750 $lines[$i]->fk_fournprice,
1754 $lines[$i]->situation_percent,
1755 $lines[$i]->fk_prev_id,
1756 $lines[$i]->fk_unit,
1771 if ($result > 0 && $lines[$i]->product_type == 9) {
1772 $fk_parent_line = $result;
1782 $object->update_price(1,
'auto', 0, $mysoc);
1812 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
1823 $id = $object->create($user);
1825 for ($i = 1; $i <= $NBLINES; $i++) {
1826 if (
GETPOST(
'idprod'.$i,
'int')) {
1828 $product->fetch(
GETPOST(
'idprod'.$i,
'int'));
1831 $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);
1835 $object->update_price(1,
'auto', 0, $mysoc);
1842 if (empty($dateinvoice)) {
1844 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
1846 } elseif ($dateinvoice > (
dol_get_last_hour(
dol_now(
'tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
1852 if (!(
GETPOST(
'situations',
'int') > 0)) {
1854 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
1860 $result = $object->fetch(
GETPOST(
'situations',
'int'));
1861 $object->fk_facture_source =
GETPOST(
'situations',
'int');
1864 if (!empty($origin) && !empty($originid)) {
1865 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1867 $object->origin = $origin;
1868 $object->origin_id = $originid;
1871 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
1872 $retained_warranty =
GETPOST(
'retained_warranty',
'int');
1873 if (
price2num($retained_warranty) > 0) {
1874 $object->retained_warranty =
price2num($retained_warranty);
1877 if (
GETPOST(
'retained_warranty_fk_cond_reglement',
'int') > 0) {
1878 $object->retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
1881 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1882 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
1883 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
1885 $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);
1888 foreach ($object->lines as $i => &$line) {
1889 $line->origin = $object->origin;
1890 $line->origin_id = $line->id;
1891 $line->fk_prev_id = $line->id;
1892 $line->fetch_optionals();
1893 $line->situation_percent = $line->get_prev_progress($object->id);
1896 $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);
1897 $line->total_ht = $tabprice[0];
1898 $line->total_tva = $tabprice[1];
1899 $line->total_ttc = $tabprice[2];
1900 $line->total_localtax1 = $tabprice[9];
1901 $line->total_localtax2 = $tabprice[10];
1902 $line->multicurrency_total_ht = $tabprice[16];
1903 $line->multicurrency_total_tva = $tabprice[17];
1904 $line->multicurrency_total_ttc = $tabprice[18];
1907 if ($line->fk_remise_except) {
1909 $result = $discount->fetch($line->fk_remise_except);
1912 if ($discount->fk_facture_line > 0) {
1913 $line->fk_remise_except = 0;
1920 $object->fetch_thirdparty();
1921 $object->date = $dateinvoice;
1922 $object->date_pointoftax = $date_pointoftax;
1923 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1924 $object->note = trim(
GETPOST(
'note',
'restricthtml'));
1925 $object->note_private = trim(
GETPOST(
'note',
'restricthtml'));
1926 $object->ref_client =
GETPOST(
'ref_client',
'alpha');
1927 $object->model_pdf =
GETPOST(
'model',
'alpha');
1928 $object->fk_project =
GETPOST(
'projectid',
'int');
1929 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1930 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1933 $object->fk_account =
GETPOST(
'fk_account',
'int');
1938 $object->situation_counter = $object->situation_counter + 1;
1939 $id = $object->createFromCurrent($user);
1941 $mesg = $object->error;
1943 $nextSituationInvoice =
new Facture($db);
1944 $nextSituationInvoice->fetch($id);
1947 $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
1948 $ret = $extrafields->setOptionalsFromPost(
null, $nextSituationInvoice);
1950 $nextSituationInvoice->insertExtraFields();
1957 if ($id > 0 && !$error) {
1961 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && count($object->lines)) {
1962 $outputlangs = $langs;
1964 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1965 $newlang =
GETPOST(
'lang_id',
'aZ09');
1967 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1968 $newlang = $object->thirdparty->default_lang;
1970 if (!empty($newlang)) {
1971 $outputlangs =
new Translate(
"", $conf);
1972 $outputlangs->setDefaultLang($newlang);
1973 $outputlangs->load(
'products');
1975 $model = $object->model_pdf;
1976 $ret = $object->fetch($id);
1978 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1984 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
1989 $_GET[
"origin"] = $_POST[
"origin"];
1990 $_GET[
"originid"] = $_POST[
"originid"];
1993 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'') {
1995 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1996 $vat_rate = str_replace(
'*',
'', $vat_rate);
1997 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1998 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1999 foreach ($object->lines as $line) {
2000 $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);
2002 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2004 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2005 $remise_percent = str_replace(
'*',
'', $remise_percent);
2006 foreach ($object->lines as $line) {
2007 $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);
2009 } elseif ($action ==
'addline' && $usercancreate) {
2010 $langs->load(
'errors');
2018 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'alpha');
2019 if ($prod_entry_mode ==
'free') {
2021 $tva_tx = (
GETPOST(
'tva_tx',
'alpha') ?
GETPOST(
'tva_tx',
'alpha') : 0);
2023 $idprod =
GETPOST(
'idprod',
'int');
2031 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
2032 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
2034 if (is_array($extralabelsline)) {
2036 foreach ($extralabelsline as $key => $value) {
2037 unset($_POST[
"options_".$key.$predef]);
2041 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2042 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2045 if (!$prod_entry_mode) {
2047 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2051 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2052 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2055 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) {
2056 if ($price_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
2057 $langs->load(
"errors");
2058 if ($object->type == $object::TYPE_DEPOSIT) {
2060 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2062 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2066 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2071 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2074 if ($prod_entry_mode ==
'free' && empty($idprod) && empty($product_desc)) {
2075 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2079 $langs->load(
"errors");
2080 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2084 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2085 if ($combinations =
GETPOST(
'combinations',
'array')) {
2089 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2090 $idprod = $res->fk_product_child;
2092 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2098 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
2099 $ret = $object->fetch($id);
2104 $ret = $object->fetch_thirdparty();
2109 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2120 if (!empty($idprod) && $idprod > 0) {
2122 $prod->fetch($idprod);
2124 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2129 $datapriceofproduct = $prod->getSellPrice($mysoc, $object->thirdparty, $pqp);
2131 $pu_ht = $datapriceofproduct[
'pu_ht'];
2132 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2133 $price_min = $datapriceofproduct[
'price_min'];
2134 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2135 $tva_tx = $datapriceofproduct[
'tva_tx'];
2136 $tva_npr = $datapriceofproduct[
'tva_npr'];
2138 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2139 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
2142 if (!empty($price_ht) || $price_ht ===
'0') {
2144 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2145 } elseif ($tmpvat != $tmpprodvat) {
2148 if ($price_base_type !=
'HT') {
2149 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2151 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2158 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
2159 $outputlangs = $langs;
2161 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
2162 $newlang =
GETPOST(
'lang_id',
'aZ09');
2164 if (empty($newlang)) {
2165 $newlang = $object->thirdparty->default_lang;
2167 if (!empty($newlang)) {
2168 $outputlangs =
new Translate(
"", $conf);
2169 $outputlangs->setDefaultLang($newlang);
2170 $outputlangs->load(
'products');
2173 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->description;
2175 $desc = $prod->description;
2179 if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
2183 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
2184 $desc = $product_desc;
2186 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
2190 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
2193 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
2194 $outputlangs = $langs;
2196 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
2197 $newlang =
GETPOST(
'lang_id',
'alpha');
2199 if (empty($newlang)) {
2200 $newlang = $object->thirdparty->default_lang;
2202 if (!empty($newlang)) {
2203 $outputlangs =
new Translate(
"", $conf);
2204 $outputlangs->setDefaultLang($newlang);
2205 $outputlangs->load(
'products');
2207 if (!empty($prod->customcode)) {
2208 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2210 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2213 if (!empty($prod->country_code)) {
2214 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
2217 if (!empty($prod->customcode)) {
2218 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2220 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2223 if (!empty($prod->country_code)) {
2224 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
2231 $type = $prod->type;
2232 $fk_unit = $prod->fk_unit;
2236 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2237 $tva_tx = str_replace(
'*',
'', $tva_tx);
2238 if (empty($tva_tx)) {
2241 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2242 $desc = $product_desc;
2244 $fk_unit =
GETPOST(
'units',
'alpha');
2247 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2254 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
2255 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
2263 $price2num_remise_percent =
price2num($remise_percent);
2264 $price2num_price_min =
price2num($price_min);
2265 if (empty($price2num_pu_ht)) {
2266 $price2num_pu_ht = 0;
2268 if (empty($price2num_remise_percent)) {
2269 $price2num_remise_percent = 0;
2271 if (empty($price2num_price_min)) {
2272 $price2num_price_min = 0;
2275 if ($usercanproductignorepricemin && (!empty($price_min) && ($price2num_pu_ht * (1 - $price2num_remise_percent / 100) < $price2num_price_min))) {
2276 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
2280 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)) {
2281 $langs->load(
'productbatch');
2282 foreach ($lines[$i]->detail_batch as $batchline) {
2283 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2288 $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);
2292 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2293 $outputlangs = $langs;
2295 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
2296 $newlang =
GETPOST(
'lang_id',
'aZ09');
2298 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) {
2299 $newlang = $object->thirdparty->default_lang;
2301 if (!empty($newlang)) {
2302 $outputlangs =
new Translate(
"", $conf);
2303 $outputlangs->setDefaultLang($newlang);
2304 $outputlangs->load(
'products');
2306 $model = $object->model_pdf;
2307 $ret = $object->fetch($id);
2309 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2315 unset($_POST[
'prod_entry_mode']);
2317 unset($_POST[
'qty']);
2318 unset($_POST[
'type']);
2319 unset($_POST[
'remise_percent']);
2320 unset($_POST[
'price_ht']);
2321 unset($_POST[
'multicurrency_price_ht']);
2322 unset($_POST[
'price_ttc']);
2323 unset($_POST[
'tva_tx']);
2324 unset($_POST[
'product_ref']);
2325 unset($_POST[
'product_label']);
2326 unset($_POST[
'product_desc']);
2327 unset($_POST[
'fournprice']);
2328 unset($_POST[
'buying_price']);
2329 unset($_POST[
'np_marginRate']);
2330 unset($_POST[
'np_markRate']);
2331 unset($_POST[
'dp_desc']);
2332 unset($_POST[
'idprod']);
2333 unset($_POST[
'units']);
2335 unset($_POST[
'date_starthour']);
2336 unset($_POST[
'date_startmin']);
2337 unset($_POST[
'date_startsec']);
2338 unset($_POST[
'date_startday']);
2339 unset($_POST[
'date_startmonth']);
2340 unset($_POST[
'date_startyear']);
2341 unset($_POST[
'date_endhour']);
2342 unset($_POST[
'date_endmin']);
2343 unset($_POST[
'date_endsec']);
2344 unset($_POST[
'date_endday']);
2345 unset($_POST[
'date_endmonth']);
2346 unset($_POST[
'date_endyear']);
2348 unset($_POST[
'situations']);
2349 unset($_POST[
'progress']);
2357 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2358 if (!$object->fetch($id) > 0) {
2361 $object->fetch_thirdparty();
2376 if (preg_match(
'/\*/', $vat_rate)) {
2381 $vat_rate = str_replace(
'*',
'', $vat_rate);
2382 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty);
2383 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty);
2390 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
2391 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
2393 if (is_array($extralabelsline)) {
2395 foreach ($extralabelsline as $key => $value) {
2396 unset($_POST[
"options_".$key]);
2401 $special_code =
GETPOST(
'special_code',
'int');
2402 if ($special_code == 3) {
2407 $line->fetch(
GETPOST(
'lineid',
'int'));
2408 $percent = $line->get_prev_progress($object->id);
2413 if ($progress >= 0) {
2414 $mesg = $langs->trans(
"CantBeNullOrPositive");
2418 } elseif ($progress < $line->situation_percent) {
2419 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
2423 } elseif ($progress < $percent) {
2424 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
2434 $productid =
GETPOST(
'productid',
'int');
2435 if (!empty($productid)) {
2437 $product->fetch($productid);
2439 $type = $product->type;
2441 $price_min = $product->price_min;
2442 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
2443 $price_min = $product->multiprices_min [$object->thirdparty->price_level];
2450 setEventMessages($langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency)),
null,
'errors');
2455 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2459 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
2464 $langs->load(
"errors");
2465 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2468 if ((empty($productid) && (($pu_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) || $pu_ht ==
'') && $pu_ht_devise ==
'') && $object->type !=
Facture::TYPE_CREDIT_NOTE) {
2469 if ($pu_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
2470 $langs->load(
"errors");
2471 if ($object->type == $object::TYPE_DEPOSIT) {
2473 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2475 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2479 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2487 if (empty($usercancreatemargin)) {
2488 foreach ($object->lines as &$line) {
2489 if ($line->id ==
GETPOST(
'lineid',
'int')) {
2490 $fournprice = $line->fk_fournprice;
2491 $buyingprice = $line->pa_ht;
2497 $result = $object->updateline(
2511 GETPOST(
'fk_parent_line',
'int'),
2524 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2526 $outputlangs = $langs;
2528 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
2529 $newlang =
GETPOST(
'lang_id',
'aZ09');
2531 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
2532 $newlang = $object->thirdparty->default_lang;
2534 if (!empty($newlang)) {
2535 $outputlangs =
new Translate(
"", $conf);
2536 $outputlangs->setDefaultLang($newlang);
2537 $outputlangs->load(
'products');
2540 $ret = $object->fetch($id);
2541 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2544 unset($_POST[
'qty']);
2545 unset($_POST[
'type']);
2546 unset($_POST[
'productid']);
2547 unset($_POST[
'remise_percent']);
2548 unset($_POST[
'price_ht']);
2549 unset($_POST[
'multicurrency_price_ht']);
2550 unset($_POST[
'price_ttc']);
2551 unset($_POST[
'tva_tx']);
2552 unset($_POST[
'product_ref']);
2553 unset($_POST[
'product_label']);
2554 unset($_POST[
'product_desc']);
2555 unset($_POST[
'fournprice']);
2556 unset($_POST[
'buying_price']);
2557 unset($_POST[
'np_marginRate']);
2558 unset($_POST[
'np_markRate']);
2560 unset($_POST[
'dp_desc']);
2561 unset($_POST[
'idprod']);
2562 unset($_POST[
'units']);
2564 unset($_POST[
'date_starthour']);
2565 unset($_POST[
'date_startmin']);
2566 unset($_POST[
'date_startsec']);
2567 unset($_POST[
'date_startday']);
2568 unset($_POST[
'date_startmonth']);
2569 unset($_POST[
'date_startyear']);
2570 unset($_POST[
'date_endhour']);
2571 unset($_POST[
'date_endmin']);
2572 unset($_POST[
'date_endsec']);
2573 unset($_POST[
'date_endday']);
2574 unset($_POST[
'date_endmonth']);
2575 unset($_POST[
'date_endyear']);
2577 unset($_POST[
'situations']);
2578 unset($_POST[
'progress']);
2583 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modifier')) {
2584 if (!$object->fetch($id) > 0) {
2587 if (
GETPOST(
'all_progress') !=
"") {
2588 $all_progress =
GETPOST(
'all_progress',
'int');
2589 foreach ($object->lines as $line) {
2590 $percent = $line->get_prev_progress($object->id);
2591 if (floatval($all_progress) < floatval($percent)) {
2592 $mesg = $langs->trans(
"Line").
' '.$i.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
2596 $object->update_percent($line,
GETPOST(
'all_progress'),
false);
2599 $object->update_price(1);
2601 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
2602 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2604 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
2606 $object->fetch($id,
'',
'',
'',
true);
2612 && $object->is_last_in_cycle()
2613 && $usercanunvalidate
2616 $newCycle = $object->newCycle();
2617 if ($newCycle > 1) {
2619 $lastCycle = $object->situation_cycle_ref;
2620 $lastSituationCounter = $object->situation_counter;
2621 $linkedCreditNotesList = array();
2623 if (count($object->tab_next_situation_invoice) > 0) {
2624 foreach ($object->tab_next_situation_invoice as $next_invoice) {
2626 && $next_invoice->situation_counter == $object->situation_counter
2627 && $next_invoice->fk_facture_source == $object->id
2629 $linkedCreditNotesList[] = $next_invoice->id;
2634 $object->situation_cycle_ref = $newCycle;
2635 $object->situation_counter = 1;
2636 $object->situation_final = 0;
2637 if ($object->update($user) > 0) {
2639 if (count($linkedCreditNotesList) > 0) {
2641 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
2642 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
2643 $sql .=
' , situation_final=0';
2644 $sql .=
' , situation_counter='.((int) $object->situation_counter);
2645 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
2647 $resql = $db->query($sql);
2653 foreach ($object->lines as $line) {
2655 if ($line->product_type == 9) {
2660 if (!empty($object->tab_previous_situation_invoice)) {
2662 $lineIndex = count($object->tab_previous_situation_invoice) - 1;
2663 $searchPreviousInvoice =
true;
2664 while ($searchPreviousInvoice) {
2666 $searchPreviousInvoice =
false;
2674 $maxPrevSituationPercent = 0;
2675 foreach ($object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
2676 if ($prevLine->id == $line->fk_prev_id) {
2677 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
2682 $line->situation_percent = $line->situation_percent - $maxPrevSituationPercent;
2684 if ($line->update() < 0) {
2693 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
2695 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
2698 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
2701 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
2704 } elseif ($action ==
'import_lines_from_object'
2709 $fromElement =
GETPOST(
'fromelement');
2710 $fromElementid =
GETPOST(
'fromelementid');
2711 $importLines =
GETPOST(
'line_checkbox');
2713 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
2714 if ($fromElement ==
'commande') {
2716 $lineClassName =
'OrderLine';
2717 } elseif ($fromElement ==
'propal') {
2718 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
2719 $lineClassName =
'PropaleLigne';
2721 $nextRang = count($object->lines) + 1;
2724 foreach ($importLines as $lineId) {
2725 $lineId = intval($lineId);
2726 $originLine =
new $lineClassName($db);
2727 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
2728 $originLine->fetch_optionals();
2729 $desc = $originLine->desc;
2730 $pu_ht = $originLine->subprice;
2731 $qty = $originLine->qty;
2732 $txtva = $originLine->tva_tx;
2733 $txlocaltax1 = $originLine->localtax1_tx;
2734 $txlocaltax2 = $originLine->localtax2_tx;
2735 $fk_product = $originLine->fk_product;
2736 $remise_percent = $originLine->remise_percent;
2737 $date_start = $originLine->date_start;
2738 $date_end = $originLine->date_end;
2740 $info_bits = $originLine->info_bits;
2741 $fk_remise_except = $originLine->fk_remise_except;
2742 $price_base_type =
'HT';
2744 $type = $originLine->product_type;
2745 $rang = $nextRang++;
2746 $special_code = $originLine->special_code;
2747 $origin = $originLine->element;
2748 $origin_id = $originLine->id;
2749 $fk_parent_line = 0;
2750 $fk_fournprice = $originLine->fk_fournprice;
2751 $pa_ht = $originLine->pa_ht;
2752 $label = $originLine->label;
2753 $array_options = $originLine->array_options;
2755 $situation_percent = 0;
2757 $situation_percent = 100;
2760 $fk_unit = $originLine->fk_unit;
2761 $pu_ht_devise = $originLine->multicurrency_subprice;
2763 $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);
2782 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2788 $triggersendname =
'BILL_SENTBYMAIL';
2790 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
2791 $trackid =
'inv'.$object->id;
2792 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2795 $upload_dir = $conf->facture->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity];
2796 $permissiontoadd = $usercancreate;
2797 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2800 if ($action ==
'update_extras') {
2801 $object->oldcopy =
dol_clone($object, 2);
2804 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
2811 $result = $object->insertExtraFields(
'BILL_MODIFY');
2819 $action =
'edit_extras';
2823 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
2824 if ($action ==
'addcontact') {
2825 $result = $object->fetch($id);
2827 if ($result > 0 && $id > 0) {
2830 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2834 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2837 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2838 $langs->load(
"errors");
2839 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
2844 } elseif ($action ==
'swapstatut') {
2846 if ($object->fetch($id)) {
2847 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
2851 } elseif ($action ==
'deletecontact') {
2853 $object->fetch($id);
2854 $result = $object->delete_contact($lineid);
2857 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2865 $action =
'edit_extras';
2881 $paymentstatic =
new Paiement($db);
2882 $bankaccountstatic =
new Account($db);
2889 $title = $langs->trans(
'InvoiceCustomer').
" - ".$langs->trans(
'Card');
2891 $help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
2897 if ($action ==
'create') {
2898 $facturestatic =
new Facture($db);
2899 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
2904 $res = $soc->fetch($socid);
2907 $currency_code = $conf->currency;
2911 $remise_absolue = 0;
2912 if (!empty($origin) && !empty($originid)) {
2914 $element = $subelement = $origin;
2916 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
2917 $element = $regs[1];
2918 $subelement = $regs[2];
2921 if ($element ==
'project') {
2922 $projectid = $originid;
2924 if (empty($cond_reglement_id)) {
2925 $cond_reglement_id = $soc->cond_reglement_id;
2927 if (empty($mode_reglement_id)) {
2928 $mode_reglement_id = $soc->mode_reglement_id;
2930 if (empty($fk_account)) {
2931 $fk_account = $soc->fk_account;
2933 if (!$remise_percent) {
2934 $remise_percent = $soc->remise_percent;
2936 if (!$dateinvoice) {
2938 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
2942 if ($element ==
'order' || $element ==
'commande') {
2943 $element = $subelement =
'commande';
2945 if ($element ==
'propal') {
2946 $element =
'comm/propal';
2947 $subelement =
'propal';
2949 if ($element ==
'contract') {
2950 $element = $subelement =
'contrat';
2952 if ($element ==
'shipping') {
2953 $element = $subelement =
'expedition';
2958 $classname = ucfirst($subelement);
2959 $objectsrc =
new $classname($db);
2960 $objectsrc->fetch($originid);
2961 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
2962 $objectsrc->fetch_lines();
2964 $objectsrc->fetch_thirdparty();
2966 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
2967 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
2970 if (empty($socid)) {
2971 $soc = $objectsrc->thirdparty;
2974 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
2976 if ($element ==
'expedition') {
2977 $ref_client = (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
'');
2979 $elem = $subelem = $objectsrc->origin;
2980 $expeoriginid = $objectsrc->origin_id;
2982 $classname = ucfirst($subelem);
2984 $expesrc =
new $classname($db);
2985 $expesrc->fetch($expeoriginid);
2987 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
2988 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
2989 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
2990 $remise_percent = (!empty($expesrc->remise_percent) ? $expesrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
2991 $remise_absolue = (!empty($expesrc->remise_absolue) ? $expesrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
2993 if (!empty($conf->multicurrency->enabled)) {
2994 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
2995 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
2999 $expesrc->fetch_optionals();
3000 $object->array_options = $expesrc->array_options;
3002 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
3003 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3004 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3005 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
3006 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
3009 if (!empty($objectsrc->multicurrency_code)) {
3010 $currency_code = $objectsrc->multicurrency_code;
3012 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
3013 $currency_tx = $objectsrc->multicurrency_tx;
3018 $objectsrc->fetch_optionals();
3019 $object->array_options = $objectsrc->array_options;
3023 $cond_reglement_id = $soc->cond_reglement_id;
3024 $mode_reglement_id = $soc->mode_reglement_id;
3025 $fk_account = $soc->fk_account;
3026 $remise_percent = $soc->remise_percent;
3027 $remise_absolue = 0;
3028 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
3030 if (
isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3031 $currency_code = $soc->multicurrency_code;
3036 if (empty($cond_reglement_id)) {
3037 $cond_reglement_id =
GETPOST(
"cond_reglement_id",
'int');
3041 if (empty($mode_reglement_id)) {
3042 $mode_reglement_id =
GETPOST(
"mode_reglement_id",
'int');
3046 if ($socid > 0 && $fk_account) {
3049 $fk_account =
GETPOST(
"fk_account",
'int');
3052 if (!empty($soc->id)) {
3053 $absolute_discount = $soc->getAvailableDiscounts();
3055 $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));
3056 $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));
3058 if (!empty($conf->use_javascript_ajax)) {
3059 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3065 if ($origin ==
'contrat') {
3066 $langs->load(
"admin");
3067 $text = $langs->trans(
"ToCreateARecurringInvoice");
3068 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3069 if (empty($conf->global->INVOICE_DISABLE_AUTOMATIC_RECURRING_INVOICE)) {
3070 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3072 print
info_admin($text, 0, 0, 0,
'opacitymedium').
'<br>';
3075 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3076 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3077 print
'<input type="hidden" name="action" value="add">';
3079 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3081 print
'<input name="ref" type="hidden" value="provisoire">';
3082 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3083 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3084 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3085 print
'<input name="force_fk_account" type="hidden" value="0">';
3086 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3087 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3088 print
'<input type="hidden" name="originentity" value="'.GETPOST(
'originentity').
'">';
3089 if (!empty($currency_tx)) {
3090 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3095 print
'<table class="border centpercent">';
3100 $exampletemplateinvoice =
new FactureRec($db);
3102 if (empty($origin) && empty($originid) &&
GETPOST(
'fac_rec',
'int') > 0) {
3103 $invoice_predefined->fetch(
GETPOST(
'fac_rec',
'int'));
3107 if ($soc->id > 0 && (!
GETPOST(
'fac_rec',
'int') || !empty($invoice_predefined->frequency))) {
3109 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3110 print
'<td colspan="2">';
3111 print $soc->getNomUrl(1,
'customer');
3112 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3114 $arrayoutstandingbills = $soc->getOutstandingBills();
3115 $outstandingBills = $arrayoutstandingbills[
'opened'];
3116 print
' - <span class="opacitymedium">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3117 print
price($outstandingBills,
'', $langs, 0, 0, -1, $conf->currency);
3118 if ($soc->outstanding_limit !=
'') {
3119 if ($outstandingBills > $soc->outstanding_limit) {
3120 print
img_warning($langs->trans(
"OutstandingBillReached"));
3122 print
' / '.price($soc->outstanding_limit,
'', $langs, 0, 0, -1, $conf->currency);
3127 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3128 print
'<td colspan="2">';
3129 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');
3131 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
3132 print
'<script type="text/javascript">
3133 $(document).ready(function() {
3134 $("#socid").change(function() {
3136 console.log("Submit page");
3137 $(\'input[name="action"]\').val(\'create\');
3138 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3139 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3140 $(\'input[name="force_fk_account"]\').val(\'1\');
3141 $("#formtocreate").submit(); */
3143 // 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.
3144 console.log("We have changed the company - Reload page");
3145 var socid = $(this).val();
3146 var fac_rec = $(\'#fac_rec\').val();
3147 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3152 if (!
GETPOST(
'fac_rec',
'int')) {
3153 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>';
3160 if (empty($origin) && empty($originid) &&
GETPOST(
'fac_rec',
'int') > 0) {
3161 $invoice_predefined->fetch(
GETPOST(
'fac_rec',
'int'));
3163 $dateinvoice = $invoice_predefined->date_when;
3164 if (empty($projectid)) {
3165 $projectid = $invoice_predefined->fk_project;
3167 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
3168 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
3169 $fk_account = $invoice_predefined->fk_account;
3170 $note_public = $invoice_predefined->note_public;
3171 $note_private = $invoice_predefined->note_private;
3173 if (!empty($invoice_predefined->multicurrency_code)) {
3174 $currency_code = $invoice_predefined->multicurrency_code;
3176 if (!empty($invoice_predefined->multicurrency_tx)) {
3177 $currency_tx = $invoice_predefined->multicurrency_tx;
3180 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
3181 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
3182 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
3184 $resql = $db->query($sql);
3186 $num = $db->num_rows(
$resql);
3190 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
3192 print
'<select class="flat" id="fac_rec" name="fac_rec">';
3193 print
'<option value="0" selected></option>';
3195 $objp = $db->fetch_object(
$resql);
3196 print
'<option value="'.$objp->rowid.
'"';
3197 if (
GETPOST(
'fac_rec',
'int') == $objp->rowid) {
3199 $exampletemplateinvoice->fetch(
GETPOST(
'fac_rec',
'int'));
3201 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
3209 if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED)) {
3210 print
'<script type="text/javascript">
3211 $(document).ready(function() {
3212 $("#fac_rec").change(function() {
3213 console.log("We have changed the template invoice - Reload page");
3214 var fac_rec = $(this).val();
3215 var socid = $(\'#socid\').val();
3216 // 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.
3217 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3230 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td colspan="2">';
3231 print
'<div class="tagtable">'.
"\n";
3234 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3235 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOST(
'type',
'int') ?
'' :
' checked').
'> ';
3236 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
3237 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
3238 print
'<table class="nobordernopadding"><tr>';
3242 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
3251 print
'<td class="nowrap" style="padding-left: 15px">';
3252 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%').
'"/>';
3255 print
'</tr></table>';
3256 print
'</div></div>';
3258 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
3260 if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) {
3261 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3262 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOST(
'type') == 3 ?
' checked' :
'').
'> ';
3263 print
'<script type="text/javascript">
3264 jQuery(document).ready(function() {
3265 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
3266 jQuery("#radio_standard").prop("checked", true);
3268 jQuery("#typedeposit, #valuedeposit").click(function() {
3269 jQuery("#radio_deposit").prop("checked", true);
3271 jQuery("#typedeposit").change(function() {
3272 console.log("We change type of down payment");
3273 jQuery("#radio_deposit").prop("checked", true);
3274 setRadioForTypeOfIncoice();
3276 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
3277 setRadioForTypeOfIncoice();
3279 function setRadioForTypeOfIncoice() {
3280 console.log("Change radio");
3281 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
3282 jQuery(".checkforselect").prop("disabled", true);
3283 jQuery(".checkforselect").prop("checked", false);
3285 jQuery(".checkforselect").prop("disabled", false);
3286 jQuery(".checkforselect").prop("checked", true);
3292 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
3293 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
3294 print
'<table class="nobordernopadding"><tr>';
3298 if (($origin ==
'propal') || ($origin ==
'commande')) {
3299 print
'<td class="nowrap" style="padding-left: 15px">';
3301 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
3302 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
3303 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
3305 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
3306 $valuedeposit =
GETPOST(
'valuedeposit',
'int');
3307 if (empty($typedeposit) && ! empty($objectsrc->deposit_percent)) {
3308 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
3309 if (! empty($origin_payment_conditions_deposit_percent)) {
3310 $typedeposit =
'variable';
3313 if (empty($valuedeposit) && $typedeposit ==
'variable' && ! empty($objectsrc->deposit_percent)) {
3314 $valuedeposit = $objectsrc->deposit_percent;
3316 print
$form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
3318 print
'<td class="nowrap" style="padding-left: 5px">';
3319 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.$valuedeposit.
'"/>';
3322 print
'</tr></table>';
3324 print
'</div></div>';
3329 if (!empty($conf->global->INVOICE_USE_SITUATION)) {
3331 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3332 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
3333 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
3334 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3);
3336 print
'</div></div>';
3339 $opt =
$form->selectSituationInvoices(
GETPOST(
'originid',
'int'), $socid);
3341 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3342 $tmp =
'<input type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOST(
'originid',
'int') ?
' checked' :
'');
3343 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3344 $tmp .=
' disabled';
3347 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3348 $text .=
'<select class="flat" id="situations" name="situations"';
3349 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3350 $text .=
' disabled';
3354 $text .=
'</select>';
3355 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
3357 print
'</div></div>';
3361 if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT)) {
3363 $facids = $facturestatic->list_replacable_invoices($soc->id);
3369 if (is_array($facids)) {
3370 foreach ($facids as $facparam) {
3371 $options .=
'<option value="'.$facparam [
'id'].
'"';
3372 if ($facparam[
'id'] ==
GETPOST(
'fac_replacement',
'int')) {
3373 $options .=
' selected';
3375 $options .=
'>'.$facparam[
'ref'];
3376 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
3377 $options .=
'</option>';
3381 print
'<!-- replacement line -->';
3382 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3383 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
3384 if (!$options || $invoice_predefined->id > 0) {
3385 $tmp .=
' disabled';
3388 print
'<script type="text/javascript">
3389 jQuery(document).ready(function() {
3390 jQuery("#fac_replacement").change(function() {
3391 jQuery("#radio_replacement").prop("checked", true);
3395 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
3396 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
3397 if (!$options || $invoice_predefined->id > 0) {
3398 $text .=
' disabled';
3402 $text .=
'<option value="-1"> </option>';
3405 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
3407 $text .=
'</select>';
3408 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3410 print
'</div></div>';
3413 if (!empty($conf->global->INVOICE_USE_SITUATION)) {
3414 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3415 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3416 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceFirstSituationAsk").
'</label> ';
3417 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3418 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3);
3420 print
'</div></div>';
3422 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3423 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3424 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3425 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3426 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3);
3428 print
'</div></div>';
3431 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3432 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
3433 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceReplacement").
'</label> ';
3434 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3435 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3437 print
'</div></div>';
3440 if (empty($origin)) {
3443 if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) {
3445 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
3451 $newinvoice_static =
new Facture($db);
3452 foreach ($facids as $key => $valarray) {
3453 $newinvoice_static->id = $key;
3454 $newinvoice_static->ref = $valarray [
'ref'];
3455 $newinvoice_static->statut = $valarray [
'status'];
3456 $newinvoice_static->type = $valarray [
'type'];
3457 $newinvoice_static->paye = $valarray [
'paye'];
3459 $optionsav .=
'<option value="'.$key.
'"';
3460 if ($key ==
GETPOST(
'fac_avoir')) {
3461 $optionsav .=
' selected';
3464 $newinvoice_static->fetch_optionals($key);
3465 $object->array_options = $newinvoice_static->array_options;
3468 $optionsav .= $newinvoice_static->ref;
3469 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
3470 $optionsav .=
'</option>';
3473 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3474 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
3475 if ((!$optionsav && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) || $invoice_predefined->id > 0) {
3476 $tmp .=
' disabled';
3480 print
'<script type="text/javascript">
3481 jQuery(document).ready(function() {
3482 if (! jQuery("#radio_creditnote").is(":checked"))
3484 jQuery("#credit_note_options").hide();
3486 jQuery("#radio_creditnote").click(function() {
3487 jQuery("#credit_note_options").show();
3489 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
3490 jQuery("#credit_note_options").hide();
3494 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
3496 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3497 if (!$optionsav || $invoice_predefined->id > 0) {
3498 $text .=
' disabled';
3502 $text .=
'<option value="-1"></option>';
3503 $text .= $optionsav;
3505 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
3507 $text .=
'</select>';
3508 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3511 print
'<div id="credit_note_options" class="clearboth">';
3512 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>";
3513 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>";
3516 print
'</div></div>';
3519 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3520 if (empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
3521 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3523 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
3525 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceAvoir").
'</label> ';
3526 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3527 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3529 print
'</div></div>'.
"\n";
3534 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3535 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
3536 $text =
'<label>'.$tmp.$langs->trans(
"RepeatableInvoice").
'</label> ';
3538 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3);
3540 print
'</div></div>';
3545 if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) {
3549 foreach ($listtType as $type) {
3550 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
3551 $curent = !empty($conf->global->{$thisTypeConfName}) ? $conf->global->{$thisTypeConfName}:$conf->global->FACTURE_ADDON_PDF;
3552 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$curent.
'"';
3555 print
'<script type="text/javascript">
3556 $(document).ready(function() {
3557 var listType = {'.$jsListType.
'};
3558 $("[name=\'type\'").change(function() {
3559 if($( this ).prop("checked"))
3561 if(($( this ).val() in listType))
3563 $("#model").val(listType[$( this ).val()]);
3567 $("#model").val("'.$conf->global->FACTURE_ADDON_PDF.
'");
3580 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
3584 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin',
'alpha').
'&originid='.
GETPOST(
'originid',
'int'));
3585 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3591 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
3594 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
3595 print
$form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'',
'',
'',
'',
"add", 1, 1);
3599 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
3600 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
3601 print
$form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax',
'',
'',
'',
"add", 1, 1);
3606 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
3607 $form->select_conditions_paiements(
GETPOSTISSET(
'cond_reglement_id') ?
GETPOST(
'cond_reglement_id',
'int') : $cond_reglement_id,
'cond_reglement_id');
3611 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
3612 $rwStyle =
'display:none;';
3613 if (in_array(
GETPOST(
'type',
'int'), $retainedWarrantyInvoiceAvailableType)) {
3617 $retained_warranty =
GETPOST(
'retained_warranty',
'int');
3618 if (empty($retained_warranty)) {
3619 if (!empty($objectsrc->retained_warranty)) {
3620 $retained_warranty = $objectsrc->retained_warranty;
3623 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT;
3625 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
3626 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
3629 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
3630 $retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
3631 if (empty($retained_warranty_fk_cond_reglement)) {
3632 $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
3633 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
3634 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
3636 $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
3639 $form->select_conditions_paiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
3642 print
'<script type="text/javascript">
3643 $(document).ready(function() {
3644 $("[name=\'type\']").change(function() {
3645 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
3647 $(".retained-warranty-line").show();
3648 $("#new-situation-invoice-retained-warranty").val("'.floatval($retained_warranty_js_default).
'");
3651 $(".retained-warranty-line").hide();
3652 $("#new-situation-invoice-retained-warranty").val("");
3656 $("[name=\'type\']:checked").trigger("change");
3662 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
3663 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
3664 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);
3669 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td colspan="2">';
3670 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
3671 print
$form->select_comptes(($fk_account < 0 ?
'' : $fk_account),
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
3677 $langs->load(
'projects');
3678 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
3679 print
img_picto(
'',
'project').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
3680 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>';
3687 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
3688 print
'<td colspan="2" class="maxwidthonsmartphone">';
3689 $incoterm_id =
GETPOST(
'incoterm_id');
3690 $incoterm_location =
GETPOST(
'location_incoterms');
3691 if (empty($incoterm_id)) {
3692 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
3693 $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
3695 print
$form->select_incoterms($incoterm_id, $incoterm_location);
3700 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid'=>$socid);
3701 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
3702 print $hookmanager->resPrint;
3703 if (empty($reshook)) {
3704 if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE) && !empty($soc->id)) {
3706 $tpExtrafields =
new Extrafields($db);
3707 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
3708 if ($soc->fetch_optionals() > 0) {
3709 $object->array_options = array_merge($object->array_options, $soc->array_options);
3713 print $object->showOptionals($extrafields,
'create',
$parameters);
3717 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
3718 print
'<td colspan="2">';
3719 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
3720 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
3722 if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) {
3724 $paramkey =
'FACTURE_ADDON_PDF_'.$object->type;
3725 $preselected = !empty($conf->global->$paramkey) ? $conf->global->$paramkey : $conf->global->FACTURE_ADDON_PDF;
3727 $preselected = $conf->global->FACTURE_ADDON_PDF;
3729 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
3735 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
3736 print
'<td colspan="2" class="maxwidthonsmartphone">';
3737 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
3738 print
$form->selectMultiCurrency($currency_code,
'multicurrency_code');
3744 if (
GETPOST(
'fac_rec',
'int') > 0) {
3745 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
3746 if (empty($dateexample)) {
3749 $substitutionarray = array(
3750 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
3751 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
3752 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
3753 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
3754 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
3755 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
3756 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
3757 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
3758 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
3759 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
3760 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
3763 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
3764 foreach ($substitutionarray as $key => $val) {
3765 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
3767 $htmltext .=
'</i>';
3772 print
'<td class="tdtop">';
3773 print
$form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
3775 print
'<td valign="top" colspan="2">';
3776 $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%');
3777 print $doleditor->Create(1);
3780 if (empty($user->socid)) {
3782 print
'<td class="tdtop">';
3783 print
$form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
3785 print
'<td valign="top" colspan="2">';
3786 $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%');
3787 print $doleditor->Create(1);
3793 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
3794 $langs->loadLangs(array(
'orders',
'propal'));
3797 if ($origin ==
'contrat') {
3799 $objectsrc->remise_absolue = $remise_absolue;
3800 $objectsrc->remise_percent = $remise_percent;
3801 $objectsrc->update_price(1, - 1, 1);
3804 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
3805 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
3806 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
3807 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
3812 switch (get_class($objectsrc)) {
3814 $newclassname =
'CommercialProposal';
3817 $newclassname =
'Order';
3820 $newclassname =
'Sending';
3823 $newclassname =
'Contract';
3826 $newclassname =
'Intervention';
3829 $newclassname = get_class($objectsrc);
3833 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
3834 print
'<td colspan="2">';
3835 print $objectsrc->getNomUrl(1);
3837 $objectsrc->fetchObjectLinked($originid, $origin,
'',
'facture');
3838 if (is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
3840 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
3843 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht).
'</td></tr>';
3844 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva).
"</td></tr>";
3845 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
3846 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax1).
"</td></tr>";
3849 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
3850 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax2).
"</td></tr>";
3852 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc).
"</td></tr>";
3855 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
3856 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
3857 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
3865 print
$form->buttonsSaveCancel(
"CreateDraft");
3868 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
3871 $title = $langs->trans(
'ProductsAndServices');
3874 print
'<div class="div-table-responsive-no-min">';
3875 print
'<table class="noborder centpercent">';
3877 $objectsrc->printOriginLinesList(
'', $selectedLines);
3884 } elseif ($id > 0 || !empty($ref)) {
3885 if (empty($object->id)) {
3886 $langs->load(
'errors');
3887 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
3896 $result = $object->fetch($id, $ref);
3903 $extrafields->fetch_name_optionals_label($object->table_element);
3905 if ($user->socid > 0 && $user->socid != $object->socid) {
3909 $result = $object->fetch_thirdparty();
3911 $result = $soc->fetch($object->socid);
3915 $selleruserevenustamp = $mysoc->useRevenueStamp();
3917 $totalpaid = $object->getSommePaiement();
3918 $totalcreditnotes = $object->getSumCreditNotesUsed();
3919 $totaldeposits = $object->getSumDepositsUsed();
3927 $resteapayer =
price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
3931 $multicurrency_totalpaid = $object->getSommePaiement(1);
3932 $multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
3933 $multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
3934 $multicurrency_resteapayer =
price2num($object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
3938 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 && $object->multicurrency_code != $conf->currency) {
3939 $resteapayer =
price2num($multicurrency_resteapayer / $object->multicurrency_tx,
'MT');
3943 if ($object->paye) {
3946 $resteapayeraffiche = $resteapayer;
3948 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
3949 $filterabsolutediscount =
"fk_facture_source IS NULL";
3950 $filtercreditnote =
"fk_facture_source IS NOT NULL";
3952 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
3953 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
3956 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
3957 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
3958 $absolute_discount =
price2num($absolute_discount,
'MT');
3959 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
3961 $author =
new User($db);
3962 if ($object->user_author) {
3963 $author->fetch($object->user_author);
3966 $objectidnext = $object->getIdReplacingInvoice();
3970 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
'bill');
3975 if ($action ==
'converttoreduc') {
3977 $type_fac =
'ExcessReceived';
3979 $type_fac =
'CreditNote';
3981 $type_fac =
'Deposit';
3983 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
3984 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
3985 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
3989 if ($action ==
'delete') {
3990 $text = $langs->trans(
'ConfirmDeleteBill', $object->ref);
3991 $formquestion = array();
3993 if ($object->type !=
Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->statut >= 1) {
3994 $qualified_for_stock_change = 0;
3995 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
3996 $qualified_for_stock_change = $object->hasProductsOrServices(2);
3998 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4001 if ($qualified_for_stock_change) {
4002 $langs->load(
"stocks");
4003 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4005 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
4007 if ($conf->browser->name ==
'ie') {
4010 $formquestion = array(
4014 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4016 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4018 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4021 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4026 if ($action ==
'situationout') {
4027 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle', $object->ref);
4028 $label = $langs->trans(
"ConfirmOuting");
4029 $formquestion = array();
4034 && $object->is_last_in_cycle()
4035 && $usercanunvalidate
4037 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4042 if ($action ==
'valid') {
4044 $objectref = substr($object->ref, 1, 4);
4045 if ($objectref ==
'PROV') {
4046 $savdate = $object->date;
4047 if (!empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
4049 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
4051 $numref = $object->getNextNumRef($soc);
4054 $numref = $object->ref;
4057 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4058 if (!empty($conf->notification->enabled)) {
4059 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4060 $notify =
new Notify($db);
4062 $text .= $notify->confirmMessage(
'BILL_VALIDATE', $object->socid, $object);
4064 $formquestion = array();
4067 $qualified_for_stock_change = 0;
4068 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
4069 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4071 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4074 if ($qualified_for_stock_change) {
4075 $langs->load(
"stocks");
4076 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4077 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4080 $warehouse_array = $warehouse->list_array();
4081 if (count($warehouse_array) == 1) {
4082 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4083 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4085 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockIncrease") : $langs->trans(
"SelectWarehouseForStockDecrease");
4086 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4088 $formquestion = array(
4094 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4098 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
4103 foreach ($object->lines as $line) {
4104 $res = $line->fetch_product();
4106 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
4112 if ($nbMandated > 0 ) $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
4115 $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);
4119 if ($action ==
'modif') {
4120 $text = $langs->trans(
'ConfirmUnvalidateBill', $object->ref);
4121 $formquestion = array();
4124 $qualified_for_stock_change = 0;
4125 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
4126 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4128 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4131 if ($qualified_for_stock_change) {
4132 $langs->load(
"stocks");
4133 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4134 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4137 $warehouse_array = $warehouse->list_array();
4138 if (count($warehouse_array) == 1) {
4139 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
4140 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4142 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
4143 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4145 $formquestion = array(
4151 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4155 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
4159 if ($action ==
'paid' && ($resteapayer <= 0 || (!empty($conf->global->INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) && $resteapayer == $object->total_ttc))) {
4160 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill', $object->ref),
'confirm_paid',
'',
"yes", 1);
4162 if ($action ==
'paid' && $resteapayer > 0 && (empty($conf->global->INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $resteapayer != $object->total_ttc)) {
4166 $close[$i][
'code'] =
'discount_vat';
4168 $close[$i][
'code'] =
'badcustomer';
4170 $close[$i][
'code'] =
'bankcharge';
4172 $close[$i][
'code'] =
'other';
4176 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
4178 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4180 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
4182 $close[$i][
'label'] = $langs->trans(
"Other");
4186 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4188 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4190 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4192 $close[$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
4195 foreach ($close as $key => $val) {
4196 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
4200 $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'));
4202 $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);
4206 if ($action ==
'canceled') {
4209 if ($objectidnext) {
4210 $facturereplacement =
new Facture($db);
4211 $facturereplacement->fetch($objectidnext);
4212 $statusreplacement = $facturereplacement->statut;
4214 if ($objectidnext && $statusreplacement == 0) {
4215 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
4218 $close[1][
'code'] =
'badcustomer';
4219 $close[2][
'code'] =
'abandon';
4221 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4222 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
4224 $close[1][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $object->ref), $close[1][
'label'], 1);
4225 $close[2][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
4227 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
4228 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
4231 $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'));
4233 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill', $object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 270);
4237 if ($action ==
'deletepayment') {
4238 $payment_id =
GETPOST(
'paiement_id');
4239 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
4243 if ($action ==
'ask_deleteline') {
4244 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
4248 if ($action ==
'clone') {
4250 $formquestion = array(
4251 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)),
4252 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
4255 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
4258 if ($action ==
"remove_file_comfirm") {
4259 $file =
GETPOST(
'file',
'alpha');
4262 $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&file='.$file,
4263 $langs->trans(
'DeleteFileHeader'),
4264 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
4274 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
4275 if (empty($reshook)) {
4277 } elseif ($reshook > 0) {
4286 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
4288 $morehtmlref =
'<div class="refidno">';
4290 if ($object->status == $object::STATUS_DRAFT && !$mysoc->isInEEC() && !empty($conf->global->INVOICE_ALLOW_FREE_REF)) {
4291 $morehtmlref .=
$form->editfieldkey(
"Ref",
'ref', $object->ref, $object, $usercancreate,
'string',
'', 0, 1);
4292 $morehtmlref .=
$form->editfieldval(
"Ref",
'ref', $object->ref, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
4293 $morehtmlref .=
'<br>';
4296 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
4297 $morehtmlref .=
$form->editfieldval(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
4299 $morehtmlref .=
'<br>'.$langs->trans(
'ThirdParty').
' : '.$object->thirdparty->getNomUrl(1,
'customer');
4300 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
4301 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
4305 $langs->load(
"projects");
4306 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
4307 if ($usercancreate) {
4308 if ($action !=
'classify') {
4309 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
4311 if ($action ==
'classify') {
4313 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
4314 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
4315 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
4316 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
4317 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4318 $morehtmlref .=
'</form>';
4320 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
4323 if (!empty($object->fk_project)) {
4325 $proj->fetch($object->fk_project);
4326 $morehtmlref .=
' : '.$proj->getNomUrl(1);
4328 $morehtmlref .=
' - '.$proj->title;
4335 $morehtmlref .=
'</div>';
4337 $object->totalpaid = $totalpaid;
4339 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
4341 print
'<div class="fichecenter">';
4342 print
'<div class="fichehalfleft">';
4343 print
'<div class="underbanner clearboth"></div>';
4345 print
'<table class="border centpercent tableforfield">';
4348 print
'<tr><td class="titlefield fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
4349 print
'<span class="badgeneutral">';
4350 print $object->getLibType();
4352 if ($object->module_source) {
4353 print
' <span class="opacitymediumbycolor paddingleft">('.$langs->trans(
"POS").
' '.ucfirst($object->module_source).
' - '.$langs->trans(
"Terminal").
' '.$object->pos_source.
')</span>';
4356 $facreplaced =
new Facture($db);
4357 $facreplaced->fetch($object->fk_facture_source);
4358 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
4362 $facusing->fetch($object->fk_facture_source);
4363 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
4366 $facidavoir = $object->getListIdAvoirFromInvoice();
4367 if (count($facidavoir) > 0) {
4368 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
4370 foreach ($facidavoir as $id) {
4377 $facavoir->fetch($id);
4378 print $facavoir->getNomUrl(1);
4382 if ($objectidnext > 0) {
4383 $facthatreplace =
new Facture($db);
4384 $facthatreplace->fetch($objectidnext);
4385 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
4390 $result = $discount->fetch(0, $object->id);
4392 print
' <span class="opacitymediumbycolor paddingleft">';
4393 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
4394 $s = str_replace(
'{s1}', $object->getLibType(1), $s);
4395 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
4397 print
'</span><br>';
4401 if ($object->fk_fac_rec_source > 0) {
4403 $result = $tmptemplate->fetch($object->fk_fac_rec_source);
4405 print
' <span class="opacitymediumbycolor paddingleft">';
4406 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
4407 $s = str_replace(
'{s1}',
'<a href="'.DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->ref).
'</a>', $s);
4415 print
'<!-- Discounts -->'.
"\n";
4416 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
4420 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?facid='.$object->id);
4421 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
4426 print
'<table class="nobordernopadding centpercent"><tr><td>';
4427 print $langs->trans(
'DateInvoice');
4429 if ($action !=
'editinvoicedate' && !empty($object->brouillon) && $usercancreate && empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
4430 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>';
4432 print
'</tr></table>';
4435 if ($action ==
'editinvoicedate') {
4436 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date,
'invoicedate');
4438 print
'<span class="valuedate">'.dol_print_date($object->date,
'day').
'</span>';
4444 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
4447 print
'<table class="nobordernopadding centpercent"><tr><td>';
4448 print $langs->trans(
'DatePointOfTax');
4450 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>';
4451 print
'</tr></table>';
4453 if ($action ==
'editdate_pointoftax') {
4454 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date_pointoftax,
'date_pointoftax');
4456 print
'<span class="valuedate">'.dol_print_date($object->date_pointoftax,
'day').
'</span>';
4463 print
'<table class="nobordernopadding centpercent"><tr><td>';
4464 print $langs->trans(
'PaymentConditionsShort');
4467 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>';
4469 print
'</tr></table>';
4472 if ($action ==
'editconditions') {
4473 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
4475 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'none');
4484 print
'<table class="nobordernopadding centpercent"><tr><td>';
4485 print $langs->trans(
'DateMaxPayment');
4488 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>';
4490 print
'</tr></table>';
4493 if ($action ==
'editpaymentterm') {
4494 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date_lim_reglement,
'paymentterm');
4496 print
'<span class="valuedate">'.dol_print_date($object->date_lim_reglement,
'day').
'</span>';
4497 if ($object->hasDelay()) {
4508 print
'<table class="nobordernopadding centpercent"><tr><td>';
4509 print $langs->trans(
'PaymentMode');
4511 if ($action !=
'editmode' && $usercancreate) {
4512 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>';
4514 print
'</tr></table>';
4516 if ($action ==
'editmode') {
4517 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
4519 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'none',
'CRDT');
4528 print
'<table class="nobordernopadding centpercent"><tr><td>';
4529 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
4531 if ($usercancreate && $action !=
'editmulticurrencycode' && !empty($object->brouillon)) {
4532 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>';
4534 print
'</tr></table>';
4536 $htmlname = (($usercancreate && $action ==
'editmulticurrencycode') ?
'multicurrency_code' :
'none');
4537 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code, $htmlname);
4541 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
4544 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4545 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
4547 if ($usercancreate && $action !=
'editmulticurrencyrate' && !empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
4548 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>';
4550 print
'</tr></table>';
4552 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
4553 if ($action ==
'actualizemulticurrencyrate') {
4556 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx, ($usercancreate ?
'multicurrency_tx' :
'none'), $object->multicurrency_code);
4558 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
4559 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
4560 print
'<div class="inline-block"> ';
4561 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
4571 print
'<tr><td class="nowrap">';
4572 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
4573 print $langs->trans(
'BankAccount');
4575 if (($action !=
'editbankaccount') && $usercancreate) {
4576 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>';
4578 print
'</tr></table>';
4580 if ($action ==
'editbankaccount') {
4581 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
4583 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
4592 print
'<table class="nobordernopadding centpercent"><tr><td>';
4593 print $langs->trans(
'IncotermLabel');
4594 print
'<td><td class="right">';
4595 if ($usercancreate) {
4596 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
4600 print
'</td></tr></table>';
4603 if ($action !=
'editincoterm') {
4604 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
4606 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
4613 if (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
4614 $displayWarranty =
true;
4615 if (!in_array($object->type, $retainedWarrantyInvoiceAvailableType) && empty($object->retained_warranty)) {
4616 $displayWarranty =
false;
4619 if ($displayWarranty) {
4621 print
'<tr class="retained-warranty-lines" ><td>';
4622 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
4623 print $langs->trans(
'RetainedWarranty');
4625 if ($action !=
'editretainedwarranty' && $user->rights->facture->creer && $object->statut ==
Facture::STATUS_DRAFT) {
4626 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>';
4629 print
'</tr></table>';
4632 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4633 print
'<input type="hidden" name="action" value="setretainedwarranty">';
4634 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4635 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
4636 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4639 print
price($object->retained_warranty).
'%';
4644 print
'<tr class="retained-warranty-lines" ><td>';
4645 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
4646 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
4648 if ($action !=
'editretainedwarrantypaymentterms' && $user->rights->facture->creer && $object->statut ==
Facture::STATUS_DRAFT) {
4649 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>';
4652 print
'</tr></table>';
4654 $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime(
'-1 years', $object->date_lim_reglement);
4655 if ($object->date > $defaultDate) {
4656 $defaultDate = $object->date;
4661 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4662 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
4663 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4664 $retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
4665 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $object->retained_warranty_fk_cond_reglement;
4666 $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;
4667 $form->select_conditions_paiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4668 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4671 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->retained_warranty_fk_cond_reglement,
'none');
4672 if (!$displayWarranty) {
4673 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning.png',
'class="pictowarning valignmiddle" ');
4679 print
'<tr class="retained-warranty-lines" ><td>';
4680 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
4681 print $langs->trans(
'RetainedWarrantyDateLimit');
4683 if ($action !=
'editretainedwarrantydatelimit' && $user->rights->facture->creer && $object->statut ==
Facture::STATUS_DRAFT) {
4684 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>';
4687 print
'</tr></table>';
4689 $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime(
'-1 years', $object->date_lim_reglement);
4690 if ($object->date > $defaultDate) {
4691 $defaultDate = $object->date;
4696 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4697 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
4698 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4699 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').
'" >';
4700 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4703 print
dol_print_date($object->retained_warranty_date_limit,
'day');
4712 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
4717 print
'<div class="fichehalfright">';
4719 print
'<!-- amounts -->'.
"\n";
4720 print
'<div class="underbanner clearboth"></div>'.
"\n";
4721 print
'<table class="border tableforfield centpercent">';
4724 if (!empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE_SCREEN) && $object->type == $object::TYPE_CREDIT_NOTE) {
4728 if (
isModEnabled(
'multicurrency') && ($object->multicurrency_code != $conf->currency)) {
4730 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
4731 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>';
4735 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
4736 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>';
4740 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
4741 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>';
4746 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
'AmountHT').
'</td>';
4747 print
'<td class="nowrap right amountcard">'.price($sign * $object->total_ht, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4750 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>';
4754 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) {
4755 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
4756 print
'<td class="nowrap right amountcard">'.price($sign * $object->total_localtax1, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4758 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) {
4759 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
4760 print
'<td class="nowrap right amountcard">'.price($sign * $object->total_localtax2, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4764 if ($selleruserevenustamp) {
4766 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4767 print $langs->trans(
'RevenueStamp');
4769 if ($action !=
'editrevenuestamp' && !empty($object->brouillon) && $usercancreate) {
4770 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>';
4772 print
'</tr></table>';
4774 if ($action ==
'editrevenuestamp') {
4775 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
4776 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4777 print
'<input type="hidden" name="action" value="setrevenuestamp">';
4778 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num($object->revenuestamp).
'">';
4779 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
4780 print
' → <span id="revenuestamp_span"></span>';
4781 print
' <input type="submit" class="button buttongen button-save" value="'.$langs->trans(
'Modify').
'">';
4784 $(document).ready(function(){
4785 js_recalculate_revenuestamp();
4786 $('select[name=revenuestamp_type]').on('change',function(){
4787 js_recalculate_revenuestamp();
4790 function js_recalculate_revenuestamp(){
4791 var valselected = $('select[name=revenuestamp_type]').val();
4792 console.log('Calculate revenue stamp from '+valselected);
4794 if (valselected.indexOf('%') == -1)
4796 revenue = valselected;
4800 var revenue_type = parseFloat(valselected);
4801 var amount_net = ".round($object->total_ht, 2).
";
4802 revenue = revenue_type * amount_net / 100;
4803 revenue = revenue.toFixed(2);
4805 $('#revenuestamp_val').val(revenue);
4806 $('#revenuestamp_span').html(revenue);
4810 print
price($object->revenuestamp, 1,
'', 1, - 1, - 1, $conf->currency);
4816 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>';
4830 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
4833 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
4836 if ($selleruserevenustamp) {
4847 if (($object->situation_cycle_ref > 0) && !empty($conf->global->INVOICE_USE_SITUATION)) {
4848 print
'<!-- List of situation invoices -->';
4849 print
'<table class="noborder situationstable" width="100%">';
4851 print
'<tr class="liste_titre">';
4852 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
4854 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
4856 print
'<td class="right"></td>';
4858 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
4859 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
4860 print
'<td width="18"> </td>';
4863 $total_prev_ht = $total_prev_ttc = 0;
4864 $total_global_ht = $total_global_ttc = 0;
4866 if (count($object->tab_previous_situation_invoice) > 0) {
4869 $current_situation_counter = array();
4870 foreach ($object->tab_previous_situation_invoice as $prev_invoice) {
4871 $tmptotalpaidforthisinvoice = $prev_invoice->getSommePaiement();
4872 $total_prev_ht += $prev_invoice->total_ht;
4873 $total_prev_ttc += $prev_invoice->total_ttc;
4874 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ?-1 : 1) * $prev_invoice->situation_counter;
4875 print
'<tr class="oddeven">';
4876 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
4878 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
4880 print
'<td class="right"></td>';
4882 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
4883 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
4884 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).
'</td>';
4890 $total_global_ht += $total_prev_ht;
4891 $total_global_ttc += $total_prev_ttc;
4892 $total_global_ht += $object->total_ht;
4893 $total_global_ttc += $object->total_ttc;
4895 print
'<tr class="oddeven">';
4896 print
'<td>'.$object->getNomUrl(1).
'</td>';
4898 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$object->situation_counter.
'</td>';
4900 print
'<td class="right"></td>';
4902 print
'<td class="right"><span class="amount">'.price($object->total_ht).
'</span></td>';
4903 print
'<td class="right"><span class="amount">'.price($object->total_ttc).
'</span></td>';
4904 print
'<td class="right">'.$object->getLibStatut(3, $object->getSommePaiement()).
'</td>';
4908 print
'<tr class="oddeven">';
4909 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'CurrentSituationTotal').
'</b></td>';
4912 foreach ($current_situation_counter as $sit) {
4913 $curSign = $sit > 0 ?
'+' :
'-';
4914 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
4916 print
' '.$curSign.
' ';
4918 print $curType.abs($sit);
4925 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
4926 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
4927 print
'<td width="18"> </td>';
4931 if (count($object->tab_next_situation_invoice) > 0) {
4943 $total_next_ht = $total_next_ttc = 0;
4945 foreach ($object->tab_next_situation_invoice as $next_invoice) {
4946 $totalpaid = $next_invoice->getSommePaiement();
4947 $total_next_ht += $next_invoice->total_ht;
4948 $total_next_ttc += $next_invoice->total_ttc;
4950 print
'<tr class="oddeven">';
4951 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
4953 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
4955 print
'<td class="right"></td>';
4957 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
4958 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
4959 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid).
'</td>';
4963 $total_global_ht += $total_next_ht;
4964 $total_global_ttc += $total_next_ttc;
4966 print
'<tr class="oddeven">';
4967 print
'<td colspan="3" class="right"></td>';
4969 print
'<td class="right"></td>';
4971 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
4972 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
4973 print
'<td width="18"> </td>';
4981 if ($object->type == $object::TYPE_CREDIT_NOTE) {
4987 print
'<!-- List of payments already done -->';
4988 print
'<div class="div-table-responsive-no-min">';
4989 print
'<table class="noborder paymenttable centpercent">';
4991 print
'<tr class="liste_titre">';
4992 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
4993 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
4994 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
4996 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
4998 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
4999 print
'<td class="liste_titre" width="18"> </td>';
5003 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
5004 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
5005 $sql .=
' pf.amount,';
5006 $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';
5007 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
5008 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
5009 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
5010 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
5011 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id).
' AND pf.fk_paiement = p.rowid';
5012 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
5013 $sql .=
' ORDER BY p.datep, p.tms';
5015 $result = $db->query($sql);
5017 $num = $db->num_rows($result);
5022 $objp = $db->fetch_object($result);
5024 $paymentstatic->id = $objp->rowid;
5025 $paymentstatic->datepaye = $db->jdate($objp->dp);
5026 $paymentstatic->ref = $objp->ref;
5027 $paymentstatic->num_payment = $objp->num_payment;
5028 $paymentstatic->paiementcode = $objp->payment_code;
5030 print
'<tr class="oddeven"><td class="nowraponall">';
5031 print $paymentstatic->getNomUrl(1);
5034 $dateofpayment = $db->jdate($objp->dp);
5036 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
5042 $label = ($langs->trans(
"PaymentType".$objp->payment_code) != (
"PaymentType".$objp->payment_code)) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
5043 print
'<td>'.$label.
' '.$objp->num_payment.
'</td>';
5045 $bankaccountstatic->id = $objp->baid;
5046 $bankaccountstatic->ref = $objp->baref;
5047 $bankaccountstatic->label = $objp->baref;
5048 $bankaccountstatic->number = $objp->banumber;
5049 $bankaccountstatic->currency_code = $objp->bacurrency_code;
5052 $bankaccountstatic->account_number = $objp->account_number;
5055 $accountingjournal->fetch($objp->fk_accountancy_journal);
5056 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
5059 print
'<td class="nowraponall">';
5060 if ($bankaccountstatic->id) {
5061 print $bankaccountstatic->getNomUrl(1,
'transactions');
5065 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
5066 print
'<td class="center">';
5068 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
5085 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5086 print
'<span class="opacitymedium">';
5088 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
5090 print $langs->trans(
'AlreadyPaid');
5092 print
'</span></td><td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td><td> </td></tr>';
5094 $resteapayeraffiche = $resteapayer;
5095 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
5098 $creditnoteamount = 0;
5100 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
5101 $sql .=
" re.description, re.fk_facture_source";
5102 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
5103 $sql .=
" WHERE fk_facture = ".((int) $object->id);
5104 $resql = $db->query($sql);
5106 $num = $db->num_rows(
$resql);
5110 $obj = $db->fetch_object(
$resql);
5111 $invoice->fetch($obj->fk_facture_source);
5112 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5113 print
'<span class="opacitymedium">';
5115 print $langs->trans(
"CreditNote").
' ';
5118 print $langs->trans(
"Deposit").
' ';
5120 print $invoice->getNomUrl(0);
5123 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
5124 print
'<td class="right">';
5125 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=unlinkdiscount&token='.
newToken().
'&discountid='.$obj->rowid.
'">'.
img_delete().
'</a>';
5129 $creditnoteamount += $obj->amount_ttc;
5132 $depositamount += $obj->amount_ttc;
5141 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5142 print
'<span class="opacitymedium">';
5143 print
$form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
5145 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5146 $resteapayeraffiche = 0;
5147 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5151 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5152 print
'<span class="opacitymedium">';
5153 print
$form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
5155 print
'</td><td class="right">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td><td> </td></tr>';
5157 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5161 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5162 print
'<span class="opacitymedium">';
5163 print
$form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
5165 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5166 $resteapayeraffiche = 0;
5167 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5171 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5172 $text = $langs->trans(
"HelpAbandonOther");
5173 if ($object->close_note) {
5174 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.$object->close_note;
5176 print
'<span class="opacitymedium">';
5177 print
$form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
5179 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5180 $resteapayeraffiche = 0;
5181 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5185 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5186 print
'<span class="opacitymedium">';
5187 print $langs->trans(
"Billed");
5188 print
'</td><td class="right">'.price($object->total_ttc).
'</td><td> </td></tr>';
5190 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5191 print
'<span class="opacitymedium">';
5192 print $langs->trans(
'RemainderToPay');
5193 if ($resteapayeraffiche < 0) {
5194 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5198 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
5201 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
5202 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5203 print
'<span class="opacitymedium">';
5204 print $langs->trans(
'RemainderToPayMulticurrency');
5205 if ($resteapayeraffiche < 0) {
5206 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5210 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">';
5212 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>';
5216 if (!empty($object->situation_final) && !empty($object->retained_warranty) && $displayWarranty) {
5219 $retainedWarranty = $total_global_ttc * $object->retained_warranty / 100;
5222 $retainedWarranty = $object->total_ttc * $object->retained_warranty / 100;
5225 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
5227 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>';
5230 print
'<tr><td colspan="'.$nbcols.
'" align="right">';
5231 print $langs->trans(
"RetainedWarranty").
' ('.$object->retained_warranty.
'%)';
5232 print !empty($object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date($object->retained_warranty_date_limit,
'day')) :
'';
5233 print
' :</td><td align="right">'.price($retainedWarranty).
'</td><td> </td></tr>';
5236 $resteapayeraffiche = $resteapayer;
5237 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5240 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5241 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
5242 print
'</td><td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td><td> </td></tr>';
5245 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>';
5248 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5249 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
5250 if ($resteapayeraffiche > 0) {
5251 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5253 print
'</span></td>';
5254 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
5255 print
'<td class="nowrap"> </td></tr>';
5258 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
5259 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5260 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
5261 if ($resteapayeraffiche > 0) {
5262 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5266 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>';
5280 $formmargin->displayMarginInfos($object);
5286 print
'<div class="clearboth"></div><br><br>';
5288 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
5289 $blocname =
'contacts';
5290 $title = $langs->trans(
'ContactsAddresses');
5291 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5294 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
5295 $blocname =
'notes';
5296 $title = $langs->trans(
'Notes');
5297 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5301 $result = $object->getLinesArray();
5304 if (!empty($conf->global->INVOICE_USE_SITUATION)) {
5305 if ($object->situation_cycle_ref && $object->statut == 0) {
5306 print
'<!-- Area to change globally the situation percent -->'.
"\n";
5307 print
'<div class="div-table-responsive">';
5309 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'#updatealllines" method="POST">';
5310 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
5311 print
'<input type="hidden" name="action" value="updatealllines" />';
5312 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
5314 print
'<table id="tablelines_all_progress" class="noborder noshadow" width="100%">';
5316 print
'<tr class="liste_titre nodrag nodrop">';
5319 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
5320 print
'<td align="center" width="5"> </td>';
5322 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
5323 print
'<td class="right">'.$langs->trans(
'Progress').
'</td>';
5324 print
'<td> </td>';
5327 print
'<tr class="nodrag nodrop">';
5329 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
5330 print
'<td align="center" width="5"> </td>';
5332 print
'<td> </td>';
5333 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
5334 print
'<td class="right"><input type="submit" class="button" name="all_percent" value="Modifier" /></td>';
5345 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
5346 <input type="hidden" name="token" value="' .
newToken().
'">
5347 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
5348 <input type="hidden" name="mode" value="">
5349 <input type="hidden" name="page_y" value="">
5350 <input type="hidden" name="id" value="' . $object->id.
'">
5353 if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
5354 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
5357 print
'<div class="div-table-responsive-no-min">';
5358 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
5361 if (!empty($object->lines)) {
5362 $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
5366 if ($object->statut == 0 && $usercancreate && $action !=
'valid' && $action !=
'editline') {
5367 if ($action !=
'editline' && $action !=
'selectlines') {
5371 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
5372 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
5373 if (empty($reshook))
5374 $object->formAddObjectLine(1, $mysoc, $soc);
5388 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
5389 print
'<div class="tabsAction">';
5392 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
5393 if (empty($reshook)) {
5396 'class' =>
'classfortooltip'
5402 $ventilExportCompta = $object->getVentilExportCompta();
5404 if ($ventilExportCompta == 0) {
5405 if (!empty($conf->global->INVOICE_CAN_BE_EDITED_EVEN_IF_PAYMENT_DONE) || ($resteapayer ==
price2num($object->total_ttc,
'MT', 1) && empty($object->paye))) {
5406 if (!$objectidnext && $object->is_last_in_cycle()) {
5407 if ($usercanunvalidate) {
5408 $params[
'attr'][
'title'] =
'';
5409 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=modif&token='.
newToken(),
'',
true, $params);
5411 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
5412 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=modif&token='.
newToken(),
'',
false, $params);
5414 } elseif (!$object->is_last_in_cycle()) {
5415 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
5416 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5418 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
5419 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5423 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5424 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5429 $result = $discount->fetch(0, $object->id);
5437 && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || $usercanreopen)) {
5438 if ($object->close_code !=
'replaced' || (!$objectidnext)) {
5439 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
5441 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
5442 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
5447 if (!empty($conf->global->CONTRACT_CREATE_FROM_INVOICE)) {
5449 $langs->load(
"contracts");
5451 if ($usercancreatecontract) {
5452 print
'<a class="butAction" href="' . DOL_URL_ROOT .
'/contrat/card.php?action=create&origin=' . $object->element .
'&originid=' . $object->id .
'&socid=' . $object->socid .
'">' . $langs->trans(
'AddContract') .
'</a>';
5459 if ($usercanvalidate) {
5460 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
5465 if (empty($user->socid)) {
5467 if ($objectidnext) {
5468 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'SendMail').
'</span>';
5471 print
dolGetButtonAction($langs->trans(
'SendMail'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
5473 print
dolGetButtonAction($langs->trans(
'SendMail'),
'',
'default',
'#',
'',
false, $params);
5481 if ($resteapayer > 0) {
5482 if ($usercancreatewithdrarequest) {
5483 if (!$objectidnext && $object->close_code !=
'replaced') {
5484 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/facture/prelevement.php?facid='.$object->id.
'" title="'.
dol_escape_htmltag($langs->trans(
"MakeWithdrawRequest")).
'">'.$langs->trans(
"MakeWithdrawRequest").
'</a>';
5486 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
5497 if (
isModEnabled(
'takepos') && $object->module_source ==
'takepos') {
5498 $langs->load(
"cashdesk");
5499 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
5500 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int) $object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
5505 if ($objectidnext) {
5506 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
5510 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
5511 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
5515 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default', DOL_URL_ROOT.
'/compta/paiement.php?facid='.$object->id.
'&action=create&accountid='.$object->fk_account,
'',
true, $params);
5520 $sumofpayment = $totalpaid;
5521 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
5527 if ($resteapayer == 0) {
5528 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
5530 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.$object->id.
'&action=create&accountid='.$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
5536 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
5540 && (!empty($conf->global->INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) || $sumofpayment == 0)
5542 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc" title="'.
dol_escape_htmltag($langs->trans(
"ConfirmConvertToReduc2")).
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
5548 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertToReduc').
'</a>';
5550 print
'<span class="butActionRefused" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
5564 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
5565 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
5567 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=paid',
'',
true, $params);
5572 if ($object->statut ==
Facture::STATUS_VALIDATED && $object->paye == 0 && $resteapayer > 0 && (empty($conf->global->INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $resteapayer != $object->total_ttc) && $usercanissuepayment) {
5573 if ($totalpaid > 0 || $totalcreditnotes > 0) {
5575 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
5577 if (empty($conf->global->INVOICE_CAN_NEVER_BE_CANCELED)) {
5578 if ($objectidnext) {
5579 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
5581 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
5589 if (!$objectidnext) {
5590 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?socid='.$object->socid.
'&fac_avoir='.$object->id.
'&action=create&type=2'.($object->fk_project > 0 ?
'&projectid='.$object->fk_project :
'').($object->entity > 0 ?
'&originentity='.$object->entity :
'').
'">'.$langs->trans(
"CreateCreditNote").
'</a>';
5597 && ($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
5600 && $object->is_last_in_cycle()
5601 && $conf->global->INVOICE_USE_SITUATION_CREDIT_NOTE
5603 if ($usercanunvalidate) {
5604 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?socid='.$object->socid.
'&fac_avoir='.$object->id.
'&invoiceAvoirWithLines=1&action=create&type=2'.($object->fk_project > 0 ?
'&projectid='.$object->fk_project :
'').
'">'.$langs->trans(
"CreateCreditNote").
'</a>';
5606 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
5612 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=clone&object=invoice',
'',
true, $params);
5617 if (!$objectidnext && count($object->lines) > 0) {
5618 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$object->id.
'&action=create',
'',
true, $params);
5627 && $object->situation_counter > 1
5628 && $object->is_last_in_cycle()
5629 && $usercanunvalidate
5631 if (($object->total_ttc - $totalcreditnotes) == 0) {
5632 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
5634 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
5639 if ($usercancreate && ($object->type == 5) && ($object->statut == 1 || $object->statut == 2)) {
5640 if ($object->is_last_in_cycle() && $object->situation_final != 1) {
5641 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.$object->id.
'&socid='.$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5642 } elseif (!$object->is_last_in_cycle()) {
5643 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5645 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5650 $isErasable = $object->is_erasable();
5654 'class' =>
'classfortooltip'
5657 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
5658 $enableDelete =
false;
5660 if ($isErasable == -4) {
5661 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecausePayments');
5662 } elseif ($isErasable == -3) {
5663 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
5664 } elseif ($isErasable == -2) {
5665 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseNotLastInvoice');
5666 } elseif ($isErasable == -1) {
5667 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5668 } elseif ($isErasable <= 0) {
5669 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseNotErasable');
5670 } elseif ($objectidnext) {
5671 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
5673 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=delete&token='.
newToken();
5674 $enableDelete =
true;
5676 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $deleteHref,
'', $enableDelete, $params);
5678 $params[
'attr'][
'title'] = $langs->trans(
'NotAllowed');
5679 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete',
'#',
'',
false, $params);
5686 if (
GETPOST(
'modelselected',
'alpha')) {
5687 $action =
'presend';
5689 if ($action !=
'prerelance' && $action !=
'presend') {
5690 print
'<div class="fichecenter"><div class="fichehalfleft">';
5691 print
'<a name="builddoc"></a>';
5695 $filedir = $conf->facture->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($object->ref);
5696 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.$object->id;
5697 $genallowed = $usercanread;
5698 $delallowed = $usercancreate;
5700 print $formfile->showdocuments(
5720 'remove_file_comfirm'
5723 $somethingshown = $formfile->numoffiles;
5726 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'invoice'));
5728 $compatibleImportElementsList =
false;
5732 $compatibleImportElementsList = array(
'commande',
'propal');
5734 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
5738 $useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled));
5741 print
'<br><!-- Link to pay -->'.
"\n";
5742 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
5743 print showOnlinePaymentUrl(
'invoice', $object->ref).
'<br>';
5746 print
'</div><div class="fichehalfright">';
5749 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
5751 $somethingshown =
$formactions->showactions($object,
'invoice', $socid, 1);
5753 print
'</div></div>';
5758 $modelmail =
'facture_send';
5759 $defaulttopic =
'SendBillRef';
5760 $diroutput = $conf->facture->multidir_output[$object->entity];
5761 $trackid =
'inv'.$object->id;
5763 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';