0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 3.135.209.231


Current Path : /proc/thread-self/root/var/www/oasis/custom_js/
Upload File :
Current File : //proc/thread-self/root/var/www/oasis/custom_js/report_setup.js

function CallReportSetup() {
  $geditinternalcode = 0;
  window.enable_proper_module = "CallReportSetup";
  $schema_id = "";
  $("#page_main_div").load(
    "../html_modules/pay_report_setup.html",
    function () {
      document.getElementById("display_module_name").innerHTML = "Report Setup";
      document.getElementById("module_name_for_save").value = "reportsetup";
      $greport_setup_emp_names_arr = "";
      getenableCriteriaFromDb("");
      getReportEmpDetailsCriteria("");
      getenableEmpFieldsFromDb(0);
      getenableSalFieldsFromDb(0);
      getReportEnableSummaryFields(0);
      enableConditions();
      getReportEnableConditions();
      getDefaultHeadFooterLinks("Report Setup");
    }
  );
}

function getenableCriteriaFromDb($value) {
  $.ajax({
    type: "POST",
    async: false,
    url: $host_url + "getReportEnableCriteria",
    data: "value=" + $value,
    success: ReportEnableCriteriaSuccess,
  });
}
function ReportEnableCriteriaSuccess($responce) {
  $responce = eval("(" + $responce + ")");
  // document.getElementById('report_setup_crieteria_data_div').innerHTML="";
  document.getElementById("report_setup_crieteria_data_div").innerHTML =
    $responce.data.criteria_html;
  $("#report_setup_crieteria_data_div").show();
  $g_report_crieteria_field_data = $responce.data.criteria_table_data;
}

function getReportEmpDetailsCriteria($value) {
  $.ajax({
    type: "POST",
    async: false,
    url: $host_url + "getReportEmpDetailsCriteria",
    data: "value=" + $value,
    success: ReportEmpDetailsCriteriaSuccess,
  });
}

function ReportEmpDetailsCriteriaSuccess($responce) {
  $responce = eval("(" + $responce + ")");
  $greport_setup_emp_names_arr = "";
  // document.getElementById('report_setup_emp_data_div').innerHTML="";
  document.getElementById("report_setup_emp_data_div").innerHTML =
    $responce.data.emp_html;
  $("#report_setup_emp_data_div").show();
  $greport_setup_emp_names_arr = $responce.data.emp_table_data;
}

function getenableEmpFieldsFromDb($int_code) {
  $.ajax({
    type: "POST",
    async: false,
    url: $host_url + "getReportEnableEmployeeFields",
    data: "internal_code=" + $int_code,
    success: enableEmpFieldsSuccess,
  });
}
function enableEmpFieldsSuccess($responce) {
  $responce = eval("(" + $responce + ")");
  document.getElementById("report_setup_emp_fields").innerHTML =
    $responce.data.html;
  $("#report_setup_emp_fields").show();
  $g_report_emp_field_data = $responce.data.table_data;
}

function getenableSalFieldsFromDb($int_code) {
  $.ajax({
    type: "POST",
    async: false,
    url: $host_url + "getReportEnableSalFields",
    data: "internal_code=" + $int_code,
    success: enableSalFieldsSuccess,
  });
}
function enableSalFieldsSuccess($responce) {
  $responce = eval("(" + $responce + ")");
  document.getElementById("report_setup_sal_fields").innerHTML =
    $responce.data.html;
  $("#report_setup_sal_fields").show();
  $g_report_sal_field_data = $responce.data.table_data;
}
function getReportEnableSummaryFields($int_code) {
  $.ajax({
    type: "POST",
    async: false,
    url: $host_url + "getReportEnableSummaryFields",
    data: "internal_code=" + $int_code,
    success: enableSummaryFieldsSuccess,
  });
}
function enableSummaryFieldsSuccess($responce) {
  $responce = eval("(" + $responce + ")");
  document.getElementById("report_setup_summary_fields").innerHTML =
    $responce.data.html;
  $("#report_setup_summary_fields").show();
  $g_report_summary_field_data = $responce.data.table_data;
}

