61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
(function() {
|
|
"use strict";
|
|
|
|
window.app.directive('inventoryAdd',
|
|
function() {
|
|
return {
|
|
templateUrl: '/inventory/template/inventoryAdd.tmpl.cshtml',
|
|
controller: controller,
|
|
controllerAs: 'vm'
|
|
}
|
|
});
|
|
|
|
controller.$inject = ['$scope', 'inventorySvc', 'inventoryTypeSvc'];
|
|
function controller($scope, inventorySvc, inventoryTypeSvc) {
|
|
var vm = this;
|
|
|
|
vm.add = add;
|
|
vm.inventory = { };
|
|
vm.inventoryTypes = inventoryTypeSvc.inventoryTypes;
|
|
|
|
vm.saving = false;
|
|
vm.statusMessage = "Enter details for the inventory arrival below.";
|
|
vm.errorMessages = [];
|
|
|
|
vm.quantity = quantity;
|
|
|
|
function zeroNaN(v) {
|
|
return isNaN(v) ? 0 : v;
|
|
}
|
|
|
|
function quantity() {
|
|
vm.inventory.quantity =
|
|
zeroNaN($scope.palletCount)
|
|
* zeroNaN($scope.casesPerPallet)
|
|
+ zeroNaN($scope.caseCount);
|
|
|
|
return vm.inventory.quantity > 0 ? vm.inventory.quantity : "";
|
|
}
|
|
|
|
$scope.$watch('vm.commodity', function (newValue) {
|
|
if (newValue)
|
|
vm.inventory.inventoryTypeId = newValue.id;
|
|
});
|
|
|
|
function add() {
|
|
vm.statusMessage = null;
|
|
vm.saving = true;
|
|
inventorySvc.add(vm.inventory)
|
|
.success(function () {
|
|
//Close the modal
|
|
$scope.$close();
|
|
})
|
|
.error(function(data) {
|
|
vm.errorMessages = angular.copy(data.errorMessages, vm.errorMessages);
|
|
})
|
|
.finally(function() {
|
|
vm.saving = false;
|
|
});
|
|
}
|
|
}
|
|
})(); |