diff --git a/client/src/js/services/receipts/ReceiptService.js b/client/src/js/services/receipts/ReceiptService.js index 6bcdd3354f..75cd9c8518 100644 --- a/client/src/js/services/receipts/ReceiptService.js +++ b/client/src/js/services/receipts/ReceiptService.js @@ -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); } diff --git a/server/controllers/finance/reports/vouchers/index.js b/server/controllers/finance/reports/vouchers/index.js index f82d10fad1..8f11f410c3 100644 --- a/server/controllers/finance/reports/vouchers/index.js +++ b/server/controllers/finance/reports/vouchers/index.js @@ -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; @@ -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; diff --git a/server/controllers/finance/reports/vouchers/receipt.handlebars b/server/controllers/finance/reports/vouchers/receipt.handlebars index 580b67c9d2..ebd1ff4631 100644 --- a/server/controllers/finance/reports/vouchers/receipt.handlebars +++ b/server/controllers/finance/reports/vouchers/receipt.handlebars @@ -6,31 +6,31 @@
-

{{enterprise.name}}

-

- {{translate 'FORM.LABELS.ADDRESS'}}: {{enterprise.location}}
- {{translate 'FORM.LABELS.PHONE'}}: {{enterprise.phone}}
- {{translate 'FORM.LABELS.EMAIL'}}: {{enterprise.email}} -

-
-
-

- {{translate 'FORM.LABELS.VOUCHER'}}
- ID: {{details.reference}}
- {{date details.date}}
-

-
+

{{enterprise.name}}

+

+ {{translate 'FORM.LABELS.ADDRESS'}}: {{enterprise.location}}
+ {{translate 'FORM.LABELS.PHONE'}}: {{enterprise.phone}}
+ {{translate 'FORM.LABELS.EMAIL'}}: {{enterprise.email}} +

+
+
+

+ {{translate 'FORM.LABELS.VOUCHER'}}
+ {{details.reference}}
+ {{date details.date}}
+

+
-
-
- {{translate 'FORM.LABELS.PAYMENT'}}: {{details.reference}}
+
+
+ {{translate 'FORM.LABELS.PAYMENT'}}: {{details.reference}}
{{translate 'FORM.LABELS.AMOUNT'}}: {{currency details.amount details.currency_id}}
- {{translate 'FORM.LABELS.DATE'}}: {{date details.date}}
- {{translate "REPORT.PRODUCED_BY"}}: {{details.display_name}} -
-
+ {{translate 'FORM.LABELS.DATE'}}: {{date details.date}}
+ {{translate "REPORT.PRODUCED_BY"}}: {{details.display_name}} +
+
@@ -43,6 +43,7 @@

{{translate 'FORM.LABELS.DETAILS'}}

+ @@ -72,6 +73,5 @@

{{translate 'FORM.LABELS.SIGNATURE'}}s

-
- +
diff --git a/server/controllers/finance/reports/vouchers/receipt.pos.handlebars b/server/controllers/finance/reports/vouchers/receipt.pos.handlebars new file mode 100644 index 0000000000..ad2b944bef --- /dev/null +++ b/server/controllers/finance/reports/vouchers/receipt.pos.handlebars @@ -0,0 +1,46 @@ + + + + + +

{{enterprise.name}}

+

{{details.reference}}

+

{{date details.date}} {{translate 'FORM.LABELS.BY'}} {{details.display_name}}

+ +
{{> barcode value=details.barcode}}
+ +

{{translate details.text}}

+ +

+ {{details.description}} +

+ +

+ {{details.reference}} +

+ +
+ + + + + + + {{#each rows as |item| }} + + + + + {{/each}} + +
{{item.label}} + {{#if item.credit}} {{currency item.credit ../details.currency_id}}{{/if}} + {{#if item.debit}} ({{currency item.debit ../details.currency_id}}){{/if}} +
+ +{{> underline}} + +

{{translate "FORM.LABELS.TOTAL"}}: {{currency details.amount details.currency_id}}

+ + + diff --git a/server/controllers/finance/vouchers.js b/server/controllers/finance/vouchers.js index 1b39753187..d183c7944b 100644 --- a/server/controllers/finance/vouchers.js +++ b/server/controllers/finance/vouchers.js @@ -22,11 +22,13 @@ const uuid = require('node-uuid'); 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'); const identifiers = require('../../config/identifiers'); +const entityIdentifier = identifiers.VOUCHER.key; /** Get list of vouchers */ exports.list = list; @@ -85,7 +87,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(); @@ -237,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; diff --git a/server/lib/renderers/pdf.js b/server/lib/renderers/pdf.js index 1ea22fab4f..4a2f9b36cd 100644 --- a/server/lib/renderers/pdf.js +++ b/server/lib/renderers/pdf.js @@ -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' }; diff --git a/server/models/test/data.sql b/server/models/test/data.sql index fe5691960f..115768d1f3 100644 --- a/server/models/test/data.sql +++ b/server/models/test/data.sql @@ -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, 1, 2, 200, 'Sample voucher data two', 1), - (@third_voucher, CURRENT_TIMESTAMP, 1, 2, 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, 1, 2, 200, 'Sample voucher data two', 1, NULL), + (@third_voucher, CURRENT_TIMESTAMP, 1, 2, 300, 'Sample voucher data three', 1, NULL); -- voucher items sample data INSERT INTO `voucher_item` VALUES