39require
'../../main.inc.php';
49require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
57$langs->loadLangs(array(
'companies',
'bills',
'banks',
'compta'));
59$action =
GETPOST(
'action',
'alpha');
60$confirm =
GETPOST(
'confirm',
'alpha');
61$optioncss =
GETPOST(
'optioncss',
'alpha');
62$cancel =
GETPOST(
'cancel',
'alpha');
63$backtopage =
GETPOST(
'backtopage',
'alpha');
64$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
73$search_ref =
GETPOST(
'search_ref',
'alpha');
74$search_account =
GETPOST(
'search_account',
'alpha');
75$search_paymenttype =
GETPOST(
'search_paymenttype');
76$search_amount =
GETPOST(
'search_amount',
'alpha');
77$search_company =
GETPOST(
'search_company',
'alpha');
78$search_payment_num =
GETPOST(
'search_payment_num',
'alpha');
80$displayAllInvoices =
getDolGlobalInt(
'MAIN_PAIMENTS_SHOW_ALL_INVOICE_TYPES', 0);
82 $displayAllInvoices =
GETPOSTINT(
'display-all-invoices');
86$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
87$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
89if (empty($page) || $page == -1) {
92$offset = $limit * $page;
99 $sortfield =
"p.rowid";
103$amountsresttopay = array();
106$multicurrency_amounts = array();
107$multicurrency_amountsresttopay = array();
110if ($user->socid > 0) {
111 $socid = $user->socid;
117$hookmanager->initHooks(array(
'paymentsupplierlist'));
121$extrafields->fetch_name_optionals_label(
$object->table_element);
123$search_array_options = $extrafields->getOptionalsFromPost(
$object->table_element,
'',
'search_');
125$arrayfields = array();
127$permissiontoadd = ($user->hasRight(
"fournisseur",
"facture",
"creer") || $user->hasRight(
"supplier_invoice",
"creer"));
134if ($facid > 0 && $invoicetocheck->fetch($facid) > 0) {
145 if (!empty($backtopageforcancel)) {
146 header(
"Location: ".$backtopageforcancel);
148 } elseif (!empty($backtopage)) {
149 header(
"Location: ".$backtopage);
152 header(
"Location: ".DOL_URL_ROOT.
'/fourn/facture/list.php');
156if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
158 $search_account =
"";
160 $search_paymenttype =
"";
161 $search_payment_num =
"";
162 $search_company =
"";
166 $search_array_options = array();
169$parameters = array(
'socid' => $socid);
170$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
172 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
175$formquestion = array();
176if (empty($reshook)) {
177 if (($action ==
'add_paiement' || ($action ==
'confirm_paiement' && $confirm ==
'yes')) && $permissiontoadd) {
181 $atleastonepaymentnotnull = 0;
182 $multicurrency_totalpayment = 0;
188 foreach (array_merge($_GET, $_POST) as $key => $value) {
189 if (substr($key, 0, 7) ==
'amount_') {
190 $cursorfacid = (int) substr($key, 7);
192 if (!empty($amounts[$cursorfacid])) {
193 $atleastonepaymentnotnull++;
194 if (is_numeric($amounts[$cursorfacid])) {
195 $totalpayment += (float) $amounts[$cursorfacid];
197 setEventMessages($langs->transnoentities(
"InputValueIsNotAnNumber",
GETPOST($key)),
null,
'warnings');
200 $result = $tmpinvoice->fetch($cursorfacid);
202 dol_print_error($db);
206 $amountsresttopay[$cursorfacid] =
price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
207 if ($amounts[$cursorfacid]) {
209 if ((abs((
float) $amounts[$cursorfacid]) > abs((
float) $amountsresttopay[$cursorfacid]))) {
211 $formquestion[
'text'] = img_warning($langs->trans(
"PaymentHigherThanReminderToPay")).
' '.$langs->trans(
"HelpPaymentHigherThanReminderToPaySupplier");
214 if ($datepaye && ($datepaye < $tmpinvoice->
date)) {
215 $langs->load(
"errors");
217 setEventMessages($langs->transnoentities(
"WarningPaymentDateLowerThanInvoiceDate",
dol_print_date($datepaye,
'day'),
dol_print_date($tmpinvoice->date,
'day'), $tmpinvoice->ref),
null,
'warnings');
221 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' => $key,
'value' =>
GETPOST($key));
222 } elseif (substr($key, 0, 21) ==
'multicurrency_amount_') {
223 $cursorfacid = (int) substr($key, 21);
225 $multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid];
226 if (!empty($multicurrency_amounts[$cursorfacid])) {
227 $atleastonepaymentnotnull++;
229 $result = $tmpinvoice->fetch($cursorfacid);
231 dol_print_error($db);
235 $multicurrency_amountsresttopay[$cursorfacid] =
price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1));
236 if ($multicurrency_amounts[$cursorfacid]) {
238 if ((abs((
float) $multicurrency_amounts[$cursorfacid]) > abs((
float) $multicurrency_amountsresttopay[$cursorfacid]))) {
240 $formquestion[
'text'] = img_warning($langs->trans(
"PaymentHigherThanReminderToPay")).
' '.$langs->trans(
"HelpPaymentHigherThanReminderToPaySupplier");
243 if ($datepaye && ($datepaye < $tmpinvoice->
date)) {
244 $langs->load(
"errors");
246 setEventMessages($langs->transnoentities(
"WarningPaymentDateLowerThanInvoiceDate",
dol_print_date($datepaye,
'day'),
dol_print_date($tmpinvoice->date,
'day'), $tmpinvoice->ref),
null,
'warnings');
250 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' => $key,
'value' =>
GETPOSTFLOAT($key));
255 if (
GETPOST(
'paiementid') <= 0) {
256 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->transnoentities(
'PaymentMode')),
null,
'errors');
262 if (
GETPOST(
'accountid') <= 0) {
263 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->transnoentities(
'AccountToCredit')),
null,
'errors');
268 if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull)) {
269 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->trans(
'PaymentAmount')),
null,
'errors');
273 if (empty($datepaye)) {
274 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->transnoentities(
'Date')),
null,
'errors');
279 if ($totalpayment > 0 && $multicurrency_totalpayment > 0) {
280 setEventMessages($langs->transnoentities(
'ErrorPaymentInBothCurrency'),
null,
'errors');
288 if ($action ==
'add_paiement') {
299 if ($action ==
'confirm_paiement' && $confirm ==
'yes' && $permissiontoadd) {
302 $multicurrency_code = array();
303 $multicurrency_tx = array();
306 foreach ($amounts as $key => $value) {
308 $tmpinvoice->fetch($key);
311 $amounts[$key] = - abs((
float) $newvalue);
313 $multicurrency_code[$key] = $tmpinvoice->multicurrency_code;
314 $multicurrency_tx[$key] = $tmpinvoice->multicurrency_tx;
317 foreach ($multicurrency_amounts as $key => $value) {
319 $tmpinvoice->fetch($key);
322 $multicurrency_amounts[$key] = - abs((
float) $newvalue);
324 $multicurrency_code[$key] = $tmpinvoice->multicurrency_code;
325 $multicurrency_tx[$key] = $tmpinvoice->multicurrency_tx;
331 $thirdparty =
new Societe($db);
333 $thirdparty->fetch($socid);
338 $paiement->datepaye = $datepaye;
340 $correctedAmounts = [];
341 foreach ($amounts as $key => $value) {
342 $correctedAmounts[$key] = (float) $value;
345 $paiement->amounts = $correctedAmounts;
346 $paiement->multicurrency_amounts = $multicurrency_amounts;
347 $paiement->multicurrency_code = $multicurrency_code;
348 $paiement->multicurrency_tx = $multicurrency_tx;
349 $paiement->paiementid =
GETPOSTINT(
'paiementid');
350 $paiement->num_payment =
GETPOST(
'num_paiement',
'alphanohtml');
351 $paiement->note_private =
GETPOST(
'comment',
'alpha');
352 $paiement->fk_account =
GETPOSTINT(
'accountid');
357 $paiement_id = $paiement->create($user, (
GETPOST(
'closepaidinvoices') ==
'on' ? 1 : 0), $thirdparty);
358 if ($paiement_id < 0) {
359 setEventMessages($paiement->error, $paiement->errors,
'errors');
364 $result = $paiement->addPaymentToBank($user,
'payment_supplier',
'(SupplierInvoicePayment)', $accountid,
GETPOST(
'chqemetteur'),
GETPOST(
'chqbank'));
366 setEventMessages($paiement->error, $paiement->errors,
'errors');
376 foreach ($paiement->amounts as $key => $amount) {
378 if (is_numeric($amount) && $amount != 0) {
379 if ($invoiceid != 0) {
386 if ($invoiceid > 0) {
387 $loc = DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$invoiceid;
389 $loc = DOL_URL_ROOT.
'/fourn/paiement/card.php?id='.$paiement_id;
391 header(
'Location: '.$loc);
405$form =
new Form($db);
408$supplierstatic =
new Societe($db);
411llxHeader(
'', $langs->trans(
'ListPayment'),
'',
'', 0, 0,
'',
'',
'',
'mod-fourn-facture page-paiement');
414$useajaxconfirm = (!empty(
$conf->use_javascript_ajax) && empty(
$conf->dol_use_jmobile)) ? 1 : 0;
416if ($action ==
'create' || $action ==
'confirm_paiement' || $action ==
'add_paiement') {
418 $result =
$object->fetch($facid);
421 $dateinvoice = ($datefacture ==
'' ? (
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datefacture);
423 $sql =
'SELECT s.nom as name, s.rowid as socid,';
424 $sql .=
' f.rowid, f.ref, f.ref_supplier, f.total_ttc as total, f.fk_mode_reglement, f.fk_account';
425 if (!$user->hasRight(
"societe",
"client",
"voir") && !$socid) {
426 $sql .=
", sc.fk_soc, sc.fk_user ";
428 $sql .=
' FROM '.MAIN_DB_PREFIX.
'societe as s, '.MAIN_DB_PREFIX.
'facture_fourn as f';
429 if (!$user->hasRight(
"societe",
"client",
"voir") && !$socid) {
430 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
432 $sql .=
' WHERE f.fk_soc = s.rowid';
433 $sql .=
' AND f.rowid = '.((int) $facid);
434 if (!$user->hasRight(
"societe",
"client",
"voir") && !$socid) {
435 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
437 $resql = $db->query($sql);
439 $totalnboflines = $num = $db->num_rows($resql);
441 $obj = $db->fetch_object($resql);
442 $total = $obj->total;
447 if (!empty(
$conf->use_javascript_ajax)) {
448 print
"\n".
'<script type="text/javascript">';
449 print
'$(document).ready(function () {
451 function _elemToJson(selector)
454 $.map(selector.serializeArray(), function(n,i)
456 subJson[n["name"]] = n["value"];
461 function callForResult(imgId)
463 console.log("callForResult Calculate total of payment");
465 var form = $("#payment_form");
467 json["invoice_type"] = $("#invoice_type").val();
468 json["amountPayment"] = $("#amountpayment").attr("value");
469 json["amounts"] = _elemToJson(form.find("input.amount"));
470 json["remains"] = _elemToJson(form.find("input.remain"));
471 json["token"] = "'.currentToken().
'";
473 json["imgClicked"] = imgId;
476 $.post("'.DOL_URL_ROOT.
'/compta/ajaxpayment.php", json, function(data)
478 json = $.parseJSON(data);
482 for (var key in json)
484 if (key == "result") {
485 if (json["makeRed"]) {
486 $("#"+key).addClass("error");
488 $("#"+key).removeClass("error");
490 json[key]=json["label"]+" "+json[key];
491 $("#"+key).text(json[key]);
492 } else {console.log(key);
493 form.find("input[name*=\""+key+"\"]").each(function() {
494 $(this).attr("value", json[key]);
501 $("#payment_form").find("input.amount").change(function() {
504 $("#payment_form").find("input.amount").keyup(function() {
512 print
' $(document).ready(function () {';
513 print
' $(".AutoFillAmount").on(\'click touchstart\', function(e){
515 $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
519 print
' </script>'.
"\n";
522 print
'<form id="payment_form" name="addpaiement" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
523 print
'<input type="hidden" name="token" value="'.newToken().
'">';
524 print
'<input type="hidden" name="action" value="add_paiement">';
525 print
'<input type="hidden" name="display-all-invoices" value="'.(int) $displayAllInvoices.
'">';
526 print
'<input type="hidden" name="facid" value="'.$facid.
'">';
527 print
'<input type="hidden" name="ref_supplier" value="'.$obj->ref_supplier.
'">';
528 print
'<input type="hidden" name="socid" value="'.$obj->socid.
'">';
529 print
'<input type="hidden" name="type" id="invoice_type" value="'.$object->type.
'">';
530 print
'<input type="hidden" name="societe" value="'.$obj->name.
'">';
531 print
'<input type="hidden" name="page_y" value="">';
535 print
'<table class="border centpercent">';
537 print
'<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans(
'Company').
'</td><td>';
538 $supplierstatic->id = $obj->socid;
539 $supplierstatic->name = $obj->name;
540 print $supplierstatic->getNomUrl(1,
'supplier');
543 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Date').
'</td><td>';
545 $adddateof = array(array(
'adddateof' =>
$object->date));
546 $adddateof[] = array(
'adddateof' =>
$object->date_echeance,
'labeladddateof' => $langs->transnoentities(
'DateDue'));
547 print $form->selectDate($dateinvoice,
'', 0, 0, 0,
"addpaiement", 1, 1, 0,
'',
'', $adddateof);
549 print
'<tr><td class="fieldrequired">'.$langs->trans(
'PaymentMode').
'</td><td>';
550 print img_picto(
'',
'bank',
'class="pictofixedwidth"');
551 $form->select_types_paiements(!
GETPOST(
'paiementid') ? $obj->fk_mode_reglement :
GETPOST(
'paiementid'),
'paiementid');
554 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Account').
'</td><td>';
555 print img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
556 print $form->select_comptes(empty($accountid) ? $obj->fk_account : $accountid,
'accountid', 0,
'', 2,
'', 0,
'widthcentpercentminusx maxwidth500', 1);
559 print
'<tr><td> </td></tr>';
561 print
'<tr><td>'.$langs->trans(
'Numero');
562 print
' <em class="opacitymedium small">('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
563 print
'</td><td><input name="num_paiement" type="text" value="'.(!
GETPOST(
'num_paiement') ?
'' :
GETPOST(
'num_paiement')).
'"></td></tr>';
564 print
'<tr><td>'.$langs->trans(
'Comments').
'</td>';
565 print
'<td class="tdtop">';
566 print
'<textarea name="comment" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.
'">'.(!
GETPOST(
'comment') ?
'' :
GETPOST(
'comment')).
'</textarea></td></tr>';
574 $reshook = $hookmanager->executeHooks(
'paymentsupplierinvoices', $parameters, $object, $action);
575 $error = $hookmanager->error;
576 $errors = $hookmanager->errors;
577 if (empty($reshook)) {
581 $sql =
'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.type, f.total_ht, f.total_ttc,';
582 $sql .=
' f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc,';
583 $sql .=
' f.datef as df, f.date_lim_reglement as dlr,';
584 $sql .=
' SUM(pf.amount) as am, SUM(pf.multicurrency_amount) as multicurrency_am';
585 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_fourn as f';
586 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
587 $sql .=
' WHERE f.entity = '.((int)
$conf->entity);
588 $sql .=
' AND (f.fk_soc = '.((int)
$object->socid);
589 $aux =
$object->fetch_thirdparty();
592 $sql .=
' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe WHERE parent = '.((int)
$object->thirdparty->parent).
')';
596 $sql .=
' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe WHERE parent = '.((int)
$object->thirdparty->id).
')';
598 $sql .=
') AND f.paye = 0';
599 $sql .=
' AND f.fk_statut = 1';
601 if (!$displayAllInvoices) {
603 $sql .=
' AND f.type IN (0,1,3,5)';
605 $sql .=
' AND f.type = 2';
610 $sql .=
' GROUP BY f.datef, f.ref, f.ref_supplier, f.rowid, f.type, f.total_ht, f.total_ttc,';
611 $sql .=
' f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc,';
612 $sql .=
' f.datef, f.date_lim_reglement';
614 $sql .=
' ORDER BY f.datef ASC, f.ref ASC';
616 $resql = $db->query($sql);
618 $num = $db->num_rows($resql);
622 if (!empty(
$conf->use_javascript_ajax)) {
624 print
"\n".
'<script type="text/javascript">';
625 print
' $(document).ready(function () {';
626 print
' $(".AutoFillAmount").on(\'click touchstart\', function(e){
628 $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value"));
631 print
' </script>'.
"\n";
635 if ($action ==
'create') {
636 $urlToggleDisplayMod = $_SERVER[
"PHP_SELF"].
'?facid='.((int) $facid).
'&action='.urlencode($action).
'&accountid='.((int) $accountid).
'&display-all-invoices=' . (intval(!$displayAllInvoices));
638 if (empty($displayAllInvoices)) {
639 $btnTitle = $langs->trans(
'DisplayOtherInvoicesToo');
641 $btnTitle = $langs->trans(
'DisplayCreditNotesToo');
644 $btnTitle = $langs->trans(
'HideOtherInvoices');
646 $btnTitle = $langs->trans(
'HideCreditNotes');
651 $btnCssGray = empty($displayAllInvoices) ?
' opacitymediumbycolor' :
'';
652 $moreHtmlRight .=
'<a class="btnTitle" title="'.dolPrintHTMLForAttribute($btnTitle).
'" href="'.
dol_escape_htmltag($urlToggleDisplayMod).
'">';
653 $moreHtmlRight .=
'<span class="fa '.(empty($displayAllInvoices) ?
'fa-plus' :
'fa-minus').
' btnTitle-icon inline-blockimp valignmiddle'.$btnCssGray.
'" style="font-size:1.6em"></span>';
654 $moreHtmlRight .= img_picto(
'', empty($displayAllInvoices) ?
'supplier_invoicea_nocolor' :
'supplier_invoicea',
'style="font-size:1.6em"', 0, 0, 1,
'',
'inline-blockimp valignmiddle marginleftonlyshort'.$btnCssGray);
655 $moreHtmlRight .=
'</a>';
658 print_barre_liste($langs->trans(
'Invoices'), 0, $_SERVER[
"PHP_SELF"],
'',
'',
'',
'', $num, $totalnboflines,
'bill', 0, $moreHtmlRight,
'', 0, 0, 0, 1);
661 print
'<div class="div-table-responsive-no-min">';
662 print
'<table id="fourn-invoices-paiments-list" data-display-all-invoices="' . (int) $displayAllInvoices .
'" class="tagtable liste" >'.
"\n";
664 print
'<tr class="liste_titre">';
665 print
'<th>'.$langs->trans(
'Invoice').
'</th>';
667 if ($displayAllInvoices) {
668 print
'<th class="center">' . $langs->trans(
'Type') .
'</th>';
670 print
'<th class="center">'.$langs->trans(
'Date').
'</th>';
671 print
'<th class="center">'.$langs->trans(
'DateDue').
'</th>';
673 $langs->load(
"multicurrency");
674 $labeltoshow = $langs->trans(
"MulticurrencyOriginalCurrency");
675 print
'<th>'.$langs->trans(
'Currency').
'</th>';
676 print
'<th class="right">'.$langs->trans(
'AmountTTC').
' <span class="opacitymedium small nowraponall">('.$labeltoshow.
')</span></th>';
677 print
'<th class="right">'.$langs->trans(
'AlreadyPaid').
' <span class="opacitymedium small nowraponall">('.$labeltoshow.
')</span></th>';
678 print
'<th class="right">'.$langs->trans(
'RemainderToPay').
' <span class="opacitymedium small nowraponall">('.$labeltoshow.
')</span></th>';
679 print
'<th class="center">'.$langs->trans(
'PaymentAmount').
' <span class="opacitymedium small nowraponall">('.$labeltoshow.
')</span></th>';
681 print
'<th class="right">'.$langs->trans(
'AmountTTC').
'</th>';
682 print
'<th class="right">'.$langs->trans(
'AlreadyPaid').
'</th>';
683 print
'<th class="right">'.$langs->trans(
'RemainderToPay').
'</th>';
684 print
'<th class="center">'.$langs->trans(
'PaymentAmount').
'</th>';
692 $totalrecucreditnote = 0;
693 $totalrecudeposits = 0;
695 $objp = $db->fetch_object($resql);
703 $invoice->fetch($objp->facid);
705 $invoicesupplierstatic->ref = $objp->ref;
706 $invoicesupplierstatic->id = $objp->facid;
708 $paiement = $invoice->getSommePaiement();
709 $creditnotes = $invoice->getSumCreditNotesUsed();
710 $deposits = $invoice->getSumDepositsUsed();
711 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
712 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
715 $multicurrency_payment = 0;
716 $multicurrency_creditnotes = 0;
717 $multicurrency_deposits = 0;
718 $multicurrency_remaintopay = 0;
720 $multicurrency_payment = $invoice->getSommePaiement(1);
721 $multicurrency_creditnotes = $invoice->getSumCreditNotesUsed(1);
722 $multicurrency_deposits = $invoice->getSumDepositsUsed(1);
723 $multicurrency_alreadypayed = (float)
price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits,
'MT');
724 $multicurrency_remaintopay = (float)
price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits,
'MT');
727 print
'<tr data-row-type="'.$objp->type.
'" class="oddeven'.(($invoice->id == $facid) ?
' highlight' :
'').
'">';
730 print
'<td data-col="object-name" class="nowraponall">';
731 print
'<div class="inline-block lineheightsmall">';
732 print
'<span data-field="ref">';
733 print $invoicesupplierstatic->getNomUrl(1);
735 print
'<br class="paiement-line-break-for-ref">';
736 print
'<span class="spantitle" data-field="ref-supplier" title="'.$langs->trans(
"RefSupplier").
'">';
746 if ($displayAllInvoices) {
754 print
'<td class="center nowraponall">' . $typearray[$objp->type] .
'</td>';
759 print
'<td data-col="datef" data-col-value="'.$db->jdate($objp->df).
'" class="center nowraponall">';
762 print
'<td data-col="datef" data-col-value="" class="center"><b>!!!</b></td>';
766 if ($objp->dlr > 0) {
767 print
'<td data-col="dater" data-col-value="'.$db->jdate($objp->dlr).
'" class="center nowraponall">';
770 if ($invoice->hasDelay()) {
771 print img_warning($langs->trans(
'Late'));
776 print
'<td data-col="dater" data-col-value="" class="center"><b>--</b></td>';
782 print
'<td data-col="multicurrency-code" class="center">'.$objp->multicurrency_code.
"</td>\n";
784 print
'<td data-col="multicurrency-total-ttc" class="right">';
785 if ($objp->multicurrency_code && $objp->multicurrency_code !=
$conf->currency) {
786 print
'<span class="amount">'.price($objp->multicurrency_total_ttc, 0, $langs, 0, -1, -1, $objp->multicurrency_code).
'</span>';
790 print
'<td data-col="multicurrency-payment" class="right">';
791 if ($objp->multicurrency_code && $objp->multicurrency_code !=
$conf->currency) {
792 print
'<span class="amount">'.price($sign * $multicurrency_payment, 0, $langs, 0, -1, -1, $objp->multicurrency_code);
793 if ($multicurrency_creditnotes) {
794 print
'+'.price($multicurrency_creditnotes, 0, $langs, 0, -1, -1, $objp->multicurrency_code);
796 if ($multicurrency_deposits) {
797 print
'+'.price($multicurrency_deposits, 0, $langs, 0, -1, -1, $objp->multicurrency_code);
803 print
'<td data-col="remain-to-pay" class="right">';
804 if ($objp->multicurrency_code && $objp->multicurrency_code !=
$conf->currency) {
805 print
'<span class="amount">'.price($sign * (
float) $multicurrency_remaintopay, 0, $langs, 0, -1, -1, $objp->multicurrency_code).
'</span>';
809 print
'<td data-col="remain-to-pay-multicurrency-amount" class="right">';
811 $namef =
'multicurrency_amount_'.$objp->facid;
812 $nameRemain =
'multicurrency_remain_'.$objp->facid;
815 if ($displayAllInvoices) {
823 if ($objp->multicurrency_code && $objp->multicurrency_code !=
$conf->currency) {
824 if ($action !=
'add_paiement' || $useajaxconfirm) {
825 if (!empty(
$conf->use_javascript_ajax)) {
826 print
'<button class="btn-low-emphasis --btn-icon AutoFillAmount" data-rowname="'.$namef.
'" data-value="'.($sign * (float) $multicurrency_remaintopay).
'">';
827 print img_picto(
"Auto fill",
'rightarrow.png');
830 print
'<input type=hidden class="multicurrency_remain" name="'.$nameRemain.
'" value="'.$multicurrency_remaintopay.
'">';
831 print
'<input '.$min.
' '.$max.
' type="text" class="multicurrency_amount right width100" name="'.$namef.
'" placeholder="'.
dol_escape_htmltag($langs->getCurrencySymbol($objp->multicurrency_code)).
'" value="'.
GETPOST($namef).
'">';
833 print
'<input type="text" class="width100" name="'.$namef.
'_disabled" placeholder="'.
dol_escape_htmltag($langs->getCurrencySymbol($objp->multicurrency_code)).
'" value="'.
GETPOST($namef).
'" disabled>';
834 print
'<input type="hidden" name="'.$namef.
'" value="'.
GETPOST($namef).
'">';
840 print
'<td class="right"><span class="amount">'.price($sign * $objp->total_ttc).
'</span></td>';
842 print
'<td class="right"><span class="amount">'.price($sign * $objp->am);
844 print
'+'.price($creditnotes);
847 print
'+'.price($deposits);
849 print
'</span></td>';
851 print
'<td class="right">';
852 print
'<span class="amount">'.price($sign * (
float) $remaintopay).
'</span>';
854 $numdirectdebitopen = 0;
855 $totaldirectdebit = 0;
856 $sql =
"SELECT COUNT(pfd.rowid) as nb, SUM(pfd.amount) as amount";
857 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
858 $sql .=
" WHERE fk_facture_fourn = ".((int) $objp->facid);
859 $sql .=
" AND pfd.traite = 0";
860 $sql .=
" AND pfd.ext_payment_id IS NULL";
862 $result_sql = $db->query($sql);
864 $obj = $db->fetch_object($result_sql);
865 $numdirectdebitopen = $obj->nb;
866 $totaldirectdebit = $obj->amount;
868 dol_print_error($db);
870 if ($numdirectdebitopen) {
871 $langs->load(
"withdrawals");
872 print img_warning($langs->trans(
"WarningSomeCreditTransferAlreadyExists", $numdirectdebitopen,
price(
price2num($totaldirectdebit,
'MT'), 0, $langs, 1, -1, -1,
$conf->currency)),
'',
'classfortooltip');
878 print
'<td class="center nowraponall">';
880 $namef =
'amount_'.$objp->facid;
881 $nameRemain =
'remain_'.$objp->facid;
884 if ($displayAllInvoices) {
892 if ($action !=
'add_paiement' || $useajaxconfirm) {
893 if (!empty(
$conf->use_javascript_ajax)) {
894 print
'<button class="btn-low-emphasis --btn-icon AutoFillAmount" data-rowname="'.$namef.
'" data-value="'.($sign * (float) $remaintopay).
'">';
895 print img_picto(
"Auto fill",
'rightarrow.png');
898 print
'<input type="hidden" class="remain" name="'.$nameRemain.
'" value="'.$remaintopay.
'">';
899 print
'<input '.$max.
' '.$min.
' type="text" class="amount right width100" name="'.$namef.
'" value="'.
dol_escape_htmltag(
GETPOST($namef)).
'">';
901 print
'<input type="text" class="width100" name="'.$namef.
'_disabled" value="'.
dol_escape_htmltag(
GETPOST($namef)).
'" disabled>';
907 $total += $objp->total_ht;
908 $total_ttc += $objp->total_ttc;
909 $totalrecu += $objp->am;
910 $totalrecucreditnote += $creditnotes;
911 $totalrecudeposits += $deposits;
920 print
'<tr class="liste_total">';
924 if ($displayAllInvoices) {
928 print
'<td colspan="'.$colspan.
'" class="left" scope="row">'.$langs->trans(
'TotalTTC').
':</td>';
930 print
'<td> </td>';
931 print
'<td> </td>';
932 print
'<td> </td>';
933 print
'<td> </td>';
934 print
'<td class="right" id="multicurrency_result" style="font-weight: bold;"></td>';
936 print
'<td class="right"><b>'.price($total_ttc).
'</b></td>';
937 print
'<td class="right"><b>'.price($totalrecu);
938 if ($totalrecucreditnote) {
939 print
'+'.price($totalrecucreditnote);
941 if ($totalrecudeposits) {
942 print
'+'.price($totalrecudeposits);
945 print
'<td class="right"><b>'.price((
float)
price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,
'MT')).
'</b></td>';
946 print
'<td class="center" id="result" style="font-weight: bold;"></td>';
958 dol_print_error($db);
963 if ($action ==
'add_paiement') {
964 $i = count($formquestion);
966 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'paiementid',
'value' =>
GETPOSTINT(
'paiementid'));
967 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'accountid',
'value' => $accountid);
968 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'reday',
'value' =>
GETPOSTINT(
'reday'));
969 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'remonth',
'value' =>
GETPOSTINT(
'remonth'));
970 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'reyear',
'value' =>
GETPOSTINT(
'reyear'));
971 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'num_paiement',
'value' =>
GETPOST(
'num_paiement',
'alphanohtml'));
972 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'comment',
'value' =>
GETPOST(
'comment',
'restricthtml'));
973 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'closepaidinvoices',
'value' =>
GETPOST(
'closepaidinvoices'));
979 if ($action !=
'add_paiement' || $useajaxconfirm) {
981 $closepaidinvoiceschecked = (($action ==
'add_paiement' && !
GETPOST(
'closepaidinvoices')) ?
'' :
' checked');
983 print
'<br><div class="center">';
984 print
'<input type="checkbox"'.$closepaidinvoiceschecked.
' id="closepaidinvoices" name="closepaidinvoices" class="marginrightonly"><label for="closepaidinvoices" class="opacitymedium">'.$langs->trans(
"ClosePaidInvoicesAutomatically").
'</label><br>';
985 print
'<input type="submit" class="button reposition" value="'.$langs->trans(
'ToMakePayment').
'">';
986 print
' <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
991 if ($action ==
'add_paiement') {
992 $preselectedchoice = $addwarning ?
'no' :
'yes';
996 if (!empty($totalpayment)) {
997 $text = $langs->trans(
'ConfirmSupplierPayment',
price($totalpayment), $langs->transnoentitiesnoconv(
"Currency".$conf->currency));
999 if (!empty($multicurrency_totalpayment)) {
1000 $text .=
'<br>'.$langs->trans(
'ConfirmSupplierPayment',
price($multicurrency_totalpayment), $langs->transnoentitiesnoconv(
"paymentInInvoiceCurrency"));
1002 if (
GETPOST(
'closepaidinvoices')) {
1003 $text .=
'<br>'.$langs->trans(
"AllCompletelyPayedInvoiceWillBeClosed");
1004 if (empty($useajaxconfirm)) {
1007 print
'<input type="hidden" name="closepaidinvoices" value="'.GETPOST(
'closepaidinvoices').
'">';
1010 print $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.
$object->id.
'&socid='.
$object->socid.
'&type='.
$object->type, $langs->trans(
'PayedSuppliersPayments'), $text,
'confirm_paiement', $formquestion, $preselectedchoice, $useajaxconfirm);
1016 dol_print_error($db);
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_STANDARD
Standard invoice.
Class to manage payments for supplier invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.