function callroomallotmentqpwise() {
$("#page_main_div").load(
"../html_modules/roomallotmentqpwise.html?v=1001",
function () {
document.getElementById("display_module_name").innerHTML =
"Room Allotment QPwise";
document.getElementById("module_name_for_save").value =
"Room Allotment QPwise";
getDefaultHeadFooterLinks("Room Allotment QPwise");
$("#modeltable").hide();
}
);
}
function getdate() {
let rdate = document.getElementById("rdate").value;
console.log(rdate, "examdate");
$.blockUI({
message:
"

",
});
$.ajax({
type: "GET",
url: $host_url + "getsession",
data: "rdate=" + rdate,
success: function (res) {
let response = JSON.parse(res);
opt = "";
opt += ``;
for (let i = 0; i < response.data.length; i++) {
opt += ``;
}
document.getElementById("session").innerHTML = opt;
$.unblockUI();
},
});
}
let qpcode = "";
let subnbame = "";
let totcount = "";
let degree = "";
let subcode = "";
let conn = "";
let fstatus = "";
function handleSubmit() {
$("#datatable").show();
$("#modeltable").hide();
let rdate = document.getElementById("rdate").value;
let session = document.getElementById("session").value;
$.blockUI({
message:
"
",
});
$.ajax({
type: "GET",
url: $host_url + "toDisplayQPcode",
data: "rdate=" + rdate + "&session=" + session,
success: function (res) {
let response = JSON.parse(res);
console.log(response, "response");
if (response.error_code == 0) {
var table = "";
table += ``;
table += `
Sl.No |
QP Code |
Subject Name |
QP Count |
Status |
Allot |
`;
for (let i = 0; i < response.data.length; i++) {
table += `
${i + 1}
|
${response.data[i].FQPCODE}
|
${response.data[i].fsubname}
|
${response.data[i].counts}
|
${conn}
|
Allot
| `;
table += `
`;
response.data[i].FQPCODE = qpcode;
response.data[i].fsubname = subnbame;
response.data[i].counts = totcount;
}
document.getElementById("datatable").innerHTML = table;
$.unblockUI();
} else {
document.getElementById(
"datatable"
).innerHTML = `Data Not Found
`;
$.unblockUI();
}
},
});
}
let arr = [];
let index = 0;
let totalcount = 0;
let grandcount = "";
let grcount = "";
let roomname = "";
function roomallotment(code, names, count, degree, subcode) {
qpcode = code;
subnbame = names;
totcount = count;
totalcount = count;
degree = degree;
subcode = subcode;
arr = [];
index = 0;
$("#modeltable").show();
$("#datatable").hide();
// $.blockUI({
// message:
// "
",
// });
$.ajax({
type: "GET",
url: $host_url + "getRoomdetailQpwise",
data:
"qpcode=" +
code +
"°ree=" +
degree +
"&subcode=" +
subcode +
"&grandcount=" +
count,
success: function (res) {
let response = JSON.parse(res);
console.log(response, "respo");
if (response.error_code == 0) {
var table1 = "";
var grcount = "";
table1 += ``;
// document.getElementById(
// "grandtotal"
// ).innerHTML += `${response.data.grcount} | `;
$("#grandtotal").append(grcount);
// $.unblockUI();
}
document.getElementById("modeltable").innerHTML = table1;
// document.getElementById("grandtotal").innerHTML =
// `Total Count: ` +
// count +
// `  Remaning: ` +
// grcount;
for (let ind = 0; ind < response.data.data.length; ind++) {
$("#savebutton").show();
opt = "";
opt += ``;
for (let i = 0; i < response.data.opt.length; i++) {
opt += ``;
}
document.getElementById("roomname_" + ind).innerHTML = opt;
document.getElementById("roomname_" + ind).value =
response.data.data[ind]["froomno"] +
"-" +
response.data.data[ind]["fcapacity"];
document.getElementById("capacity_" + ind).value =
response.data.data[ind]["fcapacity"];
document.getElementById("remain_" + ind).value =
response.data.data[ind]["fbalance"];
document.getElementById("allot_" + ind).value =
response.data.data[ind]["fallot"];
// allotvalue(ind, count);
index += 1;
}
},
});
}
// function checkRemaining(index, count) {
// let remaining = document.getElementById("remain_" + index).value;
// let capacity = document.getElementById("capacity_" + index).value;
// if (parseInt(remaining) > parseInt(count)) {
// alert(`Qp code count is only ${count}`);
// return;
// }
// if (parseInt(remaining) > parseInt(capacity)) {
// alert(`capacity is only ${capacity}`);
// return;
// }
// }
function addRow(options, count, grcount) {
$("#savebutton").show();
var table1 = `
|
| ;
|
|
|
`;
$("#qpbody").append(table1);
opt = "";
opt += ``;
for (let i = 0; i < options.length; i++) {
opt += ``;
}
document.getElementById("roomname_" + index).innerHTML = opt;
let obj = {};
obj.froomname = "";
obj.fcapacity = "";
obj.fallot = "";
obj.fbalance = "";
obj.froomno = "";
obj.fdegree = "";
obj.fsubcode = "";
obj.index = index;
arr.push(obj);
index += 1;
}
function newRow(data, i, count) {
if (document.getElementById("allot_" + i).value === "") {
alert("cannot add new row");
return false;
}
if (i + 1 == index) {
addRow(data, i);
}
arr[i]["fallot"] = document.getElementById("allot_" + i).value;
console.log(count, "addcount");
}
function allotvalue(index, count, grcount) {
var allot = document.getElementById("allot_" + index).value;
let roomname = document.getElementById("roomname_" + index).value;
let split = roomname.split("-");
let roomno = split[0];
arr[index]["fallot"] = allot;
var capacity = document.getElementById("capacity_" + index).value;
var balance = capacity - allot;
document.getElementById("remain_" + index).value = balance;
arr[index]["fbalance"] = balance;
if (parseInt(allot) > parseInt(capacity)) {
alert("Enter Valid Number");
document.getElementById("allot_" + index).value = "";
document.getElementById("allot_" + index).focus();
return;
}
// let remaining = document.getElementById("remain_" + index).value;
// let allot = document.getElementById("allot_" + index).value;
// let grandcount = parseInt(count) - parseInt(allot);
// console.log(count, grandcount, "52count");
// document.getElementById("grandtotal").innerHTML =
// `Total Count: ` +
// count +
// `  Remaning: ` +
// grandcount;
// if (parseInt(allot) > parseInt(remaining)) {
// alert(`Remaining capacity is only ${remaining}`);
// document.getElementById("allot_" + index).value = "";
// return;
// }
// if (parseInt(allot) > parseInt(count)) {
// alert(`QP code count is only ${count}`);
// document.getElementById("allot_" + index).value = "";
// return;
// }
// if (allot == "" || allot == 0 || isNaN(allot)) {
// document.getElementById("remain_" + index).value =
// arr[index]["prevRemaining"];
// return;
// }
// if (parseInt(allot) > parseInt(arr[index]["prevRemaining"])) {
// alert("cannot be set more than remaining values");
// return;
// }
arr[index]["fallot"] = allot;
let remain = parseInt(arr[index]["prevRemaining"]) - parseInt(allot);
document.getElementById("remain_" + index).value = remain;
arr[index]["fallot"] = allot;
arr[index]["fbalance"] = remain;
console.log(arr);
console.log(grcount, roomname, "grigrogriogrio");
$.ajax({
type: "GET",
url: $host_url + "getTotalRemaining",
data:
"&allot=" +
allot +
"&qpcount=" +
totalcount +
"&qpcode=" +
qpcode +
"&roomno=" +
roomno,
success: function (res) {
let response = JSON.parse(res);
console.log(response, "ebdcb");
document.getElementById("grandtotal").innerHTML =
`Total Count: ` +
totalcount +
`  Remaning: ` +
response.data.grcount;
},
});
}
function getroomcapacity(index) {
let roomname = document.getElementById("roomname_" + index).value;
console.log(roomname);
let split = roomname.split("-");
let capacity = split[1];
let roomno = split[0];
document.getElementById("capacity_" + index).value = capacity;
if (index == arr[index]["index"]) {
arr[index]["fcapacity"] = capacity;
arr[index]["froomno"] = roomno;
}
$.blockUI({
message:
"
",
});
$.ajax({
type: "GET",
url: $host_url + "getRemainingCapacity",
data: "capacity=" + split[1] + "&roomno=" + split[0],
success: function (res) {
let response = JSON.parse(res);
console.log(response);
if (response.error_code == 0) {
document.getElementById("remain_" + index).value =
response.data.fbalance;
arr[index]["prevRemaining"] = response.data.fbalance;
$.unblockUI();
}
},
});
}
function checkRemaingValue(index) {
let roomname = document.getElementById("roomname_" + index).value;
let split = roomname.split("-");
let roomno = split[0];
// console.log(arr[index]["prevRemaining"], "arr[index]");
let allot = document.getElementById("allot_" + index).value;
let remaining = document.getElementById("remain_" + index).value;
console.log(allot, "alloting");
if (allot == "" || allot == 0 || isNaN(allot)) {
document.getElementById("remain_" + index).value =
arr[index]["prevRemaining"];
}
}
function closeModelTable() {
$("#modeltable").hide();
$("#datatable").show();
index = 0;
}
let count = 0;
function saveroomallotmentqpwise() {
count = 0;
for (let i = 0; i < arr.length; i++) {
if (arr[i]["fallot"] != "" && arr[i]["fdeleted"] != true) {
count += parseInt(arr[i]["fallot"]);
}
}
if (count > totalcount) {
alert("Allotment exceeded");
return;
}
let rdate = document.getElementById("rdate").value;
let formdata = new FormData();
formdata.append("rdate", rdate);
formdata.append("qpcode", qpcode);
formdata.append("data", JSON.stringify(arr));
console.log(arr, "arrayayayaya");
// $.blockUI({
// message:
// "
",
// });
$.ajax({
type: "POST",
url: $host_url + "postToTable",
data: formdata,
contentType: false,
processData: false,
cache: false,
success: function (res) {
let response = JSON.parse(res);
console.log(response, "hihi");
if (response.error_code == 0) {
alert(response.data.msg);
roomallotment(qpcode, subnbame, totcount, degree, subcode);
$("#modeltable").show();
$("#datatable").show();
// $.unblockUI();
return;
} else {
alert(response.data.msg);
// $.unblockUI();
return;
}
},
});
}
function handledelete(i) {
if (i == arr[i]["index"]) {
arr[i]["fdeleted"] = document.getElementById("del_chk_" + i).checked;
}
console.log(arr);
}