import { Component, OnInit, ElementRef } from "@angular/core";
import { CommonService } from "src/app/hmg-common/services/common/common.service";
import { TranslatorService } from "src/app/hmg-common/services/translator/translator.service";
import { MenuService } from "src/app/hmg-common/services/menu/menuservice.service";
import { MenuResponse } from "src/app/hmg-common/services/menu/models/menu-response";
import { ModalController } from "@ionic/angular";
import { SubmitAbsenceService } from "../service/submit.absence.service";
import { AbsenceAttahcmentResponse } from "../models/abs.attach.response";
import { AbsenceListService } from "../service/service.service";
import { AbsenceDffResponse } from "../models/abs_dff_response";
import { AbsenceTransaction } from "../models/absence.transaction";
import { MenuEntry } from "../../hmg-common/services/menu/models/menu.entry";
import { ButtonInput } from "../../uI-elements/button.input";
import { HiddenInput } from "../../uI-elements/hidden.input";
import { TextAreaInput } from "../../uI-elements/text-area.input";
import { TextInput } from "../../uI-elements/text.input";
import { NumberInput } from "../../uI-elements/number.input";
import { SelectInput } from "../../uI-elements/select.input";
import { DateInput } from "../../uI-elements/date.input";
import { TimeInput } from "../../uI-elements/time.input";
import { DateTimeInput } from "../../uI-elements/date-time.input";
import { DatePicker } from "@ionic-native/date-picker/ngx";
import { Request } from '../../hmg-common/services/models/request';
// import { Request } from "../models/request";
import * as moment from "moment";
import {ReplacementListComponent} from "../../vacation-rule/replacement-list/replacement-list.component";
import {ReplacmentResponse} from "../models/replacment-response";
import { AbsenceResponse } from '../models/absence.response';
@Component({
  selector: "app-submit-absence",
  templateUrl: "./submit-absence.component.html",
  styleUrls: ["./submit-absence.component.scss"]
})
export class SubmitAbsenceComponent implements OnInit {
  private textArea: TextAreaInput;
  private numberInput: NumberInput;
  private textInput: TextInput;
  private selectInput: SelectInput;
  private dateInput: DateInput;
  private timeInput: TimeInput;
  private datetimeInput: DateTimeInput;
  private buttonInput: ButtonInput;
  private hiddenInput: HiddenInput;
  private eitVALSettoCall: any = [];
  private action: string = "";
  private modalFlag: any = false;
  menuType: any;
  employeeSel: any;
  absenceType: any;
  absenceTypeName: string = null;
  absenceTypeList: any;
  startDate: any;
  startTime: string = null;
  endTime: string = null;
  endDate: any;
  absComments: string = null;
  type: any;
  totalDays: any;
  hoursOrDay: string = "";
  replacmentEmployeeInfo: any;
  employeeName: string;
  employeeID: string = null;
  selEmp: string;
  respID: number;
  selMenu: MenuResponse;
  getPassMnuEntryObj: MenuEntry;
  notificationId: number;
  itemKey: string = null;
  //private ExtraObj:any={};
  private absenceDffresponse: AbsenceDffResponse[];
  private absenceRrequest: AbsenceTransaction;
  /*****for resubmit******* */
  getPassNotificationDetails: any;
  getPassdirfromNotifiPage: boolean = false;
  functionName: string = "";
  private submitAbsObjList: any = [];
  // private updatedValues:any=[];
  constructor(
    public submitAbsService: SubmitAbsenceService,
    public modalCtrl: ModalController,
    // public ReplacmentList: WorklistReplacmentEmployeeService,
    public common: CommonService,
    public datePicker: DatePicker,
    public ts: TranslatorService,
    private elementRef: ElementRef,

  ) {
    ////*new add*/////
    /**********resubmit************ */
    //this.getPassNotificationDetails = this.common.sharedService.getSharedData(AbsenceNotificatonBodyResponse.NOT_WORKLIST, true);
    //  this.getPassdirfromNotifiPage = this.navParams.get('dirfromNotificationPage');
    if (this.getPassdirfromNotifiPage) {
      this.functionName = this.getPassNotificationDetails.FUNCTION_NAME; //;this.getPassNotificationDetails.NOTIFICATION_NAME;
      this.menuType = "E";
      this.itemKey = this.getPassNotificationDetails.ITEM_KEY;
      this.notificationId = this.getPassNotificationDetails.NOTIFICATION_ID;
      this.selEmp = this.getPassNotificationDetails.SELECTED_EMPLOYEE_NUMBER;
      this.respID = -999;
      //this.submitAbsObjList = this.navParams.get('submitAbsObjList');
    } else {
      this.action = "CREATE";
      this.selEmp = this.common.sharedService.getSharedData(
        MenuResponse.SHARED_SEL_EMP,
        false
      );
      this.respID = this.common.sharedService.getSharedData(
        MenuResponse.SHARED_SEL_RESP_ID,
        false
      );
      this.selMenu = new MenuResponse();
      this.selMenu = this.common.sharedService.getSharedData(
        MenuResponse.SHARED_DATA,
        false
      );
      this.menuType = this.selMenu.List_Menu.MENU_TYPE;
      this.getPassMnuEntryObj = this.selMenu.GetMenuEntriesList;
      this.functionName = this.getPassMnuEntryObj.FUNCTION_NAME;
      this.submitAbsObjList = [];
    }
    this.absenceDffresponse = [];
  }

  ngOnInit() {
    this.getAbsenceTypes();
  }
  private getAbsenceDffStructure() {
    const body = {
      P_FUNCTION_NAME: this.functionName,
      P_SELECTED_EMPLOYEE_NUMBER: this.selEmp,
      P_MENU_TYPE: this.menuType,
      P_SELECTED_RESP_ID: this.respID,
      P_DESC_FLEX_CONTEXT_CODE: this.absenceTypeName
    };
    this.submitAbsService
      .getAbsenceDffStructure(body)
      .subscribe((result: any) => {
        this.handleAbcenseDFFStructure(result);
      });
  }

  handleAbcenseDFFStructure(result) {
    if (result.GetAbsenceDffStructureList != null) {
      this.absenceDffresponse = result.GetAbsenceDffStructureList;
      this.drawAbcenseFields(result.GetAbsenceDffStructureList);
    }
  }

