Advertisement
IdlaNier97

Untitled

Jun 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.35 KB | None | 0 0
  1. (function() {
  2.  
  3.     'use strict';
  4.  
  5.     angular.module('adjustmentStockQtyModule')    
  6.       .controller('AddAdjustmentStockQtyController', AddAdjustmentStockQtyController);          
  7.       AddAdjustmentStockQtyController.$inject = ['AdjustmentStockQtyService', '$state', '$stateParams', '$uibModal', '$scope', '$filter', 'ApiConstant', 'RestService']
  8.    
  9.       function AddAdjustmentStockQtyController(AdjustmentStockQtyService, $state, $stateParams, $uibModal, $scope, $filter, ApiConstant, RestService) {  
  10.          
  11.         $scope.input = {
  12.             remark : "",
  13.             adjustmentStockItem : []
  14.         }
  15.  
  16.           $scope.inputProduct = {};
  17.           $scope.errorsItems = [];
  18.           $scope.gridItemList = [];
  19.  
  20.           $scope.open1 = function() {
  21.               $scope.popup1.opened = true;
  22.            };
  23.          
  24.          $scope.setDate = function(year, month, day) {
  25.              $scope.dt = new Date(year, month, day);
  26.           };
  27.  
  28.         var today = new Date();
  29.         var lastMonth = new Date();
  30.  
  31.         lastMonth.setDate(lastMonth.getDate() - 30);
  32.        
  33.         $scope.options = {        
  34.             minDate : lastMonth,
  35.             maxDate: today          
  36.         };
  37.  
  38.          $scope.maxDate = new Date();
  39.          $scope.format = 'dd/MM/yyyy';
  40.          $scope.altInputFormats = ['M!/d!/yyyy'];
  41.          
  42.          $scope.popup1 = {
  43.               opened: false
  44.           };  
  45.          
  46.           $scope.getProductList = function(val) {            
  47.  
  48.               try {            
  49.  
  50.                   var input = {                    
  51.                       keyword: val,        
  52.                       categoryId : null,
  53.                       subCategoryId : null,
  54.                       brand : "",                                
  55.                       limit: 5,
  56.                       offset: 0
  57.                   };
  58.                   return RestService.call(ApiConstant.GET_PRODUCT_ADJUSTMENT_STOCK_LIST, input)
  59.                       .then(function(response) {                                    
  60.                           return response.result.productList.map(function(item){
  61.                               return item;
  62.                           });
  63.                       }).catch(function(response){
  64.                           errorAlert("Terjadi kesalahan pada sistem");
  65.                       });
  66.  
  67.               } catch (err) {                
  68.                   $scope.errorsItems = [err];
  69.               }
  70.           }
  71.  
  72.           $scope.addProductItem = function(){
  73.               $scope.errorsItems = [];            
  74.  
  75.               try {
  76.  
  77.                   if(!$scope.inputProduct.product) {
  78.                       throw "Produk harus diisi";
  79.                   }
  80.  
  81.                   if(!$scope.inputProduct.qty_adj || $scope.inputProduct.qty_adj == 0) {
  82.                       throw "Qty Adjustment harus diisi";
  83.                   }
  84.                   var input = {
  85.                       product_id: $scope.inputProduct.product.product_id,
  86.                       product_code: $scope.inputProduct.product.product_code,
  87.                       product_name: $scope.inputProduct.product.product_name,
  88.                       ctgr_product_name: $scope.inputProduct.product.ctgr_product_name,
  89.                       sub_ctgr_product_name: $scope.inputProduct.product.sub_ctgr_product_name,                
  90.                       product_balance_id: $scope.inputProduct.product.product_balance_id,
  91.                       current_qty: $scope.inputProduct.product.qty,
  92.                       qty_adj: parseInt($scope.inputProduct.qty_adj)
  93.                   };
  94.                  
  95.                   angular.forEach($scope.gridItemList, function(value){
  96.                       if(valUniqueValue(value.product_id, $scope.inputProduct.product.product_id)){
  97.                           throw "Kode Produk "+value.product_code+" sudah dalam daftar";
  98.                       }
  99.                   });
  100.  
  101.                   $scope.inputProduct = {};
  102.  
  103.                   $scope.gridItemList.push(input);
  104.  
  105.               } catch (err) {
  106.                   $scope.errorsItems = [err];
  107.               }
  108.           }
  109.  
  110.           $scope.removeItem = function(element) {
  111.               var index =  $scope.gridItemList.indexOf(element);
  112.              
  113.               if (index !== -1) {
  114.                   $scope.gridItemList.splice(index, 1);
  115.               }
  116.           }
  117.  
  118.           $scope.lookupProduct = function() {
  119.               $scope.errorsItems = [];
  120.  
  121.               try {
  122.  
  123.                   var modalInstance = $uibModal.open({
  124.                       animation: true,
  125.                       ariaLabelledBy: 'modal-title',
  126.                       ariaDescribedBy: 'modal-body',
  127.                       templateUrl: '/view/webtoko::adjustmentStockQty.lookupProduct',
  128.                       controller: 'LookupProductController',                    
  129.                       size:'lg',
  130.                       resolve: {
  131.                           items: function () {
  132.                               return $scope.items;
  133.                           }
  134.                       }
  135.                   });
  136.  
  137.                   modalInstance.result.then(function (selectedItem) {                       var errors = [];
  138.                       if($scope.gridItemList.length == 0){
  139.                           Array.prototype.push.apply($scope.gridItemList,selectedItem);
  140.                       } else {
  141.                           _.forEach(selectedItem, function(object) {
  142.  
  143.                               if(_.filter($scope.gridItemList, _.matches(object)).length > 0){
  144.                                   errors.push("Kode Produk "+object.product_code+"  sudah dalam daftar")
  145.                               }
  146.                           });
  147.  
  148.                           if(errors.length > 0){
  149.                               throw errors;
  150.                           }
  151.                           else {
  152.                               Array.prototype.push.apply($scope.gridItemList,selectedItem);
  153.                           }
  154.                       }
  155.                   }, function () {
  156.                       //$log.info('Modal dismissed at: ' + new Date());
  157.                   });
  158.               } catch (err) {
  159.                 $scope.errorsItems = [err];
  160.               }
  161.           }
  162.  
  163.         $scope.createAdjust = function () {  
  164.             $scope.errorsItems = [];
  165.  
  166.             var errors = [];
  167.  
  168.             try{
  169.                 _.forEach($scope.gridItemList, function(object) {
  170.                     if(!object.qty_adj || object.qty_adj == 0){
  171.                         throw "Qty adjustment tidak boleh kosong atau 0";
  172.                     }
  173.                 })                
  174.    
  175.                 //$scope.input.tgl_adjusment = $scope.input.tgl_adj ? $filter('date')($scope.input.tgl_adj, "yyyyMMdd") : null;
  176.                 $scope.input.tgl_adjusment = formatDate($scope.input.tgl_adj);
  177.                 $scope.input.adjustmentStockItem = $scope.gridItemList;          
  178.                 RestService.call(ApiConstant.ADD_ADJUSTMENT_STOCK_LIST, $scope.input)
  179.                 .then(function(response) {
  180.                     console.log('Response: ');
  181.                     console.log(response.result);
  182.                     if(response.result.status == 'OK'){
  183.                         successAlert("Dokumen berhasil dibuat");
  184.                         $state.reload();
  185.                     }else{
  186.                         if(response.result.errorKey == 'Error Business Validation'){       
  187.                             $scope.errorServerValidation = [];
  188.                             angular.forEach(response.result.errorList, function(value, key) {  
  189.                                 $scope.errorsItems.push(value[0]);
  190.                                 console.log('Error Items');
  191.                                 console.log($scope.errorsItems);                       
  192.                             });                                        
  193.                         }else{
  194.                             errorAlert("Terjadi kesalahan pada sistem sistem");
  195.                         }
  196.                     }                
  197.                 }).catch(function(response){
  198.                     errorAlert("Terjadi kesalahan pada sistem");
  199.                 });    
  200.             }
  201.             catch (err) {
  202.                 $scope.errorsItems = [err];
  203.             }
  204.                
  205.         }      
  206.                
  207.     }  
  208.    
  209.   })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement