Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- 'use strict';
- angular.module('adjustmentStockQtyModule')
- .controller('AddAdjustmentStockQtyController', AddAdjustmentStockQtyController);
- AddAdjustmentStockQtyController.$inject = ['AdjustmentStockQtyService', '$state', '$stateParams', '$uibModal', '$scope', '$filter', 'ApiConstant', 'RestService']
- function AddAdjustmentStockQtyController(AdjustmentStockQtyService, $state, $stateParams, $uibModal, $scope, $filter, ApiConstant, RestService) {
- $scope.input = {
- remark : "",
- adjustmentStockItem : []
- }
- $scope.inputProduct = {};
- $scope.errorsItems = [];
- $scope.gridItemList = [];
- $scope.open1 = function() {
- $scope.popup1.opened = true;
- };
- $scope.setDate = function(year, month, day) {
- $scope.dt = new Date(year, month, day);
- };
- var today = new Date();
- var lastMonth = new Date();
- lastMonth.setDate(lastMonth.getDate() - 30);
- $scope.options = {
- minDate : lastMonth,
- maxDate: today
- };
- $scope.maxDate = new Date();
- $scope.format = 'dd/MM/yyyy';
- $scope.altInputFormats = ['M!/d!/yyyy'];
- $scope.popup1 = {
- opened: false
- };
- $scope.getProductList = function(val) {
- try {
- var input = {
- keyword: val,
- categoryId : null,
- subCategoryId : null,
- brand : "",
- limit: 5,
- offset: 0
- };
- return RestService.call(ApiConstant.GET_PRODUCT_ADJUSTMENT_STOCK_LIST, input)
- .then(function(response) {
- return response.result.productList.map(function(item){
- return item;
- });
- }).catch(function(response){
- errorAlert("Terjadi kesalahan pada sistem");
- });
- } catch (err) {
- $scope.errorsItems = [err];
- }
- }
- $scope.addProductItem = function(){
- $scope.errorsItems = [];
- try {
- if(!$scope.inputProduct.product) {
- throw "Produk harus diisi";
- }
- if(!$scope.inputProduct.qty_adj || $scope.inputProduct.qty_adj == 0) {
- throw "Qty Adjustment harus diisi";
- }
- var input = {
- product_id: $scope.inputProduct.product.product_id,
- product_code: $scope.inputProduct.product.product_code,
- product_name: $scope.inputProduct.product.product_name,
- ctgr_product_name: $scope.inputProduct.product.ctgr_product_name,
- sub_ctgr_product_name: $scope.inputProduct.product.sub_ctgr_product_name,
- product_balance_id: $scope.inputProduct.product.product_balance_id,
- current_qty: $scope.inputProduct.product.qty,
- qty_adj: parseInt($scope.inputProduct.qty_adj)
- };
- angular.forEach($scope.gridItemList, function(value){
- if(valUniqueValue(value.product_id, $scope.inputProduct.product.product_id)){
- throw "Kode Produk "+value.product_code+" sudah dalam daftar";
- }
- });
- $scope.inputProduct = {};
- $scope.gridItemList.push(input);
- } catch (err) {
- $scope.errorsItems = [err];
- }
- }
- $scope.removeItem = function(element) {
- var index = $scope.gridItemList.indexOf(element);
- if (index !== -1) {
- $scope.gridItemList.splice(index, 1);
- }
- }
- $scope.lookupProduct = function() {
- $scope.errorsItems = [];
- try {
- var modalInstance = $uibModal.open({
- animation: true,
- ariaLabelledBy: 'modal-title',
- ariaDescribedBy: 'modal-body',
- templateUrl: '/view/webtoko::adjustmentStockQty.lookupProduct',
- controller: 'LookupProductController',
- size:'lg',
- resolve: {
- items: function () {
- return $scope.items;
- }
- }
- });
- modalInstance.result.then(function (selectedItem) { var errors = [];
- if($scope.gridItemList.length == 0){
- Array.prototype.push.apply($scope.gridItemList,selectedItem);
- } else {
- _.forEach(selectedItem, function(object) {
- if(_.filter($scope.gridItemList, _.matches(object)).length > 0){
- errors.push("Kode Produk "+object.product_code+" sudah dalam daftar")
- }
- });
- if(errors.length > 0){
- throw errors;
- }
- else {
- Array.prototype.push.apply($scope.gridItemList,selectedItem);
- }
- }
- }, function () {
- //$log.info('Modal dismissed at: ' + new Date());
- });
- } catch (err) {
- $scope.errorsItems = [err];
- }
- }
- $scope.createAdjust = function () {
- $scope.errorsItems = [];
- var errors = [];
- try{
- _.forEach($scope.gridItemList, function(object) {
- if(!object.qty_adj || object.qty_adj == 0){
- throw "Qty adjustment tidak boleh kosong atau 0";
- }
- })
- //$scope.input.tgl_adjusment = $scope.input.tgl_adj ? $filter('date')($scope.input.tgl_adj, "yyyyMMdd") : null;
- $scope.input.tgl_adjusment = formatDate($scope.input.tgl_adj);
- $scope.input.adjustmentStockItem = $scope.gridItemList;
- RestService.call(ApiConstant.ADD_ADJUSTMENT_STOCK_LIST, $scope.input)
- .then(function(response) {
- console.log('Response: ');
- console.log(response.result);
- if(response.result.status == 'OK'){
- successAlert("Dokumen berhasil dibuat");
- $state.reload();
- }else{
- if(response.result.errorKey == 'Error Business Validation'){
- $scope.errorServerValidation = [];
- angular.forEach(response.result.errorList, function(value, key) {
- $scope.errorsItems.push(value[0]);
- console.log('Error Items');
- console.log($scope.errorsItems);
- });
- }else{
- errorAlert("Terjadi kesalahan pada sistem sistem");
- }
- }
- }).catch(function(response){
- errorAlert("Terjadi kesalahan pada sistem");
- });
- }
- catch (err) {
- $scope.errorsItems = [err];
- }
- }
- }
- })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement