APS_FORM_INTERVIEW_DHAS_RESULT.Controller.js 9.08 KB
Newer Older
peema_phongam committed
1 2 3 4 5
'use strict'

angular.module('APS_INTERVIEW').controller('APS_FORM_INTERVIEW_DHAS_RESULT', ['$scope', '$http', '$sce', 'InterviewcandidateCtrl', function($scope, $http, $sce, InterviewcandidateCtrl){
  $scope.candidateid = $('input[name="candidateid"]').val()
  $scope.committeeid = $('input[name="committeeid"]').val()
peema_phongam committed
6
  $scope.judge = $('input[name="judge"]').val()
peema_phongam committed
7 8 9 10 11
  $scope.notedit = ($('input[name="notedit"]').val() == 'true')
  $scope.lang = $('input[name="lang"]').val()
  $scope.contextPath = ''
  $scope.headdata = {}
  $scope.formdata = {}
peema_phongam committed
12
  $scope.previous = []
peema_phongam committed
13 14 15 16 17
  let question = new Question()
  $scope.examdata = {}
  $scope.score2 = ''
  $scope.score3 = ''
  $scope.score4 = ''
peema_phongam committed
18
  $scope.isReady = false
peema_phongam committed
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

  let DocumentContainer
  let WindowObject

  $scope.comment = [{
    comment:'',
    appropriate:0
  }]
  $scope.apsform = [{
    percentFromHr: '',
    percentFromDept: '',
    jobName: '',
    jobCode: '',
    basicallyScore: '',
    managementScore: '',
    sumScore: '',
    estimatePercentJob: '',
    resultFromDept: '',
    hire: '',
    remarkFromDept: '',
    incentives: [{
      name: 'ค่าเดินทาง / ค่าน้ำมันรถจักรยานยนต์',
      cost: '',
      startDate: ''
    },{
      name: 'ค่าเบี้ยเลี้ยง',
      cost: '',
      startDate: ''
    },{
      name: '',
      cost: '',
      startDate: ''
    },{
      name: '',
      cost: '',
      startDate: ''
    }],
    hr: {
      score: '',
      multiple: '',
      incomeWithBonus: '',
      incomeWithoutBonus: '',
      basicSalary: '',
      qpi: '',
      m1pi: '',
      m3pi: ''
    },
    ex: {
      result: '',
      other: '',
      estimateIncome : '',
      otherEstimateIncome: ''
    },
    seniorEx: {
      remark: '',
    },
    sign: {
      manager: '',
      hr: '',
      ex: '',
      seniorEx: ''
    }
  }]

  $scope.myparam = {
    candidateid: $scope.candidateid,
peema_phongam committed
85 86
    committeeid: $scope.committeeid,
    judge: $scope.judge
peema_phongam committed
87 88 89 90
  };
  InterviewcandidateCtrl.manageInterviewForm.query($scope.myparam).$promise.then(function(data){
    $scope.headdata = data.header
    $scope.formdata = data.apsform
peema_phongam committed
91
    $scope.previous = data.previous
peema_phongam committed
92 93
    setFormAPS()

peema_phongam committed
94
    $scope.isReady = true
peema_phongam committed
95 96 97
  })


peema_phongam committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
  $scope.getResultHr = () => {
    let result = 0
    let findHr = $scope.previous.find(($item) => {
      return $item.header.dept.toUpperCase() === "HR"
    })
    if(findHr){
      for(var i = 0; i < findHr.apsform.form.length; i++){
        let form = findHr.apsform.form[i];
        result += parseInt(form.score)
      }
    }
    return (result / 50) * 100;
  }

  $scope.getResultDept = () => {
    let result = 0
    let findHr = $scope.previous.find(($item) => {
      return $item.header.dept.toUpperCase() === "DEPT" && $item.header.committeeid === $scope.committeeid
    })
    console.log(findHr)
    if(findHr){
      for(var i = 0; i < findHr.apsform.form.length; i++){
        let form = findHr.apsform.form[i];
        result += parseInt(form.score)
      }
    }
    return (result / 50) * 100;
  }



peema_phongam committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
  let setFormAPS = () => {
    if($scope.formdata.form == ''){
      $scope.formdata.form = $scope.apsform
    }else {
      $scope.formdata.form = jQuery.parseJSON($scope.formdata.form)
    }
    if($scope.formdata.comment == ''){
      $scope.formdata.comment = $scope.comment
    }else {
      $scope.formdata.comment = jQuery.parseJSON($scope.formdata.comment)
    }
  }

  $scope.getSumScore = () => {
    let result = 0
    if($scope.formdata.form != undefined){
      for(var i = 0; i <$scope.formdata.form.length; i++){
        let form = $scope.formdata.form[i];
        result += parseInt(form.score)
      }
    }
    return result;
  }

peema_phongam committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
  $scope.getSumScoreByForm = ($form) => {
    let result = 0
    if($form != undefined){
      for(var i = 0; i < $form.length; i++){
        let sform = $form[i];
        result += parseInt(sform.score)
      }
    }
    return (result / 50).toFixed(2);
  }

  $scope.getSumScoreByScoreForm = ($form, score) => {
    let result = 0
    if($form != undefined){
      for(var i = 0; i < $form.length; i++){
        let sform = $form[i];
        if(sform.score == score){
          result += parseInt(sform.score)
        }
      }
    }
    return (result / 50).toFixed(2);
  }

peema_phongam committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
  $scope.getSumScoreByScore = (score) => {
    let result = 0
    if($scope.formdata.form != undefined){
      for(var i = 0; i <$scope.formdata.form.length; i++){
        let form = $scope.formdata.form[i];
        if(form.score == score){
          result += parseInt(form.score)
        }
      }
    }
    return result;
  }

  $scope.addComment = () => {
    let data = {
      comment : ''
    }
    $scope.formdata.comment.push(data)
  }
  $scope.delComment = () => {
    $scope.formdata.comment.pop()
  }

  $scope.saveDraff = () => {
    if (confirm(MyCode[1])){
      $scope.sendparam = $scope.sendparam = setParam('0')
      InterviewcandidateCtrl.manageInterviewForm.save(JSON.stringify($scope.sendparam))
          .$promise.then(function(){
        alert(MyCode[18]);
        window.opener.location.reload();
      });
    }
  }

  $scope.save = () => {
    if(true){
      if (confirm(MyCode[1])){
        $scope.sendparam = setParam('1')
        InterviewcandidateCtrl.manageInterviewForm.save(JSON.stringify($scope.sendparam))
            .$promise.then(function(){
          alert(MyCode[18]);
          window.opener.location.reload();
        });
      }
    }else{
      alert('กรุณากรอกข้อมูลให้ครบถ้วน')
    }
  }

  let setParam = (type) => {
    let param = {
      headdata: $scope.headdata
      ,apsform: $scope.formdata
      ,savetype: type
    }
    return param
  }

  let chkData = () => {
    let result = true
    let objlist = $scope.formdata.form.filter((form) => form.score == 0)
    if (objlist.length>0){
      result = false
    }
    let objlist2 = $scope.formdata.comment.filter((comment) => comment.comment == 0)
    if (objlist2.length>0){
      result = false
    }
    let objlist3 = $scope.formdata.comment.filter((appropriate) => appropriate.appropriate == 0)
    if (objlist3.length>0){
      result = false
    }

    return result
  }

  $scope.goprint = function(){
    hidelement();
    promisePrint().then((obj) => {
      WindowObject.focus();
      console.log(WindowObject);
      // window.close();
      WindowObject.print();
    })
  }

  function promisePrint(){
    return new Promise((resolve, reject) => {
      DocumentContainer = document.getElementById('target_warpper');
      WindowObject = window.open('', 'PrintWindow', 'width=1200,height=666,top=10,right=10,toolbars=no,scrollbars=no,status=no,resizable=yes,scale=98%');
      WindowObject.document.writeln('<!DOCTYPE html>');
      WindowObject.document.writeln('<html><head><title></title>');
      WindowObject.document.writeln(`<link rel="stylesheet" type="text/css" href="${$scope.contextPath}/EMPVIEW/css/APP_UP/style_apsup.css">`);
      WindowObject.document.writeln(`<link rel="stylesheet" type="text/css" href="${$scope.contextPath}/EMPVIEW/css/APS_Interview/style_printInterview.css">`);
      WindowObject.document.writeln(`<link rel="stylesheet" type="text/css" href="${$scope.contextPath}/CSS/Bootstrap/css/bootstrap.css">`);
      WindowObject.document.writeln(`<link rel="stylesheet" type="text/css" href="${$scope.contextPath}/CSS/EMPVIEW_LAYOUT.min.css">`);
      WindowObject.document.writeln(`<link rel="stylesheet" type="text/css" href="${$scope.contextPath}/CSS/font-awesome.css">`);
      WindowObject.document.writeln('</head><body>');
      WindowObject.document.writeln(DocumentContainer.innerHTML);
      WindowObject.document.writeln('</body></html>');
      WindowObject.document.close();
      setTimeout(() => resolve(WindowObject), 1000)
    })
  }

  function hidelement(){
    let txt = ''
    let chk = false

    $(".score1").each(function(){
      if($(this).hasClass("ng-hide")){
        $(this).hide()
      }
    });

    $(".score2").each(function(){
      chk = $(this).prop('checked');
      if(chk){
        $(this).parents("td").append("<i class='fa fa-check-square-o right dis-block'></i>");
      }
      else{
        $(this).parents("td").append("<i class='fa fa-square-o right dis-block'></i>");
      }
      $(this).hide();
    });

    $(".score3").each(function(){
      chk = $(this).prop('checked');
      if(chk){
        $(this).parents(".chk").append("<i class='fa fa-check-square-o right dis-block'></i>");
      }
      else{
        $(this).parents(".chk").append("<i class='fa fa-square-o right dis-block'></i>");
      }
      $(this).hide();
    });


    $("textarea").each(function(){
      txt = $(this).val()
      if(txt ==''){
        $(this).parents(".showtxt").find("label").removeClass('hide')
        $(this).parents(".showtxt").find("label").clone().appendTo($(this).parents(".showtxt"))
      }else{
        $(this).parents(".showtxt").find("label").removeClass('txt-underline hide')
        $(this).parents(".showtxt").find("label").addClass('txt-underline2')
        $(this).parents(".showtxt").find("label").text(txt)
      }
      $(this).hide()
    });

    $('.btn').hide()
    $('.icon-btn').hide()

  }

}]);