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 : 18.118.164.100


Current Path : /var/www/html/pgadm/js/admin/
Upload File :
Current File : /var/www/html/pgadm/js/admin/applicationview copy.js

// var $host_url =
//   "http://" +
//   window.location.host +
//   "/" +
//   window.location.pathname.split("/")[1] +
//   "/app.php?a=";

var $host_url1 =
  "http://" +
  window.location.host +
  "/" +
  window.location.pathname.split("/")[1] +
  "/";

var deg;

var gAppNo;

var fappno = "";
var ffappno = "";

var photo_path = "";

var months = "";
function homeLink() {
  var r = confirm("Do You Want To Logout!");
  if (r == true) {
    window.location.href = "index.html";
  } else {
  }
}

// function login1() {
//   $.ajax({
//     type: "POST",
//     async: true,
//     url: "../pgetadm/login.php",
//     success: isLoggedInResponce
//   });
//   function isLoggedInResponce($responce) {
//     $responce = eval("(" + $responce + ")");
//     if ($responce.error_code == 1) {
//       alert("User not logged in");
//       window.location.href = "pgindex.html";
//     }
//   }
// }
var combcode = [];
var combsubject = [];
var optdegarry = [];

function loadApplicationView() {
  $.ajax({
    type: "POST",
    url: $host_url + "loadRange",
    async: false,
    success: function(response) {
      //  console.log(response);
      var { error_code, data, status } = JSON.parse(response);
      // console.log(data);
      if (error_code == "0") {
        $("#loadTab").load("applicationview.html", function() {
          var degers = data;
        });
      } else {
        alert("Please try after some time");
        return;
      }
    }
  });
}
function loadChangea() {
  // console.log('hi')
  var afrom = $("#afrom").val();
  if (afrom == 0) {
    $("#ato").val("ZZZZZZZZZZ");
  } else {
    // console.log(afrom)
    $("#ato").val(afrom);
  }
}

function loadChanged() {
  // console.log('hi')
  var dfrom = $("#dfrom").val();
  if (dfrom == 0) {
    $("#dto").val("ZZZZZ");
  } else {
    // console.log(afrom)
    $("#dto").val(dfrom);
  }
}

function loadAppDetailsView() {
  var dfrom = $("#dfrom").val();
  var dto = $("#dto").val();
  var from = $("#afrom").val();
  var ato = $("#ato").val();

  //   if (dfrom == "0") {
  //     alert("Fill Degree Range");
  //     return;
  //   }
  //    if (dto == "ZZZZ") {
  //     alert("Fill Degree Range");
  //     return;
  //   }
  //  if (afrom == "0") {
  //     alert("Fill Application Range");
  //     return;
  //   }
  //  if (ato == "ZZZZ") {
  //     alert("Fill Application Range");
  //     return;
  //   }
  $("#next").show();
  var datastring =
    "&dfrom=" +
    dfrom +
    "&dto=" +
    dto +
    "&afrom=" +
    afrom +
    "&ato=" +
    ato +
    $.blockUI({ message: "<img src='../img/Loading_icon.gif' border='0'>" });

  $.ajax({
    type: "POST",
    url: $host_url + "loadAppDetails",
    data: datastring,
    success: function(response) {
      $.unblockUI();
      var { error_code, data, status } = JSON.parse(response);
      // console.log(data);
      var app = data;

      var str = `<table class="table table-bordered" style="height: 200px;">
            <thead>
              <tr class="bg-cyan">
                <th style = "text-align: center;">Sl. No.</th>
                <th style = "text-align: center;">Application No.</th>
                <th style = "text-align: center;">Applied Date</th>
                <th style = "text-align: center;">Student Name</th>                                
                <th style = "text-align: center;">Gender</th>
                <th style = "text-align: center;">Caste</th>
                <th style = "text-align: center;">HK / NHK</th>
                <th style = "text-align: center;">Amount</th>
                <th style = "text-align: center;">Action</th>
              </tr>
            </thead>
            <tbody>`;
      for (var i = 0; i < app.length; i++) {
        str += `<tr>
              <td style = 'text-align: center;'>${i + 1}</td>
              <td style = 'text-align: center;'>${app[i]["fappno"]}</td>
              <td style = 'text-align: center;'>${app[i]["fappdate"]}</td>
              <td style = 'text-align: left;'>${
                app[i]["fname"]
              }</td>                            
              <td style = 'text-align: center;'>${app[i]["fgender"]}</td>
              <td style = 'text-align: center;'>${app[i]["fcategory"]}</td>
              <td style = 'text-align: center;'>${app[i]["fhk"]}</td>
              <td style = 'text-align: center;'>${app[i]["ftotfee"]}</td>
              <td style = 'text-align: center;'><button class="btn-info"
              style="padding-right: 8px;padding-left: 8px;padding-top: 2px;padding-bottom: 2px;" 
              onclick="loadPersonalDetails('${app[i]["fappno"]}','${
          app[i]["fname"]
        }')">View</button></td>
            </tr>`;
      }

      $("#appdet").html(str);
    }
  });
}
function studentback() {
  $("#next").show();
  $("#add").show();
  $("#perdetl").hide();
  $("#basicDet").hide();
  $("#prevAcadDetCard").hide();
  $("#optdeg_det").hide();
  $("#upload_doc_det").hide();
  $("#FeeDet").hide();
  $("#perdetl").hide();
}

