| Current Path : /var/www/html/mmishra/erp/models/ |
| Current File : /var/www/html/mmishra/erp/models/anf_model.php |
<?php
//if (!class_exists($erpModel)) {
require_once __DIR__."/erp_model.php";
//}
class anfModel 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_anf");
} catch (PDOException $e) {
die("Error!: " . $e->getMessage());
}
}
public function __destruct() {
//print mysql_error();
$this->dbStmt = null;
$this->pdo = null;
}
//***********************************************************************
//* anf fee head functions *
//***********************************************************************
function saveFeehead($feeheadCode,$feeheadName,$accountType,$paymentTerm) {
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE feeheadID=" .$this->tupleID)->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET feeheadCode='$feeheadCode',feeheadName='$feeheadName',accountType=$accountType,paymentTerm=$paymentTerm
WHERE feeheadID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
} else{
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(feeheadCode,feeheadName,accountType,paymentTerm)
value('$feeheadCode','$feeheadName',$accountType,$paymentTerm)";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
}
}
function deleteFeehead() {
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE feeheadID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function getFeehead($feeheadID=0) {
if ($feeheadID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_anf.anf_feeheads WHERE feeheadID=$feeheadID");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
}
function listFeeheads() {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_anf.anf_feeheads ORDER BY accountType,paymentTerm,feeheadName");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
function selectFeehead() {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_anf.anf_feeheads WHERE status='Enabled' ORDER BY feeheadName");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
//***********************************************************************
//* anf fees chart functions *
//***********************************************************************
function saveFeechart($feeheadID,$currency,$feeAmount,$category,$programID) {
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE feechartID=" .$this->tupleID)->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET feeheadID=$feeheadID,currency='$currency',feeAmount=$feeAmount,category='$category',programID='$programID',batchYear=" .$_SESSION["batchYear"]. "
WHERE feechartID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
} else if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE feeheadID=$feeheadID AND feeAmount=$feeAmount AND batchYear=" .$_SESSION["batchYear"])->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET category=CONCAT(category,',$category'),programID=CONCAT(programID,',$programID')
WHERE feeheadID=$feeheadID AND feeAmount=$feeAmount";
$this->pdo->exec($this->sqlStmt);
} else{
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(feeheadID,currency,feeAmount,category,programID,batchYear)
value($feeheadID,'$currency',$feeAmount,'$category','$programID'," .$_SESSION["batchYear"]. ")";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
}
}
function deleteFeechart() {
$this->sqlStmt = "DELETE FROM " .$this->tableID. " WHERE feechartID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
}
function getFeechart($feechartID=0) {
if ($feechartID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_anf.anf_feecharts WHERE feechartID=$feechartID");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
}
function listFeecharts() {
$this->dbStmt = $this->pdo->query("SELECT feeheadCode,feeheadName,accountType,paymentTerm,c.*
FROM erp_anf.anf_feecharts AS c INNER JOIN erp_anf.anf_feeheads AS h ON c.feeheadID=h.feeheadID
WHERE batchYear=" .$_SESSION["batchYear"]. " AND paymentTerm<9
ORDER BY c.feeheadID");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
function selectFeechart($programID, $category='', $feeheadID=0) {
if ($programID) {
$this->dbStmt = $this->pdo->query("SELECT feechartID,h.feeheadID,feeheadCode,feeheadName,accountType,paymentTerm,currency,feeAmount,category,programID
FROM erp_anf.anf_feecharts AS c INNER JOIN erp_anf.anf_feeheads AS h ON c.feeheadID=h.feeheadID
WHERE batchYear=" .$_SESSION["batchYear"]. " AND programID REGEXP CONCAT('(^|,)(', REPLACE('$programID', ',', '|'), ')(,|$)')" .($category ? " AND category REGEXP CONCAT('(^|,)(', REPLACE('$category', ',', '|'), ')(,|$)')" : ''). ($feeheadID ? " AND h.feeheadID=$feeheadID" : ''). " AND c.status='Enabled'
ORDER BY accountType,paymentTerm,feeheadName");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
function listPayables($programID, $category='') {
if ($programID) {
$this->dbStmt = $this->pdo->query("SELECT feechartID,h.feeheadID,feeheadCode,feeheadName,accountType,paymentTerm,currency,feeAmount,category,programID
FROM erp_anf.anf_feecharts AS c INNER JOIN erp_anf.anf_feeheads AS h ON c.feeheadID=h.feeheadID
WHERE batchYear=" .$_SESSION["batchYear"]. " AND programID REGEXP CONCAT('(^|,)(', REPLACE('$programID', ',', '|'), ')(,|$)')" .($category ? " AND category REGEXP CONCAT('(^|,)(', REPLACE('$category', ',', '|'), ')(,|$)')" : ''). " AND paymentTerm<>9
ORDER BY accountType,paymentTerm,feeheadName");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
function getPayable($programID, $category, $account) {
if ($programID && $category) {
$this->dbStmt = $this->pdo->query("SELECT MIN(currency) AS curency,SUM(feeAmount) AS amount
FROM erp_anf.anf_feecharts AS c INNER JOIN erp_anf.anf_feeheads AS h ON c.feeheadID=h.feeheadID
WHERE batchYear=" .$_SESSION['batchYear']. " AND programID REGEXP CONCAT('(^|,)(', REPLACE('$programID', ',', '|'), ')(,|$)') AND category REGEXP CONCAT('(^|,)(', REPLACE('$category', ',', '|'), ')(,|$)') AND accountType=$account AND paymentTerm<9");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
}
function getAlumniFund($programID, $category) {
if ($programID && $category) {
$this->dbStmt = $this->pdo->query("SELECT currency AS curency,feeAmount AS amount
FROM erp_anf.anf_feecharts AS c INNER JOIN erp_anf.anf_feeheads AS h ON c.feeheadID=h.feeheadID
WHERE batchYear=" .$_SESSION["batchYear"]. " AND programID REGEXP CONCAT('(^|,)(', REPLACE('$programID', ',', '|'), ')(,|$)') AND category REGEXP CONCAT('(^|,)(', REPLACE('$category', ',', '|'), ')(,|$)') AND accountType=1 AND feeheadName='Alumni Fund'");
return $this->dbStmt->fetch(PDO::FETCH_ASSOC);
}
}
//***********************************************************************
//* anf payment functions *
//***********************************************************************
function savePayment($studentID,$accountType,$paymentMode,$paymentNo,$bankName,$payAmount,$currency,$datePayment) {
if ($this->pdo->query("SELECT * FROM " .$this->tableID. " WHERE paymentID=" .$this->tupleID)->rowCount()) {
$this->sqlStmt = "UPDATE " .$this->tableID. " SET studentID=$studentID,accountType=$accountType,paymentMode='$paymentMode',paymentNo='$paymentNo',bankName='$bankName',payAmount=$payAmount,currency='$currency',datePayment='$datePayment'
WHERE paymentID=" .$this->tupleID;
$this->pdo->exec($this->sqlStmt);
} else{
$this->sqlStmt = "INSERT INTO " .$this->tableID. "(studentID,accountType,paymentMode,paymentNo,bankName,payAmount,currency,datePayment)
VALUES($studentID,$accountType,'$paymentMode','$paymentNo','$bankName',$payAmount,'$currency','$datePayment')";
$this->pdo->exec($this->sqlStmt);
$this->tupleID = $this->pdo->lastInsertId();
}
//echo $this->sqlStmt;
}
function getPayment($studentID, $account) {
if ($studentID && $account) {
$this->dbStmt = $this->pdo->query("SELECT SUM(payAmount) AS amount
FROM erp_anf.anf_payments
WHERE studentID=$studentID AND accountType=$account");
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
return $row['amount'];
}
}
function listPayments($studentID=0) {
if ($studentID) {
$this->dbStmt = $this->pdo->query("SELECT * FROM erp_anf.anf_payments
WHERE studentID=$studentID ORDER BY accountType,datePayment");
} else {
$this->dbStmt = $this->pdo->query("SELECT a.rollNo,a.nameEnglish,CASE WHEN p.accountType = 1 THEN 'Fees Amount' ELSE 'Mess Charges' END AS 'Head',p.PaymentMode,p.PaymentNo,p.BankName,p.DatePayment,CONCAT(p.Currency, ' ', p.payAmount) AS amount
FROM erp_anf.anf_payments AS p, anf_applicantsv AS a
WHERE batchYear=" .$_SESSION["batchYear"]. " AND p.studentID=a.studentID ORDER BY p.studentID,p.accountType,p.datePayment");
}
$rows = $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
return $rows;
}
function getPrepaid($programID, $category) {
if ($programID && $category) {
$this->dbStmt = $this->pdo->query("SELECT SUM(feeAmount) AS amount
FROM erp_anf.anf_feecharts AS c INNER JOIN erp_anf.anf_feeheads AS h ON c.feeheadID=h.feeheadID
WHERE batchYear=" .$_SESSION['batchYear']. " AND programID REGEXP CONCAT('(^|,)(', REPLACE('$programID', ',', '|'), ')(,|$)') AND category REGEXP CONCAT('(^|,)(', REPLACE('$category', ',', '|'), ')(,|$)') AND paymentTerm=9");
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
return $row['amount'];
}
}
function listPrepaids($programID, $category) {
if ($programID && $category) {
$this->dbStmt = $this->pdo->query("SELECT feeheadName,feeAmount,currency
FROM erp_anf.anf_feecharts AS c INNER JOIN erp_anf.anf_feeheads AS h ON c.feeheadID=h.feeheadID
WHERE batchYear=" .$_SESSION['batchYear']. " AND programID REGEXP CONCAT('(^|,)(', REPLACE('$programID', ',', '|'), ')(,|$)') AND category REGEXP CONCAT('(^|,)(', REPLACE('$category', ',', '|'), ')(,|$)') AND paymentTerm=9 AND accountType=1");
$row = $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
return $row;
}
function getPaidAmount($programID, $account) {
if ($programID && $account) {
$this->dbStmt = $this->pdo->query("SELECT SUM(payAmount) AS amount, MIN(currency) AS curency
FROM erp_anf.anf_payments AS p LEFT JOIN anf_applicants AS a ON p.studentID=a.studentID
WHERE batchYear=" .$_SESSION["batchYear"]. " AND programID=$programID AND accountType=$account");
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
return $row['curency']. ' ' .$row['amount'];
}
}
function paymentSummary($programID=0) {
$this->dbStmt = $this->pdo->query("SELECT a.rollNo,e.enrolmentNo,a.nameEnglish,CASE WHEN p.accountType=1 THEN 'Fees Amount' ELSE 'Mess Charges' END AS 'Head',p.PaymentMode,p.PaymentNo,p.BankName,p.DatePayment,CONCAT(p.Currency, ' ', p.payAmount) AS amount
FROM erp_anf.anf_payments AS p LEFT JOIN anf_applicantsv AS a ON p.studentID=a.studentID LEFT JOIN anf_enrolments AS e ON p.studentID=e.studentID
WHERE a.batchYear=" .$_SESSION["batchYear"]. ($programID ? " AND a.programID=$programID" : ''). " ORDER BY p.accountType,e.enrolmentNo,p.datePayment");
$rows = $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
return $rows;
}
function getMyPayment($studentID, $account) {
if ($studentID && $account) {
$this->dbStmt = $this->pdo->query("SELECT SUM(payAmount) AS amount
FROM erp_anf.anf_payments
WHERE studentID=$studentID AND accountType=$account");
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
return $row['amount'];
}
}
function listMyPayments($studentID) {
if ($studentID) {
$this->dbStmt = $this->pdo->query("SELECT accountType AS account,SUM(payAmount) AS amount
FROM erp_anf.anf_payments
WHERE studentID=$studentID");
return $this->dbStmt->fetchAll(PDO::FETCH_ASSOC);
}
}
function getAccountIDByStudentID($studentID) {
if ($studentID) {
$this->dbStmt = $this->pdo->query("SELECT accountID FROM erp_anf.anf_accounts WHERE studentID=$studentID");
$row = $this->dbStmt->fetch(PDO::FETCH_ASSOC);
return $row['accountID'];
} else {
return 0;
}
}
}
?>