function SaveReportSetupDetails() {
  if (trim($("#report_setup_report_name").val()) == "") {
    alert("Please Enter the Report Name");
    $("#report_setup_report_name").focus();
    return;
  }
  $report_setup_cross_tab =
    document.getElementById("report_setup_cross_tab").checked == true ? 1 : 0;
  $report_setup_col_total =
    document.getElementById("report_setup_col_total").checked == true ? 1 : 0;
  $report_setup_row_total =
    document.getElementById("report_setup_row_total").checked == true ? 1 : 0;
  if (document.getElementById("report_setup_sub_total").checked == true) {
    $report_setup_sub_total = 1;
    $report_setup_sub_field = trim($("#report_setup_sub_total_text").val());
    if ($report_setup_sub_field == "") {
      alert("Please Enter the Sub Total Field Name as in Employee Master");
      $("#report_setup_sub_total_text").focus();
      return;
    }
  } else {
    $report_setup_sub_total = 0;
    $report_setup_sub_field = "";
  }
  if (document.getElementById("report_setup_sl_no").checked == true) {
    $report_setup_sl_no = 1;
  } else {
    $report_setup_sl_no = 0;
  }

  $lstr_data = "internal_code=" + $geditinternalcode;
  $lstr_data += "&report_name=" + trim($("#report_setup_report_name").val());
  $lstr_data += "&report_freeze_cells=" + trim($("#report_freeze_cells").val());
  $lstr_data +=
    "&from_date=" + date_format($("#report_setup_start_date").val());
  $lstr_data += "&to_date=" + date_format($("#report_setup_end_date").val());
  $lstr_data += "&report_setup_cross_tab=" + $report_setup_cross_tab;
  $lstr_data += "&report_setup_col_total=" + $report_setup_col_total;
  $lstr_data += "&report_setup_row_total=" + $report_setup_row_total;
  $lstr_data += "&report_setup_sub_total=" + $report_setup_sub_total;
  $lstr_data += "&report_setup_sub_field=" + $report_setup_sub_field;
  $lstr_data += "&report_setup_sl_no=" + $report_setup_sl_no;
  $.ajax({
    type: "POST",
    //async:false,
    url: $host_url + "saveSalarySetupReportHeader",
    data: $lstr_data,
    success: saveSalarySetupReportHeaderResponse,
  });
}
function saveSalarySetupReportHeaderResponse($responce) {
  $responce = eval("(" + $responce + ")");
  if ($responce.error_code == 0) {
    $last_insert_id = $responce.data.last_insert_id;

    $report_emp_details = new Object();
    $report_sal_details = new Object();
    $report_summary_details = new Object();
    $report_condition_details = new Object();

    for ($i = 0; $i < $g_report_emp_field_data.length; $i++) {
      $emp_field_id = $g_report_emp_field_data[$i].internal_code;
      $report_emp_details[$i] = new Object();
      $report_emp_details[$i]["emp_field_id"] = $emp_field_id;
      $report_emp_details[$i]["emp_col_seq"] = $(
        "#report_emp_col_seq_" + $emp_field_id
      ).val();

      $report_emp_details[$i]["emp_field_name"] = $(
        "#report_emp_col_name_" + $emp_field_id
      ).html();

      if (
        document.getElementById("report_emp_select_" + $emp_field_id).checked ==
        true
      )
        $report_emp_details[$i]["emp_select"] = "1";
      else $report_emp_details[$i]["emp_select"] = "0";

      if (
        document.getElementById("report_emp_group_by_" + $emp_field_id)
          .checked == true
      )
        $report_emp_details[$i]["emp_group_by"] = "1";
      else $report_emp_details[$i]["emp_group_by"] = "0";

      if (
        document.getElementById("report_emp_order_by_" + $emp_field_id)
          .checked == true
      )
        $report_emp_details[$i]["emp_order_by"] = "1";
      else $report_emp_details[$i]["emp_order_by"] = "0";

      if (
        document.getElementById("report_emp_order_type_asc_" + $emp_field_id)
          .checked == true
      )
        $report_emp_details[$i]["emp_order_type"] = "asc";
      else $report_emp_details[$i]["emp_order_type"] = "desc";

      $report_emp_details[$i]["emp_order_col_seq"] = $(
        "#report_emp_order_seq_" + $emp_field_id
      ).val();
    }

    for ($i = 0; $i < $g_report_sal_field_data.length; $i++) {
      $report_sal_details[$i] = new Object();
      $sal_field_id = $g_report_sal_field_data[$i].internal_code;
      $report_sal_details[$i]["sal_field_id"] = $sal_field_id;
      $report_sal_details[$i]["sal_col_seq"] = $(
        "#report_sal_col_seq_" + $sal_field_id
      ).val();

      $report_sal_details[$i]["sal_field_name"] = $(
        "#report_sal_col_name_" + $sal_field_id
      ).html();

      if (
        document.getElementById("report_sal_select_" + $sal_field_id).checked ==
        true
      )
        $report_sal_details[$i]["sal_select"] = "1";
      else $report_sal_details[$i]["sal_select"] = "0";

      if (
        document.getElementById("report_sal_order_by_" + $sal_field_id)
          .checked == true
      )
        $report_sal_details[$i]["sal_order_by"] = "1";
      else $report_sal_details[$i]["sal_order_by"] = "0";

      if (
        document.getElementById("report_sal_order_type_asc_" + $sal_field_id)
          .checked == true
      )
        $report_sal_details[$i]["sal_order_type"] = "asc";
      else $report_sal_details[$i]["sal_order_type"] = "desc";

      $report_sal_details[$i]["sal_order_col_seq"] = $(
        "#report_sal_order_seq_" + $sal_field_id
      ).val();
      $report_sal_details[$i]["sal_sum_into"] = trim(
        $("#report_sal_sum_into_" + $sal_field_id).val()
      );
    }
    for ($i = 0; $i < $g_report_summary_field_data.length; $i++) {
      $summary_field_id = $g_report_summary_field_data[$i].internal_code;
      $report_summary_details[$i] = new Object();
      $report_summary_details[$i]["summary_field_id"] = $summary_field_id;
      $report_summary_details[$i]["summary_col_seq"] = $(
        "#report_summary_col_seq_" + $summary_field_id
      ).val();

      $report_summary_details[$i]["summary_field_name"] = $(
        "#report_summary_col_name_" + $summary_field_id
      ).html();

      if (
        document.getElementById("report_summary_select_" + $summary_field_id)
          .checked == true
      )
        $report_summary_details[$i]["summary_select"] = "1";
      else $report_summary_details[$i]["summary_select"] = "0";
    }
    var tbl = document.getElementById("mySampleTable");
    // grab how many rows are in the table
    var row_counter = tbl.rows.length - 1;
    $m = 0;
    for ($i = 1; $i <= row_counter; $i++) {
      if (trim($("#txtbox_" + row_counter).val()) != "") {
        $report_condition_details[$m] = new Object();
        $report_condition_details[$m]["ele_id"] = $("#emp_field_" + $i).val();
        $report_condition_details[$m]["operator"] = $("#oper_" + $i).val();
        $report_condition_details[$m]["value"] = trim($("#txtbox_" + $i).val());
        $report_condition_details[$m]["and_or"] = trim(
          $("#and_or_" + $i).val()
        );
        $m++;
      }
    }

    var myJSONEmpText = encodeURIComponent(JSON.stringify($report_emp_details));
    var myJSONSalText = encodeURIComponent(JSON.stringify($report_sal_details));
    var myJSONSummaryText = encodeURIComponent(
      JSON.stringify($report_summary_details)
    );
    var myJSONConditionText = encodeURIComponent(
      JSON.stringify($report_condition_details)
    );
    //console.log(myJSONConditionText);

    $lstr_data_details =
      "report_id=" +
      $last_insert_id +
      "&emp_details=" +
      myJSONEmpText +
      "&sal_details=" +
      myJSONSalText +
      "&summary_details=" +
      myJSONSummaryText +
      "&report_conditions=" +
      myJSONConditionText;
    $.ajax({
      type: "POST",
      //async:false,
      url: $host_url + "saveReportSetupResult",
      data: $lstr_data_details,
      success: saveReportSetupResultresponse,
    });
  } else {
    alert($responce.data);
  }
}
function saveReportSetupResultresponse($responce) {
  $responce = eval("(" + $responce + ")");
  alert($responce.data);
}
function ClearSalaryReport() {
  $("#report_setu_report_name").val("");
  $("#report_setup_start_date").val("");
  $("#report_setup_end_date").val("");
  ReportSetup();
}
function displayReportsSetup() {
  $geditinternalcode = 0;

  $main =
    "<table id='table_grid' class='scroll' ondblclick='getreportsSetupDetails(id);'></table> <div id='sub_grid_div' class='scroll' style='text-align:center;'></div>";
  document.getElementById("page_main_div").innerHTML = $main;
  var report_setup = jQuery("#table_grid")
    .jqGrid({
      url: $host_url + "displayReportsSetup",
      datatype: "json",
      colNames: ["Report Names"],
      colModel: [{ name: "report_name", index: "report_name", width: 115 }],
      rowNum: 10,
      rowList: [5, 10, 15, 20, 25, 30],
      imgpath: $img_path,
      pager: jQuery("#sub_grid_div"),
      sortname: "id",
      height: "70%",
      viewrecords: true,
      sortorder: "desc",
      multiselect: false,
      cellEdit: true,
      width: "850",
      caption: "Module Details",
      editurl: $host_url + "deletereportSetup",
    })
    .navGrid(
      "#sub_grid_div",
      { edit: false, add: false, del: true, search: true },
      {},
      {},
      {},
      { multipleSearch: true }
    )
    .navButtonAdd("#sub_grid_div", {
      caption: "Toggle",
      buttonicon: "ui-icon-pin-s",
      onClickButton: function () {
        report_setup[0].toggleToolbar();
      },
    })
    .navButtonAdd("#sub_grid_div", {
      caption: "Edit",
      onClickButton: function () {
        getreportsSetupDetails(id);
      },
    });
  report_setup.filterToolbar();
}