  getAbsenceTypes() {
    let AbsenceType: Request = new Request();
    //let user = this.sharedData.getSharedData(LoginResponse.SHARED_DATA,true)

    const request = {
      P_SELECTED_EMPLOYEE_NUMBER: this.selEmp
    };
    this.submitAbsService.getAbsenceType(request).subscribe((result: any) => {
      this.handlegetAbsenceTypes(result);
    });
  }
  handlegetAbsenceTypes(result) {
    if (this.common.validResponse(result)) {
      if (this.common.hasData(result.GetAbsenceAttendanceTypesList)) {
        this.absenceTypeList = result.GetAbsenceAttendanceTypesList;
        this.hoursOrDay = this.absenceTypeList[0].HOURS_OR_DAYS;
        if (this.submitAbsObjList && this.submitAbsObjList.length > 0) {
          this.fillStaticStructure();
        }
      }
    }
  }
  calcDay() {
    let msg: string = "";
    if (
      this.startDate == undefined ||
      this.startDate == "" ||
      this.startDate == null
    ) {
      // msg=this.translate.translate("submitAbsence.enterSDate");
      // this.common.showAlert(msg);
      return;
    } else if (
      this.endDate == undefined ||
      this.endDate == "" ||
      this.endDate == null
    ) {
      // msg=this.translate.translate("submitAbsence.enterEDate");
      // this.common.showAlert(msg);
      return;
    } else if (!this.absenceType) {
      // msg=this.translate.translate("submitAbsence.selAbsType");
      // this.common.showAlert(msg);
      return;
    } else {
      let numberOfType: number = parseInt(this.absenceType);
      let Sdata = moment(this.startDate).format("DD-MMM-YYYY"); //(dd/mmm/yyyy)
      let Edata = moment(this.endDate).format("DD-MMM-YYYY");
      const request = {
        P_SELECTED_EMPLOYEE_NUMBER: this.selEmp,
        P_ABSENCE_ATTENDANCE_TYPE_ID: numberOfType,
        P_DATE_START: Sdata,
        P_DATE_END: Edata,
        P_SELECTED_RESP_ID: this.respID,
        P_MENU_TYPE: this.menuType,
        P_TIME_START: null,
        P_TIME_END: null
      };
      this.submitAbsService.getCalc(request).subscribe((result: any) => {
        this.handlecalcDay(result);
      });
    }
  }

  handlecalcDay(result) {
    if (this.common.validResponse(result)) {
      // console.log(result);
      this.totalDays = result.CalculateAbsenceDuration.P_ABSENCE_DAYS;
    }
  }
  async openSearch(){
    const modal = await this.modalCtrl.create({
      component: ReplacementListComponent,
      keyboardClose: true,
      animated: false
    });
    let dismissed = modal.onDidDismiss();
    dismissed.then(() => {
      this.modalFlag = false;
    });
    return await modal.present();
  }

  async SearchReplacment() {
    const modal = await this.modalCtrl.create({
      component: ReplacementListComponent
    });

    modal.onDidDismiss()
      .then((data) => {
        const user = data.data.empData;
        console.log(data)
        console.log(user);
        if (data) {
          this.employeeName  = user.EMPLOYEE_DISPLAY_NAME;
          this.employeeID = user.USER_NAME;
          this.employeeSel = this.employeeName + "," + this.employeeID;
        }
      });

    return await modal.present();
  }
  handleReplacment(result) {
    if (this.common.validResponse(result)) {
      console.log(result);
    }
  }
  clearEmployee() {
    this.employeeName = "";
    this.employeeID = "";
  }

  public onTypeAbsenceChange() {
    if (this.absenceType) {
      let obj: any = this.absenceTypeList.find(
        s => s.ABSENCE_ATTENDANCE_TYPE_ID == this.absenceType
      );
      if (obj) this.absenceTypeName = obj.DESC_FLEX_CONTEXT_CODE;
      else this.absenceTypeName = null;
      this.getAbsenceDffStructure();
    } else {
      this.absenceTypeName = null;
    }
  }

