Skip to content

Commit

Permalink
Updates for Inventory Changes Report
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcameron committed Dec 31, 2021
1 parent 005baf6 commit 06d003f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
1 change: 1 addition & 0 deletions client/src/i18n/en/inventory.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"PREVIOUS_VALUE" : "Previous Value",
"UPDATED_VALUE" : "Updated Value",
"CHANGES" : "Changes",
"NUM_CHANGES": "# Changes",
"IMPORTANCE_LEVEL":"Importance Level",
"IMPORTANCE_LEVEL_SELECT":"Select the importance level",
"LOW":"Low",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/fr/inventory.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"PREVIOUS_VALUE" : "Valeur Précédente",
"UPDATED_VALUE" : "Nouvelle Valeur",
"CHANGES" : "Changements",
"NUM_CHANGES": "# Changements",
"IMPORTANCE_LEVEL":"Niveau d'importance",
"IMPORTANCE_LEVEL_SELECT":"Choisir le niveau d'importance",
"LOW":"Faible",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ angular.module('bhima.controllers')
.controller('inventory_changesController', inventoryChangesController);

inventoryChangesController.$inject = [
'$sce', 'NotifyService', 'BaseReportService',
'AppCache', 'reportData', '$state',
'$sce', 'NotifyService', 'BaseReportService', 'AppCache',
'reportData', '$state', 'SessionService',
];

function inventoryChangesController($sce, Notify, SavedReports, AppCache, reportData, $state) {
function inventoryChangesController($sce, Notify, SavedReports, AppCache, reportData, $state, Session) {
const vm = this;
const cache = new AppCache('inventory_changes_report');
const reportUrl = 'reports/inventory/changes/';

vm.previewGenerated = false;
vm.reportDetails = {};
vm.reportDetails = {
currencyId : Session.enterprise.currency_id,
};

vm.clearPreview = function clearPreview() {
vm.previewGenerated = false;
Expand Down
32 changes: 25 additions & 7 deletions server/controllers/inventory/reports/changes.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,28 @@

<table class="table table-report table-condensed">
<thead>
<tr>
<tr style="background-color: #CCCCCC;">
<th>{{translate "FORM.LABELS.DATE"}}</th>
<th>{{translate "FORM.LABELS.USER"}}</th>
<th>{{translate "FORM.LABELS.LABEL"}}</th>
<th>{{translate "INVENTORY.PREVIOUS_VALUE"}}</th>
<th>{{translate "INVENTORY.UPDATED_VALUE"}}</th>
<th>{{translate "INVENTORY.NUM_CHANGES"}}</th>
</tr>
</thead>

{{#each ./inventories as | inventory |}}
<tbody>
<tr>
<th colspan="4">
<tr style="background-color: #EEEEEE;">
<th colspan="5">
{{inventory.group_name}} <span>&#x7c;</span> {{inventory.code}} - {{inventory.label}}
</th>
<th colspan="1" class="text-right">
({{inventory.logs.length}} {{translate "INVENTORY.CHANGES"}})
{{#if inventory.logs.length}}
{{inventory.logs.length}}
{{else}}
{{translate "INVENTORY.NONE"}}
{{/if}}
</th>
</tr>

Expand All @@ -38,14 +43,27 @@
<td>{{timestamp log.date}}</td>
<td>{{log.userName}}</td>
<td>{{translate log.col}}</td>
<td class="text-right">{{log.value.from}}</td>
<td class="text-right">{{log.value.to}}</td>
<td class="text-right">
{{#if log.is_unit_price}}
{{currency log.value.from ../../currencyId 4}}
{{else}}
{{ log.value.from }}
{{/if}}
</td>
<td class="text-right">
{{#if log.is_unit_price}}
{{currency log.value.to ../../currencyId 4}}
{{else}}
{{ log.value.to }}
{{/if}}
</td>
<td></td>
</tr>
{{/each}}
</tbody>
{{else}}
<tbody>
{{> emptyTable columns=5 }}
{{> emptyTable columns=6 }}
</tbody>
{{/each}}
</table>
Expand Down
15 changes: 14 additions & 1 deletion server/controllers/inventory/reports/changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ async function inventoryChanges(req, res, next) {
const params = _.clone(req.query);
const metadata = _.clone(req.session);

const currencyId = req.session.enterprise.currency_id;

try {
const report = new ReportManager(TEMPLATE, metadata, params);
const { dateFrom, dateTo } = params;
Expand Down Expand Up @@ -83,6 +85,17 @@ async function inventoryChanges(req, res, next) {
// attach logs to each inventory item
inventories.forEach(inventory => {
inventory.logs = changeMap[inventory.uuid];
// Note whether the item is a unit price so we can format it in the handlebars file
if (inventory.logs) {
inventory.logs.forEach(log => {
if (log.col === 'FORM.LABELS.UNIT_PRICE' && typeof log.value.to === 'number') {
log.is_unit_price = true;
}
if (log.col === 'FORM.LABELS.UNIT_PRICE' && typeof log.value.from === 'number') {
log.is_unit_price = true;
}
});
}
});

// calculate the number of changes by user.
Expand All @@ -94,7 +107,7 @@ async function inventoryChanges(req, res, next) {
.value();

const renderResult = await report.render({
inventories, dateFrom, dateTo, userChanges,
inventories, dateFrom, dateTo, userChanges, currencyId,
});
res.set(renderResult.headers).send(renderResult.report);
} catch (e) {
Expand Down

0 comments on commit 06d003f

Please sign in to comment.