Skip to content

Commit

Permalink
feat(inventory): nicer inventory price list print (#152)
Browse files Browse the repository at this point in the history
* feat(inventory): nicer inventory price list print

This commit improves the inventory item printed report by grouping by
inventory group and only showing part of the information as needed.

* fix(i18n): translate report title
  • Loading branch information
jniles authored and sfount committed Jan 19, 2017
1 parent 266c376 commit d65b59e
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 29 deletions.
3 changes: 3 additions & 0 deletions client/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 1 addition & 28 deletions server/controllers/inventory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions server/controllers/inventory/reports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
module.exports = {
receipts: {
purchases: require('./purchases.receipt')
},
reports : {
prices : require('./prices')
}
};
64 changes: 64 additions & 0 deletions server/controllers/inventory/reports/prices.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{{> head title="INVENTORY.PRICE_LIST_REPORT" }}

<body>

{{> header }}

<h3 class="text-center">{{translate "INVENTORY.PRICES"}}</h3>

<!-- body -->
<div class="row">
<div class="col-xs-12">

<table class="table table-condensed table-bordered">
<thead>
<tr>
<th class="text-center">{{translate "TREE.INVENTORY"}}</th>
<th class="text-center">{{translate "FORM.LABELS.TYPE"}}</th>
<th class="text-center">{{translate "FORM.LABELS.DEFAULT_QUANTITY"}}</th>
<th class="text-center">{{translate "FORM.LABELS.UNIT_PRICE"}}</th>
</tr>
</thead>
<tbody>

<!-- for each inventory group -->
{{#each groups as | items name |}}

<!-- this is the inventory group header -->
<tr style="border:none">
<th style="border:none; border-bottom: solid black 2px;" class="text-uppercase">
{{ name }}
</th>

<th colspan="3" style="border:none; border-bottom: solid black 2px;" class="text-right">
({{ items.length }} {{ translate "TABLE.AGGREGATES.RECORDS" }})
</th>
</tr>

<!-- these are the items for each group -->
{{#each items as | item | }}
<tr>
<td style="text-overflow:ellipsis">
<span style="margin-left: 10px;">{{ item.text }}</span>
</td>
<td>{{ item.typeName }}</td>
<td class="text-right">{{ item.default_quantity }}</td>
<td class="text-right" style="min-width:150px;">
{{currency item.price ../../metadata.enterprise.currency_id}}
</td>
</tr>
{{/each}}

{{#unless @last }}
<!-- blank line -->
<tr style="border:none;">
<th style="border:none;"></th>
</tr>
{{/unless}}

{{/each}}
</tbody>
</table>
</div>
</div>
</body>
66 changes: 66 additions & 0 deletions server/controllers/inventory/reports/prices.js
Original file line number Diff line number Diff line change
@@ -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();

}

0 comments on commit d65b59e

Please sign in to comment.