  /***************draw Absence*******************/
  private drawAbcenseFields(feildsList) {
    const containerId = "dynamic-abs-container";
    document.getElementById(containerId).innerHTML = "";
    this.eitVALSettoCall = [];
    for (let i = 0; i < feildsList.length; i++) {
      let defaultVal: string = "";
      let defaultValText: string = "";
      defaultVal = feildsList[i].E_SERVICES_DV.P_ID_COLUMN_NAME
        ? feildsList[i].E_SERVICES_DV.P_ID_COLUMN_NAME
        : "";
      defaultValText = feildsList[i].E_SERVICES_DV.P_VALUE_COLUMN_NAME
        ? feildsList[i].E_SERVICES_DV.P_VALUE_COLUMN_NAME
        : "";

      if (feildsList[i].DISPLAY_FLAG != "N") {
        //check if the field should be displayed
        if (feildsList[i].VALIDATION_TYPE == "N") {
          //text , date , time
          if (feildsList[i].FORMAT_TYPE == "C") {
            // character
            this.textInput = new TextInput(
              feildsList[i].SEGMENT_PROMPT,
              feildsList[i].APPLICATION_COLUMN_NAME,
              defaultVal,
              containerId,
              defaultValText,
              feildsList[i].MOBILE_ENABLED,
              feildsList[i].DISPLAY_FLAG,
              feildsList[i].REQUIRED_FLAG
            );
          } else if (feildsList[i].FORMAT_TYPE == "N") {
            // number
            this.numberInput = new NumberInput(
              feildsList[i].SEGMENT_PROMPT,
              feildsList[i].APPLICATION_COLUMN_NAME,
              defaultVal,
              containerId,
              feildsList[i].MOBILE_ENABLED,
              feildsList[i].DISPLAY_FLAG,
              feildsList[i].REQUIRED_FLAG
            );
          } else if (feildsList[i].FORMAT_TYPE == "X") {
            // standard date
            if (
              feildsList[i].DEFAULT_TYPE == "C" ||
              feildsList[i].DEFAULT_TYPE == "D" ||
              feildsList[i].DEFAULT_TYPE == "P" ||
              feildsList[i].DEFAULT_TYPE == "S"
            ) {
              //constant
              this.dateInput = new DateInput(
                feildsList[i].SEGMENT_PROMPT,
                feildsList[i].APPLICATION_COLUMN_NAME,
                this.common.reverseFormatDate(defaultVal),
                containerId,
                feildsList[i].MOBILE_ENABLED,
                feildsList[i].DISPLAY_FLAG,
                feildsList[i].REQUIRED_FLAG
              );
            } else {
              this.dateInput = new DateInput(
                feildsList[i].SEGMENT_PROMPT,
                feildsList[i].APPLICATION_COLUMN_NAME,
                "",
                containerId,
                feildsList[i].MOBILE_ENABLED,
                feildsList[i].DISPLAY_FLAG,
                feildsList[i].REQUIRED_FLAG
              );
            }
          } else if (feildsList[i].FORMAT_TYPE == "Y") {
            // standard date time
            if (
              feildsList[i].DEFAULT_TYPE == "C" ||
              feildsList[i].DEFAULT_TYPE == "D" ||
              feildsList[i].DEFAULT_TYPE == "P" ||
              feildsList[i].DEFAULT_TYPE == "S"
            ) {
              this.datetimeInput = new DateTimeInput(
                feildsList[i].SEGMENT_PROMPT,
                feildsList[i].APPLICATION_COLUMN_NAME,
                this.common.reverseFormatStandardDate(defaultVal),
                containerId,
                feildsList[i].MOBILE_ENABLED,
                feildsList[i].DISPLAY_FLAG,
                feildsList[i].REQUIRED_FLAG
              );
            } else {
              this.datetimeInput = new DateTimeInput(
                feildsList[i].SEGMENT_PROMPT,
                feildsList[i].APPLICATION_COLUMN_NAME,
                "",
                containerId,
                feildsList[i].MOBILE_ENABLED,
                feildsList[i].DISPLAY_FLAG,
                feildsList[i].REQUIRED_FLAG
              );
            }
            const elem = document.getElementById(
              feildsList[i].APPLICATION_COLUMN_NAME
            );
            elem.addEventListener("click", e => {
              if (feildsList[i].MOBILE_ENABLED != "Y") return false;
              this.showDateTimePicker(
                feildsList[i].APPLICATION_COLUMN_NAME,
                feildsList[i].MAXIMUM_SIZE
              );
              e.stopImmediatePropagation();
            });
          } else if (feildsList[i].FORMAT_TYPE == "I") {
            //time
            if (
              feildsList[i].DEFAULT_TYPE == "C" ||
              feildsList[i].DEFAULT_TYPE == "D" ||
              feildsList[i].DEFAULT_TYPE == "P" ||
              feildsList[i].DEFAULT_TYPE == "S"
            ) {
              this.timeInput = new TimeInput(
                feildsList[i].SEGMENT_PROMPT,
                feildsList[i].APPLICATION_COLUMN_NAME,
                defaultVal,
                containerId,
                feildsList[i].MOBILE_ENABLED,
                feildsList[i].DISPLAY_FLAG,
                feildsList[i].REQUIRED_FLAG
              );
            } else {
              this.timeInput = new TimeInput(
                feildsList[i].SEGMENT_PROMPT,
                feildsList[i].APPLICATION_COLUMN_NAME,
                "",
                containerId,
                feildsList[i].MOBILE_ENABLED,
                feildsList[i].DISPLAY_FLAG,
                feildsList[i].REQUIRED_FLAG
              );
            }
            const elem = document.getElementById(
              feildsList[i].APPLICATION_COLUMN_NAME
            );
            elem.addEventListener("click", e => {
              if (feildsList[i].MOBILE_ENABLED != "Y") return false;
              this.showTimePicker(
                feildsList[i].APPLICATION_COLUMN_NAME,
                feildsList[i].MAXIMUM_SIZE
              );
              e.stopImmediatePropagation();
            });
          }
        } else {
          if (feildsList[i].READ_ONLY == "Y") {
            this.textInput = new TextInput(
              feildsList[i].SEGMENT_PROMPT,
              feildsList[i].APPLICATION_COLUMN_NAME,
              defaultValText,
              containerId,
              defaultVal,
              feildsList[i].MOBILE_ENABLED,
              feildsList[i].DISPLAY_FLAG,
              feildsList[i].REQUIRED_FLAG
            );
          } else {
            this.selectInput = new SelectInput(
              feildsList[i].SEGMENT_PROMPT,
              feildsList[i].APPLICATION_COLUMN_NAME,
              defaultVal,
              containerId,
              feildsList[i].MOBILE_ENABLED,
              feildsList[i].DISPLAY_FLAG,
              feildsList[i].REQUIRED_FLAG
            );

            this.fillDropdownList(
              feildsList[i].SEGMENT_NAME,
              feildsList[i].E_SERVICES_VS,
              feildsList[i].E_SERVICES_DV
            );
          }
        }

        this.bindHtmlElemEvents(
          feildsList[i].APPLICATION_COLUMN_NAME,
          feildsList[i]
        );
      } else {
        this.hiddenInput = new HiddenInput(
          defaultVal,
          feildsList[i].APPLICATION_COLUMN_NAME,
          defaultValText,
          containerId
        );

        this.bindHtmlElemEvents(
          feildsList[i].APPLICATION_COLUMN_NAME,
          feildsList[i]
        );
      }
    }

    if (this.submitAbsObjList && this.submitAbsObjList.length > 0) {
      this.fillAbsStructure();
    }
  }
 
  bindHtmlElemEvents(id, obj) {
 
    const elem = document.getElementById(id);
    elem.addEventListener("change", e => {
      elem.classList.remove("requiredClassElm");
      if (
        obj.CHILD_SEGMENTS_VS_Splited &&
        obj.CHILD_SEGMENTS_VS_Splited.length > 0
      ) {
        let listArray: any = obj.CHILD_SEGMENTS_VS_Splited;
        listArray.forEach(element => {
          //if(isEmpty)
          this.emptyChildElement(element);
          // else
          this.getValueSet(element);
        });
      }
      if (
        obj.CHILD_SEGMENTS_DV_Splited &&
        obj.CHILD_SEGMENTS_DV_Splited.length > 0
      ) {
        let listArray: any = obj.CHILD_SEGMENTS_DV_Splited;
        listArray.forEach(element => {
          // if(isEmpty){
          this.emptyChildElement(element);
          // }else{
          for (let i = 0; i < this.absenceDffresponse.length; i++) {
            if (this.absenceDffresponse[i].SEGMENT_NAME == element) {
              this.getDefaultValue(
                this.absenceDffresponse[i],
                this.absenceDffresponse[i].DESC_FLEX_NAME,
                this.absenceDffresponse[i].DESC_FLEX_CONTEXT_CODE,
                this.absenceDffresponse[i].SEGMENT_NAME,
                this.absenceDffresponse[i].PARENT_SEGMENTS_VS_SplitedVS,
                this.absenceDffresponse[i].PARENT_SEGMENTS_DV_Splited
              );
            }
          }
          // }
        });
      }
      return false;
      // e.stopImmediatePropagation();
    });
  }
  callValueSet() {
    for (var i = 0; i < this.eitVALSettoCall.length; i++) {
      this.getValueSet(this.eitVALSettoCall[i].SEGMENT_NAME);
    }
  }
  public getValueSet(segmentName) {
    let descFlexName: any = "";
    let descFlexContextCode: any = "";
    let parentValue: any = [];
    let ParentsList: any = [];
    let parentVal: any = null;
    let dependenciesList: any = [];
    let validationType: string = "";

    for (let i = 0; i < this.absenceDffresponse.length; i++) {
      if (this.absenceDffresponse[i].SEGMENT_NAME == segmentName) {
        descFlexName = this.absenceDffresponse[i].DESC_FLEX_NAME;
        descFlexContextCode = this.absenceDffresponse[i].DESC_FLEX_CONTEXT_CODE;
        parentValue = this.absenceDffresponse[i].PARENT_SEGMENTS_VS_SplitedVS;
        ParentsList = this.absenceDffresponse[i].PARENT_SEGMENTS_VS_SplitedVS;
        validationType = this.absenceDffresponse[i].VALIDATION_TYPE;
        break;
      }
    }
    if (parentValue != "" && (validationType == "D" || validationType == "Y")) {
      let parvalue = this.getDependenciesParams(parentValue);
      if (parvalue && parvalue[0]) parentVal = parvalue[0].ID_COLUMN_NAME;
      else {
        parentVal = null;
      }
      if (!parentVal) {
        return false;
      }
    }
    if (ParentsList != "") {
      dependenciesList = this.getDependenciesParams(ParentsList);
      if (!dependenciesList) {
        return false;
      }
    }
    const body = {
      P_SELECTED_EMPLOYEE_NUMBER: this.selEmp,
      P_MENU_TYPE: this.menuType,
      P_SELECTED_RESP_ID: this.respID, //-999,
      P_DESC_FLEX_NAME: descFlexName,
      P_DESC_FLEX_CONTEXT_CODE: descFlexContextCode,
      P_SEGMENT_NAME: segmentName,
      P_PARENT_VALUE: parentVal,
      GetValueSetValuesTBL: dependenciesList,
      P_PAGE_NUM: 1,
      P_PAGE_LIMIT: 1000
    };

    this.submitAbsService.getSetValue(body).subscribe((result: any) => {
      if (result.GetValueSetValuesList != null) {
        this.fillDropdownList(segmentName, result.GetValueSetValuesList);
      }
    });
    let arr: any = [];
    return arr;
  }

