From 490d96acf71f766d891d3e6feaf5e9a07ef39c4a Mon Sep 17 00:00:00 2001 From: Chris Lomame Date: Thu, 23 Jan 2020 12:27:19 +0100 Subject: [PATCH 1/3] improvement(Stock Mouvement Document) Set Voucher reference to - Adjustment Receipt - Donation Receipt - Integration Receipt - Purchase Receipt - Loss Receipt - Patient Receipt closes #2694 --- server/controllers/stock/reports/common.js | 2 ++ .../stock/reports/stock/adjustment_receipt.js | 21 ++++++++++++++++-- .../reports/stock/entry_donation_receipt.js | 21 +++++++++++++++--- .../stock/entry_integration_receipt.js | 22 ++++++++++++++++--- .../reports/stock/entry_purchase_receipt.js | 22 ++++++++++++++++--- .../stock/reports/stock/exit_loss_receipt.js | 20 ++++++++++++++--- .../reports/stock/exit_patient_receipt.js | 22 ++++++++++++++++--- .../stock_adjustment.receipt.handlebars | 3 +++ .../stock_entry_donation.receipt.handlebars | 3 +++ ...stock_entry_integration.receipt.handlebars | 3 +++ .../stock_entry_purchase.receipt.handlebars | 3 +++ .../stock_exit_loss.receipt.handlebars | 3 +++ .../stock_exit_patient.receipt.handlebars | 3 +++ 13 files changed, 131 insertions(+), 17 deletions(-) diff --git a/server/controllers/stock/reports/common.js b/server/controllers/stock/reports/common.js index 75b5da3ed1..382ab32ad9 100644 --- a/server/controllers/stock/reports/common.js +++ b/server/controllers/stock/reports/common.js @@ -32,6 +32,7 @@ const STOCK_VALUE_REPORT_TEMPLATE = `${BASE_PATH}/stock_value.report.handlebars` const _ = require('lodash'); // Application-specific imports +const q = require('q'); const db = require('../../../lib/db'); const util = require('../../../lib/util'); const Stock = require('../core'); @@ -185,6 +186,7 @@ const stockFluxReceipt = { // Exports exports._ = _; +exports.q = q; exports.db = db; exports.util = util; exports.pdf = pdf; diff --git a/server/controllers/stock/reports/stock/adjustment_receipt.js b/server/controllers/stock/reports/stock/adjustment_receipt.js index 634847b285..1bfd3a89ac 100644 --- a/server/controllers/stock/reports/stock/adjustment_receipt.js +++ b/server/controllers/stock/reports/stock/adjustment_receipt.js @@ -1,5 +1,5 @@ const { - _, ReportManager, Stock, NotFound, db, identifiers, barcode, STOCK_ADJUSTMENT_TEMPLATE, + _, ReportManager, Stock, NotFound, db, identifiers, barcode, STOCK_ADJUSTMENT_TEMPLATE, q, } = require('../common'); @@ -28,7 +28,23 @@ async function stockAdjustmentReceipt(documentUuid, session, options) { WHERE m.flux_id IN (${Stock.flux.FROM_ADJUSTMENT}, ${Stock.flux.TO_ADJUSTMENT}) AND m.document_uuid = ? `; - const rows = await db.exec(sql, [db.bid(documentUuid)]); + const sqlGetVoucherReference = ` + SELECT v.uuid, dm.text AS voucher_reference + FROM voucher AS v + JOIN voucher_item AS vi ON vi.voucher_uuid = v.uuid + JOIN document_map AS dm ON dm.uuid = v.uuid + WHERE vi.document_uuid = ? + LIMIT 1; + `; + + const results = await q.all([ + db.exec(sql, [db.bid(documentUuid)]), + db.exec(sqlGetVoucherReference, [db.bid(documentUuid)]), + ]); + + const rows = results[0]; + const voucherReference = results[1][0].voucher_reference; + if (!rows.length) { throw new NotFound('document not found'); } @@ -48,6 +64,7 @@ async function stockAdjustmentReceipt(documentUuid, session, options) { document_uuid : line.document_uuid, document_reference : line.document_reference, barcode : barcode.generate(key, line.document_uuid), + voucher_reference : voucherReference, }; data.rows = rows; diff --git a/server/controllers/stock/reports/stock/entry_donation_receipt.js b/server/controllers/stock/reports/stock/entry_donation_receipt.js index 43b10d6b4f..7ab6ad69ac 100644 --- a/server/controllers/stock/reports/stock/entry_donation_receipt.js +++ b/server/controllers/stock/reports/stock/entry_donation_receipt.js @@ -1,5 +1,5 @@ const { - _, ReportManager, Stock, NotFound, db, barcode, identifiers, STOCK_ENTRY_DONATION_TEMPLATE, + _, ReportManager, Stock, NotFound, db, barcode, identifiers, STOCK_ENTRY_DONATION_TEMPLATE, q, } = require('../common'); /** @@ -37,8 +37,22 @@ function stockEntryDonationReceipt(documentUuid, session, options) { ORDER BY i.text, l.label `; - return db.exec(sql, [db.bid(documentUuid)]) - .then((rows) => { + const sqlGetVoucherReference = ` + SELECT v.uuid, dm.text FROM voucher AS v + JOIN voucher_item AS vi ON vi.voucher_uuid = v.uuid + JOIN document_map AS dm ON dm.uuid = v.uuid + WHERE vi.document_uuid = ? + LIMIT 1; + `; + + return q.all([ + db.exec(sql, [db.bid(documentUuid)]), + db.exec(sqlGetVoucherReference, [db.bid(documentUuid)]), + ]) + .then((results) => { + const rows = results[0]; + const voucherReference = results[1][0].voucher_reference; + if (!rows.length) { throw new NotFound('document not found'); } @@ -55,6 +69,7 @@ function stockEntryDonationReceipt(documentUuid, session, options) { document_uuid : line.document_uuid, document_reference : line.document_reference, barcode : barcode.generate(key, line.document_uuid), + voucher_reference : voucherReference, }; data.rows = rows; diff --git a/server/controllers/stock/reports/stock/entry_integration_receipt.js b/server/controllers/stock/reports/stock/entry_integration_receipt.js index 966ee2bfc7..156f61437b 100644 --- a/server/controllers/stock/reports/stock/entry_integration_receipt.js +++ b/server/controllers/stock/reports/stock/entry_integration_receipt.js @@ -1,5 +1,5 @@ const { - _, ReportManager, Stock, NotFound, db, barcode, identifiers, STOCK_ENTRY_INTEGRATION_TEMPLATE, + _, ReportManager, Stock, NotFound, db, barcode, identifiers, STOCK_ENTRY_INTEGRATION_TEMPLATE, q, } = require('../common'); /** @@ -39,8 +39,23 @@ function stockEntryIntegrationReceipt(documentUuid, session, options) { ORDER BY i.text, l.label `; - return db.exec(sql, [db.bid(documentUuid)]) - .then((rows) => { + const sqlGetVoucherReference = ` + SELECT v.uuid, dm.text AS voucher_reference + FROM voucher AS v + JOIN voucher_item AS vi ON vi.voucher_uuid = v.uuid + JOIN document_map AS dm ON dm.uuid = v.uuid + WHERE vi.document_uuid = ? + LIMIT 1; + `; + + return q.all([ + db.exec(sql, [db.bid(documentUuid)]), + db.exec(sqlGetVoucherReference, [db.bid(documentUuid)]), + ]) + .then((results) => { + const rows = results[0]; + const voucherReference = results[1][0].voucher_reference; + if (!rows.length) { throw new NotFound('document not found'); } @@ -60,6 +75,7 @@ function stockEntryIntegrationReceipt(documentUuid, session, options) { integration_date : line.integration_date, project_display_name : line.project_display_name, barcode : barcode.generate(key, line.document_uuid), + voucher_reference : voucherReference, }; data.rows = rows; diff --git a/server/controllers/stock/reports/stock/entry_purchase_receipt.js b/server/controllers/stock/reports/stock/entry_purchase_receipt.js index 9561b4b5a2..2a295b201f 100644 --- a/server/controllers/stock/reports/stock/entry_purchase_receipt.js +++ b/server/controllers/stock/reports/stock/entry_purchase_receipt.js @@ -1,5 +1,5 @@ const { - _, ReportManager, Stock, identifiers, NotFound, db, barcode, STOCK_ENTRY_PURCHASE_TEMPLATE, + _, ReportManager, Stock, identifiers, NotFound, db, barcode, STOCK_ENTRY_PURCHASE_TEMPLATE, q, } = require('../common'); /** @@ -38,8 +38,23 @@ function stockEntryPurchaseReceipt(documentUuid, session, options) { ORDER BY i.text, l.label `; - return db.exec(sql, [db.bid(documentUuid)]) - .then((rows) => { + const sqlGetVoucherReference = ` + SELECT v.uuid, dm.text AS voucher_reference + FROM voucher AS v + JOIN voucher_item AS vi ON vi.voucher_uuid = v.uuid + JOIN document_map AS dm ON dm.uuid = v.uuid + WHERE vi.document_uuid = ? + LIMIT 1; + `; + + return q.all([ + db.exec(sql, [db.bid(documentUuid)]), + db.exec(sqlGetVoucherReference, [db.bid(documentUuid)]), + ]) + .then((results) => { + const rows = results[0]; + const voucherReference = results[1][0].voucher_reference; + if (!rows.length) { throw new NotFound('document not found'); } @@ -64,6 +79,7 @@ function stockEntryPurchaseReceipt(documentUuid, session, options) { supplier_display_name : line.supplier_display_name, project_display_name : line.project_display_name, barcode : barcode.generate(key, line.document_uuid), + voucher_reference : voucherReference, }; data.rows = rows; diff --git a/server/controllers/stock/reports/stock/exit_loss_receipt.js b/server/controllers/stock/reports/stock/exit_loss_receipt.js index 09ceed91fa..57e4cba1dc 100644 --- a/server/controllers/stock/reports/stock/exit_loss_receipt.js +++ b/server/controllers/stock/reports/stock/exit_loss_receipt.js @@ -1,6 +1,6 @@ const { _, ReportManager, Stock, NotFound, db, barcode, pdf, identifiers, - STOCK_EXIT_LOSS_TEMPLATE, POS_STOCK_EXIT_LOSS_TEMPLATE, + STOCK_EXIT_LOSS_TEMPLATE, POS_STOCK_EXIT_LOSS_TEMPLATE, q, } = require('../common'); /** @@ -41,8 +41,21 @@ function stockExitLossReceipt(documentUuid, session, options) { WHERE m.is_exit = 1 AND m.flux_id = ${Stock.flux.TO_LOSS} AND m.document_uuid = ? `; - return db.exec(sql, [db.bid(documentUuid)]) - .then((rows) => { + const sqlGetVoucherReference = ` + SELECT v.uuid, dm.text FROM voucher AS v + JOIN voucher_item AS vi ON vi.voucher_uuid = v.uuid + JOIN document_map AS dm ON dm.uuid = v.uuid + WHERE vi.document_uuid = ? + LIMIT 1; + `; + + return q.all([ + db.exec(sql, [db.bid(documentUuid)]), + db.exec(sqlGetVoucherReference, [db.bid(documentUuid)]), + ]) + .then((results) => { + const rows = results[0]; + const voucherReference = results[1][0].voucher_reference; if (!rows.length) { throw new NotFound('document not found'); } @@ -58,6 +71,7 @@ function stockExitLossReceipt(documentUuid, session, options) { document_uuid : line.document_uuid, document_reference : line.document_reference, barcode : barcode.generate(key, line.document_uuid), + voucher_reference : voucherReference, }; data.rows = rows; diff --git a/server/controllers/stock/reports/stock/exit_patient_receipt.js b/server/controllers/stock/reports/stock/exit_patient_receipt.js index 3adf6741ed..d0fbcc13c7 100644 --- a/server/controllers/stock/reports/stock/exit_patient_receipt.js +++ b/server/controllers/stock/reports/stock/exit_patient_receipt.js @@ -1,6 +1,6 @@ const { _, ReportManager, NotFound, Stock, db, identifiers, pdf, barcode, - STOCK_EXIT_PATIENT_TEMPLATE, POS_STOCK_EXIT_PATIENT_TEMPLATE, + STOCK_EXIT_PATIENT_TEMPLATE, POS_STOCK_EXIT_PATIENT_TEMPLATE, q, } = require('../common'); /** @@ -44,8 +44,23 @@ function stockExitPatientReceipt(documentUuid, session, options) { WHERE m.is_exit = 1 AND m.flux_id = ${Stock.flux.TO_PATIENT} AND m.document_uuid = ? `; - return db.exec(sql, [db.bid(documentUuid)]) - .then((rows) => { + const sqlGetVoucherReference = ` + SELECT v.uuid, dm.text AS voucher_reference + FROM voucher AS v + JOIN voucher_item AS vi ON vi.voucher_uuid = v.uuid + JOIN document_map AS dm ON dm.uuid = v.uuid + WHERE vi.document_uuid = ? + LIMIT 1; + `; + + return q.all([ + db.exec(sql, [db.bid(documentUuid)]), + db.exec(sqlGetVoucherReference, [db.bid(documentUuid)]), + ]) + .then((results) => { + const rows = results[0]; + const voucherReference = results[1][0].voucher_reference; + if (!rows.length) { throw new NotFound('document not found'); } @@ -65,6 +80,7 @@ function stockExitPatientReceipt(documentUuid, session, options) { document_uuid : line.document_uuid, document_reference : line.document_reference, barcode : barcode.generate(key, line.document_uuid), + voucher_reference : voucherReference, }; data.rows = rows; diff --git a/server/controllers/stock/reports/stock_adjustment.receipt.handlebars b/server/controllers/stock/reports/stock_adjustment.receipt.handlebars index 25afb12f88..c039d4a34c 100644 --- a/server/controllers/stock/reports/stock_adjustment.receipt.handlebars +++ b/server/controllers/stock/reports/stock_adjustment.receipt.handlebars @@ -24,6 +24,9 @@
{{translate 'STOCK.DEPOT'}}: {{details.depot_name}}
{{translate 'FORM.LABELS.DOCUMENT'}}: {{details.document_reference}}
+ {{#if details.voucher_reference}} + {{translate 'FORM.LABELS.VOUCHER'}}: {{details.voucher_reference}}
+ {{/if}} {{translate 'FORM.LABELS.DATE'}}: {{date details.date}}
{{translate "TABLE.COLUMNS.CREATED_BY"}}: {{details.user_display_name}}
diff --git a/server/controllers/stock/reports/stock_entry_donation.receipt.handlebars b/server/controllers/stock/reports/stock_entry_donation.receipt.handlebars index 36e4491cc9..3347e31895 100644 --- a/server/controllers/stock/reports/stock_entry_donation.receipt.handlebars +++ b/server/controllers/stock/reports/stock_entry_donation.receipt.handlebars @@ -22,6 +22,9 @@

{{translate 'STOCK.TO'}}

{{translate 'STOCK.DEPOT'}}: {{details.depot_name}}
{{translate 'FORM.LABELS.DOCUMENT'}}: {{details.document_reference}}
+ {{#if details.voucher_reference}} + {{translate 'FORM.LABELS.VOUCHER'}}: {{details.voucher_reference}}
+ {{/if}} {{translate 'FORM.LABELS.DATE'}}: {{date details.date}}
{{translate 'FORM.LABELS.COST'}}: {{currency (sum rows 'total') enterprise.currency_id}}
{{translate 'STOCK.INVENTORY'}}: {{rows.length}} {{translate 'STOCK.ITEMS'}}
diff --git a/server/controllers/stock/reports/stock_entry_integration.receipt.handlebars b/server/controllers/stock/reports/stock_entry_integration.receipt.handlebars index 79e1967c9c..31d95be1fe 100644 --- a/server/controllers/stock/reports/stock_entry_integration.receipt.handlebars +++ b/server/controllers/stock/reports/stock_entry_integration.receipt.handlebars @@ -24,6 +24,9 @@

{{translate 'STOCK.TO'}}

{{translate 'STOCK.DEPOT'}}: {{details.depot_name}}
{{translate 'FORM.LABELS.DOCUMENT'}}: {{details.document_reference}}
+ {{#if details.voucher_reference}} + {{translate 'FORM.LABELS.VOUCHER'}}: {{details.voucher_reference}}
+ {{/if}} {{translate 'FORM.LABELS.DATE'}}: {{date details.date}}
{{translate 'FORM.LABELS.COST'}}: {{currency (sum rows 'total') enterprise.currency_id}}
{{translate 'STOCK.INVENTORY'}}: {{rows.length}} {{translate 'STOCK.ITEMS'}}
diff --git a/server/controllers/stock/reports/stock_entry_purchase.receipt.handlebars b/server/controllers/stock/reports/stock_entry_purchase.receipt.handlebars index 744a926194..494ed2706c 100644 --- a/server/controllers/stock/reports/stock_entry_purchase.receipt.handlebars +++ b/server/controllers/stock/reports/stock_entry_purchase.receipt.handlebars @@ -27,6 +27,9 @@

{{translate 'STOCK.TO'}}

{{translate 'STOCK.DEPOT'}}: {{details.depot_name}}
{{translate 'FORM.LABELS.DOCUMENT'}}: {{details.document_reference}}
+ {{#if details.voucher_reference}} + {{translate 'FORM.LABELS.VOUCHER'}}: {{details.voucher_reference}}
+ {{/if}} {{translate 'FORM.LABELS.DATE'}}: {{date details.date}}
{{translate 'FORM.LABELS.COST'}}: {{currency (sum rows 'total') enterprise.currency_id}}
{{translate 'STOCK.INVENTORY'}}: {{rows.length}} {{translate 'STOCK.ITEMS'}}
diff --git a/server/controllers/stock/reports/stock_exit_loss.receipt.handlebars b/server/controllers/stock/reports/stock_exit_loss.receipt.handlebars index 3b98819e39..7659439c65 100644 --- a/server/controllers/stock/reports/stock_exit_loss.receipt.handlebars +++ b/server/controllers/stock/reports/stock_exit_loss.receipt.handlebars @@ -21,6 +21,9 @@
{{translate 'STOCK.DEPOT'}}: {{details.depot_name}}
{{translate 'FORM.LABELS.DOCUMENT'}}: {{details.document_reference}}
+ {{#if details.voucher_reference}} + {{translate 'FORM.LABELS.VOUCHER'}}: {{details.voucher_reference}}
+ {{/if}} {{translate 'FORM.LABELS.DATE'}}: {{date details.date}}
{{translate "TABLE.COLUMNS.CREATED_BY"}}: {{details.user_display_name}}
diff --git a/server/controllers/stock/reports/stock_exit_patient.receipt.handlebars b/server/controllers/stock/reports/stock_exit_patient.receipt.handlebars index 5c4e8e7018..29723f5394 100644 --- a/server/controllers/stock/reports/stock_exit_patient.receipt.handlebars +++ b/server/controllers/stock/reports/stock_exit_patient.receipt.handlebars @@ -22,6 +22,9 @@
{{translate 'STOCK.DEPOT'}}: {{details.depot_name}}
{{translate 'FORM.LABELS.DOCUMENT'}}: {{details.document_reference}}
+ {{#if details.voucher_reference}} + {{translate 'FORM.LABELS.VOUCHER'}}: {{details.voucher_reference}}
+ {{/if}} {{translate 'FORM.LABELS.DATE'}}: {{date details.date}}
{{translate "TABLE.COLUMNS.CREATED_BY"}}: {{details.user_display_name}}
From 5625a89eb71e367db0331ec4c45601e87dc23470 Mon Sep 17 00:00:00 2001 From: Chris Lomame Date: Fri, 24 Jan 2020 10:34:04 +0100 Subject: [PATCH 2/3] improvement(Stock Movement Link Voucher Transaction) - Set the function getVoucherReferenceForStockMovement in stock/reports/common.js --- server/controllers/stock/reports/common.js | 14 ++++ .../stock/reports/stock/adjustment_receipt.js | 19 ++--- .../reports/stock/entry_donation_receipt.js | 71 ++++++++--------- .../stock/entry_integration_receipt.js | 70 ++++++++--------- .../reports/stock/entry_purchase_receipt.js | 77 ++++++++----------- .../stock/reports/stock/exit_loss_receipt.js | 64 +++++++-------- .../reports/stock/exit_patient_receipt.js | 71 ++++++++--------- 7 files changed, 178 insertions(+), 208 deletions(-) diff --git a/server/controllers/stock/reports/common.js b/server/controllers/stock/reports/common.js index 382ab32ad9..2d3b139f22 100644 --- a/server/controllers/stock/reports/common.js +++ b/server/controllers/stock/reports/common.js @@ -159,6 +159,19 @@ const pdfOptions = { footerFontSize : '7', }; +async function getVoucherReferenceForStockMovement(documentUuid) { + const sql = ` + SELECT v.uuid, dm.text AS voucher_reference + FROM voucher AS v + JOIN voucher_item AS vi ON vi.voucher_uuid = v.uuid + JOIN document_map AS dm ON dm.uuid = v.uuid + WHERE vi.document_uuid = ? + LIMIT 1; + `; + + return db.exec(sql, [db.bid(documentUuid)]); +} + /** * Stock Receipt API * /receipts/stock/{{name}}/:document_uuid @@ -200,6 +213,7 @@ exports.stockFluxReceipt = stockFluxReceipt; exports.formatFilters = formatFilters; exports.identifiers = identifiers; exports.getDepotMovement = getDepotMovement; +exports.getVoucherReferenceForStockMovement = getVoucherReferenceForStockMovement; exports.pdfOptions = pdfOptions; diff --git a/server/controllers/stock/reports/stock/adjustment_receipt.js b/server/controllers/stock/reports/stock/adjustment_receipt.js index 1bfd3a89ac..40c6fcf8ba 100644 --- a/server/controllers/stock/reports/stock/adjustment_receipt.js +++ b/server/controllers/stock/reports/stock/adjustment_receipt.js @@ -1,5 +1,6 @@ const { - _, ReportManager, Stock, NotFound, db, identifiers, barcode, STOCK_ADJUSTMENT_TEMPLATE, q, + _, ReportManager, Stock, NotFound, db, identifiers, barcode, STOCK_ADJUSTMENT_TEMPLATE, + getVoucherReferenceForStockMovement, } = require('../common'); @@ -28,20 +29,14 @@ async function stockAdjustmentReceipt(documentUuid, session, options) { WHERE m.flux_id IN (${Stock.flux.FROM_ADJUSTMENT}, ${Stock.flux.TO_ADJUSTMENT}) AND m.document_uuid = ? `; - const sqlGetVoucherReference = ` - SELECT v.uuid, dm.text AS voucher_reference - FROM voucher AS v - JOIN voucher_item AS vi ON vi.voucher_uuid = v.uuid - JOIN document_map AS dm ON dm.uuid = v.uuid - WHERE vi.document_uuid = ? - LIMIT 1; - `; - - const results = await q.all([ + const results = await Promise.all([ db.exec(sql, [db.bid(documentUuid)]), - db.exec(sqlGetVoucherReference, [db.bid(documentUuid)]), + getVoucherReferenceForStockMovement(documentUuid), ]); + console.log('PLUSSSSSSssssss'); + console.log(results); + const rows = results[0]; const voucherReference = results[1][0].voucher_reference; diff --git a/server/controllers/stock/reports/stock/entry_donation_receipt.js b/server/controllers/stock/reports/stock/entry_donation_receipt.js index 7ab6ad69ac..176b78663e 100644 --- a/server/controllers/stock/reports/stock/entry_donation_receipt.js +++ b/server/controllers/stock/reports/stock/entry_donation_receipt.js @@ -1,5 +1,6 @@ const { - _, ReportManager, Stock, NotFound, db, barcode, identifiers, STOCK_ENTRY_DONATION_TEMPLATE, q, + _, ReportManager, Stock, NotFound, db, barcode, identifiers, STOCK_ENTRY_DONATION_TEMPLATE, + getVoucherReferenceForStockMovement, } = require('../common'); /** @@ -9,7 +10,7 @@ const { * This method builds the stock inventory report as either a JSON, PDF, or HTML * file to be sent to the client. */ -function stockEntryDonationReceipt(documentUuid, session, options) { +async function stockEntryDonationReceipt(documentUuid, session, options) { const data = {}; const optionReport = _.extend(options, { filename : 'STOCK.RECEIPTS.ENTRY_DONATION' }); @@ -37,50 +38,42 @@ function stockEntryDonationReceipt(documentUuid, session, options) { ORDER BY i.text, l.label `; - const sqlGetVoucherReference = ` - SELECT v.uuid, dm.text FROM voucher AS v - JOIN voucher_item AS vi ON vi.voucher_uuid = v.uuid - JOIN document_map AS dm ON dm.uuid = v.uuid - WHERE vi.document_uuid = ? - LIMIT 1; - `; - - return q.all([ + const results = await Promise.all([ db.exec(sql, [db.bid(documentUuid)]), - db.exec(sqlGetVoucherReference, [db.bid(documentUuid)]), - ]) - .then((results) => { - const rows = results[0]; - const voucherReference = results[1][0].voucher_reference; + getVoucherReferenceForStockMovement(documentUuid), + ]); + + const rows = results[0]; + const voucherReference = results[1][0].voucher_reference; + + if (!rows.length) { + throw new NotFound('document not found'); + } + const line = rows[0]; + const { key } = identifiers.STOCK_ENTRY; - if (!rows.length) { - throw new NotFound('document not found'); - } - const line = rows[0]; - const { key } = identifiers.STOCK_ENTRY; + data.enterprise = session.enterprise; - data.enterprise = session.enterprise; + data.details = { + depot_name : line.depot_name, + user_display_name : line.user_display_name, + description : line.description, + date : line.date, + document_uuid : line.document_uuid, + document_reference : line.document_reference, + barcode : barcode.generate(key, line.document_uuid), + voucher_reference : voucherReference, + }; - data.details = { - depot_name : line.depot_name, - user_display_name : line.user_display_name, - description : line.description, - date : line.date, - document_uuid : line.document_uuid, - document_reference : line.document_reference, - barcode : barcode.generate(key, line.document_uuid), - voucher_reference : voucherReference, - }; + data.rows = rows; - data.rows = rows; + // sum elements of rows by their `total` property + data.total = data.rows.reduce((aggregate, row) => { + return row.total + aggregate; + }, 0); - // sum elements of rows by their `total` property - data.total = data.rows.reduce((aggregate, row) => { - return row.total + aggregate; - }, 0); + return report.render(data); - return report.render(data); - }); } module.exports = stockEntryDonationReceipt; diff --git a/server/controllers/stock/reports/stock/entry_integration_receipt.js b/server/controllers/stock/reports/stock/entry_integration_receipt.js index 156f61437b..d50520306c 100644 --- a/server/controllers/stock/reports/stock/entry_integration_receipt.js +++ b/server/controllers/stock/reports/stock/entry_integration_receipt.js @@ -1,5 +1,6 @@ const { - _, ReportManager, Stock, NotFound, db, barcode, identifiers, STOCK_ENTRY_INTEGRATION_TEMPLATE, q, + _, ReportManager, Stock, NotFound, db, barcode, identifiers, STOCK_ENTRY_INTEGRATION_TEMPLATE, + getVoucherReferenceForStockMovement, } = require('../common'); /** @@ -11,7 +12,7 @@ const { * * GET /receipts/stock/entry_integration/:document_uuid */ -function stockEntryIntegrationReceipt(documentUuid, session, options) { +async function stockEntryIntegrationReceipt(documentUuid, session, options) { const data = {}; const optionReport = _.extend(options, { filename : 'STOCK.RECEIPTS.ENTRY_INTEGRATION' }); @@ -39,48 +40,39 @@ function stockEntryIntegrationReceipt(documentUuid, session, options) { ORDER BY i.text, l.label `; - const sqlGetVoucherReference = ` - SELECT v.uuid, dm.text AS voucher_reference - FROM voucher AS v - JOIN voucher_item AS vi ON vi.voucher_uuid = v.uuid - JOIN document_map AS dm ON dm.uuid = v.uuid - WHERE vi.document_uuid = ? - LIMIT 1; - `; - - return q.all([ + const results = await Promise.all([ db.exec(sql, [db.bid(documentUuid)]), - db.exec(sqlGetVoucherReference, [db.bid(documentUuid)]), - ]) - .then((results) => { - const rows = results[0]; - const voucherReference = results[1][0].voucher_reference; + getVoucherReferenceForStockMovement(documentUuid), + ]); + + const rows = results[0]; + const voucherReference = results[1][0].voucher_reference; + + if (!rows.length) { + throw new NotFound('document not found'); + } + const line = rows[0]; + const { key } = identifiers.STOCK_ENTRY; - if (!rows.length) { - throw new NotFound('document not found'); - } - const line = rows[0]; - const { key } = identifiers.STOCK_ENTRY; + data.enterprise = session.enterprise; - data.enterprise = session.enterprise; + data.details = { + depot_name : line.depot_name, + user_display_name : line.user_display_name, + description : line.description, + date : line.date, + document_uuid : line.document_uuid, + document_reference : line.document_reference, + integration_reference : line.integration_reference, + integration_date : line.integration_date, + project_display_name : line.project_display_name, + barcode : barcode.generate(key, line.document_uuid), + voucher_reference : voucherReference, + }; - data.details = { - depot_name : line.depot_name, - user_display_name : line.user_display_name, - description : line.description, - date : line.date, - document_uuid : line.document_uuid, - document_reference : line.document_reference, - integration_reference : line.integration_reference, - integration_date : line.integration_date, - project_display_name : line.project_display_name, - barcode : barcode.generate(key, line.document_uuid), - voucher_reference : voucherReference, - }; + data.rows = rows; + return report.render(data); - data.rows = rows; - return report.render(data); - }); } module.exports = stockEntryIntegrationReceipt; diff --git a/server/controllers/stock/reports/stock/entry_purchase_receipt.js b/server/controllers/stock/reports/stock/entry_purchase_receipt.js index 2a295b201f..6989b71282 100644 --- a/server/controllers/stock/reports/stock/entry_purchase_receipt.js +++ b/server/controllers/stock/reports/stock/entry_purchase_receipt.js @@ -1,5 +1,6 @@ const { - _, ReportManager, Stock, identifiers, NotFound, db, barcode, STOCK_ENTRY_PURCHASE_TEMPLATE, q, + _, ReportManager, Stock, identifiers, NotFound, db, barcode, STOCK_ENTRY_PURCHASE_TEMPLATE, + getVoucherReferenceForStockMovement, } = require('../common'); /** @@ -9,7 +10,7 @@ const { * This method builds the stock inventory report as either a JSON, PDF, or HTML * file to be sent to the client. */ -function stockEntryPurchaseReceipt(documentUuid, session, options) { +async function stockEntryPurchaseReceipt(documentUuid, session, options) { const data = {}; const optionReport = _.extend(options, { filename : 'STOCK.RECEIPTS.ENTRY_PURCHASE' }); @@ -38,53 +39,43 @@ function stockEntryPurchaseReceipt(documentUuid, session, options) { ORDER BY i.text, l.label `; - const sqlGetVoucherReference = ` - SELECT v.uuid, dm.text AS voucher_reference - FROM voucher AS v - JOIN voucher_item AS vi ON vi.voucher_uuid = v.uuid - JOIN document_map AS dm ON dm.uuid = v.uuid - WHERE vi.document_uuid = ? - LIMIT 1; - `; - - return q.all([ + const results = await Promise.all([ db.exec(sql, [db.bid(documentUuid)]), - db.exec(sqlGetVoucherReference, [db.bid(documentUuid)]), - ]) - .then((results) => { - const rows = results[0]; - const voucherReference = results[1][0].voucher_reference; + getVoucherReferenceForStockMovement(documentUuid), + ]); + + const rows = results[0]; + const voucherReference = results[1][0].voucher_reference; - if (!rows.length) { - throw new NotFound('document not found'); - } + if (!rows.length) { + throw new NotFound('document not found'); + } - const line = rows[0]; - const { key } = identifiers.STOCK_ENTRY; + const line = rows[0]; + const { key } = identifiers.STOCK_ENTRY; - data.enterprise = session.enterprise; + data.enterprise = session.enterprise; - data.details = { - depot_name : line.depot_name, - user_display_name : line.user_display_name, - description : line.description, - date : line.date, - document_uuid : line.document_uuid, - document_reference : line.document_reference, - purchase_reference : line.purchase_reference, - p_note : line.note, - p_cost : line.cost, - p_date : line.purchase_date, - p_method : line.payment_method, - supplier_display_name : line.supplier_display_name, - project_display_name : line.project_display_name, - barcode : barcode.generate(key, line.document_uuid), - voucher_reference : voucherReference, - }; + data.details = { + depot_name : line.depot_name, + user_display_name : line.user_display_name, + description : line.description, + date : line.date, + document_uuid : line.document_uuid, + document_reference : line.document_reference, + purchase_reference : line.purchase_reference, + p_note : line.note, + p_cost : line.cost, + p_date : line.purchase_date, + p_method : line.payment_method, + supplier_display_name : line.supplier_display_name, + project_display_name : line.project_display_name, + barcode : barcode.generate(key, line.document_uuid), + voucher_reference : voucherReference, + }; - data.rows = rows; - return report.render(data); - }); + data.rows = rows; + return report.render(data); } module.exports = stockEntryPurchaseReceipt; diff --git a/server/controllers/stock/reports/stock/exit_loss_receipt.js b/server/controllers/stock/reports/stock/exit_loss_receipt.js index 57e4cba1dc..9fa73e043c 100644 --- a/server/controllers/stock/reports/stock/exit_loss_receipt.js +++ b/server/controllers/stock/reports/stock/exit_loss_receipt.js @@ -1,6 +1,7 @@ const { _, ReportManager, Stock, NotFound, db, barcode, pdf, identifiers, - STOCK_EXIT_LOSS_TEMPLATE, POS_STOCK_EXIT_LOSS_TEMPLATE, q, + STOCK_EXIT_LOSS_TEMPLATE, POS_STOCK_EXIT_LOSS_TEMPLATE, + getVoucherReferenceForStockMovement, } = require('../common'); /** @@ -12,7 +13,7 @@ const { * * GET /receipts/stock/exit_loss/:document_uuid */ -function stockExitLossReceipt(documentUuid, session, options) { +async function stockExitLossReceipt(documentUuid, session, options) { const data = {}; const optionReport = _.extend(options, { filename : 'STOCK.REPORTS.EXIT_LOSS' }); @@ -41,42 +42,35 @@ function stockExitLossReceipt(documentUuid, session, options) { WHERE m.is_exit = 1 AND m.flux_id = ${Stock.flux.TO_LOSS} AND m.document_uuid = ? `; - const sqlGetVoucherReference = ` - SELECT v.uuid, dm.text FROM voucher AS v - JOIN voucher_item AS vi ON vi.voucher_uuid = v.uuid - JOIN document_map AS dm ON dm.uuid = v.uuid - WHERE vi.document_uuid = ? - LIMIT 1; - `; - - return q.all([ + const results = await Promise.all([ db.exec(sql, [db.bid(documentUuid)]), - db.exec(sqlGetVoucherReference, [db.bid(documentUuid)]), - ]) - .then((results) => { - const rows = results[0]; - const voucherReference = results[1][0].voucher_reference; - if (!rows.length) { - throw new NotFound('document not found'); - } - const line = rows[0]; - const { key } = identifiers.STOCK_EXIT; - data.enterprise = session.enterprise; + getVoucherReferenceForStockMovement(documentUuid), + ]); + + const rows = results[0]; + const voucherReference = results[1][0].voucher_reference; + + if (!rows.length) { + throw new NotFound('document not found'); + } + const line = rows[0]; + const { key } = identifiers.STOCK_EXIT; + data.enterprise = session.enterprise; + + data.details = { + depot_name : line.depot_name, + user_display_name : line.user_display_name, + description : line.description, + date : line.date, + document_uuid : line.document_uuid, + document_reference : line.document_reference, + barcode : barcode.generate(key, line.document_uuid), + voucher_reference : voucherReference, + }; - data.details = { - depot_name : line.depot_name, - user_display_name : line.user_display_name, - description : line.description, - date : line.date, - document_uuid : line.document_uuid, - document_reference : line.document_reference, - barcode : barcode.generate(key, line.document_uuid), - voucher_reference : voucherReference, - }; + data.rows = rows; + return report.render(data); - data.rows = rows; - return report.render(data); - }); } module.exports = stockExitLossReceipt; diff --git a/server/controllers/stock/reports/stock/exit_patient_receipt.js b/server/controllers/stock/reports/stock/exit_patient_receipt.js index d0fbcc13c7..aeb3662985 100644 --- a/server/controllers/stock/reports/stock/exit_patient_receipt.js +++ b/server/controllers/stock/reports/stock/exit_patient_receipt.js @@ -1,6 +1,7 @@ const { _, ReportManager, NotFound, Stock, db, identifiers, pdf, barcode, - STOCK_EXIT_PATIENT_TEMPLATE, POS_STOCK_EXIT_PATIENT_TEMPLATE, q, + STOCK_EXIT_PATIENT_TEMPLATE, POS_STOCK_EXIT_PATIENT_TEMPLATE, + getVoucherReferenceForStockMovement, } = require('../common'); /** @@ -12,7 +13,7 @@ const { * * GET /receipts/stock/exit_patient/:document_uuid */ -function stockExitPatientReceipt(documentUuid, session, options) { +async function stockExitPatientReceipt(documentUuid, session, options) { const data = {}; const optionReport = _.extend(options, { filename : 'STOCK.REPORTS.EXIT_PATIENT' }); @@ -44,48 +45,38 @@ function stockExitPatientReceipt(documentUuid, session, options) { WHERE m.is_exit = 1 AND m.flux_id = ${Stock.flux.TO_PATIENT} AND m.document_uuid = ? `; - const sqlGetVoucherReference = ` - SELECT v.uuid, dm.text AS voucher_reference - FROM voucher AS v - JOIN voucher_item AS vi ON vi.voucher_uuid = v.uuid - JOIN document_map AS dm ON dm.uuid = v.uuid - WHERE vi.document_uuid = ? - LIMIT 1; - `; - - return q.all([ + const results = await Promise.all([ db.exec(sql, [db.bid(documentUuid)]), - db.exec(sqlGetVoucherReference, [db.bid(documentUuid)]), - ]) - .then((results) => { - const rows = results[0]; - const voucherReference = results[1][0].voucher_reference; + getVoucherReferenceForStockMovement(documentUuid), + ]); - if (!rows.length) { - throw new NotFound('document not found'); - } - const line = rows[0]; - const { key } = identifiers.STOCK_EXIT; - data.enterprise = session.enterprise; + const rows = results[0]; + const voucherReference = results[1][0].voucher_reference; + + if (!rows.length) { + throw new NotFound('document not found'); + } + const line = rows[0]; + const { key } = identifiers.STOCK_EXIT; + data.enterprise = session.enterprise; - data.details = { - depot_name : line.depot_name, - patient_reference : line.patient_reference, - patient_display_name : line.patient_display_name, - full_display_name : line.patient_reference.concat(' - ', line.patient_display_name), - hospital_no : line.hospital_no, - user_display_name : line.user_display_name, - description : line.description, - date : line.date, - document_uuid : line.document_uuid, - document_reference : line.document_reference, - barcode : barcode.generate(key, line.document_uuid), - voucher_reference : voucherReference, - }; + data.details = { + depot_name : line.depot_name, + patient_reference : line.patient_reference, + patient_display_name : line.patient_display_name, + full_display_name : line.patient_reference.concat(' - ', line.patient_display_name), + hospital_no : line.hospital_no, + user_display_name : line.user_display_name, + description : line.description, + date : line.date, + document_uuid : line.document_uuid, + document_reference : line.document_reference, + barcode : barcode.generate(key, line.document_uuid), + voucher_reference : voucherReference, + }; - data.rows = rows; - return report.render(data); - }); + data.rows = rows; + return report.render(data); } module.exports = stockExitPatientReceipt; From fcdf98c09039fe2a0e6707f5c43c92201e044000 Mon Sep 17 00:00:00 2001 From: Chris Lomame Date: Fri, 24 Jan 2020 11:06:10 +0100 Subject: [PATCH 3/3] Clear and Sanitaze --- server/controllers/stock/reports/stock/adjustment_receipt.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/server/controllers/stock/reports/stock/adjustment_receipt.js b/server/controllers/stock/reports/stock/adjustment_receipt.js index 40c6fcf8ba..210ed5035e 100644 --- a/server/controllers/stock/reports/stock/adjustment_receipt.js +++ b/server/controllers/stock/reports/stock/adjustment_receipt.js @@ -34,9 +34,6 @@ async function stockAdjustmentReceipt(documentUuid, session, options) { getVoucherReferenceForStockMovement(documentUuid), ]); - console.log('PLUSSSSSSssssss'); - console.log(results); - const rows = results[0]; const voucherReference = results[1][0].voucher_reference;