From 5138e21a888f396ce77dcf4516f3a4dbdb0e7bfc Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Wed, 17 Jul 2024 11:32:47 +0100 Subject: [PATCH] Minor improvements to the Annual Clients Report. --- client/src/css/structure.css | 4 ++ client/src/i18n/en/report.json | 3 +- client/src/i18n/en/table.json | 2 + client/src/i18n/fr/report.json | 3 +- client/src/i18n/fr/table.json | 2 + client/src/modules/debtors/groups.list.html | 6 +- .../debtors/annual_clients_report.handlebars | 56 ++++++++++++++++--- .../reports/debtors/annual_clients_report.js | 34 ++++++++--- 8 files changed, 91 insertions(+), 19 deletions(-) diff --git a/client/src/css/structure.css b/client/src/css/structure.css index 2a87ba31e2..e148bab208 100644 --- a/client/src/css/structure.css +++ b/client/src/css/structure.css @@ -157,6 +157,10 @@ color : #505050; } +.no-top-margin { + margin-top: 0; +} + /** * Application Header * diff --git a/client/src/i18n/en/report.json b/client/src/i18n/en/report.json index 157a2a5be1..2ced655fd9 100644 --- a/client/src/i18n/en/report.json +++ b/client/src/i18n/en/report.json @@ -86,7 +86,8 @@ "HIDE_LOCKED_CLIENTS" : "Hide Locked Clients", "HIDE_LOCKED_CLIENTS_HELP_TEXT" : "Selecting yes will filter out all locked clients from the report. By default, the value is no.", "INCLUDE_CASH_CLIENTS" : "Include Cash Clients", - "INCLUDE_CASH_CLIENTS_HELP_TEXT" : "Selecting this option will add in cash debtor groups. By default only non-cash clients (conventions) are queried." + "INCLUDE_CASH_CLIENTS_HELP_TEXT" : "Selecting this option will add in cash debtor groups. By default only non-cash clients (conventions) are queried.", + "NO_LOCKED_CLIENTS_FOUND" : "No locked clients found." }, "CLOSING_BALANCE": "Closing Balance", "COMPARE_INVOICED_RECEIVED": { diff --git a/client/src/i18n/en/table.json b/client/src/i18n/en/table.json index dd7d8d2b03..e76d28ba7a 100644 --- a/client/src/i18n/en/table.json +++ b/client/src/i18n/en/table.json @@ -48,6 +48,7 @@ "BY": "by", "CASHBOX": "Cashbox", "CASES": "Cases", + "CASHQ": "Cash?", "CANCEL_CASH": "Cancel Cash Payment", "CHARGE": "cost", "CHARGES": "costs", @@ -152,6 +153,7 @@ "LISTS": "Registered price list", "LOADING": "Fetching data from the server.", "LOCKED": "Locked", + "LOCKEDQ": "Locked?", "LOT": "Lot / Batch", "LONGITUDE": "Longitude", "LATITUDE": "Latitude", diff --git a/client/src/i18n/fr/report.json b/client/src/i18n/fr/report.json index 8de440da64..ac4fbe733d 100644 --- a/client/src/i18n/fr/report.json +++ b/client/src/i18n/fr/report.json @@ -292,7 +292,8 @@ "HIDE_LOCKED_CLIENTS" : "Masquer les clients verrouillés", "HIDE_LOCKED_CLIENTS_HELP_TEXT" : "Si vous sélectionnez oui, tous les clients verrouillés seront filtrés dans le rapport. Par défaut, la valeur est non.", "INCLUDE_CASH_CLIENTS" : "Inclure les payant cash", - "INCLUDE_CASH_CLIENTS_HELP_TEXT" : "La sélection de cette option ajoutera des groupes de débiteurs en espèces. Par défaut, seules les conventions sont interrogées." + "INCLUDE_CASH_CLIENTS_HELP_TEXT" : "La sélection de cette option ajoutera des groupes de débiteurs en espèces. Par défaut, seules les conventions sont interrogées.", + "NO_LOCKED_CLIENTS_FOUND" : "Aucun client bloqué n'a été trouvé." }, "UNPAID_INVOICE_PAYMENTS_REPORT": { "TITLE": "Rapport de Factures Non-Payées", diff --git a/client/src/i18n/fr/table.json b/client/src/i18n/fr/table.json index fea9eaaff1..1bf7c19d20 100644 --- a/client/src/i18n/fr/table.json +++ b/client/src/i18n/fr/table.json @@ -48,6 +48,7 @@ "CANCEL_CASH": "Annuler le paiement", "BY": "Par", "CASES": "Cas", + "CASHQ": "Cash ?", "CASHBOX": "Caisse", "CHARGE": "Charge", "CHARGES": "Charges", @@ -152,6 +153,7 @@ "LISTS": "Liste des prix enregistrés", "LOADING": "Récupération des données à partir du serveur.", "LOCKED": "Bloquée", + "LOCKEDQ": "Bloquée ?", "LONGITUDE": "Longitude", "LATITUDE": "Latitude", "LOT": "Lot", diff --git a/client/src/modules/debtors/groups.list.html b/client/src/modules/debtors/groups.list.html index 85bf9a8958..53ab049edb 100644 --- a/client/src/modules/debtors/groups.list.html +++ b/client/src/modules/debtors/groups.list.html @@ -49,7 +49,11 @@
FORM.LABELS.ACCOUNT_NUMBER DEBTOR_GROUP.EDIT - +
+
+
{{ debtorGroup.note }}
+
+
diff --git a/server/controllers/finance/reports/debtors/annual_clients_report.handlebars b/server/controllers/finance/reports/debtors/annual_clients_report.handlebars index 3c1351187a..fe40e77ec1 100644 --- a/server/controllers/finance/reports/debtors/annual_clients_report.handlebars +++ b/server/controllers/finance/reports/debtors/annual_clients_report.handlebars @@ -1,10 +1,31 @@ {{> head }} + +
{{#> header }}

- {{ fiscalYear.label }} + {{fiscalYear.label}}
+ {{date fiscalYear.start_date "MMMM YYYY"}} - {{date fiscalYear.end_date "MMMM YYYY"}}

{{/header}} @@ -16,11 +37,17 @@ {{translate "TABLE.COLUMNS.ACCOUNT"}} {{translate "TABLE.COLUMNS.NAME"}} - {{translate "REPORT.OPENING_BALANCE"}} - {{translate "TABLE.COLUMNS.DEBIT"}} - {{translate "TABLE.COLUMNS.CREDIT"}} - {{translate "FORM.LABELS.DIFFERENCE"}} - {{translate "REPORT.CLOSING_BALANCE"}} + {{#if includeCashClients}} +
{{translate "TABLE.COLUMNS.CASHQ"}}
+ {{/if}} + {{#if showLockedColumn}} +
{{translate "TABLE.COLUMNS.LOCKEDQ"}}
+ {{/if}} + {{translate "REPORT.OPENING_BALANCE"}} + {{translate "TABLE.COLUMNS.DEBIT"}} + {{translate "TABLE.COLUMNS.CREDIT"}} + {{translate "FORM.LABELS.DIFFERENCE"}} + {{translate "REPORT.CLOSING_BALANCE"}} @@ -28,7 +55,13 @@ {{#each rows as | row |}} {{row.accountNumber}} - {{row.groupName }} + {{row.groupName}} + {{#if ../includeCashClients}} + {{#if row.isConvention}}{{else}}X{{/if}} + {{/if}} + {{#if ../showLockedColumn}} + {{#if row.locked}}X{{/if}} + {{/if}} {{debcred row.openingBalance row.currencyId}} {{debcred row.debit row.currencyId}} {{debcred row.credit row.currencyId}} @@ -36,12 +69,12 @@ {{debcred row.closingBalance row.currencyId}} {{else}} - {{> emptyTable columns="6" }} + {{> emptyTable columns="{{../numCols}}" }} {{/each}} - {{translate "TABLE.COLUMNS.TOTAL"}} + {{translate "TABLE.COLUMNS.TOTAL"}} {{debcred footer.openingBalance footer.currencyId}} {{debcred footer.debit footer.currencyId}} {{debcred footer.credit footer.currencyId}} @@ -49,6 +82,11 @@ {{debcred footer.closingBalance footer.currencyId}} + {{#if noLockedClientsFound}} +
+ * {{translate "REPORT.CLIENTS.NO_LOCKED_CLIENTS_FOUND"}} +
+ {{/if}}
diff --git a/server/controllers/finance/reports/debtors/annual_clients_report.js b/server/controllers/finance/reports/debtors/annual_clients_report.js index d8258f0d97..d7ee7c3e51 100644 --- a/server/controllers/finance/reports/debtors/annual_clients_report.js +++ b/server/controllers/finance/reports/debtors/annual_clients_report.js @@ -18,8 +18,9 @@ async function setupAnnualClientsReport(options, enterprise) { const currencyId = Number(options.currencyId); // convert to an integer - const shouldHideLockedClients = Number(hideLockedClients); const shouldIncludeCashClients = Number(includeCashClients); + const shouldHideLockedClients = Number(hideLockedClients); + const showLockedClients = shouldHideLockedClients === 0 ? 1 : 0; const [fiscalYear, exchange] = await Promise.all([ Fiscal.lookupFiscalYear(fiscalId), @@ -33,8 +34,26 @@ async function setupAnnualClientsReport(options, enterprise) { getTotalsFooter(fiscalYear.id, currencyId, rate, shouldHideLockedClients, shouldIncludeCashClients), ]); + // Computations for optional columns + const numLocked = rows.reduce((sum, row) => sum + (row.locked ? 1 : 0), 0); + const noLockedClientsFound = Number(!shouldHideLockedClients && (numLocked === 0)); + const showLockedColumn = Number(!shouldHideLockedClients && (numLocked > 0)); + const skipCols = 2 + shouldIncludeCashClients + (showLockedColumn ? 1 : 0); + const numCols = 6 + skipCols; + return { - rows, footer, fiscalYear, exchangeRate : rate, currencyId, + rows, + footer, + fiscalYear, + exchangeRate : rate, + currencyId, + lockedClients : showLockedClients, + showLockedColumn, + noLockedClientsFound, + numLocked, + includeCashClients : shouldIncludeCashClients, + skipCols, + numCols, }; } @@ -91,7 +110,8 @@ function getDebtorGroupMovements(fiscalYearId, currencyId, rate, hideLockedClien const hiddenClientsCondition = ' AND dg.locked = 0 '; const excludeCashClientsCondition = 'AND dg.is_convention = 1 '; const sql = ` - SELECT ac.number AS accountNumber, dg.name AS groupName, + SELECT act.number AS accountNumber, dg.name AS groupName, + dg.locked, dg.is_convention AS isConvention, IFNULL(SUM(IF(p.number = 0, pt.debit - pt.credit, 0)), 0) * ${rate} AS openingBalance, IFNULL(SUM(IF(p.number > 0, pt.debit, 0)), 0) * ${rate} AS debit, IFNULL(SUM(IF(p.number > 0, pt.credit, 0)), 0) * ${rate} AS credit, @@ -100,13 +120,13 @@ function getDebtorGroupMovements(fiscalYearId, currencyId, rate, hideLockedClien ${currencyId} as currencyId FROM debtor_group dg LEFT JOIN period_total pt ON dg.account_id = pt.account_id - LEFT JOIN account ac ON ac.id = pt.account_id + LEFT JOIN account act ON act.id = pt.account_id LEFT JOIN period p ON p.id = pt.period_id WHERE pt.fiscal_year_id = ? ${hideLockedClients ? hiddenClientsCondition : ''} ${includeCashClients ? '' : excludeCashClientsCondition} GROUP BY pt.account_id - ORDER BY ac.number ASC, dg.name DESC; + ORDER BY act.number ASC, dg.name DESC; `; return db.exec(sql, fiscalYearId); @@ -123,7 +143,7 @@ function getTotalsFooter(fiscalYearId, currencyId, rate, hideLockedClients = 0, const hiddenClientsCondition = ' AND dg.locked = 0 '; const excludeCashClientsCondition = 'AND dg.is_convention = 1 '; const sql = ` - SELECT ac.number AS accountNumber, ac.label AS accountLabel, + SELECT act.number AS accountNumber, act.label AS accountLabel, IFNULL(SUM(IF(p.number = 0, pt.debit - pt.credit, 0)), 0) * ${rate} AS openingBalance, IFNULL(SUM(IF(p.number > 0, pt.debit, 0)), 0) * ${rate} AS debit, IFNULL(SUM(IF(p.number > 0, pt.credit, 0)), 0) * ${rate} AS credit, @@ -132,7 +152,7 @@ function getTotalsFooter(fiscalYearId, currencyId, rate, hideLockedClients = 0, ${currencyId} as currencyId FROM debtor_group dg LEFT JOIN period_total pt ON dg.account_id = pt.account_id - LEFT JOIN account ac ON ac.id = pt.account_id + LEFT JOIN account act ON act.id = pt.account_id LEFT JOIN period p ON p.id = pt.period_id WHERE pt.fiscal_year_id = ? ${hideLockedClients ? hiddenClientsCondition : ''}