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.224.38.170


Current Path : /var/www/html/studentportal_wait/js/
Upload File :
Current File : /var/www/html/studentportal_wait/js/examApp.js

// import { getRegno, getDegree } from "./MainPage";
var examAppJson;
var examAppData;

var GrandTotal = 0;
var semTtl = 0;
var feeTotal = 0;
var ghide = true;
var gExamAppSemData = [];
var gFreshExam = "";

var gSemwisedata = new Object();
function loadExamApplication1() {
  $("#loadtab").load(
    "html_modules/examApplication.html?v=" + version,
    function() {
      $.ajax({
        type: "get",
        url: `${$host_url}getExamapplication&univcode=${window.FUNIVCODE}`, // ${UNIVCODE}
        //data:parameters,
        success: function(response) {
          var { error_code, status, data, FRESHEXAM, exmNos } = JSON.parse(
            response
          );
          console.log(JSON.parse(response));
          if (error_code == -1) {
            //----- Ex. REGNO: 8073092172 --------//
            var { msg } = data;
            swal(
              {
                title: msg + " ",
                type: "warning",
                showCancelButton: false,
                confirmButtonColor: "#5495ff",
                confirmButtonText: "OK",
                closeOnConfirm: false
              },
              function(isConfirm) {
                if (isConfirm) swal.close();
                loadProfile();
                $("#profile").addClass("active");
                $("#examappmenu").removeClass("active");
              }
            );
          } else {
            //===================== Select Semester Table ===============//
            var tr1 = `<tr style="text-align:center">`;
            var tblExamData = `<tr style="text-align:center">`;

            var tr2 = `<tr style="text-align:center">`;

            exmNos.exam_detail_radioButton_table_data.map((el, i) => {
              tr1 += `<td style="font-weight: 900">
                ${romanize(alphabet.indexOf(el.id) + 1)}
                </td>
                `;

              tblExamData += `
                <td style="pdding:0px 0px">`;

              if (el.tableDataValue == "Radio") {
                tblExamData += `<input name="examno" class="with-gap" type="radio" id="exam${el.id}" 
                  onChange="ShwExamDet('${el.id}')" value="${el.id}" />
                  <label for="exam${el.id}" style="height:15px; line-height:15px"></label>`;
                tr2 += `<td id="sem_totfee_${el.id}" style="font-weight: 600">
                  0
                </td>`;
              } else {
                tblExamData += `${el.tableDataValue}`;
                tr2 += `<td id="sem_totfee_${el.id}" style="font-weight: 600">
                </td>`;
              }
              tblExamData += `</td>`;
            });

            tblExamData += `</tr>`;
            tr1 += `</tr>`;
            tr2 += `</tr>`;
            $("#idExmNoTbl").append(tr1 + tblExamData + tr2);
            $("#exam" + FRESHEXAM).attr("checked", "checked");

            //================== Semester Details Table ======================//
            var grand_total = 0;
            examAppData = data;
            GrandTotal = 0;

            ghide = true;

            var sem_wise_data = new Object();
            var i = 0;
            for (let item of data) {
              sem_wise_data[item.FEXAMNO] = new Object();

              var sub_selected = Array();
              var ftotthcnt = 0;
              var ftotprcnt = 0;
              for (let sub of item.sub_details) {
                var sel = {
                  fsubcode: sub.f_sub_code,
                  fsubname: sub.f_sub_name,
                  fqpcode: sub.qp_code,
                  fthcnt: sub.th_cnt,
                  fprcnt: sub.pr_cnt,
                  fpresent: "P",
                  finserted: "F",
                  fpass_month: sub.fpass_month
                };
                sub_selected.push(sel);

                if (sub.fpass_month == "CheckBox") {
                  ftotthcnt += parseInt(sub.th_cnt);
                  ftotprcnt += parseInt(sub.pr_cnt);
                }
              }
              sem_wise_data[item.FEXAMNO]["sub_selected"] = sub_selected;
              sem_wise_data[item.FEXAMNO]["subject_table_header"] =
                item.subject_table_header;
              sem_wise_data[item.FEXAMNO]["fexamno"] = item.FEXAMNO;
              sem_wise_data[item.FEXAMNO]["ftotsub"] = item.sem_totsub;
              sem_wise_data[item.FEXAMNO]["sub_options"] = item.sub_options;
              sem_wise_data[item.FEXAMNO]["fees_table_data"] =
                item.fees_table_data;
              // sub_options
              sem_wise_data[item.FEXAMNO]["ftotthcnt"] = ftotthcnt;
              sem_wise_data[item.FEXAMNO]["ftotprcnt"] = ftotprcnt;

              var fee_heads = [];
              let semtotfee = 0;
              for (let fee of item.fees_table_data) {
                let fheadcode = fee.FHEADCODE;
                let fthfee = parseInt(fee.TH_FFEE);
                let fprfee = parseInt(fee.FPRFEE);
                let fmaxfee = parseInt(fee.max_fee);
                let fcalfee = fthfee * ftotthcnt + fprfee * ftotprcnt;
                let fheadfee = fcalfee < fmaxfee ? fcalfee : fmaxfee;
                semtotfee += fheadfee;
                let feehead = { fheadcode, fheadfee };
                fee_heads.push(feehead);
              }
              sem_wise_data[item.FEXAMNO]["fee_heads"] = fee_heads;
              sem_wise_data[item.FEXAMNO]["semtotfee"] = semtotfee;
              i++;
            }
            gSemwisedata = sem_wise_data;

            gExamAppSemData = data;
            gFreshExam = FRESHEXAM;
            callRebuildExamApp();
            return;
          }
        }
      });
    }
  );
}

