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

", }); $.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 += ``; for (let i = 0; i < response.data.length; i++) { opt += ``; } 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: "

", }); $.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 += ``; 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 += ` `; } $.unblockUI(); } else { table += ``; $.unblockUI(); } table += `
Room Allotment
Sl.No QP Code Subject Name QP Count Status Allot
${index + 1} ${res.data[index].fqpcode} ${ res.data[index].fsubname } ${res.data[index].counts} ${status} Allot Reset
No data found
`; $("#roomAllotData").html(table); }, }); } function addItem() { console.log(arr, options); let table = ""; table += ``; for (let i = 0; i < arr.length; i++) { let disabled = arr[i]["fdisabled"] ? "disabled" : ""; table += ``; slno = i; } $.unblockUI(); table += `
x
QP CODE
Subject Name
Total Count
Allotted Count
Remaining Count Add+
Current Allot
Roomname Capacity Allotted Remaining Allot
Save
`; $("#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 = ``; if (options.length > 0) { for (let i = 0; i < arr.length; i++) { for (let j = 0; j < options.length; j++) { opt += ``; } 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 = ""; } $.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: "

", }); $.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 = ` // // ; // // // // // `; // $("#allot_tbody").append(tr); // ////options///// // opt = ""; // opt += ``; // for (let i = 0; i < options.length; i++) { // opt += ``; // } // $("#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: "

", }); $.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: "

", }); $.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: "

", }); $.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; } }, }); }