ria/application/models/inwardgateregister_model.php
2017-12-18 11:22:59 +05:30

197 lines
6.4 KiB
PHP

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class inwardgateregister_model extends CI_Model
{
/**
* To get the IGR details for listing
* @return array $result : result of the query
*/
function igrListing()
{
$this->db->select('igr.*,PO.DeliveryDate,sup.SupplierName');
$this->db->from('T_IGR_Master igr');
$this->db->join('T_PurchaseOrder_Master PO','igr.PONO = PO.PONO');
$this->db->join('T_SupplierDetailsN` sup','PO.SupplierID = sup.SupplierID');
$this->db->order_by('igr.CreatedDate','desc');
$query = $this->db->get();
$result = $query->result();
return $result;
}
/**
* To get the po details
* @return array $result : result of the query
*/
function getpurchaseorder()
{
$this->db->distinct();
$this->db->select('POM.PONO,POM.ServiceDescription,POM.DeliveryDate,sup.SupplierName,sup.Address,POM.status');
$this->db->from('T_PurchaseOrder_Master POM');
$this->db->join('T_PurchaseOrder_LineItem POL', 'POL.PONO = POM.PONO');
$this->db->join('T_SupplierDetailsN sup', 'POM.SupplierID = sup.SupplierID');
$this->db->where('POM.Status',PO_RELEASED);
$this->db->where('POM.POType !=',SERVICE);
$this->db->or_where('POM.Status',IGR_CREATED);
$this->db->or_where('POM.Status',MRIR_CREATED);
$this->db->or_where('POM.Status',MRIR_APPROVED);
$query = $this->db->get();
$result = $query->result();
return $result;
}
/**
* To get the po details for revalant Po
* @param number $PO : this is po number
* @return array $query->result() : result of the query
*/
function viewpurchaseorder($PO)
{
$subQuery ='SELECT distinct POM.PONO,POL.MaterialCode,POL.Quantity,POL.ReceivedQuantity,(POL.Quantity -POL.ReceivedQuantity ) as PendingQty,POL.PONO,MM.MaterialName,MM.UOM
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 where POM.PONO=? ';
$query = $this->db->query($subQuery, array($PO,IGR_CREATED));
return $query->result();
}
/**
* To store the igr master details
* @param array $igrM : This will have all igr master details
* @var number $insert_id :
* @return array $query->result() : result of the query
*/
function addigrM($igrM)
{
$this->db->trans_start();
$this->db->insert('T_IGR_Master', $igrM);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
if($insert_id>0)
{
$subQuery = 'select max(IGRNO) as IGRNO from T_IGR_Master';
$query = $this->db->query($subQuery);
return $query->result();
}
}
/**
* To store the igr child details
* @param array $igrD : This will have all igr child details
* @var number $insert_id :
* @return array $query->result() : result of the query
*/
function addigrD($igrD)
{
$this->db->trans_start();
$this->db->insert('T_IGR_Details', $igrD);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
if($insert_id>0)
{
$subQuery = 'select max(IGRItemNo) as IGRItemNo from T_IGR_Details';
$query = $this->db->query($subQuery);
return $query->result();
}
}
/**
* To get igr details for revalant IGRNO
* @param number $IGRNO : This is IGRNO
* @return array $result : result of the query
*/
function viewigr($IGRNO)
{
$this->db->distinct();
$this->db->select('igr.IGRNO,igr.*,igrd.*,MM.MaterialName,MM.UOM,sup.Address,sup.SupplierName,POM.ServiceDescription,POL.Quantity');
$this->db->select('igr.IGRNO,igr.*,igrd.*,MM.MaterialName,MM.UOM,sup.Address,sup.SupplierName,POM.ServiceDescription,POL.Quantity');
$this->db->from('T_IGR_Master igr');
$this->db->join('T_IGR_Details igrd','igrd.IGRNO = igr.IGRNO');
$this->db->join('T_PurchaseOrder_Master POM','igr.PONO = POM.PONO');
$this->db->join('T_PurchaseOrder_LineItem POL','igr.PONO = POL.PONO and POL.MaterialCode=igrd.MaterialCode ');
$this->db->join('T_SupplierDetailsN sup', 'sup.SupplierID = POM.SupplierID');
$this->db->join('T_MaterialMaster MM', 'MM.MaterialCode = igrd.MaterialCode');
$this->db->where('igr.IGRNO',$IGRNO);
$query = $this->db->get();
$result = $query->result();
return $result;
}
/**
* To store edited po lineitem details
* @param number $PONO : This is PONO
* @param number $MaterialCode : This material code
* @param array $Lineitem : This will have all edited po lineitem details
*/
function UpdatePOLineItem($LineItem,$PONO,$MaterialCode)
{
$this->db->where('PONO', $PONO);
$this->db->where('MaterialCode', $MaterialCode);
$this->db->update('T_PurchaseOrder_LineItem', $LineItem);
return TRUE;
}
/**
* To store edited po master details
* @param number $PONO : This is PONO
* @var array $POStatus : for updation operation : this will have igrcreated's const value and updater' id
* @param number $updatedBy : This is updater's id
* @param array $Lineitem : This will have all edited po lineitem details
*/
function UpdatePOMaster($PONO,$updatedBy)
{
$this->db->select('*');
$this->db->from('T_PurchaseOrder_LineItem');
$this->db->where('PONO',$PONO);
$this->db->where('Status !=',IGR_CREATED);
$query = $this->db->get();
if ($query->num_rows == 0) {
$this->db->where('PONO', $PONO);
$POStatus = array('status'=>IGR_CREATED,'UpdateBY'=>$updatedBy);
$this->db->update('T_PurchaseOrder_Master', $POStatus);
}
}
/**
* To get po lineitem details for recieved qty
* @param number $PONO : This is PONO
* @param number $MaterialCode : This is material code
* @return array $result : result of the query
*/
function getPOLineItemReceivedQty($PONO,$MaterialCode)
{
$this->db->select('ReceivedQuantity');
$this->db->from('T_PurchaseOrder_LineItem');
$this->db->where('PONO',$PONO);
$this->db->where('MaterialCode',$MaterialCode);
$query = $this->db->get();
$result = $query->result();
return $result;
}
}