siddharth_application/application/models/purchaseorder_model.php~

1546 lines
62 KiB
PHP

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class purchaseorder_model extends CI_Model
{
function GetServicePOListforStatusUpdate()
{
$this->db->distinct();
$this->db->select('PO.PONO');
$this->db->from('T_PurchaseOrder_Master PO');
$this->db->Join('T_PurchaseOrder_LineItem Line','PO.PONO = Line.PONO');
$this->db->Join('T_Requestion_Master Req','Req.ReqNo = Line.ReqNo');
$this->db->Join('T_Employee_Details Emp','Emp.EmpID= Req.Requestedby');
$this->db->where('PO.POType',SERVICE);
$this->db->where('PO.status',PO_RELEASED);
$this->db->where('Emp.Departmentcode',$this->session->userdata('DEPCode'));
$query = $this->db->get();
return $query->result();
}
function GetPODetailforBillingServicePO($PONO)
{
$subQuery ='select mast.ReqNo,mast.ReqDate,supp.SupplierName,PODate,st.StatusName as WorkStatus,ServiceWorkStatus,POMast.PaymentTerms,
POMast.ServiceWorkStatus,LineItem.*,mat.MaterialName,mat.UOM,emp.FirstName,emp.LastName,POMast.TotalOrderValue
from T_PurchaseOrder_Master POMast
join T_PurchaseOrder_LineItem LineItem on LineItem.PONO = POMast.PONO
join T_SupplierDetailsN supp on supp.SupplierID = POMast.SupplierID
join T_MaterialMaster mat on mat.MaterialCode = LineItem.MaterialCode
join T_Status Stat on Stat.StatusCode = POMast.Status
join T_Status st on st.StatusCode = POMast.ServiceWorkStatus
join T_Requestion_Master mast on mast.ReqNo = LineItem.ReqNo
join tbl_users users on users.userId = mast.CreatedBy
join T_Employee_Details emp on emp.EmpID = users.EmpID
where POMast.POType=? and POMast.PONO=?';
$query = $this->db->query($subQuery,array(SERVICE,$PONO));
return $query->result_array();
}
function GetServicePOListforBilling()
{
$subQuery ='select POMast.PONO,supp.SupplierName,PODate,POMast.PaymentTerms,POMast.ServiceWorkStatusRemarks,
LineItem.*,mat.MaterialName,mat.UOM,emp.FirstName,emp.LastName,Tax.TotalValue,Cost.CostCenterName,AdvanceAmount
,Dept.DepartmentName from T_PurchaseOrder_Master POMast
join T_PurchaseOrder_LineItem LineItem on LineItem.PONO = POMast.PONO
join T_Service_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo
left join T_PurchaseOrder_AdvanceRequest PUADV on POMast.PONO=PUADV.PONO
join T_SupplierDetailsN supp on supp.SupplierID = POMast.SupplierID
join T_MaterialMaster mat on mat.MaterialCode = LineItem.MaterialCode
join T_Status Stat on Stat.StatusCode = POMast.Status
join T_Requestion_Master mast on mast.ReqNo = LineItem.ReqNo
join tbl_users users on users.userId = POMast.CreatedBy
join T_Employee_Details emp on emp.EmpID = mast.Requestedby
join T_DepartmentDetails Dept on Dept.DEPCode = emp.Departmentcode
join T_CostCenter_Master Cost on Cost.CostCenterCode=LineItem.CostCenterCode
where POMast.POType=? and ServiceWorkStatus=?';
$query = $this->db->query($subQuery,array(SERVICE,SERVICE_COMPLETED));
//print_r( $this->db->last_query());
return $query->result();
}
/**
* 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()
{
$this->db->distinct();
$this->db->select('POMast.PONO,supp.SupplierName,TotalOrderValue,PODate,Stat.StatusName,Req.ReqType,DeliveryDate');
$this->db->from('T_PurchaseOrder_Master POMast');
$this->db->join('T_SupplierDetailsN supp', 'supp.SupplierID = POMast.SupplierID');
$this->db->join('T_Status Stat', 'Stat.StatusCode = POMast.Status');
$this->db->join('T_PurchaseOrder_LineItem LineItem', 'POMast.PONO = LineItem.PONO');
$this->db->join('T_Requestion_Master Req', 'Req.ReqNo = LineItem.ReqNo');
// print_r( $this->db->last_query());
$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($forwhat='')
{
$this->db->distinct();
$this->db->select('POMast.PONO,supp.SupplierName,TotalOrderValue,PODate,Stat.StatusName,Stat.StatusCode,POMast.POType as ReqType,DeliveryDate,DeliverySchedule,DeliveryOption,POMast.CapitalRange');
$this->db->from('T_PurchaseOrder_Master POMast');
$this->db->join('T_SupplierDetailsN supp', 'supp.SupplierID = POMast.SupplierID');
$this->db->join('T_Status Stat', 'Stat.StatusCode = POMast.Status');
$this->db->join('T_PurchaseOrder_LineItem LineItem', 'POMast.PONO = LineItem.PONO');
$this->db->join('T_Requestion_Master Req', 'Req.ReqNo = LineItem.ReqNo');
if($forwhat=='amendment')
{
$this->db->where('POMast.Status',PO_RELEASED);
}
else
{
$this->db->where('POMast.Status !=',PO_AMENDED);
// $this->db->order_by('POMast.Status !=',PO_AMENDED);
}
$query = $this->db->get();
//print_r( $this->db->last_query());
$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($supID='')
{
$this->db->select('SupplierID, SupplierName,Address,PaymentID');
$this->db->from('T_SupplierDetailsN');
if($supID != '')
{
$this->db->where('SupplierID',$supID);
}
//$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 getRawPOMaterialList($ReqNo,$IsArray='')
{
$result = $this->db-> query("CALL P_GET_REQUISTIONLIST('".$ReqNo."')") or die(mysql_error());
$result ->next_result();
//print_r($this->db->last_query());
if ($result->num_rows > 0)
{
//echo 'PO Line item Inserted successfully';
if($IsArray != '')
{
return $result->result_array();
}
else
{
return $result->result();
}
}
}
/**
This Function to get the List of Requistion which require to create PO
*/
function getAllRequistionListToCreatePO()
{
$result = $this->db-> query("CALL P_PURCHASEORDER_DETAILS()") or die(mysql_error());
$result ->next_result();
if ($result->num_rows > 0)
{
return $result->result();
}
}
/**
* This function is used to get the Raw Material information
* @return array $result : This is result of the query
*/
function getRawMaterialList($MatType='',$ReqNoList='')
{
$this->db->select('ReqNo,Req.MaterialCode,MaterialName,UOM,Req.Quantity');
$this->db->from('T_Requestion_Details Req');
$this->db->join('T_MaterialMaster mat', 'Req.MaterialCode = mat.MaterialCode');
$this->db->where('mat.MaterialType', $MatType);
$this->db->where_in('Req.ReqNo', $ReqNoList);
$query = $this->db->get();
//print_r($this->db->last_query());
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 join T_Requestion_Master mast on mast.ReqNo = Item.ReqNo where Item.CostCenterCode=? and mast.ReqType=?)as Totalvalue
from T_CostCenter_Budget Bud where Bud.CostCenterCode=? and
BudgetYear = ? and BudgetType =?'; */
$subQuery ='select BudgetAmount, (select ifnull(sum(Quantity*Rate)-tax.AfterDiscount,0) as Totalvalue from
T_PurchaseOrder_LineItem Item join T_Requestion_Master mast
on mast.ReqNo = Item.ReqNo left join T_Revenue_Tax tax on
tax.LineItemNo = Item.LineItemNo where Item.CostCenterCode=? and mast.ReqType=?)as Totalvalue
from T_CostCenter_Budget Bud where Bud.CostCenterCode=? and
BudgetYear = ? and BudgetType =?';
$query = $this->db->query($subQuery,array($CostCode,$BudgetType,$CostCode,$Year,$BudgetType));
//print_r($this->db->last_query());
return $query->result_array();
}
function GetAvailableImportBudgetAmount($CostCode,$Year,$BudgetType)
{
$subQuery='select BudgetAmount,(select ifnull(sum((Quantity*Rate*ExchangeRate)),0)as TValue from T_PurchaseOrder_LineItem LineItem
join T_PurchaseOrder_Master Mast on Mast.PONO=LineItem.PONO where POType=?
and CostCenterCode=?)as TotalValue from T_CostCenter_Budget Bud where Bud.CostCenterCode=? and BudgetYear=? and BudgetType=?';
$query = $this->db->query($subQuery,array($BudgetType,$CostCode,$CostCode,$Year,$BudgetType));
//print_r($this->db->last_query());
return $query->result_array();
}
/**
* This function is used to get the Requsition List for the login user
* @return array $result : This is result of the query
*/
function getRequistDetails($ReqNoList='')
{
$this->db->distinct();
$this->db->select('ReqNo,ReqType,Status,Requestedby,mast.CreatedDate,mast.Schedule_Type,mast.NumberOfService,mast.Service_Period,emp.FirstName,emp.EmpID,emp.Designation, Dept.DEPCode,Dept.DepartmentName,mast.ReqDate,mast.CostCenterCode,mast.Status');
$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();
//print_r($this->db->last_query());
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
* @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 CostCenter for the Selected Requistion Number
* @return array $result : This is result of the query
*/
function getCostCenterbyRequist($ReqNo='',$BudYear='',$ReqType='')
{
$this->db->distinct();
$this->db->select('Mast.CostCenterCode,Mast.CostCenterName,Bud.BudgetAmount,ReqNo');
$this->db->from('T_CostCenter_Master Mast');
$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_Employee_Details emp', 'CostDept.DEPCode = emp.Departmentcode');
$this->db->join('T_Requestion_Master req', 'req.Requestedby = emp.EmpID');
$this->db->where('BudgetType ',$ReqType );
$this->db->where('BudgetYear ',$BudYear );
if($ReqNo != '')
{
$this->db->where('ReqNo ',$ReqNo);
}
$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 getRequistionNoFromPO($PONO='')
{
$this->db->distinct();
$this->db->select('ReqNo,');
$this->db->from('T_PurchaseOrder_LineItem');
if($PONO != '')
{
$this->db->where('PONO ',$PONO );
}
$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 Company information from T_Company_Details table
* @return array $result : This is result of the query
*/
function getCompanyInformation()
{
$this->db->select('CompanyName,Address');
$this->db->from('T_Company_Details');
$query = $this->db->get();
return $query->result();
}
/**
* This function is used to get the Employee List
* @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 get the Employee List
* @return array $result : This is result of the query
*/
function getLastCreatedPODate()
{
$this->db->select('max(PODate) as PODate');
$this->db->from('T_PurchaseOrder_Master');
$query = $this->db->get();
return $query->result();
}
function getLastReleasedPODate()
{
$this->db->select('max(ReleasedOn) as PODate');
$this->db->from('T_PurchaseOrder_Master');
$query = $this->db->get();
return $query->result();
}
/**
* This function is used to add New Purchase order to the system
*/
function addPOMaster($POMaster)
{
$this->db->trans_start();
$this->db->insert('T_PurchaseOrder_Master', $POMaster);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
// print_r($this->db->last_query());
if($insert_id>0)
{
$subQuery = 'select max(PONO) as PONO from T_PurchaseOrder_Master';
$query = $this->db->query($subQuery);
return $query->result_array();
}
}
function addAmendPOMaster($POMaster,$CreatedBy,$ParentPO)
{
// print_r($POMaster);
$this->db->trans_start();
$this->db->insert('T_PurchaseOrder_Master', $POMaster);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
// print_r($this->db->last_query());
if($insert_id>0)
{
$subQuery = 'select max(PONO) as PONO from T_PurchaseOrder_Master where CreatedBy=? and ParentPO=?';
$query = $this->db->query($subQuery,array($CreatedBy,$ParentPO));
return $query->result_array();
}
}
/**
* This function is used to add New Purchase order Line Item to the system
*/
function addPOLineItem($POLineItem)
{
$this->db->trans_start();
$this->db->insert('T_PurchaseOrder_LineItem', $POLineItem);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
// print_r($this->db->last_query());
if($insert_id>0)
{
$subQuery = 'select max(LineItemNo) as LineItemNo from T_PurchaseOrder_LineItem';
$query = $this->db->query($subQuery);
return $query->result_array();
}
}
/**
* This function is used to add Revenue Tax to the system
*/
function addRevenueTax($RevenueTaxList)
{
$this->db->trans_start();
$this->db->insert('T_Revenue_Tax', $RevenueTaxList);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return $insert_id;
}
/**
* This function is used to add Service Tax to the system
*/
function addServiceTax($ServiceTaxList)
{
$this->db->trans_start();
$this->db->insert('T_Service_Tax', $ServiceTaxList);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return $insert_id;
}
/**
* This function is used to add Service Tax to the system
*/
function addImportTax($ImportTaxList)
{
$this->db->trans_start();
$this->db->insert('T_Import_Tax', $ImportTaxList);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return $insert_id;
}
function addadvanceRequest($advance)
{
$this->db->trans_start();
$this->db->insert('T_PurchaseOrder_AdvanceRequest', $advance);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return $insert_id;
}
/**
* 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();
}
// This Method to get the Service PO Details for Edit the Item
function GetServicePurchaseOrder($PONO = '')
{
$this->db->distinct();
$this->db->select('ReqNo,POMast.PONO,POMast.PaymentTerms,POMast.PaymentOtherDescription,ServiceDescription,supp.SupplierID,supp.SupplierName,supp.Address,PODate,Stat.StatusName,DeliveryOption,DeliverySchedule,DeliveryDate,DeliveryAddress,POMast.PaymentTerms,POMast.ExchangeRate,POMast.UpdatedOn,Stat.StatusCode,POMast.ServiceWorkStatus,POMast.*');
$this->db->from('T_PurchaseOrder_Master POMast');
$this->db->join('T_SupplierDetailsN supp', 'supp.SupplierID = POMast.SupplierID');
$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();
$result = $query->result();
return $result;
}
// This Method to get the Service PO Child Details for Edit the Item
// This Method to get the Service PO Child Details for Edit the Item
function GetServicePurchaseOrderDetails($PONO = '')
{
$subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.ReqNo,Mat.MaterialCode,Mat.MaterialName,Mat.UOM,Quantity,ReceivedQuantity,Rate,LineItem.Status,(Quantity *Rate) as BasicValue ,(After_CGST + After_SGST + After_IGST) as Taxamount
,TotalValue,CGST,After_CGST,SGST,After_SGST,IGST,After_IGST,otherallowance,LineItem.CostCenterCode,LineItem.ServiceFrequency,LineItem.ServiceMaterialDescription,Req.Schedule_Type,Req.NumberOfService,Req.Service_Period
FROM T_PurchaseOrder_LineItem LineItem
join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
join T_Service_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo
join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo
where LineItem.PONO =?';
$query = $this->db->query($subQuery,array($PONO));
return $query->result();
}
// This Method to get the Service PO Child Details for Edit the Item
function GetServicePurchaseOrderDetailsForPrint($PONO = '')
{
$subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.ReqNo,LineItem.ServiceMaterialDescription,Mat.MaterialCode,Mat.MaterialName,Mat.UOM,Mat.HSNCODE,
LineItem.Quantity,LineItem.Rate,(LineItem.Quantity *LineItem.Rate) as BasicValue ,(After_CGST + After_SGST + After_IGST) as Taxamount
,TotalValue,CGST,SGST,IGST,After_CGST,After_SGST,After_IGST,otherallowance,LineItem.CostCenterCode,sup.SupplierName,sup.Address,POMaster.DeliveryAddress,POMaster.DeliveryDate,POMaster.Status,POMaster.PODate,POMaster.PONO,POMaster.ServiceDescription,POMaster.PaymentOtherDescription,POMaster.DeliveryOption,POMaster.DeliverySchedule,ReqMat.NumberOfService,ReqMat.Service_Period,ReqMat.Schedule_Type,Payment.PaymentID,Payment.PaymentTerms,AdvanceAmount FROM
T_PurchaseOrder_LineItem LineItem
join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
join T_Service_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo
join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO
join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID
join T_Requestion_Master ReqMat on ReqMat.ReqNo = LineItem.ReqNo
join T_PaymentTerms Payment on Payment.PaymentID = POMaster.PaymentTerms
left join T_PurchaseOrder_AdvanceRequest PurAdv on POMaster.PONO=PurAdv.PONO
where LineItem.PONO =?';
$query = $this->db->query($subQuery,array($PONO));
return $query->result();
}
function GetServicePurchaseOrderAmendDetailsforPdfprint($PONO = '')
{
$subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.ReqNo,LineItem.ServiceMaterialDescription,Mat.MaterialCode,Mat.MaterialName,
Mat.UOM,Quantity,Rate,ROUND((Quantity *Rate),2 ) as BasicValue,POMaster.AmendedDetails,LineItem.AmendedDetails as lineamenddetails,
ROUND(( Tax.After_SGST + Tax.After_CGST + Tax.After_IGST ) ,2)as Taxamount,ReqMat.NumberOfService,ReqMat.Schedule_Type,ReqMat.Service_Period,
TotalValue,Tax.*,LineItem.CostCenterCode ,POMaster.*,sup.SupplierName,sup.Address,Payment.PaymentTerms
FROM T_PurchaseOrder_LineItem LineItem
join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
join T_Service_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo
join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO
join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID
join T_PaymentTerms Payment on Payment.PaymentID = POMaster.PaymentTerms
join T_Requestion_Master ReqMat on ReqMat.ReqNo = LineItem.ReqNo
where LineItem.PONO =?';
$query = $this->db->query($subQuery,array($PONO));
return $query->result();
}
// This Method to get the Revenue PO Child Details for Edit the Item
function GetRevenuePurchaseOrderDetails($PONO = '')
{
$subQuery ='SELECT distinct LineItem.LineItemNo,Req.ReqNo,Mat.MaterialCode,Mat.MaterialName,Mat.UOM,Quantity,ReceivedQuantity,Rate,Req.Status,(Quantity *Rate) as BasicValue , ((AfterPackagingValue + AfterFreightValue + AfterSGST + AfterCGST +
AfterIGST + Insurance)) as Taxamount ,TotalValue,Tax.*,Req.CostCenterCode,Dept.DepartmentName
FROM T_PurchaseOrder_LineItem LineItem
join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
join T_Revenue_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo
join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo
join T_Employee_Details emp on Req.Requestedby = emp.EmpID
join T_DepartmentDetails Dept on emp.Departmentcode = Dept.DEPCode
where LineItem.PONO =?';
$query = $this->db->query($subQuery,array($PONO));
return $query->result();
}
// This Method to get the Revenue PO Child Details for Edit the Item
function GetRevenuePurchaseOrderDetailsForPDF($PONO = '')
{
$subQuery ='SELECT distinct LineItem.LineItemNo,ReqNo,Mat.MaterialCode,Mat.MaterialName,
Mat.UOM,Mat.HSNCODE,Quantity,Rate,(Quantity *Rate) as BasicValue ,
(AfterPackagingValue + AfterFreightValue + AfterSGST + AfterCGST +
AfterIGST + Insurance) as Taxamount,AdvanceAmount,
TotalValue,Tax.*,LineItem.CostCenterCode ,POMaster.*,sup.SupplierName,sup.Address,Payment.PaymentID,Payment.PaymentTerms
FROM T_PurchaseOrder_LineItem LineItem
join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
join T_Revenue_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo
join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO
join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID
join T_PaymentTerms Payment on Payment.PaymentID = POMaster.PaymentTerms
left join T_PurchaseOrder_AdvanceRequest PurAdv on POMaster.PONO=PurAdv.PONO
where LineItem.PONO =?';
$query = $this->db->query($subQuery,array($PONO));
return $query->result();
}
// This Method to get the Revenue PO Child Details for Edit the Item
function GetRevenuePurchaseOrderDetailsForAmendPDF($PONO = '')
{
$subQuery ='SELECT distinct LineItem.LineItemNo,ReqNo,Mat.MaterialCode,Mat.MaterialName,POMaster.PaymentOtherDescription,
Mat.UOM,Quantity,Rate,ROUND((Quantity *Rate),2 ) as BasicValue ,
ROUND(((AfterPackagingValue + AfterFreightValue + AfterSGST + AfterCGST +
AfterIGST + Insurance)) ,2)as Taxamount,
TotalValue,Tax.*,LineItem.CostCenterCode ,POMaster.*,sup.SupplierName,sup.Address,LineItem.AmendedDetails as LineAmend,Payment.PaymentTerms
FROM T_PurchaseOrder_LineItem LineItem
join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
join T_Revenue_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo
join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO
join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID
join T_PaymentTerms Payment on Payment.PaymentID = POMaster.PaymentTerms
where LineItem.PONO =?';
$query = $this->db->query($subQuery,array($PONO));
return $query->result();
}
function GetImportPurchaseOrderDetailsForPDF($PONO = '')
{
// $subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.ReqNo,Mat.MaterialCode,Mat.MaterialName,
// Mat.UOM,Quantity,ReqMas.Requestedby,Rate,ROUND((RMCIncludingCustomersPerKG*Quantity),2)as Taxamount,
// ProductPrice,Tax.*,LineItem.CostCenterCode , POMaster.*,sup.SupplierName,sup.Address
// FROM T_PurchaseOrder_LineItem LineItem
// join T_Requestion_Master ReqMas on ReqMas.ReqNo=LineItem.ReqNo
// join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
// join T_Import_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo
// join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO
// join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID
// where LineItem.PONO =?';
$subQuery='SELECT distinct LineItem.LineItemNo,LineItem.ReqNo,Mat.MaterialCode,Mat.MaterialName,Import_DispatchDetails,
Mat.UOM,Quantity,ReqMas.Requestedby,Rate,ROUND((RMCIncludingCustomersPerKG*Quantity),2)as Taxamount ,
ProductPrice,Tax.*,LineItem.CostCenterCode ,Date(ReqMast.ReqDate) as ReqDate,POMaster.*,sup.SupplierName,sup.Address,LineItem.AmendedDetails as LineAmend,AdvanceAmount, Pay.PaymentTerms as Pay
FROM T_PurchaseOrder_LineItem LineItem
join T_Requestion_Master ReqMas on ReqMas.ReqNo=LineItem.ReqNo
join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
join T_Import_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo
join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO
join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID
left join T_PurchaseOrder_AdvanceRequest PurAdv on POMaster.PONO=PurAdv.PONO
join T_Requestion_Master ReqMast on LineItem.ReqNo=ReqMast.ReqNo
join T_PaymentTerms Pay on POMaster.PaymentTerms=Pay.PaymentID
where LineItem.PONO =?';
$query = $this->db->query($subQuery,array($PONO));
//print_r($this->db->last_query());
return $query->result();
}
function GetCurrencyDetail($Currency='')
{
$subQuery='SELECT * from T_Currency_Details where Currency_Code=?';
$query=$this->db->query($subQuery,array($Currency));
//print_r($query);
return $query->result();
}
function GerRequesterName($Requester='')
{
$subQuery='SELECT EmpID,FirstName,Departmentcode from T_Employee_Details where EmpID=?';
$query=$this->db->query($subQuery,array($Requester));
return $query->result();
}
function GerRequesterDep($Depcode='')
{
$subQuery='SELECT DepartmentName from T_DepartmentDetails where DEPCode=?';
$query=$this->db->query($subQuery,array($Depcode));
return $query->result();
}
function GerCurrencyCodeName($Currencycode='')
{
$subQuery='SELECT * from T_Currency_Details where Currency_Code=?';
$query=$this->db->query($subQuery,array($Currencycode));
//print_r($this->db->last_query());
return $query->result();
}
function GetPOStatus($Status='')
{
$subQuery='SELECT StatusName from T_Status where StatusCode=?';
$query=$this->db->query($subQuery,array($Status));
return $query->result();
}
function GetPaymentTerms($PONO='')
{
$subQuery='SELECT PaymentTerms from T_PurchaseOrder_Master where PONO=?';
$query=$this->db->query($subQuery,array($PONO));
//print_r($query);
return $query->result();
}
// function getSupplierPayment($Currency='')
// {
// $subQuery='select distinct PaymentTerms from T_SupplierDetailsN';
// $query=$this->db->query($subQuery,array($Currency));
// //print_r($this->db->last_query());
// return $query->result();
// }
function getSupplierPayment($Config_ID='')
{
// $subQuery='select distinct PaymentTerms from T_SupplierDetailsN';
$subQuery='select ConfigValue from T_ConfigDetails where Config_ID=?';
$query=$this->db->query($subQuery,array($Config_ID));
//print_r($this->db->last_query());
return $query->result();
}
function GetWorkStatus($Config_ID='')
{
$subQuery = 'select ConfigValue from T_ConfigDetails where Config_ID=?';
$query=$this->db->query($subQuery,array($Config_ID));
//print_r($query);
return $query->result();
}
function GetImportPurchaseOrderDetails($PONO = '')
{
$subQuery ='SELECT distinct LineItem.LineItemNo,Req.ReqNo,Mat.MaterialCode,Mat.MaterialName,
Mat.UOM,Quantity,Rate,Req.Status,ROUND((Quantity *Rate),2 ) as BasicValue,ReceivedQuantity,
QuantityRejected,ROUND(ReceivedQuantity-QuantityRejected)as PendingQty,
ROUND((RMCIncludingCustomersPerKG*Quantity),2)as Taxamount,LandingCharge,HighSeasSalesCharge,CustomDuty,ExciseDuty,ExciseDutyEdCess,CustomEdCess,POMast.ExchangeRate,AfterLandingCharge,AfterHighSeasSalesCharge,AfterCustomDuty,AfterExciseDuty,AfterExciseDutyEdCess,AddlExciseDuty,AfterAddlExciseDuty,Grossdutypayable,AvailableModvat,Grossexpensesduetocustomduty,purchaseratePerKG,CustomDutyExpensesPerKG,RMCIncludingCustomersPerKG,QuantityKG,BasicPriceInMTon,ProductPrice,CustomSHCess,AfterCustomSHCess,AfterExciseDutySHCess,ExciseDutySHCess,AfterCustomEdCess,ROUND((Quantity *Rate)+(RMCIncludingCustomersPerKG*Quantity),2)as TotalOrderValue,ROUND((POMast.ExchangeRate*BasicPriceInMTon),2) as BasicINRValue,TotalValue,CurrencyType,ReceivedQuantity,
Req.CostCenterCode,Dept.DepartmentName FROM T_PurchaseOrder_LineItem LineItem
join T_PurchaseOrder_Master POMast on POMast.PONO = LineItem.PONO
join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
join T_Import_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo
join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo
join T_Employee_Details emp on Req.Requestedby = emp.EmpID
left join T_MRIR_Details Det on Det.MaterialCode=LineItem.MaterialCode
join T_DepartmentDetails Dept on emp.Departmentcode = Dept.DEPCode where LineItem.PONO =?';
//print_r($subQuery);
$query = $this->db->query($subQuery,array($PONO));
return $query->result();
}
function GetCapitalAmendPurchaseOrderDetailsForprintPDF($PONO = '')
{
//echo $PONO;
$subQuery ='SELECT distinct LineItem.PONO,LineItem.AmendedDetails as lineamd,LineItem.LineItemNo,SUP.SupplierName,SUP.Address,POMast.DeliveryAddress,POMast.DeliveryDate,POMast.PODate,POMast.DeliveryOption,POMast.ServiceDescription,POMast.ServiceDescription,POMast.Import_DispatchDetails,POMast.Import_PlaceofOrgin,POMast.AmendedDetails,POMast.DeliverySchedule,POMast.TotalOrderValue,Req.ReqNo,Mat.MaterialCode,Mat.MaterialName,LineItem.ServiceMaterialDescription,LineItem.ServiceFrequency,
Mat.UOM,Quantity,Rate,POMast.Status,POMast.ExchangeRate,POMast.ExchangeRateCalculatedon,POMast.PaymentOtherDescription,POMast.TotalOrderValue as BasicValue,POMast.CapitalRange,POMast.CurrencyType,Payment.PaymentTerms,
Req.CostCenterCode FROM T_PurchaseOrder_LineItem LineItem
join T_PurchaseOrder_Master POMast on POMast.PONO = LineItem.PONO
join T_SupplierDetailsN SUP on SUP.SupplierID=POMast.SupplierID
join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
join T_Service_Tax ServiceTax on ServiceTax.LineItemNo = LineItem.LineItemNo
join T_Import_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo
join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo
join T_PaymentTerms Payment on Payment.PaymentID = POMast.PaymentTerms
join T_Employee_Details emp on Req.Requestedby = emp.EmpID where LineItem.PONO =?';
$query = $this->db->query($subQuery,array($PONO));
//print_r ($query->result());
return $query->result();
}
function GetCurrencytype()
{
$subQuery = 'select * from T_Currency_Details';
$query = $this->db->query($subQuery);
return $query->result();
}
function GetINRCurrencytype($Currency_Code='')
{
$subQuery='select * from T_Currency_Details where Currency_Code=?';
$query=$this->db->query($subQuery,array($Currency_Code));
//print_r($this->db->last_query());
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;
}
// To update Parent PO as Amended PO
function updateAmendPOMaster($PONO,$PODetail)
{
//echo $PONO."from model";
$this->db->where('PONO', $PONO);
$this->db->update('T_PurchaseOrder_Master', $PODetail);
$insert_id = $this->db->affected_rows();
return $insert_id;
}
/**
* This function is used to check the Line Item is already available in the database
* @return array $result : This is result of the query
*/
function LineItemExists($LineItemNo)
{
$this->db->select('LineItemNo,TaxID');
$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();
}
}
/**
* This function is used to check the Revenue Line Item is already available in the database
* @return array $result : This is result of the query
*/
function LineItemExistsinRevenueTax($LineItemNo)
{
$this->db->select('LineItemNo');
$this->db->from('T_Revenue_Tax');
$this->db->where('LineItemNo ',$LineItemNo );
$query = $this->db->get();
if ($query->num_rows > 0) {
return $query->result_array();
}
}
function LineItemExistsinImportTax($LineItemNo)
{
$this->db->select('LineItemNo');
$this->db->from('T_Import_Tax');
$this->db->where('LineItemNo ',$LineItemNo );
$query = $this->db->get();
if ($query->num_rows > 0) {
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 Service Tax Item */
function updateServiceTax($LineItemNo,$PODetails)
{
$this->db->where('LineItemNo', $LineItemNo);
$this->db->update('T_Service_Tax', $PODetails);
// print_r($this->db->last_query());
return TRUE;
}
/*// To Update the Revenue Tax Item */
function updateRevenueTax($LineItemNo,$PODetails)
{
$this->db->where('LineItemNo', $LineItemNo);
$this->db->update('T_Revenue_Tax', $PODetails);
// print_r($this->db->last_query());
return TRUE;
}
function updateImportTax($LineItemNo,$PODetails)
{
$this->db->where('LineItemNo', $LineItemNo);
$this->db->update('T_Import_Tax', $PODetails);
// print_r($this->db->last_query());
return TRUE;
}
function getLastInsertedPO()
{
$this->db->select('max(PONO) as PO');
$this->db->from('T_PurchaseOrderDetails');
$query = $this->db->get();
return $query->result_array();
}
/* This Method to get all the Department name for the requistion */
function getDepartmentListForAllReq()
{
$subQuery ='SELECT DISTINCT DEPT.DEPCode,DEPT.DepartmentName FROM T_Requestion_Master REQ
JOIN T_Employee_Details EMP ON REQ.Requestedby = EMP.EmpID
JOIN T_DepartmentDetails DEPT ON EMP.Departmentcode = DEPT.DEPCode WHERE REQ.Status not in(?,?,?,?)';
$query = $this->db->query($subQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED));
//print_r($query);
return $query->result();
}
/*
This Method to get all department list
*/
function getDepartmentAllList()
{
$subQuery ='SELECT DISTINCT DEPCode,DepartmentName FROM T_DepartmentDetails';
$query = $this->db->query($subQuery);
//print_r($query);
return $query->result();
}
function getStatusListforAllReq()
{
$subQuery ='SELECT DISTINCT STAT.StatusCode, STAT.StatusName FROM T_Requestion_Master REQ
JOIN T_Status STAT on REQ.Status = STAT.StatusCode where STAT.StatusCode not in (?,?,?,?)';
$query = $this->db->query($subQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED));
// print_r( $this->db->last_query());
return $query->result();
}
function getStatusByDepartment($DepNo='')
{
$subQuery ='SELECT DISTINCT STAT.StatusCode ,STAT.StatusName FROM T_Requestion_Master REQ
JOIN T_Employee_Details EMP ON REQ.Requestedby = EMP.EmpID
JOIN T_DepartmentDetails DEPT ON EMP.Departmentcode = DEPT.DEPCode
JOIN T_Status STAT ON REQ.Status = STAT.StatusCode
WHERE DEPT.DEPCode=? AND REQ.Status NOT IN (?,?,?,?)';
$query = $this->db->query($subQuery,array($DepNo,REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED));
return $query->result_array();
}
function getRequistionListbySearch($Depid='',$Status='',$FromDate='',$ToDate='')
{
$subQuery =' SELECT ReqNo,ReqType,Requestedby,EMP.FirstName,EMP.Designation,STAT.StatusCode ,STAT.StatusName,ReqDate,DEPT.DEPCode,DEPT.DepartmentName FROM T_Requestion_Master REQ
JOIN T_Employee_Details EMP ON REQ.Requestedby = EMP.EmpID
JOIN T_DepartmentDetails DEPT ON EMP.Departmentcode = DEPT.DEPCode
JOIN T_Status STAT on REQ.Status = STAT.StatusCode
where REQ.Status NOT IN (?,?,?,?,?)';
$appendQuery = $subQuery ;
if($Depid != '' && $Status != '' && $FromDate != '' && $ToDate != '')
{
$appendQuery .= ' AND DEPT.DEPCode=? AND STAT.StatusCode=? AND ReqDate >= ? AND ReqDate <= ?';
//echo "$appendQuery";die();
$query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Depid ,$Status,$FromDate,$ToDate));
//print_r($this->db->last_query());
return $query->result_array();
}
else if($Depid != '' && $Status == '' && $FromDate == '' && $ToDate == '')
{
$appendQuery .= ' AND DEPT.DEPCode=?';
$query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Depid));
//print_r($this->db->last_query());
return $query->result_array();
}
else if($Depid == '' && $Status != '' && $FromDate == '' && $ToDate == '')
{
$appendQuery .= ' AND STAT.StatusCode=?';
$query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Status));
//print_r($this->db->last_query());
return $query->result_array();
}
else if($Depid == '' && $Status == '' && $FromDate != '' && $ToDate != '')
{
$appendQuery .= ' AND ReqDate >= ? AND ReqDate <= ?';
$query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$FromDate,$ToDate));
//print_r($this->db->last_query());
return $query->result_array();
}
else if($Depid != '' && $Status != '' && $FromDate == '' && $ToDate == '')
{
$appendQuery .= ' AND DEPT.DEPCode=? AND STAT.StatusCode=?';
$query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Depid ,$Status));
// print_r($this->db->last_query());
return $query->result_array();
}
else if($Depid != '' && $Status == '' && $FromDate != '' && $ToDate != '')
{
$appendQuery .= ' AND DEPT.DEPCode=? AND ReqDate >= ? AND ReqDate <= ?';
$query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Depid ,$FromDate,$ToDate));
//print_r($this->db->last_query());
return $query->result_array();
}
else if($Depid == '' && $Status != '' && $FromDate != '' && $ToDate != '')
{
$appendQuery .= ' AND STAT.StatusCode=? AND ReqDate >= ? AND ReqDate <= ?';
$query = $this->db->query($appendQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED,$Status ,$FromDate,$ToDate));
// print_r($this->db->last_query());
return $query->result_array();
}
else
{
$query = $this->db->query($subQuery,array(REQ_DRAFT,REQ_PENDING_APPROVAL,REQ_DELETED,REQ_REJECTED,REQ_PO_CREATED));
//print_r($this->db->last_query());
return $query->result();
}
}
function UpdateRequistItemStatus()
{
$query = $this->db->query("update T_Requestion_Details REQ
JOIN T_PurchaseOrder_LineItem line ON REQ.ReqNo = line.ReqNo
JOIN T_PurchaseOrder_Master PO ON PO.PONO = line.PONO
set REQ.Status = CASE WHEN REQ.Quantity = line.Quantity THEN 'ST022' WHEN REQ.Quantity > line.Quantity THEN 'ST023' ELSE 'ST003' END ,
REQ.updatedOn= CURRENT_TIMESTAMP
where PO.Status ='".PO_CREATED."'");
//$query ->next_result();
}
function UpdateRequistionStatus()
{
$result = $this->db-> query("CALL P_UPDATE_REQUISTIONSTATUS_New()") or die(mysql_error());
$result ->next_result();
}
/**
* This function is used to delete the Line item from details into Database
* @return array $result : This is result of the query
*/
function DeletePOLineItem( $LineItem='',$ReqNo='',$MaterialCode='')
{
$this->db->where('LineItemNo', $LineItem);
$this->db->where('ReqNo', $ReqNo);
$this->db->where('MaterialCode', $MaterialCode);
$this->db->delete('T_PurchaseOrder_LineItem');
return TRUE;
}
/**
* This function is used to delete the Revenue item from details into Database
* @return array $result : This is result of the query
*/
function DeletePORevenueTax( $LineItem='')
{
$this->db->where('LineItemNo', $LineItem);
$this->db->delete('T_Revenue_Tax');
return TRUE;
}
/**
* This function is used to delete Service Tax from details into Database
* @return array $result : This is result of the query
*/
function DeletePOServiceTax( $LineItem='')
{
$this->db->where('LineItemNo', $LineItem);
$this->db->delete('T_Service_Tax');
return TRUE;
}
function DeletePOImportTax( $LineItem='')
{
$this->db->where('LineItemNo', $LineItem);
$this->db->delete('T_Import_Tax');
return TRUE;
}
/**
* This function is used to get the List of PO details to the approver
* @return array $result : This is result of the query
join T_DepartmentDetails Dept on emp.Departmentcode = Dept.DEPCode
*/
function getPOList($Amendment)
{
$this->db->distinct();
$this->db->select('mast.PONO,mast.TotalOrderValue,st.StatusCode,st.StatusName,emp.FirstName,mast.CreatedDate,ccm.CostCenterName,ccm.CostCenterCode,mast.POType as ReqType,mast.Remarks,DepartmentName,mast.ApprovedBy,(select EmpID from tbl_users where userId=mast.ApprovedBy )as EID,
(select FirstName from T_Employee_Details where EmpID=EID)as Approver');
$this->db->from('T_PurchaseOrder_Master mast');
// $this->db->order_by('mast.Status',"PO_CREATED");
$this->db->join('T_Status st', 'st.StatusCode=mast.Status');
$this->db->join('T_PurchaseOrder_LineItem req', 'req.PONO= mast.PONO');
$this->db->join('T_Requestion_Master rmast','rmast.ReqNo=req.ReqNo');
//$this->db->join('T_CostCenter_Budget bud','bud.CostCenterCode = req.CostCenterCode and bud.BudgetType = rmast.ReqType');
$this->db->join('T_CostCenter_Master ccm','ccm.CostCenterCode = req.CostCenterCode');
$this->db->join('tbl_users tbl', 'rmast.createdby=tbl.userid');
$this->db->join('T_Employee_Details as emp', 'emp.empid=tbl.empid');
$this->db->join('T_DepartmentDetails as Dep','Dep.DEPCode=emp.Departmentcode');
// $this->db->where('mast.Status',PO_AMENDED); // EMERGENGY PO
if($Amendment=='A'){ //A- Approved
$this->db->or_where('mast.Status',PO_CREATED);//PO CREATED
$this->db->or_where('mast.Status',PO_ONHOLD);//ON HOLD
$this->db->or_where('mast.Status',PO_AWAITING_RELEASE);// PO APPROVED
$this->db->or_where('mast.Status',PO_RELEASED);//PO RELEASED
$this->db->or_where('mast.Status',REQITEM_Emergency_PO_CREATED);
$this->db->order_by('mast.Status'); // EMERGENGY PO
// $this->db->or_where('mast.Status',PO_AMENDED); // EMERGENGY PO
}
else if($Amendment=='R'){ // R -RELEASED
$this->db->or_where('mast.Status',PO_AWAITING_RELEASE);// PO APPROVED
$this->db->or_where('mast.Status',PO_RELEASED);
$this->db->order_by('mast.Status','asc');
}
$result=$this->db->get();
// print_r($this->db->last_query());
return $result->result();
}
function UpdatePO($store, $PONO)
{
$this->db->where('PONO', $PONO);
$this->db->update('T_PurchaseOrder_Master', $store);
return TRUE;
}
function GetReleasedDetails($PONO){
$this->db->select('mast.ReleasedOn,re.FirstName');
$this->db->from('T_PurchaseOrder_Master mast');
$this->db->join('tbl_users tbl','mast.ReleasedBy=tbl.userid');
$this->db->join('T_Employee_Details re','re.EmpID=tbl.EmpID');
$this->db->where('mast.PONO',$PONO);
$result=$this->db->get();
//print_r($this->db->last_query());
//die();
return $result->result();
}
//This is get the capital po list for edit
function getCapitalPurchaseOrderDetails($PONO = '')
{
$subQuery ='SELECT distinct LineItem.LineItemNo,Req.ReqNo,Mat.MaterialCode,Mat.MaterialName,LineItem.ServiceMaterialDescription,LineItem.ServiceFrequency,
Mat.UOM,Quantity,ReceivedQuantity,Rate,Req.Status,
ROUND((RMCIncludingCustomersPerKG*Quantity),2)as Taxamount,LandingCharge,HighSeasSalesCharge,CustomDuty,ExciseDuty,ExciseDutyEdCess,CustomEdCess,POMast.ExchangeRate,POMast.ExchangeRateCalculatedon,POMast.TotalOrderValue as BasicValue,POMast.CapitalRange,AfterLandingCharge,AfterHighSeasSalesCharge,AfterCustomDuty,AfterExciseDuty,AfterExciseDutyEdCess,AddlExciseDuty,AfterAddlExciseDuty,Grossdutypayable,AvailableModvat,Grossexpensesduetocustomduty,purchaseratePerKG,CustomDutyExpensesPerKG,RMCIncludingCustomersPerKG,QuantityKG,BasicPriceInMTon,ProductPrice,CustomSHCess,AfterCustomSHCess,AfterExciseDutySHCess,ExciseDutySHCess,AfterCustomEdCess,ROUND((POMast.ExchangeRate*BasicPriceInMTon*Quantity),2) as BasicINRValue,Tax.TotalValue as ImportTotalValue,POMast.CurrencyType,
Req.CostCenterCode,Dept.DepartmentName FROM T_PurchaseOrder_LineItem LineItem
join T_PurchaseOrder_Master POMast on POMast.PONO = LineItem.PONO
join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
join T_Import_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo
join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo
join T_Employee_Details emp on Req.Requestedby = emp.EmpID
join T_DepartmentDetails Dept on emp.Departmentcode = Dept.DEPCode where LineItem.PONO =?';
//print_r($subQuery);
$query = $this->db->query($subQuery,array($PONO));
return $query->result();
}
// This Method to get the Capital PO Details for pdf
function GetCapitalPurchaseOrderDetailsForPDF($PONO = '')
{
$subQuery ='SELECT distinct LineItem.LineItemNo,ReqNo,Mat.MaterialCode,Mat.MaterialName,
Mat.UOM,Mat.HSNCODE,Quantity,Rate,ROUND((Quantity *Rate),2 ) as BasicValue ,
LineItem.CostCenterCode , POMaster.*,sup.SupplierName,sup.Address,Payment.PaymentID,Payment.PaymentTerms
FROM T_PurchaseOrder_LineItem LineItem
join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
join T_PurchaseOrder_Master POMaster on POMaster.PONO = LineItem.PONO
join T_SupplierDetailsN sup on sup.SupplierID = POMaster.SupplierID
join T_PaymentTerms Payment on Payment.PaymentID = POMaster.PaymentTerms
where LineItem.PONO =?';
$query = $this->db->query($subQuery,array($PONO));
return $query->result();
}
// get requested by details
function GetRequesedByDetails($PONO){
$this->db->select('mast.CreatedBy,re.FirstName,Dept.DEPCode,Dept.DepartmentName');
$this->db->from('T_PurchaseOrder_Master mast');
$this->db->join('tbl_users tbl','mast.CreatedBy=tbl.userid');
$this->db->join('T_Employee_Details re','re.EmpID=tbl.EmpID');
$this->db->join('T_DepartmentDetails Dept', 're.Departmentcode = Dept.DEPCode');
$this->db->where('mast.PONO',$PONO);
$result=$this->db->get();
return $result->result();
}
// get domestic capital po list
function getDomesticCapitalPurchaseOrderDetails($PONO = '')
{
$subQuery ='SELECT distinct LineItem.LineItemNo,Req.ReqNo,Mat.MaterialCode,Mat.MaterialName,LineItem.ServiceMaterialDescription,LineItem.ServiceFrequency,
Mat.UOM,Quantity,ReceivedQuantity,Rate,Req.Status,ROUND((ServiceTax.After_CGST + ServiceTax.After_SGST + ServiceTax.After_IGST + ServiceTax.otherallowance),2) as ServiceTaxamount
,ServiceTax.TotalValue,ServiceTax.CGST,ServiceTax.After_CGST,ServiceTax.SGST,ServiceTax.After_SGST,ServiceTax.IGST,ServiceTax.After_IGST,ServiceTax.otherallowance,
POMast.ExchangeRate,POMast.ExchangeRateCalculatedon,POMast.TotalOrderValue as BasicValue,POMast.CapitalRange,ROUND((POMast.TotalOrderValue),2) as BasicINRValue,POMast.CurrencyType,
Req.CostCenterCode,Dept.DepartmentName FROM T_PurchaseOrder_LineItem LineItem
join T_PurchaseOrder_Master POMast on POMast.PONO = LineItem.PONO
join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
join T_Service_Tax ServiceTax on ServiceTax.LineItemNo = LineItem.LineItemNo
join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo
join T_Employee_Details emp on Req.Requestedby = emp.EmpID
join T_DepartmentDetails Dept on emp.Departmentcode = Dept.DEPCode where LineItem.PONO =?';
//print_r($subQuery);
$query = $this->db->query($subQuery,array($PONO));
return $query->result();
}
//get pdf po requistion details
function GetPdfRequistionDetails($PONO){
$this->db->select('LineItem.ReqNo');
$this->db->from('T_PurchaseOrder_LineItem LineItem');
$this->db->where('LineItem.PONO',$PONO);
$result=$this->db->get();
$ReqNo='';
foreach ($result->result() as $res){
if($ReqNo==$res->ReqNo){
}
else{
$ReqNo = $res->ReqNo;
$this->db->select('ReqMast.ReqNo,ReqMast.CostCenterCode,ReqMast.ReqDate,ReqMast.Schedule_Type,ReqMast.NumberOfService,ReqMast.Service_Period,re.FirstName,Dept.DEPCode,Dept.DepartmentName');
$this->db->from('T_Requestion_Master ReqMast');
$this->db->join('T_Employee_Details re','re.EmpID=ReqMast.Requestedby');
$this->db->join('T_DepartmentDetails Dept', 're.Departmentcode = Dept.DEPCode');
$this->db->where('ReqMast.ReqNo',$ReqNo);
$Reqresult=$this->db->get();
$Details['RequistionNo']= $Reqresult->result()[0]->ReqNo;
$Detaisl['ReqDate']=$Reqresult->result()[0]->ReqDate;
$Details['RequestedName']= $Reqresult->result()[0]->FirstName;
$Details['RequestedDept']= $Reqresult->result()[0]->DepartmentName;
$Details['CostCenterCode']= $Reqresult->result()[0]->CostCenterCode;
$date = new DateTime($Reqresult->result()[0]->ReqDate,new DateTimeZone('Asia/Kolkata'));
$retDate = $date->format('d-m-Y');
$Details['ReqDate']= $retDate;
$ScheduleType = $Reqresult->result()[0]->Schedule_Type;
if($ScheduleType!='Recurring'){
$Details['Frequency']= $Reqresult->result()[0]->Schedule_Type;
}
else{
$Details['Frequency']= $Reqresult->result()[0]->Service_Period.' - '.$Reqresult->result()[0]->NumberOfService;
}
$ResultArray[]=$Details;
}
}
$RequistionDetails = $ResultArray;
return $RequistionDetails;
}
function GetLineItemReceivedQty($ParentPO,$MaterialCode)
{
$this->db->select('ReceivedQuantity');
$this->db->from('T_PurchaseOrder_LineItem');
$this->db->where('PONO',$ParentPO);
$this->db->where('MaterialCode',$MaterialCode);
$result=$this->db->get();
return $result->result_array();
}
//get paymentTerms details
function getPaymentTermsDetails($Payment_ID='')
{
$getpaymentQuery='select distinct PaymentID,PaymentTerms,Details from T_PaymentTerms';
$paymentQuery=$this->db->query($getpaymentQuery);
return $paymentQuery->result();
}
/**
* This function is used to get status in status table
*/
function getStatus($StatusType = '')
{
$this->db->select('StatusCode,StatusName ');
$this->db->from('T_Status');
$this->db->where('StatusType', $StatusType);
$query = $this->db->get();
return $query->result();
}
function edit_mrir($MrirNo)
{
$this->db->distinct();
$this->db->select('TMM.MRIRNO,TMM.PONO,TMM.IGRNO,TMM.Createdon,TMD.ActualQuantityReceived,IGRM.DeliveryChellanOrInvoiceNo,IGRM.DeliveryChellanDate,IGRM.VehicleNo,IGRM.CourierNo,IGRM.CreatedDate,IGRD.QuantityAsPerInvoice,SUPP.SupplierName,SUPP.Address,POMR.PODate,POMR.DeliveryDate,POMR.ServiceDescription,TMD.MaterialCode,MM.MaterialName,MM.UOM,POLT.Quantity,POLT.ReceivedQuantity,ED.FirstName as PORasiedbyName,ED1.FirstName as MRIRRasiedbyName, ED2.FirstName as IGRRasiedbyName,TMM.MRIRStatus,TMM.Createdon as MRIRCreatedon,POLT.CostCenterCode,CostCenterName,QuantityAccepted,QuantityRejected,TMD.Remarks');
$this->db->from ('T_MRIR_Master TMM');
$this->db->join ('T_MRIR_Details TMD','TMM.MRIRNO = TMD.MRIRNO','left');//to get IGRNO,PONO,MRIRNO,mrirdate,
$this->db->join ('T_IGR_Master IGRM', 'IGRM.IGRNO = TMM.IGRNO','left');//to get actualquantity,deliverydate,Invoicedate,vechileno,courierno,igrdate,
$this->db->join ('T_PurchaseOrder_Master POMR ','IGRM.PONO = POMR.PONO','left');//to get podate,deliverydate,servicedescription
$this->db->join ('T_PurchaseOrder_LineItem POLT','IGRM.PONO=POLT.PONO','left');//to get receivedquantity,quantity
$this->db->join ('T_IGR_Details IGRD','IGRD.IGRNO = IGRM.IGRNO','left');//to get invoicequantity
$this->db->join ('T_MaterialMaster MM','IGRD.MaterialCode = MM.MaterialCode','left');
$this->db->join ('T_SupplierDetailsN SUPP','POMR.SupplierID = SUPP.SupplierID','left');//to get suppliername,supplieraddress
$this->db->join ('tbl_users user','user.userid = POMR.CreatedBy','left');//to get poraisedby
$this->db->join ('T_Employee_Details ED','ED.EmpID = user.EmpID','left');
$this->db->join ('tbl_users user1','user1.userid=TMM.CreatedBy','left');//to get mrirraisedby
$this->db->join ('T_Employee_Details ED1','ED1.EmpID = user1.EmpID','left');
$this->db->join ('tbl_users user2','user2.userid=IGRM.CreatedBy','left');//to get igrraisedby
$this->db->join ('T_Employee_Details ED2','ED2.EmpID = user2.EmpID','left');
$this->db->join('T_CostCenter_Master TCOST','POLT.CostCenterCode=TCOST.CostCenterCode');
$this->db->where('TMM.MRIRNO',$MrirNo);
$this->db->group_by('TMM.MRIRNO,TMD.MaterialCode');
$query = $this->db->get();
$result = $query->result();
//print_r( $this->db->last_query());
return $result;
}
function getadvancePONO($Status='')
{
$this->db->select ('Mast.PONO,POType,Mast.CreatedDate,Mast.ReleasedOn,Mast.TotalOrderValue,Mast.SupplierID,DeliveryDate,DeliverySchedule,DeliveryOption,Mast.PaymentTerms as Paycode,Payterm.PaymentTerms,LineItem.ReqNo,Requestedby,Departmentcode,DepartmentName,LineItem.CostCenterCode,SupDet.SupplierName,Import_DispatchDetails,CurrencyType,AdvancePercentage,AdvanceAmount,POAdv.Remarks');
$this->db->from('T_PurchaseOrder_Master Mast');
$this->db->join('T_PurchaseOrder_LineItem LineItem','Mast.PONO=LineItem.PONO');
$this->db->join('T_Requestion_Master ReqMa','LineItem.ReqNo=ReqMa.ReqNo');
$this->db->join('T_Employee_Details EmpDet','ReqMa.Requestedby=EmpDet.EmpID');
$this->db->join('T_DepartmentDetails DepDet','EmpDet.Departmentcode=DepDet.DEPCode');
$this->db->join('T_SupplierDetailsN SupDet','Mast.SupplierID=SupDet.SupplierID');
$this->db->join('T_PurchaseOrder_AdvanceRequest POAdv','Mast.PONO=POAdv.PONO','left');
$this->db->join('T_PaymentTerms Payterm','Mast.PaymentTerms=Payterm.PaymentID');
$this->db->where('Mast.Status',$Status);
$query = $this->db->get();
//print_r($this->db->last_query());
return $query->result();
}
//get available budget for capital
function GetAvailableCapitalBudgetAmount($CostCode,$Year,$BudgetType)
{
$subQuery ='select BudgetAmount, (select ifnull(sum(IF(POMaster.ExchangeRate>0,Quantity*Rate*POMaster.ExchangeRate,Quantity*Rate)),0) as Totalvalue from
T_PurchaseOrder_LineItem Item join T_Requestion_Master mast
on mast.ReqNo = Item.ReqNo join T_PurchaseOrder_Master POMaster on POMaster.PONO=Item.PONO where Item.CostCenterCode=? and mast.ReqType=?)as Totalvalue
from T_CostCenter_Budget Bud where Bud.CostCenterCode=? and
BudgetYear = ? and BudgetType =?';
$query = $this->db->query($subQuery,array($CostCode,$BudgetType,$CostCode,$Year,$BudgetType));
return $query->result_array();
}
}