Skip to content

Commit

Permalink
Merge pull request #24 from sfount/receipt-barcode-standard
Browse files Browse the repository at this point in the history
Receipt Barcode Standard
  • Loading branch information
jniles authored Dec 22, 2016
2 parents f6fdc91 + 7b5596d commit 3480b59
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions server/controllers/finance/patientInvoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ const uuid = require('node-uuid');
const _ = require('lodash');

const identifiers = require('../../config/identifiers');
const entityIdentifier = identifiers.INVOICE;

const util = require('../../lib/util');
const db = require('../../lib/db');
const barcode = require('../../lib/barcode');

const NotFound = require('../../lib/errors/NotFound');
const BadRequest = require('../../lib/errors/BadRequest');
Expand Down Expand Up @@ -147,6 +149,9 @@ function lookupInvoice(invoiceUuid) {
})
.then(rows => {
record.subsidy = rows;

// provide barcode string to be rendered by client/ receipts
record.barcode = barcode.generate(entityIdentifier, record.uuid);
return record;
});
}
Expand Down
3 changes: 3 additions & 0 deletions server/controllers/finance/reports/invoices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
const q = require('q');
const _ = require('lodash');
const util = require('../../../../lib/util');

const moment = require('moment');

const ReportManager = require('../../../../lib/ReportManager');
Expand All @@ -27,6 +28,8 @@ const POS_RECEIPT_TEMPLATE = './server/controllers/finance/reports/invoices/rece
const RECEIPT_TEMPLATE = './server/controllers/finance/reports/invoices/receipt.handlebars';
const REPORT_TEMPLATE = './server/controllers/finance/reports/invoices/report.handlebars';

const invoiceIdentifier = require('../../../../config/identifiers').INVOICE;

exports.report = report;
exports.receipt = receipt;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<head>
<meta charset="utf-8" />
<script src="{{absolutePath}}/vendor/JsBarcode.all.min.js"></script>
</head>
<body>
<p><b style="text-transform : uppercase">{{translate 'HOME.BHIMA_FINANCE'}} - {{translate 'PATIENT_INVOICE.PAGE_TITLE'}}</b></p>
<p>----------------------------------------------------------------</p>
<!-- <p>----------------------------------------------------------------</p> -->
<div style="text-align : center;">{{> barcode value=barcode}}</div>
<p><b>{{recipient.display_name}}</b></p>
<p>{{recipient.debtor_group_name}}</p>
<p style="text-transform : uppercase">{{reference}} {{translate 'FORM.LABELS.ON'}} {{date date}} {{translate 'FORM.LABELS.BY'}} {{user.display_name}}</p>
Expand All @@ -28,5 +30,7 @@
</table>
<p>----------------------------------------------------------------</p>
<h2 style="text-align : right;">{{translate 'FORM.LABELS.TOTAL'}}: <b>{{currency cost metadata.enterprise.currency_id}}</b></h2>

<script>JsBarcode('.barcode').init();</script>
</body>

20 changes: 20 additions & 0 deletions server/lib/barcode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

exports.generate = generate;

/**
* @description
* Standard method for generating the code used to display bar codes, this
* provides a uniform interface ensuring that all barcodes displayed to users
* use the same schema.
*
* ##Current Schema
* ${receiptIdentifier}.${uuid(6)}
*
*/
const UUID_ACCURACY_LENGTH = 12;

function generate(receiptIdentifier, uuid) {
let entityIdentifier = uuid.substr(0, UUID_ACCURACY_LENGTH);

return `${receiptIdentifier}${entityIdentifier}`;
}
7 changes: 7 additions & 0 deletions server/lib/template/helpers/identifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const barcode = require('../../barcode');

function barcodeString(receiptIdentifier, uuid) {
return barcode.generate(receiptIdentifier, uuid);
}

exports.barcodeString = barcodeString;

0 comments on commit 3480b59

Please sign in to comment.