function loadPersonalDetails(fappno, fname) {
  // login1();
  $("#next").hide();
  $("#add").hide();
  $("#success_card").hide();
  $("#basicDet").show();
  $("#prevAcadDetCard").show();
  $("#optdeg_det").show();
  $("#upload_doc_det").show();
  $("#FeeDet").hide();
  $("#perdetl").show();
  $("#fbcuetype").hide();

  // console.log(fappno,fname);

  var datastring = "&fappno=" + fappno + "&fname=" + fname;

  $.blockUI({ message: "<img src='../img/Loading_icon.gif' border='0'>" });
  $.ajax({
    type: "POST",
    data: datastring,
    url: $host_url + "getFacultyDegreeView",
    success: response => {
      $.unblockUI();
      var { error_code, data, status } = JSON.parse(response);
      // console.log(data);
      if (error_code == 0) {
        var fmobileno = data.fmobileno;
        combcode = data.combcode;
        combsubject = data.combsubs;
        // console.log(combcode,combsubject);
        $("#fmobileno").val(fmobileno);
        $("#fmobileno").prop("disabled", "disabled");
        var options;
        fappno = data.fappno;
        ffappno = data.fappno;
        deg = data.degree;
        options += `<option value="">--Select--</option>`;
        deg.map((el, i) => {
          options += `<option value="${deg[i]["int_code"]}">${
            deg[i]["int_code"]
          } - ${deg[i]["val"]}</options>`;
        });
        $("#fdegree").html(options);
        var options = "";
        lanres = data.lanres;
        options += `<option value="">--Select--</option>`;
        lanres.map((el, i) => {
          options += `<option value="${lanres[i]["int_code"]}">${
            lanres[i]["val"]
          }</options>`;
        });
        $("#flang1").html(options);
        $("#flang2").html(options);

        var year = "";
        var d = new Date();
        var n = d.getFullYear();
        for (var j = n; j > 1980; j--) {
          year += "<option value='" + j + "'>" + j + "</option>";
        }
        $("#fqyear").append(year);
        $("#fpgyear").append(year);

        var monthNames = [
          "January",
          "February",
          "March",
          "April",
          "May",
          "June",
          "July",
          "August",
          "September",
          "October",
          "November",
          "December"
        ];
        var months = monthNames
          .map(month => {
            return "<option>" + month + "</option>";
          })
          .join("");
        $("#fqmonth").html(months);
        $("#fpgmonth").html(months);
        $.ajax({
          type: "GET",
          async: false,
          url: $host_url + "getCategory",
          success: response => {
            var { error_code, data, status } = JSON.parse(response);
            // console.log(data);
            var options;

            if (error_code == 0) {
              cat = data.category;
              options += `<option value="">--Select--</option>`;
              cat.map((el, i) => {
                options += `<option value="${cat[i]["fcategory"]}">${
                  cat[i]["fcategory"]
                }</options>`;
              });
            }

            if (error_code == -1) {
              options += `<option>---Select---</option>
              <option value="">No Category Found</option>`;
            }
            $("#fcategory").html(options);
          }
        });
        // console.log(fappno);
        if (data.fappno != "") loadSavedData(data.fappno);
        loadotdeg(data.fappno);
        // console.log(fappno);
        fappno = "";
        fappno = data.fappno;
        // console.log(fappno);
      }
      if (error_code == -1) {
        alert("Something went wrong, Please Try after sometime.");
      }
    }
  });

  // console.log(statusandremarks);
}

function loadotdeg(fappno) {
  var degcode = $("#fdegree").val();
  // console.log(degcode);
  var combcode = $("#fcombcode").val();
  fappno = fappno;
  $.ajax({
    type: "POST",
    url: $host_url + "loadotdeg",
    data: "fappno=" + fappno + "&degcode=" + degcode + "&combcode=" + combcode,
    success: response => {
      var { error_code, data, status } = JSON.parse(response);
      // console.log(data);
      var { msg } = data;
      if (error_code === -1) {
        swal({
          title: data.msg,
          html: true,
          showCancelButton: false,
          confirmButtonColor: "#5495ff",
          confirmButtonText: "OK",
          closeOnConfirm: false
        });
      } else {
        var optdeg = data.optdeg;
        optdegarry = data.optdeg;
        var optdegtable = `<table class='table table-bordered table-striped table-upd' id="optdet" style="margin: 20px;">
            <thead>
            <tr class="bg-cyan">
            <td style="width :8%">Sl. No.</td>
            <td style="width : 40%;">Degree Name</td>
            <td style="width : 5%;">Select</td>
            </tr>
            </thead>
            <tbody>`;

        var i = 1;

        optdeg.forEach(element => {
          optdegtable += `<tr>
            <td style="text-align: center;">${i}</td>
            <td style="text-align: left;" id="doc_upload_1" >${element.fdescpn}
             <input type = 'hidden' value = '${element.fdegree}' id = 'h_optdeg_${i}' >
            </td>
            <td><input type = 'checkbox' ${element.sddeg} value = '${element.fdegree}' id = 'deg_${i}' name = 'deg_${i}' disabled />
            <label for="deg_${i}" style="font-size:10px !important;"></label>
            </td>`;
          // if(element.sddeg == '0')
          // {
          //   optdegtable += `<td><input type = 'checkbox' ${element.sddeg} value = '${element.fdegree}' id = 'deg_${i}'>
          //   <label for="deg_${i}" style="font-size:10px !important;"></label>
          //   </td>`;
          // }else
          // {
          //   optdegtable += `<td><input type = 'checkbox' value = '${element.fdegree}' checked id = 'deg_${i}'>
          //   <label for="deg_${i}" style="font-size:10px !important;"></label></td>`;
          // }
          optdegtable += `</tr>`;
          i++;
        });
        optdegtable += `</tbody></table>`;
        $("#optdeg").html(optdegtable);
      }
    }
  });
}

function changePhoto() {
  $("#frmFileUpload").show();
  $("#studphoto").hide();
}