  getParentValue(parentValue) {
    if (parentValue.length == 0) {
      for (let i = 0; i < this.absenceDffresponse.length; i++) {
        if (this.absenceDffresponse[i].SEGMENT_NAME == parentValue[0].Name) {
          if (this.absenceDffresponse[i].VALIDATION_TYPE == "N") {
            let val = (document.getElementById(
              this.absenceDffresponse[i].APPLICATION_COLUMN_NAME
            ) as HTMLInputElement).value;
            return val;
          } else {
            let x = document.getElementById(
              this.absenceDffresponse[i].APPLICATION_COLUMN_NAME
            ) as HTMLSelectElement;
            if (x.options.length > 0) {
              let val = x.options[x.selectedIndex]
                ? x.options[x.selectedIndex].value
                : null;
              return val;
            } else {
              return "";
            }
          }
        }
      }
    } else {
      return "";
    }
  }
  public showDateTimePicker(elemID, maxSize) {
    let elem = document.getElementById(elemID) as HTMLDivElement;
    let date: any;
    let value = elem.innerHTML;
    if (value) date = moment(value, "YYYY/MM/DD HH:mm:ss").toDate();
    else date = new Date();
    this.datePicker
      .show({
        date: date,
        is24Hour: true,
        mode: "datetime"
      })
      .then(
        date => {
          let dateString: string = moment(date).format("YYYY/MM/DD HH:mm:ss");
          //remove seconds if the maximum size is 17
          if (maxSize == 17) {
            elem.innerHTML = dateString.substring(0, 16);
            elem.dataset.dtvalue = dateString.substring(0, 16);
          } else {
            elem.innerHTML = dateString;
            elem.dataset.dtvalue = dateString;
          }
        },
        err => console.log("Error occurred while getting date: ", err)
      );
  }
  public showTimePicker(elemID, maxSize) {
    let elem = document.getElementById(elemID) as HTMLDivElement;
    let date: any;
    let value = elem.innerHTML;
    if (value) {
      let nowDate = moment().format("YYYY/MM/DD") + " " + value;
      date = moment(nowDate, "YYYY/MM/DD HH:mm:ss").toDate();
    } else {
      date = new Date();
    }
    this.datePicker
      .show({
        date: date,
        is24Hour: true,
        mode: "time"
      })
      .then(
        date => {
          let dateString: string = moment(date).format("HH:mm:ss");
          //remove seconds if the maximum size is 5
          if (maxSize == 5) {
            elem.innerHTML = dateString.substring(0, 5);
            elem.dataset.dtvalue = dateString.substring(0, 5);
          } else {
            elem.innerHTML = dateString;
            elem.dataset.dtvalue = dateString;
          }
        },
        err => console.log("Error occurred while getting date: ", err)
      );
  }
  getDependenciesParams(parentsList) {
    let parentArr: any = [];
    for (let i = 0; i < parentsList.length; i++) {
      for (let j = 0; j < this.absenceDffresponse.length; j++) {
        if (this.absenceDffresponse[j].SEGMENT_NAME == parentsList[i].Name) {
          if (this.absenceDffresponse[j].DISPLAY_FLAG != "N") {
            if (this.absenceDffresponse[j].VALIDATION_TYPE == "N") {
              let idColName: string;
              let val: any;
              if (
                this.absenceDffresponse[j].FORMAT_TYPE == "Y" ||
                this.absenceDffresponse[j].FORMAT_TYPE == "I"
              ) {
                //standard date time or //time
                let elem = document.getElementById(
                  this.absenceDffresponse[j].APPLICATION_COLUMN_NAME
                ) as HTMLDivElement;
                val = elem.dataset.dtvalue;
                if (
                  (val == undefined || val == "") &&
                  parentsList[i].IsRequired == "REQUIRED"
                ) {
                  //alert(parentsList[i].Name +" Is required");
                  return false;
                }
                idColName = val;
                if (this.absenceDffresponse[j].FORMAT_TYPE == "Y")
                  idColName = this.common.formatStandardDate(val);
              } else {
                val = (document.getElementById(
                  this.absenceDffresponse[j].APPLICATION_COLUMN_NAME
                ) as HTMLInputElement).value;
                if (
                  (val == undefined || val == "") &&
                  parentsList[i].IsRequired == "REQUIRED"
                ) {
                  //alert(parentsList[i].Name +" Is required");
                  return false;
                }
                idColName = val;
                if (this.absenceDffresponse[j].FORMAT_TYPE == "X") {
                  //date
                  idColName = this.common.formatDate(val);
                }
              }
              parentArr.push({
                SEGMENT_NAME: this.absenceDffresponse[j].SEGMENT_NAME,
                VALUE_COLUMN_NAME: val,
                DESCRIPTION: "",
                ID_COLUMN_NAME: idColName,
                FLEX_VALUE_SET_NAME: this.absenceDffresponse[j]
                  .FLEX_VALUE_SET_NAME
              });
              break;
            } else {
              if (this.absenceDffresponse[j].READ_ONLY != "Y") {
                let x = document.getElementById(
                  this.absenceDffresponse[j].APPLICATION_COLUMN_NAME
                ) as HTMLSelectElement;
                let text = x.options[x.selectedIndex]
                  ? x.options[x.selectedIndex].text
                  : "";
                let val = x.options[x.selectedIndex]
                  ? x.options[x.selectedIndex].value
                  : undefined;
                if (
                  (val == undefined || val == "") &&
                  parentsList[i].IsRequired == "REQUIRED"
                ) {
                  //alert(parentsList[i].Name +" Is required");
                  return false;
                } else {
                }
                if (text == undefined) {
                  text = "";
                }
                parentArr.push({
                  SEGMENT_NAME: this.absenceDffresponse[j].SEGMENT_NAME,
                  VALUE_COLUMN_NAME: text,
                  DESCRIPTION: "",
                  ID_COLUMN_NAME: val,
                  FLEX_VALUE_SET_NAME: this.absenceDffresponse[j]
                    .FLEX_VALUE_SET_NAME
                });
                break;
              } else {
                let x = document.getElementById(
                  this.absenceDffresponse[j].APPLICATION_COLUMN_NAME
                ) as HTMLInputElement;
                let text = x.value;
                let val = x.dataset.colmText;
                if (
                  (val == undefined || val == "") &&
                  parentsList[i].IsRequired == "REQUIRED"
                ) {
                  // alert(parentsList[i].Name +" Is required");
                  return false;
                } else {
                }
                if (text == undefined) {
                  text = "";
                }
                parentArr.push({
                  SEGMENT_NAME: this.absenceDffresponse[j].SEGMENT_NAME,
                  VALUE_COLUMN_NAME: text,
                  DESCRIPTION: "",
                  ID_COLUMN_NAME: val,
                  FLEX_VALUE_SET_NAME: this.absenceDffresponse[j]
                    .FLEX_VALUE_SET_NAME
                });
                break;
              }
            }
          } else {
            let x = document.getElementById(
              this.absenceDffresponse[j].APPLICATION_COLUMN_NAME
            ) as HTMLInputElement;
            let text = x.value;
            let val = x.dataset.colmText;
            if (
              (val == undefined || val == "") &&
              parentsList[i].IsRequired == "REQUIRED"
            ) {
              //alert(parentsList[i].Name +" Is required");
              return false;
            } else {
            }
            if (text == undefined) {
              text = "";
            }
            parentArr.push({
              SEGMENT_NAME: this.absenceDffresponse[j].SEGMENT_NAME,
              VALUE_COLUMN_NAME: text,
              DESCRIPTION: "",
              ID_COLUMN_NAME: val,
              FLEX_VALUE_SET_NAME: this.absenceDffresponse[j]
                .FLEX_VALUE_SET_NAME
            });
            break;
          }
        }
      }
    }
    return parentArr;
  }
  emptyChildElement(segmentName) {
    let elem = this.getElementByName(segmentName);
    elem.value = null;
    elem.innerHTML = "";
    if ("dtvalue" in elem.dataset) {
      elem.dataset.dtvalue = "";
    }
    if ("colmText" in elem.dataset) {
      elem.dataset.colmText = "";
    }
    var event = new Event("change");
    elem.dispatchEvent(event);
    elem.classList.remove("requiredClassElm");
  }
  fillDropdownList(segmentName, optionList: any = [], DV: any = "") {
    let elemID: any = "";
    let absenceObj: any;
    if (optionList.length > 0) {
      for (let i = 0; i < this.absenceDffresponse.length; i++) {
        if (this.absenceDffresponse[i].SEGMENT_NAME == segmentName) {
          if (
            this.absenceDffresponse[i].READ_ONLY == "Y" ||
            this.absenceDffresponse[i].DISPLAY_FLAG == "N"
          ) {
            return false;
          }
          elemID = this.absenceDffresponse[i].APPLICATION_COLUMN_NAME;
          absenceObj = this.absenceDffresponse[i];
          break;
        }
      }
      let select = document.getElementById(elemID) as HTMLSelectElement;
      document.getElementById(elemID).innerHTML = "";

      // for(let i = select.options.length - 1 ; i >= 0 ; i--)
      // {
      //   select.remove(i);
      // }
      if (absenceObj.IsEmptyOption && absenceObj.REQUIRED_FLAG == "N") {
        var firstoption = document.createElement("option");
        //firstoption.text = this.translate.translate("general.choose");
        firstoption.value = "";
        select.add(firstoption);
      }
      for (let i = 0; i < optionList.length; i++) {
        var option = document.createElement("option");
        option.text = optionList[i].VALUE_COLUMN_NAME;
        option.value = optionList[i].ID_COLUMN_NAME;
        select.add(option);
      }
      if (select.dataset.hiddenval) select.value = select.dataset.hiddenval;
      else select.value = DV.P_VALUE_COLUMN_NAME;
      select.disabled = false;
    }
  }

