Skip to content

Commit

Permalink
fix(review): Update the pull requst according the review suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
DedrickEnc committed Aug 17, 2017
1 parent 999b9a8 commit fb2ec1f
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 87 deletions.
23 changes: 15 additions & 8 deletions client/src/i18n/en/depot.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{"DEPOT":{"ADD_DEPOT":"Add a Depot",
"ALL_DEPOTS":"All Depots",
"DEPOTS_LIST":"Depots list",
"DESCRIPTION":"This module allows you to List, Create, Edit and Delete a Depot",
"EDIT_DEPOT":"Edit the information in a Depot",
"MAIN":{"TITLE":"Depot Management"},
"NO_DEPOT":"No Depot",
"TITLE":"Depot Management"}}
{
"DEPOT": {
"ADD_DEPOT": "Add a Depot",
"ALL_DEPOTS": "All Depots",
"DEPOTS_LIST": "Depots list",
"DESCRIPTION": "This module allows you to List, Create, Edit and Delete a Depot",
"EDIT_DEPOT": "Edit the information in a Depot",
"ENTITY" : "Depot",
"MAIN": {
"TITLE": "Depot Management"
},
"NO_DEPOT": "No Depot",
"TITLE": "Depot Management"
}
}
34 changes: 18 additions & 16 deletions client/src/js/components/bhStockEntryExitType.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ angular.module('bhima.components')
templateUrl: 'modules/templates/bhStockEntryExitType.tmpl.html',
controller: StockEntryExitTypeController,
bindings: {
onEntryExitTypeSelectCallback: '&?',
onEntryExitTypeSelectCallback: '&',
reference: '<?',
displayName: '<?',
isEntry: '<'
isEntry: '@'
},
});

