From 08a35bbcff49db0d0d1780f5453774657ae5a3d3 Mon Sep 17 00:00:00 2001 From: John BOTELLA <68917336+thersane-john@users.noreply.github.com> Date: Tue, 15 Apr 2025 18:17:36 +0200 Subject: [PATCH] NEW : Toggle Display of Supplier Invoices and Credit Notes on Payment Page (#33856) * New supplier paiments display all invoices mode * fix param * fix php stan * add display mode dinstinction for css selector --- htdocs/fourn/facture/paiement.php | 167 ++++++++++++++++++++++-------- htdocs/langs/en_US/bills.lang | 5 + 2 files changed, 129 insertions(+), 43 deletions(-) diff --git a/htdocs/fourn/facture/paiement.php b/htdocs/fourn/facture/paiement.php index 9b44a560d9f..9d476fa8912 100644 --- a/htdocs/fourn/facture/paiement.php +++ b/htdocs/fourn/facture/paiement.php @@ -76,6 +76,11 @@ $search_amount = GETPOST('search_amount', 'alpha'); // alpha because we must be $search_company = GETPOST('search_company', 'alpha'); $search_payment_num = GETPOST('search_payment_num', 'alpha'); +$displayAllInvoices = getDolGlobalInt('MAIN_PAIMENTS_SHOW_ALL_INVOICE_TYPES', 0); +if (GETPOSTISSET('display-all-invoices')) { + $displayAllInvoices = GETPOSTINT('display-all-invoices'); +} + $limit = GETPOSTINT('limit') ? GETPOST('limit') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); @@ -413,7 +418,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie } $resql = $db->query($sql); if ($resql) { - $num = $db->num_rows($resql); + $totalnboflines = $num = $db->num_rows($resql); if ($num) { $obj = $db->fetch_object($resql); $total = $obj->total; @@ -487,7 +492,8 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie //Add js for AutoFill print ' $(document).ready(function () {'; - print ' $(".AutoFillAmount").on(\'click touchstart\', function(){ + print ' $(".AutoFillAmount").on(\'click touchstart\', function(e){ + e.preventDefault(); $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change"); });'; print ' });'."\n"; @@ -498,6 +504,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print '
'; print ''; print ''; + print ''; print ''; print ''; print ''; @@ -560,11 +567,15 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $sql .= ' AND f.fk_soc = '.((int) $object->socid); $sql .= ' AND f.paye = 0'; $sql .= ' AND f.fk_statut = 1'; // Status=0 => unvalidated, Status=2 => canceled - if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE) { - $sql .= ' AND f.type IN (0,1,3,5)'; // Standard invoice, replacement, deposit, situation - } else { - $sql .= ' AND f.type = 2'; // If paying back a credit note, we show all credit notes + + if (!$displayAllInvoices) { + if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE) { + $sql .= ' AND f.type IN (0,1,3,5)'; // Standard invoice, replacement, deposit, situation + } else { + $sql .= ' AND f.type = 2'; // If paying back a credit note, we show all credit notes + } } + // Group by because we have a total $sql .= ' GROUP BY f.datef, f.ref, f.ref_supplier, f.rowid, f.type, f.total_ht, f.total_ttc,'; $sql .= ' f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc,'; @@ -583,34 +594,62 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie //Add js for AutoFill print "\n".''."\n"; } - print '
'; - print ''."\n"; + $moreHtmlRight = ''; + if ($action=='create') { + $urlToggleDisplayMod = $_SERVER["PHP_SELF"].'?facid='.$facid.'&action='.$action.'&accountid='.$accountid.'&display-all-invoices=' . (intval(!$displayAllInvoices)); - print ''; - print ''; - print ''; - print ''; - print ''; - if (isModEnabled("multicurrency")) { - print ''; - print ''; - print ''; - print ''; - print ''; + if (empty($displayAllInvoices)) { + $btnTitle = $langs->trans('DisplayOtherInvoicesToo'); + if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE) { + $btnTitle = $langs->trans('DisplayCreditNotesToo'); + } + } else { + $btnTitle = $langs->trans('HideOtherInvoices'); + if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE) { + $btnTitle = $langs->trans('HideCreditNotes'); + } + } + + $btnIcon = empty($displayAllInvoices) ? 'fa fa-eye' : 'fa fa-eye-slash'; + $moreHtmlRight.= dolGetButtonTitle($btnTitle, '', $btnIcon, $urlToggleDisplayMod); } - print ''; - print ''; - print ''; - print ''; - print ''; + print_barre_liste($langs->trans('Invoices'), 0, $_SERVER["PHP_SELF"], '', '', '', '', $num, $totalnboflines, 'bill', 0, $moreHtmlRight, '', 0, 0, 0, 1); + + + print '
'; + print '
'.$langs->trans('Invoice').''.$langs->trans('RefSupplier').''.$langs->trans('Date').''.$langs->trans('DateMaxPayment').''.$langs->trans('Currency').''.$langs->trans('MulticurrencyAmountTTC').''.$langs->trans('MulticurrencyAlreadyPaid').''.$langs->trans('MulticurrencyRemainderToPay').''.$langs->trans('MulticurrencyPaymentAmount').''.$langs->trans('AmountTTC').''.$langs->trans('AlreadyPaid').''.$langs->trans('RemainderToPay').''.$langs->trans('PaymentAmount').'
'."\n"; + print ''; + print ''; + print ''; + print ''; + if ($displayAllInvoices) { + print ''; + } + print ''; + print ''; + if (isModEnabled("multicurrency")) { + print ''; + print ''; + print ''; + print ''; + print ''; + } + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; $total = 0; $total_ttc = 0; $totalrecu = 0; @@ -620,7 +659,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $objp = $db->fetch_object($resql); $sign = 1; - if ($objp->type == FactureFournisseur::TYPE_CREDIT_NOTE) { + if ($objp->type == FactureFournisseur::TYPE_CREDIT_NOTE && !$displayAllInvoices) { $sign = -1; } @@ -649,27 +688,39 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $multicurrency_remaintopay = price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits, 'MT'); } - print ''; + print ''; // Ref - print ''; // Ref supplier - print ''; + print ''; + + // type + if ($displayAllInvoices) { + $typearray = [ + FactureFournisseur::TYPE_STANDARD => $langs->trans("InvoiceStandard"), + FactureFournisseur::TYPE_REPLACEMENT => $langs->trans("InvoiceReplacement"), + FactureFournisseur::TYPE_CREDIT_NOTE => $langs->trans("InvoiceAvoir"), + FactureFournisseur::TYPE_DEPOSIT => $langs->trans("InvoiceDeposit"), + ]; + // Primary Secondary Success Danger Warning Info Light Dark status0 status1 status2 status3 status4 status5 status6 status7 status8 status9 + print ''; + } // Date if ($objp->df > 0) { - print ''; } else { - print ''; + print ''; } // Date Max Payment if ($objp->dlr > 0) { - print ''; } else { - print ''; + print ''; } // Multicurrency if (isModEnabled("multicurrency")) { // Currency - print '\n"; + print '\n"; - print ''; - print ''; - print ''; - print ''; + if ($i > 1) { + print ''; // Print total print ''; - print ''; + $colspan = 4; + + // type + if ($displayAllInvoices) { + $colspan++; + } + + print ''; if (isModEnabled("multicurrency")) { print ''; print ''; @@ -815,6 +895,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''; print ''; // Autofilled print "\n"; + print ''; } print "
'.$langs->trans('Invoice').''.$langs->trans('RefSupplier').'' . $langs->trans('Type') . ''.$langs->trans('Date').''.$langs->trans('DateMaxPayment').''.$langs->trans('Currency').''.$langs->trans('MulticurrencyAmountTTC').''.$langs->trans('MulticurrencyAlreadyPaid').''.$langs->trans('MulticurrencyRemainderToPay').''.$langs->trans('MulticurrencyPaymentAmount').''.$langs->trans('AmountTTC').''.$langs->trans('AlreadyPaid').''.$langs->trans('RemainderToPay').''.$langs->trans('PaymentAmount').'
'; + print ''; print $invoicesupplierstatic->getNomUrl(1); print ''.$objp->ref_supplier.''.$objp->ref_supplier.'' . $typearray[$objp->type] . ''; + print ''; print dol_print_date($db->jdate($objp->df), 'day').'!!!!!!'; + print ''; print dol_print_date($db->jdate($objp->dlr), 'day'); if ($invoice->hasDelay()) { @@ -678,21 +729,21 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print '----'.$objp->multicurrency_code."'.$objp->multicurrency_code."'; + print ''; if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { print price($objp->multicurrency_total_ttc); } print ''; + print ''; if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { print price($sign * $multicurrency_payment); if ($multicurrency_creditnotes) { @@ -704,23 +755,33 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie } print ''; + print ''; if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { print price($sign * (float) $multicurrency_remaintopay); } print ''; + print ''; // Add remind multicurrency amount $namef = 'multicurrency_amount_'.$objp->facid; $nameRemain = 'multicurrency_remain_'.$objp->facid; + + $min = $max = ''; + if ($displayAllInvoices) { + if ($objp->type == FactureFournisseur::TYPE_CREDIT_NOTE) { + $max = ' max="0" '; + } else { + $min = ' min="0" '; + } + } + if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { if ($action != 'add_paiement') { if (!empty($conf->use_javascript_ajax)) { - print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmount' data-rowname='".$namef."' data-value='".($sign * (float) $multicurrency_remaintopay)."'"); + print ''; } print ''; - print ''; // class is required to be used by javascript callForResult(); + print ''; // class is required to be used by javascript callForResult(); } else { print ''; print ''; // class is required to be used by javascript callForResult(); @@ -792,10 +862,20 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $totalrecudeposits += $deposits; $i++; } + print '
'.$langs->trans('TotalTTC').':'.$langs->trans('TotalTTC').':  '.price((float) price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).'
\n"; diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 555c77bcc5c..c78fe9d4036 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -468,6 +468,11 @@ ValidateGeneratedDeposit=Validate the generated deposit DepositGenerated=Deposit generated ErrorCanOnlyAutomaticallyGenerateADepositFromProposalOrOrder=You can only automatically generate a deposit from a proposal or an order ErrorPaymentConditionsNotEligibleToDepositCreation=The chose payment conditions are not eligible for automatic deposit generation +# Paiement page +DisplayOtherInvoicesToo = Display other invoices too +DisplayCreditNotesToo = Display credit notes too +HideOtherInvoices = Hide other invoices +HideCreditNotes = Hide credit notes # PaymentType PaymentTypeVIR=Bank transfer PaymentTypeShortVIR=Bank transfer