301 lines
8.7 KiB
PHP
Executable File
301 lines
8.7 KiB
PHP
Executable File
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
class rawmaterialdetails_model extends CI_Model
|
|
{
|
|
|
|
/**
|
|
* 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 rawmaterialListing()
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('T_MaterialMaster');
|
|
$this->db->where('IsActive',1 );
|
|
$query = $this->db->get();
|
|
$result = $query->result();
|
|
return $result;
|
|
}
|
|
|
|
function getUOM($UOM = '')
|
|
{
|
|
$ConfigID = 'C001';
|
|
$this->db->select('ConfigValue');
|
|
$this->db->from('T_ConfigDetails');
|
|
$this->db->where('Config_id ',$ConfigID );
|
|
if($UOM != '')
|
|
{
|
|
$this->db->where('ConfigValue !=',$UOM );
|
|
}
|
|
$query = $this->db->get();
|
|
|
|
return $query->result();
|
|
}
|
|
|
|
function getmaterialType($MaterialType = '')
|
|
{
|
|
$Config_ID = 'C003';
|
|
$this->db->select('Config_ID,ConfigValue');
|
|
$this->db->from('T_ConfigDetails');
|
|
$this->db->where('Config_id',$Config_ID );
|
|
if($MaterialType != '')
|
|
{
|
|
$this->db->where('ConfigValue !=',$MaterialType );
|
|
}
|
|
$query = $this->db->get();
|
|
|
|
return $query->result();
|
|
}
|
|
|
|
//This function used to get the material category using configdetails table
|
|
function getmaterialCategory($MaterialCategory = '')
|
|
{
|
|
$Config_ID = 'C023';
|
|
$this->db->select('Config_ID,ConfigValue');
|
|
$this->db->from('T_ConfigDetails');
|
|
$this->db->where('Config_id',$Config_ID );
|
|
if($MaterialCategory != '')
|
|
{
|
|
$this->db->where('ConfigValue !=',$MaterialCategory );
|
|
}
|
|
$query = $this->db->get();
|
|
|
|
return $query->result();
|
|
}
|
|
|
|
//This function used to get the conversionfactor using configdetails table
|
|
function getConversionfactorUOM($ConversionFactorUOM ='')
|
|
{
|
|
$Config_ID = 'C024';
|
|
$this->db->select('Config_ID,ConfigValue');
|
|
$this->db->from('T_ConfigDetails');
|
|
$this->db->where('Config_id',$Config_ID );
|
|
if($ConversionFactorUOM != '')
|
|
{
|
|
$this->db->where('ConfigValue !=',$ConversionFactorUOM );
|
|
}
|
|
$query = $this->db->get();
|
|
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
//AssetCode
|
|
/**
|
|
* This function used to get user information by id
|
|
* @param number $userId : This is user id
|
|
* @return array $result : This is user information
|
|
*/
|
|
|
|
|
|
function addNewRawMaterial($RawMaterial='')
|
|
{
|
|
|
|
$this->db->insert('T_MaterialMaster', $RawMaterial);
|
|
return TRUE;
|
|
}
|
|
|
|
function insertvalueintoconfig($config){
|
|
|
|
$this->db->insert('T_ConfigDetails', $config);
|
|
return TRUE;
|
|
}
|
|
|
|
/**
|
|
* This function used to get user information by id
|
|
* @param number $userId : This is user id
|
|
* @return array $result : This is user information
|
|
*/
|
|
function getMaterialDetails($MaterialCode)
|
|
{
|
|
|
|
|
|
$sql=" SELECT * FROM T_MaterialMaster WHERE MaterialCode ='$MaterialCode'";
|
|
$query = $this->db->query( $sql);
|
|
return $query->result();
|
|
|
|
|
|
}
|
|
|
|
|
|
function getMaterialstock($MaterialCode, $currentdate)
|
|
|
|
{
|
|
|
|
$dt = date('d',strtotime($currentdate));
|
|
$year = date('Y', strtotime($currentdate));
|
|
$month = date('m', strtotime($currentdate));
|
|
|
|
if($month<04)
|
|
{
|
|
//echo "b4finance";
|
|
$newyr = $year - 1;
|
|
$startdate = $newyr.'-'.'04'.'-'.'01';
|
|
// print_r( $startdate);die();
|
|
|
|
//echo $startdate;
|
|
}
|
|
|
|
else
|
|
{
|
|
//echo "after Finance";
|
|
$startdate = $year.'-'.'04'.'-'.'01';
|
|
// print_r( $startdate);die();
|
|
// echo $startdate;
|
|
}
|
|
|
|
$nedt= $dt+1;
|
|
|
|
$newdate=$year.'-'.$month.'-'.$nedt;
|
|
|
|
|
|
$subquery="SELECT SUM(IF(Transaction_type='Add',Quantity,0)) - SUM(IF(Transaction_type='Reduce',Quantity,0))as remainingqty
|
|
FROM T_Material_stock_history
|
|
WHERE MaterialCode=? AND CreatedOn >=? AND CreatedOn <=? ";
|
|
$query = $this->db->query($subquery,array($MaterialCode,$startdate,$newdate));
|
|
|
|
return $query->result_array();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAssetcode()
|
|
{
|
|
$this->db->select('AssetCode,AssetName');
|
|
$this->db->from('T_Asset_Details');
|
|
//$this->db->where('Assetcode',$Assetcode );
|
|
//$this->db->where('AssetCode',$Assetcode );
|
|
$query = $this->db->get();
|
|
return $query->result();
|
|
}
|
|
|
|
|
|
function getCostCenterCode()//$CostCenterCode='')
|
|
{
|
|
$this->db->select('CostCenterCode,CostCenterName');
|
|
$this->db->from('T_CostCenter_Master');
|
|
//$this->db->where('CostCenterCode', $CostCenterCode);
|
|
$query = $this->db->get();
|
|
return $query->result();
|
|
}
|
|
|
|
|
|
function editRawmaterial($RawMaterial, $MaterialCode)
|
|
{
|
|
|
|
$this->db->where('MaterialCode', $MaterialCode);
|
|
$this->db->update('T_MaterialMaster', $RawMaterial);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function viewrawmaterial($RawMaterial, $MaterialCode)
|
|
{
|
|
echo $MaterialCode; //."and".$RawMaterial ;
|
|
|
|
$this->db->where('MaterialCode', $MaterialCode);
|
|
$this->db->update('T_MaterialMaster', $RawMaterial);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
function export_excel(){
|
|
|
|
$this->db->select('det.*,emp.firstname,emp1.firstname as Updated_By,det.IsActive');
|
|
$this->db->join('tbl_users as tbl',' det.createdby = tbl.userid','left');
|
|
$this->db->join('T_Employee_Details as emp', 'emp.empid=tbl.empid','left');
|
|
$this->db->join('tbl_users as tbl1',' det.UpdatedBy = tbl1.userid','left');
|
|
$this->db->join('T_Employee_Details as emp1', 'emp1.empid=tbl1.empid','left');
|
|
return $this->db->get('T_MaterialMaster as det')->result_array();
|
|
}
|
|
|
|
/**
|
|
* This function is used to delete the user information
|
|
* @param number $userId : This is user id
|
|
* @return boolean $result : TRUE / FALSE*/
|
|
|
|
// function deletePO($PO, $POinfo)
|
|
// {
|
|
// $this->db->where('PO', $PO);
|
|
// $this->db->update('T_PurchaseOrderDetails', $POInfo);
|
|
// return $this->db->affected_rows();
|
|
// }
|
|
function checkMaterialExists($material)
|
|
{
|
|
// $sql="SELECT MaterialCode, MaterialName, MaterialType, Category,REPLACE(MaterialName, ' ', '')
|
|
// FROM T_MaterialMaster
|
|
// WHERE REPLACE(MaterialName, ' ', '') LIKE REPLACE('%'".$material."'%', ' ', '')";
|
|
|
|
$this->db->select('MaterialCode,MaterialName,MaterialType,Category');
|
|
$this->db->from('T_MaterialMaster');
|
|
$this->db->like('REPLACE(MaterialName, " ", "")',$material);
|
|
|
|
$query = $this->db->get();
|
|
//print_r($query->result());
|
|
return $query->result();
|
|
|
|
}
|
|
function checkMaterialCategory($mc){
|
|
|
|
// $this->db->select('ConfigValue');
|
|
// $this->db->from('T_ConfigDetails');
|
|
// $this->db->where(Config_ID,'C023');
|
|
// $this->db->like('ConfigValue',$mc);
|
|
// $query = $this->db->get();
|
|
// //print_r($query->result());
|
|
// return $query->result();
|
|
|
|
// //return $this->db->get('T_MaterialMaster');
|
|
// }
|
|
$temp[] = '' ;
|
|
// echo $materialcategory;
|
|
$this->db->distinct();
|
|
$this->db->select('ConfigValue');
|
|
$this->db->from('T_ConfigDetails');
|
|
$this->db->where('Config_ID','C023');
|
|
$this->db->like('ConfigValue',$mc);
|
|
$query = $this->db->get();
|
|
//print_r($query->result());die;
|
|
$temparr[] = '' ;
|
|
foreach($query->result() as $arr){
|
|
$temparr[] = $arr->ConfigValue ;
|
|
}
|
|
$temp['suggestions'] = $temparr;
|
|
//print_r($temp);
|
|
|
|
return $temp;
|
|
}
|
|
|
|
|
|
|
|
function reOrderListing()
|
|
{
|
|
|
|
$subQuery='SELECT * from T_MaterialMaster where Current_stock < reorder?';
|
|
|
|
$query=$this->db->query($subQuery,array());
|
|
//print_r($this->db->last_query());
|
|
|
|
return $query->result();
|
|
}
|
|
|
|
|
|
function getMaterialAvg($RawMaterialID)
|
|
{
|
|
$subQuery='select AVG(Rate) as avg_rate from T_PurchaseOrder_LineItem
|
|
join T_PurchaseOrder_Master on T_PurchaseOrder_Master.PONO=T_PurchaseOrder_LineItem.PONO
|
|
where MaterialCode = ?';
|
|
|
|
$query = $this->db->query($subQuery,array($RawMaterialID));
|
|
//print_r($this->db->last_query());
|
|
return $query->result_array();
|
|
}
|
|
|
|
}
|
|
?>
|