siddharth_application/application/models/purchaseorder_model.php

2545 lines
90 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->where('PO.POType',SERVICE);
$this->db->where('PO.status',PO_RELEASED);
$this->db->where('Req.RequestedDept',$this->session->userdata('DEPCode'));
$query = $this->db->get();
// print_r( $this->db->last_query());
return $query->result();
}
/*------------jun15------------------*/
function getfies($pono)
{
$this->db->select('*');
$this->db->from('T_PurchaseOrder_BillUpload bill');
$this->db->where('PONO',$pono);
$query = $this->db->get();
return $query->result();
}
/*-----------jun15-------------------*/
function updateMatStock($itemNo,
$MaterialstockHistoryupdate){
//echo'hi';
$this->db->where('Ref_No',$itemNo);
$this->db->update('T_Material_stock_history', $MaterialstockHistoryupdate);
$r = $this->db->affected_rows();
return $r;
}
function updateReqDetails($Reqnumber,$MaterialCode,$ReqDetail){
//echo'hi';
$this->db->where('ReqNo',$Reqnumber);
$this->db->where('MaterialCode',$MaterialCode);
// $this->db->where('Quantity',$Quantity);
$this->db->update('T_Requestion_Details',$ReqDetail);
$r = $this->db->affected_rows();
return $r;
}
function IGRDetailsupdate($PONO)
{
//echo 'hi';
$subQuery ='select IGRM.PONO,IGRD.IGRItemNo,IGRD.IGRNO from
T_IGR_Master IGRM
join T_IGR_Details IGRD on IGRD.IGRNO = IGRM.IGRNO
Where IGRM.PONO = ? ';
$query = $this->db->query($subQuery,array($PONO));
return $query->result_array();
}
function updateIGR($IGRItemNo,$IGRDs) //,$MaterialCode,
{
//print_r(array($IGRDs,$IGRItemNo));
$this->db->where('IGRItemNo',$IGRItemNo); //,'IGRNO',$IGRNO,'MaterialCode',$MaterialCode);
//$this->db->where('IGRNO',$IGRNO);
// $this->db->where('MaterialCode',$MaterialCode);
$this->db->update('T_IGR_Details',$IGRDs);
$r = $this->db->affected_rows();
// $this->db->last_query();
return $r;
}
/*------------------------------*/
/////////////////// start this function used to pono reset financeyear configuration
function ponoreset($ponoreset)
{
//print_r($ponoreset); die;
$this->db->insert('T_PONO_Reset_Table',$ponoreset);
$r = $this->db->affected_rows();
return $r;
}
function updateponoreset($ponoreset,$sno,$potype,$posubtype)
{
$this->db->where('reset_pono_id',$sno,'POType',$potype,'POSubtype',$posubtype);
$this->db->update('T_PONO_Reset_Table',$ponoreset);
$r = $this->db->affected_rows();
return $r;
}
function ponoresetfinyear()
{
$this->db->select('*');
$this->db->from('T_PONO_Reset_Table');
$query =$this->db->get();
return $query->result();
}
///////////////////end this function used to pono reset financeyear configuration
function fileupload($myfile)
{
//print_r($myfile);die;
$this->db->insert('T_PurchaseOrder_BillUpload',$myfile);
$myfile=$this->db->affected_rows();
return $myfile;
}
/*--------------------------------------------------*/
/* this function used parendpo igr values get inward report display */
function updateigrmaster($igrno,$NewPOno)
{
// $this->db->insert('T_IGR_Master',$IGRaddvalues);
// $myfile=$this->db->affected_rows();
// return $myfile;
$this->db->where('IGRNO',$igrno);
$this->db->update('T_IGR_Master',$NewPOno);
$insert_id = $this->db->affected_rows();
return $insert_id;
}
function updateigrfile($igrno,$NewPOno)
{
$this->db->where('IGRNO',$igrno);
$this->db->update('T_Inwardgateregister_fileupload',$NewPOno);
$insert_id = $this->db->affected_rows();
return $insert_id;
}
function selectigrmaster($PONO)
{
$this->db->select('*');
$this->db->from('T_IGR_Master');
$this->db->where('PONO',$PONO);
$query = $this->db->get();
return $query->result();
}
function getpolineqty($NewPO)
{
$this->db->select('sum(Quantity)as Qty,sum(ReceivedQuantity)as rec');
$this->db->from('T_PurchaseOrder_LineItem');
$this->db->where('PONO',$NewPO);
$query = $this->db->get();
return $query->result();
}
function POLineItemsupdatestatus($NewPO,$Newstatus)
{
$this->db->where('PONO',$NewPO);
$this->db->update('T_PurchaseOrder_LineItem',$Newstatus);
$update = $this->db->affected_rows();
return $update;
}
function pomasterupdatestatus($NewPO,$Newstatus)
{
$this->db->where('PONO',$NewPO);
$this->db->update('T_PurchaseOrder_Master',$Newstatus);
$update = $this->db->affected_rows();
return $update;
}
/*--------------------------------------------------*/
function getfunction($pono)
{
$this->db->distinct();
$this->db->select('bill.PONO,mstr.IGRNO,bill.BillNo,mstr.MaterialRcvdDate,bill.FilePath,mstr.DeliveryChellanOrInvoiceNo,mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.CourierNo,dtl.QuantityAsPerInvoice,pom.POType');
$this->db->from('T_PurchaseOrder_BillUpload bill');
$this->db->join('T_IGR_Master mstr','bill.PONO = mstr.PONO','left');
$this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left');
// $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode');
$this->db->join('T_PurchaseOrder_Master pom','pom.PONO = bill.PONO');
$this->db->where('bill.PONO',$pono);
//$this->db->or_where('pom.status',SPECIAL_PO);
$this->db->group_by('bill.BillNo');
// $this->db->select('mstr.PONO,mstr.IGRNO,mstr.DeliveryChellanOrInvoiceNo,
// mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.MaterialRcvdDate,
// mstr.CourierNo,bill.BillNo,bill.FilePath,pom.Status,pom.POType');
// $this->db->from('T_IGR_Master mstr');
// $this->db->join('T_PurchaseOrder_BillUpload bill','bill.PONO = mstr.PONO','left');
// $this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left');
// // $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode');
// $this->db->join('T_PurchaseOrder_Master pom','pom.PONO = mstr.PONO');
// $this->db->where('mstr.PONO',$pono);
$query = $this->db->get();
return $query->result();
}
function getfunctionr($pono)
{
$this->db->distinct();
// $this->db->select('bill.PONO,mstr.IGRNO,bill.BillNo,mstr.MaterialRcvdDate,bill.FilePath,mstr.DeliveryChellanOrInvoiceNo,mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.CourierNo,dtl.QuantityAsPerInvoice,pom.POType');
// $this->db->from('T_PurchaseOrder_BillUpload bill');
// $this->db->join('T_IGR_Master mstr','bill.PONO = mstr.PONO','left');
// $this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left');
// // $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode');
// $this->db->join('T_PurchaseOrder_Master pom','pom.PONO = bill.PONO');
// $this->db->where('bill.PONO',$pono);
// //$this->db->or_where('pom.status',SPECIAL_PO);
// $this->db->group_by('bill.BillNo');
$this->db->select('mstr.PONO,mstr.IGRNO,mstr.DeliveryChellanOrInvoiceNo,
mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.MaterialRcvdDate,
mstr.CourierNo,pom.Status,pom.POType'); //,bill.BillNo,bill.FilePath,
$this->db->from('T_IGR_Master mstr');
//$this->db->join('T_PurchaseOrder_BillUpload bill','bill.PONO = mstr.PONO','left');
$this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left');
// $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode');
$this->db->join('T_PurchaseOrder_Master pom','pom.PONO = mstr.PONO');
$this->db->where('mstr.PONO',$pono);
$query = $this->db->get();
return $query->result();
}
function getbillfiesr($pono)
{
$this->db->distinct();
// $this->db->select('bill.PONO,mstr.IGRNO,bill.BillNo,mstr.MaterialRcvdDate,bill.FilePath,mstr.DeliveryChellanOrInvoiceNo,mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.CourierNo,dtl.QuantityAsPerInvoice,pom.POType');
// $this->db->from('T_PurchaseOrder_BillUpload bill');
// $this->db->join('T_IGR_Master mstr','bill.PONO = mstr.PONO','left');
// $this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left');
// // $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode');
// $this->db->join('T_PurchaseOrder_Master pom','pom.PONO = bill.PONO');
// $this->db->where('bill.PONO',$pono);
// //$this->db->or_where('pom.status',SPECIAL_PO);
// $this->db->group_by('bill.BillNo');
$this->db->select('mstr.PONO,mstr.IGRNO,mstr.DeliveryChellanOrInvoiceNo,
mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.MaterialRcvdDate,
mstr.CourierNo,bill.BillNo,bill.FilePath,pom.Status,pom.POType');
$this->db->from('T_IGR_Master mstr');
$this->db->join('T_PurchaseOrder_BillUpload bill','bill.PONO = mstr.PONO','left');
$this->db->join('T_IGR_Details dtl','mstr.IGRNO = dtl.IGRNO','left');
// $this->db->join('T_MaterialMaster mm','mm.MaterialCode = bill.MaterialCode');
$this->db->join('T_PurchaseOrder_Master pom','pom.PONO = mstr.PONO');
$this->db->where('mstr.PONO',$pono);
$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,StatusName,POMast.CapitalRange,POType,
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
left join T_Employee_Details emp on emp.EmpID = mast.Requestedby
join T_DepartmentDetails Dept on Dept.DEPCode = mast.RequestedDept
join T_CostCenter_Master Cost on Cost.CostCenterCode=LineItem.CostCenterCode
where POMast.POType=? and ServiceWorkStatus=? order by POMast.UpdatedOn desc';
$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,POMast.UpdatedOn');
$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);
}
$this->db->order_by('POMast.UpdatedOn','desc');
$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');
$this->db->where('IsActive', 1);
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();
}
function getqtycheck($PONO)
{
$this->db->select('IsQualityChkReqired');
$this->db->from('T_PurchaseOrder_Master');
$this->db->where('PONO',$PONO);
$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();
}
//Import PO Available Budget Amount
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=? and Mast.status not in (?) )as Totalvalue from T_CostCenter_Budget Bud where Bud.CostCenterCode=? and BudgetYear=? and BudgetType=?';
$query = $this->db->query($subQuery,array($BudgetType,$CostCode,PO_AMENDED,$CostCode,$Year,$BudgetType));
//print_r($this->db->last_query());
return $query->result_array();
}
//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-tax.Afterdiscountval)),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 left join T_Service_Tax tax on tax.LineItemNo=Item.LineItemNo where Item.CostCenterCode=? and POMaster.POType=? and POMaster.status not in (?))as Totalvalue
from T_CostCenter_Budget Bud where Bud.CostCenterCode=? and
BudgetYear = ? and BudgetType =?';
$query = $this->db->query($subQuery,array($CostCode,$BudgetType,PO_AMENDED,$CostCode,$Year,$BudgetType));
return $query->result_array();
}
function GetAvailableBudgetAmount($CostCode,$Year,$BudgetType)
{
$subQuery ='select distinct Bud.CostCenterCode,BudgetAmount, case WHEN BudgetType = ? then (select
round(ifnull(sum((Quantity*Rate)-ifnull(tax.AfterDiscount,0)),0),2) as
Totalvalue from T_PurchaseOrder_LineItem Item join T_Requestion_Master mast
on mast.ReqNo = Item.ReqNo join T_PurchaseOrder_Master POM on POM.PONO = Item.PONO left join T_Revenue_Tax tax on
tax.LineItemNo = Item.LineItemNo
where Item.CostCenterCode=? and POM.POType=? and POM.status not in (?)) else (select
round(ifnull(sum(Quantity*Rate*ifnull(case when mast.NumberOfService=?
then 1 else mast.NumberOfService end ,1)),0),2) as
Totalvalue from T_PurchaseOrder_LineItem Item join T_Requestion_Master mast
on mast.ReqNo = Item.ReqNo join T_PurchaseOrder_Master POM on POM.PONO = Item.PONO left join T_Requestion_Master ReqMas on ReqMas.ReqNo= Item.ReqNo
where Item.CostCenterCode=? and POM.POType=? and POM.status not in (?) ) end as Totalvalue
from T_CostCenter_Budget Bud join T_CostCenter_Departments dept on dept.CostCenterCode = Bud.CostCenterCode
where Bud.CostCenterCode=? and
BudgetYear = ? and BudgetType =?';
$query = $this->db->query($subQuery,array(REVENUE,$CostCode,$BudgetType,PO_AMENDED,'0.00',$CostCode,$BudgetType,PO_AMENDED,$CostCode,$Year,$BudgetType));
//print_r($this->db->last_query());
return $query->result_array();
}
//to get POTYpe from ReqNo
function GetPOType($ReqNo)
{
$this->db->select('POType');
$this->db->from('T_PurchaseOrder_Master mast');
$this->db->join('T_PurchaseOrder_LineItem Line', 'mast.PONO=Line.PONO');
$this->db->where('Line.ReqNo', $ReqNo);
$query = $this->db->get();
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='')
{
$ReqDeatis = $this->GetRequistionMasterUsingReqNo($ReqNoList);
foreach ($ReqDeatis as $SID):
$ReqBy = $SID->Requestedby ;
endforeach;
if($ReqBy=='' || $ReqBy==null){
$this->db->distinct();
$this->db->select('ReqNo,ReqType,Status,Requestedby,mast.CreatedDate,mast.Schedule_Type,mast.NumberOfService,mast.Service_Period,
Dept.DEPCode,Dept.DepartmentName,mast.ReqDate,mast.CostCenterCode,mast.Status');
$this->db->from('T_Requestion_Master mast');
$this->db->join('T_DepartmentDetails Dept', 'mast.RequestedDept = Dept.DEPCode');
$this->db->where_in('mast.ReqNo', $ReqNoList);
}
else if($ReqBy!='') {
$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', 'mast.RequestedDept = Dept.DEPCode');
$this->db->where_in('mast.ReqNo', $ReqNoList);
}
$query = $this->db->get();
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()
{
$subQuery = "select CompanyName,replace(Address,'<br>','') as Address,GSTNO,PAN,ContactNumber,EmailAddress,AlternateContactNumber,companyWebsite,StateCode
from T_Company_Details ";
$query = $this->db->query($subQuery);
//print_r($this->db->last_query());
return $query->result();
// 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 getCompanyInformationforPDF()
{
$subQuery = "select CompanyName,Address,GSTNO,PAN,ContactNumber,EmailAddress,AlternateContactNumber,companyWebsite,StateCode
from T_Company_Details ";
$query = $this->db->query($subQuery);
//print_r($this->db->last_query());
return $query->result();
// 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,$POType,$POSubtype)
{
$this->db->trans_start();
$this->db->insert('T_PurchaseOrder_Master', $POMaster);
//$this->db->update('T_PONO_Reset_Table')
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
// print_r($this->db->last_query());
if($insert_id>0)
{
$subQuery = 'select PONO from T_PurchaseOrder_Master where POType=? and POSubType=? and isnull(ParentPO) order by CreatedDate desc limit 1 ';
$query = $this->db->query($subQuery,array($POType,$POSubtype));
//print_r($query->result());die();
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 PONO from T_PurchaseOrder_Master where CreatedBy=? and ParentPO=? order by CreatedDate desc limit 1';
$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';
$subQuery = 'SELECT * FROM T_PurchaseOrder_LineItem where PONO = "'.$POLineItem['PONO'].'" ORDER BY LineItemNo DESC';
$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);
$this->db->trans_complete();
$insert_id = $this->db->insert_id();
$aff_row = $this->db->affected_rows();
// print_r( $this->db->last_query()); die();
// echo "aff_row".$aff_row." $insert_id".$insert_id;
return $aff_row > 0 ? $this->db->insert_id() : 0;
}
/**
* 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);
$this->db->trans_complete();
$insert_id = $this->db->affected_rows();
return $insert_id>0 ? $this->db->insert_id() : 0;
}
/**
* 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);
$this->db->trans_complete();
$insert_id = $this->db->affected_rows();
return $insert_id>0 ? $this->db->insert_id() : 0;
}
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;
}
function PONOExists($PONO)
{
$this->db->select('PONO');
$this->db->from('T_PurchaseOrder_AdvanceRequest');
$this->db->where('PONO ',$PONO);
$query = $this->db->get();
if ($query->num_rows > 0) {
return $query->result_array();
}
}
function updateadvanceRequest($advance,$PONO)
{
$this->db->where('PONO', $PONO);
$this->db->update('T_PurchaseOrder_AdvanceRequest',$advance);
$insert_id = $this->db->affected_rows();
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.*,POMast.TotalOrderValue,POMast.BudgetType,IGR.IGRNO');
$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_IGR_Master IGR','POMast.PONO = IGR.PONO','left');
$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,LineItem.Per,Mat.MaterialCode,Mat.MaterialName,Mat.UOM,LineItem.Quantity,ReceivedQuantity,Rate,LineItem.Status,(LineItem.Quantity *Rate) as BasicValue ,(After_CGST + After_SGST + After_IGST) as Taxamount,Dept.DepartmentName
,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,ReqDet.MaterialDescription
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
join T_Requestion_Details ReqDet on ReqDet.ReqNo = LineItem.ReqNo and LineItem.MaterialCode = ReqDet.MaterialCode
left join T_Employee_Details emp on Req.Requestedby = emp.EmpID
join T_DepartmentDetails Dept on Req.RequestedDept = Dept.DEPCode
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 GetServicePurchaseOrderDetailsforPdf($PONO = '')
{
$subQuery ='SELECT distinct LineItem.LineItemNo,LineItem.ReqNo,LineItem.Per,LineItem.ServiceMaterialDescription,Mat.MaterialCode,Mat.MaterialName,POMaster.ParentPO,
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.SupplierID,sup.Address,sup.ContactNumber,sup.EmailAddress,sup.PAN,sup.GSTNO,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_PaymentTerms Payment on Payment.PaymentID = POMaster.PaymentTerms
join T_Requestion_Master ReqMat on ReqMat.ReqNo = LineItem.ReqNo
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 GetRevenuePurchaseOrderDetails($PONO = '')
{
$subQuery ='SELECT distinct LineItem.LineItemNo,Req.ReqNo,Mat.MaterialCode,Mat.MaterialName,Mat.UOM,Quantity,Per,ServiceMaterialDescription,ReceivedQuantity,Rate,Req.Status,(Quantity *Rate) as BasicValue , (( AfterSGST + AfterCGST +
AfterIGST )) as Taxamount ,TotalValue,Tax.*,Req.CostCenterCode,Dept.DepartmentName
FROM T_PurchaseOrder_LineItem LineItem
join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
left join T_Revenue_Tax Tax on Tax.LineItemNo = LineItem.LineItemNo
join T_Requestion_Master Req on Req.ReqNo = LineItem.ReqNo
left join T_Employee_Details emp on Req.Requestedby = emp.EmpID
join T_DepartmentDetails Dept on Req.RequestedDept = 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,LineItem.Per,ReqNo,Mat.MaterialCode,Mat.MaterialName,POMaster.PaymentOtherDescription,LineItem.ServiceMaterialDescription,
Mat.UOM,Mat.HSNCODE,Quantity,Rate,ROUND((Quantity *Rate),2 ) as BasicValue ,
ROUND(((AfterSGST + AfterCGST +
AfterIGST)) ,2)as Taxamount,AdvanceAmount,
TotalValue,Tax.*,LineItem.CostCenterCode ,POMaster.*,sup.SupplierName,sup.Address,sup.SupplierID,sup.ContactNumber,sup.EmailAddress,sup.PAN,sup.GSTNO,LineItem.AmendedDetails as LineAmend,Payment.PaymentTerms
FROM T_PurchaseOrder_LineItem LineItem
left join T_MaterialMaster Mat on Mat.MaterialCode = LineItem.MaterialCode
left 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
left 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 getRevenueTaxinforforpdf($PONO)
{
$subQuery ='SELECT group_concat(pl.MaterialCode ORDER BY pl.MaterialCode ASC) as Itemcode,rt.CGST,rt.SGST,rt.IGST,rt.FreightValue,rt.AfterFreightValue,rt.PackagingValue,rt.AfterPackagingValue,rt.DiscountValue,rt.AfterDiscount FROM T_Revenue_Tax rt
join T_PurchaseOrder_LineItem pl on pl.LineItemNo=rt.LineItemNo
join T_PurchaseOrder_Master pm on pm.PONO=pl.PONO
where pm.POType=? and pm.PONO=?
group by rt.CGST,rt.SGST,rt.IGST,rt.FreightValue,rt.PackagingValue,rt.AfterDiscount,rt.AfterFreightValue,rt.AfterPackagingValue ORDER BY rt.LineItemNo ASC';
$query = $this->db->query($subQuery,array("REVENUE",$PONO));
return $query->result();
}
// This Method to get the Revenue PO Child Details for Edit the Item
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,LineItem.Per,LineItem.ServiceMaterialDescription,
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,ROUND((Quantity *Rate),2 ) as BasicValue,HSNCODE,sup.EmailAddress,sup.SupplierID,sup.PAN,sup.ContactNumber,sup.GSTNO
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(Quantity-ReceivedQuantity)as PendingQty,Per,
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),2)as TotalOrderValue,ROUND((POMast.ExchangeRate*BasicPriceInMTon),2) as BasicINRValue,TotalValue,CurrencyType,ReceivedQuantity,Tax.*,LineItem.ServiceMaterialDescription,
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
left join T_Employee_Details emp on Req.Requestedby = emp.EmpID
left join T_MRIR_Master Mast on POMast.PONO=Mast.PONO
left join T_MRIR_Details Det on Det.MaterialCode=LineItem.MaterialCode and Mast.MRIRNO=Det.MRIRNO
join T_DepartmentDetails Dept on Req.RequestedDept = Dept.DEPCode where LineItem.PONO =?';
//print_r($subQuery);
$query = $this->db->query($subQuery,array($PONO));
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($type)
{
$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 RType,mast.Remarks,DepartmentName,mast.ApprovedBy,(select EmpID from tbl_users where userId=mast.ApprovedBy )as EID,rmast.ReqType,mast.Status,mast.CapitalRange,
(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','left');
$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');
if($type=='APPROVAL'){
$this->db->or_where('mast.Status',PO_CREATED);
$this->db->or_where('mast.Status',PO_APPROVER_ONHOLD);
$this->db->or_where('mast.Status',PO_AWAITING_RELEASE);
$this->db->or_where('mast.Status',PO_RELEASED);
$this->db->or_where('mast.Status',REQITEM_Emergency_PO_CREATED);
$this->db->order_by('mast.Status');
}
else if($type=='RELEASE'){
$this->db->or_where('mast.Status',PO_AWAITING_RELEASE);
$this->db->or_where('mast.Status',PO_RELEASER_ONHOLD);
$this->db->or_where('mast.Status',PO_RELEASED);
$this->db->order_by('mast.Status');
}
$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,LineItem.Per,LineItem.ServiceMaterialDescription,Req.ReqNo,Mat.MaterialCode,Mat.MaterialName,LineItem.ServiceMaterialDescription,LineItem.ServiceFrequency,
Mat.UOM,Quantity,ReceivedQuantity,Rate,Req.Status,Tax.*,
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,Tax.FreightType,Tax.NoOfTrip,Tax.FreightValue,Tax.AfterFreightValue,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
left join T_Employee_Details emp on Req.Requestedby = emp.EmpID
join T_DepartmentDetails Dept on Req.RequestedDept = 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,LineItem.Per,LineItem.AmendedDetails as lineamd,ReqNo,Mat.MaterialCode,Mat.MaterialName,LineItem.ServiceMaterialDescription,
Mat.UOM,Mat.HSNCODE,Quantity,Rate,ROUND((Quantity *Rate),2 ) as BasicValue ,
LineItem.CostCenterCode , POMaster.*,sup.SupplierName,sup.SupplierID,sup.Address,sup.ContactNumber,sup.EmailAddress,sup.PAN,sup.GSTNO,Payment.PaymentID,Payment.PaymentTerms,AdvanceAmount,HSNCODE
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
left join T_PurchaseOrder_AdvanceRequest Adv on POMaster.PONO=Adv.PONO
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,LineItem.Per,LineItem.ServiceMaterialDescription,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),2) as ServiceTaxamount
,ServiceTax.TotalValue,ServiceTax.CGST,ServiceTax.After_CGST,ServiceTax.SGST,ServiceTax.After_SGST,ServiceTax.IGST,ServiceTax.After_IGST,ServiceTax.otherallowance,ServiceTax.discount,ServiceTax.discountval,ServiceTax.Afterdiscountval,
POMast.ExchangeRate,POMast.ExchangeRateCalculatedon,POMast.TotalOrderValue as BasicValue,POMast.CapitalRange,ROUND((POMast.TotalOrderValue),2) as BasicINRValue,POMast.CurrencyType,FreightType as Ftype,NoOfTrip as NoTrip,FreightValue as Fvalue,AfterFreightValue as Afvalue,
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,Dept.DEPCode,Dept.DepartmentName,Dept.shortName');
$this->db->from('T_Requestion_Master ReqMast');
$this->db->join('T_DepartmentDetails Dept', 'ReqMast.RequestedDept = 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['RequestedDept']= $Reqresult->result()[0]->shortName;
$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,Mast.CapitalRange,Mast.PaymentOtherDescription,RequestedDept');
$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','left');
$this->db->join('T_DepartmentDetails DepDet','EmpDet.Departmentcode=DepDet.DEPCode or ReqMa.RequestedDept=DepDet.DEPCode','left');
$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();
}
// update req deatail if work status is completed
function updateReqDetail($PONO,$POStatus,$MaterialCode)
{
$this->db->set('Req.Status',$POStatus);
$this->db->where('Item.PONO',$PONO);
$this->db->where('Req.MaterialCode',$MaterialCode);
$this->db->update('T_PurchaseOrder_LineItem Item JOIN T_Requestion_Details Req ON Item.ReqNo= Req.ReqNo');
return TRUE;
}
function UpdateReceivedQtyforServicePO($PONO,$updateddt,$updatedBy)
{
$this->db->select('LineItemNo,MaterialCode');
$this->db->from('T_PurchaseOrder_LineItem');
$this->db->where('PONO ',$PONO );
$query = $this->db->get();
$result = $query->result();
if(!empty($result))
{
foreach ($result as $res)
{
$LineItemNo =$res->LineItemNo;
$MaterialCode = $res->MaterialCode;
//echo $LineItemNo;
$subQuery = 'update T_PurchaseOrder_LineItem
set ReceivedQuantity=Quantity, status=?,UpdatedOn=?,UpdateBY=? where PONO=? and LineItemNo=?';
$query = $this->db->query($subQuery,array(PO_SERVICE_COMPLETED,$updateddt,$updatedBy,$PONO,$LineItemNo));
$finddot = strpos($PONO,'.');
if($finddot = true)
{
$subQuery = 'update T_PurchaseOrder_LineItem
set ReceivedQuantity=Quantity, status=?,UpdatedOn=?,UpdateBY=? where PONO=substring(?,1,(case when INstr(?,?) > 0 then INstr(?,?)-1 else 0 end)) and MaterialCode=?';
$query = $this->db->query($subQuery,array(PO_SERVICE_COMPLETED,$updateddt,$updatedBy,$PONO,$PONO,'.',$PONO,'.',$MaterialCode));
}
}
}
}
//get service tax listusing po number
function GetServiceTaxDetails($PONO = ''){
$taxQuery ='SELECT group_concat(@count:=@count+1) Itemcode,
st.CGST,st.SGST,st.IGST,st.otherallowance FROM T_Service_Tax st
join T_PurchaseOrder_LineItem pl on pl.LineItemNo=st.LineItemNo
join T_PurchaseOrder_Master pm on pm.PONO=pl.PONO JOIN
(SELECT @count := 0) count
where pm.POType=? and pm.PONO=?
group by st.CGST,st.SGST,st.IGST,st.otherallowance
ORDER BY Itemcode ASC ';
$query = $this->db->query($taxQuery,array("SERVICE",$PONO));
return $query->result();
}
// get capital tax listing by po no
function GetCapitalTaxListDetails($PONO = '',$CapitalRange=''){
if($CapitalRange==1){
$taxQuery ='SELECT group_concat(pl.MaterialCode ORDER BY pl.MaterialCode ASC) as Itemcode,SUM(st.`After_CGST`) AS TotalCGST,SUM(st.`After_SGST`) AS TotalSGST,SUM(st.`After_IGST`) AS TotalIGST,SUM(st.`otherallowance`) AS TotalOtherAllowance,SUM(st.`Afterdiscountval`) AS TotalDiscount,st.discountval,st.Afterdiscountval,st.CGST,st.SGST,st.IGST,st.otherallowance,SUM(st.`AfterFreightValue`) AS TotalFreight,st.FreightValue FROM T_Service_Tax st
join T_PurchaseOrder_LineItem pl on pl.LineItemNo=st.LineItemNo
join T_PurchaseOrder_Master pm on pm.PONO=pl.PONO
where pm.POType=? and pm.PONO=?
group by st.Afterdiscountval,st.CGST,st.SGST,st.IGST,st.otherallowance ORDER BY st.LineItemNo ASC';
$query = $this->db->query($taxQuery,array("CAPITAL",$PONO));
return $query->result();
}
else if($CapitalRange==0){
$taxQuery ='SELECT group_concat(pl.MaterialCode ORDER BY pl.MaterialCode ASC) as Itemcode,
SUM(it.`AfterFreightValue`) AS TotalFreight,it.FreightValue,it.AfterFreightValue,
it.IGST AS TotalIGSTPer,SUM(it.AfterIGST) as AfterIGST1,it.AfterIGST as AIgst FROM T_Import_Tax it
join T_PurchaseOrder_LineItem pl on pl.LineItemNo=it.LineItemNo
join T_PurchaseOrder_Master pm on pm.PONO=pl.PONO
where pm.POType=? and pm.PONO=?
group by it.AfterFreightValue ORDER BY it.LineItemNo ASC';
$query = $this->db->query($taxQuery,array("CAPITAL",$PONO));
return $query->result();
}
}
// get po format for acedamic year based
function GetPoFormat($PONO=''){
$poQuery ='select PONO from T_PurchaseOrder_Master where PONO=?';
$query = $this->db->query($poQuery,array($PONO));
return $query->result();
}
//get Dept Emp Name
function getDepartmentEmpList($DepCode=''){
$this->db->select('EmpID');
$this->db->from('T_Employee_Details');
$this->db->where('Departmentcode', $DepCode);
$this->db->limit('1');
$query = $this->db->get();
return $query->result();
}
//get req master details using reqno
function GetRequistionMasterUsingReqNo($Req){
$this->db->select('Requestedby');
$this->db->from('T_Requestion_Master');
$this->db->where('ReqNo', $Req[0]);
$query = $this->db->get();
return $query->result();
}
function amendpdf($PONO='')
{
$Amend ='select p.PONO,p.ParentPO,p.Status,p.TotalOrderValue,
m.Status as parentpostatus,
m.TotalOrderValue as partenttotalorder
from T_PurchaseOrder_Master as p
join T_PurchaseOrder_Master as m
on m.PONO = p.ParentPO
where p.PONO = ?';
$amendment = $this->db->query($Amend,array($PONO));
return $amendment->result();
}
function GetClients()
{
$this->db->select('client_id,client_name');
$this->db->from('ip_clients');
$query = $this->db->get();
return $query->result_array();
}
function SaveEnquiry($save)
{
$this->db->trans_start();
$this->db->insert('T_Enquiry', $save);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return $insert_id;
}
function UpdateEnquiry($save,$Id)
{
$this->db->where('Id',$Id);
$this->db->update('T_Enquiry',$save);
$insert_id = $this->db->affected_rows();
return $insert_id;
}
function GetEnquiryDetails()
{
$this->db->select('T_Enquiry.*,client_name');
$this->db->from('T_Enquiry');
$this->db->join('ip_clients','ip_clients.client_id=T_Enquiry.client_id');
$this->db->order_by('Id','desc');
$query = $this->db->get();
return $query->result();
}
function GetEnquiry($Id)
{
$this->db->select('T_Enquiry.*,client_name');
$this->db->from('T_Enquiry');
$this->db->join('ip_clients','ip_clients.client_id=T_Enquiry.client_id');
$this->db->where('Id',$Id);
$this->db->order_by('Id','desc');
$query = $this->db->get();
return $query->result();
}
function GetEnquiryCount($createddt)
{
$this->db->select('count(Id) as Countnumber');
$this->db->from('T_Enquiry');
$this->db->where('Created_Date',$createddt);
$query = $this->db->get();
return $query->result();
}
function SaveActionMaster($master)
{
$this->db->trans_start();
$this->db->insert('T_ActionReport_Master', $master);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
// print_r($this->db->last_query());
if($insert_id>0)
{
$subQuery = 'select max(Id) as Id from T_ActionReport_Master';
$query = $this->db->query($subQuery,array());
return $query->result_array();
}
}
function SaveActionDisposition($actionsave)
{
$this->db->trans_start();
$this->db->insert('T_Action_Disposition',$actionsave);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return $insert_id;
}
function UpdateActionDisposition($actionsave,$LineDisposition)
{
//echo $LineDisposition;
$this->db->where('DispositionId', $LineDisposition);
$this->db->update('T_Action_Disposition', $actionsave);
return TRUE;
}
function UpdateRootCause($rootsave,$Lineroot)
{
$this->db->where('RootId', $Lineroot);
$this->db->update('T_RootCause', $rootsave);
return TRUE;
}
function Updatecounteraction($savecounter,$LineCounter)
{
$this->db->where('CounterId', $LineCounter);
$this->db->update('T_Action_Counter_Measure', $savecounter);
return TRUE;
}
function UpdateActionMaster($master,$Id)
{
$this->db->where('Id', $Id);
$this->db->update('T_ActionReport_Master', $master);
$insert_id = $this->db->affected_rows();
//return TRUE;
if($insert_id>0)
{
$subQuery = 'select max(Id) as Id from T_ActionReport_Master';
$query = $this->db->query($subQuery,array());
return $query->result_array();
}
}
function SaveRootCause($rootsave)
{
$this->db->trans_start();
$this->db->insert('T_RootCause',$rootsave);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return $insert_id;
}
function Savecounteraction($savecounter)
{
$this->db->trans_start();
$this->db->insert('T_Action_Counter_Measure',$savecounter);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return $insert_id;
}
function GetNcrlist()
{
$this->db->select('*');
$this->db->from('T_ComplaintRegister');
$this->db->join('ip_clients','ip_clients.client_id=T_ComplaintRegister.client_id');
$this->db->order_by('CId','desc');
$query = $this->db->get();
return $query->result();
}
function GetncrmasterDetails($Id)
{
$this->db->select('*');
$this->db->from('T_ActionReport_Master');
$this->db->where('Id',$Id);
$query = $this->db->get();
return $query->result();
}
function GetDispositionDetails($Id)
{
$this->db->select('*');
$this->db->from('T_Action_Disposition');
$this->db->where('Id',$Id);
$query = $this->db->get();
return $query->result();
}
function GetRootcauseDetails($Id)
{
$this->db->select('*');
$this->db->from('T_RootCause');
$this->db->where('Id',$Id);
$query = $this->db->get();
return $query->result();
}
function GetCouteractionDetails($Id)
{
$this->db->select('*');
$this->db->from('T_Action_Counter_Measure');
$this->db->where('Id',$Id);
$query = $this->db->get();
return $query->result();
}
function Savecomplaint($save_complaint)
{
$this->db->trans_start();
$this->db->insert('T_ComplaintRegister',$save_complaint);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return $insert_id;
}
function Get_SavedComplaint($CId)
{
$this->db->select('*');
$this->db->from('T_ComplaintRegister');
$this->db->join('ip_clients','ip_clients.client_id=T_ComplaintRegister.client_id');
$this->db->where('CId',$CId);
$this->db->order_by('CId','desc');
$query = $this->db->get();
//print_r($this->db->last_query());
return $query->result();
}
function Updatecomplaint($save_complaint,$CId)
{
$this->db->where('CId', $CId);
$this->db->update('T_ComplaintRegister', $save_complaint);
return TRUE;
}
function updatecomplaintId($up,$CId)
{
$this->db->where('CId', $CId);
$this->db->update('T_ComplaintRegister',$up);
return TRUE;
}
function GetActionid($LineDisposition)
{
$this->db->select('*');
$this->db->from('T_Action_Disposition');
$this->db->where('DispositionId',$LineDisposition);
$query = $this->db->get();
//print_r($this->db->last_query());
return $query->result();
}
function GetlastDispositionId()
{
$subQuery = 'select max(DispositionId) from T_Action_Disposition';
$query = $this->db->query($subQuery,array());
return $query->result_array();
}
function Getrootid($Lineroot)
{
$this->db->select('*');
$this->db->from('T_RootCause');
$this->db->where('RootId',$Lineroot);
$query = $this->db->get();
//print_r($this->db->last_query());
return $query->result();
}
function Getcounterid($LineCounter)
{
$this->db->select('*');
$this->db->from('T_Action_Counter_Measure');
$this->db->where('CounterId',$LineCounter);
$query = $this->db->get();
//print_r($this->db->last_query());
return $query->result();
}
function DeleteAction($DelId)
{
$this->db->where('DispositionId', $DelId);
$this->db->delete('T_Action_Disposition');
//print_r($this->db->last_query());
return TRUE;
}
function DeleteRoot($DelId)
{
$this->db->where('RootId', $DelId);
$this->db->delete('T_RootCause');
//print_r($this->db->last_query());
return TRUE;
}
function DeleteCounter($DelId)
{
$this->db->where('CounterId', $DelId);
$this->db->delete('T_Action_Counter_Measure');
//print_r($this->db->last_query());
return TRUE;
}
/*------------------------------------------------------------------------------*/
function updatefile($bill,$Picture,$oldfile)
{
// if($oldfile != ''){
// //unlink("uploads/BillFiles/".$oldfile);//this deletes the file on particular folder too
// }
$this->db->set('FilePath', $Picture); //value that used to update column
$this->db->where('BillNo', $bill); //which row want to upgrade
$this->db->update('T_PurchaseOrder_BillUpload');
$afftectedRows = $this->db->affected_rows();
return $afftectedRows;
}
// function newlogpo($logpo)
// {
// $this->db->trans_start();
// $this->db->insert('T_ponewlogs_Details',$logpo);
// $insert_id = $this->db->affected_rows();
// $this->db->trans_complete();
// return $insert_id;
// // $this->db->trans_start();
// // $this->db->insert('T_polog_Details',$logpo);
// // $insert_id = $this->db->affected_rows();
// // $this->db->trans_complete();
// // return $insert_id;
// }
function insertlogpo($logpo){
// $this->db->where('MaterialCode',$MaterialCode,'LineItemNos',$POLineItemNo);
// $this->db->update('T_ponewlogs_Details',$logpo);
$this->db->trans_start();
$this->db->insert('T_polog_Details',$logpo);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return $insert_id;
}
function getlogpodtl($PONO){
// $SQL = "select distinct log.PONO as LPONO,
// case
// WHEN log.Quantity <> pl.Quantity THEN log.Quantity
// else '-'
// ENd as Lqty,
// case
// WHEN log.SupplierID <> pm.SupplierID THEN sup.Suppliername
// else '-'
// ENd as LSuppid,
// case
// WHEN log.Date <> pm.PODate THEN log.Date
// else '-'
// ENd as logDate ,
// case
// WHEN log.Rate <> pl.Rate THEN log.Rate
// else '-'
// ENd as logRate ,
// log.LineItemNos,log.MaterialCode,log.UpdatedOn,log.UpdateBy,emp.FirstName
// from T_ponewlogs_Details log
// join T_PurchaseOrder_LineItem pl on log.LineItemNos = pl.LineItemNo
// join T_PurchaseOrder_Master pm on pm.PONO = log.PONO
// join tbl_users user on user.userId = log.UpdateBy
// left join T_Employee_Details emp on emp.EmpID= user.EmpID
// left join T_SupplierDetailsN sup on sup.SupplierID = log.SupplierID
// where log.PONO ='".$PONO."'";
$SQL = "select log.*,sup.SupplierName,emp.FirstName from
T_polog_Details log
join tbl_users user on user.userId = log.UpdateBy
left join T_Employee_Details emp on emp.EmpID= user.EmpID
left join T_SupplierDetailsN sup on sup.SupplierID = log.oldValue
where PONO ='".$PONO."'";
$logpodtl = $this->db->query($SQL);
return $logpodtl->result();
}
// function EditpoValues($pono)
// {
// $this->db->select('*');
// $this->db->from('T_ponewlogs_Details');
// $this->db->where('PONO',$pono);
// // $this->db->where('MaterialCode',$materialcode);
// $query = $this->db->get();
// return $query->result_array();
// }
function insertfile($filelist)
{
//print_r($myfile);die;
$this->db->insert('T_PurchaseOrder_BillUpload',$filelist);
$myfile=$this->db->affected_rows();
return $myfile;
}
/*------------------------------------------------------------------------------*/
function updateigrM($PONO,$IGRNo,$igrMaster){
//print_r($igrMaster);die;
$this->db->where('PONO',$PONO);
$this->db->where('IGRNO',$IGRNo);
$this->db->update('T_IGR_Master',$igrMaster);
$r = $this->db->affected_rows();
return $r;
}
function getigrno($bill){
$subQuery ='select bill.BillNo,IGR.IGRNO, IGR.PONO FROM T_IGR_Master IGR
join T_PurchaseOrder_BillUpload bill on bill.IGRNO = IGR.IGRNO
where bill.BillNO = ? ';
$query = $this->db->query($subQuery,array($bill));
return $query->result_array();
}
/*** ----------------------------- */
}