Skip to content

Commit

Permalink
fix(filter): handle the filter properly from the client to the server
Browse files Browse the repository at this point in the history
  • Loading branch information
DedrickEnc committed Jun 7, 2017
1 parent d2cc37f commit 0431554
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
3 changes: 1 addition & 2 deletions client/src/i18n/en/cash_registry.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"CASH_REGISTRY" : {
"TITLE" : "Payment registry",
"RECEIPT_CURRENCY" : "receipt Currency"
"TITLE" : "Payment registry"
}
}
3 changes: 1 addition & 2 deletions client/src/i18n/fr/cash_registry.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"CASH_REGISTRY" : {
"TITLE" : "Registre des payments",
"RECEIPT_CURRENCY" : "Monnaie du reçu"
"TITLE" : "Registre des payments"
}
}
24 changes: 8 additions & 16 deletions server/controllers/finance/reports/cash/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,13 @@ function receipt(req, res, next) {
* GET /reports/finance/cash
*/
function report(req, res, next) {
let options = {};
let display = {};
let hasFilter = false;

let reportInstance;
const optionReport = _.extend(req.query, { filename : 'TREE.CASH_PAYMENT_REGISTRY', orientation : 'landscape' });
const query = _.clone(req.query);
_.extend(query, { filename : 'TREE.CASH_PAYMENT_REGISTRY', csvKey : 'rows' });

// set up the report with report manager
try {
if (req.query.identifiers && req.query.display) {
options = JSON.parse(req.query.identifiers);
display = JSON.parse(req.query.display);
hasFilter = Object.keys(display).length > 0;
}

reportInstance = new ReportManager(REPORT_TEMPLATE, req.session, optionReport);
reportInstance = new ReportManager(REPORT_TEMPLATE, req.session, query);
} catch (e) {
next(e);
return;
Expand Down Expand Up @@ -180,16 +171,15 @@ function report(req, res, next) {
const data = {};
let uuids;

CashPayments.listPayment(options)
CashPayments.listPayment(query)
.then(rows => {
data.rows = rows;
data.hasFilter = hasFilter;
data.csv = rows;
data.display = display;

// map the uuids for aggregate sql consumption
uuids = rows.map(row => db.bid(row.uuid));

if (!uuids.length) { return false; }

return db.one(aggregateSql, [uuids]);
})
.then(aggregates => {
Expand All @@ -199,6 +189,8 @@ function report(req, res, next) {
data.hasMultipleProjects = aggregates.numProjects > 1;
data.hasMultipleCashboxes = aggregates.numCashboxes > 1;

if (!uuids.length) { return false; }

return db.exec(costSql, [uuids]);
})
.then(amounts => {
Expand Down

0 comments on commit 0431554

Please sign in to comment.