var courseFee = 1;
//=============  Load Degrees To Course Preference Details ==============//
var selectedOpt = new Array();
var count = 0;
const loadfilteredDeg = val => {
  var value = val.value;
  var cat = $("#fcategory").val();
  var degree = $("#fdegree1").val();
  if (cat != "" && degree != "") {
    getFeestr();
  }

  if (!in_array(value, selectedOpt)) {
    if (val.selectedIndex <= 0) {
      count--;
      getFeestr();
    } else {
      selectedOpt.push(value);
      count++;
    }
  } else {
    alert("course already selected.");
    val.value = "";
    return;
  }
  // console.log("cnt", count);
};

function loadcombination() {
  var degcomb = combcode[$("#fdegree").val()];
  // console.log(degcomb,combcode);
  var options = "";
  options += `<option value="">--Select--</option>`;
  if (degcomb != undefined) {
    var res = degcomb.split("*");
    res.forEach(element => {
      var value = element.split("-");
      options += `<option value="${value[0]}">${value[1]}</options>`;
    });
  }
  $("#fcombcode").html(options);
}

//============= Calculate Total MM =============//
const getlTotalMM = () => {
  var val1 = $("#flang1mm").val();
  var val2 = $("#flang2mm").val();
  if (val1 == "") val1 = 0;
  if (val2 == "") val2 = 0;

  ttlMM = parseInt(val1) + parseInt(val2);

  $("#flangttlmm").val(ttlMM);
};

//============= Calculate Total MS =============//
const getlTotalMS = () => {
  var val1 = $("#flang1ms").val();
  var val2 = $("#flang2ms").val();
  if (val1 == "") val1 = 0;
  if (val2 == "") val2 = 0;

  ttlMS = parseInt(val1) + parseInt(val2);
  $("#flangttlms").val(ttlMS);
};

const optTtlMM = () => {
  var val1 = $("#fopt1mm").val();
  var val2 = $("#fopt2mm").val();
  var val3 = $("#fopt3mm").val();
  var val4 = $("#fopt4mm").val();

  if (val1 == "") val1 = 0;
  if (val2 == "") val2 = 0;
  if (val3 == "") val3 = 0;
  if (val4 == "") val4 = 0;

  ttlMM = parseInt(val1) + parseInt(val2) + parseInt(val3) + parseInt(val4);
  $("#foptttlmm").val(ttlMM);
};

//================= Validate Values  ==============//
jsonObj = [];
const nonMandFields = [
  "adhar",
  "pmobileno",
  "income",
  "othUniv",
  "fqpercentage",
  "flangttlms",
  "flangttlmm",
  "flang2",
  "flang2mm",
  "flang2ms",
  "fopt2",
  "fopt2mm",
  "fopt2ms",
  "fopt3",
  "fopt3mm",
  "fopt3ms",
  "fopt4",
  "fopt4mm",
  "fopt4ms",
  "foptttlmm",
  "foptttlms",
  "flangttlms",
  "flangttlmm",
  "fpmregno",
  "fbcuetype",
  "OtherUniv",
  "fquniv",
  "fpgunivtype",
  ""
];
var feestr = {};
var privsub = [];
var finaloptdeg = [];
var privackd = [];

var gfilename;

function UploadDocument() {
  file_file = "fwrkexppath"; //file
  var file_name = $("#" + file_file).val();
  var file_size = $("#" + file_file)[0].files[0].size;
  var file_extn = file_name.split(".").pop();
  var file_extn = file_extn.toLowerCase();
  // if (file_extn == "xlsx") {

  // }
  // else {
  //   alert("XLSX files are allowed!");
  //   return false;
  // }

  if (file_size >= 1000000) {
    alert("Upload files with size less then 1MB!");
    return false;
  }

  var file_data = $("#" + file_file).prop("files")[0];
  var form_data = new FormData();
  form_data.append("file", file_data);
  // console.log("fileeee", form_data, file_data, file_name);
  $.blockUI({
    message:
      "<h1 class='h1' style='font-size:12px'><img src='../images/ajax-loader.gif' border='0'></h1>"
  });
  $.ajax({
    type: "POST",
    url: "./upload_file.php",
    data: form_data,
    cache: false,
    contentType: false,
    processData: false,
    success: function(data) {
      $.unblockUI();
      // console.log(data);
      gfilename = data;
    },
    error: function(data) {
      alert(data);
    }
  });
}

const autoFillAddr = obj => {
  if ($(obj).is(":checked")) {
    $("#fcurradd1").val($("#fpermadd1").val());
    $("#fcurradd2").val($("#fpermadd2").val());
    $("#fcurradd3").val($("#fpermadd3").val());
    $("#fcurrdist").val($("#fpermdist").val());
    $("#fcurrpin").val($("#fpermpin").val());
    $("#fcurrstate").val($("#fpermstate").val());
  } else {
    $("#fcurradd1").val("");
    $("#fcurradd2").val("");
    $("#fcurradd3").val("");
    $("#fcurrdist").val("");
    $("#fcurrpin").val("");
    $("#fcurrstate").val("");
  }
};

//=========== BCU Employee Type=============//
const showOpt = () => {
  if ($("#fbcue_1").is(":checked")) $("#fbcuetype").show();
  else {
    $('input[name="fbcuetype"]').val("");
    $("#fbcuetype").hide();
  }
};

//========= Calculate Percentage ========//
const getPrevPercent = () => {
  if ($("#fqmaxmarks").val() == "") return;

  if ($("#fqsecmarks").val() == "") return;

  if (parseFloat($("#fqsecmarks").val()) > parseFloat($("#fqmaxmarks").val())) {
    alert("Maximum Marks less than Secured Marks");
    $("#fqmaxmarks").val("");
    $("#fqsecmarks").val("");
    return;
  }
  $("#fqpercentage").val(
    (
      (parseFloat($("#fqsecmarks").val()) * 100) /
      parseFloat($("#fqmaxmarks").val())
    ).toFixed(2)
  );
};