  public getDefaultValue(
    obj,
    descFlexName,
    descFlexContextCode,
    segmentName,
    parentValue,
    ParentsList
  ) {
    let dependenciesList: any = [];
    let parentVal: any = null;
    let isStandardDate: boolean = false;
    let isStandardTimeDate: boolean = false;
    let isStandardTime: boolean = false;
    let isHidden: boolean = false;
    let isReadOnlyList: boolean = false;
    isStandardDate = this.isStandardDate(obj);
    isStandardTimeDate = this.isStandardDateTime(obj);
    isStandardTime = this.isStandardTime(obj);
    if (obj.DISPLAY_FLAG == "N") isHidden = true;
    if (obj.VALIDATION_TYPE != "N" && obj.READ_ONLY == "Y") {
      isReadOnlyList = true;
    }
    //if(parentValue!=""){ parentVal= this.getDependenciesParams(parentValue)[0].ID_COLUMN_NAME;}
    //if(ParentsList!=""){dependenciesList =this.getDependenciesParams(ParentsList); }

    if (
      parentValue != "" &&
      (obj.VALIDATION_TYPE == "D" || obj.VALIDATION_TYPE == "Y")
    ) {
      let parvalue = this.getDependenciesParams(parentValue);
      if (parvalue && parvalue[0]) parentVal = parvalue[0].ID_COLUMN_NAME;
      else {
        parentVal = null;
      }
      if (!parentVal) {
        return false;
      }
    }
    if (ParentsList != "") {
      if (parentValue) ParentsList.concat(parentValue);
      dependenciesList = this.getDependenciesParams(ParentsList);
      if (!dependenciesList) {
        return false;
      }
    }

    //if (dependenciesList==false){return false};
    const body = {
      P_SELECTED_EMPLOYEE_NUMBER: this.selEmp,
      P_MENU_TYPE: this.menuType,
      P_SELECTED_RESP_ID: this.respID, //-999,
      P_DESC_FLEX_NAME: descFlexName,
      P_DESC_FLEX_CONTEXT_CODE: descFlexContextCode,
      P_SEGMENT_NAME: segmentName,
      P_PARENT_VALUE: parentVal,
      GetValueSetValuesTBL: dependenciesList
    };

    this.submitAbsService.getDefaultValue(body).subscribe((result: any) => {
      let elem = this.getElementByName(segmentName);
      let obj = this.handleDefaultValueResult(result);
      let val = obj.value;
      let text = obj.text;
      if (isStandardDate) {
        // elem.value = this.common.reverseFormatDate(val);
      } else if (isStandardTimeDate) {
        if (val) {
          //   elem.dataset.dtvalue = this.common.reverseFormatStandardDate(val);
          //  elem.innerHTML = this.common.reverseFormatStandardDate(val);
        } else {
          elem.dataset.dtvalue = "";
          elem.innerHTML = "";
        }
      } else if (isStandardTime) {
        if (val) {
          elem.dataset.dtvalue = val;
          elem.innerHTML = val;
        } else {
          elem.dataset.dtvalue = "";
          elem.innerHTML = "";
        }
      } else {
        elem.value = val;
      }
      if (isHidden || isReadOnlyList) {
        if (val) elem.dataset.colmText = val;
        else elem.dataset.colmText = "";
        elem.value = text;
      }
      var event = new Event("change");
      elem.dispatchEvent(event);
    });
  }
  handleDefaultValueResult(result) {
    let data = {
      text: result.GetDefaultValueList.P_VALUE_COLUMN_NAME,
      value: result.GetDefaultValueList.P_ID_COLUMN_NAME
    };
    return data;
  }

