1211 lines
40 KiB
PHP
Executable File
1211 lines
40 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class Inwardgateregister_model extends Model
|
|
{
|
|
|
|
function updatefile($bill, $Picture, $oldfile)
|
|
{
|
|
|
|
// if($oldfile != ''){
|
|
// //unlink("public/uploads/BillFiles/".$oldfile);//this deletes the file on particular folder too
|
|
// }
|
|
|
|
$this->db->table('t_inwardgateregister_fileupload')
|
|
->set('FilePath', $Picture)
|
|
->where('BillNo', $bill)
|
|
->update();
|
|
$afftectedRows = $this->db->affectedRows();
|
|
return $afftectedRows;
|
|
}
|
|
function getAdditionalIGRFile($igr){
|
|
$builder = $this->db->table('t_inwardgateregister_fileupload')->select('*')
|
|
->where('IGRNO', $igr);
|
|
$query = $builder->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
function uploadAdditionalFile($myfiles)
|
|
{
|
|
$builder = $this->db->table('t_inwardgateregister_fileupload');
|
|
$builder->insert($myfiles);
|
|
$aff = $this->db->affectedRows();
|
|
return $aff > 0 ? $this->db->insertID() : 0;
|
|
}
|
|
|
|
function deleteAdditionalFile($fileid)
|
|
{
|
|
$arr = array('Isactive' => 0);
|
|
$this->db->table('t_inwardgateregister_fileupload')
|
|
->where('BillNo', $fileid)
|
|
->update($arr);
|
|
$aff = $this->db->affectedRows();
|
|
return $aff > 0 ? true : false;
|
|
}
|
|
|
|
|
|
/*------------------------------------------------------------*/
|
|
function addMaterialStockHistory($MaterialstockHistoryadd)
|
|
{
|
|
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_material_stock_history');
|
|
$builder->insert($MaterialstockHistoryadd);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
|
|
//print_r($insert_id);
|
|
if ($insert_id > 0) {
|
|
$subQuery = 'select * from t_material_stock_history';
|
|
|
|
$query = $this->db->query($subQuery);
|
|
|
|
return $query->getResult();
|
|
}
|
|
}
|
|
|
|
/*------------------------------------------------------------*/
|
|
// function igrListing()
|
|
// {
|
|
// $builder = $this->db->table('t_igr_master igr')->select('igr.*,PO.DeliveryDate,sup.SupplierName,igr.file');
|
|
// ->join('t_purchaseorder_master PO','igr.PONO = PO.PONO');
|
|
// ->join('t_supplierdetailsn` sup','PO.SupplierID = sup.SupplierID');
|
|
// ->orderBy('igr.CreatedDate','desc');
|
|
// $query =$builder->get();
|
|
// $result = $query->getResult();
|
|
// return $result;
|
|
// }
|
|
function igrListing()
|
|
{
|
|
|
|
$builder = $this->db->table('t_igr_master igr')
|
|
->select('igr.*,PO.DeliveryDate,sup.SupplierName,fileup.FilePath,igr.file,PO.POType')
|
|
->join('t_purchaseorder_master PO', 'igr.PONO = PO.PONO')
|
|
->join('t_inwardgateregister_fileupload fileup', ' igr.IGRNO = fileup.IGRNO', 'left')
|
|
->join('t_supplierdetailsn` sup', 'PO.SupplierID = sup.SupplierID')
|
|
->orderBy('igr.IGRID','desc')
|
|
->groupBy('igr.IGRNO', 'desc');
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
|
|
|
|
|
|
function viewIGRFile($IGRNO)
|
|
{
|
|
$builder = $this->db->table('t_inwardgateregister_fileupload')
|
|
->distinct()->select('*') //BillNo,IGRNO,FilePath,PONO
|
|
->where('IGRNO', $IGRNO);
|
|
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
// print_r($result);die;
|
|
|
|
return $result;
|
|
}
|
|
|
|
function viewIGRFile1($IGRNO)
|
|
{
|
|
$builder = $this->db->table('t_igr_master igrm')
|
|
->distinct()->select('igrm.file,igrm.PONO as pono') //BillNo,IGRNO,FilePath,PONO
|
|
//->join('t_inwardgateregister_fileupload igrf','igrm.IGRNO = igrf.IGRNO','left')
|
|
//->join('t_igr_details igrd','igrm.IGRNO = igrd.IGRNO','left');
|
|
->where('igrm.IGRNO', $IGRNO);
|
|
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
// print_r($result);die;
|
|
|
|
return $result;
|
|
}
|
|
|
|
function getpurchaseorder()
|
|
{
|
|
|
|
$builder = $this->db->table('t_purchaseorder_master POM')
|
|
->distinct()->select('POM.PONO,POM.ServiceDescription,POM.DeliveryDate,sup.SupplierName,sup.Address,POM.status,OGR_Status,POM.PODate,POM.IsOpenOrder,POM.CreatedDate,POM.POType')
|
|
->select("IF(POM.PODate IS NOT NULL, DATE_FORMAT(POM.PODate, '%Y-%m-%d'), NULL) AS formatted_PODate")
|
|
->select("IF(POM.IsOpenOrder IS NULL OR POM.IsOpenOrder = '', 0, POM.IsOpenOrder) AS formatted_IsOpenOrder")
|
|
->join('t_purchaseorder_lineitem POL', 'POL.PONO = POM.PONO')
|
|
->join('t_supplierdetailsn sup', 'POM.SupplierID = sup.SupplierID')
|
|
->join('t_ogr_master OGM ', 'POM.PONO = OGM.PONO_INV', 'left')
|
|
// ->where('POM.POType !=', SERVICE) // due to client requirements - he wants to remove the conidition.
|
|
->where('POM.Status', PO_RELEASED)
|
|
->orWhere('POM.Status',REQITEM_Emergency_PO_CREATED)
|
|
->orWhere('POM.Status',IGR_CREATED)
|
|
->orWhere('POM.Status', IGR_DRAFT )
|
|
->where( 'POM.IsOpenOrder', 1)
|
|
->orWhere('POM.Status', MRIR_CREATED)
|
|
->orWhere('POM.Status', MRIR_APPROVED)
|
|
->orWhere('POM.Status', OGR_COMPLETE)
|
|
->orderBy('POM.CreatedDate', 'desc');
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
// echo $this->db->getLastQuery()->getQuery(); die;
|
|
|
|
return $result;
|
|
}
|
|
function checkdrivername($dr)
|
|
{
|
|
$temp[] = '';
|
|
$builder = $this->db->table('t_igr_master')
|
|
->distinct()
|
|
->select('DriverName')
|
|
->like('DriverName', $dr);
|
|
$query = $builder->get();
|
|
|
|
$temparr[] = '';
|
|
foreach ($query->getResult() as $arr) {
|
|
$temparr[] = $arr->DriverName;
|
|
}
|
|
$temp['suggestions'] = $temparr;
|
|
|
|
return $temp;
|
|
}
|
|
|
|
public function checkdriverMobile($mobile,$driverName) {
|
|
$builder = $this->db->table('t_igr_master')
|
|
->distinct()
|
|
->select('DriverMobileNumber')
|
|
->like('DriverMobileNumber', $mobile);
|
|
if($driverName){
|
|
$builder->where('DriverName', $driverName);
|
|
}
|
|
|
|
|
|
$query = $builder->get();
|
|
$temparr[] = '';
|
|
foreach ($query->getResult() as $arr) {
|
|
$temparr[] = $arr->DriverMobileNumber;
|
|
}
|
|
// echo $this->db->getLastQuery()->getQuery();die;
|
|
$temp['suggestions'] = $temparr;
|
|
|
|
return $temp;
|
|
}
|
|
|
|
function viewpurchaseorder($PO)
|
|
{
|
|
|
|
$subQuery = 'SELECT distinct POM.PONO, POL.MaterialCode, POL.Quantity, POL.ReceivedQuantity, (POL.Quantity - POL.ReceivedQuantity) as PendingQty, QuantityRejected, POL.PONO, MM.MaterialName, MM.UOM,POL.Rate
|
|
FROM t_purchaseorder_master POM
|
|
LEFT JOIN t_purchaseorder_lineitem POL ON POL.PONO = POM.PONO
|
|
LEFT JOIN t_igr_master IGM ON IGM.PONO = POL.PONO
|
|
LEFT JOIN t_igr_details igr ON igr.MaterialCode = POL.MaterialCode AND IGM.PONO = POL.PONO
|
|
LEFT JOIN t_materialmaster MM ON MM.MaterialCode = POL.MaterialCode
|
|
LEFT JOIN t_mrir_master MRM ON POM.PONO = MRM.PONO
|
|
LEFT JOIN t_mrir_details MRD ON MRM.MRIRNO = MRD.MRIRNO AND POL.MaterialCode = MRD.MaterialCode
|
|
WHERE POM.PONO = ? GROUP BY POL.MaterialCode';
|
|
|
|
$query = $this->db->query($subQuery, [$PO]);
|
|
|
|
|
|
return $query->getResult();
|
|
|
|
/*
|
|
$builder = $this->db->table('t_purchaseorder_master POM')
|
|
->select('POM.PONO,POL.MaterialCode,POL.Quantity,POL.PONO,MM.MaterialName,MM.UOM')
|
|
->join('t_purchaseorder_lineitem POL', 'POL.PONO = POM.PONO','left')
|
|
->join('t_materialmaster MM', 'MM.MaterialCode = POL.MaterialCode','left')
|
|
->where('POM.PONO',$PO )
|
|
->where('POL.Status !=',POLINEITEM_IGR_CREATED );
|
|
$query =$builder->get();
|
|
$result = $query->getResult();
|
|
return $result; */
|
|
}
|
|
|
|
public function igr_history($hsty_arr) {
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_igr_history');
|
|
$builder->insert($hsty_arr);
|
|
$this->db->transComplete();
|
|
if ($this->db->transStatus() === FALSE) {
|
|
return false;
|
|
} else {
|
|
return $this->db->insertID();
|
|
}
|
|
}
|
|
|
|
function get_igr_history($col,$IGR,$IGRITEM = null)
|
|
{
|
|
|
|
$builder = $this->db->table('t_igr_history Hist')
|
|
->select("Hist.*");
|
|
$builder->where('Hist.field', $col);
|
|
if($IGR){
|
|
$builder->where('Hist.IGR_No', $IGR);
|
|
}
|
|
if ($IGRITEM !== null) {
|
|
$builder->where('Hist.IGRItem_No', $IGRITEM);
|
|
}
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
return $result;
|
|
// $result = $model->get_igr_history('001');
|
|
// $result = $model->get_igr_history('001', 1);
|
|
|
|
}
|
|
|
|
function addigrM($igrM)
|
|
{
|
|
// print_r($igrM);die;
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_igr_master');
|
|
$builder->insert($igrM);
|
|
$YesIAmAffected = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
|
|
$result = [];
|
|
if ($YesIAmAffected > 0) {
|
|
$result = $this->db->table('t_igr_master')
|
|
->select('IGRNO')
|
|
->orderBy('CreatedDate', 'desc')
|
|
->get()
|
|
->getRow();
|
|
// $result->IGRNO;
|
|
}
|
|
|
|
$igrno = ($YesIAmAffected && !empty($result)) ? $result->IGRNO : '';
|
|
return $igrno;
|
|
}
|
|
|
|
function addigrD($igrD)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_igr_details');
|
|
$builder->insert($igrD);
|
|
$aff_row = $this->db->affectedRows();
|
|
log_message('error', 'addigrD Query: ' . $this->db->getLastQuery()->getQuery());
|
|
$this->db->transComplete();
|
|
|
|
$result = $this->db->table('t_igr_details')
|
|
->select('IGRItemNo')
|
|
->orderBy('CreatedDate', 'desc')
|
|
->get()
|
|
->getRow();
|
|
|
|
$res = ($aff_row > 0) ? $result->IGRItemNo : 0;
|
|
return $res;
|
|
}
|
|
|
|
|
|
|
|
function addmaterialhistory($historydetails)
|
|
{
|
|
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_material_stock_history');
|
|
$builder->insert($historydetails);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
function addmaterialmaster($current_qty, $MaterialCode)
|
|
{
|
|
$this->db->table('t_materialmaster')
|
|
->where('MaterialCode', $MaterialCode)
|
|
->update($current_qty);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function get_CurrentQty($MaterialCode)
|
|
{
|
|
|
|
$builder = $this->db->table('t_materialmaster')->select('Current_stock')
|
|
->where('t_materialmaster.MaterialCode', $MaterialCode);
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
|
|
|
|
function getitemvalue($pono, $MaterialCode)
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_lineitem')->select('Rate,SupplierID')
|
|
->join('t_purchaseorder_master', 't_purchaseorder_master.PONO=t_purchaseorder_lineitem.PONO')
|
|
->where('t_purchaseorder_lineitem.PONO', $pono)
|
|
->where('MaterialCode', $MaterialCode);
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
function ViewigrListing_old()
|
|
{
|
|
|
|
// $builder = $this->db->table('t_igr_master igr')
|
|
// ->select('igr.*,PO.IsOpenOrder,PO.DeliveryDate,sup.SupplierName,PO.POType,trans.name as TransporterName')
|
|
// ->join('t_purchaseorder_master PO', 'igr.PONO = PO.PONO')
|
|
// ->join('t_supplierdetailsn` sup', 'PO.SupplierID = sup.SupplierID')
|
|
// ->join('t_transporter` trans', 'igr.TransporterId = trans.id' , 'left')
|
|
// ->where('igr.IGRStatus !=', MRIR_CREATED)
|
|
// ->orderBy('igr.CreatedDate', 'desc');
|
|
|
|
$builder = $this->db->table('t_igr_details igr_details')
|
|
->select('igr.*,PO.IsOpenOrder,PO.DeliveryDate,sup.SupplierName,PO.POType,trans.name as TransporterName,item.MaterialName, igr_details.QuantityAsPerInvoice as ReceivedQuantity , igr_details.NetWeight as NetWeight')
|
|
->join('t_igr_master igr', 'igr_details.IGRNo = igr.IGRNo')
|
|
->join('t_purchaseorder_master PO', 'igr.PONO = PO.PONO')
|
|
->join('t_supplierdetailsn` sup', 'PO.SupplierID = sup.SupplierID')
|
|
->join('t_transporter` trans', 'igr.TransporterId = trans.id' , 'left')
|
|
->join('t_materialmaster` item', 'igr_details.MaterialCode = item.MaterialCode' , 'left')
|
|
->where('igr.IGRStatus !=', MRIR_CREATED)
|
|
->orderBy('igr.CreatedDate', 'desc');
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
|
|
|
|
|
|
// echo $this->db->getLastQuery()->getQuery();die;
|
|
return $result;
|
|
}
|
|
|
|
function ViewigrListing($fromDate,$toDate)
|
|
{
|
|
$subQuery1 = $this->db->table('t_igr_remarkes')
|
|
->select('COUNT(id)')
|
|
->where('igr_no = igr.IGRNo')
|
|
->getCompiledSelect();
|
|
|
|
// Build subQuery2 dynamically for rate and tax based on POType
|
|
$subQuery2 = "(CASE
|
|
WHEN PO.POType = 'revenue' THEN (
|
|
SELECT JSON_OBJECT('total_rate', SUM(POL.Rate), 'total_tax', AVG(tax.CGST + tax.SGST + tax.IGST))
|
|
FROM t_igr_details IGRD
|
|
LEFT JOIN t_purchaseorder_lineitem POL ON PONO = POL.PONO AND IGRD.MaterialCode = POL.MaterialCode
|
|
LEFT JOIN t_revenue_tax tax ON tax.LineItemNo = POL.LineItemNo
|
|
WHERE IGRD.IGRNO = igr.IGRNO
|
|
)
|
|
WHEN PO.POType = 'service' THEN (
|
|
SELECT JSON_OBJECT('total_rate', SUM(POL.Rate), 'total_tax', AVG(tax.CGST + tax.SGST + tax.IGST))
|
|
FROM t_igr_details IGRD
|
|
LEFT JOIN t_purchaseorder_lineitem POL ON PONO = POL.PONO AND IGRD.MaterialCode = POL.MaterialCode
|
|
LEFT JOIN t_service_tax tax ON tax.LineItemNo = POL.LineItemNo
|
|
WHERE IGRD.IGRNO = igr.IGRNO
|
|
)
|
|
|
|
ELSE NULL
|
|
END)";
|
|
|
|
|
|
// Main query
|
|
$builder = $this->db->table('t_igr_master igr')
|
|
->select("igr.*, PO.IsOpenOrder, PO.DeliveryDate, sup.SupplierName, PO.POType,
|
|
trans.name as TransporterName,
|
|
SUM(IGRD.QuantityAsPerInvoice) as ReceivedQuantity,
|
|
SUM(IGRD.NetWeight) as NetWeight,
|
|
COUNT(IGRD.IGRNo) as itemCount,
|
|
COALESCE(($subQuery1), 0) as remark_count,
|
|
JSON_EXTRACT(($subQuery2), '$.total_rate') as total_rate,
|
|
JSON_EXTRACT(($subQuery2), '$.total_tax') as total_tax")
|
|
->join('t_purchaseorder_master PO', 'igr.PONO = PO.PONO')
|
|
->join('t_supplierdetailsn sup', 'PO.SupplierID = sup.SupplierID')
|
|
->join('t_transporter trans', 'igr.TransporterId = trans.id', 'left')
|
|
->join('t_igr_details IGRD', 'igr.IGRNo = IGRD.IGRNo')
|
|
->where('igr.IGRStatus !=', MRIR_CREATED)
|
|
->where('Date(igr.CreatedDate) >=', "$fromDate")
|
|
->where('Date(igr.CreatedDate) <=', "$toDate")
|
|
->groupBy('IGRD.IGRNo')
|
|
->orderBy('igr.CreatedDate', 'desc');
|
|
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
|
|
|
|
// echo $this->db->getLastQuery()->getQuery();die;
|
|
// dd($result);
|
|
|
|
|
|
// old - issue in t_igr_remarkes join
|
|
// $builder = $this->db->table('t_igr_master igr')
|
|
// ->select('igr.*,PO.IsOpenOrder,PO.DeliveryDate,sup.SupplierName,PO.POType,trans.name as TransporterName , SUM(IGRD.QuantityAsPerInvoice) as ReceivedQuantity, SUM(IGRD.NetWeight) as NetWeight , count(IGRD.IGRNo) as itemCount , count(remark.id) as remark_count')
|
|
// ->join('t_purchaseorder_master PO', 'igr.PONO = PO.PONO')
|
|
// ->join('t_supplierdetailsn sup', 'PO.SupplierID = sup.SupplierID')
|
|
// ->join('t_transporter trans', 'igr.TransporterId = trans.id' , 'left')
|
|
// ->join('t_igr_details IGRD', 'igr.IGRNo = IGRD.IGRNo')
|
|
// ->join('t_igr_remarkes remark', 'igr.IGRNo = remark.igr_no', 'left')
|
|
// ->where('igr.IGRStatus !=', MRIR_CREATED)
|
|
// ->where('Date(igr.CreatedDate) >=',"$fromDate")
|
|
// ->where('Date(igr.CreatedDate) <=', "$toDate")
|
|
// ->where('igr.IGRNo', "IGRNO-1627")
|
|
// ->groupBy('IGRD.IGRNo')
|
|
// ->orderBy('igr.CreatedDate', 'desc');
|
|
// $query = $builder->get();
|
|
// $result = $query->getResult();
|
|
|
|
|
|
|
|
|
|
// $builder2 = $this->db->table('t_igr_details igr_details')
|
|
// ->select('igr.*,PO.IsOpenOrder,PO.DeliveryDate,sup.SupplierName,PO.POType,trans.name as TransporterName,item.MaterialName, igr_details.QuantityAsPerInvoice as ReceivedQuantity , igr_details.NetWeight as NetWeight')
|
|
// ->join('t_igr_master igr', 'igr_details.IGRNo = igr.IGRNo')
|
|
// ->join('t_purchaseorder_master PO', 'igr.PONO = PO.PONO')
|
|
// ->join('t_supplierdetailsn sup', 'PO.SupplierID = sup.SupplierID')
|
|
// ->join('t_transporter trans', 'igr.TransporterId = trans.id' , 'left')
|
|
// ->join('t_materialmaster` item', 'igr_details.MaterialCode = item.MaterialCode' , 'left')
|
|
// ->where('igr.IGRStatus !=', MRIR_CREATED)
|
|
// ->orderBy('igr.CreatedDate', 'desc');
|
|
// $query2 = $builder2->get();
|
|
// $result2 = $query2->getResult();
|
|
// echo $this->db->getLastQuery()->getQuery();die;
|
|
return [$result,[]];
|
|
}
|
|
|
|
|
|
function customViewigrListing($fromDate,$toDate)
|
|
{
|
|
|
|
$builder = $this->db->table('t_igr_master igr')
|
|
->select('igr.*,PO.IsOpenOrder,PO.DeliveryDate,sup.SupplierName,PO.POType,trans.name as TransporterName , SUM(IGRD.QuantityAsPerInvoice) as ReceivedQuantity, SUM(IGRD.NetWeight) as NetWeight , count(IGRD.IGRNo) as itemCount')
|
|
->join('t_purchaseorder_master PO', 'igr.PONO = PO.PONO')
|
|
->join('t_supplierdetailsn sup', 'PO.SupplierID = sup.SupplierID')
|
|
->join('t_transporter trans', 'igr.TransporterId = trans.id' , 'left')
|
|
->join('t_igr_details IGRD', 'igr.IGRNo = IGRD.IGRNo')
|
|
->where('igr.IGRStatus !=', MRIR_CREATED)
|
|
->groupStart()
|
|
->where('Date(igr.CreatedDate) >=', $fromDate)
|
|
->orWhere('Date(igr.UpdatedOn) >=', $fromDate)
|
|
->groupEnd()
|
|
->groupStart()
|
|
->where('Date(igr.CreatedDate) <=', $toDate)
|
|
->orWhere('Date(igr.UpdatedOn) <=', $toDate)
|
|
->groupEnd()
|
|
->groupBy('igr.IGRNo')
|
|
->orderBy('igr.CreatedDate', 'desc');
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
|
|
$builder2 = $this->db->table('t_igr_details igr_details')
|
|
->select('igr.*,PO.IsOpenOrder,PO.DeliveryDate,sup.SupplierName,PO.POType,trans.name as TransporterName,item.MaterialName, igr_details.QuantityAsPerInvoice as ReceivedQuantity , igr_details.NetWeight as NetWeight')
|
|
->join('t_igr_master igr', 'igr_details.IGRNo = igr.IGRNo')
|
|
->join('t_purchaseorder_master PO', 'igr.PONO = PO.PONO')
|
|
->join('t_supplierdetailsn sup', 'PO.SupplierID = sup.SupplierID')
|
|
->join('t_transporter trans', 'igr.TransporterId = trans.id' , 'left')
|
|
->join('t_materialmaster` item', 'igr_details.MaterialCode = item.MaterialCode' , 'left')
|
|
->where('igr.IGRStatus !=', MRIR_CREATED)
|
|
->orderBy('igr.CreatedDate', 'desc');
|
|
$query2 = $builder2->get();
|
|
$result2 = $query2->getResult();
|
|
// echo $this->db->getLastQuery()->getQuery();die;
|
|
return [$result,$result2];
|
|
}
|
|
|
|
|
|
|
|
function viewigr($IGRNO)
|
|
{
|
|
// ->select('igr.IGRNO','igr.PONO','igr.DeliveryChellanOrInvoiceNo','igr.DeliveryChellanDate','igr.MaterialRcvdDate','igr.VehicleNo','igr.CourierNo','igr.Remarks','igr.IGRStatus','igr.CreatedDate','igr.CreatedBy','igr.UpdateBY','igr.UpdatedOn','igr.file','igr.Paymentstatus','igr.DriverName','igr.DriverMobileNumber','igr.NetWeight','igr.GrossWeight','igr.TareWeight','igr.GrossWeightDate','igr.TareWeightDate')
|
|
// ->select('igrd.IGRItemNo','igrd.IGRNO','igrd.MaterialCode','igrd.QuantityAsPerInvoice')
|
|
// ->select('igrd.Remarks','igrd.IGRItemStatus','igrd.CancelNote','igrd.BankStatus')
|
|
// ->select('MM.MaterialName,MM.UOM,sup.Address,sup.SupplierName,POM.ServiceDescription,POL.Quantity,POM.POType')
|
|
|
|
$builder = $this->db->table('t_igr_master igr')
|
|
->distinct()
|
|
->select('igr.IGRNO,igr.*,igrd.*,MM.MaterialName,MM.UOM,sup.Address,sup.SupplierName,POM.ServiceDescription,POL.Quantity,POL.Rate,POM.POType,POM.IsOpenOrder')
|
|
->join('t_igr_details igrd', 'igrd.IGRNO = igr.IGRNO')
|
|
->join('t_purchaseorder_master POM', 'igr.PONO = POM.PONO')
|
|
->join('t_purchaseorder_lineitem POL', 'igr.PONO = POL.PONO and POL.MaterialCode=igrd.MaterialCode ')
|
|
->join('t_supplierdetailsn sup', 'sup.SupplierID = POM.SupplierID')
|
|
->join('t_materialmaster MM', 'MM.MaterialCode = igrd.MaterialCode')
|
|
->where('igr.IGRNO', $IGRNO);
|
|
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
// echo $this->db->getLastQuery()->getQuery();
|
|
// echo $this->db->getLastQuery()->getQuery();die;
|
|
return $result;
|
|
}
|
|
|
|
function UpdatePOLineItem($LineItem, $PONO, $MaterialCode)
|
|
{
|
|
$this->db->table('t_purchaseorder_lineitem')
|
|
->where('PONO', $PONO)
|
|
->where('MaterialCode', $MaterialCode)
|
|
->update($LineItem);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function UpdateMRIROUTQty($mrirarray, $MRIRNO, $MaterialCode)
|
|
{
|
|
$this->db->table('t_mrir_details')
|
|
->where('MaterialCode', $MaterialCode)
|
|
->update($mrirarray);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function UpdatePOMasterOGRStatus($pono, $POMasterStatuss)
|
|
{
|
|
$this->db->table('t_purchaseorder_master')
|
|
->where('PONO', $pono)
|
|
->update($POMasterStatuss);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function update_OGR($PONO, $status)
|
|
{
|
|
|
|
$builder = $this->db->table('t_ogr_master')->select('*')
|
|
->where('PONO_INV', $PONO);
|
|
$query = $builder->get();
|
|
|
|
if ($query->getNumRows() != 0) {
|
|
|
|
$ogrstatus = array('Status' => $status);
|
|
$this->db->table('t_ogr_master')
|
|
->where('PONO_INV', $PONO)
|
|
->update($ogrstatus);
|
|
}
|
|
}
|
|
|
|
function UpdatePOMaster($PONO, $updatedBy,$IGRStatus)
|
|
{
|
|
|
|
$builder = $this->db->table('t_purchaseorder_lineitem')->select('*')
|
|
->where('PONO', $PONO)
|
|
->where('Status !=', IGR_CREATED);
|
|
|
|
$query = $builder->get();
|
|
|
|
|
|
if ($query->getNumRows() == 0) {
|
|
$POStatus = array('status' => $IGRStatus, 'UpdateBY' => $updatedBy);
|
|
$this->db->table('t_purchaseorder_master')
|
|
->where('PONO', $PONO)
|
|
->update($POStatus);
|
|
}
|
|
}
|
|
|
|
function UpdateOGRMasterOGRStatus($OGRNO)
|
|
{
|
|
|
|
$builder = $this->db->table('t_ogr_details')->select('*')
|
|
->where('OGRNO', $OGRNO)
|
|
->where('Status !=', OGR_PARTIAL_COMPLETE);
|
|
|
|
$query = $builder->get();
|
|
|
|
$OGRStatus = ($query->getNumRows() == 0) ? array('status' => OGR_PARTIAL_COMPLETE) : array('status' => OGR_COMPLETE);
|
|
|
|
$this->db->table('t_ogr_master')
|
|
->where('OGRNO', $OGRNO)
|
|
->update($OGRStatus);
|
|
}
|
|
|
|
|
|
function UpdateMRIRMasterOGRStatus($MRIRNO, $OGRNO)
|
|
{
|
|
|
|
$builder = $this->db->table('t_ogr_details')->select('*')
|
|
->where('OGRNO', $OGRNO)
|
|
->where('Status !=', OGR_PARTIAL_COMPLETE);
|
|
|
|
$query = $builder->get();
|
|
|
|
$OGRStatus = ($query->getNumRows() == 0) ? array('OGRstatus' => OGR_PARTIAL_COMPLETE) : array('OGRstatus' => OGR_COMPLETE);
|
|
$this->db->table('t_mrir_master')
|
|
->where('MRIRNO', $MRIRNO)
|
|
->update($OGRStatus);
|
|
}
|
|
|
|
|
|
|
|
function updateogrpomaster($pono)
|
|
{
|
|
|
|
$builder = $this->db->table('t_purchaseorder_lineitem')->select('*')
|
|
->where('PONO', $pono)
|
|
->where('OGR_Status !=', 'ST064');
|
|
|
|
$query = $builder->get();
|
|
|
|
$POStatus = ($query->getNumRows() == 0) ?? array('status' => 'ST063');
|
|
$this->db->table('t_purchaseorder_master')
|
|
->where('PONO', $pono)
|
|
->update($POStatus);
|
|
}
|
|
|
|
|
|
|
|
function getPOLineItemReceivedQty($PONO, $MaterialCode)
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_lineitem')->select('ReceivedQuantity')
|
|
->where('PONO', $PONO)
|
|
->where('MaterialCode', $MaterialCode);
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
|
|
|
|
function GetMRIROutQty($MRIRNO, $MaterialCode)
|
|
{
|
|
|
|
$builder = $this->db->table('t_mrir_details')->select('Ogr_Out_Qty')
|
|
->where('MRIRNO', $MRIRNO)
|
|
->where('MaterialCode', $MaterialCode);
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
|
|
|
|
function getCustomer()
|
|
{
|
|
$subQuery = 'select client_id,client_name from ip_clients';
|
|
$query = $this->db->query($subQuery);
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function getSupplier()
|
|
{
|
|
$subQuery = 'select SupplierID,SupplierName from t_supplierdetailsn';
|
|
$query = $this->db->query($subQuery);
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function getstoredmaterialcode()
|
|
{
|
|
$subQuery = 'select MaterialCode,MaterialName from t_materialmaster';
|
|
$query = $this->db->query($subQuery);
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
function getOGRData()
|
|
{
|
|
$builder = $this->db->table('t_ogr_master')
|
|
->select('t_ogr_master.*,t_ogr_details.*,t_supplierdetailsn.SupplierName,sup.SupplierName as Servicesupplier')
|
|
->join('t_ogr_details', 't_ogr_details.OGRNO=t_ogr_master.OGRNO')
|
|
->join('t_purchaseorder_master', 't_purchaseorder_master.PONO=t_ogr_master.PONO_INV', 'left')
|
|
->join('t_supplierdetailsn', 't_supplierdetailsn.SupplierID=t_purchaseorder_master.SupplierID', 'left')
|
|
->join('t_supplierdetailsn sup', 'sup.SupplierID=t_ogr_details.SupplierID', 'left')
|
|
->groupBy('t_ogr_master.OGRNO');
|
|
//$this->db->where();
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
|
|
|
|
function getOGRDataforedit($OGRNO)
|
|
{
|
|
|
|
$builder = $this->db->table('t_ogr_master')
|
|
->select('t_ogr_master.*,t_supplierdetailsn.SupplierName,t_ogr_details.*,sup.SupplierName as ServiceSupname,t_materialmaster.MaterialName as Matname,Remark')
|
|
->join('t_ogr_details', 't_ogr_details.OGRNO=t_ogr_master.OGRNO')
|
|
->join('t_purchaseorder_master', 't_purchaseorder_master.PONO=t_ogr_master.PONO_INV', 'left')
|
|
->join('t_supplierdetailsn', 't_supplierdetailsn.SupplierID=t_purchaseorder_master.SupplierID', 'left')
|
|
->join('t_supplierdetailsn sup', 'sup.SupplierID=t_ogr_details.SupplierID', 'left')
|
|
->join('t_materialmaster', 't_materialmaster.MaterialCode=t_ogr_details.MaterialCode', 'left')
|
|
->where('t_ogr_master.OGRNO', $OGRNO);
|
|
//$this->db->groupBy('t_ogr_master.OGRNO');
|
|
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
|
|
|
|
|
|
function getOGRlineDataforedit($OGRNO, $MRIRNO)
|
|
{
|
|
|
|
$builder = $this->db->table('t_ogr_details')
|
|
->select('t_ogr_details.*,MaterialName,ActualQuantityReceived,Quantity,QuantityRejected')
|
|
->join('t_materialmaster', 't_materialmaster.MaterialCode=t_ogr_details.MaterialCode')
|
|
->join('t_ogr_master', 't_ogr_master.OGRNO=t_ogr_details.OGRNO')
|
|
->join('t_mrir_master', 't_mrir_master.PONO=t_ogr_master.PONO_INV', 'left')
|
|
->join('t_mrir_details', 't_mrir_details.MRIRNO=t_mrir_master.MRIRNO and t_mrir_details.MaterialCode=t_ogr_details.MaterialCode')
|
|
->join('t_purchaseorder_master', 't_purchaseorder_master.PONO=t_mrir_master.PONO')
|
|
->join('t_purchaseorder_lineitem', 't_purchaseorder_master.PONO=t_purchaseorder_lineitem.PONO and t_ogr_details.MaterialCode=t_purchaseorder_lineitem.MaterialCode')
|
|
->where('t_ogr_details.OGRNO', $OGRNO)
|
|
->where('t_mrir_details.MRIRNO', $MRIRNO)
|
|
->groupBy('t_ogr_details.MaterialCode');
|
|
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
|
|
function getInvoice($CustomerId)
|
|
{
|
|
|
|
$builder = $this->db->table('ip_invoices')->select('ip_invoices.invoice_id,invoice_number,item_product_id,item_name,item_quantity')
|
|
->join('ip_invoice_items', 'ip_invoice_items.invoice_id = ip_invoices.invoice_id')
|
|
->join('ip_clients', 'ip_invoices.client_id = ip_clients.client_id')
|
|
->where('ip_invoices.client_id', $CustomerId);
|
|
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
|
|
|
|
function getPOmrir($PONO)
|
|
{
|
|
|
|
$builder = $this->db->table('t_mrir_master')->select('MRIRNO')
|
|
->where('t_mrir_master.PONO', $PONO)
|
|
->where('t_mrir_master.OGRstatus !=', OGR_COMPLETE);
|
|
// ->where('Status !=',IGR_CREATED);
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
|
|
|
|
|
|
|
|
function getPO($supplierId)
|
|
{
|
|
|
|
/// echo $supplierId;
|
|
$subQuery = 'select t_purchaseorder_master.PONO from t_purchaseorder_master
|
|
join t_mrir_master on t_mrir_master.PONO= t_purchaseorder_master.PONO
|
|
where t_purchaseorder_master.SupplierID=? and (t_purchaseorder_master.Status=? or t_purchaseorder_master.Status=? or t_purchaseorder_master.Status=? or t_purchaseorder_master.Status=? or t_purchaseorder_master.Status=? or t_purchaseorder_master.Status=? or t_purchaseorder_master.Status=?) group by t_purchaseorder_master.PONO';
|
|
|
|
//$query= $this->db->query($subQuery, array($supplierId,ST044,PO,ST063));
|
|
$query = $this->db->query($subQuery, array($supplierId, ST044, PO, PO_RELEASED, IGR_CREATED, MRIR_CREATED, PARTIAL_MRIRAPPROVED, OGR_COMPLETE, OGR_PARTIAL_COMPLETE, OGR_CREATED));
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
function getPODetails($PONO)
|
|
{
|
|
|
|
$subQuery = 'select distinct t_purchaseorder_master.PONO,t_purchaseorder_lineitem.MaterialCode,
|
|
t_purchaseorder_lineitem.Quantity as Oqty,t_mrir_details.ActualQuantityReceived,
|
|
t_mrir_details.QuantityRejected,MaterialName,balance_Qty
|
|
from t_purchaseorder_master
|
|
join t_purchaseorder_lineitem on t_purchaseorder_lineitem.PONO = t_purchaseorder_master.PONO
|
|
join t_mrir_master on t_mrir_master.PONO = t_purchaseorder_master.PONO
|
|
join t_mrir_details on t_mrir_master.MRIRNO = t_mrir_details.MRIRNO and t_purchaseorder_lineitem.MaterialCode=t_mrir_details.MaterialCode
|
|
join t_materialmaster on t_mrir_details.MaterialCode=t_materialmaster.MaterialCode
|
|
left join t_ogr_master on t_purchaseorder_master.PONO=t_ogr_master.PONO_INV
|
|
left join t_ogr_details on t_ogr_master.OGRNO=t_ogr_details.OGRNO and t_purchaseorder_lineitem.MaterialCode= t_ogr_details.MaterialCode
|
|
where t_purchaseorder_master.PONO=?';
|
|
|
|
$query = $this->db->query($subQuery, array($PONO));
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
function getPOMRIRDetails($MRIRno, $PONO, $materialcode)
|
|
{
|
|
$subQuery = 'select t_mrir_details.MaterialCode,ActualQuantityReceived,QuantityAccepted,QuantityRejected,
|
|
MaterialName,Quantity as Oqty,SUM(Ogr_Out_Qty) as allowedQty
|
|
from t_mrir_details
|
|
join t_materialmaster on t_mrir_details.MaterialCode=t_materialmaster.MaterialCode
|
|
join t_mrir_master on t_mrir_details.MRIRNO = t_mrir_master.MRIRNO
|
|
join t_purchaseorder_lineitem on t_mrir_master.PONO = t_purchaseorder_lineitem.PONO and t_purchaseorder_lineitem.MaterialCode=t_mrir_details.MaterialCode
|
|
where t_mrir_details.MRIRNO=? and t_mrir_master.PONO=? and t_mrir_details.MaterialCode=? group by t_mrir_details.MaterialCode;';
|
|
$query = $this->db->query($subQuery, array($MRIRno, $PONO, $materialcode));
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function getPOMRIRMaterial($MRIRno, $PONO)
|
|
{
|
|
$builder = $this->db->table('t_mrir_details')
|
|
->select('MaterialCode')
|
|
->join('t_mrir_master', 't_mrir_master.MRIRNO=t_mrir_details.MRIRNO')
|
|
->where('t_mrir_details.MRIRNO', $MRIRno)
|
|
->where('PONO', $PONO)
|
|
->groupBy('t_mrir_details.MaterialCode');
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
|
|
|
|
function gettotalout($PONO, $materialcode)
|
|
{
|
|
$subQuery = 'select SUM(Ogr_Out_Qty)
|
|
from t_mrir_details
|
|
join t_mrir_master on t_mrir_master.MRIRNO= t_mrir_details.MRIRNO
|
|
where PONO =? and MaterialCode = ?; ';
|
|
|
|
$query = $this->db->query($subQuery, array($PONO, $materialcode));
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function getPOmaterialDetails($PONO, $materialcode)
|
|
{
|
|
$subQuery = 'select distinct t_purchaseorder_lineitem.MaterialCode,MaterialName,t_purchaseorder_lineitem.Quantity as Oqty,t_mrir_details.ActualQuantityReceived,t_mrir_details.QuantityRejected,balance_Qty
|
|
from t_purchaseorder_master
|
|
join t_purchaseorder_lineitem on t_purchaseorder_lineitem.PONO = t_purchaseorder_master.PONO
|
|
join t_mrir_master on t_mrir_master.PONO = t_purchaseorder_master.PONO
|
|
join t_mrir_details on t_mrir_master.MRIRNO = t_mrir_details.MRIRNO and t_purchaseorder_lineitem.MaterialCode=t_mrir_details.MaterialCode
|
|
join t_materialmaster on t_mrir_details.MaterialCode=t_materialmaster.MaterialCode
|
|
left join t_ogr_master on t_purchaseorder_master.PONO=t_ogr_master.PONO_INV
|
|
left join t_ogr_details on t_ogr_master.OGRNO=t_ogr_details.OGRNO and t_purchaseorder_lineitem.MaterialCode= t_ogr_details.MaterialCode
|
|
where t_purchaseorder_lineitem.PONO=? and t_purchaseorder_lineitem.MaterialCode=?';
|
|
$query = $this->db->query($subQuery, array($PONO, $materialcode));
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function getPOmaterial($PONO)
|
|
{
|
|
$subQuery = 'select MaterialCode from t_purchaseorder_lineitem where PONO=?';
|
|
|
|
$query = $this->db->query($subQuery, array($PONO));
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
function AddOGR($ogrmaster)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_ogr_master');
|
|
$builder->insert($ogrmaster);
|
|
$aff_row = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
|
|
if ($aff_row > 0) {
|
|
//$subQuery = 'select max(OGRNO) as OGRNO from t_ogr_master';
|
|
// $subQuery = 'select OGRNO from order by desc limit 1';
|
|
// $query = $this->db->query($subQuery);
|
|
// return $query->getResult();
|
|
$result = $this->db->table('t_ogr_master')
|
|
->select('OGRNO')
|
|
->orderBy('CreatedOn', 'desc')
|
|
->get()
|
|
->getRow();
|
|
|
|
$OGRNO = ($aff_row && $result !== null) ? $result->OGRNO : 0;
|
|
return $OGRNO;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
function getlastogrline()
|
|
{
|
|
//$subQuery = 'select max(OGRItemNO) as OGRItemNO from t_ogr_details';
|
|
$subQuery = 'select OGRItemNO from t_ogr_details order by CreatedOn desc limit 1';
|
|
|
|
$query = $this->db->query($subQuery);
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function UpdateOGR($updateogrmaster, $OGRNO)
|
|
{
|
|
$this->db->table('t_ogr_master')
|
|
->where('OGRNO', $OGRNO)
|
|
->update($updateogrmaster);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function AddOgrLine($Ogrline)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_ogr_details');
|
|
$builder->insert($Ogrline);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
return $insert_id;
|
|
}
|
|
|
|
|
|
// function GetIGR_Details($pono)
|
|
// {
|
|
//
|
|
// $builder = $this->db->table('ip_invoices')->select('IGRNO,MRIRNO,MaterialCode,')
|
|
// ->join('ip_invoice_items','ip_invoice_items.invoice_id = ip_invoices.invoice_id');
|
|
// ->join('ip_clients','ip_invoices.client_id = ip_clients.client_id');
|
|
// $this->db->where('ip_invoices.client_id',$CustomerId);
|
|
// $query =$builder->get();
|
|
//
|
|
// $result = $query->getResult();
|
|
// return $result;
|
|
// }
|
|
|
|
|
|
function GetPreSavedQty($pono, $MaterialCode)
|
|
{
|
|
// $subQuery = 'select Total_OutwardQty from t_purchaseorder_lineitem where PONO=? and MaterialCode=?';
|
|
// $query = $this->db->query($subQuery, array($pono,$MaterialCode));
|
|
//
|
|
// return $query->getResult();
|
|
|
|
|
|
$builder = $this->db->table('t_purchaseorder_lineitem')
|
|
->select('Total_OutwardQty')
|
|
->where('PONO', $pono)
|
|
->where('MaterialCode', $MaterialCode);
|
|
$query = $builder->get();
|
|
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
|
|
|
|
function check_PO($pono)
|
|
{
|
|
$subQuery = 'select * from t_ogr_master where PONO_INV=?';
|
|
$query = $this->db->query($subQuery, array($pono));
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function UpdatePOMasterOGR($postatus, $pono)
|
|
{
|
|
$this->db->table('t_purchaseorder_master')
|
|
->where('PONO', $pono)
|
|
//->where('MaterialCode', $MaterialCode)
|
|
->update($postatus);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
function updateigr($igrarr, $IGRNo)
|
|
{
|
|
$this->db->table('t_igr_master')
|
|
->where('IGRNO', $IGRNo)
|
|
//->where('MaterialCode', $MaterialCode)
|
|
->update($igrarr);
|
|
$r = $this->db->affectedRows();
|
|
return $r;
|
|
}
|
|
function updateIGRLineItem($igrlineitemarr, $IGRitemNo){
|
|
$this->db->table('t_igr_details')
|
|
->where('IGRItemNo', $IGRitemNo)
|
|
->update($igrlineitemarr);
|
|
$r = $this->db->affectedRows();
|
|
return $r;
|
|
}
|
|
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($PONO, $Newstatus)
|
|
{
|
|
$this->db->table('t_purchaseorder_lineitem')
|
|
->where('PONO', $PONO)
|
|
->update($Newstatus);
|
|
|
|
$update = $this->db->affectedRows();
|
|
return $update;
|
|
}
|
|
|
|
function pomasterupdatestatus($PONO, $Newstatus)
|
|
{
|
|
$this->db->table('t_purchaseorder_master')
|
|
->where('PONO', $PONO)
|
|
->update($Newstatus);
|
|
|
|
$update = $this->db->affectedRows();
|
|
return $update;
|
|
}
|
|
|
|
public function ViewIGRHistory($igr)
|
|
{
|
|
$builder = $this->db->table('t_igr_history');
|
|
|
|
$builder->select('t_igr_history.*, CONCAT_WS(" ", t_employee_details.FirstName, t_employee_details.LastName) AS FullName');
|
|
$builder->join('tbl_users', 'tbl_users.userId = t_igr_history.by', 'left');
|
|
$builder->join('t_employee_details', 'tbl_users.EmpID = t_employee_details.EmpID', 'left');
|
|
$builder->where('IGR_No', $igr);
|
|
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
return $result;
|
|
|
|
// Pass the result to the view or return it as JSON
|
|
// return $this->response->setJSON($result);
|
|
}
|
|
public function isFileExistsInIGRmaster($filename)
|
|
{
|
|
$result = $this->db->table('t_igr_master')->where('MasterFile', $filename);
|
|
$query = $result->get();
|
|
return $query->getResult();
|
|
}
|
|
public function isFileExistsInIGRdetails($filename)
|
|
{
|
|
$result = $this->db->table('t_igr_details')->where('WeightFile', $filename);
|
|
$query = $result->get();
|
|
return $query->getResult();
|
|
}
|
|
|
|
public function getCostCenterData($pono)
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_lineitem');
|
|
|
|
$builder->select('t_purchaseorder_lineitem.ReqNo,reqMaster.CostCenterCode,CSMaster.CostCenterName');
|
|
$builder->join('t_requestion_master reqMaster', 't_purchaseorder_lineitem.ReqNo = reqMaster.ReqNo', 'left');
|
|
$builder->join('t_costcenter_master CSMaster', 'reqMaster.CostCenterCode = CSMaster.CostCenterCode', 'left');
|
|
$builder->where('PONO', $pono);
|
|
$builder->groupBy('t_purchaseorder_lineitem.ReqNo');
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
return $result;
|
|
|
|
|
|
}
|
|
|
|
public function getAllIgrFileDetails($igrno)
|
|
{
|
|
|
|
// Query 1: Get FilePath and Remarks from t_inwardgateregister_fileupload
|
|
$builder1 = $this->db->table('t_inwardgateregister_fileupload IFU');
|
|
$query1 = $builder1->select('IFU.FilePath as file, IFU.Remarks as filename')
|
|
->where('IFU.IGRNO', $igrno)
|
|
->where('IFU.Isactive', 1)
|
|
->get();
|
|
$result1 = $query1->getResult();
|
|
|
|
// Query 2: Get MasterFile from t_igr_master
|
|
$builder2 = $this->db->table('t_igr_master IM');
|
|
$query2 = $builder2->select('IM.MasterFile as file, IM.MasterFile as filename')
|
|
->where('IM.IGRNO', $igrno)
|
|
->where('IM.MasterFile IS NOT NULL')
|
|
->get();
|
|
$result2 = $query2->getResult();
|
|
|
|
// Query 3: Get WeightFile from t_igr_details
|
|
$builder3 = $this->db->table('t_igr_details ID');
|
|
$query3 = $builder3->select('ID.WeightFile as file, ID.WeightFile as filename')
|
|
->where('ID.IGRNO', $igrno)
|
|
->where('ID.WeightFile IS NOT NULL')
|
|
->get();
|
|
$result3 = $query3->getResult();
|
|
|
|
// Merging results into a single array
|
|
$results = array_merge($result1, $result2, $result3);
|
|
|
|
return $results;
|
|
}
|
|
|
|
public function transporter()
|
|
{
|
|
$builder = $this->db->table('t_transporter t');
|
|
$query = $builder->select('t.*')->get();
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
|
|
public function findIgrDetailsForIncomingSilicaSand($materialCodes, $month ,$remark)
|
|
{
|
|
$builder = $this->db->table('t_igr_details')
|
|
->select(
|
|
't_igr_details.IGRNO,
|
|
t_igr_details.MaterialCode,
|
|
igrMast.DeliveryChellanOrInvoiceNo as invoiceNo,
|
|
igrMast.DeliveryChellanDate as invoiceDate,
|
|
igrMast.MaterialRcvdDate as materialRecievedDate,
|
|
igrMast.VehicleNo,
|
|
supplierDetails.SupplierName,
|
|
materialMaster.Category as sandType ,
|
|
t_igr_details.QuantityAsPerInvoice as Qty,
|
|
issd.*')
|
|
->whereIn('t_igr_details.MaterialCode', $materialCodes)
|
|
->like('t_igr_details.CreatedDate', $month, 'after');
|
|
|
|
// remark needed for those who selected any remark.
|
|
if ($remark != "noRemark") {
|
|
$builder->where('issd.remark', $remark);
|
|
}
|
|
|
|
$builder->groupBy('t_igr_details.IGRNO, t_igr_details.MaterialCode')
|
|
->join('t_igr_master igrMast', 'igrMast.IGRNO = t_igr_details.IGRNO')
|
|
->join('t_incomingSilicaSandDetails issd','issd.igrNo_fk = t_igr_details.IGRNO AND issd.materialCode = t_igr_details.MaterialCode','left')
|
|
->join('t_materialmaster materialMaster', 'materialMaster.MaterialCode = t_igr_details.MaterialCode')
|
|
->join('t_purchaseorder_master poMaster', 'poMaster.PONO = igrMast.PONO', 'left')
|
|
->join('t_supplierdetailsn supplierDetails', 'supplierDetails.SupplierID = poMaster.SupplierID', 'left')
|
|
->orderBy('t_igr_details.CreatedDate', 'asc ');
|
|
|
|
$query = $builder->get();
|
|
$result = $query->getResultArray();
|
|
|
|
return $result;
|
|
}
|
|
|
|
public function getDetailsforEmail($userId)
|
|
{
|
|
$query0 = $this->db->query("
|
|
SELECT CompanyName,EmailAddress
|
|
FROM t_company_details");
|
|
$company = $query0->getRow();
|
|
|
|
$query1 = $this->db->query("
|
|
SELECT CONCAT_WS(' ', t_employee_details.FirstName, t_employee_details.LastName) AS FullName
|
|
FROM tbl_users
|
|
LEFT JOIN t_employee_details ON tbl_users.EmpID = t_employee_details.EmpID
|
|
WHERE tbl_users.userId = ?", [$userId]
|
|
);
|
|
$fullName = $query1->getRow();
|
|
|
|
$query2 = $this->db->query("
|
|
SELECT email FROM tbl_users
|
|
WHERE isDeleted = 0 AND roleId = 2" // hardcoded because auditor role only. refer with gwm 29/01/2025
|
|
);
|
|
$emails = $query2->getResult();
|
|
|
|
return [
|
|
'from_mail' => $company ? $company->EmailAddress : null,
|
|
'full_name' => $fullName ? $fullName->FullName : null,
|
|
'company' => $company ? $company->CompanyName : null,
|
|
'emails' => $emails
|
|
];
|
|
}
|
|
|
|
public function getdriverlist()
|
|
{
|
|
|
|
$query = $this->db->query('SELECT DriverName,DriverMobileNumber
|
|
FROM t_igr_master
|
|
WHERE DriverName != ""
|
|
GROUP BY DriverName,DriverMobileNumber');
|
|
$result = $query->getResultArray();
|
|
return $result;
|
|
}
|
|
|
|
|
|
}
|