function loadcombsubjects() {
  var res = combsubject[`${$("#fdegree").val()}${$("#fcombcode").val()}`];

  var table = ` <thead>
  <tr class='bg-cyan'>
    <td class="qaltablefisrtrd">
      Sl.
    </td>
    <td class="qaltabletd" style="width: 200px;" rowspan="2">
      Subject
    </td>
    <td class="qaltabletd" colspan="2">
      Sem / Year I
    </td>
    <td class="qaltabletd" colspan="2">
      Sem / Year II
    </td>
    <td class="qaltabletd" colspan="2">
      Sem / Year III
    </td>
    <td class="qaltabletd" colspan="2">
      Sem / Year IV
    </td>
    <td class="qaltabletd" colspan="2">
      Sem / Year V
    </td>
    <td class="qaltabletd" colspan="2">
      Sem / Year VI
    </td>
    <td class="qaltabletd" colspan="2">
      Total Marks
    </td>
    <td class="qaltabletd" rowspan="2">
      % of Marks
    </td>
  </tr>
  <tr class='bg-cyan'>
    <td class="qaltablefisrtrd">
      No.
    </td>
    <td class="qaltabletd">
      Obt
    </td>
    <td class="qaltabletd">
      Max
    </td>
    <td class="qaltabletd">
      Obt
    </td>
    <td class="qaltabletd">
      Max
    </td>
    <td class="qaltabletd">
      Obt
    </td>
    <td class="qaltabletd">
      Max
    </td>
    <td class="qaltabletd">
      Obt
    </td>
    <td class="qaltabletd">
      Max
    </td>
    <td class="qaltabletd">
      Obt
    </td>
    <td class="qaltabletd">
      Max
    </td>
    <td class="qaltabletd">
      Obt
    </td>
    <td class="qaltabletd">
      Max
    </td>
    <td class="qaltabletd">
      Obt
    </td>
    <td class="qaltabletd">
      Max
    </td>
  </tr>
</thead>
<tbody>`;
  if (res != undefined) {
    var subdet = res.split("*");
    var i = 1;
    subdet.forEach(element => {
      var value = element.split("-");
      table += `<tr id='${i}' class="ui-widget-content jqgrow">
        <td class='tbl_row_new tdfirst'>
          <centre>${i}. </centre>
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subsem1_${i}" id="subsem1_${i}"
            style="max-width: 200px !important;" disabled value = '${value[1]}'>
          <input type="hidden" name="subcode_${i}" id="subcode_${i}" value="${
        value[0]
      }">
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subsem1mo_${i}" maxlength="4"
            onkeypress="return acceptNumbersOnlyForModule(event);" onchange="gettoal('${i}')"
            id="subsem1mo_${i}">
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subsem1mm_${i}" maxlength="4"
            onkeypress="return acceptNumbersOnlyForModule(event);" id="subsem1mm_${i}"
            onchange="gettoal('${i}')">
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subsem2mo_${i}" maxlength="4"
            onkeypress="return acceptNumbersOnlyForModule(event);" id="subsem2mo_${i}"
            onchange="gettoal('${i}')">
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subsem2mm_${i}" maxlength="4"
            onkeypress="return acceptNumbersOnlyForModule(event);" id="subsem2mm_${i}"
            onchange="gettoal('${i}')">
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subsem3mo_${i}" maxlength="4"
            onkeypress="return acceptNumbersOnlyForModule(event);" id="subsem3mo_${i}"
            onchange="gettoal('${i}')">
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subsem3mm_1" maxlength="4"
            onkeypress="return acceptNumbersOnlyForModule(event);" id="subsem3mm_${i}"
            onchange="gettoal('${i}')">
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subsem4mo_${i}" maxlength="4"
            onkeypress="return acceptNumbersOnlyForModule(event);" id="subsem4mo_${i}"
            onchange="gettoal('${i}')">
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subsem4mm_${i}" maxlength="4"
            onkeypress="return acceptNumbersOnlyForModule(event);" id="subsem4mm_${i}"
            onchange="gettoal('${i}')">
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subsem5mo_${i}" maxlength="4"
            onkeypress="return acceptNumbersOnlyForModule(event);" id="subsem5mo_${i}"
            onchange="gettoal('${i}')">
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subsem5mm_${i}" maxlength="4"
            onkeypress="return acceptNumbersOnlyForModule(event);" id="subsem5mm_${i}"
            onchange="gettoal('${i}')">
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subsem6mo_${i}" maxlength="4"
            onkeypress="return acceptNumbersOnlyForModule(event);" id="subsem6mo_${i}"
            onchange="gettoal('${i}')">
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subsem6mm_${i}" maxlength="4"
            onkeypress="return acceptNumbersOnlyForModule(event);" id="subsem6mm_${i}"
            onchange="gettoal('${i}')">
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subtotalmo_${i}" maxlength="4" readonly
            onkeypress="return acceptNumbersOnlyForModule(event);" id="subtotalmo_${i}">
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subtotalmm_${i}" maxlength="4" readonly
            onkeypress="return acceptNumbersOnlyForModule(event);" id="subtotalmm_${i}">
        </td>
        <td class='tbl_row_new'>
          <input type="text" name="subpercentagemm_${i}" maxlength="5" readonly
            style="max-width: 70px" onkeypress="return acceptNumbersOnlyForModule(event);"
            id="subpercentagemm_${i}">
        </td>
      </tr>`;
      i++;
    });
    table += `</tbody>`;
    $("#qalsemdet").html(table);
  }
}

