MyEpaySlip_DHAS.Controller.js 3.53 KB
Newer Older
Thitichaipun Wutthisak committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
'use strict'

angular.module('EPAYSLIP').controller('MyEpaySlip', ['$scope', '$http', 'EpayslipCtrl', function($scope, $http, EpayslipCtrl){
   var nowdate = new Date();
   $scope.mypw = '';
   $scope.result= '';
   $scope.paysliplist = [];
   $scope.yearselect;
   $scope.monthselect = '';
   $scope.periodselect = '1';
   $scope.tmpmonth = [];
   $scope.tmpperiod = [];
   $scope.firstr = true;
   $scope.itemparam = {
      gettype: 'select_list',
      prgcode: 'none',
      period: 'none',
      years: 'none',
      months: 'none',
      round: 'none',
      salatype: 'none',
      gendate: 'none',
      periodseq: 'none'
   };

   EpayslipCtrl.manageEpaySlip.query($scope.itemparam)
   .$promise.then(function(data){
      $scope.paysliplist = data.listyear;
      $scope.yearselect = $scope.paysliplist[0].year.toString();
      $scope.genMonth();
      console.log($scope.paysliplist);
   });

   $scope.checkPassword = function(){
      EpayslipCtrl.managePassword.query({password: SHA1($scope.mypw)})
      .$promise.then(function(data){
         $scope.result = data.result;
         if ($scope.result == true || $scope.result == 'true'){
            $scope.mypw = '';
            $('.blog-password').fadeOut('fast');
				$('section[name="__secpayslip"]').removeClass('hidesection');
            $scope.genParam();
            viewData();
         }else{
            alert(MyCode[226]);
         }
      });
   }

   $scope.genMonth = function(){
      var tmpmname = '';
      $scope.periodselect = '1';
      $scope.tmpmonth = [];
      $scope.paysliplist.forEach(function(data){
         if ($scope.yearselect == data.year){
            data.monthdata.forEach(function(mdata){
               tmpmname = mdata.month;
               if (mdata.month < 10){
                  tmpmname = mdata.month.substring(1, mdata.month.length);
               }
               $scope.tmpmonth.push({id: mdata.month, name: getMonthFullName(tmpmname), period: mdata.round});
            });
         }
      });
      $scope.monthselect = $scope.tmpmonth[0].id;
      $scope.genPeriod();
   }

   $scope.genPeriod = function(){
      $scope.periodselect = '1';
      $scope.tmpperiod = [];
      $scope.tmpmonth.forEach(function(data){
         if ($scope.monthselect == data.id){
			var aListIndex = data.period.split(",");
			for(var x=1;x<aListIndex.length;x++){
				var aListPeriod = aListIndex[x].split("#");
				if($scope.yearselect==aListPeriod[0].split("$")[0]){
					if($scope.monthselect==aListPeriod[0].split("$")[1]){
						if($scope.periodselect=="1"){
							$scope.periodselect = aListPeriod[1].substring(3, 13);
						}
								$scope.tmpperiod.push(aListPeriod[1]);
					}
				}
			}
         }
      });
   }

   $scope.genParam = function(){
      $scope.paysliplist.forEach(function(maindata){
         if ($scope.yearselect == maindata.year){
            maindata.monthdata.forEach(function(subdata){
               if ($scope.monthselect == subdata.month){
                  var periodselectindex = $('select[ng-model="periodselect"]').prop('selectedIndex') + 1;
                  $('input[name="__prgcode"]').val(subdata.prgcode.split(",")[periodselectindex]);
                  $('input[name="__gendate"]').val(subdata.gendate.split(",")[periodselectindex]);
                  $('input[name="__period"]').val(subdata.period.split(",")[periodselectindex]);
                  $('input[name="__salatype"]').val(subdata.salatype);
                  $('input[name="__periodseq"]').val(subdata.periodseq.split(",")[periodselectindex]);
               }
            });
         }
      });
   }
}]);