function callRebuildExamApp() {
  // for all semesters
  for (let key in gSemwisedata) {
    let item = gSemwisedata[key];
    buildSubjectTable(item);
    bulidFeeTable(item);
  }

  //============= Dispaly Grand Total ================//
  var grandTotalDet = `
  <p>Grand Total : Rs. ${GrandTotal} /-</p>`;
  $("#GrandTotal").html(grandTotalDet);

  var AppSubmitBtn = `<button type="button" class="btn btn-primary waves-effect mr-1" 
        id="idSubmitExamApp" onclick="submitExamApplication()">Submit</button>`;
  $("#idSubmitExmApp").html(AppSubmitBtn);
}

function buildSubjectTable(item) {
  // console.log(item);
  var options = "<option>Select</option>";

  const sub_options = item.sub_options;

  for (let opt of sub_options) {
    options += `<option value="${opt.code}">
    ${opt.code}-${opt.FSUBNAME}</options>`;
  }

  var main_subs = item.sub_selected;

  var len = item.ftotsub - main_subs.length;
  var subjectDetails = ``;

  subjectDetails += `
    <table class="table table-bordered table-hover" id="MainTbl${item.FEXAMNO}">
      <thead style = "height:40px;background-color: #184F76 !important;color: #fff;">
        <tr>
          <td class="text-center">Sl. No.</td>`;
  item.subject_table_header.forEach((el, i) => {
    if (el == "Checkbox") {
      subjectDetails += `<td class="text-center">Select</td>`;
    } else {
      subjectDetails += `<td class="text-center">${el}</td>`;
    }
  });

  subjectDetails += `</tr></thead><tbody>`;

  let sub_cnt = 0;

  item.sub_selected.map((el, i) => {
    if (el.finserted !== "T") {
      subjectDetails += `<tr>
                    <td class="text-center">${sub_cnt + 1}</td>
                    <td class="text-center SubjectCode" style="width:15%">${
                      el.fsubcode
                    }
                    <input type="hidden" class="subcode" id="subcode${
                      item.fexamno
                    }${i}" value="${el.fsubcode}" /></td>
                    <td class="text-center">${el.fqpcode}</td>
                    <td class="subjectName" id="parsubname_${item.fexamno}_${
        el.fsubcode
      }">${el.fsubname}</td>`;
      if (el.fpass_month == "CheckBox") {
        let checked = "";
        checked = el.fpresent == "P" ? "checked='checked'" : "";
        subjectDetails += `<td class="text-center">
                      <input type="checkbox" class="filled-in" id="${el.fsubcode}"
                        ${checked} onChange="subPresent('${item.fexamno}','${el.fsubcode}', this)"/>
                      <label for="${el.fsubcode}" style="font-size:14px !important;height:8px"></label>
                      </td>`;
      } else {
        subjectDetails += `<td>${el.fpass_month}</td>`;
      }
      subjectDetails += `</tr>`;
    } else {
      let options_sel = "";
      for (let opt of sub_options) {
        if (opt.code == el.fsubcode) {
          options_sel += `<option selected value="${opt.code}">
          ${opt.code}-${opt.FSUBNAME}</options>`;
        } else {
          options_sel += `<option value="${opt.code}">
          ${opt.code}-${opt.FSUBNAME}</options>`;
        }
      }

      let checked = el.fpresent == "P" ? "checked='checked'" : "";
      subjectDetails += `<tr calss="">
          <td class="text-center">${sub_cnt + 1}</td>
          <td class="text-center SubjectCode" id="exam${
            item.fexamno
          }subcode${i}">
          <select value="${
            el.fsubcode
          }" name="subjectOpt" style="width:100px" class="subOpt" id="exam${
        item.fexamno
      }sub${i}" onChange="optionSelectSub('${
        item.fexamno
      }',this)">${options_sel}</select>
            <input type="hidden" class="osubcode"  value="${el.fsubcode}" />
          </td>
          <td class="text-center">${el.fqpcode}</td>
          <td class="subjectName" id="parsubname_${item.fexamno}_${
        el.fsubcode
      }">${el.fsubname}</td>
          <td class="text-center">
            <input type="checkbox" class="filled-in" id="${el.fsubcode}"
              ${checked} onChange="subPresent('${item.fexamno}','${
        el.fsubcode
      }', this)"/>
      <label for="${
        el.fsubcode
      }" style="font-size:14px !important;height:8px"></label>
      </td></tr>`;
    }
    sub_cnt++;
  });

  // =================  Sub Options =============== //
  if (item.fexamno == gFreshExam) {
    for (var i = 0; i < len; i++) {
      if (options != "" && main_subs.length < item.ftotsub) {
        subjectDetails += `<tr calss="">
          <td class="text-center">${sub_cnt + 1}</td>
          <td class="text-center SubjectCode" id="exam${
            item.fexamno
          }subcode${i}">
          <input type="hidden" class="osubcode" value="" />
          <select name="subjectOpt" style="width:100px" class="subOpt" id="exam${
            item.fexamno
          }sub${i}" onChange="optionSelectSub('${
          item.fexamno
        }',this)">${options}</select>
          </td>
          <td class="text-center" id="exam${item.fexamno}qpcode${i}"></td>
          <td class="subjectName" id="exam${item.fexamno}subname${i}"></td>
          <td class="text-center"  id="exam${item.fexamno}checkbox${i}">
          <input type="checkbox" class="filled-in" id="opt_${i}"
              checked="checked"/>
            <label for="opt_${i}" style="font-size:14px !important;"></label>
          </td></tr>`;
        sub_cnt++;
      }
    }
  }
  //================= end Sub Options ===============//

  subjectDetails += `</tbody></table>`;

  $(`#idSubDetails${item.fexamno}`).html(`<div class="row clearfix">
  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    <div class="card" style="margin:20px 35px; border-radius:5px ">
      <div
        class="header"
        id=""
        style="background-color:#133c55;color:#fff;border-radius:5px 5px 0px 0px;padding:10px;"
      >
        <h5>${romanize(
          alphabet.indexOf(item.fexamno) + 1
        )} - Semester Subject Details</h5>
      </div>
      <div class="row clearfix">
        <div
          class="col-lg-12  col-md-12 col-sm-12 col-xs-12"
          style="width: 100%"
        >
        ${subjectDetails}
        </div>
      </div>
    </div>
  </div>
</div>`);

  if (item.fexamno != gFreshExam && ghide) {
    $(`#idSubDetails${item.fexamno}`).hide();
  }
}

