42require
'../../main.inc.php';
43require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
55require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
56if (isModEnabled(
'commande')) {
57 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
59if (isModEnabled(
'project')) {
60 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
61 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
63require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
65if (isModEnabled(
'variants')) {
66 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
68if (isModEnabled(
'accounting')) {
69 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
73$langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
74if (isModEnabled(
'incoterm')) {
75 $langs->load(
'incoterm');
77if (isModEnabled(
'margin')) {
78 $langs->load(
'margins');
84$socid =
GETPOST(
'socid',
'int');
85$action =
GETPOST(
'action',
'aZ09');
86$confirm =
GETPOST(
'confirm',
'alpha');
87$cancel =
GETPOST(
'cancel',
'alpha');
88$backtopage =
GETPOST(
'backtopage',
'alpha');
89$lineid =
GETPOST(
'lineid',
'int');
90$userid =
GETPOST(
'userid',
'int');
91$search_ref =
GETPOST(
'sf_ref',
'alpha') ?
GETPOST(
'sf_ref',
'alpha') :
GETPOST(
'search_ref',
'alpha');
92$search_societe =
GETPOST(
'search_societe',
'alpha');
93$search_montant_ht =
GETPOST(
'search_montant_ht',
'alpha');
94$search_montant_ttc =
GETPOST(
'search_montant_ttc',
'alpha');
95$origin =
GETPOST(
'origin',
'alpha');
97$fac_rec =
GETPOST(
'fac_rec',
'int');
98$facid =
GETPOST(
'facid',
'int');
99$ref_client =
GETPOST(
'ref_client',
'alpha');
100$rank = (
GETPOST(
'rank',
'int') > 0) ?
GETPOST(
'rank',
'int') : -1;
101$projectid = (
GETPOST(
'projectid',
'int') ?
GETPOST(
'projectid',
'int') : 0);
102$selectedLines =
GETPOST(
'toselect',
'array');
112$usehm = (
getDolGlobalString(
'MAIN_USE_HOURMIN_IN_DATE_RANGE') ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : 0);
118$extrafields->fetch_name_optionals_label($object->table_element);
121if ($id > 0 || !empty($ref)) {
122 if ($action !=
'add') {
124 $fetch_situation =
false;
126 $fetch_situation =
true;
128 $ret = $object->fetch($id, $ref,
'',
'', $fetch_situation);
129 if ($ret > 0 && isset($object->fk_project)) {
130 $ret = $object->fetch_project();
136$hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
139$usercanread = $user->hasRight(
"facture",
"lire");
140$usercancreate = $user->hasRight(
"facture",
"creer");
141$usercanissuepayment = $user->hasRight(
"facture",
"paiement");
142$usercandelete = $user->hasRight(
"facture",
"supprimer");
143$usercancreatecontract = $user->hasRight(
"contrat",
"creer");
146$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->facture->invoice_advance->validate)));
148$usercanreopen = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->facture->invoice_advance->reopen)));
150 $usercanreopen =
false;
152$usercanunvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->facture->invoice_advance->unvalidate)));
154$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && empty($user->rights->produit->ignore_price_min_advance)) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
155$usercancreatemargin = (!empty($user->rights->margins->creer) ? $user->rights->margins->creer : 0);
156$usercanreadallmargin = (!empty($user->rights->margins->liretous) ? $user->rights->margins->liretous : 0);
157$usercancreatewithdrarequest = (!empty($user->rights->prelevement->bons->creer) ? $user->rights->prelevement->bons->creer : 0);
159$permissionnote = $usercancreate;
160$permissiondellink = $usercancreate;
161$permissiontoedit = $usercancreate;
162$permissiontoadd = $usercancreate;
165$retainedWarrantyInvoiceAvailableType = array();
167 $retainedWarrantyInvoiceAvailableType = explode(
'+',
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY'));
172 $socid = $user->socid;
176$result =
restrictedArea($user,
'facture', $object->id,
'',
'',
'fk_soc',
'rowid', $isdraft);
183$parameters = array(
'socid' => $socid);
184$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
189if (empty($reshook)) {
190 $backurlforlist = DOL_URL_ROOT.
'/compta/facture/list.php';
192 if (empty($backtopage) || ($cancel && empty($id))) {
193 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
194 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
195 $backtopage = $backurlforlist;
197 $backtopage = DOL_URL_ROOT.
'/compta/facture/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
203 if (!empty($backtopageforcancel)) {
204 header(
"Location: ".$backtopageforcancel);
206 } elseif (!empty($backtopage)) {
207 header(
"Location: ".$backtopage);
213 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
215 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
217 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
220 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
224 $objectutil->socid = $socid;
225 $result = $objectutil->createFromClone($user, $id);
227 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?facid='.$result);
230 $langs->load(
"errors");
234 } elseif ($action ==
'reopen' && $usercanreopen) {
235 $result = $object->fetch($id);
238 $result = $object->setUnpaid($user);
240 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
246 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
248 $result = $object->fetch($id);
249 $object->fetch_thirdparty();
251 $idwarehouse =
GETPOST(
'idwarehouse');
253 $qualified_for_stock_change = 0;
255 $qualified_for_stock_change = $object->hasProductsOrServices(2);
257 $qualified_for_stock_change = $object->hasProductsOrServices(1);
260 $isErasable = $object->is_erasable();
262 if (($usercandelete && $isErasable > 0)
263 || ($usercancreate && $isErasable == 1)) {
264 $result = $object->delete($user, 0, $idwarehouse);
266 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
273 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
276 $object->fetch_thirdparty();
278 $result = $object->deleteline(
GETPOST(
'lineid',
'int'));
281 $object->line_order(
true);
283 $outputlangs = $langs;
289 $newlang = $object->thirdparty->default_lang;
291 if (!empty($newlang)) {
293 $outputlangs->setDefaultLang($newlang);
294 $outputlangs->load(
'products');
297 $ret = $object->fetch($id);
298 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
301 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
308 } elseif ($action ==
'unlinkdiscount' && $usercancreate) {
311 $result = $discount->fetch(
GETPOSTINT(
"discountid"));
312 $discount->unlink_invoice();
313 } elseif ($action ==
'valid' && $usercancreate) {
317 if ((preg_match(
'/^[\(]?PROV/i', $object->ref) || empty($object->ref)) &&
324 $last_of_type = $object->willBeLastOfSameType(
true);
325 if (empty($object->date_validation) && !$last_of_type[0]) {
334 if ($object->total_ht > 0) {
335 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"),
null,
'errors');
344 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"),
null,
'errors');
353 $array_of_total_ht_per_vat_rate = array();
354 $array_of_total_ht_devise_per_vat_rate = array();
355 foreach ($object->lines as $line) {
357 $vat_src_code_for_line =
'';
358 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
359 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
361 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) {
362 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
364 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
365 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
369 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) {
370 $tmp_total_ht =
price2num($array_of_total_ht_per_vat_rate[$vatrate]);
371 $tmp_total_ht_devise =
price2num($array_of_total_ht_devise_per_vat_rate[$vatrate]);
373 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
374 if ($object->type == $object::TYPE_DEPOSIT) {
375 $langs->load(
"errors");
377 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
381 $tmpvatratetoshow = explode(
'_', $vatrate);
382 $tmpvatratetoshow[0] = round($tmpvatratetoshow[0], 2);
384 if ($tmpvatratetoshow[0] != 0) {
385 $langs->load(
"errors");
386 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", $tmpvatratetoshow[0]),
null,
'errors');
394 } elseif ($action ==
'classin' && $usercancreate) {
396 $object->setProject(
GETPOST(
'projectid',
'int'));
397 } elseif ($action ==
'setmode' && $usercancreate) {
399 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
403 } elseif ($action ==
'setretainedwarrantyconditions' && $user->hasRight(
'facture',
'creer')) {
405 $object->retained_warranty_fk_cond_reglement = 0;
406 $result = $object->setRetainedWarrantyPaymentTerms(
GETPOST(
'retained_warranty_fk_cond_reglement',
'int'));
411 $old_rw_date_lim_reglement = $object->retained_warranty_date_limit;
412 $new_rw_date_lim_reglement = $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement);
413 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) {
414 $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
416 if ($object->retained_warranty_date_limit < $object->date) {
417 $object->retained_warranty_date_limit = $object->date;
419 $result = $object->update($user);
423 } elseif ($action ==
'setretainedwarranty' && $user->hasRight(
'facture',
'creer')) {
425 $result = $object->setRetainedWarranty(
GETPOST(
'retained_warranty',
'float'));
429 } elseif ($action ==
'setretainedwarrantydatelimit' && $user->hasRight(
'facture',
'creer')) {
431 $result = $object->setRetainedWarrantyDateLimit(
GETPOST(
'retained_warranty_date_limit',
'float'));
435 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
436 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
437 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
438 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
439 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
441 $old_date_lim_reglement = $object->date_lim_reglement;
443 if (empty($newdate)) {
444 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
445 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id.
'&action=editinvoicedate&token='.newToken());
448 if ($newdate > (
dol_now(
'tzuserrel') + (!
getDolGlobalString(
'INVOICE_MAX_FUTURE_DELAY') ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
450 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
452 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
456 $object->date = $newdate;
457 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
458 if ($new_date_lim_reglement) {
459 $object->date_lim_reglement = $new_date_lim_reglement;
461 if ($object->date_lim_reglement < $object->date) {
462 $object->date_lim_reglement = $object->date;
464 $result = $object->update($user);
468 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
471 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
473 $object->date_pointoftax = $date_pointoftax;
474 $result = $object->update($user);
478 } elseif ($action ==
'setconditions' && $usercancreate) {
480 $object->cond_reglement_code = 0;
481 $object->cond_reglement_id = 0;
488 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
496 $old_date_lim_reglement = $object->date_lim_reglement;
497 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
498 if ($new_date_lim_reglement) {
499 $object->date_lim_reglement = $new_date_lim_reglement;
501 if ($object->date_lim_reglement < $object->date) {
502 $object->date_lim_reglement = $object->date;
504 $result = $object->update($user);
516 } elseif ($action ==
'setpaymentterm' && $usercancreate) {
518 $object->date_lim_reglement =
dol_mktime(12, 0, 0,
GETPOST(
'paymenttermmonth',
'int'),
GETPOST(
'paymenttermday',
'int'),
GETPOST(
'paymenttermyear',
'int'));
519 if ($object->date_lim_reglement < $object->date) {
520 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
521 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
523 $result = $object->update($user);
527 } elseif ($action ==
'setrevenuestamp' && $usercancreate) {
529 $object->revenuestamp =
GETPOST(
'revenuestamp');
530 $result = $object->update($user);
531 $object->update_price(1);
537 $outputlangs = $langs;
540 $newlang =
GETPOST(
'lang_id',
'aZ09');
543 $newlang = $object->thirdparty->default_lang;
545 if (!empty($newlang)) {
547 $outputlangs->setDefaultLang($newlang);
548 $outputlangs->load(
'products');
550 $model = $object->model_pdf;
551 $ret = $object->fetch($id);
553 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
559 } elseif ($action ==
'set_incoterms' && isModEnabled(
'incoterm')) {
560 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
561 } elseif ($action ==
'setbankaccount' && $usercancreate) {
562 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
563 } elseif ($action ==
'setremisepercent' && $usercancreate) {
565 $result = $object->setDiscount($user,
price2num(
GETPOST(
'remise_percent'),
'', 2));
566 } elseif ($action ==
"setabsolutediscount" && $usercancreate) {
571 if (
GETPOST(
"remise_id",
'int') > 0) {
572 $ret = $object->fetch($id);
574 $result = $object->insert_discount(
GETPOST(
"remise_id",
'int'));
584 if (
GETPOST(
"remise_id_for_payment",
'int') > 0) {
585 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
587 $discount->fetch(
GETPOST(
"remise_id_for_payment",
'int'));
591 $remaintopay = $object->getRemainToPay(0);
595 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"),
null,
'errors');
599 $result = $discount->link_to_invoice(0, $id);
607 $newremaintopay = $object->getRemainToPay(0);
608 if ($newremaintopay == 0) {
609 $object->setPaid($user);
621 $outputlangs = $langs;
624 $newlang =
GETPOST(
'lang_id',
'aZ09');
627 $object->fetch_thirdparty();
628 $newlang = $object->thirdparty->default_lang;
630 if (!empty($newlang)) {
632 $outputlangs->setDefaultLang($newlang);
634 $ret = $object->fetch($id);
636 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
641 } elseif ($action ==
'setref' && $usercancreate) {
643 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'',
null,
'',
'', $user,
'BILL_MODIFY');
644 } elseif ($action ==
'setref_client' && $usercancreate) {
646 $object->set_ref_client(
GETPOST(
'ref_client',
'alpha'));
647 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
649 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
652 $object->fetch_thirdparty();
656 $qualified_for_stock_change = 0;
658 $qualified_for_stock_change = $object->hasProductsOrServices(2);
660 $qualified_for_stock_change = $object->hasProductsOrServices(1);
663 if ($qualified_for_stock_change) {
664 if (!$idwarehouse || $idwarehouse == - 1) {
666 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
673 $result = $object->validate($user,
'', $idwarehouse);
677 $outputlangs = $langs;
680 $newlang =
GETPOST(
'lang_id',
'aZ09');
683 $newlang = $object->thirdparty->default_lang;
685 if (!empty($newlang)) {
687 $outputlangs->setDefaultLang($newlang);
688 $outputlangs->load(
'products');
690 $model = $object->model_pdf;
692 $ret = $object->fetch($id);
694 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
700 if (count($object->errors)) {
707 } elseif ($action ==
'confirm_modif' && $usercanunvalidate) {
709 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
712 $object->fetch_thirdparty();
716 $qualified_for_stock_change = 0;
718 $qualified_for_stock_change = $object->hasProductsOrServices(2);
720 $qualified_for_stock_change = $object->hasProductsOrServices(1);
723 if ($qualified_for_stock_change) {
724 if (!$idwarehouse || $idwarehouse == - 1) {
726 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
735 $sql =
'SELECT pf.amount';
736 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf';
737 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id);
739 $result = $db->query($sql);
742 $num = $db->num_rows($result);
745 $objp = $db->fetch_object($result);
746 $totalpaid += $objp->amount;
753 $resteapayer = $object->total_ttc - $totalpaid;
756 $ventilExportCompta = $object->getVentilExportCompta();
759 if ($ventilExportCompta == 0) {
760 if (
getDolGlobalString(
'INVOICE_CAN_BE_EDITED_EVEN_IF_PAYMENT_DONE') || ($resteapayer == $object->total_ttc && empty($object->paye))) {
761 $result = $object->setDraft($user, $idwarehouse);
768 $outputlangs = $langs;
771 $newlang =
GETPOST(
'lang_id',
'aZ09');
774 $newlang = $object->thirdparty->default_lang;
776 if (!empty($newlang)) {
778 $outputlangs->setDefaultLang($newlang);
779 $outputlangs->load(
'products');
781 $model = $object->model_pdf;
782 $ret = $object->fetch($id);
784 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
789 } elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment) {
792 $result = $object->setPaid($user);
796 } elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment) {
799 $close_code =
GETPOST(
"close_code",
'restricthtml');
800 $close_note =
GETPOST(
"close_note",
'restricthtml');
802 $result = $object->setPaid($user, $close_code, $close_note);
807 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
809 } elseif ($action ==
'confirm_canceled' && $confirm ==
'yes') {
812 $close_code =
GETPOST(
"close_code",
'restricthtml');
813 $close_note =
GETPOST(
"close_note",
'restricthtml');
815 $result = $object->setCanceled($user, $close_code, $close_note);
820 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")),
null,
'errors');
822 } elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate) {
825 $object->fetch_thirdparty();
830 $result = $discountcheck->fetch(0, $object->id);
843 $amount_ht = $amount_tva = $amount_ttc = array();
844 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
848 foreach ($object->lines as $line) {
849 if ($line->product_type < 9 && $line->total_ht != 0) {
850 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
852 $amount_ht[$keyforvatrate] += $line->total_ht;
853 $amount_tva[$keyforvatrate] += $line->total_tva;
854 $amount_ttc[$keyforvatrate] += $line->total_ttc;
855 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
856 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
857 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
864 $alreadypaid = $object->getSommePaiement();
865 if ($alreadypaid && abs($alreadypaid) < abs($object->total_ttc)) {
866 $ratio = abs(($object->total_ttc - $alreadypaid) / $object->total_ttc);
867 foreach ($amount_ht as $vatrate => $val) {
868 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
869 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
870 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
871 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
872 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
873 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
882 $discount->description =
'(CREDIT_NOTE)';
884 $discount->description =
'(DEPOSIT)';
886 $discount->description =
'(EXCESS RECEIVED)';
888 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'),
null,
'errors');
890 $discount->fk_soc = $object->socid;
891 $discount->fk_facture_source = $object->id;
899 $sql =
'SELECT SUM(pf.amount) as total_paiements';
900 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
901 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
902 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id);
903 $sql .=
' AND pf.fk_paiement = p.rowid';
904 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
905 $resql = $db->query($sql);
910 $res = $db->fetch_object($resql);
911 $total_paiements = $res->total_paiements;
914 $total_creditnote_and_deposit = 0;
915 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
916 $sql .=
" re.description, re.fk_facture_source";
917 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
918 $sql .=
" WHERE fk_facture = ".((int) $object->id);
919 $resql = $db->query($sql);
920 if (!empty($resql)) {
921 while ($obj = $db->fetch_object($resql)) {
922 $total_creditnote_and_deposit += $obj->amount_ttc;
928 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object->total_ttc;
929 $discount->amount_tva = 0;
930 $discount->tva_tx = 0;
931 $discount->vat_src_code =
'';
933 $result = $discount->create($user);
939 foreach ($amount_ht as $tva_tx => $xxx) {
940 $discount->amount_ht = abs($amount_ht[$tva_tx]);
941 $discount->amount_tva = abs($amount_tva[$tva_tx]);
942 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
943 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
944 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
945 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
950 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
951 $vat_src_code = $reg[1];
952 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
955 $discount->tva_tx = abs($tva_tx);
956 $discount->vat_src_code = $vat_src_code;
958 $result = $discount->create($user);
969 $result = $object->setPaid($user);
984 } elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
989 $result = $paiement->fetch(
GETPOST(
'paiement_id',
'int'));
991 $result = $paiement->delete();
993 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1001 } elseif ($action ==
'add' && $usercancreate) {
1004 $object->socid =
GETPOST(
'socid',
'int');
1007 if (
GETPOST(
'type',
'int') ===
'') {
1008 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1014 $originentity =
GETPOST(
'originentity');
1016 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1022 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
1026 if (empty($dateinvoice)) {
1028 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1036 if (!(
GETPOST(
'fac_replacement',
'int') > 0)) {
1038 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")),
null,
'errors');
1044 $result = $object->fetch(
GETPOST(
'fac_replacement',
'int'));
1045 $object->fetch_thirdparty();
1047 $object->date = $dateinvoice;
1048 $object->date_pointoftax = $date_pointoftax;
1049 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1050 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1051 $object->ref_client =
GETPOST(
'ref_client',
'alphanohtml');
1052 $object->ref_customer =
GETPOST(
'ref_client',
'alphanohtml');
1053 $object->model_pdf =
GETPOST(
'model',
'alphanohtml');
1054 $object->fk_project =
GETPOST(
'projectid',
'int');
1055 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1056 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1057 $object->fk_account =
GETPOST(
'fk_account',
'int');
1060 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1061 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1062 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1063 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1066 $object->fk_facture_source =
GETPOST(
'fac_replacement',
'int');
1069 $id = $object->createFromCurrent($user);
1078 $sourceinvoice =
GETPOST(
'fac_avoir',
'int');
1079 if (!($sourceinvoice > 0) && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) {
1081 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")),
null,
'errors');
1085 if (empty($dateinvoice)) {
1087 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1097 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1102 if (!empty($originentity)) {
1103 $object->entity = $originentity;
1105 $object->socid =
GETPOST(
'socid',
'int');
1106 $object->subtype =
GETPOST(
'subtype');
1107 $object->ref =
GETPOST(
'ref');
1108 $object->date = $dateinvoice;
1109 $object->date_pointoftax = $date_pointoftax;
1110 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1111 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1112 $object->ref_client =
GETPOST(
'ref_client',
'alphanohtml');
1113 $object->ref_customer =
GETPOST(
'ref_client',
'alphanohtml');
1114 $object->model_pdf =
GETPOST(
'model');
1115 $object->fk_project =
GETPOST(
'projectid',
'int');
1116 $object->cond_reglement_id = 0;
1117 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1118 $object->fk_account =
GETPOST(
'fk_account',
'int');
1121 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1122 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1123 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1124 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1127 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1130 $facture_source =
new Facture($db);
1131 if ($facture_source->fetch($object->fk_facture_source) > 0) {
1133 $object->situation_counter = $facture_source->situation_counter;
1134 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1135 $facture_source->fetchPreviousNextSituationInvoice();
1140 $id = $object->create($user);
1145 if ($object->copy_linked_contact($facture_source,
'internal') < 0) {
1147 } elseif ($facture_source->socid == $object->socid) {
1149 if ($object->copy_linked_contact($facture_source,
'external') < 0) {
1160 if (
GETPOST(
'invoiceAvoirWithLines',
'int') == 1 && $id > 0) {
1161 if (!empty($facture_source->lines)) {
1162 $fk_parent_line = 0;
1164 foreach ($facture_source->lines as $line) {
1166 if (method_exists($line,
'fetch_optionals')) {
1168 $line->fetch_optionals();
1172 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1173 $fk_parent_line = 0;
1178 $source_fk_prev_id = $line->fk_prev_id;
1179 $line->fk_prev_id = $line->id;
1181 if (!empty($facture_source->tab_previous_situation_invoice)) {
1184 $tab_jumped_credit_notes = array();
1185 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1186 $searchPreviousInvoice =
true;
1187 while ($searchPreviousInvoice) {
1188 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
1189 $searchPreviousInvoice =
false;
1193 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1199 $maxPrevSituationPercent = 0;
1200 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
1201 if ($prevLine->id == $source_fk_prev_id) {
1202 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1205 $line->total_ht = $line->total_ht - $prevLine->total_ht;
1206 $line->total_tva = $line->total_tva - $prevLine->total_tva;
1207 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
1208 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
1209 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
1211 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
1212 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
1213 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
1214 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
1219 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1224 $maxPrevSituationPercent = 0;
1225 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1226 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
1227 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
1228 $maxPrevSituationPercent = $prevLine->situation_percent;
1230 $line->total_ht -= $prevLine->total_ht;
1231 $line->total_tva -= $prevLine->total_tva;
1232 $line->total_ttc -= $prevLine->total_ttc;
1233 $line->total_localtax1 -= $prevLine->total_localtax1;
1234 $line->total_localtax2 -= $prevLine->total_localtax2;
1236 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1237 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1238 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1239 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1245 $line->situation_percent += $maxPrevSituationPercent;
1251 $line->fk_facture = $object->id;
1252 $line->fk_parent_line = $fk_parent_line;
1254 $line->subprice = -$line->subprice;
1255 $line->pa_ht = $line->pa_ht;
1256 $line->total_ht = -$line->total_ht;
1257 $line->total_tva = -$line->total_tva;
1258 $line->total_ttc = -$line->total_ttc;
1259 $line->total_localtax1 = -$line->total_localtax1;
1260 $line->total_localtax2 = -$line->total_localtax2;
1262 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1263 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1264 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1265 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1267 $line->context[
'createcreditnotefrominvoice'] = 1;
1268 $result = $line->insert(0, 1);
1270 $object->lines[] = $line;
1273 if ($result > 0 && $line->product_type == 9) {
1274 $fk_parent_line = $result;
1278 $object->update_price(1);
1282 if (
GETPOST(
'invoiceAvoirWithPaymentRestAmount',
'int') == 1 && $id > 0) {
1283 if ($facture_source->fetch($object->fk_facture_source) > 0) {
1284 $totalpaid = $facture_source->getSommePaiement();
1285 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1286 $totaldeposits = $facture_source->getSumDepositsUsed();
1287 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
1289 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 1, 0, 0, 0, 0, 0,
'',
'',
'TTC');
1294 if (!empty($object->fk_facture_source) && $id > 0) {
1295 $facture_source->fetch($object->fk_facture_source);
1296 $facture_source->fetchObjectLinked();
1298 if (!empty($facture_source->linkedObjectsIds)) {
1299 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1300 $object->add_object_linked($sourcetype, current($TIds));
1309 if (empty($dateinvoice)) {
1311 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1322 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1327 $object->socid =
GETPOST(
'socid',
'int');
1328 $object->type =
GETPOST(
'type');
1329 $object->subtype =
GETPOST(
'subtype');
1330 $object->ref =
GETPOST(
'ref');
1331 $object->date = $dateinvoice;
1332 $object->date_pointoftax = $date_pointoftax;
1333 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1334 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1335 $object->ref_customer =
GETPOST(
'ref_client');
1336 $object->ref_client = $object->ref_customer;
1337 $object->model_pdf =
GETPOST(
'model');
1338 $object->fk_project =
GETPOST(
'projectid',
'int');
1339 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
1340 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1341 $object->fk_account =
GETPOST(
'fk_account',
'int');
1345 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1346 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1347 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1348 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1351 $object->fac_rec =
GETPOST(
'fac_rec',
'int');
1353 $id = $object->create($user);
1359 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1360 $valuestandardinvoice =
price2num(str_replace(
'%',
'',
GETPOST(
'valuestandardinvoice',
'alpha')),
'MU');
1361 $valuedeposit =
price2num(str_replace(
'%',
'',
GETPOST(
'valuedeposit',
'alpha')),
'MU');
1363 if (
GETPOST(
'socid',
'int') < 1) {
1365 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
1369 if (empty($dateinvoice)) {
1371 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1381 if ($valuestandardinvoice < 0 || $valuestandardinvoice > 100) {
1382 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1387 if ($typeamount && !empty($origin) && !empty($originid)) {
1388 if ($typeamount ==
'amount' && $valuedeposit <= 0) {
1389 setEventMessages($langs->trans(
"ErrorAnAmountWithoutTaxIsRequired"),
null,
'errors');
1393 if ($typeamount ==
'variable' && $valuedeposit <= 0) {
1394 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1398 if ($typeamount ==
'variablealllines' && $valuedeposit <= 0) {
1399 setEventMessages($langs->trans(
"ErrorAPercentIsRequired"),
null,
'errors');
1409 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSubtype")),
null,
'errors');
1414 $object->socid =
GETPOST(
'socid',
'int');
1415 $object->type =
GETPOST(
'type');
1416 $object->subtype =
GETPOST(
'subtype');
1417 $object->ref =
GETPOST(
'ref');
1418 $object->date = $dateinvoice;
1419 $object->date_pointoftax = $date_pointoftax;
1420 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1421 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1422 $object->ref_client =
GETPOST(
'ref_client');
1423 $object->ref_customer =
GETPOST(
'ref_client');
1424 $object->model_pdf =
GETPOST(
'model');
1425 $object->fk_project =
GETPOST(
'projectid',
'int');
1426 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
1427 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
1428 $object->fk_account =
GETPOST(
'fk_account',
'int');
1432 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1433 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1434 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1435 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1438 $object->situation_counter = 1;
1439 $object->situation_final = 0;
1440 $object->situation_cycle_ref = $object->newCycle();
1443 if (in_array($object->type, $retainedWarrantyInvoiceAvailableType)) {
1444 $object->retained_warranty =
GETPOST(
'retained_warranty',
'int');
1445 $object->retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
1447 $object->retained_warranty = 0;
1448 $object->retained_warranty_fk_cond_reglement = 0;
1451 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1452 if (!empty($retained_warranty_date_limit) &&
dol_stringtotime($retained_warranty_date_limit)) {
1453 $object->retained_warranty_date_limit =
dol_stringtotime($retained_warranty_date_limit);
1455 $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);
1457 $object->fetch_thirdparty();
1460 if (!empty($origin) && !empty($originid)) {
1463 $element = $subelement = $origin;
1464 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1465 $element = $regs[1];
1466 $subelement = $regs[2];
1470 if ($element ==
'order') {
1471 $element = $subelement =
'commande';
1473 if ($element ==
'propal') {
1474 $element =
'comm/propal';
1475 $subelement =
'propal';
1477 if ($element ==
'contract') {
1478 $element = $subelement =
'contrat';
1480 if ($element ==
'inter') {
1481 $element = $subelement =
'ficheinter';
1483 if ($element ==
'shipping') {
1484 $element = $subelement =
'expedition';
1487 $object->origin = $origin;
1488 $object->origin_id = $originid;
1491 $object->linked_objects[$object->origin] = $object->origin_id;
1493 if ($object->origin ==
'shipping') {
1494 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1496 $exp->fetch($object->origin_id);
1497 $exp->fetchObjectLinked();
1498 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1499 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1500 $object->linked_objects[
'commande'] = $value;
1505 if (is_array($_POST[
'other_linked_objects']) && !empty($_POST[
'other_linked_objects'])) {
1506 $object->linked_objects = array_merge($object->linked_objects, $_POST[
'other_linked_objects']);
1509 $id = $object->create($user);
1514 $classname = ucfirst($subelement);
1515 $srcobject =
new $classname($db);
1517 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines or deposit lines");
1518 $result = $srcobject->fetch($object->origin_id);
1523 $amountdeposit = array();
1525 if ($typeamount ==
'amount') {
1526 $amount = $valuedeposit;
1528 $amount = $srcobject->total_ttc * ($valuedeposit / 100);
1531 $TTotalByTva = array();
1532 foreach ($srcobject->lines as &$line) {
1533 if (!empty($line->special_code)) {
1536 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1539 foreach ($TTotalByTva as $tva => &$total) {
1540 if (empty($amountdeposit[$tva])) {
1541 $amountdeposit[$tva] = 0;
1543 $coef = $total / $srcobject->total_ttc;
1544 $am = $amount * $coef;
1545 $amount_ttc_diff += $am;
1546 $amountdeposit[$tva] += $am / (1 + $tva / 100);
1549 if ($typeamount ==
'amount') {
1550 $amountdeposit[0] = $valuedeposit;
1551 } elseif ($typeamount ==
'variable') {
1554 $lines = $srcobject->lines;
1555 $numlines = count($lines);
1556 for ($i = 0; $i < $numlines; $i++) {
1558 if (empty($lines[$i]->qty)) {
1561 if (!empty($lines[$i]->special_code)) {
1565 $totalamount += $lines[$i]->total_ht;
1566 $tva_tx = $lines[$i]->tva_tx;
1567 if (empty($amountdeposit[$tva_tx])) {
1568 $amountdeposit[$tva_tx] = 0;
1570 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $valuedeposit) / 100;
1574 if ($totalamount == 0) {
1575 $amountdeposit[0] = 0;
1583 $amount_ttc_diff = $amountdeposit[0];
1586 foreach ($amountdeposit as $tva => $amount) {
1587 if (empty($amount)) {
1592 'amount' =>
'FixAmount',
1593 'variable' =>
'VarAmount'
1595 $descline =
'(DEPOSIT)';
1597 if ($typeamount ==
'amount') {
1598 $descline .=
' ('.price($valuedeposit,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
')';
1599 } elseif ($typeamount ==
'variable') {
1600 $descline .=
' ('.$valuedeposit.
'%)';
1603 $descline .=
' - '.$srcobject->ref;
1604 $result = $object->addline(
1611 (!
getDolGlobalString(
'INVOICE_PRODUCTID_DEPOSIT') ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT),
1616 $lines[$i]->info_bits,
1622 $lines[$i]->special_code,
1635 (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)?0:1)
1639 $diff = $object->total_ttc - $amount_ttc_diff;
1642 $object->fetch_lines();
1643 $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100);
1644 $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);
1651 $lines = $srcobject->lines;
1652 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1653 $srcobject->fetch_lines();
1654 $lines = $srcobject->lines;
1659 if (is_array($lines)) {
1660 foreach ($lines as $line) {
1662 $line->qty =
price2num($line->qty * $valuestandardinvoice / 100,
'MS');
1668 if (is_array($lines)) {
1669 foreach ($lines as $line) {
1671 $line->qty =
price2num($line->qty * $valuedeposit / 100,
'MS');
1676 $fk_parent_line = 0;
1677 $num = count($lines);
1679 for ($i = 0; $i < $num; $i++) {
1680 if (!in_array($lines[$i]->
id, $selectedLines)) {
1685 if ($srcobject->element ==
'shipping' &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS') && $lines[$i]->qty == 0) {
1689 if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) {
1690 $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1692 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->
statut, explode(
',',
getDolGlobalString(
'CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE')))) {
1696 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1697 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1698 if ($object->situation_counter == 1) {
1699 $lines[$i]->situation_percent = 0;
1702 if ($lines[$i]->subprice < 0 && !
getDolGlobalString(
'INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
1705 $desc = $label ? $label : $langs->trans(
'Discount');
1709 $discount->fk_soc = $object->socid;
1710 $discount->amount_ht = abs($lines[$i]->total_ht);
1711 $discount->amount_tva = abs($lines[$i]->total_tva);
1712 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1713 $discount->tva_tx = $lines[$i]->tva_tx;
1714 $discount->fk_user = $user->id;
1715 $discount->description = $desc;
1716 $discount->multicurrency_subprice = abs($lines[$i]->multicurrency_subprice);
1717 $discount->multicurrency_amount_ht = abs($lines[$i]->multicurrency_total_ht);
1718 $discount->multicurrency_amount_tva = abs($lines[$i]->multicurrency_total_tva);
1719 $discount->multicurrency_amount_ttc = abs($lines[$i]->multicurrency_total_ttc);
1721 $discountid = $discount->create($user);
1722 if ($discountid > 0) {
1723 $result = $object->insert_discount($discountid);
1735 $date_start =
false;
1736 if ($lines[$i]->date_debut_prevue) {
1737 $date_start = $lines[$i]->date_debut_prevue;
1739 if ($lines[$i]->date_debut_reel) {
1740 $date_start = $lines[$i]->date_debut_reel;
1742 if ($lines[$i]->date_start) {
1743 $date_start = $lines[$i]->date_start;
1748 if ($lines[$i]->date_fin_prevue) {
1749 $date_end = $lines[$i]->date_fin_prevue;
1751 if ($lines[$i]->date_fin_reel) {
1752 $date_end = $lines[$i]->date_fin_reel;
1754 if ($lines[$i]->date_end) {
1755 $date_end = $lines[$i]->date_end;
1759 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1760 $fk_parent_line = 0;
1764 if (method_exists($lines[$i],
'fetch_optionals')) {
1765 $lines[$i]->fetch_optionals();
1766 $array_options = $lines[$i]->array_options;
1769 $tva_tx = $lines[$i]->tva_tx;
1770 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
1771 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1776 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty);
1777 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty);
1779 $result = $object->addline(
1781 $lines[$i]->subprice,
1786 $lines[$i]->fk_product,
1787 $lines[$i]->remise_percent,
1791 $lines[$i]->info_bits,
1792 $lines[$i]->fk_remise_except,
1797 $lines[$i]->special_code,
1801 $lines[$i]->fk_fournprice,
1805 $lines[$i]->situation_percent ?? 100,
1806 $lines[$i]->fk_prev_id ?? 0,
1807 $lines[$i]->fk_unit,
1822 if ($result > 0 && $lines[$i]->product_type == 9) {
1823 $fk_parent_line = $result;
1833 $object->update_price(1,
'auto', 0, $mysoc);
1862 $parameters = array(
'objFrom' => $srcobject);
1863 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1874 $id = $object->create($user);
1876 for ($i = 1; $i <= $NBLINES; $i++) {
1877 if (
GETPOST(
'idprod'.$i,
'int')) {
1879 $product->fetch(
GETPOST(
'idprod'.$i,
'int'));
1882 $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);
1886 $object->update_price(1,
'auto', 0, $mysoc);
1893 if (empty($dateinvoice)) {
1895 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
1903 if (!(
GETPOST(
'situations',
'int') > 0)) {
1905 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
1911 $result = $object->fetch(
GETPOST(
'situations',
'int'));
1912 $object->fk_facture_source =
GETPOST(
'situations',
'int');
1915 if (!empty($origin) && !empty($originid)) {
1916 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1918 $object->origin = $origin;
1919 $object->origin_id = $originid;
1923 $retained_warranty =
GETPOST(
'retained_warranty',
'int');
1924 if (
price2num($retained_warranty) > 0) {
1925 $object->retained_warranty =
price2num($retained_warranty);
1928 if (
GETPOST(
'retained_warranty_fk_cond_reglement',
'int') > 0) {
1929 $object->retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
1932 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1933 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
1934 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
1936 $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);
1939 foreach ($object->lines as $i => &$line) {
1940 $line->origin = $object->origin;
1941 $line->origin_id = $line->id;
1942 $line->fk_prev_id = $line->id;
1943 $line->fetch_optionals();
1944 $line->situation_percent = $line->get_prev_progress($object->id);
1947 $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);
1948 $line->total_ht = $tabprice[0];
1949 $line->total_tva = $tabprice[1];
1950 $line->total_ttc = $tabprice[2];
1951 $line->total_localtax1 = $tabprice[9];
1952 $line->total_localtax2 = $tabprice[10];
1953 $line->multicurrency_total_ht = $tabprice[16];
1954 $line->multicurrency_total_tva = $tabprice[17];
1955 $line->multicurrency_total_ttc = $tabprice[18];
1958 if ($line->fk_remise_except) {
1960 $result = $discount->fetch($line->fk_remise_except);
1963 if ($discount->fk_facture_line > 0) {
1964 $line->fk_remise_except = 0;
1971 $object->fetch_thirdparty();
1972 $object->date = $dateinvoice;
1973 $object->date_pointoftax = $date_pointoftax;
1974 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1975 $object->note = trim(
GETPOST(
'note',
'restricthtml'));
1976 $object->note_private = trim(
GETPOST(
'note',
'restricthtml'));
1977 $object->ref_client =
GETPOST(
'ref_client',
'alpha');
1978 $object->model_pdf =
GETPOST(
'model',
'alpha');
1979 $object->fk_project =
GETPOST(
'projectid',
'int');
1980 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1981 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1984 $object->fk_account =
GETPOST(
'fk_account',
'int');
1989 $object->situation_counter = $object->situation_counter + 1;
1990 $id = $object->createFromCurrent($user);
1992 $mesg = $object->error;
1994 $nextSituationInvoice =
new Facture($db);
1995 $nextSituationInvoice->fetch($id);
1998 $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
1999 $ret = $extrafields->setOptionalsFromPost(
null, $nextSituationInvoice);
2001 $nextSituationInvoice->insertExtraFields();
2008 if ($id > 0 && !$error) {
2013 $outputlangs = $langs;
2016 $newlang =
GETPOST(
'lang_id',
'aZ09');
2019 $newlang = $object->thirdparty->default_lang;
2021 if (!empty($newlang)) {
2022 $outputlangs =
new Translate(
"", $conf);
2023 $outputlangs->setDefaultLang($newlang);
2024 $outputlangs->load(
'products');
2026 $model = $object->model_pdf;
2027 $ret = $object->fetch($id);
2029 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2035 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2040 $_GET[
"origin"] = $_POST[
"origin"];
2041 $_GET[
"originid"] = $_POST[
"originid"];
2044 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'') {
2046 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
2047 $vat_rate = str_replace(
'*',
'', $vat_rate);
2048 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
2049 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
2050 foreach ($object->lines as $line) {
2051 $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);
2053 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
2055 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
2056 $remise_percent = str_replace(
'*',
'', $remise_percent);
2057 foreach ($object->lines as $line) {
2058 $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);
2060 } elseif ($action ==
'addline' && $usercancreate) {
2061 $langs->load(
'errors');
2066 $product_desc =(GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
2069 $price_ht_devise =
'';
2071 $price_ttc_devise =
'';
2073 $price_min_ttc =
'';
2075 if (
GETPOST(
'price_ht') !==
'') {
2078 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
2081 if (
GETPOST(
'price_ttc') !==
'') {
2084 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
2085 $price_ttc_devise =
price2num(
GETPOST(
'multicurrency_price_ttc'),
'CU', 2);
2088 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
2089 if ($prod_entry_mode ==
'free') {
2092 $idprod =
GETPOST(
'idprod',
'int');
2095 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
2100 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
2103 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
2104 if (empty($remise_percent)) {
2105 $remise_percent = 0;
2109 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
2110 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
2112 if (is_array($extralabelsline)) {
2114 foreach ($extralabelsline as $key => $value) {
2115 unset($_POST[
"options_".$key.$predef]);
2119 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
2120 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2123 if (!$prod_entry_mode) {
2125 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'),
null,
'errors');
2129 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
2130 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
2133 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && (($price_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht ==
'') && (($price_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise ==
'') && $price_ttc ===
'' && $price_ttc_devise ===
'' && $object->type !=
Facture::TYPE_CREDIT_NOTE) {
2134 if (($price_ht < 0 || $price_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2135 $langs->load(
"errors");
2136 if ($object->type == $object::TYPE_DEPOSIT) {
2138 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2140 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2144 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2149 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
2152 if ($prod_entry_mode ==
'free' && empty($idprod) && empty($product_desc)) {
2153 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
2157 $langs->load(
"errors");
2158 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2162 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
2163 if ($combinations =
GETPOST(
'combinations',
'array')) {
2167 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
2168 $idprod = $res->fk_product_child;
2170 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
2176 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
2177 $ret = $object->fetch($id);
2182 $ret = $object->fetch_thirdparty();
2187 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2198 if (!empty($idprod) && $idprod > 0) {
2200 $prod->fetch($idprod);
2202 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2207 $datapriceofproduct = $prod->getSellPrice($mysoc, $object->thirdparty, $pqp);
2209 $pu_ht = $datapriceofproduct[
'pu_ht'];
2210 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2211 $price_min = $datapriceofproduct[
'price_min'];
2212 $price_min_ttc = (isset($datapriceofproduct[
'price_min_ttc'])) ? $datapriceofproduct[
'price_min_ttc'] : null;
2213 $price_base_type = empty($datapriceofproduct[
'price_base_type']) ?
'HT' : $datapriceofproduct[
'price_base_type'];
2217 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2218 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
2222 if (!empty($price_ht) || $price_ht ===
'0') {
2224 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2225 } elseif (!empty($price_ht_devise) || $price_ht_devise ===
'0') {
2226 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2229 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
2231 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2232 } elseif ($tmpvat != $tmpprodvat) {
2234 if ($price_base_type !=
'HT') {
2235 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2237 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2245 $outputlangs = $langs;
2247 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
2248 $newlang =
GETPOST(
'lang_id',
'aZ09');
2250 if (empty($newlang)) {
2251 $newlang = $object->thirdparty->default_lang;
2253 if (!empty($newlang)) {
2254 $outputlangs =
new Translate(
"", $conf);
2255 $outputlangs->setDefaultLang($newlang);
2256 $outputlangs->load(
'products');
2259 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->
description;
2261 $desc = $prod->description;
2270 $desc = $product_desc;
2276 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
2280 $outputlangs = $langs;
2282 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
2283 $newlang =
GETPOST(
'lang_id',
'alpha');
2285 if (empty($newlang)) {
2286 $newlang = $object->thirdparty->default_lang;
2288 if (!empty($newlang)) {
2289 $outputlangs =
new Translate(
"", $conf);
2290 $outputlangs->setDefaultLang($newlang);
2291 $outputlangs->load(
'products');
2293 if (!empty($prod->customcode)) {
2294 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2296 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2299 if (!empty($prod->country_code)) {
2300 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
2303 if (!empty($prod->customcode)) {
2304 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2306 if (!empty($prod->customcode) && !empty($prod->country_code)) {
2309 if (!empty($prod->country_code)) {
2310 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
2317 $type = $prod->type;
2318 $fk_unit = $prod->fk_unit;
2320 if (!empty($price_ht)) $pu_ht =
price2num($price_ht,
'MU');
2322 if (!empty($price_ttc)) $pu_ttc =
price2num($price_ttc,
'MU');
2324 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2325 $tva_tx = str_replace(
'*',
'', $tva_tx);
2326 if (empty($tva_tx)) {
2329 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2330 $desc = $product_desc;
2332 $fk_unit =
GETPOST(
'units',
'alpha');
2334 if ($pu_ttc && !$pu_ht) {
2335 $price_base_type =
'TTC';
2346 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
2347 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
2349 $pu_ht_devise =
price2num($price_ht_devise,
'', 2);
2350 $pu_ttc_devise =
price2num($price_ttc_devise,
'', 2);
2353 $pu_equivalent = $pu_ht;
2354 $pu_equivalent_ttc = $pu_ttc;
2356 $currency_tx = $object->multicurrency_tx;
2360 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2361 $pu_equivalent = $pu_ht_devise * $currency_tx;
2363 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2364 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
2384 $price2num_remise_percent =
price2num($remise_percent);
2385 $price2num_price_min =
price2num($price_min);
2386 $price2num_price_min_ttc =
price2num($price_min_ttc);
2387 if (empty($price2num_pu_ht)) {
2388 $price2num_pu_ht = 0;
2390 if (empty($price2num_remise_percent)) {
2391 $price2num_remise_percent = 0;
2393 if (empty($price2num_price_min)) {
2394 $price2num_price_min = 0;
2396 if (empty($price2num_price_min_ttc)) {
2397 $price2num_price_min_ttc = 0;
2402 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min)) && $price_base_type ==
'HT') {
2403 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2406 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
2407 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2415 if (isModEnabled(
'productbatch') && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) &&
getDolGlobalString(
'INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS')) {
2416 $langs->load(
'productbatch');
2417 foreach ($lines[$i]->detail_batch as $batchline) {
2418 $desc .=
' '.$langs->trans(
'Batch').
' '.$batchline->batch.
' '.$langs->trans(
'printQty', $batchline->qty).
' ';
2423 $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);
2428 $outputlangs = $langs;
2431 $newlang =
GETPOST(
'lang_id',
'aZ09');
2434 $newlang = $object->thirdparty->default_lang;
2436 if (!empty($newlang)) {
2437 $outputlangs =
new Translate(
"", $conf);
2438 $outputlangs->setDefaultLang($newlang);
2439 $outputlangs->load(
'products');
2441 $model = $object->model_pdf;
2442 $ret = $object->fetch($id);
2444 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2450 unset($_POST[
'prod_entry_mode']);
2451 unset($_POST[
'qty']);
2452 unset($_POST[
'type']);
2453 unset($_POST[
'remise_percent']);
2454 unset($_POST[
'price_ht']);
2455 unset($_POST[
'multicurrency_price_ht']);
2456 unset($_POST[
'price_ttc']);
2457 unset($_POST[
'tva_tx']);
2458 unset($_POST[
'product_ref']);
2459 unset($_POST[
'product_label']);
2460 unset($_POST[
'product_desc']);
2461 unset($_POST[
'fournprice']);
2462 unset($_POST[
'buying_price']);
2463 unset($_POST[
'np_marginRate']);
2464 unset($_POST[
'np_markRate']);
2465 unset($_POST[
'dp_desc']);
2466 unset($_POST[
'idprod']);
2467 unset($_POST[
'units']);
2468 unset($_POST[
'date_starthour']);
2469 unset($_POST[
'date_startmin']);
2470 unset($_POST[
'date_startsec']);
2471 unset($_POST[
'date_startday']);
2472 unset($_POST[
'date_startmonth']);
2473 unset($_POST[
'date_startyear']);
2474 unset($_POST[
'date_endhour']);
2475 unset($_POST[
'date_endmin']);
2476 unset($_POST[
'date_endsec']);
2477 unset($_POST[
'date_endday']);
2478 unset($_POST[
'date_endmonth']);
2479 unset($_POST[
'date_endyear']);
2480 unset($_POST[
'situations']);
2481 unset($_POST[
'progress']);
2489 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
2490 if (!$object->fetch($id) > 0) {
2493 $object->fetch_thirdparty();
2502 $vat_rate = str_replace(
'*',
'', $vat_rate);
2514 if (preg_match(
'/\*/', $vat_rate)) {
2519 $vat_rate = str_replace(
'*',
'', $vat_rate);
2520 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty);
2521 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty);
2528 $pu_equivalent = $pu_ht;
2529 $pu_equivalent_ttc = $pu_ttc;
2531 $currency_tx = $object->multicurrency_tx;
2535 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
2536 $pu_equivalent = $pu_ht_devise * $currency_tx;
2538 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
2539 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
2554 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
2555 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
2557 if (is_array($extralabelsline)) {
2559 foreach ($extralabelsline as $key => $value) {
2560 unset($_POST[
"options_".$key]);
2565 $special_code =
GETPOST(
'special_code',
'int');
2566 if ($special_code == 3) {
2571 $line->fetch(
GETPOST(
'lineid',
'int'));
2572 $percent = $line->get_prev_progress($object->id);
2577 if ($progress >= 0) {
2578 $mesg = $langs->trans(
"CantBeNullOrPositive");
2582 } elseif ($progress < $line->situation_percent) {
2583 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
2587 } elseif ($progress < $percent) {
2588 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
2598 $productid =
GETPOST(
'productid',
'int');
2599 if (!empty($productid)) {
2601 $product->fetch($productid);
2603 $type = $product->type;
2605 $price_min = $product->price_min;
2607 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
2609 $price_min_ttc = $product->price_min_ttc;
2611 $price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
2618 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - (
float) $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
2619 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2622 $action =
'editline';
2623 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - (
float) $remise_percent / 100)) <
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
2624 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
2627 $action =
'editline';
2632 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2636 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
2641 $langs->load(
"errors");
2642 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'),
null,
'errors');
2645 if (empty($productid) && (($pu_ht < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $pu_ht ==
'') && (($pu_ht_devise < 0 && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) || $pu_ht_devise ==
'') && $pu_ttc ===
'' && $pu_ttc_devise ===
'' && $object->type !=
Facture::TYPE_CREDIT_NOTE) {
2646 if (($pu_ht < 0 || $pu_ttc < 0) && !
getDolGlobalString(
'FACTURE_ENABLE_NEGATIVE_LINES')) {
2647 $langs->load(
"errors");
2648 if ($object->type == $object::TYPE_DEPOSIT) {
2650 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"),
null,
'errors');
2652 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")),
null,
'errors');
2656 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
2664 if (empty($usercancreatemargin)) {
2665 foreach ($object->lines as &$line) {
2666 if ($line->id ==
GETPOST(
'lineid',
'int')) {
2667 $fournprice = $line->fk_fournprice;
2668 $buyingprice = $line->pa_ht;
2674 $price_base_type =
'HT';
2676 if (empty($pu) && !empty($pu_ttc)) {
2678 $price_base_type =
'TTC';
2681 $result = $object->updateline(
2695 GETPOST(
'fk_parent_line',
'int'),
2710 $outputlangs = $langs;
2713 $newlang =
GETPOST(
'lang_id',
'aZ09');
2716 $newlang = $object->thirdparty->default_lang;
2718 if (!empty($newlang)) {
2719 $outputlangs =
new Translate(
"", $conf);
2720 $outputlangs->setDefaultLang($newlang);
2721 $outputlangs->load(
'products');
2724 $ret = $object->fetch($id);
2725 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2728 unset($_POST[
'qty']);
2729 unset($_POST[
'type']);
2730 unset($_POST[
'productid']);
2731 unset($_POST[
'remise_percent']);
2732 unset($_POST[
'price_ht']);
2733 unset($_POST[
'multicurrency_price_ht']);
2734 unset($_POST[
'price_ttc']);
2735 unset($_POST[
'tva_tx']);
2736 unset($_POST[
'product_ref']);
2737 unset($_POST[
'product_label']);
2738 unset($_POST[
'product_desc']);
2739 unset($_POST[
'fournprice']);
2740 unset($_POST[
'buying_price']);
2741 unset($_POST[
'np_marginRate']);
2742 unset($_POST[
'np_markRate']);
2743 unset($_POST[
'dp_desc']);
2744 unset($_POST[
'idprod']);
2745 unset($_POST[
'units']);
2746 unset($_POST[
'date_starthour']);
2747 unset($_POST[
'date_startmin']);
2748 unset($_POST[
'date_startsec']);
2749 unset($_POST[
'date_startday']);
2750 unset($_POST[
'date_startmonth']);
2751 unset($_POST[
'date_startyear']);
2752 unset($_POST[
'date_endhour']);
2753 unset($_POST[
'date_endmin']);
2754 unset($_POST[
'date_endsec']);
2755 unset($_POST[
'date_endday']);
2756 unset($_POST[
'date_endmonth']);
2757 unset($_POST[
'date_endyear']);
2758 unset($_POST[
'situations']);
2759 unset($_POST[
'progress']);
2764 } elseif ($action ==
'updatealllines' && $usercancreate &&
GETPOST(
'all_percent') == $langs->trans(
'Modifier')) {
2765 if (!$object->fetch($id) > 0) {
2768 if (
GETPOST(
'all_progress') !=
"") {
2769 $all_progress =
GETPOST(
'all_progress',
'int');
2770 foreach ($object->lines as $line) {
2771 $percent = $line->get_prev_progress($object->id);
2772 if ((
float) $all_progress < (
float) $percent) {
2773 $mesg = $langs->trans(
"Line").
' '.$i.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
2777 $object->update_percent($line,
GETPOST(
'all_progress'),
false);
2780 $object->update_price(1);
2782 } elseif ($action ==
'updateline' && $usercancreate && !$cancel) {
2783 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2785 } elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate) {
2787 $object->fetch($id,
'',
'',
'',
true);
2793 && $object->is_last_in_cycle()
2794 && $usercanunvalidate
2797 $newCycle = $object->newCycle();
2798 if ($newCycle > 1) {
2800 $lastCycle = $object->situation_cycle_ref;
2801 $lastSituationCounter = $object->situation_counter;
2802 $linkedCreditNotesList = array();
2804 if (count($object->tab_next_situation_invoice) > 0) {
2805 foreach ($object->tab_next_situation_invoice as $next_invoice) {
2807 && $next_invoice->situation_counter == $object->situation_counter
2808 && $next_invoice->fk_facture_source == $object->id
2810 $linkedCreditNotesList[] = $next_invoice->id;
2815 $object->situation_cycle_ref = $newCycle;
2816 $object->situation_counter = 1;
2817 $object->situation_final = 0;
2818 if ($object->update($user) > 0) {
2820 if (count($linkedCreditNotesList) > 0) {
2822 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture';
2823 $sql .=
' SET situation_cycle_ref = '.((int) $newCycle);
2824 $sql .=
' , situation_final=0';
2825 $sql .=
' , situation_counter='.((int) $object->situation_counter);
2826 $sql .=
' WHERE rowid IN ('.$db->sanitize(implode(
',', $linkedCreditNotesList)).
')';
2828 $resql = $db->query($sql);
2834 foreach ($object->lines as $line) {
2836 if ($line->product_type == 9) {
2841 if (!empty($object->tab_previous_situation_invoice)) {
2843 $lineIndex = count($object->tab_previous_situation_invoice) - 1;
2844 $searchPreviousInvoice =
true;
2845 while ($searchPreviousInvoice) {
2847 $searchPreviousInvoice =
false;
2855 $maxPrevSituationPercent = 0;
2856 foreach ($object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
2857 if ($prevLine->id == $line->fk_prev_id) {
2858 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
2863 $line->situation_percent = $line->situation_percent - $maxPrevSituationPercent;
2865 if ($line->update() < 0) {
2874 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
2876 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
2879 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
2882 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
2885 } elseif ($action ==
'import_lines_from_object'
2890 $fromElement =
GETPOST(
'fromelement');
2891 $fromElementid =
GETPOST(
'fromelementid');
2892 $importLines =
GETPOST(
'line_checkbox');
2894 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
2895 if ($fromElement ==
'commande') {
2897 $lineClassName =
'OrderLine';
2898 } elseif ($fromElement ==
'propal') {
2899 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
2900 $lineClassName =
'PropaleLigne';
2902 $nextRang = count($object->lines) + 1;
2905 foreach ($importLines as $lineId) {
2906 $lineId = intval($lineId);
2907 $originLine =
new $lineClassName($db);
2908 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
2909 $originLine->fetch_optionals();
2910 $desc = $originLine->desc;
2911 $pu_ht = $originLine->subprice;
2912 $qty = $originLine->qty;
2913 $txtva = $originLine->tva_tx;
2914 $txlocaltax1 = $originLine->localtax1_tx;
2915 $txlocaltax2 = $originLine->localtax2_tx;
2916 $fk_product = $originLine->fk_product;
2917 $remise_percent = $originLine->remise_percent;
2918 $date_start = $originLine->date_start;
2919 $date_end = $originLine->date_end;
2921 $info_bits = $originLine->info_bits;
2922 $fk_remise_except = $originLine->fk_remise_except;
2923 $price_base_type =
'HT';
2925 $type = $originLine->product_type;
2926 $rang = $nextRang++;
2927 $special_code = $originLine->special_code;
2928 $origin = $originLine->element;
2929 $origin_id = $originLine->id;
2930 $fk_parent_line = 0;
2931 $fk_fournprice = $originLine->fk_fournprice;
2932 $pa_ht = $originLine->pa_ht;
2933 $label = $originLine->label;
2934 $array_options = $originLine->array_options;
2936 $situation_percent = 0;
2938 $situation_percent = 100;
2941 $fk_unit = $originLine->fk_unit;
2942 $pu_ht_devise = $originLine->multicurrency_subprice;
2944 $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);
2963 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2969 $triggersendname =
'BILL_SENTBYMAIL';
2971 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
2972 $trackid =
'inv'.$object->id;
2973 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2976 $upload_dir = $conf->facture->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity];
2977 $permissiontoadd = $usercancreate;
2978 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2981 if ($action ==
'update_extras') {
2982 $object->oldcopy =
dol_clone($object, 2);
2985 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
2992 $result = $object->insertExtraFields(
'BILL_MODIFY');
3000 $action =
'edit_extras';
3005 if ($action ==
'addcontact') {
3006 $result = $object->fetch($id);
3008 if ($result > 0 && $id > 0) {
3011 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
3015 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
3018 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
3019 $langs->load(
"errors");
3020 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
3025 } elseif ($action ==
'swapstatut') {
3027 if ($object->fetch($id)) {
3028 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
3032 } elseif ($action ==
'deletecontact') {
3034 $object->fetch($id);
3035 $result = $object->delete_contact($lineid);
3038 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
3046 $action =
'edit_extras';
3057$form =
new Form($db);
3063$bankaccountstatic =
new Account($db);
3064if (isModEnabled(
'project')) {
3070$title = $object->ref.
" - ".$langs->trans(
'Card');
3071if ($action ==
'create') {
3072 $title = $langs->trans(
"NewBill");
3074$help_url =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
3080if ($action ==
'create') {
3081 $facturestatic =
new Facture($db);
3082 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
3087 $res = $soc->fetch($socid);
3090 $currency_code = $conf->currency;
3092 $cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
3093 $mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
3094 $fk_account =
GETPOST(
'fk_account',
'int');
3098 if (!empty($origin) && !empty($originid)) {
3100 $element = $subelement = $origin;
3102 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
3103 $element = $regs[1];
3104 $subelement = $regs[2];
3107 if ($element ==
'project') {
3108 $projectid = $originid;
3110 if (empty($cond_reglement_id)) {
3111 $cond_reglement_id = $soc->cond_reglement_id;
3113 if (empty($mode_reglement_id)) {
3114 $mode_reglement_id = $soc->mode_reglement_id;
3116 if (empty($fk_account)) {
3117 $fk_account = $soc->fk_account;
3119 if (!$remise_percent) {
3120 $remise_percent = $soc->remise_percent;
3122 if (!$dateinvoice) {
3124 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3128 if ($element ==
'order' || $element ==
'commande') {
3129 $element = $subelement =
'commande';
3131 if ($element ==
'propal') {
3132 $element =
'comm/propal';
3133 $subelement =
'propal';
3135 if ($element ==
'contract') {
3136 $element = $subelement =
'contrat';
3138 if ($element ==
'shipping') {
3139 $element = $subelement =
'expedition';
3144 $classname = ucfirst($subelement);
3145 $objectsrc =
new $classname($db);
3146 $objectsrc->fetch($originid);
3147 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
3148 $objectsrc->fetch_lines();
3150 $objectsrc->fetch_thirdparty();
3152 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
3153 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
3156 if (empty($socid)) {
3157 $soc = $objectsrc->thirdparty;
3160 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3162 if ($element ==
'expedition') {
3163 $ref_client = (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
'');
3165 $elem = $subelem = $objectsrc->origin;
3166 $expeoriginid = $objectsrc->origin_id;
3168 $classname = ucfirst($subelem);
3170 $expesrc =
new $classname($db);
3171 $expesrc->fetch($expeoriginid);
3173 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
3174 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
3175 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
3179 if (isModEnabled(
'multicurrency')) {
3180 $currency_code = (!empty($expesrc->multicurrency_code) ? $expesrc->multicurrency_code : (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : $objectsrc->multicurrency_code));
3181 $currency_tx = (!empty($expesrc->multicurrency_tx) ? $expesrc->multicurrency_tx : (!empty($soc->multicurrency_tx) ? $soc->multicurrency_tx : $objectsrc->multicurrency_tx));
3185 $expesrc->fetch_optionals();
3186 $object->array_options = $expesrc->array_options;
3188 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : (!empty($cond_reglement_id) ? $cond_reglement_id : 0)));
3189 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : (!empty($mode_reglement_id) ? $mode_reglement_id : 0)));
3190 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : (!empty($fk_account) ? $fk_account : 0)));
3194 if (isModEnabled(
'multicurrency')) {
3195 if (!empty($objectsrc->multicurrency_code)) {
3196 $currency_code = $objectsrc->multicurrency_code;
3198 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
3199 $currency_tx = $objectsrc->multicurrency_tx;
3204 $objectsrc->fetch_optionals();
3205 $object->array_options = $objectsrc->array_options;
3209 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
3210 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
3211 $fk_account = empty($soc->fk_account) ? $fk_account : $soc->fk_account;
3214 $dateinvoice = (empty($dateinvoice) ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $dateinvoice);
3216 if (isModEnabled(
'multicurrency') && !empty($soc->multicurrency_code)) {
3217 $currency_code = $soc->multicurrency_code;
3222 if (!
GETPOST(
'changecompany')) {
3223 if (GETPOSTISSET(
'cond_reglement_id')) {
3224 $cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
3226 if (GETPOSTISSET(
'mode_reglement_id')) {
3227 $mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
3229 if (GETPOSTISSET(
'cond_reglement_id')) {
3230 $fk_account =
GETPOST(
'fk_account',
'int');
3235 if (empty($cond_reglement_id)) {
3236 $cond_reglement_id =
GETPOST(
"cond_reglement_id",
'int');
3240 if (empty($mode_reglement_id)) {
3241 $mode_reglement_id =
GETPOST(
"mode_reglement_id",
'int');
3251 if (!empty($soc->id)) {
3252 $absolute_discount = $soc->getAvailableDiscounts();
3254 $note_public = $object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null));
3255 $note_private = $object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) &&
getDolGlobalString(
'FACTURE_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null));
3257 if (!empty($conf->use_javascript_ajax)) {
3258 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3264 if ($origin ==
'contrat') {
3265 $langs->load(
"admin");
3266 $text = $langs->trans(
"ToCreateARecurringInvoice");
3267 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
3269 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
3271 print
info_admin($text, 0, 0, 0,
'opacitymedium').
'<br>';
3274 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
3275 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3276 print
'<input type="hidden" name="action" id="formtocreateaction" value="add">';
3277 print
'<input type="hidden" name="changecompany" value="0">';
3279 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
3281 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
3282 print
'<input name="ref" type="hidden" value="provisoire">';
3283 print
'<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
3284 print
'<input name="force_cond_reglement_id" type="hidden" value="0">';
3285 print
'<input name="force_mode_reglement_id" type="hidden" value="0">';
3286 print
'<input name="force_fk_account" type="hidden" value="0">';
3287 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
3288 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
3289 print
'<input type="hidden" name="originentity" value="'.GETPOST(
'originentity').
'">';
3290 if (!empty($currency_tx)) {
3291 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
3297 $parameters = array();
3299 $reshook = $hookmanager->executeHooks(
'tabContentCreateInvoice', $parameters, $object, $action);
3300 if (empty($reshook)) {
3301 print
'<table class="border centpercent">';
3306 $exampletemplateinvoice =
new FactureRec($db);
3308 if (empty($origin) && empty($originid) &&
GETPOST(
'fac_rec',
'int') > 0) {
3309 $invoice_predefined->fetch(
GETPOST(
'fac_rec',
'int'));
3313 if ($soc->id > 0 && (!
GETPOST(
'fac_rec',
'int') || !empty($invoice_predefined->frequency))) {
3315 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3316 print
'<td colspan="2">';
3317 print $soc->getNomUrl(1,
'customer');
3318 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
3320 $arrayoutstandingbills = $soc->getOutstandingBills();
3321 $outstandingBills = $arrayoutstandingbills[
'opened'];
3322 print
' - <span class="opacitymedium">'.$langs->trans(
'CurrentOutstandingBill').
':</span> ';
3323 print
'<span class="amount">'.price($outstandingBills,
'', $langs, 0, 0, -1, $conf->currency).
'</span>';
3324 if ($soc->outstanding_limit !=
'') {
3325 if ($outstandingBills > $soc->outstanding_limit) {
3326 print
img_warning($langs->trans(
"OutstandingBillReached"));
3328 print
' / '.price($soc->outstanding_limit,
'', $langs, 0, 0, -1, $conf->currency);
3333 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
3334 print
'<td colspan="2">';
3335 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
3336 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company($soc->id,
'socid', $filter,
'SelectThirdParty', 1, 0,
null, 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
3340 $(document).ready(function() {
3341 $("#socid").change(function() {
3343 console.log("Submit page");
3344 $(\'input[name="action"]\').val(\'create\');
3345 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
3346 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
3347 $(\'input[name="force_fk_account"]\').val(\'1\');
3348 $("#formtocreate").submit(); */
3350 // For company change, we must submit page with action=create instead of action=add
3351 console.log("We have changed the company - Resubmit page");
3352 jQuery("input[name=changecompany]").val("1");
3353 jQuery("#formtocreateaction").val("create");
3354 jQuery("#formtocreate").submit();
3359 if (!
GETPOST(
'fac_rec',
'int')) {
3360 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>';
3367 if (empty($origin) && empty($originid) &&
GETPOST(
'fac_rec',
'int') > 0) {
3368 $invoice_predefined->fetch(
GETPOST(
'fac_rec',
'int'));
3370 $dateinvoice = $invoice_predefined->date_when;
3371 if (empty($projectid)) {
3372 $projectid = $invoice_predefined->fk_project;
3374 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
3375 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
3376 $fk_account = $invoice_predefined->fk_account;
3377 $note_public = $invoice_predefined->note_public;
3378 $note_private = $invoice_predefined->note_private;
3380 if (!empty($invoice_predefined->multicurrency_code)) {
3381 $currency_code = $invoice_predefined->multicurrency_code;
3383 if (!empty($invoice_predefined->multicurrency_tx)) {
3384 $currency_tx = $invoice_predefined->multicurrency_tx;
3387 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
3388 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
3389 $sql .=
' WHERE r.fk_soc = '.((int) $invoice_predefined->socid);
3391 $resql = $db->query($sql);
3393 $num = $db->num_rows($resql);
3397 print
'<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
3399 print
'<select class="flat" id="fac_rec" name="fac_rec">';
3400 print
'<option value="0" selected></option>';
3402 $objp = $db->fetch_object($resql);
3403 print
'<option value="'.$objp->rowid.
'"';
3404 if (
GETPOST(
'fac_rec',
'int') == $objp->rowid) {
3406 $exampletemplateinvoice->fetch(
GETPOST(
'fac_rec',
'int'));
3408 print
'>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
3417 print
'<script type="text/javascript">
3418 $(document).ready(function() {
3419 $("#fac_rec").change(function() {
3420 console.log("We have changed the template invoice - Reload page");
3421 var fac_rec = $(this).val();
3422 var socid = $(\'#socid\').val();
3423 // 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.
3424 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3437 print
'<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td colspan="2">';
3438 print
'<div class="tagtable">'.
"\n";
3441 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3442 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOST(
'type',
'int') ?
'' :
' checked').
'> ';
3443 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
3444 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3,
'standardonsmartphone');
3445 print
'<table class="nobordernopadding"><tr>';
3449 if ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))) {
3458 print
'<td class="nowrap" style="padding-left: 15px">';
3459 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%').
'"/>';
3462 print
'</tr></table>';
3463 print
'</div></div>';
3465 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid)))) {
3468 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3469 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOST(
'type') == 3 ?
' checked' :
'').
'> ';
3470 print
'<script type="text/javascript">
3471 jQuery(document).ready(function() {
3472 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
3473 jQuery("#radio_standard").prop("checked", true);
3475 jQuery("#typedeposit, #valuedeposit").click(function() {
3476 jQuery("#radio_deposit").prop("checked", true);
3478 jQuery("#typedeposit").change(function() {
3479 console.log("We change type of down payment");
3480 jQuery("#radio_deposit").prop("checked", true);
3481 setRadioForTypeOfInvoice();
3483 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_creditnote, #radio_template").change(function() {
3484 setRadioForTypeOfInvoice();
3486 function setRadioForTypeOfInvoice() {
3487 console.log("Change radio");
3488 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
3489 jQuery(".checkforselect").prop("disabled", true);
3490 jQuery(".checkforselect").prop("checked", false);
3492 jQuery(".checkforselect").prop("disabled", false);
3493 jQuery(".checkforselect").prop("checked", true);
3499 print
'<table class="nobordernopadding"><tr>';
3501 $tmp = $tmp.
'<label for="radio_deposit">'.$langs->trans(
"InvoiceDeposit").
'</label>';
3502 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3,
'depositonsmartphone');
3505 if (($origin ==
'propal') || ($origin ==
'commande')) {
3506 print
'<td class="nowrap" style="padding-left: 15px">';
3508 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
3509 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
3510 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
3512 $typedeposit =
GETPOST(
'typedeposit',
'aZ09');
3513 $valuedeposit =
GETPOST(
'valuedeposit',
'int');
3514 if (empty($typedeposit) && !empty($objectsrc->deposit_percent)) {
3515 $origin_payment_conditions_deposit_percent =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $objectsrc->cond_reglement_id);
3516 if (!empty($origin_payment_conditions_deposit_percent)) {
3517 $typedeposit =
'variable';
3520 if (empty($valuedeposit) && $typedeposit ==
'variable' && !empty($objectsrc->deposit_percent)) {
3521 $valuedeposit = $objectsrc->deposit_percent;
3523 print $form->selectarray(
'typedeposit', $arraylist, $typedeposit, 0, 0, 0,
'', 1);
3525 print
'<td class="nowrap" style="padding-left: 5px">';
3526 print
'<span class="opacitymedium paddingleft">'.$langs->trans(
"AmountOrPercent").
'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.$valuedeposit.
'"/>';
3529 print
'</tr></table>';
3531 print
'</div></div>';
3538 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3539 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
3540 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
3541 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
3543 print
'</div></div>';
3546 $opt = $form->selectSituationInvoices(
GETPOST(
'originid',
'int'), $socid);
3548 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3549 $tmp =
'<input type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOST(
'originid',
'int') ?
' checked' :
'');
3550 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3551 $tmp .=
' disabled';
3554 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3555 $text .=
'<select class="flat" id="situations" name="situations"';
3556 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) {
3557 $text .=
' disabled';
3561 $text .=
'</select>';
3562 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
3564 print
'</div></div>';
3570 $facids = $facturestatic->list_replacable_invoices($soc->id);
3576 if (is_array($facids)) {
3577 foreach ($facids as $facparam) {
3578 $options .=
'<option value="'.$facparam [
'id'].
'"';
3579 if ($facparam[
'id'] ==
GETPOST(
'fac_replacement',
'int')) {
3580 $options .=
' selected';
3582 $options .=
'>'.$facparam[
'ref'];
3583 $options .=
' ('.$facturestatic->LibStatut($facparam[
'paid'], $facparam[
'status'], 0, $facparam[
'alreadypaid']).
')';
3584 $options .=
'</option>';
3588 print
'<!-- replacement line -->';
3589 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3590 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
3591 if (!$options || $invoice_predefined->id > 0) {
3592 $tmp .=
' disabled';
3595 print
'<script type="text/javascript">
3596 jQuery(document).ready(function() {
3597 jQuery("#fac_replacement").change(function() {
3598 jQuery("#radio_replacement").prop("checked", true);
3602 $text = $tmp.
'<label for="radio_replacement">'.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
3603 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
3604 if (!$options || $invoice_predefined->id > 0) {
3605 $text .=
' disabled';
3609 $text .=
'<option value="-1"> </option>';
3612 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
3614 $text .=
'</select>';
3615 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3617 print
'</div></div>';
3621 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3622 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3623 $text = $tmp.
'<label>'.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3624 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3625 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3,
'firstsituationonsmartphone');
3627 print
'</div></div>';
3630 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3631 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
3632 $text = $tmp.
'<label for="radio_replacement" class="opacitymedium">'.$langs->trans(
"InvoiceReplacement").
'</label> ';
3634 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc").
'<br><br>'.$langs->trans(
"YouMustCreateInvoiceFromThird"), 1,
'help',
'', 0, 3,
'replacementonsmartphone');
3636 print
'</div></div>';
3639 if (empty($origin)) {
3644 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
3650 $newinvoice_static =
new Facture($db);
3651 foreach ($facids as $key => $valarray) {
3652 $newinvoice_static->id = $key;
3653 $newinvoice_static->ref = $valarray [
'ref'];
3654 $newinvoice_static->statut = $valarray [
'status'];
3655 $newinvoice_static->type = $valarray [
'type'];
3656 $newinvoice_static->paye = $valarray [
'paye'];
3658 $optionsav .=
'<option value="'.$key.
'"';
3659 if ($key ==
GETPOST(
'fac_avoir')) {
3660 $optionsav .=
' selected';
3663 $newinvoice_static->fetch_optionals($key);
3664 $object->array_options = $newinvoice_static->array_options;
3667 $optionsav .= $newinvoice_static->ref;
3668 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
3669 $optionsav .=
'</option>';
3672 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3673 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
3674 if ((!$optionsav && !
getDolGlobalString(
'INVOICE_CREDIT_NOTE_STANDALONE')) || $invoice_predefined->id > 0) {
3675 $tmp .=
' disabled';
3679 print
'<script type="text/javascript">
3680 jQuery(document).ready(function() {
3681 if (jQuery("#radio_creditnote").is(":checked"))
3683 jQuery("#radio_standard").prop("disabled", true);
3685 jQuery("#radio_standard").prop("disabled", false);
3687 if (! jQuery("#radio_creditnote").is(":checked"))
3689 jQuery("#credit_note_options").hide();
3691 jQuery("#radio_creditnote").click(function() {
3692 jQuery("#credit_note_options").show();
3694 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
3695 jQuery("#credit_note_options").hide();
3699 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
3700 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3701 if (!$optionsav || $invoice_predefined->id > 0) {
3702 $text .=
' disabled';
3706 $text .=
'<option value="-1"></option>';
3707 $text .= $optionsav;
3709 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
3711 $text .=
'</select>';
3712 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3715 print
'<div id="credit_note_options" class="clearboth paddingtop marginbottomonly">';
3716 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>";
3717 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>";
3720 print
'</div></div>';
3723 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3725 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3727 $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
3729 $text = $tmp.
'<label class="opacitymedium" for="radio_creditnote">'.$langs->trans(
"InvoiceAvoir").
'</label> ';
3731 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc").
'<br><br>'.$langs->trans(
"CreateCreditNoteWhenClientInvoiceExists"), 1,
'help',
'', 0, 3,
'creditnoteonsmartphone');
3733 print
'</div></div>'.
"\n";
3738 print
'<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3739 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
3740 $text = $tmp.
'<label class="opacitymedium" for="radio_template">'.$langs->trans(
"RepeatableInvoice").
'</label> ';
3741 $desc = $form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3,
'templateonsmartphone');
3743 print
'</div></div>';
3752 foreach ($listtType as $type) {
3753 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
3755 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$curent.
'"';
3758 print
'<script type="text/javascript">
3759 $(document).ready(function() {
3760 var listType = {'.$jsListType.
'};
3761 $("[name=\'type\'").change(function() {
3762 console.log("change name=type");
3763 if ($( this ).prop("checked"))
3765 if(($( this ).val() in listType))
3767 $("#model").val(listType[$( this ).val()]);
3784 print
'<tr><td class="fieldrequired">'.$langs->trans(
'InvoiceSubtype').
'</td><td colspan="2">';
3785 print $form->getSelectInvoiceSubtype(
GETPOST(
'subtype'),
'subtype', 1, 0,
'');
3791 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="2">';
3795 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode(
GETPOST(
'origin')).
'&originid='.urlencode(
GETPOSTINT(
'originid'));
3796 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3802 $date_pointoftax =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'),
'tzserver');
3805 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
3806 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3807 print $form->selectDate($newdateinvoice ? $newdateinvoice : $dateinvoice,
'',
'',
'',
'',
"add", 1, 1);
3812 print
'<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
3813 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
3814 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax',
'',
'',
'',
"add", 1, 1);
3819 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
3820 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
3821 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', -1, 1, 0,
'maxwidth500 widthcentpercentminusx');
3826 $rwStyle =
'display:none;';
3827 if (in_array(
GETPOST(
'type',
'int'), $retainedWarrantyInvoiceAvailableType)) {
3831 $retained_warranty =
GETPOST(
'retained_warranty',
'int');
3832 if (empty($retained_warranty)) {
3833 if (!empty($objectsrc->retained_warranty)) {
3834 $retained_warranty = $objectsrc->retained_warranty;
3837 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT;
3839 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
3840 print
'<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
3843 print
'<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
3844 $retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
3845 if (empty($retained_warranty_fk_cond_reglement)) {
3846 $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
3847 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
3848 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
3850 $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
3853 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
3856 print
'<script type="text/javascript">
3857 $(document).ready(function() {
3858 $("[name=\'type\']").change(function() {
3859 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
3861 $(".retained-warranty-line").show();
3862 $("#new-situation-invoice-retained-warranty").val("'.(float) $retained_warranty_js_default.
'");
3865 $(".retained-warranty-line").hide();
3866 $("#new-situation-invoice-retained-warranty").val("");
3870 $("[name=\'type\']:checked").trigger("change");
3876 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
3877 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
3878 print $form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
3882 if (isModEnabled(
"banque")) {
3883 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td colspan="2">';
3884 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
3885 print $form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
3890 if (isModEnabled(
'project')) {
3891 $langs->load(
'projects');
3892 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
3893 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
3894 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>';
3899 if (isModEnabled(
'incoterm')) {
3901 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms :
'', 1).
'</label></td>';
3902 print
'<td colspan="2" class="maxwidthonsmartphone">';
3903 $incoterm_id =
GETPOST(
'incoterm_id');
3904 $incoterm_location =
GETPOST(
'location_incoterms');
3905 if (empty($incoterm_id)) {
3906 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
3907 $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
3909 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
3910 print $form->select_incoterms($incoterm_id, $incoterm_location);
3915 $parameters = array(
'objectsrc' => !empty($objectsrc) ? $objectsrc : 0,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid'=>$socid);
3916 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
3917 print $hookmanager->resPrint;
3918 if (empty($reshook)) {
3919 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE') && !empty($soc->id)) {
3922 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
3923 if ($soc->fetch_optionals() > 0) {
3924 $object->array_options = array_merge($object->array_options, $soc->array_options);
3928 print $object->showOptionals($extrafields,
'create', $parameters);
3932 print
'<tr><td>'.$langs->trans(
'Model').
'</td>';
3933 print
'<td colspan="2">';
3934 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
3935 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
3938 $type = GETPOSTISSET(
'type') ?
GETPOSTINT(
'type') : $object->
type;
3940 $paramkey =
'FACTURE_ADDON_PDF_'.$type;
3945 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
3949 if (isModEnabled(
'multicurrency')) {
3951 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
3952 print
'<td colspan="2" class="maxwidthonsmartphone">';
3953 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
3954 print $form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code');
3960 if (
GETPOST(
'fac_rec',
'int') > 0) {
3961 $dateexample = ($newdateinvoice ? $newdateinvoice : $dateinvoice);
3962 if (empty($dateexample)) {
3965 $substitutionarray = array(
3966 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
3967 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
3968 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
3969 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
3970 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
3971 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
3972 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
3973 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
3974 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
3975 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
3976 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
3979 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
3980 foreach ($substitutionarray as $key => $val) {
3981 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
3983 $htmltext .=
'</i>';
3988 print
'<td class="tdtop">';
3989 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
3991 print
'<td valign="top" colspan="2">';
3992 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
3993 print $doleditor->Create(1);
3996 if (empty($user->socid)) {
3998 print
'<td class="tdtop">';
3999 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
4001 print
'<td valign="top" colspan="2">';
4002 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
4003 print $doleditor->Create(1);
4009 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4010 $langs->loadLangs(array(
'orders',
'propal'));
4013 if ($origin ==
'contrat') {
4017 $objectsrc->update_price(1,
'auto', 1);
4020 print
"\n<!-- Show ref of origin ".$classname.
" -->\n";
4021 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
4022 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
4023 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
4028 switch (get_class($objectsrc)) {
4030 $newclassname =
'CommercialProposal';
4033 $newclassname =
'Order';
4036 $newclassname =
'Sending';
4039 $newclassname =
'Contract';
4042 $newclassname =
'Intervention';
4045 $newclassname = get_class($objectsrc);
4049 print
'<tr><td>'.$langs->trans($newclassname).
'</td>';
4050 print
'<td colspan="2">';
4051 print $objectsrc->getNomUrl(1);
4053 $objectsrc->fetchObjectLinked($originid, $origin,
'',
'facture');
4054 if (isset($objectsrc->linkedObjects[
'facture']) && is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1) {
4056 echo
' - '.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1);
4059 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht).
'</td></tr>';
4060 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva).
"</td></tr>";
4061 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
4062 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax1).
"</td></tr>";
4065 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
4066 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax2).
"</td></tr>";
4068 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc).
"</td></tr>";
4070 if (isModEnabled(
'multicurrency')) {
4071 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
4072 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
4073 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
4081 print $form->buttonsSaveCancel(
"CreateDraft");
4084 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
4087 $title = $langs->trans(
'ProductsAndServices');
4090 print
'<div class="div-table-responsive-no-min">';
4091 print
'<table class="noborder centpercent">';
4093 $objectsrc->printOriginLinesList(
'', $selectedLines);
4100} elseif ($id > 0 || !empty($ref)) {
4101 if (empty($object->id)) {
4102 $langs->load(
'errors');
4103 echo
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
4112 $result = $object->fetch($id, $ref);
4119 $extrafields->fetch_name_optionals_label($object->table_element);
4121 if ($user->socid > 0 && $user->socid != $object->socid) {
4125 $result = $object->fetch_thirdparty();
4127 $result = $soc->fetch($object->socid);
4131 $selleruserevenustamp = $mysoc->useRevenueStamp();
4133 $totalpaid = $object->getSommePaiement();
4134 $totalcreditnotes = $object->getSumCreditNotesUsed();
4135 $totaldeposits = $object->getSumDepositsUsed();
4143 $resteapayer =
price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
4146 if (isModEnabled(
'multicurrency')) {
4147 $multicurrency_totalpaid = $object->getSommePaiement(1);
4148 $multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
4149 $multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
4150 $multicurrency_resteapayer =
price2num($object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits,
'MT');
4154 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 && $object->multicurrency_code != $conf->currency) {
4155 $resteapayer =
price2num($multicurrency_resteapayer / $object->multicurrency_tx,
'MT');
4159 if ($object->paye) {
4162 $resteapayeraffiche = $resteapayer;
4165 $filterabsolutediscount =
"fk_facture_source IS NULL";
4166 $filtercreditnote =
"fk_facture_source IS NOT NULL";
4168 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
4169 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
4172 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
4173 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
4174 $absolute_discount =
price2num($absolute_discount,
'MT');
4175 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
4177 $author =
new User($db);
4178 if ($object->user_author) {
4179 $author->fetch($object->user_author);
4182 $objectidnext = $object->getIdReplacingInvoice();
4186 print
dol_get_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
'bill');
4191 if ($action ==
'converttoreduc') {
4193 $type_fac =
'ExcessReceived';
4195 $type_fac =
'CreditNote';
4197 $type_fac =
'Deposit';
4199 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
4200 $text .=
'<br>'.$langs->trans(
'ConfirmConvertToReduc2');
4201 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
4205 if ($action ==
'delete') {
4206 $text = $langs->trans(
'ConfirmDeleteBill', $object->ref);
4207 $formquestion = array();
4210 $qualified_for_stock_change = 0;
4212 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4214 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4217 if ($qualified_for_stock_change) {
4218 $langs->load(
"stocks");
4219 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4221 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
4223 if ($conf->browser->name ==
'ie') {
4226 $formquestion = array(
4230 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
4232 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
4234 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4237 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
4242 if ($action ==
'situationout') {
4243 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle', $object->ref);
4244 $label = $langs->trans(
"ConfirmOuting");
4245 $formquestion = array();
4250 && $object->is_last_in_cycle()
4251 && $usercanunvalidate
4253 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
4258 if ($action ==
'valid') {
4260 $objectref = substr($object->ref, 1, 4);
4261 if ($objectref ==
'PROV') {
4262 $savdate = $object->date;
4265 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
4267 $numref = $object->getNextNumRef($soc);
4270 $numref = $object->ref;
4273 $text = $langs->trans(
'ConfirmValidateBill', $numref);
4274 if (isModEnabled(
'notification')) {
4275 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
4276 $notify =
new Notify($db);
4278 $text .= $notify->confirmMessage(
'BILL_VALIDATE', $object->socid, $object);
4280 $formquestion = array();
4283 $qualified_for_stock_change = 0;
4285 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4287 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4290 if ($qualified_for_stock_change) {
4291 $langs->load(
"stocks");
4292 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4293 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4296 $warehouse_array = $warehouse->list_array();
4297 if (count($warehouse_array) == 1) {
4298 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
4299 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4301 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockIncrease") : $langs->trans(
"SelectWarehouseForStockDecrease");
4302 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4304 $formquestion = array(
4310 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4314 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
4319 foreach ($object->lines as $line) {
4320 $res = $line->fetch_product();
4322 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
4328 if ($nbMandated > 0) {
4329 $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
4333 $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);
4337 if ($action ==
'modif') {
4338 $text = $langs->trans(
'ConfirmUnvalidateBill', $object->ref);
4339 $formquestion = array();
4342 $qualified_for_stock_change = 0;
4344 $qualified_for_stock_change = $object->hasProductsOrServices(2);
4346 $qualified_for_stock_change = $object->hasProductsOrServices(1);
4349 if ($qualified_for_stock_change) {
4350 $langs->load(
"stocks");
4351 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
4352 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
4355 $warehouse_array = $warehouse->list_array();
4356 if (count($warehouse_array) == 1) {
4357 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
4358 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
4360 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
4361 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
4363 $formquestion = array(
4369 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
4373 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
4377 if ($action ==
'paid' && ($resteapayer <= 0 || (
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer == $object->total_ttc))) {
4378 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill', $object->ref),
'confirm_paid',
'',
"yes", 1);
4380 if ($action ==
'paid' && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer != $object->total_ttc)) {
4384 $close[$i][
'code'] =
'discount_vat';
4386 $close[$i][
'code'] =
'badcustomer';
4388 $close[$i][
'code'] =
'bankcharge';
4390 $close[$i][
'code'] =
'withholdingtax';
4392 $close[$i][
'code'] =
'other';
4396 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
4398 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4400 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankChargeDesc");
4402 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTaxDesc");
4404 $close[$i][
'label'] = $langs->trans(
"Other");
4408 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4410 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4412 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBankCharge", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
4414 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax"), $close[$i][
'label'], 1);
4416 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
4419 foreach ($close as $key => $val) {
4420 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
4424 $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'));
4426 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially', $object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 380, 600);
4430 if ($action ==
'canceled') {
4433 if ($objectidnext) {
4434 $facturereplacement =
new Facture($db);
4435 $facturereplacement->fetch($objectidnext);
4436 $statusreplacement = $facturereplacement->statut;
4438 if ($objectidnext && $statusreplacement == 0) {
4439 print
'<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
4442 $close[1][
'code'] =
'badcustomer';
4443 $close[2][
'code'] =
'abandon';
4445 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
4446 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
4448 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $object->ref), $close[1][
'label'], 1);
4449 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
4451 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
4452 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
4455 $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'));
4457 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill', $object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 270);
4461 if ($action ==
'deletepayment') {
4462 $payment_id =
GETPOST(
'paiement_id');
4463 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
4467 if ($action ==
'ask_deleteline') {
4468 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
4472 if ($action ==
'clone') {
4473 $filter =
'(s.client:IN:1,2,3)';
4475 $formquestion = array(
4476 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company($object->socid,
'socid', $filter, 1)),
4477 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
4480 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
4483 if ($action ==
"remove_file_comfirm") {
4484 $file =
GETPOST(
'file',
'alpha');
4486 $formconfirm = $form->formconfirm(
4487 $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&file='.urlencode($file),
4488 $langs->trans(
'DeleteFileHeader'),
4489 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
4498 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
4499 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
4500 if (empty($reshook)) {
4501 $formconfirm .= $hookmanager->resPrint;
4502 } elseif ($reshook > 0) {
4503 $formconfirm = $hookmanager->resPrint;
4511 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
4513 $morehtmlref =
'<div class="refidno">';
4515 if ($object->status == $object::STATUS_DRAFT && !$mysoc->isInEEC() &&
getDolGlobalString(
'INVOICE_ALLOW_FREE_REF')) {
4516 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref', $object->ref, $object, $usercancreate,
'string',
'', 0, 1);
4517 $morehtmlref .= $form->editfieldval(
"Ref",
'ref', $object->ref, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
4518 $morehtmlref .=
'<br>';
4521 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
4522 $morehtmlref .= $form->editfieldval(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ?
':' .
getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') :
''),
'', null, null,
'', 1);
4524 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1,
'customer');
4526 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
4529 if (isModEnabled(
'project')) {
4530 $langs->load(
"projects");
4531 $morehtmlref .=
'<br>';
4532 if ($usercancreate) {
4533 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
4534 if ($action !=
'classify') {
4535 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
4537 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
4539 if (!empty($object->fk_project)) {
4541 $proj->fetch($object->fk_project);
4542 $morehtmlref .= $proj->getNomUrl(1);
4544 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
4549 $morehtmlref .=
'</div>';
4551 $object->totalpaid = $totalpaid;
4552 $object->totalcreditnotes = $totalcreditnotes;
4553 $object->totaldeposits = $totaldeposits;
4554 $object->remaintopay =
price2num($object->total_ttc - $object->totalpaid - $object->totalcreditnotes - $object->totaldeposits,
'MT');
4556 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
4559 $parameters = array();
4561 $reshook = $hookmanager->executeHooks(
'tabContentViewInvoice', $parameters, $object, $action);
4562 if (empty($reshook)) {
4563 print
'<div class="fichecenter">';
4564 print
'<div class="fichehalfleft">';
4565 print
'<div class="underbanner clearboth"></div>';
4567 print
'<table class="border centpercent tableforfield">';
4570 print
'<tr><td class="titlefield fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
4571 print $object->getLibType(2);
4572 if ($object->subtype > 0) {
4573 print
' '.$object->getSubtypeLabel(
'facture');
4575 if ($object->module_source) {
4576 print
' <span class="opacitymediumbycolor paddingleft">('.$langs->trans(
"POS").
' '.
dol_escape_htmltag(ucfirst($object->module_source)).
' - '.$langs->trans(
"Terminal").
' '.
dol_escape_htmltag($object->pos_source).
')</span>';
4579 $facreplaced =
new Facture($db);
4580 $facreplaced->fetch($object->fk_facture_source);
4581 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1,
'', 32)).
'</span>';
4585 $facusing->fetch($object->fk_facture_source);
4586 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1,
'', 32)).
'</span>';
4589 $facidavoir = $object->getListIdAvoirFromInvoice();
4590 if (count($facidavoir) > 0) {
4591 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
4593 foreach ($facidavoir as $id) {
4600 $facavoir->fetch($id);
4601 print $facavoir->getNomUrl(1,
'', 32);
4605 if ($objectidnext > 0) {
4606 $facthatreplace =
new Facture($db);
4607 $facthatreplace->fetch($objectidnext);
4608 print
' <span class="opacitymediumbycolor paddingleft">'.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
'</span>';
4613 $result = $discount->fetch(0, $object->id);
4615 print
' <span class="opacitymediumbycolor paddingleft">';
4616 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
4617 $s = str_replace(
'{s1}', $object->getLibType(0), $s);
4618 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
4620 print
'</span><br>';
4624 if ($object->fk_fac_rec_source > 0) {
4626 $result = $tmptemplate->fetch($object->fk_fac_rec_source);
4628 print
' <span class="opacitymediumbycolor paddingleft">';
4629 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
4630 $s = str_replace(
'{s1}', $tmptemplate->getNomUrl(1,
'', 32), $s);
4638 print
'<!-- Discounts -->'.
"\n";
4639 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td>';
4643 $backtopage = $_SERVER[
"PHP_SELF"].
'?facid='.$object->id;
4644 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
4649 print
'<table class="nobordernopadding centpercent"><tr><td>';
4650 print $langs->trans(
'DateInvoice');
4652 if ($action !=
'editinvoicedate' && $object->status == $object::STATUS_DRAFT && $usercancreate && !
getDolGlobalString(
'FAC_FORCE_DATE_VALIDATION')) {
4653 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>';
4655 print
'</tr></table>';
4658 if ($action ==
'editinvoicedate') {
4659 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date,
'invoicedate');
4661 print
'<span class="valuedate">'.dol_print_date($object->date,
'day').
'</span>';
4670 print
'<table class="nobordernopadding centpercent"><tr><td>';
4671 print $langs->trans(
'DatePointOfTax');
4673 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>';
4674 print
'</tr></table>';
4676 if ($action ==
'editdate_pointoftax') {
4677 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date_pointoftax,
'date_pointoftax');
4679 print
'<span class="valuedate">'.dol_print_date($object->date_pointoftax,
'day').
'</span>';
4686 print
'<table class="nobordernopadding centpercent"><tr><td>';
4687 print $langs->trans(
'PaymentConditionsShort');
4690 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>';
4692 print
'</tr></table>';
4695 if ($action ==
'editconditions') {
4696 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
4698 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'none');
4707 print
'<table class="nobordernopadding centpercent"><tr><td>';
4708 print $langs->trans(
'DateMaxPayment');
4711 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>';
4713 print
'</tr></table>';
4716 if ($action ==
'editpaymentterm') {
4717 $form->form_date($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date_lim_reglement,
'paymentterm');
4719 print
'<span class="valuedate">'.dol_print_date($object->date_lim_reglement,
'day').
'</span>';
4720 if ($object->hasDelay()) {
4731 print
'<table class="nobordernopadding centpercent"><tr><td>';
4732 print $langs->trans(
'PaymentMode');
4734 if ($action !=
'editmode' && $usercancreate) {
4735 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>';
4737 print
'</tr></table>';
4739 if ($action ==
'editmode') {
4740 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
4742 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'none',
'CRDT');
4747 if (isModEnabled(
'multicurrency')) {
4751 print
'<table class="nobordernopadding centpercent"><tr><td>';
4752 print $form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
4754 if ($usercancreate && $action !=
'editmulticurrencycode' && $object->status == $object::STATUS_DRAFT) {
4755 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>';
4757 print
'</tr></table>';
4759 $htmlname = (($usercancreate && $action ==
'editmulticurrencycode') ?
'multicurrency_code' :
'none');
4760 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code, $htmlname);
4764 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
4767 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4768 print $form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
4770 if ($usercancreate && $action !=
'editmulticurrencyrate' && $object->status == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
4771 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>';
4773 print
'</tr></table>';
4775 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
4776 if ($action ==
'actualizemulticurrencyrate') {
4779 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx, ($usercancreate ?
'multicurrency_tx' :
'none'), $object->multicurrency_code);
4781 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
4782 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
4783 print
'<div class="inline-block"> ';
4784 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
4793 if (isModEnabled(
"banque")) {
4794 print
'<tr><td class="nowrap">';
4795 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
4796 print $langs->trans(
'BankAccount');
4798 if (($action !=
'editbankaccount') && $usercancreate) {
4799 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>';
4801 print
'</tr></table>';
4803 if ($action ==
'editbankaccount') {
4804 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
4806 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
4813 if (isModEnabled(
'incoterm')) {
4815 print
'<table class="nobordernopadding centpercent"><tr><td>';
4816 print $langs->trans(
'IncotermLabel');
4817 print
'<td><td class="right">';
4818 if ($usercancreate) {
4819 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$object->id.
'&action=editincoterm&token='.newToken().
'">'.
img_edit().
'</a>';
4823 print
'</td></tr></table>';
4826 if ($action !=
'editincoterm') {
4827 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
4829 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
4836 if (!empty($object->retained_warranty) ||
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY')) {
4837 $displayWarranty =
true;
4838 if (!in_array($object->type, $retainedWarrantyInvoiceAvailableType) && empty($object->retained_warranty)) {
4839 $displayWarranty =
false;
4842 if ($displayWarranty) {
4844 print
'<tr class="retained-warranty-lines" ><td>';
4845 print
'<table id="retained-warranty-table" class="nobordernopadding centpercent"><tr><td>';
4846 print $langs->trans(
'RetainedWarranty');
4848 if ($action !=
'editretainedwarranty' && $user->hasRight(
'facture',
'creer') && $object->statut ==
Facture::STATUS_DRAFT) {
4849 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>';
4852 print
'</tr></table>';
4855 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4856 print
'<input type="hidden" name="action" value="setretainedwarranty">';
4857 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4858 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4859 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
4860 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
4863 print
price($object->retained_warranty).
'%';
4868 print
'<tr class="retained-warranty-lines" ><td>';
4869 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
4870 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
4872 if ($action !=
'editretainedwarrantypaymentterms' && $user->hasRight(
'facture',
'creer') && $object->statut ==
Facture::STATUS_DRAFT) {
4873 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>';
4876 print
'</tr></table>';
4878 $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime(
'-1 years', $object->date_lim_reglement);
4879 if ($object->date > $defaultDate) {
4880 $defaultDate = $object->date;
4885 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4886 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
4887 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4888 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4889 $retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
4890 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $object->retained_warranty_fk_cond_reglement;
4891 $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;
4892 print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4893 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4896 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->retained_warranty_fk_cond_reglement,
'none');
4897 if (!$displayWarranty) {
4898 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning.png',
'class="pictowarning valignmiddle" ');
4904 print
'<tr class="retained-warranty-lines" ><td>';
4905 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
4906 print $langs->trans(
'RetainedWarrantyDateLimit');
4908 if ($action !=
'editretainedwarrantydatelimit' && $user->hasRight(
'facture',
'creer') && $object->statut ==
Facture::STATUS_DRAFT) {
4909 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>';
4912 print
'</tr></table>';
4914 $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime(
'-1 years', $object->date_lim_reglement);
4915 if ($object->date > $defaultDate) {
4916 $defaultDate = $object->date;
4921 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4922 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
4923 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4924 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
4925 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').
'" >';
4926 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4929 print
dol_print_date($object->retained_warranty_date_limit,
'day');
4938 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
4943 print
'<div class="fichehalfright">';
4945 print
'<!-- amounts -->'.
"\n";
4946 print
'<div class="underbanner clearboth"></div>'.
"\n";
4948 print
'<table class="border tableforfield centpercent">';
4951 if (
getDolGlobalString(
'INVOICE_POSITIVE_CREDIT_NOTE_SCREEN') && $object->type == $object::TYPE_CREDIT_NOTE) {
4956 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
4957 print
'<td class="nowrap amountcard right">' .
price($sign * $object->total_ht,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
4958 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
4960 print
'<td class="nowrap amountcard right">' .
price($sign * $object->multicurrency_total_ht,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
4966 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountVAT') .
'</td>';
4967 print
'<td class="nowrap amountcard right">' .
price($sign * $object->total_tva,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
4968 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
4970 print
'<td class="nowrap amountcard right">' .
price($sign * $object->multicurrency_total_tva,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
4975 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) {
4977 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
4978 print
'<td class="nowrap amountcard right">' .
price($sign * $object->total_localtax1,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
4979 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
4980 $object->multicurrency_total_localtax1 =
price2num($object->total_localtax1 * $object->multicurrency_tx,
'MT');
4982 print
'<td class="nowrap amountcard right">' .
price($sign * $object->multicurrency_total_localtax1,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
4987 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) {
4989 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
4990 print
'<td class="nowrap amountcard right">' .
price($sign * $object->total_localtax2,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
4991 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
4992 $object->multicurrency_total_localtax2 =
price2num($object->total_localtax2 * $object->multicurrency_tx,
'MT');
4994 print
'<td class="nowrap amountcard right">' .
price($sign * $object->multicurrency_total_localtax2,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
5000 if ($selleruserevenustamp) {
5001 print
'<tr><td class="titlefieldmiddle">';
5002 print
'<table class="nobordernopadding centpercent"><tr><td>';
5003 print $langs->trans(
'RevenueStamp');
5005 if ($action !=
'editrevenuestamp' && $object->status == $object::STATUS_DRAFT && $usercancreate) {
5006 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>';
5008 print
'</tr></table>';
5009 print
'</td><td class="nowrap amountcard right">';
5010 if ($action ==
'editrevenuestamp') {
5011 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
5012 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5013 print
'<input type="hidden" name="action" value="setrevenuestamp">';
5014 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num($object->revenuestamp).
'">';
5015 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5016 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
5017 print
' → <span id="revenuestamp_span"></span>';
5018 print
' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans(
'Modify').
'">';
5021 $(document).ready(function(){
5022 js_recalculate_revenuestamp();
5023 $('select[name=revenuestamp_type]').on('change',function(){
5024 js_recalculate_revenuestamp();
5027 function js_recalculate_revenuestamp(){
5028 var valselected = $('select[name=revenuestamp_type]').val();
5029 console.log('Calculate revenue stamp from '+valselected);
5031 if (valselected.indexOf('%') == -1)
5033 revenue = valselected;
5037 var revenue_type = parseFloat(valselected);
5038 var amount_net = ".round($object->total_ht, 2).
";
5039 revenue = revenue_type * amount_net / 100;
5040 revenue = revenue.toFixed(2);
5042 $('#revenuestamp_val').val(revenue);
5043 $('#revenuestamp_span').html(revenue);
5047 print
price($object->revenuestamp, 1,
'', 1, -1, -1, $conf->currency);
5054 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
5055 print
'<td class="nowrap amountcard right">' .
price($sign * $object->total_ttc,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
5056 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
5058 print
'<td class="nowrap amountcard right">' .
price($sign * $object->multicurrency_total_ttc,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
5066 if (isModEnabled(
'project')) {
5069 if (isModEnabled(
"banque")) {
5073 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
5076 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
5079 if ($selleruserevenustamp) {
5082 if (isModEnabled(
'multicurrency')) {
5085 if (isModEnabled(
'incoterm')) {
5090 if (($object->situation_cycle_ref > 0) &&
getDolGlobalString(
'INVOICE_USE_SITUATION')) {
5091 print
'<!-- List of situation invoices -->';
5092 print
'<table class="noborder situationstable" width="100%">';
5094 print
'<tr class="liste_titre">';
5095 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
5097 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
5098 if (isModEnabled(
"banque")) {
5099 print
'<td class="right"></td>';
5101 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
5102 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
5103 print
'<td width="18"> </td>';
5106 $total_prev_ht = $total_prev_ttc = 0;
5107 $total_global_ht = $total_global_ttc = 0;
5109 if (count($object->tab_previous_situation_invoice) > 0) {
5112 $current_situation_counter = array();
5113 foreach ($object->tab_previous_situation_invoice as $prev_invoice) {
5114 $tmptotalpaidforthisinvoice = $prev_invoice->getSommePaiement();
5115 $total_prev_ht += $prev_invoice->total_ht;
5116 $total_prev_ttc += $prev_invoice->total_ttc;
5117 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? -1 : 1) * $prev_invoice->situation_counter;
5118 print
'<tr class="oddeven">';
5119 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
5121 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
5122 if (isModEnabled(
"banque")) {
5123 print
'<td class="right"></td>';
5125 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ht).
'</span></td>';
5126 print
'<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).
'</span></td>';
5127 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).
'</td>';
5133 $total_global_ht += $total_prev_ht;
5134 $total_global_ttc += $total_prev_ttc;
5135 $total_global_ht += $object->total_ht;
5136 $total_global_ttc += $object->total_ttc;
5138 print
'<tr class="oddeven">';
5139 print
'<td>'.$object->getNomUrl(1).
'</td>';
5141 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$object->situation_counter.
'</td>';
5142 if (isModEnabled(
"banque")) {
5143 print
'<td class="right"></td>';
5145 print
'<td class="right"><span class="amount">'.price($object->total_ht).
'</span></td>';
5146 print
'<td class="right"><span class="amount">'.price($object->total_ttc).
'</span></td>';
5147 print
'<td class="right">'.$object->getLibStatut(3, $object->getSommePaiement()).
'</td>';
5151 print
'<tr class="oddeven">';
5152 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'CurrentSituationTotal').
'</b></td>';
5155 foreach ($current_situation_counter as $sit) {
5156 $curSign = $sit > 0 ?
'+' :
'-';
5157 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
5159 print
' '.$curSign.
' ';
5161 print $curType.abs($sit);
5165 if (isModEnabled(
"banque")) {
5168 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5169 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5170 print
'<td width="18"> </td>';
5174 if (count($object->tab_next_situation_invoice) > 0) {
5186 $total_next_ht = $total_next_ttc = 0;
5188 foreach ($object->tab_next_situation_invoice as $next_invoice) {
5189 $totalpaid = $next_invoice->getSommePaiement();
5190 $total_next_ht += $next_invoice->total_ht;
5191 $total_next_ttc += $next_invoice->total_ttc;
5193 print
'<tr class="oddeven">';
5194 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
5196 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
5197 if (isModEnabled(
"banque")) {
5198 print
'<td class="right"></td>';
5200 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ht).
'</span></td>';
5201 print
'<td class="right"><span class="amount">'.price($next_invoice->total_ttc).
'</span></td>';
5202 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid).
'</td>';
5206 $total_global_ht += $total_next_ht;
5207 $total_global_ttc += $total_next_ttc;
5209 print
'<tr class="oddeven">';
5210 print
'<td colspan="3" class="right"></td>';
5211 if (isModEnabled(
"banque")) {
5212 print
'<td class="right"></td>';
5214 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
5215 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
5216 print
'<td width="18"> </td>';
5224 if ($object->type == $object::TYPE_CREDIT_NOTE) {
5230 print
'<!-- List of payments already done -->';
5231 print
'<div class="div-table-responsive-no-min">';
5232 print
'<table class="noborder paymenttable centpercent">';
5234 print
'<tr class="liste_titre">';
5235 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
5236 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Date').
'</span></td>';
5237 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'Type').
'</span></td>';
5238 if (isModEnabled(
"banque")) {
5239 print
'<td class="liste_titre"><span class="hideonsmartphone">'.$langs->trans(
'BankAccount').
'</span></td>';
5241 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
5242 print
'<td class="liste_titre" width="18"> </td>';
5246 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
5247 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
5248 $sql .=
' pf.amount,';
5249 $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';
5250 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
5251 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
5252 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
5253 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
5254 $sql .=
' WHERE pf.fk_facture = '.((int) $object->id).
' AND pf.fk_paiement = p.rowid';
5255 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
5256 $sql .=
' ORDER BY p.datep, p.tms';
5258 $result = $db->query($sql);
5260 $num = $db->num_rows($result);
5265 $objp = $db->fetch_object($result);
5267 $paymentstatic->id = $objp->rowid;
5268 $paymentstatic->datepaye = $db->jdate($objp->dp);
5269 $paymentstatic->ref = $objp->ref;
5270 $paymentstatic->num_payment = $objp->num_payment;
5271 $paymentstatic->paiementcode = $objp->payment_code;
5273 print
'<tr class="oddeven"><td class="nowraponall">';
5274 print $paymentstatic->getNomUrl(1);
5277 $dateofpayment = $db->jdate($objp->dp);
5279 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
5286 $label = ($langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
5287 print
'<td class="tdoverflowmax80" title="'.dol_escape_htmltag($label.
' '.$objp->num_payment).
'">'.
dol_escape_htmltag($label.
' '.$objp->num_payment).
'</td>';
5288 if (isModEnabled(
"banque")) {
5289 $bankaccountstatic->id = $objp->baid;
5290 $bankaccountstatic->ref = $objp->baref;
5291 $bankaccountstatic->label = $objp->baref;
5292 $bankaccountstatic->number = $objp->banumber;
5293 $bankaccountstatic->currency_code = $objp->bacurrency_code;
5295 if (isModEnabled(
'accounting')) {
5296 $bankaccountstatic->account_number = $objp->account_number;
5299 $accountingjournal->fetch($objp->fk_accountancy_journal);
5300 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
5303 print
'<td class="nowraponall">';
5304 if ($bankaccountstatic->id) {
5305 print $bankaccountstatic->getNomUrl(1,
'transactions');
5309 print
'<td class="right"><span class="amount">'.price($sign * $objp->amount).
'</span></td>';
5310 print
'<td class="center">';
5313 $paiement->fetch($objp->rowid);
5314 if ($object->statut ==
Facture::STATUS_VALIDATED && $object->paye == 0 && $user->socid == 0 && !$paiement->isReconciled()) {
5315 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=deletepayment&token='.newToken().
'&paiement_id='.$objp->rowid.
'">';
5332 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5333 print
'<span class="opacitymedium">';
5335 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
5337 print $langs->trans(
'AlreadyPaid');
5339 print
'</span></td><td class="right'.(($totalpaid > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaid).
'</td><td> </td></tr>';
5341 $resteapayeraffiche = $resteapayer;
5342 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
5345 $creditnoteamount = 0;
5347 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
5348 $sql .=
" re.description, re.fk_facture_source";
5349 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
5350 $sql .=
" WHERE fk_facture = ".((int) $object->id);
5351 $resql = $db->query($sql);
5353 $num = $db->num_rows($resql);
5357 $obj = $db->fetch_object($resql);
5358 $invoice->fetch($obj->fk_facture_source);
5359 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5360 print
'<span class="opacitymedium">';
5362 print $langs->trans(
"CreditNote").
' ';
5365 print $langs->trans(
"Deposit").
' ';
5367 print $invoice->getNomUrl(0);
5370 print
'<td class="right"><span class="amount">'.price($obj->amount_ttc).
'</span></td>';
5371 print
'<td class="right">';
5372 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=unlinkdiscount&token='.newToken().
'&discountid='.$obj->rowid.
'">';
5373 print
img_picto($langs->transnoentitiesnoconv(
"RemoveDiscount"),
'unlink');
5378 $creditnoteamount += $obj->amount_ttc;
5381 $depositamount += $obj->amount_ttc;
5390 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5391 print
'<span class="opacitymedium">';
5392 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
5394 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5395 $resteapayeraffiche = 0;
5396 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5400 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5401 print
'<span class="opacitymedium">';
5402 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
5404 print
'</td><td class="right">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</td><td> </td></tr>';
5406 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5410 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5411 print
'<span class="opacitymedium">';
5412 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
5414 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5415 $resteapayeraffiche = 0;
5416 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5420 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
5421 $text = $langs->trans(
"HelpAbandonOther");
5422 if ($object->close_note) {
5423 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.$object->close_note;
5425 print
'<span class="opacitymedium">';
5426 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
5428 print
'</td><td class="right"><span class="amount">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid,
'MT')).
'</span></td><td> </td></tr>';
5429 $resteapayeraffiche = 0;
5430 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5434 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5435 print
'<span class="opacitymedium">';
5436 print $langs->trans(
"Billed");
5437 print
'</td><td class="right">'.price($object->total_ttc).
'</td><td> </td></tr>';
5439 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5440 print
'<span class="opacitymedium">';
5441 print $langs->trans(
'RemainderToPay');
5442 if ($resteapayeraffiche < 0) {
5443 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5447 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td> </td></tr>';
5450 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
5451 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5452 print
'<span class="opacitymedium">';
5453 print $langs->trans(
'RemainderToPayMulticurrency');
5454 if ($resteapayeraffiche < 0) {
5455 print
' ('.$langs->trans(
'NegativeIfExcessReceived').
')';
5459 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">';
5461 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>';
5465 if (!empty($object->situation_final) && !empty($object->retained_warranty) && $displayWarranty) {
5468 $retainedWarranty = $total_global_ttc * $object->retained_warranty / 100;
5471 $retainedWarranty = $object->total_ttc * $object->retained_warranty / 100;
5474 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
5476 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>';
5479 print
'<tr><td colspan="'.$nbcols.
'" align="right">';
5480 print $langs->trans(
"RetainedWarranty").
' ('.$object->retained_warranty.
'%)';
5481 print !empty($object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date($object->retained_warranty_date_limit,
'day')) :
'';
5482 print
' :</td><td align="right">'.price($retainedWarranty).
'</td><td> </td></tr>';
5485 $resteapayeraffiche = $resteapayer;
5486 $cssforamountpaymentcomplete =
'amountpaymentneutral';
5489 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5490 print
'<span class="opacitymedium">'.$langs->trans(
'AlreadyPaidBack').
'</span>';
5491 print
'</td><td class="right"><span class="amount">'.price($sign * $totalpaid).
'</span></td><td> </td></tr>';
5494 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>';
5497 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5498 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBack');
5499 if ($resteapayeraffiche > 0) {
5500 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5502 print
'</span></td>';
5503 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
5504 print
'<td class="nowrap"> </td></tr>';
5507 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
5508 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
5509 print
'<span class="opacitymedium">'.$langs->trans(
'RemainderToPayBackMulticurrency');
5510 if ($resteapayeraffiche > 0) {
5511 print
' ('.$langs->trans(
'NegativeIfExcessRefunded').
')';
5515 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>';
5528 if (isModEnabled(
'margin')) {
5529 $formmargin->displayMarginInfos($object);
5535 print
'<div class="clearboth"></div><br><br>';
5538 $blocname =
'contacts';
5539 $title = $langs->trans(
'ContactsAddresses');
5540 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5544 $blocname =
'notes';
5545 $title = $langs->trans(
'Notes');
5546 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
5550 $result = $object->getLinesArray();
5554 global $inputalsopricewithtax;
5555 $inputalsopricewithtax = 1;
5559 if ($object->situation_cycle_ref && $object->statut == 0) {
5560 print
'<!-- Area to change globally the situation percent -->'.
"\n";
5561 print
'<div class="div-table-responsive">';
5563 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'#updatealllines" method="POST">';
5564 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
5565 print
'<input type="hidden" name="action" value="updatealllines" />';
5566 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
5567 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
5569 print
'<table id="tablelines_all_progress" class="noborder noshadow" width="100%">';
5571 print
'<tr class="liste_titre nodrag nodrop">';
5575 print
'<td align="center" width="5"> </td>';
5577 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
5578 print
'<td class="right">'.$langs->trans(
'Progress').
'</td>';
5579 print
'<td> </td>';
5582 print
'<tr class="nodrag nodrop">';
5585 print
'<td align="center" width="5"> </td>';
5587 print
'<td> </td>';
5588 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
5589 print
'<td class="right"><input type="submit" class="button" name="all_percent" value="Modifier" /></td>';
5600 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">
5601 <input type="hidden" name="token" value="' . newToken().
'">
5602 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
5603 <input type="hidden" name="mode" value="">
5604 <input type="hidden" name="page_y" value="">
5605 <input type="hidden" name="id" value="' . $object->id.
'">
5606 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
5609 if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
5610 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
5613 print
'<div class="div-table-responsive-no-min">';
5614 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
5617 if (!empty($object->lines)) {
5618 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
5622 if ($object->statut == 0 && $usercancreate && $action !=
'valid') {
5623 if ($action !=
'editline' && $action !=
'selectlines') {
5626 $parameters = array();
5627 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
5631 if (empty($reshook)) {
5632 $object->formAddObjectLine(1, $mysoc, $soc);
5635 $parameters = array();
5636 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters, $object, $action);
5650 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline') {
5651 print
'<div class="tabsAction">';
5653 $parameters = array();
5654 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
5655 if (empty($reshook)) {
5658 'class' =>
'classfortooltip'
5664 $ventilExportCompta = $object->getVentilExportCompta();
5666 if ($ventilExportCompta == 0) {
5667 if (
getDolGlobalString(
'INVOICE_CAN_BE_EDITED_EVEN_IF_PAYMENT_DONE') || ($resteapayer ==
price2num($object->total_ttc,
'MT', 1) && empty($object->paye))) {
5668 if (!$objectidnext && $object->is_last_in_cycle()) {
5669 if ($usercanunvalidate) {
5670 unset($params[
'attr'][
'title']);
5671 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=modif&token='.newToken(),
'',
true, $params);
5673 $params[
'attr'][
'title'] = $langs->trans(
'NotEnoughPermissions');
5674 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=modif&token='.newToken(),
'',
false, $params);
5676 } elseif (!$object->is_last_in_cycle()) {
5677 $params[
'attr'][
'title'] = $langs->trans(
'NotLastInCycle');
5678 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5680 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseReplacedInvoice');
5681 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5685 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5686 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
5691 $result = $discount->fetch(0, $object->id);
5699 && ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || $usercanreopen)) {
5700 if ($object->close_code !=
'replaced' || (!$objectidnext)) {
5701 unset($params[
'attr'][
'title']);
5702 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=reopen&token='.newToken(),
'',
true, $params);
5704 $params[
'attr'][
'title'] = $langs->trans(
"DisabledBecauseReplacedInvoice");
5705 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default',
'#',
'',
false, $params);
5712 $langs->load(
"contracts");
5714 if ($usercancreatecontract) {
5715 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>';
5722 if ($usercanvalidate) {
5723 unset($params[
'attr'][
'title']);
5724 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=valid&token='.newToken(),
'',
true, $params);
5729 if (empty($user->socid)) {
5731 if ($objectidnext) {
5732 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'SendMail').
'</span>';
5735 unset($params[
'attr'][
'title']);
5736 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=presend&mode=init#formmailbeforetitle',
'',
true, $params);
5738 unset($params[
'attr'][
'title']);
5739 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
5747 if ($resteapayer > 0) {
5748 if ($usercancreatewithdrarequest) {
5749 if (!$objectidnext && $object->close_code !=
'replaced') {
5750 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>';
5752 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
5763 if (isModEnabled(
'takepos') && $object->module_source ==
'takepos') {
5764 $langs->load(
"cashdesk");
5765 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
5766 print
'<a target="_blank" rel="noopener noreferrer" class="butAction" href="'.$receipt_url.
'?facid='.((int) $object->id).
'">'.$langs->trans(
'POSTicket').
'</a>';
5771 if ($objectidnext) {
5772 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
5776 $params[
'attr'][
'title'] = $langs->trans(
'DisabledBecauseRemainderToPayIsZero');
5777 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default',
'#',
'',
false, $params);
5781 unset($params[
'attr'][
'title']);
5782 print
dolGetButtonAction($langs->trans(
'DoPayment'),
'',
'default', DOL_URL_ROOT.
'/compta/paiement.php?facid='.$object->id.
'&action=create'.($object->fk_account > 0 ?
'&accountid='.$object->fk_account :
''),
'', true, $params);
5787 $sumofpayment = $totalpaid;
5788 $sumofpaymentall = $totalpaid + $totalcreditnotes + $totaldeposits;
5794 if ($resteapayer == 0) {
5795 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
5797 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.$object->id.
'&action=create&accountid='.$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
5803 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
5807 && (
getDolGlobalString(
'INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $sumofpayment == 0) && $object->total_ht < 0
5809 print
'<a class="butAction classfortooltip'.($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>';
5815 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertToReduc').
'</a>';
5817 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"AmountPaidMustMatchAmountOfDownPayment").
'">'.$langs->trans(
'ConvertToReduc').
'</span>';
5831 $params[
'attr'][
'title'] = $langs->trans(
'AmountPaidMustMatchAmountOfDownPayment');
5832 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default',
'#',
'',
false, $params);
5834 unset($params[
'attr'][
'title']);
5835 print
dolGetButtonAction($langs->trans(
'ClassifyPaid'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=paid',
'',
true, $params);
5840 if ($object->statut ==
Facture::STATUS_VALIDATED && $object->paye == 0 && $resteapayer > 0 && (!
getDolGlobalString(
'INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer != $object->total_ttc) && $usercanissuepayment) {
5841 if ($totalpaid > 0 || $totalcreditnotes > 0) {
5843 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
5846 if ($objectidnext) {
5847 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
5849 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
5857 if (!$objectidnext) {
5858 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>';
5865 && ($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) > 0
5868 && $object->is_last_in_cycle()
5871 if ($usercanunvalidate) {
5872 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>';
5874 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
5880 unset($params[
'attr'][
'title']);
5881 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=clone&object=invoice',
'',
true, $params);
5886 if (!$objectidnext && count($object->lines) > 0) {
5887 unset($params[
'attr'][
'title']);
5888 print
dolGetButtonAction($langs->trans(
'ChangeIntoRepeatableInvoice'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$object->id.
'&action=create',
'',
true, $params);
5897 && $object->situation_counter > 1
5898 && $object->is_last_in_cycle()
5899 && $usercanunvalidate
5901 if (($object->total_ttc - $totalcreditnotes) == 0) {
5902 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
5904 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
5909 if ($usercancreate && ($object->type == 5) && ($object->statut == 1 || $object->statut == 2)) {
5910 if ($object->is_last_in_cycle() && $object->situation_final != 1) {
5911 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.$object->id.
'&socid='.$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5912 } elseif (!$object->is_last_in_cycle()) {
5913 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5915 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5920 $isErasable = $object->is_erasable();
5921 if ($usercandelete || ($usercancreate && $isErasable == 1)) {
5922 $enableDelete =
false;
5925 if ($isErasable == -4) {
5926 $htmltooltip = $langs->trans(
'DisabledBecausePayments');
5927 } elseif ($isErasable == -3) {
5928 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastSituationInvoice');
5929 } elseif ($isErasable == -2) {
5930 $htmltooltip = $langs->trans(
'DisabledBecauseNotLastInvoice');
5931 } elseif ($isErasable == -1) {
5932 $htmltooltip = $langs->trans(
'DisabledBecauseDispatchedInBookkeeping');
5933 } elseif ($isErasable <= 0) {
5934 $htmltooltip = $langs->trans(
'DisabledBecauseNotErasable');
5935 } elseif ($objectidnext) {
5936 $htmltooltip = $langs->trans(
'DisabledBecauseReplacedInvoice');
5938 $deleteHref = $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=delete&token='.newToken();
5939 $enableDelete =
true;
5941 unset($params[
'attr'][
'title']);
5942 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete', $deleteHref,
'', $enableDelete, $params);
5944 unset($params[
'attr'][
'title']);
5945 print
dolGetButtonAction($htmltooltip, $langs->trans(
'Delete'),
'delete',
'#',
'',
false);
5952 if (
GETPOST(
'modelselected',
'alpha')) {
5953 $action =
'presend';
5955 if ($action !=
'prerelance' && $action !=
'presend') {
5956 print
'<div class="fichecenter"><div class="fichehalfleft">';
5957 print
'<a name="builddoc"></a>';
5961 $filedir = $conf->facture->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($object->ref);
5962 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.$object->id;
5963 $genallowed = $usercanread;
5964 $delallowed = $usercancreate;
5966 print $formfile->showdocuments(
5986 'remove_file_comfirm'
5989 $somethingshown = $formfile->numoffiles;
5992 $linktoelem = $form->showLinkToObjectBlock($object,
null, array(
'invoice'));
5994 $compatibleImportElementsList =
false;
5998 $compatibleImportElementsList = array(
'commande',
'propal');
6000 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
6004 $useonlinepayment = (isModEnabled(
'paypal') || isModEnabled(
'stripe') || isModEnabled(
'paybox'));
6007 print
'<br><!-- Link to pay -->'.
"\n";
6008 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
6009 print showOnlinePaymentUrl(
'invoice', $object->ref).
'<br>';
6012 print
'</div><div class="fichehalfright">';
6016 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/compta/facture/agenda.php?id='.$object->id);
6019 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
6021 $somethingshown =
$formactions->showactions($object,
'invoice', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
6023 print
'</div></div>';
6028 $modelmail =
'facture_send';
6029 $defaulttopic =
'SendBillRef';
6030 $diroutput = $conf->facture->multidir_output[$object->entity];
6031 $trackid =
'inv'.$object->id;
6033 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif( $action=='specimen') elseif($action=='setmodel') elseif( $action=='del') elseif($action=='setdoc') $formactions
View.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage bank accounts.
Class to manage accounting journals.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage shipments.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_DRAFT
Draft status.
const TYPE_STANDARD
Standard invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_PROFORMA
Proforma invoice (should not be used.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_DEPOSIT
Deposit invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const TYPE_CREDIT_NOTE
Credit note invoice.
const STATUS_CLOSED
Classified paid.
Class to manage invoice lines.
Class to manage invoice templates.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage notifications.
Class to manage payments of customer invoices.
Class ProductCombination Used to represent a product combination.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array='', $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.