Skip to content

Commit

Permalink
improvement(Cash Flow Reports)
Browse files Browse the repository at this point in the history
- Adding Possibilty to view the detailed cashflow report

closes #3800
  • Loading branch information
lomamech committed Jul 27, 2019
1 parent 34fe9fc commit 946e278
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
"DANGER_ZONE": "Danger Zone",
"DELETE_RECORD_SUCCESS": "Successfully deleted the record.",
"DELETE_SUCCESS": "Successfully deleted a record",
"DETAILED_REPORT": "Detailed report",
"DISABLED_CURRENCY": "This currency is unusable since there is no account set for it. Use the Cashbox Management module to set an account for this currency and cashbox.",
"DISPLAY_NAME": "The user's full name. This is displayed on any formal documents or receipts processed by the system.",
"DISTRIBUTION_INVALID": "The distribution is invalid. The sum of distributed values must be equal to the amount of the transaction.",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/fr/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"CLOSED": "Fermée",
"CLOSE_FISCAL_YEAR": "Clôturer l'année fiscale",
"CONFIGURED_SUCCESSFULLY": "Configuré avec succès",
"DETAILED_REPORT": "Rapport détaillé",
"DISTRIBUTION_INVALID": "La répartition est invalide, la somme de valeurs réparties doit être égale au montant de la transaction",
"DISTRIBUTION_PERCENT_INVALID": "La distribution est invalide, la somme des valeurs en pourcentage doit être égale à 100%",
"DISTRIBUTION_SUCCESSFULLY": "Répartition avec succès",
Expand Down
8 changes: 8 additions & 0 deletions client/src/modules/reports/generate/cashflow/cashflow.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ <h3 class="text-capitalize" translate>REPORT.CASHFLOW.TITLE</h3>
on-change="ReportConfigCtrl.onSelectCashboxes(cashboxes)"
required="true">
</bh-multiple-cashbox-select>
<hr>
<div class="checkbox">
<label>
<input type="checkbox" ng-model="ReportConfigCtrl.reportDetails.detailed" ng-true-value="1" ng-false-value="0">
<span translate>FORM.INFO.DETAILED_REPORT</span>
</label>
</div>


<bh-loading-button loading-state="ConfigForm.$loading">
<span translate>REPORT.UTIL.PREVIEW</span>
Expand Down
61 changes: 60 additions & 1 deletion server/controllers/finance/reports/cashflow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ function report(req, res, next) {
const options = _.clone(req.query);
const data = {};

data.detailledReport = parseInt(req.query.detailed, 10);

// convert cashboxesIds parameters in array format ['', '', ...]
// this parameter can be sent as a string or an array we force the conversion into an array
const cashboxesIds = _.values(req.query.cashboxesIds);
Expand Down Expand Up @@ -299,6 +301,47 @@ function report(req, res, next) {
GROUP BY transaction_type_id, account_id;
`;

// To obtain the detailed cashflow report, the SQL query searches all the transactions
// concerned by the cash accounts in a sub-request, from the data coming
// from the sub-requests excluded the transaction lines of the accounts
// linked to the cash accounts.

const queryDetailed = `
SELECT
source.transaction_text, source.account_label, ${periodString},
source.transaction_type, source.transaction_type_id, source.account_id
FROM (
SELECT
a.number AS account_number, a.label AS account_label,
SUM(gl.credit_equiv - gl.debit_equiv) AS balance,
gl.transaction_type_id, tt.type AS transaction_type, tt.text AS transaction_text,
gl.account_id, gl.period_id
FROM general_ledger AS gl
JOIN account AS a ON a.id = gl.account_id
JOIN transaction_type AS tt ON tt.id = gl.transaction_type_id
WHERE gl.record_uuid IN (
SELECT record_uuid FROM general_ledger WHERE
account_id IN ? AND ((DATE(gl.trans_date) >= DATE(?)) AND (DATE(gl.trans_date) <= DATE(?)))
) AND account_id NOT IN ? AND gl.transaction_type_id <> 10 AND gl.record_uuid NOT IN (
SELECT DISTINCT gl.record_uuid
FROM general_ledger AS gl
WHERE gl.record_uuid IN (
SELECT rev.uuid
FROM (
SELECT v.uuid FROM voucher v WHERE v.reversed = 1
AND DATE(v.date) >= DATE(?) AND DATE(v.date) <= DATE(?) UNION
SELECT c.uuid FROM cash c WHERE c.reversed = 1
AND DATE(c.date) >= DATE(?) AND DATE(c.date) <= DATE(?) UNION
SELECT i.uuid FROM invoice i WHERE i.reversed = 1
AND DATE(i.date) >= DATE(?) AND DATE(i.date) <= DATE(?)
) AS rev
)
) GROUP BY gl.transaction_type_id, gl.account_id, gl.period_id
) AS source
GROUP BY transaction_type_id, account_id;
`;


const params = [...periodParams,
[data.cashAccountIds],
data.dateFrom,
Expand All @@ -309,7 +352,23 @@ function report(req, res, next) {
data.dateTo,
data.dateFrom,
data.dateTo];
return db.exec(query, params);

const paramsDetailed = [...periodParams,
[data.cashAccountIds],
data.dateFrom,
data.dateTo,
[data.cashAccountIds],
data.dateFrom,
data.dateTo,
data.dateFrom,
data.dateTo,
data.dateFrom,
data.dateTo];

const queryRun = data.detailledReport ? queryDetailed : query;
const paramsRun = data.detailledReport ? paramsDetailed : params;

return db.exec(queryRun, paramsRun);
})
.then(rows => {
// split incomes from expenses
Expand Down

0 comments on commit 946e278

Please sign in to comment.