function bulidFeeTable(item) {
  //======================== Fee Details ===========================//
  var FeeDetailsExmAppl = `<div class="row clearfix">
  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    <div class="card" style="margin:20px 35px; border-radius:5px ">
      <div
        class="header"
        style="background-color:#133c55;color:#fff;border-radius:5px 5px 0px 0px;padding:10px;"
      >
        <h5>${romanize(
          alphabet.indexOf(item.fexamno) + 1
        )} - Semester Fee Details</h5>
      </div>
      <div class="row clearfix" style="width:70%;margin:0px">`;

  FeeDetailsExmAppl += `
    <table class="table table-bordered" id="MainTbl${item.fexamno}">
      <thead style = "height:40px;background-color: #184F76 !important;color: #fff;">
        <tr>
          <td class="text-center">Sl. No.</td>
          <td class="text-center">Fee Head</td>
          <td class="text-center">Amount</td>
          </tr><tbody>`;
  var feeTotal = 0;
  item.fee_heads.map((el, i) => {
    // console.log("feesTblData", el, i);
    var headcode = el.fheadcode.split(" ").join("");
    FeeDetailsExmAppl += `<tr>
                    <td class="text-center">${i + 1}</td>
                    <td> ${el.fheadcode}</td>
                    <td id="idFeeDet_${
                      item.fexamno
                    }_${headcode}" style="text-align: right;padding-right:10%">
                    ${el.fheadfee}    
                    </td></tr>`;
    feeTotal += parseInt(el.fheadfee);
  });

  FeeDetailsExmAppl += `</tbody><tfoot>
                  <tr style="background-color:lightgrey;padding:1% 2% 2% 5%;width:100%;margin-left:0px">
                  <td colspan="2" class="text-center" >Total            </td>
                  <td id="ttlamt${item.fexamno}" style="text-align: right;padding-right:10%">
                  <input type="hidden" value="${feeTotal}" id="examTtl${item.fexamno}"/>
                  <strong>${feeTotal}</strong>
                  </td>
                  </tr>
                  </tfoot></table></div>
                  </div>
                </div>
              </div>`;

  $(`#idFeeDetailsExmApp${item.fexamno}`).html(FeeDetailsExmAppl);

  $(`#sem_totfee_${item.fexamno}`).html(feeTotal);

  GrandTotal += feeTotal;

  // $(`#idFeeDetailsTtl${item.fexamno}`).html(FeeDetailsTtl);
  // console.log(item.fexamno, gFreshExam);
  if (item.fexamno != gFreshExam && ghide) {
    $(`#idFeeDetailsExmApp${item.fexamno}`).hide();
    $(`#idFeeDetailsTtl${item.fexamno}`).hide();
  }
}