function getreportsSetupDetails(id) {
  var id = jQuery("#table_grid").getGridParam("selrow");
  if (id > 0) {
    CallReportSetup();
    getenableEmpFieldsFromDb(id);
    getenableSalFieldsFromDb(id);
    getReportEnableSummaryFields(id);
    enableConditions();

    $.ajax({
      type: "POST",
      async: false,
      url: $host_url + "getReportSetupName",
      data: "internal_code=" + id,
      success: getReportSetupNameresponse,
    });
    $geditinternalcode = id;
  } else {
    alert("Please select row");
  }
}

function getReportSetupNameresponse($responce) {
  $responce = eval("(" + $responce + ")");
  $("#report_setup_report_name").val($responce.data.report_name);
  $("#report_setup_start_date").val($responce.data.from_date);
  $("#report_setup_end_date").val($responce.data.to_date);
  $("#report_freeze_cells").val($responce.data.freeze_cells);
  if ($responce.data.is_cross_tab == 1)
    document.getElementById("report_setup_cross_tab").checked = true;

  if ($responce.data.is_col_tot == 1)
    document.getElementById("report_setup_col_total").checked = true;

  if ($responce.data.is_row_total == 1)
    document.getElementById("report_setup_row_total").checked = true;
  if ($responce.data.is_sub_tot == 1) {
    $("#report_setup_sub_total_text").val($responce.data.sub_tot_field);
    document.getElementById("report_setup_sub_total").checked = true;
  } else document.getElementById("report_setup_sub_total").checked = false;
  getReportEnableConditions();

  if ($responce.data.is_sl_no == 1)
    document.getElementById("report_setup_sl_no").checked = true;

  for ($n = 1; $n < $responce.data.conditions.length; $n++) {
    addReportSetupCondtionsRow();
  }
  //alert('aa');
  $i = 1;
  for ($k = 0; $k < $responce.data.conditions.length; $k++) {
    $("#emp_field_" + $i).val($responce.data.conditions[$k]["ref_ele_code"]);
    $("#oper_" + $i).val($responce.data.conditions[$k]["operator"]);
    document.getElementById("txtbox_" + $i).value =
      $responce.data.conditions[$k]["value"];
    $("#and_or_" + $i).val($responce.data.conditions[$k]["and_or"]);
    $i++;
  }
}