//================= Load Fee Structure ================//
var totalFee = 0;
const getFeestr = () => {
  var cat = $("#fcategory").val();
  var degree = $("#fdegree1").val();

  var value = $('input[name="fgender"]:checked').val();
  if (value == "T") cat = "SC";
  var karstudy = $('input[name="fkarstudy"]:checked').val();
  if (karstudy == "No") cat = "GM";
  if (cat != "" && degree != "") {
    $.ajax({
      type: "POST",
      url: $host_url + "getFees",
      data: "&fcatcode=" + cat + "&fdegree=" + degree,
      success: response => {
        var { error_code, data, status } = JSON.parse(response);
        var table = ``;
        var feeData = data.feestr;
        if (error_code == 0) {
          courseFee = 1;
          // if ($("#fdegree1").val() != "") courseFee = courseFee + 1;
          totalFee = 0;
          if ($("#fdegree2").val() != "") courseFee = courseFee + 1;

          if ($("#fdegree3").val() != "") courseFee = courseFee + 1;

          if ($("#fdegree4").val() != "") courseFee = courseFee + 1;

          if ($("#fdegree5").val() != "") courseFee = courseFee + 1;

          if ($("#fdegree6").val() != "") courseFee = courseFee + 1;

          table = `
          <table class="table table-bordered table-hover" id='mainTable'>
          <thead style = 'height:40px;background-color: #184F76 !important;color: #fff;'>
            <tr>
              <th>    SL. No.   </th>
              <th>    Head Code   </th>
              <th>    Fee   </th>
            </tr>
          </thead>`;
          feeData.map((el, i) => {
            if (el.fheadcode == "01 ADDITIONAL COURSE FEE") {
              if (courseFee > 1) {
                table += `<tr class="tblRow" id="tblid">
              <td> ${i + 1} </td>
              <td id="fheadcode${i}"> ${el.fheadcode} </td>
              <td id="fmaxfee${i}"> ${el.fmaxfee * (courseFee - 1)} </td>
            </tr>`;
                totalFee += el.fmaxfee * (courseFee - 1);
                // console.log(totalFee);
              }
            } else {
              table += `<tr class="tblRow" id="tblid">
                <td> ${i + 1} </td>
                <td id="fheadcode${i}"> ${el.fheadcode} </td>
                <td id="fmaxfee${i}"> ${el.fmaxfee} </td>
                </tr>`;
              totalFee += Number(el.fmaxfee);
              // console.log("ttt", totalFee);
            }
          });
          table += `
        <tr>
          <td colspan="2" class="text-left">Total</td>
          <td id="ttlAmt">${totalFee}</td>
        </tr>
        </table>`;
        }
        if (error_code == -1) {
          table = `<p>No Fee Sturcture found for the above selected Category and Preference 1.<p>`;
        }
        $("#FeeTbl").html(table);
      }
    });
  }
};

