| Current Path : /var/www/html/mmishra/erp/models/ |
| Current File : /var/www/html/mmishra/erp/models/hms_model.php |
<?php
//if (!class_exists($erpModel)) {
require_once __DIR__."/erp_model.php";
//}
class hmsModel extends erpModel {
public function __construct() {
// mysql connection using PDO
try {
$this->pdo = new PDO('mysql:host=' .DB_SERVER. ';dbname=' .DB_NAME. ';charset=utf8', DB_USER, DB_PASSWD, $options);
$this->pdo->query("use erp_hms");
} catch (PDOException $e) {
die("Error!: " . $e->getMessage());
}
}
public function __destruct() {
//print mysql_error();
$this->dbStmt = null;
$this->pdo = null;
}
//***********************************************************************
//* hms Dashboard data *
//***********************************************************************
/*
function hmsDashboard(&$programs, &$fees, &$candidates, &$applicants, &$students, &$slidding, &$withdrawns) {
$this->dbStmt = $this->pdo->prepare("SELECT degreeLevel,COUNT(programID) AS no FROM erp_hms.hms_programs WHERE instituteID=" .$_SESSION["instituteID"]. " GROUP BY degreeLevel");
if ($this->dbStmt->execute()) {
$rows = $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
$programs = $rows;
}
$this->dbStmt = $this->pdo->prepare("SELECT p.programCode,CASE WHEN category = '*' THEN 'All' ELSE category END AS Cat,SUM(f.feeAmount) AS amount FROM erp_hms.hms_feeheads AS f LEFT JOIN erp_hms.hms_programs AS p ON f.programID=p.programID WHERE f.accountType=1 AND f.paymentTerm<9 GROUP BY f.programID,f.category");
if ($this->dbStmt->execute()) {
$rows = $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
$fees = $rows;
}
return $data;
}
function listBatches() {
$this->dbStmt = $this->pdo->query("SELECT DISTINCT batchYear FROM erp_hms.hms_enrolments ORDER BY batchYear");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
//***********************************************************************
//* hms alert functions *
//***********************************************************************
function saveAlert($subjectID,$message,$emailsTo,$emailsCC,$emailsBCC,$targetGroups,$schedule) {
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE alertID=" .$this->tupleID)->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET subjectID=$subjectID,message='$message',emailsTo='$emailsTo',emailsCC='$emailsCC',emailsBCC='$emailsBCC',targetGroups='$targetGroups',schedule='$schedule'
WHERE alertID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
} else{
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(subjectID,message,attachments,emailsTo,emailsCC,emailsBCC,targetGroups,schedule)
value($subjectID,'$message','$attachments','$emailsTo','$emailsCC','$emailsBCC','$targetGroups','$schedule')";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
}
}
function updateAlert($alertID) {
// reset dateXalert timestamp automatically on each update
$this->sqlStmt = "UPDATE erp_hms.hms_autoalerts SET alertCounter=alertCounter+1 WHERE alertID=" .$alertID;
$this->pdo->exec($this->sqlStmt);
}
function saveAlertAttachments($alertID,$attachments) {
$this->sqlStmt = "UPDATE erp_hms.hms_autoalerts SET attachments=CONCAT(attachments, ',', '$attachments') WHERE alertID=" .$alertID;
$this->pdo->exec($this->sqlStmt);
}
function removeAlertAttachments($alertID,$attachment) {
$this->sqlStmt = "UPDATE erp_hms.hms_autoalerts SET attachments=REPLACE(attachments, '$attachment,', ''),attachments=REPLACE(attachments, '$attachment', '') WHERE alertID=" .$alertID;
$this->pdo->exec($this->sqlStmt);
}
function enableAlert() {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='Enabled' WHERE alertID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function disableAlert() {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='Disabled' WHERE alertID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function deleteAlert() {
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE alertID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function getAlert($alertID=0) {
if ($alertID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_autoalerts WHERE alertID=$alertID");
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
return $row;
}
function listAlerts() {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_autoalerts ORDER BY subjectID");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
function selectAlert() {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_autoalerts WHERE status='Enabled' ORDER BY subjectID");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
// list defaulters
//public $reminders = [1 => 'Document overdue reminder',2 => 'Fees overdue reminder',3 => 'Mess-charge overdue reminder',4 => 'Name correction for degree',5 => 'Photo submission for degree',6 => 'Arrival plan submission for convocation']; // used to generate auto alerts (email/sms)
function listDefaulters($programID, $subjectID=0) {
switch ($subjectID) {
case 1: //document overdue
$this->dbStmt = $this->pdo->query("SELECT enrolmentNo,nameEnglish,nameHindi,e.category,e.phoneNo,e.email,x.docheadCode,d.docheadName,x.remark
FROM erp_hms.hms_exemptions AS x LEFT JOIN hms_docheads AS d ON x.docheadCode=d.docheadCode AND x.docheadCode NOT IN (1, 2) LEFT JOIN erp_hms.hms_enrolmentsv AS e ON x.studentID=e.studentID
WHERE batchYear=" .$_SESSION["batchYear"]. " AND e.programID=$programID AND e.estatus='Enrolled' AND x.docheadCode NOT IN (1,2) ORDER BY e.enrolmentNo");
break;
case 2: // fees overdue
$this->dbStmt = $this->pdo->query("SELECT enrolmentNo,nameEnglish,nameHindi,e.category,e.phoneNo,e.email,docheadCode,CASE docheadCode WHEN '1' THEN 'Fees' ELSE 'Mess' END AS docheadName, x.remark
FROM erp_hms.hms_exemptions AS x LEFT JOIN erp_hms.hms_enrolmentsv AS e ON x.studentID=e.studentID
WHERE batchYear=" .$_SESSION["batchYear"]. " AND e.programID=$programID AND e.estatus='Enrolled' AND x.docheadCode='1' ORDER BY e.enrolmentNo");
break;
case 3: // messcharge overdue
$this->dbStmt = $this->pdo->query("SELECT enrolmentNo,nameEnglish,nameHindi,e.category,e.phoneNo,e.email,docheadCode,CASE docheadCode WHEN '1' THEN 'Fees' ELSE 'Mess' END AS docheadName, x.remark
FROM erp_hms.hms_exemptions AS x LEFT JOIN erp_hms.hms_enrolmentsv AS e ON x.studentID=e.studentID
WHERE batchYear=" .$_SESSION["batchYear"]. " AND e.programID=$programID AND e.estatus='Enrolled' AND x.docheadCode='2' ORDER BY e.enrolmentNo");
break;
case 4: // name correction for degree
$this->dbStmt = $this->pdo->query("SELECT enrolmentNo,nameEnglish,nameHindi,e.category,e.phoneNo,e.email,d.docheadName
FROM erp_hms.hms_exemptions AS x LEFT JOIN hms_docheads AS d on x.docheadCode=d.docheadCode LEFT JOIN erp_hms.hms_enrolmentsv AS e ON x.studentID=e.studentID
WHERE batchYear=" .$_SESSION["batchYear"]. " AND e.programID=$programID AND e.estatus='Enrolled' ORDER BY e.enrolmentNo");
break;
case 5: // photo submission for degree
$this->dbStmt = $this->pdo->query("SELECT enrolmentNo,nameEnglish,nameHindi,e.category,e.phoneNo,e.email,d.docheadName
FROM erp_hms.hms_exemptions AS x LEFT JOIN hms_docheads AS d on x.docheadCode=d.docheadCode LEFT JOIN erp_hms.hms_enrolmentsv AS e ON x.studentID=e.studentID
WHERE batchYear=" .$_SESSION["batchYear"]. " AND e.programID=$programID AND e.estatus='Enrolled' ORDER BY e.enrolmentNo");
break;
case 6: // arrival plan submission for convocation
$this->dbStmt = $this->pdo->query("SELECT enrolmentNo,nameEnglish,nameHindi,e.category,e.phoneNo,e.email,d.docheadName
FROM erp_hms.hms_exemptions AS x LEFT JOIN hms_docheads AS d on x.docheadCode=d.docheadCode LEFT JOIN erp_hms.hms_enrolmentsv AS e ON x.studentID=e.studentID
WHERE batchYear=" .$_SESSION["batchYear"]. " AND e.programID=$programID AND e.estatus='Enrolled' ORDER BY e.enrolmentNo");
break;
default:
$this->dbStmt = $this->pdo->query("SELECT *
FROM erp_hms.hms_enrolmentsv
WHERE batchYear=" .$_SESSION["batchYear"]. " AND programID=$programID AND estatus='Enrolled' ORDER BY enrolmentNo");
break;
}
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
*/
//***********************************************************************
//* hms hostel functions *
//***********************************************************************
function saveHostel($hostelCode,$hostelName,$hostelType,$totalFloors,$totalCapacity,$singleBedded,$doubleBedded,$tripleBedded,$apartment,$suite,$receptionNo) {
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE hostelID=" .$this->tupleID)->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET hostelCode='$hostelCode',hostelName='$hostelName',hostelType='$hostelType',totalFloors=$totalFloors,totalCapacity=$totalCapacity,singleBedded=$singleBedded,doubleBedded=$doubleBedded,tripleBedded=$tripleBedded,apartment=$apartment,suite=$suite,receptionNo=$receptionNo
WHERE hostelID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
} else{
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(hostelCode,hostelName,hostelType,totalFloors,totalCapacity,singleBedded,doubleBedded,tripleBedded,apartment,suite,receptionNo)
value('$hostelCode','$hostelName','$hostelType',$totalFloors,$totalCapacity,$singleBedded,$doubleBedded,$tripleBedded,$apartment,$suite,$receptionNo)";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
}
}
function enableHostel() {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='Enabled' WHERE hostelID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function disableHostel() {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='Disabled' WHERE hostelID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function deleteHostel() {
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE hostelID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function getHostel($hostelID=0) {
if ($hostelID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_hostels WHERE hostelID=$hostelID");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
}
function listHostels() {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_hostels ORDER BY hostelCode");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
function selectHostel() {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_hostels WHERE status='Enabled' ORDER BY hostelCode");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
/* moved to erpModel.php
function selectHostel() {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_hostels WHERE status='Enabled' ORDER BY hostelCode");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
*/
//***********************************************************************
//* hms room functions *
//***********************************************************************
function saveRoom($hostelID,$floorNo,$roomNo,$roomType) {
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE roomID=" .$this->tupleID)->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET hostelID=$hostelID,floorNo=$floorNo,roomNo='$roomNo',roomType=$roomType
WHERE roomID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
} else{
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(hostelID,floorNo,roomNo,roomType)
value($hostelID,$floorNo,'$roomNo',$roomType)";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
}
//echo $this->sqlStmt;
}
function enableRoom() {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='Enabled' WHERE roomID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function disableRoom() {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='Disabled' WHERE roomID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function deleteRoom() {
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE roomID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
/*
function getRoom($roomID=0) {
if ($roomID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_rooms WHERE roomID=$roomID");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
}
*/
function listRooms($hostelID=0) {
if ($hostelID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_rooms WHERE hostelID=$hostelID ORDER BY floorNo,roomNo");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
function selectRoom() {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_rooms WHERE status IN('Vacant','Semi-occupied') ORDER BY floorNo,roomNo");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
function bookRoom($hostelID, $floorNo, $roomType=2) {
if ($hostelID) {
$this->dbStmt = $this->pdo->query("SELECT roomID FROM erp_hms.hms_rooms WHERE hostelID=$hostelID AND floorNo=$floorNo" .($roomType ? " AND roomType=$roomType" : ''). " AND status IN('Vacant', 'Semi-occupied') ORDER BY status DESC, roomID LIMIT 0,1");
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
return $row['roomID'];
}
}
/* moved to erpModel.php
function filterRooms($hostelID, $roomType=0) {
if ($hostelID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_rooms WHERE hostelID=$hostelID" .($roomType ? " AND roomType=$roomType" : ''). " ORDER BY floorNo,roomNo");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
*/
function listFloorRooms($hostelID, $floorNo=0, $roomType=0) {
if ($hostelID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_rooms WHERE hostelID=$hostelID AND floorNo=$floorNo AND roomType=$roomType ORDER BY roomNo");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
function listVacancys($hostelID=0) {
if ($hostelID) {
$this->dbStmt = $this->pdo->query("SELECT roomNo,CASE
WHEN roomType=2 THEN 'Double'
WHEN roomType=3 THEN 'Triple'
ELSE 'Single' END AS Type,status FROM erp_hms.hms_rooms WHERE hostelID=$hostelID AND status IN ('Vacant', 'Semi-occupied') ORDER BY roomNo");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
function listOccupancys($hostelID=0) {
if ($hostelID) {
$this->dbStmt = $this->pdo->query("SELECT roomNo,CASE
WHEN roomType=2 THEN 'Double'
WHEN roomType=3 THEN 'Triple'
ELSE 'Single' END AS Type,status FROM erp_hms.hms_rooms WHERE hostelID=$hostelID AND status IN ('Semi-occupied', 'Occupied') ORDER BY roomNo");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
//***********************************************************************
//* hms allocation functions *
//***********************************************************************
function saveAllocation($hostelID,$floorNo,$programID) {
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(hostelID,floorNo,programID)
value($hostelID,$floorNo,$programID)";
$this->pdo->exec($this->sqlStmt);
}
function deleteAllocation() {
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE programID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function getAllocation($allocationID=0) {
if ($AllocationID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_allocations WHERE allocationID=$allocationID");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
}
function listAllocations($programID=0) {
if ($programID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_allocations WHERE programID=$programID ORDER BY hostelID,floorNo");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
function selectAllocation() {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_allocations WHERE status='Enabled' ORDER BY allocationName");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
//***********************************************************************
//* hms warden functions *
//***********************************************************************
function saveWarden($hostelID,$wardenName,$wardenEmail,$wardenMobile) {
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE wardenID=" .$this->tupleID)->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET hostelID=$hostelID,wardenName='$wardenName',wardenEmail='$wardenEmail',wardenMobile='$wardenMobile'
WHERE wardenID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
} else{
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(hostelID,wardenName,wardenEmail,wardenMobile)
value($hostelID,'$wardenName','$wardenEmail','$wardenMobile')";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
}
}
function enableWarden() {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='Enabled' WHERE wardenID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function disableWarden() {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='Disabled' WHERE wardenID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function deleteWarden() {
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE wardenID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function getWarden($wardenID=0) {
if ($wardenID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_wardens WHERE wardenID=$wardenID");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
}
function listWardens($hostelID=0) {
if ($hostelID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_wardens WHERE hostelID=$hostelID ORDER BY wardenName");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
function selectWarden() {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_wardens WHERE status='Enabled' ORDER BY wardenName");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
//***********************************************************************
//* hms asstt functions *
//***********************************************************************
function saveAsstt($hostelID,$assttName,$assttEmail,$assttMobile) {
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE assttID=" .$this->tupleID)->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET hostelID=$hostelID,assttName='$assttName',assttEmail='$assttEmail',assttMobile='$assttMobile'
WHERE assttID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
} else{
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(hostelID,assttName,assttEmail,assttMobile)
value($hostelID,'$assttName','$assttEmail','$assttMobile')";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
}
}
function enableAsstt() {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='Enabled' WHERE assttID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function disableAsstt() {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='Disabled' WHERE assttID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function deleteAsstt() {
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE assttID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function getAsstt($assttID=0) {
if ($assttID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_assistants WHERE assttID=$assttID");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
}
function listAsstts($hostelID=0) {
if ($hostelID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_assistants WHERE hostelID=$hostelID ORDER BY assttName");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
function selectAsstt() {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_assistants WHERE status='Enabled' ORDER BY assttName");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
//***********************************************************************
//* hms allotment functions *
//***********************************************************************
function saveAllotment($hostelID,$allotteeNo,$roomID,$acCooler) {
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE allotmentID=" .$this->tupleID)->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET hostelID=$hostelID,allotteeNo='$allotteeNo',roomID=$roomID,acCooler='$acCooler',loginID='" .$_SESSION['loginID']. "'
WHERE allotmentID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
} else{
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(hostelID,allotteeNo,roomID,acCooler,loginID)
value($hostelID,'$allotteeNo',$roomID,'$acCooler','" .$_SESSION['loginID']. "')";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
//echo $this->sqlStmt;
// update room status
if ($this->tupleID) {
$room = $this->getRoom($roomID);
if ($room['roomType'] == 1 || $room['roomType'] == 4 || $room['roomType'] == 5) $status = 'Occupied';
if ($room['roomType'] == 2) $status = ($room['status'] == 'Vacant' ? 'Semi-occupied' : 'Occupied');
if ($room['roomType'] == 3) {
$allotments = $this->getAllotmentCountByRoomID($roomID);
$status = ($room['status'] == 'Vacant' ? 'Semi-occupied' : ($allotments < 3 ? 'Semi-occupied' : 'Occupied'));
}
$this->sqlStmt = "UPDATE erp_hms.hms_rooms SET status='$status'
WHERE roomID=$roomID";
$this->pdo->exec($this->sqlStmt);
}
}
//echo $this->sqlStmt;
}
function changeAllotment($allotteeNo) {
if ($allotteeNo) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET allotteeNo='$allotteeNo',loginID='" .$_SESSION['loginID']. "'
WHERE allotmentID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
//echo $this->sqlStmt;
}
}
function enableAllotment() {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='Enabled' WHERE allotmentID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function disableAllotment() {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='Disabled' WHERE allotmentID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function deleteAllotment() {
$allotment = $this->getAllotment($this->tupleID);
$hostelID = $allotment['hostelID'];
$roomID = $allotment['roomID'];
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE allotmentID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
// update room status
$room = $this->getRoom($roomID);
if ($room['roomType'] == 1 || $room['roomType'] == 4 || $room['roomType'] == 5) $status = 'Vacant';
if ($room['roomType'] == 2) $status = ($room['status'] == 'Occupied' ? 'Semi-occupied' : 'Vacant');
if ($room['roomType'] == 3) {
$allotments = $this->getAllotmentCountByRoomID($roomID);
$status = ($room['status'] == 'Occupied' ? 'Semi-occupied' : ($allotments > 1 ? 'Semi-occupied' : 'Vacant'));
}
$this->sqlStmt = "UPDATE erp_hms.hms_rooms SET status='$status'
WHERE roomID=$roomID";
$this->pdo->exec($this->sqlStmt);
}
/*
function getAllotment($allotmentID=0) {
if ($allotmentID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_allotments WHERE allotmentID=$allotmentID");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
}
*/
function listAllotments($hostelID=0) {
if ($hostelID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_allotments WHERE hostelID=$hostelID ORDER BY allotteeNo");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
function filterAllotments($hostelID, $roomID=0) {
if ($hostelID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_allotments WHERE hostelID=$hostelID" .($roomID ? " AND roomID=$roomID" : ''). " ORDER BY allotteeNo");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
function statusAllotment($hostelID=0) {
if ($hostelID) {
$this->dbStmt = $this->pdo->query("SELECT r.floorNo,r.roomNo,r.roomType,r.status,h.hostelCode,e.nameEnglish,a.*
FROM erp_hms.hms_rooms AS r LEFT JOIN erp_hms.hms_hostels AS h ON r.hostelID=h.hostelID LEFT JOIN erp_hms.hms_allotments AS a ON r.roomID=a.roomID LEFT JOIN erp_aaa.aaa_enrolmentsv AS e ON a.allotteeNo=e.enrolmentNo
WHERE r.hostelID=$hostelID ORDER BY r.floorNo,r.roomID,a.allotteeNo ");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
//***********************************************************************
//* hms asset functions *
//***********************************************************************
function saveAsset($allotmentID,$assetName,$description,$approxCost) {
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE assetID=" .$this->tupleID)->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET allotmentID=$allotmentID,assetName='$assetName',description='$description',approxCost=$approxCost
WHERE assetID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
} else{
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(allotmentID,assetName,description,approxCost)
value($allotmentID,'$assetName','$description',$approxCost)";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
}
}
function enableAsset() {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='Enabled' WHERE assetID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function disableAsset() {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='Disabled' WHERE assetID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function deleteAsset() {
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE assetID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function getAsset($assetID=0) {
if ($assetID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_assets WHERE assetID=$assetID");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
}
function listAssets($allotmentID=0) {
if ($allotmentID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_assets WHERE allotmentID=$allotmentID ORDER BY assetName");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
function printAssets($allotmentID=0) {
if ($allotmentID) {
$this->dbStmt = $this->pdo->query("SELECT a.allotteeNo,assetName,description,approxCost,dateDeclaration FROM erp_hms.hms_assets AS s LEFT JOIN erp_hms.hms_allotments AS a ON s.allotmentID=a.allotmentID WHERE s.allotmentID=$allotmentID ORDER BY assetName");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
//***********************************************************************
//* hms gatepass functions *
//***********************************************************************
function saveGatepass($allotmentID,$description,$assetIDs) {
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE passID=" .$this->tupleID)->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET allotmentID=$allotmentID,description='$description'
WHERE passID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
} else{
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(allotmentID,description)
value($allotmentID,'$description')";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
}
//echo $this->sqlStmt;
// save item list
foreach ($assetIDs as $assetID) {
if ($this->pdo->query("SELECT * FROM erp_hms.hms_passitems WHERE assetID=$assetID AND passID=" .$this->tupleID)->rowCount()) {
// do nothing
//$this->sqlStmt = "UPDATE erp_hms.hms_passitems SET assetID=$assetID
//WHERE assetID=$assetID AND passID=" .$this->tupleID;
//$this->pdo->exec($this->sqlStmt);
} else {
$this->sqlStmt = "INSERT INTO erp_hms.hms_passitems(passID,assetID)
value(" .$this->tupleID. ",$assetID)";
$this->pdo->exec($this->sqlStmt);
}
}
//echo $this->sqlStmt;
}
function deleteGatepass() {
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE passID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function getGatepass($passID=0) {
if ($passID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_gatepasses WHERE passID=$passID");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
}
function listGatepasses($allotmentID=0) {
if ($allotmentID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_gatepasses WHERE allotmentID=$allotmentID ORDER BY dateIssue");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
function printGatepasses($allotmentID=0) {
if ($allotmentID) {
$this->dbStmt = $this->pdo->query("SELECT allotmentID,description,dateIssue FROM erp_hms.hms_gatepasses WHERE allotmentID=$allotmentID ORDER BY dateIssue");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
function listPassitems($passID=0) {
if ($passID) {
$this->dbStmt = $this->pdo->query("SELECT a.* FROM erp_hms.hms_passitems AS i LEFT JOIN erp_hms.hms_assets AS a ON i.assetID=a.assetID WHERE passID=$passID ORDER BY assetName");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
//***********************************************************************
//* misc. query functions *
//***********************************************************************
function getHostelIDByHostelCode($hostelCode) {
if ($hostelCode) {
$this->dbStmt = $this->pdo->query("SELECT hostelID FROM erp_hms.hms_hostels WHERE hostelCode='$hostelCode'");
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
return $row['hostelID'];
}
}
/* function getHostelCodeByHostelID($hostelID) {
if ($hostelID) {
$this->dbStmt = $this->pdo->query("SELECT hostelCode FROM erp_hms.hms_hostels WHERE hostelID=$hostelID");
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
return $row['hostelCode'];
}
}
*/
function listAllotmentsByRoomID($roomID=0) {
if ($roomID) { // multi allotments in same room
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_allotments WHERE roomID=$roomID");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
function getAllotmentCountByRoomID($roomID=0) {
if ($roomID) {
$this->dbStmt = $this->pdo->query("SELECT count(allotteeNo) AS no FROM erp_hms.hms_allotments WHERE roomID=$roomID");
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
return $row['no'];
}
}
/* moved to erpModel.php
function getAllotmentCountByRoomType($hostelID, $roomType) {
if ($hostelID && $roomType) {
$this->dbStmt = $this->pdo->query("SELECT count(a.allotteeNo) AS no FROM erp_hms.hms_allotments AS a INNER JOIN erp_hms.hms_rooms AS r ON a.roomID=r.roomID WHERE r.hostelID=$hostelID AND r.roomType=$roomType");
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
return $row['no'];
}
}
function getAllotmentIDByAllotteeNo($allotteeNo='') {
if ($allotteeNo) {
$this->dbStmt = $this->pdo->query("SELECT allotmentID FROM erp_hms.hms_allotments WHERE allotteeNo='$allotteeNo'");
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
return $row['allotmentID'];
}
}
*/
function getGatepassItemByAssetID($assetID) {
if ($assetID) {
$this->dbStmt = $this->pdo->query("SELECT itemID FROM erp_hms.hms_passitems WHERE assetID=$assetID");
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
return $row['itemID'];
}
}
function getWardenNameByHostelID($hostelID) {
if ($hostelID) {
$this->dbStmt = $this->pdo->query("SELECT wardenName FROM erp_hms.hms_wardens WHERE hostelID=$hostelID");
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
return $row['wardenName'];
}
}
function getAssistantNameByHostelID($hostelID) {
if ($hostelID) {
$this->dbStmt = $this->pdo->query("SELECT assttName FROM erp_hms.hms_assistants WHERE hostelID=$hostelID");
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
return $row['assttName'];
}
}
function getAllocationByProgramID($program) {
if ($programID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_hms.hms_allocations WHERE programID=$programID");
$rows = $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
return $rows;
}
}
}
?>