function subPresent(examno, subcode, el) {
  ghide = false;
  let sub_obj = gSemwisedata[examno].sub_selected.filter(
    el => el.fsubcode == subcode
  )[0];
  sub_obj.fpresent = $(el).is(":checked") ? "P" : "N";

  let sem_subselected = gSemwisedata[examno].sub_selected.map((el, i) => {
    if (el.fsubcode == subcode) return sub_obj;
    else return el;
  });

  gSemwisedata[examno].sub_selected = sem_subselected;

  calculatefee();
}

function calculatefee() {
  GrandTotal = 0;
  var sem_wise_data = new Object();
  var i = 0;
  for (let key in gSemwisedata) {
    let item = gSemwisedata[key];
    sem_wise_data[item.fexamno] = new Object();

    var ftotthcnt = 0;
    var ftotprcnt = 0;
    for (let sub of item.sub_selected) {
      if (sub.fpass_month == "CheckBox" && sub.fpresent == "P") {
        ftotthcnt += parseInt(sub.fthcnt);
        ftotprcnt += parseInt(sub.fprcnt);
      }
    }

    gSemwisedata[item.fexamno]["ftotthcnt"] = ftotthcnt;
    gSemwisedata[item.fexamno]["ftotprcnt"] = ftotprcnt;

    var fee_heads = [];
    let semtotfee = 0;
    for (let fee of item.fees_table_data) {
      let fheadcode = fee.FHEADCODE;
      let fthfee = parseInt(fee.TH_FFEE);
      let fprfee = parseInt(fee.FPRFEE);
      let fmaxfee = parseInt(fee.max_fee);
      let fcalfee = fthfee * ftotthcnt + fprfee * ftotprcnt;
      let fheadfee = fcalfee < fmaxfee ? fcalfee : fmaxfee;
      semtotfee += fheadfee;
      let feehead = { fheadcode, fheadfee };
      fee_heads.push(feehead);
    }
    gSemwisedata[item.fexamno]["semtotfee"] = semtotfee;
    gSemwisedata[item.fexamno]["fee_heads"] = fee_heads;
    i++;
  }

  callRebuildExamApp();
  return;
}

