Skip to content

Commit

Permalink
Update asset inventory scans
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcameron committed Jun 22, 2022
1 parent ee4bd6c commit 8e88a3d
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 5 deletions.
2 changes: 2 additions & 0 deletions client/src/i18n/en/asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"NEW_REQUIRED_INVENTORY_SCAN" : "New Required Inventory Scan",
"NOT_ASSIGNED" : "Not assigned",
"NO_ASSIGNMENT_HISTORY" : "No assignment history",
"NUMBER_SCANNED": "Number scanned",
"ONLY_ASSETS" : "Only Assets",
"OUT_OF": "out of",
"REQUIRED_INVENTORY_SCAN" : "Required Inventory Scan",
"REQUIRED_INVENTORY_SCANS" : "Required Inventory Scans",
"REQUIRED_INVENTORY_SCAN_CREATED" : "Required inventory scan successfully created",
Expand Down
2 changes: 2 additions & 0 deletions client/src/i18n/fr/asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"NEW_REQUIRED_INVENTORY_SCAN" : "Nouveau scan d'inventaire obligatoire",
"NOT_ASSIGNED" : "Aucune assignation",
"NO_ASSIGNMENT_HISTORY" : "Aucun historique des assignations",
"NUMBER_SCANNED": "Nombre scannés",
"ONLY_ASSETS" : "Seulement les immobilisations",
"OUT_OF": "sur",
"REQUIRED_INVENTORY_SCAN" : "Scan d'inventaire obligatoire",
"REQUIRED_INVENTORY_SCANS" : "Scans d'inventaire obligatoires",
"REQUIRED_INVENTORY_SCAN_CREATED" : "Scan d'inventaire obligatoire créé avec succès",
Expand Down
11 changes: 11 additions & 0 deletions server/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ module.exports = {
ALLOCATION_BASIS_NUM_COMPUTERS : 5,
ALLOCATION_BASIS_NUM_LABOR_HOURS : 6,
},
assetCondition : [
{ id : 1, label : 'ASSET.CONDITION.NEW' },
{ id : 2, label : 'ASSET.CONDITION.GOOD' },
{ id : 3, label : 'ASSET.CONDITION.FAIR' },
{ id : 4, label : 'ASSET.CONDITION.POOR' },
{ id : 5, label : 'ASSET.CONDITION.BROKEN' },
{ id : 6, label : 'ASSET.CONDITION.OBSOLETE' },
{ id : 7, label : 'ASSET.CONDITION.DISCARDED' },
{ id : 8, label : 'ASSET.CONDITION.SOLD' },
{ id : 9, label : 'ASSET.CONDITION.LOST' },
],
settings : {
CONTACT_EMAIL : 'developers@imaworldhealth.org',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ caption {
{{#if scan.reference_number}}
<h4 class="text-right">{{translate 'FORM.LABELS.REFERENCE_NUMBER'}}: {{scan.reference_number}}</h4>
{{/if}}
<h3 class="text-right">{{translate 'ASSET.NUMBER_SCANNED'}}: {{countScanned}} {{translate 'ASSET.OUT_OF'}} {{countTotal}} ({{percentScanned}}%)</h3>
{{/header}}

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

{{#if scan.description}}
<h4 class="text-center" style="margin: 7px 0">{{scan.description}}</h4>
<h3 class="text-center" style="margin: 7px 0">{{scan.description}}</h3>
{{/if}}

<!-- list of assets-->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
const _ = require('lodash');
const core = require('../../../stock/core');
const util = require('../../../../lib/util');
const reqInvScans = require('../../../stock/required_inventory_scans');
const ReportManager = require('../../../../lib/ReportManager');

const BASE_URL = './server/controllers/asset_management/assets';
const NEEDED_INVENTORY_SCAN_REPORT_TEMPLATE = `${BASE_URL}/reports/needed_inventory_scans.handlebars`;

const {
assetCondition,
} = require('../../../../config/constants');

async function neededInventoryScansReport(req, res, next) {
const options = req.query;

Expand Down Expand Up @@ -35,13 +40,37 @@ async function neededInventoryScansReport(req, res, next) {
scan_start_date : new Date(scan.start_date),
scan_end_date : new Date(scan.end_date),
reference_number : scan.reference_number,
scan_status : options.scan_status,
// Do not pass in scan_status, filter after the query
};
const assets = await core.getAssets(params);

const allAssets = await core.getAssets(params);

// Fill in the asset condition names
allAssets.forEach(asset => {
if (asset.scan_condition_id) {
const condition = assetCondition.find(ac => ac.id === asset.scan_condition_id);
asset.scan_condition = condition ? condition.label : '';
}
});

const countScanned = allAssets.reduce((num, asset) => (asset.scan_uuid ? num + 1 : num), 0);
const countTotal = allAssets.length;
const percentScanned = util.roundDecimal(100.0 * (countScanned / countTotal), 1);

// filter for scan status (if needed)
let assets = allAssets;
if (options.scan_status === 'scanned') {
assets = allAssets.filter(a => a.scan_uuid);
} else if (options.scan_status === 'unscanned') {
assets = allAssets.filter(a => !a.scan_uuid);
}

const data = {
scan,
assets,
countScanned,
countTotal,
percentScanned,
tableTitle : tableTitles[tableType],
date : new Date(),
};
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/stock/asset_scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function listAssetScans(params) {
if ('show_only_last_scans' in params) {
// See 'Outer Join Method' in https://thoughtbot.com/blog/ordering-within-a-sql-group-by-clause
// This join with the 'show_only_last_scans' filter (defined above) ensures that we
// are not selecting only the latest⁄last asset scan for each asset.
// are selecting only the latest⁄last asset scan for each asset.
lastScanJoin = `
LEFT OUTER JOIN asset_scan AS s2
ON s2.asset_uuid = s.asset_uuid AND
Expand Down
4 changes: 3 additions & 1 deletion server/controllers/stock/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,11 @@ async function getAssets(params) {
LEFT JOIN (
SELECT scan.*
FROM asset_scan AS scan
LEFT JOIN asset_scan AS s2 ON (s2.asset_uuid = scan.asset_uuid
AND scan.created_at < s2.created_at AND s2.uuid IS NULL)
${scanPeriod}
ORDER BY scan.created_at DESC LIMIT 1
) AS last_scan ON last_scan.asset_uuid = l.uuid
`;

const groupByClause = ` GROUP BY l.uuid, m.depot_uuid ORDER BY i.code, l.label `;
Expand Down

0 comments on commit 8e88a3d

Please sign in to comment.