Skip to content

Commit

Permalink
feat(stock): adjustment select depot modal
Browse files Browse the repository at this point in the history
This commit implements the depot selection modal on the stock adjustment
page.  It fixes a bug where modals were not correctly dismissed because
of the $state transitions taking place.
  • Loading branch information
jniles committed Sep 14, 2017
1 parent 7812eac commit 2bbe37b
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 66 deletions.
60 changes: 39 additions & 21 deletions client/src/modules/stock/adjustment/adjustment.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,31 @@
<div class="bhima-title">
<ol class="headercrumb">
<li class="static" translate>TREE.STOCK</li>
<li class="title"><span translate>STOCK.ADJUSTMENT</span> <span class="text-uppercase badge badge-primary">{{StockCtrl.movement.ADJUSTMENT_type}}</span></li>
<li ng-class="{ 'title' : !StockCtrl.depot.uuid, 'static' : StockCtrl.depot.uuid }">
<span translate>STOCK.ADJUSTMENT</span>
</li>
<li class="title" ng-if="StockCtrl.depot.uuid">
<span>{{ StockCtrl.depot.text }}</span>
<span class="text-uppercase badge badge-primary" ng-show="StockCtrl.adjustmentOption">
{{ StockCtrl.adjustmentOption }}
</span>
</li>
</ol>

<div class="toolbar">
<div class="toolbar-item">
<bh-depot-dropdown on-select="StockCtrl.setupDepot(depot)"></bh-depot-dropdown>
<div uib-dropdown dropdown-append-to-body data-action="open-tools">
<a class="btn btn-default" uib-dropdown-toggle>
<span class="fa fa-bars"></span> <span class="hidden-xs" translate>FORM.LABELS.MENU</span> <span class="caret"></span>
</a>
<ul uib-dropdown-menu role="menu" class="dropdown-menu-right">
<li role="menuitem">
<a href ng-click="StockCtrl.changeDepot()" data-action="change-depot">
<i class="fa fa-archive"></i> <span translate>DEPOT.CHANGE</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
Expand All @@ -23,17 +42,18 @@
<div class="col-xs-6">
<!-- adjustment type -->
<div class="form-group">
<div class="well well-sm clearfix">
<label class="col-md-6 text-action">
<input type="radio" ng-model="StockCtrl.adjustmentOption" ng-value="'increase'">
<span translate>STOCK.INCREASE</span>
</label>

<label class="col-md-6 text-action">
<input type="radio" ng-model="StockCtrl.adjustmentOption" ng-value="'decrease'">
<span translate>STOCK.DECREASE</span>
</label>
</div>
<div class="well well-sm">
<div class="radio">
<label class="radio-inline" style="padding: 0 3em;">
<input type="radio" ng-model="StockCtrl.adjustmentOption" ng-value="'increase'">
<span translate>STOCK.INCREASE</span>
</label>

<label class="radio-inline" style="padding: 0 3em;">
<input type="radio" ng-model="StockCtrl.adjustmentOption" ng-value="'decrease'">
<span translate>STOCK.DECREASE</span>
</label>
</div>
</div>

<!-- date -->
Expand All @@ -52,7 +72,7 @@
class="form-control"
name="description"
ng-model="StockCtrl.movement.description"
placeholder="{{ ::'FORM.PLACEHOLDERS.DESCRIPTION' | translate }}"
placeholder="{{ 'FORM.PLACEHOLDERS.DESCRIPTION' | translate }}"
ng-maxlength="StockCtrl.maxLength"
required>
</textarea>
Expand Down Expand Up @@ -84,7 +104,7 @@ <h4><i class="fa fa-arrow-circle-down"></i> <span translate>STOCK.DECREASE</span
style="padding-top : 10px;"
class="text-info"
ng-show="!StockCtrl.adjustmentOption">
<span class="fa fa-info-circle"></span>
<span class="fa fa-info-circle"></span>
<span translate>FORM.INFO.NO_DESTINATION</span>
</p>

Expand All @@ -96,7 +116,7 @@ <h4><i class="fa fa-arrow-circle-down"></i> <span translate>STOCK.DECREASE</span
ng-class="{'btn-primary' : StockCtrl.hasCacheAvailable }"
ng-click="StockCtrl.readCache()"
ng-disabled="!StockCtrl.hasCacheAvailable">
<span class="fa fa-recycle"></span>
<span class="fa fa-recycle"></span>
<span translate>FORM.BUTTONS.RECOVER_ITEMS</span>
</button>
</div>
Expand All @@ -110,7 +130,7 @@ <h4><i class="fa fa-arrow-circle-down"></i> <span translate>STOCK.DECREASE</span
class="btn btn-default"
ng-disabled="!StockCtrl.adjustmentOption"
ng-click="StockCtrl.addItems(StockCtrl.itemIncrement)">
<span class="fa fa-plus-circle"></span>
<span class="fa fa-plus-circle"></span>
<span translate>FORM.BUTTONS.ADD</span>
</button>
</span>
Expand All @@ -125,8 +145,8 @@ <h4><i class="fa fa-arrow-circle-down"></i> <span translate>STOCK.DECREASE</span
</div>

<!-- grid -->
<div id="stock-adjustment-grid"
ui-grid="StockCtrl.gridOptions"
<div id="stock-adjustment-grid"
ui-grid="StockCtrl.gridOptions"
style="height: 300px; width: 100%;"
ui-grid-auto-resize
ui-grid-resize-columns>
Expand All @@ -146,8 +166,6 @@ <h4><i class="fa fa-arrow-circle-down"></i> <span translate>STOCK.DECREASE</span
</div>
</div>
</div>

</form>

