ria/app/Controllers/Batchcard.php
2024-09-11 08:54:25 +05:30

2134 lines
77 KiB
PHP
Executable File

<?php
namespace App\Controllers;
use App\Controllers\BaseController;
use App\Models\Batchcard_model;
use App\Models\Inwardgateregister_model;
use App\Models\Rawmaterialdetails_model;
use App\Models\Dashboard_model;
/**
* Module : Batchcard
* Batchcard Class to control all batchcard related operations.
* @author : Gandhimathi
* @version : 1.1
* @since : 13 Nov 2017
* @example : Revised at 15th april 2024
*/
class Batchcard extends BaseController
{
protected $batchcard_model;
protected $inwardgateregister_model;
protected $rawmaterialdetails_model;
protected $dahsboard_model;
protected $session;
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->batchcard_model = new Batchcard_model();
$this->inwardgateregister_model = new Inwardgateregister_model();
$this->rawmaterialdetails_model = new Rawmaterialdetails_model();;
$this->dahsboard_model = new Dashboard_model();
$this->session = session();
$this->isLoggedIn();
helper(['form', 'url']);
date_default_timezone_set('Asia/Kolkata');
}
public function index()
{
$data['emplist'] = $this->batchcard_model->getEmplistforReport();
$this->global['pageTitle'] = 'Hourly Batch Card';
$this->loadViews("hourly_batch_card", $this->global, $data, NULL);
}
function saveHourlyBatchCard()
{
//echo "done";
$data = $this->request->getPost('myData');
// print_r($data);
//echo "*********************";
$reportdate = $data['curdate'];
$reporttime = $data['usr_time'];
$reportdate = format_date($reportdate);//3rd
$open_trp_reading = $data['open_trp_reading'];
$close_trp_reading = $data['close_trp_reading'];
$total_trp_reading = $data['total_trp_reading'];
$auto_start = $data['auto_start'];
$auto_stop = $data['auto_stop'];
$atime = $data['atime'];
$feed30sec = $data['feed30sec'];
$feed1hr = $data['feed1hr'];
$inlet_temp = $data['inlet_temp'];
$outlet_temp = $data['outlet_temp'];
$output_feed_30 = $data['output_feed_30'];
$output_feed_1 = $data['output_feed_1'];
$weight_rough = $data['weight_rough'];
$weight_fine = $data['weight_fine'];
$total = $data['total'];
$cyclone = $data['cyclone'];
$remarks = $data['remarks'];
$cby = $data['cby'];
$approvedby = $data['approvedby'];
//echo "******************************";
$datatostore = array('report_date' => $reportdate, 'report_time' => $reporttime, 'opening_trp_reading' => $open_trp_reading, 'close_trp_reading' => $close_trp_reading, 'total_trp_reading' => $total_trp_reading, 'auto_start' => $auto_start, 'auto_stop' => $auto_stop, 'time' => $atime, 'feed30sec' => $feed30sec, 'feed1hr' => $feed1hr, 'inlet_temp' => $inlet_temp, 'outlet_temp' => $outlet_temp, 'output_feed_30' => $output_feed_30, 'output_feed_1' => $output_feed_1, 'weight_rough' => $weight_rough, 'weight_fine' => $weight_fine, 'total' => $total, 'cyclone' => $cyclone, 'remarks' => $remarks, 'checkedby' => $cby, 'approvedby' => $approvedby);
//print_r($datatostore);die();
$res = $this->batchcard_model->saveHourlyBatchInfo($datatostore);
if ($res == 1) {
echo "<script>alert('Data Saved Successfully!');window.location.href='HourlyListing';</script>";
} else {
echo "<script>alert('Something Went Wrong..!!');window.location.href='HourlyListing';</script>";
}
}
function HourlyListing()
{
$data['allhourdata'] = $this->batchcard_model->getAllHourlyData();
//print_r($data['allhourdata']);die();
$this->global['pageTitle'] = 'Hourly Batch CardListing';
$this->loadViews("hourlybatchcardlisting", $this->global, $data, NULL);
}
function checkExistHour()
{
$bdate = $this->request->getPost('param1');
$btime = $this->request->getPost('param2');
//echo $bdate."-".$btime;
$bdate = format_date($bdate);//3rd
//echo $bdate."-".$btime;
$res = $this->batchcard_model->checkExistHourlyData($bdate, $btime);
if ($res[0]->count == 1) {
echo "Duplicate Entry...!Data Exist for Same Time Information";
}
}
function filterHourlyBatchData()
{
$hid = '';
$from = $this->request->getPost('fromdate');
$to = $this->request->getPost('todate');
$from = format_date($from);//3rd
$to = format_date($to);//3rd
//echo $from.'-'.$to;exit();
$data['allhourdata'] = $this->batchcard_model->getAllHourlyData($hid, $from, $to);
$this->global['pageTitle'] = 'Hourly Batch CardListing';
$this->loadViews("hourlybatchcardlisting", $this->global, $data, NULL);
}
function editHourly()
{
$uri = service('uri');
$hid = $uri->getSegment(3);
$data['emplist'] = $this->batchcard_model->getEmplistforReport();
$data['batchdata'] = $this->batchcard_model->getAllHourlyData($hid);
$this->global['pageTitle'] = 'Edit Hourly Batch Card';
$this->loadViews("edit_hourly_batch_card", $this->global, $data, NULL);
}
function updateHourlyBatchCard()
{
$data = $this->request->getPost('myData');
// print_r($data);
//echo "*********************";
$hid = $data['hid'];
$reportdate = $data['curdate'];
$reporttime = $data['usr_time'];
$reportdate = format_date($reportdate);//3rd
$open_trp_reading = $data['open_trp_reading'];
$close_trp_reading = $data['close_trp_reading'];
$total_trp_reading = $data['total_trp_reading'];
$auto_start = $data['auto_start'];
$auto_stop = $data['auto_stop'];
$atime = $data['atime'];
$feed30sec = $data['feed30sec'];
$feed1hr = $data['feed1hr'];
$inlet_temp = $data['inlet_temp'];
$outlet_temp = $data['outlet_temp'];
$output_feed_30 = $data['output_feed_30'];
$output_feed_1 = $data['output_feed_1'];
$weight_rough = $data['weight_rough'];
$weight_fine = $data['weight_fine'];
$total = $data['total'];
$cyclone = $data['cyclone'];
$remarks = $data['remarks'];
$cby = $data['cby'];
$approvedby = $data['approvedby'];
$datatostore = array('report_date' => $reportdate, 'report_time' => $reporttime, 'opening_trp_reading' => $open_trp_reading, 'close_trp_reading' => $close_trp_reading, 'total_trp_reading' => $total_trp_reading, 'auto_start' => $auto_start, 'auto_stop' => $auto_stop, 'time' => $atime, 'feed30sec' => $feed30sec, 'feed1hr' => $feed1hr, 'inlet_temp' => $inlet_temp, 'outlet_temp' => $outlet_temp, 'output_feed_30' => $output_feed_30, 'output_feed_1' => $output_feed_1, 'weight_rough' => $weight_rough, 'weight_fine' => $weight_fine, 'total' => $total, 'cyclone' => $cyclone, 'remarks' => $remarks, 'checkedby' => $cby, 'approvedby' => $approvedby, 'updatedby' => $cby);
//print_r($datatostore);die();
$res = $this->batchcard_model->updateHourlyBatchInfo($datatostore, $hid);
if ($res == 1) {
echo "<script>alert('Data Saved Successfully!');window.location.href='HourlyListing';</script>";
} else {
echo "<script>alert('Something Went Wrong..!!');window.location.href='HourlyListing';</script>";
}
}
function loadDailyBatchCard()
{
$data['emplist'] = $this->batchcard_model->getEmplistforReport();
$this->global['pageTitle'] = 'Daily Batch Card';
$this->loadViews("dailybatchcard", $this->global, $data, NULL);
}
function dailyListing()
{
$data = array();
$uri = service('uri');
if (empty($uri->getSegment(3))) {
$year = date("Y");
$month = date("m");
// $current = $current."-01";
$data['month'] = $month . '-' . $year;
$data['monthdays'] = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$data['hourdata'] = $this->batchcard_model->getDailyBatchCardData($month);
$data['datefordisplay'] = date('M-Y');
} else {
$fromview = $uri->getSegment(3);
$dmy = explode('-', $fromview);
$fromview_month = date('m', strtotime($dmy[0]));
$fromview_year = $dmy[1];
$data['month'] = $fromview_month . '-' . $fromview_year;
$data['monthdays'] = cal_days_in_month(CAL_GREGORIAN, $fromview_month, $fromview_year);
$data['hourdata'] = $this->batchcard_model->getDailyBatchCardData($fromview_month);
$data['datefordisplay'] = $fromview;
}
//print_r($data['hourdata']);exit();
$this->global['pageTitle'] = 'Daily Batch Card Listing';
$this->loadViews("dailyBatchCardListing", $this->global, $data, NULL);
}
function saveDailyBatchCardData() //T_daily_batchcard_data
{
$ddate = $this->request->getPost('rdate');
$ddate = format_date($ddate);//3rd
$description = $this->request->getPost('description');
$trp_running_hrs = $this->request->getPost('trp_running_hrs');
$feeding_start = $this->request->getPost('feeding_start');
$less_maintenance = $this->request->getPost('less_maintenance');
$less_break_down_hrs = $this->request->getPost('less_break_down_hrs');
$total_burner_running_time = $this->request->getPost('total_burner_running_time');
$total_feeding_hrs = $this->request->getPost('total_feeding_hrs');
// $gas_consumption_per_hour = $this->request->getPost('gas_consumption_per_hour');
// $gas_consumption_per_ton = $this->request->getPost('gas_consumption_per_ton');
// $total_gas_consumption = $this->request->getPost('total_gas_consumption');
$ed_running_hrs = $this->request->getPost('ed_running_hrs');
$ed_receipt = $this->request->getPost('ed_receipt');
$ed_issues = $this->request->getPost('ed_issues');
$rotatry_input = $this->request->getPost('rotary_input');
$rotatry_output = $this->request->getPost('rotatry_output');
$roughsand_receipt = $this->request->getPost('roughsand_receipt');
$roughsand_issues = $this->request->getPost('roughsand_issues');
$finesand_receipt = $this->request->getPost('finesand_receipt');
$finesand_issues = $this->request->getPost('finesand_issues');
$gastrip_receipt = $this->request->getPost('gastrip_receipt');
$gastrip_consumption = $this->request->getPost('gastrip_consumption');
$water_receipt = $this->request->getPost('water_receipt');
$water_consumpiton = $this->request->getPost('water_consumpiton');
$diesel_receipt = $this->request->getPost('diesel_receipt');
$diesel_consumption = $this->request->getPost('diesel_consumption');
$diesel_running_hrs = $this->request->getPost('diesel_running_hrs');
$diesel_rotary_receipt = $this->request->getPost('diesel_rotary_receipt');
$diesel_rotary_consumption = $this->request->getPost('diesel_rotary_consumption');
$diesel_rotary_running_hrs = $this->request->getPost('diesel_rotary_running_hrs');
$open_reading = $this->request->getPost('open_reading');
$close_reading = $this->request->getPost('close_reading');
$engineers = $this->request->getPost('engineers');
$operators = $this->request->getPost('operators');
$helpers = $this->request->getPost('helpers');
// $breakdown = $this->request->getPost('breakdown');
// $location = $this->request->getPost('location');
// $maintenance_description = $this->request->getPost('maintenance_description');
// $maintenance_reason = $this->request->getPost('maintenance_reason');
// $maintenance_time_from = $this->request->getPost('maintenance_time_from');
// $maintenance_time_to = $this->request->getPost('maintenance_time_to');
// $maintenance_total_hrs = $this->request->getPost('maintenance_total_hrs');
// $cost_material = $this->request->getPost('cost_material');
// $cost_labour = $this->request->getPost('cost_labour');
$remarks = $this->request->getPost('remarks');
$createdby = $this->session->get('userId');
$createdtime = get_current_date();
$approvedby = $this->request->getPost('approvedby');
$datatostore = array('ddate' => $ddate, 'description' => $description, 'total_trp_running_hrs' => $trp_running_hrs, 'less_feeding_start' => $feeding_start, 'less_maintenance' => $less_maintenance, 'less_break_down_hrs' => $less_break_down_hrs, 'total_burner_running_time' => $total_burner_running_time, 'total_feeding_hrs' => $total_feeding_hrs, 'ed_running_hrs' => $ed_running_hrs, 'ed_receipt' => $ed_receipt, 'ed_issues' => $ed_issues, 'rotary_input' => $rotatry_input, 'rotary_output' => $rotatry_output, 'trp_roughsand_receipt' => $roughsand_receipt, 'trp_roughsand_issues' => $roughsand_issues, 'trp_finesand_receipt' => $finesand_receipt, 'trp_finesand_issues' => $finesand_issues, 'water_receipt' => $water_receipt, 'water_consumption' => $water_consumpiton, 'diesel_receipt' => $diesel_receipt, 'diesel_consumption' => $diesel_consumption, 'diesel_runninig_hrs' => $diesel_running_hrs, 'diesel_dryer_receipt' => $diesel_rotary_receipt, 'diesel_dryer_consumption' => $diesel_rotary_consumption, 'diesel_dryer_runninig_hrs' => $diesel_rotary_running_hrs, 'power_open_reading' => $open_reading, 'power_close_reading' => $close_reading, 'engineers' => $engineers, 'operators' => $operators, 'helpers' => $helpers, 'gas_for_trip_receipt' => $gastrip_receipt, 'gas_for_trip_consumption' => $gastrip_consumption, 'remarks' => $remarks, 'createdby' => $createdby, 'createdon' => $createdtime, 'approvedby' => $approvedby);
//'total_gas_consumption'=>$total_gas_consumption,'gas_consumption_hr'=>$gas_consumption_per_hour,'gas_consumption_ton'=>$gas_consumption_per_ton,'maintenance_breakdown'=>$breakdown,'maintenance_location'=>$location,'maintenance_description'=>$maintenance_description,'maintenance_reason'=>$maintenance_reason,'maintenance_from_hrs'=>$maintenance_time_from,'maintenance_to_hrs'=>$maintenance_time_to,'maintenance_total_hrs'=>$maintenance_total_hrs,'cost_material'=>$cost_material,'cost_labour'=>$cost_labour
//$datatostore = array('ddate'=>$ddate,'description'=>$description,'total_trp_running_hrs'=>$trp_running_hrs,'less_feeding_start'=>$feeding_start,'less_maintenance'=>$less_maintenance,'less_break_down_hrs'=>$less_break_down_hrs,'total_burner_running_time'=>$total_burner_running_time,'total_feeding_hrs'=>$total_feeding_hrs,'gas_consumption_hr'=>$gas_consumption_per_hour,'gas_consumption_ton'=>$gas_consumption_per_ton,'total_gas_consumption'=>$total_gas_consumption,'ed_running_hrs'=>$ed_running_hrs,'ed_receipt'=>$ed_receipt,'ed_issues'=>$ed_issues,'rotary_input'=>$rotatry_input,'rotary_output'=>$rotatry_output,'trp_roughsand_receipt'=>$roughsand_receipt,'trp_roughsand_issues'=>$roughsand_issues,'trp_finesand_receipt'=>$finesand_receipt,'trp_finesand_issues'=>$finesand_issues,'gas_for_trip_receipt'=>$gastrip_receipt,'gas_for_trip_consumption'=>$gastrip_consumption,'water_receipt'=>$water_receipt,'water_consumption'=>$water_consumpiton,'diesel_receipt'=>$diesel_receipt,'diesel_consumption'=>$diesel_consumption,'diesel_runninig_hrs'=>$diesel_running_hrs,'diesel_dryer_receipt'=>$diesel_rotary_receipt,'diesel_dryer_consumption'=>$diesel_rotary_consumption,'diesel_dryer_runninig_hrs'=>$diesel_rotary_running_hrs,'power_open_reading'=>$open_reading,'power_close_reading'=>$close_reading,'engineers'=>$engineers,'operators'=>$operators,'helpers'=>$helpers,'maintenance_breakdown'=>$breakdown,'maintenance_location'=>$location,'maintenance_description'=>$maintenance_description,'maintenance_reason'=>$maintenance_reason,'maintenance_from_hrs'=>$maintenance_time_from,'maintenance_to_hrs'=>$maintenance_time_to,'maintenance_total_hrs'=>$maintenance_total_hrs,'cost_material'=>$cost_material,'cost_labour'=>$cost_labour,'remarks'=>$remarks,'createdby'=>$createdby,'createdon'=>$createdtime,'approvedby'=>$approvedby);
//print_r($datatostore);
$res = $this->batchcard_model->saveDailyBatchCardData($datatostore);
if ($res == 1) {
echo "<script>alert('Data Saved Successfully..!');window.location.href='dailyListing';</script>";
} else {
echo "<script>alert('Something Went Wrong. Try Again Later..!);window.location.href='dailyListing';</script>";
}
//exit();
}
function checkExistDaily()
{
$rdate = $this->request->getPost('param1');
$rdate = format_date($rdate);//3rd
$res = $this->batchcard_model->checkExistDaily($rdate);
echo $res[0]->count;
}
function getPowerConsumptionDetails()
{
$rdate = $this->request->getPost('param1');
$rdate = format_date($rdate);//3rd
$res = $this->batchcard_model->getPowerConsumptionDetails($rdate);
//print_r($res);exit();
$counut = count($res);
$data['open'] = '';
$data['close'] = '';
$data['start'] = '';
$data['stop'] = '';
for ($i = 0; $i <= $counut; $i++) {
if ($i == 0) {
$data['open'] = $res[$i]->opening_trp_reading;
$data['start'] = $res[$i]->auto_start;
}
if ($i == ($counut - 1)) {
$data['close'] = $res[$i]->close_trp_reading;
$data['stop'] = $res[$i]->auto_stop;
}
}
echo json_encode($data);
}
function editDailyData()
{
$uri = service('uri');
$did = $uri->getSegment(3);
$data['emplist'] = $this->batchcard_model->getEmplistforReport();
$data['dailydata'] = $this->batchcard_model->getIndividualDailyData($did);
$ddate = explode("-", $data['dailydata'][0]->ddate);
$dateval = $ddate[2] . '-' . $ddate[1] . '-' . $ddate[0];
//$data['Maintenances'] = $this->batchcard_model->getmaint_dtl_MntDate($data['dailydata'][0]->ddate);
$data['Maintenances'] = $this->batchcard_model->maintenancesdata($dateval);
//$arraydata = $this->batchcard_model->maintenancesdata($date);
$this->global['pageTitle'] = 'Daily Batch Card Edit';
$this->loadViews("editDailyData", $this->global, $data, NULL);
}
function updateDailyBatchCardData()
{
$did = $this->request->getPost('did');
$ddate = $this->request->getPost('rdate');
$ddate = format_date($ddate);//3rd
$description = $this->request->getPost('description');
$trp_running_hrs = $this->request->getPost('trp_running_hrs');
$feeding_start = $this->request->getPost('feeding_start');
$less_maintenance = $this->request->getPost('less_maintenance');
$less_break_down_hrs = $this->request->getPost('less_break_down_hrs');
$total_burner_running_time = $this->request->getPost('total_burner_running_time');
$total_feeding_hrs = $this->request->getPost('total_feeding_hrs');
// $gas_consumption_per_hour = $this->request->getPost('gas_consumption_per_hour');
// $gas_consumption_per_ton = $this->request->getPost('gas_consumption_per_ton');
// $total_gas_consumption = $this->request->getPost('total_gas_consumption');
$ed_running_hrs = $this->request->getPost('ed_running_hrs');
$ed_receipt = $this->request->getPost('ed_receipt');
$ed_issues = $this->request->getPost('ed_issues');
$rotatry_input = $this->request->getPost('rotary_input');
$rotatry_output = $this->request->getPost('rotatry_output');
$roughsand_receipt = $this->request->getPost('roughsand_receipt');
$roughsand_issues = $this->request->getPost('roughsand_issues');
$finesand_receipt = $this->request->getPost('finesand_receipt');
$finesand_issues = $this->request->getPost('finesand_issues');
$gastrip_receipt = $this->request->getPost('gastrip_receipt');
$gastrip_consumption = $this->request->getPost('gastrip_consumption');
$water_receipt = $this->request->getPost('water_receipt');
$water_consumpiton = $this->request->getPost('water_consumpiton');
$diesel_receipt = $this->request->getPost('diesel_receipt');
$diesel_consumption = $this->request->getPost('diesel_consumption');
$diesel_running_hrs = $this->request->getPost('diesel_running_hrs');
$diesel_rotary_receipt = $this->request->getPost('diesel_rotary_receipt');
$diesel_rotary_consumption = $this->request->getPost('diesel_rotary_consumption');
$diesel_rotary_running_hrs = $this->request->getPost('diesel_rotary_running_hrs');
$open_reading = $this->request->getPost('open_reading');
$close_reading = $this->request->getPost('close_reading');
$engineers = $this->request->getPost('engineers');
$operators = $this->request->getPost('operators');
$helpers = $this->request->getPost('helpers');
// $breakdown = $this->request->getPost('breakdown');
// $location = $this->request->getPost('location');
// $maintenance_description = $this->request->getPost('maintenance_description');
// $maintenance_reason = $this->request->getPost('maintenance_reason');
// $maintenance_time_from = $this->request->getPost('maintenance_time_from');
// $maintenance_time_to = $this->request->getPost('maintenance_time_to');
// $maintenance_total_hrs = $this->request->getPost('maintenance_total_hrs');
// $cost_material = $this->request->getPost('cost_material');
// $cost_labour = $this->request->getPost('cost_labour');
$remarks = $this->request->getPost('remarks');
$createdby = $this->session->get('userId');
$createdtime = get_current_date();
$approvedby = $this->request->getPost('approvedby');
$datatostore = array('ddate' => $ddate, 'description' => $description, 'total_trp_running_hrs' => $trp_running_hrs, 'less_feeding_start' => $feeding_start, 'less_maintenance' => $less_maintenance, 'less_break_down_hrs' => $less_break_down_hrs, 'total_burner_running_time' => $total_burner_running_time, 'total_feeding_hrs' => $total_feeding_hrs, 'ed_running_hrs' => $ed_running_hrs, 'ed_receipt' => $ed_receipt, 'ed_issues' => $ed_issues, 'rotary_input' => $rotatry_input, 'rotary_output' => $rotatry_output, 'trp_roughsand_receipt' => $roughsand_receipt, 'trp_roughsand_issues' => $roughsand_issues, 'trp_finesand_receipt' => $finesand_receipt, 'trp_finesand_issues' => $finesand_issues, 'gas_for_trip_receipt' => $gastrip_receipt, 'gas_for_trip_consumption' => $gastrip_consumption, 'water_receipt' => $water_receipt, 'water_consumption' => $water_consumpiton, 'diesel_receipt' => $diesel_receipt, 'diesel_consumption' => $diesel_consumption, 'diesel_runninig_hrs' => $diesel_running_hrs, 'diesel_dryer_receipt' => $diesel_rotary_receipt, 'diesel_dryer_consumption' => $diesel_rotary_consumption, 'diesel_dryer_runninig_hrs' => $diesel_rotary_running_hrs, 'power_open_reading' => $open_reading, 'power_close_reading' => $close_reading, 'engineers' => $engineers, 'operators' => $operators, 'helpers' => $helpers, 'remarks' => $remarks, 'updatedby' => $createdby, 'approvedby' => $approvedby);
//'gas_consumption_hr'=>$gas_consumption_per_hour,'gas_consumption_ton'=>$gas_consumption_per_ton,'total_gas_consumption'=>$total_gas_consumption,'maintenance_breakdown'=>$breakdown,'maintenance_location'=>$location,'maintenance_description'=>$maintenance_description,'maintenance_reason'=>$maintenance_reason,'maintenance_from_hrs'=>$maintenance_time_from,'maintenance_to_hrs'=>$maintenance_time_to,'maintenance_total_hrs'=>$maintenance_total_hrs,'cost_material'=>$cost_material,'cost_labour'=>$cost_labour,
//print_r($datatostore);
$res = $this->batchcard_model->updateDailyBatchCardData($datatostore, $did);
if ($res == 1) {
echo "<script>alert('Data Saved Successfully..!');window.location.href='dailyListing';</script>";
} else {
echo "<script>alert('Something Went Wrong. Try Again Later..!);window.location.href='dailyListing';</script>";
}
}
function saveAbstractReport()
{
//echo "working";
$overalltotal = 0;
$date = $this->request->getPost('param1');
$cur_day = format_date($date,0,'Y-m');
//echo $date;
$jsondata = $this->request->getPost('param2');
$phpdata = json_decode($jsondata, TRUE);
//print_r($phpdata);
//die();
//$isExist = $this->batchcard_model->checkAbstractReport($date);
$isExist = $this->batchcard_model->checkAbstractReport($cur_day);
$c = $isExist[0]->count;
if ($c == 0) {
foreach ($phpdata as $d) {
$abstract_report_date = $date;
$abstract_details = $d['Particulars'];
$running_hrs = $d['Running Hrs'];
$per_hr = $d['Per Hour'];
$open_stock = $d['Open Stock'];
$receipt = $d['Receipt'];
$total = $d['Total'];
$consumption = $d['Consumption'];
$close_stock = $d['Closing Stock'];
$physical_stock = $d['Physical Stock'];
$difference = $d['Difference'];
$createdby = $this->session->get('userId');
$datatostore = array('abstract_report_date' => $abstract_report_date, 'abstract_details' => $abstract_details, 'running_hrs' => $running_hrs, 'per_hr' => $per_hr, 'open_stock' => $open_stock, 'receipt' => $receipt, 'total' => $total, 'consumption' => $consumption, 'close_stock' => $close_stock, 'physical_stock' => $physical_stock, 'difference' => $difference, 'createdby' => $createdby);
$res = $this->batchcard_model->saveAbstractReport($datatostore);
$overalltotal += $res;
}
} else {
foreach ($phpdata as $d) {
$abstract_report_date = $date;
$abstract_details = $d['Particulars'];
$running_hrs = $d['Running Hrs'];
$per_hr = $d['Per Hour'];
$open_stock = $d['Open Stock'];
$receipt = $d['Receipt'];
$total = $d['Total'];
$consumption = $d['Consumption'];
$close_stock = $d['Closing Stock'];
$physical_stock = $d['Physical Stock'];
$difference = $d['Difference'];
$createdby = $this->session->get('userId');
$datatostore = array('abstract_details' => $abstract_details, 'running_hrs' => $running_hrs, 'per_hr' => $per_hr, 'open_stock' => $open_stock, 'receipt' => $receipt, 'total' => $total, 'consumption' => $consumption, 'close_stock' => $close_stock, 'physical_stock' => $physical_stock, 'difference' => $difference, 'updatedby' => $createdby);
//$res = $this->batchcard_model->updateAbstractReport($datatostore,$date,$abstract_details);
$res = $this->batchcard_model->updateAbstractReport($datatostore, $cur_day, $abstract_details);
$overalltotal += $res;
}
}
echo $overalltotal . ' - Details Saved Successfully..!';
}
function getPreviousMonthAbstractDetails()
{
$month = $this->request->getPost('param1');
$year = $this->request->getPost('param2');
$date = $this->request->getPost('param3');
$currmonthyear = format_date($date,0,'Y-m');
$isExist = $this->batchcard_model->checkAbstractReport($currmonthyear);
$c = $isExist[0]->count;
if ($c == 0) { //echo " for closestock";
$res = $this->batchcard_model->getPreviousMonthAbstractDetails($month, $year);
echo json_encode($res);
} else { //echo " for openstock";
$arr = $this->batchcard_model->getMonthAbstractDetails($currmonthyear);
echo json_encode($arr);
}
}
function getMonthAbstractDetails()
{
$month = $this->request->getPost('param1');
$year = $this->request->getPost('param2');
$arr = $this->batchcard_model->getMonthAbstractDetails($month, $year);
echo json_encode($arr);
}
function getStockDetails()
{
//echo "hi";
if (!empty($this->request->getPost('fromdate')) && $this->request->getPost('stockname')) {
$sn = $this->request->getPost('stockname');
$snforview = $sn;
$fd = $this->request->getPost('fromdate');
$fm = format_date($fd, 0, 'm');
$fy = format_date($fd, 0, 'Y');
$string = $fy . $fm . '01' . 'last month';
$py = format_date($fd, 0, 'Y-m');
$py = explode('-', $py);
// echo 'CURRENT'.$fm.'-'.$fy.'<br>';
// echo 'PREVOIUS'.$py[0].'-'.$py[1].'<br>';
// echo $sn;
switch ($sn) {
case 1:
$sn = '(sum(ed_receipt) - sum(ed_issues)) as lastmonthclosinged';
$sd1 = 'ed_receipt';
$sd2 = 'ed_issues';
break;
case 2:
$sn = '(sum(rotary_input) - sum(rotary_output)) as lastmonthclosingrotary';
$sd1 = 'rotary_input as ed_receipt';
$sd2 = 'rotary_output as ed_issues';
break;
case 3:
$sn = '(sum(diesel_dryer_receipt) - sum(diesel_dryer_consumption)) as lastmonthclosingdryerdiesel';
$sd1 = 'diesel_dryer_receipt as ed_receipt';
$sd2 = 'diesel_dryer_consumption as ed_issues';
break;
case 4:
$sn = '(sum(diesel_receipt) - sum(diesel_consumption)) as lastmonthclosingbull';
$sd1 = 'diesel_receipt as ed_receipt';
$sd2 = 'diesel_consumption as ed_issues';
break;
case 5:
$sn = '(sum(trp_roughsand_receipt) - sum(trp_roughsand_issues)) as lastmonthclosingrough';
$sd1 = 'trp_roughsand_receipt as ed_receipt';
$sd2 = 'trp_roughsand_issues as ed_issues';
break;
case 6:
$sn = '(sum(trp_finesand_receipt) - sum(trp_finesand_issues)) as lastmonthclosingfine';
$sd1 = 'trp_finesand_receipt as ed_receipt';
$sd2 = 'trp_finesand_issues as ed_issues';
break;
case 7:
$sn = '(sum(gas_for_trip_receipt) - sum(gas_for_trip_consumption)) as lastmonthclosinggas';
$sd1 = 'gas_for_trip_receipt as ed_receipt';
$sd2 = 'gas_for_trip_consumption as ed_issues';
break;
case 8:
$sn = '(sum(water_receipt) - sum(water_consumption)) as lastmonthclosingewater';
$sd1 = 'water_receipt as ed_receipt';
$sd2 = 'water_consumption as ed_issues';
break;
}
$data['previousmonthclosingstock'] = $this->batchcard_model->getPreviousMonthClosedStockDetails($py[0], $py[1], $sn);
//print_r($data['previousmonthclosingstock']);echo '<br>';die();
$data['currentmonthstockdetails'] = $this->batchcard_model->currentMonthStockDetails($fm, $fy, $sd1, $sd2);
$data['selmonth'] = $fd;
$data['selstockvalue'] = $snforview;
//print_r($data['currentmonthstockdetails']);echo '<br>';die();
} else {
}
$this->global['pageTitle'] = 'Stock Details';
$this->loadViews("batchcard_stockdetails", $this->global, $data, NULL);
}
function getMaintenancesDetails()
{
$date = $this->request->getPost('id1');
// echo $date;
// die();
$arraydata = $this->batchcard_model->maintenancesdata($date);
if (count($arraydata) != 0) {
echo json_encode($arraydata);
}
}
function getMaintListing()
{
if ($this->request->getPost('btn_submit')) {
$fdate = $this->request->getPost('from_date');
$tdate = $this->request->getPost('to_date');
$type = $this->request->getPost('mySelect');
}
$data['MaintListing'] = $this->batchcard_model->getmaint_dtl($fdate, $tdate, $type);
$this->global['pageTitle'] = 'Maintenance/Breakdown Listing';
$this->loadViews("BatchcardMaintListing", $this->global, $data, NULL);
}
function addMaint()
{
$data['emplist'] = $this->batchcard_model->getEmplistforReport();
$data['supplist'] = $this->batchcard_model->getSupplierlist();
$data['MachineList'] = $this->batchcard_model->getmachine_codename();
$this->global['pageTitle'] = 'Add Maintenance/Breakdown';
$this->loadViews("BatchcardMaintAdd", $this->global, $data, NULL);
}
function editMaint()
{
$uri = service('uri');
$MntID = base64_decode(urldecode($uri->getSegment(3)));
$data['emplist'] = $this->batchcard_model->getEmplistforReport();
$data['MachineList'] = $this->batchcard_model->getmachine_codename();
$data['supplist'] = $this->batchcard_model->getSupplierlist();
$data['MaintEdit'] = $this->batchcard_model->getmaint_dtl_MntID($MntID);
$data['MaintFileEdit'] = $this->batchcard_model->getfiledetails($MntID);
//print_r($data);
$this->global['pageTitle'] = 'Edit Maintenance/Breakdown';
$this->loadViews("BatchcardMaintEdit", $this->global, $data, NULL);
}
function addmntbr()
{
$type = $this->request->getPost('radiobtn');
//$maintenance_date = $this->request->getPost('maintenance_date');
$machinecode = $this->request->getPost('machine');
if ($type == '0') {
$maintenance_subtype = $this->request->getPost('maintenance_subtype');
if ($maintenance_subtype == '1') {
$supplier = $this->request->getPost('supplier');
} else {
$supplier = NULL;
}
} else {
$maintenance_subtype = NULL;
$supplier = NULL;
}
//$maintenance_time= $this->request->getPost('maintenance_time');
$location = $this->request->getPost('location');
$maintenance_description = $this->request->getPost('maintenance_description');
$maintenance_reason = $this->request->getPost('maintenance_reason');
// $maintenance_time_from = $this->request->getPost('maintenance_time_from');
// $maintenance_time_to = $this->request->getPost('maintenance_time_to');
$maintenance_date_time = $this->request->getPost('maintenance_date_time');
$maintenance_date_time = explode(" - ", $maintenance_date_time);
$maintenance_time_from = $maintenance_date_time[0];
$maintenance_time_to = $maintenance_date_time[1];
$maintenance_total_hrs = $this->request->getPost('maintenance_total_hrs');
$cost_material = $this->request->getPost('cost_material');
$cost_labour = $this->request->getPost('cost_labour');
$createdby = $this->session->get('userId');
$approvedby = $this->request->getPost('approvedby');
$workdoneby = $this->request->getPost('workdoneby');
$addmntbr = array('Type' => $type, 'Machine_Code' => $machinecode, 'Maint_Subtype' => $maintenance_subtype, 'Maint_Supplier' => $supplier, 'Maint_Location' => $location, 'Maint_Description' => $maintenance_description, 'Maint_Reason' => $maintenance_reason, 'Maint_Time_from' => $maintenance_time_from, 'Maint_Time_to' => $maintenance_time_to, 'Maint_Total_hrs' => $maintenance_total_hrs, 'Cost_Material' => $cost_material, 'Cost_Labour' => $cost_labour, 'WorkDone_By' => $workdoneby, 'Approved_By' => $approvedby, 'CreatedBy' => $createdby);
//'Maint_Date'=>$maintenance_date,'Maint_Time'=>$maintenance_time,
//print_r($addmntbr);
//die();
$added = $this->batchcard_model->addmaint_dtl($addmntbr);
$maint_id = '';
if (count($added) > 0) {
foreach ($added as $key) {
$maint_id = $key->Maint_ID;
}
}
$count = $this->request->getPost('hidecounter');
$constant = $this->request->getPost('hideconstant');
for ($i = 1; $i <= $constant; $i++) {
$pathname = 'browseFiles' . $i;
if (!empty($_FILES[$pathname]['name'])) {
$varname = 'filename' . $i;
$temp = $this->request->getPost($varname);
$Picture = $this->add($pathname);
$arr[] = array($temp, $Picture);
}
}
foreach ($arr as $ma) {
$index = 0;
foreach ($ma as $key => $value) {
$index++;
if ($index == 1) {
$file_descrpition = $value;
}
if ($index == 2) {
$filename = $value;
}
}
$addfilelist = array(
'Machine_code/Maint_id' => $maint_id,
'File_name' => $filename,
'Status' => "1",
'Status_description' => ($type == '0') ? ('Maintenaces related files') : ('Breakdown related files')
);
$this->batchcard_model->addfiledetails($addfilelist);
//print_r($addfilelist);
//die();
}
if (count($added) > 0) {
echo "<script>alert('Saved Successfully!');window.location.href='getMaintListing';</script>";
}
//print_r($addmntbr);
}
function editmntbr()
{
$type = $this->request->getPost('radiobtn');
$mntid = $this->request->getPost('mntid');
$machinecode = $this->request->getPost('machine');
if ($type == '0') {
$maintenance_subtype = $this->request->getPost('maintenance_subtype');
if ($maintenance_subtype == '1') {
$supplier = $this->request->getPost('supplier');
} else {
$supplier = NULL;
}
} else {
$maintenance_subtype = NULL;
$supplier = NULL;
}
// $maintenance_date = $this->request->getPost('maintenance_date');
// $maintenance_time= $this->request->getPost('maintenance_time');
$location = $this->request->getPost('location');
$maintenance_description = $this->request->getPost('maintenance_description');
$maintenance_reason = $this->request->getPost('maintenance_reason');
// $maintenance_time_from = $this->request->getPost('maintenance_time_from');
// $maintenance_time_to = $this->request->getPost('maintenance_time_to');
$maintenance_date_time = $this->request->getPost('maintenance_date_time');
$maintenance_date_time = explode(" - ", $maintenance_date_time);
$maintenance_time_from = $maintenance_date_time[0];
$maintenance_time_to = $maintenance_date_time[1];
$maintenance_total_hrs = $this->request->getPost('maintenance_total_hrs');
$cost_material = $this->request->getPost('cost_material');
$cost_labour = $this->request->getPost('cost_labour');
$updatedby = $this->session->get('userId');
$approvedby = $this->request->getPost('approvedby');
$workdoneby = $this->request->getPost('workdoneby');
// $date = get_current_date_time();
// $updatedon = get_current_date_time();
$editmntbr = array('Type' => $type, 'Machine_Code' => $machinecode, 'Maint_Subtype' => $maintenance_subtype, 'Maint_Supplier' => $supplier, 'Maint_Location' => $location, 'Maint_Description' => $maintenance_description, 'Maint_Reason' => $maintenance_reason, 'Maint_Time_from' => $maintenance_time_from, 'Maint_Time_to' => $maintenance_time_to, 'Maint_Total_hrs' => $maintenance_total_hrs, 'Cost_Material' => $cost_material, 'Cost_Labour' => $cost_labour, 'WorkDone_By' => $workdoneby, 'Approved_By' => $approvedby, 'UpdatedBy' => $updatedby);
//'Maint_Date'=>$maintenance_date,'Maint_Time'=>$maintenance_time,
//print_r($editmntbr);
//die();
// echo $type;
// echo $mntid;
// die();
$updated = $this->batchcard_model->updatemaint_dtl($editmntbr, $mntid);
$count = $this->request->getPost('hidecounter');
$constant = $this->request->getPost('hideconstant');
for ($i = 1; $i <= $constant; $i++) {
$pathname = 'browseFiles' . $i;
if (!empty($_FILES[$pathname]['name'])) {
$varname = 'filename' . $i;
$temp = $this->request->getPost($varname);
$Picture = $this->add($pathname);
$arr[] = array($temp, $Picture);
}
}
foreach ($arr as $ma) {
$index = 0;
foreach ($ma as $key => $value) {
$index++;
if ($index == 1) {
$file_descrpition = $value;
}
if ($index == 2) {
$filename = $value;
}
}
$addfilelist = array(
'Machine_code/Maint_id' => $mntid,
'File_name' => $filename,
'Status' => "1",
'Status_description' => ($type == '0') ? ('Maintenaces files') : ('Breakdown files')
);
$this->batchcard_model->addfiledetails($addfilelist);
//$updatefilelist= array_filter(array_map('array_filter',$updatefilelist ));
}
if ($updated >= 0) {
echo "<script>alert('Saved Successfully!');window.location.href='HourlyListing';</script>";
}
}
function getHistListing()
{
$data['HistListing'] = $this->batchcard_model->getHist_mstr();
$this->global['pageTitle'] = 'Machine Master/History Listing';
$this->loadViews("BatchcardHistListing", $this->global, $data, NULL);
}
function getPODtls()
{
$pono = $this->request->getPost('id');
$podtls = $this->batchcard_model->getpo_dtls($pono);
echo json_encode($podtls);
}
function addHist()
{
$data['HistDeptList'] = $this->batchcard_model->getdept_dtls();
$data['HistPONOList'] = $this->batchcard_model->getpono();
$this->global['pageTitle'] = 'Add Machine Master/History ';
$this->loadViews("BatchcardHistAdd", $this->global, $data, NULL);
}
function autocomplete()
{
$mc = $this->request->getGet('query');
$query = $this->batchcard_model->checkMachineCategory($mc);
echo json_encode($query);
}
function add($pathname)
{
// echo "add files";
// die();
// echo $pathname;
$picture = '';
if (!empty($_FILES[$pathname]['name'])) {
$config['upload_path'] = 'public/uploads/images/';
$config['allowed_types'] = '*';
//$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['file_name'] = $_FILES[$pathname]['name'];
//print_r($config);
//Load upload library and initialize configuration
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload($pathname)) {
$uploadData = $this->upload->data();
$picture = $uploadData['file_name'];
} else {
$error = array('error' => $this->upload->display_errors());
$picture = '';
}
} else {
$picture = '';
}
return $picture;
}
function addHist_mstr()
{
$machinename = $this->request->getPost('mach_name');
$make = $this->request->getPost('tomake');
$capacity = $this->request->getPost('machs_capacity');
$machs_category = $this->request->getPost('machs_category');
$category = ($machs_category !== null && is_string($machs_category)) ? strtoupper($machs_category) : '';
$categoryarray = $this->batchcard_model->getmachineCategory();
foreach ($categoryarray as $mc) {
$TempArr[] = $mc->ConfigValue;
}
if (in_array($category, $TempArr)) {
} else {
$configcode = 'C028';
$config = array('Config_ID' => $configcode, 'ConfigValue' => $category);
$query = $this->batchcard_model->insertvalueintoconfig($config);
}
$dept = $this->request->getPost('machs_dept');
$location = $this->request->getPost('machs_locn');
$PONO = $this->request->getPost('machs_pono');
$POdate = $this->request->getPost('machs_podate');
$supplier = $this->request->getPost('machs_supplier');
$instalizationdate = $this->request->getPost('install_date');
$machineslifetime = $this->request->getPost('machs_lifetime');
$commencementdate = $this->request->getPost('machs_comm_date');
$createdby = $this->session->get('userId');
$add = array(
'Machine_Name' => $machinename,
'Machines_Make' => $make,
'Machines_Capacity' => $capacity,
'Machines_Category' => $category,
'Machines_Dept' => $dept,
'Factory_Loc' => $location,
'Machines_PONO' => $PONO,
'Machines_POdate' => $POdate,
'Machines_Supplier' => $supplier,
'Instalization_Date' => $instalizationdate,
'Machines_Lifetime' => $machineslifetime,
'Commencement_Date' => $commencementdate,
'CreatedBy' => $createdby
);
$addedmaster = $this->batchcard_model->addhist_mstr($add);
$mach_code = '';
if (count($addedmaster) > 0) {
foreach ($addedmaster as $key) {
$mach_code = $key->Machine_Code;
}
}
$count = $this->request->getPost('hidecounter');
$constant = $this->request->getPost('hideconstant');
for ($i = 1; $i <= $constant; $i++) {
$pathname = 'browseFiles' . $i;
if (!empty($_FILES[$pathname]['name'])) {
$varname = 'filename' . $i;
$temp = $this->request->getPost($varname);
$Picture = $this->add($pathname);
$arr[] = array($temp, $Picture);
}
}
foreach ($arr as $ma) {
$index = 0;
foreach ($ma as $key => $value) {
$index++;
if ($index == 1) {
$file_descrpition = $value;
}
if ($index == 2) {
$filename = $value;
}
}
$addfilelist = array(
'Machine_code/Maint_id' => $mach_code,
'File_name' => $filename,
'Status' => "0",
'Status_description' => "Machine file"
);
$this->batchcard_model->addfiledetails($addfilelist);
//print_r($addfilelist);
//die();
}
$range = $this->request->getPost('machs_range');
$operatingrange = $this->request->getPost('machs_operating_range');
$leastcount = $this->request->getPost('machs_least_count');
$calibrationagency = $this->request->getPost('machs_calibration_agency');
$Calibrationon = $this->request->getPost('machs_calibration_on');
$Calibrationdue = $this->request->getPost('machs_calibration_due');
if ($category == 'LAB') {
$Acctcriteria = $this->request->getPost('machs_acceptence_criteria');
} else {
$Acctcriteria = NULL;
}
$addchild = array(
'Machine_Code' => $mach_code,
'Machine_Name' => $machinename,
'Range' => $range,
'Operating_Range' => $operatingrange,
'Least_Count' => $leastcount,
'Calibration_Agency' => $calibrationagency,
'Calibration_On' => $Calibrationon,
'Calibration_Due' => $Calibrationdue,
'Acceptence_Criteria' => $Acctcriteria
);
$addedchild = $this->batchcard_model->addhist_dtl($addchild);
echo "<script>alert('Saved Successfully!');window.location.href='getHistListing';</script>";
}
function editHist()
{
//echo 'i am a edit function';
//$MachineCode = $_GET['Machcode'];
$uri = service('uri');
$MachineCode = base64_decode(urldecode($uri->getSegment(3)));
//echo $MachineCode;
$data['TableDatas'] = $this->batchcard_model->getHist_tbls($MachineCode);
$data['HistMstrEdit'] = $this->batchcard_model->getHist_mstr($MachineCode);
$data['HistDtlsEdit'] = $this->batchcard_model->getHist_dtls($MachineCode);
$data['HistFileEdit'] = $this->batchcard_model->getfiledetails($MachineCode);
$data['HistDeptList'] = $this->batchcard_model->getdept_dtls();
$data['HistPONOList'] = $this->batchcard_model->getpono();
//echo count($data['HistFileEdit']);
//echo "<br>";
//echo sizeof($data['HistFileEdit']);
$this->global['pageTitle'] = 'Edit Machine Master/History ';
$this->loadViews("BatchcardHistEdit", $this->global, $data, NULL);
}
function Removefiledetails()
{
$id = $this->request->getPost('id');
$name = $this->request->getPost('name');
$deletedata = $this->batchcard_model->deletefiledetails($id, $name);
echo $deletedata;
}
function editHist_mstr()
{
$code_and_name = $this->request->getPost('mach_name');
$machcn = explode("-", $code_and_name);
//$machinename = $machcn[1];
$machinecode = $machcn[0];
$make = $this->request->getPost('tomake');
$capacity = $this->request->getPost('machs_capacity');
$machs_category = $this->request->getPost('machs_category');
$category = ($machs_category !== null && is_string($machs_category)) ? strtoupper($machs_category) : '';
$categoryarray = $this->batchcard_model->getmachineCategory();
foreach ($categoryarray as $mc) {
$TempArr[] = $mc->ConfigValue;
}
if (in_array($category, $TempArr)) {
} else {
$configcode = 'C028';
$config = array('Config_ID' => $configcode, 'ConfigValue' => $category);
$query = $this->batchcard_model->insertvalueintoconfig($config);
}
$dept = $this->request->getPost('machs_dept');
$location = $this->request->getPost('machs_locn');
$PONO = $this->request->getPost('machs_pono');
$POdate = $this->request->getPost('machs_podate');
$supplier = $this->request->getPost('machs_supplier');
$instalizationdate = $this->request->getPost('install_date');
$machineslifetime = $this->request->getPost('machs_lifetime');
$commencementdate = $this->request->getPost('machs_comm_date');
$updatedby = $this->session->get('userId');
$update = array(
//'Machine_Name' => $machinename,
'Machines_Make' => $make,
'Machines_Capacity' => $capacity,
'Machines_Category' => $category,
'Machines_Dept' => $dept,
'Factory_Loc' => $location,
'Machines_PONO' => $PONO,
'Machines_POdate' => $POdate,
'Machines_Supplier' => $supplier,
'Instalization_Date' => $instalizationdate,
'Machines_Lifetime' => $machineslifetime,
'Commencement_Date' => $commencementdate,
'UpdatedBy' => $updatedby
);
$updatedmaster = $this->batchcard_model->edithist_mstr($update, $machinecode);
$range = $this->request->getPost('machs_range');
$operatingrange = $this->request->getPost('machs_operating_range');
$leastcount = $this->request->getPost('machs_least_count');
$calibrationagency = $this->request->getPost('machs_calibration_agency');
$Calibrationon = $this->request->getPost('machs_calibration_on');
$Calibrationdue = $this->request->getPost('machs_calibration_due');
if ($category == 'LAB') {
$Acctcriteria = $this->request->getPost('machs_acceptence_criteria');
} else {
$Acctcriteria = NULL;
}
$updatechild = array(
//'Machine_Code' => $machinecode,
//'Machine_Name'=> $machinename,
'Range' => $range,
'Operating_Range' => $operatingrange,
'Least_Count' => $leastcount,
'Calibration_Agency' => $calibrationagency,
'Calibration_On' => $Calibrationon,
'Calibration_Due' => $Calibrationdue,
'Acceptence_Criteria' => $Acctcriteria
);
//print_r($updatechild);
//die();
$updatedchild = $this->batchcard_model->edithist_dtl($updatechild, $machinecode);
$count = $this->request->getPost('hidecounter');
$constant = $this->request->getPost('hideconstant');
for ($i = 1; $i <= $constant; $i++) {
$pathname = 'browseFiles' . $i;
if (!empty($_FILES[$pathname]['name'])) {
$varname = 'filename' . $i;
$temp = $this->request->getPost($varname);
$Picture = $this->add($pathname);
$arr[] = array($temp, $Picture);
}
}
foreach ($arr as $ma) {
$index = 0;
foreach ($ma as $key => $value) {
$index++;
if ($index == 1) {
$file_descrpition = $value;
}
if ($index == 2) {
$filename = $value;
}
}
$addfilelist = array(
'Machine_code/Maint_id' => $machinecode,
'File_name' => $filename,
'Status' => "0",
'Status_description' => "Machine File"
);
$this->batchcard_model->addfiledetails($addfilelist);
//$updatefilelist= array_filter(array_map('array_filter',$updatefilelist ));
}
echo "<script>alert('Saved Successfully!');window.location.href='getHistListing';</script>";
//echo "<script>alert('Saved Successfully); window.location.href='getHistListing';</script>";
}
function FinalProductCalculation()
{
$data['inv_final_product'] = $this->batchcard_model->getinvoice_products();
$data['consumable_material'] = $this->batchcard_model->get_consumablematerials();
$data['Raw_material'] = $this->batchcard_model->get_rawmaterials();
$data['Pack_material'] = $this->batchcard_model->get_packmaterials();
$data['rawsupplier'] = $this->batchcard_model->Rawsupplier();
$data['consusupplier'] = $this->batchcard_model->Consupplier();
$data['packsupplier'] = $this->batchcard_model->Pacsupplier();
$data['stock_value'] = $this->batchcard_model->getStockValue();
$data['Records'] = $this->rawmaterialdetails_model->reOrderListing();
$data['productprices'] = $this->batchcard_model->getSalesProductvalue();
$data['reclaation'] = $this->batchcard_model->GetReclamationMaterial();
//echo count($data['rawsupplier']);die();
$this->global['pageTitle'] = 'Finished Product Batch Card';
$this->loadViews("FinalProduct", $this->global, $data, NULL);
}
function EditFinalProduct()
{
$FPId = $_GET['FPId'];
$data['check'] = $_GET['check'];
$data['masterproduct'] = $this->batchcard_model->getmasterProductDetails($FPId);
$data['rawmaterial'] = $this->batchcard_model->getrawmaterialDetails($FPId);
$data['consumaterial'] = $this->batchcard_model->getconsumaterialDetails($FPId);
$data['packagematerial'] = $this->batchcard_model->getpackagematerialDetails($FPId);
$data['coproductmaterial'] = $this->batchcard_model->getcoproductmaterial($FPId);
$data['inv_final_product'] = $this->batchcard_model->getinvoice_products();
$data['consumable_material'] = $this->batchcard_model->get_consumablematerials();
$data['Raw_material'] = $this->batchcard_model->get_rawmaterials();
$data['Pack_material'] = $this->batchcard_model->get_packmaterials();
$data['supplier'] = $this->batchcard_model->getSupplierlist();
$data['stock_value'] = $this->batchcard_model->getStockValue();
$data['reclaation'] = $this->batchcard_model->GetReclamationMaterial();
$data['Records'] = $this->rawmaterialdetails_model->reOrderListing();
$data['rawsupplier'] = $this->batchcard_model->Rawsupplier();
$data['consusupplier'] = $this->batchcard_model->Consupplier();
$data['packsupplier'] = $this->batchcard_model->Pacsupplier();
$this->global['pageTitle'] = 'Finished Product Batch Card';
$this->loadViews("editFinalProduct", $this->global, $data, NULL);
// $this->loadViews("finaledit", $this->global,$data,NULL);
}
function FinalProductlisting()
{
$data['final_product'] = $this->batchcard_model->getFinalProductDetaisl();
$this->global['pageTitle'] = 'Finished Product Batch Card Listing';
$this->loadViews("FinalProductlisting", $this->global, $data, NULL);
}
function FinalProductHistory()
{
$data['inv_final_product'] = $this->batchcard_model->getinvoice_products();
$this->global['pageTitle'] = 'Finished Product Batch Card History';
$this->loadViews("FinalProductHistory", $this->global, $data, NULL);
}
function MaterailAdjustment()
{
$data['MaterialCode'] = $this->batchcard_model->getMaterial();
$data['Supplier'] = $this->batchcard_model->getSupplierlist();
$data['stock_value'] = $this->batchcard_model->getStockValue();
$this->global['pageTitle'] = 'Material Adjustment';
$this->loadViews("materialadjustment", $this->global, $data, NULL);
}
function MaterailAdjustmentlist()
{
$data['materailAdjustmentlist'] = $this->batchcard_model->getAllMaterialAdjustments();
$this->global['pageTitle'] = 'Material Adjustment';
$this->loadViews("materialadjustmentlist", $this->global, $data, NULL);
}
function getQuantity()
{
$MaterialCode = $this->request->getPost('materialcode');
$date = $this->request->getPost('date');
$Supplier = $this->request->getPost('Supplier');
$netQtyarray = $this->batchcard_model->GetNetQty($MaterialCode, $date, $Supplier);
echo json_encode($netQtyarray);
//print_r($netQtyarray);
// echo $MaterialCode;
// echo $date;
// echo $Supplier;
}
function getFinishedProduct()
{
$starting_date = $this->request->getPost('from_date');
$end_date = $this->request->getPost('to_date');
$product_id = $this->request->getPost('productid');
$productlist = $this->batchcard_model->GetFinishedProductList($starting_date, $end_date, $product_id);
$obj = json_encode($productlist);
echo $obj;
//print_r($productlist);
}
// function displaying_stockvalues()
// {
// $MaterialCode = $this->request->getPost('MaterialCode');
// $date = $this->request->getPost('date');
// $Qtyarray = $this->batchcard_model->GettotalQty($MaterialCode,$date);
// //print_r($Qtyarray);
// $obj=json_encode($Qtyarray);
// echo $obj;
// }
function displaying_stockvalues()
{
$AdjustmentId = $this->request->getPost('AdjustmentId');
$historydetais = $this->batchcard_model->GetMaterialHistory($AdjustmentId);
$SupplierID = '';
// if(!empty($historydetais))
// {
// foreach($historydetais as $hi)
// {
// $SupplierID = $hi->SupplierID;
// }
// }
$obj = json_encode($historydetais);
echo $obj;
}
function addNewMaterialHistory()
{
$supplier = $this->request->getPost('supplier');
$materialcode = $this->request->getPost('materialcode');
$date = $this->request->getPost('date');
$ActualQty = $this->request->getPost('ActualQty');
$Qty = $this->request->getPost('AdjustableQty');
$reason = $this->request->getPost('reason');
$Description = $this->request->getPost('Description');
$status = $this->request->getPost('transtatus');
$CreatedBy = $this->session->get('userId');
$absaluteQty = ($Qty !== null && is_numeric($Qty)) ? abs($Qty) :null;
$Isactive = 1;
// echo $Qty;
// echo "abs";
// echo abs($Qty);
//die();
$createddt = get_current_date_time();
//echo $dt;
// echo $createddt;
// die();
$adjustmentaarray = array(
'MaterialCode' => $materialcode, 'ActualQuantity' => $ActualQty, 'Quantity' => $absaluteQty, 'SupplierID' => $supplier, 'Reason' => $reason, 'Description' => $Description, 'CreatedOn' => $createddt,
'CreatedBy' => $CreatedBy, 'Isactive' => $Isactive
);
$materialadjust = $this->batchcard_model->AddmaterialAdjustment($adjustmentaarray);
$adjustId = '';
if (!empty($materialadjust)) {
foreach ($materialadjust as $ig) {
$adjustId = $ig->AdjustmentId;
}
}
$historytable = array('SupplierID' => $supplier, 'MaterialCode' => $materialcode, 'Transaction_type' => $status, 'Ref_Type' => 'Adjust', 'Quantity' => $absaluteQty, 'CreatedBy' => $CreatedBy, 'CreatedOn' => $createddt, 'Ref_No' => $adjustId, 'Isactive' => $Isactive);
$historyadd = $this->batchcard_model->AddMaterialHistory($historytable);
$get_pre_qty = $this->inwardgateregister_model->get_CurrentQty($materialcode);
$av_qty = 0;
if (!empty($get_pre_qty)) {
foreach ($get_pre_qty as $gt) {
$av_qty = $gt->Current_stock;
}
}
if ($status == 'Add') {
$currentav_qty = $av_qty + $absaluteQty;
} else if ($status == 'Reduce') {
$currentav_qty = $av_qty - $absaluteQty;
}
$current_qty = array('Current_stock' => $currentav_qty);
$this->inwardgateregister_model->addmaterialmaster($current_qty, $materialcode);
if ((count($materialadjust) > 0) && ($historyadd !== null)) {
echo "Material Details Added Successfully";
} else {
echo "Something Went Wrong,Please Try Again";
}
}
function Final_Product_Save()
{
$final_product = $this->request->getPost('DEPTFN');
$final_qty = $this->request->getPost('Quantity');
$product_date = $this->request->getPost('Date');
//$pdt = $product_date->format('Y-m-d');
$pdt = format_date($product_date,0,'Y-m-d');
$product_value = $this->request->getPost('values');
$createdby = $this->session->get('userId');
$final_master = array('MaterialCode' => $final_product, 'Quantity' => $final_qty, 'Price' => $product_value, 'CreatedBy' => $createdby, 'ProductDate' => $pdt, 'ProductType' => 'Inward');
$final_master_save = $this->batchcard_model->insert_final_product($final_master);
//$final_product_id= $final_master_save[0]['PId'];
$createddt = get_current_date_time();
if (!empty($final_master_save)) {
foreach ($final_master_save as $pm) {
$final_product_id = $pm->PId;
}
}
$final_history = array('RefID' => $final_product_id, 'ProductCode' => $final_product, 'Quantity' => $final_qty, 'Price' => $product_value, 'Transactiondate' => $createddt, 'TransactionType' => 'Inward');
$final_history_save = $this->batchcard_model->SaveFinalHistory($final_history);
$Getmaterial_code = $this->batchcard_model->GetMaterialCode($final_product);
$material_code = '';
foreach ($Getmaterial_code as $mas) {
$material_code = $mas->MaterialCode;
}
$finalproducthistory = array('MaterialCode' => $material_code, 'Transaction_type' => 'Add', 'Ref_Type' => 'Final Product', 'Ref_No' => $final_product_id, 'Quantity' => $final_qty, 'ItemValue' => $product_value, 'CreatedBy' => $createdby, 'CreatedOn' => $createddt);
$this->batchcard_model->save_rawmaterialto_materialHistory($finalproducthistory);
$rawilne = $this->request->getPost('RawRow');
$consuline = $this->request->getPost('ConsuRow');
$packline = $this->request->getPost('PkgRow');
$coproline = $this->request->getPost('CopRow');
//echo $coproline;
for ($i = 1; $i <= $rawilne; $i++) {
$rawmaterial = $this->request->getPost('rawmaterialcode' . $i);
$rawsupplier = $this->request->getPost('rawSupplierID' . $i);
$rawqty = $this->request->getPost('rawQty' . $i);
$rawvalue = $this->request->getPost('rawprice' . $i);
$rawarray = array('FPId' => $final_product_id, 'MaterialCode' => $rawmaterial, 'SupplierID' => $rawsupplier, 'Quantity' => $rawqty, 'Price' => $rawvalue, 'CreatedBy' => $createdby, 'CreatedDate' => $createddt);
$rawmaterialhistory = array('MaterialCode' => $rawmaterial, 'Transaction_type' => 'Reduce', 'Ref_Type' => 'Final Product', 'Ref_No' => $final_product_id, 'SupplierID' => $rawsupplier, 'Quantity' => $rawqty, 'ItemValue' => $rawvalue, 'CreatedBy' => $createdby, 'CreatedOn' => $createddt);
$this->batchcard_model->save_rawmaterialto_materialHistory($rawmaterialhistory);
$rawget_pre_qty = $this->inwardgateregister_model->get_CurrentQty($rawmaterial);
$av_qty = 0;
if (!empty($rawget_pre_qty)) {
foreach ($rawget_pre_qty as $gt) {
$av_qty = $gt->Current_stock;
}
}
$currentav_qty = $av_qty - $rawqty;
$current_qty = array('Current_stock' => $currentav_qty);
$this->inwardgateregister_model->addmaterialmaster($current_qty, $rawmaterial);
//print_r($rawarray);
$this->batchcard_model->save_finalraw($rawarray);
}
for ($i = 1; $i <= $consuline; $i++) {
$conmaterial = $this->request->getPost('consumematerialcode' . $i);
$consupplier = $this->request->getPost('consumeSupplierID' . $i);
$conqty = $this->request->getPost('consumeQty' . $i);
$convalue = $this->request->getPost('consumeprice' . $i);
$conarray = array('FPId' => $final_product_id, 'MaterialCode' => $conmaterial, 'SupplierID' => $consupplier, 'Quantity' => $conqty, 'Price' => $convalue, 'CreatedBy' => $createdby, 'CreatedDate' => $createddt);
$consuhistory = array('MaterialCode' => $conmaterial, 'Transaction_type' => 'Reduce', 'Ref_Type' => 'Final Product', 'Ref_No' => $final_product_id, 'SupplierID' => $consupplier, 'Quantity' => $conqty, 'ItemValue' => $convalue, 'CreatedBy' => $createdby, 'CreatedOn' => $createddt);
$this->batchcard_model->save_rawmaterialto_materialHistory($consuhistory);
$conget_pre_qty = $this->inwardgateregister_model->get_CurrentQty($conmaterial);
$conav_qty = 0;
if (!empty($conget_pre_qty)) {
foreach ($conget_pre_qty as $gt) {
$conav_qty = $gt->Current_stock;
}
}
$concurrentav_qty = $conav_qty - $conqty;
$concurrent_qty = array('Current_stock' => $concurrentav_qty);
$this->inwardgateregister_model->addmaterialmaster($concurrent_qty, $conmaterial);
$this->batchcard_model->save_finalcon($conarray);
}
for ($i = 1; $i <= $packline; $i++) {
$packmaterial = $this->request->getPost('packmaterialcode' . $i);
$packsupplier = $this->request->getPost('packSupplierID' . $i);
$packqty = $this->request->getPost('packQty' . $i);
$packvalue = $this->request->getPost('packprice' . $i);
$packarray = array('FPId' => $final_product_id, 'MaterialCode' => $packmaterial, 'SupplierID' => $packsupplier, 'Quantity' => $packqty, 'Price' => $packvalue, 'CreatedBy' => $createdby, 'CreatedDate' => $createddt);
$packmathistory = array('MaterialCode' => $packmaterial, 'Transaction_type' => 'Reduce', 'Ref_Type' => 'Final Product', 'Ref_No' => $final_product_id, 'SupplierID' => $packsupplier, 'Quantity' => $packqty, 'ItemValue' => $packvalue, 'CreatedBy' => $createdby, 'CreatedOn' => $createddt);
$this->batchcard_model->save_rawmaterialto_materialHistory($packmathistory);
$pacget_pre_qty = $this->inwardgateregister_model->get_CurrentQty($packmaterial);
$pacav_qty = 0;
if (!empty($pacget_pre_qty)) {
foreach ($pacget_pre_qty as $gt) {
$pacav_qty = $gt->Current_stock;
}
}
$paccurrentav_qty = $pacav_qty - $packqty;
$paccurrent_qty = array('Current_stock' => $paccurrentav_qty);
$this->inwardgateregister_model->addmaterialmaster($paccurrent_qty, $packmaterial);
$this->batchcard_model->save_finalpacking($packarray);
}
for ($i = 1; $i <= $coproline; $i++) {
$copmaterial = $this->request->getPost('Copmaterialcode' . $i);
$codate = $this->request->getPost('CopDate' . $i);
$copqty = $this->request->getPost('CopQty' . $i);
$copvalue = $this->request->getPost('Copprice' . $i);
$coparray = array('FPId' => $final_product_id, 'MaterialCode' => $copmaterial, 'CoDate' => $codate, 'Quantity' => $copqty, 'Price' => $copvalue, 'CreatedBy' => $createdby, 'CreatedDate' => $createddt);
// print_r($coparray);
$this->batchcard_model->save_finalcoproduct($coparray);
$copfinal_history = array('RefID' => $final_product_id, 'ProductCode' => $copmaterial, 'Quantity' => $copqty, 'Price' => $copvalue, 'Transactiondate' => $createddt, 'TransactionType' => 'Inward');
$Getmaterial_code = $this->batchcard_model->GetMaterialCode($copmaterial);
$material_code = '';
foreach ($Getmaterial_code as $mas) {
$material_code = $mas->MaterialCode;
}
$copproducthistory = array('MaterialCode' => $material_code, 'Transaction_type' => 'Reduce', 'Ref_Type' => 'Final Product', 'Ref_No' => $final_product_id, 'Quantity' => $copqty, 'ItemValue' => $copvalue, 'CreatedBy' => $createdby, 'CreatedOn' => $createddt);
$this->batchcard_model->save_rawmaterialto_materialHistory($copproducthistory);
//$final_cophistory_save= $this->batchcard_model->SaveFinalHistory($copfinal_history);
}
echo "Details Saved Successfully";
}
function UpdateFinal_Product_Save()
{
$FPID = $this->request->getPost('FPId');
$final_product = $this->request->getPost('DEPTFN');
$final_qty = $this->request->getPost('Quantity');
$product_date = $this->request->getPost('Date');
//$pdt = $product_date->format('Y-m-d H:i:s');
//$pdt = date("Y-m-d", strtotime($product_date));
$product_value = $this->request->getPost('values');
$createdby = $this->session->get('userId');
$createddt = get_current_date_time();
$final_master = array('MaterialCode' => $final_product, 'Quantity' => $final_qty, 'Price' => $product_value, 'CreatedBy' => $createdby, 'ProductDate' => $product_date);
// / print_r($final_master);
$final_master_save = $this->batchcard_model->update_final_product($final_master, $FPID);
$lastId = '';
$final_history = array('ProductCode' => $final_product, 'Quantity' => $final_qty, 'Price' => $product_value, 'Transactiondate' => $createddt, 'TransactionType' => 'Inward');
//print_r($final_history);
//die();
$finalHistoryupdate = $this->batchcard_model->UpdateFinalHistory($final_history, $FPID, $final_product);
$Getmaterial_code = $this->batchcard_model->GetMaterialCode($final_product);
$material_code = '';
foreach ($Getmaterial_code as $mas) {
$material_code = $mas->MaterialCode;
}
$FPhistory = array('MaterialCode' => $material_code, 'Transaction_type' => 'Add', 'Ref_Type' => 'Final Product', 'Ref_No' => $FPID, 'Quantity' => $final_qty, 'ItemValue' => $product_value, 'CreatedBy' => $createdby, 'CreatedOn' => $createddt);
$this->batchcard_model->update_rawmaterialto_materialHistory($FPhistory, $material_code, $FPID);
$rawilne = $this->request->getPost('RawRow');
$consuline = $this->request->getPost('ConsuRow');
$packline = $this->request->getPost('PkgRow');
$coproline = $this->request->getPost('CopRow');
for ($i = 1; $i <= $rawilne; $i++) {
$rawmaterial = $this->request->getPost('rawmaterialcode' . $i);
$rawsupplier = $this->request->getPost('rawSupplierID' . $i);
$rawqty = $this->request->getPost('rawQty' . $i);
$rawvalue = $this->request->getPost('rawprice' . $i);
$rawilneno = $this->request->getPost('RawId' . $i);
$beforawqty = $this->request->getPost('beforerawQty' . $i);
// echo $beforawqty;
// die();
//echo $rawilneno;
if ($rawmaterial == '' && $rawsupplier == '' & $rawqty == '') {
} else {
$rawarray = array('FPId' => $FPID, 'MaterialCode' => $rawmaterial, 'SupplierID' => $rawsupplier, 'Quantity' => $rawqty, 'Price' => $rawvalue, 'CreatedBy' => $createdby, 'CreatedDate' => $createddt);
$rawmaterialhistory = array('MaterialCode' => $rawmaterial, 'Transaction_type' => 'Reduce', 'Ref_Type' => 'Final Product', 'Ref_No' => $FPID, 'SupplierID' => $rawsupplier, 'Quantity' => $rawqty, 'ItemValue' => $rawvalue, 'CreatedBy' => $createdby, 'CreatedOn' => $createddt);
$checkrawid = $this->batchcard_model->GetRawid($rawilneno);
$checkrawhistory = $this->batchcard_model->GetRawCheck($rawmaterial, $FPID);
$rawget_pre_qty = $this->inwardgateregister_model->get_CurrentQty($rawmaterial);
$av_qty = 0;
if (!empty($rawget_pre_qty)) {
foreach ($rawget_pre_qty as $gt) {
$av_qty = $gt->Current_stock;
}
}
// echo $av_qty;
// die();
$qty_dif = $rawqty - $beforawqty;
//echo $qty_dif;
// if($qty_dif >0)
// {
// echo 'if';
// $currentav_qty=$av_qty+$qty_dif;
// }
// else
// {
// echo 'else';
$currentav_qty = $av_qty - $qty_dif;
// }
//echo $currentav_qty;
//die();
$current_qty = array('Current_stock' => $currentav_qty);
//print($current_qty);
$this->inwardgateregister_model->addmaterialmaster($current_qty, $rawmaterial);
if (count($checkrawid) == 0) {
$this->batchcard_model->save_finalraw($rawarray);
$this->batchcard_model->save_rawmaterialto_materialHistory($rawmaterialhistory);
} else {
$this->batchcard_model->update_finalraw($rawarray, $rawilneno);
$this->batchcard_model->update_rawmaterialto_materialHistory($rawmaterialhistory, $rawmaterial, $FPID);
//$this->batchcard_model->save_rawmaterialto_materialHistory($rawmaterialhistory);
}
}
}
//echo $consuline;
for ($i = 1; $i <= $consuline; $i++) {
$conmaterial = $this->request->getPost('consumematerialcode' . $i);
$consupplier = $this->request->getPost('consumeSupplierID' . $i);
$conqty = $this->request->getPost('consumeQty' . $i);
$convalue = $this->request->getPost('consumeprice' . $i);
$consulinee = $this->request->getPost('Consumable' . $i);
$beforeconqty = $this->request->getPost('beforeconsumeQty' . $i);
if ($conmaterial == '' && $consupplier == '' & $conqty == '') {
} else {
$conarray = array('FPId' => $FPID, 'MaterialCode' => $conmaterial, 'SupplierID' => $consupplier, 'Quantity' => $conqty, 'Price' => $convalue, 'CreatedBy' => $createdby, 'CreatedDate' => $createddt);
//echo $consuline;
//print_r($conarray);
$consuhistory = array('MaterialCode' => $conmaterial, 'Transaction_type' => 'Reduce', 'Ref_Type' => 'Final Product', 'Ref_No' => $FPID, 'SupplierID' => $consupplier, 'Quantity' => $conqty, 'ItemValue' => $convalue, 'CreatedBy' => $createdby, 'CreatedOn' => $createddt);
$checkconsuid = $this->batchcard_model->Getconsuid($consulinee);
$conget_pre_qty = $this->inwardgateregister_model->get_CurrentQty($conmaterial);
$conav_qty = 0;
if (!empty($conget_pre_qty)) {
foreach ($conget_pre_qty as $gt) {
$conav_qty = $gt->Current_stock;
}
}
$conqty_dif = $conqty - $beforeconqty;
// if($conqty_dif >0)
// {
// $concurrentav_qty=$conav_qty+$conqty_dif;
// }
// else
// {
$concurrentav_qty = $conav_qty - $conqty_dif;
//}
// $concurrentav_qty=$conav_qty-$conqty;
$concurrent_qty = array('Current_stock' => $concurrentav_qty);
$this->inwardgateregister_model->addmaterialmaster($concurrent_qty, $conmaterial);
if (count($checkconsuid) > 0) {
//echo 'if';
$this->batchcard_model->update_finalconsu($conarray, $consulinee);
$this->batchcard_model->update_rawmaterialto_materialHistory($consuhistory, $conmaterial, $FPID);
} else {
echo 'else';
$this->batchcard_model->save_finalcon($conarray);
$this->batchcard_model->save_rawmaterialto_materialHistory($consuhistory);
}
}
}
for ($i = 1; $i <= $packline; $i++) {
$packmaterial = $this->request->getPost('packmaterialcode' . $i);
$packsupplier = $this->request->getPost('packSupplierID' . $i);
$packqty = $this->request->getPost('packQty' . $i);
$packvalue = $this->request->getPost('packprice' . $i);
$packlineId = $this->request->getPost('packId' . $i);
$beforepacqty = $this->request->getPost('beforepackQty' . $i);
if ($packmaterial == '' && $packsupplier == '' & $packqty == '') {
} else {
$packarray = array('FPId' => $FPID, 'MaterialCode' => $packmaterial, 'SupplierID' => $packsupplier, 'Quantity' => $packqty, 'Price' => $packvalue, 'CreatedBy' => $createdby, 'CreatedDate' => $createddt);
//print_r($packarray);
$packmathistory = array('MaterialCode' => $packmaterial, 'Transaction_type' => 'Reduce', 'Ref_Type' => 'Final Product', 'Ref_No' => $FPID, 'SupplierID' => $packsupplier, 'Quantity' => $packqty, 'ItemValue' => $packvalue, 'CreatedBy' => $createdby, 'CreatedOn' => $createddt);
$checkpackid = $this->batchcard_model->Getpackid($packlineId);
$pacget_pre_qty = $this->inwardgateregister_model->get_CurrentQty($packmaterial);
$pacav_qty = 0;
if (!empty($pacget_pre_qty)) {
foreach ($pacget_pre_qty as $gt) {
$pacav_qty = $gt->Current_stock;
}
}
$pacqty_dif = $packqty - $beforepacqty;
// if($pacqty_dif >0)
// {
// $paccurrentav_qty=$pacav_qty+$pacqty_dif;
// }
// else
// {
$paccurrentav_qty = $pacav_qty - $pacqty_dif;
//}
// $paccurrentav_qty=$pacav_qty-$packqty;
$paccurrent_qty = array('Current_stock' => $paccurrentav_qty);
$this->inwardgateregister_model->addmaterialmaster($paccurrent_qty, $packmaterial);
if (count($checkpackid) > 0) {
$this->batchcard_model->update_finalpacking($packarray, $packlineId);
$this->batchcard_model->update_rawmaterialto_materialHistory($packmathistory, $packmaterial, $FPID);
} else {
$this->batchcard_model->save_rawmaterialto_materialHistory($packmathistory);
$this->batchcard_model->save_finalpacking($packarray);
}
}
//echo "Updated";
}
for ($i = 1; $i <= $coproline; $i++) {
$copmaterial = $this->request->getPost('Copmaterialcode' . $i);
$codate = $this->request->getPost('CopDate' . $i);
$cddt = format_date($codate,0,"Y-m-d");
$copqty = $this->request->getPost('CopQty' . $i);
$copvalue = $this->request->getPost('Copprice' . $i);
$coplineId = $this->request->getPost('CopId' . $i);
if ($copmaterial == '' && $codate == '' & $copqty == '') {
} else {
$coparray = array('FPId' => $FPID, 'MaterialCode' => $copmaterial, 'CoDate' => $cddt, 'Quantity' => $copqty, 'Price' => $copvalue, 'CreatedBy' => $createdby, 'CreatedDate' => $createddt);
$checkpackid = $this->batchcard_model->Getcopid($coplineId);
// $copfinal_history = array('ProductCode'=>$copmaterial,'Quantity'=>$copqty,'Price'=>$copvalue,'Transactiondate'=>$createddt,'TransactionType'=>'Inward');
$copfinal_history = array('RefID' => $FPID, 'ProductCode' => $copmaterial, 'Quantity' => $copqty, 'Price' => $copvalue, 'Transactiondate' => $createddt, 'TransactionType' => 'Inward');
$Getmaterial_code = $this->batchcard_model->GetMaterialCode($copmaterial);
$material_code = '';
foreach ($Getmaterial_code as $mas) {
$material_code = $mas->MaterialCode;
}
$Cophistory = array('MaterialCode' => $material_code, 'Transaction_type' => 'Reduce', 'Ref_Type' => 'Final Product', 'Ref_No' => $FPID, 'Quantity' => $copqty, 'ItemValue' => $copvalue, 'CreatedBy' => $createdby, 'CreatedOn' => $createddt);
// $this->batchcard_model->update_rawmaterialto_materialHistory($FPhistory,$final_product,$FPID);
// print_r($coparray);
if (count($checkpackid) > 0) {
$this->batchcard_model->update_finalcoproduct($coparray, $coplineId);
$finalHistoryupdate = $this->batchcard_model->UpdateFinalHistory($copfinal_history, $FPID, $copmaterial);
$this->batchcard_model->update_rawmaterialto_materialHistory($Cophistory, $material_code, $FPID);
} else {
$this->batchcard_model->save_finalcoproduct($coparray);
$final_cophistory_save = $this->batchcard_model->SaveFinalHistory($copfinal_history);
$this->batchcard_model->save_rawmaterialto_materialHistory($Cophistory);
}
}
}
echo "Updated Successfully";
}
function EditMaterialAdjustment()
{
$AdjustmentId = $_GET['AdjustmentId'];
$Supplier = $_GET['sn'];
$date = $_GET['date'];
$MaterialCode = $_GET['mc'];
$this->global['pageTitle'] = 'Material Adjustment';
$data['netQuantityarray'] = $this->batchcard_model->GetNetQty($MaterialCode, $date, $Supplier);
//print_r($data['netQuantityarray']);
$data['materailAdjustmentlist'] = $this->batchcard_model->getEditMaterialAdjustments($AdjustmentId);
$data['materiallist'] = $this->batchcard_model->getMaterial();
$data['getSupplierlist'] = $this->batchcard_model->getSupplierlist();
$this->loadViews("editmaterialadjustment", $this->global, $data, NULL);
//return true;
}
function material_history()
{
$this->global['pageTitle'] = 'Material History';
if ($this->request->getPost('btn_submit')) {
$prod = $this->request->getPost('item_name');
$frm = $this->request->getPost('from_date');
$t = $this->request->getPost('to_date');
$data['material'] = $this->batchcard_model->getMaterial_history($prod, $frm, $t);
}
$data['material_name'] = $this->batchcard_model->material_name();
$this->loadviews("MaterialHistory", $this->global, $data, NULL);
}
function UpdateQuantity()
{
$adjquantity = $this->request->getPost('adjquantity');
$reason = $this->request->getPost('reason');
$id = $this->request->getPost('adid');
//echo $id;
$adjustquantity = $this->request->getPost('editquantity');
$description = $this->request->getPost('desc');
$updatequantitydes = array('Quantity' => $adjustquantity, 'Description' => $description, 'Reason' => $reason, 'ActualQuantity' => $adjquantity);
//print_r($updatequantitydes);
$updatequantity = array('Quantity' => $adjustquantity);
$UpdateQuantityHistory = $this->batchcard_model->updateQuantityStockHistory($updatequantity, $id);
$UpdateQuantityAdj = $this->batchcard_model->updateQuantityAdjusment($updatequantitydes, $id);
// print_r($updatequantityadj);
if ((count($updatequantityadj) > 0) && (count($updatequantityhistory))) {
echo "Details Added Successfully";
} else {
echo "Something Went Wrong,Please Try Again";
}
//$this->loadViews("editmaterialadjustment", $this->global,$data,NULL);
}
function Deletequantity()
{
$AdjustmentId = $_GET['AdjustmentId'];
$Isactive = 0;
$Updateactive = array('Isactive' => $Isactive);
$this->batchcard_model->updateisactiveadjusment($Updateactive, $AdjustmentId);
$this->batchcard_model->updateisactiveastockhistory($Updateactive, $AdjustmentId);
$this->loadViews("editmaterialadjustment", $this->global, $data, NULL);
}
function getAvgPrice()
{
$MaterialCode = $this->request->getPost('materialcode');
$date = $this->request->getPost('date');
$Supplier = $this->request->getPost('Supplier');
$pricearray = $this->batchcard_model->GetAvgPrice($MaterialCode, $date, $Supplier);
echo json_encode($pricearray);
}
function get_Product_Supplier()
{
$MaterialCode = $this->request->getPost('materialcode');
$type = $this->request->getPost('type');
$supplierlist = $this->batchcard_model->Get_Product_Supplier($MaterialCode, $type);
echo json_encode($supplierlist);
}
function MaterailStockReport()
{
//$data['materailAdjustmentlist'] = $this->batchcard_model->getAllMaterialAdjustments();
$data['finyear'] = $this->batchcard_model->finyear();
if ($this->request->getPost('btn_submit')) {
$search['year'] = $this->request->getPost('Finyear');
$search['from_date'] = $this->request->getPost('fdate');
$search['to_date'] = $this->request->getPost('tdate');
$search['month'] = $this->request->getPost('month');
$data['getdata'] = $this->batchcard_model->GetStockAbstract($search);
$data['field_det'] = $search;
//print_r($data['getdata']);die();
}
$this->global['pageTitle'] = 'Stock Report';
$this->loadViews("materialStockReport", $this->global, $data, NULL);
}
function IndividualStockDetails()
{
//$PONO = $_GET['PONO'];
$get['year'] = $_GET['year'];
$get['materialcode'] = $_GET['MaterialCode'];
$get['month'] = $_GET['month'];
$get['fdate'] = $_GET['fromdate'];
$get['tdate'] = $_GET['todate'];
$get['open'] = $_GET['openingstock'];
$get['addition'] = $_GET['Add'];
$get['reduce'] = $_GET['Reduce'];
$data['finyear'] = $this->batchcard_model->finyear();
if ($get['tdate'] == '') {
$get['tdate'] = '0';
} else if ($get['fdate'] == '') {
$get['fdate'] = '0';
}
//die();
$data['getdata'] = $this->batchcard_model->GetStockAbstractdetails($get);
$data['field_det'] = $get;
$this->global['pageTitle'] = 'Stock Report';
$this->loadViews("individualStockdetails", $this->global, $data, NULL);
}
function DeleteFinalProduct()
{
$FPId = $_GET['FPId'];
$data['check'] = $_GET['check'];
$deletedata = $this->batchcard_model->Delete_ProductBatchCard($FPId);
$data['final_product'] = $this->batchcard_model->getFinalProductDetaisl();
$this->global['pageTitle'] = 'Finished Product Batch Card Listing';
$this->loadViews("FinalProductlisting", $this->global, $data, NULL);
}
}