  // getElementsValues(){
  //   let valuseArr:any=[];
  //   for(let i=0;i<this.absenceDffresponse.length;i++){
  //     let elemVal=(document.getElementById(this.absenceDffresponse[i].APPLICATION_COLUMN_NAME ) as  HTMLInputElement ).value;
  //     valuseArr.push({ID:this.absenceDffresponse[i].APPLICATION_COLUMN_NAME,VAl:elemVal})
  //   }

  //}

  getRequiredFilds() {
    for (let i = 0; i < this.absenceDffresponse.length; i++) {
      if (this.absenceDffresponse[i].REQUIRED_FLAG == "Y") {
        let elemVal = (document.getElementById(
          this.absenceDffresponse[i].APPLICATION_COLUMN_NAME
        ) as HTMLInputElement).value;
        if (elemVal == "") {
          //alert(this.absenceDffresponse[i].SEGMENT_NAME+" is required");
          break;
        }
      }
    }
  }

  getElementByName(segmentName) {
    let elemID: any = "";
    for (let i = 0; i < this.absenceDffresponse.length; i++) {
      if (this.absenceDffresponse[i].SEGMENT_NAME == segmentName) {
        elemID = this.absenceDffresponse[i].APPLICATION_COLUMN_NAME;
        break;
      }
    }
    return document.getElementById(elemID) as HTMLInputElement;
  }
  getElementsValues() {
    //this.updatedValues=[];//fill updated list
    let valuseArr: any = [];
    let varcharValue: any = null;
    let numbervalue: any = 0;
    let dateValue: any = null;
    let textValue = "";
    let key: string = "";
    let obj: any = {};
    for (let i = 0; i < this.absenceDffresponse.length; i++) {
      varcharValue = null;
      numbervalue = null;
      dateValue = null;
      if (this.absenceDffresponse[i].DISPLAY_FLAG != "N") {
        if (this.absenceDffresponse[i].VALIDATION_TYPE == "N") {
          let elem = document.getElementById(
            this.absenceDffresponse[i].APPLICATION_COLUMN_NAME
          ) as HTMLInputElement;
          let elemVal="";
          if (elem.classList.contains('onic-date')) {
             elemVal = (document.getElementById(
              this.absenceDffresponse[i].APPLICATION_COLUMN_NAME
            ) as HTMLInputElement).value;
            if(elemVal){
              elemVal = moment(elemVal).format("YYYY/MM/DD hh:mm:ss");
            }
           
        }else{
           elemVal = (document.getElementById(
            this.absenceDffresponse[i].APPLICATION_COLUMN_NAME
          ) as HTMLInputElement).value;
        }
          textValue = elemVal;

          if (
            this.absenceDffresponse[i].FORMAT_TYPE == "X" &&
            this.absenceDffresponse[i].DISPLAY_FLAG != "N"
          ) {
            //date
            //   elemVal = this.common.formatDate(elemVal);
          } else if (
            this.absenceDffresponse[i].FORMAT_TYPE == "Y" &&
            this.absenceDffresponse[i].DISPLAY_FLAG != "N"
          ) {
            //standard date time
            elemVal = elem.dataset.dtvalue;
            //   elemVal = this.common.formatStandardDate(elemVal);
          } else if (
            this.absenceDffresponse[i].FORMAT_TYPE == "I" &&
            this.absenceDffresponse[i].DISPLAY_FLAG != "N"
          ) {
            //time
            elemVal = elem.dataset.dtvalue;
          }
          if (this.absenceDffresponse[i].REQUIRED_FLAG == "Y" && !elemVal) {
            elem.classList.add("requiredClassElm");
            return false;
          } else {
            elem.classList.remove("requiredClassElm");
          }
          if (elemVal) varcharValue = elemVal;
          key = "P_" + this.absenceDffresponse[i].APPLICATION_COLUMN_NAME;
          // obj = {};
          obj[key] = varcharValue;
        } else {
          let x = document.getElementById(
            this.absenceDffresponse[i].APPLICATION_COLUMN_NAME
          ) as HTMLSelectElement;
          if (this.absenceDffresponse[i].READ_ONLY == "Y") {
            let text = x.value;
            let val = x.dataset.colmText;
            varcharValue = val;
            textValue = text;
          } else {
            let val = x.options[x.selectedIndex]
              ? x.options[x.selectedIndex].value
              : null;
            let txt = x.options[x.selectedIndex]
              ? x.options[x.selectedIndex].text
              : null;
            varcharValue = val;
            textValue = txt;
          }
          if (
            this.absenceDffresponse[i].REQUIRED_FLAG == "Y" &&
            !varcharValue
          ) {
            x.classList.add("requiredClassElm");
            // this.common.showRequiredMsg();
            return false;
          } else {
            x.classList.remove("requiredClassElm");
          }

          key = "P_" + this.absenceDffresponse[i].APPLICATION_COLUMN_NAME;
          //obj = {};
          obj[key] = varcharValue;
        } //end else
      } else {
        let x = document.getElementById(
          this.absenceDffresponse[i].APPLICATION_COLUMN_NAME
        ) as HTMLSelectElement;
        let val = x.dataset.colmText;
        textValue = x.value;
        if (this.absenceDffresponse[i].REQUIRED_FLAG == "Y" && !varcharValue) {
          x.classList.add("requiredClassElm");
          // this.common.showRequiredMsg();
          return false;
        } else {
          x.classList.remove("requiredClassElm");
        }
        if (val) varcharValue = val;
        key = "P_" + this.absenceDffresponse[i].APPLICATION_COLUMN_NAME;
        //obj = {};
        obj[key] = varcharValue;
      }
    } // end for

    valuseArr.push(obj);
    return valuseArr;
  }
  fillStaticStructure() {
    for (let i = 0; i < this.submitAbsObjList.length; i++) {
      let val: any;
      if (this.submitAbsObjList[i].DATATYPE == "VARCHAR2")
        val = this.submitAbsObjList[i].VARCHAR2_VALUE;
      else if (this.submitAbsObjList[i].DATATYPE == "DATE")
        val = this.submitAbsObjList[i].DATE_VALUE;
      else if (this.submitAbsObjList[i].DATATYPE == "NUMBER")
        val = this.submitAbsObjList[i].NUMBER_VALUE;
      this.action = this.submitAbsObjList[i].ACTION;
      if (this.submitAbsObjList[i].SEGMENT_NAME == "ABSENCE_TYPE") {
        this.absenceType = val;
      }
      if (this.submitAbsObjList[i].SEGMENT_NAME == "DESC_FLEX_CONTEXT_CODE") {
        this.absenceTypeName = val;
      } else if (this.submitAbsObjList[i].SEGMENT_NAME == "START_DATE") {
        this.startDate = moment(val).format("YYYY-MM-DD");
      } else if (this.submitAbsObjList[i].SEGMENT_NAME == "END_DATE") {
        this.endDate = moment(val).format("YYYY-MM-DD");
      } else if (this.submitAbsObjList[i].SEGMENT_NAME == "ABSENCE_DAYS") {
        this.totalDays = val;
      } else if (this.submitAbsObjList[i].SEGMENT_NAME == "TIME_START") {
        this.startTime = val;
      } else if (this.submitAbsObjList[i].SEGMENT_NAME == "TIME_END") {
        this.endTime = val;
      } else if (this.submitAbsObjList[i].SEGMENT_NAME == "REPLACED_BY") {
        this.employeeID = val;
        this.employeeName = this.submitAbsObjList[i].SEGMENT_VALUE_DSP;
        this.employeeSel = this.employeeName + "," + this.employeeID;
      } else if (this.submitAbsObjList[i].SEGMENT_NAME == "COMMENTS") {
        this.absComments = val;
      }
    }

    this.onTypeAbsenceChange();
  }
  fillAbsStructure() {
    for (let i = 0; i < this.submitAbsObjList.length; i++) {
      let val: any;
      if (this.submitAbsObjList[i].VARCHAR2_VALUE)
        val = this.submitAbsObjList[i].VARCHAR2_VALUE;
      else if (this.submitAbsObjList[i].DATE_VALUE)
        val = this.submitAbsObjList[i].DATE_VALUE;
      else if (this.submitAbsObjList[i].NUMBER_VALUE)
        val = this.submitAbsObjList[i].NUMBER_VALUE;
      const elem = document.getElementById(
        this.submitAbsObjList[i].APPLICATION_COLUMN_NAME
      ) as HTMLInputElement;
      //obj.transactionNo=this.submitAbsObjList[i].TRANSACTION_NUMBER;
      if (elem) {
        if (val) {
          let feldDetails = this.absenceDffresponse.find(
            x =>
              x.APPLICATION_COLUMN_NAME ==
              this.submitAbsObjList[i].APPLICATION_COLUMN_NAME
          );
          if (feldDetails) {
            let isStandardDate = this.isStandardDateVal(feldDetails);
            let isStandardDateTime = this.isStandardDateTimeVal(feldDetails);
            let isStandardTime = this.isStandardTimeVal(feldDetails);
            if (isStandardDate) {
              //elem.value = this.common.reverseFormatDate(val);
            } else if (isStandardDateTime) {
              //  elem.innerHTML = this.common.reverseFormatStandardDate(val);
              //  elem.dataset.dtvalue = this.common.reverseFormatStandardDate(val);
            } else if (isStandardTime) {
              elem.innerHTML = val;
              elem.dataset.dtvalue = val;
            } else {
              elem.value = val;
              elem.setAttribute("value", elem.value);
            }
            if (
              feldDetails.DISPLAY_FLAG == "N" ||
              (feldDetails.VALIDATION_TYPE != "N" &&
                feldDetails.READ_ONLY == "Y")
            ) {
              elem.dataset.colmText = val;
              elem.value = this.submitAbsObjList[i].SEGMENT_VALUE_DSP;
              elem.setAttribute("value", elem.value);
            }
          }
          elem.dataset.hiddenval = val; //hide the value to set it after calling get value set
          if (
            feldDetails.CHILD_SEGMENTS_VS_Splited &&
            feldDetails.CHILD_SEGMENTS_VS_Splited.length > 0
          ) {
            let listArray: any = feldDetails.CHILD_SEGMENTS_VS_Splited;
            listArray.forEach(element => {
              this.getValueSet(element);
            });
          }
          //var event = new Event('change');
          //elem.dispatchEvent(event);
        }
      } else {
      }
    }
    //this.ExtraObj=obj;
  }
  isStandardDate(obj: any): boolean {
    let isSt: boolean = false;
    if (obj.FORMAT_TYPE == "X") {
      // standard date
      if (
        obj.DEFAULT_TYPE == "C" ||
        obj.DEFAULT_TYPE == "D" ||
        obj.DEFAULT_TYPE == "P" ||
        obj.DEFAULT_TYPE == "S"
      ) {
        //constant
        isSt = true;
      }
    }
    return isSt;
  }
  isStandardDateTime(obj: any): boolean {
    let isSt: boolean = false;
    if (obj.FORMAT_TYPE == "Y") {
      // standard date time
      if (
        obj.DEFAULT_TYPE == "C" ||
        obj.DEFAULT_TYPE == "D" ||
        obj.DEFAULT_TYPE == "P" ||
        obj.DEFAULT_TYPE == "S"
      ) {
        //constant
        isSt = true;
      }
    }
    return isSt;
  }
  isStandardTime(obj: any): boolean {
    let isSt: boolean = false;
    if (obj.FORMAT_TYPE == "I") {
      // standard date time
      if (
        obj.DEFAULT_TYPE == "C" ||
        obj.DEFAULT_TYPE == "D" ||
        obj.DEFAULT_TYPE == "P" ||
        obj.DEFAULT_TYPE == "S"
      ) {
        //constant
        isSt = true;
      }
    }
    return isSt;
  }

