Server : Apache System : Linux profile 3.10.0-1160.88.1.el7.x86_64 #1 SMP Tue Mar 7 15:41:52 UTC 2023 x86_64 User : apache ( 48) PHP Version : 8.0.28 Disable Function : NONE Directory : /var/www/html/mmishra/erp-19-12-2019/models/ |
<?php
class deptModel extends erpModel {
public function __construct() {
parent::__construct();
$this->pdo->query($this->db);
}
//***********************************************************************
//* dept fundhead functions *
//***********************************************************************
function saveFundhead($headName,$headNature) {
// $adminEmail = filter_var($adminEmail, FILTER_SANITIZE_EMAIL);
// $adminEmail = filter_var($adminEmail, FILTER_VALIDATE_EMAIL);
//$description = filter_var($description, FILTER_SANITIZE_STRING);
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE headID=" .$this->tupleID)->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET headName='$headName',headDept='$headNature'
WHERE headID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
} else{
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(headName,headNature)
values('$headName','$headNature')";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
}
//echo $this->sqlStmt;
}
function enableFundhead() {
$status = 'Enabled';
// set status of head to enabled
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='$status' WHERE headID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function disableFundhead() {
$status = 'Disabled';
// set status of head to disabled
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='$status' WHERE headID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function deleteFundhead($headID) {
if ($this->tupleID > 1) {
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE headID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
}
function getFundhead($headID=0) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_dept.dept_fundheads WHERE headID=$headID");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
function listFundheads($filterText='') {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_dept.dept_fundheads ORDER BY headID");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
function selectFundhead() {
// list only enabled records
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_dept.dept_fundheads WHERE status='Enabled' ORDER BY headName");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
//***********************************************************************
//* dept budget functions *
//***********************************************************************
function saveBudget($deptID,$headID,$accountYear,$amount) {
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE budgetID=" .$this->tupleID)->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET deptID=$deptID,headID=$headID,accountYear='$accountYear',amount=$amount
WHERE budgetID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
} else {
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(deptID,headID,accountYear,amount)
values($deptID,$headID,'$accountYear',$amount)";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
}
//echo $this->sqlStmt;
}
function deleteBudget() {
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE budgetID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function getBudget($appID=0) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_dept.dept_budgets WHERE budgetID=$appID");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
function listBudgets() {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_dept.dept_budgets ORDER BY budgetID");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
function selectBudget($moduleID=0) {
// list enabled records only
$this->dbStmt = $this->pdo->query("SELECT b.*,h.moduleName FROM erp_dept.dept_budgets AS b, erp_dept.dept_fundheads AS h WHERE b.headID=h.headID ORDER BY b.budgetID, h.headID");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
//***********************************************************************
//* dept Utilization functions *
//***********************************************************************
function saveUtilization($deptID,$headID,$accountYear,$amount,$description,$facultyID) {
$description = filter_var($description, FILTER_SANITIZE_URL);
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE expenseID=" .$this->tupleID)->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET deptID=$deptID,headID=$headID,accountYear='$accountYear',amount=$amount,description='$description',facultyID='$facultyID
WHERE expenseID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
// reduce budget
$this->sqlStmt = "UPDATE erp_dept.dept_budgets SET amount=amount - $amount
WHERE deptID=$deptID AND headID=$headID AND accountYear='$accountYear'";
// $this->pdo->exec($this->sqlStmt);
} else {
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(deptID,headID,accountYear,amount,description,facultyID)
values($deptID,$headID,'$accountYear',$amount,'$description','$facultyID')";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
echo $this->sqlStmt;
// reduce budget
$this->sqlStmt = "UPDATE erp_dept.dept_budgets SET amount= amount - $amount
WHERE deptID=$deptID AND headID=$headID AND accountYear='$accountYear'";
$this->pdo->exec($this->sqlStmt);
}
echo $this->sqlStmt;
}
function deleteUtilization() {
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE expenseID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function getUtilization($expenseID=0) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_dept.dept_utilizations WHERE expenseID=$expenseID");
if ($this->dbStmt->rowCount()) {
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
}
function listUtilizations() {
$this->dbStmt = $this->pdo->query("SELECT e.*, h.headName FROM erp_dept.dept_utilizations AS e, erp_dept.dept_fundheads AS h WHERE e.headID=h.headID ORDER BY e.deptID,e.headID");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
function selectUtilization($expenseID=0) {
$this->dbStmt = $this->pdo->query("SELECT e.*, h.headName FROM erp_dept.dept_utilizations AS e, erp_dept.dept_fundheads AS h WHERE e.headID=h.headID" .($expenseID ? " AND e.expenseID=$expenseID" : ''). " ORDER BY e.deptID,e.headID");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
/*
//***********************************************************************
//* dept purchase functions *
//***********************************************************************
function savePurchase($groupName,$description,$dashboard) {
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE groupID=" .$this->tupleID)->rowCount()) {
// get member count
$this->dbStmt = $this->pdo->query("SELECT count(userID) AS no FROM erp_dept.dept_users WHERE groupID=" .$this->tupleID);
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
$memberCount= $row['no'];
$this->sqlStmt = "UPDATE " .$this->tableID. " SET groupName='$groupName',description='$description',dashboard='$dashboard',memberCount=$memberCount
WHERE groupID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
} else {
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(groupName,description,dashboard)
values('$groupName','$description','$dashboard')";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
}
//echo $this->sqlStmt;
}
function enablePurchase() {
$status = 'Enabled';
// set status of group to enabled
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='$status' WHERE groupID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
// cascade status upto gacls
$this->sqlStmt = "UPDATE erp_dept.dept_gacls SET status='$status' WHERE groupID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
// cascade status upto users
$this->sqlStmt = "UPDATE erp_dept.dept_users SET status='$status' WHERE groupID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
// cascade status upto uacls
$this->sqlStmt = "UPDATE erp_dept.dept_uacls SET status='$status' WHERE userID IN (SELECT userID FROM erp_dept.dept_users WHERE groupID=" .$this->tupleID. ")";
$this->pdo->exec($this->sqlStmt);
}
function disablePurchase() {
$status = 'Disabled';
// set status of group to enabled
$this->sqlStmt = "UPDATE " .$this->tableID. " SET status='$status' WHERE groupID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
// cascade status upto gacls
$this->sqlStmt = "UPDATE erp_dept.dept_gacls SET status='$status' WHERE groupID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
// cascade status upto users
$this->sqlStmt = "UPDATE erp_dept.dept_users SET status='$status' WHERE groupID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
// cascade status upto uacls
$this->sqlStmt = "UPDATE erp_dept.dept_uacls SET status='$status' WHERE userID IN (SELECT userID FROM erp_dept.dept_users WHERE groupID=" .$this->tupleID. ")";
$this->pdo->exec($this->sqlStmt);
}
function deletePurchase() {
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE groupID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function getPurchase($groupID=0) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_dept.dept_groups WHERE groupID=$groupID");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
function listPurchases($filterText='') {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_dept.dept_groups" .($filterText ? " WHERE CONCAT(groupName, status) like '%$filterText%'" : ''). " ORDER BY groupName");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
function selectPurchase() {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_dept.dept_groups WHERE status='Enabled' ORDER BY groupID");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
//*******************************group ACL functions
function saveDocfile($groupID,$menuID,$aclRead,$aclInsert,$aclUpdate,$aclDelete) {
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE aclID=" .$this->tupleID)->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET groupID=$groupID,menuID=$menuID,aclRead=$aclRead,aclInsert=$aclInsert,aclUpdate=$aclUpdate,aclDelete=$aclDelete
WHERE aclID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
} else {
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(groupID,menuID,aclRead,aclInsert,aclUpdate,aclDelete)
VALUES($groupID,$menuID,$aclRead,$aclInsert,$aclUpdate,$aclDelete)";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
}
//echo $this->sqlStmt;
}
function deleteDocfile($aclID) {
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE aclID=$aclID";
$this->pdo->exec($this->sqlStmt);
}
function getDocfile($aclID=0) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_dept.dept_gacls WHERE aclID=$aclID");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
function listDocfiles($groupID) {
$this->dbStmt = $this->pdo->query("SELECT a.appName,a.appIcon,m.menuID,m.menuName,m.menuIcon,m.interface,m.protection,g.aclID,aclRead,aclInsert,aclUpdate,aclDelete FROM erp_dept.dept_apps AS a LEFT JOIN erp_dept.dept_menus AS m ON a.appID=m.appID AND a.status='Enabled' LEFT JOIN erp_dept.dept_gacls AS g ON m.menuID=g.menuID AND g.groupID=$groupID ORDER BY a.appName, m.interface, m.menuName");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
*/
}
?>