function optionSelectSub(examno, el) {
  let fsubcode = $(el).val();
  let degree = $("#side_degree")
    .html()
    .replace("[", "")
    .replace("]", "");
  let subexist = gSemwisedata[examno].sub_selected.filter(
    el => el.fsubcode == fsubcode
  );
  console.log(subexist);

  let prevsubcode = $(el)
    .parents("td")
    .find("input[type=hidden].osubcode")
    .val();
  console.log(prevsubcode);
  if (prevsubcode !== "") {
    let newsublist = gSemwisedata[examno].sub_selected.filter(
      el => el.fsubcode != prevsubcode
    );
    console.log(newsublist);
    gSemwisedata[examno].sub_selected = newsublist;
  }

  if (subexist.length > 0) {
    swal({
      title: "Subject already exists. Select another one.",
      type: "warning",
      showCancelButton: false,
      confirmButtonColor: "#5495ff",
      confirmButtonText: "OK",
      closeOnConfirm: false
    });
    $(el).val("");
    calculatefee();
    return;
  }

  $.ajax({
    type: "GET",
    async: false,
    data: `degree_code=${degree}&exam=${examno}&subject_code=${fsubcode}&univcode=${window.FUNIVCODE}`, //${UNIVCODE}`,
    url: $host_url + "getSubjectNamesForSelectedSub",
    success: responce => {
      var { error_code, status, data } = JSON.parse(responce);
      if (error_code == -1) {
        swal({
          title: data.msg + " ",
          type: "warning",
          showCancelButton: false,
          confirmButtonColor: "#5495ff",
          confirmButtonText: "OK",
          closeOnConfirm: false
        });
        return;
      } else {
        // console.log(data);

        let insert_obj = {
          fsubcode: data.FSUBCODE,
          fsubname: data.FSUBNAME,
          fqpcode: data.FSUBSHORT,
          fthcnt: data.th_cnt,
          fprcnt: data.pr_cnt,
          fpresent: "P",
          finserted: "T",
          fpass_month: "CheckBox"
        };
        gSemwisedata[examno].sub_selected.push(insert_obj);
        calculatefee();
      }
    }
  });
}

const ShwExamDet = examno => {
  $("div.desc").hide();
  $("#idSubDetails" + examno).show();
  $("#idFeeDetailsExmApp" + examno).show();
  $("#idFeeDetailsTtl" + examno).show();
};

