Skip to content

Commit

Permalink
Resolve conflict with branch Master
Browse files Browse the repository at this point in the history
  • Loading branch information
lomamech committed Aug 25, 2016
1 parent e5983f5 commit 699372b
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 26 deletions.
6 changes: 5 additions & 1 deletion client/src/js/components/bhBreadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ angular.module('bhima.components')
path: '<',
button: '<',
label: '<',
dropdown: '<'
dropdown: '<',
print : '<'
},
templateUrl : 'partials/templates/breadcrumb.tmpl.html',
controller : BreadcrumbController,
Expand Down Expand Up @@ -99,6 +100,9 @@ function BreadcrumbController() {
vm.bcDropdowns = vm.dropdown || [];


vm.buttonPrint = vm.print || [];


/** call the appropriate function and update the dropdown label **/
vm.helperDropdown = function helperDropdown(child, parent) {
parent.selected = child.label;
Expand Down
6 changes: 4 additions & 2 deletions client/src/partials/inventory/list/list.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<!-- breadcrumb header -->
<bh-breadcrumb
path="InventoryCtrl.bcPaths"
button="InventoryCtrl.bcButtons">
path ="InventoryCtrl.bcPaths"
button ="InventoryCtrl.bcButtons"
print ="InventoryCtrl.buttonPrint"
>
</bh-breadcrumb>

<!-- grid content -->
Expand Down
15 changes: 6 additions & 9 deletions client/src/partials/inventory/list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ function InventoryListController ($translate, Inventory, Notify, uiGridConstants
{ icon: 'fa fa-plus', label: $translate.instant('FORM.LABELS.ADD'),
action: addInventoryItem, color: 'btn-default',
dataMethod: 'create'
},
{ icon: 'fa fa-print', label: $translate.instant('FORM.LABELS.PRINT'),
action: printList, color: 'btn-default'
}
];

/** button Print */
vm.buttonPrint = {
pdfUrl: '/inventory/reports/metadata'
};


// edit button template
var editTemplate = '<div style="padding: 5px;">' +
'<a title="{{ \'FORM.LABELS.EDIT\' | translate }}" href="" ' +
Expand Down Expand Up @@ -89,7 +92,6 @@ function InventoryListController ($translate, Inventory, Notify, uiGridConstants
vm.addInventoryItem = addInventoryItem;
vm.editInventoryItem = editInventoryItem;
vm.toggleFilter = toggleFilter;
vm.printList = printList;

/** initial setting start */
startup();
Expand Down Expand Up @@ -126,11 +128,6 @@ function InventoryListController ($translate, Inventory, Notify, uiGridConstants
vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ALL);
}

/** print inventory list */
function printList() {
Modal.openReports({ url: '/inventory/reports/metadata', renderer: 'pdf' });
}

/** startup */
function startup() {
Inventory.read()
Expand Down
6 changes: 6 additions & 0 deletions client/src/partials/patient_invoice/registry/registry.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
<span class="fa fa-search"></span> {{ "FORM.BUTTONS.SEARCH" | translate }}
</button>
</div>
<div class="toolbar-item">
<bh-pdf-print
pdf-url="invoices/patient/report"
>
</bh-pdf-print>
</div>
</div>
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions client/src/partials/templates/breadcrumb.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
</button>
</div>

<!-- buttons Print -->
<div class="toolbar-item btn-group btn-group-sm" ng-if="vm.buttonPrint.pdfUrl">
<bh-pdf-print
pdf-url="{{ vm.buttonPrint.pdfUrl }}">
</bh-pdf-print>
</div>

<!-- labels -->
<div class="toolbar-item" ng-if="vm.bcLabels.length">
<label ng-repeat="l in vm.bcLabels" id="{{ vm.prefix + l.id }}" data-method="{{ l.dataMethod }}">
Expand Down
6 changes: 4 additions & 2 deletions client/src/partials/vouchers/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<!-- breadcrumb header -->
<bh-breadcrumb
path="VoucherCtrl.bcPaths"
button="VoucherCtrl.bcButtons">
path = "VoucherCtrl.bcPaths"
button = "VoucherCtrl.bcButtons"
print = "VoucherCtrl.buttonPrint"
>
</bh-breadcrumb>

<div class="flex-util">
Expand Down
18 changes: 6 additions & 12 deletions client/src/partials/vouchers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
51 changes: 51 additions & 0 deletions server/controllers/finance/patientInvoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*
Expand Down Expand Up @@ -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);
}
54 changes: 54 additions & 0 deletions server/controllers/finance/receipts/list.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{> head title="INVOICE_REGISTRY.TITLE"}}

<body>
<div class="container">
<!-- header -->
<div class="row">
<div class="col-xs-4">
<h3 style="margin:2px;">{{model.enterprise.name}} ({{model.enterprise.abbr}})</h3>
<span>{{translate 'FORM.LABELS.PHONE'}}: {{model.enterprise.phone}}</span><br>
<span>{{translate 'FORM.LABELS.EMAIL'}}: {{model.enterprise.email}}</span><br>
</div>
<div class="col-xs-offset-4 col-xs-4 text-right">
<small>{{model.project.name}} ({{model.project.abbr}})</small>
</div>
</div>

<!-- body -->
<div class="row">
<div class="col-xs-12">

<!-- page title -->
<h2 style="margin:15px; font-weight:bold" class="text-center text-uppercase">
{{translate 'INVOICE_REGISTRY.TITLE'}}
</h2>

<!-- list of data -->
<table class="table table-condensed table-bordered table-striped">
<thead>
<tr>
<th>{{translate 'TABLE.COLUMNS.REFERENCE'}}</th>
<th>{{translate 'TABLE.COLUMNS.BILLING_DATE'}}</th>
<th>{{translate 'TABLE.COLUMNS.PATIENT'}}</th>
<th>{{translate 'TABLE.COLUMNS.COST'}}</th>
<th>{{translate 'TABLE.COLUMNS.SERVICE'}}</th>
<th>{{translate 'TABLE.COLUMNS.BY'}}</th>
</tr>
</thead>
<tbody>
{{#each model.data}}
<tr>
<td>{{ reference }}</td>
<td>{{ date date }}</td>
<td>{{ patientNames }}</td>
<td>{{ currency cost }}</td>
<td>{{ serviceName }}</td>
<td>{{ createdBy }}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</div>
</div>
</body>
42 changes: 42 additions & 0 deletions server/controllers/finance/receipts/list.js
Original file line number Diff line number Diff line change
@@ -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);
}

1 comment on commit 699372b

@lomamech
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding print functionality

  • Update bhBreadcrumb.js component for adding property print
  • Update template for breadCrumb with the using of bh-breadcrumb
  • Implement patient invoice report in PDF
  • Update inventory list, voucher registry for Prevent modale windows
  • Adding route for manage invoice / patient / report

@jniles

Please sign in to comment.