This commit is contained in:
gandhimathi Bharathirajan 2017-05-20 13:45:13 +05:30
parent f37d2ea011
commit babadfd8be

View File

@ -7,31 +7,18 @@ class purchaseorder_model extends CI_Model
* @param string $searchText : This is optional search text * @param string $searchText : This is optional search text
* @return number $count : This is row count * @return number $count : This is row count
*/ */
function purchaseorderListingCount($searchText = '') function purchaseorderListingCount()
{ {
$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->distinct();
$this->db->from('T_PurchaseOrderDetails as BaseT'); $this->db->select('POMast.PONO,supp.SupplierName,TotalOrderValue,PODate,Stat.StatusName,Req.ReqType,DeliveryDate');
$this->db->join('tbl_users as users', 'users.userId = BaseT.userId','left'); $this->db->from('T_PurchaseOrder_Master POMast');
$this->db->join('T_SupplierDetailsN as ID', 'ID.SupplierID = BaseT.SupplierID','left'); $this->db->join('T_SupplierDetailsN supp', 'supp.SupplierID = POMast.SupplierID');
if(!empty($searchText)) { $this->db->join('T_Status Stat', 'Stat.StatusCode = POMast.Status');
$likeCriteria = "(BaseT.PONO LIKE '%".$searchText."%' $this->db->join('T_PurchaseOrder_LineItem LineItem', 'POMast.PONO = LineItem.PONO');
OR BaseT.POType LIKE '%".$searchText."%' $this->db->join('T_Requestion_Master Req', 'Req.ReqNo = LineItem.ReqNo');
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(); $query = $this->db->get();
return count($query->result()); return count($query->result());
} }
@ -42,32 +29,18 @@ class purchaseorder_model extends CI_Model
* @param number $segment : This is pagination limit * @param number $segment : This is pagination limit
* @return array $result : This is result * @return array $result : This is result
*/ */
function purchaseorderListing($searchText = '', $page, $segment) function purchaseorderListing()
{ {
$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->distinct();
$this->db->from('T_PurchaseOrderDetails as BaseT'); $this->db->select('POMast.PONO,supp.SupplierName,TotalOrderValue,PODate,Stat.StatusName,Stat.StatusCode,Req.ReqType,DeliveryDate');
$this->db->join('tbl_users as users', 'users.userId = BaseT.userId','left'); $this->db->from('T_PurchaseOrder_Master POMast');
$this->db->join('T_SupplierDetailsN as ID', 'ID.SupplierID = BaseT.SupplierID','left'); $this->db->join('T_SupplierDetailsN supp', 'supp.SupplierID = POMast.SupplierID');
if(!empty($searchText)) { $this->db->join('T_Status Stat', 'Stat.StatusCode = POMast.Status');
$likeCriteria = "(BaseT.PONO LIKE '%".$searchfield."%' $this->db->join('T_PurchaseOrder_LineItem LineItem', 'POMast.PONO = LineItem.PONO');
OR BaseT.POType LIKE '%".$searchText."%' $this->db->join('T_Requestion_Master Req', 'Req.ReqNo = LineItem.ReqNo');
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(); $query = $this->db->get();
$result = $query->result(); $result = $query->result();
return $result; return $result;
} }
@ -110,15 +83,57 @@ class purchaseorder_model extends CI_Model
function getRawMaterialList($MatType='',$ReqNoList='') function getRawMaterialList($MatType='',$ReqNoList='')
{ {
$this->db->select('ReqNo,Req.MaterialCode,MaterialName,UOM,Req.Quantity'); $this->db->select('ReqNo,Req.MaterialCode,MaterialName,UOM,Req.Quantity');
$this->db->from('T_Requestion_Details Req'); $this->db->from('T_Requestion_Details Req');
$this->db->join('T_MaterialMaster mat', 'Req.MaterialCode = mat.MaterialCode'); $this->db->join('T_MaterialMaster mat', 'Req.MaterialCode = mat.MaterialCode');
$this->db->where('mat.MaterialType', $MatType); $this->db->where('mat.MaterialType', $MatType);
$this->db->where_in('Req.ReqNo', $ReqNoList); $this->db->where_in('Req.ReqNo', $ReqNoList);
$query = $this->db->get(); $query = $this->db->get();
return $query->result(); return $query->result();
}
/**
* This function is used to get the Raw Material information
* @return array $result : This is result of the query
*/
function getRawMaterialListForPO($MatType='',$ReqNo='')
{
$subQuery ='SELECT ReqNo,Req.MaterialCode,MaterialName,UOM,Req.Quantity
FROM T_Requestion_Details Req
JOIN T_MaterialMaster mat ON Req.MaterialCode = mat.MaterialCode
where mat.MaterialType = ?
AND Req.ReqNo = ?
AND mat.MaterialCode != (SELECT MaterialCode FROM T_PurchaseOrder_LineItem WHERE ReqNo =?
)';
$query = $this->db->query($subQuery,array($MatType,$ReqNo,$ReqNo));
return $query->result_array();
}
function GetAvailableBudgetAmount($CostCode,$Year,$BudgetType)
{
/* $this->db->select('BudgetAmount');
$this->db->from('T_CostCenter_Budget');
$this->db->where('CostCenterCode',$CostCode );
$this->db->where('BudgetYear',$Year );
$this->db->where('BudgetType',$BudgetType );
$query = $this->db->get();
return $query->result_array(); */
$subQuery ='select BudgetAmount, (select ifnull(sum(TotalOrderValue),0) as Totalvalue from
T_PurchaseOrder_Master PO join T_PurchaseOrder_LineItem Item on
Item.PONO = PO.PONO where Item.CostCenterCode=? )as val
from T_CostCenter_Budget Bud where Bud.CostCenterCode=? and
BudgetYear = ? and BudgetType =?';
$query = $this->db->query($subQuery,array($CostCode,$CostCode,$Year,$BudgetType));
return $query->result_array();
} }
/** /**
@ -127,16 +142,33 @@ class purchaseorder_model extends CI_Model
*/ */
function getRequistDetails($ReqNoList='') function getRequistDetails($ReqNoList='')
{ {
$this->db->distinct(); $this->db->distinct();
$this->db->select('ReqNo,ReqType,Status,Requestedby,mast.CreatedDate,emp.FirstName,emp.EmpID,emp.Designation, Dept.DEPCode,Dept.DepartmentName,mast.ReqDate'); $this->db->select('ReqNo,ReqType,Status,Requestedby,mast.CreatedDate,emp.FirstName,emp.EmpID,emp.Designation, Dept.DEPCode,Dept.DepartmentName,mast.ReqDate');
$this->db->from('T_Requestion_Master mast'); $this->db->from('T_Requestion_Master mast');
$this->db->join('T_Employee_Details emp', 'mast.Requestedby = emp.EmpID'); $this->db->join('T_Employee_Details emp', 'mast.Requestedby = emp.EmpID');
$this->db->join('T_DepartmentDetails Dept', 'emp.Departmentcode = Dept.DEPCode'); $this->db->join('T_DepartmentDetails Dept', 'emp.Departmentcode = Dept.DEPCode');
$this->db->where_in('mast.ReqNo', $ReqNoList); $this->db->where_in('mast.ReqNo', $ReqNoList);
$query = $this->db->get(); $query = $this->db->get();
return $query->result(); return $query->result();
}
/**
* This function is used to get the Requsition List for the login user
* @return array $result : This is result of the query
*/
function getRequistDetailsForPO($ReqNoList='')
{
$this->db->distinct();
$this->db->select('ReqNo,ReqType,Status,Requestedby,mast.CreatedDate,emp.FirstName,emp.EmpID,emp.Designation, Dept.DEPCode,Dept.DepartmentName,mast.ReqDate');
$this->db->from('T_Requestion_Master mast');
$this->db->join('T_Employee_Details emp', 'mast.Requestedby = emp.EmpID');
$this->db->join('T_DepartmentDetails Dept', 'emp.Departmentcode = Dept.DEPCode');
$this->db->where_in('mast.ReqNo', $ReqNoList);
$query = $this->db->get();
return $query->result();
} }
/** /**
* This function is used to get the Cost center information * This function is used to get the Cost center information
@ -161,37 +193,37 @@ class purchaseorder_model extends CI_Model
function getCostCenterbyRequist($ReqNo='',$BudYear='',$ReqType='') function getCostCenterbyRequist($ReqNo='',$BudYear='',$ReqType='')
{ {
$this->db->distinct(); $this->db->distinct();
$this->db->select('Mast.CostCenterCode,Mast.CostCenterName,Bud.BudgetAmount,ReqNo'); $this->db->select('Mast.CostCenterCode,Mast.CostCenterName,Bud.BudgetAmount,ReqNo');
$this->db->from('T_CostCenter_Master Mast'); $this->db->from('T_CostCenter_Master Mast');
$this->db->join('T_CostCenter_Departments CostDept', 'CostDept.CostCenterCode = Mast.CostCenterCode'); $this->db->join('T_CostCenter_Departments CostDept', 'CostDept.CostCenterCode = Mast.CostCenterCode');
$this->db->join('T_CostCenter_Budget Bud', 'Bud.CostCenterCode = Mast.CostCenterCode'); $this->db->join('T_CostCenter_Budget Bud', 'Bud.CostCenterCode = Mast.CostCenterCode');
$this->db->join('T_Employee_Details emp', 'CostDept.DEPCode = emp.Departmentcode'); $this->db->join('T_Employee_Details emp', 'CostDept.DEPCode = emp.Departmentcode');
$this->db->join('T_Requestion_Master req', 'req.Requestedby = emp.EmpID'); $this->db->join('T_Requestion_Master req', 'req.Requestedby = emp.EmpID');
$this->db->where('BudgetType ',$ReqType ); $this->db->where('BudgetType ',$ReqType );
$this->db->where('BudgetYear ',$BudYear ); $this->db->where('BudgetYear ',$BudYear );
if($ReqNo != '') if($ReqNo != '')
{ {
$this->db->where('ReqNo ',$ReqNo); $this->db->where('ReqNo ',$ReqNo);
} }
$query = $this->db->get(); $query = $this->db->get();
return $query->result(); return $query->result();
} }
/** /**
* This function is used to get the Config value from configuration table * This function is used to get the Config value from configuration table
* @return array $result : This is result of the query * @return array $result : This is result of the query
*/ */
function getFormula($FormulaID='' ,$Type = '') function getRequistionNoFromPO($PONO='')
{ {
$this->db->select('FormulaID,Condition1,Condition2,Condition3,value1,value2,value3'); $this->db->select('ReqNo');
$this->db->from('T_Formula_Details'); $this->db->from('T_PurchaseOrder_LineItem');
if($FormulaID != '') if($PONO != '')
{ {
$this->db->where('FormulaID ',$FormulaID ); $this->db->where('PONO ',$PONO );
} }
$query = $this->db->get(); $query = $this->db->get();
@ -255,6 +287,8 @@ class purchaseorder_model extends CI_Model
return $query->result_array(); return $query->result_array();
} }
} }
/** /**
* This function is used to add New Purchase order Line Item to the system * This function is used to add New Purchase order Line Item to the system
*/ */
@ -276,7 +310,7 @@ class purchaseorder_model extends CI_Model
} }
/** /**
* This function is used to add New Purchase order Line Item to the system * This function is used to add Revenue Tax to the system
*/ */
function addRevenueTax($RevenueTaxList) function addRevenueTax($RevenueTaxList)
{ {
@ -286,57 +320,32 @@ class purchaseorder_model extends CI_Model
$this->db->trans_complete(); $this->db->trans_complete();
return $insert_id; return $insert_id;
} }
/** /**
* This function is used to add new PO Line Item to T_PurchaseOrderLineItem table * This function is used to add Service Tax to the system
* @return number $insert_id : This is last inserted id
*/ */
function addServiceTax($ServiceTaxList)
function addNewPOLineItem($PONO,$Material_ID,$UOM,$Quantity,$UnitPrice) {
{ $this->db->trans_start();
//echo 'addNewPOLineItem Model called'; $this->db->insert('T_Service_Tax', $ServiceTaxList);
$insert_id = $this->db->affected_rows();
$result = $this->db-> query("CALL P_LINEITEM('".$PONO."','".$Material_ID."','".$UOM."',".$Quantity.",".$UnitPrice.")") or die(mysql_error()); $this->db->trans_complete();
return $insert_id;
$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 * This function is used to add Service Tax to the system
* @param number $userId : This is user id
* @return array $result : This is user information
*/ */
function getPOLineItem($PO = '') function addImportTax($ImportTaxList)
{ {
$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->trans_start();
$this->db->from('T_POLineItem as POline '); $this->db->insert('T_Import_Tax', $ImportTaxList);
$this->db->join('T_RawMaterialDetailsN as Raw', 'POline.Material_ID = Raw.MaterialCode'); $insert_id = $this->db->affected_rows();
if(!empty($PO)) { $this->db->trans_complete();
return $insert_id;
$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 * This function used to get user information by id
* @param number $userId : This is user id * @param number $userId : This is user id
@ -352,21 +361,86 @@ class purchaseorder_model extends CI_Model
return $query->result(); return $query->result();
} }
function getPurchaseOrder($PONO) // This Method to get the Service PO Details for Edit the Item
function GetServicePurchaseOrder($PONO = '')
{ {
$this->db->select('PODetail.*,Supplier.SupplierName,Supplier.Address,usr.name as usrName'); $this->db->distinct();
$this->db->from('T_PurchaseOrderDetails AS PODetail'); $this->db->select('ReqNo,POMast.PONO,ServiceDescription,supp.SupplierID,supp.SupplierName,supp.Address,PODate,Stat.StatusName,DeliveryDate,DeliveryAddress,Stat.StatusCode');
$this->db->join('T_SupplierDetailsN as Supplier', 'PODetail.SupplierID = Supplier.SupplierID'); $this->db->from('T_PurchaseOrder_Master POMast');
$this->db->join('tbl_users as usr', 'usr.userId = PODetail.UserID'); $this->db->join('T_SupplierDetailsN supp', 'supp.SupplierID = POMast.SupplierID');
$this->db->where('PODetail.PONO', $PONO); $this->db->join('T_Status Stat', 'Stat.StatusCode = POMast.Status');
$this->db->join('T_PurchaseOrder_LineItem LineItem', 'POMast.PONO = LineItem.PONO');
$this->db->where('POMast.PONO', $PONO);
$query = $this->db->get(); $query = $this->db->get();
$result = $query->result(); $result = $query->result();
// print_r($this->db->last_query()); return $result;
return $result;
} }
// This Method to get the Service PO Child Details for Edit the Item
function GetServicePurchaseOrderDetails($PONO = '')
{
$subQuery ='SELECT distinct LineItem.LineItemNo,ReqNo,Mat.MaterialCode,Mat.MaterialName,Mat.UOM,Quantity,Rate,Status,ROUND((Quantity *Rate),2 ) as BasicValue ,ROUND((ServiceTax + EducessTax + SecHigherEducessTax + KrishiKalyantax + SwachhBharattax),2)as Taxamount
,TotalValue,ServiceTax,EducessTax,SecHigherEducessTax,KrishiKalyantax,SwachhBharattax,CostCenterCode
FROM T_PurchaseOrder_LineItem LineItem
join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
join T_Service_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo
where LineItem.PONO =?';
$query = $this->db->query($subQuery,array($PONO));
return $query->result();
}
// To Update the PO
function updatePOMaster($PONO,$PODetails)
{
$this->db->where('PONO', $PONO);
$this->db->update('T_PurchaseOrder_Master', $PODetails);
return TRUE;
}
/**
* This function is used to check the Request is in Draft status
* @return array $result : This is result of the query
*/
function LineItemExists($LineItemNo)
{
$this->db->select('LineItemNo');
$this->db->from('T_Service_Tax');
$this->db->where('LineItemNo ',$LineItemNo );
//$this->db->where('Requestedby ',$ReqBy );
$query = $this->db->get();
if ($query->num_rows > 0) {
//echo $result->num_rows;
return $query->result_array();
}
}
// To Update the PO Line Item
function updatePOLineItem($PONO,$LineItemNo,$PODetails)
{
$this->db->where('PONO', $PONO);
$this->db->where('LineItemNo', $LineItemNo);
$this->db->update('T_PurchaseOrder_LineItem', $PODetails);
return TRUE;
}
/*// To Update the PO Line Item */
function updateServiceTax($LineItemNo,$PODetails)
{
$this->db->where('LineItemNo', $LineItemNo);
$this->db->update('T_PurchaseOrder_LineItem', $PODetails);
return TRUE;
}
function getLastInsertedPO() function getLastInsertedPO()
{ {
$this->db->select('max(PONO) as PO'); $this->db->select('max(PONO) as PO');
@ -375,13 +449,7 @@ class purchaseorder_model extends CI_Model
return $query->result_array(); return $query->result_array();
} }
function updatePODetails($PO,$PODetails)
{
$this->db->where('PONO', $PO);
$this->db->update('T_PurchaseOrderDetails', $PODetails);
return TRUE;
}
/* This Method to get all the Department name for the requistion */ /* This Method to get all the Department name for the requistion */
function getDepartmentListForAllReq() function getDepartmentListForAllReq()