diff --git a/client/src/partials/vouchers/index.js b/client/src/partials/vouchers/index.js
index 17f7d2622c..625e14ce42 100644
--- a/client/src/partials/vouchers/index.js
+++ b/client/src/partials/vouchers/index.js
@@ -36,12 +36,15 @@ function VoucherController(Vouchers, $translate, Notify, Filtering, uiGridGroupi
},
{ icon: 'fa fa-search', label: $translate.instant('FORM.LABELS.SEARCH'),
action: search, color: 'btn-default'
- },
- { icon: 'fa fa-print', label: $translate.instant('FORM.LABELS.PRINT'),
- action: printList, color: 'btn-default'
}
];
+ /** button Print */
+ vm.buttonPrint = {
+ pdfUrl: '/vouchers/reports'
+ };
+
+
/** search filters */
vm.searchFilter = [
{ displayName: 'FORM.LABELS.DATE_FROM', values: vm.dateInterval ? vm.dateInterval.dateFrom : null, filter: 'moment' },
@@ -153,15 +156,6 @@ function VoucherController(Vouchers, $translate, Notify, Filtering, uiGridGroupi
.catch(Notify.errorHandler);
}
- // print vouchers list
- function printList() {
- var dateFrom = vm.dateInterval ? vm.dateInterval.dateFrom: null;
- var dateTo = vm.dateInterval ? vm.dateInterval.dateTo : null;
- var url = '/vouchers/reports';
- var params = { dateFrom: dateFrom, dateTo: dateTo, renderer: 'pdf', lang: Languages.key };
- Modal.openReports({ url: url, params: params });
- }
-
// showReceipt
function showReceipt(uuid) {
var url = '/vouchers/receipts/' + uuid;
diff --git a/server/config/routes.js b/server/config/routes.js
index f4a157ece2..402008baae 100644
--- a/server/config/routes.js
+++ b/server/config/routes.js
@@ -341,6 +341,9 @@ exports.configure = function configure(app) {
app.get('/invoices/:uuid', patientInvoice.details);
app.get('/invoices/references/:reference', patientInvoice.reference);
+ // route for invoice Report
+ app.get('/invoices/patient/report', patientInvoice.getPatientInvoice);
+
// reports API: Invoices (receipts)
app.get('/reports/invoices/:uuid', financeReports.receipts.invoices);
app.get('/reports/cash/:uuid', financeReports.receipts.cash);
diff --git a/server/controllers/finance/patientInvoice.js b/server/controllers/finance/patientInvoice.js
index e5e79c910d..491e5acf50 100644
--- a/server/controllers/finance/patientInvoice.js
+++ b/server/controllers/finance/patientInvoice.js
@@ -22,6 +22,7 @@ const NotFound = require('../../lib/errors/NotFound');
const BadRequest = require('../../lib/errors/BadRequest');
const createInvoice = require('./invoice/patientInvoice.create');
+const listReceipt = require('../finance/receipts/list');
/** Retrieves a list of all patient invoices (accepts ?q delimiter). */
exports.list = list;
@@ -43,6 +44,14 @@ exports.reference = reference;
/** Expose lookup invoice for other controllers to use internally */
exports.lookupInvoice = lookupInvoice;
+
+exports.getPatientInvoice = getPatientInvoice;
+
+
+/** Undo the financial effects of a invoice generating an equal and opposite credit note. */
+// exports.reverse = reverse;
+
+
/**
* list
*
@@ -290,3 +299,45 @@ function reference(req, res, next) {
.catch(next)
.done();
}
+
+
+/**
+* GET /invoices/patient/report
+* Returns a pdf file for Patient Invoice
+*
+* @function getPatientInvoice
+*/
+function getPatientInvoice(req, res, next) {
+ const request = {
+ query : req.query,
+ enterprise : req.session.enterprise,
+ project : req.session.project
+ };
+
+ let invoiceListQuery =
+ `SELECT CONCAT(project.abbr, invoice.reference) AS reference, BUID(invoice.uuid) as uuid, cost,
+ BUID(invoice.debtor_uuid) as debtor_uuid, CONCAT(patient.first_name, ' - ', patient.last_name) as patientNames,
+ service.name as serviceName, CONCAT(user.first, ' - ', user.last) as createdBy, voucher.type_id,
+ invoice.date, invoice.is_distributable
+ FROM invoice
+ LEFT JOIN patient ON invoice.debtor_uuid = patient.debtor_uuid
+ JOIN service ON service.id = invoice.service_id
+ LEFT JOIN voucher ON voucher.reference_uuid = invoice.uuid
+ JOIN user ON user.id = invoice.user_id
+ JOIN project ON invoice.project_id = project.id
+ ORDER BY invoice.reference ASC, invoice.date ASC;`;
+
+ db.exec(invoiceListQuery)
+ .then(rows => listReceipt.build(rows, request))
+ .then(result => {
+ const renderer = {
+ 'pdf' : '"Content-Type" : "application/pdf"',
+ 'html' : '"Content-Type" : "application/html"',
+ 'json' : '"Content-Type" : "application/json"'
+ };
+ let headerKey = req.query.renderer || 'pdf';
+ let headers = renderer[headerKey];
+ res.set(headers).send(result);
+ })
+ .catch(next);
+}
\ No newline at end of file
diff --git a/server/controllers/finance/receipts/list.handlebars b/server/controllers/finance/receipts/list.handlebars
new file mode 100644
index 0000000000..4f038b6156
--- /dev/null
+++ b/server/controllers/finance/receipts/list.handlebars
@@ -0,0 +1,54 @@
+{{> head title="INVOICE_REGISTRY.TITLE"}}
+
+
+
+
+
+
+
{{model.enterprise.name}} ({{model.enterprise.abbr}})
+ {{translate 'FORM.LABELS.PHONE'}}: {{model.enterprise.phone}}
+ {{translate 'FORM.LABELS.EMAIL'}}: {{model.enterprise.email}}
+
+
+ {{model.project.name}} ({{model.project.abbr}})
+
+
+
+
+
+
+
+
+
+ {{translate 'INVOICE_REGISTRY.TITLE'}}
+
+
+
+
+
+
+ {{translate 'TABLE.COLUMNS.REFERENCE'}} |
+ {{translate 'TABLE.COLUMNS.BILLING_DATE'}} |
+ {{translate 'TABLE.COLUMNS.PATIENT'}} |
+ {{translate 'TABLE.COLUMNS.COST'}} |
+ {{translate 'TABLE.COLUMNS.SERVICE'}} |
+ {{translate 'TABLE.COLUMNS.BY'}} |
+
+
+
+ {{#each model.data}}
+
+ {{ reference }} |
+ {{ date date }} |
+ {{ patientNames }} |
+ {{ currency cost }} |
+ {{ serviceName }} |
+ {{ createdBy }} |
+
+ {{/each}}
+
+
+
+
+
+
diff --git a/server/controllers/finance/receipts/list.js b/server/controllers/finance/receipts/list.js
new file mode 100644
index 0000000000..9dfa85d964
--- /dev/null
+++ b/server/controllers/finance/receipts/list.js
@@ -0,0 +1,42 @@
+'use strict';
+
+const path = require('path');
+const BadRequest = require('../../../lib/errors/BadRequest');
+const supportedRender = {
+ json : require('../../../lib/renderers/json'),
+ html : require('../../../lib/renderers/html'),
+ pdf : require('../../../lib/renderers/pdf')
+};
+
+const defaultRender = 'pdf';
+const template = path.normalize('./server/controllers/finance/receipts/list.handlebars');
+const receiptOptions = { pageSize : 'A4', orientation: 'landscape' };
+
+// export the receipt object
+exports.build = build;
+
+/**
+ * @function build
+ * @desc build a report for invoice patient report of metadata
+ * @param {array} data invoice patient report of metadata
+ * @return {object} promise
+ */
+function build(data, request) {
+
+
+ let queryString = request.query;
+ let renderTarget = (queryString && queryString.renderer) ? queryString.renderer : defaultRender;
+ let renderer = supportedRender[renderTarget];
+
+ if (!renderer) {
+ throw new BadRequest('Render target provided is invalid or not supported by this report '.concat(renderTarget));
+ }
+
+ let model = {
+ enterprise : request.enterprise,
+ project : request.project,
+ data : data
+ };
+
+ return renderer.render({ model }, template, receiptOptions);
+}