siddharth_application/application/models/quality_model.php
2018-01-04 07:24:20 +00:00

429 lines
20 KiB
PHP
Executable File

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Quality_model extends CI_Model
{
function getAllInvoiceNo()
{
$this->db->select('invoice_number');
$this->db->from('ip_invoices');
$result = $this->db->get();
return $result->result();
}
function getAllprodcuts()
{
$this->db->select('product_id,product_name,product_description');
$this->db->from('ip_products');
$result = $this->db->get();
return $result->result();
}
function getAllprodcutsInward()
{
$this->db->select('MaterialCode,MaterialName');
$this->db->from('T_MaterialMaster');
$this->db->like('T_MaterialMaster.Category','raw material');
$result = $this->db->get();
return $result->result();
}
function getAllcustomers()
{
$this->db->select('client_id,client_name');
$this->db->from('ip_clients');
$result = $this->db->get();
return $result->result();
}
function getAllcustomersInward()
{
$this->db->select('SupplierID,SupplierName');
$this->db->from('T_SupplierDetailsN');
$this->db->where('IsActive',1);
$result = $this->db->get();
return $result->result();
}
function checkExist($product,$customer,$name)
{
$this->db->select('count(*) as count');
$this->db->from('T_Prodcut_Specification_Master');
$this->db->where('product_id',$product);
$this->db->where('customer_id',$customer);
$this->db->where('testtype',$name);
$result = $this->db->get();
return $result->result();
}
function addSpecMast($data)
{
//print_r($data);
$this->db->insert('T_Prodcut_Specification_Master',$data);
$r = $this->db->affected_rows();
return $r;
}
function updateSpecMast($data,$product,$customer,$name)
{
//echo $product.$customer.$name;
//print_r($data);
$this->db->where('product_id',$product);
$this->db->where('customer_id',$customer);
$this->db->where('testtype',$name);
$this->db->update('T_Prodcut_Specification_Master',$data);
$r = $this->db->affected_rows();
//echo $r;die();
return $r;
}
function getAllspec()
{
$this->db->select('T_Prodcut_Specification_Master.*,ip_products.product_name,ip_products.product_description,ip_clients.client_name,count(*) as count');
$this->db->from('T_Prodcut_Specification_Master');
$this->db->join('ip_products','T_Prodcut_Specification_Master.product_id=ip_products.product_id');
$this->db->join('ip_clients','T_Prodcut_Specification_Master.customer_id=ip_clients.client_id');
$this->db->group_by('product_id,customer_id');
$result = $this->db->get();
return $result->result();
}
function getAllspecInward()
{
$this->db->select('T_Prodcut_Specification_Master.*,T_MaterialMaster.MaterialCode,T_MaterialMaster.MaterialName,T_SupplierDetailsN.SupplierID,T_SupplierDetailsN.SupplierName,count(*) as count');
$this->db->from('T_Prodcut_Specification_Master');
$this->db->join('T_MaterialMaster','T_Prodcut_Specification_Master.product_id=T_MaterialMaster.MaterialCode');
$this->db->join('T_SupplierDetailsN','T_Prodcut_Specification_Master.customer_id=T_SupplierDetailsN.SupplierID');
$this->db->group_by('product_id,customer_id');
$result = $this->db->get();
return $result->result();
}
function getIndividualSpec($prodcutid,$customerid)
{
$this->db->select('T_Prodcut_Specification_Master.*,ip_products.product_name,ip_products.product_description,ip_clients.client_name');
$this->db->from('T_Prodcut_Specification_Master');
$this->db->join('ip_products','T_Prodcut_Specification_Master.product_id=ip_products.product_id');
$this->db->join('ip_clients','T_Prodcut_Specification_Master.customer_id=ip_clients.client_id');
$this->db->where('T_Prodcut_Specification_Master.product_id',$prodcutid);
$this->db->where('T_Prodcut_Specification_Master.customer_id',$customerid);
$result = $this->db->get();
//print_r($result->result());
if(empty($result->result()))
{
$this->db->select('T_Prodcut_Specification_Master.*,T_MaterialMaster.MaterialCode,T_MaterialMaster.MaterialName as product_name,T_SupplierDetailsN.SupplierID,T_SupplierDetailsN.SupplierName as client_name');
$this->db->from('T_Prodcut_Specification_Master');
$this->db->join('T_MaterialMaster','T_Prodcut_Specification_Master.product_id=T_MaterialMaster.MaterialCode');
$this->db->join('T_SupplierDetailsN','T_Prodcut_Specification_Master.customer_id=T_SupplierDetailsN.SupplierID');
$this->db->where('T_Prodcut_Specification_Master.product_id',$prodcutid);
$this->db->where('T_Prodcut_Specification_Master.customer_id',$customerid);
$result = $this->db->get();
}
//exit();
return $result->result();
}
function deleteSpecification($spname,$product,$customer)
{
$this->db->where("testtype", $spname);
$this->db->where("product_id", $product);
$this->db->where("customer_id", $customer);
$this->db->delete('T_Prodcut_Specification_Master');
$r = $this->db->affected_rows();
return $r;
}
function getDataforReport()
{
$this->db->select('ip_invoices.invoice_number,ip_invoices.client_id,ip_invoice_custom.invoice_custom_fieldvalue,ip_clients.client_name,ip_invoices.invoice_date_created,ip_invoice_items.item_product_id,ip_products.product_name,ip_products.product_description,ip_invoice_items.item_quantity');
$this->db->from('ip_invoices');
$this->db->join('ip_clients','ip_invoices.client_id=ip_clients.client_id');
$this->db->join('ip_invoice_items','ip_invoices.invoice_id=ip_invoice_items.invoice_id');
$this->db->join('ip_products','ip_invoice_items.item_product_id=ip_products.product_id');
$this->db->join('ip_invoice_custom','ip_invoices.invoice_id=ip_invoice_custom.invoice_id and invoice_custom_fieldid=62');
$this->db->where('ip_invoices.invoice_number NOT IN (SELECT invoiceid from T_Test_Report_Master)',NULL,false);
$this->db->order_by('ip_invoices.invoice_number','desc');
$res = $this->db->get();
//print_r($res->result());die();
return $res->result();
}
function getSpecifications($productid,$customerid)
{
//echo 'from model'.$productid.'-'.$customerid;
// $this->db->where('product_id',$productid);
// $this->db->where('customer_id',$customerid);
// $res = $this->db->get('T_Prodcut_Specification_Master');
$sql = "Select * from T_Prodcut_Specification_Master where product_id = ? and customer_id = ?";
$res = $this->db->query($sql,array($productid,$customerid));
// print_r($this->db->last_query());
return $res->result();
//print_r($res->result());
}
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 saveMasterTestData($masterreportdata)
{
$this->db->insert('T_Test_Report_Master',$masterreportdata);
$id = $this->db->insert_id();
return $id;
}
function saveTestReportData($testreportdata)
{
$this->db->insert('T_Test_Report',$testreportdata);
$row = $this->db->affected_rows();
return $row;
}
function saveTestReportAFSData($afstabledata)
{
$this->db->insert('T_Test_Report_AFS',$afstabledata);
$row = $this->db->affected_rows();
return $row;
}
function saveTestReportLOIData($loitabledata)
{
$this->db->insert('T_Test_Report_LOI',$loitabledata);
$row = $this->db->affected_rows();
return $row;
}
function getIndividualReportData($reportid)
{
$this->db->select('T_Test_Report_Master.testreport_id,ip_invoices.invoice_date_created,T_Test_Report_Master.invoiceid,T_Test_Report_Master.batchdate,T_Test_Report_Master.chartdata,ip_clients.client_id,ip_clients.client_name,invoice_custom_fieldvalue,ip_products.product_id,ip_products.product_name,ip_products.product_description,T_Employee_Details.FirstName,T_Employee_Details.LastName,ip_invoice_items.item_quantity,T_Test_Report_Master.approvedby');
$this->db->from('T_Test_Report_Master');
$this->db->join('ip_invoices','T_Test_Report_Master.invoiceid=ip_invoices.invoice_number');
$this->db->join('ip_clients','ip_invoices.client_id=ip_clients.client_id');
$this->db->join('ip_invoice_items','ip_invoices.invoice_id=ip_invoice_items.invoice_id');
$this->db->join('ip_products','ip_products.product_id=ip_invoice_items.item_product_id');
$this->db->join('ip_invoice_custom','ip_invoices.invoice_id=ip_invoice_custom.invoice_id and invoice_custom_fieldid=62');
$this->db->join('tbl_users','T_Test_Report_Master.createdby=tbl_users.userid');
$this->db->join('T_Employee_Details','tbl_users.EmpID=T_Employee_Details.EmpID');
//$this->db->join('T_Employee_Details','T_Test_Report_Master.EmpID=T_Employee_Details.EmpID');
//$this->db->join('ip_invoice_custom','ip_invoices.invoice_number=ip_invoice_custom.invoice_number and invoice_custom_fieldid=62');
$this->db->where('testreport_id',$reportid);
// $this->db->join('T_Test_Report','T_Test_Report_Master.testreport_id=T_Test_Report.testreport_id');
// $this->db->join('T_Test_Report_loi','T_Test_Report_Master.testreport_id=T_Test_Report_loi.testreport_id');
// $this->db->join('T_Test_Report_afs','T_Test_Report_Master.testreport_id=T_Test_Report_afs.testreport_id');
$res = $this->db->get();
$reportdata['master'] = $res->result();
$this->db->select('T_Test_Report.*');
$this->db->from('T_Test_Report');
$this->db->where('testreport_id',$reportid);
$res1 = $this->db->get();
$reportdata['masterreport'] = $res1->result();
$this->db->select('T_Test_Report_LOI.*');
$this->db->from('T_Test_Report_LOI');
$this->db->where('testreport_id',$reportid);
$res1 = $this->db->get();
$reportdata['masterreportloi'] = $res1->result();
$this->db->select('T_Test_Report_AFS.*');
$this->db->from('T_Test_Report_AFS');
$this->db->where('testreport_id',$reportid);
$res1 = $this->db->get();
$reportdata['masterreportafs'] = $res1->result();
$this->db->select('T_Company_Details.CompanyName,T_Company_Details.Address,T_Company_Details.ProfilePic');
$this->db->from('T_Company_Details');
//$this->db->where('testreport_id',$reportid);
$res1 = $this->db->get();
$reportdata['company'] = $res1->result();
return $reportdata;
}
function getIndividualInwardReportData($reportid)
{
$this->db->select('T_Test_Report_Master.chartdata,T_Test_Report_Master.batchdate,T_Test_Report_Master.testreport_id,T_IGR_Master.IGRNO,T_IGR_Master.DeliveryChellanOrInvoiceNo,T_IGR_Master.DeliveryChellanDate,T_IGR_Details.IGRItemNo,T_IGR_Details.QuantityAsPerInvoice,T_MaterialMaster.MaterialCode,T_MaterialMaster.Materialname,T_SupplierDetailsN.SupplierID,T_SupplierDetailsN.SupplierName,T_Test_Report_Master.approvedby,T_Employee_Details.EmpID,T_Employee_Details.FirstName,T_Employee_Details.LastName');
$this->db->from('T_Test_Report_Master');
$this->db->join('T_IGR_Master','T_Test_Report_Master.igrno=T_IGR_Master.IGRNO');
$this->db->join('T_IGR_Details','T_Test_Report_Master.igrlineitemno=T_IGR_Details.IGRItemNo');
$this->db->join('T_PurchaseOrder_Master','T_IGR_Master.PONO=T_PurchaseOrder_Master.PONO');
$this->db->join('T_MaterialMaster','T_IGR_Details.MaterialCode=T_MaterialMaster.MaterialCode');
$this->db->join('T_SupplierDetailsN','T_PurchaseOrder_Master.SupplierID=T_SupplierDetailsN.SupplierID');
$this->db->join('tbl_users','T_Test_Report_Master.createdby=tbl_users.userid');
$this->db->join('T_Employee_Details','tbl_users.EmpID=T_Employee_Details.EmpID');
$this->db->where('T_Test_Report_Master.testreport_id',$reportid);
$res = $this->db->get();
$reportdata['master'] = $res->result();
$this->db->select('T_Test_Report.*');
$this->db->from('T_Test_Report');
$this->db->where('testreport_id',$reportid);
$res1 = $this->db->get();
$reportdata['masterreport'] = $res1->result();
$this->db->select('T_Test_Report_LOI.*');
$this->db->from('T_Test_Report_LOI');
$this->db->where('testreport_id',$reportid);
$res1 = $this->db->get();
$reportdata['masterreportloi'] = $res1->result();
$this->db->select('T_Test_Report_AFS.*');
$this->db->from('T_Test_Report_AFS');
$this->db->where('testreport_id',$reportid);
$res1 = $this->db->get();
$reportdata['masterreportafs'] = $res1->result();
$this->db->select('T_Company_Details.CompanyName,T_Company_Details.Address,T_Company_Details.ProfilePic');
$this->db->from('T_Company_Details');
//$this->db->where('testreport_id',$reportid);
$res1 = $this->db->get();
$reportdata['company'] = $res1->result();
return $reportdata;
}
function getTestMasterforList()
{
$this->db->select('T_Test_Report_Master.testreport_id,T_Test_Report_Master.invoiceid,T_Test_Report_Master.batchdate,ip_clients.client_id,ip_clients.client_name,ip_products.product_id,ip_products.product_name,ip_products.product_description');
$this->db->from('T_Test_Report_Master');
$this->db->join('ip_invoices','T_Test_Report_Master.invoiceid=ip_invoices.invoice_number');
$this->db->join('ip_clients','ip_invoices.client_id=ip_clients.client_id');
$this->db->join('ip_invoice_items','ip_invoices.invoice_id=ip_invoice_items.invoice_id');
$this->db->join('ip_products','ip_products.product_id=ip_invoice_items.item_product_id');
//$this->db->where('T_Test_Report_Master.invoiceid','!=0');
$res = $this->db->get();
return $res->result();
}
function getTestMasterforListInward()
{
// $this->db->select('T_Test_Report_Master.testreport_id,T_Test_Report_Master.igrno,T_Test_Report_Master.igrlineitemno,T_Test_Report_Master.batchdate,ip_clients.client_id,ip_clients.client_name,ip_products.product_id,ip_products.product_name,ip_products.product_description');
// $this->db->from('T_Test_Report_Master');
// $this->db->join('ip_invoices','T_Test_Report_Master.invoiceid=ip_invoices.invoice_number');
// $this->db->join('ip_clients','ip_invoices.client_id=ip_clients.client_id');
// $this->db->join('ip_invoice_items','ip_invoices.invoice_id=ip_invoice_items.invoice_id');
// $this->db->join('ip_products','ip_products.product_id=ip_invoice_items.item_product_id');
// $res = $this->db->get();
// return $res->result();
$this->db->select('T_Test_Report_Master.batchdate,T_Test_Report_Master.testreport_id,T_IGR_Master.IGRNO,T_IGR_Master.DeliveryChellanOrInvoiceNo,T_IGR_Master.DeliveryChellanDate,T_IGR_Details.IGRItemNo,T_IGR_Details.QuantityAsPerInvoice,T_MaterialMaster.MaterialCode,T_MaterialMaster.Materialname,T_SupplierDetailsN.SupplierID,T_SupplierDetailsN.SupplierName,T_Test_Report_Master.approvedby,T_Employee_Details.EmpID,T_Employee_Details.FirstName,T_Employee_Details.LastName');
$this->db->from('T_Test_Report_Master');
$this->db->join('T_IGR_Master','T_Test_Report_Master.igrno=T_IGR_Master.IGRNO');
$this->db->join('T_IGR_Details','T_Test_Report_Master.igrlineitemno=T_IGR_Details.IGRItemNo');
$this->db->join('T_PurchaseOrder_Master','T_IGR_Master.PONO=T_PurchaseOrder_Master.PONO');
$this->db->join('T_MaterialMaster','T_IGR_Details.MaterialCode=T_MaterialMaster.MaterialCode');
$this->db->join('T_SupplierDetailsN','T_PurchaseOrder_Master.SupplierID=T_SupplierDetailsN.SupplierID');
$this->db->join('tbl_users','T_Test_Report_Master.createdby=tbl_users.userid');
$this->db->join('T_Employee_Details','tbl_users.EmpID=T_Employee_Details.EmpID');
$this->db->order_by('testreport_id','desc');
$res = $this->db->get();
return $res->result();
}
function getIGRNOforReport()
{
// $this->db->distinct();
// $this->db->select('IGRNO');
// $this->db->from('T_IGR_Details');
// $this->db->join('T_MaterialMaster','T_IGR_Details.MaterialCode=T_MaterialMaster.MaterialCode');
// $this->db->like('T_MaterialMaster.Category','raw material');
$sql = 'select distinct IGRNO from T_IGR_Details
join T_MaterialMaster on T_IGR_Details.MaterialCode = T_MaterialMaster.MaterialCode
where T_MaterialMaster.Category like "%Raw Material%"and date(T_IGR_Details.CreatedDate)
between date(SUBDATE(CURRENT_DATE,1)) and date(CURRENT_DATE)
order by IGRNO desc';
$result = $this->db->query($sql);
return $result->result();
}
function getIGRLineItemNo($igrno)
{
// $this->db->select('IGRItemNo');
// $this->db->from('T_IGR_Details');
// $this->db->where('IGRNO',$igrno);
$sql = 'select IGRItemNo from T_IGR_Details
join T_MaterialMaster on T_IGR_Details.MaterialCode = T_MaterialMaster.MaterialCode
where T_IGR_Details.IGRItemNo not in (select igrlineitemno from T_Test_Report_Master where igrno != "") and IGRNO = ? and T_MaterialMaster.Category like "%Raw Material%"';
$result = $this->db->query($sql,array($igrno));
return $result->result();
}
function getIGRNOReport()
{
$this->db->select('igrno,igrlineitemno');
$this->db->from('T_Test_Report_Master');
$res['generated'] = ($this->db->get()->result());
// $this->db->select('IGRNO,IGRItemNo');
// $this->db->from('T_IGR_Details');
// $this->db->where('IGRNO NOT IN (SELECT IGRNO from T_Test_Report_Master)',NULL,false);
// $this->db->or_where('IGRItemNo NOT IN (SELECT IGRItemNo from T_Test_Report_Master)',NULL,false);
$sql= 'select distinct IGRNO,IGRItemNo from T_IGR_Details join T_MaterialMaster on T_IGR_Details.MaterialCode = T_MaterialMaster.MaterialCode
where (T_IGR_Details.IGRNO not in (select igrno from T_Test_Report_Master where igrno != "")
or T_IGR_Details.IGRItemNo not in (select igrlineitemno from T_Test_Report_Master where igrno != "") )
and T_MaterialMaster.Category like "%Raw Material%"
order by T_IGR_Details.IGRNO DESC';
$r = $this->db->query($sql);
$res['notgenerated'] = ($r->result());
return $res;
}
function getIGRDataforReport($igrno,$igrlineitemno)
{
//echo $igrno.'-'.$igrlineitemno;die();
// $this->db->select('T_IGR_Master.DeliveryChellanOrInvoiceNo,T_IGR_Master.DeliveryChellanDate,T_SupplierDetailsN.SupplierID,T_SupplierDetailsN.SupplierName,T_MaterialMaster.MaterialCode,T_MaterialMaster.MaterialName,T_IGR_Details.QuantityAsPerInvoice');
// $this->db->from('T_IGR_Master');
// $this->db->join('T_IGR_Details','T_IGR_Master.IGRNO=T_IGR_Details.IGRNO');
// $this->db->join('T_MaterialMaster','T_IGR_Details.MaterialCode=T_MaterialMaster.MaterialCode');
// $this->db->join('T_PurchaseOrder_Master','T_IGR_Master.PONO=T_PurchaseOrder_Master.PONO');
// $this->db->join('T_SupplierDetailsN','T_PurchaseOrder_Master.SupplierID=T_SupplierDetailsN.SupplierID');
// $this->db->where('T_IGR_Details.IGRNO',$igrno);
// $this->db->where('T_IGR_Details.IGRItemNo',$igrlineitemno);
// $this->db->order_by('T_IGR_Master.IGRNO');
// $res = $this->db->get();
// return $res->result();
$sql = 'select T_IGR_Master.DeliveryChellanOrInvoiceNo, date_format(T_IGR_Master.DeliveryChellanDate,"%d-%m-%Y") as DeliveryChellanDate,T_SupplierDetailsN.SupplierID,T_SupplierDetailsN.SupplierName,T_MaterialMaster.MaterialCode,
T_MaterialMaster.MaterialName,T_IGR_Details.QuantityAsPerInvoice
from T_IGR_Master
join T_IGR_Details on T_IGR_Master.IGRNO=T_IGR_Details.IGRNO
join T_MaterialMaster on T_IGR_Details.MaterialCode=T_MaterialMaster.MaterialCode
join T_PurchaseOrder_Master on T_IGR_Master.PONO=T_PurchaseOrder_Master.PONO
join T_SupplierDetailsN on T_PurchaseOrder_Master.SupplierID=T_SupplierDetailsN.SupplierID
where T_IGR_Master.IGRNO = ? and T_IGR_Details.IGRItemNo = ?';
$res = $this->db->query($sql,array($igrno,$igrlineitemno));
return $res->result();
}
}
?>