-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the asset management registry exports to the Assets module. This includes exporting to PDF, XLSX, and CSV. Closes #6580.
- Loading branch information
Showing
8 changed files
with
263 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,108 @@ | ||
const inventoryScansReports = require('./reports/needed_inventory_scans'); | ||
const router = require('express').Router(); | ||
|
||
module.exports = { | ||
neededInventoryScansReport : inventoryScansReports.neededInventoryScansReport, | ||
}; | ||
const { neededInventoryScansReport } = require('./reports/needed_inventory_scans'); | ||
|
||
const { | ||
_, ReportManager, Stock, formatFilters, ASSETS_REGISTRY_TEMPLATE, stockStatusLabelKeys, | ||
} = require('../../stock/reports/common'); | ||
|
||
const i18n = require('../../../lib/helpers/translate'); | ||
|
||
/** | ||
* @method assetRegistryReport | ||
* | ||
* @description | ||
* This method builds the assets report as either a JSON, PDF, or HTML | ||
* file to be sent to the client. | ||
* | ||
* GET /assets/reports/registry | ||
*/ | ||
async function assetRegistryReport(req, res, next) { | ||
const { lang } = req.query; | ||
|
||
const optionReport = _.extend(req.query, { filename : 'TREE.ASSETS_REGISTRY' }); | ||
|
||
try { | ||
const options = req.query; | ||
|
||
const report = new ReportManager(ASSETS_REGISTRY_TEMPLATE, req.session, optionReport); | ||
|
||
if (options.defaultPeriod) { | ||
options.defaultPeriodEntry = options.defaultPeriod; | ||
delete options.defaultPeriod; | ||
} | ||
|
||
options.month_average_consumption = req.session.stock_settings.month_average_consumption; | ||
options.average_consumption_algo = req.session.stock_settings.average_consumption_algo; | ||
|
||
const purgeKeys = [ | ||
'NO_CONSUMPTION', 'S_MONTH', 'S_RISK', 'S_RISK_QUANTITY', | ||
'S_MAX', 'S_MIN', 'S_SEC', 'S_Q', | ||
'at_risk_of_stock_out', 'cmms', 'color', | ||
'default_purchase_interval', 'delay', 'depot_uuid', | ||
'enterprisePurchaseInterval', 'exhausted', 'expired', | ||
'inventory_uuid', 'lifetime_lot', 'min_delay', | ||
'min_months_security_stock', 'mvt_quantity', 'near_expiration', | ||
'purchase_interval', 'tag_name', 'tracking_consumption', | ||
'tracking_expiration', 'wac', | ||
]; | ||
|
||
const dateKeys = ['min_stock_date', 'max_stock_date']; | ||
|
||
options.is_asset = 1; | ||
|
||
const rows = (await Stock.getLotsDepot(null, options)) | ||
.map(row => { | ||
const item = _.omit(row, purgeKeys); | ||
|
||
// Sanitize invalid dates | ||
dateKeys.forEach(key => { | ||
if (JSON.stringify(item[key]) === 'null') { | ||
item[key] = ''; | ||
} | ||
}); | ||
|
||
// translate the status field | ||
if (item.status in stockStatusLabelKeys) { | ||
item.status = i18n(lang)(stockStatusLabelKeys[item.status]); | ||
} | ||
return item; | ||
}); | ||
|
||
const data = {}; | ||
|
||
data.rows = rows; | ||
data.csv = rows; | ||
|
||
data.filters = _.uniqBy(formatFilters(options), 'field'); | ||
|
||
// group by depot | ||
const groupedDepots = _.groupBy(rows, d => d.depot_text); | ||
const depots = {}; | ||
|
||
Object.keys(groupedDepots).sort(compare).forEach(d => { | ||
depots[d] = _.sortBy(groupedDepots[d], line => String(line.text).toLocaleLowerCase()); | ||
}); | ||
|
||
data.depots = depots; | ||
|
||
const result = await report.render(data); | ||
|
||
res.set(result.headers).send(result.report); | ||
} catch (e) { | ||
next(e); | ||
} | ||
} | ||
|
||
function compare(a, b) { | ||
return a.localeCompare(b); | ||
} | ||
|
||
/** | ||
* @description | ||
* This is the base "assets/" route to render the asset registry report. | ||
*/ | ||
router.get('/reports/registry', assetRegistryReport); | ||
|
||
router.neededInventoryScansReport = neededInventoryScansReport; | ||
module.exports = router; |
86 changes: 86 additions & 0 deletions
86
server/controllers/stock/reports/assets_registry.report.handlebars
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,86 @@ | ||
{{> head title="TREE.ASSETS_REGISTRY" }} | ||
|
||
<body> | ||
|
||
{{> header}} | ||
|
||
<!-- body --> | ||
<!-- page title --> | ||
<h2 class="text-center text-uppercase"> | ||
{{translate 'TREE.ASSETS_REGISTRY'}} | ||
</h2> | ||
|
||
<h4 class="text-center"> | ||
{{date}} | ||
</h4> | ||
|
||
<!-- filters --> | ||
{{> filterbar filters=filters }} | ||
|
||
<!-- list of data --> | ||
<table class="table table-condensed table-bordered table-report"> | ||
<thead> | ||
<tr> | ||
<th>{{translate 'STOCK.CODE'}}</th> | ||
<th>{{translate 'STOCK.INVENTORY'}}</th> | ||
<th>{{translate 'TABLE.COLUMNS.INVENTORY_GROUP'}}</th> | ||
<th>{{translate 'ASSET.ASSET_LABEL'}}</th> | ||
<th>{{translate 'STOCK.QUANTITY'}}</th> | ||
<th>{{translate 'STOCK.UNIT_COST'}}</th> | ||
<th>{{translate 'STOCK.ENTRY_DATE'}}</th> | ||
<th>{{translate 'TABLE.COLUMNS.REFERENCE'}}</th> | ||
<th>{{translate 'FORM.LABELS.REFERENCE_NUMBER'}}</th> | ||
<th>{{translate 'FORM.LABELS.MANUFACTURER_BRAND'}}</th> | ||
<th>{{translate 'FORM.LABELS.MANUFACTURER_MODEL'}}</th> | ||
<th>{{translate 'FORM.LABELS.SERIAL_NUMBER'}}</th> | ||
<th>{{translate 'TABLE.COLUMNS.STATUS'}}</th> | ||
<th title={{translate 'LOTS.ASSIGNMENT_CREATED'}}>{{translate 'ENTITY.ASSIGNED_TO'}}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<!-- for each depots which contains lots --> | ||
{{#each depots as | items name |}} | ||
|
||
<!-- this is the depot group header --> | ||
<tr style="border:none"> | ||
<th style="border:none; border-bottom: solid black 2px;" class="text-uppercase" colspan="10"> | ||
{{ name }} | ||
</th> | ||
|
||
<th colspan="5" 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>{{code}}</td> | ||
<td>{{text}}</td> | ||
<td>{{group_name}}</td> | ||
<td>{{label}}</td> | ||
<td class="text-right">{{quantity}}</td> | ||
<td class="text-right">{{unit_cost}}</td> | ||
<td class="text-right">{{date entry_date}}</td> | ||
<td class="text-right">{{documentReference}}</td> | ||
<td class="text-right">{{reference_number}}</td> | ||
<td class="text-right">{{manufacturer_brand}}</td> | ||
<td class="text-right">{{manufacturer_model}}</td> | ||
<td class="text-right">{{serial_number}}</td> | ||
<td class="text-right">{{status}}</td> | ||
<td class="text-right">{{assigned_to_name}}</td> | ||
</tr> | ||
{{else}} | ||
{{> emptyTable columns=15}} | ||
{{/each}} | ||
|
||
<!-- blank row --> | ||
{{#unless @last }} | ||
<!-- blank line --> | ||
<tr style="border:none;"> | ||
<th style="border:none;"></th> | ||
</tr> | ||
{{/unless}} | ||
{{/each}} | ||
</tbody> | ||
</table> |
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