</div>
</div>
97 changes: 59 additions & 38 deletions client/src/modules/stock/adjustment/adjustment.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
angular.module('bhima.controllers')
.controller('StockAdjustmentController', StockAdjustmentController);
.controller('StockAdjustmentController', StockAdjustmentController);

// dependencies injections
StockAdjustmentController.$inject = [
'DepotService', 'InventoryService', 'NotifyService',
'SessionService', 'util', 'bhConstants', 'ReceiptModal',
'StockFormService', 'StockService', 'StockModalService',
'uiGridGroupingConstants',
'uiGridGroupingConstants', 'appcache',
];

function StockAdjustmentController(Depots, Inventory, Notify,
Session, util, bhConstants, ReceiptModal, StockForm, Stock, StockModal,
uiGridGroupingConstants) {
/**
* @class StockAdjustmentController
*
* @description
* This module exists to make sure that stock can be adjusted up and down as needed.
*/
function StockAdjustmentController(
Depots, Inventory, Notify, Session, util, bhConstants, ReceiptModal, StockForm, Stock, StockModal,
uiGridGroupingConstants, AppCache
) {
var vm = this;

// TODO - merge all stock caches together so that the same depot is shared across all stock modules
var cache = new AppCache('StockAdjustment');

// global variables
vm.Stock = new StockForm('StockAdjustment');
vm.gridApi = {};
vm.depot = {};
vm.movement = {};

// bind methods
// bind constants
vm.itemIncrement = 1;
vm.enterprise = Session.enterprise;
vm.maxLength = util.maxLength;
vm.maxDate = new Date();

// bind methods
vm.addItems = addItems;
vm.removeItem = removeItem;
vm.maxDate = new Date();
vm.configureItem = configureItem;
vm.setupDepot = setupDepot;
vm.checkValidity = checkValidity;
vm.submit = submit;
vm.changeDepot = changeDepot;

// grid columns
var columns = [
Expand Down Expand Up @@ -84,26 +94,11 @@ function StockAdjustmentController(Depots, Inventory, Notify,
enableSorting : false,
enableColumnMenus : false,
columnDefs : columns,
onRegisterApi : onRegisterApi,
data : vm.Stock.store.data,
fastWatch : true,
flatEntityAccess : true,
};

// expose the API so that scrolling methods can be used
function onRegisterApi(api) {
vm.gridApi = api;
}

// configure depot
function setupDepot(depot) {
if (!depot || !depot.uuid) { return; }
vm.depot = depot;
loadInventories(vm.depot);
vm.Stock.setup();
vm.Stock.store.clear();
}

// add items
function addItems(n) {
vm.Stock.addItems(n);
Expand All @@ -127,12 +122,32 @@ function StockAdjustmentController(Depots, Inventory, Notify,
.catch(Notify.handleError);
}

// init actions
function moduleInit() {
vm.movement = { date: new Date(), entity: {} };
loadInventories(vm.depot);
setupDepot(vm.depot);
checkValidity();
function setupStock() {
vm.Stock.setup();
vm.Stock.store.clear();
}

function startup() {
vm.movement = {
date : new Date(),
entity : {},
};

vm.depot = cache.depot;

// make sure that the depot is loaded if it doesn't exist at startup.
if (vm.depot) {
setupStock();
loadInventories(vm.depot);
checkValidity();
} else {
changeDepot()
.then(setupStock)
.then(function () {
loadInventories(vm.depot);
checkValidity();
});
}
}

// ============================ Inventories ==========================
Expand Down Expand Up @@ -203,13 +218,19 @@ function StockAdjustmentController(Depots, Inventory, Notify,
movement.lots = lots;

return Stock.movements.create(movement)
.then(function (document) {
vm.Stock.store.clear();
ReceiptModal.stockAdjustmentReceipt(document.uuid, fluxId);
})
.catch(Notify.handleError);
.then(function (document) {
vm.Stock.store.clear();
ReceiptModal.stockAdjustmentReceipt(document.uuid, fluxId);
})
.catch(Notify.handleError);
}
function changeDepot() {
return Depots.openSelectionModal(vm.depot)
.then(function (depot) {
vm.depot = depot;
cache.depot = vm.depot;
});
}

// ================================= Startup ===============================
moduleInit();
startup();
}
1 change: 0 additions & 1 deletion client/src/modules/stock/exit/exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function StockExitController(

vm.util = util;
vm.Stock = new StockForm('StockExit');
vm.depot = {};
vm.movement = {};

// bind methods
Expand Down
17 changes: 11 additions & 6 deletions client/src/modules/stock/stock.routes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
angular.module('bhima.routes')
.config(['$stateProvider', function ($stateProvider) {

$stateProvider
.state('stockLots', {
url : '/stock/lots',
Expand All @@ -24,19 +23,25 @@ angular.module('bhima.routes')
url : '/stock/exit',
controller : 'StockExitController as StockCtrl',
templateUrl : 'modules/stock/exit/exit.html',
onExit : ['$uibModalStack', closeModals],
})

.state('stockEntry', {
url : '/stock/entry',
controller : 'StockEntryController as StockCtrl',
templateUrl : 'modules/stock/entry/entry.html',
onExit : ['$uibModalStack', closeModals],
})

.state('stockAdjustment', {
url : '/stock/adjustment',
controller : 'StockAdjustmentController as StockCtrl',
templateUrl : 'modules/stock/adjustment/adjustment.html',
})
;
},
]);
onExit : ['$uibModalStack', closeModals],
});
}]);


function closeModals($uibModalStack) {
$uibModalStack.dismissAll();
}

0 comments on commit 2bbe37b

Please sign in to comment.