Expand All @@ -17,9 +17,12 @@ StockEntryExitTypeController.$inject = [];
*/
function StockEntryExitTypeController() {
var $ctrl = this;
$ctrl.selectedEntryExitType = null;

$ctrl.entryExitTypeList = [
$ctrl.$onInit = function onInit () {
$ctrl.selectedEntryExitType = null;
$ctrl.isEntry = $ctrl.isEntry === 'true';

$ctrl.entryExitTypeList = [
{ label: 'patient', labelKey: 'PATIENT_REG.ENTITY', descriptionKey: 'STOCK.PATIENT_DISTRIBUTION', isEntry: false },
{ label: 'service', labelKey: 'SERVICE.ENTITY', descriptionKey: 'STOCK.SERVICE_DISTRIBUTION', isEntry: false },
{ label: 'depot', labelKey: 'DEPOT.ENTITY', descriptionKey: 'STOCK.DEPOT_DISTRIBUTION', isEntry: false },
Expand All @@ -28,25 +31,24 @@ function StockEntryExitTypeController() {
{ label: 'integration', labelKey: 'STOCK.INTEGRATION', descriptionKey: 'STOCK_FLUX.FROM_INTEGRATION', isEntry: true },
{ label: 'donation', labelKey: 'STOCK.DONATION', descriptionKey: 'STOCK_FLUX.FROM_DONATION', isEntry: true },
{ label: 'transfer_reception', labelKey: 'STOCK.RECEPTION_TRANSFER', descriptionKey: 'STOCK_FLUX.FROM_TRANSFER', isEntry: true }
];
];
};

$ctrl.display = function () {
if ($ctrl.isEntry) {
return $ctrl.reference || '';
} else {
var list = [];

if ($ctrl.reference) {
list.push($ctrl.reference);
}

if ($ctrl.displayName) {
list.push($ctrl.displayName);
}
var list = [];

}
if ($ctrl.reference) {
list.push($ctrl.reference);
}

return list.join(' - ');
if ($ctrl.displayName) {
list.push($ctrl.displayName);
}

return list.join(' - ');
}

$ctrl.selectEntryExitType = function (type) {
Expand Down
4 changes: 0 additions & 4 deletions client/src/js/services/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ function UtilService(moment) {
return duration ? moment().diff(date, duration) : moment().diff(date);
};

service.getTimeFromToday = function (date, duration){
return duration ? moment(date).diff(new Date(), duration) : moment(date).diff(new Date());
}

/**
* @function once
*
Expand Down
8 changes: 4 additions & 4 deletions client/src/modules/stock/entry/modals/findTransfer.modal.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<form
name="FindForm"
bh-submit="$ctrl.submit(FindForm)"
ng-submit="$ctrl.submit(FindForm)"
novalidate>

<div class="modal-header space-between">
Expand Down Expand Up @@ -46,8 +46,8 @@
FORM.BUTTONS.CLOSE
</button>

<bh-loading-button loading-state="FindForm.$loading">
<span translate>FORM.BUTTONS.SUBMIT</span>
</bh-loading-button>
<button class="btn btn-primary" type="submit" data-method="submit" translate>
FORM.BUTTONS.SUBMIT
</button>
</div>
</form>
50 changes: 30 additions & 20 deletions client/src/modules/stock/entry/modals/findTransfer.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@ StockFindTransferModalController.$inject = [
function StockFindTransferModalController(Instance, StockService, Notify,
uiGridConstants, Filtering, Receipts, data) {
var vm = this;

// global
vm.selectedRow = {};

/* ======================= Grid configurations ============================ */
vm.filterEnabled = false;
vm.gridOptions = { appScopeProvider: vm };

var filtering = new Filtering(vm.gridOptions);

var columns = [
{
field: 'date',
Expand Down Expand Up @@ -51,13 +45,19 @@ function StockFindTransferModalController(Instance, StockService, Notify,
vm.gridOptions.multiSelect = false;
vm.gridOptions.enableFiltering = vm.filterEnabled;
vm.gridOptions.onRegisterApi = onRegisterApi;
vm.gridOptions.enableColumnMenus = false;
vm.gridOptions.fastWatch = true;
vm.gridOptions.flatEntityAccess = true;
vm.toggleFilter = toggleFilter;

// bind methods
vm.submit = submit;
vm.cancel = cancel;
vm.showReceipt = showReceipt;

vm.hasError = false;
vm.lo

function onRegisterApi(gridApi) {
vm.gridApi = gridApi;
vm.gridApi.selection.on.rowSelectionChanged(null, rowSelectionCallback);
Expand All @@ -71,42 +71,52 @@ function StockFindTransferModalController(Instance, StockService, Notify,
function toggleFilter() {
vm.filterEnabled = !vm.filterEnabled;
vm.gridOptions.enableFiltering = vm.filterEnabled;
vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN);
vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.OPTIONS);
}

/** get transfer document */
function showReceipt(uuid) {
Receipts.stockExitDepotReceipt(uuid, true);
}

/* ======================= End Grid ======================================== */
StockService.movements.read(null, {
entity_uuid: data.depot_uuid,
is_exit: 1,
finalClauseParameter: 'GROUP BY document_uuid',
})
function load (){
vm.loading = true;

StockService.movements.read(null, {
entity_uuid: data.depot_uuid,
is_exit: 1,
groupByDocument : 1,
})
.then(function (transfers) {
vm.gridOptions.data = transfers;
})
.catch(Notify.errorHandler);
.catch(function (err){
vm.hasError = true;
Notify.errorHandler(err);
})
.finally(function (){
vm.loading = false;
});
}

// submit
function submit() {
if (!vm.selectedRow) { return; }

if(!vm.selectedRow) {return;}
return StockService.movements.read(null, {
document_uuid: vm.selectedRow.document_uuid,
is_exit: 1,
})
.then(function (transfers) {
Instance.close(transfers);
})
.catch(Notify.errorHandler);
.then(function (transfers) {
Instance.close(transfers);
})
.catch(Notify.errorHandler);
}

// cancel
function cancel() {
Instance.dismiss();
}

load();

}
2 changes: 1 addition & 1 deletion client/src/modules/stock/exit/exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function StockExitController(Depots, Inventory, Notify, Session, util, bhConstan
function configureItem(item) {
item._initialised = true;
// get lots
Stock.lots.read(null, { depot_uuid: vm.depot.uuid, inventory_uuid: item.inventory.inventory_uuid, includeEmptyLot : false })
Stock.lots.read(null, { depot_uuid: vm.depot.uuid, inventory_uuid: item.inventory.inventory_uuid, includeEmptyLot : 0 })
.then(function (lots) {
item.lots = lots;
})
Expand Down
3 changes: 1 addition & 2 deletions client/src/modules/stock/exit/templates/expiration.tmpl.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<div ng-if="row.entity.lot.uuid" class="ui-grid-cell-contents">
{{grid.appScope.util.getTimeFromToday(row.entity.lot.expiration_date, 'days')}}
<span translate>FORM.LABELS.DAYS</span>
<span am-time-ago="row.entity.lot.expiration_date"></span>
</div>
36 changes: 21 additions & 15 deletions client/src/modules/templates/bhStockEntryExitType.tmpl.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
<div class="col-md-3 col-sm-6 col-xs-12" ng-repeat="type in $ctrl.entryExitTypeList | filter:{isEntry : $ctrl.isEntry}">
<button id="entry-exit-type-{{type.label}}" class="btn-block panel panel-default segment" type="button" ng-class="{'bg-ima-dark-blue': type.label === $ctrl.selectedEntryExitType.label}"
ng-click="$ctrl.selectEntryExitType(type)" name="btn-patient">
<div class="panel-body text-center text-ellipsis">
<div class="ui lg ima-blue statistic">
<div class="value" translate>
{{type.labelKey}}
</div>
<div>
<div class="uilabel">
<span ng-hide="($ctrl.reference || $ctrl.displayName) && type.label === $ctrl.selectedEntryExitType.label" translate>{{type.descriptionKey}}</span>
<span ng-show="($ctrl.reference || $ctrl.displayName) && type.label === $ctrl.selectedEntryExitType.label">
{{$ctrl.display()}}
</span>
<button
id="entry-exit-type-{{type.label}}"
class="btn-block panel panel-default segment"
type="button"
ng-class="{'bg-ima-dark-blue': type.label === $ctrl.selectedEntryExitType.label}"
ng-click="$ctrl.selectEntryExitType(type)">
<div class="panel-body text-center text-ellipsis">
<div class="ui lg ima-blue statistic">
<div class="value" translate>
{{type.labelKey}}
</div>
<div>
<div class="uilabel">
<span ng-hide="($ctrl.reference || $ctrl.displayName) && type.label === $ctrl.selectedEntryExitType.label" translate>
{{type.descriptionKey}}
</span>
<span ng-show="($ctrl.reference || $ctrl.displayName) && type.label === $ctrl.selectedEntryExitType.label">
{{$ctrl.display()}}
</span>
</div>
</div>
</div>
</div>
</div>
</button>
</button>
</div>
6 changes: 3 additions & 3 deletions server/controllers/stock/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function getLotsDepot(depotUuid, params, finalClause) {
delete params.status;
}

if(params.includeEmptyLot === 'false'){
if(Number(params.includeEmptyLot) === 0){
exludeToken = 'HAVING quantity > 0';
delete params.includeEmptyLot;
}
Expand Down Expand Up @@ -180,9 +180,9 @@ function getLotsMovements(depotUuid, params) {
params.depot_uuid = depotUuid;
}

if(params.finalClauseParameter){
if(params.groupByDocument === 1){
finalClause = 'GROUP BY document_uuid';
delete params.finalClauseParameter;
delete params.groupByDocument;
}

const sql = `
Expand Down
15 changes: 10 additions & 5 deletions server/controllers/stock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,25 +190,30 @@ function depotMovement(document, params) {

parameters.entity_uuid = parameters.entity_uuid ? db.bid(parameters.entity_uuid) : null;

const depot_uuid = isExit ? db.bid(parameters.from_depot) : db.bid(parameters.to_depot);
const entity_uuid = isExit ? db.bid(parameters.to_depot) : db.bid(parameters.from_depot);
const is_exit = isExit ? 1 : 0;
const flux_id = isExit ? core.flux.TO_OTHER_DEPOT : core.flux.FROM_OTHER_DEPOT;

parameters.lots.forEach((lot) => {

record = {
depot_uuid,
entity_uuid,
is_exit,
flux_id,
uuid : db.bid(uuid.v4()),
lot_uuid : db.bid(lot.uuid),
depot_uuid : isExit ? db.bid(parameters.from_depot) : db.bid(parameters.to_depot),
document_uuid : db.bid(document.uuid),
quantity : lot.quantity,
unit_cost : lot.unit_cost,
date : document.date,
entity_uuid : isExit ? db.bid(parameters.to_depot) : db.bid(parameters.from_depot),
is_exit : isExit ? 1 : 0,
flux_id : isExit ? core.flux.TO_OTHER_DEPOT : core.flux.FROM_OTHER_DEPOT,
description : parameters.description,
user_id : document.user,
};

transaction.addQuery('INSERT INTO stock_movement SET ?', [record]);

isWarehouse = !!(parameters.from_depot_is_warehouse);

// track distribution to patient
Expand Down
2 changes: 1 addition & 1 deletion test/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ INSERT INTO `stock_movement` (`uuid`, `lot_uuid`, `document_uuid`, `depot_uuid`,
(HUID('a4ff7358-f1f8-4301-86e4-e9e6fe99bd31'), HUID('5a0e06c2-6ca7-4633-8b17-92e2a59db44c'), HUID('682e11c0-93a7-49f8-b79b-a4bc8e3e6f47'), HUID('f9caeb16-1684-43c5-a6c4-47dbac1df296'), '', 1, '2017-02-02', 20, 0.5000, 0, 1),
(HUID('d8c83ad9-a3ea-4f9f-96f9-456a435f480d'), HUID('ef24cf1a-d5b9-4846-b70c-520e601c1ea6'), HUID('682e11c0-93a7-49f8-b79b-a4bc8e3e6f47'), HUID('f9caeb16-1684-43c5-a6c4-47dbac1df296'), '', 1, '2017-02-02', 50, 2.0000, 0, 1),
(HUID('f9aa33f1-65e2-4e37-89cb-843d27b2c586'), HUID('064ab1d9-5246-4402-ae8a-958fcdb07b35'), HUID('682e11c0-93a7-49f8-b79b-a4bc8e3e6f47'), HUID('f9caeb16-1684-43c5-a6c4-47dbac1df296'), '', 1, '2017-02-02', 100, 1.2000, 0, 1),
(HUID('e8502c3e-7483-11e7-a8de-507b9dd6de91'), HUID('064ab1d9-5246-4402-ae8a-958fcdb07b35'), HUID('0cc6c435-7484-11e7-a8de-507b9dd6de91'), HUID('f9caeb16-1684-43c5-a6c4-47dbac1df296'), HUID('d4bb1452-e4fa-4742-a281-814140246877'), 1, '2017-02-02', 75, 1.2000, 1, 1);
(HUID('e8502c3e-7483-11e7-a8de-507b9dd6de91'), HUID('064ab1d9-5246-4402-ae8a-958fcdb07b35'), HUID('0cc6c435-7484-11e7-a8de-507b9dd6de91'), HUID('f9caeb16-1684-43c5-a6c4-47dbac1df296'), HUID('d4bb1452-e4fa-4742-a281-814140246877'), 8, '2017-02-02', 75, 1.2000, 1, 1);

-- general ledger data
INSERT INTO `general_ledger` VALUES
Expand Down
3 changes: 2 additions & 1 deletion test/end-to-end/shared/components/bhStockEntryExitType.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const FU = require('../FormUtils');

module.exports = {
set : function set(id) {
const locator = by.id(id);
var prefix = 'entry-exit-type-';
const locator = by.id(prefix.concat(id));
const target = element(locator);

target.click();
Expand Down
6 changes: 3 additions & 3 deletions test/end-to-end/stock/stock.entry.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function StockEntryPage() {
* @param {string} rowNumber - the purchase line on the modal
*/
page.setPurchase = function setPurchase(rowNumber) {
components.stockEntryExitType.set('entry-exit-type-purchase');
components.stockEntryExitType.set('purchase');
GU.selectRow('PurchaseGrid', rowNumber);
FU.modal.submit();
};
Expand All @@ -35,7 +35,7 @@ function StockEntryPage() {
* @param {string} rowNumber - movement line on the modal grid
*/
page.setTransfer = function setTransfer(rowNumber) {
components.stockEntryExitType.set('entry-exit-type-transfer_reception');
components.stockEntryExitType.set('transfer_reception');
GU.selectRow('TransferGrid', rowNumber);
FU.modal.submit();
};
Expand All @@ -44,7 +44,7 @@ function StockEntryPage() {
* @method setIntegration
*/
page.setIntegration = function setIntegration() {
components.stockEntryExitType.set('entry-exit-type-integration');
components.stockEntryExitType.set('integration');
};

/**
Expand Down
Loading

0 comments on commit fb2ec1f

Please sign in to comment.