Skip to content

Commit

Permalink
fix(invoices): make PDF report filter
Browse files Browse the repository at this point in the history
This commit changes the invoice registry to make sure that the PDF
report prints with filtered data as reflected in the view.
  • Loading branch information
Jonathan Niles authored and jniles committed Jan 5, 2017
1 parent 9bc9786 commit 71b7b07
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 35 deletions.
5 changes: 2 additions & 3 deletions client/src/partials/patient_invoice/registry/registry.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
</button>
</div>
<div class="toolbar-item">
<bh-pdf-print
pdf-url="/reports/finance/invoices"
>
<bh-pdf-print pdf-url="/reports/finance/invoices"
options="InvoiceRegistryCtrl.filters">
</bh-pdf-print>
</div>

Expand Down
33 changes: 2 additions & 31 deletions server/controllers/finance/patientInvoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,15 @@ exports.search = search;
/** Expose lookup invoice for other controllers to use internally */
exports.lookupInvoice = lookupInvoice;

// @todo - this is used by the invoices receipt which really should use
// a .find() method
exports.listInvoices = listInvoices;
exports.find = find;

/**
* list
*
* Retrieves a list of all patient invoices in the database
*/
function list(req, res, next) {
listInvoices()
find({})
.then(function (invoices) {
res.status(200).json(invoices);
})
Expand All @@ -62,33 +60,6 @@ function list(req, res, next) {
}


/**
* @method listInvoices
*
* @description
* Looks up all patients invoices in the data base
*
*/
function listInvoices() {
const sql = `
SELECT CONCAT_WS('.', '${identifiers.INVOICE}', project.abbr, invoice.reference) AS reference, BUID(invoice.uuid) as uuid, cost,
BUID(invoice.debtor_uuid) as debtor_uuid, patient.display_name as patientName,
service.name as serviceName, user.display_name, invoice.date, invoice.is_distributable,
enterprise.currency_id, voucher.type_id
FROM invoice
LEFT JOIN patient ON invoice.debtor_uuid = patient.debtor_uuid
LEFT JOIN voucher ON voucher.reference_uuid = invoice.uuid
JOIN service ON service.id = invoice.service_id
JOIN user ON user.id = invoice.user_id
JOIN project ON invoice.project_id = project.id
JOIN enterprise ON enterprise.id = project.enterprise_id
ORDER BY invoice.date DESC, invoice.reference DESC;
`;

// TODO - this shouldn't throw an error...
return db.exec(sql);
}

/**
* @method lookupInvoice
*
Expand Down
4 changes: 3 additions & 1 deletion server/controllers/finance/reports/invoices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ function report(req, res, next) {
return next(e);
}

const query = _.clone(req.query);

// @todo - this should use a .find() method like patient registratons
Invoices.listInvoices()
Invoices.find(query)
.then(rows => report.render({ rows }))
.then(result => {
res.set(result.headers).send(result.report);
Expand Down

0 comments on commit 71b7b07

Please sign in to comment.