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.191.28.200
Current Path : /var/www/oasis/js/ |
| Current File : /var/www/oasis/js/roomallotmentqpwisenew.js |
let arr = [];
let options = [];
let slno = 0;
let allot_qpcode = "";
let allot_subname = "";
let allot_count = "";
let qp_alloted_count = "";
let qp_remain_count = "";
let curr_allot = 0;
function callEnableRoomAllotmentQpWiseNew() {
$("#page_main_div").load(
"../html_modules/roomallotmentqpwisenew.html?v=1",
function () {
document.getElementById("display_module_name").innerHTML =
"Room Allotment QPwise";
document.getElementById("module_name_for_save").value =
"Room Allotment QPwise";
getDefaultHeadFooterLinks("Room Allotment QPwise New");
arr = [];
options = [];
slno = 0;
allot_qpcode = "";
allot_subname = "";
allot_count = "";
qp_alloted_count = "";
qp_remain_count = "";
curr_allot = 0;
}
);
}
function getRoomAllotmentdate() {
let allot_date = document.getElementById("allot_date").value;
$.blockUI({
message:
"<h1 class='h1' style='font-size:12px'><img src='img/ajax-loader.gif' border='0'></h1>",
});
$.ajax({
type: "GET",
url: $host_url + "getRoomAllotmentdate",
data: "date=" + allot_date,
success: function (res) {
let response = JSON.parse(res);
console.log(response);
if (response.error_code === 0) {
opt = "";
opt += `<option>---Select---</option>`;
for (let i = 0; i < response.data.length; i++) {
opt += `<option value="${response.data[i].fsession}">${response.data[i].fsession} - ${response.data[i].fdescpn}</option>`;
}
document.getElementById("allot_session").innerHTML = opt;
$.unblockUI();
} else {
alert(response.data.msg);
$.unblockUI();
return;
}
},
});
}
function getRoomAllotmentData() {
$("#roomAllotData").show();
$("#roomAllotQpData").hide();
let allot_date = document.getElementById("allot_date").value;
let allot_session = document.getElementById("allot_session").value;
if (allot_date == "") {
alert("Enter Date");
return;
} else if (allot_session == "" || allot_session == "---Select---") {
alert("select Session");
document.getElementById("allot_session").focus();
return;
}
$.blockUI({
message:
"<h1 class='h1' style='font-size:12px'><img src='img/ajax-loader.gif' border='0'></h1>",
});
$.ajax({
type: "GET",
url: $host_url + "getQpRoomAllotmentData",
data: "date=" + allot_date + "&session=" + allot_session,
success: function (params) {
let res = JSON.parse(params);
console.log(res);
let table = `<table style='width: 100%;'>`;
table += `<thead>
<tr>
<th colspan='6' align='left' class='ui-jqgrid-titlebar ui-widget-header ui-corner-tl ui-corner-tr ui-helper'>Room Allotment</th>
</tr>
<tr align='center' class='ui-state-default ui-jqgrid-hdiv' style='position: sticky; top: 0;'>
<th >Sl.No</th>
<th >QP Code</th>
<th>Subject Name</th>
<th>QP Count</th>
<th>Status</th>
<th>Allot</th>
</tr>
</thead><tbody>`;
if (res.error_code === 0) {
for (let index = 0; index < res.data.length; index++) {
let status =
res.data[index].counts == res.data[index].qpcount
? "Completed"
: "Pending";
table += ` <tr align='center'>
<td class='border'>${index + 1}</td>
<td class='border'>${res.data[index].fqpcode}</td>
<td class='border' style="text-align:left">${
res.data[index].fsubname
}</td>
<td class='border'>${res.data[index].counts}</td>
<td class='border' >${status}</td>
<td class='border'><span class="btn" onclick="allotQpCode('${
res.data[index].fqpcode
}', '${res.data[index].fsubname}','${res.data[index].counts}', '${
res.data[index].qpcount
}','${
res.data[index].fremaingcount
}')">Allot</span> <span class="btn" onclick="reSetAllotedData('${
res.data[index].fqpcode
}','${res.data[index].fsubcode}','${
res.data[index].qpcount
}')">Reset</span></td>
</tr>`;
}
$.unblockUI();
} else {
table += `<tr align='center'>
<td colspan='6'>No data found</td>
</tr>`;
$.unblockUI();
}
table += `</tbody></table>`;
$("#roomAllotData").html(table);
},
});
}
function addItem() {
console.log(arr, options);
let table = "";
table += `<table style="width:100%">
<thead>
<tr>
<th colspan='6' class='ui-jqgrid-titlebar ui-widget-header ui-corner-tl ui-corner-tr ui-helper'>
<div style="display: flex; justify-content: space-between; align-items: center;">
<span style="cursor: pointer; margin-left: 98.5%;" onclick='closeModelTable()'>x</span>
</div>
</th>
</tr>
<tr><td>QP CODE</td><td colspan='3'><input class='text' type='text' value='' id='allot_qpcode' disabled/></td></tr>
<tr><td>Subject Name</td><td colspan='3'><input class='text' type='text' value='' id='allot_subname' disabled/></td></tr>
<tr><td>Total Count</td><td colspan='3'><input class='text' type='text' value='' id='allot_count' disabled/></td></tr>
<tr><td>Allotted Count</td><td colspan='3'><input class='text' type='text' value='' id='qp_alloted_count' disabled/></td></tr>
<tr><td>Remaining Count</td><td colspan='3'><input class='text' type='text' value='' id='qp_remain_count' disabled/>
</td>
<td> <span style="cursor: pointer;" onclick='addRow()' class='btn'>Add+</span></td>
</tr>
<tr>
<td>
Current Allot
</td>
<td colspan='3'><input class='text' type='text' value='' id='curr_allot' disabled/>
</tr>
<tr>
<tr style='text-align: center; height: 25px;' class='ui-state-default ui-jqgrid-hdiv'>
<td style='width:20%;'>Roomname</td>
<td style='width:20%;'>Capacity</td>
<td style='width:20%;'>Allotted</td>
<td style='width:20%;'>Remaining</td>
<td style='width:20%;'>Allot</td>
</tr>
</tr>
</thead>
<tbody id='allot_tbody'>`;
for (let i = 0; i < arr.length; i++) {
let disabled = arr[i]["fdisabled"] ? "disabled" : "";
table += `<tr id='row_${i}'>
<td style='text-align:center; border: 1px solid #ddd; padding: 8px;'><select class='select' id='room_name_${i}' onchange='getRoomCapacity(${i})' ${disabled}></select></td>
<td style='text-align:center; border: 1px solid #ddd; padding: 8px;'><input class='input' type='text' value='' id='room_capacity_${i}' disabled/></td>
<td style='text-align:center; border: 1px solid #ddd; padding: 8px;'><input class='input' type='text' value='${arr[i]["falloted"]}' id='allotted_${i}' disabled/></td>
<td style='text-align:center; border: 1px solid #ddd; padding: 8px;'><input class='input' type='text' value='${arr[i]["fbalance"]}' id='remaining_capacity_${i}' disabled/></td>
<td style='text-align:center; border: 1px solid #ddd; padding: 8px;'><input id="allot_${i}" value='${arr[i]["fallot"]}' oninput="checkTotRemaining('${i}')" onblur='checkQpRemaingValue(${i})' class="input"/></td>
</tr>`;
slno = i;
}
$.unblockUI();
table += `</tbody></table>
<div style='display: flex; justify-content: center; padding: 20px;' > <span class='btn' onclick="saveQpRoomAllotment()" >Save</span></div>`;
$("#roomAllotQpData").html(table);
$("#allot_qpcode").val(allot_qpcode);
$("#allot_subname").val(allot_subname);
$("#allot_count").val(allot_count);
$("#qp_alloted_count").val(qp_alloted_count);
$("#qp_remain_count").val(qp_remain_count);
$("#curr_allot").val(curr_allot);
//////////options for select//////////
let opt = `<option value=''>---select---</option>`;
if (options.length > 0) {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < options.length; j++) {
opt += `<option value="${
options[j].froomno + "-" + options[j].fcapacity
}" >${options[j].froomname}</option>`;
}
document.getElementById("room_name_" + i).innerHTML = opt;
////////Assign Values//////
let data = arr[i];
$("#room_name_" + i).val(data["froomno"] + "-" + data["fcapacity"]);
$("#room_capacity_" + i).val(data["fcapacity"]);
// $("#remaining_capacity_" + i).val(data["fbalance"]);
// $("#allotted_" + i).val(data["falloted"]);
// $("#allot_" + i).val(data["fallot"]);
opt = "<option value=''>---select---</option>";
}
$.unblockUI();
}
}
function allotQpCode(qpcode, subname, count, qpcount, remcount) {
$("#roomAllotQpData").show();
let allot_date = document.getElementById("allot_date").value;
let allot_session = document.getElementById("allot_session").value;
arr = [];
options = [];
curr_allot = 0;
$.blockUI({
message:
"<h1 class='h1' style='font-size:12px'><img src='img/ajax-loader.gif' border='0'></h1>",
});
$.ajax({
type: "GET",
url: $host_url + "getQpRoomAllotment",
data:
"qpcode=" + qpcode + "&date=" + allot_date + "&session=" + allot_session,
success: function (params) {
let res = JSON.parse(params);
console.log(res.data, "hii");
if (res.data.data.length > 0) {
for (let i = 0; i < res.data.data.length; i++) {
let obj = {};
obj.fallot = "";
obj.fbalance = res.data.data[i].fbalance;
obj.fprevRemaining = res.data.data[i].fbalance;
obj.fcapacity = res.data.data[i].fcapacity;
obj.froomname = res.data.data[i].froomname;
obj.froomno = res.data.data[i].froomno;
obj.falloted = res.data.data[i].fallot;
obj.fdisabled = true;
arr.push(obj);
}
} else {
let obj = {};
obj.fallot = "";
obj.fbalance = "";
obj.fprevRemaining = "";
obj.fcapacity = "";
obj.froomname = "";
obj.froomno = "";
obj.falloted = "";
arr.push(obj);
}
if (res.data.options.length > 0) {
for (let index = 0; index < res.data.options.length; index++) {
let obj = {};
obj.froomname = res.data.options[index].froomname;
obj.froomno = res.data.options[index].froomno;
obj.fcapacity = res.data.options[index].fcapacity;
options.push(obj);
}
} else {
alert("No room data found");
$.unblockUI();
return;
}
allot_qpcode = qpcode;
allot_subname = subname;
allot_count = count;
qp_alloted_count = qpcount;
qp_remain_count = remcount;
addItem();
$.unblockUI();
},
});
}
function addRow() {
if (
arr[arr.length - 1]["fallot"] == "" &&
arr[arr.length - 1]["falloted"] == ""
) {
alert("please enter number to be allotted");
return;
}
let obj = {};
obj.fallot = "";
obj.fbalance = "";
obj.fcapacity = "";
obj.froomname = "";
obj.froomno = "";
obj.falloted = "";
arr.push(obj);
addItem();
}
function checkQpRemaingValue(i) {
let allot = $("#allot_" + i).val();
let totRemaining = arr[i]["fprevRemaining"];
// let remaining_capacity = $("#remaining_capacity_" + i).val();
// let allot = $("#allot_" + i).val();
let roomname = $("#room_name_" + i).val();
if (roomname === "") {
alert("select room name");
return;
}
if (allot === "") {
alert("Enter number to be allotted");
return;
}
if (parseInt(allot) > parseInt(totRemaining)) {
alert(`remaining capacity for this room only ${totRemaining}`);
arr[i]["fallot"] = "";
arr[i]["fbalance"] = totRemaining;
document.getElementById("allot_" + i).value = 0;
document.getElementById("allot_" + i).focus();
return;
}
let rem = parseInt(totRemaining) - parseInt(allot);
arr[i]["fbalance"] = rem;
arr[i]["fallot"] = allot;
let tot = 0;
for (let index = 0; index < arr.length; index++) {
tot += arr[index]["fallot"] == "" ? 0 : parseInt(arr[index]["fallot"]);
}
console.log(tot, qp_remain_count, "qp_remain_count");
if (parseInt(tot) > parseInt(qp_remain_count)) {
alert(`you can allot for this qpcode upto ${qp_remain_count}`);
arr[i]["fallot"] = "";
arr[i]["fbalance"] = totRemaining;
document.getElementById("allot_" + i).value = "";
// addItem();
return;
}
curr_allot = tot;
addItem();
console.log(arr);
if (i === slno) {
addRow();
}
}
function getRoomCapacity(i) {
let roomname = $("#room_name_" + i).val();
let split = roomname.split("-");
let roomno = [];
for (let i = 0; i < arr.length; i++) {
if (arr[i].froomno === split[0]) {
roomno.push(split[0]);
}
}
if (roomno.length > 0) {
alert("room already selected please allot");
$("#room_name_" + i).val("");
return;
}
$("#room_capacity_" + i).val(split[1]);
arr[i]["froomno"] = split[0];
arr[i]["fcapacity"] = split[1];
$.ajax({
type: "GET",
url: $host_url + "getQPRoomCapacity",
data: "roomno=" + split[0] + "&capacity=" + split[1],
success: function (params) {
let res = JSON.parse(params);
console.log(res);
// $("#remaining_capacity_" + i).val(res.data.fbalance);
arr[i]["fprevRemaining"] = res.data.fbalance;
arr[i]["fbalance"] = res.data.fbalance;
// $("#allotted_" + i).val(res.data.fallotted);
arr[i]["falloted"] = res.data.fallotted;
addItem();
},
});
}
// function addRow(options) {
// console.log(options, slno, "HHV");
// var tr = `<tr id='row_${slno}'>
// <td style='text-align:center; border: 1px solid #ddd; padding: 8px;'><select id="room_name_${slno}" onchange="getRoomCapacity('${slno}')" class="select"></select></td>
// <td style='text-align:center; border: 1px solid #ddd; padding: 8px;'><input id="room_capacity_${slno}" class="input" disabled/></td>;
// <td style='text-align:center; border: 1px solid #ddd; padding: 8px;'><input id="allotted_${slno}" class="input" disabled/></td>
// <td style='text-align:center; border: 1px solid #ddd; padding: 8px;'><input id="remaining_capacity_${slno}" class="input" disabled/></td>
// <td style='text-align:center; border: 1px solid #ddd; padding: 8px;'><input id="allot_${slno}" oninput="checkTotRemaining(${slno})" onblur='checkQpRemaingValue(${slno},${JSON.stringify(
// options
// )})' class="input"/></td>
// <td style='text-align:center; border: 1px solid #ddd; padding: 8px;'><input type="submit" onkeydown=""></input></td>
// </tr>`;
// $("#allot_tbody").append(tr);
// ////options/////
// opt = "";
// opt += `<option>---Select---</option>`;
// for (let i = 0; i < options.length; i++) {
// opt += `<option value="${
// options[i].froomno + "-" + options[i].fcapacity
// }" >${options[i].froomname}</option>`;
// }
// $("#room_name_" + slno).html(opt);
// let obj = {};
// obj.fqpcode = "";
// obj.froomno = "";
// obj.fallot = "";
// // if (arr.length === 0) {
// // slno += 1;
// // }
// arr.push(obj);
// }
// let rem = 0;
// function checkQpRemaingValue(i, options) {
// console.log(slno, i);
// let allot = $("#allot_" + i).val();
// let select = $("#room_name_" + i).val();
// // if (allot !== "" || isNaN(allot)) {
// // $("#room_name_" + i).val(select);
// // return;
// // } else {
// // addRow(options);
// // }
// let remain = $("#remaining_capacity_" + i).val();
// let qpRemainCount = $("#qp_remain_count").val();
// let qpcode = $("#allot_qpcode").val();
// let capacity = $("#room_capacity_" + i).val();
// let allotted = $("#allotted_" + i).val();
// // if (allot == "" || isNaN(allot)) {
// // let val = parseInt(capacity) - parseInt(allotted);
// // $("#remaining_capacity_" + i).val(val);
// // return;
// // } else {
// // let val = parseInt(capacity) - (parseInt(allotted) + parseInt(allot));
// // $("#remaining_capacity_" + i).val(val);
// // }
// // if (parseInt(allot) > parseInt(remain)) {
// // $("#qp_remain_count").val(reamin_count);
// // alert(`you can allot only in this room upto ${remain}`);
// // $("#allot_" + i).val("");
// // return;
// // }
// if (parseInt(allotted) + parseInt(allot) > parseInt(capacity)) {
// let val = parseInt(capacity) - parseInt(allotted);
// $("#remaining_capacity_" + i).val(val);
// alert("Enter valid number");
// $("#allot_" + i).val("");
// return;
// }
// if (parseInt(allot) > parseInt(reamin_count)) {
// $("#qp_remain_count").val(reamin_count);
// alert(`Qp code Remaining count is only ${reamin_count}`);
// $("#allot_" + i).val("");
// return;
// }
// if (parseInt(allot) <= 0) {
// alert(`Enter valid number`);
// $("#allot_" + i).val("");
// return;
// }
// let reamin_count1 = parseInt(reamin_count) - parseInt(allot);
// $("#qp_remain_count").val(reamin_count1);
// if (select == "---Select---") {
// alert("select Roomname");
// $("#room_name_" + i).focus();
// return;
// } else if (allot == "") {
// alert("Add allot number here");
// $("#qp_remain_count").val(reamin_count);
// return;
// }
// arr[i]["fqpcode"] = qpcode;
// arr[i]["fallot"] = allot;
// reamin_count = rem;
// if (slno === i) {
// slno += 1;
// addRow(options);
// }
// }
// function checkTotRemaining(index) {
// let allot = $("#allot_" + index).val();
// let capacity = $("#room_capacity_" + index).val();
// let allotted = $("#allotted_" + index).val();
// let reamin_count1 = parseInt(reamin_count) - parseInt(allot);
// reamin_count1 = isNaN(reamin_count1) ? reamin_count : reamin_count1;
// $("#qp_remain_count").val(reamin_count1);
// let recapacity = $("#remaining_capacity_" + index).val();
// if (recapacity == "" || isNaN(recapacity)) {
// let remcapacity = parseInt(allotted) - parseInt(capacity) - parseInt(allot);
// $("#remaining_capacity_" + index).val(remcapacity);
// }
// if (allot == "" || isNaN(allot)) {
// let capacity = $("#room_capacity_" + index).val();
// let allotted = $("#allotted_" + index).val();
// let val = parseInt(capacity) - parseInt(allotted);
// $("#remaining_capacity_" + index).val(val);
// } else {
// let capacity = $("#room_capacity_" + index).val();
// let allotted = $("#allotted_" + index).val();
// let val = parseInt(capacity) - (parseInt(allotted) + parseInt(allot));
// $("#remaining_capacity_" + index).val(val);
// }
// rem = reamin_count1;
// }
function saveQpRoomAllotment() {
// $("#roomAllotData").show();
// $("#roomAllotQpData").hide();
let date = $("#allot_date").val();
let qpcode = $("#allot_qpcode").val();
console.log(arr);
$.blockUI({
message:
"<h1 class='h1' style='font-size:12px'><img src='img/ajax-loader.gif' border='0'></h1>",
});
$.ajax({
type: "POST",
url: $host_url + "saveQpRoomAllotment",
data: "data=" + JSON.stringify(arr) + "&date=" + date + "&qpcode=" + qpcode,
success: function (params) {
let res = JSON.parse(params);
if (res.error_code === 0) {
alert(res.data.msg);
getRoomAllotmentData();
$.unblockUI();
} else {
alert(res.data.msg);
$.unblockUI();
return;
}
},
});
}
function closeModelTable() {
$("#roomAllotData").show();
$("#roomAllotQpData").hide();
}
function reSetAllotedData(qpcode, subcode, count) {
let allot_date = document.getElementById("allot_date").value;
let allot_session = document.getElementById("allot_session").value;
$.blockUI({
message:
"<h1 class='h1' style='font-size:12px'><img src='img/ajax-loader.gif' border='0'></h1>",
});
$.ajax({
type: "GET",
url: $host_url + "viewAllotedData",
data:
"&date=" +
allot_date +
"&session=" +
allot_session +
"&code=" +
qpcode +
"&subcode=" +
subcode +
"&count=" +
count,
success: function (res) {
let response = JSON.parse(res);
console.log(response, "hii");
if (response.error_code == 0) {
alert(response.data.msg);
getRoomAllotmentData();
$.unblockUI();
return;
} else {
alert(response.data.msg);
$.unblockUI();
return;
}
},
});
}
// function handlerback() {
// $("#viwedata_alloted").hide();
// getRoomAllotmentData();
// }
function roomAllotmentDataReset() {
let allot_date = document.getElementById("allot_date").value;
let allot_session = document.getElementById("allot_session").value;
if (allot_date == "") {
alert("Enter Date");
return;
} else if (allot_session == "" || allot_session == "---Select---") {
alert("select Session");
document.getElementById("allot_session").focus();
return;
}
if (!confirm("Are you sure you want to reset the data?")) {
return;
}
$.blockUI({
message:
"<h1 class='h1' style='font-size:12px'><img src='img/ajax-loader.gif' border='0'></h1>",
});
$.ajax({
type: "GET",
url: $host_url + "resetBalanceOfRoomAllotmentData",
data: "date=" + allot_date + "&session=" + allot_session,
success: function (params) {
let res = JSON.parse(params);
if (res.error_code == 0) {
alert(res.data.msg);
$.unblockUI();
return;
} else {
alert(res.data.msg);
$.unblockUI();
return;
}
},
});
}
|