/* function assignReportSetupFieldId($field_id)
 {
window.$reportsetupfieldid=$field_id;
 } */
function GenerateFinalReportSetupDetails() {
  $report_id = $geditinternalcode;
  $schema_id = $g_report_crieteria_field_data[0].schema_id;
  $cond = "";
  for ($i = 0; $i < $g_report_crieteria_field_data.length; $i++) {
    $emp_field_id = $g_report_crieteria_field_data[$i].internal_code;
    $emp_field_value = encodeURIComponent(
      trim($("#emp_report_criteria_" + $emp_field_id).val())
    );
    if ($emp_field_value != "") {
      $cond +=
        " and m_" +
        $schema_id +
        "_ele_" +
        $emp_field_id +
        "='" +
        $emp_field_value +
        "'";
    }
  }
  $emp_ids = 0;
  for ($i = 0; $i < $greport_setup_emp_names_arr.length; $i++) {
    $int_code = $greport_setup_emp_names_arr[$i].internal_code;
    if (
      document.getElementById("emp_sal_process_int_code_" + $int_code).checked
    ) {
      $emp_ids += $int_code + ",";
    }
  }

  $data =
    "&emp_ids=" +
    $emp_ids +
    "&schema_id=" +
    $schema_id +
    "&report_id=" +
    $report_id +
    "&cond=" +
    $cond +
    "&from_date=" +
    date_format($("#report_setup_start_date").val()) +
    "&to_date=" +
    date_format($("#report_setup_end_date").val());
  window.open($host_url + "GenerateFinalReportSetupDetails" + $data);
}

