-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(inventory): nicer inventory price list print (#152)
* 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
Showing
7 changed files
with
139 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |