39 require
'../../main.inc.php';
40 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
45 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
46 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
49 require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
50 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
51 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
52 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
53 if (!empty($conf->commande->enabled))
54 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
55 if (!empty($conf->projet->enabled)) {
56 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
57 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
59 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
61 if (!empty($conf->variants->enabled)) {
62 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
64 if (!empty($conf->accounting->enabled)) {
65 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
69 $langs->loadLangs(array(
'bills',
'companies',
'compta',
'products',
'banks',
'main',
'withdrawals'));
70 if (!empty($conf->incoterm->enabled)) $langs->load(
'incoterm');
71 if (!empty($conf->margin->enabled)) $langs->load(
'margins');
73 $projectid = (
GETPOST(
'projectid',
'int') ?
GETPOST(
'projectid',
'int') : 0);
77 $socid =
GETPOST(
'socid',
'int');
78 $action =
GETPOST(
'action',
'aZ09');
79 $confirm =
GETPOST(
'confirm',
'alpha');
80 $cancel =
GETPOST(
'cancel',
'alpha');
81 $lineid =
GETPOST(
'lineid',
'int');
82 $userid =
GETPOST(
'userid',
'int');
83 $search_ref =
GETPOST(
'sf_ref',
'alpha') ?
GETPOST(
'sf_ref',
'alpha') :
GETPOST(
'search_ref',
'alpha');
84 $search_societe =
GETPOST(
'search_societe',
'alpha');
85 $search_montant_ht =
GETPOST(
'search_montant_ht',
'alpha');
86 $search_montant_ttc =
GETPOST(
'search_montant_ttc',
'alpha');
87 $origin =
GETPOST(
'origin',
'alpha');
89 $fac_rec =
GETPOST(
'fac_rec',
'int');
92 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
93 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
94 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
99 $usehm = (!empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : 0);
105 $extrafields->fetch_name_optionals_label($object->table_element);
108 if ($id > 0 || !empty($ref)) {
109 if ($action !=
'add') {
110 $ret = $object->fetch($id, $ref,
'',
'', $conf->global->INVOICE_USE_SITUATION);
115 $hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
117 $usercanread = $user->rights->facture->lire;
118 $usercancreate = $user->rights->facture->creer;
119 $usercanissuepayment = $user->rights->facture->paiement;
120 $usercandelete = $user->rights->facture->supprimer;
121 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->validate)));
122 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send);
123 $usercanreopen = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->reopen);
124 $usercanunvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->unvalidate)));
126 $usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
127 $usercancreatemargin = $user->rights->margins->creer;
128 $usercanreadallmargin = $user->rights->margins->liretous;
129 $usercancreatewithdrarequest = $user->rights->prelevement->bons->creer;
131 $permissionnote = $usercancreate;
132 $permissiondellink = $usercancreate;
133 $permissiontoedit = $usercancreate;
134 $permissiontoadd = $usercancreate;
137 $fieldid = (!empty($ref) ?
'ref' :
'rowid');
138 if ($user->socid) $socid = $user->socid;
140 $result =
restrictedArea($user,
'facture', $id,
'',
'',
'fk_soc', $fieldid, $isdraft);
143 $retainedWarrantyInvoiceAvailableType = array();
144 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
145 $retainedWarrantyInvoiceAvailableType = explode(
'+', $conf->global->INVOICE_USE_RETAINED_WARRANTY);
153 $parameters = array(
'socid' => $socid);
154 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
155 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
161 if (!empty($backtopage))
163 header(
"Location: ".$backtopage);
169 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
171 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
173 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
176 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd)
181 $objectutil->socid = $socid;
182 $result = $objectutil->createFromClone($user, $id);
184 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
'?facid='.$result);
187 $langs->load(
"errors");
192 elseif ($action ==
'reopen' && $usercancreate) {
193 $result = $object->fetch($id);
196 $result = $object->set_unpaid($user);
198 header(
'Location: '.
$_SERVER[
"PHP_SELF"].
'?facid='.$id);
205 elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
206 $result = $object->fetch($id);
207 $object->fetch_thirdparty();
209 $idwarehouse =
GETPOST(
'idwarehouse');
211 $qualified_for_stock_change = 0;
212 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
213 $qualified_for_stock_change = $object->hasProductsOrServices(2);
215 $qualified_for_stock_change = $object->hasProductsOrServices(1);
218 $isErasable = $object->is_erasable();
220 if (($usercandelete && $isErasable > 0)
221 || ($usercancreate && $isErasable == 1))
223 $result = $object->delete($user, 0, $idwarehouse);
225 header(
'Location: '.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1');
233 elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate)
236 $object->fetch_thirdparty();
238 $result = $object->deleteline(
GETPOST(
'lineid'));
241 $outputlangs = $langs;
243 if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST[
'lang_id']))
244 $newlang = $_REQUEST[
'lang_id'];
245 if ($conf->global->MAIN_MULTILANGS && empty($newlang))
246 $newlang = $object->thirdparty->default_lang;
247 if (!empty($newlang)) {
249 $outputlangs->setDefaultLang($newlang);
250 $outputlangs->load(
'products');
252 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
253 $ret = $object->fetch($id);
254 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
257 header(
'Location: '.
$_SERVER[
"PHP_SELF"].
'?facid='.$id);
265 elseif ($action ==
'unlinkdiscount' && $usercancreate)
268 $result = $discount->fetch(
GETPOST(
"discountid"));
269 $discount->unlink_invoice();
271 elseif ($action ==
'valid' && $usercancreate)
278 if ($object->total_ht >= 0) {
279 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"), null,
'errors');
287 if (empty($conf->global->FACTURE_ENABLE_NEGATIVE) && $object->total_ttc < 0) {
288 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"), null,
'errors');
297 $array_of_total_ht_per_vat_rate = array();
298 $array_of_total_ht_devise_per_vat_rate = array();
299 foreach ($object->lines as $line) {
301 $vat_src_code_for_line =
'';
302 if (empty($array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
303 if (empty($array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line])) $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] = 0;
304 $array_of_total_ht_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->total_ht;
305 $array_of_total_ht_devise_per_vat_rate[$line->tva_tx.
'_'.$vat_src_code_for_line] += $line->multicurrency_total_ht;
309 foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue)
311 $tmp_total_ht = $array_of_total_ht_per_vat_rate[$vatrate];
312 $tmp_total_ht_devise = $array_of_total_ht_devise_per_vat_rate[$vatrate];
314 if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES))
316 if ($object->type == $object::TYPE_DEPOSIT) {
317 $langs->load(
"errors");
319 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"), null,
'errors');
323 $tmpvatratetoshow = explode(
'_', $vatrate);
324 $tmpvatratetoshow[0] = round($tmpvatratetoshow[0], 2);
326 if ($tmpvatratetoshow[0] != 0) {
327 $langs->load(
"errors");
328 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeForOneVATRate", $tmpvatratetoshow[0]), null,
'errors');
338 elseif ($action ==
'classin' && $usercancreate)
341 $object->setProject($_POST[
'projectid']);
342 } elseif ($action ==
'setmode' && $usercancreate)
345 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
348 } elseif ($action ==
'setretainedwarrantyconditions' && $user->rights->facture->creer)
351 $object->retained_warranty_fk_cond_reglement = 0;
352 $result = $object->setRetainedWarrantyPaymentTerms(
GETPOST(
'retained_warranty_fk_cond_reglement',
'int'));
355 $old_rw_date_lim_reglement = $object->retained_warranty_date_limit;
356 $new_rw_date_lim_reglement = $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement);
357 if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) $object->retained_warranty_date_limit = $new_rw_date_lim_reglement;
358 if ($object->retained_warranty_date_limit < $object->date) $object->retained_warranty_date_limit = $object->date;
359 $result = $object->update($user);
361 } elseif ($action ==
'setretainedwarranty' && $user->rights->facture->creer) {
363 $result = $object->setRetainedWarranty(
GETPOST(
'retained_warranty',
'float'));
366 } elseif ($action ==
'setretainedwarrantydatelimit' && $user->rights->facture->creer) {
368 $result = $object->setRetainedWarrantyDateLimit(
GETPOST(
'retained_warranty_date_limit',
'float'));
372 elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
373 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
375 elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
376 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
377 } elseif ($action ==
'setinvoicedate' && $usercancreate) {
379 $old_date_lim_reglement = $object->date_lim_reglement;
383 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")), null,
'errors');
384 header(
'Location: '.
$_SERVER[
"PHP_SELF"].
'?facid='.$id.
'&action=editinvoicedate');
387 $object->date = $date;
388 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
389 if ($new_date_lim_reglement > $old_date_lim_reglement) $object->date_lim_reglement = $new_date_lim_reglement;
390 if ($object->date_lim_reglement < $object->date) $object->date_lim_reglement = $object->date;
391 $result = $object->update($user);
395 } elseif ($action ==
'setdate_pointoftax' && $usercancreate) {
397 $date_pointoftax =
dol_mktime(12, 0, 0, $_POST[
'date_pointoftaxmonth'], $_POST[
'date_pointoftaxday'], $_POST[
'date_pointoftaxyear']);
398 $object->date_pointoftax = $date_pointoftax;
399 $result = $object->update($user);
403 } elseif ($action ==
'setconditions' && $usercancreate)
406 $object->cond_reglement_code = 0;
407 $object->cond_reglement_id = 0;
414 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
422 $old_date_lim_reglement = $object->date_lim_reglement;
423 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
424 if ($new_date_lim_reglement > $old_date_lim_reglement) $object->date_lim_reglement = $new_date_lim_reglement;
425 if ($object->date_lim_reglement < $object->date) $object->date_lim_reglement = $object->date;
426 $result = $object->update($user);
438 } elseif ($action ==
'setpaymentterm' && $usercancreate)
441 $object->date_lim_reglement =
dol_mktime(12, 0, 0, $_POST[
'paymenttermmonth'], $_POST[
'paymenttermday'], $_POST[
'paymenttermyear']);
442 if ($object->date_lim_reglement < $object->date) {
443 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
444 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"), null,
'warnings');
446 $result = $object->update($user);
450 } elseif ($action ==
'setrevenuestamp' && $usercancreate)
453 $object->revenuestamp =
GETPOST(
'revenuestamp');
454 $result = $object->update($user);
455 $object->update_price(1);
460 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
462 $outputlangs = $langs;
464 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
465 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
466 if (!empty($newlang)) {
468 $outputlangs->setDefaultLang($newlang);
469 $outputlangs->load(
'products');
471 $model = $object->model_pdf;
472 $ret = $object->fetch($id);
474 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
475 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
479 elseif ($action ==
'set_incoterms' && !empty($conf->incoterm->enabled))
481 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
483 elseif ($action ==
'setbankaccount' && $usercancreate)
485 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
486 } elseif ($action ==
'setremisepercent' && $usercancreate)
489 $result = $object->set_remise($user, $_POST[
'remise_percent']);
490 } elseif ($action ==
"setabsolutediscount" && $usercancreate)
495 if (
GETPOST(
"remise_id",
'int') > 0) {
496 $ret = $object->fetch($id);
498 $result = $object->insert_discount(
GETPOST(
"remise_id",
'int'));
507 if (
GETPOST(
"remise_id_for_payment",
'int') > 0)
509 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
511 $discount->fetch(
GETPOST(
"remise_id_for_payment",
'int'));
519 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"), null,
'errors');
524 $result = $discount->link_to_invoice(0, $id);
531 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
533 $outputlangs = $langs;
535 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
536 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
537 if (!empty($newlang)) {
539 $outputlangs->setDefaultLang($newlang);
541 $ret = $object->fetch($id);
543 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
544 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
546 } elseif ($action ==
'setref' && $usercancreate)
549 $object->setValueFrom(
'ref',
GETPOST(
'ref'),
'', null,
'',
'', $user,
'BILL_MODIFY');
550 } elseif ($action ==
'setref_client' && $usercancreate)
553 $object->set_ref_client(
GETPOST(
'ref_client'));
555 elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate)
557 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
560 $object->fetch_thirdparty();
565 $array_to_check = array(
'IDPROF1',
'IDPROF2',
'IDPROF3',
'IDPROF4',
'IDPROF5',
'IDPROF6',
'EMAIL');
566 foreach ($array_to_check as $key)
568 $keymin = strtolower($key);
569 $i = (int) preg_replace(
'/[^0-9]/',
'', $key);
570 $vallabel = $object->thirdparty->$keymin;
574 if ($object->thirdparty->isACompany())
577 if ($mysoc->country_id > 0 && $object->thirdparty->country_id == $mysoc->country_id)
579 $idprof_mandatory =
'SOCIETE_'.$key.
'_INVOICE_MANDATORY';
580 if (!$vallabel && !empty($conf->global->$idprof_mandatory))
582 $langs->load(
"errors");
584 setEventMessages($langs->trans(
'ErrorProdIdIsMandatory', $langs->transcountry(
'ProfId'.$i, $object->thirdparty->country_code)).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')', null,
'errors');
593 if (!empty($conf->global->SOCIETE_EMAIL_INVOICE_MANDATORY) && !isValidEMail($object->thirdparty->email))
595 $langs->load(
"errors");
597 setEventMessages($langs->trans(
"ErrorBadEMail", $object->thirdparty->email).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')', null,
'errors');
604 $array_to_check = array(
'REF_CUSTOMER'=>
'RefCustomer');
605 foreach ($array_to_check as $key => $val)
607 $keymin = strtolower($key);
608 $vallabel = $object->$keymin;
611 $keymandatory =
'INVOICE_'.$key.
'_MANDATORY_FOR_VALIDATION';
612 if (!$vallabel && !empty($conf->global->$keymandatory))
614 $langs->load(
"errors");
616 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val)), null,
'errors');
623 $qualified_for_stock_change = 0;
624 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
625 $qualified_for_stock_change = $object->hasProductsOrServices(2);
627 $qualified_for_stock_change = $object->hasProductsOrServices(1);
630 if ($qualified_for_stock_change)
632 if (!$idwarehouse || $idwarehouse == - 1) {
634 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")), null,
'errors');
642 $result = $object->validate($user,
'', $idwarehouse);
646 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
648 $outputlangs = $langs;
650 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
651 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
652 if (!empty($newlang)) {
654 $outputlangs->setDefaultLang($newlang);
655 $outputlangs->load(
'products');
657 $model = $object->model_pdf;
659 $ret = $object->fetch($id);
661 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
662 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
665 if (count($object->errors))
setEventMessages(null, $object->errors,
'errors');
670 elseif ($action ==
'confirm_modif' && $usercanunvalidate)
672 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
675 $object->fetch_thirdparty();
680 $qualified_for_stock_change = 0;
681 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
682 $qualified_for_stock_change = $object->hasProductsOrServices(2);
684 $qualified_for_stock_change = $object->hasProductsOrServices(1);
687 if ($qualified_for_stock_change)
689 if (!$idwarehouse || $idwarehouse == - 1) {
691 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")), null,
'errors');
699 $sql =
'SELECT pf.amount';
700 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf';
701 $sql .=
' WHERE pf.fk_facture = '.$object->id;
703 $result = $db->query($sql);
706 $num = $db->num_rows($result);
709 $objp = $db->fetch_object($result);
710 $totalpaye += $objp->amount;
717 $resteapayer = $object->total_ttc - $totalpaye;
720 $ventilExportCompta = $object->getVentilExportCompta();
723 if ($ventilExportCompta == 0)
725 if (!empty($conf->global->INVOICE_CAN_ALWAYS_BE_EDITED) || ($resteapayer == $object->total_ttc && empty($object->paye)))
727 $result = $object->setDraft($user, $idwarehouse);
728 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
731 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
733 $outputlangs = $langs;
735 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
736 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
737 if (!empty($newlang)) {
739 $outputlangs->setDefaultLang($newlang);
740 $outputlangs->load(
'products');
742 $model = $object->model_pdf;
743 $ret = $object->fetch($id);
745 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
751 elseif ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment)
754 $result = $object->set_paid($user);
755 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
757 elseif ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment)
760 $close_code =
GETPOST(
"close_code",
'restricthtml');
761 $close_note =
GETPOST(
"close_note",
'restricthtml');
763 $result = $object->set_paid($user, $close_code, $close_note);
764 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
766 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")), null,
'errors');
769 elseif ($action ==
'confirm_canceled' && $confirm ==
'yes') {
771 $close_code =
GETPOST(
"close_code",
'restricthtml');
772 $close_note =
GETPOST(
"close_note",
'restricthtml');
774 $result = $object->set_canceled($user, $close_code, $close_note);
775 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
777 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")), null,
'errors');
780 elseif ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate)
783 $object->fetch_thirdparty();
788 $result = $discountcheck->fetch(0, $object->id);
797 $amount_ht = $amount_tva = $amount_ttc = array();
798 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
802 foreach ($object->lines as $line)
804 if ($line->product_type < 9 && $line->total_ht != 0)
806 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
808 $amount_ht[$keyforvatrate] += $line->total_ht;
809 $amount_tva[$keyforvatrate] += $line->total_tva;
810 $amount_ttc[$keyforvatrate] += $line->total_ttc;
811 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
812 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
813 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
819 if (!empty($conf->global->INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED)) {
820 $alreadypaid = $object->getSommePaiement();
821 if ($alreadypaid && abs($alreadypaid) < abs($object->total_ttc)) {
822 $ratio = abs(($object->total_ttc - $alreadypaid) / $object->total_ttc);
823 foreach ($amount_ht as $vatrate => $val) {
824 $amount_ht[$vatrate] =
price2num($amount_ht[$vatrate] * $ratio,
'MU');
825 $amount_tva[$vatrate] =
price2num($amount_tva[$vatrate] * $ratio,
'MU');
826 $amount_ttc[$vatrate] =
price2num($amount_ttc[$vatrate] * $ratio,
'MU');
827 $multicurrency_amount_ht[$vatrate] =
price2num($multicurrency_amount_ht[$vatrate] * $ratio,
'MU');
828 $multicurrency_amount_tva[$vatrate] =
price2num($multicurrency_amount_tva[$vatrate] * $ratio,
'MU');
829 $multicurrency_amount_ttc[$vatrate] =
price2num($multicurrency_amount_ttc[$vatrate] * $ratio,
'MU');
838 $discount->description =
'(CREDIT_NOTE)';
844 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'), null,
'errors');
846 $discount->fk_soc = $object->socid;
847 $discount->fk_facture_source = $object->id;
856 $sql =
'SELECT SUM(pf.amount) as total_paiements';
857 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
858 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
859 $sql .=
' WHERE pf.fk_facture = '.$object->id;
860 $sql .=
' AND pf.fk_paiement = p.rowid';
861 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
862 $resql = $db->query($sql);
865 $res = $db->fetch_object(
$resql);
866 $total_paiements = $res->total_paiements;
869 $total_creditnote_and_deposit = 0;
870 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
871 $sql .=
" re.description, re.fk_facture_source";
872 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
873 $sql .=
" WHERE fk_facture = ".$object->id;
874 $resql = $db->query($sql);
876 while ($obj = $db->fetch_object(
$resql)) {
877 $total_creditnote_and_deposit += $obj->amount_ttc;
881 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object->total_ttc;
882 $discount->amount_tva = 0;
883 $discount->tva_tx = 0;
884 $discount->vat_src_code =
'';
886 $result = $discount->create($user);
894 foreach ($amount_ht as $tva_tx => $xxx)
896 $discount->amount_ht = abs($amount_ht[$tva_tx]);
897 $discount->amount_tva = abs($amount_tva[$tva_tx]);
898 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
899 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
900 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
901 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
906 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg))
908 $vat_src_code = $reg[1];
909 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
912 $discount->tva_tx = abs($tva_tx);
913 $discount->vat_src_code = $vat_src_code;
915 $result = $discount->create($user);
928 $result = $object->set_paid($user);
945 elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate)
951 $result = $paiement->fetch(
GETPOST(
'paiement_id'));
953 $result = $paiement->delete();
954 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
"?id=".$id);
963 elseif ($action ==
'add' && $usercancreate)
965 if ($socid > 0) $object->socid =
GETPOST(
'socid',
'int');
966 $selectedLines =
GETPOST(
'toselect',
'array');
971 $originentity =
GETPOST(
'originentity');
973 $ret = $extrafields->setOptionalsFromPost(null, $object);
974 if ($ret < 0) $error++;
980 if (empty($dateinvoice))
983 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")), null,
'errors');
987 if (!(
GETPOST(
'fac_replacement',
'int') > 0)) {
989 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")), null,
'errors');
993 $date_pointoftax =
dol_mktime(12, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'));
997 $result = $object->fetch(
GETPOST(
'fac_replacement',
'int'));
998 $object->fetch_thirdparty();
1000 $object->date = $dateinvoice;
1001 $object->date_pointoftax = $date_pointoftax;
1002 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1004 $object->ref_client =
GETPOST(
'ref_client');
1006 $object->model_pdf =
GETPOST(
'model');
1007 $object->fk_project =
GETPOST(
'projectid',
'int');
1008 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1009 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1010 $object->fk_account =
GETPOST(
'fk_account',
'int');
1011 $object->remise_absolue =
GETPOST(
'remise_absolue',
'alpha');
1012 $object->remise_percent =
GETPOST(
'remise_percent',
'alpha');
1013 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1014 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1015 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1016 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1019 $object->fk_facture_source =
GETPOST(
'fac_replacement',
'int');
1022 $id = $object->createFromCurrent($user);
1032 $sourceinvoice =
GETPOST(
'fac_avoir');
1033 if (!($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE))
1036 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")), null,
'errors');
1041 if (empty($dateinvoice))
1044 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")), null,
'errors');
1048 $date_pointoftax =
dol_mktime(12, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'));
1052 if (!empty($originentity)) {
1053 $object->entity = $originentity;
1055 $object->socid =
GETPOST(
'socid',
'int');
1056 $object->ref =
GETPOST(
'ref');
1057 $object->date = $dateinvoice;
1058 $object->date_pointoftax = $date_pointoftax;
1059 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1061 $object->ref_client =
GETPOST(
'ref_client');
1062 $object->model_pdf =
GETPOST(
'model');
1063 $object->fk_project =
GETPOST(
'projectid',
'int');
1064 $object->cond_reglement_id = 0;
1065 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
1066 $object->fk_account =
GETPOST(
'fk_account',
'int');
1067 $object->remise_absolue =
GETPOST(
'remise_absolue');
1068 $object->remise_percent =
GETPOST(
'remise_percent');
1069 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1070 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1071 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1072 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1075 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
1078 $facture_source =
new Facture($db);
1079 if ($facture_source->fetch($object->fk_facture_source) > 0)
1083 $object->situation_counter = $facture_source->situation_counter;
1084 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
1085 $facture_source->fetchPreviousNextSituationInvoice();
1088 $id = $object->create($user);
1095 if (
GETPOST(
'invoiceAvoirWithLines',
'int') == 1 && $id > 0)
1097 if (!empty($facture_source->lines))
1099 $fk_parent_line = 0;
1101 foreach ($facture_source->lines as $line)
1104 if (method_exists($line,
'fetch_optionals')) {
1106 $line->fetch_optionals();
1110 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1111 $fk_parent_line = 0;
1117 $source_fk_prev_id = $line->fk_prev_id;
1118 $line->fk_prev_id = $line->id;
1120 if (!empty($facture_source->tab_previous_situation_invoice))
1124 $tab_jumped_credit_notes = array();
1125 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
1126 $searchPreviousInvoice =
true;
1127 while ($searchPreviousInvoice)
1129 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1)
1131 $searchPreviousInvoice =
false;
1135 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
1141 $maxPrevSituationPercent = 0;
1142 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine)
1144 if ($prevLine->id == $source_fk_prev_id)
1146 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
1149 $line->total_ht = $line->total_ht - $prevLine->total_ht;
1150 $line->total_tva = $line->total_tva - $prevLine->total_tva;
1151 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
1152 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
1153 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
1155 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
1156 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
1157 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
1158 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
1163 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1168 $maxPrevSituationPercent = 0;
1169 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
1170 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine)
1172 if ($prevLine->fk_prev_id == $source_fk_prev_id)
1174 $maxPrevSituationPercent = $prevLine->situation_percent;
1176 $line->total_ht -= $prevLine->total_ht;
1177 $line->total_tva -= $prevLine->total_tva;
1178 $line->total_ttc -= $prevLine->total_ttc;
1179 $line->total_localtax1 -= $prevLine->total_localtax1;
1180 $line->total_localtax2 -= $prevLine->total_localtax2;
1182 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
1183 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
1184 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
1185 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
1191 $line->situation_percent += $maxPrevSituationPercent;
1197 $line->fk_facture = $object->id;
1198 $line->fk_parent_line = $fk_parent_line;
1200 $line->subprice = -$line->subprice;
1201 $line->pa_ht = $line->pa_ht;
1202 $line->total_ht = -$line->total_ht;
1203 $line->total_tva = -$line->total_tva;
1204 $line->total_ttc = -$line->total_ttc;
1205 $line->total_localtax1 = -$line->total_localtax1;
1206 $line->total_localtax2 = -$line->total_localtax2;
1208 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1209 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1210 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1211 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1213 $result = $line->insert(0, 1);
1215 $object->lines[] = $line;
1218 if ($result > 0 && $line->product_type == 9) {
1219 $fk_parent_line = $result;
1223 $object->update_price(1);
1227 if (
GETPOST(
'invoiceAvoirWithPaymentRestAmount',
'int') == 1 && $id > 0)
1229 if ($facture_source->fetch($object->fk_facture_source) > 0)
1231 $totalpaye = $facture_source->getSommePaiement();
1232 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1233 $totaldeposits = $facture_source->getSumDepositsUsed();
1234 $remain_to_pay = abs($facture_source->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits);
1236 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 1, 0, 0, 0, 0, 0,
'',
'',
'TTC');
1241 if (!empty($object->fk_facture_source) && $id > 0) {
1242 $facture_source->fetch($object->fk_facture_source);
1243 $facture_source->fetchObjectLinked();
1245 if (!empty($facture_source->linkedObjectsIds)) {
1246 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1247 $object->add_object_linked($sourcetype, current($TIds));
1258 if (empty($dateinvoice))
1261 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")), null,
'errors');
1265 $date_pointoftax =
dol_mktime(12, 0, 0, $_POST[
'date_pointoftaxmonth'], $_POST[
'date_pointoftaxday'], $_POST[
'date_pointoftaxyear']);
1269 $object->socid =
GETPOST(
'socid',
'int');
1270 $object->type =
GETPOST(
'type');
1271 $object->ref =
GETPOST(
'ref');
1272 $object->date = $dateinvoice;
1273 $object->date_pointoftax = $date_pointoftax;
1274 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1275 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1276 $object->ref_client =
GETPOST(
'ref_client');
1277 $object->model_pdf =
GETPOST(
'model');
1278 $object->fk_project =
GETPOST(
'projectid',
'int');
1279 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
1280 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1281 $object->fk_account =
GETPOST(
'fk_account',
'int');
1283 $object->remise_absolue =
GETPOST(
'remise_absolue');
1284 $object->remise_percent =
GETPOST(
'remise_percent');
1285 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1286 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1287 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1288 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1291 $object->fac_rec =
GETPOST(
'fac_rec',
'int');
1293 $id = $object->create($user);
1300 if (
GETPOST(
'socid',
'int') < 1)
1303 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")), null,
'errors');
1308 if (empty($dateinvoice))
1311 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")), null,
'errors');
1315 $date_pointoftax =
dol_mktime(12, 0, 0, $_POST[
'date_pointoftaxmonth'], $_POST[
'date_pointoftaxday'], $_POST[
'date_pointoftaxyear']);
1320 $object->socid =
GETPOST(
'socid',
'int');
1321 $object->type =
GETPOST(
'type');
1322 $object->ref =
GETPOST(
'ref');
1323 $object->date = $dateinvoice;
1324 $object->date_pointoftax = $date_pointoftax;
1325 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1326 $object->note_private = trim(
GETPOST(
'note_private',
'restricthtml'));
1327 $object->ref_client =
GETPOST(
'ref_client');
1328 $object->model_pdf =
GETPOST(
'model');
1329 $object->fk_project =
GETPOST(
'projectid');
1330 $object->cond_reglement_id = (
GETPOST(
'type') == 3 ? 1 :
GETPOST(
'cond_reglement_id'));
1331 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
1332 $object->fk_account =
GETPOST(
'fk_account',
'int');
1334 $object->remise_absolue =
GETPOST(
'remise_absolue');
1335 $object->remise_percent =
GETPOST(
'remise_percent');
1336 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1337 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1338 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1339 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1343 $object->situation_counter = 1;
1344 $object->situation_final = 0;
1345 $object->situation_cycle_ref = $object->newCycle();
1348 if (in_array($object->type, $retainedWarrantyInvoiceAvailableType)) {
1349 $object->retained_warranty =
GETPOST(
'retained_warranty',
'int');
1350 $object->retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
1352 $object->retained_warranty = 0;
1353 $object->retained_warranty_fk_cond_reglement = 0;
1356 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1357 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
1358 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
1360 $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);
1362 $object->fetch_thirdparty();
1365 if (!empty($origin) && !empty($originid))
1368 $element = $subelement = $origin;
1369 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1370 $element = $regs [1];
1371 $subelement = $regs [2];
1375 if ($element ==
'order') {
1376 $element = $subelement =
'commande';
1378 if ($element ==
'propal') {
1379 $element =
'comm/propal';
1380 $subelement =
'propal';
1382 if ($element ==
'contract') {
1383 $element = $subelement =
'contrat';
1385 if ($element ==
'inter') {
1386 $element = $subelement =
'ficheinter';
1388 if ($element ==
'shipping') {
1389 $element = $subelement =
'expedition';
1392 $object->origin = $origin;
1393 $object->origin_id = $originid;
1396 $object->linked_objects[$object->origin] = $object->origin_id;
1398 if ($object->origin ==
'shipping')
1400 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1402 $exp->fetch($object->origin_id);
1403 $exp->fetchObjectLinked();
1404 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1405 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1406 $object->linked_objects[
'commande'] = $value;
1411 if (is_array($_POST[
'other_linked_objects']) && !empty($_POST[
'other_linked_objects']))
1413 $object->linked_objects = array_merge($object->linked_objects, $_POST[
'other_linked_objects']);
1416 $id = $object->create($user);
1422 $classname = ucfirst($subelement);
1423 $srcobject =
new $classname($db);
1425 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines or deposit lines");
1426 $result = $srcobject->fetch($object->origin_id);
1428 $typeamount =
GETPOST(
'typedeposit',
'aZ09');
1434 $amountdeposit = array();
1435 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA))
1437 if ($typeamount ==
'amount') $amount = $valuedeposit;
1438 else $amount = $srcobject->total_ttc * ($valuedeposit / 100);
1440 $TTotalByTva = array();
1441 foreach ($srcobject->lines as &$line)
1443 if (!empty($line->special_code))
continue;
1444 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1447 foreach ($TTotalByTva as $tva => &$total)
1449 $coef = $total / $srcobject->total_ttc;
1450 $am = $amount * $coef;
1451 $amount_ttc_diff += $am;
1452 $amountdeposit[$tva] += $am / (1 + $tva / 100);
1455 if ($typeamount ==
'amount')
1457 $amountdeposit[0] = $valuedeposit;
1458 } elseif ($typeamount ==
'variable')
1463 $lines = $srcobject->lines;
1464 $numlines = count($lines);
1465 for ($i = 0; $i < $numlines; $i++)
1468 if (empty($lines[$i]->qty)) $qualified = 0;
1469 if (!empty($lines[$i]->special_code)) $qualified = 0;
1471 $totalamount += $lines[$i]->total_ht;
1472 $tva_tx = $lines[$i]->tva_tx;
1473 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $valuedeposit) / 100;
1477 if ($totalamount == 0) {
1478 $amountdeposit[0] = 0;
1486 $amount_ttc_diff = $amountdeposit[0];
1489 foreach ($amountdeposit as $tva => $amount)
1491 if (empty($amount))
continue;
1494 'amount' =>
'FixAmount',
1495 'variable' =>
'VarAmount'
1497 $descline =
'(DEPOSIT)';
1499 if ($typeamount ==
'amount') {
1500 $descline .=
' ('.price($valuedeposit,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
')';
1501 } elseif ($typeamount ==
'variable') {
1502 $descline .=
' ('.$valuedeposit.
'%)';
1505 $descline .=
' - '.$srcobject->ref;
1506 $result = $object->addline(
1513 (empty($conf->global->INVOICE_PRODUCTID_DEPOSIT) ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT),
1518 $lines[$i]->info_bits,
1524 $lines[$i]->special_code,
1534 $diff = $object->total_ttc - $amount_ttc_diff;
1536 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0)
1538 $object->fetch_lines();
1539 $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100);
1540 $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);
1548 $lines = $srcobject->lines;
1549 if (empty($lines) && method_exists($srcobject,
'fetch_lines'))
1551 $srcobject->fetch_lines();
1552 $lines = $srcobject->lines;
1557 if (is_array($lines)) {
1558 foreach ($lines as $line) {
1560 $line->qty =
price2num($line->qty * $valuedeposit / 100,
'MS');
1565 $fk_parent_line = 0;
1566 $num = count($lines);
1568 for ($i = 0; $i < $num; $i++)
1570 if (!in_array($lines[$i]->
id, $selectedLines))
continue;
1573 if ($srcobject->element ==
'shipping' && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS && $lines[$i]->qty == 0)
continue;
1575 if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE =
'5';
1576 if ($srcobject->element ==
'contrat' && in_array($lines[$i]->
statut, explode(
',', $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)))
continue;
1578 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1579 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->libelle);
1580 if ($object->situation_counter == 1) $lines[$i]->situation_percent = 0;
1582 if ($lines[$i]->subprice < 0 && empty($conf->global->INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN))
1586 $discount->fk_soc = $object->socid;
1587 $discount->amount_ht = abs($lines[$i]->total_ht);
1588 $discount->amount_tva = abs($lines[$i]->total_tva);
1589 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1590 $discount->tva_tx = $lines[$i]->tva_tx;
1591 $discount->fk_user = $user->id;
1592 $discount->description = $desc;
1593 $discountid = $discount->create($user);
1594 if ($discountid > 0) {
1595 $result = $object->insert_discount($discountid);
1603 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1606 $date_start =
false;
1607 if ($lines[$i]->date_debut_prevue)
1608 $date_start = $lines[$i]->date_debut_prevue;
1609 if ($lines[$i]->date_debut_reel)
1610 $date_start = $lines[$i]->date_debut_reel;
1611 if ($lines[$i]->date_start)
1612 $date_start = $lines[$i]->date_start;
1616 if ($lines[$i]->date_fin_prevue)
1617 $date_end = $lines[$i]->date_fin_prevue;
1618 if ($lines[$i]->date_fin_reel)
1619 $date_end = $lines[$i]->date_fin_reel;
1620 if ($lines[$i]->date_end)
1621 $date_end = $lines[$i]->date_end;
1624 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1625 $fk_parent_line = 0;
1629 if (method_exists($lines[$i],
'fetch_optionals')) {
1630 $lines[$i]->fetch_optionals();
1631 $array_options = $lines[$i]->array_options;
1634 $tva_tx = $lines[$i]->tva_tx;
1635 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1639 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty);
1640 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty);
1642 $result = $object->addline(
1643 $desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $localtax1_tx, $localtax2_tx, $lines[$i]->fk_product,
1644 $lines[$i]->remise_percent, $date_start, $date_end, 0, $lines[$i]->info_bits, $lines[$i]->fk_remise_except,
1645 'HT', 0, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $object->origin, $lines[$i]->rowid,
1646 $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_options,
1647 $lines[$i]->situation_percent, $lines[$i]->fk_prev_id, $lines[$i]->fk_unit
1659 if ($result > 0 && $lines[$i]->product_type == 9) {
1660 $fk_parent_line = $result;
1697 $parameters = array(
'objFrom' => $srcobject);
1698 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1710 $id = $object->create($user);
1712 for ($i = 1; $i <= $NBLINES; $i++) {
1713 if ($_POST[
'idprod'.$i]) {
1715 $product->fetch($_POST[
'idprod'.$i]);
1716 $startday =
dol_mktime(12, 0, 0, $_POST[
'date_start'.$i.
'month'], $_POST[
'date_start'.$i.
'day'], $_POST[
'date_start'.$i.
'year']);
1717 $endday =
dol_mktime(12, 0, 0, $_POST[
'date_end'.$i.
'month'], $_POST[
'date_end'.$i.
'day'], $_POST[
'date_end'.$i.
'year']);
1718 $result = $object->addline($product->description, $product->price, $_POST[
'qty'.$i], $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx, $_POST[
'idprod'.$i], $_POST[
'remise_percent'.$i], $startday, $endday, 0, 0,
'', $product->price_base_type, $product->price_ttc, $product->type, -1, 0,
'', 0, 0, null, 0,
'', 0, 100,
'', $product->fk_unit);
1729 if (empty($datefacture)) {
1731 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date"));
1735 $date_pointoftax =
dol_mktime(12, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'));
1737 if (!(
GETPOST(
'situations',
'int') > 0)) {
1739 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"InvoiceSituation"));
1745 $result = $object->fetch(
GETPOST(
'situations',
'int'));
1746 $object->fk_facture_source =
GETPOST(
'situations',
'int');
1749 if (!empty($origin) && !empty($originid))
1751 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1753 $object->origin = $origin;
1754 $object->origin_id = $originid;
1757 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY))
1759 $retained_warranty =
GETPOST(
'retained_warranty',
'int');
1762 $object->retained_warranty =
price2num($retained_warranty);
1765 if (
GETPOST(
'retained_warranty_fk_cond_reglement',
'int') > 0)
1767 $object->retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
1770 $retained_warranty_date_limit =
GETPOST(
'retained_warranty_date_limit');
1771 if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
1772 $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
1774 $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);
1777 foreach ($object->lines as $i => &$line)
1779 $line->origin = $object->origin;
1780 $line->origin_id = $line->id;
1781 $line->fk_prev_id = $line->id;
1782 $line->fetch_optionals();
1783 $line->situation_percent = $line->get_prev_progress($object->id);
1786 $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);
1787 $line->total_ht = $tabprice[0];
1788 $line->total_tva = $tabprice[1];
1789 $line->total_ttc = $tabprice[2];
1790 $line->total_localtax1 = $tabprice[9];
1791 $line->total_localtax2 = $tabprice[10];
1792 $line->multicurrency_total_ht = $tabprice[16];
1793 $line->multicurrency_total_tva = $tabprice[17];
1794 $line->multicurrency_total_ttc = $tabprice[18];
1797 if ($line->fk_remise_except)
1800 $result = $discount->fetch($line->fk_remise_except);
1804 if ($discount->fk_facture_line > 0)
1806 $line->fk_remise_except = 0;
1813 $object->fetch_thirdparty();
1814 $object->date = $datefacture;
1815 $object->date_pointoftax = $date_pointoftax;
1816 $object->note_public = trim(
GETPOST(
'note_public',
'restricthtml'));
1817 $object->note = trim(
GETPOST(
'note',
'restricthtml'));
1818 $object->note_private = trim(
GETPOST(
'note',
'restricthtml'));
1819 $object->ref_client =
GETPOST(
'ref_client',
'alpha');
1820 $object->model_pdf =
GETPOST(
'model',
'alpha');
1821 $object->fk_project =
GETPOST(
'projectid',
'int');
1822 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1823 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1824 $object->remise_absolue =
GETPOST(
'remise_absolue',
'int');
1825 $object->remise_percent =
GETPOST(
'remise_percent',
'int');
1829 $object->situation_counter = $object->situation_counter + 1;
1830 $id = $object->createFromCurrent($user);
1833 $mesg = $object->error;
1835 $nextSituationInvoice =
new Facture($db);
1836 $nextSituationInvoice->fetch($id);
1839 $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
1840 $ret = $extrafields->setOptionalsFromPost(null, $nextSituationInvoice);
1842 $nextSituationInvoice->insertExtraFields();
1849 if ($id > 0 && !$error)
1854 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && count($object->lines))
1856 $outputlangs = $langs;
1858 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
1859 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
1860 if (!empty($newlang)) {
1861 $outputlangs =
new Translate(
"", $conf);
1862 $outputlangs->setDefaultLang($newlang);
1863 $outputlangs->load(
'products');
1865 $model = $object->model_pdf;
1866 $ret = $object->fetch($id);
1868 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1869 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
1872 header(
'Location: '.
$_SERVER[
"PHP_SELF"].
'?facid='.$id);
1877 $_GET[
"origin"] = $_POST[
"origin"];
1878 $_GET[
"originid"] = $_POST[
"originid"];
1881 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'') {
1883 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
1884 $vat_rate = str_replace(
'*',
'', $vat_rate);
1885 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1886 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1887 foreach ($object->lines as $line) {
1888 $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);
1890 } elseif ($action ==
'addline' && $usercancreate)
1892 $langs->load(
'errors');
1897 $product_desc = (
GETPOST(
'dp_desc',
'none') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
1900 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'alpha');
1901 if ($prod_entry_mode ==
'free')
1904 $tva_tx = (
GETPOST(
'tva_tx',
'alpha') ?
GETPOST(
'tva_tx',
'alpha') : 0);
1906 $idprod =
GETPOST(
'idprod',
'int');
1910 $qty =
GETPOST(
'qty'.$predef);
1911 $remise_percent =
GETPOST(
'remise_percent'.$predef);
1914 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1915 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
1917 if (is_array($extralabelsline)) {
1919 foreach ($extralabelsline as $key => $value) {
1920 unset($_POST[
"options_".$key.$predef]);
1924 if (empty($idprod) && ($price_ht < 0) && ($qty < 0)) {
1925 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
1928 if (!$prod_entry_mode)
1932 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'), null,
'errors');
1936 if ($prod_entry_mode ==
'free' && empty($idprod) &&
GETPOST(
'type') < 0) {
1937 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')), null,
'errors');
1940 if (($prod_entry_mode ==
'free' && empty($idprod) && (($price_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) || $price_ht ==
'') && $price_ht_devise ==
'') && $object->type !=
Facture::TYPE_CREDIT_NOTE)
1942 if ($price_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES))
1944 $langs->load(
"errors");
1945 if ($object->type == $object::TYPE_DEPOSIT) {
1947 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"), null,
'errors');
1949 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")), null,
'errors');
1953 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")), null,
'errors');
1958 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
1961 if ($prod_entry_mode ==
'free' && empty($idprod) && empty($product_desc)) {
1962 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')), null,
'errors');
1966 $langs->load(
"errors");
1967 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'), null,
'errors');
1971 if (!$error && !empty($conf->variants->enabled) && $prod_entry_mode !=
'free') {
1972 if ($combinations =
GETPOST(
'combinations',
'array')) {
1976 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1977 $idprod = $res->fk_product_child;
1979 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'), null,
'errors');
1985 if (!$error && ($qty >= 0) && (!empty($product_desc) || !empty($idprod))) {
1986 $ret = $object->fetch($id);
1991 $ret = $object->fetch_thirdparty();
1996 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
2007 if (!empty($idprod))
2010 $prod->fetch($idprod);
2012 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
2017 $datapriceofproduct = $prod->getSellPrice($mysoc, $object->thirdparty, $pqp);
2019 $pu_ht = $datapriceofproduct[
'pu_ht'];
2020 $pu_ttc = $datapriceofproduct[
'pu_ttc'];
2021 $price_min = $datapriceofproduct[
'price_min'];
2022 $price_base_type = $datapriceofproduct[
'price_base_type'];
2023 $tva_tx = $datapriceofproduct[
'tva_tx'];
2024 $tva_npr = $datapriceofproduct[
'tva_npr'];
2026 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
2027 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
2030 if (!empty($price_ht) || $price_ht ===
'0')
2033 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2036 elseif ($tmpvat != $tmpprodvat)
2038 if ($price_base_type !=
'HT')
2040 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
2042 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
2049 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
2050 $outputlangs = $langs;
2052 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09'))
2053 $newlang =
GETPOST(
'lang_id',
'aZ09');
2054 if (empty($newlang))
2055 $newlang = $object->thirdparty->default_lang;
2056 if (!empty($newlang)) {
2057 $outputlangs =
new Translate(
"", $conf);
2058 $outputlangs->setDefaultLang($newlang);
2059 $outputlangs->load(
'products');
2062 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->description;
2064 $desc = $prod->description;
2067 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) $desc = $product_desc;
2068 else $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
2071 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
2074 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
2075 $outputlangs = $langs;
2077 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha'))
2078 $newlang =
GETPOST(
'lang_id',
'alpha');
2079 if (empty($newlang))
2080 $newlang = $object->thirdparty->default_lang;
2081 if (!empty($newlang)) {
2082 $outputlangs =
new Translate(
"", $conf);
2083 $outputlangs->setDefaultLang($newlang);
2084 $outputlangs->load(
'products');
2086 if (!empty($prod->customcode))
2087 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2088 if (!empty($prod->customcode) && !empty($prod->country_code))
2090 if (!empty($prod->country_code))
2091 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
2093 if (!empty($prod->customcode))
2094 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
2095 if (!empty($prod->customcode) && !empty($prod->country_code))
2097 if (!empty($prod->country_code))
2098 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
2104 $type = $prod->type;
2105 $fk_unit = $prod->fk_unit;
2109 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
2110 $tva_tx = str_replace(
'*',
'', $tva_tx);
2111 if (empty($tva_tx)) $tva_npr = 0;
2112 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2113 $desc = $product_desc;
2115 $fk_unit =
GETPOST(
'units',
'alpha');
2116 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
2124 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
2125 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
2132 $price2num_remise_percent =
price2num($remise_percent);
2133 $price2num_price_min =
price2num($price_min);
2134 if (empty($price2num_pu_ht)) $price2num_pu_ht = 0;
2135 if (empty($price2num_remise_percent)) $price2num_remise_percent = 0;
2136 if (empty($price2num_price_min)) $price2num_price_min = 0;
2138 if ($usercanproductignorepricemin && (!empty($price_min) && ($price2num_pu_ht * (1 - $price2num_remise_percent / 100) < $price2num_price_min))) {
2139 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
2143 $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, - 1, $special_code,
'', 0,
GETPOST(
'fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $_POST[
'progress'],
'', $fk_unit, $pu_ht_devise);
2148 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
2150 $outputlangs = $langs;
2152 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
2153 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
2154 if (!empty($newlang)) {
2155 $outputlangs =
new Translate(
"", $conf);
2156 $outputlangs->setDefaultLang($newlang);
2157 $outputlangs->load(
'products');
2159 $model = $object->model_pdf;
2160 $ret = $object->fetch($id);
2162 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2163 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
2166 unset($_POST[
'prod_entry_mode']);
2168 unset($_POST[
'qty']);
2169 unset($_POST[
'type']);
2170 unset($_POST[
'remise_percent']);
2171 unset($_POST[
'price_ht']);
2172 unset($_POST[
'multicurrency_price_ht']);
2173 unset($_POST[
'price_ttc']);
2174 unset($_POST[
'tva_tx']);
2175 unset($_POST[
'product_ref']);
2176 unset($_POST[
'product_label']);
2177 unset($_POST[
'product_desc']);
2178 unset($_POST[
'fournprice']);
2179 unset($_POST[
'buying_price']);
2180 unset($_POST[
'np_marginRate']);
2181 unset($_POST[
'np_markRate']);
2182 unset($_POST[
'dp_desc']);
2183 unset($_POST[
'idprod']);
2184 unset($_POST[
'units']);
2186 unset($_POST[
'date_starthour']);
2187 unset($_POST[
'date_startmin']);
2188 unset($_POST[
'date_startsec']);
2189 unset($_POST[
'date_startday']);
2190 unset($_POST[
'date_startmonth']);
2191 unset($_POST[
'date_startyear']);
2192 unset($_POST[
'date_endhour']);
2193 unset($_POST[
'date_endmin']);
2194 unset($_POST[
'date_endsec']);
2195 unset($_POST[
'date_endday']);
2196 unset($_POST[
'date_endmonth']);
2197 unset($_POST[
'date_endyear']);
2199 unset($_POST[
'situations']);
2200 unset($_POST[
'progress']);
2208 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha'))
2211 $object->fetch_thirdparty();
2226 if (preg_match(
'/\*/', $vat_rate)) $info_bits |= 0x01;
2229 $vat_rate = str_replace(
'*',
'', $vat_rate);
2230 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty);
2231 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty);
2238 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
2239 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
2241 if (is_array($extralabelsline)) {
2243 foreach ($extralabelsline as $key => $value) {
2244 unset($_POST[
"options_".$key]);
2249 $special_code =
GETPOST(
'special_code');
2250 if (!
GETPOST(
'qty')) $special_code = 3;
2253 $line->fetch(
GETPOST(
'lineid',
'int'));
2254 $percent = $line->get_prev_progress($object->id);
2261 $mesg = $langs->trans(
"CantBeNullOrPositive");
2265 } elseif (
GETPOST(
'progress') < $line->situation_percent)
2267 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
2272 } elseif (
GETPOST(
'progress') < $percent)
2274 $mesg =
'<div class="warning">'.$langs->trans(
"CantBeLessThanMinPercent").
'</div>';
2281 $productid =
GETPOST(
'productid',
'int');
2282 if (!empty($productid))
2285 $product->fetch($productid);
2287 $type = $product->type;
2289 $price_min = $product->price_min;
2290 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level))
2291 $price_min = $product->multiprices_min [$object->thirdparty->price_level];
2297 setEventMessages($langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null,
'errors');
2302 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2306 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")), null,
'errors');
2311 $langs->load(
"errors");
2312 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'), null,
'errors');
2315 if ((empty($productid) && (($pu_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) || $pu_ht ==
'') && $pu_ht_devise ==
'') && $object->type !=
Facture::TYPE_CREDIT_NOTE)
2317 if ($pu_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES))
2319 $langs->load(
"errors");
2320 if ($object->type == $object::TYPE_DEPOSIT) {
2322 setEventMessages($langs->trans(
"ErrorLinesCantBeNegativeOnDeposits"), null,
'errors');
2324 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT"), $langs->transnoentitiesnoconv(
"CustomerAbsoluteDiscountShort")), null,
'errors');
2328 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")), null,
'errors');
2336 if (empty($usercancreatemargin))
2338 foreach ($object->lines as &$line)
2340 if ($line->id ==
GETPOST(
'lineid'))
2342 $fournprice = $line->fk_fournprice;
2343 $buyingprice = $line->pa_ht;
2349 $result = $object->updateline(
GETPOST(
'lineid',
'int'), $description, $pu_ht, $qty,
price2num(
GETPOST(
'remise_percent',
'alpha')),
2350 $date_start, $date_end, $vat_rate, $localtax1_rate, $localtax2_rate,
'HT', $info_bits, $type,
2351 GETPOST(
'fk_parent_line',
'int'), 0, $fournprice, $buyingprice, $label, $special_code, $array_options,
price2num(
GETPOST(
'progress',
'alpha')),
2352 GETPOST(
'units',
'alpha'), $pu_ht_devise);
2355 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2357 $outputlangs = $langs;
2359 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09'))
2360 $newlang =
GETPOST(
'lang_id',
'aZ09');
2361 if ($conf->global->MAIN_MULTILANGS && empty($newlang))
2362 $newlang = $object->thirdparty->default_lang;
2363 if (!empty($newlang)) {
2364 $outputlangs =
new Translate(
"", $conf);
2365 $outputlangs->setDefaultLang($newlang);
2366 $outputlangs->load(
'products');
2369 $ret = $object->fetch($id);
2370 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2373 unset($_POST[
'qty']);
2374 unset($_POST[
'type']);
2375 unset($_POST[
'productid']);
2376 unset($_POST[
'remise_percent']);
2377 unset($_POST[
'price_ht']);
2378 unset($_POST[
'multicurrency_price_ht']);
2379 unset($_POST[
'price_ttc']);
2380 unset($_POST[
'tva_tx']);
2381 unset($_POST[
'product_ref']);
2382 unset($_POST[
'product_label']);
2383 unset($_POST[
'product_desc']);
2384 unset($_POST[
'fournprice']);
2385 unset($_POST[
'buying_price']);
2386 unset($_POST[
'np_marginRate']);
2387 unset($_POST[
'np_markRate']);
2389 unset($_POST[
'dp_desc']);
2390 unset($_POST[
'idprod']);
2391 unset($_POST[
'units']);
2393 unset($_POST[
'date_starthour']);
2394 unset($_POST[
'date_startmin']);
2395 unset($_POST[
'date_startsec']);
2396 unset($_POST[
'date_startday']);
2397 unset($_POST[
'date_startmonth']);
2398 unset($_POST[
'date_startyear']);
2399 unset($_POST[
'date_endhour']);
2400 unset($_POST[
'date_endmin']);
2401 unset($_POST[
'date_endsec']);
2402 unset($_POST[
'date_endday']);
2403 unset($_POST[
'date_endmonth']);
2404 unset($_POST[
'date_endyear']);
2406 unset($_POST[
'situations']);
2407 unset($_POST[
'progress']);
2412 } elseif ($action ==
'updatealllines' && $usercancreate && $_POST[
'all_percent'] == $langs->trans(
'Modifier'))
2415 if (
GETPOST(
'all_progress') !=
"")
2417 $all_progress =
GETPOST(
'all_progress',
'int');
2418 foreach ($object->lines as $line)
2420 $percent = $line->get_prev_progress($object->id);
2421 if (floatval($all_progress) < floatval($percent)) {
2422 $mesg = $langs->trans(
"Line").
' '.$i.
' : '.$langs->trans(
"CantBeLessThanMinPercent");
2425 }
else $object->update_percent($line, $_POST[
'all_progress']);
2428 } elseif ($action ==
'updateline' && $usercancreate && $_POST[
'cancel'] == $langs->trans(
"Cancel")) {
2429 header(
'Location: '.
$_SERVER[
"PHP_SELF"].
'?facid='.$id);
2432 elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate)
2434 $object->fetch($id,
'',
'',
'',
true);
2440 && $object->is_last_in_cycle()
2441 && $usercanunvalidate
2445 $newCycle = $object->newCycle();
2449 $lastCycle = $object->situation_cycle_ref;
2450 $lastSituationCounter = $object->situation_counter;
2451 $linkedCreditNotesList = array();
2453 if (count($object->tab_next_situation_invoice) > 0) {
2454 foreach ($object->tab_next_situation_invoice as $next_invoice) {
2456 && $next_invoice->situation_counter == $object->situation_counter
2457 && $next_invoice->fk_facture_source == $object->id
2460 $linkedCreditNotesList[] = $next_invoice->id;
2465 $object->situation_cycle_ref = $newCycle;
2466 $object->situation_counter = 1;
2467 $object->situation_final = 0;
2468 if ($object->update($user) > 0)
2471 if (count($linkedCreditNotesList) > 0)
2474 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture ';
2475 $sql .=
' SET situation_cycle_ref='.$newCycle;
2476 $sql .=
' , situation_final=0';
2477 $sql .=
' , situation_counter='.$object->situation_counter;
2478 $sql .=
' WHERE rowid IN ('.implode(
',', $linkedCreditNotesList).
')';
2480 $resql = $db->query($sql);
2484 foreach ($object->lines as $line)
2487 if ($line->product_type == 9)
continue;
2490 if (!empty($object->tab_previous_situation_invoice))
2493 $lineIndex = count($object->tab_previous_situation_invoice) - 1;
2494 $searchPreviousInvoice =
true;
2495 while ($searchPreviousInvoice)
2499 $searchPreviousInvoice =
false;
2507 $maxPrevSituationPercent = 0;
2508 foreach ($object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine)
2510 if ($prevLine->id == $line->fk_prev_id)
2512 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
2517 $line->situation_percent = $line->situation_percent - $maxPrevSituationPercent;
2519 if ($line->update() < 0) $errors++;
2527 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
"?id=".$id);
2529 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
2532 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
2535 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
2539 elseif ($action ==
'import_lines_from_object'
2544 $fromElement =
GETPOST(
'fromelement');
2545 $fromElementid =
GETPOST(
'fromelementid');
2546 $importLines =
GETPOST(
'line_checkbox');
2548 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid))
2550 if ($fromElement ==
'commande')
2553 $lineClassName =
'OrderLine';
2554 } elseif ($fromElement ==
'propal')
2556 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
2557 $lineClassName =
'PropaleLigne';
2559 $nextRang = count($object->lines) + 1;
2562 foreach ($importLines as $lineId)
2564 $lineId = intval($lineId);
2565 $originLine =
new $lineClassName($db);
2566 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0)
2568 $originLine->fetch_optionals();
2569 $desc = $originLine->desc;
2570 $pu_ht = $originLine->subprice;
2571 $qty = $originLine->qty;
2572 $txtva = $originLine->tva_tx;
2573 $txlocaltax1 = $originLine->localtax1_tx;
2574 $txlocaltax2 = $originLine->localtax2_tx;
2575 $fk_product = $originLine->fk_product;
2576 $remise_percent = $originLine->remise_percent;
2577 $date_start = $originLine->date_start;
2578 $date_end = $originLine->date_end;
2580 $info_bits = $originLine->info_bits;
2581 $fk_remise_except = $originLine->fk_remise_except;
2582 $price_base_type =
'HT';
2584 $type = $originLine->product_type;
2585 $rang = $nextRang++;
2586 $special_code = $originLine->special_code;
2587 $origin = $originLine->element;
2588 $origin_id = $originLine->id;
2589 $fk_parent_line = 0;
2590 $fk_fournprice = $originLine->fk_fournprice;
2591 $pa_ht = $originLine->pa_ht;
2592 $label = $originLine->label;
2593 $array_options = $originLine->array_options;
2595 $situation_percent = 0;
2597 $situation_percent = 100;
2600 $fk_unit = $originLine->fk_unit;
2601 $pu_ht_devise = $originLine->multicurrency_subprice;
2603 $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);
2623 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2626 if (empty($id)) $id = $facid;
2627 $triggersendname =
'BILL_SENTBYMAIL';
2629 $autocopy =
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
2630 $trackid =
'inv'.$object->id;
2631 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2634 $upload_dir = $conf->facture->multidir_output[$object->entity];
2635 $permissiontoadd = $usercancreate;
2636 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2639 if ($action ==
'update_extras') {
2643 $ret = $extrafields->setOptionalsFromPost(null, $object,
GETPOST(
'attribute',
'restricthtml'));
2644 if ($ret < 0) $error++;
2649 $result = $object->insertExtraFields(
'BILL_MODIFY');
2658 $action =
'edit_extras';
2661 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
2662 if ($action ==
'addcontact') {
2663 $result = $object->fetch($id);
2665 if ($result > 0 && $id > 0) {
2668 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
2672 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2675 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2676 $langs->load(
"errors");
2677 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"), null,
'errors');
2683 elseif ($action ==
'swapstatut') {
2684 if ($object->fetch($id)) {
2685 $result = $object->swapContactStatus(
GETPOST(
'ligne'));
2690 elseif ($action ==
'deletecontact') {
2691 $object->fetch($id);
2692 $result = $object->delete_contact($lineid);
2695 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2703 $action =
'edit_extras';
2712 $form =
new Form($db);
2717 $paymentstatic =
new Paiement($db);
2718 $bankaccountstatic =
new Account($db);
2719 if (!empty($conf->projet->enabled)) { $formproject =
new FormProjets($db); }
2723 $title = $langs->trans(
'InvoiceCustomer').
" - ".$langs->trans(
'Card');
2724 $helpurl =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
2729 if ($action ==
'create')
2731 $facturestatic =
new Facture($db);
2732 $extrafields->fetch_name_optionals_label($facturestatic->table_element);
2737 $res = $soc->fetch($socid);
2739 $currency_code = $conf->currency;
2742 $remise_absolue = 0;
2743 if (!empty($origin) && !empty($originid))
2746 $element = $subelement = $origin;
2748 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
2749 $element = $regs[1];
2750 $subelement = $regs[2];
2753 if ($element ==
'project') {
2754 $projectid = $originid;
2756 if (empty($cond_reglement_id)) {
2757 $cond_reglement_id = $soc->cond_reglement_id;
2759 if (empty($mode_reglement_id)) {
2760 $mode_reglement_id = $soc->mode_reglement_id;
2762 if (!$remise_percent) {
2763 $remise_percent = $soc->remise_percent;
2765 if (!$dateinvoice) {
2767 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
2771 if ($element ==
'order' || $element ==
'commande') {
2772 $element = $subelement =
'commande';
2774 if ($element ==
'propal') {
2775 $element =
'comm/propal';
2776 $subelement =
'propal';
2778 if ($element ==
'contract') {
2779 $element = $subelement =
'contrat';
2781 if ($element ==
'shipping') {
2782 $element = $subelement =
'expedition';
2787 $classname = ucfirst($subelement);
2788 $objectsrc =
new $classname($db);
2789 $objectsrc->fetch($originid);
2790 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines'))
2791 $objectsrc->fetch_lines();
2792 $objectsrc->fetch_thirdparty();
2794 $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project);
2795 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
''));
2796 $ref_int = (!empty($objectsrc->ref_int) ? $objectsrc->ref_int :
'');
2800 $soc = $objectsrc->thirdparty;
2802 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
2804 if ($element ==
'expedition') {
2805 $ref_client = (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer :
'');
2807 $elem = $subelem = $objectsrc->origin;
2808 $expeoriginid = $objectsrc->origin_id;
2810 $classname = ucfirst($subelem);
2812 $expesrc =
new $classname($db);
2813 $expesrc->fetch($expeoriginid);
2815 $cond_reglement_id = (!empty($expesrc->cond_reglement_id) ? $expesrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
2816 $mode_reglement_id = (!empty($expesrc->mode_reglement_id) ? $expesrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
2817 $fk_account = (!empty($expesrc->fk_account) ? $expesrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
2818 $remise_percent = (!empty($expesrc->remise_percent) ? $expesrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
2819 $remise_absolue = (!empty($expesrc->remise_absolue) ? $expesrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
2822 $expesrc->fetch_optionals();
2823 $object->array_options = $expesrc->array_options;
2825 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
2826 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
2827 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
2828 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
2829 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
2831 if (!empty($conf->multicurrency->enabled))
2833 if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code;
2834 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $currency_tx = $objectsrc->multicurrency_tx;
2838 $objectsrc->fetch_optionals();
2839 $object->array_options = $objectsrc->array_options;
2843 $cond_reglement_id = $soc->cond_reglement_id;
2844 $mode_reglement_id = $soc->mode_reglement_id;
2845 $fk_account = $soc->fk_account;
2846 $remise_percent = $soc->remise_percent;
2847 $remise_absolue = 0;
2848 $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $dateinvoice);
2850 if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) $currency_code = $soc->multicurrency_code;
2854 if (empty($cond_reglement_id)) {
2855 $cond_reglement_id =
GETPOST(
"cond_reglement_id");
2859 if (empty($mode_reglement_id)) {
2860 $mode_reglement_id =
GETPOST(
"mode_reglement_id");
2863 if (!empty($soc->id)) $absolute_discount = $soc->getAvailableDiscounts();
2864 $note_public = $object->getDefaultCreateValueFor(
'note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($conf->global->FACTURE_REUSE_NOTES_ON_CREATE_FROM)) ? $objectsrc->note_public : null));
2865 $note_private = $object->getDefaultCreateValueFor(
'note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($conf->global->FACTURE_REUSE_NOTES_ON_CREATE_FROM)) ? $objectsrc->note_private : null));
2867 if (!empty($conf->use_javascript_ajax)) {
2868 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
2874 if ($origin ==
'contrat')
2876 $langs->load(
"admin");
2877 $text = $langs->trans(
"ToCreateARecurringInvoice");
2878 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
2879 if (empty($conf->global->INVOICE_DISABLE_AUTOMATIC_RECURRING_INVOICE))
2881 $text .=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
2886 print '<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" id="formtocreate" name="formtocreate">';
2887 print '<input type="hidden" name="token" value="'.newToken().
'">';
2888 print '<input type="hidden" name="action" value="add">';
2889 if ($soc->id > 0)
print '<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
2890 print '<input name="ref" type="hidden" value="provisoire">';
2891 print '<input name="ref_client" type="hidden" value="'.$ref_client.
'">';
2892 print '<input name="force_cond_reglement_id" type="hidden" value="0">';
2893 print '<input name="force_mode_reglement_id" type="hidden" value="0">';
2894 print '<input name="force_fk_account" type="hidden" value="0">';
2895 print '<input type="hidden" name="origin" value="'.$origin.
'">';
2896 print '<input type="hidden" name="originid" value="'.$originid.
'">';
2897 print '<input type="hidden" name="originentity" value="'.GETPOST(
'originentity').
'">';
2898 if (!empty($currency_tx))
print '<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2902 print '<table class="border centpercent">';
2905 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td colspan="2">'.$langs->trans(
'Draft').
'</td></tr>';
2907 $exampletemplateinvoice =
new FactureRec($db);
2909 if (empty($origin) && empty($originid) &&
GETPOST(
'fac_rec',
'int') > 0)
2911 $invoice_predefined->fetch(
GETPOST(
'fac_rec',
'int'));
2915 if ($soc->id > 0 && (!
GETPOST(
'fac_rec',
'int') || !empty($invoice_predefined->frequency)))
2918 print '<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
2919 print '<td colspan="2">';
2920 print $soc->getNomUrl(1);
2921 print '<input type="hidden" name="socid" value="'.$soc->id.
'">';
2923 $arrayoutstandingbills = $soc->getOutstandingBills();
2924 $outstandingBills = $arrayoutstandingbills[
'opened'];
2925 print ' ('.$langs->trans(
'CurrentOutstandingBill').
': ';
2926 print price($outstandingBills,
'', $langs, 0, 0, -1, $conf->currency);
2927 if ($soc->outstanding_limit !=
'')
2929 if ($outstandingBills > $soc->outstanding_limit)
print img_warning($langs->trans(
"OutstandingBillReached"));
2930 print ' / '.price($soc->outstanding_limit,
'', $langs, 0, 0, -1, $conf->currency);
2936 print '<tr><td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
2937 print '<td colspan="2">';
2938 print img_picto(
'',
'company').$form->select_company($soc->id,
'socid',
'((s.client = 1 OR s.client = 3) AND s.status=1)',
'SelectThirdParty', 0, 0, null, 0,
'minwidth300');
2940 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED))
2942 print '<script type="text/javascript">
2943 $(document).ready(function() {
2944 $("#socid").change(function() {
2946 console.log("Submit page");
2947 $(\'input[name="action"]\').val(\'create\');
2948 $(\'input[name="force_cond_reglement_id"]\').val(\'1\');
2949 $(\'input[name="force_mode_reglement_id"]\').val(\'1\');
2950 $(\'input[name="force_fk_account"]\').val(\'1\');
2951 $("#formtocreate").submit(); */
2953 // For company change, we must reuse data of comany, not input already done, so we call a GET with action=create, not a POST submit.
2954 console.log("We have changed the company - Reload page");
2955 var socid = $(this).val();
2956 var fac_rec = $(\'#fac_rec\').val();
2957 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
2962 if (!
GETPOST(
'fac_rec',
'int'))
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>';
2968 if (empty($origin) && empty($originid) &&
GETPOST(
'fac_rec',
'int') > 0)
2970 $invoice_predefined->fetch(
GETPOST(
'fac_rec',
'int'));
2972 $dateinvoice = $invoice_predefined->date_when;
2973 if (empty($projectid)) $projectid = $invoice_predefined->fk_project;
2974 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2975 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2976 $fk_account = $invoice_predefined->fk_account;
2977 $note_public = $invoice_predefined->note_public;
2978 $note_private = $invoice_predefined->note_private;
2980 if (!empty($invoice_predefined->multicurrency_code)) $currency_code = $invoice_predefined->multicurrency_code;
2981 if (!empty($invoice_predefined->multicurrency_tx)) $currency_tx = $invoice_predefined->multicurrency_tx;
2983 $sql =
'SELECT r.rowid, r.titre as title, r.total_ttc';
2984 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as r';
2985 $sql .=
' WHERE r.fk_soc = '.$invoice_predefined->socid;
2987 $resql = $db->query($sql);
2990 $num = $db->num_rows(
$resql);
2995 print '<tr><td>'.$langs->trans(
'CreateFromRepeatableInvoice').
'</td><td>';
2997 print '<select class="flat" id="fac_rec" name="fac_rec">';
2998 print '<option value="0" selected></option>';
3001 $objp = $db->fetch_object(
$resql);
3002 print '<option value="'.$objp->rowid.
'"';
3003 if (
GETPOST(
'fac_rec',
'int') == $objp->rowid)
3006 $exampletemplateinvoice->fetch(
GETPOST(
'fac_rec',
'int'));
3008 print '>'.$objp->title.
' ('.
price($objp->total_ttc).
' '.$langs->trans(
"TTC").
')</option>';
3013 if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED))
3015 print '<script type="text/javascript">
3016 $(document).ready(function() {
3017 $("#fac_rec").change(function() {
3018 console.log("We have changed the template invoice - Reload page");
3019 var fac_rec = $(this).val();
3020 var socid = $(\'#socid\').val();
3021 // 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.
3022 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec;
3035 print '<tr><td class="tdtop fieldrequired">'.$langs->trans(
'Type').
'</td><td colspan="2">';
3037 print '<div class="tagtable">'.
"\n";
3040 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3041 $tmp =
'<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOST(
'type') == 0 ?
' checked' :
'').
'> ';
3042 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
3043 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
3045 print '</div></div>';
3047 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (!empty($originid))))
3050 if (empty($conf->global->INVOICE_DISABLE_DEPOSIT))
3052 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3053 $tmp =
'<input type="radio" id="radio_deposit" name="type" value="3"'.(GETPOST(
'type') == 3 ?
' checked' :
'').
'> ';
3054 print '<script type="text/javascript" language="javascript">
3055 jQuery(document).ready(function() {
3056 jQuery("#typedeposit, #valuedeposit").click(function() {
3057 jQuery("#radio_deposit").prop("checked", true);
3062 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
3063 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
3064 print '<table class="nobordernopadding"><tr><td>';
3067 if (($origin ==
'propal') || ($origin ==
'commande'))
3069 print '<td class="nowrap" style="padding-left: 5px">';
3071 'amount' => $langs->transnoentitiesnoconv(
'FixAmount', $langs->transnoentitiesnoconv(
'Deposit')),
3072 'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')),
3073 'variablealllines' => $langs->transnoentitiesnoconv(
'VarAmountAllLines')
3075 print $form->selectarray(
'typedeposit', $arraylist,
GETPOST(
'typedeposit',
'aZ09'), 0, 0, 0,
'', 1);
3077 print '<td class="nowrap" style="padding-left: 5px">'.$langs->trans(
'Value').
':<input type="text" id="valuedeposit" name="valuedeposit" size="3" value="'.
GETPOST(
'valuedeposit',
'int').
'"/>';
3079 print '</td></tr></table>';
3081 print '</div></div>';
3087 if (!empty($conf->global->INVOICE_USE_SITUATION))
3090 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3091 $tmp =
'<input id="radio_situation" type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 ?
' checked' :
'').
'> ';
3092 $tmp = $tmp.
'<label for="radio_situation" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
3093 $desc = $form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3);
3095 print '</div></div>';
3098 $opt = $form->selectSituationInvoices(
GETPOST(
'originid',
'int'), $socid);
3100 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3101 $tmp =
'<input type="radio" name="type" value="5"'.(GETPOST(
'type') == 5 &&
GETPOST(
'originid',
'int') ?
' checked' :
'');
3102 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande'))
3103 $tmp .=
' disabled';
3105 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3106 $text .=
'<select class="flat" id="situations" name="situations"';
3107 if ($opt == (
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande'))
3108 $text .=
' disabled';
3111 $text .=
'</select>';
3112 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
3114 print '</div></div>';
3118 if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT))
3121 $facids = $facturestatic->list_replacable_invoices($soc->id);
3127 if (is_array($facids)) {
3128 foreach ($facids as $facparam)
3130 $options .=
'<option value="'.$facparam [
'id'].
'"';
3131 if ($facparam [
'id'] == $_POST[
'fac_replacement'])
3132 $options .=
' selected';
3133 $options .=
'>'.$facparam [
'ref'];
3134 $options .=
' ('.$facturestatic->LibStatut(0, $facparam [
'status']).
')';
3135 $options .=
'</option>';
3139 print '<!-- replacement line -->';
3140 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3141 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="1"'.(GETPOST(
'type') == 1 ?
' checked' :
'');
3142 if (!$options || $invoice_predefined->id > 0) $tmp .=
' disabled';
3144 print '<script type="text/javascript" language="javascript">
3145 jQuery(document).ready(function() {
3146 jQuery("#fac_replacement").change(function() {
3147 jQuery("#radio_replacement").prop("checked", true);
3151 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceReplacementAsk").
'</label>';
3152 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
3153 if (!$options || $invoice_predefined->id > 0)
3154 $text .=
' disabled';
3157 $text .=
'<option value="-1"> </option>';
3160 $text .=
'<option value="-1">'.$langs->trans(
"NoReplacableInvoice").
'</option>';
3162 $text .=
'</select>';
3163 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3165 print '</div></div>';
3168 if (!empty($conf->global->INVOICE_USE_SITUATION))
3170 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3171 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3172 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceFirstSituationAsk").
'</label> ';
3173 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3174 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3);
3176 print '</div></div>';
3178 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3179 $tmp =
'<input type="radio" name="type" id="radio_situation" value="0" disabled> ';
3180 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceSituationAsk").
'</label> ';
3181 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3182 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3);
3184 print '</div></div>';
3187 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3188 $tmp =
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
3189 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceReplacement").
'</label> ';
3190 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3191 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3193 print '</div></div>';
3202 if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE))
3205 $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
3212 $newinvoice_static =
new Facture($db);
3213 foreach ($facids as $key => $valarray)
3215 $newinvoice_static->id = $key;
3216 $newinvoice_static->ref = $valarray [
'ref'];
3217 $newinvoice_static->statut = $valarray [
'status'];
3218 $newinvoice_static->type = $valarray [
'type'];
3219 $newinvoice_static->paye = $valarray [
'paye'];
3221 $optionsav .=
'<option value="'.$key.
'"';
3222 if ($key ==
GETPOST(
'fac_avoir'))
3223 $optionsav .=
' selected';
3225 $optionsav .= $newinvoice_static->ref;
3226 $optionsav .=
' ('.$newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']).
')';
3227 $optionsav .=
'</option>';
3230 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3231 $tmp =
'<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST(
'type') == 2 ?
' checked' :
'');
3232 if ((!$optionsav && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) || $invoice_predefined->id > 0) $tmp .=
' disabled';
3235 print '<script type="text/javascript" language="javascript">
3236 jQuery(document).ready(function() {
3237 if (! jQuery("#radio_creditnote").is(":checked"))
3239 jQuery("#credit_note_options").hide();
3241 jQuery("#radio_creditnote").click(function() {
3242 jQuery("#credit_note_options").show();
3244 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
3245 jQuery("#credit_note_options").hide();
3249 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk").
'</label> ';
3251 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3252 if (!$optionsav || $invoice_predefined->id > 0)
3253 $text .=
' disabled';
3256 $text .=
'<option value="-1"></option>';
3257 $text .= $optionsav;
3259 $text .=
'<option value="-1">'.$langs->trans(
"NoInvoiceToCorrect").
'</option>';
3261 $text .=
'</select>';
3262 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3265 print '<div id="credit_note_options" class="clearboth">';
3266 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>";
3267 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>";
3270 print '</div></div>';
3273 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3274 if (empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3275 else $tmp =
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
3276 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceAvoir").
'</label> ';
3277 $text .=
'<span class="opacitymedium">('.$langs->trans(
"YouMustCreateInvoiceFromThird").
')</span> ';
3278 $desc = $form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3280 print '</div></div>'.
"\n";
3285 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3286 $tmp =
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
3287 $text =
'<label>'.$tmp.$langs->trans(
"RepeatableInvoice").
'</label> ';
3289 $desc = $form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3);
3291 print '</div></div>';
3296 if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT))
3301 foreach ($listtType as $type)
3303 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
3304 $curent = !empty($conf->global->{$thisTypeConfName}) ? $conf->global->{$thisTypeConfName}:$conf->global->FACTURE_ADDON_PDF;
3305 $jsListType .= (!empty($jsListType) ?
',' :
'').
'"'.$type.
'":"'.$curent.
'"';
3308 print '<script type="text/javascript" language="javascript">
3309 $(document).ready(function() {
3310 var listType = {'.$jsListType.
'};
3311 $("[name=\'type\'").change(function() {
3312 if($( this ).prop("checked"))
3314 if(($( this ).val() in listType))
3316 $("#model").val(listType[$( this ).val()]);
3320 $("#model").val("'.$conf->global->FACTURE_ADDON_PDF.
'");
3335 print '<tr><td>'.$langs->trans(
'Discounts').
'</td><td colspan="2">';
3339 $backtopage = urlencode(
$_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin',
'alpha').
'&originid='.
GETPOST(
'originid',
'int'));
3340 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3348 print '<tr><td class="fieldrequired">'.$langs->trans(
'DateInvoice').
'</td><td colspan="2">';
3349 print $form->selectDate($datefacture ? $datefacture : $dateinvoice,
'',
'',
'',
'',
"add", 1, 1);
3353 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE))
3355 print '<tr><td class="fieldrequired">'.$langs->trans(
'DatePointOfTax').
'</td><td colspan="2">';
3356 $date_pointoftax =
dol_mktime(12, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'));
3357 print $form->selectDate($date_pointoftax ? $date_pointoftax : -1,
'date_pointoftax',
'',
'',
'',
"add", 1, 1);
3362 print '<tr><td class="nowrap fieldrequired">'.$langs->trans(
'PaymentConditionsShort').
'</td><td colspan="2">';
3363 $form->select_conditions_paiements(
GETPOSTISSET(
'cond_reglement_id') ?
GETPOST(
'cond_reglement_id',
'int') : $cond_reglement_id,
'cond_reglement_id');
3367 if ($conf->global->INVOICE_USE_RETAINED_WARRANTY) {
3368 $rwStyle =
'display:none;';
3369 if (in_array(
GETPOST(
'type',
'int'), $retainedWarrantyInvoiceAvailableType)) {
3373 $retained_warranty =
GETPOST(
'retained_warranty',
'int');
3374 if (empty($retained_warranty)) {
3375 if (!empty($objectsrc->retained_warranty)) {
3376 $retained_warranty = $objectsrc->retained_warranty;
3379 $retained_warranty_js_default = !empty($retained_warranty) ? $retained_warranty : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT;
3381 print '<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'RetainedWarranty').
'</td><td colspan="2">';
3382 print '<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.
'" step="0.01" min="0" max="100" />%';
3385 print '<tr class="retained-warranty-line" style="'.$rwStyle.
'" ><td class="nowrap">'.$langs->trans(
'PaymentConditionsShortRetainedWarranty').
'</td><td colspan="2">';
3386 $retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
3387 if (empty($retained_warranty_fk_cond_reglement)) {
3388 $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
3389 if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) {
3390 $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
3392 $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
3395 $form->select_conditions_paiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
3398 print '<script type="text/javascript" language="javascript">
3399 $(document).ready(function() {
3400 $("[name=\'type\']").change(function() {
3401 if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).
' ) !== -1)
3403 $(".retained-warranty-line").show();
3404 $("#new-situation-invoice-retained-warranty").val("'.doubleval($retained_warranty_js_default).
'");
3407 $(".retained-warranty-line").hide();
3408 $("#new-situation-invoice-retained-warranty").val("");
3412 $("[name=\'type\']:checked").trigger("change");
3418 print '<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td colspan="2">';
3419 $form->select_types_paiements(
GETPOSTISSET(
'mode_reglement_id') ?
GETPOST(
'mode_reglement_id') : $mode_reglement_id,
'mode_reglement_id',
'CRDT');
3423 if (!empty($conf->banque->enabled))
3426 $fk_account =
GETPOST(
'fk_account',
'int');
3429 print '<tr><td>'.$langs->trans(
'BankAccount').
'</td><td colspan="2">';
3430 print img_picto(
'',
'bank_account',
'class="paddingrightonly"').$form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'', 1);
3435 if (!empty($conf->projet->enabled))
3437 $langs->load(
'projects');
3438 print '<tr><td>'.$langs->trans(
'Project').
'</td><td colspan="2">';
3439 print img_picto(
'',
'project').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500');
3440 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>';
3445 if (!empty($conf->incoterm->enabled))
3448 print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), $objectsrc->label_incoterms, 1).
'</label></td>';
3449 print '<td colspan="2" class="maxwidthonsmartphone">';
3450 $incoterm_id =
GETPOST(
'incoterm_id');
3451 $incoterm_location =
GETPOST(
'location_incoterms');
3452 if (empty($incoterm_id))
3454 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
3455 $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
3457 print $form->select_incoterms($incoterm_id, $incoterm_location);
3462 $parameters = array(
'objectsrc' => $objectsrc,
'colspan' =>
' colspan="2"',
'cols' =>
'2',
'socid'=>$socid);
3463 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
3464 print $hookmanager->resPrint;
3465 if (empty($reshook)) {
3466 if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE) && !empty($soc->id)) {
3468 $tpExtrafields =
new Extrafields($db);
3469 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
3470 if ($soc->fetch_optionals() > 0) {
3471 $object->array_options = array_merge($object->array_options, $soc->array_options);
3475 print $object->showOptionals($extrafields,
'edit', $parameters);
3479 print '<tr><td>'.$langs->trans(
'Model').
'</td>';
3480 print '<td colspan="2">';
3481 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
3483 if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) {
3485 $paramkey =
'FACTURE_ADDON_PDF_'.$object->type;
3486 $preselected = !empty($conf->global->$paramkey) ? $conf->global->$paramkey : $conf->global->FACTURE_ADDON_PDF;
3488 $preselected = $conf->global->FACTURE_ADDON_PDF;
3490 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'', 1);
3494 if (!empty($conf->multicurrency->enabled))
3497 print '<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
3498 print '<td colspan="2" class="maxwidthonsmartphone">';
3499 print $form->selectMultiCurrency($currency_code,
'multicurrency_code');
3505 if (
GETPOST(
'fac_rec',
'int') > 0)
3507 $dateexample = ($datefacture ? $datefacture : $dateinvoice);
3508 if (empty($dateexample)) $dateexample =
dol_now();
3509 $substitutionarray = array(
3510 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
3511 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
3512 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
3513 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
3514 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
3515 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
3516 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
3517 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
3518 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
3519 '__INVOICE_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
3520 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')'
3523 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
3524 foreach ($substitutionarray as $key => $val)
3526 $htmltext .= $key.
' = '.$langs->trans($val).
'<br>';
3528 $htmltext .=
'</i>';
3533 print '<td class="tdtop">';
3534 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
3536 print '<td valign="top" colspan="2">';
3537 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false,
true, ROWS_3,
'90%');
3538 print $doleditor->Create(1);
3541 if (empty($user->socid))
3544 print '<td class="tdtop">';
3545 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
3547 print '<td valign="top" colspan="2">';
3548 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false,
true, ROWS_3,
'90%');
3549 print $doleditor->Create(1);
3555 if (!empty($origin) && !empty($originid) && is_object($objectsrc))
3558 if ($origin ==
'contrat') {
3560 $objectsrc->remise_absolue = $remise_absolue;
3561 $objectsrc->remise_percent = $remise_percent;
3562 $objectsrc->update_price(1, - 1, 1);
3565 print "\n<!-- ".$classname.
" info -->";
3567 print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
3568 print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
3569 print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
3570 print '<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
3571 print '<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
3573 switch (get_class($objectsrc)) {
3575 $newclassname =
'CommercialProposal';
3578 $newclassname =
'Order';
3581 $newclassname =
'Sending';
3584 $newclassname =
'Contract';
3587 $newclassname =
'Intervention';
3590 $newclassname = get_class($objectsrc);
3593 print '<tr><td>'.$langs->trans($newclassname).
'</td><td colspan="2">'.$objectsrc->getNomUrl(1);
3595 $objectsrc->fetchObjectLinked($originid, $origin,
'',
'facture');
3596 if (is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1)
3599 echo
' ('.$langs->trans(
'LatestRelatedBill').
' '.end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1).
')';
3602 print '<tr><td>'.$langs->trans(
'AmountHT').
'</td><td colspan="2">'.
price($objectsrc->total_ht).
'</td></tr>';
3603 print '<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="2">'.
price($objectsrc->total_tva).
"</td></tr>";
3604 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0)
3606 print '<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax1).
"</td></tr>";
3609 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0)
3611 print '<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td colspan="2">'.
price($objectsrc->total_localtax2).
"</td></tr>";
3613 print '<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td colspan="2">'.
price($objectsrc->total_ttc).
"</td></tr>";
3615 if (!empty($conf->multicurrency->enabled))
3617 print '<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
3618 print '<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
3619 print '<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td colspan="2">'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
3628 print '<div class="center">';
3629 print '<input type="submit" class="button" name="bouton" value="'.$langs->trans(
'CreateDraft').
'">';
3630 print ' ';
3631 print '<input type="button" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'" onClick="javascript:history.go(-1)">';
3635 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
3638 $title = $langs->trans(
'ProductsAndServices');
3641 print '<table class="noborder centpercent">';
3643 $objectsrc->printOriginLinesList(
'', $selectedLines);
3649 } elseif ($id > 0 || !empty($ref)) {
3654 $result = $object->fetch($id, $ref);
3661 $extrafields->fetch_name_optionals_label($object->table_element);
3663 if ($user->socid > 0 && $user->socid != $object->socid)
3668 $result = $object->fetch_thirdparty();
3670 $result = $soc->fetch($object->socid);
3672 $selleruserevenustamp = $mysoc->useRevenueStamp();
3674 $totalpaye = $object->getSommePaiement();
3675 $totalcreditnotes = $object->getSumCreditNotesUsed();
3676 $totaldeposits = $object->getSumDepositsUsed();
3684 $resteapayer =
price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,
'MT');
3690 $resteapayeraffiche = $resteapayer;
3692 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
3693 $filterabsolutediscount =
"fk_facture_source IS NULL";
3694 $filtercreditnote =
"fk_facture_source IS NOT NULL";
3696 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
3697 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
3700 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
3701 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
3702 $absolute_discount =
price2num($absolute_discount,
'MT');
3703 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
3705 $author =
new User($db);
3706 if ($object->user_author) {
3707 $author->fetch($object->user_author);
3710 $objectidnext = $object->getIdReplacingInvoice();
3719 if ($action ==
'converttoreduc') {
3722 elseif ($object->
type ==
Facture::TYPE_DEPOSIT) $type_fac = 'Deposit';
3723 $text = $langs->trans('ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
3724 $text .= '<br>'.$langs->trans('ConfirmConvertToReduc2');
3725 $formconfirm = $form->formconfirm(
$_SERVER['PHP_SELF'].'?facid='.$object->
id, $langs->trans('ConvertToReduc'), $text, 'confirm_converttoreduc', '', "yes", 2);
3729 if ($action == 'delete') {
3730 $text = $langs->trans(
'ConfirmDeleteBill', $object->ref);
3731 $formquestion = array();
3733 if ($object->type !=
Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->statut >= 1)
3735 $qualified_for_stock_change = 0;
3736 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
3737 $qualified_for_stock_change = $object->hasProductsOrServices(2);
3739 $qualified_for_stock_change = $object->hasProductsOrServices(1);
3742 if ($qualified_for_stock_change)
3744 $langs->load(
"stocks");
3745 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3747 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
3749 if ($conf->browser->name ==
'ie') $forcecombo = 1;
3750 $formquestion = array(
3754 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
3756 $formconfirm = $form->formconfirm(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
3758 $formconfirm = $form->formconfirm(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
3761 $formconfirm = $form->formconfirm(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
3766 if ($action ==
'situationout') {
3767 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle', $object->ref);
3768 $label = $langs->trans(
"ConfirmOuting");
3769 $formquestion = array();
3774 && $object->is_last_in_cycle()
3775 && $usercanunvalidate
3778 $formconfirm = $form->formconfirm(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
3783 if ($action ==
'valid')
3786 $objectref = substr($object->ref, 1, 4);
3787 if ($objectref ==
'PROV') {
3788 $savdate = $object->date;
3789 if (!empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
3791 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
3793 $numref = $object->getNextNumRef($soc);
3796 $numref = $object->ref;
3799 $text = $langs->trans(
'ConfirmValidateBill', $numref);
3800 if (!empty($conf->notification->enabled)) {
3801 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
3802 $notify =
new Notify($db);
3804 $text .= $notify->confirmMessage(
'BILL_VALIDATE', $object->socid, $object);
3806 $formquestion = array();
3810 $qualified_for_stock_change = 0;
3811 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
3812 $qualified_for_stock_change = $object->hasProductsOrServices(2);
3814 $qualified_for_stock_change = $object->hasProductsOrServices(1);
3817 if ($qualified_for_stock_change)
3819 $langs->load(
"stocks");
3820 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3821 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
3824 $warehouse_array = $warehouse->list_array();
3825 if (count($warehouse_array) == 1) {
3826 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
3827 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3829 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockIncrease") : $langs->trans(
"SelectWarehouseForStockDecrease");
3830 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3832 $formquestion = array(
3838 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
3843 $text .=
'<br>'.img_warning().
' '.$langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
3845 $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);
3849 if ($action ==
'modif') {
3850 $text = $langs->trans(
'ConfirmUnvalidateBill', $object->ref);
3851 $formquestion = array();
3855 $qualified_for_stock_change = 0;
3856 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
3857 $qualified_for_stock_change = $object->hasProductsOrServices(2);
3859 $qualified_for_stock_change = $object->hasProductsOrServices(1);
3862 if ($qualified_for_stock_change)
3864 $langs->load(
"stocks");
3865 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
3866 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
3869 $warehouse_array = $warehouse->list_array();
3870 if (count($warehouse_array) == 1) {
3871 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
3872 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).
'">';
3874 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
3875 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1);
3877 $formquestion = array(
3883 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
3887 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
3891 if ($action ==
'paid' && $resteapayer <= 0) {
3892 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill', $object->ref),
'confirm_paid',
'',
"yes", 1);
3894 if ($action ==
'paid' && $resteapayer > 0) {
3898 $close[$i][
'code'] =
'discount_vat';
3900 $close[$i][
'code'] =
'badcustomer';
3902 $close[$i][
'code'] =
'other';
3906 $close[$i][
'label'] = $langs->trans(
"HelpEscompte").
'<br><br>'.$langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
3908 $close[$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
3910 $close[$i][
'label'] = $langs->trans(
"Other");
3914 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3916 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency".$conf->currency)), $close[$i][
'label'], 1);
3918 $close[$i][
'reason'] = $form->textwithpicto($langs->transnoentities(
"Other"), $close[$i][
'label'], 1);
3921 foreach ($close as $key => $val) {
3922 $arrayreasons[$close[$key][
'code']] = $close[$key][
'reason'];
3926 $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'));
3928 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially', $object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
3932 if ($action ==
'canceled') {
3935 if ($objectidnext) {
3936 $facturereplacement =
new Facture($db);
3937 $facturereplacement->fetch($objectidnext);
3938 $statusreplacement = $facturereplacement->statut;
3940 if ($objectidnext && $statusreplacement == 0) {
3941 print '<div class="error">'.$langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated").
'</div>';
3944 $close[1][
'code'] =
'badcustomer';
3945 $close[2][
'code'] =
'abandon';
3947 $close[1][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
3948 $close[2][
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
3950 $close[1][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $object->ref), $close[1][
'label'], 1);
3951 $close[2][
'reason'] = $form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close[2][
'label'], 1);
3953 $arrayreasons[$close[1][
'code']] = $close[1][
'reason'];
3954 $arrayreasons[$close[2][
'code']] = $close[2][
'reason'];
3957 $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'));
3959 $formconfirm = $form->formconfirm(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill', $object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 250);
3963 if ($action ==
'deletepayment')
3965 $payment_id =
GETPOST(
'paiement_id');
3966 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
3970 if ($action ==
'ask_deleteline') {
3971 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
3975 if ($action ==
'clone')
3978 $formquestion = array(
3979 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company($object->socid,
'socid',
'(s.client=1 OR s.client=2 OR s.client=3)', 1)),
3980 array(
'type' =>
'date',
'name' =>
'newdate',
'label' => $langs->trans(
"Date"),
'value' =>
dol_now())
3983 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?facid='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneInvoice', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 250);
3986 if ($action ==
"remove_file_comfirm")
3988 $file =
GETPOST(
'file',
'alpha');
3990 $formconfirm = $form->formconfirm(
3991 $_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&file='.$file,
3992 $langs->trans(
'DeleteFileHeader'),
3993 $langs->trans(
'DeleteFileText').
"<br><br>".$file,
4001 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid,
'remainingtopay' => &$resteapayer);
4002 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
4003 if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
4004 elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
4011 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
4013 $morehtmlref = '<div class="refidno">';
4015 if ($object->status == $object::STATUS_DRAFT && !$mysoc->
isInEEC() && !empty($conf->global->INVOICE_ALLOW_FREE_REF)) {
4016 $morehtmlref .= $form->editfieldkey(
"Ref",
'ref', $object->ref, $object, $usercancreate,
'string',
'', 0, 1);
4017 $morehtmlref .= $form->editfieldval(
"Ref",
'ref', $object->ref, $object, $usercancreate,
'string',
'', null, null,
'', 1);
4018 $morehtmlref .=
'<br>';
4021 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
4022 $morehtmlref .= $form->editfieldval(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', null, null,
'', 1);
4024 $morehtmlref .=
'<br>'.$langs->trans(
'ThirdParty').
' : '.$object->thirdparty->getNomUrl(1,
'customer');
4025 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
4027 if (!empty($conf->projet->enabled))
4029 $langs->load(
"projects");
4030 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
4033 if ($action !=
'classify') {
4034 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
4036 if ($action ==
'classify') {
4038 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
4039 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
4040 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
4041 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
4042 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4043 $morehtmlref .=
'</form>';
4045 $morehtmlref .= $form->form_project(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
4048 if (!empty($object->fk_project)) {
4050 $proj->fetch($object->fk_project);
4051 $morehtmlref .=
'<a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$object->fk_project.
'" title="'.$langs->trans(
'ShowProject').
'">';
4052 $morehtmlref .= $proj->ref;
4053 $morehtmlref .=
'</a>';
4059 $morehtmlref .=
'</div>';
4061 $object->totalpaye = $totalpaye;
4063 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'',
'');
4065 print '<div class="fichecenter">';
4066 print '<div class="fichehalfleft">';
4067 print '<div class="underbanner clearboth"></div>';
4069 print '<table class="border tableforfield" width="100%">';
4072 print '<tr><td class="titlefield fieldname_type">'.$langs->trans(
'Type').
'</td><td class="valuefield fieldname_type">';
4073 print '<span class="badgeneutral">';
4074 print $object->getLibType();
4076 if ($object->module_source) {
4077 print ' <span class="opacitymediumbycolor paddingleft">('.$langs->trans(
"POS").
' '.ucfirst($object->module_source).
' - '.$langs->trans(
"Terminal").
' '.$object->pos_source.
')</span>';
4080 $facreplaced =
new Facture($db);
4081 $facreplaced->fetch($object->fk_facture_source);
4082 print ' <span class="opacitymediumbycolor paddingleft">('.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
')</span>';
4086 $facusing->fetch($object->fk_facture_source);
4087 print ' <span class="opacitymediumbycolor paddingleft">('.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
')</span>';
4090 $facidavoir = $object->getListIdAvoirFromInvoice();
4091 if (count($facidavoir) > 0) {
4092 print ' <span class="opacitymediumbycolor paddingleft">('.$langs->transnoentities(
"InvoiceHasAvoir");
4094 foreach ($facidavoir as $id) {
4099 $facavoir->fetch($id);
4100 print $facavoir->getNomUrl(1);
4104 if ($objectidnext > 0) {
4105 $facthatreplace =
new Facture($db);
4106 $facthatreplace->fetch($objectidnext);
4107 print ' <span class="opacitymediumbycolor paddingleft">('.str_replace(
'{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities(
"ReplacedByInvoice",
'{s1}')).
')</span>';
4112 $result = $discount->fetch(0, $object->id);
4114 print ' <span class="opacitymediumbycolor paddingleft">';
4115 $s = $langs->trans(
"CreditNoteConvertedIntoDiscount",
'{s1}',
'{s2}');
4116 $s = str_replace(
'{s1}', $object->getLibType(1), $s);
4117 $s = str_replace(
'{s2}', $discount->getNomUrl(1,
'discount'), $s);
4119 print '</span><br>';
4123 if ($object->fk_fac_rec_source > 0)
4126 $result = $tmptemplate->fetch($object->fk_fac_rec_source);
4128 print ' <span class="opacitymediumbycolor paddingleft">';
4129 $s = $langs->transnoentities(
"GeneratedFromTemplate",
'{s1}');
4130 $s = str_replace(
'{s1}',
'<a href="'.DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$tmptemplate->id.
'">'.
dol_escape_htmltag($tmptemplate->ref).
'</a>', $s);
4138 print '<!-- Discounts -->'.
"\n";
4139 print '<tr><td>'.$langs->trans(
'Discounts');
4143 $backtopage = urlencode(
$_SERVER[
"PHP_SELF"].
'?facid='.$object->id);
4144 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
4149 print '<table class="nobordernopadding" width="100%"><tr><td>';
4150 print $langs->trans(
'DateInvoice');
4152 if ($action !=
'editinvoicedate' && !empty($object->brouillon) && $usercancreate && empty($conf->global->FAC_FORCE_DATE_VALIDATION))
4153 print '<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editinvoicedate&facid='.$object->id.
'">'.
img_edit($langs->trans(
'SetDate'), 1).
'</a></td>';
4154 print '</tr></table>';
4157 if ($action ==
'editinvoicedate') {
4158 $form->form_date(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date,
'invoicedate');
4160 print
'<span class="valuedate">'.dol_print_date($object->date,
'day').
'</span>';
4166 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE))
4170 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4171 print $langs->trans(
'DatePointOfTax');
4173 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editdate_pointoftax&facid='.$object->id.
'">'.
img_edit($langs->trans(
'SetDate'), 1).
'</a></td>';
4174 print
'</tr></table>';
4176 if ($action ==
'editdate_pointoftax') {
4177 $form->form_date(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date_pointoftax,
'date_pointoftax');
4179 print
'<span class="valuedate">'.dol_print_date($object->date_pointoftax,
'day').
'</span>';
4186 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4187 print $langs->trans(
'PaymentConditionsShort');
4190 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editconditions&facid='.$object->id.
'">'.
img_edit($langs->trans(
'SetConditions'), 1).
'</a></td>';
4191 print
'</tr></table>';
4195 if ($action ==
'editconditions') {
4196 $form->form_conditions_reglement(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
4198 $form->form_conditions_reglement(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->cond_reglement_id,
'none');
4207 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4208 print $langs->trans(
'DateMaxPayment');
4211 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editpaymentterm&facid='.$object->id.
'">'.
img_edit($langs->trans(
'SetDate'), 1).
'</a></td>';
4212 print
'</tr></table>';
4216 if ($action ==
'editpaymentterm') {
4217 $form->form_date(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->date_lim_reglement,
'paymentterm');
4219 print
'<span class="valuedate">'.dol_print_date($object->date_lim_reglement,
'day').
'</span>';
4220 if ($object->hasDelay()) {
4231 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4232 print $langs->trans(
'PaymentMode');
4234 if ($action !=
'editmode' && $usercancreate)
4235 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&facid='.$object->id.
'">'.
img_edit($langs->trans(
'SetMode'), 1).
'</a></td>';
4236 print
'</tr></table>';
4238 if ($action ==
'editmode')
4240 $form->form_modes_reglement(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
4242 $form->form_modes_reglement(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'none',
'CRDT');
4247 if (!empty($conf->multicurrency->enabled))
4252 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4253 print $form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
4255 if ($usercancreate && $action !=
'editmulticurrencycode' && !empty($object->brouillon))
4256 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencycode&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
4257 print
'</tr></table>';
4259 $htmlname = (($usercancreate && $action ==
'editmulticurrencycode') ?
'multicurrency_code' :
'none');
4260 $form->form_multicurrency_code(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code, $htmlname);
4264 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1)
4268 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4269 print $form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
4271 if ($usercancreate && $action !=
'editmulticurrencyrate' && !empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency)
4272 print
'<td class="right"><a href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencyrate&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
4273 print
'</tr></table>';
4275 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
4276 if ($action ==
'actualizemulticurrencyrate') {
4279 $form->form_multicurrency_rate(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx, ($usercancreate ?
'multicurrency_tx' :
'none'), $object->multicurrency_code);
4281 $form->form_multicurrency_rate(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
4282 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
4283 print
'<div class="inline-block"> ';
4284 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
4293 if (!empty($conf->banque->enabled))
4295 print
'<tr><td class="nowrap">';
4296 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
4297 print $langs->trans(
'BankAccount');
4299 if (($action !=
'editbankaccount') && $usercancreate)
4300 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editbankaccount&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetBankAccount'), 1).
'</a></td>';
4301 print
'</tr></table>';
4303 if ($action ==
'editbankaccount')
4305 $form->formSelectAccount(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
4307 $form->formSelectAccount(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
4314 if (!empty($conf->incoterm->enabled))
4317 print
'<table width="100%" class="nobordernopadding"><tr><td>';
4318 print $langs->trans(
'IncotermLabel');
4319 print
'<td><td class="right">';
4320 if ($usercancreate) print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$object->id.
'&action=editincoterm">'.
img_edit().
'</a>';
4321 else print
' ';
4322 print
'</td></tr></table>';
4325 if ($action !=
'editincoterm')
4327 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
4329 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''),
$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
4336 if (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
4337 $displayWarranty =
true;
4338 if (!in_array($object->type, $retainedWarrantyInvoiceAvailableType) && empty($object->retained_warranty)) {
4339 $displayWarranty =
false;
4342 if ($displayWarranty) {
4344 print
'<tr class="retained-warranty-lines" ><td>';
4345 print
'<table id="retained-warranty-table" class="nobordernopadding" width="100%"><tr><td>';
4346 print $langs->trans(
'RetainedWarranty');
4348 if ($action !=
'editretainedwarranty' && $user->rights->facture->creer) {
4349 print
'<td align="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editretainedwarranty&facid='.$object->id.
'">'.
img_edit($langs->trans(
'setretainedwarranty'), 1).
'</a></td>';
4352 print
'</tr></table>';
4354 if ($action ==
'editretainedwarranty')
4356 print
'<form id="retained-warranty-form" method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4357 print
'<input type="hidden" name="action" value="setretainedwarranty">';
4358 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4359 print
'<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.
'" >';
4360 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4363 print
price($object->retained_warranty).
'%';
4368 print
'<tr class="retained-warranty-lines" ><td>';
4369 print
'<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>';
4370 print $langs->trans(
'PaymentConditionsShortRetainedWarranty');
4372 if ($action !=
'editretainedwarrantypaymentterms' && $user->rights->facture->creer) {
4373 print
'<td align="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editretainedwarrantypaymentterms&facid='.$object->id.
'">'.
img_edit($langs->trans(
'setPaymentConditionsShortRetainedWarranty'), 1).
'</a></td>';
4376 print
'</tr></table>';
4378 $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime(
'-1 years', $object->date_lim_reglement);
4379 if ($object->date > $defaultDate) {
4380 $defaultDate = $object->date;
4383 if ($action ==
'editretainedwarrantypaymentterms')
4386 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4387 print
'<input type="hidden" name="action" value="setretainedwarrantyconditions">';
4388 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4389 $retained_warranty_fk_cond_reglement =
GETPOST(
'retained_warranty_fk_cond_reglement',
'int');
4390 $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $object->retained_warranty_fk_cond_reglement;
4391 $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;
4392 $form->select_conditions_paiements($retained_warranty_fk_cond_reglement,
'retained_warranty_fk_cond_reglement', -1, 1);
4393 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4396 $form->form_conditions_reglement(
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->retained_warranty_fk_cond_reglement,
'none');
4397 if (!$displayWarranty) {
4398 print
img_picto($langs->trans(
'RetainedWarrantyNeed100Percent'),
'warning.png',
'class="pictowarning valignmiddle" ');
4404 print
'<tr class="retained-warranty-lines" ><td>';
4405 print
'<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';
4406 print $langs->trans(
'RetainedWarrantyDateLimit');
4408 if ($action !=
'editretainedwarrantydatelimit' && $user->rights->facture->creer) {
4409 print
'<td align="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editretainedwarrantydatelimit&facid='.$object->id.
'">'.
img_edit($langs->trans(
'setretainedwarrantyDateLimit'), 1).
'</a></td>';
4412 print
'</tr></table>';
4414 $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime(
'-1 years', $object->date_lim_reglement);
4415 if ($object->date > $defaultDate) {
4416 $defaultDate = $object->date;
4419 if ($action ==
'editretainedwarrantydatelimit')
4422 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'">';
4423 print
'<input type="hidden" name="action" value="setretainedwarrantydatelimit">';
4424 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4425 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').
'" >';
4426 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4429 print
dol_print_date($object->retained_warranty_date_limit,
'day');
4438 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
4443 print
'<div class="fichehalfright">';
4444 print
'<div class="ficheaddleft">';
4446 print
'<!-- amounts -->'.
"\n";
4447 print
'<table class="border bordertop tableforfield centpercent">';
4450 if (!empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE_SCREEN) && $object->type == $object::TYPE_CREDIT_NOTE) {
4454 if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency))
4457 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
4458 print
'<td class="nowrap amountcard">'.price($sign * $object->multicurrency_total_ht,
'', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
4462 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
4463 print
'<td class="nowrap amountcard">'.price($sign * $object->multicurrency_total_tva,
'', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
4467 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
4468 print
'<td class="nowrap amountcard">'.price($sign * $object->multicurrency_total_ttc,
'', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
4473 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
'AmountHT').
'</td>';
4474 print
'<td class="nowrap amountcard">'.price($sign * $object->total_ht, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4477 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="3" class="nowrap amountcard">'.
price($sign * $object->total_tva, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4481 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0)
4483 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
4484 print
'<td class="nowrap amountcard">'.price($sign * $object->total_localtax1, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4486 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0)
4488 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
4489 print
'<td class=nowrap amountcard">'.price($sign * $object->total_localtax2, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4493 if ($selleruserevenustamp)
4496 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4497 print $langs->trans(
'RevenueStamp');
4499 if ($action !=
'editrevenuestamp' && !empty($object->brouillon) && $usercancreate)
4501 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editrevenuestamp&facid='.$object->id.
'">'.
img_edit($langs->trans(
'SetRevenuStamp'), 1).
'</a></td>';
4503 print
'</tr></table>';
4505 if ($action ==
'editrevenuestamp') {
4506 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
4507 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4508 print
'<input type="hidden" name="action" value="setrevenuestamp">';
4509 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num($object->revenuestamp).
'">';
4510 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
4511 print
' → <span id="revenuestamp_span"></span>';
4512 print
' <input type="submit" class="button buttongen" value="'.$langs->trans(
'Modify').
'">';
4515 $(document).ready(function(){
4516 js_recalculate_revenuestamp();
4517 $('select[name=revenuestamp_type]').on('change',function(){
4518 js_recalculate_revenuestamp();
4521 function js_recalculate_revenuestamp(){
4522 var valselected = $('select[name=revenuestamp_type]').val();
4523 console.log('Calculate revenue stamp from '+valselected);
4525 if (valselected.indexOf('%') == -1)
4527 revenue = valselected;
4531 var revenue_type = parseFloat(valselected);
4532 var amount_net = ".round($object->total_ht, 2).
";
4533 revenue = revenue_type * amount_net / 100;
4534 revenue = revenue.toFixed(2);
4536 $('#revenuestamp_val').val(revenue);
4537 $('#revenuestamp_span').html(revenue);
4541 print
price($object->revenuestamp, 1,
'', 1, - 1, - 1, $conf->currency);
4547 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td class="nowrap amountcard">'.
price($sign * $object->total_ttc, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
4554 if (!empty($conf->projet->enabled))
4556 if (!empty($conf->banque->enabled)) {
4560 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0)
4562 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0)
4564 if ($selleruserevenustamp)
4566 if (!empty($conf->multicurrency->enabled))
4568 if (!empty($conf->incoterm->enabled))
4572 if (($object->situation_cycle_ref > 0) && !empty($conf->global->INVOICE_USE_SITUATION))
4574 print
'<table class="noborder situationstable" width="100%">';
4577 print
'<tr class="liste_titre">';
4578 print
'<td>'.$langs->trans(
'ListOfSituationInvoices').
'</td>';
4580 print
'<td class="center">'.$langs->trans(
'Situation').
'</td>';
4581 if (!empty($conf->banque->enabled)) print
'<td class="right"></td>';
4582 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
4583 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
4584 print
'<td width="18"> </td>';
4588 $total_prev_ht = $total_prev_ttc = 0;
4589 $total_global_ht = $total_global_ttc = 0;
4591 if (count($object->tab_previous_situation_invoice) > 0) {
4594 $current_situation_counter = array();
4595 foreach ($object->tab_previous_situation_invoice as $prev_invoice) {
4596 $tmptotalpaidforthisinvoice = $prev_invoice->getSommePaiement();
4597 $total_prev_ht += $prev_invoice->total_ht;
4598 $total_prev_ttc += $prev_invoice->total_ttc;
4599 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ?-1 : 1) * $prev_invoice->situation_counter;
4600 print
'<tr class="oddeven">';
4601 print
'<td>'.$prev_invoice->getNomUrl(1).
'</td>';
4603 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$prev_invoice->situation_counter.
'</td>';
4604 if (!empty($conf->banque->enabled)) print
'<td class="right"></td>';
4605 print
'<td class="right">'.price($prev_invoice->total_ht).
'</td>';
4606 print
'<td class="right">'.price($prev_invoice->total_ttc).
'</td>';
4607 print
'<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).
'</td>';
4613 $total_global_ht += $total_prev_ht;
4614 $total_global_ttc += $total_prev_ttc;
4615 $total_global_ht += $object->total_ht;
4616 $total_global_ttc += $object->total_ttc;
4618 print
'<tr class="oddeven">';
4619 print
'<td>'.$object->getNomUrl(1).
'</td>';
4621 print
'<td class="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$object->situation_counter.
'</td>';
4622 if (!empty($conf->banque->enabled)) print
'<td class="right"></td>';
4623 print
'<td class="right">'.price($object->total_ht).
'</td>';
4624 print
'<td class="right">'.price($object->total_ttc).
'</td>';
4625 print
'<td class="right">'.$object->getLibStatut(3, $object->getSommePaiement()).
'</td>';
4629 print
'<tr class="oddeven">';
4630 print
'<td colspan="2" class="left"><b>'.$langs->trans(
'CurrentSituationTotal').
'</b></td>';
4633 foreach ($current_situation_counter as $sit)
4635 $curSign = $sit > 0 ?
'+' :
'-';
4636 $curType = $sit > 0 ? $langs->trans(
'situationInvoiceShortcode_S') : $langs->trans(
'situationInvoiceShortcode_AS');
4637 if ($i > 0) print
' '.$curSign.
' ';
4638 print $curType.abs($sit);
4642 if (!empty($conf->banque->enabled)) print
'<td></td>';
4643 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
4644 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
4645 print
'<td width="18"> </td>';
4649 if (count($object->tab_next_situation_invoice) > 0) {
4661 $total_next_ht = $total_next_ttc = 0;
4663 foreach ($object->tab_next_situation_invoice as $next_invoice) {
4664 $totalpaye = $next_invoice->getSommePaiement();
4665 $total_next_ht += $next_invoice->total_ht;
4666 $total_next_ttc += $next_invoice->total_ttc;
4668 print
'<tr class="oddeven">';
4669 print
'<td>'.$next_invoice->getNomUrl(1).
'</td>';
4671 print
'<td class="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE) ? $langs->trans(
'situationInvoiceShortcode_AS') : $langs->trans(
'situationInvoiceShortcode_S')).$next_invoice->situation_counter.
'</td>';
4672 if (!empty($conf->banque->enabled)) print
'<td class="right"></td>';
4673 print
'<td class="right">'.price($next_invoice->total_ht).
'</td>';
4674 print
'<td class="right">'.price($next_invoice->total_ttc).
'</td>';
4675 print
'<td class="right">'.$next_invoice->getLibStatut(3, $totalpaye).
'</td>';
4679 $total_global_ht += $total_next_ht;
4680 $total_global_ttc += $total_next_ttc;
4682 print
'<tr class="oddeven">';
4683 print
'<td colspan="3" class="right"></td>';
4684 if (!empty($conf->banque->enabled)) print
'<td class="right"></td>';
4685 print
'<td class="right"><b>'.price($total_global_ht).
'</b></td>';
4686 print
'<td class="right"><b>'.price($total_global_ttc).
'</b></td>';
4687 print
'<td width="18"> </td>';
4695 if ($object->type == $object::TYPE_CREDIT_NOTE) $sign = -1;
4699 print
'<div class="div-table-responsive-no-min">';
4700 print
'<table class="noborder paymenttable" width="100%">';
4702 print
'<tr class="liste_titre">';
4703 print
'<td class="liste_titre">'.($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')).
'</td>';
4704 print
'<td class="liste_titre">'.$langs->trans(
'Date').
'</td>';
4705 print
'<td class="liste_titre">'.$langs->trans(
'Type').
'</td>';
4706 if (!empty($conf->banque->enabled)) {
4707 print
'<td class="liste_titre right">'.$langs->trans(
'BankAccount').
'</td>';
4709 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
4710 print
'<td class="liste_titre" width="18"> </td>';
4714 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
4715 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
4716 $sql .=
' pf.amount,';
4717 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
4718 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
4719 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
4720 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
4721 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
4722 $sql .=
' WHERE pf.fk_facture = '.$object->id.
' AND pf.fk_paiement = p.rowid';
4723 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
4724 $sql .=
' ORDER BY p.datep, p.tms';
4726 $result = $db->query($sql);
4728 $num = $db->num_rows($result);
4735 $objp = $db->fetch_object($result);
4737 $paymentstatic->id = $objp->rowid;
4738 $paymentstatic->datepaye = $db->jdate($objp->dp);
4739 $paymentstatic->ref = $objp->ref;
4740 $paymentstatic->num_payment = $objp->num_payment;
4741 $paymentstatic->payment_code = $objp->payment_code;
4743 print
'<tr class="oddeven"><td>';
4744 print $paymentstatic->getNomUrl(1);
4747 $dateofpayment = $db->jdate($objp->dp);
4749 if ($tmparray[
'seconds'] == 0 && $tmparray[
'minutes'] == 0 && ($tmparray[
'hours'] == 0 || $tmparray[
'hours'] == 12)) {
4755 $label = ($langs->trans(
"PaymentType".$objp->payment_code) != (
"PaymentType".$objp->payment_code)) ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_label;
4756 print
'<td>'.$label.
' '.$objp->num_payment.
'</td>';
4757 if (!empty($conf->banque->enabled))
4759 $bankaccountstatic->id = $objp->baid;
4760 $bankaccountstatic->ref = $objp->baref;
4761 $bankaccountstatic->label = $objp->baref;
4762 $bankaccountstatic->number = $objp->banumber;
4764 if (!empty($conf->accounting->enabled)) {
4765 $bankaccountstatic->account_number = $objp->account_number;
4768 $accountingjournal->fetch($objp->fk_accountancy_journal);
4769 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
4772 print
'<td class="right">';
4773 if ($bankaccountstatic->id)
4774 print $bankaccountstatic->getNomUrl(1,
'transactions');
4777 print
'<td class="right">'.price($sign * $objp->amount).
'</td>';
4778 print
'<td class="center">';
4781 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=deletepayment&token='.
newToken().
'&paiement_id='.$objp->rowid.
'">';
4801 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4802 print
'<span class="opacitymedium">';
4804 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
4806 print $langs->trans(
'AlreadyPaid');
4808 print
'</span></td><td class="right'.(($totalpaye > 0) ?
' amountalreadypaid' :
'').
'">'.
price($totalpaye).
'</td><td> </td></tr>';
4810 $resteapayeraffiche = $resteapayer;
4811 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
4814 $creditnoteamount = 0;
4816 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
4817 $sql .=
" re.description, re.fk_facture_source";
4818 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
4819 $sql .=
" WHERE fk_facture = ".$object->id;
4820 $resql = $db->query($sql);
4822 $num = $db->num_rows(
$resql);
4826 $obj = $db->fetch_object(
$resql);
4827 $invoice->fetch($obj->fk_facture_source);
4828 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4829 print
'<span class="opacitymedium">';
4831 print $langs->trans(
"CreditNote").
' ';
4833 print $langs->trans(
"Deposit").
' ';
4834 print $invoice->getNomUrl(0);
4837 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
4838 print
'<td class="right">';
4839 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=unlinkdiscount&discountid='.$obj->rowid.
'">'.
img_delete().
'</a>';
4843 $creditnoteamount += $obj->amount_ttc;
4845 $depositamount += $obj->amount_ttc;
4853 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
4854 print
'<span class="opacitymedium">';
4855 print $form->textwithpicto($langs->trans(
"Discount"), $langs->trans(
"HelpEscompte"), - 1);
4857 print
'</td><td class="right">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye,
'MT')).
'</td><td> </td></tr>';
4858 $resteapayeraffiche = 0;
4859 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4863 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
4864 print
'<span class="opacitymedium">';
4865 print $form->textwithpicto($langs->trans(
"Abandoned"), $langs->trans(
"HelpAbandonBadCustomer"), - 1);
4867 print
'</td><td class="right">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye,
'MT')).
'</td><td> </td></tr>';
4869 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4873 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
4874 print
'<span class="opacitymedium">';
4875 print $form->textwithpicto($langs->trans(
"ProductReturned"), $langs->trans(
"HelpAbandonProductReturned"), - 1);
4877 print
'</td><td class="right">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye,
'MT')).
'</td><td> </td></tr>';
4878 $resteapayeraffiche = 0;
4879 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4883 print
'<tr><td colspan="'.$nbcols.
'" class="nowrap right">';
4884 $text = $langs->trans(
"HelpAbandonOther");
4885 if ($object->close_note)
4886 $text .=
'<br><br><b>'.$langs->trans(
"Reason").
'</b>:'.$object->close_note;
4887 print
'<span class="opacitymedium">';
4888 print $form->textwithpicto($langs->trans(
"Abandoned"), $text, - 1);
4890 print
'</td><td class="right">'.price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye,
'MT')).
'</td><td> </td></tr>';
4891 $resteapayeraffiche = 0;
4892 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4896 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4897 print
'<span class="opacitymedium">';
4898 print $langs->trans(
"Billed");
4899 print
'</td><td class="right">'.price($object->total_ttc).
'</td><td> </td></tr>';
4901 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4902 print
'<span class="opacitymedium">';
4903 print $langs->trans(
'RemainderToPay');
4904 if ($resteapayeraffiche < 0)
4905 print
' ('.$langs->trans(
'ExcessReceived').
')';
4908 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td>';
4909 print
'<td class="nowrap"> </td></tr>';
4912 if (!empty($object->situation_final) && !empty($object->retained_warranty) && $displayWarranty) {
4916 $retainedWarranty = $total_global_ttc * $object->retained_warranty / 100;
4919 $retainedWarranty = $object->total_ttc * $object->retained_warranty / 100;
4922 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
4924 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>';
4927 print
'<tr><td colspan="'.$nbcols.
'" align="right">';
4928 print $langs->trans(
"RetainedWarranty").
' ('.$object->retained_warranty.
'%)';
4929 print !empty($object->retained_warranty_date_limit) ?
' '.$langs->trans(
"ToPayOn",
dol_print_date($object->retained_warranty_date_limit,
'day')) :
'';
4930 print
' :</td><td align="right">'.price($retainedWarranty).
'</td><td> </td></tr>';
4934 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4937 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4938 print $langs->trans(
'AlreadyPaidBack');
4939 print
' :</td><td class="right">'.price($sign * $totalpaye).
'</td><td> </td></tr>';
4942 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"Billed").
' :</td><td class="right">'.
price($sign * $object->total_ttc).
'</td><td> </td></tr>';
4945 print
'<tr><td colspan="'.$nbcols.
'" class="right">';
4946 print $langs->trans(
'RemainderToPayBack');
4947 if ($resteapayeraffiche > 0)
4948 print
' ('.$langs->trans(
'ExcessPaid').
')';
4950 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopayback' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($sign * $resteapayeraffiche).
'</td>';
4951 print
'<td class="nowrap"> </td></tr>';
4963 if (!empty($conf->margin->enabled)) {
4964 $formmargin->displayMarginInfos($object);
4971 print
'<div class="clearboth"></div><br>';
4973 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
4974 $blocname =
'contacts';
4975 $title = $langs->trans(
'ContactsAddresses');
4976 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4979 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
4980 $blocname =
'notes';
4981 $title = $langs->trans(
'Notes');
4982 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
4986 $result = $object->getLinesArray();
4989 if (!empty($conf->global->INVOICE_USE_SITUATION))
4991 if ($object->situation_cycle_ref && $object->statut == 0)
4993 print
'<!-- Area to change globally the situation percent -->'.
"\n";
4994 print
'<div class="div-table-responsive">';
4996 print
'<form name="updatealllines" id="updatealllines" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'#updatealllines" method="POST">';
4997 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
4998 print
'<input type="hidden" name="action" value="updatealllines" />';
4999 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
5001 print
'<table id="tablelines_all_progress" class="noborder noshadow" width="100%">';
5003 print
'<tr class="liste_titre nodrag nodrop">';
5006 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
5007 print
'<td align="center" width="5"> </td>';
5009 print
'<td class="minwidth500imp">'.$langs->trans(
'ModifyAllLines').
'</td>';
5010 print
'<td class="right">'.$langs->trans(
'Progress').
'</td>';
5011 print
'<td> </td>';
5014 print
'<tr class="nodrag nodrop">';
5016 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
5017 print
'<td align="center" width="5"> </td>';
5019 print
'<td> </td>';
5020 print
'<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>';
5021 print
'<td class="right"><input class="button" type="submit" name="all_percent" value="Modifier" /></td>';
5032 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'#addline' :
'#line_'.
GETPOST(
'lineid')).
'" method="POST">
5033 <input type="hidden" name="token" value="' .
newToken().
'">
5034 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
5035 <input type="hidden" name="mode" value="">
5036 <input type="hidden" name="id" value="' . $object->id.
'">
5039 if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
5040 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
5043 print
'<div class="div-table-responsive-no-min">';
5044 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
5047 if (!empty($object->lines)) {
5048 $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
5052 if ($object->statut == 0 && $usercancreate && $action !=
'valid' && $action !=
'editline')
5054 if ($action !=
'editline' && $action !=
'selectlines')
5057 $object->formAddObjectLine(1, $mysoc, $soc);
5059 $parameters = array();
5060 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
5074 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline')
5076 print
'<div class="tabsAction">';
5078 $parameters = array();
5079 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
5080 if (empty($reshook)) {
5085 $ventilExportCompta = $object->getVentilExportCompta();
5087 if ($ventilExportCompta == 0)
5089 if (!empty($conf->global->INVOICE_CAN_ALWAYS_BE_EDITED) || ($resteapayer ==
price2num($object->total_ttc,
'MT', 1) && empty($object->paye)))
5091 if (!$objectidnext && $object->is_last_in_cycle())
5093 if ($usercanunvalidate)
5095 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=modif">'.$langs->trans(
'Modify').
'</a>';
5097 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
'Modify').
'</span>';
5099 } elseif (!$object->is_last_in_cycle()) {
5100 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotLastInCycle").
'">'.$langs->trans(
'Modify').
'</span>';
5102 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'Modify').
'</span>';
5106 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Modify').
'</span>';
5111 $result = $discount->fetch(0, $object->id);
5118 && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || $usercanreopen))
5120 if ($object->close_code !=
'replaced' || (!$objectidnext))
5122 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=reopen">'.$langs->trans(
'ReOpen').
'</a>';
5124 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ReOpen').
'</span>';
5130 if ($usercanvalidate)
5132 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.
$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=valid">'.$langs->trans(
'Validate').
'</a>';
5137 if (empty($user->socid)) {
5139 if ($objectidnext) {
5140 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'SendMail').
'</span>';
5143 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
5144 }
else print
'<a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
'SendMail').
'</a>';
5152 if ($resteapayer > 0)
5154 if ($usercancreatewithdrarequest)
5156 if (!$objectidnext && $object->close_code !=
'replaced')
5158 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>';
5160 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'MakeWithdrawRequest').
'</span>';
5171 if (!empty($conf->takepos->enabled) && $object->module_source ==
'takepos')
5173 $langs->load(
"cashdesk");
5174 $receipt_url = DOL_URL_ROOT.
"/takepos/receipt.php";
5175 print
'<a target="_blank" class="butAction" href="'.$receipt_url.
'?facid='.$object->id.
'">'.$langs->trans(
'POSTicket').
'</a>';
5180 if ($objectidnext) {
5181 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'DoPayment').
'</span>';
5186 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.$object->id.
'&action=create&accountid='.$object->fk_account.
'">'.$langs->trans(
'DoPayment').
'</a>';
5196 if ($resteapayer == 0)
5198 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span>';
5200 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/paiement.php?facid='.$object->id.
'&action=create&accountid='.$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a>';
5207 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.
$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a>';
5211 && (!empty($conf->global->INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) || $object->getSommePaiement() == 0)
5213 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.
$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc" title="'.
dol_escape_htmltag($langs->trans(
"ConfirmConvertToReduc2")).
'">'.$langs->trans(
'ConvertToReduc').
'</a>';
5216 if ($object->type ==
Facture::TYPE_DEPOSIT && $usercancreate && $object->statut > 0 && empty($discount->id))
5218 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.
$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertToReduc').
'</a>';
5224 || ($object->type ==
Facture::TYPE_DEPOSIT && $object->paye == 0 && $object->total_ttc > 0 && $resteapayer == 0 && $usercanissuepayment && empty($discount->id))
5227 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaid').
'</a>';
5234 if ($totalpaye > 0 || $totalcreditnotes > 0)
5237 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaidPartially').
'</a>';
5239 if (empty($conf->global->INVOICE_CAN_NEVER_BE_CANCELED))
5243 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'ClassifyCanceled').
'</span>';
5245 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=canceled">'.$langs->trans(
'ClassifyCanceled').
'</a>';
5256 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>';
5263 && ($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits) > 0
5266 && $object->is_last_in_cycle()
5267 && $conf->global->INVOICE_USE_SITUATION_CREDIT_NOTE
5270 if ($usercanunvalidate)
5272 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>';
5274 print
'<span class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
"CreateCreditNote").
'</span>';
5281 print
'<a class="butAction'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=clone&object=invoice">'.$langs->trans(
"ToClone").
'</a>';
5287 if (!$objectidnext && count($object->lines) > 0)
5289 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$object->id.
'&action=create">'.$langs->trans(
"ChangeIntoRepeatableInvoice").
'</a>';
5298 && $object->situation_counter > 1
5299 && $object->is_last_in_cycle()
5300 && $usercanunvalidate
5303 if (($object->total_ttc - $totalcreditnotes) == 0)
5305 print
'<a id="butSituationOut" class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=situationout">'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
5307 print
'<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotEnouthCreditNote").
'" >'.$langs->trans(
"RemoveSituationFromCycle").
'</a>';
5312 if ($usercancreate && ($object->type == 5) && ($object->statut == 1 || $object->statut == 2)) {
5313 if ($object->is_last_in_cycle() && $object->situation_final != 1) {
5314 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=create&type=5&origin=facture&originid='.$object->id.
'&socid='.$object->socid.
'" >'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5315 } elseif (!$object->is_last_in_cycle()) {
5316 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInCycle").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5318 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseFinal").
'">'.$langs->trans(
'CreateNextSituationInvoice').
'</a>';
5323 $isErasable = $object->is_erasable();
5324 if ($usercandelete || ($usercancreate && $isErasable == 1))
5327 if ($isErasable == -4) {
5328 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecausePayments").
'">'.$langs->trans(
'Delete').
'</a>';
5329 } elseif ($isErasable == -3) {
5330 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastSituationInvoice").
'">'.$langs->trans(
'Delete').
'</a>';
5331 } elseif ($isErasable == -2) {
5332 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotLastInvoice").
'">'.$langs->trans(
'Delete').
'</a>';
5333 } elseif ($isErasable == -1) {
5334 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseDispatchedInBookkeeping").
'">'.$langs->trans(
'Delete').
'</a>';
5335 } elseif ($isErasable <= 0)
5337 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseNotErasable").
'">'.$langs->trans(
'Delete').
'</a>';
5338 } elseif ($objectidnext)
5340 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"DisabledBecauseReplacedInvoice").
'">'.$langs->trans(
'Delete').
'</a>';
5342 print
'<a class="butActionDelete'.($conf->use_javascript_ajax ?
' reposition' :
'').
'" href="'.
$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
'Delete').
'</a>';
5345 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotAllowed").
'">'.$langs->trans(
'Delete').
'</a>';
5352 if (
GETPOST(
'modelselected',
'alpha')) {
5353 $action =
'presend';
5355 if ($action !=
'prerelance' && $action !=
'presend')
5357 print
'<div class="fichecenter"><div class="fichehalfleft">';
5358 print
'<a name="builddoc"></a>';
5362 $filedir = $conf->facture->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($object->ref);
5363 $urlsource =
$_SERVER[
'PHP_SELF'].
'?facid='.$object->id;
5364 $genallowed = $usercanread;
5365 $delallowed = $usercancreate;
5367 print $formfile->showdocuments(
5368 'facture', $filename, $filedir, $urlsource, $genallowed,
5369 $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'',
5370 $soc->default_lang,
'', $object, 0,
'remove_file_comfirm');
5372 $somethingshown = $formfile->numoffiles;
5375 $linktoelem = $form->showLinkToObjectBlock($object, null, array(
'invoice'));
5377 $compatibleImportElementsList =
false;
5382 $compatibleImportElementsList = array(
'commande',
'propal');
5384 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
5388 $useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled));
5392 print
'<br><!-- Link to pay -->'.
"\n";
5393 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
5394 print showOnlinePaymentUrl(
'invoice', $object->ref).
'<br>';
5398 if ($object->statut !=
Facture::STATUS_DRAFT && !empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD))
5400 print
'<br><!-- Link to download main doc -->'.
"\n";
5404 print
'</div><div class="fichehalfright"><div class="ficheaddleft">';
5407 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
5409 $somethingshown =
$formactions->showactions($object,
'invoice', $socid, 1);
5411 print
'</div></div></div>';
5416 $modelmail =
'facture_send';
5417 $defaulttopic =
'SendBillRef';
5418 $diroutput = $conf->facture->multidir_output[$object->entity];
5419 $trackid =
'inv'.$object->id;
5421 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage notifications.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
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.
const TYPE_STANDARD
Standard invoice.
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...
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
static getIdAndTxFromCode($db, $code, $date_document= '')
Get id and rate of currency from code.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
Class to manage invoice templates.
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.
Class to manage Dolibarr users.
const TYPE_REPLACEMENT
Replacement invoice.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete= 'resolve')
Convert a html select field into an ajax combobox.
const TYPE_PROFORMA
Proforma invoice (should not be used.
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...
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate, from a $thirdparty_buyer to a $thirdparty_seller Note: This function applies same rules than get_default_tva.
const TYPE_SITUATION
Situation invoice.
Class to manage bank accounts.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
const TYPE_CREDIT_NOTE
Credit note invoice.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
showDirectDownloadLink($object)
Return string with full Url.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
const STATUS_VALIDATED
Validated (need to be paid)
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
Class to manage shipments.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
const STATUS_DRAFT
Draft status.
Class to manage payments of customer invoices.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=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 Calling this function terminate execution ...
Class to manage translations.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
const STATUS_CLOSED
Classified paid.
Class ProductCombination Used to represent a product combination.
const STATUS_ABANDONED
Classified abandoned and no payment done.
print $_SERVER["PHP_SELF"]
Edit parameters.
const TYPE_DEPOSIT
Deposit invoice.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Class to manage absolute discounts.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
Class to manage accounting accounts.
Class to manage invoices.
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_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
Class to manage invoice lines.
Class to manage warehouses.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.