456 lines
15 KiB
PHP
Executable File
456 lines
15 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class Storerequistion_model extends Model
|
|
{
|
|
|
|
/* completed*/
|
|
function getCostUser($userId = '', $BudgetType = '')
|
|
{
|
|
$builder = $this->db->table('t_costcenter_master CM')
|
|
->select('ED.FirstName,CM.CostCenterCode,CM.CostCenterName,CB.BudgetAmount,CB.BudgetType')
|
|
->join('t_costcenter_departments CD ', ' CD.CostCenterCode = CM.CostCenterCode')
|
|
->join('t_costcenter_budget CB ', ' CB.CostCenterCode = CM.CostCenterCode')
|
|
->join('t_employee_details ED ', 'ED.Departmentcode = CD.DEPCode')
|
|
->join('tbl_users TU ', ' TU.EmpID = ED.EmpID ')
|
|
->where('TU.userId ', $userId);
|
|
//$this->db->where('CB.BudgetType','SERVICE');
|
|
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
//print_r( $result );
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
function getRawMaterialList($MaterialCode = '')
|
|
{
|
|
|
|
$builder = $this->db->table('t_materialmaster')->select('MaterialName,UOM,MaterialCode');
|
|
//$this->db->where('MaterialCode',$MaterialCode );
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
// print_r($result);
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* This function is used to add the Raise store Requestion into the Database
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function addRequistion($ReqDate = '')
|
|
{
|
|
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_store_requestion_master');
|
|
$builder->insert($ReqDate);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
if ($insert_id > 0) {
|
|
$subQuery = 'select max(StoreReqNo) as StoreReqNo from t_store_requestion_master';
|
|
|
|
$query = $this->db->query($subQuery);
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
//return $insert_id;
|
|
|
|
}
|
|
|
|
/**
|
|
* This function is used to update the details into Database
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function UpdateRequistion($StoreReqNo, $Request)
|
|
{
|
|
$this->db->table('t_store_requestion_master')
|
|
->where('StoreReqNo', $StoreReqNo)
|
|
->update($Request);
|
|
return TRUE;
|
|
}
|
|
|
|
function getRequistionList()
|
|
{
|
|
$builder = $this->db->table('t_store_requestion_master Sm')
|
|
->select('Sm.StoreReqNo, Emp.FirstName as Requestedby,Sm.ReqDate,Sm.Status,Sm.Comments as Remarks,St.StatusName,Dept.DepartmentName ')
|
|
->join('tbl_users user', 'Sm.CreatedBy = user.userId ')
|
|
->join('t_employee_details Emp', 'Emp.EmpID= user.EmpID')
|
|
->join('t_departmentdetails Dept', 'Dept.DEPCode = Sm.DepartmentCode')
|
|
->join('t_status St', 'St.StatusCode = Sm.Status')
|
|
->where('Sm.Status ', STORE_APPROVAL)
|
|
->orWhere('Sm.Status ', STORE_PARTIALLYISSUSED);
|
|
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/*this function used to Add Store Requistion*/
|
|
function addstoreRequistion($Request)
|
|
{
|
|
//print_r($Request);
|
|
//die();
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_store_requestion_details');
|
|
$builder->insert($Request);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
if ($insert_id > 0) {
|
|
$subQuery = 'select max(StoreReqLineItemNo) as StoreReqLineItemNo from t_store_requestion_details';
|
|
|
|
$query = $this->db->query($subQuery);
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
}
|
|
|
|
/*this function used to Update Store Requistion*/
|
|
function upstoreRequistion($Request)
|
|
{
|
|
//print_r($Request);
|
|
$this->db->transStart();
|
|
$this->db->table('t_store_requestion_details')
|
|
->update($Request);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
if ($insert_id > 0) {
|
|
$subQuery = 'select max(StoreReqLineItemNo) as StoreReqLineItemNo from t_store_requestion_details';
|
|
|
|
$query = $this->db->query($subQuery);
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
}
|
|
/**
|
|
* This function is used to check the Request Line Item is in Draft status
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function LineItemIsExists($StoreReqNo, $MaterialCode)
|
|
{
|
|
|
|
$builder = $this->db->table('t_store_requestion_details');
|
|
$builder->select('StoreReqNo')
|
|
->where('StoreReqNo', $StoreReqNo)
|
|
->where('MaterialCode', $MaterialCode);
|
|
$query = $builder->get();
|
|
|
|
if ($query->getNumRows() > 0) {
|
|
return $query->getResultArray();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* This function is used to add the Line item details to the Database
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function addRequistionDetails($StoreReqLineItemNo)
|
|
{
|
|
//echo "nsmdnsjkkjasdf"; die();
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_store_requestion_details');
|
|
$builder->insert($StoreReqLineItemNo);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
|
|
return $insert_id;
|
|
}
|
|
|
|
/**
|
|
* This function is used to update the Line item details to the Database
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function upRequistionDetails($StoreReqLineItemNo)
|
|
{
|
|
//echo "nsmdnsjkkjasdf"; die();
|
|
$this->db->transStart();
|
|
$this->db->table('t_store_requestion_details')
|
|
->update($StoreReqLineItemNo);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
|
|
return $insert_id;
|
|
}
|
|
|
|
|
|
/**
|
|
* This function is used to update the details into Database
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function UpdateRequistionLineItem($Request, $StoreReqNo, $MaterialCode)
|
|
{
|
|
$this->db->table('t_store_requestion_details')
|
|
->where('MaterialCode', $MaterialCode)
|
|
->where('StoreReqNo', $StoreReqNo)
|
|
->update($Request);
|
|
return TRUE;
|
|
}
|
|
|
|
/**
|
|
* This function is used to delete the Line item from details into Database
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function DeleteRequistionLineItem($StoreReqNo, $MaterialCode)
|
|
{
|
|
$this->db->table('t_store_requestion_details')->delete(['StoreReqNo' => $StoreReqNo, 'MaterialCode' => $MaterialCode]);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* This function is used to get the userId information
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getStatus()
|
|
{
|
|
|
|
$builder = $this->db->table('t_status')->select('StatusCode,StatusName ')
|
|
->where('Remarks', 'STORE REQUISTION STATUS');
|
|
//->where('StatusCode!=', REQ_DRAFT);
|
|
$query = $builder->get();
|
|
// print_r($query);
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function editstorerequistions($StoreReqNo)
|
|
{
|
|
$builder = $this->db->table('t_store_requestion_details Sr')
|
|
->select('Sr.StoreReqNo,Sr.MaterialCode,Sr.QuantityRequired,Sr.Status,Sr.Remarks,Mm.MaterialName,Mm.UOM,Sr.QuantityIssued,STM.Status ')
|
|
->join('t_materialmaster Mm', ' Mm.MaterialCode = Sr.MaterialCode')
|
|
->join('t_store_requestion_master STM', ' STM.StoreReqNo = Sr.StoreReqNo')
|
|
->where('Sr.StoreReqNo', $StoreReqNo);
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
/**
|
|
* This function is used to check the Request is in Draft status
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function RequistionIsExists($ReqDate)
|
|
{
|
|
|
|
$builder = $this->db->table('t_store_requestion_master')
|
|
->select('StoreReqNo')
|
|
//->where('Status ',REQ_DRAFT )
|
|
->where('ReqDate', $ReqDate);
|
|
$query = $builder->get();
|
|
|
|
if ($query->getNumRows() > 0) {
|
|
//echo $result->getNumRows();
|
|
return $query->getResultArray();
|
|
}
|
|
}
|
|
/**
|
|
* This function is used to check the Request is in Draft status
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function Storerequisition($MaterialCode)
|
|
{
|
|
|
|
$builder = $this->db->table('t_store_requestion_details')->select('StoreReqNo')
|
|
//->where('Status ',REQ_DRAFT )
|
|
->where('MaterialCode', $MaterialCode);
|
|
$query = $builder->get();
|
|
|
|
if ($query->getNumRows() > 0) {
|
|
//echo $result->getNumRows();
|
|
return $query->getResultArray();
|
|
}
|
|
}
|
|
|
|
/** COMPLETED
|
|
* This function is used to get the List of Store Requist details to the approver
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getApproverRequistList($UserID)
|
|
{
|
|
// echo 'UserId: '.$UserID . 'From: '.$FromDate .'TO: '. $ToDate. 'Status: '. $Status;
|
|
|
|
|
|
$subQuery = ' select distinct Str.StoreReqNo,Str.Requestedby,Str.ReqDate,Str.Status,Str.CreatedDate,Str.Comments,St.StatusName,Emp1.FirstName
|
|
from t_store_requestion_master Str
|
|
join t_status St on St.StatusCode = Str.Status
|
|
join t_employee_details Emp on Emp.Departmentcode =Str.DepartmentCode
|
|
join t_employee_details Emp1 on Emp1.EmpID =Str.Requestedby
|
|
join t_departmentdetails Dept on Dept.DEPCode = Emp.Departmentcode
|
|
where Str.Status not in(?,?,?) and Emp.Departmentcode in (select DEPCode from t_departmentdetails where HeadDept=
|
|
(select HeadDept from t_departmentdetails where DEPCode = (select Departmentcode from t_employee_details where
|
|
EmpID=(select EmpID from tbl_users where userId=?))))';
|
|
|
|
$query = '';
|
|
|
|
$query = $this->db->query($subQuery, array(STORE_REJECT, STORE_DRAFT, REQ_DELETED, $UserID));
|
|
|
|
return $query->getResult();
|
|
}
|
|
/**
|
|
* This function is used to get the Store Requsition List for the login user
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getRequistDetails($StoreReqNo = '')
|
|
{
|
|
|
|
$subQuery = ' select Str.StoreReqNo,Str.Requestedby,Str.ReqDate,Dept.DEPCode,Dept.DepartmentName,Cm.CostCenterCode,Cm.CostCenterName,Emp.FirstName from t_store_requestion_master Str
|
|
join t_departmentdetails Dept on Dept.DEPCode = Str.DepartmentCode
|
|
join t_costcenter_master Cm on Cm.CostCenterCode =Str.CostCenterCode
|
|
join t_employee_details Emp on Emp.EmpID =Str.Requestedby
|
|
where StoreReqNo =? ';
|
|
|
|
|
|
|
|
$query = $this->db->query($subQuery, array($StoreReqNo));
|
|
|
|
return $query->getResult();
|
|
}
|
|
function editRequistDetails($StoreReqNo)
|
|
{
|
|
|
|
$builder = $this->db->table('t_store_requestion_master Sr')
|
|
->select('StoreReqNo,Sr.CostCenterCode,Cc.CostCenterName ')
|
|
->join('t_costcenter_master Cc ', ' Cc.CostCenterCode=Sr.CostCenterCode')
|
|
->where('StoreReqNo', $StoreReqNo);
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
/**
|
|
* This function is used to get the Store Requsition List for the login user
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getRequistItemListApproval($StoreReqNo, $NoArray = '')
|
|
{
|
|
|
|
$subQuery = ' select Str.StoreReqNo,Str.MaterialCode,Str.QuantityRequired,Str.Remarks,Mat.MaterialName,Mat.UOM,Ss.StatusName,Str.Status,Str.QuantityIssued
|
|
from t_store_requestion_details Str
|
|
join t_materialmaster Mat on Mat.MaterialCode = Str.MaterialCode
|
|
join t_status Ss on Ss.StatusCode = Str.Status
|
|
where Str.StoreReqNo =?';
|
|
|
|
$query = $this->db->query($subQuery, array($StoreReqNo));
|
|
if ($NoArray == '') {
|
|
return $query->getResultArray();
|
|
} else {
|
|
return $query->getResult();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This function is used to get the Store Requsition List for the login user
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getRequistItemList($StoreReqNo)
|
|
{
|
|
|
|
$subQuery = ' select Str.StoreReqNo,Str.MaterialCode,Str.QuantityRequired,Str.QuantityIssued,Str.Remarks,Str.StoreComments,Mat.MaterialName,Mat.UOM,Ss.StatusName,St.Status,St.Quantity
|
|
from t_store_requestion_details Str
|
|
join t_materialmaster Mat on Mat.MaterialCode = Str.MaterialCode
|
|
join t_status Ss on Ss.StatusCode = Str.Status
|
|
left join t_store_stockdetails St on St.MaterialCode=Str.MaterialCode
|
|
where Str.StoreReqNo =?';
|
|
|
|
$query = $this->db->query($subQuery, array($StoreReqNo));
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
function getStoreRequistionStatus($StreReqNo = '')
|
|
{
|
|
|
|
$builder = $this->db->table('t_store_requestion_master Sr')
|
|
->select('Status')
|
|
->where('StoreReqNo', $StreReqNo);
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
function UpdateStoreRequistionItem($Items, $ReqNo, $MaterialCode)
|
|
{
|
|
$this->db->table('t_store_requestion_details')
|
|
->where('StoreReqNo', $ReqNo)
|
|
->where('MaterialCode', $Items)
|
|
->update($Items);
|
|
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function getSavedQty($ReqNO, $MaterialCode)
|
|
{
|
|
$subQuery = 'select QuantityIssued from t_store_requestion_details
|
|
where StoreReqNo=? and MaterialCode=?';
|
|
|
|
$query = $this->db->query($subQuery, array($ReqNO, $MaterialCode));
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function updatestoremaster($updatestatus, $StoreReqNo)
|
|
{
|
|
$this->db->table('t_store_requestion_master')
|
|
->where('StoreReqNo', $StoreReqNo)
|
|
->update($updatestatus);
|
|
return TRUE;
|
|
}
|
|
|
|
function getstatuscount($Status, $StoreReqNo)
|
|
{
|
|
|
|
$builder = $this->db->table('t_store_requestion_details')->select('count(Status) as SCount')
|
|
->where('Status', $Status)
|
|
->where('StoreReqNo', $StoreReqNo);
|
|
//->where('StoreReqNo', $StoreReqNo);
|
|
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
/*this function used to get the all store requistion list view*/
|
|
function Storeall($StoreReqNo, $IsArray = '')
|
|
{
|
|
|
|
$result = $this->db->query("CALL P_GET_AllSTOREREQUISTION('" . $StoreReqNo . "')");
|
|
// or die(mysql_error()); {
|
|
//echo 'Store Line item Inserted successfully';
|
|
if ($IsArray != '') {
|
|
|
|
return $result->getResultArray();
|
|
} else {
|
|
return $result->getResult();
|
|
}
|
|
}
|
|
|
|
|
|
function getItemQuantityFromStock($MaterialCode)
|
|
{
|
|
$subQuery = 'select Quantity from t_store_stockdetails where MaterialCode=?';
|
|
$query = $this->db->query($subQuery, array($MaterialCode));
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
function UpdateStock($StockDetails, $MaterialCode)
|
|
{
|
|
$this->db->table('t_store_stockdetails')
|
|
->where('MaterialCode', $MaterialCode)
|
|
->update($StockDetails);
|
|
|
|
return TRUE;
|
|
}
|
|
}
|