  isStandardDateVal(obj: any): boolean {
    let isSt: boolean = false;
    if (obj.FORMAT_TYPE == "X") {
      // standard date

      isSt = true;
      // }
    }
    return isSt;
  }
  isStandardDateTimeVal(obj: any): boolean {
    let isSt: boolean = false;
    if (obj.FORMAT_TYPE == "Y") {
      // standard date time

      isSt = true;
      //}
    }
    return isSt;
  }
  isStandardTimeVal(obj: any): boolean {
    let isSt: boolean = false;
    if (obj.FORMAT_TYPE == "I") {
      // standard  time

      isSt = true;
      //}
    }
    return isSt;
  }
  validateAbcenseTransaction() {
    (this.elementRef.nativeElement.querySelectorAll(
      "ion-item"
    ) as HTMLElement[]).forEach(x => {
      x.classList.add("ng-touched");
      x.classList.remove("ng-untouched");
    });

    let arrValues = this.getElementsValues();

    if (arrValues) {
      if (!this.startDate || !this.endDate || !this.absenceType) {
        //this.common.showRequiredMsg();
        return false;
      }
      let Sdata = moment(this.startDate).format("MM/DD/YYYY");
      let Edata = moment(this.endDate).format("MM/DD/YYYY");
      this.absenceRrequest = new AbsenceTransaction();
      this.absenceRrequest.P_SELECTED_EMPLOYEE_NUMBER = this.selEmp;
      this.absenceRrequest.P_MENU_TYPE = this.menuType;
      this.absenceRrequest.P_SELECTED_RESP_ID = this.respID;
      this.absenceRrequest.P_FUNCTION_NAME = this.functionName;
      this.absenceRrequest.P_ABSENCE_ACTION = this.action;
      this.absenceRrequest.P_ABSENCE_ATTENDANCE_ID = parseInt(this.absenceType); // later on when we activate the update and delete;
      this.absenceRrequest.P_ABSENCE_ATTENDANCE_TYPE_ID = parseInt(
        this.absenceType
      );
      this.absenceRrequest.P_DATE_START = Sdata;
      this.absenceRrequest.P_DATE_END = Edata;
      this.absenceRrequest.P_TIME_START = this.startTime;
      this.absenceRrequest.P_TIME_END = this.endTime;
      this.absenceRrequest.P_REPLACEMENT_USER_NAME = this.employeeID;
      this.absenceRrequest.P_DESC_FLEX_CONTEXT_CODE = this.absenceTypeName;
      this.absenceRrequest.P_ATTRIBUTE1 = arrValues[0].P_ATTRIBUTE1
        ? arrValues[0].P_ATTRIBUTE1
        : null;
      this.absenceRrequest.P_ATTRIBUTE2 = arrValues[0].P_ATTRIBUTE2
        ? arrValues[0].P_ATTRIBUTE2
        : null;
      this.absenceRrequest.P_ATTRIBUTE3 = arrValues[0].P_ATTRIBUTE3
        ? arrValues[0].P_ATTRIBUTE3
        : null;
      this.absenceRrequest.P_ATTRIBUTE4 = arrValues[0].P_ATTRIBUTE4
        ? arrValues[0].P_ATTRIBUTE4
        : null;
      this.absenceRrequest.P_ATTRIBUTE5 = arrValues[0].P_ATTRIBUTE5
        ? arrValues[0].P_ATTRIBUTE5
        : null;
      this.absenceRrequest.P_ATTRIBUTE6 = arrValues[0].P_ATTRIBUTE6
        ? arrValues[0].P_ATTRIBUTE6
        : null;
      this.absenceRrequest.P_ATTRIBUTE7 = arrValues[0].P_ATTRIBUTE7
        ? arrValues[0].P_ATTRIBUTE7
        : null;
      this.absenceRrequest.P_ATTRIBUTE8 = arrValues[0].P_ATTRIBUTE8
        ? arrValues[0].P_ATTRIBUTE8
        : null;
      this.absenceRrequest.P_ATTRIBUTE9 = arrValues[0].P_ATTRIBUTE9
        ? arrValues[0].P_ATTRIBUTE9
        : null;
      this.absenceRrequest.P_ATTRIBUTE10 = arrValues[0].P_ATTRIBUTE10
        ? arrValues[0].P_ATTRIBUTE10
        : null;
      this.absenceRrequest.P_ATTRIBUTE11 = arrValues[0].P_ATTRIBUTE11
        ? arrValues[0].P_ATTRIBUTE11
        : null;
      this.absenceRrequest.P_ATTRIBUTE12 = arrValues[0].P_ATTRIBUTE12
        ? arrValues[0].P_ATTRIBUTE12
        : null;
      this.absenceRrequest.P_ATTRIBUTE13 = arrValues[0].P_ATTRIBUTE13
        ? arrValues[0].P_ATTRIBUTE13
        : null;
      this.absenceRrequest.P_ATTRIBUTE14 = arrValues[0].P_ATTRIBUTE14
        ? arrValues[0].P_ATTRIBUTE14
        : null;
      this.absenceRrequest.P_ATTRIBUTE15 = arrValues[0].P_ATTRIBUTE15
        ? arrValues[0].P_ATTRIBUTE15
        : null;
      this.absenceRrequest.P_ATTRIBUTE16 = arrValues[0].P_ATTRIBUTE16
        ? arrValues[0].P_ATTRIBUTE16
        : null;
      this.absenceRrequest.P_ATTRIBUTE17 = arrValues[0].P_ATTRIBUTE17
        ? arrValues[0].P_ATTRIBUTE17
        : null;
      this.absenceRrequest.P_ATTRIBUTE18 = arrValues[0].P_ATTRIBUTE18
        ? arrValues[0].P_ATTRIBUTE18
        : null;
      this.absenceRrequest.P_ATTRIBUTE19 = arrValues[0].P_ATTRIBUTE19
        ? arrValues[0].P_ATTRIBUTE19
        : null;
      this.absenceRrequest.P_ATTRIBUTE20 = arrValues[0].P_ATTRIBUTE20
        ? arrValues[0].P_ATTRIBUTE20
        : null;
      this.absenceRrequest.P_ABSENCE_COMMENTS = this.absComments;
      this.submitAbsService
        .validateAbsenceTransaction(this.absenceRrequest)
        .subscribe((result: any) => {
          this.handleAbsenceValidateTr(result);
        });
    }
  }
  private handleAbsenceValidateTr(result) {
    if (this.common.validResponse(result)) {
      if (this.getPassdirfromNotifiPage) {
        this.absenceRrequest.P_NOTIFICATION_ID = this.notificationId;
        this.absenceRrequest.P_ITEM_KEY = this.itemKey;
        this.submitAbsService
          .resubmitAbsence(this.absenceRrequest)
          .subscribe((result: any) => {
            this.handleSubmitAbsence(result);
          });
      } else {
        this.submitAbsService
          .submitAbsence(this.absenceRrequest)
          .subscribe((result: any) => {
            this.handleSubmitAbsence(result);
          });
      }
    }
  }

  private handleSubmitAbsence(result) {
    if (this.common.validResponse(result)) {
      if (this.getPassdirfromNotifiPage) {
         this.common.sharedService.setSharedData(result.ResubmitAbsenceTransactionList.P_TRANSACTION_ID, AbsenceResponse.SHARED_DATA);
          this.common.openConfirmAbsece();
         //  this.navCtrl.push("SubmitAbsenceConfirmPage", { isResubmit: true });
      } else {
        this.common.sharedService.setSharedData(result.SumbitAbsenceTransactionList.P_TRANSACTION_ID, AbsenceResponse.SHARED_DATA);
        this.common.openConfirmAbsece();
        // this.navCtrl.push("SubmitAbsenceConfirmPage", { isResubmit: false });
      }
    }
  }
}