function submitExamApplication() {
  let senddata = new Object();
  senddata["fregno"] = window.FREGNO;
  senddata["fdegree"] = window.FDEGREE;
  senddata["ffreshexam"] = gFreshExam;
  senddata["ftotalfee"] = GrandTotal;

  if (GrandTotal <= 0) {
    swal({
      title: "Select subjects to continue.",
      type: "warning",
      showCancelButton: false,
      confirmButtonColor: "#5495ff",
      confirmButtonText: "OK",
      closeOnConfirm: false
    });
    return;
  }
  let sendsemdata = Array();
  for (let key in gSemwisedata) {
    let semwisedata = gSemwisedata[key];
    let semdata = new Object();
    semdata["fee_heads"] = semwisedata.fee_heads;
    semdata["fexamno"] = semwisedata["fexamno"];
    semdata["ftotsub"] = semwisedata["ftotsub"];
    semdata["semtotfee"] = semwisedata["semtotfee"];
    //semdata["sub_selected"] = semwisedata["sub_selected"];
    let sub_selected = [...semwisedata["sub_selected"]];
    sub_selected = sub_selected.map(el => {
      delete el.fsubname;
      delete el.fqpcode;
      delete el.fthcnt;
      delete el.fprcnt;
      return el;
    });
    semdata["sub_selected"] = sub_selected;
    sendsemdata.push(semdata);
    if (
      gFreshExam == key &&
      semwisedata["ftotsub"] != semwisedata["sub_selected"].length
    ) {
      swal({
        title: "Select all the subjects.",
        type: "warning",
        showCancelButton: false,
        confirmButtonColor: "#5495ff",
        confirmButtonText: "OK",
        closeOnConfirm: false
      });
      return;
    }
  }
  senddata["semdata"] = sendsemdata;
  console.log(senddata);

  $.ajax({
    type: "POST",
    url: $host_url + `submitExamApplication&univcode=${window.FUNIVCODE}`,
    data: "data=" + JSON.stringify(senddata),
    success: responce => {
      var { error_code, status, data } = JSON.parse(responce);
      if (error_code == -1) {
        swal({
          title: data.msg + " ",
          type: "warning",
          showCancelButton: false,
          confirmButtonColor: "#5495ff",
          confirmButtonText: "OK",
          closeOnConfirm: false
        });
        return;
      } else {
        $("#loadtab").load(
          "html_modules/payment_page.html?v=" + version,
          function() {
            var studDet = ``;
            var registrationStats = "";

            studDet += `
              <tr>
              <td width="15%">Register number</td>
              <td width="2%"> : </td>
              <td width="30%"> <b>${window.FREGNO}</b></td></tr>`;

            studDet += `
              <tr>
                <td>Student Name</td>
                <td > : </td>`;

            studDet +=
              FNAME != ""
                ? `<td width="68%"> <b>${window.FNAME}</b></td>`
                : `<td width="68%"> </td>`;

            studDet += `</tr>
              <tr>
                <td>Application No.</td>
                <td > : </td>
                <td> <b>${data.fappno} </b></td></tr>`;

            $("#AppDet").html(studDet);

            registrationStats += `<b style="color:green">Registered Successfully !!</b>`;
            $("#regStat").html(registrationStats);

            getPaymentTypes(data.fappno, window.FUNIVCODE);
          }
        );
      }
    }
  });
}

function loadyourApp() {
  $.ajax({
    type: "GET",
    url:
      $host_url +
      `DisplayApplications&univcode=${window.FUNIVCODE}&fregno=${window.FREGNO}`,
    success: response => {
      console.log("RES", JSON.parse(response));
      var { status, error_code, data } = JSON.parse(response);

      if (error_code == "0") {
        $("#loadtab").load(
          "html_modules/yourExmAppList.html?v=" + version,
          function() {
            var tblDet = `
            <thead style = "height:40px;background-color: #184F76 !important;color: #fff;">
              <tr >`;

            data.tableHeader.forEach((el, i) => {
              tblDet += `<th class="text-center">${el}</td>`;
            });

            tblDet += `
            </tr>
            </thead>
            <tbody>`;
            // var tblDet = "";
            sl_no = 1;
            data.list.forEach((el, i) => {
              var payBtn =
                el.FPAYMENTCONFIRM == ""
                  ? `<Button type="button" class="btn btn-primary waves-effect mr-1" 
                  id="idpayment" onclick="rvrtResponse(${el.APPNO})">Make Payment</button>`
                  : `<Button type="button" class="btn btn-primary waves-effect mr-1" 
                  onclick="">Print App.</button>`;

              var status =
                el.FPAYMENTCONFIRM == "success"
                  ? `<span style="color:green">Received at University</span>`
                  : `<span style="color:red">Pending</span>`;
              tblDet += `
              <tr style="text-align:center">
                <td style="width:10px">${sl_no}</td>
                <td>${el.FPAYMENTYPE}</td>
                <td>${el.APPNO}</td>
                <td>${el.FAPPDATE}</td>
                <td>${el.FTOTALFEE}</td>
                <td>${status}</td>
                <td>${payBtn}</td>
                </tr>`;
              sl_no++;
            });

            $("#yourExmAppsDet").html(tblDet);
          }
        );
      } else {
        alert("No Applications Found.");
      }
    }
  });
}

// ========================================= End OF Script ================================================== //