function savepgApplication() {
  jsonObj = [];
  var errcount = 0;
  var missing_fields = [];
  privsub = [];
  finaloptdeg = [];
  privackd = [];
  // var photo_path = $("#file").val();

  //validate and read values of text and select boxes for Personal Details
  $("#idPerDet input[type=text],#idPerDet select").each(function() {
    if ($(this).val() == "" && !in_array($(this).attr("id"), nonMandFields)) {
      $(this)
        .closest(".form-group")
        .find(".fieldError")
        .addClass("hasError");

      if ($(this).attr("name") != "") errcount++;
      missing_fields.push($(this).attr("name"));
    } else {
      $(this)
        .closest(".form-group")
        .find(".fieldError")
        .removeClass("hasError");
      item = {};
      item["id"] = $(this).attr("id");
      item["value"] = $(this).val();
      jsonObj.push(item);
    }
  });

  var radio_names = ["fgender", "fkashmir", "fhk"];

  // resStat
  var checkboxes = $("#quota input[type=checkbox]");
  var vals = "";
  // console.log(checkboxes);
  for (var i = 0, n = checkboxes.length; i < n; i++) {
    if (checkboxes[i].checked) {
      item = {};

      item["id"] = checkboxes[i].id;
      item["value"] = "Yes";
      jsonObj.push(item);
    } else {
      item = {};

      item["id"] = checkboxes[i].id;
      item["value"] = "No";
      jsonObj.push(item);
    }
  }

  if ($("#resStat").is(":checked")) {
    item = {};
    item["id"] = "fresstat";
    item["value"] = "Yes";
    jsonObj.push(item);
    $("#prevAcdMarks input[type=text]").each(function() {
      $("input[type=text].clr").val("");
      $(this)
        .closest(".form-group")
        .find(".fieldError")
        .removeClass("hasError");
      item = {};
      item["id"] = $(this).attr("id");
      item["value"] = $(this).val();
      jsonObj.push(item);
    });
  } else {
    item = {};
    item["id"] = "fresstat";
    item["value"] = "No";
    jsonObj.push(item);

    $(".reqMarks input[type=text]").each(function() {
      if ($(this).val() == "" && !in_array($(this).attr("id"), nonMandFields)) {
        $(this)
          .closest(".form-group")
          .find(".fieldError")
          .addClass("hasError");
        if ($(this).attr("name") != "") errcount++;
        missing_fields.push($(this).attr("name"));
      } else {
        $(this)
          .closest(".form-group")
          .find(".fieldError")
          .removeClass("hasError");
        item = {};
        item["id"] = $(this).attr("id");
        item["value"] = $(this).val();
        jsonObj.push(item);
      }
    });
  }
  //======= validate 1st preference ==========//
  // if ($("#fdegree1").val() == null || $("#fdegree1").val() == "") {
  //   $("#pref1")
  //     .closest(".form-group")
  //     .find(".fieldError")
  //     .addClass("hasError");
  //   errcount++;
  //   missing_fields.push($(this).attr("name"));
  // } else {
  //   $("#subjectdet select").each(function() {
  //     $(this)
  //       .closest(".form-group")
  //       .find(".fieldError")
  //       .removeClass("hasError");
  //     item = {};
  //     item["id"] = $(this).attr("id");
  //     item["value"] = $(this).val();
  //     jsonObj.push(item);
  //   });
  // }

  $("#prevAcadDet input[type=text]:enabled,#prevAcadDet select").each(
    function() {
      if ($(this).val() == "" && !in_array($(this).attr("id"), nonMandFields)) {
        $(this)
          .closest(".form-group")
          .find(".fieldError")
          .addClass("hasError");
        errcount++;
        missing_fields.push($(this).attr("name"));
      } else {
        $(this)
          .closest(".form-group")
          .find(".fieldError")
          .removeClass("hasError");
        item = {};
        item["id"] = $(this).attr("id");
        item["value"] = $(this).val();
        jsonObj.push(item);
      }
    }
  );

  if ($('input[id="fpgdegree_1"]').is(":checked")) {
    //radio_names.push("fpgunivtype");
    $("#prevPGDet input[type=text],#prevPGDet select").each(function() {
      if ($(this).val() == "" && !in_array($(this).attr("id"), nonMandFields)) {
        $(this)
          .closest(".form-group")
          .find(".fieldError")
          .addClass("hasError");
        errcount++;
        missing_fields.push($(this).attr("name"));
      } else {
        $(this)
          .closest(".form-group")
          .find(".fieldError")
          .removeClass("hasError");
        item = {};
        item["id"] = $(this).attr("id");
        item["value"] = $(this).val();
        jsonObj.push(item);
      }
    });
  } else {
    $("#prevPGDet input[type=text],#prevPGDet select").each(function() {
      item = {};
      item["id"] = $(this).attr("id");
      item["value"] = $(this).val();
      jsonObj.push(item);
    });
  }

  //===== MBA Entrance Exam Name ======//
  if ($('input[id="fmngetexam_1"]').is(":checked")) {
    // radio_names.push("fpgunivtype");
    var entranceExm_Name = $("#fmngexamname").val();
    var entranceExm_Rnk = $("#fmngrank").val();

    console.log("entranceExm_Name", entranceExm_Name);
    //----- MBA Exam NAME -----//
    if (entranceExm_Name == "") {
      $("#mbaName_err")
        .closest(".form-group")
        .find(".fieldError")
        .addClass("hasError");
      errcount++;
      missing_fields.push("fmngexamname");
    } else {
      $("#mbaName_err")
        .closest(".form-group")
        .find(".fieldError")
        .removeClass("hasError");

      item = {};
      item["id"] = "fmngexamname";
      item["value"] = entranceExm_Name;
      jsonObj.push(item);
    }
    //----- MBA Rank -----//
    if (entranceExm_Rnk == "") {
      $("#mbaRnk_err")
        .closest(".form-group")
        .find(".fieldError")
        .addClass("hasError");
      errcount++;
      missing_fields.push("fmngrank");
    } else {
      $("#mbaRnk_err")
        .closest(".form-group")
        .find(".fieldError")
        .removeClass("hasError");
      item = {};
      item["id"] = "fmngrank";
      item["value"] = entranceExm_Rnk;
      jsonObj.push(item);
    }
  } else {
    var entranceExm_Name = $("#fmngexamname").val();
    var entranceExm_Rnk = $("#fmngrank").val();
    item = {};
    item["id"] = "fmngexamname";
    item["value"] = entranceExm_Name;
    jsonObj.push(item);

    item = {};
    item["id"] = "fmngrank";
    item["value"] = entranceExm_Rnk;
    jsonObj.push(item);
  }

  // if ($('input[id="fmbaentrace_1"]').is(":checked")) {
  var mbawrkExp = $("#fwrkexp").val();

  // console.log("mbawrkExp", mbawrkExp);
  //----- MBA Exam NAME -----//
  if (mbawrkExp == "") {
    $("#mbawrk_err")
      .closest(".form-group")
      .find(".fieldError")
      .addClass("hasError");
    // errcount++;
    // missing_fields.push("mbawrkExp");
    // console.log("mbawrkExp empty", mbawrkExp);
    item = {};
    item["id"] = "fwrkexp";
    item["value"] = mbawrkExp;
    jsonObj.push(item);
  } else {
    $("#mbawrk_err")
      .closest(".form-group")
      .find(".fieldError")
      .removeClass("hasError");
    item = {};
    item["id"] = "fwrkexp";
    item["value"] = mbawrkExp;
    jsonObj.push(item);
  }

  if (gfilename != "") {
    item = {};
    item["id"] = "fwrkexppath";
    item["value"] = gfilename;
    jsonObj.push(item);
  }
  // }

  for (var i = 0; i < radio_names.length; i++) {
    if (!$('input[name="' + radio_names[i] + '"]').is(":checked")) {
      console.log(radio_names[i] + " is not checked");
      if (radio_names[i] != "fbcuetype") {
        $('input[name="' + radio_names[i] + '"]')
          .closest(".form-group")
          .find(".fieldError")
          .addClass("hasError");
        errcount++;
        missing_fields.push(radio_names[i]);
      } else {
        value = $('input[name="' + radio_names[i] + '"]').val();
        item = {};
        item["id"] = radio_names[i];
        item["value"] = value;
        jsonObj.push(item);
      }
    } else {
      // console.log(radio_names[i] + "is checked");
      $('input[name="' + radio_names[i] + '"]')
        .closest(".form-group")
        .find(".fieldError")
        .removeClass("hasError");
      value = $('input[name="' + radio_names[i] + '"]:checked').val();
      item = {};
      item["id"] = radio_names[i];
      item["value"] = value;
      jsonObj.push(item);
    }
  }

  var feestr1 = [];
  $("#mainTable tr.tblRow").each((i, el) => {
    var $tds = $(el).find("td");
    var feehead = $.trim($tds.eq(1).text());
    var fee = $.trim($tds.eq(2).text());
    var obj = {};
    obj.feehead = feehead;
    obj.fee = fee;
    feestr1.push(obj);
  });
  var obj = {};
  feestr.data = feestr1;

  item = {};
  item["id"] = "ftotfee";
  item["value"] = totalFee;
  jsonObj.push(item);

  var ressub = combsubject[`${$("#fdegree").val()}${$("#fcombcode").val()}`];
  if (ressub != undefined) {
    var res = ressub.split("*");

    var z = 1;
    for (var i = 0; i < res.length; i++) {
      var item = {};
      item["subcode"] = $(`#subcode_${z}`).val();
      item["subsem1mo"] = $(`#subsem1mo_${z}`).val();
      item["subsem1mm"] = $(`#subsem1mm_${z}`).val();
      item["subsem2mo"] = $(`#subsem2mo_${z}`).val();
      item["subsem2mm"] = $(`#subsem2mm_${z}`).val();
      item["subsem3mo"] = $(`#subsem3mo_${z}`).val();
      item["subsem3mm"] = $(`#subsem3mm_${z}`).val();
      item["subsem4mo"] = $(`#subsem4mo_${z}`).val();
      item["subsem4mm"] = $(`#subsem4mm_${z}`).val();
      item["subsem5mo"] = $(`#subsem5mo_${z}`).val();
      item["subsem5mm"] = $(`#subsem5mm_${z}`).val();
      item["subsem6mo"] = $(`#subsem6mo_${z}`).val();
      item["subsem6mm"] = $(`#subsem6mm_${z}`).val();
      item["subtotalmo"] = $(`#subtotalmo_${z}`).val();
      item["subtotalmm"] = $(`#subtotalmm_${z}`).val();
      item["subpercentagemm"] = $(`#subpercentagemm_${z}`).val();
      z++;
      privsub.push(item);
    }
  }

  // console.log('hii')

  if (optdegarry.length > 0) {
    for (let i = 1; i <= optdegarry.length; i++) {
      if ($('input[name="deg_' + i + '"]').is(":checked")) {
        var item = {};
        item["optdeg"] = $(`#h_optdeg_${i}`).val();
        finaloptdeg.push(item);
      }
    }
  }

  if ($('input[name="vfd"]').is(":checked")) {
    ackvfd = $(`#vfd`).val();
  } else {
    ackvfd = "";
  }

  var item = {};
  item["fqpercentage"] = $("#fqpercentage").val();
  item["flang1"] = $("#flang1").val();
  item["flang2"] = $("#flang2").val();
  item["flang1mm"] = $("#flang1mm").val();
  item["flang2mm"] = $("#flang2mm").val();
  item["flangttlmm"] = $("#flangttlmm").val();
  item["flang1ms"] = $("#flang1ms").val();
  item["flang2ms"] = $("#flang2ms").val();
  item["flangttlms"] = $("#flangttlms").val();
  item["qulregno"] = $("#qulregno").val();
  item["idUnvExam"] = $("#idUnvExam").val();
  item["qulcollname"] = $("#qulcollname").val();
  item["fcombcode"] = $("#fcombcode").val();
  item["fdegree"] = $("#fdegree").val();

  item["sslc"] = $("#h_SSLC").val();
  item["ug"] = $("#h_UG").val();
  item["caste"] = $("#h_CASTE").val();
  item["hk"] = $("#h_HK").val();

  privackd.push(item);

  $("#OtherInfo input[type=text],#OtherInfo textarea").each(function() {
    if ($(this).val() == "" && !in_array($(this).attr("id"), nonMandFields)) {
      $(this)
        .closest(".form-group")
        .find(".fieldError")
        .addClass("hasError");
      errcount++;
      missing_fields.push($(this).attr("name"));
    } else {
      $(this)
        .closest(".form-group")
        .find(".fieldError")
        .removeClass("hasError");
      item = {};
      item["id"] = $(this).attr("id");
      item["value"] = $(this).val();
      jsonObj.push(item);
    }
  });
  // console.log(fappno);
  // console.log({ errcount, missing_fields, jsonObj });
  return errcount;
}

