Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement(Cash Flow Reports) #3801

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 7 additions & 0 deletions client/src/modules/reports/generate/cashflow/cashflow.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ <h3 class="text-capitalize" translate>REPORT.CASHFLOW.TITLE</h3>
required="true">
</bh-multiple-cashbox-select>

<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>
</bh-loading-button>
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