Skip to content

Commit

Permalink
fix(review): Ud[Capdate the code tor the review and fix donation subm…
Browse files Browse the repository at this point in the history
…issiono
  • Loading branch information
DedrickEnc committed Oct 19, 2017
1 parent f0cc43d commit 5d014f9
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 97 deletions.
101 changes: 64 additions & 37 deletions client/src/js/services/StockService.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@ function StockService(Api, Filters, AppCache, Periods, $httpParamSerializer, Lan
StockInventoryFilters.registerDefaultFilters(bhConstants.defaultFilters);

StockLotFilters.registerCustomFilters([
{ key : 'depot_uuid', label : 'STOCK.DEPOT' },
{ key : 'inventory_uuid', label : 'STOCK.INVENTORY' },
{ key : 'label', label : 'STOCK.LOT' },
{ key : 'entry_date_from', label : 'STOCK.ENTRY_DATE', comparitor : '>', valueFilter : 'date' },
{ key : 'entry_date_to', label : 'STOCK.ENTRY_DATE', comparitor : '<', valueFilter : 'date' },
{ key : 'expiration_date_from', label : 'STOCK.EXPIRATION_DATE', comparitor : '>', valueFilter : 'date' },
{ key : 'expiration_date_to', label : 'STOCK.EXPIRATION_DATE', comparitor : '<', valueFilter : 'date' },
{ key: 'depot_uuid', label: 'STOCK.DEPOT' },
{ key: 'inventory_uuid', label: 'STOCK.INVENTORY' },
{ key: 'label', label: 'STOCK.LOT' },
{ key: 'entry_date_from', label: 'STOCK.ENTRY_DATE', comparitor: '>', valueFilter: 'date' },
{ key: 'entry_date_to', label: 'STOCK.ENTRY_DATE', comparitor: '<', valueFilter: 'date' },
{ key: 'expiration_date_from', label: 'STOCK.EXPIRATION_DATE', comparitor: '>', valueFilter: 'date' },
{ key: 'expiration_date_to', label: 'STOCK.EXPIRATION_DATE', comparitor: '<', valueFilter: 'date' },
]);

StockMovementFilters.registerCustomFilters([
{ key : 'is_exit', label : 'STOCK.OUTPUT'},
{ key : 'depot_uuid', label : 'STOCK.DEPOT' },
{ key : 'inventory_uuid', label : 'STOCK.INVENTORY' },
{ key : 'label', label : 'STOCK.LOT' },
{ key : 'flux_id', label : 'STOCK.FLUX'},
{ key : 'dateFrom', label : 'FORM.LABELS.DATE', comparitor: '>', valueFilter : 'date' },
{ key : 'dateTo', label : 'FORM.LABELS.DATE', comparitor: '<', valueFilter : 'date' },
{ key: 'is_exit', label: 'STOCK.OUTPUT' },
{ key: 'depot_uuid', label: 'STOCK.DEPOT' },
{ key: 'inventory_uuid', label: 'STOCK.INVENTORY' },
{ key: 'label', label: 'STOCK.LOT' },
{ key: 'flux_id', label: 'STOCK.FLUX' },
{ key: 'dateFrom', label: 'FORM.LABELS.DATE', comparitor: '>', valueFilter: 'date' },
{ key: 'dateTo', label: 'FORM.LABELS.DATE', comparitor: '<', valueFilter: 'date' },
]);

StockInventoryFilters.registerCustomFilters([
{ key : 'depot_uuid', label : 'STOCK.DEPOT' },
{ key : 'inventory_uuid', label : 'STOCK.INVENTORY' },
{ key : 'status', label : 'STOCK.STATUS.LABEL' },
{ key: 'depot_uuid', label: 'STOCK.DEPOT' },
{ key: 'inventory_uuid', label: 'STOCK.INVENTORY' },
{ key: 'status', label: 'STOCK.STATUS.LABEL' },
]);


Expand All @@ -84,16 +84,16 @@ function StockService(Api, Filters, AppCache, Periods, $httpParamSerializer, Lan

// creating an object of filter to avoid method duplication
var stockFilter = {
lot : StockLotFilters,
movement : StockMovementFilters,
inventory : StockInventoryFilters
lot: StockLotFilters,
movement: StockMovementFilters,
inventory: StockInventoryFilters
};

// creating an object of filter object to avoid method duplication
var filterCache = {
lot : filterLotCache,
movement : filterMovementCache,
inventory : filterInventoryCache
lot: filterLotCache,
movement: filterMovementCache,
inventory: filterInventoryCache
};

function assignLotDefaultFilters() {
Expand Down Expand Up @@ -166,7 +166,7 @@ function StockService(Api, Filters, AppCache, Periods, $httpParamSerializer, Lan
// downloads a type of report based on the
function download(filterKey, type) {
var filterOpts = stockFilter[filterKey].formatHTTP();
var defaultOpts = { renderer : type, lang : Languages.key };
var defaultOpts = { renderer: type, lang: Languages.key };

// combine options
var options = angular.merge(defaultOpts, filterOpts);
Expand All @@ -190,21 +190,48 @@ function StockService(Api, Filters, AppCache, Periods, $httpParamSerializer, Lan
}
});

return { reference : entity.reference || '', displayName : entity.displayName || '' };
return { reference: entity.reference || '', displayName: entity.displayName || '' };
}

/**
* @function processLotsFromStore
*
* @description
* This function loops through the store's contents mapping them into a flat array
* of lots.
*
* @returns {Array} - lots in an array.
*/
function processLotsFromStore(data, uuid) {
return data.reduce(function (current, line) {
return line.lots.map(function (lot) {
return {
uuid: lot.uuid || null,
label: lot.lot,
initial_quantity: lot.quantity,
quantity: lot.quantity,
unit_cost: line.unit_cost,
expiration_date: lot.expiration_date,
inventory_uuid: line.inventory_uuid,
origin_uuid: uuid,
};
}).concat(current);
}, []);
}

return {
stocks : stocks,
lots : lots,
movements : movements,
inventories : inventories,
integration : integration,
transfers : transfers,
filter : stockFilter,
cacheFilters : cacheFilters,
removeFilter : removeFilter,
loadCachedFilters : loadCachedFilters,
download : download,
uniformSelectedEntity : uniformSelectedEntity,
stocks: stocks,
lots: lots,
movements: movements,
inventories: inventories,
integration: integration,
transfers: transfers,
filter: stockFilter,
cacheFilters: cacheFilters,
removeFilter: removeFilter,
loadCachedFilters: loadCachedFilters,
download: download,
uniformSelectedEntity: uniformSelectedEntity,
processLotsFromStore : processLotsFromStore,
};
}
4 changes: 2 additions & 2 deletions client/src/modules/stock/StockForm.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function StockFormService(StockItem, Store, AppCache, Session, $timeout) {

this.cache = AppCache(cacheKey);
this.details = {};
this.store = new Store({ identifier: 'index', data: [] });
this.store = new Store({ data: [] });
}

/**
Expand Down Expand Up @@ -56,7 +56,7 @@ function StockFormService(StockItem, Store, AppCache, Session, $timeout) {
// will repeat will n > 0
while (n--) {
elt = new StockItem();
elt.index = this.store.data.length;
elt.id = this.store.data.length;
this.store.post(elt);
}
};
Expand Down
8 changes: 4 additions & 4 deletions client/src/modules/stock/entry/entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<div class="flex-content">
<div class="container-fluid">

<form name="StockForm" bh-submit="StockCtrl.submit(StockForm)" novalidate>
<form name="StockEntryForm" bh-submit="StockCtrl.submit(StockEntryForm)" novalidate>

<!-- activator -->
<div class="row">
Expand All @@ -60,7 +60,7 @@

<!-- note -->
<div class="form-group"
ng-class="{ 'has-error' : StockForm.$submitted && StockForm.description.$invalid }">
ng-class="{ 'has-error' : StockEntryForm.$submitted && StockEntryForm.description.$invalid }">
<label class="control-label">
<span translate>FORM.LABELS.DESCRIPTION</span>
</label>
Expand All @@ -72,7 +72,7 @@
ng-maxlength="StockCtrl.maxLength"
required>
</textarea>
<div class="help-block" ng-messages="StockForm.description.$error" ng-show="StockForm.$submitted">
<div class="help-block" ng-messages="StockEntryForm.description.$error" ng-show="StockEntryForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>
Expand Down Expand Up @@ -113,7 +113,7 @@
<div class="row" style="margin-top: 5px;">
<div class="col-xs-6 col-xs-offset-6">
<div class="text-right">
<button class="btn btn-default" ng-click="StockCtrl.suspend(StockForm)" type="button" translate>
<button class="btn btn-default" ng-click="StockCtrl.suspend(StockEntryForm)" type="button" translate>
FORM.BUTTONS.SUSPEND
</button>

Expand Down
35 changes: 5 additions & 30 deletions client/src/modules/stock/entry/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function StockEntryController(
}

/**
* The first function to ba called, it init :
* The first function to be called, it init :
* - A list of inventories
* - An object dor a movement
* - A depot from the cache or give possiblity of choosing one if not set
Expand Down Expand Up @@ -298,31 +298,6 @@ function StockEntryController(
if (form.$invalid) { return; }
mapEntry[vm.movement.entry_type].submit();
}
/**
* @function processLotsFromStore
*
* @description
* This function loops through the store's contents mapping them into a flat array
* of lots.
*
* @returns {Array} - lots in an array.
*/
function processLotsFromStore(data, uuid) {
return data.reduce(function (current, line) {
return line.lots.map(function (lot) {
return {
uuid : lot.uuid || null,
label: lot.lot,
initial_quantity: lot.quantity,
quantity: lot.quantity,
unit_cost: line.unit_cost,
expiration_date: lot.expiration_date,
inventory_uuid: line.inventory_uuid,
origin_uuid: uuid,
};
}).concat(current);
}, []);
}

function submitPurchase() {

Expand All @@ -335,7 +310,7 @@ function StockEntryController(
user_id: vm.stockForm.details.user_id,
};

movement.lots = processLotsFromStore(vm.stockForm.store.data, vm.movement.entity.uuid);
movement.lots = Stock.processLotsFromStore(vm.stockForm.store.data, vm.movement.entity.uuid);

Stock.stocks.create(movement)
.then(function (document) {
Expand All @@ -362,7 +337,7 @@ function StockEntryController(
};

var entry = {
lots: processLotsFromStore(vm.stockForm.store.data, movement.entity_uuid),
lots: Stock.processLotsFromStore(vm.stockForm.store.data, movement.entity_uuid),
movement: movement
}

Expand Down Expand Up @@ -392,7 +367,7 @@ function StockEntryController(
TODO: add a donor management module
*/
movement.lots = processLotsFromStore(vm.stockForm.store.data, movement.entity_uuid);
movement.lots = Stock.processLotsFromStore(vm.stockForm.store.data, Uuid());

return Stock.stocks.create(movement)
.then(function (document) {
Expand All @@ -415,7 +390,7 @@ function StockEntryController(
user_id: vm.stockForm.details.user_id,
};

movement.lots = processLotsFromStore(vm.stockForm.store.data, null);
movement.lots = Stock.processLotsFromStore(vm.stockForm.store.data, null);

return Stock.movements.create(movement)
.then(function (document) {
Expand Down
19 changes: 9 additions & 10 deletions client/src/modules/stock/entry/modals/lots.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ol class="headercrumb">
<li class="static" translate>TREE.STOCK</li>
<li class="static" translate>STOCK.ENTRY</li>
<li class="title">{{ $ctrl.inventory.inventory.label }}</li>
<li class="title">{{ $ctrl.stockLine.label }}</li>
</ol>
</div>

Expand All @@ -32,22 +32,21 @@
<div class="form-group">
<label translate>STOCK.UNIT_COST</label>

<div ng-if="!$ctrl.hasEditableInventory">
<div ng-if="!$ctrl.isCostEditable">
<span class="form-control-static">{{ $ctrl.stockLine.unit_cost }} {{ $ctrl.enterprise.currencyLabel }} </span>
</div>

<div ng-if="$ctrl.hasEditableInventory" class="input-group">
<div ng-if="$ctrl.isCostEditable" class="input-group">
<input
class="form-control"
type="number"
ng-model="$ctrl.stockLine.unit_cost"
ng-model-options="{ 'debounce' : { 'default' : 150, 'blur' : 0 }}"
ng-change="$ctrl.handleChange($ctrl.stockLine)">
ng-model-options="{ 'debounce' : { 'default' : 150, 'blur' : 0 }}">
<span class="input-group-addon">{{ $ctrl.enterprise.currencySymbol }}</span>
</div>
</div>

<!-- No need of defining lot label if it a transfer reception -->
<!-- No need of defining lot label if it is a transfer reception -->
<div class="text-right" style="margin-bottom: 5px;">
<button type="button"
data-add-lot
Expand Down Expand Up @@ -75,18 +74,18 @@
</div>
</div>

<div ng-if="!$ctrl.isAllValid">
<div ng-if="!$ctrl.isLotExist" class="alert alert-warning">
<div ng-if="$ctrl.hasInvalidEntries">
<div ng-if="$ctrl.hasNoLot" class="alert alert-warning">
<i class="fa fa-warning"></i>
<span translate>FORM.WARNINGS.NO_LOT</span>
</div>

<div ng-if="!$ctrl.isEveryLineCorrect" class="alert alert-danger">
<div ng-if="$ctrl.isSomeLineIncorrect" class="alert alert-danger">
<i class="fa fa-warning"></i>
<span translate>FORM.ERRORS.STOCK_LINE</span>
</div>

<div ng-if="!$ctrl.isQuantityCorrect" class="alert alert-danger">
<div ng-if="$ctrl.isQuantityIncorrect" class="alert alert-danger">
<i class="fa fa-warning"></i>
<span translate>FORM.ERRORS.LOT_QUANTITY</span>
</div>
Expand Down
27 changes: 13 additions & 14 deletions client/src/modules/stock/entry/modals/lots.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function StockDefineLotsModalController(Instance, Notify, uiGridConstants, Data,
vm.stockLine = Data.stockLine;
vm.entryType = Data.entry_type;
vm.gridApi = {};
vm.isCostEditable = (vm.entryType !== 'purchase' && vm.entryType !== 'transfer_reception');

vm.gridOptions = {
appScopeProvider: vm,
Expand Down Expand Up @@ -77,6 +78,10 @@ function StockDefineLotsModalController(Instance, Notify, uiGridConstants, Data,
vm.checkAll = checkAll;
vm.removeLot = removeLot;

function sumLot(x, y) {
return x + y.quantity;
}

function init() {
if (!vm.stockLine.lots.length) {
addLot();
Expand All @@ -102,25 +107,23 @@ function StockDefineLotsModalController(Instance, Notify, uiGridConstants, Data,
}

function checkAll() {
vm.isLotExist = vm.stockLine.lots.length > 0;
vm.hasNoLot = !vm.stockLine.lots.length > 0;

vm.isEveryLineCorrect = vm.stockLine.lots.every(function (lot) {
return lot.isValid === true;
vm.isSomeLineIncorrect = vm.stockLine.lots.some(function (lot) {
return lot.isValid === false;
});

vm.sum = vm.stockLine.lots.reduce(function (x, y) {
return x + y.quantity;
}, 0);
vm.sum = vm.stockLine.lots.reduce(sumLot, 0);

vm.isQuantityCorrect = vm.sum <= vm.stockLine.quantity;
vm.isQuantityIncorrect = vm.sum > vm.stockLine.quantity;

vm.isAllValid = vm.isEveryLineCorrect && vm.isQuantityCorrect && vm.isLotExist;
vm.hasInvalidEntries = vm.isSomeLineIncorrect || vm.isQuantityIncorrect || vm.hasNoLot;
}

function checkLine(line, date) {
if (date) { line.expiration_date = date; }

var isPosterior = new Date(line.expiration_date).getTime() >= new Date().getTime();
var isPosterior = new Date(line.expiration_date) >= new Date();
line.isValid = (line.lot && line.quantity > 0 && isPosterior);
vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.EDIT);

Expand All @@ -137,14 +140,10 @@ function StockDefineLotsModalController(Instance, Notify, uiGridConstants, Data,
}

function submit(detailsForm) {
if (vm.isAllValid) {
if (!vm.hasInvalidEntries) {
Instance.close({ lots: vm.stockLine.lots, quantity: vm.sum });
}
}

init();
}

// // // determine if the inventory quantity and cost should be editable or not.
// // vm.hasEditableInventory = (vm.entryType !== 'purchase' && vm.entryType !== 'transfer_reception');

0 comments on commit 5d014f9

Please sign in to comment.