var ackvfd = [];
const savePGAdmDet = finsub => {
  var errorcount = savepgApplication();
  console.log("ack", ackvfd);
  if (ackvfd !== "T") {
    swal({
      title: `Please Acknowledge and Verify the Application`,
      html: true,
      showCancelButton: false,
      confirmButtonColor: "#5495ff",
      confirmButtonText: "OK",
      closeOnConfirm: false
    });
    return;
  }
  if (finsub == "T" && errorcount > 0) {
    swal({
      title: `Fill All the missing fields. Missing fields are highlighted in red color.`,
      html: true,
      showCancelButton: false,
      confirmButtonColor: "#5495ff",
      confirmButtonText: "OK",
      closeOnConfirm: false
    });
    return;
  }
  // console.log(ffappno);
  fappno = ffappno;
  $.blockUI({ message: "<img src='../img/Loading_icon.gif' border='0'>" });
  $.ajax({
    type: "POST",
    url: $host_url + "admpgsaveApplication",
    data:
      "fappno=" +
      fappno +
      "&final=" +
      finsub +
      "&ackvfd=" +
      ackvfd +
      "&feestr=" +
      JSON.stringify(feestr) +
      "&data=" +
      JSON.stringify(jsonObj) +
      "&privackd=" +
      JSON.stringify(privackd) +
      "&privsub=" +
      JSON.stringify(privsub) +
      "&finaloptdeg=" +
      JSON.stringify(finaloptdeg),
    success: response => {
      $.unblockUI();
      var { error_code, data, status } = JSON.parse(response);
      // console.log(data)
      var { message } = data;
      if (error_code === -1) {
        swal({
          title: data.message,
          html: true,
          showCancelButton: false,
          confirmButtonColor: "#5495ff",
          confirmButtonText: "OK",
          closeOnConfirm: false
        });
      } else {
        var { app_no } = data;
        gAppNo = app_no;
        fappno = app_no;
        if (finsub == "T") {
          $("#sbmchallan").hide();
          $("#makepayment").show();
          $("#dapp_no").append(app_no);

          $("#app_msg").append(message);
          $("#prefDet").hide();
          $("#prefDet").hide();
          $("#personal_det").hide();
          $("#basicDet").hide();
          $("#prevAcadDetCard").hide();
          $("#FeeDet").hide();
          $("#upload_doc_det").hide();
          $("#optdeg_det").hide();
          $("#success_card").show();
          makepayment(gAppNo, "026");
        } else {
          swal({
            title: `Updated successfully.`,
            html: true,
            showCancelButton: false,
            confirmButtonColor: "#5495ff",
            confirmButtonText: "OK",
            closeOnConfirm: false
          });
        }
      }
    }
  });
  $("#next").show();
  $("#add").show();
  $("#success_card").hide();
  $("#basicDet").hide();
  $("#prevAcadDetCard").hide();
  $("#optdeg_det").hide();
  $("#upload_doc_det").hide();
  $("#perdetl").hide();
  $("#FeeDet").hide();
  $("#fbcuetype").show();
};

