Skip to content

Commit

Permalink
fix(reporeport): Cleaning inventory list code a bit and make it use t…
Browse files Browse the repository at this point in the history
…he same request than the client
  • Loading branch information
DedrickEnc committed Dec 6, 2017
1 parent 907a0b9 commit 7588cbf
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 54 deletions.
47 changes: 29 additions & 18 deletions client/src/modules/inventory/inventory.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ angular.module('bhima.services')

InventoryService.$inject = [
'PrototypeApiService', 'InventoryGroupService', 'InventoryUnitService', 'InventoryTypeService', '$uibModal',
'FilterService', 'appcache',
'FilterService', 'appcache', 'LanguageService', '$httpParamSerializer'
];

function InventoryService(Api, Groups, Units, Types, $uibModal, Filters, AppCache) {
function InventoryService(Api, Groups, Units, Types, $uibModal, Filters, AppCache, Languages, $httpParamSerializer) {
var service = new Api('/inventory/metadata/');

var inventoryFilters = new Filters();
Expand All @@ -28,30 +28,30 @@ function InventoryService(Api, Groups, Units, Types, $uibModal, Filters, AppCach
*/
function openSearchModal(filters) {
return $uibModal.open({
templateUrl : 'modules/inventory/list/modals/search.modal.html',
size : 'md',
keyboard : false,
animation : false,
backdrop : 'static',
controller : 'InventorySearchModalController as ModalCtrl',
resolve : {
filters : function filtersProvider() { return filters; },
templateUrl: 'modules/inventory/list/modals/search.modal.html',
size: 'md',
keyboard: false,
animation: false,
backdrop: 'static',
controller: 'InventorySearchModalController as ModalCtrl',
resolve: {
filters: function filtersProvider() { return filters; },
},
}).result;
}

inventoryFilters.registerDefaultFilters([
{ key : 'limit', label : 'FORM.LABELS.LIMIT' },
{ key: 'limit', label: 'FORM.LABELS.LIMIT' },
]);

inventoryFilters.registerCustomFilters([
{ key : 'group_uuid', label : 'FORM.LABELS.GROUP' },
{ key : 'code', label : 'FORM.LABELS.CODE' },
{ key : 'consumable', label : 'FORM.LABELS.CONSUMABLE' },
{ key : 'locked', label : 'FORM.LABELS.LOCKED' },
{ key : 'text', label : 'FORM.LABELS.LABEL' },
{ key : 'type_id', label : 'FORM.LABELS.TYPE' },
{ key : 'price', label : 'FORM.LABELS.PRICE' },
{ key: 'group_uuid', label: 'FORM.LABELS.GROUP' },
{ key: 'code', label: 'FORM.LABELS.CODE' },
{ key: 'consumable', label: 'FORM.LABELS.CONSUMABLE' },
{ key: 'locked', label: 'FORM.LABELS.LOCKED' },
{ key: 'text', label: 'FORM.LABELS.LABEL' },
{ key: 'type_id', label: 'FORM.LABELS.TYPE' },
{ key: 'price', label: 'FORM.LABELS.PRICE' },
]);

if (filterCache.filters) {
Expand Down Expand Up @@ -84,5 +84,16 @@ function InventoryService(Api, Groups, Units, Types, $uibModal, Filters, AppCach
inventoryFilters.loadCache(filterCache.filters || {});
};

service.download = function download(type) {
var filterOpts = inventoryFilters.formatHTTP();
var defaultOpts = { renderer: type, lang: Languages.key };

// combine options
var options = angular.merge(defaultOpts, filterOpts);

// return serialized options
return $httpParamSerializer(options);
};

return service;
}
3 changes: 1 addition & 2 deletions client/src/modules/inventory/list/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@

<li role="separator" class="divider"></li>
<li role="menuitem">
<a ng-href="/reports/inventory/items/?params={{ InventoryCtrl.filters.formatHTTP(true) }}&lang={{ InventoryCtrl.lang }}"
download="{{ 'INVENTORY.PRICE_LIST_REPORT' | translate }}">
<a ng-href="/reports/inventory/items/?{{ InventoryCtrl.download('pdf') }}" download="{{ 'INVENTORY.PRICE_LIST_REPORT' | translate }}">
<span class="fa fa-file-pdf-o"></span> <span translate>DOWNLOADS.PDF</span>
</a>
</li>
Expand Down
2 changes: 2 additions & 0 deletions client/src/modules/inventory/list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function InventoryListController(
GridExport, Languages, Session
) {
var vm = this;
vm.download = Inventory.download;

var cacheKey = 'InventoryGrid';
var cache = new AppCache(cacheKey);

Expand Down
21 changes: 13 additions & 8 deletions server/controllers/inventory/reports/prices.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
<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.CODE"}}</th>
<th class="text-center">{{translate "FORM.LABELS.CONSUMABLE"}}</th>
<th class="text-center">{{translate "FORM.LABELS.LABEL"}}</th>
<th class="text-center">{{translate "FORM.LABELS.UNIT_PRICE"}}</th>
<th class="text-center">{{translate "FORM.LABELS.DEFAULT_QUANTITY"}}</th>
<th class="text-center">{{translate "FORM.LABELS.TYPE"}}</th>
<th class="text-center">{{translate "FORM.LABELS.UNIT"}}</th>
</tr>
</thead>
<tbody>
Expand All @@ -30,22 +33,25 @@
{{ name }}
</th>

<th colspan="3" style="border:none; border-bottom: solid black 2px;" class="text-right">
<th colspan="6" 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>{{item.code}}</div>
<td>{{item.consumable}}</div>
<td style="text-overflow:ellipsis">
<span style="margin-left: 10px;">{{ item.text }}</span>
<span style="margin-left: 10px;">{{ item.label }}</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>
<td class="text-right">{{ item.default_quantity }}</td>
<td>{{ item.type }}</td>
<td>{{ item.unit }}</td>
</tr>
{{/each}}

Expand All @@ -55,7 +61,6 @@
<th style="border:none;"></th>
</tr>
{{/unless}}

{{/each}}
</tbody>
</table>
Expand Down
34 changes: 8 additions & 26 deletions server/controllers/inventory/reports/prices.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,26 @@
* 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
* @requires inventorycore
*/

const _ = require('lodash');
const db = require('../../../lib/db');
const FilterParser = require('../../../lib/filter');
const ReportManager = require('../../../lib/ReportManager');
const inventorycore = require('../inventory/core');

module.exports = prices;

const TEMPLATE = './server/controllers/inventory/reports/prices.handlebars';

function prices(req, res, next) {
const params = req.query.params ? JSON.parse(req.query.params) : {};
const params = _.clone(req.query);

db.convert(params, ['uuid', 'group_uuid']);

const filters = new FilterParser(params);
const qs = _.extend(req.query, {
csvKey : 'groups',
footerRight : '[page] / [toPage]',
footerFontSize : '7',
csvKey: 'groups',
footerRight: '[page] / [toPage]',
footerFontSize: '7',
});
const metadata = _.clone(req.session);

Expand All @@ -42,29 +38,15 @@ function prices(req, res, next) {
return;
}

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
`;

filters.fullText('text', 'text', 'inventory');
filters.equals('group_uuid');
filters.setOrder('ORDER BY inventory.text');

const query = filters.applyQuery(sql);
const parameters = filters.parameters();

db.exec(query, parameters)
inventorycore.getItemsMetadata(params)
.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, lines => {
_.sortBy(lines, 'text');
_.sortBy(lines, 'label');
return lines;
});

Expand Down

0 comments on commit 7588cbf

Please sign in to comment.