291 lines
11 KiB
PHP
291 lines
11 KiB
PHP
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
class purchaseorder_model extends CI_Model
|
|
{
|
|
/**
|
|
* This function is used to get the user listing count
|
|
* @param string $searchText : This is optional search text
|
|
* @return number $count : This is row count
|
|
*/
|
|
function purchaseorderListingCount($searchText = '')
|
|
{
|
|
$this->db->select('BaseT.PONO, BaseT.POType, BaseT.PODate, ID.SupplierID,BaseT.SpecialOrder, users.UserID,BaseT.RequesterEmail,BaseT.RequesterPh,BaseT.RequestedDate,BaseT.BudgetManager,BaseT.BudgetManagerDepartment,BaseT.PurchasingCategory');
|
|
$this->db->from('T_PurchaseOrderDetails as BaseT');
|
|
$this->db->join('tbl_users as users', 'users.userId = BaseT.userId','left');
|
|
$this->db->join('T_SupplierDetailsN as ID', 'ID.SupplierID = BaseT.SupplierID','left');
|
|
if(!empty($searchText)) {
|
|
$likeCriteria = "(BaseT.PONO LIKE '%".$searchText."%'
|
|
OR BaseT.POType LIKE '%".$searchText."%'
|
|
OR BaseT.PODate LIKE '%".$searchText."%'
|
|
OR BaseT.SupplierID LIKE '%".$searchText."%'
|
|
OR BaseT.UserID LIKE '%".$searchText."%'
|
|
OR BaseT.RequesterEmail LIKE '%".$searchText."%'
|
|
OR BaseT.RequesterPh LIKE '%".$searchText."%'
|
|
OR BaseT.RequestedDate LIKE '%".$searchText."%'
|
|
OR BaseT.BudgetManager LIKE '%".$searchText."%'
|
|
OR BaseT.BudgetManagerDepartment LIKE '%".$searchText."%'
|
|
OR BaseT.PurchasingCategory LIKE '%".$searchText."%'
|
|
OR BaseT.SpecialOrder LIKE '%".$searchText."%')";
|
|
$this->db->where($likeCriteria);
|
|
}
|
|
//$this->db->where('BaseT.isDeleted', 0);
|
|
$this->db->where('BaseT.userId !=', 1);
|
|
$query = $this->db->get();
|
|
|
|
return count($query->result());
|
|
}
|
|
|
|
/**
|
|
* This function is used to get the user listing count
|
|
* @param string $searchText : This is optional search text
|
|
* @param number $page : This is pagination offset
|
|
* @param number $segment : This is pagination limit
|
|
* @return array $result : This is result
|
|
*/
|
|
function purchaseorderListing($searchText = '', $page, $segment)
|
|
{
|
|
$this->db->select('BaseT.PONO, BaseT.POType, BaseT.PODate, ID.SupplierID,BaseT.SpecialOrder, users.UserID,BaseT.RequesterEmail,BaseT.RequesterPh, BaseT.RequestedDate, BaseT.BudgetManager, BaseT.BudgetManagerDepartment, BaseT.PurchasingCategory');
|
|
$this->db->from('T_PurchaseOrderDetails as BaseT');
|
|
$this->db->join('tbl_users as users', 'users.userId = BaseT.userId','left');
|
|
$this->db->join('T_SupplierDetailsN as ID', 'ID.SupplierID = BaseT.SupplierID','left');
|
|
if(!empty($searchText)) {
|
|
$likeCriteria = "(BaseT.PONO LIKE '%".$searchfield."%'
|
|
OR BaseT.POType LIKE '%".$searchText."%'
|
|
OR BaseT.PODate LIKE '%".$searchText."%'
|
|
OR BaseT.SupplierID LIKE '%".$searchText."%'
|
|
OR BaseT.UserID LIKE '%".$searchText."%'
|
|
OR BaseT.RequesterEmail LIKE '%".$searchText."%'
|
|
OR BaseT.RequesterPh LIKE '%".$searchText."%'
|
|
OR BaseT.RequestedDate LIKE '%".$searchText."%'
|
|
OR BaseT.BudgetManager LIKE '%".$searchText."%'
|
|
OR BaseT.BudgetManagerDepartment LIKE '%".$searchText."%'
|
|
OR BaseT.PurchasingCategory LIKE '%".$searchText."%'
|
|
OR BaseT.SpecialOrder LIKE '%".$searchText."%')";
|
|
$this->db->where($likeCriteria);
|
|
}
|
|
//$this->db->where('BaseT.isDeleted', 0);
|
|
//$this->db->where('BaseT.userId !=', 1);
|
|
$this->db->limit($page, $segment);
|
|
$query = $this->db->get();
|
|
|
|
$result = $query->result();
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* This function is used to get the SupplierID and SupplierName information
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getSupplierName()
|
|
{
|
|
$this->db->select('SupplierID, SupplierName,Address');
|
|
$this->db->from('T_SupplierDetailsN');
|
|
//$this->db->where('roleId !=', 1);
|
|
$query = $this->db->get();
|
|
|
|
return $query->result();
|
|
}
|
|
/**
|
|
* This function is used to get the userId information
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getusers()
|
|
{
|
|
$this->db->select('userId, name');
|
|
$this->db->from('tbl_users');
|
|
//$this->db->where('roleId !=', 1);
|
|
$query = $this->db->get();
|
|
|
|
return $query->result();
|
|
}
|
|
|
|
/**
|
|
* This function is used to get the Raw Material information
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getRawMaterialList()
|
|
{
|
|
|
|
$this->db->select('MaterialCode, MaterialName');
|
|
$this->db->from('T_MaterialMaster');
|
|
|
|
$query = $this->db->get();
|
|
|
|
return $query->result();
|
|
}
|
|
|
|
|
|
/**
|
|
* This function is used to get the Cost center information
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getCostCenter()
|
|
{
|
|
|
|
$this->db->select('CostName, Description');
|
|
$this->db->from('T_CostCentre');
|
|
|
|
$query = $this->db->get();
|
|
|
|
return $query->result();
|
|
}
|
|
|
|
|
|
/**
|
|
* This function is used to get the Config value from configuration table
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getConfigValue($ConfigID ,$ConfigValue = '')
|
|
{
|
|
|
|
$this->db->select('ConfigValue');
|
|
$this->db->from('T_ConfigDetails');
|
|
$this->db->where('Config_id ',$ConfigID );
|
|
if($ConfigValue != '')
|
|
{
|
|
$this->db->where('ConfigValue != ',$ConfigValue );
|
|
}
|
|
$query = $this->db->get();
|
|
|
|
return $query->result();
|
|
}
|
|
|
|
|
|
/**
|
|
* This function is used to get the Purchase order Type
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getAllEmployees()
|
|
{
|
|
$this->db->select('EmpID,FirstName,LastName');
|
|
$this->db->from('T_Employee_Details');
|
|
$query = $this->db->get();
|
|
|
|
return $query->result();
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* This function is used to add New Purchase order to the system
|
|
|
|
*/
|
|
function addNewPO($PO_Type,$PO_Date,$Supplier_ID,$Special_Order,$User_ID,$Requester_Email,$Requester_Ph,$Requested_Date,$Budget_Manager,
|
|
$Budget_Manager_Department,$Purchasing_Category,$Purchasing_Justification,$Created_By,$BasicValue,$DiscountType,$txtDiscount,$PackagingType,
|
|
$txtPackaging,$Exciseduty,$txtVat,$txtFreight,$AfterDiscount,$AfterPackaging,$AferExciseduty,$txtAfterVat,$txtOrderValue)
|
|
{
|
|
|
|
$result = $this->db-> query("CALL P_PURCHASEORDER_DETAILS('".$PO_Type."',STR_TO_DATE('".$PO_Date."','%m-%d-%Y %H:%i:%s'),'".$Supplier_ID."','".$Special_Order."','".$User_ID."'
|
|
,'".$Requester_Email."','".$Requester_Ph."',STR_TO_DATE('".$Requested_Date."','%m-%d-%Y %H:%i:%s'),'".$Budget_Manager."','".$Budget_Manager_Department."','".$Purchasing_Category."','".$Purchasing_Justification."','".$Created_By."','".$BasicValue."','".$DiscountType."','".$txtDiscount."','".$PackagingType."','".$txtPackaging."','".$Exciseduty."','".$txtVat."','".$txtFreight."','".$AfterDiscount."','".$AfterPackaging."','".$AferExciseduty."','".$txtAfterVat."','".$txtOrderValue."')") or die(mysql_error());
|
|
|
|
// print_r($this->db->last_query());
|
|
|
|
$result ->next_result();
|
|
|
|
if ($result->num_rows > 0) {
|
|
//echo $result->num_rows;
|
|
return $result->result_array();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* This function is used to add new PO Line Item to T_PurchaseOrderLineItem table
|
|
* @return number $insert_id : This is last inserted id
|
|
*/
|
|
|
|
function addNewPOLineItem($PONO,$Material_ID,$UOM,$Quantity,$UnitPrice)
|
|
{
|
|
//echo 'addNewPOLineItem Model called';
|
|
|
|
$result = $this->db-> query("CALL P_LINEITEM('".$PONO."','".$Material_ID."','".$UOM."',".$Quantity.",".$UnitPrice.")") or die(mysql_error());
|
|
|
|
$result ->next_result();
|
|
|
|
//print_r($this->db->last_query());
|
|
|
|
if ($result->num_rows > 0)
|
|
{
|
|
//echo 'PO Line item Inserted successfully';
|
|
return $result->result_array();
|
|
}
|
|
|
|
return $result ->result_array(); ;
|
|
}
|
|
|
|
/**
|
|
* This function used to get user information by id
|
|
* @param number $userId : This is user id
|
|
* @return array $result : This is user information
|
|
*/
|
|
function getPOLineItem($PO = '')
|
|
{
|
|
$this->db->select('POline.POLineNo as POLineNo,Raw.MaterialName as materialName ,POline.UOM as UOM,POline.Quantity as Quantity,POline.UnitPrice as UnitPrice, (POline.Quantity * POline.UnitPrice) as ProductPrice');
|
|
$this->db->from('T_POLineItem as POline ');
|
|
$this->db->join('T_RawMaterialDetailsN as Raw', 'POline.Material_ID = Raw.MaterialCode');
|
|
if(!empty($PO)) {
|
|
|
|
$this->db->where('POline.PONO', $PO);
|
|
}
|
|
else
|
|
{
|
|
$likeCriteria = "(POline.PONO is null)";
|
|
$this->db->where($likeCriteria);
|
|
}
|
|
|
|
$query = $this->db->get();
|
|
// print_r($query);
|
|
$result = $query->result();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* This function used to get user information by id
|
|
* @param number $userId : This is user id
|
|
* @return array $result : This is user information
|
|
*/
|
|
function getuserInfo($PO)
|
|
{
|
|
$this->db->select('POType, PODate, SupplierID,SpecialOrder,UserID,RequestedDate,RequesterEmail,RequesterPh, PurchasingCategory,BudgetManager,BudgetManagerDepartment,');
|
|
$this->db->from('T_PurchaseOrderDetails');
|
|
$this->db->where('PONO', $PO);
|
|
$query = $this->db->get();
|
|
|
|
return $query->result();
|
|
}
|
|
|
|
function getPurchaseOrder($PONO)
|
|
{
|
|
$this->db->select('PODetail.*,Supplier.SupplierName,Supplier.Address,usr.name as usrName');
|
|
$this->db->from('T_PurchaseOrderDetails AS PODetail');
|
|
$this->db->join('T_SupplierDetailsN as Supplier', 'PODetail.SupplierID = Supplier.SupplierID');
|
|
$this->db->join('tbl_users as usr', 'usr.userId = PODetail.UserID');
|
|
$this->db->where('PODetail.PONO', $PONO);
|
|
$query = $this->db->get();
|
|
|
|
$result = $query->result();
|
|
|
|
// print_r($this->db->last_query());
|
|
return $result;
|
|
}
|
|
|
|
function getLastInsertedPO()
|
|
{
|
|
$this->db->select('max(PONO) as PO');
|
|
$this->db->from('T_PurchaseOrderDetails');
|
|
$query = $this->db->get();
|
|
|
|
return $query->result_array();
|
|
}
|
|
function updatePODetails($PO,$PODetails)
|
|
{
|
|
$this->db->where('PONO', $PO);
|
|
$this->db->update('T_PurchaseOrderDetails', $PODetails);
|
|
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
|