1546 lines
46 KiB
PHP
Executable File
1546 lines
46 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class Batchcard_model extends Model
|
|
{
|
|
|
|
function getEmplistforReport()
|
|
{
|
|
$builder = $this->db->table('t_employee_details')
|
|
->select('t_employee_details.EmpID,t_employee_details.FirstName,t_employee_details.LastName,t_employee_details.Departmentcode,t_departmentdetails.shortName')
|
|
->join('t_departmentdetails', 't_employee_details.Departmentcode=t_departmentdetails.DEPCode')
|
|
//->join('ip_invoice_items','ip_invoices.invoice_number=ip_invoice_items.invoice_number')
|
|
//->join('ip_products','ip_invoice_items.item_product_id=ip_products.product_id')
|
|
//->join('ip_invoice_custom','ip_invoices.invoice_number=ip_invoice_custom.invoice_number and invoice_custom_fieldid=62')
|
|
->orderBy('t_employee_details.EmpID');
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
function getSupplierlist()
|
|
{
|
|
$builder = $this->db->table('t_supplierdetailsn')
|
|
->select('SupplierName,SupplierID');
|
|
$supp = $builder->get();
|
|
return $supp->getResult();
|
|
}
|
|
|
|
function Rawsupplier()
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_master mas')
|
|
->select('mas.SupplierID,sup.SupplierName,mmas.MaterialCode,mmas.MaterialName')
|
|
->join('t_supplierdetailsn sup', 'sup.SupplierID=mas.SupplierID')
|
|
->join('t_purchaseorder_lineitem line', 'line.PONO=mas.PONO')
|
|
->join('t_materialmaster mmas', 'mmas.MaterialCode=line.MaterialCode')
|
|
->where('Category', 'Raw Material')
|
|
->groupBy('SupplierID');
|
|
$supp = $builder->get();
|
|
return $supp->getResult();
|
|
}
|
|
|
|
function Consupplier()
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_master mas')
|
|
->select('mas.SupplierID,sup.SupplierName')
|
|
->join('t_supplierdetailsn sup', 'sup.SupplierID=mas.SupplierID')
|
|
->join('t_purchaseorder_lineitem line', 'line.PONO=mas.PONO')
|
|
->join('t_materialmaster mmas', 'mmas.MaterialCode=line.MaterialCode')
|
|
->where('Category', 'Consumables')
|
|
->groupBy('SupplierID');
|
|
$supp = $builder->get();
|
|
return $supp->getResult();
|
|
}
|
|
|
|
function Pacsupplier()
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_master mas')
|
|
->select('mas.SupplierID,sup.SupplierName')
|
|
->join('t_supplierdetailsn sup', 'sup.SupplierID=mas.SupplierID')
|
|
->join('t_purchaseorder_lineitem line', 'line.PONO=mas.PONO')
|
|
->join('t_materialmaster mmas', 'mmas.MaterialCode=line.MaterialCode')
|
|
->where('Category', 'Packing material')
|
|
->groupBy('SupplierID');
|
|
$supp = $builder->get();
|
|
return $supp->getResult();
|
|
}
|
|
|
|
function getStockValue()
|
|
{
|
|
$builder = $this->db->table('t_materialmaster')
|
|
->select('MaterialCode,stock,stockdate');
|
|
$supp = $builder->get();
|
|
return $supp->getResult();
|
|
}
|
|
|
|
function saveHourlyBatchInfo($datatostore)
|
|
{
|
|
$builder = $this->db->table('T_hourly_batch_info');
|
|
$builder->insert($datatostore);
|
|
$res = $this->db->affectedRows();
|
|
return $res;
|
|
}
|
|
|
|
function saveDailyBatchCardData($datatostore)
|
|
{
|
|
$builder = $this->db->table('T_daily_batchcard_data');
|
|
$builder->insert($datatostore);
|
|
$res = $this->db->affectedRows();
|
|
return $res;
|
|
}
|
|
|
|
function updateHourlyBatchInfo($datatostore, $hid)
|
|
{
|
|
$this->db->table('T_hourly_batch_info')
|
|
->where('hourlyid', $hid)
|
|
->update($datatostore);
|
|
$res = $this->db->affectedRows();
|
|
return $res;
|
|
}
|
|
|
|
function getAllHourlyData($hid = '', $from = '', $to = '')
|
|
{
|
|
//echo "Model".$from.'-'.$to;
|
|
$builder = $this->db->table('T_hourly_batch_info')
|
|
->select('T_hourly_batch_info.*,t_employee_details.FirstName as F,t_employee_details.LastName as L')
|
|
->join('tbl_users', 'T_hourly_batch_info.checkedby=tbl_users.userId')
|
|
->join('t_employee_details', 'tbl_users.EmpID=t_employee_details.EmpID');
|
|
if (!empty($hid)) {
|
|
$builder->where('hourlyid', $hid);
|
|
}
|
|
if (!empty($from) && !empty($to)) {
|
|
$builder->where('T_hourly_batch_info.report_date <=', $to);
|
|
$builder->where('T_hourly_batch_info.report_date >=', $from);
|
|
}
|
|
$builder->orderBy('hourlyid', 'desc');
|
|
$res = $builder->get();
|
|
|
|
return $res->getResult();
|
|
}
|
|
|
|
function checkExistHourlyData($bdate, $btime)
|
|
{
|
|
//echo 'Model'.$bdate.'-'.$btime;
|
|
$builder = $this->db->table('T_hourly_batch_info')
|
|
->select('count(*) as count')
|
|
->where('report_date', $bdate)
|
|
->where('report_time', $btime);
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
function getPowerConsumptionDetails($rdate)
|
|
{
|
|
$builder = $this->db->table('T_hourly_batch_info')
|
|
->select('hourlyid,report_time,opening_trp_reading,close_trp_reading,auto_start,auto_stop')
|
|
->where('report_date', $rdate);
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
function getDailyBatchCardData($month)
|
|
{
|
|
// ->select('*');
|
|
// $builder = $this->db->table('T_daily_batchcard_data');
|
|
// ->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->getResult();
|
|
}
|
|
|
|
function getIndividualDailyData($did)
|
|
{
|
|
$builder = $this->db->table('T_daily_batchcard_data')
|
|
->select('*')
|
|
->where('dailyid', $did);
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
function checkExistDaily($rdate)
|
|
{
|
|
$builder = $this->db->table('T_daily_batchcard_data')
|
|
->select('count(*) as count')
|
|
->where('ddate', $rdate);
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
function updateDailyBatchCardData($datatostore, $did)
|
|
{
|
|
$this->db->table('T_daily_batchcard_data')
|
|
->where('dailyid', $did)
|
|
->update($datatostore);
|
|
$res = $this->db->affectedRows();
|
|
|
|
return $res;
|
|
}
|
|
|
|
function checkAbstractReport($date)
|
|
{
|
|
$builder = $this->db->table('T_abstract_report')
|
|
->select('count(*) as count')
|
|
//->where('abstract_report_date',$date)
|
|
->where("date_format(abstract_report_date,'%Y-%m')", $date);
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
function saveAbstractReport($datatostore)
|
|
{
|
|
$builder = $this->db->table('T_abstract_report');
|
|
$builder->insert($datatostore);
|
|
$res = $this->db->affectedRows();
|
|
return $res;
|
|
}
|
|
|
|
function updateAbstractReport($datatostore, $date, $abstract_details)
|
|
{
|
|
//->where('abstract_report_date',$date);
|
|
$this->db->table('T_abstract_report')
|
|
->where("date_format(abstract_report_date,'%Y-%m')", $date)
|
|
->where('abstract_details', $abstract_details)
|
|
->update($datatostore);
|
|
$res = $this->db->affectedRows();
|
|
|
|
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->getResult();
|
|
}
|
|
|
|
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->getResult();
|
|
}
|
|
|
|
function getPreviousMonthClosedStockDetails($y, $m, $sn)
|
|
{
|
|
$month = 'month(ddate)';
|
|
$year = 'year(ddate)';
|
|
//->select($sn);
|
|
$builder = $this->db->table('T_daily_batchcard_data')
|
|
->select($sn, 'ddate')
|
|
->where($month, $m)
|
|
->where($year, $y)
|
|
->orderBy('ddate', 'desc')
|
|
->limit(1);
|
|
$res = $builder->get();
|
|
//print_r($res->getResult());
|
|
return $res->getResult();
|
|
}
|
|
|
|
function currentMonthStockDetails($m, $y, $sd1, $sd2)
|
|
{
|
|
$month = 'month(ddate)';
|
|
$year = 'year(ddate)';
|
|
$list = array('ddate', $sd1, $sd2);
|
|
$builder = $this->db->table('T_daily_batchcard_data')
|
|
->select($list)
|
|
->where($month, $m)
|
|
->where($year, $y)
|
|
->orderBy('ddate', 'asc');
|
|
$res = $builder->get();
|
|
//print_r($res->getResult());
|
|
return $res->getResult();
|
|
}
|
|
|
|
function addmaint_dtl($array)
|
|
{
|
|
$builder = $this->db->table('T_Batchcard_MaintanceDetails');
|
|
$builder->insert($array);
|
|
if ($this->db->affectedRows() > 0) {
|
|
|
|
$builder = $this->db->table('T_Batchcard_MaintanceDetails')
|
|
->select('max(Maint_ID) as Maint_ID');
|
|
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
} else {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
function getmaint_dtl($fdate, $tdate, $type)
|
|
{
|
|
|
|
$builder = $this->db->table('T_Batchcard_MaintanceDetails BMD')
|
|
->select('BMD.*')
|
|
->select('CONCAT(ED1.FirstName, " - " , ED1.LastName) AS Approver_Name', FALSE)
|
|
->select('CONCAT(ED2.FirstName, " - " , ED2.LastName) AS Worker_Name', FALSE)
|
|
->join('t_employee_details ED1', 'ED1.EmpID = BMD.Approved_By', 'left')
|
|
->join('t_employee_details ED2', 'ED2.EmpID = BMD.WorkDone_By', 'left');
|
|
|
|
if ($fdate and $tdate != '') {
|
|
|
|
$fromdate = date("Y-m-d", strtotime($fdate));
|
|
$todate = date("Y-m-d", strtotime($tdate));
|
|
|
|
$date = "date(BMD.CreatedOn) >= '" . $fromdate . "'
|
|
and date( BMD.CreatedOn) <= '" . $todate . "'";
|
|
$builder->where($date);
|
|
}
|
|
|
|
if ($type != "") {
|
|
$builder->where("BMD.type", $type);
|
|
}
|
|
$bmd = $builder->get();
|
|
return $bmd->getResult();
|
|
}
|
|
|
|
function getmaint_dtl_MntID($MntID)
|
|
{
|
|
$builder = $this->db->table('T_Batchcard_MaintanceDetails')
|
|
->select('*')
|
|
->where('Maint_ID', $MntID);
|
|
$bmd = $builder->get();
|
|
return $bmd->getResult();
|
|
}
|
|
|
|
function updatemaint_dtl($array, $MntID)
|
|
{
|
|
$this->db->table('T_Batchcard_MaintanceDetails')
|
|
->where('Maint_ID', $MntID)
|
|
->update($array);
|
|
|
|
$bmd = $this->db->affectedRows();
|
|
|
|
return $bmd;
|
|
}
|
|
|
|
function maintenancesdata($date)
|
|
{
|
|
$builder = $this->db->table("T_Batchcard_MaintanceDetails bm")
|
|
->select("bm.*,mm.Machine_Name")
|
|
->select("DATE_FORMAT(bm.CreatedOn,'%d-%m-%Y') AS date", FALSE)
|
|
->select("DATE_FORMAT(bm.CreatedOn,'%l:%i %p') AS time", FALSE)
|
|
->select("CONCAT(ED1.FirstName, ' - ' , ED1.LastName) AS Approver_Name", FALSE)
|
|
->select("CONCAT(ED2.FirstName, ' - ' , ED2.LastName) AS Worker_Name", FALSE)
|
|
->join("T_Machine_Master mm", "bm.Machine_Code = mm.Machine_Code", "left")
|
|
->join("t_employee_details ED1", "bm.Approved_By = ED1.EmpID", "left")
|
|
->join("t_employee_details ED2", "bm.WorkDone_By = ED2.EmpID", "left")
|
|
->where("mm.Machines_Category = 'TRP'")
|
|
//AND DATE_FORMAT(bm.CreatedOn,'%Y-%m-%d') = '19-04-2018'
|
|
->where("DATE_FORMAT(bm.CreatedOn,'%d-%m-%Y')", $date);
|
|
$bmd = $builder->get();
|
|
return $bmd->getResult();
|
|
}
|
|
|
|
function getmachine_codename()
|
|
{
|
|
$builder = $this->db->table('T_Machine_Master')
|
|
->select('Machine_Code,Machine_Name');
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
/** Machines History/Master */
|
|
function getdept_dtls()
|
|
{
|
|
$builder = $this->db->table('t_departmentdetails')
|
|
->select('t_departmentdetails.DEPCode,t_departmentdetails.shortName')
|
|
->where('IsActive', 1);
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
function getpono()
|
|
{
|
|
$builder = $this->db->table('t_purchaseorder_master')
|
|
->select('PONO')
|
|
->where('Status', 'ST026');
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
function getpo_dtls($pono)
|
|
{
|
|
|
|
// ->select('t_purchaseorder_master.PONO,t_purchaseorder_master.SupplierID,t_supplierdetailsn.SupplierName,DATE_FORMAT(t_purchaseorder_master.PODate,"%d-%m-%Y") as PO_Date');
|
|
// $builder = $this->db->table('t_purchaseorder_master');
|
|
// ->join('t_supplierdetailsn','t_purchaseorder_master.SupplierID=t_supplierdetailsn.SupplierID');
|
|
// ->where('PONO',$pono);
|
|
// $res =$builder->get();
|
|
// return $res->getResult();
|
|
$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->getResult();
|
|
}
|
|
|
|
function addhist_mstr($array)
|
|
{
|
|
$builder = $this->db->table('T_Machine_Master');
|
|
$builder->insert($array);
|
|
if ($this->db->affectedRows() > 0) {
|
|
$builder = $this->db->table('T_Machine_Master')
|
|
->select('max(Machine_Code) as Machine_Code');
|
|
|
|
$res = $builder->get();
|
|
//print_r($res->getResult());
|
|
return $res->getResult();
|
|
} else {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
function addhist_dtl($array)
|
|
{
|
|
$builder = $this->db->table('T_Machine_Master');
|
|
$builder->insert($array);
|
|
$child = $this->db->affectedRows();
|
|
return $child;
|
|
}
|
|
|
|
//This function for multi file upload option (both machine and maint/br screen)
|
|
function addfiledetails($array)
|
|
{
|
|
$builder = $this->db->table('T_Machines_file');
|
|
$builder->insert($array);
|
|
$r = $this->db->affectedRows();
|
|
return $r;
|
|
//return TRUE;
|
|
|
|
}
|
|
|
|
function insertvalueintoconfig($config)
|
|
{
|
|
$builder = $this->db->table('t_configdetails');
|
|
$builder->insert($config);
|
|
return TRUE;
|
|
}
|
|
|
|
//This function used to get the material category using configdetails table
|
|
function getmachineCategory($MaterialCategory = '')
|
|
{
|
|
$Config_ID = 'C028';
|
|
$builder = $this->db->table('t_configdetails')
|
|
->select('Config_ID,ConfigValue')
|
|
->where('Config_id', $Config_ID);
|
|
if ($MaterialCategory != '') {
|
|
$builder->where('ConfigValue !=', $MaterialCategory);
|
|
}
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
function getHist_dtls($MachineCode = '')
|
|
{
|
|
$builder = $this->db->table('T_Machine_Details')
|
|
->select('*');
|
|
|
|
if ($MachineCode != '') {
|
|
$builder->where('Machine_Code', $MachineCode);
|
|
}
|
|
$bmd = $builder->get();
|
|
return $bmd->getResult();
|
|
}
|
|
|
|
//This function for multi file upload option (both machine and maint/br screen)
|
|
function getfiledetails($data = '')
|
|
{
|
|
|
|
$builder = $this->db->table('T_Machines_file')->select('*');
|
|
|
|
if ($data != '') {
|
|
$builder->where('Machine_code/Maint_id', $data);
|
|
}
|
|
$bmd = $builder->get();
|
|
return $bmd->getResult();
|
|
}
|
|
|
|
function getHist_mstr($MachineCode = '')
|
|
{
|
|
$builder = $this->db->table('T_Machine_Master')->select('*');
|
|
if ($MachineCode != '') {
|
|
$builder->where('Machine_Code', $MachineCode);
|
|
}
|
|
$bmd = $builder->get();
|
|
return $bmd->getResult();
|
|
}
|
|
|
|
// function getHist_dtlsID($MntID)
|
|
// {
|
|
// $builder = $this->db->table('T_Batchcard_MaintanceDetails')->select('*')
|
|
// ->where('Maint_ID',$MntID);
|
|
// $bmd = $builder->get();
|
|
// return $bmd->getResult();
|
|
// }
|
|
|
|
// function getHist_dtlsDate($dateval)
|
|
// {
|
|
// $builder = $this->db->table('T_Batchcard_MaintanceDetails')->select('*')
|
|
// ->where('Maint_Date',$dateval);
|
|
// $bmd = $builder->get();
|
|
// return $bmd->getResult();
|
|
// }
|
|
|
|
|
|
function edithist_mstr($array, $machinecode)
|
|
{
|
|
|
|
$this->db->table('T_Machine_Master')
|
|
->where('Machine_Code', $machinecode)
|
|
->update($array);
|
|
|
|
$mstr = $this->db->affectedRows();
|
|
if ($mstr > 0) {
|
|
$builder = $this->db->table('T_Machine_Master')
|
|
->select('max(Machine_Code) as Machine_Code');
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
}
|
|
|
|
function edithist_dtl($array, $machinecode)
|
|
{
|
|
$this->db->table('T_Machine_Details')
|
|
->where('Machine_Code', $machinecode)
|
|
->update($array);
|
|
|
|
$mdtl = $this->db->affectedRows();
|
|
return $mdtl;
|
|
}
|
|
|
|
function updatefilelist($array, $fileid)
|
|
{
|
|
$this->db->table('T_Machines_file')
|
|
->where('File_No', $fileid)
|
|
->update($array);
|
|
|
|
$ar = $this->db->affectedRows();
|
|
return $ar;
|
|
}
|
|
|
|
function checkMachineCategory($mc)
|
|
{
|
|
|
|
// $builder = $this->db->table('t_configdetails')
|
|
// ->select('ConfigValue')
|
|
// ->where(Config_ID,'C023')
|
|
// ->like('ConfigValue',$mc);
|
|
// $query = $builder->get();
|
|
// //print_r($query->getResult());
|
|
// return $query->getResult();
|
|
// $builder = $this->db->table('t_materialmaster')
|
|
// return $query = $builder->get();
|
|
// }
|
|
$temp[] = '';
|
|
|
|
|
|
$builder = $this->db->table('t_configdetails')
|
|
->distinct()->select('ConfigValue')
|
|
->where('Config_ID', 'C028')
|
|
->like('ConfigValue', $mc);
|
|
$query = $builder->get();
|
|
|
|
$temparr[] = '';
|
|
foreach ($query->getResult() 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("public/uploads/images/" . $name); //this deletes the file on particular folder too
|
|
$query = $this->db->query($sql);
|
|
$ar = $this->db->affectedRows();
|
|
return $ar;
|
|
}
|
|
|
|
function getHist_tbls($MachineCode)
|
|
{
|
|
|
|
$builder = $this->db->table('T_Machine_Master')
|
|
->select('T_Machine_Master.*,T_Batchcard_MaintanceDetails.*,t_departmentdetails.DepartmentName')
|
|
->select("DATE_FORMAT(T_Batchcard_MaintanceDetails.CreatedOn,'%d-%m-%Y') AS date", FALSE)
|
|
->select("DATE_FORMAT(T_Batchcard_MaintanceDetails.CreatedOn,'%l:%i %p') AS time", FALSE)
|
|
->select("CONCAT(ED1.FirstName, ' - ' , ED1.LastName) AS Approver_Name", FALSE)
|
|
->select("CONCAT(ED2.FirstName, ' - ' , ED2.LastName) AS Worker_Name", FALSE)
|
|
->join('T_Batchcard_MaintanceDetails', 'T_Batchcard_MaintanceDetails.Machine_Code=T_Machine_Master.Machine_Code')
|
|
->join('t_departmentdetails', 't_departmentdetails.DEPCode=T_Machine_Master.Machines_Dept')
|
|
->join('t_employee_details ED1', 'ED1.EmpID = T_Batchcard_MaintanceDetails.Approved_By', 'left')
|
|
->join('t_employee_details ED2', 'ED2.EmpID = T_Batchcard_MaintanceDetails.WorkDone_By', 'left')
|
|
->where('T_Machine_Master.Machine_Code', $MachineCode);
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
|
|
// $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->getResult();
|
|
|
|
}
|
|
|
|
function getinvoice_products()
|
|
{
|
|
$builder = $this->db->table('ip_products')
|
|
->select('product_id,product_name,product_description');
|
|
$supp = $builder->get();
|
|
return $supp->getResult();
|
|
}
|
|
|
|
function get_consumablematerials()
|
|
{
|
|
$builder = $this->db->table('t_materialmaster')
|
|
->select('MaterialCode,MaterialName')
|
|
//->where('t_materialmaster.Category',Consumables)
|
|
->where('t_materialmaster.Category like', '%Consumable%');
|
|
$supp = $builder->get();
|
|
return $supp->getResult();
|
|
}
|
|
|
|
function get_rawmaterials()
|
|
{
|
|
$builder = $this->db->table('t_materialmaster')
|
|
->select('MaterialCode,MaterialName,')
|
|
->where('t_materialmaster.Category like', '%Raw Material%');
|
|
$supp = $builder->get();
|
|
|
|
return $supp->getResult();
|
|
}
|
|
|
|
function get_packmaterials()
|
|
{
|
|
$builder = $this->db->table('t_materialmaster')
|
|
->select('MaterialCode,MaterialName')
|
|
// ->where('t_materialmaster.Category',Packingmaterial);
|
|
->where('t_materialmaster.Category like', '%Packing%');
|
|
$supp = $builder->get();
|
|
return $supp->getResult();
|
|
}
|
|
|
|
function GetReclamationMaterial()
|
|
{
|
|
|
|
$builder = $this->db->table('ip_products')
|
|
->select('product_id,product_name,product_description')
|
|
->join('ip_families', 'ip_families.family_id=ip_products.family_id')
|
|
// ->where('t_materialmaster.Category',Packingmaterial);
|
|
->where('ip_families.family_name like', '%Reclam%');
|
|
$supp = $builder->get();
|
|
return $supp->getResult();
|
|
}
|
|
|
|
function getMaterial()
|
|
{
|
|
$builder = $this->db->table('t_materialmaster')
|
|
->select('MaterialCode,MaterialName,');
|
|
//->where('t_materialmaster.Category',Consumables);
|
|
$supp = $builder->get();
|
|
return $supp->getResult();
|
|
}
|
|
|
|
|
|
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));
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
|
|
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));
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
|
|
function GetMaterialHistory($AdjustmentId)
|
|
{
|
|
$builder = $this->db->table('t_material_adjustment')
|
|
->select('t_material_adjustment.*,SupplierName,MaterialName')
|
|
->join('t_supplierdetailsn', "t_supplierdetailsn.SupplierID=t_material_adjustment.SupplierID")
|
|
->join('t_materialmaster', "t_materialmaster.MaterialCode=t_material_adjustment.MaterialCode")
|
|
->where('t_material_adjustment.AdjustmentId', $AdjustmentId);
|
|
$supp = $builder->get();
|
|
return $supp->getResult();
|
|
|
|
// join("T_Machine_Master mm", "bm.Machine_Code = mm.Machine_Code", "left");
|
|
}
|
|
|
|
|
|
|
|
|
|
function AddmaterialAdjustment($adjustmentaarray)
|
|
{
|
|
$this->db->transStart();
|
|
|
|
$builder = $this->db->table('t_material_adjustment');
|
|
$builder->insert($adjustmentaarray);
|
|
|
|
$insert_id = $this->db->insertID();
|
|
$aff = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
|
|
if ($insert_id > 0) {
|
|
$subQuery = 'select max(AdjustmentId) as AdjustmentId from t_material_adjustment';
|
|
$query = $this->db->query($subQuery);
|
|
|
|
return $query->getResult();
|
|
}
|
|
}
|
|
|
|
|
|
function AddMaterialHistory($historytable)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_material_stock_history');
|
|
$builder->insert($historytable);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
return $insert_id;
|
|
}
|
|
|
|
|
|
function insert_final_product($final_master)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_finalproduct_master');
|
|
$builder->insert($final_master);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
|
|
//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->getResult();
|
|
}
|
|
}
|
|
|
|
|
|
function save_finalraw($rawarray)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_finalproduct_rawmaterials');
|
|
$builder->insert($rawarray);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
return true;
|
|
}
|
|
|
|
|
|
function save_finalcon($conarray)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_finalproduct_consumablematerials');
|
|
$builder->insert($conarray);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
return true;
|
|
}
|
|
|
|
function save_finalpacking($packarray)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_finalproduct_packingmaterials');
|
|
$builder->insert($packarray);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
return true;
|
|
}
|
|
|
|
|
|
function save_finalcoproduct($coparray)
|
|
{
|
|
|
|
//print_r($coparray);
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_finalproduct_coproduct_materials');
|
|
$builder->insert($coparray);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
return true;
|
|
}
|
|
|
|
|
|
function getAllMaterialAdjustments()
|
|
{
|
|
$builder = $this->db->table('t_material_adjustment')
|
|
->select('t_material_adjustment.*,SupplierName,MaterialName')
|
|
->join('t_supplierdetailsn', 't_material_adjustment.SupplierID = t_supplierdetailsn.SupplierID')
|
|
->join('t_materialmaster', 't_materialmaster.MaterialCode = t_material_adjustment.MaterialCode');
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
|
|
|
|
|
|
function save_rawmaterialto_materialHistory($materialhistory)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_material_stock_history');
|
|
$builder->insert($materialhistory);
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
return true;
|
|
}
|
|
|
|
|
|
function getFinalProductDetaisl()
|
|
{
|
|
$builder = $this->db->table('t_finalproduct_master')
|
|
->select('t_finalproduct_master.*,product_name,product_description')
|
|
->join('ip_products', 'ip_products.product_id=t_finalproduct_master.MaterialCode')
|
|
->orderBy('t_finalproduct_master.FPId', 'desc');
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
|
|
function getmasterProductDetails($FPId)
|
|
{
|
|
$builder = $this->db->table('t_finalproduct_master')
|
|
->select('t_finalproduct_master.*,product_name,product_description')
|
|
->join('ip_products', 'ip_products.product_id=t_finalproduct_master.MaterialCode')
|
|
->where('t_finalproduct_master.FPId', $FPId);
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
|
|
function getrawmaterialDetails($FPId)
|
|
{
|
|
|
|
$builder = $this->db->table('t_finalproduct_rawmaterials')
|
|
->select('t_finalproduct_rawmaterials.*,SupplierName,MaterialName')
|
|
->join('t_materialmaster', 't_materialmaster.MaterialCode=t_finalproduct_rawmaterials.MaterialCode')
|
|
->join('t_supplierdetailsn', 't_supplierdetailsn.SupplierID=t_finalproduct_rawmaterials.SupplierID')
|
|
->where('t_finalproduct_rawmaterials.FPId', $FPId);
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
|
|
function getconsumaterialDetails($FPId)
|
|
{
|
|
$builder = $this->db->table('t_finalproduct_consumablematerials')
|
|
->select('t_finalproduct_consumablematerials.*,SupplierName,MaterialName')
|
|
->join('t_materialmaster', 't_materialmaster.MaterialCode=t_finalproduct_consumablematerials.MaterialCode')
|
|
->join('t_supplierdetailsn', 't_supplierdetailsn.SupplierID=t_finalproduct_consumablematerials.SupplierID')
|
|
->where('t_finalproduct_consumablematerials.FPId', $FPId);
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
|
|
function getpackagematerialDetails($FPId)
|
|
{
|
|
$builder = $this->db->table('t_finalproduct_packingmaterials')
|
|
->select('t_finalproduct_packingmaterials.*,SupplierName,MaterialName')
|
|
->join('t_materialmaster', 't_materialmaster.MaterialCode=t_finalproduct_packingmaterials.MaterialCode')
|
|
->join('t_supplierdetailsn', 't_supplierdetailsn.SupplierID=t_finalproduct_packingmaterials.SupplierID')
|
|
->where('t_finalproduct_packingmaterials.FPId', $FPId);
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
|
|
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->getResultArray();
|
|
}
|
|
|
|
|
|
function update_final_product($final_master, $FPId)
|
|
{
|
|
//print_r($final_master);
|
|
$this->db->table('t_finalproduct_master')
|
|
->where('FPId', $FPId)
|
|
->update($final_master);
|
|
|
|
$aff = $this->db->affectedRows();
|
|
//return TRUE;
|
|
if ($aff > 0) {
|
|
$subQuery = 'select max(FPId) as FPId from t_finalproduct_master';
|
|
|
|
$query = $this->db->query($subQuery, array());
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function GetRawid($rawilneno)
|
|
{
|
|
|
|
$builder = $this->db->table('t_finalproduct_rawmaterials')
|
|
->select('*')->where('RawId', $rawilneno);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
function Getconsuid($consuline)
|
|
{
|
|
|
|
$builder = $this->db->table('t_finalproduct_consumablematerials')
|
|
->select('*')->where('ConId', $consuline);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function Getpackid($packlineId)
|
|
{
|
|
|
|
|
|
$builder = $this->db->table('t_finalproduct_packingmaterials')
|
|
->select('*')->where('PackId', $packlineId);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function Getcopid($coplineId)
|
|
{
|
|
|
|
$builder = $this->db->table('t_finalproduct_coproduct_materials')
|
|
->select('*')
|
|
->where('CoId', $coplineId);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function update_finalraw($rawarray, $rawilneno)
|
|
{
|
|
$this->db->table('t_finalproduct_rawmaterials')
|
|
->where('RawId', $rawilneno)
|
|
->update($rawarray);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function GetRawCheck($rawmaterial, $final_product_id)
|
|
{
|
|
|
|
$builder = $this->db->table('t_material_stock_history')
|
|
->select('*')->where('MaterialCode', $rawmaterial)
|
|
->where('Ref_No', $final_product_id)
|
|
->where('Ref_Type', FinalProduct);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
function update_rawmaterialto_materialHistory($rawmaterialhistory, $rawmaterial, $FPID)
|
|
{
|
|
$this->db->table('t_material_stock_history')
|
|
->where('Ref_No', $FPID)
|
|
->where('MaterialCode', $rawmaterial)
|
|
->update($rawmaterialhistory);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function update_finalconsu($conarray, $consuline)
|
|
{
|
|
$this->db->table('t_finalproduct_consumablematerials')
|
|
->where('ConId', $consuline)
|
|
->update($conarray);
|
|
|
|
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function update_finalpacking($conarray, $packlineId)
|
|
{
|
|
|
|
$this->db->table('t_finalproduct_packingmaterials')
|
|
->where('PackId', $packlineId)
|
|
->update($conarray);
|
|
|
|
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
function update_finalcoproduct($coparray, $coplineId)
|
|
{
|
|
$this->db->table('t_finalproduct_coproduct_materials')
|
|
->where('CoId', $coplineId)
|
|
->update($coparray);
|
|
|
|
|
|
|
|
return TRUE;
|
|
}
|
|
function getEditMaterialAdjustments($AdjustmentId)
|
|
{
|
|
$builder = $this->db->table('t_material_adjustment')
|
|
->select('t_material_adjustment.*,SupplierName,MaterialName,Description,AdjustmentId,ActualQuantity,t_material_stock_history.Quantity,Ref_Type,Transaction_type')
|
|
->join('t_material_stock_history', 't_material_adjustment.AdjustmentId = t_material_stock_history.Ref_No and t_material_stock_history.Ref_Type="Adjust"')
|
|
->join('t_supplierdetailsn', 't_material_adjustment.SupplierID = t_supplierdetailsn.SupplierID')
|
|
->join('t_materialmaster', 't_materialmaster.MaterialCode = t_material_adjustment.MaterialCode')
|
|
->where('t_material_adjustment.AdjustmentId', $AdjustmentId);
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
function material_name()
|
|
{
|
|
$sql = "SELECT distinct MaterialName FROM t_materialmaster;";
|
|
$query = $this->db->query($sql);
|
|
return $query->getResult();
|
|
}
|
|
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->getResult();
|
|
}
|
|
//created by TamilBala
|
|
//for update quantity stockhistory
|
|
function updateQuantityStockHistory($updatequantity, $id)
|
|
{
|
|
$this->db->table('t_material_stock_history')
|
|
->where('Ref_No', $id)
|
|
->where('Ref_Type', 'Adjust')
|
|
->update($updatequantity);
|
|
$r = $this->db->affectedRows();
|
|
//return $r->getResult();
|
|
//echo "HIS";
|
|
|
|
}
|
|
|
|
//created by TamilBala
|
|
//for update quantity t_material_adjustment
|
|
|
|
function updateQuantityAdjusment($updatequantitydes, $id)
|
|
{
|
|
$this->db->table('t_material_adjustment')
|
|
->where('AdjustmentId', $id)
|
|
->update($updatequantitydes);
|
|
|
|
$r = $this->db->affectedRows();
|
|
return $r;
|
|
}
|
|
//created by TamilBala
|
|
//for update isactive t_material_adjustment
|
|
function updateisactiveadjusment($Updateactive, $AdjustmentId)
|
|
{
|
|
$this->db->table('t_material_adjustment')
|
|
->where('AdjustmentId', $AdjustmentId)
|
|
->update($Updateactive);
|
|
|
|
$r = $this->db->affectedRows();
|
|
return $r;
|
|
}
|
|
|
|
//created by TamilBala
|
|
//for update isactive stockhistory
|
|
function updateisactiveastockhistory($Updateactive, $AdjustmentId)
|
|
{
|
|
$this->db->table('t_material_stock_history')
|
|
->where('Ref_No', $AdjustmentId)
|
|
->where('Ref_Type', 'Adjust')
|
|
->update($Updateactive);
|
|
|
|
|
|
$r = $this->db->affectedRows();
|
|
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));
|
|
|
|
//
|
|
|
|
|
|
// return $query->getResultArray();
|
|
|
|
|
|
// }
|
|
|
|
|
|
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,product_description,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 <= ?';
|
|
|
|
|
|
// $subQuery='select FPId as RefID,product_id as ProductCode,Quantity,product_description,Price,ProductDate as Transactiondate,ProductType as TransactionType,product_name from t_finalproduct_master join ip_products on ip_products.product_id= t_finalproduct_master.MaterialCode where MaterialCode=? and ProductDate >= ? and ProductDate <= ?';
|
|
|
|
$query = $this->db->query($subQuery, array($product_id, $starting_date, $end_date));
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
|
|
function SaveFinalHistory($final_history)
|
|
{
|
|
$this->db->transStart();
|
|
$builder = $this->db->table('t_finalproduct_history');
|
|
$builder->insert($final_history);
|
|
|
|
$insert_id = $this->db->affectedRows();
|
|
$this->db->transComplete();
|
|
return true;
|
|
}
|
|
|
|
|
|
function UpdateFinalHistory($final_history, $FPID, $rawmaterial)
|
|
{
|
|
//print_r($final_history);
|
|
$this->db->table('t_finalproduct_history')
|
|
->where('RefID', $FPID)
|
|
->where('ProductCode', $rawmaterial)
|
|
->update($final_history);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
function GetAvgPrice($MaterialCode, $date, $Supplier)
|
|
{
|
|
$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 = ? and SupplierID=?';
|
|
|
|
$query = $this->db->query($subQuery, array($MaterialCode, $Supplier));
|
|
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
|
|
|
|
|
|
function Get_Product_Supplier($MaterialCode, $type)
|
|
{
|
|
//echo $MaterialCode;
|
|
$ltype = '%' . $type . '%';
|
|
//echo $ltype;
|
|
$builder = $this->db->table('t_purchaseorder_master mas')
|
|
->select('mas.SupplierID,sup.SupplierName,mmas.MaterialCode,mmas.MaterialName')
|
|
->join('t_supplierdetailsn sup', 'sup.SupplierID=mas.SupplierID')
|
|
->join('t_purchaseorder_lineitem line', 'line.PONO=mas.PONO')
|
|
->join('t_materialmaster mmas', 'mmas.MaterialCode=line.MaterialCode')
|
|
->where('Category like', $ltype)
|
|
// ->where('t_materialmaster.Category like','%Raw Material%');
|
|
->where('mmas.MaterialCode', $MaterialCode)
|
|
->groupBy('SupplierID');
|
|
$supp = $builder->get();
|
|
return $supp->getResult();
|
|
}
|
|
|
|
|
|
|
|
function getSalesProductvalue()
|
|
{
|
|
$builder = $this->db->table('ip_products')
|
|
->select('product_id,product_price');
|
|
$price = $builder->get();
|
|
return $price->getResult();
|
|
}
|
|
|
|
|
|
|
|
function finyear()
|
|
{
|
|
$sql = "SELECT
|
|
CASE WHEN MONTH(MaterialRcvdDate)>=4
|
|
THEN concat(YEAR(MaterialRcvdDate), '-',YEAR(MaterialRcvdDate)+1)
|
|
ELSE concat(YEAR(MaterialRcvdDate)-1,'-', YEAR(MaterialRcvdDate))
|
|
END AS financial_year
|
|
FROM t_igr_master
|
|
GROUP BY financial_year";
|
|
$query = $this->db->query($sql);
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
function GetStockAbstract($search)
|
|
{
|
|
// echo 'in';
|
|
|
|
$fdate = $search['from_date'];
|
|
$fromdate = date("Y-m-d", strtotime($fdate));
|
|
|
|
$tdate = $search['to_date'];
|
|
$todate = date("Y-m-d", strtotime($tdate));
|
|
|
|
$currentyr = date("Y");
|
|
|
|
|
|
|
|
$finyear = $search['year'];
|
|
|
|
$pieces = explode("-", $finyear); ///fin year
|
|
|
|
$startyr = $pieces['0'];
|
|
$endyr = $pieces['1'];
|
|
|
|
//echo $search['month'].'-'.$startyr.'-'. $endyr;die();
|
|
|
|
|
|
|
|
|
|
$subquery = "SELECT
|
|
DISTINCT(p.MaterialCode) AS ProductID,Ref_No,Date(CreatedOn),mm.MaterialName,stock,MaterialType,Category,stockdate,mm.Category,ip.product_name,ip.product_id,
|
|
SUM(IF(p.Transaction_type='Add',p.Quantity,0)) AS Addition,
|
|
SUM(IF(p.Transaction_type='Reduce',p.Quantity,0)) AS Reduce,
|
|
SUM((IF(p.Transaction_type='Add',p.Quantity,0))-(IF(p.Transaction_type='Reduce',p.Quantity,0))) AS AvailableStock,ROUND(AVG(Rate),2) as Avg_rate,ROUND(AVG(ItemValue),2) as Final_avg
|
|
FROM t_material_stock_history AS p
|
|
LEFT JOIN t_materialmaster mm on mm.MaterialCode = p.MaterialCode
|
|
LEFT JOIN ip_products ip on ip.product_id=p.MaterialCode
|
|
LEFT JOIN t_purchaseorder_lineitem pol on pol.MaterialCode = mm.MaterialCode";
|
|
|
|
|
|
if ($search['month'] == '' && $startyr == '') {
|
|
|
|
|
|
if ($search['from_date'] != '') {
|
|
|
|
$subquery .= " LEFT JOIN (select StockId,pp.MaterialCode mc,
|
|
SUM((IF(pp.Transaction_type='Add',Quantity,0))-(IF(pp.Transaction_type='Reduce',Quantity,0)))
|
|
AS OpeningStock
|
|
FROM t_material_stock_history AS pp
|
|
where pp.CreatedOn < '" . $fromdate . "'
|
|
GROUP BY pp.MaterialCode
|
|
) as opens on opens.mc = p.MaterialCode";
|
|
}
|
|
} else if ($search['month'] != '' && $startyr != '') {
|
|
|
|
|
|
|
|
if ($search['month'] != '') {
|
|
$subquery .= " LEFT JOIN (select StockId,pq.MaterialCode mc,
|
|
SUM((IF(pq.Transaction_type='Add',Quantity,0))-(IF(pq.Transaction_type='Reduce',Quantity,0)))
|
|
AS OpeningStock
|
|
FROM t_material_stock_history AS pq
|
|
where month(pq.CreatedOn) < '" . $search['month'] . "'
|
|
GROUP BY pq.MaterialCode
|
|
) as opens on opens.mc = p.MaterialCode";
|
|
}
|
|
} else if ($search['month'] != '' && $startyr == '') {
|
|
|
|
|
|
|
|
$subquery .= " LEFT JOIN (select StockId,pq.MaterialCode mc,
|
|
SUM((IF(pq.Transaction_type='Add',Quantity,0))-(IF(pq.Transaction_type='Reduce',Quantity,0)))
|
|
AS OpeningStock
|
|
FROM t_material_stock_history AS pq
|
|
where date(pq.CreatedOn) < '" . $currentyr . '-' . $search['month'] . "-01'
|
|
GROUP BY pq.MaterialCode
|
|
) as opens on opens.mc = p.MaterialCode";
|
|
} else if ($search['month'] == '' && $startyr != '') {
|
|
|
|
// if($search['month']!='')
|
|
// {
|
|
$subquery .= " LEFT JOIN (select StockId,pq.MaterialCode mc,
|
|
SUM((IF(pq.Transaction_type='Add',Quantity,0))-(IF(pq.Transaction_type='Reduce',Quantity,0)))
|
|
AS OpeningStock
|
|
FROM t_material_stock_history AS pq
|
|
where date(pq.CreatedOn) < '" . $startyr . "-03-31'
|
|
GROUP BY pq.MaterialCode
|
|
) as opens on opens.mc = p.MaterialCode";
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
//$subquery.=" where mm.IsActive='1'";
|
|
|
|
if ($search['month'] == '' && $startyr == '') {
|
|
|
|
if ($search['from_date'] != '') {
|
|
|
|
$subquery .= " where date(p.CreatedOn)>= '" . $fromdate . "'";
|
|
}
|
|
|
|
if ($search['to_date'] != '') {
|
|
//$subquery. = " and date(p.CreatedOn)<='".$todate."'";
|
|
|
|
$subquery .= " and date(p.CreatedOn)<= '" . $todate . "'";
|
|
}
|
|
} else {
|
|
|
|
if ($search['month'] != '' && $startyr == '') {
|
|
$subquery .= " where date(p.CreatedOn)>= '" . $currentyr . '-' . $search['month'] . "-01' and
|
|
date(p.CreatedOn)<='" . $currentyr . '-' . $search['month'] . "-31'";
|
|
}
|
|
|
|
|
|
if ($search['month'] != '' && $startyr != '') {
|
|
$subquery .= " where month(p.CreatedOn)= '" . $search['month'] . "' and date(p.CreatedOn)>= '" . $startyr . "-04-01' and date(p.CreatedOn)<= '" . $endyr . "-03-31'";
|
|
}
|
|
|
|
if ($startyr != '' && $search['month'] == '') {
|
|
$subquery .= " where date(p.CreatedOn)>= '" . $startyr . "-04-01' and date(p.CreatedOn)<= '" . $endyr . "-03-31'";
|
|
}
|
|
}
|
|
|
|
|
|
$subquery .= " and (mm.Category like '%Consumable%' or mm.Category like '%Raw Material%'
|
|
or mm.Category like '%Packing%' or mm.Category like '%Reclam%' or mm.Category like '%Finish%' or mm.Category like '%Final%' )";
|
|
$subquery .= " GROUP BY p.MaterialCode";
|
|
//$subquery. = "GROUP BY p.MaterialCode";
|
|
|
|
$query = $this->db->query($subquery, array());
|
|
|
|
//print_r($query->getResult());die();
|
|
|
|
die();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
function GetStockAbstractdetails($search)
|
|
{
|
|
// echo 'in';
|
|
|
|
$fdate = $search['fdate'];
|
|
|
|
if ($fdate != '0') {
|
|
$fromdate = date("Y-m-d", strtotime($fdate));
|
|
} else {
|
|
$fromdate = '';
|
|
}
|
|
|
|
$tdate = $search['tdate'];
|
|
|
|
if ($tdate != '0') {
|
|
$todate = date("Y-m-d", strtotime($tdate));
|
|
} else {
|
|
$todate = '';
|
|
}
|
|
//echo $todate;die();
|
|
|
|
$finyear = $search['year'];
|
|
|
|
$pieces = explode("-", $finyear); ///fin year
|
|
//print_r($search); die();
|
|
$startyr = $pieces['0'];
|
|
$endyr = $pieces['1'];
|
|
|
|
//echo $endyr;die();
|
|
|
|
|
|
$subquery = "SELECT
|
|
DISTINCT(p.MaterialCode) AS ProductID,Ref_No,Date(CreatedOn) as Cdate,mm.MaterialName,stock,MaterialType,Category,stockdate,p.Transaction_type,Ref_Type, Ref_No,ip.product_name,invoice_number,
|
|
SUM(IF(p.Transaction_type='Add',Quantity,0)) AS Addition,
|
|
SUM(IF(p.Transaction_type='Reduce',Quantity,0)) AS Reduce,
|
|
SUM((IF(p.Transaction_type='Add',Quantity,0))-(IF(p.Transaction_type='Reduce',Quantity,0))) AS AvailableStock
|
|
FROM
|
|
t_material_stock_history AS p
|
|
LEFT JOIN t_materialmaster mm on mm.MaterialCode = p.MaterialCode
|
|
LEFT JOIN ip_products ip on ip.product_id=p.MaterialCode
|
|
LEFT JOIN ip_invoices inv on inv.invoice_id=p.Ref_No
|
|
where p.MaterialCode='" . $search['materialcode'] . "'";
|
|
|
|
if ($search['month'] == '' && $startyr == '' && $endyr == '') {
|
|
|
|
if ($fromdate != '') {
|
|
|
|
//echo "sv";die();
|
|
|
|
$subquery .= " and date(p.CreatedOn)>= '" . $fromdate . "'";
|
|
}
|
|
|
|
if ($todate != '') {
|
|
//$subquery. = " and date(p.CreatedOn)<='".$todate."'";
|
|
|
|
$subquery .= " and date(p.CreatedOn)<= '" . $todate . "'";
|
|
}
|
|
} else {
|
|
|
|
if ($search['month'] != '') {
|
|
$subquery .= " and month(p.CreatedOn)>= '" . $search['month'] . "'";
|
|
}
|
|
|
|
if ($startyr != '' && $endyr != '') {
|
|
$subquery .= " and date(p.CreatedOn)>= '" . $startyr . "-04-01' and date(p.CreatedOn)<= '" . $endyr . "-03-31'";
|
|
}
|
|
}
|
|
|
|
$subquery .= " GROUP BY p.CreatedOn";
|
|
//$subquery. = "GROUP BY p.MaterialCode";
|
|
|
|
$query = $this->db->query($subquery, array());
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
|
|
public function GetMaterialCode($itemproductid)
|
|
{
|
|
|
|
$builder = $this->db->table('ip_products')
|
|
->select('MaterialCode')
|
|
->where('product_id', $itemproductid);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
|
|
public function Delete_ProductBatchCard($FPId)
|
|
{
|
|
|
|
$this->db->table('t_finalproduct_consumablematerials')->delete(['FPId' => $FPId]);
|
|
|
|
$this->db->table('t_finalproduct_coproduct_materials')->delete(['FPId' => $FPId]);
|
|
|
|
$this->db->table('t_finalproduct_history')->delete(['RefID' => $FPId]);
|
|
|
|
$this->db->table('t_finalproduct_master')->delete(['FPId' => $FPId]);
|
|
|
|
$this->db->table('t_finalproduct_packingmaterials')->delete(['FPId' => $FPId]);
|
|
|
|
$this->db->table('t_finalproduct_rawmaterials')->delete(['FPId' => $FPId]);
|
|
|
|
$this->db->table('t_material_stock_history')->delete(['Ref_No' => $FPId]);
|
|
|
|
return true;
|
|
}
|
|
}
|