Skip to content

Commit

Permalink
feat(vouchers): POS receipt
Browse files Browse the repository at this point in the history
This commit implements a POS receipt for the voucher page.  This receipt
also puts the transaction type at the top of the receipt and groups by
debits/credits.

Fixes #184. Fixes #185.
  • Loading branch information
Jonathan Niles authored and jniles committed Feb 4, 2017
1 parent b093af8 commit 7f3e5e8
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 41 deletions.
1 change: 1 addition & 0 deletions client/src/js/services/receipts/ReceiptService.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function ReceiptService($http, util, Language, AppCache, Session) {

// print a complex voucher receipt
function voucher(uuid, options) {
options.posReceipt = service.posReceipt;
var route = '/reports/finance/vouchers/'.concat(uuid);
return fetch(route, options);
}
Expand Down
22 changes: 19 additions & 3 deletions server/controllers/finance/reports/vouchers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ const _ = require('lodash');
const ReportManager = require('../../../../lib/ReportManager');
const NotFound = require('../../../../lib/errors/NotFound');
const Vouchers = require('../../vouchers');
const pdf = require('../../../../lib/renderers/pdf');

// dependencies for barcode translation
const barcode = require('../../../../lib/barcode');
const identifiers = require('../../../../config/identifiers');
const entityIdentifier = identifiers.VOUCHER.key;

const RECEIPT_TEMPLATE = './server/controllers/finance/reports/vouchers/receipt.handlebars';
const POS_TEMPLATE = './server/controllers/finance/reports/vouchers/receipt.pos.handlebars';
const REPORT_TEMPLATE = './server/controllers/finance/reports/vouchers/report.handlebars';

exports.receipt = receipt;
Expand All @@ -39,25 +46,34 @@ function receipt(req, res, next) {
let data = {};
let record = {};

let template = RECEIPT_TEMPLATE;

if (Boolean(Number(options.posReceipt))) {
template = POS_TEMPLATE;
_.extend(options, pdf.posReceiptOptions);
}

try {
report = new ReportManager(RECEIPT_TEMPLATE, req.session, options);
report = new ReportManager(template, req.session, options);
} catch (e) {
return next(e);
}

// request for detailed receipt
req.query.detailed = true;
options.detailed = true;

Vouchers.getVouchers(req.params.uuid, options)
.then(rows => {

if (!rows.length) {
throw new NotFound(`Could not find a voucher with uuid ${req.params.uuid}`);
throw new NotFound(`Could not find a voucher with uuid ${req.params.uuid}.`);
}

// voucher details
record.details = rows[0];

record.details.barcode = barcode.generate(entityIdentifier, record.details.uuid);

// voucher transaction rows
record.rows = rows;

Expand Down
46 changes: 23 additions & 23 deletions server/controllers/finance/reports/vouchers/receipt.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@
<!-- headings -->
<div class="row">
<div class="col-xs-6">
<h3 style="margin: 0px;">{{enterprise.name}}</h3>
<p>
<span class="text-capitalize">{{translate 'FORM.LABELS.ADDRESS'}}</span>: {{enterprise.location}} <br>
<span class="text-capitalize">{{translate 'FORM.LABELS.PHONE'}}</span>: {{enterprise.phone}} <br>
<span class="text-capitalize">{{translate 'FORM.LABELS.EMAIL'}}</span>: {{enterprise.email}}
</p>
</div>
<div class="col-xs-6 text-right">
<h3 style="margin: 0px;">
<span class="text-uppercase">{{translate 'FORM.LABELS.VOUCHER'}}</span> <br>
<strong>ID: {{details.reference}}</strong> <br>
<small>{{date details.date}}</small> <br>
</h3>
</div>
<h3 style="margin: 0px;">{{enterprise.name}}</h3>
<p>
<span class="text-capitalize">{{translate 'FORM.LABELS.ADDRESS'}}</span>: {{enterprise.location}} <br>
<span class="text-capitalize">{{translate 'FORM.LABELS.PHONE'}}</span>: {{enterprise.phone}} <br>
<span class="text-capitalize">{{translate 'FORM.LABELS.EMAIL'}}</span>: {{enterprise.email}}
</p>
</div>
<div class="col-xs-6 text-right">
<h3 style="margin: 0px;">
<span class="text-uppercase">{{translate 'FORM.LABELS.VOUCHER'}}</span> <br>
<strong>{{details.reference}}</strong> <br>
<small>{{date details.date}}</small> <br>
</h3>
</div>
</div>

<!-- client and user details -->
<div class="row" style="border: 1px solid #ccc; padding: 5px; margin-bottom: 15px;">
<div class="col-xs-6">
<span class="text-capitalize">{{translate 'FORM.LABELS.PAYMENT'}}</span>: <strong>{{details.reference}}</strong> <br>
<div class="row" style="border: 1px solid #ccc; padding: 5px; margin-bottom: 15px;">
<div class="col-xs-6">
<span class="text-capitalize">{{translate 'FORM.LABELS.PAYMENT'}}</span>: <strong>{{details.reference}}</strong> <br>
<span class="text-capitalize">{{translate 'FORM.LABELS.AMOUNT'}}</span>: <strong>{{currency details.amount details.currency_id}}</strong> <br>
<span class="text-capitalize">{{translate 'FORM.LABELS.DATE'}}</span>: {{date details.date}} <br>
<span class="text-capitalize">{{translate "REPORT.PRODUCED_BY"}}</span>: {{details.display_name}}
</div>
</div>
<span class="text-capitalize">{{translate 'FORM.LABELS.DATE'}}</span>: {{date details.date}} <br>
<span class="text-capitalize">{{translate "REPORT.PRODUCED_BY"}}</span>: {{details.display_name}}
</div>
</div>
</header>

<!-- description -->
Expand All @@ -43,6 +43,7 @@
<h4>
<u>{{translate 'FORM.LABELS.DETAILS'}}</u>
</h4>

<table class="table table-condensed">
<thead>
<tr>
Expand Down Expand Up @@ -72,6 +73,5 @@
<h4>
<u>{{translate 'FORM.LABELS.SIGNATURE'}}s</u>
</h4>
<hr>

<hr />
</div>
46 changes: 46 additions & 0 deletions server/controllers/finance/reports/vouchers/receipt.pos.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<head>
<meta charset="utf-8" />
<script src="{{absolutePath}}/vendor/JsBarcode.all.min.js"></script>
</head>
<body>
<p><b style="text-transform : uppercase">{{enterprise.name}}</b></p>
<h2 style="text-align : left; margin : 0px">{{details.reference}}</h2>
<p style="margin-top : 0px">{{date details.date}} {{translate 'FORM.LABELS.BY'}} {{details.display_name}}</p>

<div style="text-align : center;">{{> barcode value=details.barcode}}</div>

<h2 style="margin-bottom : 0px">{{translate details.text}}</h2>

<p style="margin-bottom : 0px;">
{{details.description}}
</p>

<p style="font-weight : bold; text-decoration : underline; margin-bottom : 0px;">
{{details.reference}}
</p>

<table style="width : 100%">
<thead>
<tr>
<th></th><th></th>
</tr>
</thead>
<tbody>
{{#each rows as |item| }}
<tr>
<td>{{item.label}}</td>
<th style="text-align : right;">
{{#if item.credit}} {{currency item.credit ../details.currency_id}}{{/if}}
{{#if item.debit}} ({{currency item.debit ../details.currency_id}}){{/if}}
</th>
</tr>
{{/each}}
</tbody>
</table>

{{> underline}}

<h2 style="text-align : right;">{{translate "FORM.LABELS.TOTAL"}}: {{currency details.amount details.currency_id}}</h2>

<script>JsBarcode('.barcode').init();</script>
</body>
16 changes: 11 additions & 5 deletions server/controllers/finance/vouchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const NotFound = require('../../lib/errors/NotFound');
const BadRequest = require('../../lib/errors/BadRequest');

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

/** Get list of vouchers */
exports.list = list;
Expand Down Expand Up @@ -85,7 +86,10 @@ function detail(req, res, next) {
if (!rows.length) {
throw new NotFound(`Could not find a voucher with uuid ${req.params.uuid}`);
}
res.status(200).json(rows[0]);

let record = rows[0];

res.status(200).json(record);
})
.catch(next)
.done();
Expand Down Expand Up @@ -238,25 +242,27 @@ function getVouchers(uuid, request) {
function getSql(detailed) {
let sql = `
SELECT BUID(v.uuid) as uuid, v.date, v.project_id, v.currency_id, v.amount,
v.description, v.user_id, v.type_id, u.display_name,
CONCAT_WS('.', '${identifiers.VOUCHER.key}', p.abbr, v.reference) AS reference,
v.description, v.user_id, v.type_id, u.display_name, transaction_type.text,
CONCAT_WS('.', '${entityIdentifier}', p.abbr, v.reference) AS reference,
BUID(vi.document_uuid) AS document_uuid
FROM voucher v
JOIN voucher_item vi ON vi.voucher_uuid = v.uuid
JOIN project p ON p.id = v.project_id
JOIN user u ON u.id = v.user_id
LEFT JOIN transaction_type ON v.type_id = transaction_type.id
`;

let detailedSql =
`SELECT BUID(v.uuid) as uuid, v.date, v.project_id, v.currency_id, v.amount,
v.description, v.user_id, v.type_id, BUID(vi.document_uuid) as document_uuid,
BUID(vi.uuid) AS voucher_item_uuid, vi.account_id, vi.debit,
BUID(vi.uuid) AS voucher_item_uuid, vi.account_id, vi.debit, transaction_type.text,
vi.credit, a.number, a.label, u.display_name,
CONCAT_WS('.', '${identifiers.VOUCHER.key}', p.abbr, v.reference) AS reference
CONCAT_WS('.', '${entityIdentifier}', p.abbr, v.reference) AS reference
FROM voucher v
JOIN voucher_item vi ON vi.voucher_uuid = v.uuid
JOIN project p ON p.id = v.project_id
JOIN user u ON u.id = v.user_id
LEFT JOIN transaction_type ON v.type_id = transaction_type.id
JOIN account a ON a.id = vi.account_id `;

return !util.isFalsy(detailed) ? detailedSql : sql;
Expand Down
12 changes: 6 additions & 6 deletions server/lib/renderers/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ exports.posReceiptOptions = {

// smaller format for providing identifications/ receipts with reduced information
exports.reducedCardOptions = {
pageWidth : '75mm',
pageHeight : '125mm',
marginLeft : '5mm',
marginRight : '5mm',
marginTop : '5mm',
marginBottom : '5mm',
pageWidth : '75mm', // 2.95in
pageHeight : '125mm', // 4.92.in
marginLeft : '5mm', // 0.20in
marginRight : '5mm', // 0.20in
marginTop : '5mm', // 0.20in
marginBottom : '5mm', // 0.20in
orientation : 'landscape'
};

Expand Down
8 changes: 4 additions & 4 deletions server/models/test/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ SET @first_voucher = HUID('a5a5f950-a4c9-47f0-9a9a-2bfc3123e534');
SET @second_voucher = HUID('304cfa94-0249-466c-9870-95eb3c221b0a');
SET @third_voucher = HUID('3688e9ce-85ea-4b5c-9144-688177edcb63');

INSERT INTO `voucher` (uuid, `date`, project_id, currency_id, amount, description, user_id) VALUES
(@first_voucher, CURRENT_TIMESTAMP, 1, 2, 100, 'Sample voucher data one', 1),
(@second_voucher, CURRENT_TIMESTAMP, 2, 2, 200, 'Sample voucher data two', 1),
(@third_voucher, CURRENT_TIMESTAMP, 3, 1, 300, 'Sample voucher data three', 1);
INSERT INTO `voucher` (uuid, `date`, project_id, currency_id, amount, description, user_id, type_id) VALUES
(@first_voucher, CURRENT_TIMESTAMP, 1, 2, 100, 'Sample voucher data one', 1, 1),
(@second_voucher, CURRENT_TIMESTAMP, 2, 2, 200, 'Sample voucher data two', 1, NULL),
(@third_voucher, CURRENT_TIMESTAMP, 3, 1, 300, 'Sample voucher data three', 1, NULL);

-- voucher items sample data
INSERT INTO `voucher_item` VALUES
Expand Down

0 comments on commit 7f3e5e8

Please sign in to comment.