'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' }; 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); } }); } }); } }]);