669 lines
20 KiB
PHP
Executable File
669 lines
20 KiB
PHP
Executable File
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
class batchcard_model extends CI_Model
|
|
{
|
|
|
|
function getEmplistforReport()
|
|
{
|
|
$this->db->select('T_Employee_Details.EmpID,T_Employee_Details.FirstName,T_Employee_Details.LastName,T_Employee_Details.Departmentcode,T_DepartmentDetails.shortName');
|
|
$this->db->from('T_Employee_Details');
|
|
$this->db->join('T_DepartmentDetails','T_Employee_Details.Departmentcode=T_DepartmentDetails.DEPCode');
|
|
//$this->db->join('ip_invoice_items','ip_invoices.invoice_number=ip_invoice_items.invoice_number');
|
|
//$this->db->join('ip_products','ip_invoice_items.item_product_id=ip_products.product_id');
|
|
//$this->db->join('ip_invoice_custom','ip_invoices.invoice_number=ip_invoice_custom.invoice_number and invoice_custom_fieldid=62');
|
|
$this->db->order_by('T_Employee_Details.EmpID');
|
|
$res = $this->db->get();
|
|
return $res->result();
|
|
|
|
}
|
|
|
|
function getSupplierlist(){
|
|
|
|
$this->db->select('SupplierName,SupplierID');
|
|
$this->db->from('T_SupplierDetailsN');
|
|
$supp = $this->db->get();
|
|
return $supp->result();
|
|
|
|
}
|
|
|
|
function saveHourlyBatchInfo($datatostore)
|
|
{
|
|
$this->db->insert('T_hourly_batch_info',$datatostore);
|
|
$res = $this->db->affected_rows();
|
|
|
|
return $res;
|
|
}
|
|
|
|
function saveDailyBatchCardData($datatostore)
|
|
{
|
|
$this->db->insert('T_daily_batchcard_data',$datatostore);
|
|
$res = $this->db->affected_rows();
|
|
return $res;
|
|
}
|
|
|
|
function updateHourlyBatchInfo($datatostore,$hid)
|
|
{
|
|
$this->db->where('hourlyid',$hid);
|
|
$this->db->update('T_hourly_batch_info',$datatostore);
|
|
$res = $this->db->affected_rows();
|
|
|
|
return $res;
|
|
}
|
|
|
|
function getAllHourlyData($hid='',$from='',$to='')
|
|
{
|
|
//echo "Model".$from.'-'.$to;
|
|
|
|
$this->db->select('T_hourly_batch_info.*,T_Employee_Details.FirstName as F,T_Employee_Details.LastName as L');
|
|
$this->db->from('T_hourly_batch_info');
|
|
$this->db->join('tbl_users','T_hourly_batch_info.checkedby=tbl_users.userId');
|
|
$this->db->join('T_Employee_Details','tbl_users.EmpID=T_Employee_Details.EmpID');
|
|
if(!empty($hid))
|
|
{
|
|
$this->db->where('hourlyid',$hid);
|
|
}
|
|
if(!empty($from) && !empty($to))
|
|
{
|
|
$this->db->where('T_hourly_batch_info.report_date <=',$to);
|
|
$this->db->where('T_hourly_batch_info.report_date >=',$from);
|
|
}
|
|
$this->db->order_by('hourlyid','desc');
|
|
$res = $this->db->get();
|
|
//print_r($res->result());die();
|
|
return $res->result();
|
|
}
|
|
|
|
|
|
function checkExistHourlyData($bdate,$btime)
|
|
{
|
|
//echo 'Model'.$bdate.'-'.$btime;
|
|
$this->db->select('count(*) as count');
|
|
$this->db->from('T_hourly_batch_info');
|
|
$this->db->where('report_date',$bdate);
|
|
$this->db->where('report_time',$btime);
|
|
$res = $this->db->get();
|
|
return $res->result();
|
|
}
|
|
|
|
|
|
function getPowerConsumptionDetails($rdate)
|
|
{
|
|
|
|
$this->db->select('hourlyid,report_time,opening_trp_reading,close_trp_reading,auto_start,auto_stop');
|
|
$this->db->from('T_hourly_batch_info');
|
|
$this->db->where('report_date',$rdate);
|
|
$res = $this->db->get();
|
|
return $res->result();
|
|
}
|
|
|
|
function getDailyBatchCardData($month)
|
|
{
|
|
// $this->db->select('*');
|
|
// $this->db->from('T_daily_batchcard_data');
|
|
// $this->db->where('month(ddate)',$month);
|
|
$sql = 'select T_daily_batchcard_data.*,T_Employee_Details.FirstName,T_Employee_Details.LastName from T_daily_batchcard_data
|
|
join tbl_users on T_daily_batchcard_data.createdby = tbl_users.userId
|
|
join T_Employee_Details on T_Employee_Details.EmpID = tbl_users.EmpID
|
|
where month(ddate) = ?';
|
|
$res = $this->db->query($sql,array($month));
|
|
return $res->result();
|
|
}
|
|
|
|
function getIndividualDailyData($did)
|
|
{
|
|
|
|
$this->db->select('*');
|
|
$this->db->from('T_daily_batchcard_data');
|
|
$this->db->where('dailyid',$did);
|
|
$res = $this->db->get();
|
|
return $res->result();
|
|
|
|
}
|
|
|
|
function checkExistDaily($rdate)
|
|
{
|
|
$this->db->select('count(*) as count');
|
|
$this->db->from('T_daily_batchcard_data');
|
|
$this->db->where('ddate',$rdate);
|
|
$res = $this->db->get();
|
|
return $res->result();
|
|
}
|
|
|
|
function updateDailyBatchCardData($datatostore,$did)
|
|
{
|
|
$this->db->where('dailyid',$did);
|
|
$this->db->update('T_daily_batchcard_data',$datatostore);
|
|
$res = $this->db->affected_rows();
|
|
|
|
return $res;
|
|
}
|
|
|
|
function checkAbstractReport($date)
|
|
{
|
|
$this->db->select('count(*) as count');
|
|
$this->db->from('T_abstract_report');
|
|
//$this->db->where('abstract_report_date',$date);
|
|
$this->db->where("date_format(abstract_report_date,'%Y-%m')",$date);
|
|
$res = $this->db->get();
|
|
return $res->result();
|
|
}
|
|
|
|
function saveAbstractReport($datatostore)
|
|
{
|
|
$this->db->insert('T_abstract_report',$datatostore);
|
|
$res = $this->db->affected_rows();
|
|
return $res;
|
|
}
|
|
|
|
function updateAbstractReport($datatostore,$date,$abstract_details)
|
|
{
|
|
//$this->db->where('abstract_report_date',$date);
|
|
$this->db->where("date_format(abstract_report_date,'%Y-%m')",$date);
|
|
$this->db->where('abstract_details',$abstract_details);
|
|
$this->db->update('T_abstract_report',$datatostore);
|
|
$res = $this->db->affected_rows();
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
function getPreviousMonthAbstractDetails($month,$year)
|
|
{
|
|
//$sql = "select abstract_details,close_stock from T_abstract_report where month(abstract_report_date) =? and year(abstract_report_date) =? ";
|
|
$sql = "select abstract_details,close_stock as Available from T_abstract_report where month(abstract_report_date) =? and year(abstract_report_date) =? ";
|
|
$res = $this->db->query($sql,array($month,$year));
|
|
return $res->result();
|
|
|
|
}
|
|
|
|
function getMonthAbstractDetails($month_year)
|
|
{
|
|
$sql = "select abstract_details,close_stock,open_stock as Available,physical_stock from T_abstract_report where date_format(abstract_report_date,'%Y-%m') = ? ";
|
|
$res = $this->db->query($sql,array($month_year));
|
|
|
|
return $res->result();
|
|
}
|
|
|
|
function getPreviousMonthClosedStockDetails($y,$m,$sn)
|
|
{
|
|
$month = 'month(ddate)';
|
|
$year = 'year(ddate)';
|
|
//$this->db->select($sn);
|
|
$this->db->select($sn,'ddate');
|
|
$this->db->from('T_daily_batchcard_data');
|
|
$this->db->where($month,$m);
|
|
$this->db->where($year,$y);
|
|
$this->db->order_by('ddate','desc');
|
|
$this->db->limit(1);
|
|
$res = $this->db->get();
|
|
//print_r($res->result());
|
|
return $res->result();
|
|
}
|
|
|
|
function currentMonthStockDetails($m,$y,$sd1,$sd2)
|
|
{
|
|
$month = 'month(ddate)';
|
|
$year = 'year(ddate)';
|
|
$list = array('ddate',$sd1,$sd2);
|
|
$this->db->select($list);
|
|
$this->db->from('T_daily_batchcard_data');
|
|
$this->db->where($month,$m);
|
|
$this->db->where($year,$y);
|
|
$this->db->order_by('ddate','asc');
|
|
$res = $this->db->get();
|
|
//print_r($res->result());
|
|
return $res->result();
|
|
}
|
|
|
|
function addmaint_dtl($array)
|
|
{
|
|
// $this->db->insert('T_Batchcard_MaintanceDetails',$array);
|
|
// $bmd = $this->db->affected_rows();
|
|
// return $bmd;
|
|
|
|
$this->db->insert('T_Batchcard_MaintanceDetails',$array);
|
|
$bmd = $this->db->affected_rows();
|
|
|
|
|
|
if($bmd>0)
|
|
{
|
|
$this->db->select('max(Maint_ID) as Maint_ID');
|
|
$this->db->from('T_Batchcard_MaintanceDetails');
|
|
$res = $this->db->get();
|
|
return $res->result();
|
|
}
|
|
}
|
|
function getmaint_dtl()
|
|
{
|
|
// $r->FirstName.' '.$r->LastName
|
|
$this->db->select('BMD.*');
|
|
$this->db->select('CONCAT(ED1.FirstName, " - " , ED1.LastName) AS Approver_Name', FALSE);
|
|
$this->db->select('CONCAT(ED2.FirstName, " - " , ED2.LastName) AS Worker_Name', FALSE);
|
|
$this->db->from('T_Batchcard_MaintanceDetails BMD');
|
|
$this->db->join('T_Employee_Details ED1', 'ED1.EmpID = BMD.Approved_By', 'left');
|
|
$this->db->join('T_Employee_Details ED2', 'ED2.EmpID = BMD.WorkDone_By', 'left');
|
|
$bmd = $this->db->get();
|
|
return $bmd->result();
|
|
}
|
|
|
|
function getmaint_dtl_MntID($MntID)
|
|
{
|
|
|
|
$this->db->select('*');
|
|
$this->db->from('T_Batchcard_MaintanceDetails');
|
|
$this->db->where('Maint_ID',$MntID);
|
|
$bmd = $this->db->get();
|
|
return $bmd->result();
|
|
}
|
|
|
|
function updatemaint_dtl($array,$MntID)
|
|
{
|
|
$this->db->where('Maint_ID',$MntID);
|
|
$this->db->update('T_Batchcard_MaintanceDetails',$array);
|
|
$bmd = $this->db->affected_rows();
|
|
|
|
return $bmd;
|
|
}
|
|
|
|
function maintenancesdata($date){
|
|
|
|
$this->db->select("bm.*,mm.Machine_Name");
|
|
$this->db->select("DATE_FORMAT(bm.CreatedOn,'%d-%m-%Y') AS date", FALSE);
|
|
$this->db->select("DATE_FORMAT(bm.CreatedOn,'%l:%i %p') AS time", FALSE);
|
|
$this->db->select("CONCAT(ED1.FirstName, ' - ' , ED1.LastName) AS Approver_Name", FALSE);
|
|
$this->db->select("CONCAT(ED2.FirstName, ' - ' , ED2.LastName) AS Worker_Name", FALSE);
|
|
$this->db->from("T_Batchcard_MaintanceDetails bm");
|
|
$this->db->join("T_Machine_Master mm", "bm.Machine_Code = mm.Machine_Code", "left");
|
|
$this->db->join("T_Employee_Details ED1", "bm.Approved_By = ED1.EmpID", "left");
|
|
$this->db->join("T_Employee_Details ED2", "bm.WorkDone_By = ED2.EmpID", "left");
|
|
$this->db->where("mm.Machines_Category = 'TRP'");
|
|
//AND DATE_FORMAT(bm.CreatedOn,'%Y-%m-%d') = '19-04-2018'
|
|
$this->db->where("DATE_FORMAT(bm.CreatedOn,'%d-%m-%Y')",$date);
|
|
$bmd = $this->db->get();
|
|
return $bmd->result();
|
|
|
|
//print_r($this->db->last_query());
|
|
//die();
|
|
|
|
}
|
|
|
|
function getmachine_codename(){
|
|
$this->db->select('Machine_Code,Machine_Name');
|
|
$this->db->from('T_Machine_Master');
|
|
$res = $this->db->get();
|
|
return $res->result();
|
|
}
|
|
|
|
/** Machines History/Master */
|
|
function getdept_dtls()
|
|
{
|
|
$this->db->select('T_DepartmentDetails.DEPCode,T_DepartmentDetails.shortName');
|
|
$this->db->from('T_DepartmentDetails');
|
|
$this->db->where('IsActive',1);
|
|
$res = $this->db->get();
|
|
return $res->result();
|
|
}
|
|
|
|
function getpono(){
|
|
|
|
$this->db->select('PONO');
|
|
$this->db->from('T_PurchaseOrder_Master');
|
|
$this->db->where('Status','ST026');
|
|
$res = $this->db->get();
|
|
return $res->result();
|
|
}
|
|
|
|
function getpo_dtls($pono){
|
|
|
|
// $this->db->select('T_PurchaseOrder_Master.PONO,T_PurchaseOrder_Master.SupplierID,T_SupplierDetailsN.SupplierName,DATE_FORMAT(T_PurchaseOrder_Master.PODate,"%d-%m-%Y") as PO_Date');
|
|
// $this->db->from('T_PurchaseOrder_Master');
|
|
// $this->db->join('T_SupplierDetailsN','T_PurchaseOrder_Master.SupplierID=T_SupplierDetailsN.SupplierID');
|
|
// $this->db->where('PONO',$pono);
|
|
// $res = $this->db->get();
|
|
// return $res->result();
|
|
$sql = "select T_PurchaseOrder_Master.PONO,T_PurchaseOrder_Master.SupplierID,T_SupplierDetailsN.SupplierName,DATE_FORMAT(T_PurchaseOrder_Master.PODate,'%d-%m-%Y') as PO_Date
|
|
from T_PurchaseOrder_Master
|
|
join T_SupplierDetailsN on T_PurchaseOrder_Master.SupplierID=T_SupplierDetailsN.SupplierID
|
|
where PONO = ? ";
|
|
$res = $this->db->query($sql,array($pono));
|
|
return $res->result();
|
|
|
|
}
|
|
|
|
function addhist_mstr($array)
|
|
{
|
|
$this->db->insert('T_Machine_Master',$array);
|
|
$mstr = $this->db->affected_rows();
|
|
//print_r($this->db->last_query());
|
|
//print_r($mstr);
|
|
if($mstr>0)
|
|
{
|
|
|
|
$this->db->select('max(Machine_Code) as Machine_Code');
|
|
$this->db->from('T_Machine_Master');
|
|
$res = $this->db->get();
|
|
//print_r($res->result());
|
|
return $res->result();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
function addhist_dtl($array){
|
|
|
|
$this->db->insert('T_Machine_Details',$array);
|
|
$child = $this->db->affected_rows();
|
|
return $child;
|
|
|
|
}
|
|
//This function for multi file upload option (both machine and maint/br screen)
|
|
function addfiledetails($array){
|
|
|
|
$this->db->insert('T_Machines_file', $array);
|
|
$r = $this->db->affected_rows();
|
|
return $r;
|
|
//return TRUE;
|
|
|
|
}
|
|
function insertvalueintoconfig($config){
|
|
|
|
$this->db->insert('T_ConfigDetails', $config);
|
|
return TRUE;
|
|
}
|
|
|
|
//This function used to get the material category using configdetails table
|
|
function getmachineCategory($MaterialCategory = '')
|
|
{
|
|
$Config_ID = 'C028';
|
|
$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();
|
|
}
|
|
|
|
|
|
function getHist_dtls($MachineCode = '')
|
|
{
|
|
|
|
$this->db->select('*');
|
|
$this->db->from('T_Machine_Details');
|
|
if($MachineCode != '')
|
|
{
|
|
$this->db->where('Machine_Code',$MachineCode );
|
|
}
|
|
$bmd = $this->db->get();
|
|
return $bmd->result();
|
|
}
|
|
|
|
//This function for multi file upload option (both machine and maint/br screen)
|
|
function getfiledetails($data = '')
|
|
{
|
|
|
|
$this->db->select('*');
|
|
$this->db->from('T_Machines_file');
|
|
if($data != '')
|
|
{
|
|
$this->db->where('Machine_code/Maint_id',$data );
|
|
}
|
|
$bmd = $this->db->get();
|
|
return $bmd->result();
|
|
}
|
|
|
|
function getHist_mstr($MachineCode = '')
|
|
{
|
|
|
|
$this->db->select('*');
|
|
$this->db->from('T_Machine_Master');
|
|
if($MachineCode != '')
|
|
{
|
|
$this->db->where('Machine_Code',$MachineCode );
|
|
}
|
|
$bmd = $this->db->get();
|
|
return $bmd->result();
|
|
}
|
|
|
|
// function getHist_dtlsID($MntID)
|
|
// {
|
|
|
|
// $this->db->select('*');
|
|
// $this->db->from('T_Batchcard_MaintanceDetails');
|
|
// $this->db->where('Maint_ID',$MntID);
|
|
// $bmd = $this->db->get();
|
|
// return $bmd->result();
|
|
// }
|
|
|
|
// function getHist_dtlsDate($dateval)
|
|
// {
|
|
|
|
// $this->db->select('*');
|
|
// $this->db->from('T_Batchcard_MaintanceDetails');
|
|
// $this->db->where('Maint_Date',$dateval);
|
|
// $bmd = $this->db->get();
|
|
// return $bmd->result();
|
|
// }
|
|
|
|
|
|
function edithist_mstr($array,$machinecode){
|
|
|
|
$this->db->where('Machine_Code',$machinecode );
|
|
$this->db->update('T_Machine_Master',$array);
|
|
$mstr = $this->db->affected_rows();
|
|
if($mstr>0)
|
|
{
|
|
|
|
$this->db->select('max(Machine_Code) as Machine_Code');
|
|
$this->db->from('T_Machine_Master');
|
|
$res = $this->db->get();
|
|
return $res->result();
|
|
}
|
|
|
|
}
|
|
|
|
function edithist_dtl($array,$machinecode){
|
|
$this->db->where('Machine_Code',$machinecode );
|
|
$this->db->update('T_Machine_Details',$array);
|
|
$mdtl = $this->db->affected_rows();
|
|
return $mdtl;
|
|
}
|
|
|
|
function updatefilelist($array,$fileid){
|
|
|
|
$this->db->where('File_No',$fileid);
|
|
$this->db->update('T_Machines_file', $array);
|
|
$ar = $this->db->affected_rows();
|
|
return $ar;
|
|
|
|
}
|
|
|
|
function checkMachineCategory($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[] = '' ;
|
|
|
|
$this->db->distinct();
|
|
$this->db->select('ConfigValue');
|
|
$this->db->from('T_ConfigDetails');
|
|
$this->db->where('Config_ID','C028');
|
|
$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;
|
|
}
|
|
|
|
//This function for multi file upload option (both machine and maint/br screen)
|
|
function deletefiledetails($id,$name){
|
|
$sql = "DELETE FROM T_Machines_file WHERE File_No =".$id;
|
|
unlink("uploads/images/".$name);//this deletes the file on particular folder too
|
|
$query = $this->db->query($sql);
|
|
$ar = $this->db->affected_rows();
|
|
return $ar;
|
|
}
|
|
|
|
|
|
function getHist_tbls($MachineCode){
|
|
|
|
$this->db->select('T_Machine_Master.*,T_Batchcard_MaintanceDetails.*,T_DepartmentDetails.DepartmentName');
|
|
$this->db->select("DATE_FORMAT(T_Batchcard_MaintanceDetails.CreatedOn,'%d-%m-%Y') AS date", FALSE);
|
|
$this->db->select("DATE_FORMAT(T_Batchcard_MaintanceDetails.CreatedOn,'%l:%i %p') AS time", FALSE);
|
|
$this->db->select("CONCAT(ED1.FirstName, ' - ' , ED1.LastName) AS Approver_Name", FALSE);
|
|
$this->db->select("CONCAT(ED2.FirstName, ' - ' , ED2.LastName) AS Worker_Name", FALSE);
|
|
$this->db->from('T_Machine_Master');
|
|
$this->db->join('T_Batchcard_MaintanceDetails','T_Batchcard_MaintanceDetails.Machine_Code=T_Machine_Master.Machine_Code');
|
|
$this->db->join('T_DepartmentDetails','T_DepartmentDetails.DEPCode=T_Machine_Master.Machines_Dept');
|
|
$this->db->join('T_Employee_Details ED1', 'ED1.EmpID = T_Batchcard_MaintanceDetails.Approved_By', 'left');
|
|
$this->db->join('T_Employee_Details ED2', 'ED2.EmpID = T_Batchcard_MaintanceDetails.WorkDone_By', 'left');
|
|
$this->db->where('T_Machine_Master.Machine_Code',$MachineCode);
|
|
$res = $this->db->get();
|
|
return $res->result();
|
|
|
|
// $sql = "SELECT T_Machine_Master.*,T_Batchcard_MaintanceDetails.*,
|
|
// T_DepartmentDetails.DepartmentName,
|
|
// DATE_FORMAT(T_Batchcard_MaintanceDetails.CreatedOn, '%d-%m-%Y') as date,
|
|
// DATE_FORMAT(T_Batchcard_MaintanceDetails.CreatedOn, '%l:%i %p') as time,
|
|
// FROM T_Machine_Master
|
|
// LEFT JOIN T_Batchcard_MaintanceDetails ON T_Batchcard_MaintanceDetails.Machine_Code=T_Machine_Master.Machine_Code
|
|
// LEFT JOIN T_DepartmentDetails ON T_DepartmentDetails.DEPCode=T_Machine_Master.Machines_Dept
|
|
// WHERE T_Machine_Master.Machine_Code = '".$MachineCode."'" ;
|
|
// $res = $this->db->query($sql);
|
|
// return $res->result();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getinvoice_products()
|
|
{
|
|
|
|
$this->db->select('product_id,product_name');
|
|
$this->db->from('ip_products');
|
|
$supp = $this->db->get();
|
|
return $supp->result();
|
|
|
|
}
|
|
|
|
function get_consumablematerials()
|
|
{
|
|
|
|
$this->db->select('MaterialCode,MaterialName,');
|
|
$this->db->from('T_MaterialMaster');
|
|
$this->db->where('T_MaterialMaster.Category',Consumables);
|
|
$supp = $this->db->get();
|
|
return $supp->result();
|
|
|
|
}
|
|
|
|
|
|
function get_rawmaterials()
|
|
{
|
|
$this->db->select('MaterialCode,MaterialName,');
|
|
$this->db->from('T_MaterialMaster');
|
|
$this->db->where('T_MaterialMaster.Category',RawMaterial);
|
|
$supp = $this->db->get();
|
|
return $supp->result();
|
|
}
|
|
|
|
|
|
function getMaterial()
|
|
{
|
|
$this->db->select('MaterialCode,MaterialName,');
|
|
$this->db->from('T_MaterialMaster');
|
|
//$this->db->where('T_MaterialMaster.Category',Consumables);
|
|
$supp = $this->db->get();
|
|
return $supp->result();
|
|
}
|
|
|
|
|
|
function GetNetQty($MaterialCode,$date,$Supplier)
|
|
{
|
|
//echo $date;
|
|
$dt = date('d',strtotime($date));
|
|
$year = date('Y', strtotime($date));
|
|
$month = date('m', strtotime($date));
|
|
|
|
if($month<04)
|
|
{
|
|
//echo "b4finance";
|
|
$newyr = $year - 1;
|
|
$startdate = $newyr.'-'.'04'.'-'.'01';
|
|
|
|
//echo $startdate;
|
|
}
|
|
|
|
else
|
|
{
|
|
// echo "after Finance";
|
|
$startdate = $year.'-'.'04'.'-'.'01';
|
|
//echo $startdate;
|
|
}
|
|
|
|
|
|
$subQuery='select (select sum(Quantity) as AddQty from T_Material_stock_history where Transaction_type = "Add" and MaterialCode=?
|
|
) as Addqty,(select sum(Quantity) as ReduceQty from T_Material_stock_history where Transaction_type = "Reduce" and MaterialCode=?
|
|
) as ReduceQty from T_Material_stock_history where MaterialCode=? and CreatedOn >= ? and CreatedOn<=? and SupplierID=? group by Addqty';
|
|
$query = $this->db->query($subQuery,array($MaterialCode,$MaterialCode,$MaterialCode,$startdate,$date,$Supplier));
|
|
//print_r($this->db->last_query());
|
|
return $query->result_array();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function AddmaterialAdjustment($adjustmentaarray)
|
|
{
|
|
$this->db->trans_start();
|
|
$this->db->insert('T_Material_Adjustment',$adjustmentaarray);
|
|
$insert_id = $this->db->affected_rows();
|
|
$this->db->trans_complete();
|
|
// print_r($this->db->last_query());
|
|
//print_r($insert_id);
|
|
if($insert_id>0)
|
|
{
|
|
$subQuery = 'select max(AdjustmentId) as AdjustmentId from T_Material_Adjustment';
|
|
$query = $this->db->query($subQuery);
|
|
|
|
return $query->result();
|
|
}
|
|
}
|
|
|
|
|
|
function AddMaterialHistory($historytable)
|
|
{
|
|
$this->db->trans_start();
|
|
$this->db->insert('T_Material_stock_history',$historytable);
|
|
$insert_id = $this->db->affected_rows();
|
|
$this->db->trans_complete();
|
|
return $insert_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|