function enableConditions() {
  $("#report_setup_condition_fields").show();
}

function getReportEnableConditions() {
  $.ajax({
    type: "POST",
    async: false,
    url: $host_url + "getEmployeeConditionfileds",
    success: populategetEmployeeConditionfileds,
  });
}
function populategetEmployeeConditionfileds($responce) {
  $responce = eval("(" + $responce + ")");
  if ($responce.error_code == "0") {
    $g_emp_cond_fields = $responce.data;
    document.getElementById("emp_field_1").options.length = 0;
    for ($i = 0; $i < $responce.data["fields"].length; $i++) {
      $op = new Option(
        $responce.data["fields"][$i]["ele_name"],
        $responce.data["fields"][$i]["internal_code"]
      );
      $op.id = $responce.data["fields"][$i]["internal_code"]; //specifying the id  for options
      document.getElementById("emp_field_1").options.add($op);
    }

    document.getElementById("oper_1").options.length = 0;

    for ($i = 0; $i < $responce.data["oper"].length; $i++) {
      $op = new Option(
        $responce.data["oper"][$i]["operator"],
        $responce.data["oper"][$i]["operator"]
      );
      $op.id = $responce.data["oper"][$i]["internal_code"]; //specifying the id  for options
      document.getElementById("oper_1").options.add($op);
    }
  }
  // to delete the rows mannually
  var tbl = document.getElementById("mySampleTable");
  var lastRow_full_length = tbl.rows.length;

  for ($i = 0; $i < lastRow_full_length; $i++) {
    var lastRow = tbl.rows.length;
    if (lastRow > 2) tbl.deleteRow(lastRow - 1);
  }
}

