ria/application/models/batchcard_model.php
venbatechnologies@gmail.com 9981afe243 stock changes
2018-06-28 15:58:17 +05:30

651 lines
21 KiB
PHP
Executable File

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class batchcard_model extends CI_Model
{
function __construct(){
parent::__construct();
//load our second db and put in $db2
$this->db2 = $this->load->database('invoicedb', TRUE);
}
// function selectquery(){
// $query = $this->db2->get('ip_invoices');
// return $query->result();
// }
//presented
function getSupplierlist(){
$this->db->select('SupplierName,SupplierID');
$this->db->from('T_SupplierDetailsN');
$supp = $this->db->get();
return $supp->result();
}
//presented
function getinvoice_products()
{
$this->db2->select('product_id,product_name');
$this->db2->from('ip_products');
$supp = $this->db2->get();
return $supp->result();
}
//presented
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();
}
//presented
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();
}
//presented
function get_packmaterials()
{
$this->db->select('MaterialCode,MaterialName,');
$this->db->from('T_MaterialMaster');
$this->db->where('T_MaterialMaster.Category',Packingmaterial);
$supp = $this->db->get();
return $supp->result();
}
//presented
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 GettotalQty($MaterialCode,$date)
{
echo $model;
$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;
}
$nedt= $dt;
$newdate=$year.'-'.$month.'-'.$nedt;
$subQuery='select T_MaterialMaster.MaterialName,T_Material_stock_history.MaterialCode,ifnull((select ifnull(sum(Quantity),0) as AddQty from T_Material_stock_history
where Transaction_type = "Add" and MaterialCode=?),0) as Addqty,
ifnull((select ifnull(sum(Quantity),0) as ReduceQty from T_Material_stock_history where Transaction_type = "Reduce"
and MaterialCode=?),0) as ReduceQty from T_Material_stock_history join T_MaterialMaster on T_Material_stock_history.MaterialCode=T_MaterialMaster.MaterialCode where T_Material_stock_history.MaterialCode=?
and CreatedOn >= ? and CreatedOn<=? group by Addqty';
$query = $this->db->query($subQuery,array($MaterialCode,$MaterialCode,$MaterialCode,$startdate,$newdate));
//print_r($this->db->last_query());
return $query->result_array();
}
//presented
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;
}
$nedt= $dt+1;
$newdate=$year.'-'.$month.'-'.$nedt;
// $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';
$subQuery='select ifnull((select ifnull(sum(Quantity),0) as AddQty from T_Material_stock_history
where Transaction_type = "Add" and MaterialCode=? and SupplierID=? ),0) as Addqty,
ifnull((select ifnull(sum(Quantity),0) as ReduceQty from T_Material_stock_history where Transaction_type = "Reduce"
and MaterialCode=? and SupplierID=? ),0) 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,$Supplier,$MaterialCode,$Supplier,$MaterialCode,$startdate,$newdate,$Supplier));
//print_r($this->db->last_query());
return $query->result_array();
}
//presented
function GetMaterialHistory($AdjustmentId)
{
$this->db->select('T_Material_Adjustment.*,SupplierName,MaterialName');
$this->db->from('T_Material_Adjustment');
$this->db->join('T_SupplierDetailsN',"T_SupplierDetailsN.SupplierID=T_Material_Adjustment.SupplierID");
$this->db->join('T_MaterialMaster',"T_MaterialMaster.MaterialCode=T_Material_Adjustment.MaterialCode");
$this->db->where('T_Material_Adjustment.AdjustmentId',$AdjustmentId);
$supp = $this->db->get();
return $supp->result();
join("T_Machine_Master mm", "bm.Machine_Code = mm.Machine_Code", "left");
}
//presented
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();
}
}
//presented
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;
}
//presented
function insert_final_product($final_master)
{
$this->db->trans_start();
$this->db->insert('T_FinalProduct_Master',$final_master);
$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(FPId) as PId from T_FinalProduct_Master';
$query = $this->db->query($subQuery);
return $query->result();
}
}
//presented
function save_finalraw($rawarray)
{
$this->db->trans_start();
$this->db->insert('T_FinalProduct_RawMaterials',$rawarray);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return true;
}
//presented
function save_finalcon($conarray)
{
$this->db->trans_start();
$this->db->insert('T_FinalProduct_ConsumableMaterials',$conarray);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return true;
}
//presented
function save_finalpacking($packarray)
{
$this->db->trans_start();
$this->db->insert('T_FinalProduct_PackingMaterials',$packarray);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return true;
}
//presented
function save_finalcoproduct($coparray)
{
//print_r($coparray);
$this->db->trans_start();
$this->db->insert('T_FinalProduct_CoProduct_Materials',$coparray);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return true;
}
//presented
function getAllMaterialAdjustments()
{
$this->db->select('T_Material_Adjustment.*,SupplierName,MaterialName');
$this->db->from('T_Material_Adjustment');
$this->db->join('T_SupplierDetailsN', 'T_Material_Adjustment.SupplierID = T_SupplierDetailsN.SupplierID');
$this->db->join('T_MaterialMaster', 'T_MaterialMaster.MaterialCode = T_Material_Adjustment.MaterialCode');
$res = $this->db->get();
return $res->result();
}
//presented
function save_rawmaterialto_materialHistory($materialhistory)
{
$this->db->trans_start();
$this->db->insert('T_Material_stock_history',$materialhistory);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return true;
}
//presented
function getFinalProductDetaisl()
{
$this->db->select('T_FinalProduct_Master.*,product_name,product_description');
$this->db->from('T_FinalProduct_Master');
$this->db->join('ip_products','ip_products.product_id=T_FinalProduct_Master.MaterialCode');
$res = $this->db->get();
return $res->result();
}
//presented
function getmasterProductDetails($FPId)
{
$this->db->select('T_FinalProduct_Master.*,product_name,product_description');
$this->db->from('T_FinalProduct_Master');
$this->db->join('ip_products','ip_products.product_id=T_FinalProduct_Master.MaterialCode');
$this->db->where('T_FinalProduct_Master.FPId',$FPId);
$res = $this->db->get();
return $res->result();
}
//presented
function getrawmaterialDetails($FPId)
{
$this->db->select('T_FinalProduct_RawMaterials.*,SupplierName,MaterialName');
$this->db->from('T_FinalProduct_RawMaterials');
$this->db->join('T_MaterialMaster','T_MaterialMaster.MaterialCode=T_FinalProduct_RawMaterials.MaterialCode');
$this->db->join('T_SupplierDetailsN','T_SupplierDetailsN.SupplierID=T_FinalProduct_RawMaterials.SupplierID');
$this->db->where('T_FinalProduct_RawMaterials.FPId',$FPId);
$res = $this->db->get();
return $res->result();
}
//presented
function getconsumaterialDetails($FPId)
{
$this->db->select('T_FinalProduct_ConsumableMaterials.*,SupplierName,MaterialName');
$this->db->from('T_FinalProduct_ConsumableMaterials');
$this->db->join('T_MaterialMaster','T_MaterialMaster.MaterialCode=T_FinalProduct_ConsumableMaterials.MaterialCode');
$this->db->join('T_SupplierDetailsN','T_SupplierDetailsN.SupplierID=T_FinalProduct_ConsumableMaterials.SupplierID');
$this->db->where('T_FinalProduct_ConsumableMaterials.FPId',$FPId);
$res = $this->db->get();
return $res->result();
}
//presented
function getpackagematerialDetails($FPId)
{
$this->db->select('T_FinalProduct_PackingMaterials.*,SupplierName,MaterialName');
$this->db->from('T_FinalProduct_PackingMaterials');
$this->db->join('T_MaterialMaster','T_MaterialMaster.MaterialCode=T_FinalProduct_PackingMaterials.MaterialCode');
$this->db->join('T_SupplierDetailsN','T_SupplierDetailsN.SupplierID=T_FinalProduct_PackingMaterials.SupplierID');
$this->db->where('T_FinalProduct_PackingMaterials.FPId',$FPId);
$res = $this->db->get();
return $res->result();
}
//presented
function getcoproductmaterial($FPId)
{
$subQuery ='select T_FinalProduct_CoProduct_Materials.*,product_name
from T_FinalProduct_CoProduct_Materials
join ip_products on ip_products.product_id = T_FinalProduct_CoProduct_Materials.MaterialCode
where T_FinalProduct_CoProduct_Materials.FPId=?';
$query = $this->db->query($subQuery,array($FPId));
return $query->result_array();
}
//presented
function update_final_product($final_master,$FPId)
{
//print_r($final_master);
$this->db->where('FPId', $FPId);
$this->db->update('T_FinalProduct_Master', $final_master);
$insert_id = $this->db->affected_rows();
//return TRUE;
if($insert_id>0)
{
$subQuery = 'select max(FPId) as FPId from T_FinalProduct_Master';
$query = $this->db->query($subQuery,array());
return $query->result_array();
}
}
//presented
function GetRawid($rawilneno)
{
$this->db->select('*');
$this->db->from('T_FinalProduct_RawMaterials');
$this->db->where('RawId',$rawilneno);
$query = $this->db->get();
//print_r($this->db->last_query());
return $query->result();
}
//presented
function Getconsuid($consuline)
{
$this->db->select('*');
$this->db->from('T_FinalProduct_ConsumableMaterials');
$this->db->where('ConId',$consuline);
$query = $this->db->get();
//print_r($this->db->last_query());
return $query->result();
}
function Getpackid($packlineId)
{
$this->db->select('*');
$this->db->from('T_FinalProduct_PackingMaterials');
$this->db->where('PackId',$packlineId);
$query = $this->db->get();
//print_r($this->db->last_query());
return $query->result();
}
//presented
function Getcopid($coplineId)
{
$this->db->select('*');
$this->db->from('T_FinalProduct_CoProduct_Materials');
$this->db->where('CoId',$coplineId);
$query = $this->db->get();
//print_r($this->db->last_query());
return $query->result();
}
//presented
function update_finalraw($rawarray,$rawilneno)
{
$this->db->where('RawId', $rawilneno);
$this->db->update('T_FinalProduct_RawMaterials', $rawarray);
return TRUE;
}
//presented
function GetRawCheck($rawmaterial,$final_product_id)
{
$this->db->select('*');
$this->db->from('T_Material_stock_history');
$this->db->where('MaterialCode',$rawmaterial);
$this->db->where('Ref_No',$final_product_id);
$this->db->where('Ref_Type',FinalProduct);
$query = $this->db->get();
//print_r($this->db->last_query());
return $query->result();
}
//presented
function update_rawmaterialto_materialHistory($rawmaterialhistory,$rawmaterial,$FPID)
{
$this->db->where('Ref_No', $FPID);
$this->db->where('MaterialCode', $rawmaterial);
$this->db->update('T_Material_stock_history', $rawmaterialhistory);
return TRUE;
}
//presented
function update_finalconsu($conarray,$consuline)
{
$this->db->where('ConId', $consuline);
$this->db->update('T_FinalProduct_ConsumableMaterials', $conarray);
return TRUE;
}
//presented
function update_finalpacking($conarray,$packlineId)
{
$this->db->where('PackId', $packlineId);
$this->db->update('T_FinalProduct_PackingMaterials', $conarray);
return TRUE;
}
//presented
function update_finalcoproduct($coparray,$coplineId)
{
$this->db->where('CoId', $coplineId);
$this->db->update('T_FinalProduct_CoProduct_Materials', $coparray);
return TRUE;
}
//presented
function getEditMaterialAdjustments($AdjustmentId)
{
$this->db->select('T_Material_Adjustment.*,SupplierName,MaterialName,Description,AdjustmentId,ActualQuantity,T_Material_stock_history.Quantity,Ref_Type,Transaction_type');
$this->db->from('T_Material_Adjustment');
$this->db->join('T_Material_stock_history', 'T_Material_Adjustment.AdjustmentId = T_Material_stock_history.Ref_No and T_Material_stock_history.Ref_Type="Adjust"');
$this->db->join('T_SupplierDetailsN', 'T_Material_Adjustment.SupplierID = T_SupplierDetailsN.SupplierID');
$this->db->join('T_MaterialMaster', 'T_MaterialMaster.MaterialCode = T_Material_Adjustment.MaterialCode');
$this->db->where('T_Material_Adjustment.AdjustmentId',$AdjustmentId);
$res = $this->db->get();
return $res->result();
}
//presented
function material_name(){
$sql="SELECT distinct MaterialName FROM T_MaterialMaster;";
$query = $this->db->query($sql);
return $query->result();
}
//presented
function getMaterial_history($prod,$frm,$t)
{
$sql="SELECT msh.StockId,sd.SupplierName,mm.MaterialName,msh.Transaction_type,msh.Ref_Type,msh.Ref_No,msh.Quantity,msh.ItemValue,date_format(msh.UpdatedOn,'%d-%m-%Y') as updatedOn FROM T_Material_stock_history as msh
left join T_SupplierDetailsN as sd on sd.SupplierID=msh.SupplierID
left join T_MaterialMaster as mm on mm.MaterialCode=msh.MaterialCode
where msh.StockId != 'null' ";
if ($prod!= ''){
$sql.=" and mm.MaterialName = '".$prod."' ";
}
if ($frm and $t != ''){
$fromd= date("Y-m-d",strtotime($frm));
$tod=date("Y-m-d",strtotime($t));
$sql.="and date(msh.UpdatedOn) >= '".$fromd."'
and date(msh.UpdatedOn) <= '".$tod."'";
}
$query =$this->db->query($sql);
return $query->result();
}
//created by TamilBala
//for update quantity stockhistory
//presented
function updateQuantityStockHistory($updatequantity,$id)
{
$this->db->where('Ref_No',$id);
$this->db->where('Ref_Type',Adjust);
$this->db->update('T_Material_stock_history',$updatequantity);
$r = $this->db->affected_rows();
//return $r->result();
//echo "HIS";
}
//created by TamilBala
//for update quantity T_Material_Adjustment
//presented
function updateQuantityAdjusment($updatequantitydes,$id)
{
$this->db->where('AdjustmentId',$id);
$this->db->update('T_Material_Adjustment',$updatequantitydes);
$r = $this->db->affected_rows();
return $r;
}
//created by TamilBala
//for update isactive T_Material_Adjustment
//presented
function updateisactiveadjusment($Updateactive,$AdjustmentId)
{
$this->db->where('AdjustmentId',$AdjustmentId);
$this->db->update('T_Material_Adjustment',$Updateactive);
$r = $this->db->affected_rows();
return $r;
}
//created by TamilBala
//for update isactive stockhistory
//
function updateisactiveastockhistory($Updateactive,$AdjustmentId)
{
$this->db->where('Ref_No',$AdjustmentId);
$this->db->where('Ref_Type',Adjust);
$this->db->update('T_Material_stock_history',$Updateactive);
$r = $this->db->affected_rows();
return $r;
}
// function GetFinishedProductList($starting_date,$end_date,$product_id)
// {
// $subQuery ='select ip_products.product_id,ip_products.product_name,ip_invoices.invoice_id,ip_invoice_items.item_quantity,ip_invoice_items.item_price,ip_invoices.invoice_number as IDnumber,ip_invoices.receivedstatus as Type from ip_products join ip_invoice_items on ip_products.product_id = ip_invoice_items.item_product_id join ip_invoices on ip_invoice_items.invoice_id = ip_invoices.invoice_id
// join T_FinalProduct_Master on ip_products.product_id = T_FinalProduct_Master.MaterialCode where (ip_invoices.invoice_date_modified>=? and ip_invoices.invoice_date_modified<=? and ip_invoice_items.item_product_id=?) union
// select ip_products.product_id,ip_products.product_name,T_FinalProduct_Master.FPId,T_FinalProduct_Master.Quantity,T_FinalProduct_Master.Price,T_FinalProduct_Master.FPId as IDnumber,T_FinalProduct_Master.ProductType as Type from ip_products join ip_invoice_items on ip_products.product_id = ip_invoice_items.item_product_id
// join T_FinalProduct_Master on ip_products.product_id = T_FinalProduct_Master.MaterialCode where
// (T_FinalProduct_Master.ProductDate<=? and T_FinalProduct_Master.ProductDate>=? and T_FinalProduct_Master.MaterialCode=?) group by FPId';
// $query = $this->db->query($subQuery,array($starting_date,$end_date,$product_id,$end_date,$starting_date,$product_id));
// //print_r($this->db->last_query());
// return $query->result_array();
// }
//presented
function GetFinishedProductList($starting_date,$end_date,$product_id)
{
// $subQuery = 'select * from T_FinalProduct_History,ip_products.product_name
// join ip_products on T_FinalProduct_History.ProductCode = ip_products.product_id
// where ProductCode=?
// and Transactiondate >= ? and Transactiondate <= ?';
$subQuery='select RefID,ProductCode,Quantity,Price,Transactiondate,TransactionType,product_name
from T_FinalProduct_History
join ip_products on ip_products.product_id= T_FinalProduct_History.ProductCode
where ProductCode=? and Transactiondate >= ? and Transactiondate <= ?';
$query = $this->db->query($subQuery,array($product_id,$starting_date,$end_date));
return $query->result_array();
}
//presented
function SaveFinalHistory($final_history)
{
$this->db->trans_start();
$this->db->insert('T_FinalProduct_History',$final_history);
$insert_id = $this->db->affected_rows();
$this->db->trans_complete();
return true;
}
//presented
function UpdateFinalHistory($final_history,$FPID,$rawmaterial)
{
//print_r($final_history);
$this->db->where('RefID', $FPID);
$this->db->where('ProductCode',$rawmaterial);
$this->db->update('T_FinalProduct_History',$final_history);
//print_r($this->db->last_query());
return TRUE;
}
}
?>