2529 lines
86 KiB
PHP
Executable File
2529 lines
86 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class Purchaseorder_model extends Model
|
|
{
|
|
function GetServicePOListforStatusUpdate()
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_master PO')->distinct()
|
|
->select('PO.PONO')
|
|
->join('t_purchaseorder_lineitem Line', 'PO.PONO = Line.PONO')
|
|
->join('t_requestion_master Req', 'Req.ReqNo = Line.ReqNo')
|
|
->where('PO.POType', SERVICE)
|
|
->where('PO.status', PO_RELEASED)
|
|
->where('Req.RequestedDept', $this->session->get('DEPCode'));
|
|
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
/*------------jun15------------------*/
|
|
|
|
|
|
function getfies($pono)
|
|
{
|
|
|
|
$builder = $this->db->table('t_purchaseorder_billupload')
|
|
->select('*')
|
|
->where('PONO', $pono);
|
|
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
/*-----------jun15-------------------*/
|
|
|
|
|
|
function updateMatStock($itemNo, $MaterialstockHistoryupdate)
|
|
{
|
|
//echo'hi';
|
|
$this->db->table('t_material_stock_history')
|
|
->where('Ref_No', $itemNo)
|
|
->update($MaterialstockHistoryupdate);
|
|
|
|
$r = $this->db->affectedRows();
|
|
return $r;
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateReqDetails($Reqnumber, $MaterialCode, $ReqDetail)
|
|
{
|
|
//echo'hi';
|
|
$this->db->table('t_requestion_details')
|
|
->where('ReqNo', $Reqnumber)
|
|
->where('MaterialCode', $MaterialCode)
|
|
// ->where('Quantity',$Quantity);
|
|
|
|
->update($ReqDetail);
|
|
|
|
$r = $this->db->affectedRows();
|
|
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->getResultArray();
|
|
}
|
|
|
|
|
|
function updateIGR($IGRItemNo, $IGRDs) //,$MaterialCode,
|
|
{
|
|
//print_r(array($IGRDs,$IGRItemNo));
|
|
$this->db->table('t_igr_details')
|
|
->where('IGRItemNo', $IGRItemNo) //,'IGRNO',$IGRNO,'MaterialCode',$MaterialCode);
|
|
//->where('IGRNO',$IGRNO);
|
|
// ->where('MaterialCode',$MaterialCode);
|
|
->update($IGRDs);
|
|
|
|
$r = $this->db->affectedRows();
|
|
|
|
|
|
|
|
return $r;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*------------------------------*/
|
|
|
|
|
|
/////////////////// start this function used to pono reset financeyear configuration
|
|
|
|
function ponoreset($ponoreset)
|
|
{
|
|
|
|
//print_r($ponoreset); die;
|
|
$builder = $this->db->table('T_PONO_Reset_Table');
|
|
$builder->insert($ponoreset);
|
|
$r = $this->db->affectedRows();
|
|
return $r;
|
|
}
|
|
|
|
|
|
function updateponoreset($ponoreset, $sno, $potype, $posubtype)
|
|
{
|
|
$this->db->table('T_PONO_Reset_Table')
|
|
->where('reset_pono_id', $sno)
|
|
->where('POType', $potype)
|
|
->where('POSubtype', $posubtype)
|
|
->update($ponoreset);
|
|
$r = $this->db->affectedRows();
|
|
return $r;
|
|
}
|
|
|
|
function ponoresetfinyear()
|
|
{
|
|
$builder = $this->db->table('T_PONO_Reset_Table')->select('*');
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
///////////////////end this function used to pono reset financeyear configuration
|
|
public function isFileExists($filename)
|
|
{
|
|
$result = $this->db->table('t_purchaseorder_master')->where('POFile', $filename);
|
|
$query = $result->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
function fileupload($myfile)
|
|
{
|
|
|
|
//print_r($myfile);die;
|
|
$builder = $this->db->table('t_purchaseorder_billupload');
|
|
$builder->insert($myfile);
|
|
$myfile = $this->db->affectedRows();
|
|
return $myfile;
|
|
}
|
|
|
|
/*--------------------------------------------------*/
|
|
/* this function used parendpo igr values get inward report display */
|
|
function updateigrmaster($igrno, $NewPOno)
|
|
{
|
|
// $builder = $this->db->table('t_igr_master');
|
|
// $builder->insert($IGRaddvalues);
|
|
|
|
// $myfile=$this->db->affectedRows();
|
|
// return $myfile;
|
|
$this->db->table('t_igr_master')
|
|
|
|
->where('IGRNO', $igrno)
|
|
->update($NewPOno);
|
|
$insert_id = $this->db->affectedRows();
|
|
return $insert_id;
|
|
}
|
|
function updateigrfile($igrno, $NewPOno)
|
|
{
|
|
$this->db->table('t_inwardgateregister_fileupload')
|
|
->where('IGRNO', $igrno)
|
|
->update($NewPOno);
|
|
$insert_id = $this->db->affectedRows();
|
|
return $insert_id;
|
|
}
|
|
|
|
function selectigrmaster($PONO)
|
|
{
|
|
|
|
$builder = $this->db->table('t_igr_master')->select('*')
|
|
->where('PONO', $PONO);
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
function getpolineqty($NewPO)
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_lineitem')->select('sum(Quantity)as Qty,sum(ReceivedQuantity)as rec')
|
|
->where('PONO', $NewPO);
|
|
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function POLineItemsupdatestatus($NewPO, $Newstatus)
|
|
{
|
|
$this->db->table('t_purchaseorder_lineitem')
|
|
->where('PONO', $NewPO)
|
|
->update($Newstatus);
|
|
$update = $this->db->affectedRows();
|
|
return $update;
|
|
}
|
|
|
|
function pomasterupdatestatus($NewPO, $Newstatus)
|
|
{
|
|
$this->db->table('t_purchaseorder_master')
|
|
->where('PONO', $NewPO)
|
|
->update($Newstatus);
|
|
$update = $this->db->affectedRows();
|
|
return $update;
|
|
}
|
|
|
|
|
|
/*--------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
function getfunction($pono)
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_billupload bill')->distinct()
|
|
->select('bill.PONO,mstr.IGRNO,bill.BillNo,mstr.MaterialRcvdDate,bill.FilePath,mstr.DeliveryChellanOrInvoiceNo,mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.CourierNo,dtl.QuantityAsPerInvoice,pom.POType')
|
|
->join('t_igr_master mstr', 'bill.PONO = mstr.PONO', 'left')
|
|
->join('t_igr_details dtl', 'mstr.IGRNO = dtl.IGRNO', 'left')
|
|
// ->join('t_materialmaster mm','mm.MaterialCode = bill.MaterialCode')
|
|
->join('t_purchaseorder_master pom', 'pom.PONO = bill.PONO')
|
|
->where('bill.PONO', $pono)
|
|
//->orWhere('pom.status',SPECIAL_PO);
|
|
->groupBy('bill.BillNo');
|
|
// $builder = $this->db->table('t_igr_master mstr')
|
|
// ->select('mstr.PONO,mstr.IGRNO,mstr.DeliveryChellanOrInvoiceNo,
|
|
// mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.MaterialRcvdDate,
|
|
// mstr.CourierNo,bill.BillNo,bill.FilePath,pom.Status,pom.POType');
|
|
// ->join('t_purchaseorder_billupload bill','bill.PONO = mstr.PONO','left');
|
|
// ->join('t_igr_details dtl','mstr.IGRNO = dtl.IGRNO','left');
|
|
// // ->join('t_materialmaster mm','mm.MaterialCode = bill.MaterialCode');
|
|
// ->join('t_purchaseorder_master pom','pom.PONO = mstr.PONO');
|
|
// ->where('mstr.PONO',$pono);
|
|
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
function getfunctionr($pono)
|
|
{
|
|
|
|
// ->select('bill.PONO,mstr.IGRNO,bill.BillNo,mstr.MaterialRcvdDate,bill.FilePath,mstr.DeliveryChellanOrInvoiceNo,mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.CourierNo,dtl.QuantityAsPerInvoice,pom.POType');
|
|
// $builder = $this->db->table('t_purchaseorder_billupload bill');
|
|
// ->join('t_igr_master mstr','bill.PONO = mstr.PONO','left');
|
|
// ->join('t_igr_details dtl','mstr.IGRNO = dtl.IGRNO','left');
|
|
// // ->join('t_materialmaster mm','mm.MaterialCode = bill.MaterialCode');
|
|
// ->join('t_purchaseorder_master pom','pom.PONO = bill.PONO');
|
|
// ->where('bill.PONO',$pono);
|
|
// //$this->db->orWhere('pom.status',SPECIAL_PO);
|
|
// $this->db->group_by('bill.BillNo');
|
|
|
|
|
|
|
|
|
|
$builder = $this->db->table('t_igr_master mstr')->distinct()
|
|
->select('mstr.PONO,mstr.IGRNO,mstr.DeliveryChellanOrInvoiceNo,
|
|
mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.MaterialRcvdDate,
|
|
mstr.CourierNo,pom.Status,pom.POType') //,bill.BillNo,bill.FilePath,
|
|
|
|
|
|
//->join('t_purchaseorder_billupload bill','bill.PONO = mstr.PONO','left');
|
|
->join('t_igr_details dtl', 'mstr.IGRNO = dtl.IGRNO', 'left')
|
|
// ->join('t_materialmaster mm','mm.MaterialCode = bill.MaterialCode');
|
|
->join('t_purchaseorder_master pom', 'pom.PONO = mstr.PONO')
|
|
->where('mstr.PONO', $pono);
|
|
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function getbillfiesr($pono)
|
|
{
|
|
|
|
// $builder = $this->db->table('t_purchaseorder_billupload bill')->select('bill.PONO,mstr.IGRNO,bill.BillNo,mstr.MaterialRcvdDate,bill.FilePath,mstr.DeliveryChellanOrInvoiceNo,mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.CourierNo,dtl.QuantityAsPerInvoice,pom.POType');
|
|
// ->join('t_igr_master mstr','bill.PONO = mstr.PONO','left');
|
|
// ->join('t_igr_details dtl','mstr.IGRNO = dtl.IGRNO','left');
|
|
// // ->join('t_materialmaster mm','mm.MaterialCode = bill.MaterialCode');
|
|
// ->join('t_purchaseorder_master pom','pom.PONO = bill.PONO');
|
|
// ->where('bill.PONO',$pono);
|
|
// //->orWhere('pom.status',SPECIAL_PO);
|
|
// ->groupBy('bill.BillNo');
|
|
|
|
|
|
$builder = $this->db->table('t_igr_master mstr')->distinct()
|
|
->select('mstr.PONO,mstr.IGRNO,mstr.DeliveryChellanOrInvoiceNo,
|
|
mstr.DeliveryChellanDate,mstr.VehicleNo,mstr.MaterialRcvdDate,
|
|
mstr.CourierNo,bill.BillNo,bill.FilePath,pom.Status,pom.POType')
|
|
->join('t_purchaseorder_billupload bill', 'bill.PONO = mstr.PONO', 'left')
|
|
->join('t_igr_details dtl', 'mstr.IGRNO = dtl.IGRNO', 'left')
|
|
// ->join('t_materialmaster mm','mm.MaterialCode = bill.MaterialCode');
|
|
->join('t_purchaseorder_master pom', 'pom.PONO = mstr.PONO')
|
|
->where('mstr.PONO', $pono);
|
|
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
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->getResultArray();
|
|
}
|
|
|
|
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));
|
|
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
/**
|
|
* 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()
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_master POMast')->distinct()
|
|
->select('POMast.PONO,supp.SupplierName,TotalOrderValue,PODate,Stat.StatusName,Req.ReqType,DeliveryDate')
|
|
->join('t_supplierdetailsn supp', 'supp.SupplierID = POMast.SupplierID')
|
|
->join('t_status Stat', 'Stat.StatusCode = POMast.Status')
|
|
->join('t_purchaseorder_lineitem LineItem', 'POMast.PONO = LineItem.PONO')
|
|
->join('t_requestion_master Req', 'Req.ReqNo = LineItem.ReqNo');
|
|
|
|
$query = $builder->get();
|
|
|
|
return count($query->getResult());
|
|
}
|
|
|
|
/**
|
|
* 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 ,$fromDate='',$toDate='')
|
|
{
|
|
|
|
$builder = $this->db->table('t_purchaseorder_master POMast')->distinct()
|
|
->select('POMast.PONO,POMast.CreatedDate,supp.SupplierName,TotalOrderValue,PODate,Stat.StatusName,Stat.StatusCode,POMast.POType as ReqType,DeliveryDate,DeliverySchedule,DeliveryOption,POMast.CapitalRange')
|
|
->join('t_supplierdetailsn supp', 'supp.SupplierID = POMast.SupplierID')
|
|
->join('t_status Stat', 'Stat.StatusCode = POMast.Status')
|
|
->join('t_purchaseorder_lineitem LineItem', 'POMast.PONO = LineItem.PONO')
|
|
->join('t_requestion_master Req', 'Req.ReqNo = LineItem.ReqNo');
|
|
if ($forwhat == 'amendment') {
|
|
$builder->where('POMast.Status', PO_RELEASED);
|
|
} else {
|
|
$builder->where('POMast.Status !=', PO_AMENDED);
|
|
// $builder->orderBy('POMast.Status !=',PO_AMENDED);
|
|
}
|
|
|
|
$builder->where('Date(POMast.CreatedDate) >=', $fromDate)
|
|
->where('Date(POMast.CreatedDate) <=', $toDate);
|
|
|
|
|
|
$builder->orderBy('POMast.CreatedDate', 'desc');
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
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 = '')
|
|
{
|
|
$builder = $this->db->table('t_supplierdetailsn')->select('SupplierID, SupplierName,Address,PaymentID,MSME')
|
|
->where('IsActive', 1);
|
|
if ($supID != '') {
|
|
$builder->where('SupplierID', $supID);
|
|
}
|
|
//$builder->where('roleId !=', 1);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
/**
|
|
* This function is used to get the userId information
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getusers()
|
|
{
|
|
|
|
$builder = $this->db->table('tbl_users')->select('userId, name');
|
|
//->where('roleId !=', 1);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function getqtycheck($PONO)
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_master')->select('IsQualityChkReqired')
|
|
->where('PONO', $PONO);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
/**
|
|
* 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();
|
|
|
|
|
|
|
|
if ($result->getNumRows() > 0) {
|
|
//echo 'PO Line item Inserted successfully';
|
|
if ($IsArray != '') {
|
|
return $result->getResultArray();
|
|
} else {
|
|
return $result->getResult();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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->getNumRows() > 0) {
|
|
|
|
return $result->getResult();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This function is used to get the Raw Material information
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getRawMaterialList($MatType = '', $ReqNoList = '')
|
|
{
|
|
|
|
$builder = $this->db->table('t_requestion_details Req')->select('ReqNo,Req.MaterialCode,MaterialName,UOM,Req.Quantity')
|
|
->join('t_materialmaster mat', 'Req.MaterialCode = mat.MaterialCode')
|
|
->where('mat.MaterialType', $MatType)
|
|
->whereIn('Req.ReqNo', $ReqNoList);
|
|
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
/**
|
|
* 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->getResultArray();
|
|
}
|
|
//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));
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
//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->getResultArray();
|
|
}
|
|
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));
|
|
|
|
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
//to get POTYpe from ReqNo
|
|
function GetPOType($ReqNo)
|
|
{
|
|
|
|
$builder = $this->db->table('t_purchaseorder_master mast')->select('POType')
|
|
->join('t_purchaseorder_lineitem Line', 'mast.PONO=Line.PONO')
|
|
->where('Line.ReqNo', $ReqNo);
|
|
$query = $builder->get();
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
/**
|
|
* 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) {
|
|
$builder = $this->db->table('t_requestion_master mast')->distinct()
|
|
->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')
|
|
->join('t_departmentdetails Dept', 'mast.RequestedDept = Dept.DEPCode')
|
|
->whereIn('mast.ReqNo', $ReqNoList);
|
|
} else if ($ReqBy != '') {
|
|
$builder = $this->db->table('t_requestion_master mast')->distinct()
|
|
->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')
|
|
->join('t_employee_details emp', 'mast.Requestedby = emp.EmpID')
|
|
->join('t_departmentdetails Dept', 'mast.RequestedDept = Dept.DEPCode')
|
|
->whereIn('mast.ReqNo', $ReqNoList);
|
|
}
|
|
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
/**
|
|
* 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 = '')
|
|
{
|
|
$builder = $this->db->table('t_requestion_master mast')
|
|
->distinct()->select('ReqNo,ReqType,Status,Requestedby,mast.CreatedDate,emp.FirstName,emp.EmpID,emp.Designation, Dept.DEPCode,Dept.DepartmentName,mast.ReqDate')
|
|
->join('t_employee_details emp', 'mast.Requestedby = emp.EmpID')
|
|
->join('t_departmentdetails Dept', 'emp.Departmentcode = Dept.DEPCode')
|
|
->whereIn('mast.ReqNo', $ReqNoList);
|
|
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
/**
|
|
* This function is used to get the Cost center information
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getCostCenter()
|
|
{
|
|
|
|
$builder = $this->db->table('T_CostCentre')->select('CostName, Description');
|
|
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
/**
|
|
* 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 = '')
|
|
{
|
|
|
|
$builder = $this->db->table('t_costcenter_master Mast')->distinct()
|
|
->select('Mast.CostCenterCode,Mast.CostCenterName,Bud.BudgetAmount,ReqNo')
|
|
->join('t_costcenter_departments CostDept', 'CostDept.CostCenterCode = Mast.CostCenterCode')
|
|
->join('t_costcenter_budget Bud', 'Bud.CostCenterCode = Mast.CostCenterCode')
|
|
->join('t_employee_details emp', 'CostDept.DEPCode = emp.Departmentcode')
|
|
->join('t_requestion_master req', 'req.Requestedby = emp.EmpID')
|
|
->where('BudgetType ', $ReqType)
|
|
->where('BudgetYear ', $BudYear);
|
|
if ($ReqNo != '') {
|
|
$builder->where('ReqNo ', $ReqNo);
|
|
}
|
|
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
public function getCostCenterMasterDetails($costCenterCode){
|
|
$builder = $this->db->table('t_costcenter_master Mast')->distinct()
|
|
->select('Mast.*')
|
|
->where('CostCenterCode ', $costCenterCode);
|
|
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
/**
|
|
* This function is used to get the Config value from configuration table
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getRequistionNoFromPO($PONO = '')
|
|
{
|
|
|
|
$builder = $this->db->table('t_purchaseorder_lineitem')
|
|
->select('ReqNo')->distinct();
|
|
if ($PONO != '') {
|
|
$builder->where('PONO ', $PONO);
|
|
}
|
|
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
/**
|
|
* 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 = '')
|
|
{
|
|
|
|
|
|
$builder = $this->db->table('t_configdetails')->select('ConfigValue')
|
|
->where('Config_id ', $ConfigID);
|
|
if ($ConfigValue != '') {
|
|
$builder->where('ConfigValue != ', $ConfigValue);
|
|
}
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* 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);
|
|
|
|
|
|
|
|
return $query->getResult();
|
|
// return $query->getResult();
|
|
}
|
|
/**
|
|
* 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,MSME,ContactNumber,EmailAddress,AlternateContactNumber,companyWebsite,StateCode
|
|
from t_company_details ";
|
|
|
|
|
|
|
|
$query = $this->db->query($subQuery);
|
|
|
|
|
|
|
|
return $query->getResult();
|
|
// return $query->getResult();
|
|
}
|
|
|
|
/**
|
|
* This function is used to get the Employee List
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getAllEmployees()
|
|
{
|
|
|
|
$builder = $this->db->table('t_employee_details')->select('EmpID,FirstName,LastName');
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
/**
|
|
* This function is used to get the Employee List
|
|
* @return array $result : This is result of the query
|
|
*/
|
|
function getLastCreatedPODate()
|
|
{
|
|
|
|
$builder = $this->db->table('t_purchaseorder_master')->select('max(PODate) as PODate');
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
function getLastReleasedPODate()
|
|
{
|
|
|
|
$builder = $this->db->table('t_purchaseorder_master')->select('max(ReleasedOn) as PODate');
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
/**
|
|
* This function is used to add New Purchase order to the system
|
|
*/
|
|
function addPOMaster($POMaster, $POType, $revenuetype)
|
|
{
|
|
// print_r($POMaster);die;
|
|
try {
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_purchaseorder_master');
|
|
$builder->insert($POMaster);
|
|
$aff_row = $this->db->affectedRows();
|
|
$insertId = $this->db->insertId();
|
|
log_message('error', 'addPOMaster POID : ' . $insertId);
|
|
$this->db->transComplete();
|
|
if ($aff_row > 0) {
|
|
|
|
// log_message('error', 'Error inside if now insertId: ' . $this->db->insertId());
|
|
|
|
$subQuery = 'SELECT PONO FROM t_purchaseorder_master
|
|
WHERE POID = ? AND ParentPO IS NULL
|
|
ORDER BY CreatedDate DESC LIMIT 1';
|
|
|
|
$query = $this->db->query($subQuery, [$insertId]);
|
|
$result = $query->getResultArray();
|
|
log_message('error', 'addPOMaster subQuery: ' . $this->db->getLastQuery()->getQuery());
|
|
log_message('error', 'addPOMaster subQuery result : ' . json_encode($result));
|
|
return $result;
|
|
}
|
|
return [];
|
|
} catch (\Exception $e) {
|
|
$this->db->transRollback();
|
|
log_message('error', 'not inserted in addPOMaster due to : ' . $e->getMessage());
|
|
throw $e;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function addAmendPOMaster($POMaster, $CreatedBy, $ParentPO)
|
|
{
|
|
// print_r($POMaster);die;
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_purchaseorder_master');
|
|
$builder->insert($POMaster);
|
|
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
|
|
// print_r($insert_id);die;
|
|
|
|
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));
|
|
|
|
$result = $query->getResultArray();
|
|
|
|
//print_r($result);die;
|
|
|
|
return $result;
|
|
} else {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This function is used to add New Purchase order Line Item to the system
|
|
*/
|
|
function addPOLineItem($POLineItem)
|
|
{
|
|
log_message('error', 'addPOLineItem Requested : ' . json_encode($POLineItem));
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_purchaseorder_lineitem');
|
|
$builder->insert($POLineItem);
|
|
$insertId = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
|
|
if ($insertId > 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);
|
|
$result = $query->getResultArray();
|
|
log_message('error', 'addPOLineItem subQuery: ' . $this->db->getLastQuery()->getQuery());
|
|
log_message('error', 'addPOLineItem subQuery result : ' . json_encode($result));
|
|
|
|
return $query->getResultArray();
|
|
} else {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This function is used to add Revenue Tax to the system
|
|
*/
|
|
function addRevenueTax($RevenueTaxList)
|
|
{
|
|
log_message('error', 'addRevenueTax Requested : ' . json_encode($RevenueTaxList));
|
|
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_revenue_tax');
|
|
$builder->insert($RevenueTaxList);
|
|
$insertId = $this->db->insertId();
|
|
$aff_row = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
|
|
log_message('error', 'addRevenueTax query: ' . $this->db->getLastQuery()->getQuery());
|
|
log_message('error', 'addRevenueTax affrow : ' . $aff_row);
|
|
log_message('error', 'addRevenueTax insertId : ' . $insertId);
|
|
return $insertId;
|
|
}
|
|
/**
|
|
* This function is used to add Service Tax to the system
|
|
*/
|
|
function addServiceTax($ServiceTaxList)
|
|
{
|
|
|
|
log_message('error', 'addServiceTax Requested : ' . json_encode($ServiceTaxList));
|
|
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_service_tax');
|
|
$builder->insert($ServiceTaxList);
|
|
$insertId = $this->db->insertId();
|
|
$aff_row = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
|
|
log_message('error', 'addServiceTax query: ' . $this->db->getLastQuery()->getQuery());
|
|
log_message('error', 'addServiceTax affrow : ' . $aff_row);
|
|
log_message('error', 'addServiceTax insertId : ' . $insertId);
|
|
return $insertId;
|
|
}
|
|
|
|
|
|
/**
|
|
* This function is used to add Service Tax to the system
|
|
*/
|
|
function addImportTax($ImportTaxList)
|
|
{
|
|
log_message('error', 'addImportTax Requested : ' . json_encode($ImportTaxList));
|
|
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_import_tax');
|
|
$builder->insert($ImportTaxList);
|
|
$insertId = $this->db->insertId();
|
|
$aff_row = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
|
|
log_message('error', 'addImportTax query: ' . $this->db->getLastQuery()->getQuery());
|
|
log_message('error', 'addImportTax affrow : ' . $aff_row);
|
|
log_message('error', 'addImportTax insertId : ' . $insertId);
|
|
return $insertId;
|
|
}
|
|
|
|
|
|
|
|
function addadvanceRequest($advance)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_purchaseorder_advancerequest');
|
|
$builder->insert($advance);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
return $insert_id;
|
|
}
|
|
|
|
function PONOExists($PONO)
|
|
{
|
|
|
|
|
|
$builder = $this->db->table('t_purchaseorder_advancerequest')
|
|
->select('PONO')
|
|
->where('PONO ', $PONO);
|
|
$query = $builder->get();
|
|
|
|
if ($query->getNumRows() > 0) {
|
|
return $query->getResultArray();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function updateadvanceRequest($advance, $PONO)
|
|
{
|
|
$this->db->table('t_purchaseorder_advancerequest')
|
|
->where('PONO', $PONO)
|
|
->update($advance);
|
|
$insert_id = $this->db->affectedRows();
|
|
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)
|
|
{
|
|
|
|
$builder = $this->db->table('T_PurchaseOrderDetails')
|
|
->select('POType, PODate, SupplierID,SpecialOrder,UserID,RequestedDate,RequesterEmail,RequesterPh, PurchasingCategory,BudgetManager,BudgetManagerDepartment,')
|
|
->where('PONO', $PO);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
// This Method to get the Service PO Details for Edit the Item
|
|
|
|
function GetServicePurchaseOrder($PONO = '')
|
|
{
|
|
|
|
$builder = $this->db->table('t_purchaseorder_master POMast')->distinct()
|
|
->select('ReqNo,POMast.PONO,POMast.PaymentTerms,POMast.PaymentOtherDescription,
|
|
ServiceDescription,supp.SupplierID,supp.SupplierName,supp.Address,supp.MSME,
|
|
PODate,Stat.StatusName,DeliveryOption,DeliverySchedule,DeliveryDate,DeliveryAddress,
|
|
POMast.PaymentTerms,POMast.ExchangeRate,POMast.UpdatedOn,Stat.StatusCode,
|
|
POMast.ServiceWorkStatus,POMast.*,POMast.TotalOrderValue,POMast.BudgetType,IGR.IGRNO')
|
|
|
|
->join('t_supplierdetailsn supp', 'supp.SupplierID = POMast.SupplierID')
|
|
->join('t_status Stat', 'Stat.StatusCode = POMast.Status')
|
|
->join('t_purchaseorder_lineitem LineItem', 'POMast.PONO = LineItem.PONO')
|
|
->join('t_igr_master IGR', 'POMast.PONO = IGR.PONO', 'left')
|
|
->where('POMast.PONO', $PONO);
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
|
|
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
|
|
left join t_materialmaster Mat on Mat.MaterialCode = LineItem.MaterialCode
|
|
left join t_service_tax Tax on Tax.LineItemNo = LineItem.LineItemNo
|
|
left join t_requestion_master Req on Req.ReqNo = LineItem.ReqNo
|
|
left 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
|
|
left join t_departmentdetails Dept on Req.RequestedDept = Dept.DEPCode
|
|
where LineItem.PONO =?';
|
|
|
|
$query = $this->db->query($subQuery, array($PONO));
|
|
|
|
return $query->getResult();
|
|
}
|
|
// 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.After_SGST AS AfterSGST,Tax.After_CGST AS AfterCGST,Tax.After_IGST AS AfterIGST , Tax.*,LineItem.CostCenterCode ,POMaster.*,sup.SupplierName,sup.SupplierID,sup.Address,sup.ContactNumber,sup.EmailAddress,sup.PAN,sup.GSTNO,sup.MSME,sup.Cert_MSME,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->getResult();
|
|
}
|
|
|
|
|
|
|
|
// 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->getResult();
|
|
}
|
|
|
|
// 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,sup.MSME,sup.Cert_MSME,
|
|
LineItem.AmendedDetails as LineAmend,LineItem.AmendedDetails as lineamenddetails,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->getResult();
|
|
}
|
|
|
|
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->getResult();
|
|
}
|
|
// 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,LineItem.AmendedDetails as lineamenddetails,AdvanceAmount, Pay.PaymentTerms as Pay,ROUND((Quantity *Rate),2 ) as BasicValue,HSNCODE,
|
|
sup.EmailAddress,sup.SupplierID,sup.PAN,sup.ContactNumber,sup.GSTNO,sup.MSME,sup.Cert_MSME
|
|
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));
|
|
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function GetCurrencyDetail($Currency = '')
|
|
{
|
|
|
|
$subQuery = 'SELECT * from t_currency_details where Currency_Code=?';
|
|
$query = $this->db->query($subQuery, array($Currency));
|
|
//print_r($query);
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function GerRequesterName($Requester = '')
|
|
{
|
|
$subQuery = 'SELECT EmpID,FirstName,Departmentcode from t_employee_details where EmpID=?';
|
|
|
|
$query = $this->db->query($subQuery, array($Requester));
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function GerRequesterDep($Depcode = '')
|
|
{
|
|
$subQuery = 'SELECT DepartmentName from t_departmentdetails where DEPCode=?';
|
|
$query = $this->db->query($subQuery, array($Depcode));
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
function GerCurrencyCodeName($Currencycode = '')
|
|
{
|
|
$subQuery = 'SELECT * from t_currency_details where Currency_Code=?';
|
|
$query = $this->db->query($subQuery, array($Currencycode));
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function GetPOStatus($Status = '')
|
|
{
|
|
$subQuery = 'SELECT StatusName from t_status where StatusCode=?';
|
|
$query = $this->db->query($subQuery, array($Status));
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function GetPaymentTerms($PONO = '')
|
|
{
|
|
$subQuery = 'SELECT PaymentTerms from t_purchaseorder_master where PONO=?';
|
|
$query = $this->db->query($subQuery, array($PONO));
|
|
//print_r($query);
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
|
|
// function getSupplierPayment($Currency='')
|
|
// {
|
|
|
|
// $subQuery='select distinct PaymentTerms from t_supplierdetailsn';
|
|
// $query=$this->db->query($subQuery,array($Currency));
|
|
//
|
|
// return $query->getResult();
|
|
|
|
// }
|
|
|
|
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));
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
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->getResult();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
LEFT JOIN t_purchaseorder_master POMast ON POMast.PONO = LineItem.PONO
|
|
LEFT JOIN t_materialmaster Mat ON Mat.MaterialCode = LineItem.MaterialCode
|
|
LEFT JOIN t_import_tax Tax ON Tax.LineItemNo = LineItem.LineItemNo
|
|
LEFT 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
|
|
LEFT JOIN t_departmentdetails Dept ON Req.RequestedDept = Dept.DEPCode
|
|
|
|
WHERE LineItem.PONO = ?';
|
|
|
|
$query = $this->db->query($subQuery, array($PONO));
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function GetCurrencytype()
|
|
{
|
|
|
|
$subQuery = 'select * from t_currency_details';
|
|
|
|
$query = $this->db->query($subQuery);
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
function GetINRCurrencytype($Currency_Code = '')
|
|
{
|
|
$subQuery = 'select * from t_currency_details where Currency_Code=?';
|
|
$query = $this->db->query($subQuery, array($Currency_Code));
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// To Update the PO
|
|
function updatePOMaster($PONO, $PODetails)
|
|
{
|
|
$this->db->table('t_purchaseorder_master')
|
|
->where('PONO', $PONO)
|
|
->update($PODetails);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
// To update Parent PO as Amended PO
|
|
function updateAmendPOMaster($PONO, $PODetail)
|
|
{
|
|
//echo $PONO."from model";
|
|
$this->db->table('t_purchaseorder_master')
|
|
->where('PONO', $PONO)
|
|
->update($PODetail);
|
|
$insert_id = $this->db->affectedRows();
|
|
|
|
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)
|
|
{
|
|
|
|
$builder = $this->db->table('t_service_tax')
|
|
->select('LineItemNo,TaxID')
|
|
->where('LineItemNo ', $LineItemNo);
|
|
//->where('Requestedby ',$ReqBy );
|
|
$query = $builder->get();
|
|
|
|
if ($query->getNumRows() > 0) {
|
|
//echo $result->getNumRows();
|
|
return $query->getResultArray();
|
|
}
|
|
}
|
|
/**
|
|
* 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)
|
|
{
|
|
|
|
$builder = $this->db->table('t_revenue_tax')->select('LineItemNo')
|
|
->where('LineItemNo ', $LineItemNo);
|
|
$query = $builder->get();
|
|
|
|
if ($query->getNumRows() > 0) {
|
|
return $query->getResultArray();
|
|
}
|
|
}
|
|
|
|
|
|
function LineItemExistsinImportTax($LineItemNo)
|
|
{
|
|
|
|
$builder = $this->db->table('t_import_tax')->select('LineItemNo')
|
|
->where('LineItemNo ', $LineItemNo);
|
|
$query = $builder->get();
|
|
|
|
if ($query->getNumRows() > 0) {
|
|
return $query->getResultArray();
|
|
}
|
|
}
|
|
// To Update the PO Line Item
|
|
function updatePOLineItem($PONO, $LineItemNo, $PODetails)
|
|
{
|
|
$this->db->table('t_purchaseorder_lineitem')
|
|
->where('PONO', $PONO)
|
|
->where('LineItemNo', $LineItemNo)
|
|
->update($PODetails);
|
|
|
|
return TRUE;
|
|
}
|
|
/*// To Update the Service Tax Item */
|
|
function updateServiceTax($LineItemNo, $PODetails)
|
|
{
|
|
$this->db->table('t_service_tax')
|
|
->where('LineItemNo', $LineItemNo)
|
|
->update($PODetails);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
/*// To Update the Revenue Tax Item */
|
|
function updateRevenueTax($LineItemNo, $PODetails)
|
|
{
|
|
$this->db->table('t_revenue_tax')
|
|
->where('LineItemNo', $LineItemNo)
|
|
->update($PODetails);
|
|
return TRUE;
|
|
}
|
|
|
|
function updateImportTax($LineItemNo, $PODetails)
|
|
{
|
|
$this->db->table('t_import_tax')
|
|
->where('LineItemNo', $LineItemNo)
|
|
->update($PODetails);
|
|
return TRUE;
|
|
}
|
|
|
|
function getLastInsertedPO()
|
|
{
|
|
|
|
$builder = $this->db->table('T_PurchaseOrderDetails')->select('max(PONO) as PO');
|
|
$query = $builder->get();
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
|
|
/* 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->getResult();
|
|
}
|
|
/*
|
|
* 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->getResult();
|
|
}
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
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->getResultArray();
|
|
}
|
|
|
|
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));
|
|
|
|
return $query->getResultArray();
|
|
} 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));
|
|
|
|
return $query->getResultArray();
|
|
} 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));
|
|
|
|
return $query->getResultArray();
|
|
} 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));
|
|
|
|
return $query->getResultArray();
|
|
} 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));
|
|
|
|
return $query->getResultArray();
|
|
} 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));
|
|
|
|
return $query->getResultArray();
|
|
} 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));
|
|
|
|
return $query->getResultArray();
|
|
} else {
|
|
$query = $this->db->query($subQuery, array(REQ_DRAFT, REQ_PENDING_APPROVAL, REQ_DELETED, REQ_REJECTED, REQ_PO_CREATED));
|
|
|
|
return $query->getResult();
|
|
}
|
|
}
|
|
|
|
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->table('t_purchaseorder_lineitem')->delete(['LineItemNo' => $LineItem, 'ReqNo' => $ReqNo, 'MaterialCode' => $MaterialCode]);
|
|
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->table('t_revenue_tax')->delete(['LineItemNo' => $LineItem]);
|
|
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->table('t_service_tax')->delete(['LineItemNo' => $LineItem]);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function DeletePOImportTax($LineItem = '')
|
|
{
|
|
|
|
$this->db->table('t_import_tax')->delete(['LineItemNo' => $LineItem]);
|
|
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, $fromDate , $toDate)
|
|
{
|
|
|
|
$builder = $this->db->table('t_purchaseorder_master mast')->distinct()
|
|
->select('mast.PODate,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,sup.SupplierName,sup.MSME')
|
|
->join('t_supplierdetailsn sup', 'sup.SupplierID = mast.SupplierID')
|
|
->join('t_status st', 'st.StatusCode=mast.Status')
|
|
->join('t_purchaseorder_lineitem req', 'req.PONO= mast.PONO')
|
|
->join('t_requestion_master rmast', 'rmast.ReqNo=req.ReqNo')
|
|
//->join('t_costcenter_budget bud','bud.CostCenterCode = req.CostCenterCode and bud.BudgetType = rmast.ReqType')
|
|
->join('t_costcenter_master ccm', 'ccm.CostCenterCode = req.CostCenterCode', 'left')
|
|
->join('tbl_users tbl', 'rmast.createdby=tbl.userid', 'left')
|
|
->join('t_employee_details as emp', 'emp.empid=tbl.empid', 'left')
|
|
->join('t_departmentdetails as Dep', 'Dep.DEPCode=emp.Departmentcode', 'left');
|
|
|
|
$builder->where('DATE(mast.CreatedDate) >=', $fromDate);
|
|
$builder->where('DATE(mast.CreatedDate) <=', $toDate);
|
|
$builder->orderBy('mast.CreatedDate', 'DESC');
|
|
|
|
if ($type == 'RELEASE') {
|
|
$builder->groupStart();
|
|
$builder->orWhere('mast.Status', PO_DRAFT);
|
|
$builder->orWhere('mast.Status', PO_CREATED);
|
|
$builder->orWhere('mast.Status', PO_APPROVER_ONHOLD);
|
|
$builder->orWhere('mast.Status', PO_AWAITING_RELEASE);
|
|
$builder->orWhere('mast.Status', PO_RELEASER_ONHOLD);
|
|
$builder->orWhere('mast.Status', PO_RELEASED);
|
|
$builder->orWhere('mast.Status', REQITEM_Emergency_PO_CREATED);
|
|
$builder->groupEnd();
|
|
}
|
|
|
|
|
|
|
|
$result = $builder->get();
|
|
// Get the last executed query
|
|
// $lastQuery = $this->db->getLastQuery();
|
|
// echo $lastQuery;
|
|
// die;
|
|
return $result->getResult();
|
|
}
|
|
|
|
|
|
function UpdatePO($store, $PONO)
|
|
{
|
|
$this->db->table('t_purchaseorder_master')
|
|
->where('PONO', $PONO)
|
|
->update($store);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
function GetReleasedDetails($PONO)
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_master mast')
|
|
->select('mast.ReleasedOn,re.FirstName')
|
|
->join('tbl_users tbl', 'mast.ReleasedBy=tbl.userid')
|
|
->join('t_employee_details re', 're.EmpID=tbl.EmpID')
|
|
->where('mast.PONO', $PONO);
|
|
$result = $builder->get();
|
|
|
|
//die();
|
|
return $result->getResult();
|
|
}
|
|
//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
|
|
left 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_departmentdetails Dept on Req.RequestedDept = Dept.DEPCode where LineItem.PONO =?';
|
|
//print_r($subQuery);
|
|
|
|
$query = $this->db->query($subQuery, array($PONO));
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
// This Method to get the Capital PO Details for pdf
|
|
function GetCapitalPurchaseOrderDetailsForPDF($PONO = '')
|
|
{
|
|
|
|
$subQuery = 'SELECT distinct LineItem.LineItemNo,LineItem.Per,LineItem.AmendedDetails as lineamd,LineItem.AmendedDetails as lineamenddetails,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,sup.MSME,sup.Cert_MSME,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->getResult();
|
|
}
|
|
// get requested by details
|
|
function GetRequesedByDetails($PONO)
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_master mast')
|
|
->select('mast.CreatedBy, re.FirstName, Dept.DEPCode, Dept.DepartmentName')
|
|
->join('tbl_users tbl', 'mast.CreatedBy = tbl.userid', 'left')
|
|
->join('t_employee_details re', 're.EmpID = tbl.EmpID', 'left')
|
|
->join('t_departmentdetails Dept', 're.Departmentcode = Dept.DEPCode', 'left')
|
|
->where('mast.PONO', $PONO);
|
|
|
|
$result = $builder->get();
|
|
return $result->getResult();
|
|
}
|
|
|
|
|
|
// 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
|
|
left 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->getResult();
|
|
}
|
|
//get pdf po requistion details
|
|
|
|
|
|
function GetPdfRequistionDetails($PONO)
|
|
{
|
|
|
|
$builder = $this->db->table('t_purchaseorder_lineitem LineItem')->select('LineItem.ReqNo')
|
|
->where('LineItem.PONO', $PONO);
|
|
$result = $builder->get();
|
|
$ReqNo = '';
|
|
|
|
foreach ($result->getResult() as $res) {
|
|
|
|
if ($ReqNo == $res->ReqNo) {
|
|
} else {
|
|
$ReqNo = $res->ReqNo;
|
|
$builder1 = $this->db->table('t_requestion_master ReqMast')
|
|
->select('ReqMast.ReqNo,ReqMast.CostCenterCode,ReqMast.ReqDate,ReqMast.Schedule_Type,ReqMast.NumberOfService,ReqMast.Service_Period,Dept.DEPCode,Dept.DepartmentName,Dept.shortName')
|
|
->join('t_departmentdetails Dept', 'ReqMast.RequestedDept = Dept.DEPCode')
|
|
->where('ReqMast.ReqNo', $ReqNo);
|
|
$Reqresult = $builder1->get();
|
|
$Details['RequistionNo'] = $Reqresult->getResult()[0]->ReqNo;
|
|
$Details['ReqDate'] = $Reqresult->getResult()[0]->ReqDate;
|
|
|
|
$Details['RequestedDept'] = $Reqresult->getResult()[0]->shortName;
|
|
$Details['CostCenterCode'] = $Reqresult->getResult()[0]->CostCenterCode;
|
|
$retDate = format_date($Reqresult->getResult()[0]->ReqDate, 0, $format = 'd-m-Y');
|
|
$Details['ReqDate'] = $retDate;
|
|
$ScheduleType = $Reqresult->getResult()[0]->Schedule_Type;
|
|
if ($ScheduleType != 'Recurring') {
|
|
$Details['Frequency'] = $Reqresult->getResult()[0]->Schedule_Type;
|
|
} else {
|
|
$Details['Frequency'] = $Reqresult->getResult()[0]->Service_Period . ' - ' . $Reqresult->getResult()[0]->NumberOfService;
|
|
}
|
|
|
|
$ResultArray[] = $Details;
|
|
}
|
|
}
|
|
|
|
$RequistionDetails = $ResultArray;
|
|
return $RequistionDetails;
|
|
}
|
|
function GetLineItemReceivedQty($ParentPO, $MaterialCode)
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_lineitem')
|
|
->select('ReceivedQuantity')
|
|
->where('PONO', $ParentPO)
|
|
->where('MaterialCode', $MaterialCode);
|
|
$result = $builder->get();
|
|
|
|
return $result->getResultArray();
|
|
}
|
|
|
|
//get paymentTerms details
|
|
|
|
function getPaymentTermsDetails($Payment_ID = '')
|
|
{
|
|
|
|
|
|
$getpaymentQuery = 'select distinct PaymentID,PaymentTerms,Details from t_paymentterms';
|
|
$paymentQuery = $this->db->query($getpaymentQuery);
|
|
|
|
return $paymentQuery->getResult();
|
|
}
|
|
/**
|
|
* This function is used to get status in status table
|
|
|
|
*/
|
|
function getStatus($StatusType = '')
|
|
{
|
|
|
|
$builder = $this->db->table('t_status')->select('StatusCode,StatusName ')
|
|
->where('StatusType', $StatusType);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function edit_mrir($MrirNo)
|
|
{
|
|
$builder = $this->db->table('t_mrir_master TMM')
|
|
->distinct()
|
|
->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')
|
|
->join('t_mrir_details TMD', 'TMM.MRIRNO = TMD.MRIRNO', 'left') //to get IGRNO,PONO,MRIRNO,mrirdate,
|
|
->join('t_igr_master IGRM', 'IGRM.IGRNO = TMM.IGRNO', 'left') //to get actualquantity,deliverydate,Invoicedate,vechileno,courierno,igrdate,
|
|
->join('t_purchaseorder_master POMR ', 'IGRM.PONO = POMR.PONO', 'left') //to get podate,deliverydate,servicedescription
|
|
->join('t_purchaseorder_lineitem POLT', 'IGRM.PONO=POLT.PONO', 'left') //to get receivedquantity,quantity
|
|
->join('t_igr_details IGRD', 'IGRD.IGRNO = IGRM.IGRNO', 'left') //to get invoicequantity
|
|
->join('t_materialmaster MM', 'IGRD.MaterialCode = MM.MaterialCode', 'left')
|
|
->join('t_supplierdetailsn SUPP', 'POMR.SupplierID = SUPP.SupplierID', 'left') //to get suppliername,supplieraddress
|
|
->join('tbl_users user', 'user.userid = POMR.CreatedBy', 'left') //to get poraisedby
|
|
->join('t_employee_details ED', 'ED.EmpID = user.EmpID', 'left')
|
|
->join('tbl_users user1', 'user1.userid=TMM.CreatedBy', 'left') //to get mrirraisedby
|
|
->join('t_employee_details ED1', 'ED1.EmpID = user1.EmpID', 'left')
|
|
->join('tbl_users user2', 'user2.userid=IGRM.CreatedBy', 'left') //to get igrraisedby
|
|
->join('t_employee_details ED2', 'ED2.EmpID = user2.EmpID', 'left')
|
|
->join('t_costcenter_master TCOST', 'POLT.CostCenterCode=TCOST.CostCenterCode')
|
|
->where('TMM.MRIRNO', $MrirNo)
|
|
->groupBy('TMM.MRIRNO,TMD.MaterialCode');
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getadvancePONO($Status = '')
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_master Mast')->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')
|
|
->join('t_purchaseorder_lineitem LineItem', 'Mast.PONO=LineItem.PONO')
|
|
->join('t_requestion_master ReqMa', 'LineItem.ReqNo=ReqMa.ReqNo')
|
|
->join('t_employee_details EmpDet', 'ReqMa.Requestedby=EmpDet.EmpID', 'left')
|
|
->join('t_departmentdetails DepDet', 'EmpDet.Departmentcode=DepDet.DEPCode or ReqMa.RequestedDept=DepDet.DEPCode', 'left')
|
|
->join('t_supplierdetailsn SupDet', 'Mast.SupplierID=SupDet.SupplierID')
|
|
->join('t_purchaseorder_advancerequest POAdv', 'Mast.PONO=POAdv.PONO', 'left')
|
|
->join('t_paymentterms Payterm', 'Mast.PaymentTerms=Payterm.PaymentID')
|
|
->where('Mast.Status', $Status);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
// update req deatail if work status is completed
|
|
|
|
function updateReqDetail($PONO, $POStatus, $MaterialCode)
|
|
{
|
|
$this->db->table('t_purchaseorder_lineitem Item')
|
|
->join('t_requestion_details Req', 'Item.ReqNo = Req.ReqNo')
|
|
->where('Item.PONO', $PONO)
|
|
->where('Req.MaterialCode', $MaterialCode)
|
|
->set('Req.Status', $POStatus)
|
|
->update();
|
|
return TRUE;
|
|
}
|
|
|
|
function UpdateReceivedQtyforServicePO($PONO, $updateddt, $updatedBy)
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_lineitem')->select('LineItemNo,MaterialCode')
|
|
->where('PONO ', $PONO);
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
|
|
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->getResult();
|
|
}
|
|
// 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->getResult();
|
|
} 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->getResult();
|
|
}
|
|
}
|
|
// 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->getResult();
|
|
}
|
|
//get Dept Emp Name
|
|
function getDepartmentEmpList($DepCode = '')
|
|
{
|
|
|
|
$builder = $this->db->table('t_employee_details')->select('EmpID')
|
|
->where('Departmentcode', $DepCode)
|
|
->limit('1');
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
//get req master details using reqno
|
|
function GetRequistionMasterUsingReqNo($Req)
|
|
{
|
|
|
|
$builder = $this->db->table('t_requestion_master')->select('Requestedby')
|
|
->where('ReqNo', $Req[0]);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
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->getResult();
|
|
}
|
|
|
|
|
|
|
|
function GetClients()
|
|
{
|
|
|
|
$builder = $this->db->table('ip_clients')->select('client_id,client_name');
|
|
$query = $builder->get();
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
|
|
function SaveEnquiry($save)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('T_Enquiry');
|
|
$builder->insert($save);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
return $insert_id;
|
|
}
|
|
|
|
|
|
function UpdateEnquiry($save, $Id)
|
|
{
|
|
$this->db->table('T_Enquiry')
|
|
->where('Id', $Id)
|
|
->update($save);
|
|
$insert_id = $this->db->affectedRows();
|
|
return $insert_id;
|
|
}
|
|
|
|
|
|
function GetEnquiryDetails()
|
|
{
|
|
$builder = $this->db->table('T_Enquiry')
|
|
->select('T_Enquiry.*,client_name')
|
|
->join('ip_clients', 'ip_clients.client_id=T_Enquiry.client_id')
|
|
->orderBy('Id', 'desc');
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function GetEnquiry($Id)
|
|
{
|
|
|
|
$builder = $this->db->table('T_Enquiry')
|
|
->select('T_Enquiry.*,client_name')
|
|
->join('ip_clients', 'ip_clients.client_id=T_Enquiry.client_id')
|
|
->where('Id', $Id)
|
|
->orderBy('Id', 'desc');
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
function GetEnquiryCount($createddt)
|
|
{
|
|
|
|
|
|
$builder = $this->db->table('T_Enquiry')
|
|
->select('count(Id) as Countnumber')
|
|
->where('Created_Date', $createddt);
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function SaveActionMaster($master)
|
|
{
|
|
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('T_ActionReport_Master');
|
|
$builder->insert($master);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
|
|
if ($insert_id > 0) {
|
|
$subQuery = 'select max(Id) as Id from T_ActionReport_Master';
|
|
|
|
$query = $this->db->query($subQuery, array());
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
}
|
|
|
|
|
|
function SaveActionDisposition($actionsave)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('T_Action_Disposition');
|
|
$builder->insert($actionsave);
|
|
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
return $insert_id;
|
|
}
|
|
|
|
|
|
function UpdateActionDisposition($actionsave, $LineDisposition)
|
|
{
|
|
//echo $LineDisposition;
|
|
$this->db->table('T_Action_Disposition')
|
|
->where('DispositionId', $LineDisposition)
|
|
->update($actionsave);
|
|
return TRUE;
|
|
}
|
|
|
|
function UpdateRootCause($rootsave, $Lineroot)
|
|
{
|
|
$this->db->table('T_RootCause')
|
|
->where('RootId', $Lineroot)
|
|
->update($rootsave);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function Updatecounteraction($savecounter, $LineCounter)
|
|
{
|
|
$this->db->table('T_Action_Counter_Measure')
|
|
->where('CounterId', $LineCounter)
|
|
->update($savecounter);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function UpdateActionMaster($master, $Id)
|
|
{
|
|
$this->db->table('T_ActionReport_Master')
|
|
->where('Id', $Id)
|
|
->update($master);
|
|
$insert_id = $this->db->affectedRows();
|
|
//return TRUE;
|
|
if ($insert_id > 0) {
|
|
$subQuery = 'select max(Id) as Id from T_ActionReport_Master';
|
|
|
|
$query = $this->db->query($subQuery, array());
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function SaveRootCause($rootsave)
|
|
{
|
|
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('T_RootCause');
|
|
$builder->insert($rootsave);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
return $insert_id;
|
|
}
|
|
|
|
function Savecounteraction($savecounter)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('T_Action_Counter_Measure');
|
|
$builder->insert($savecounter);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
return $insert_id;
|
|
}
|
|
|
|
function GetNcrlist()
|
|
{
|
|
$builder = $this->db->table('t_complaintregister')->select('*')
|
|
->join('ip_clients', 'ip_clients.client_id=t_complaintregister.client_id')
|
|
->orderBy('CId', 'desc');
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function GetncrmasterDetails($Id)
|
|
{
|
|
|
|
$builder = $this->db->table('T_ActionReport_Master')->select('*')
|
|
->where('Id', $Id);
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function GetDispositionDetails($Id)
|
|
{
|
|
|
|
$builder = $this->db->table('T_Action_Disposition')->select('*')
|
|
->where('Id', $Id);
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
function GetRootcauseDetails($Id)
|
|
{
|
|
|
|
$builder = $this->db->table('T_RootCause')->select('*')
|
|
->where('Id', $Id);
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
function GetCouteractionDetails($Id)
|
|
{
|
|
|
|
$builder = $this->db->table('T_Action_Counter_Measure')->select('*')
|
|
->where('Id', $Id);
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
function Savecomplaint($save_complaint)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_complaintregister');
|
|
$builder->insert($save_complaint);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
return $insert_id;
|
|
}
|
|
|
|
|
|
function Get_SavedComplaint($CId)
|
|
{
|
|
|
|
$builder = $this->db->table('t_complaintregister')->select('*')
|
|
->join('ip_clients', 'ip_clients.client_id=t_complaintregister.client_id')
|
|
->where('CId', $CId)
|
|
->orderBy('CId', 'desc');
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
function Updatecomplaint($save_complaint, $CId)
|
|
{
|
|
$this->db->table('t_complaintregister')
|
|
->where('CId', $CId)
|
|
->update($save_complaint);
|
|
return TRUE;
|
|
}
|
|
|
|
function updatecomplaintId($up, $CId)
|
|
{
|
|
$this->db->table('t_complaintregister')
|
|
->where('CId', $CId)
|
|
->update($up);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function GetActionid($LineDisposition)
|
|
{
|
|
|
|
$builder = $this->db->table('T_Action_Disposition')
|
|
->select('*')
|
|
->where('DispositionId', $LineDisposition);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
function GetlastDispositionId()
|
|
{
|
|
$subQuery = 'select max(DispositionId) from T_Action_Disposition';
|
|
|
|
$query = $this->db->query($subQuery, array());
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
|
|
|
|
function Getrootid($Lineroot)
|
|
{
|
|
|
|
$builder = $this->db->table('T_RootCause')->select('*')
|
|
->where('RootId', $Lineroot);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
function Getcounterid($LineCounter)
|
|
{
|
|
|
|
$builder = $this->db->table('T_Action_Counter_Measure')->select('*')
|
|
->where('CounterId', $LineCounter);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function DeleteAction($DelId)
|
|
{
|
|
|
|
$this->db->table('T_Action_Disposition')->delete(['DispositionId' => $DelId]);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function DeleteRoot($DelId)
|
|
{
|
|
$this->db->table('T_RootCause')->delete(['RootId' => $DelId]);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function DeleteCounter($DelId)
|
|
{
|
|
$this->db->table('T_Action_Counter_Measure')->delete(['CounterId' => $DelId]);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
/*------------------------------------------------------------------------------*/
|
|
|
|
function updatefile($bill, $Picture)
|
|
{
|
|
|
|
$uploadfile=[];
|
|
$this->db->table('t_purchaseorder_billupload')
|
|
->set('FilePath', $Picture)
|
|
->where('BillNo', $bill)
|
|
->update();
|
|
|
|
$uploadfile['afftectedRows'] = $this->db->affectedRows();
|
|
|
|
if( $uploadfile['afftectedRows'] > 0){
|
|
$uploadfile['updatedRow'] = $this->db->table('t_purchaseorder_billupload')
|
|
->where('BillNo', $bill)
|
|
->get()
|
|
->getRowArray();
|
|
|
|
}
|
|
return $uploadfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getBillFile($PONO){
|
|
$builder = $this->db->table('t_purchaseorder_billupload')->select('*')
|
|
->where('PONO', $PONO);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
function insertlogpo($logpo)
|
|
{
|
|
|
|
// $this->db->table('T_ponewlogs_Details')
|
|
// ->where('MaterialCode',$MaterialCode,'LineItemNos',$POLineItemNo)
|
|
// ->update($logpo)
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_polog_details');
|
|
$builder->insert($logpo);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
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->getResult();
|
|
}
|
|
|
|
|
|
// function EditpoValues($pono)
|
|
// {
|
|
// ->select('*');
|
|
// $builder = $this->db->table('T_ponewlogs_Details');
|
|
// ->where('PONO',$pono);
|
|
// // ->where('MaterialCode',$materialcode);
|
|
// $query = $builder->get();
|
|
// return $query->getResultArray();
|
|
// }
|
|
|
|
|
|
function insertfile($filelist)
|
|
{
|
|
|
|
$builder = $this->db->table('t_purchaseorder_billupload');
|
|
$builder->insert($filelist);
|
|
$insertedID = $this->db->insertID();
|
|
$insertedRow = $builder->where('BillNo', $insertedID)->get()->getRowArray();
|
|
return $insertedRow;
|
|
}
|
|
|
|
/*------------------------------------------------------------------------------*/
|
|
|
|
function updateigrM($PONO, $IGRNo, $igrMaster)
|
|
{
|
|
|
|
//print_r($igrMaster);die;
|
|
$this->db->table('t_igr_master')
|
|
->where('PONO', $PONO)
|
|
->where('IGRNO', $IGRNo)
|
|
->update($igrMaster);
|
|
|
|
$r = $this->db->affectedRows();
|
|
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->getResultArray();
|
|
}
|
|
|
|
function VerifyWithSupplierForPendingPO($supplierid, $materialcode)
|
|
{
|
|
|
|
$subQuery = 'SELECT COUNT(t_purchaseorder_master.PONO) AS PO_count,GROUP_CONCAT(t_purchaseorder_master.PONO) AS PONO,t_purchaseorder_lineitem.MaterialCode
|
|
FROM t_purchaseorder_lineitem
|
|
LEFT JOIN t_purchaseorder_master ON t_purchaseorder_lineitem.PONO = t_purchaseorder_master .PONO
|
|
WHERE t_purchaseorder_master.SupplierID != ? AND t_purchaseorder_lineitem.MaterialCode = ? AND t_purchaseorder_master.Status = "ST014"
|
|
GROUP BY t_purchaseorder_lineitem.MaterialCode';
|
|
// -- and t_purchaseorder_master.Status != "ST026"
|
|
$query = $this->db->query($subQuery, array($supplierid, $materialcode));
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
function lastPONO()
|
|
{
|
|
$query = $this->db->table('t_purchaseorder_master')->select('PONO')->orderBy('PONO', 'DESC')->limit(1)->get();
|
|
$lastPONO = $query->getRow()->PONO;
|
|
return $lastPONO;
|
|
}
|
|
/*** ----------------------------- */
|
|
|
|
function deletePurchaseOrderFile($PONO){
|
|
|
|
$builder = $this->db->table('t_purchaseorder_master POMast')
|
|
->where('PONO',$PONO);
|
|
$result = $builder->update(['POFile' => NULL]);
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
function findPurchaseOrderFile($filename){
|
|
|
|
$builder = $this->db->table('t_purchaseorder_master POMast')
|
|
->where('POFile',$filename);
|
|
$query = $builder->get();
|
|
$result = $query->getRow();
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|