function addReportSetupCondtionsRow() {
  // grab the element, i.e. the table your editing, in this we're calling it
  // 'mySampleTable' and it is reffered to in the table further down on the page
  // with a unique of id of you guessed it, 'mySampleTable'
  var tbl = document.getElementById("mySampleTable");
  // grab how many rows are in the table
  var lastRow = tbl.rows.length;

  // if there's no header row in the table (there should be, code at least one
  //manually!), then iteration = lastRow + 1
  var iteration = lastRow;
  var counter = iteration - 1;
  /* if(trim($("#txtbox_"+counter).val())=='')
  {
  alert('Please enter the Value');
  $("#txtbox_"+counter).focus();
  return;
  }   */

  // creates a new row
  var row = tbl.insertRow(lastRow);

  //Field
  var cellLeft = row.insertCell(0);
  var sel = document.createElement("select");
  sel.id = "emp_field_" + iteration;
  for ($i = 0; $i < $g_emp_cond_fields["fields"].length; $i++) {
    sel.options[$i] = new Option(
      $g_emp_cond_fields["fields"][$i]["ele_name"],
      $g_emp_cond_fields["fields"][$i]["internal_code"]
    );
  }
  cellLeft.appendChild(sel);

  document.getElementById("emp_field_" + iteration).style.width = "120px";

  // Operator
  var cellRightSel = row.insertCell(1);
  var sel = document.createElement("select");
  sel.id = "oper_" + iteration;
  for ($i = 0; $i < $g_emp_cond_fields["oper"].length; $i++) {
    sel.options[$i] = new Option(
      $g_emp_cond_fields["oper"][$i]["operator"],
      $g_emp_cond_fields["oper"][$i]["operator"]
    );
  }
  cellRightSel.appendChild(sel);
  document.getElementById("oper_" + iteration).style.width = "70px";

  // TExt Box
  var cellRightSel = row.insertCell(2);
  var el = document.createElement("input");
  el.type = "text";
  el.id = "txtbox_" + iteration;
  cellRightSel.appendChild(el);
  document.getElementById("txtbox_" + iteration).style.width = "165px";

  var cellRightSel = row.insertCell(3);
  var sel = document.createElement("select");
  sel.id = "and_or_" + iteration;
  sel.options[0] = new Option("And", "And");
  sel.options[1] = new Option("Or", "Or");
  cellRightSel.appendChild(sel);
  return;
}

function removeReportSetupCondtionsRow() {
  // grab the element again!
  var tbl = document.getElementById("mySampleTable");
  // grab the length!
  var lastRow = tbl.rows.length;
  // delete the last row if there is more than one row!
  if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}

function selectAllEmpFields() {
  if (document.getElementById("select_emp_fields").checked == true) {
    for ($m = 0; $m < $g_report_emp_field_data.length; $m++) {
      $id = $g_report_emp_field_data[$m].internal_code;
      document.getElementById("report_emp_select_" + $id).checked = true;
    }
  } else {
    for ($m = 0; $m < $g_report_emp_field_data.length; $m++) {
      $id = $g_report_emp_field_data[$m].internal_code;
      document.getElementById("report_emp_select_" + $id).checked = false;
    }
  }
}
function selectAllSalFields() {
  if (document.getElementById("select_sal_fields").checked == true) {
    for ($m = 0; $m < $g_report_sal_field_data.length; $m++) {
      $id = $g_report_sal_field_data[$m].internal_code;
      document.getElementById("report_sal_select_" + $id).checked = true;
    }
  } else {
    for ($m = 0; $m < $g_report_sal_field_data.length; $m++) {
      $id = $g_report_sal_field_data[$m].internal_code;
      document.getElementById("report_sal_select_" + $id).checked = false;
    }
  }
}
function disableReportSetupTextBox() {
  if (document.getElementById("report_setup_sub_total").checked == true)
    document.getElementById("report_setup_sub_total_text").disabled = false;
  else document.getElementById("report_setup_sub_total_text").disabled = true;
}