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',
'alpha');
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 if ($id > 0 || ! empty($ref)) {
106 $ret = $object->fetch($id, $ref,
'',
'', $conf->global->INVOICE_USE_SITUATION);
110 $hookmanager->initHooks(array(
'invoicecard',
'globalcard'));
112 $usercanread = $user->rights->facture->lire;
113 $usercancreate = $user->rights->facture->creer;
114 $usercanissuepayment = $user->rights->facture->paiement;
115 $usercandelete = $user->rights->facture->supprimer;
116 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->validate)));
117 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send);
118 $usercanreopen = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->reopen);
119 $usercanunvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($usercancreate)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate)));
121 $usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
122 $usercancreatemargin = $user->rights->margins->creer;
123 $usercanreadallmargin = $user->rights->margins->liretous;
124 $usercancreatewithdrarequest = $user->rights->prelevement->bons->creer;
126 $permissionnote = $usercancreate;
127 $permissiondellink = $usercancreate;
128 $permissiontoedit = $usercancreate;
131 $fieldid = (! empty($ref) ?
'facnumber' :
'rowid');
132 if ($user->societe_id) $socid = $user->societe_id;
134 $result =
restrictedArea($user,
'facture', $id,
'',
'',
'fk_soc', $fieldid, $isdraft);
142 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
143 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
149 if (! empty($backtopage))
151 header(
"Location: ".$backtopage);
157 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
159 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
161 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
164 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
168 if ($object->fetch($id) > 0) {
169 $result = $object->createFromClone($socid);
171 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?facid=' . $result);
182 else if ($action ==
'reopen' && $usercancreate) {
183 $result = $object->fetch($id);
184 if ($object->statut == 2 || ($object->statut == 3 && $object->close_code !=
'replaced') || ($object->statut == 1 && $object->paye == 1)) {
185 $result = $object->set_unpaid($user);
187 header(
'Location: ' . $_SERVER[
"PHP_SELF"] .
'?facid=' . $id);
196 else if ($action ==
'confirm_delete' && $confirm ==
'yes') {
197 $result = $object->fetch($id);
198 $object->fetch_thirdparty();
200 $idwarehouse =
GETPOST(
'idwarehouse');
202 $qualified_for_stock_change = 0;
203 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
204 $qualified_for_stock_change = $object->hasProductsOrServices(2);
206 $qualified_for_stock_change = $object->hasProductsOrServices(1);
209 $isErasable=$object->is_erasable();
211 if (($usercandelete && $isErasable > 0)
212 || ($usercancreate && $isErasable == 1))
214 $result = $object->delete($user, 0, $idwarehouse);
216 header(
'Location: ' . DOL_URL_ROOT .
'/compta/facture/list.php?restore_lastsearch_values=1');
226 else if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate)
229 $object->fetch_thirdparty();
231 $result = $object->deleteline(
GETPOST(
'lineid'));
234 $outputlangs = $langs;
236 if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST[
'lang_id']))
237 $newlang = $_REQUEST[
'lang_id'];
238 if ($conf->global->MAIN_MULTILANGS && empty($newlang))
239 $newlang = $object->thirdparty->default_lang;
240 if (! empty($newlang)) {
242 $outputlangs->setDefaultLang($newlang);
243 $outputlangs->load(
'products');
245 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
246 $ret = $object->fetch($id);
247 $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
250 header(
'Location: ' . $_SERVER[
"PHP_SELF"] .
'?facid=' . $id);
260 else if ($action ==
'unlinkdiscount' && $usercancreate)
263 $result = $discount->fetch(
GETPOST(
"discountid"));
264 $discount->unlink_invoice();
268 else if ($action ==
'valid' && $usercancreate)
275 if ($object->total_ht >= 0) {
276 setEventMessages($langs->trans(
"ErrorInvoiceAvoirMustBeNegative"), null,
'errors');
281 if (empty($conf->global->FACTURE_ENABLE_NEGATIVE) && $object->total_ht < 0) {
282 setEventMessages($langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive"), null,
'errors');
288 else if ($action ==
'set_thirdparty' && $usercancreate)
291 $object->setValueFrom(
'fk_soc', $socid,
'', null,
'int',
'', $user,
'BILL_MODIFY');
293 header(
'Location: ' . $_SERVER[
"PHP_SELF"] .
'?facid=' . $id);
297 else if ($action ==
'classin' && $usercancreate)
300 $object->setProject($_POST[
'projectid']);
303 else if ($action ==
'setmode' && $usercancreate)
306 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
312 else if ($action ==
'setmulticurrencycode' && $usercancreate) {
313 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
317 else if ($action ==
'setmulticurrencyrate' && $usercancreate) {
318 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
321 else if ($action ==
'setinvoicedate' && $usercancreate)
324 $old_date_lim_reglement = $object->date_lim_reglement;
325 $date =
dol_mktime(12, 0, 0, $_POST[
'invoicedatemonth'], $_POST[
'invoicedateday'], $_POST[
'invoicedateyear']);
328 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")), null,
'errors');
329 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?facid='.$id.
'&action=editinvoicedate');
333 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
334 if ($new_date_lim_reglement > $old_date_lim_reglement) $object->date_lim_reglement = $new_date_lim_reglement;
335 if ($object->date_lim_reglement < $object->date) $object->date_lim_reglement = $object->date;
336 $result = $object->update($user);
340 else if ($action ==
'setdate_pointoftax' && $usercancreate)
343 $date_pointoftax =
dol_mktime(12, 0, 0, $_POST[
'date_pointoftaxmonth'], $_POST[
'date_pointoftaxday'], $_POST[
'date_pointoftaxyear']);
344 $object->date_pointoftax=$date_pointoftax;
345 $result = $object->update($user);
349 else if ($action ==
'setconditions' && $usercancreate)
352 $object->cond_reglement_code = 0;
353 $object->cond_reglement_id = 0;
354 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
357 $old_date_lim_reglement = $object->date_lim_reglement;
358 $new_date_lim_reglement = $object->calculate_date_lim_reglement();
359 if ($new_date_lim_reglement > $old_date_lim_reglement) $object->date_lim_reglement = $new_date_lim_reglement;
360 if ($object->date_lim_reglement < $object->date) $object->date_lim_reglement = $object->date;
361 $result = $object->update($user);
365 else if ($action ==
'setpaymentterm' && $usercancreate)
368 $object->date_lim_reglement =
dol_mktime(12, 0, 0, $_POST[
'paymenttermmonth'], $_POST[
'paymenttermday'], $_POST[
'paymenttermyear']);
369 if ($object->date_lim_reglement < $object->date) {
370 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
371 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"), null,
'warnings');
373 $result = $object->update($user);
378 else if ($action ==
'setrevenuestamp' && $usercancreate)
381 $object->revenuestamp =
GETPOST(
'revenuestamp');
382 $result = $object->update($user);
383 $object->update_price(1);
389 elseif ($action ==
'set_incoterms' && !empty($conf->incoterm->enabled))
391 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
395 else if ($action ==
'setbankaccount' && $usercancreate)
397 $result=$object->setBankAccount(
GETPOST(
'fk_account',
'int'));
400 else if ($action ==
'setremisepercent' && $usercancreate)
403 $result = $object->set_remise($user, $_POST[
'remise_percent']);
406 else if ($action ==
"setabsolutediscount" && $usercancreate)
411 if (! empty($_POST[
"remise_id"])) {
412 $ret = $object->fetch($id);
414 $result = $object->insert_discount($_POST[
"remise_id"]);
423 if (! empty($_POST[
"remise_id_for_payment"]))
425 require_once DOL_DOCUMENT_ROOT .
'/core/class/discount.class.php';
427 $discount->fetch($_POST[
"remise_id_for_payment"]);
435 setEventMessages($langs->trans(
"ErrorDiscountLargerThanRemainToPaySplitItBefore"), null,
'errors');
440 $result = $discount->link_to_invoice(0, $id);
447 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
449 $outputlangs = $langs;
451 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
452 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
453 if (! empty($newlang)) {
455 $outputlangs->setDefaultLang($newlang);
457 $ret = $object->fetch($id);
459 $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
460 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
464 else if ($action ==
'setref_client' && $usercancreate)
467 $object->set_ref_client(
GETPOST(
'ref_client'));
471 else if ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate)
473 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
476 $object->fetch_thirdparty();
481 $array_to_check=array(
'IDPROF1',
'IDPROF2',
'IDPROF3',
'IDPROF4',
'IDPROF5',
'IDPROF6',
'EMAIL');
482 foreach($array_to_check as $key)
484 $keymin=strtolower($key);
485 $i=(int) preg_replace(
'/[^0-9]/',
'',$key);
486 $vallabel=$object->thirdparty->$keymin;
490 if ($object->thirdparty->isACompany())
493 if ($mysoc->country_id > 0 && $object->thirdparty->country_id == $mysoc->country_id)
495 $idprof_mandatory =
'SOCIETE_'.$key.
'_INVOICE_MANDATORY';
496 if (! $vallabel && ! empty($conf->global->$idprof_mandatory))
498 $langs->load(
"errors");
500 setEventMessages($langs->trans(
'ErrorProdIdIsMandatory', $langs->transcountry(
'ProfId'.$i, $object->thirdparty->country_code)).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')', null,
'errors');
511 if (! empty($conf->global->SOCIETE_EMAIL_INVOICE_MANDATORY) && ! isValidEMail($object->thirdparty->email))
513 $langs->load(
"errors");
515 setEventMessages($langs->trans(
"ErrorBadEMail", $object->thirdparty->email).
' ('.$langs->trans(
"ForbiddenBySetupRules").
')', null,
'errors');
521 $qualified_for_stock_change = 0;
522 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
523 $qualified_for_stock_change = $object->hasProductsOrServices(2);
525 $qualified_for_stock_change = $object->hasProductsOrServices(1);
529 if ($object->type !=
Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change)
531 if (! $idwarehouse || $idwarehouse == - 1) {
533 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")), null,
'errors');
540 $result = $object->validate($user,
'', $idwarehouse);
544 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
546 $outputlangs = $langs;
548 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
549 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
550 if (! empty($newlang)) {
552 $outputlangs->setDefaultLang($newlang);
553 $outputlangs->load(
'products');
555 $model=$object->modelpdf;
556 $ret = $object->fetch($id);
558 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
559 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
564 if (count($object->errors))
setEventMessages(null, $object->errors,
'errors');
571 else if ($action ==
'confirm_modif' && $usercanunvalidate)
573 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
576 $object->fetch_thirdparty();
578 $qualified_for_stock_change = 0;
579 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
580 $qualified_for_stock_change = $object->hasProductsOrServices(2);
582 $qualified_for_stock_change = $object->hasProductsOrServices(1);
586 if ($object->type !=
Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change)
588 if (! $idwarehouse || $idwarehouse == - 1) {
590 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")), null,
'errors');
597 $sql =
'SELECT pf.amount';
598 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'paiement_facture as pf';
599 $sql .=
' WHERE pf.fk_facture = ' . $object->id;
601 $result = $db->query($sql);
604 $num = $db->num_rows($result);
607 $objp = $db->fetch_object($result);
608 $totalpaye += $objp->amount;
615 $resteapayer = $object->total_ttc - $totalpaye;
618 $ventilExportCompta = $object->getVentilExportCompta();
621 if ($ventilExportCompta == 0)
623 if (! empty($conf->global->INVOICE_CAN_ALWAYS_BE_EDITED) || ($resteapayer == $object->total_ttc && empty($object->paye)))
625 $result=$object->set_draft($user, $idwarehouse);
629 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
631 $outputlangs = $langs;
633 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
634 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
635 if (! empty($newlang)) {
637 $outputlangs->setDefaultLang($newlang);
638 $outputlangs->load(
'products');
640 $model=$object->modelpdf;
641 $ret = $object->fetch($id);
643 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
651 else if ($action ==
'confirm_paid' && $confirm ==
'yes' && $usercanissuepayment)
654 $result = $object->set_paid($user);
657 else if ($action ==
'confirm_paid_partially' && $confirm ==
'yes' && $usercanissuepayment)
660 $close_code =
GETPOST(
"close_code",
'none');
661 $close_note =
GETPOST(
"close_note",
'none');
663 $result = $object->set_paid($user, $close_code, $close_note);
666 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")), null,
'errors');
669 else if ($action ==
'confirm_canceled' && $confirm ==
'yes') {
671 $close_code =
GETPOST(
"close_code",
'none');
672 $close_note =
GETPOST(
"close_note",
'none');
674 $result = $object->set_canceled($user, $close_code, $close_note);
677 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Reason")), null,
'errors');
682 else if ($action ==
'confirm_converttoreduc' && $confirm ==
'yes' && $usercancreate)
685 $object->fetch_thirdparty();
690 $result=$discountcheck->fetch(0,$object->id);
699 $amount_ht = $amount_tva = $amount_ttc = array();
703 foreach ($object->lines as $line)
705 if ($line->product_type < 9 && $line->total_ht != 0)
707 $amount_ht[$line->tva_tx] += $line->total_ht;
708 $amount_tva[$line->tva_tx] += $line->total_tva;
709 $amount_ttc[$line->tva_tx] += $line->total_ttc;
710 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
711 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
712 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
720 $discount->description =
'(CREDIT_NOTE)';
722 $discount->description =
'(DEPOSIT)';
724 $discount->description =
'(EXCESS RECEIVED)';
726 setEventMessages($langs->trans(
'CantConvertToReducAnInvoiceOfThisType'), null,
'errors');
728 $discount->fk_soc = $object->socid;
729 $discount->fk_facture_source = $object->id;
738 $sql =
'SELECT SUM(pf.amount) as total_paiements';
739 $sql.=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
740 $sql.=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
741 $sql.=
' WHERE pf.fk_facture = '.$object->id;
742 $sql.=
' AND pf.fk_paiement = p.rowid';
743 $sql.=
' AND p.entity IN (' .
getEntity(
'facture').
')';
744 $resql = $db->query($sql);
747 $res = $db->fetch_object(
$resql);
748 $total_paiements = $res->total_paiements;
751 $total_creditnote_and_deposit = 0;
752 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
753 $sql .=
" re.description, re.fk_facture_source";
754 $sql .=
" FROM " . MAIN_DB_PREFIX .
"societe_remise_except as re";
755 $sql .=
" WHERE fk_facture = " . $object->id;
756 $resql = $db->query($sql);
758 while ($obj = $db->fetch_object(
$resql)) $total_creditnote_and_deposit += $obj->amount_ttc;
761 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object->total_ttc;
762 $discount->amount_tva = 0;
763 $discount->tva_tx = 0;
765 $result = $discount->create($user);
773 foreach ($amount_ht as $tva_tx => $xxx)
775 $discount->amount_ht = abs($amount_ht[$tva_tx]);
776 $discount->amount_tva = abs($amount_tva[$tva_tx]);
777 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
778 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
779 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
780 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
781 $discount->tva_tx = abs($tva_tx);
783 $result = $discount->create($user);
796 $result = $object->set_paid($user);
819 elseif ($action ==
'confirm_delete_paiement' && $confirm ==
'yes' && $usercancreate)
825 $result=$paiement->fetch(
GETPOST(
'paiement_id'));
827 $result=$paiement->delete();
828 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
839 else if ($action ==
'add' && $usercancreate)
841 if ($socid > 0) $object->socid =
GETPOST(
'socid',
'int');
848 $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
849 $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
850 if ($ret < 0) $error++;
855 $dateinvoice =
dol_mktime(12, 0, 0, $_POST[
'remonth'], $_POST[
'reday'], $_POST[
'reyear']);
856 if (empty($dateinvoice))
859 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")), null,
'errors');
862 if (! ($_POST[
'fac_replacement'] > 0)) {
864 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReplaceInvoice")), null,
'errors');
867 $date_pointoftax =
dol_mktime(12, 0, 0, $_POST[
'date_pointoftaxmonth'], $_POST[
'date_pointoftaxday'], $_POST[
'date_pointoftaxyear']);
871 $result = $object->fetch($_POST[
'fac_replacement']);
872 $object->fetch_thirdparty();
874 $object->date = $dateinvoice;
875 $object->date_pointoftax = $date_pointoftax;
876 $object->note_public = trim(
GETPOST(
'note_public',
'none'));
878 $object->ref_client = $_POST[
'ref_client'];
879 $object->ref_int = $_POST[
'ref_int'];
880 $object->modelpdf = $_POST[
'model'];
881 $object->fk_project = $_POST[
'projectid'];
882 $object->cond_reglement_id = $_POST[
'cond_reglement_id'];
883 $object->mode_reglement_id = $_POST[
'mode_reglement_id'];
884 $object->fk_account =
GETPOST(
'fk_account',
'int');
885 $object->remise_absolue = $_POST[
'remise_absolue'];
886 $object->remise_percent = $_POST[
'remise_percent'];
887 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
888 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
889 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
890 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
894 $object->fk_facture_source = $_POST[
'fac_replacement'];
897 $id = $object->createFromCurrent($user);
907 $sourceinvoice =
GETPOST(
'fac_avoir');
908 if (! ($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE))
911 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CorrectInvoice")), null,
'errors');
914 $dateinvoice =
dol_mktime(12, 0, 0, $_POST[
'remonth'], $_POST[
'reday'], $_POST[
'reyear']);
915 if (empty($dateinvoice))
918 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->trans(
"Date")), null,
'errors');
921 $date_pointoftax =
dol_mktime(12, 0, 0, $_POST[
'date_pointoftaxmonth'], $_POST[
'date_pointoftaxday'], $_POST[
'date_pointoftaxyear']);
925 $object->socid =
GETPOST(
'socid',
'int');
926 $object->number = $_POST[
'facnumber'];
927 $object->date = $dateinvoice;
928 $object->date_pointoftax = $date_pointoftax;
929 $object->note_public = trim(
GETPOST(
'note_public',
'none'));
931 $object->ref_client = $_POST[
'ref_client'];
932 $object->ref_int = $_POST[
'ref_int'];
933 $object->modelpdf = $_POST[
'model'];
934 $object->fk_project = $_POST[
'projectid'];
935 $object->cond_reglement_id = 0;
936 $object->mode_reglement_id = $_POST[
'mode_reglement_id'];
937 $object->fk_account =
GETPOST(
'fk_account',
'int');
938 $object->remise_absolue = $_POST[
'remise_absolue'];
939 $object->remise_percent = $_POST[
'remise_percent'];
940 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
941 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
942 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
943 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
947 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice :
'';
950 $facture_source =
new Facture($db);
951 if ($facture_source->fetch($object->fk_facture_source)>0)
955 $object->situation_counter = $facture_source->situation_counter;
956 $object->situation_cycle_ref = $facture_source->situation_cycle_ref;
957 $facture_source->fetchPreviousNextSituationInvoice();
960 $id = $object->create($user);
962 if (
GETPOST(
'invoiceAvoirWithLines',
'int')==1 && $id>0)
964 if (!empty($facture_source->lines))
968 foreach($facture_source->lines as $line)
971 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($line,
'fetch_optionals')) {
973 $line->fetch_optionals();
977 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
986 $source_fk_prev_id = $line->fk_prev_id;
987 $line->fk_prev_id = $line->id;
989 if(!empty($facture_source->tab_previous_situation_invoice))
992 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
993 $searchPreviousInvoice =
true;
994 while( $searchPreviousInvoice )
996 if($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1)
998 $searchPreviousInvoice=
false;
1008 $maxPrevSituationPercent = 0;
1009 foreach($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine)
1011 if($prevLine->id == $source_fk_prev_id)
1013 $maxPrevSituationPercent = max($maxPrevSituationPercent,$prevLine->situation_percent);
1016 $line->total_ht = $line->total_ht - $prevLine->total_ht;
1017 $line->total_tva = $line->total_tva - $prevLine->total_tva;
1018 $line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
1019 $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
1020 $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
1022 $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
1023 $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
1024 $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
1025 $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
1030 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
1034 $line->fk_facture = $object->id;
1035 $line->fk_parent_line = $fk_parent_line;
1037 $line->subprice = -$line->subprice;
1038 $line->pa_ht = $line->pa_ht;
1039 $line->total_ht = -$line->total_ht;
1040 $line->total_tva = -$line->total_tva;
1041 $line->total_ttc = -$line->total_ttc;
1042 $line->total_localtax1 = -$line->total_localtax1;
1043 $line->total_localtax2 = -$line->total_localtax2;
1045 $line->multicurrency_subprice = -$line->multicurrency_subprice;
1046 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
1047 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
1048 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
1050 $result = $line->insert(0, 1);
1052 $object->lines[] = $line;
1055 if ($result > 0 && $line->product_type == 9) {
1056 $fk_parent_line = $result;
1060 $object->update_price(1);
1064 if(
GETPOST(
'invoiceAvoirWithPaymentRestAmount',
'int')==1 && $id>0)
1066 if ($facture_source->fetch($object->fk_facture_source)>0)
1068 $totalpaye = $facture_source->getSommePaiement();
1069 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
1070 $totaldeposits = $facture_source->getSumDepositsUsed();
1071 $remain_to_pay = abs($facture_source->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits);
1073 $object->addline($langs->trans(
'invoiceAvoirLineWithPaymentRestAmount'),$remain_to_pay,1,0,0,0,0,0,
'',
'',
'TTC');
1078 if(! empty($object->fk_facture_source)) {
1079 $facture_source->fetch($object->fk_facture_source);
1080 $facture_source->fetchObjectLinked();
1082 if(! empty($facture_source->linkedObjectsIds)) {
1083 foreach($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
1084 $object->add_object_linked($sourcetype, current($TIds));
1094 $dateinvoice =
dol_mktime(12, 0, 0, $_POST[
'remonth'], $_POST[
'reday'], $_POST[
'reyear']);
1095 if (empty($dateinvoice))
1098 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")), null,
'errors');
1101 $date_pointoftax =
dol_mktime(12, 0, 0, $_POST[
'date_pointoftaxmonth'], $_POST[
'date_pointoftaxday'], $_POST[
'date_pointoftaxyear']);
1105 $object->socid =
GETPOST(
'socid',
'int');
1106 $object->type = $_POST[
'type'];
1107 $object->number = $_POST[
'facnumber'];
1108 $object->date = $dateinvoice;
1109 $object->date_pointoftax = $date_pointoftax;
1110 $object->note_public = trim(
GETPOST(
'note_public',
'none'));
1111 $object->note_private = trim(
GETPOST(
'note_private',
'none'));
1112 $object->ref_client = $_POST[
'ref_client'];
1113 $object->ref_int = $_POST[
'ref_int'];
1114 $object->modelpdf = $_POST[
'model'];
1115 $object->fk_project = $_POST[
'projectid'];
1116 $object->cond_reglement_id = ($_POST[
'type'] == 3?1:$_POST[
'cond_reglement_id']);
1117 $object->mode_reglement_id = $_POST[
'mode_reglement_id'];
1118 $object->fk_account =
GETPOST(
'fk_account',
'int');
1119 $object->amount = $_POST[
'amount'];
1120 $object->remise_absolue = $_POST[
'remise_absolue'];
1121 $object->remise_percent = $_POST[
'remise_percent'];
1122 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1123 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1124 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1125 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1129 $object->fac_rec =
GETPOST(
'fac_rec',
'int');
1131 $id = $object->create($user);
1138 if (
GETPOST(
'socid',
'int') < 1)
1141 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")), null,
'errors');
1144 $dateinvoice =
dol_mktime(12, 0, 0, $_POST[
'remonth'], $_POST[
'reday'], $_POST[
'reyear']);
1145 if (empty($dateinvoice))
1148 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")), null,
'errors');
1151 $date_pointoftax =
dol_mktime(12, 0, 0, $_POST[
'date_pointoftaxmonth'], $_POST[
'date_pointoftaxday'], $_POST[
'date_pointoftaxyear']);
1156 $object->socid =
GETPOST(
'socid',
'int');
1157 $object->type =
GETPOST(
'type');
1158 $object->number = $_POST[
'facnumber'];
1159 $object->date = $dateinvoice;
1160 $object->date_pointoftax = $date_pointoftax;
1161 $object->note_public = trim(
GETPOST(
'note_public',
'none'));
1162 $object->note_private = trim(
GETPOST(
'note_private',
'none'));
1163 $object->ref_client = $_POST[
'ref_client'];
1164 $object->ref_int = $_POST[
'ref_int'];
1165 $object->modelpdf = $_POST[
'model'];
1166 $object->fk_project = $_POST[
'projectid'];
1167 $object->cond_reglement_id = ($_POST[
'type'] == 3?1:$_POST[
'cond_reglement_id']);
1168 $object->mode_reglement_id = $_POST[
'mode_reglement_id'];
1169 $object->fk_account =
GETPOST(
'fk_account',
'int');
1170 $object->amount = $_POST[
'amount'];
1171 $object->remise_absolue = $_POST[
'remise_absolue'];
1172 $object->remise_percent = $_POST[
'remise_percent'];
1173 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1174 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1175 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1176 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1181 $object->situation_counter = 1;
1182 $object->situation_final = 0;
1183 $object->situation_cycle_ref = $object->newCycle();
1186 $object->fetch_thirdparty();
1189 if (! empty($origin) && ! empty($originid))
1192 $element = $subelement = $origin;
1193 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1194 $element = $regs [1];
1195 $subelement = $regs [2];
1199 if ($element ==
'order') {
1200 $element = $subelement =
'commande';
1202 if ($element ==
'propal') {
1203 $element =
'comm/propal';
1204 $subelement =
'propal';
1206 if ($element ==
'contract') {
1207 $element = $subelement =
'contrat';
1209 if ($element ==
'inter') {
1210 $element = $subelement =
'ficheinter';
1212 if ($element ==
'shipping') {
1213 $element = $subelement =
'expedition';
1216 $object->origin = $origin;
1217 $object->origin_id = $originid;
1220 $object->linked_objects[$object->origin] = $object->origin_id;
1222 if ($object->origin ==
'shipping')
1224 require_once DOL_DOCUMENT_ROOT .
'/expedition/class/expedition.class.php';
1226 $exp->fetch($object->origin_id);
1227 $exp->fetchObjectLinked();
1228 if (is_array($exp->linkedObjectsIds[
'commande']) && count($exp->linkedObjectsIds[
'commande']) > 0) {
1229 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value){
1230 $object->linked_objects[
'commande'] = $value;
1235 if (is_array($_POST[
'other_linked_objects']) && ! empty($_POST[
'other_linked_objects']))
1237 $object->linked_objects = array_merge($object->linked_objects, $_POST[
'other_linked_objects']);
1240 $id = $object->create($user);
1246 $classname = ucfirst($subelement);
1247 $srcobject =
new $classname($db);
1249 dol_syslog(
"Try to find source object origin=" . $object->origin .
" originid=" . $object->origin_id .
" to add lines or deposit lines");
1250 $result = $srcobject->fetch($object->origin_id);
1255 $typeamount =
GETPOST(
'typedeposit',
'alpha');
1256 $valuedeposit =
GETPOST(
'valuedeposit',
'int');
1258 $amountdeposit = array();
1259 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA))
1261 if ($typeamount ==
'amount') $amount = $valuedeposit;
1262 else $amount = $srcobject->total_ttc * ($valuedeposit / 100);
1264 $TTotalByTva = array();
1265 foreach ($srcobject->lines as &$line)
1267 if(! empty($line->special_code))
continue;
1268 $TTotalByTva[$line->tva_tx] += $line->total_ttc ;
1271 $amount_to_diff = 0;
1272 foreach ($TTotalByTva as $tva => &$total)
1274 $coef = $total / $srcobject->total_ttc;
1275 $am = $amount * $coef;
1276 $amount_ttc_diff += $am;
1277 $amountdeposit[$tva] += $am / (1 + $tva / 100);
1282 if ($typeamount ==
'amount')
1284 $amountdeposit[0] = $valuedeposit;
1291 $lines = $srcobject->lines;
1292 $numlines=count($lines);
1293 for ($i=0; $i<$numlines; $i++)
1296 if (empty($lines[$i]->qty)) $qualified=0;
1297 if (! empty($lines[$i]->special_code)) $qualified=0;
1298 if ($qualified) $totalamount += $lines[$i]->total_ht;
1301 if ($totalamount != 0) {
1302 if ($numlines > 0) $numlines = $numlines-1;
1303 $tva_tx = $lines[$numlines]->tva_tx;
1304 if (! empty($lines[$numlines]->vat_src_code) && ! preg_match(
'/\(/', $tva_tx)) $tva_tx .=
' ('.$lines[$numlines]->vat_src_code.
')';
1305 $amountdeposit[$tva_tx] = ($totalamount * $valuedeposit) / 100;
1307 $amountdeposit[0] = 0;
1315 $amount_ttc_diff = $amountdeposit[0];
1318 foreach ($amountdeposit as $tva => $amount)
1320 $arraylist = array(
'amount' =>
'FixAmount',
'variable' =>
'VarAmount');
1321 $descline = $langs->trans(
'Deposit');
1323 if ($typeamount==
'amount') {
1324 $descline.=
' ('.
price($valuedeposit,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
')';
1325 } elseif ($typeamount==
'variable') {
1326 $descline.=
' ('. $valuedeposit.
'%)';
1328 $descline.=
' - '.$srcobject->ref;
1329 $result = $object->addline(
1336 (empty($conf->global->INVOICE_PRODUCTID_DEPOSIT)?0:$conf->global->INVOICE_PRODUCTID_DEPOSIT),
1341 $lines[$i]->info_bits,
1347 $lines[$i]->special_code,
1357 $diff = $object->total_ttc - $amount_ttc_diff;
1359 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0)
1361 $object->fetch_lines();
1362 $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100);
1363 $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);
1370 $lines = $srcobject->lines;
1371 if (empty($lines) && method_exists($srcobject,
'fetch_lines'))
1373 $srcobject->fetch_lines();
1374 $lines = $srcobject->lines;
1379 for ($i=0;$i<$num;$i++)
1382 if($srcobject->element ==
'shipping' && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS && $lines[$i]->qty == 0)
continue;
1384 if($srcobject->element ==
'contrat' && $lines[$i]->statut == 5)
continue;
1386 $label=(! empty($lines[$i]->
label)?$lines[$i]->label:
'');
1387 $desc=(! empty($lines[$i]->desc)?$lines[$i]->desc:$lines[$i]->libelle);
1388 if ($object->situation_counter == 1) $lines[$i]->situation_percent = 0;
1390 if ($lines[$i]->subprice < 0)
1394 $discount->fk_soc = $object->socid;
1395 $discount->amount_ht = abs($lines[$i]->total_ht);
1396 $discount->amount_tva = abs($lines[$i]->total_tva);
1397 $discount->amount_ttc = abs($lines[$i]->total_ttc);
1398 $discount->tva_tx = $lines[$i]->tva_tx;
1399 $discount->fk_user = $user->id;
1400 $discount->description = $desc;
1401 $discountid = $discount->create($user);
1402 if ($discountid > 0) {
1403 $result = $object->insert_discount($discountid);
1411 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1414 $date_start =
false;
1415 if ($lines[$i]->date_debut_prevue)
1416 $date_start = $lines[$i]->date_debut_prevue;
1417 if ($lines[$i]->date_debut_reel)
1418 $date_start = $lines[$i]->date_debut_reel;
1419 if ($lines[$i]->date_start)
1420 $date_start = $lines[$i]->date_start;
1424 if ($lines[$i]->date_fin_prevue)
1425 $date_end = $lines[$i]->date_fin_prevue;
1426 if ($lines[$i]->date_fin_reel)
1427 $date_end = $lines[$i]->date_fin_reel;
1428 if ($lines[$i]->date_end)
1429 $date_end = $lines[$i]->date_end;
1432 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1433 $fk_parent_line = 0;
1437 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines[$i],
'fetch_optionals')) {
1438 $lines[$i]->fetch_optionals($lines[$i]->rowid);
1439 $array_options = $lines[$i]->array_options;
1442 $tva_tx = $lines[$i]->tva_tx;
1443 if (! empty($lines[$i]->vat_src_code) && ! preg_match(
'/\(/', $tva_tx)) $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
1447 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty);
1448 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty);
1450 $result = $object->addline(
1451 $desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $localtax1_tx, $localtax2_tx, $lines[$i]->fk_product,
1452 $lines[$i]->remise_percent, $date_start, $date_end, 0, $lines[$i]->info_bits, $lines[$i]->fk_remise_except,
1453 'HT', 0, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $object->origin, $lines[$i]->rowid,
1454 $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_options,
1455 $lines[$i]->situation_percent, $lines[$i]->fk_prev_id, $lines[$i]->fk_unit
1467 if ($result > 0 && $lines[$i]->product_type == 9) {
1468 $fk_parent_line = $result;
1506 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
1520 $id = $object->create($user);
1522 for ($i = 1; $i <= $NBLINES; $i ++) {
1523 if ($_POST[
'idprod' . $i]) {
1525 $product->fetch($_POST[
'idprod' . $i]);
1526 $startday =
dol_mktime(12, 0, 0, $_POST[
'date_start' . $i .
'month'], $_POST[
'date_start' . $i .
'day'], $_POST[
'date_start' . $i .
'year']);
1527 $endday =
dol_mktime(12, 0, 0, $_POST[
'date_end' . $i .
'month'], $_POST[
'date_end' . $i .
'day'], $_POST[
'date_end' . $i .
'year']);
1528 $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);
1538 $datefacture =
dol_mktime(12, 0, 0, $_POST[
'remonth'], $_POST[
'reday'], $_POST[
'reyear']);
1539 if (empty($datefacture)) {
1541 $mesg =
'<div class="error">' . $langs->trans(
"ErrorFieldRequired", $langs->trans(
"Date")) .
'</div>';
1544 $date_pointoftax =
dol_mktime(12, 0, 0, $_POST[
'date_pointoftaxmonth'], $_POST[
'date_pointoftaxday'], $_POST[
'date_pointoftaxyear']);
1546 if (!($_POST[
'situations'] > 0)) {
1548 $mesg =
'<div class="error">' . $langs->trans(
"ErrorFieldRequired", $langs->trans(
"InvoiceSituation")) .
'</div>';
1552 $result = $object->fetch($_POST[
'situations']);
1553 $object->fk_facture_source = $_POST[
'situations'];
1556 if (!empty($origin) && !empty($originid))
1558 $object->origin = $origin;
1559 $object->origin_id = $originid;
1561 foreach ($object->lines as $i => &$line)
1563 $line->origin = $object->origin;
1564 $line->origin_id = $line->id;
1565 $line->fk_prev_id = $line->id;
1566 $line->fetch_optionals($line->id);
1567 $line->situation_percent = $line->get_prev_progress($object->id);
1570 if ($line->fk_remise_except)
1573 $result=$discount->fetch($line->fk_remise_except);
1577 if ($discount->fk_facture_line > 0)
1579 $line->fk_remise_except = 0;
1586 $object->fetch_thirdparty();
1587 $object->date = $datefacture;
1588 $object->date_pointoftax = $date_pointoftax;
1589 $object->note_public = trim(
GETPOST(
'note_public',
'none'));
1590 $object->note = trim(
GETPOST(
'note',
'none'));
1591 $object->ref_client =
GETPOST(
'ref_client',
'alpha');
1592 $object->ref_int =
GETPOST(
'ref_int',
'alpha');
1593 $object->modelpdf =
GETPOST(
'model',
'alpha');
1594 $object->fk_project =
GETPOST(
'projectid',
'int');
1595 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1596 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1597 $object->remise_absolue =
GETPOST(
'remise_absolue',
'int');
1598 $object->remise_percent =
GETPOST(
'remise_percent',
'int');
1602 $object->situation_counter = $object->situation_counter + 1;
1603 $id = $object->createFromCurrent($user);
1606 $mesg = $object->error;
1610 $nextSituationInvoice =
new Facture($db);
1611 $nextSituationInvoice->fetch($id);
1613 $extralabels = $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element);
1614 $ret = $extrafields->setOptionalsFromPost($extralabels, $nextSituationInvoice);
1616 $nextSituationInvoice->insertExtraFields();
1623 if ($id > 0 && ! $error)
1628 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && count($object->lines))
1630 $outputlangs = $langs;
1632 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
1633 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
1634 if (! empty($newlang)) {
1635 $outputlangs =
new Translate(
"", $conf);
1636 $outputlangs->setDefaultLang($newlang);
1637 $outputlangs->load(
'products');
1639 $model=$object->modelpdf;
1640 $ret = $object->fetch($id);
1642 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1643 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
1646 header(
'Location: ' . $_SERVER[
"PHP_SELF"] .
'?facid=' . $id);
1653 $_GET[
"origin"] = $_POST[
"origin"];
1654 $_GET[
"originid"] = $_POST[
"originid"];
1660 else if ($action ==
'addline' && $usercancreate)
1662 $langs->load(
'errors');
1667 $product_desc=(
GETPOST(
'dp_desc',
'none')?
GETPOST(
'dp_desc',
'none'):
'');
1668 $price_ht =
GETPOST(
'price_ht');
1669 $price_ht_devise =
GETPOST(
'multicurrency_price_ht');
1670 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'alpha');
1671 if ($prod_entry_mode ==
'free')
1674 $tva_tx = (
GETPOST(
'tva_tx',
'alpha') ?
GETPOST(
'tva_tx',
'alpha') : 0);
1678 $idprod=
GETPOST(
'idprod',
'int');
1682 $qty =
GETPOST(
'qty' . $predef);
1683 $remise_percent =
GETPOST(
'remise_percent' . $predef);
1687 $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
1688 $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
1690 if (is_array($extralabelsline)) {
1692 foreach ($extralabelsline as $key => $value) {
1693 unset($_POST[
"options_" . $key . $predef]);
1697 if (empty($idprod) && ($price_ht < 0) && ($qty < 0)) {
1698 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
1701 if (!$prod_entry_mode)
1705 setEventMessages($langs->trans(
'ErrorChooseBetweenFreeEntryOrPredefinedProduct'), null,
'errors');
1709 if ($prod_entry_mode ==
'free' && empty($idprod) &&
GETPOST(
'type') < 0) {
1710 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')), null,
'errors');
1713 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)
1715 if ($price_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES))
1717 $langs->load(
"errors");
1718 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT")), null,
'errors');
1723 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")), null,
'errors');
1728 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
1731 if ($prod_entry_mode ==
'free' && empty($idprod) && empty($product_desc)) {
1732 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')), null,
'errors');
1736 $langs->load(
"errors");
1737 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'), null,
'errors');
1741 if (!$error && !empty($conf->variants->enabled) && $prod_entry_mode !=
'free') {
1742 if ($combinations =
GETPOST(
'combinations',
'array')) {
1746 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1747 $idprod = $res->fk_product_child;
1751 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'), null,
'errors');
1757 if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod))) {
1759 $ret = $object->fetch($id);
1764 $ret = $object->fetch_thirdparty();
1767 $date_start =
dol_mktime(
GETPOST(
'date_start' . $predef .
'hour'),
GETPOST(
'date_start' . $predef .
'min'),
GETPOST(
'date_start' . $predef .
'sec'),
GETPOST(
'date_start' . $predef .
'month'),
GETPOST(
'date_start' . $predef .
'day'),
GETPOST(
'date_start' . $predef .
'year'));
1768 $date_end =
dol_mktime(
GETPOST(
'date_end' . $predef .
'hour'),
GETPOST(
'date_end' . $predef .
'min'),
GETPOST(
'date_end' . $predef .
'sec'),
GETPOST(
'date_end' . $predef .
'month'),
GETPOST(
'date_end' . $predef .
'day'),
GETPOST(
'date_end' . $predef .
'year'));
1769 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
1780 if (! empty($idprod))
1783 $prod->fetch($idprod);
1785 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
1790 if (empty($tva_tx)) $tva_npr=0;
1792 $pu_ht = $prod->price;
1793 $pu_ttc = $prod->price_ttc;
1794 $price_min = $prod->price_min;
1795 $price_base_type = $prod->price_base_type;
1798 if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level))
1800 $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
1801 $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
1802 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
1803 $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
1804 if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL))
1806 if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) $tva_tx=$prod->multiprices_tva_tx[$object->thirdparty->price_level];
1807 if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) $tva_npr=$prod->multiprices_recuperableonly[$object->thirdparty->price_level];
1808 if (empty($tva_tx)) $tva_npr=0;
1812 elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
1814 require_once DOL_DOCUMENT_ROOT .
'/product/class/productcustomerprice.class.php';
1818 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
1820 $result = $prodcustprice->fetch_all(
'',
'', 0, 0, $filter);
1822 if (count($prodcustprice->lines) > 0) {
1823 $pu_ht =
price($prodcustprice->lines[0]->price);
1824 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
1825 $price_base_type = $prodcustprice->lines[0]->price_base_type;
1826 $tva_tx = $prodcustprice->lines[0]->tva_tx;
1827 if ($prodcustprice->lines[0]->default_vat_code && ! preg_match(
'/\(.*\)/', $tva_tx)) $tva_tx.=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
1828 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
1829 if (empty($tva_tx)) $tva_npr=0;
1834 elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))
1836 if ($prod->prices_by_qty[0])
1842 foreach($prod->prices_by_qty_list[0] as $priceforthequantityarray)
1844 if ($priceforthequantityarray[
'rowid'] != $pqp)
continue;
1846 if ($priceforthequantityarray[
'price_base_type'] ==
'HT')
1848 $pu_ht = $priceforthequantityarray[
'unitprice'];
1852 $pu_ttc = $priceforthequantityarray[
'unitprice'];
1860 elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))
1862 if ($prod->prices_by_qty[$object->thirdparty->price_level])
1868 foreach($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray)
1870 if ($priceforthequantityarray[
'rowid'] != $pqp)
continue;
1872 if ($priceforthequantityarray[
'price_base_type'] ==
'HT')
1874 $pu_ht = $priceforthequantityarray[
'unitprice'];
1878 $pu_ttc = $priceforthequantityarray[
'unitprice'];
1886 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
1887 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
1890 if (! empty($price_ht))
1893 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
1897 elseif ($tmpvat != $tmpprodvat)
1899 if ($price_base_type !=
'HT')
1901 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
1905 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
1912 if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1913 $outputlangs = $langs;
1915 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09'))
1916 $newlang =
GETPOST(
'lang_id',
'aZ09');
1917 if (empty($newlang))
1918 $newlang = $object->thirdparty->default_lang;
1919 if (! empty($newlang)) {
1920 $outputlangs =
new Translate(
"", $conf);
1921 $outputlangs->setDefaultLang($newlang);
1922 $outputlangs->load(
'products');
1925 $desc = (! empty($prod->multilangs [$outputlangs->defaultlang] [
"description"])) ? $prod->multilangs [$outputlangs->defaultlang] [
"description"] : $prod->description;
1927 $desc = $prod->description;
1933 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) {
1936 if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1937 $outputlangs = $langs;
1939 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha'))
1940 $newlang =
GETPOST(
'lang_id',
'alpha');
1941 if (empty($newlang))
1942 $newlang = $object->thirdparty->default_lang;
1943 if (! empty($newlang)) {
1944 $outputlangs =
new Translate(
"", $conf);
1945 $outputlangs->setDefaultLang($newlang);
1946 $outputlangs->load(
'products');
1948 if (! empty($prod->customcode))
1949 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode") .
': ' . $prod->customcode;
1950 if (! empty($prod->customcode) && ! empty($prod->country_code))
1952 if (! empty($prod->country_code))
1953 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin") .
': ' .
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
1955 if (! empty($prod->customcode))
1956 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode") .
': ' . $prod->customcode;
1957 if (! empty($prod->customcode) && ! empty($prod->country_code))
1959 if (! empty($prod->country_code))
1960 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin") .
': ' .
getCountry($prod->country_code, 0, $db, $langs, 0);
1966 $type = $prod->type;
1967 $fk_unit = $prod->fk_unit;
1971 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1972 $tva_tx = str_replace(
'*',
'', $tva_tx);
1973 if (empty($tva_tx)) $tva_npr=0;
1974 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1975 $desc = $product_desc;
1977 $fk_unit=
GETPOST(
'units',
'alpha');
1978 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
1986 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
1987 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
1993 if ($usercanproductignorepricemin && (! empty($price_min) && (
price2num($pu_ht) * (1 -
price2num($remise_percent) / 100) <
price2num($price_min)))) {
1994 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
1998 $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);
2003 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
2005 $outputlangs = $langs;
2007 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
2008 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
2009 if (! empty($newlang)) {
2010 $outputlangs =
new Translate(
"", $conf);
2011 $outputlangs->setDefaultLang($newlang);
2012 $outputlangs->load(
'products');
2014 $model=$object->modelpdf;
2015 $ret = $object->fetch($id);
2017 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
2018 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
2021 unset($_POST[
'prod_entry_mode']);
2023 unset($_POST[
'qty']);
2024 unset($_POST[
'type']);
2025 unset($_POST[
'remise_percent']);
2026 unset($_POST[
'price_ht']);
2027 unset($_POST[
'multicurrency_price_ht']);
2028 unset($_POST[
'price_ttc']);
2029 unset($_POST[
'tva_tx']);
2030 unset($_POST[
'product_ref']);
2031 unset($_POST[
'product_label']);
2032 unset($_POST[
'product_desc']);
2033 unset($_POST[
'fournprice']);
2034 unset($_POST[
'buying_price']);
2035 unset($_POST[
'np_marginRate']);
2036 unset($_POST[
'np_markRate']);
2037 unset($_POST[
'dp_desc']);
2038 unset($_POST[
'idprod']);
2039 unset($_POST[
'units']);
2041 unset($_POST[
'date_starthour']);
2042 unset($_POST[
'date_startmin']);
2043 unset($_POST[
'date_startsec']);
2044 unset($_POST[
'date_startday']);
2045 unset($_POST[
'date_startmonth']);
2046 unset($_POST[
'date_startyear']);
2047 unset($_POST[
'date_endhour']);
2048 unset($_POST[
'date_endmin']);
2049 unset($_POST[
'date_endsec']);
2050 unset($_POST[
'date_endday']);
2051 unset($_POST[
'date_endmonth']);
2052 unset($_POST[
'date_endyear']);
2054 unset($_POST[
'situations']);
2055 unset($_POST[
'progress']);
2065 elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha'))
2068 $object->fetch_thirdparty();
2079 $pu_ht_devise =
GETPOST(
'multicurrency_subprice');
2083 if (preg_match(
'/\*/', $vat_rate)) $info_bits |= 0x01;
2086 $vat_rate = str_replace(
'*',
'', $vat_rate);
2087 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty);
2088 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty);
2096 $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
2097 $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
2099 if (is_array($extralabelsline)) {
2101 foreach ($extralabelsline as $key => $value) {
2102 unset($_POST[
"options_" . $key]);
2107 $special_code=
GETPOST(
'special_code');
2108 if (!
GETPOST(
'qty')) $special_code=3;
2111 $line->fetch(
GETPOST(
'lineid'));
2112 $percent = $line->get_prev_progress($object->id);
2119 $mesg = $langs->trans(
"CantBeNullOrPositive");
2124 elseif (
GETPOST(
'progress') < $line->situation_percent)
2126 $mesg = $langs->trans(
"CantBeLessThanMinPercent");
2132 elseif (
GETPOST(
'progress') < $percent)
2134 $mesg =
'<div class="warning">' . $langs->trans(
"CantBeLessThanMinPercent") .
'</div>';
2141 $productid =
GETPOST(
'productid',
'int');
2142 if (! empty($productid))
2145 $product->fetch($productid);
2147 $type = $product->type;
2149 $price_min = $product->price_min;
2150 if ((! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && ! empty($object->thirdparty->price_level))
2151 $price_min = $product->multiprices_min [$object->thirdparty->price_level];
2157 setEventMessages($langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null,
'errors');
2162 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
2166 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")), null,
'errors');
2171 $langs->load(
"errors");
2172 setEventMessages($langs->trans(
'ErrorQtyForCustomerInvoiceCantBeNegative'), null,
'errors');
2175 if ((empty($productid) && (($pu_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) || $pu_ht ==
'') && $pu_ht_devise ==
'') && $object->type !=
Facture::TYPE_CREDIT_NOTE)
2177 if ($pu_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES))
2179 $langs->load(
"errors");
2180 setEventMessages($langs->trans(
"ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv(
"UnitPriceHT")), null,
'errors');
2185 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")), null,
'errors');
2193 if (empty($usercancreatemargin))
2195 foreach ($object->lines as &$line)
2197 if ($line->id ==
GETPOST(
'lineid'))
2199 $fournprice = $line->fk_fournprice;
2200 $buyingprice = $line->pa_ht;
2206 $result = $object->updateline(
GETPOST(
'lineid'), $description, $pu_ht, $qty,
GETPOST(
'remise_percent'),
2207 $date_start, $date_end, $vat_rate, $localtax1_rate, $localtax2_rate,
'HT', $info_bits, $type,
2208 GETPOST(
'fk_parent_line'), 0, $fournprice, $buyingprice, $label, $special_code, $array_options,
GETPOST(
'progress'),
2209 $_POST[
'units'],$pu_ht_devise);
2212 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
2214 $outputlangs = $langs;
2216 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09'))
2217 $newlang =
GETPOST(
'lang_id',
'aZ09');
2218 if ($conf->global->MAIN_MULTILANGS && empty($newlang))
2219 $newlang = $object->thirdparty->default_lang;
2220 if (! empty($newlang)) {
2221 $outputlangs =
new Translate(
"", $conf);
2222 $outputlangs->setDefaultLang($newlang);
2223 $outputlangs->load(
'products');
2226 $ret = $object->fetch($id);
2227 $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
2230 unset($_POST[
'qty']);
2231 unset($_POST[
'type']);
2232 unset($_POST[
'productid']);
2233 unset($_POST[
'remise_percent']);
2234 unset($_POST[
'price_ht']);
2235 unset($_POST[
'multicurrency_price_ht']);
2236 unset($_POST[
'price_ttc']);
2237 unset($_POST[
'tva_tx']);
2238 unset($_POST[
'product_ref']);
2239 unset($_POST[
'product_label']);
2240 unset($_POST[
'product_desc']);
2241 unset($_POST[
'fournprice']);
2242 unset($_POST[
'buying_price']);
2243 unset($_POST[
'np_marginRate']);
2244 unset($_POST[
'np_markRate']);
2246 unset($_POST[
'dp_desc']);
2247 unset($_POST[
'idprod']);
2248 unset($_POST[
'units']);
2250 unset($_POST[
'date_starthour']);
2251 unset($_POST[
'date_startmin']);
2252 unset($_POST[
'date_startsec']);
2253 unset($_POST[
'date_startday']);
2254 unset($_POST[
'date_startmonth']);
2255 unset($_POST[
'date_startyear']);
2256 unset($_POST[
'date_endhour']);
2257 unset($_POST[
'date_endmin']);
2258 unset($_POST[
'date_endsec']);
2259 unset($_POST[
'date_endday']);
2260 unset($_POST[
'date_endmonth']);
2261 unset($_POST[
'date_endyear']);
2263 unset($_POST[
'situations']);
2264 unset($_POST[
'progress']);
2271 else if ($action ==
'updatealllines' && $usercancreate && $_POST[
'all_percent'] == $langs->trans(
'Modifier'))
2274 if (!is_null(
GETPOST(
'all_progress')) &&
GETPOST(
'all_progress') !=
"")
2276 foreach ($object->lines as $line)
2278 $percent = $line->get_prev_progress($object->id);
2279 if (
GETPOST(
'all_progress') < $percent) {
2280 $mesg =
'<div class="warning">' . $langs->trans(
"CantBeLessThanMinPercent") .
'</div>';
2283 $object->update_percent($line, $_POST[
'all_progress']);
2288 else if ($action ==
'updateline' && $usercancreate && $_POST[
'cancel'] == $langs->trans(
'Cancel')) {
2289 header(
'Location: ' . $_SERVER[
"PHP_SELF"] .
'?facid=' . $id);
2294 elseif ($action ==
'confirm_situationout' && $confirm ==
'yes' && $usercancreate)
2296 $object->fetch($id,
'',
'',
'',
true);
2302 && $object->is_last_in_cycle()
2303 && $usercanunvalidate
2307 $newCycle = $object->newCycle();
2311 $lastCycle = $object->situation_cycle_ref;
2312 $lastSituationCounter = $object->situation_counter;
2313 $linkedCreditNotesList = array();
2315 if (count($object->tab_next_situation_invoice) > 0) {
2316 foreach ($object->tab_next_situation_invoice as $next_invoice) {
2318 && $next_invoice->situation_counter == $object->situation_counter
2319 && $next_invoice->fk_facture_source == $object->id
2322 $linkedCreditNotesList[] = $next_invoice->id ;
2327 $object->situation_cycle_ref = $newCycle;
2328 $object->situation_counter = 1;
2329 $object->situation_final = 0;
2330 if($object->update($user) > 0)
2333 if(count($linkedCreditNotesList) > 0)
2336 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facture ';
2337 $sql.=
' SET situation_cycle_ref='.$newCycle;
2338 $sql.=
' , situation_final=0';
2339 $sql.=
' , situation_counter='.$object->situation_counter;
2340 $sql.=
' WHERE rowid IN ('.implode(
',',$linkedCreditNotesList).
')';
2346 foreach($object->lines as $line)
2350 if ($line->product_type == 9 )
continue;
2353 if(!empty($object->tab_previous_situation_invoice))
2356 $lineIndex = count($object->tab_previous_situation_invoice) - 1;
2357 $searchPreviousInvoice =
true;
2358 while( $searchPreviousInvoice )
2362 $searchPreviousInvoice=
false;
2372 $maxPrevSituationPercent = 0;
2373 foreach($object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine)
2375 if($prevLine->id == $line->fk_prev_id)
2377 $maxPrevSituationPercent = max($maxPrevSituationPercent,$prevLine->situation_percent);
2382 $line->situation_percent = $line->situation_percent - $maxPrevSituationPercent;
2384 if($line->update()<0) $errors++;
2392 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
2396 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceCreditNote'), array(),
'errors');
2401 setEventMessages($langs->trans(
'ErrorOutingSituationInvoiceOnUpdate'), array(),
'errors');
2406 setEventMessages($langs->trans(
'ErrorFindNextSituationInvoice'), array(),
'errors');
2412 elseif($action ==
'import_lines_from_object' 2417 $fromElement =
GETPOST(
'fromelement');
2418 $fromElementid =
GETPOST(
'fromelementid');
2419 $importLines =
GETPOST(
'line_checkbox');
2421 if(!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid))
2423 if($fromElement ==
'commande')
2426 $lineClassName =
'OrderLine';
2428 elseif($fromElement ==
'propal')
2430 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
2431 $lineClassName =
'PropaleLigne';
2433 $nextRang = count($object->lines) + 1;
2436 foreach($importLines as $lineId)
2438 $lineId = intval($lineId);
2439 $originLine =
new $lineClassName($db);
2440 if(intval($fromElementid) > 0 && $originLine->fetch( $lineId ) > 0)
2442 $originLine->fetch_optionals($lineId);
2443 $desc = $originLine->desc;
2444 $pu_ht = $originLine->subprice;
2445 $qty = $originLine->qty;
2446 $txtva = $originLine->tva_tx;
2447 $txlocaltax1 = $originLine->localtax1_tx;
2448 $txlocaltax2 = $originLine->localtax2_tx;
2449 $fk_product = $originLine->fk_product;
2450 $remise_percent = $originLine->remise_percent;
2451 $date_start = $originLine->date_start;
2452 $date_end = $originLine->date_end;
2454 $info_bits = $originLine->info_bits;
2455 $fk_remise_except = $originLine->fk_remise_except;
2456 $price_base_type=
'HT';
2458 $type = $originLine->product_type;
2460 $special_code = $originLine->special_code;
2461 $origin = $originLine->element;
2462 $origin_id = $originLine->id;
2464 $fk_fournprice=$originLine->fk_fournprice;
2465 $pa_ht = $originLine->pa_ht;
2466 $label = $originLine->label;
2467 $array_options = $originLine->array_options;
2468 $situation_percent = 100;
2470 $fk_unit = $originLine->fk_unit;
2471 $pu_ht_devise = $originLine->multicurrency_subprice;
2473 $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);
2494 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
2497 if (empty($id)) $id=$facid;
2498 $trigger_name=
'BILL_SENTBYMAIL';
2500 $autocopy=
'MAIN_MAIL_AUTOCOPY_INVOICE_TO';
2501 $trackid=
'inv'.$object->id;
2502 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
2505 $upload_dir = $conf->facture->dir_output;
2506 $permissioncreate=$usercancreate;
2507 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
2510 if ($action ==
'update_extras') {
2514 $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
2515 $ret = $extrafields->setOptionalsFromPost($extralabels, $object,
GETPOST(
'attribute',
'none'));
2516 if ($ret < 0) $error++;
2521 $result = $object->insertExtraFields(
'BILL_MODIFY');
2530 $action =
'edit_extras';
2533 if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
2534 if ($action ==
'addcontact') {
2535 $result = $object->fetch($id);
2537 if ($result > 0 && $id > 0) {
2539 $result = $object->add_contact($contactid, $_POST[
"type"], $_POST[
"source"]);
2543 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2546 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2547 $langs->load(
"errors");
2548 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"), null,
'errors');
2554 elseif ($action ==
'swapstatut') {
2555 if ($object->fetch($id)) {
2556 $result = $object->swapContactStatus(
GETPOST(
'ligne'));
2561 elseif ($action ==
'deletecontact') {
2562 $object->fetch($id);
2563 $result = $object->delete_contact($lineid);
2566 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
2574 $action =
'edit_extras';
2588 $bankaccountstatic =
new Account($db);
2589 if (! empty($conf->projet->enabled)) { $formproject =
new FormProjets($db); }
2593 $title = $langs->trans(
'InvoiceCustomer') .
" - " . $langs->trans(
'Card');
2594 $helpurl =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
2600 if ($action ==
'create')
2602 $facturestatic =
new Facture($db);
2603 $extralabels = $extrafields->fetch_name_optionals_label($facturestatic->table_element);
2609 $res = $soc->fetch($socid);
2611 $currency_code = $conf->currency;
2614 $remise_absolue = 0;
2616 if (! empty($origin) && ! empty($originid))
2619 $element = $subelement = $origin;
2620 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
2621 $element = $regs [1];
2622 $subelement = $regs [2];
2625 if ($element ==
'project') {
2626 $projectid = $originid;
2628 if (!$cond_reglement_id) {
2629 $cond_reglement_id = $soc->cond_reglement_id;
2631 if (!$mode_reglement_id) {
2632 $mode_reglement_id = $soc->mode_reglement_id;
2634 if (!$remise_percent) {
2635 $remise_percent = $soc->remise_percent;
2637 if (!$dateinvoice) {
2639 $dateinvoice = (empty($dateinvoice)?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:
''):$dateinvoice);
2643 if ($element ==
'order' || $element ==
'commande') {
2644 $element = $subelement =
'commande';
2646 if ($element ==
'propal') {
2647 $element =
'comm/propal';
2648 $subelement =
'propal';
2650 if ($element ==
'contract') {
2651 $element = $subelement =
'contrat';
2653 if ($element ==
'shipping') {
2654 $element = $subelement =
'expedition';
2659 $classname = ucfirst($subelement);
2660 $objectsrc =
new $classname($db);
2661 $objectsrc->fetch($originid);
2662 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines'))
2663 $objectsrc->fetch_lines();
2664 $objectsrc->fetch_thirdparty();
2666 $projectid = (! empty($projectid) ? $projectid : $objectsrc->fk_project);
2667 $ref_client = (! empty($objectsrc->ref_client) ? $objectsrc->ref_client : (! empty($objectsrc->ref_customer) ? $objectsrc->ref_customer:
''));
2668 $ref_int = (! empty($objectsrc->ref_int) ? $objectsrc->ref_int :
'');
2672 $soc = $objectsrc->thirdparty;
2674 $cond_reglement_id = (! empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(! empty($soc->cond_reglement_id)?$soc->cond_reglement_id:0));
2675 $mode_reglement_id = (! empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(! empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
2676 $fk_account = (! empty($objectsrc->fk_account)?$objectsrc->fk_account:(! empty($soc->fk_account)?$soc->fk_account:0));
2677 $remise_percent = (! empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(! empty($soc->remise_percent)?$soc->remise_percent:0));
2678 $remise_absolue = (! empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(! empty($soc->remise_absolue)?$soc->remise_absolue:0));
2679 $dateinvoice = (empty($dateinvoice)?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:
''):$dateinvoice);
2681 if (!empty($conf->multicurrency->enabled))
2683 if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code;
2684 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $currency_tx = $objectsrc->multicurrency_tx;
2688 $objectsrc->fetch_optionals($originid);
2689 $object->array_options = $objectsrc->array_options;
2694 $cond_reglement_id = $soc->cond_reglement_id;
2695 $mode_reglement_id = $soc->mode_reglement_id;
2696 $fk_account = $soc->fk_account;
2697 $remise_percent = $soc->remise_percent;
2698 $remise_absolue = 0;
2699 $dateinvoice = (empty($dateinvoice)?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:
''):$dateinvoice);
2701 if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) $currency_code = $soc->multicurrency_code;
2704 if (!empty($soc->id)) $absolute_discount = $soc->getAvailableDiscounts();
2705 $note_public = $object->getDefaultCreateValueFor(
'note_public', (is_object($objectsrc)?$objectsrc->note_public:null));
2706 $note_private = $object->getDefaultCreateValueFor(
'note_private', ((! empty($origin) && ! empty($originid) && is_object($objectsrc))?$objectsrc->note_private:null));
2708 if (! empty($conf->use_javascript_ajax))
2710 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
2716 if ($origin ==
'contrat')
2718 $langs->load(
"admin");
2719 $text=$langs->trans(
"ToCreateARecurringInvoice");
2720 $text.=
' '.$langs->trans(
"ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv(
"MenuFinancial"), $langs->transnoentitiesnoconv(
"BillsCustomers"), $langs->transnoentitiesnoconv(
"ListOfTemplates"));
2721 if (empty($conf->global->INVOICE_DISABLE_AUTOMATIC_RECURRING_INVOICE))
2723 $text.=
' '.$langs->trans(
"ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv(
'Module2300Name'));
2728 print '<form name="add" action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST">';
2729 print '<input type="hidden" name="token" value="' . $_SESSION [
'newtoken'] .
'">';
2730 print '<input type="hidden" name="action" value="add">';
2731 if ($soc->id > 0)
print '<input type="hidden" name="socid" value="' . $soc->id .
'">' .
"\n";
2732 print '<input name="facnumber" type="hidden" value="provisoire">';
2733 print '<input name="ref_client" type="hidden" value="' . $ref_client .
'">';
2734 print '<input name="ref_int" type="hidden" value="' . $ref_int .
'">';
2735 print '<input type="hidden" name="origin" value="' . $origin .
'">';
2736 print '<input type="hidden" name="originid" value="' . $originid .
'">';
2737 if (!empty($currency_tx))
print '<input type="hidden" name="originmulticurrency_tx" value="' . $currency_tx .
'">';
2741 print '<table class="border" width="100%">';
2744 print '<tr><td class="titlefieldcreate fieldrequired">' . $langs->trans(
'Ref') .
'</td><td colspan="2">' . $langs->trans(
'Draft') .
'</td></tr>';
2747 print '<td class="fieldrequired">' . $langs->trans(
'Customer') .
'</td>';
2748 if ($soc->id > 0 && !
GETPOST(
'fac_rec',
'alpha'))
2750 print '<td colspan="2">';
2751 print $soc->getNomUrl(1);
2752 print '<input type="hidden" name="socid" value="' . $soc->id .
'">';
2754 $outstandingBills = $soc->get_OutstandingBill();
2755 print ' (' . $langs->trans(
'CurrentOutstandingBill') .
': ';
2756 print price($outstandingBills,
'', $langs, 0, 0, -1, $conf->currency);
2757 if ($soc->outstanding_limit !=
'')
2759 if ($outstandingBills > $soc->outstanding_limit)
print img_warning($langs->trans(
"OutstandingBillReached"));
2760 print ' / ' .
price($soc->outstanding_limit,
'', $langs, 0, 0, -1, $conf->currency);
2767 print '<td colspan="2">';
2768 print $form->select_company($soc->id,
'socid',
'(s.client = 1 OR s.client = 3) AND status=1',
'SelectThirdParty', 0, 0, null, 0,
'minwidth300');
2770 if (!empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE))
2772 print '<script type="text/javascript"> 2773 $(document).ready(function() { 2774 $("#socid").change(function() { 2775 var socid = $(this).val(); 2776 var fac_rec = $(\'#fac_rec\').val(); 2778 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec; 2783 print ' <a href="'.DOL_URL_ROOT.
'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create').
'">'.$langs->trans(
"AddThirdParty").
'</a>';
2786 print '</tr>' .
"\n";
2791 if (empty($origin) && empty($originid) &&
GETPOST(
'fac_rec',
'int') > 0)
2794 $invoice_predefined->fetch(
GETPOST(
'fac_rec',
'int'));
2796 $dateinvoice = $invoice_predefined->date_when;
2797 if (empty($projectid)) $projectid = $invoice_predefined->fk_project;
2798 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2799 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2800 $fk_account = $invoice_predefined->fk_account;
2801 $note_public = $invoice_predefined->note_public;
2802 $note_private = $invoice_predefined->note_private;
2804 $sql =
'SELECT r.rowid, r.titre, r.total_ttc';
2805 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'facture_rec as r';
2806 $sql .=
' WHERE r.fk_soc = ' . $invoice_predefined->socid;
2808 $resql = $db->query($sql);
2811 $num = $db->num_rows(
$resql);
2816 print '<tr><td>' . $langs->trans(
'CreateFromRepeatableInvoice') .
'</td><td>';
2817 print '<select class="flat" id="fac_rec" name="fac_rec">';
2818 print '<option value="0" selected></option>';
2821 $objp = $db->fetch_object(
$resql);
2822 print '<option value="' . $objp->rowid .
'"';
2823 if (
GETPOST(
'fac_rec') == $objp->rowid)
2826 $exampletemplateinvoice->fetch(
GETPOST(
'fac_rec'));
2828 print '>' . $objp->titre .
' (' .
price($objp->total_ttc) .
' ' . $langs->trans(
"TTC") .
')</option>';
2833 if (!empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE))
2835 print '<script type="text/javascript"> 2836 $(document).ready(function() { 2837 $("#fac_rec").change(function() { 2838 var fac_rec = $(this).val(); 2839 var socid = $(\'#socid\').val(); 2841 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&fac_rec="+fac_rec; 2855 $facids = $facturestatic->list_replacable_invoices($soc->id);
2861 foreach ($facids as $facparam)
2863 $options .=
'<option value="' . $facparam [
'id'] .
'"';
2864 if ($facparam [
'id'] == $_POST[
'fac_replacement'])
2865 $options .=
' selected';
2866 $options .=
'>' . $facparam [
'ref'];
2867 $options .=
' (' . $facturestatic->LibStatut(0, $facparam [
'status']) .
')';
2868 $options .=
'</option>';
2872 $facids=$facturestatic->list_qualified_avoir_invoices($soc->id);
2879 $newinvoice_static =
new Facture($db);
2880 foreach ($facids as $key => $valarray)
2882 $newinvoice_static->id = $key;
2883 $newinvoice_static->ref = $valarray [
'ref'];
2884 $newinvoice_static->statut = $valarray [
'status'];
2885 $newinvoice_static->type = $valarray [
'type'];
2886 $newinvoice_static->paye = $valarray [
'paye'];
2888 $optionsav .=
'<option value="' . $key .
'"';
2889 if ($key ==
GETPOST(
'fac_avoir'))
2890 $optionsav .=
' selected';
2892 $optionsav .= $newinvoice_static->ref;
2893 $optionsav .=
' (' . $newinvoice_static->getLibStatut(1, $valarray [
'paymentornot']) .
')';
2894 $optionsav .=
'</option>';
2897 print '<tr><td class="tdtop fieldrequired">' . $langs->trans(
'Type') .
'</td><td colspan="2">';
2899 print '<div class="tagtable">' .
"\n";
2902 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2903 $tmp=
'<input type="radio" id="radio_standard" name="type" value="0"' . (
GETPOST(
'type') == 0 ?
' checked' :
'') .
'> ';
2904 $tmp = $tmp.
'<label for="radio_standard" >'.$langs->trans(
"InvoiceStandardAsk").
'</label>';
2905 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceStandardDesc"), 1,
'help',
'', 0, 3);
2907 print '</div></div>';
2909 if ((empty($origin)) || ((($origin ==
'propal') || ($origin ==
'commande')) && (! empty($originid))))
2912 if (empty($conf->global->INVOICE_DISABLE_DEPOSIT))
2914 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2915 $tmp=
'<input type="radio" id="radio_deposit" name="type" value="3"' . (
GETPOST(
'type') == 3 ?
' checked' :
'') .
'> ';
2916 print '<script type="text/javascript" language="javascript"> 2917 jQuery(document).ready(function() { 2918 jQuery("#typedeposit, #valuedeposit").click(function() { 2919 jQuery("#radio_deposit").prop("checked", true); 2924 $tmp = $tmp.
'<label for="radio_deposit" >'.$langs->trans(
"InvoiceDeposit").
'</label>';
2925 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceDepositDesc"), 1,
'help',
'', 0, 3);
2926 print '<table class="nobordernopadding"><tr><td>';
2929 if (($origin ==
'propal') || ($origin ==
'commande'))
2931 print '<td class="nowrap" style="padding-left: 5px">';
2932 $arraylist = array(
'amount' => $langs->transnoentitiesnoconv(
'FixAmount'),
'variable' => $langs->transnoentitiesnoconv(
'VarAmountOneLine', $langs->transnoentitiesnoconv(
'Deposit')));
2933 print $form->selectarray(
'typedeposit', $arraylist,
GETPOST(
'typedeposit'), 0, 0, 0,
'', 1);
2935 print '<td class="nowrap" style="padding-left: 5px">' . $langs->trans(
'Value') .
':<input type="text" id="valuedeposit" name="valuedeposit" size="3" value="' .
GETPOST(
'valuedeposit',
'int') .
'"/>';
2937 print '</td></tr></table>';
2939 print '</div></div>';
2945 if (! empty($conf->global->INVOICE_USE_SITUATION))
2948 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2949 $tmp=
'<input id="radio_situation invoice" type="radio" name="type" value="5"' . (
GETPOST(
'type') == 5 ?
' checked' :
'') .
'> ';
2950 $tmp = $tmp.
'<label for="radio_situation invoice" >'.$langs->trans(
"InvoiceFirstSituationAsk").
'</label>';
2951 $desc =
$form->textwithpicto($tmp, $langs->transnoentities(
"InvoiceFirstSituationDesc"), 1,
'help',
'', 0, 3);
2953 print '</div></div>';
2956 $opt =
$form->selectSituationInvoices(
GETPOST(
'originid'), $socid);
2957 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2958 $tmp=
'<input type="radio" name="type" value="5"' . (
GETPOST(
'type') == 5 &&
GETPOST(
'originid') ?
' checked' :
'');
2959 if ($opt == (
'<option value ="0" selected>' . $langs->trans(
'NoSituations') .
'</option>') || (
GETPOST(
'origin') &&
GETPOST(
'origin') !=
'facture' &&
GETPOST(
'origin') !=
'commande')) $tmp.=
' disabled';
2961 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceSituationAsk") .
'</label> ';
2962 $text .=
'<select class="flat" id="situations" name="situations">';
2964 $text .=
'</select>';
2965 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceSituationDesc"), 1,
'help',
'', 0, 3);
2967 print '</div></div>';
2971 if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT))
2973 print '<!-- replacement line -->';
2974 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2975 $tmp=
'<input type="radio" name="type" id="radio_replacement" value="1"' . (
GETPOST(
'type') == 1 ?
' checked' :
'');
2976 if (! $options) $tmp.=
' disabled';
2978 print '<script type="text/javascript" language="javascript"> 2979 jQuery(document).ready(function() { 2980 jQuery("#fac_replacement").change(function() { 2981 jQuery("#radio_replacement").prop("checked", true); 2985 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceReplacementAsk") .
'</label>';
2986 $text .=
'<select class="flat" name="fac_replacement" id="fac_replacement"';
2988 $text .=
' disabled';
2991 $text .=
'<option value="-1"> </option>';
2994 $text .=
'<option value="-1">' . $langs->trans(
"NoReplacableInvoice") .
'</option>';
2996 $text .=
'</select>';
2997 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
2999 print '</div></div>';
3004 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3005 $tmp=
'<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
3006 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceReplacement") .
'</label> ';
3007 $text.=
'('.$langs->trans(
"YouMustCreateInvoiceFromThird").
') ';
3008 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceReplacementDesc"), 1,
'help',
'', 0, 3);
3010 print '</div></div>';
3019 if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE))
3021 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3022 $tmp=
'<input type="radio" id="radio_creditnote" name="type" value="2"' . (
GETPOST(
'type') == 2 ?
' checked' :
'');
3023 if (! $optionsav) $tmp.=
' disabled';
3026 print '<script type="text/javascript" language="javascript"> 3027 jQuery(document).ready(function() { 3028 if (! jQuery("#radio_creditnote").is(":checked")) 3030 jQuery("#credit_note_options").hide(); 3032 jQuery("#radio_creditnote").click(function() { 3033 jQuery("#credit_note_options").show(); 3035 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() { 3036 jQuery("#credit_note_options").hide(); 3040 $text =
'<label>'.$tmp.$langs->transnoentities(
"InvoiceAvoirAsk") .
'</label> ';
3042 $text .=
'<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
3044 $text .=
' disabled';
3047 $text .=
'<option value="-1"></option>';
3048 $text .= $optionsav;
3050 $text .=
'<option value="-1">' . $langs->trans(
"NoInvoiceToCorrect") .
'</option>';
3052 $text .=
'</select>';
3053 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3056 print '<div id="credit_note_options" class="clearboth">';
3057 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>";
3058 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>";
3061 print '</div></div>';
3066 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3067 if (empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) $tmp=
'<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
3068 else $tmp=
'<input type="radio" name="type" id="radio_creditnote" value="2" > ';
3069 $text =
'<label>'.$tmp.$langs->trans(
"InvoiceAvoir") .
'</label> ';
3070 $text.=
'('.$langs->trans(
"YouMustCreateInvoiceFromThird").
') ';
3071 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"InvoiceAvoirDesc"), 1,
'help',
'', 0, 3);
3073 print '</div></div>' .
"\n";
3078 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
3079 $tmp=
'<input type="radio" name="type" id="radio_template" value="0" disabled> ';
3080 $text =
'<label>'.$tmp.$langs->trans(
"RepeatableInvoice") .
'</label> ';
3082 $desc =
$form->textwithpicto($text, $langs->transnoentities(
"YouMustCreateStandardInvoiceFirstDesc"), 1,
'help',
'', 0, 3);
3084 print '</div></div>';
3089 if(!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT))
3094 foreach ($listtType as $type)
3096 $thisTypeConfName =
'FACTURE_ADDON_PDF_'.$type;
3097 $curent = !empty($conf->global->{$thisTypeConfName})?$conf->global->{$thisTypeConfName}:$conf->global->FACTURE_ADDON_PDF;
3098 $jsListType.=(!empty($jsListType)?
',':
'').
'"'.$type.
'":"'.$curent.
'"';
3101 print '<script type="text/javascript" language="javascript"> 3102 $(document).ready(function() { 3103 var listType = {'.$jsListType.
'}; 3104 $("[name=\'type\'").change(function() { 3105 if($( this ).prop("checked")) 3107 if(($( this ).val() in listType)) 3109 $("#model").val(listType[$( this ).val()]); 3113 $("#model").val("'.$conf->global->FACTURE_ADDON_PDF.
'"); 3128 print '<tr><td>' . $langs->trans(
'Discounts') .
'</td><td colspan="2">';
3132 $backtopage = urlencode($_SERVER[
"PHP_SELF"] .
'?socid=' . $thirdparty->id .
'&action=' . $action .
'&origin=' .
GETPOST(
'origin') .
'&originid=' .
GETPOST(
'originid'));
3133 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3138 $datefacture =
dol_mktime(12, 0, 0, $_POST[
'remonth'], $_POST[
'reday'], $_POST[
'reyear']);
3141 print '<tr><td class="fieldrequired">' . $langs->trans(
'DateInvoice') .
'</td><td colspan="2">';
3142 print $form->selectDate($datefacture?$datefacture:$dateinvoice,
'',
'',
'',
'',
"add", 1, 1);
3146 if (! empty($conf->global->INVOICE_POINTOFTAX_DATE))
3148 print '<tr><td class="fieldrequired">' . $langs->trans(
'DatePointOfTax') .
'</td><td colspan="2">';
3149 $date_pointoftax =
dol_mktime(12, 0, 0, $_POST[
'date_pointoftaxmonth'], $_POST[
'date_pointoftaxday'], $_POST[
'date_pointoftaxyear']);
3150 print $form->selectDate($date_pointoftax?$date_pointoftax:-1,
'date_pointoftax',
'',
'',
'',
"add", 1, 1);
3155 print '<tr><td class="nowrap fieldrequired">' . $langs->trans(
'PaymentConditionsShort') .
'</td><td colspan="2">';
3156 $form->select_conditions_paiements(isset($_POST[
'cond_reglement_id']) ? $_POST[
'cond_reglement_id'] : $cond_reglement_id,
'cond_reglement_id');
3160 print '<tr><td>' . $langs->trans(
'PaymentMode') .
'</td><td colspan="2">';
3161 $form->select_types_paiements(isset($_POST[
'mode_reglement_id']) ? $_POST[
'mode_reglement_id'] : $mode_reglement_id,
'mode_reglement_id',
'CRDT');
3165 if (isset($_POST[
'fk_account'])) {
3166 $fk_account = $_POST[
'fk_account'];
3169 print '<tr><td>' . $langs->trans(
'BankAccount') .
'</td><td colspan="2">';
3170 $form->select_comptes($fk_account,
'fk_account', 0,
'', 1);
3174 if (! empty($conf->projet->enabled))
3176 $langs->load(
'projects');
3177 print '<tr><td>' . $langs->trans(
'Project') .
'</td><td colspan="2">';
3178 $numprojet = $formproject->select_projects(($socid > 0 ? $socid : -1), $projectid,
'projectid', 0, 0, 1, 1);
3179 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:
'')).
'">' . $langs->trans(
"AddProject") .
'</a>';
3184 if (!empty($conf->incoterm->enabled))
3187 print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), $objectsrc->libelle_incoterms, 1).
'</label></td>';
3188 print '<td colspan="2" class="maxwidthonsmartphone">';
3189 $incoterm_id =
GETPOST(
'incoterm_id');
3190 $incoterm_location =
GETPOST(
'location_incoterms');
3191 if (empty($incoterm_id))
3193 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
3194 $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
3196 print $form->select_incoterms($incoterm_id, $incoterm_location);
3201 $parameters = array(
'objectsrc' => $objectsrc,
'colspan' =>
' colspan="2"',
'cols'=>2);
3202 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
3203 print $hookmanager->resPrint;
3204 if (empty($reshook)) {
3205 print $object->showOptionals($extrafields,
'edit');
3209 print '<tr><td>' . $langs->trans(
'Model') .
'</td>';
3210 print '<td colspan="2">';
3211 include_once DOL_DOCUMENT_ROOT .
'/core/modules/facture/modules_facture.php';
3213 if(!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)){
3214 $paramkey=
'FACTURE_ADDON_PDF_'.$object->type;
3215 $curent = !empty($conf->global->$paramkey)?$conf->global->$paramkey:$conf->global->FACTURE_ADDON_PDF;
3218 $curent = $conf->global->FACTURE_ADDON_PDF;
3220 print $form->selectarray(
'model', $liste, $curent);
3224 if (! empty($conf->multicurrency->enabled))
3227 print '<td>'.fieldLabel(
'Currency',
'multicurrency_code').
'</td>';
3228 print '<td colspan="2" class="maxwidthonsmartphone">';
3229 print $form->selectMultiCurrency($currency_code,
'multicurrency_code');
3235 if (
GETPOST(
'fac_rec',
'int') > 0)
3237 $dateexample=($datefacture ? $datefacture : $dateinvoice);
3238 if (empty($dateexample)) $dateexample=
dol_now();
3239 $substitutionarray=array(
3240 '__TOTAL_HT__' => $langs->trans(
"AmountHT").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ht).
')',
3241 '__TOTAL_TTC__' => $langs->trans(
"AmountTTC").
' ('.$langs->trans(
"Example").
': '.
price($exampletemplateinvoice->total_ttc).
')',
3242 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans(
"PreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%m').
')',
3243 '__INVOICE_MONTH__' => $langs->trans(
"MonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%m').
')',
3244 '__INVOICE_NEXT_MONTH__' => $langs->trans(
"NextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%m').
')',
3245 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans(
"TextPreviousMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'm'),
'%B').
')',
3246 '__INVOICE_MONTH_TEXT__' => $langs->trans(
"TextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%B').
')',
3247 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans(
"TextNextMonthOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'm'),
'%B').
')',
3248 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans(
"YearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, -1,
'y'),
'%Y').
')',
3249 '__INVOICE_YEAR__' => $langs->trans(
"PreviousYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date($dateexample,
'%Y').
')',
3250 '__INVOICE_NEXT_YEAR__' => $langs->trans(
"NextYearOfInvoice").
' ('.$langs->trans(
"Example").
': '.
dol_print_date(
dol_time_plus_duree($dateexample, 1,
'y'),
'%Y').
')' 3253 $htmltext =
'<i>'.$langs->trans(
"FollowingConstantsWillBeSubstituted").
':<br>';
3254 foreach($substitutionarray as $key => $val)
3256 $htmltext.=$key.
' = '.$langs->trans($val).
'<br>';
3263 print '<td class="tdtop">';
3264 print $form->textwithpicto($langs->trans(
'NotePublic'), $htmltext);
3266 print '<td valign="top" colspan="2">';
3267 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false,
true, ROWS_3,
'90%');
3268 print $doleditor->Create(1);
3271 if (empty($user->societe_id))
3274 print '<td class="tdtop">';
3275 print $form->textwithpicto($langs->trans(
'NotePrivate'), $htmltext);
3277 print '<td valign="top" colspan="2">';
3278 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false,
true, ROWS_3,
'90%');
3279 print $doleditor->Create(1);
3285 if (! empty($origin) && ! empty($originid) && is_object($objectsrc))
3288 if ($origin ==
'contrat') {
3290 $objectsrc->remise_absolue = $remise_absolue;
3291 $objectsrc->remise_percent = $remise_percent;
3292 $objectsrc->update_price(1, - 1, 1);
3295 print "\n<!-- " . $classname .
" info -->";
3297 print '<input type="hidden" name="amount" value="' . $objectsrc->total_ht .
'">' .
"\n";
3298 print '<input type="hidden" name="total" value="' . $objectsrc->total_ttc .
'">' .
"\n";
3299 print '<input type="hidden" name="tva" value="' . $objectsrc->total_tva .
'">' .
"\n";
3300 print '<input type="hidden" name="origin" value="' . $objectsrc->element .
'">';
3301 print '<input type="hidden" name="originid" value="' . $objectsrc->id .
'">';
3303 switch (get_class($objectsrc)) {
3305 $newclassname =
'CommercialProposal';
3308 $newclassname =
'Order';
3311 $newclassname =
'Sending';
3314 $newclassname =
'Contract';
3317 $newclassname =
'Intervention';
3320 $newclassname = get_class($objectsrc);
3323 print '<tr><td>' . $langs->trans($newclassname) .
'</td><td colspan="2">' . $objectsrc->getNomUrl(1);
3325 $objectsrc->fetchObjectLinked($originid,$origin,
'',
'facture');
3326 if (is_array($objectsrc->linkedObjects[
'facture']) && count($objectsrc->linkedObjects[
'facture']) >= 1)
3329 echo
' ('.$langs->trans(
'LatestRelatedBill').end($objectsrc->linkedObjects[
'facture'])->getNomUrl(1).
')';
3332 print '<tr><td>' . $langs->trans(
'TotalHT') .
'</td><td colspan="2">' .
price($objectsrc->total_ht) .
'</td></tr>';
3333 print '<tr><td>' . $langs->trans(
'TotalVAT') .
'</td><td colspan="2">' .
price($objectsrc->total_tva) .
"</td></tr>";
3334 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0)
3336 print '<tr><td>' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td><td colspan="2">' .
price($objectsrc->total_localtax1) .
"</td></tr>";
3339 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0)
3341 print '<tr><td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td><td colspan="2">' .
price($objectsrc->total_localtax2) .
"</td></tr>";
3343 print '<tr><td>' . $langs->trans(
'TotalTTC') .
'</td><td colspan="2">' .
price($objectsrc->total_ttc) .
"</td></tr>";
3345 if (!empty($conf->multicurrency->enabled))
3347 print '<tr><td>' . $langs->trans(
'MulticurrencyAmountHT') .
'</td><td colspan="2">' .
price($objectsrc->multicurrency_total_ht) .
'</td></tr>';
3348 print '<tr><td>' . $langs->trans(
'MulticurrencyAmountVAT') .
'</td><td colspan="2">' .
price($objectsrc->multicurrency_total_tva) .
"</td></tr>";
3349 print '<tr><td>' . $langs->trans(
'MulticurrencyAmountTTC') .
'</td><td colspan="2">' .
price($objectsrc->multicurrency_total_ttc) .
"</td></tr>";
3358 print '<div class="center">';
3359 print '<input type="submit" class="button" name="bouton" value="' . $langs->trans(
'CreateDraft') .
'">';
3360 print ' ';
3361 print '<input type="button" class="button" value="' . $langs->trans(
"Cancel") .
'" onClick="javascript:history.go(-1)">';
3367 if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) {
3370 $title = $langs->trans(
'ProductsAndServices');
3373 print '<table class="noborder" width="100%">';
3375 $objectsrc->printOriginLinesList();
3382 else if ($id > 0 || ! empty($ref))
3388 $result = $object->fetch($id, $ref);
3395 $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
3397 if ($user->societe_id > 0 && $user->societe_id != $object->socid)
3400 $result = $object->fetch_thirdparty();
3403 $result=$soc->fetch($object->socid);
3405 $selleruserevenustamp = $mysoc->useRevenueStamp();
3407 $totalpaye = $object->getSommePaiement();
3408 $totalcreditnotes = $object->getSumCreditNotesUsed();
3409 $totaldeposits = $object->getSumDepositsUsed();
3417 $resteapayer =
price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,
'MT');
3423 $resteapayeraffiche = $resteapayer;
3425 if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
3426 $filterabsolutediscount =
"fk_facture_source IS NULL";
3427 $filtercreditnote =
"fk_facture_source IS NOT NULL";
3429 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
3430 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
3433 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
3434 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
3435 $absolute_discount =
price2num($absolute_discount,
'MT');
3436 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
3438 $author =
new User($db);
3439 if ($object->user_author) {
3440 $author->fetch($object->user_author);
3443 $objectidnext = $object->getIdReplacingInvoice();
3447 dol_fiche_head($head,
'compta', $langs->trans(
'InvoiceCustomer'), -1,
'bill');
3452 if ($action ==
'converttoreduc') {
3456 $text = $langs->trans(
'ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
3457 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id, $langs->trans(
'ConvertToReduc'), $text,
'confirm_converttoreduc',
'',
"yes", 2);
3461 if ($action ==
'delete') {
3462 $text = $langs->trans(
'ConfirmDeleteBill', $object->ref);
3463 $formquestion = array();
3465 $qualified_for_stock_change = 0;
3466 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
3467 $qualified_for_stock_change = $object->hasProductsOrServices(2);
3469 $qualified_for_stock_change = $object->hasProductsOrServices(1);
3472 if ($object->type !=
Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change && $object->statut >= 1)
3474 $langs->load(
"stocks");
3475 require_once DOL_DOCUMENT_ROOT .
'/product/class/html.formproduct.class.php';
3477 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
3479 if ($conf->browser->name ==
'ie') $forcecombo = 1;
3480 $formquestion = array(
3484 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse')?
GETPOST(
'idwarehouse'):
'ifone',
'idwarehouse',
'', 1, 0, 0, $langs->trans(
"NoStockAction"), 0, $forcecombo))
3486 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete', $formquestion,
"yes", 1);
3488 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id, $langs->trans(
'DeleteBill'), $text,
'confirm_delete',
'',
'no', 1);
3493 if ($action ==
'situationout') {
3494 $text = $langs->trans(
'ConfirmRemoveSituationFromCycle', $object->ref);
3495 $label = $langs->trans(
"ConfirmOuting");
3496 $formquestion = array();
3501 && $object->is_last_in_cycle()
3502 && $usercanunvalidate
3505 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id, $label, $text,
'confirm_situationout', $formquestion,
"yes", 1);
3510 if ($action ==
'valid')
3513 $objectref = substr($object->ref, 1, 4);
3514 if ($objectref ==
'PROV') {
3515 $savdate = $object->date;
3516 if (! empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
3518 $object->date_lim_reglement = $object->calculate_date_lim_reglement();
3520 $numref = $object->getNextNumRef($soc);
3523 $numref = $object->ref;
3526 $text = $langs->trans(
'ConfirmValidateBill', $numref);
3527 if (! empty($conf->notification->enabled)) {
3528 require_once DOL_DOCUMENT_ROOT .
'/core/class/notify.class.php';
3529 $notify =
new Notify($db);
3531 $text .= $notify->confirmMessage(
'BILL_VALIDATE', $object->socid, $object);
3533 $formquestion = array();
3535 $qualified_for_stock_change = 0;
3536 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
3537 $qualified_for_stock_change = $object->hasProductsOrServices(2);
3539 $qualified_for_stock_change = $object->hasProductsOrServices(1);
3542 if ($object->type !=
Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change)
3544 $langs->load(
"stocks");
3545 require_once DOL_DOCUMENT_ROOT .
'/product/class/html.formproduct.class.php';
3546 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
3549 $warehouse_array = $warehouse->list_array();
3550 if (count($warehouse_array) == 1) {
3551 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array));
3552 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="' . key($warehouse_array) .
'">';
3554 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockIncrease") : $langs->trans(
"SelectWarehouseForStockDecrease");
3555 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse')?
GETPOST(
'idwarehouse'):
'ifone',
'idwarehouse',
'', 1);
3557 $formquestion = array(
3563 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
3567 $text .=
'<br>' .
img_warning() .
' ' . $langs->trans(
"ErrorInvoiceOfThisTypeMustBePositive");
3569 $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);
3573 if ($action ==
'modif') {
3574 $text = $langs->trans(
'ConfirmUnvalidateBill', $object->ref);
3575 $formquestion = array();
3577 $qualified_for_stock_change = 0;
3578 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
3579 $qualified_for_stock_change = $object->hasProductsOrServices(2);
3581 $qualified_for_stock_change = $object->hasProductsOrServices(1);
3583 if ($object->type !=
Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) {
3584 $langs->load(
"stocks");
3585 require_once DOL_DOCUMENT_ROOT .
'/product/class/html.formproduct.class.php';
3586 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
3589 $warehouse_array = $warehouse->list_array();
3590 if (count($warehouse_array) == 1) {
3591 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans(
"WarehouseForStockIncrease", current($warehouse_array));
3592 $value =
'<input type="hidden" id="idwarehouse" name="idwarehouse" value="' . key($warehouse_array) .
'">';
3594 $label = $object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"SelectWarehouseForStockDecrease") : $langs->trans(
"SelectWarehouseForStockIncrease");
3595 $value = $formproduct->selectWarehouses(
GETPOST(
'idwarehouse')?
GETPOST(
'idwarehouse'):
'ifone',
'idwarehouse',
'', 1);
3597 $formquestion = array(
3603 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $label,
'value' => $value));
3606 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"] .
'?facid=' . $object->id, $langs->trans(
'UnvalidateBill'), $text,
'confirm_modif', $formquestion,
"yes", 1);
3610 if ($action ==
'paid' && $resteapayer <= 0) {
3611 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"] .
'?facid=' . $object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidBill', $object->ref),
'confirm_paid',
'',
"yes", 1);
3613 if ($action ==
'paid' && $resteapayer > 0) {
3616 $close [$i][
'code'] =
'discount_vat';
3618 $close [$i][
'code'] =
'badcustomer';
3622 $close [$i][
'label'] = $langs->trans(
"HelpEscompte") .
'<br><br>' . $langs->trans(
"ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
3624 $close [$i][
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
3628 $close [$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans(
"Currency" . $conf->currency)), $close[$i][
'label'], 1);
3630 $close [$i][
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans(
"Currency" . $conf->currency)), $close[$i][
'label'], 1);
3633 foreach ($close as $key => $val) {
3634 $arrayreasons[$close [$key][
'code']] = $close[$key][
'reason'];
3638 $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'));
3640 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"] .
'?facid=' . $object->id, $langs->trans(
'ClassifyPaid'), $langs->trans(
'ConfirmClassifyPaidPartially', $object->ref),
'confirm_paid_partially', $formquestion,
"yes", 1, 310);
3644 if ($action ==
'canceled') {
3647 if ($objectidnext) {
3648 $facturereplacement =
new Facture($db);
3649 $facturereplacement->fetch($objectidnext);
3650 $statusreplacement = $facturereplacement->statut;
3652 if ($objectidnext && $statusreplacement == 0) {
3653 print '<div class="error">' . $langs->trans(
"ErrorCantCancelIfReplacementInvoiceNotValidated") .
'</div>';
3656 $close [1] [
'code'] =
'badcustomer';
3657 $close [2] [
'code'] =
'abandon';
3659 $close [1] [
'label'] = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
3660 $close [2] [
'label'] = $langs->trans(
"ConfirmClassifyAbandonReasonOtherDesc");
3662 $close [1] [
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyPaidPartiallyReasonBadCustomer", $object->ref), $close [1] [
'label'], 1);
3663 $close [2] [
'reason'] =
$form->textwithpicto($langs->transnoentities(
"ConfirmClassifyAbandonReasonOther"), $close [2] [
'label'], 1);
3665 $arrayreasons [$close [1] [
'code']] = $close [1] [
'reason'];
3666 $arrayreasons [$close [2] [
'code']] = $close [2] [
'reason'];
3669 $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'));
3671 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id, $langs->trans(
'CancelBill'), $langs->trans(
'ConfirmCancelBill', $object->ref),
'confirm_canceled', $formquestion,
"yes", 1, 250);
3675 if ($action ==
'deletepaiement')
3677 $payment_id =
GETPOST(
'paiement_id');
3678 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&paiement_id='.$payment_id, $langs->trans(
'DeletePayment'), $langs->trans(
'ConfirmDeletePayment'),
'confirm_delete_paiement',
'',
'no', 1);
3682 if ($action ==
'ask_deleteline') {
3683 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"] .
'?facid=' . $object->id .
'&lineid=' . $lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'',
'no', 1);
3687 if ($action ==
'clone')
3690 $formquestion = array(
3693 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)));
3695 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"] .
'?facid=' . $object->id, $langs->trans(
'CloneInvoice'), $langs->trans(
'ConfirmCloneInvoice', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
3700 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
3701 if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
3702 elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;
3709 $linkback = '<a href="' . DOL_URL_ROOT . '/compta/facture/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
3711 $morehtmlref='<div class="refidno">';
3713 $morehtmlref.=
$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, '
string', '', 0, 1);
3714 $morehtmlref.=
$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, '
string', '', null, null, '', 1);
3716 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1,'customer');
3717 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>)';
3719 if (! empty($conf->projet->enabled))
3721 $langs->load(
"projects");
3722 $morehtmlref.=
'<br>'.$langs->trans(
'Project') .
' ';
3725 if ($action !=
'classify')
3726 $morehtmlref.=
'<a href="' . $_SERVER[
'PHP_SELF'] .
'?action=classify&id=' . $object->id .
'">' .
img_edit($langs->transnoentitiesnoconv(
'SetProject')) .
'</a> : ';
3727 if ($action ==
'classify') {
3729 $morehtmlref.=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
3730 $morehtmlref.=
'<input type="hidden" name="action" value="classin">';
3731 $morehtmlref.=
'<input type="hidden" name="token" value="'.$_SESSION[
'newtoken'].
'">';
3732 $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
3733 $morehtmlref.=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
3734 $morehtmlref.=
'</form>';
3736 $morehtmlref.=
$form->form_project($_SERVER[
'PHP_SELF'] .
'?id=' . $object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
3739 if (! empty($object->fk_project)) {
3741 $proj->fetch($object->fk_project);
3742 $morehtmlref.=
'<a href="'.DOL_URL_ROOT.
'/projet/card.php?id=' . $object->fk_project .
'" title="' . $langs->trans(
'ShowProject') .
'">';
3743 $morehtmlref.=$proj->ref;
3744 $morehtmlref.=
'</a>';
3750 $morehtmlref.=
'</div>';
3752 $object->totalpaye = $totalpaye;
3754 dol_banner_tab($object,
'ref', $linkback, 1,
'facnumber',
'ref', $morehtmlref,
'', 0,
'',
'');
3756 print '<div class="fichecenter">';
3757 print '<div class="fichehalfleft">';
3758 print '<div class="underbanner clearboth"></div>';
3760 print '<table class="border" width="100%">';
3763 print '<tr><td class="titlefield">' . $langs->trans(
'Type') .
'</td><td>';
3764 print $object->getLibType();
3766 $facreplaced =
new Facture($db);
3767 $facreplaced->fetch($object->fk_facture_source);
3768 print ' (' . $langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)) .
')';
3772 $facusing->fetch($object->fk_facture_source);
3773 print ' (' . $langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)) .
')';
3776 $facidavoir = $object->getListIdAvoirFromInvoice();
3777 if (count($facidavoir) > 0) {
3778 print ' (' . $langs->transnoentities(
"InvoiceHasAvoir");
3780 foreach ($facidavoir as $id) {
3786 $facavoir->fetch($id);
3787 print $facavoir->getNomUrl(1);
3791 if ($objectidnext > 0) {
3792 $facthatreplace =
new Facture($db);
3793 $facthatreplace->fetch($objectidnext);
3794 print ' (' . $langs->transnoentities(
"ReplacedByInvoice", $facthatreplace->getNomUrl(1)) .
')';
3799 $result = $discount->fetch(0, $object->id);
3801 print '. '.$langs->trans(
"CreditNoteConvertedIntoDiscount", $object->getLibType(1), $discount->getNomUrl(1,
'discount')).
'<br>';
3807 print '<!-- Discounts --><tr><td>' . $langs->trans(
'Discounts');
3812 $backtopage = urlencode($_SERVER[
"PHP_SELF"] .
'?facid=' . $object->id);
3813 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
3819 print '<table class="nobordernopadding" width="100%"><tr><td>';
3820 print $langs->trans(
'DateInvoice');
3822 if ($object->type !=
Facture::TYPE_CREDIT_NOTE && $action !=
'editinvoicedate' && ! empty($object->brouillon) && $usercancreate && empty($conf->global->FAC_FORCE_DATE_VALIDATION))
3823 print '<td align="right"><a href="' . $_SERVER[
"PHP_SELF"] .
'?action=editinvoicedate&facid=' . $object->id .
'">' .
img_edit($langs->trans(
'SetDate'), 1) .
'</a></td>';
3824 print '</tr></table>';
3828 if ($action ==
'editinvoicedate') {
3829 $form->form_date($_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id, $object->date,
'invoicedate');
3840 if (! empty($conf->global->INVOICE_POINTOFTAX_DATE))
3844 print
'<table class="nobordernopadding" width="100%"><tr><td>';
3845 print $langs->trans(
'DatePointOfTax');
3847 print
'<td align="right"><a href="' . $_SERVER[
"PHP_SELF"] .
'?action=editdate_pointoftax&facid=' . $object->id .
'">' .
img_edit($langs->trans(
'SetDate'), 1) .
'</a></td>';
3848 print
'</tr></table>';
3850 if ($action ==
'editdate_pointoftax') {
3851 $form->form_date($_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id, $object->date_pointoftax,
'date_pointoftax');
3860 print
'<table class="nobordernopadding" width="100%"><tr><td>';
3861 print $langs->trans(
'PaymentConditionsShort');
3864 print
'<td align="right"><a href="' . $_SERVER[
"PHP_SELF"] .
'?action=editconditions&facid=' . $object->id .
'">' .
img_edit($langs->trans(
'SetConditions'), 1) .
'</a></td>';
3865 print
'</tr></table>';
3869 if ($action ==
'editconditions') {
3870 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id, $object->cond_reglement_id,
'cond_reglement_id');
3872 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id, $object->cond_reglement_id,
'none');
3881 print
'<table class="nobordernopadding" width="100%"><tr><td>';
3882 print $langs->trans(
'DateMaxPayment');
3885 print
'<td align="right"><a href="' . $_SERVER[
"PHP_SELF"] .
'?action=editpaymentterm&facid=' . $object->id .
'">' .
img_edit($langs->trans(
'SetDate'), 1) .
'</a></td>';
3886 print
'</tr></table>';
3890 if ($action ==
'editpaymentterm') {
3891 $form->form_date($_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id, $object->date_lim_reglement,
'paymentterm');
3894 if ($object->hasDelay()) {
3905 print
'<table class="nobordernopadding" width="100%"><tr><td>';
3906 print $langs->trans(
'PaymentMode');
3908 if ($action !=
'editmode' && $usercancreate)
3909 print
'<td align="right"><a href="' . $_SERVER[
"PHP_SELF"] .
'?action=editmode&facid=' . $object->id .
'">' .
img_edit($langs->trans(
'SetMode'), 1) .
'</a></td>';
3910 print
'</tr></table>';
3912 if ($action ==
'editmode')
3914 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
3918 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?facid='.$object->id, $object->mode_reglement_id,
'none',
'CRDT');
3923 if (! empty($conf->multicurrency->enabled))
3928 print
'<table class="nobordernopadding" width="100%"><tr><td>';
3929 print
fieldLabel(
'Currency',
'multicurrency_code');
3931 if ($usercancreate && $action !=
'editmulticurrencycode' && ! empty($object->brouillon))
3932 print
'<td align="right"><a href="' . $_SERVER[
"PHP_SELF"] .
'?action=editmulticurrencycode&id=' . $object->id .
'">' .
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1) .
'</a></td>';
3933 print
'</tr></table>';
3935 $htmlname = (($usercancreate && $action ==
'editmulticurrencycode')?
'multicurrency_code':
'none');
3936 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'] .
'?id=' . $object->id, $object->multicurrency_code, $htmlname);
3941 print
'<table class="nobordernopadding" width="100%"><tr><td>';
3942 print
fieldLabel(
'CurrencyRate',
'multicurrency_tx');
3944 if ($usercancreate && $action !=
'editmulticurrencyrate' && ! empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency)
3945 print
'<td align="right"><a href="' . $_SERVER[
"PHP_SELF"] .
'?action=editmulticurrencyrate&id=' . $object->id .
'">' .
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1) .
'</a></td>';
3946 print
'</tr></table>';
3948 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
3949 if($action ==
'actualizemulticurrencyrate') {
3952 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'] .
'?id=' . $object->id, $object->multicurrency_tx, ($usercancreate?
'multicurrency_tx':
'none'), $object->multicurrency_code);
3954 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'] .
'?id=' . $object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
3955 if($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3956 print
'<div class="inline-block"> ';
3957 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
3965 print
'<tr><td class="nowrap">';
3966 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3967 print $langs->trans(
'BankAccount');
3969 if (($action !=
'editbankaccount') && $usercancreate)
3970 print
'<td align="right"><a href="'.$_SERVER[
"PHP_SELF"].
'?action=editbankaccount&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetBankAccount'),1).
'</a></td>';
3971 print
'</tr></table>';
3973 if ($action ==
'editbankaccount')
3975 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
3979 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
3990 if (!empty($conf->incoterm->enabled))
3993 print
'<table width="100%" class="nobordernopadding"><tr><td>';
3994 print $langs->trans(
'IncotermLabel');
3995 print
'<td><td align="right">';
3996 if ($usercancreate) print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$object->id.
'&action=editincoterm">'.
img_edit().
'</a>';
3997 else print
' ';
3998 print
'</td></tr></table>';
4001 if ($action !=
'editincoterm')
4003 print
$form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
4007 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms)?$object->location_incoterms:
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
4014 include DOL_DOCUMENT_ROOT .
'/core/tpl/extrafields_view.tpl.php';
4019 print
'<div class="fichehalfright">';
4020 print
'<div class="ficheaddleft">';
4021 print
'<div class="underbanner clearboth"></div>';
4023 print
'<table class="border centpercent">';
4025 if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency))
4028 print
'<tr><td class="titlefieldmiddle">' .
fieldLabel(
'MulticurrencyAmountHT',
'multicurrency_total_ht') .
'</td>';
4029 print
'<td class="nowrap amountcard">' .
price($object->multicurrency_total_ht,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) .
'</td>';
4033 print
'<tr><td>' .
fieldLabel(
'MulticurrencyAmountVAT',
'multicurrency_total_tva') .
'</td>';
4034 print
'<td class="nowrap amountcard">' .
price($object->multicurrency_total_tva,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) .
'</td>';
4038 print
'<tr><td>' .
fieldLabel(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc') .
'</td>';
4039 print
'<td class="nowrap amountcard">' .
price($object->multicurrency_total_ttc,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) .
'</td>';
4044 print
'<tr><td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
4045 print
'<td class="nowrap amountcard">' .
price($object->total_ht, 1,
'', 1, - 1, - 1, $conf->currency) .
'</td></tr>';
4048 print
'<tr><td>' . $langs->trans(
'AmountVAT') .
'</td><td colspan="3" class="nowrap amountcard">' .
price($object->total_tva, 1,
'', 1, - 1, - 1, $conf->currency) .
'</td></tr>';
4052 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0)
4054 print
'<tr><td>' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
4055 print
'<td class="nowrap amountcard">' .
price($object->total_localtax1, 1,
'', 1, - 1, - 1, $conf->currency) .
'</td></tr>';
4057 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0)
4059 print
'<tr><td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
4060 print
'<td class=nowrap amountcard">' .
price($object->total_localtax2, 1,
'', 1, - 1, - 1, $conf->currency) .
'</td></tr>';
4064 if ($selleruserevenustamp)
4067 print
'<table class="nobordernopadding" width="100%"><tr><td>';
4068 print $langs->trans(
'RevenueStamp');
4070 if ($action !=
'editrevenuestamp' && ! empty($object->brouillon) && $usercancreate)
4072 print
'<td align="right"><a href="' . $_SERVER[
"PHP_SELF"] .
'?action=editrevenuestamp&facid=' . $object->id .
'">' .
img_edit($langs->trans(
'SetRevenuStamp'), 1) .
'</a></td>';
4074 print
'</tr></table>';
4076 if ($action ==
'editrevenuestamp') {
4077 print
'<form action="' . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'" method="post">';
4078 print
'<input type="hidden" name="token" value="' . $_SESSION [
'newtoken'] .
'">';
4079 print
'<input type="hidden" name="action" value="setrevenuestamp">';
4080 print
'<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num($object->revenuestamp).
'">';
4081 print $formother->select_revenue_stamp(
'',
'revenuestamp_type', $mysoc->country_code);
4082 print
' → <span id="revenuestamp_span"></span>';
4083 print
' <input type="submit" class="button" value="' . $langs->trans(
'Modify') .
'">';
4086 $(document).ready(function(){ 4087 js_recalculate_revenuestamp(); 4088 $('select[name=revenuestamp_type]').on('change',function(){ 4089 js_recalculate_revenuestamp(); 4092 function js_recalculate_revenuestamp(){ 4093 var valselected = $('select[name=revenuestamp_type]').val(); 4094 console.log('Calculate revenue stamp from '+valselected); 4096 if (valselected.indexOf('%') == -1) 4098 revenue = valselected; 4102 var revenue_type = parseFloat(valselected); 4103 var amount_net = ".round($object->total_ht, 2).
"; 4104 revenue = revenue_type * amount_net / 100; 4105 revenue = revenue.toFixed(2); 4107 $('#revenuestamp_val').val(revenue); 4108 $('#revenuestamp_span').html(revenue); 4112 print
price($object->revenuestamp, 1,
'', 1, - 1, - 1, $conf->currency);
4118 print
'<tr><td>' . $langs->trans(
'AmountTTC') .
'</td><td class="nowrap amountcard">' .
price($object->total_ttc, 1,
'', 1, - 1, - 1, $conf->currency) .
'</td></tr>';
4127 if (! empty($conf->projet->enabled))
4129 if (! empty($conf->banque->enabled)) {
4133 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0)
4135 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0)
4137 if ($selleruserevenustamp)
4139 if (! empty($conf->multicurrency->enabled))
4141 if (! empty($conf->incoterm->enabled))
4145 if (($object->situation_cycle_ref > 0) && ! empty($conf->global->INVOICE_USE_SITUATION))
4148 print
'<table class="noborder situationstable" width="100%">';
4151 print
'<tr class="liste_titre">';
4152 print
'<td>' . $langs->trans(
'ListOfSituationInvoices') .
'</td>';
4154 print
'<td align="center">' . $langs->trans(
'Situation') .
'</td>';
4155 if (! empty($conf->banque->enabled)) print
'<td align="right"></td>';
4156 print
'<td align="right">' . $langs->trans(
'AmountHT') .
'</td>';
4157 print
'<td align="right">' . $langs->trans(
'AmountTTC') .
'</td>';
4158 print
'<td width="18"> </td>';
4162 $total_prev_ht = $total_prev_ttc = 0;
4163 $total_global_ht = $total_global_ttc = 0;
4165 if (count($object->tab_previous_situation_invoice) > 0) {
4168 $current_situation_counter = array();
4169 foreach ($object->tab_previous_situation_invoice as $prev_invoice) {
4170 $totalpaye = $prev_invoice->getSommePaiement();
4171 $total_prev_ht += $prev_invoice->total_ht;
4172 $total_prev_ttc += $prev_invoice->total_ttc;
4173 $current_situation_counter[] = (($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE)?-1:1) * $prev_invoice->situation_counter;
4174 print
'<tr class="oddeven">';
4175 print
'<td>' . $prev_invoice->getNomUrl(1) .
'</td>';
4177 print
'<td align="center" >'.(($prev_invoice->type ==
Facture::TYPE_CREDIT_NOTE)?$langs->trans(
'situationInvoiceShortcode_AS'):$langs->trans(
'situationInvoiceShortcode_S')) . $prev_invoice->situation_counter.
'</td>';
4178 if (! empty($conf->banque->enabled)) print
'<td align="right"></td>';
4179 print
'<td align="right">' .
price($prev_invoice->total_ht) .
'</td>';
4180 print
'<td align="right">' .
price($prev_invoice->total_ttc) .
'</td>';
4181 print
'<td align="right">' . $prev_invoice->getLibStatut(3, $totalpaye) .
'</td>';
4187 $total_global_ht += $total_prev_ht ;
4188 $total_global_ttc += $total_prev_ttc ;
4189 $total_global_ht += $object->total_ht;
4190 $total_global_ttc += $object->total_ttc;
4192 print
'<tr class="oddeven">';
4193 print
'<td>' . $object->getNomUrl(1) .
'</td>';
4195 print
'<td align="center">'.(($object->type ==
Facture::TYPE_CREDIT_NOTE)?$langs->trans(
'situationInvoiceShortcode_AS'):$langs->trans(
'situationInvoiceShortcode_S')) . $object->situation_counter.
'</td>';
4196 if (! empty($conf->banque->enabled)) print
'<td align="right"></td>';
4197 print
'<td align="right">' .
price($object->total_ht) .
'</td>';
4198 print
'<td align="right">' .
price($object->total_ttc) .
'</td>';
4199 print
'<td align="right">' . $object->getLibStatut(3, $object->getSommePaiement()) .
'</td>';
4203 print
'<tr class="oddeven">';
4204 print
'<td colspan="2" align="left"><b>' . $langs->trans(
'CurrentSituationTotal') .
'</b></td>';
4207 foreach ($current_situation_counter as $sit)
4209 $curSign = $sit>0?
'+':
'-';
4210 $curType = $sit>0?$langs->trans(
'situationInvoiceShortcode_S'):$langs->trans(
'situationInvoiceShortcode_AS');
4211 if($i>0) print
' '.$curSign.
' ';
4212 print $curType . abs($sit);
4216 if (! empty($conf->banque->enabled)) print
'<td></td>';
4217 print
'<td align="right"><b>' .
price($total_global_ht) .
'</b></td>';
4218 print
'<td align="right"><b>' .
price($total_global_ttc) .
'</b></td>';
4219 print
'<td width="18"> </td>';
4223 if (count($object->tab_next_situation_invoice) > 0) {
4235 $total_next_ht = $total_next_ttc = 0;
4237 foreach ($object->tab_next_situation_invoice as $next_invoice) {
4238 $totalpaye = $next_invoice->getSommePaiement();
4239 $total_next_ht += $next_invoice->total_ht;
4240 $total_next_ttc += $next_invoice->total_ttc;
4242 print
'<tr class="oddeven">';
4243 print
'<td>' . $next_invoice->getNomUrl(1) .
'</td>';
4245 print
'<td align="center">'.(($next_invoice->type ==
Facture::TYPE_CREDIT_NOTE)?$langs->trans(
'situationInvoiceShortcode_AS'):$langs->trans(
'situationInvoiceShortcode_S')) . $next_invoice->situation_counter.
'</td>';
4246 if (! empty($conf->banque->enabled)) print
'<td align="right"></td>';
4247 print
'<td align="right">' .
price($next_invoice->total_ht) .
'</td>';
4248 print
'<td align="right">' .
price($next_invoice->total_ttc) .
'</td>';
4249 print
'<td align="right">' . $next_invoice->getLibStatut(3, $totalpaye) .
'</td>';
4253 $total_global_ht += $total_next_ht;
4254 $total_global_ttc += $total_next_ttc;
4256 print
'<tr class="oddeven">';
4257 print
'<td colspan="3" align="right"></td>';
4258 if (! empty($conf->banque->enabled)) print
'<td align="right"></td>';
4259 print
'<td align="right"><b>' .
price($total_global_ht) .
'</b></td>';
4260 print
'<td align="right"><b>' .
price($total_global_ttc) .
'</b></td>';
4261 print
'<td width="18"> </td>';
4271 print
'<div class="div-table-responsive-no-min">';
4272 print
'<table class="noborder paymenttable" width="100%">';
4274 print
'<tr class="liste_titre">';
4275 print
'<td class="liste_titre">' . ($object->type ==
Facture::TYPE_CREDIT_NOTE ? $langs->trans(
"PaymentsBack") : $langs->trans(
'Payments')) .
'</td>';
4276 print
'<td class="liste_titre">' . $langs->trans(
'Date') .
'</td>';
4277 print
'<td class="liste_titre">' . $langs->trans(
'Type') .
'</td>';
4278 if (! empty($conf->banque->enabled)) {
4279 print
'<td class="liste_titre" align="right">' . $langs->trans(
'BankAccount') .
'</td>';
4281 print
'<td class="liste_titre" align="right">' . $langs->trans(
'Amount') .
'</td>';
4282 print
'<td class="liste_titre" width="18"> </td>';
4286 $sql =
'SELECT p.datep as dp, p.ref, p.num_paiement, p.rowid, p.fk_bank,';
4287 $sql .=
' c.code as payment_code, c.libelle as payment_label,';
4288 $sql .=
' pf.amount,';
4289 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
4290 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'paiement_facture as pf, ' . MAIN_DB_PREFIX .
'paiement as p';
4291 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'c_paiement as c ON p.fk_paiement = c.id' ;
4292 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'bank as b ON p.fk_bank = b.rowid';
4293 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'bank_account as ba ON b.fk_account = ba.rowid';
4294 $sql .=
' WHERE pf.fk_facture = ' . $object->id .
' AND pf.fk_paiement = p.rowid';
4295 $sql .=
' AND p.entity IN (' .
getEntity(
'facture').
')';
4296 $sql .=
' ORDER BY p.datep, p.tms';
4298 $result = $db->query($sql);
4300 $num = $db->num_rows($result);
4307 $objp = $db->fetch_object($result);
4309 $paymentstatic->id = $objp->rowid;
4310 $paymentstatic->datepaye = $db->jdate($objp->dp);
4311 $paymentstatic->ref = $objp->ref;
4312 $paymentstatic->num_paiement = $objp->num_paiement;
4313 $paymentstatic->payment_code = $objp->payment_code;
4315 print
'<tr class="oddeven"><td>';
4316 print $paymentstatic->getNomUrl(1);
4318 print
'<td>' .
dol_print_date($db->jdate($objp->dp),
'day') .
'</td>';
4319 $label = ($langs->trans(
"PaymentType" . $objp->payment_code) != (
"PaymentType" . $objp->payment_code)) ? $langs->trans(
"PaymentType" . $objp->payment_code) : $objp->payment_label;
4320 print
'<td>' . $label .
' ' . $objp->num_paiement .
'</td>';
4321 if (! empty($conf->banque->enabled))
4323 $bankaccountstatic->id = $objp->baid;
4324 $bankaccountstatic->ref = $objp->baref;
4325 $bankaccountstatic->label = $objp->baref;
4326 $bankaccountstatic->number = $objp->banumber;
4328 if (! empty($conf->accounting->enabled)) {
4329 $bankaccountstatic->account_number = $objp->account_number;
4332 $accountingjournal->fetch($objp->fk_accountancy_journal);
4333 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0,1,1,
'',1);
4336 print
'<td align="right">';
4337 if ($bankaccountstatic->id)
4338 print $bankaccountstatic->getNomUrl(1,
'transactions');
4341 print
'<td align="right">' .
price($sign * $objp->amount) .
'</td>';
4342 print
'<td align="center">';
4345 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=deletepaiement&paiement_id='.$objp->rowid.
'">';
4365 print
'<tr><td colspan="' . $nbcols .
'" align="right">';
4367 print $langs->trans(
'AlreadyPaidNoCreditNotesNoDeposits');
4369 print $langs->trans(
'AlreadyPaid');
4370 print
' :</td><td align="right"'.(($totalpaye > 0)?
' class="amountalreadypaid"':
'').
'>' .
price($totalpaye) .
'</td><td> </td></tr>';
4372 $resteapayeraffiche = $resteapayer;
4373 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
4376 $creditnoteamount = 0;
4378 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
4379 $sql .=
" re.description, re.fk_facture_source";
4380 $sql .=
" FROM " . MAIN_DB_PREFIX .
"societe_remise_except as re";
4381 $sql .=
" WHERE fk_facture = " . $object->id;
4382 $resql = $db->query($sql);
4384 $num = $db->num_rows(
$resql);
4388 $obj = $db->fetch_object(
$resql);
4389 $invoice->fetch($obj->fk_facture_source);
4390 print
'<tr><td colspan="' . $nbcols .
'" align="right">';
4392 print $langs->trans(
"CreditNote") .
' ';
4394 print $langs->trans(
"Deposit") .
' ';
4395 print $invoice->getNomUrl(0);
4397 print
'<td align="right">' .
price($obj->amount_ttc) .
'</td>';
4398 print
'<td align="right">';
4399 print
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?facid=' . $object->id .
'&action=unlinkdiscount&discountid=' . $obj->rowid .
'">' .
img_delete() .
'</a>';
4403 $creditnoteamount += $obj->amount_ttc;
4405 $depositamount += $obj->amount_ttc;
4413 print
'<tr><td colspan="' . $nbcols .
'" align="right" class="nowrap">';
4414 print
$form->textwithpicto($langs->trans(
"Discount") .
':', $langs->trans(
"HelpEscompte"), - 1);
4415 print
'</td><td align="right">' .
price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye,
'MT')) .
'</td><td> </td></tr>';
4416 $resteapayeraffiche = 0;
4417 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4421 print
'<tr><td colspan="' . $nbcols .
'" align="right" class="nowrap">';
4422 print
$form->textwithpicto($langs->trans(
"Abandoned") .
':', $langs->trans(
"HelpAbandonBadCustomer"), - 1);
4423 print
'</td><td align="right">' .
price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye,
'MT')) .
'</td><td> </td></tr>';
4425 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4429 print
'<tr><td colspan="' . $nbcols .
'" align="right" class="nowrap">';
4430 print
$form->textwithpicto($langs->trans(
"ProductReturned") .
':', $langs->trans(
"HelpAbandonProductReturned"), - 1);
4431 print
'</td><td align="right">' .
price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye,
'MT')) .
'</td><td> </td></tr>';
4432 $resteapayeraffiche = 0;
4433 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4437 print
'<tr><td colspan="' . $nbcols .
'" align="right" class="nowrap">';
4438 $text = $langs->trans(
"HelpAbandonOther");
4439 if ($object->close_note)
4440 $text .=
'<br><br><b>' . $langs->trans(
"Reason") .
'</b>:' . $object->close_note;
4441 print
$form->textwithpicto($langs->trans(
"Abandoned") .
':', $text, - 1);
4442 print
'</td><td align="right">' .
price(
price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye,
'MT')) .
'</td><td> </td></tr>';
4443 $resteapayeraffiche = 0;
4444 $cssforamountpaymentcomplete =
'amountpaymentneutral';
4448 print
'<tr><td colspan="' . $nbcols .
'" align="right">' . $langs->trans(
"Billed") .
' :</td><td align="right">' .
price($object->total_ttc) .
'</td><td> </td></tr>';
4451 print
'<tr><td colspan="' . $nbcols .
'" align="right">';
4452 if ($resteapayeraffiche >= 0)
4453 print $langs->trans(
'RemainderToPay');
4455 print $langs->trans(
'ExcessReceived');
4457 print
'<td align="right"'.($resteapayeraffiche?
' class="amountremaintopay"':(
' class="'.$cssforamountpaymentcomplete.
'"')).
'>' .
price($resteapayeraffiche) .
'</td>';
4458 print
'<td class="nowrap"> </td></tr>';
4462 $cssforamountpaymentcomplete=
'amountpaymentneutral';
4465 print
'<tr><td colspan="' . $nbcols .
'" align="right">';
4466 print $langs->trans(
'AlreadyPaidBack');
4467 print
' :</td><td align="right">' .
price($sign * $totalpaye) .
'</td><td> </td></tr>';
4470 print
'<tr><td colspan="' . $nbcols .
'" align="right">' . $langs->trans(
"Billed") .
' :</td><td align="right">' .
price($sign * $object->total_ttc) .
'</td><td> </td></tr>';
4473 print
'<tr><td colspan="' . $nbcols .
'" align="right">';
4474 if ($resteapayeraffiche <= 0)
4475 print $langs->trans(
'RemainderToPayBack');
4477 print $langs->trans(
'ExcessPaid');
4479 print
'<td align="right"'.($resteapayeraffiche?
' class="amountremaintopayback"':(
' class="'.$cssforamountpaymentcomplete.
'"')).
'>' .
price($sign * $resteapayeraffiche) .
'</td>';
4480 print
'<td class="nowrap"> </td></tr>';
4492 if (! empty($conf->margin->enabled)) {
4493 $formmargin->displayMarginInfos($object);
4500 print
'<div class="clearboth"></div><br>';
4502 if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
4503 $blocname =
'contacts';
4504 $title = $langs->trans(
'ContactsAddresses');
4505 include DOL_DOCUMENT_ROOT .
'/core/tpl/bloc_showhide.tpl.php';
4508 if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
4509 $blocname =
'notes';
4510 $title = $langs->trans(
'Notes');
4511 include DOL_DOCUMENT_ROOT .
'/core/tpl/bloc_showhide.tpl.php';
4515 $result = $object->getLinesArray();
4518 if (! empty($conf->global->INVOICE_USE_SITUATION))
4520 if ($object->situation_cycle_ref && $object->statut == 0) {
4521 print
'<div class="div-table-responsive">';
4523 print
'<form name="updatealllines" id="updatealllines" action="' . $_SERVER[
'PHP_SELF'] .
'?id=' . $object->id .
'#updatealllines" method="POST">';
4524 print
'<input type="hidden" name="token" value="' . $_SESSION[
'newtoken'] .
'" />';
4525 print
'<input type="hidden" name="action" value="updatealllines" />';
4526 print
'<input type="hidden" name="id" value="' . $object->id .
'" />';
4528 print
'<table id="tablelines_all_progress" class="noborder noshadow" width="100%">';
4530 print
'<tr class="liste_titre nodrag nodrop">';
4533 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
4534 print
'<td align="center" width="5"> </td>';
4536 print
'<td>' . $langs->trans(
'ModifyAllLines') .
'</td>';
4537 print
'<td align="right" width="50"> </td>';
4538 print
'<td align="right" width="80"> </td>';
4539 if ($inputalsopricewithtax) print
'<td align="right" width="80"> </td>';
4540 print
'<td align="right" width="50"> </td>';
4541 print
'<td align="right" width="50"> </td>';
4542 print
'<td align="right" width="50">' . $langs->trans(
'Progress') .
'</td>';
4543 if (! empty($conf->margin->enabled) && empty($user->societe_id))
4545 print
'<td align="right" class="margininfos" width="80"> </td>';
4546 if ((! empty($conf->global->DISPLAY_MARGIN_RATES) || ! empty($conf->global->DISPLAY_MARK_RATES)) && $usercanreadallmargin) {
4547 print
'<td align="right" class="margininfos" width="50"> </td>';
4550 print
'<td align="right" width="50"> </td>';
4551 print
'<td> </td>';
4552 print
'<td width="10"> </td>';
4553 print
'<td width="10"> </td>';
4557 if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
4558 print
'<td align="center" width="5"> </td>';
4560 print
'<tr width="100%" class="nodrag nodrop">';
4561 print
'<td> </td>';
4562 print
'<td width="50"> </td>';
4563 print
'<td width="80"> </td>';
4564 print
'<td width="50"> </td>';
4565 print
'<td width="50"> </td>';
4566 print
'<td align="right" class="nowrap"><input type="text" size="1" value="" name="all_progress">%</td>';
4567 print
'<td colspan="4" align="right"><input class="button" type="submit" name="all_percent" value="Modifier" /></td>';
4578 print
' <form name="addproduct" id="addproduct" action="' . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id . (($action !=
'editline') ?
'#addline' :
'#line_' .
GETPOST(
'lineid')) .
'" method="POST"> 4579 <input type="hidden" name="token" value="' . $_SESSION [
'newtoken'] .
'"> 4580 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline') .
'"> 4581 <input type="hidden" name="mode" value=""> 4582 <input type="hidden" name="id" value="' . $object->id .
'"> 4585 if (! empty($conf->use_javascript_ajax) && $object->statut == 0) {
4586 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
4589 print
'<div class="div-table-responsive-no-min">';
4590 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
4593 if (! empty($object->lines))
4594 $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
4597 if ($object->statut == 0 && $usercancreate && $action !=
'valid' && $action !=
'editline' && ($object->is_first() || empty($object->situation_cycle_ref)))
4599 if ($action !=
'editline' && $action !=
'selectlines')
4602 $object->formAddObjectLine(1, $mysoc, $soc);
4605 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
4619 if ($action !=
'prerelance' && $action !=
'presend' && $action !=
'valid' && $action !=
'editline')
4621 print
'<div class="tabsAction">';
4624 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
4625 if (empty($reshook)) {
4630 $ventilExportCompta = $object->getVentilExportCompta();
4632 if ($ventilExportCompta == 0)
4634 if (! empty($conf->global->INVOICE_CAN_ALWAYS_BE_EDITED) || ($resteapayer == $object->total_ttc && empty($object->paye)))
4636 if (! $objectidnext && $object->is_last_in_cycle())
4638 if ($usercanunvalidate)
4640 print
'<div class="inline-block divButAction"><a class="butAction'.($conf->use_javascript_ajax?
' reposition':
'').
'" href="' . $_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id .
'&action=modif">' . $langs->trans(
'Modify') .
'</a></div>';
4642 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans(
"NotEnoughPermissions") .
'">' . $langs->trans(
'Modify') .
'</span></div>';
4644 }
else if (!$object->is_last_in_cycle()) {
4645 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans(
"NotLastInCycle") .
'">' . $langs->trans(
'Modify') .
'</span></div>';
4647 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans(
"DisabledBecauseReplacedInvoice") .
'">' . $langs->trans(
'Modify') .
'</span></div>';
4653 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans(
"DisabledBecauseDispatchedInBookkeeping") .
'">' . $langs->trans(
'Modify') .
'</span></div>';
4658 $result = $discount->fetch(0, $object->id);
4664 && ($object->statut == 2 || $object->statut == 3 || ($object->statut == 1 && $object->paye == 1))
4665 && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || $usercanreopen))
4667 if (! $objectidnext && $object->close_code !=
'replaced')
4669 print
'<div class="inline-block divButAction"><a class="butAction'.($conf->use_javascript_ajax?
' reposition':
'').
'" href="' . $_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id .
'&action=reopen">' . $langs->trans(
'ReOpen') .
'</a></div>';
4671 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans(
"DisabledBecauseReplacedInvoice") .
'">' . $langs->trans(
'ReOpen') .
'</span></div>';
4677 if ($usercanvalidate)
4679 print
'<div class="inline-block divButAction"><a class="butAction'.($conf->use_javascript_ajax?
' reposition':
'').
'" href="' . $_SERVER[
"PHP_SELF"] .
'?facid=' . $object->id .
'&action=valid">' . $langs->trans(
'Validate') .
'</a></div>';
4685 if ($objectidnext) {
4686 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans(
"DisabledBecauseReplacedInvoice") .
'">' . $langs->trans(
'SendMail') .
'</span></div>';
4689 print
'<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id .
'&action=presend&mode=init#formmailbeforetitle">' . $langs->trans(
'SendMail') .
'</a></div>';
4691 print
'<div class="inline-block divButAction"><a class="butActionRefused" href="#">' . $langs->trans(
'SendMail') .
'</a></div>';
4698 if ($resteapayer > 0)
4700 if ($usercancreatewithdrarequest)
4702 if (! $objectidnext && $object->close_code !=
'replaced')
4704 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>';
4706 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans(
"DisabledBecauseReplacedInvoice") .
'">' . $langs->trans(
'MakeWithdrawRequest') .
'</span></div>';
4722 if ($objectidnext) {
4723 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans(
"DisabledBecauseReplacedInvoice") .
'">' . $langs->trans(
'DoPayment') .
'</span></div>';
4728 print
'<div class="inline-block divButAction"><a class="butAction" href="'. DOL_URL_ROOT .
'/compta/paiement.php?facid=' . $object->id .
'&action=create&accountid='.$object->fk_account.
'">' . $langs->trans(
'DoPayment') .
'</a></div>';
4738 if ($resteapayer == 0)
4740 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPaymentBack').
'</span></div>';
4744 print
'<div class="inline-block divButAction"><a class="butAction" href="'. DOL_URL_ROOT .
'/compta/paiement.php?facid='.$object->id.
'&action=create&accountid='.$object->fk_account.
'">'.$langs->trans(
'DoPaymentBack').
'</a></div>';
4749 if ($object->type ==
Facture::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits) < 0 && $usercancreate && empty($discount->id))
4751 print
'<div class="inline-block divButAction"><a class="butAction'.($conf->use_javascript_ajax?
' reposition':
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertExcessReceivedToReduc').
'</a></div>';
4754 if ($object->type ==
Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $usercancreate && $object->getSommePaiement() == 0) {
4755 print
'<div class="inline-block divButAction"><a class="butAction'.($conf->use_javascript_ajax?
' reposition':
'').
'" href="' . $_SERVER[
"PHP_SELF"] .
'?facid=' . $object->id .
'&action=converttoreduc">' . $langs->trans(
'ConvertToReduc') .
'</a></div>';
4758 if ($object->type ==
Facture::TYPE_DEPOSIT && $usercancreate && $object->statut > 0 && empty($discount->id))
4760 print
'<div class="inline-block divButAction"><a class="butAction'.($conf->use_javascript_ajax?
' reposition':
'').
'" href="'.$_SERVER[
"PHP_SELF"].
'?facid='.$object->id.
'&action=converttoreduc">'.$langs->trans(
'ConvertToReduc').
'</a></div>';
4766 || ($object->type ==
Facture::TYPE_DEPOSIT && $object->paye == 0 && $object->total_ttc > 0 && $resteapayer == 0 && $usercanissuepayment && empty($discount->id))
4769 print
'<div class="inline-block divButAction"><a class="butAction'.($conf->use_javascript_ajax?
' reposition':
'').
'" href="'.$_SERVER[
'PHP_SELF'].
'?facid='.$object->id.
'&action=paid">'.$langs->trans(
'ClassifyPaid').
'</a></div>';
4774 if ($object->statut == 1 && $object->paye == 0 && $resteapayer > 0 && $usercanissuepayment)
4776 if ($totalpaye > 0 || $totalcreditnotes > 0)
4779 print
'<div class="inline-block divButAction"><a class="butAction'.($conf->use_javascript_ajax?
' reposition':
'').
'" href="' . $_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id .
'&action=paid">' . $langs->trans(
'ClassifyPaidPartially') .
'</a></div>';
4783 if ( empty($conf->global->INVOICE_CAN_NEVER_BE_CANCELED))
4787 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans(
"DisabledBecauseReplacedInvoice") .
'">' . $langs->trans(
'ClassifyCanceled') .
'</span></div>';
4791 print
'<div class="inline-block divButAction"><a class="butAction'.($conf->use_javascript_ajax?
' reposition':
'').
'" href="' . $_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id .
'&action=canceled">' . $langs->trans(
'ClassifyCanceled') .
'</a></div>';
4800 print
'<div class="inline-block divButAction"><a class="butAction'.($conf->use_javascript_ajax?
' reposition':
'').
'" href="' . $_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id .
'&action=clone&object=invoice">' . $langs->trans(
"ToClone") .
'</a></div>';
4806 if (! $objectidnext && count($object->lines) > 0)
4808 print
'<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.
'/compta/facture/fiche-rec.php?facid=' . $object->id .
'&action=create">' . $langs->trans(
"ChangeIntoRepeatableInvoice") .
'</a></div>';
4815 if (! $objectidnext)
4817 print
'<div class="inline-block divButAction"><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 :
'').
'">' . $langs->trans(
"CreateCreditNote") .
'</a></div>';
4823 && ($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits) > 0
4826 && $object->is_last_in_cycle()
4827 && $conf->global->INVOICE_USE_SITUATION_CREDIT_NOTE
4830 if ($usercanunvalidate)
4832 print
'<div class="inline-block divButAction"><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></div>';
4834 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans(
"NotEnoughPermissions") .
'">' . $langs->trans(
"CreateCreditNote") .
'</span></div>';
4843 && $object->situation_counter > 1
4844 && $object->is_last_in_cycle()
4845 && $usercanunvalidate
4848 if(($object->total_ttc - $totalcreditnotes ) == 0 )
4850 print
'<div class="inline-block divButAction"><a id="butSituationOut" class="butAction" href="' . $_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id .
'&action=situationout">' . $langs->trans(
"RemoveSituationFromCycle") .
'</a></div>';
4854 print
'<div class="inline-block divButAction"><a id="butSituationOutRefused" class="butActionRefused" href="#" title="' . $langs->trans(
"DisabledBecauseNotEnouthCreditNote") .
'" >' . $langs->trans(
"RemoveSituationFromCycle") .
'</a></div>';
4859 if ($usercancreate && ($object->type == 5) && ($object->statut == 1 || $object->statut == 2)) {
4860 if ($object->is_last_in_cycle() && $object->situation_final != 1) {
4861 print
'<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER[
'PHP_SELF'] .
'?action=create&type=5&origin=facture&originid=' . $object->id .
'&socid=' . $object->socid .
'" >' . $langs->trans(
'CreateNextSituationInvoice') .
'</a></div>';
4862 }
else if (!$object->is_last_in_cycle()) {
4863 print
'<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs->trans(
"DisabledBecauseNotLastInCycle") .
'">' . $langs->trans(
'CreateNextSituationInvoice') .
'</a></div>';
4865 print
'<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs->trans(
"DisabledBecauseFinal") .
'">' . $langs->trans(
'CreateNextSituationInvoice') .
'</a></div>';
4870 $isErasable = $object->is_erasable();
4871 if ($usercandelete || ($usercancreate && $isErasable == 1))
4874 if ($isErasable == -4) {
4875 print
'<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs->trans(
"DisabledBecausePayments") .
'">' . $langs->trans(
'Delete') .
'</a></div>';
4877 elseif ($isErasable == -3) {
4878 print
'<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs->trans(
"DisabledBecauseNotLastSituationInvoice") .
'">' . $langs->trans(
'Delete') .
'</a></div>';
4880 elseif ($isErasable == -2) {
4881 print
'<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs->trans(
"DisabledBecauseNotLastInvoice") .
'">' . $langs->trans(
'Delete') .
'</a></div>';
4883 elseif ($isErasable == -1) {
4884 print
'<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs->trans(
"DisabledBecauseDispatchedInBookkeeping") .
'">' . $langs->trans(
'Delete') .
'</a></div>';
4886 elseif ($isErasable <= 0)
4888 print
'<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs->trans(
"DisabledBecauseNotErasable") .
'">' . $langs->trans(
'Delete') .
'</a></div>';
4890 elseif ($objectidnext)
4892 print
'<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs->trans(
"DisabledBecauseReplacedInvoice") .
'">' . $langs->trans(
'Delete') .
'</a></div>';
4896 print
'<div class="inline-block divButAction"><a class="butActionDelete'.($conf->use_javascript_ajax?
' reposition':
'').
'" href="' . $_SERVER[
"PHP_SELF"] .
'?facid=' . $object->id .
'&action=delete">' . $langs->trans(
'Delete') .
'</a></div>';
4899 print
'<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs->trans(
"NotAllowed") .
'">' . $langs->trans(
'Delete') .
'</a></div>';
4906 if (
GETPOST(
'modelselected',
'alpha')) {
4907 $action =
'presend';
4909 if ($action !=
'prerelance' && $action !=
'presend')
4911 print
'<div class="fichecenter"><div class="fichehalfleft">';
4912 print
'<a name="builddoc"></a>';
4917 $urlsource = $_SERVER[
'PHP_SELF'] .
'?facid=' . $object->id;
4918 $genallowed = $usercanread;
4919 $delallowed = $usercancreate;
4921 print $formfile->showdocuments(
'facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0,
'',
'',
'', $soc->default_lang);
4922 $somethingshown = $formfile->numoffiles;
4925 $linktoelem =
$form->showLinkToObjectBlock($object, null, array(
'invoice'));
4927 $compatibleImportElementsList =
false;
4932 $compatibleImportElementsList = array(
'commande',
'propal');
4934 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem,$compatibleImportElementsList);
4938 $useonlinepayment = (! empty($conf->paypal->enabled) || ! empty($conf->stripe->enabled) || ! empty($conf->paybox->enabled));
4942 print
'<br><!-- Link to pay -->'.
"\n";
4943 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
4944 print showOnlinePaymentUrl(
'invoice', $object->ref).
'<br>';
4948 if ($object->statut !=
Facture::STATUS_DRAFT && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD))
4950 print
'<br><!-- Link to download main doc -->'.
"\n";
4954 print
'</div><div class="fichehalfright"><div class="ficheaddleft">';
4957 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formactions.class.php';
4959 $somethingshown =
$formactions->showactions($object,
'invoice', $socid, 1);
4961 print
'</div></div></div>';
4966 $modelmail=
'facture_send';
4967 $defaulttopic=
'SendBillRef';
4968 $diroutput = $conf->facture->dir_output;
4969 $trackid =
'inv'.$object->id;
4971 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
print $object label
hash of file content (md5_file(dol_osencode($destfull))
File of class to manage predefined price products or services by customer.
img_warning($titlealt='default', $moreatt='')
Show warning logo.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage notifications.
const TYPE_STANDARD
Standard invoice.
print
Draft customers invoices.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') else if($action=='specimen') else if($action=='setmodel') else if($action=='del') else if($action=='setdoc') $formactions
View.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Class to manage products or services.
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.
Class to manage invoice templates.
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...
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_concatdesc($text1, $text2, $forxml=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
$conf db name
Only used if Module[ID]Name translation string is not found.
const TYPE_PROFORMA
Proforma invoice (should not be used.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
const TYPE_SITUATION
Situation invoice.
Class to manage bank accounts.
img_delete($titlealt='default', $other='class="pictodelete"')
Show delete logo.
const TYPE_CREDIT_NOTE
Credit note invoice.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
showDirectDownloadLink($object)
Return string with full Url.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting a parameter.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
const STATUS_VALIDATED
Validated (need to be paid)
Class to manage projects.
if(! function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='')
Show information for admin users or standard users.
Class to manage shipments.
dol_fiche_end($notab=0)
Show tab footer of a card.
const STATUS_DRAFT
Draft status.
Class to manage payments of customer invoices.
Class to manage translations.
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
const STATUS_CLOSED
Classified paid.
dol_now($mode='gmt')
Return date for now.
Class ProductCombination Used to represent a product combination.
if($_POST["cancel"]==$langs->trans("Cancel") &&! $id) if($action=='add' && $_POST["cancel"]<> $langs->trans("Cancel")) if($action=='delete') if($id) $form
Actions.
const STATUS_ABANDONED
Classified abandoned and no payment done.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
const TYPE_DEPOSIT
Deposit invoice.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
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.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) Si ...
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage accounting accounts.
Class to manage invoices.
fieldLabel($langkey, $fieldkey, $fieldrequired=0)
Show a string with the label tag dedicated to the HTML edit field.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
Class to manage invoice lines.
Class to manage warehouses.
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
static getIdAndTxFromCode(&$db, $code, $date_document='')
Get id and rate of currency from code.