diff --git a/client/src/i18n/en.json b/client/src/i18n/en.json index 07eaba09ab..8c3a77d143 100644 --- a/client/src/i18n/en.json +++ b/client/src/i18n/en.json @@ -858,6 +858,7 @@ "EDIT_TYPE" : "Edit inventory type", "EDIT_UNIT" : "Edit inventory unit form", "ELEMENT" : "Element", + "PRICES" : "Inventory Prices", "LIST" : "Inventory Data List", "LIST_METADATA" : "Inventory", "LIST_GROUP" : "Inventory Groups", @@ -1393,11 +1394,13 @@ "NUMBER_OF_DAYS" : "Number of Days", "TOTAL_COST" : "Total Cost", "TOTAL_AMOUNT" : "Total Amount", + "RECORDS" : "Records", "NUM_USERS" : "Number of Users", "NUM_SERVICES" : "Number of Services", "NUM_PROJECTS" : "Number of Projects", "NUM_PAYMENTS" : "Number of Payments", "NUM_INVOICES" : "Number of Invoices", + "NUM_RECORDS" : "Number of Records", "NUM_CAUTIONS" : "Number of PrePayments", "NUM_CASHBOXES" : "Number of Cashboxes", "NUM_CLIENTS" : "Number of Unique Clients", diff --git a/client/src/i18n/fr.json b/client/src/i18n/fr.json index 680ddb3de5..fb295faf8c 100644 --- a/client/src/i18n/fr.json +++ b/client/src/i18n/fr.json @@ -871,6 +871,7 @@ "EDIT_TYPE" : "Modifier Types d'inventaires", "EDIT_UNIT" : "Modifier Forme d'inventaires", "ELEMENT" : "Élément", + "PRICES" : "Tarification", "LIST" : "Liste des données d'inventaire", "LIST_METADATA" : "Inventaires", "LIST_GROUP" : "Groupes d'inventaires", diff --git a/server/config/routes.js b/server/config/routes.js index 4853cdf2b8..cc29c0b19e 100644 --- a/server/config/routes.js +++ b/server/config/routes.js @@ -368,7 +368,7 @@ exports.configure = function configure(app) { app.get('/reports/medical/patients/:uuid/checkins', medicalReports.patientCheckins); app.get('/reports/inventory/purchases/:uuid', inventoryReports.receipts.purchases); - app.get('/reports/inventory/items', inventory.getInventoryItemReport); + app.get('/reports/inventory/items', inventoryReports.reports.prices); app.get('/reports/finance/invoices', financeReports.invoices.report); app.get('/reports/finance/invoices/:uuid', financeReports.invoices.receipt); diff --git a/server/controllers/inventory/index.js b/server/controllers/inventory/index.js index 9545a28e9a..6862781cc7 100644 --- a/server/controllers/inventory/index.js +++ b/server/controllers/inventory/index.js @@ -51,7 +51,6 @@ exports.createInventoryItems = createInventoryItems; exports.updateInventoryItems = updateInventoryItems; exports.getInventoryItems = getInventoryItems; exports.getInventoryItemsById = getInventoryItemsById; -exports.getInventoryItemReport = getInventoryItemReport; // expose inventory group methods exports.createInventoryGroups = createInventoryGroups; @@ -166,34 +165,8 @@ function getInventoryItemsById(req, res, next) { .done(); } -/** -* GET /reports/inventory/imtes -* Returns a pdf file for inventory metadata -* -* @function getInventoryItemReport -*/ -function getInventoryItemReport(req, res, next) { - const template = './server/controllers/inventory/reports/items.handlebars'; - let report; - - const context = _.defaults({orientation : 'landscape' }, req.query); - - try { - report = new ReportManager(template, req.session, context); - } catch(e) { - return next(e); - } - - core.getItemsMetadata() - .then(rows => report.render({ rows })) - .then(result => { - res.set(result.headers).send(result.report); - }) - .catch(next) - .done(); -} - // ======================= inventory group ============================= + /** * POST /inventory/groups * Create a new inventory group diff --git a/server/controllers/inventory/reports/index.js b/server/controllers/inventory/reports/index.js index 2c6ed6e487..560a8bec19 100644 --- a/server/controllers/inventory/reports/index.js +++ b/server/controllers/inventory/reports/index.js @@ -8,5 +8,8 @@ module.exports = { receipts: { purchases: require('./purchases.receipt') + }, + reports : { + prices : require('./prices') } }; diff --git a/server/controllers/inventory/reports/prices.handlebars b/server/controllers/inventory/reports/prices.handlebars new file mode 100644 index 0000000000..ceff55159c --- /dev/null +++ b/server/controllers/inventory/reports/prices.handlebars @@ -0,0 +1,64 @@ +{{> head title="INVENTORY.PRICE_LIST_REPORT" }} + + + + {{> header }} + +

{{translate "INVENTORY.PRICES"}}

+ + +
+
+ + + + + + + + + + + + + + {{#each groups as | items name |}} + + + + + + + + + + {{#each items as | item | }} + + + + + + + {{/each}} + + {{#unless @last }} + + + + + {{/unless}} + + {{/each}} + +
{{translate "TREE.INVENTORY"}}{{translate "FORM.LABELS.TYPE"}}{{translate "FORM.LABELS.DEFAULT_QUANTITY"}}{{translate "FORM.LABELS.UNIT_PRICE"}}
+ {{ name }} + + ({{ items.length }} {{ translate "TABLE.AGGREGATES.RECORDS" }}) +
+ {{ item.text }} + {{ item.typeName }}{{ item.default_quantity }} + {{currency item.price ../../metadata.enterprise.currency_id}} +
+
+
+ diff --git a/server/controllers/inventory/reports/prices.js b/server/controllers/inventory/reports/prices.js new file mode 100644 index 0000000000..1f7c0beb7a --- /dev/null +++ b/server/controllers/inventory/reports/prices.js @@ -0,0 +1,66 @@ +'use strict'; + +/** + * @overview Price Report + * + * @description + * This file describes the price list report - it produces the list of prices to + * be used as a physical reference for invoicing. + * + * @requires db + * @requires lodash + * @requires ReportManager + */ + +const db = require('../../../lib/db'); +const _ = require('lodash'); + +const ReportManager = require('../../../lib/ReportManager'); + +module.exports = prices; + +const TEMPLATE = './server/controllers/inventory/reports/prices.handlebars'; + +function prices(req, res, next) { + + const qs = _.extend(req.query, { csvKey : 'debtors' }); + const metadata = _.clone(req.session); + + let report; + + try { + report = new ReportManager(TEMPLATE, metadata, qs); + } catch(e) { + return next(e); + } + + const sql = ` + SELECT BUID(inventory.uuid) AS uuid, inventory.default_quantity, inventory.text, + inventory.price, inventory_group.name AS groupName, inventory_type.text AS typeName + FROM inventory + JOIN inventory_group ON inventory.group_uuid = inventory_group.uuid + JOIN inventory_type ON inventory.type_id = inventory_type.id + ORDER BY inventory.text; + `; + + db.exec(sql) + .then(items => { + + // group by inventory group + let groups = _.groupBy(items, i => i.groupName); + + // make sure that they keys are sorted in alphabetical order + groups = _.mapValues(groups, items => { + _.sortBy(items, 'text'); + return items; + }); + + return report.render({ groups }); + }) + .then(result => { + res.set(result.headers).send(result.report); + }) + .catch(next) + .done(); + +}