diff --git a/client/src/i18n/en/form.json b/client/src/i18n/en/form.json index 21f7492de9..fdc0d451c3 100644 --- a/client/src/i18n/en/form.json +++ b/client/src/i18n/en/form.json @@ -198,6 +198,8 @@ "AVG_MONTHLY_CONSUMPTION": "Monthly Average Consumption", "MONTHLY_CONSUMPTION": "Monthly Consumption", "BALANCE": "Balance", + "BALANCE_INTERMEDIATE" : "Intermediate Balance", + "BALANCE_FINAL" : "Final Balance", "BALANCE_SECTION": "Balance Sheet Section", "BANK": "Bank", "BANK_ACCOUNT": "Bank Account", @@ -668,4 +670,4 @@ "NO_CHANGES": "You haven't changed any form values. Nothing will be submitted to the server." } } -} \ No newline at end of file +} diff --git a/client/src/i18n/fr/form.json b/client/src/i18n/fr/form.json index bd6a33589f..9f65ad7da9 100644 --- a/client/src/i18n/fr/form.json +++ b/client/src/i18n/fr/form.json @@ -200,6 +200,8 @@ "AVG_MONTHLY_CONSUMPTION": "Consommation Mensuelle Moyenne", "MONTHLY_CONSUMPTION": "Consommation Mensuelle", "BALANCE": "Balance", + "BALANCE_INTERMEDIATE" : "Solde Intermediate", + "BALANCE_FINAL" : "Solde Finale", "BALANCE_SECTION": "Section du Bilan", "BANK": "Banque", "BANK_ACCOUNT": "Compte Bancaire", diff --git a/server/controllers/finance/reports/clientsReport/index.js b/server/controllers/finance/reports/clientsReport/index.js index b23c17ffb5..037710370c 100644 --- a/server/controllers/finance/reports/clientsReport/index.js +++ b/server/controllers/finance/reports/clientsReport/index.js @@ -165,7 +165,7 @@ function buildComplexReport(opt) { // removing the period filter delete opt.period_id; - // fecth final balances + // fetch final balances return getClientBalancesFromPeriodTotal(opt, false); }) .then((data) => { @@ -176,6 +176,7 @@ function buildComplexReport(opt) { }); } }); + // fetch the final total for each row of the period total table return getClientTotalsFromPeriodTotal(opt, false); }) @@ -195,13 +196,13 @@ function buildComplexReport(opt) { function getFiscalYearByDate(date, periodZeroNumber) { var query = ` - SELECT - fy.id AS fiscal_year_id, fy.previous_fiscal_year_id, fy.start_date, fy.end_date, p.id AS period_id - FROM - fiscal_year fy - JOIN + SELECT + fy.id AS fiscal_year_id, fy.previous_fiscal_year_id, fy.start_date, fy.end_date, p.id AS period_id + FROM + fiscal_year fy + JOIN period p ON p.fiscal_year_id = fy.id - WHERE + WHERE p.number = ? AND DATE(?) BETWEEN DATE(fy.start_date) AND DATE(fy.end_date)`; return db.one(query, [periodZeroNumber, date]); @@ -229,11 +230,11 @@ function getClientBalancesFromPeriodTotal(options, isInitial) { const sql = ` SELECT ac.number AS number, dg.name AS name, SUM(pt.debit) AS debit, - SUM(pt.credit) AS credit, SUM(pt.debit - pt.credit) AS balance - FROM - debtor_group dg - JOIN - account ac ON ac.id = dg.account_id + SUM(pt.credit) AS credit, SUM(pt.debit - pt.credit) AS balance + FROM + debtor_group dg + JOIN + account ac ON ac.id = dg.account_id LEFT JOIN period_total pt ON ac.id = pt.account_id`; filterParser.equals('fiscal_year_id', 'fiscal_year_id', 'pt'); @@ -260,9 +261,9 @@ function getClientBalancesFromPeriodTotal(options, isInitial) { const finalQuery = ` - SELECT - ${cols} - FROM + SELECT + ${cols} + FROM (${query}) AS t`; return db.exec(finalQuery, parameters); } @@ -272,13 +273,13 @@ function getClientBalancesFromGeneralLedger(options) { const filterParser = new FilterParser(options, { tableAlias : 'gl' }); const sql = ` SELECT - ac.number, dg.name, SUM(gl.debit_equiv) AS debit, SUM(gl.credit_equiv) AS credit, - SUM(gl.debit_equiv - gl.credit_equiv) AS balance - FROM - debtor_group dg - JOIN + ac.number, dg.name, SUM(gl.debit_equiv) AS debit, SUM(gl.credit_equiv) AS credit, + SUM(gl.debit_equiv - gl.credit_equiv) AS balance + FROM + debtor_group dg + JOIN account ac ON ac.id = dg.account_id - LEFT JOIN + LEFT JOIN general_ledger gl ON ac.id = gl.account_id`; filterParser.dateFrom('dateFrom', 'trans_date'); @@ -291,10 +292,10 @@ function getClientBalancesFromGeneralLedger(options) { // request to fetch the current fiscal year data of a client from the general ledger const finalQuery = ` - SELECT - t.number AS accountNumber, t.name, IFNULL(t.debit, 0) AS debit, IFNULL(t.credit, 0) AS credit, + SELECT + t.number AS accountNumber, t.name, IFNULL(t.debit, 0) AS debit, IFNULL(t.credit, 0) AS credit, IFNULL(t.balance, 0) AS balance - FROM + FROM (${query}) AS t`; return db.exec(finalQuery, parameters); } @@ -305,10 +306,10 @@ function getClientTotalsFromPeriodTotal(options, isInitial) { const sql = ` SELECT - SUM(pt.debit) AS debit, SUM(pt.credit) AS credit, SUM(pt.debit - pt.credit) AS balance - FROM + SUM(pt.debit) AS debit, SUM(pt.credit) AS credit, SUM(pt.debit - pt.credit) AS balance + FROM period_total pt - JOIN + JOIN debtor_group dg ON dg.account_id = pt.account_id`; filterParser.equals('fiscal_year_id', 'fiscal_year_id', 'pt'); @@ -324,15 +325,15 @@ function getClientTotalsFromPeriodTotal(options, isInitial) { cols = `IFNULL(t.balance, 0) AS balance`; } else { cols = (isInitial) ? - `IFNULL(debit, 0) AS totalInitDebit, IFNULL(credit, 0) AS totalInitCredit, IFNULL(balance, 0) AS totalInitBalance` : - `IFNULL(t.balance, 0) AS totalFinalBalance`; + 'IFNULL(debit, 0) AS totalInitDebit, IFNULL(credit, 0) AS totalInitCredit, IFNULL(balance, 0) AS totalInitBalance' : + 'IFNULL(t.balance, 0) AS totalFinalBalance'; } const finalQuery = ` - SELECT - ${cols} - FROM + SELECT + ${cols} + FROM (${query}) AS t`; return db.one(finalQuery, parameters); @@ -343,14 +344,14 @@ function getClientTotalsFromGeneralLedger(options) { const filterParser = new FilterParser(options, { tableAlias : 'gl', autoParseStatements : false }); const sql = ` - SELECT - SUM(gl.debit_equiv) AS debit, SUM(gl.credit_equiv) AS credit, - SUM(gl.debit_equiv - gl.credit_equiv) AS balance - FROM - debtor_group dg - JOIN - account ac ON ac.id = dg.account_id - JOIN + SELECT + SUM(gl.debit_equiv) AS debit, SUM(gl.credit_equiv) AS credit, + SUM(gl.debit_equiv - gl.credit_equiv) AS balance + FROM + debtor_group dg + JOIN + account ac ON ac.id = dg.account_id + JOIN general_ledger gl ON ac.id = gl.account_id`; filterParser.dateFrom('dateFrom', 'trans_date'); @@ -361,10 +362,10 @@ function getClientTotalsFromGeneralLedger(options) { const parameters = filterParser.parameters(); const finalQuery = - `SELECT - IFNULL(t.debit, 0) AS totalCurrentDebit, IFNULL(t.credit, 0) AS totalCurrentCredit, + `SELECT + IFNULL(t.debit, 0) AS totalCurrentDebit, IFNULL(t.credit, 0) AS totalCurrentCredit, IFNULL(t.balance, 0) AS totalCurrentBalance - FROM + FROM (${query}) AS t`; return db.one(finalQuery, parameters); diff --git a/server/controllers/finance/reports/clientsReport/report_complex.handlebars b/server/controllers/finance/reports/clientsReport/report_complex.handlebars index af4985c845..5c1cada584 100644 --- a/server/controllers/finance/reports/clientsReport/report_complex.handlebars +++ b/server/controllers/finance/reports/clientsReport/report_complex.handlebars @@ -41,15 +41,15 @@ {{this.accountNumber}} {{this.name}} {{#if ../detailPrevious}} - {{currency this.initDebit ../enterprise.currency_id}} - {{currency this.initCredit ../enterprise.currency_id}} + {{currency this.initDebit ../metadata.enterprise.currency_id}} + {{currency this.initCredit ../metadata.enterprise.currency_id}} {{else}} - {{currency this.initBalance ../enterprise.currency_id}} + {{currency this.initBalance ../metadata.enterprise.currency_id}} {{/if}} - {{currency this.debit ../enterprise.currency_id}} - {{currency this.credit ../enterprise.currency_id}} - {{currency this.currentBalance ../enterprise.currency_id}} - {{currency this.finalBalance ../enterprise.currency_id}} + {{currency this.debit ../metadata.enterprise.currency_id}} + {{currency this.credit ../metadata.enterprise.currency_id}} + {{currency this.currentBalance ../metadata.enterprise.currency_id}} + {{currency this.finalBalance ../metadata.enterprise.currency_id}} {{else}} {{>emptyTable columns=7}} @@ -59,15 +59,15 @@ {{translate 'FORM.LABELS.TOTAL'}} {{#if detailPrevious}} - {{currency totalInitDebit enterprise.currency_id}} - {{currency totalInitCredit enterprise.currency_id}} + {{currency totalInitDebit metadata.enterprise.currency_id}} + {{currency totalInitCredit metadata.enterprise.currency_id}} {{else}} - {{currency totalInitBalance enterprise.currency_id}} + {{currency totalInitBalance metadata.enterprise.currency_id}} {{/if}} - {{currency totalCurrentDebit enterprise.currency_id}} - {{currency totalCurrentCredit enterprise.currency_id}} - {{currency totalCurrentBalance enterprise.currency_id}} - {{currency totalFinalBalance enterprise.currency_id}} + {{currency totalCurrentDebit metadata.enterprise.currency_id}} + {{currency totalCurrentCredit metadata.enterprise.currency_id}} + {{currency totalCurrentBalance metadata.enterprise.currency_id}} + {{currency totalFinalBalance metadata.enterprise.currency_id}} diff --git a/server/controllers/finance/reports/clientsReport/report_simple.handlebars b/server/controllers/finance/reports/clientsReport/report_simple.handlebars index 9af2089174..764be59b91 100644 --- a/server/controllers/finance/reports/clientsReport/report_simple.handlebars +++ b/server/controllers/finance/reports/clientsReport/report_simple.handlebars @@ -28,17 +28,17 @@ {{this.accountNumber}} {{this.name}} - {{currency this.balance ../enterprise.currency_id}} + {{currency this.balance ../metadata.enterprise.currency_id}} {{/each}} - {{translate 'FORM.LABELS.TOTAL'}} - {{currency totalBalance enterprise.currency_id}} + {{translate 'FORM.LABELS.TOTAL'}} + {{currency totalBalance ../metadata.enterprise.currency_id}} - +