function gettoal(i) {
  var semmo1 = parseInt($("#subsem1mo_" + i).val());
  var semmm1 = parseInt($("#subsem1mm_" + i).val());

  if (semmo1 > semmm1 && !isNaN(semmm1)) {
    alert("sem 1 obtained marks is greater than the max. marks");
    $("#subsem1mm_" + i).val("");
    $("#subsem1mo_" + i).val("");
    $("#subsem1mo_" + i).focus();
    return;
  }

  var semmo2 = parseInt($("#subsem2mo_" + i).val());
  var semmm2 = parseInt($("#subsem2mm_" + i).val());

  if (semmo2 > semmm2 && !isNaN(semmm2)) {
    alert("sem 2 obtained marks is greater than the max. marks");
    $("#subsem2mm_" + i).val("");
    $("#subsem2mo_" + i).val("");
    $("#subsem2mo_" + i).focus();
    return;
  }

  var semmo3 = parseInt($("#subsem3mo_" + i).val());
  var semmm3 = parseInt($("#subsem3mm_" + i).val());

  if (semmo3 > semmm3 && !isNaN(semmm3)) {
    alert("sem 3 obtained marks is greater than the max. marks");
    $("#subsem3mm_" + i).val("");
    $("#subsem3mo_" + i).val("");
    $("#subsem3mo_" + i).focus();
    return;
  }

  var semmo4 = parseInt($("#subsem4mo_" + i).val());
  var semmm4 = parseInt($("#subsem4mm_" + i).val());

  if (semmo4 > semmm4 && !isNaN(semmm4)) {
    alert("sem 4 obtained marks is greater than the max. marks");
    $("#subsem4mm_" + i).val("");
    $("#subsem4mo_" + i).val("");
    $("#subsem4mo_" + i).focus();
    return;
  }

  var semmo5 = parseInt($("#subsem5mo_" + i).val());
  var semmm5 = parseInt($("#subsem5mm_" + i).val());

  if (semmo5 > semmm5 && !isNaN(semmm5)) {
    alert("sem 5 obtained marks is greater than the max. marks");
    $("#subsem5mm_" + i).val("");
    $("#subsem5mo_" + i).val("");
    $("#subsem5mo_" + i).focus();
    return;
  }

  var semmo6 = parseInt($("#subsem6mo_" + i).val());
  var semmm6 = parseInt($("#subsem6mm_" + i).val());

  if (semmo6 > semmm6 && !isNaN(semmm6)) {
    alert("sem 6 obtained marks is greater than the max. marks");
    $("#subsem6mm_" + i).val("");
    $("#subsem6mo_" + i).val("");
    $("#subsem6mo_" + i).focus();
    return;
  }

  var totobt = 0;
  var totmarks = 0;

  if (
    !isNaN(semmo1) &&
    !isNaN(semmo2) &&
    !isNaN(semmo3) &&
    !isNaN(semmo4) &&
    !isNaN(semmo5) &&
    !isNaN(semmo6)
  ) {
    totobt =
      parseInt(semmo1) +
      parseInt(semmo2) +
      parseInt(semmo3) +
      parseInt(semmo4) +
      parseInt(semmo5) +
      parseInt(semmo6);
    $("#subtotalmo_" + i).val(totobt);
  }

  if (
    !isNaN(semmm1) &&
    !isNaN(semmm2) &&
    !isNaN(semmm3) &&
    !isNaN(semmm4) &&
    !isNaN(semmm5) &&
    !isNaN(semmm6)
  ) {
    totmarks =
      parseInt(semmm1) +
      parseInt(semmm2) +
      parseInt(semmm3) +
      parseInt(semmm4) +
      parseInt(semmm5) +
      parseInt(semmm6);
    $("#subtotalmm_" + i).val(totmarks);
    var totpercetage = (parseInt(totobt) / parseInt(totmarks)) * 100;
    $("#subpercentagemm_" + i).val(Math.round(totpercetage * 100) / 100);
  }
}