siddharth_application/application/controllers/resinbatchcard.php
2023-05-30 18:45:55 +05:30

485 lines
15 KiB
PHP

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH . '/libraries/BaseController.php';
/**
* Class : purchaseorder (PurchaseorderController)
* User Class to control all user related operations.
* @author : VenbaMail Mali
* @version : 1.1
* @since : 15 Feb 2016
*/
class resinbatchcard extends BaseController
{
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->load->model('quality_model');
$this->load->library('form_validation');
//$this->load->library('dompdf_gen');
$this->isLoggedIn();
}
/**
* This function used to load the first screen of the user
*/
function addNewResinBatchCard()
{
$data['productsoutward'] = $this->quality_model->getAllprodcuts();
$data['customersoutward'] = $this->quality_model->getAllcustomers();
$data['emplist'] = $this->quality_model->getEmplistforReport();
$data['operatorslist'] = $this->quality_model->getOperatorsListforReport();
$data['machinelist'] = $this->quality_model->getMachineList();
$data['trpbatchcardnos'] = $this->quality_model->getTRPBatchcardNos();
$data['igrno'] = $this->quality_model->getIGRNos();
$this->global['pageTitle'] = 'Siddharth : Resin Batch Card';
$this->loadViews("newresinbatchcard", $this->global, $data , NULL);
}
function getIGRLineNo()
{
$igrno = $this->input->post('param1');
$sql = 'select IGRItemNo from T_IGR_Details where IGRNO = ?';
$res = $this->db->query($sql,array($igrno));
echo json_encode($res->result());
}
function resinBatchCardLisitng()
{
$data['records'] = $this->quality_model->getResinBatchCardTestMasterList();
$this->global['pageTitle'] = 'Siddharth : Prodcut Report List ';
$this->loadViews("resinbatchcardreportlist", $this->global, $data , NULL);
}
function saveTestReportData()
{
//echo "system soft";
date_default_timezone_get('Asia/Kolkata');
$productid = $this->input->post('param1');
$customerid = $this->input->post('param2');
$batchdate = $this->input->post('param3');
$batchdate = date_format(date_create($batchdate),'Y-m-d');
$plantname = $this->input->post('param4');
$macinecode = $this->input->post('param5');
$trpbatchcard = $this->input->post('param6');
$igrnos = $this->input->post('param7');
$igrlinenos = $this->input->post('param8');
$remarks = $this->input->post('param9');
$approvedby = $this->input->post('param10');
$masterdata = $this->input->post('param11');
$totaldata = $this->input->post('param12');
$masterdata = json_decode($masterdata,true);
$totaldata = json_decode($totaldata,true);
$createby = $this->session->userdata ( 'userId' );
$document = null;
$resinname = $this->input->post('param13');
$oplist = $this->input->post('param14');
$oplist = json_decode($oplist);
$operator = $this->input->post('param15');
$sandigrnos = $this->input->post('param16');
$Resinigrnos = $this->input->post('param17');
$Hexamineigrnos = $this->input->post('param18');
$CSigrnos = $this->input->post('param19');
$Catalystigrno = $this->input->post('param20');
$bagsigrnos = $this->input->post('param21');
$tonigrnos= $this->input->post('param22');
if(!empty($_FILES['rfile']['name']))
{
$fs = $this->uploadFile();
$document = $fs;
}
$sandtotal = 0;
$resintotal = 0;
$catalysttotal = 0;
$hextotal = 0;
$cstotal = 0;
$bags50total = 0;
$ton1bagstotal = 0;
$producitonloss = 0;
$finishedproduct = 0;
foreach($totaldata as $key => $tot)
{
if($key != 0)
{
$sandtotal = $tot['Sand'];
$resintotal = $tot['Resin'];
$hextotal = $tot['Hexamine'];
$catalysttotal = $tot['Catalyst'];
$cstotal = $tot['CS'];
$bags50total = $tot['50 Bags'];
$ton1bagstotal = $tot['1 ton Bag'];
$producitonloss = $tot['Production Loss Lump'];
$finishedproduct = $tot['Finished Prodcut PCS'];
}
}
$masterreportdata = array('productid'=>$productid,
'customerid'=>$customerid,
'batchdate'=>$batchdate,
'plantname'=>$plantname,
'resinname'=>$resinname,
'machinecode'=>$macinecode,
'trpbatchcardno'=>$trpbatchcard,
'igrno'=>$igrnos,
'igrlineno'=>$igrlinenos,
'remarks'=>$remarks,
'createdby'=>$createby,
'approvedby'=>$approvedby,
'document'=>$document,
'sandtotal'=>$sandtotal,
'resintotal'=>$resintotal,
'hextotal'=>$hextotal,
'cstotal'=>$cstotal,
'catalysttotal'=>$catalysttotal,
'bags50total'=>$bags50total,
'ton1bagstotal'=>$ton1bagstotal,
'producitonloss'=>$producitonloss,
'finishedproduct'=>$finishedproduct,
'operatedby'=>$operator,
'igrno_for_sand'=>$sandigrnos,
'igrno_for_resin'=>$Resinigrnos,
'igrno_for_haxamine'=>$Hexamineigrnos,
'igrno_for_cs'=>$CSigrnos,
'igrno_for_catalyst'=>$Catalystigrno,
'igrno_for_bags'=>$bagsigrnos,
'igrno_for_tonbags'=>$tonigrnos
);
// print_r($masterreportdata);
// die();
$MASTERID = $this->quality_model->saveResinBatchCardMasterTestData($masterreportdata);
// echo $MASTERID;die();
//$MASTERID = 56;
foreach($masterdata as $key => $mas)
{
if($key > 2){
$t = array_pop($mas);
array_pop($mas);
foreach($mas as $key => $m)
{
$newArray = array('master_report_id'=>$MASTERID,'i_time'=>$t,'spec_id'=>$key,'spec_value'=>$m);
$res = $this->quality_model->saveResinBatchCardChildTestData($newArray);
//print_r($newArray);
}
}
}
foreach($oplist as $op)
{
$nArray = array('master_id'=>$MASTERID,'EmpID'=>$op);
$this->db->insert('T_ResinBatchCard_Operators',$nArray);
}
echo "Report Data Saved Successfully!";
}
function updateTestReportData()
{
date_default_timezone_get('Asia/Kolkata');
$productid = $this->input->post('param1');
$customerid = $this->input->post('param2');
$batchdate = $this->input->post('param3');
$batchdate = date_format(date_create($batchdate),'Y-m-d');
$plantname = $this->input->post('param4');
$machines = $this->input->post('param5');
$trpbatchcardno = $this->input->post('param6');
$igrnos = $this->input->post('param7');
$igrlinenos = $this->input->post('param8');
$remarks = $this->input->post('param9');
$approvedby = $this->input->post('param10');
$masterdata = $this->input->post('param11');
$totaldata = $this->input->post('param12');
$masterdata = json_decode($masterdata,true);
$totaldata = json_decode($totaldata,true);
$createby = $this->session->userdata ( 'userId' );
$document = $this->input->post('param13');
$MASTERID = $this->input->post('param14');
$opstoinsert = $this->input->post('param15');
$opstodelete = $this->input->post('param16');
$operatedby = $this->input->post('param17');
$sandigrnos = $this->input->post('param18');
$Resinigrnos = $this->input->post('param19');
$Hexamineigrnos = $this->input->post('param20');
$CSigrnos = $this->input->post('param21');
$Catalystigrno = $this->input->post('param22');
$bagsigrnos = $this->input->post('param23');
$tonigrnos= $this->input->post('param24');
$resinname=$this->input->post('param25');
$opstoinsert = json_decode($opstoinsert);
$opstodelete = json_decode($opstodelete);
// print_r($opstodelete);
// echo count($opstodelete);
//die();
//$oplist = json_decode($oplist);
if(!empty($_FILES['rfile']['name']))
{
if(!empty($document)){
$file = getcwd()."\\uploads\QAD\\".$document;
if(unlink($file)){
//echo "sucess";
}else{
//echo "Failed";
}
}
$fs = $this->uploadFile();
$document = $fs;
}
$sandtotal = 0;
$resintotal = 0;
$hextotal = 0;
$cstotal = 0;
$catalysttotal = 0;
$bags50total = 0;
$ton1bagstotal = 0;
$producitonloss = 0;
$finishedproduct = 0;
foreach($totaldata as $key => $tot)
{
if($key != 0)
{
$sandtotal = $tot['Sand'];
$resintotal = $tot['Resin'];
$hextotal = $tot['Hexamine'];
$cstotal = $tot['CS'];
$catalysttotal = $tot['Catalyst'];
$bags50total = $tot['50 Bags'];
$ton1bagstotal = $tot['1 ton Bag'];
$producitonloss = $tot['Production Loss Lump'];
$finishedproduct = $tot['Finished Prodcut PCS'];
}
}
$masterreportdata = array('batchdate'=>$batchdate,'plantname'=>$plantname,'machinecode'=>$machines,'trpbatchcardno'=>$trpbatchcardno,'igrno'=>$igrnos,'igrlineno'=>$igrlinenos,'resinname'=>$resinname,'remarks'=>$remarks,'updatedby'=>$createby,'approvedby'=>$approvedby,'document'=>$document,'sandtotal'=>$sandtotal,'resintotal'=>$resintotal,'hextotal'=>$hextotal,'cstotal'=>$cstotal,'catalysttotal'=>$catalysttotal,'bags50total'=>$bags50total,'ton1bagstotal'=>$ton1bagstotal,'producitonloss'=>$producitonloss,'finishedproduct'=>$finishedproduct,'operatedby'=>$operatedby,
'igrno_for_sand'=>$sandigrnos,
'igrno_for_resin'=>$Resinigrnos,
'igrno_for_haxamine'=>$Hexamineigrnos,
'igrno_for_cs'=>$CSigrnos,
'igrno_for_catalyst'=>$Catalystigrno,
'igrno_for_bags'=>$bagsigrnos,
'igrno_for_tonbags'=>$tonigrnos);
//print_r($masterreportdata);
$this->quality_model->updateResinBatchCardMasterTestData($masterreportdata,$MASTERID);
//echo $MASTERID;die();
//$MASTERID = 56;
foreach($masterdata as $key => $mas)
{
if($key > 2){
$t = array_pop($mas);
array_pop($mas);
foreach($mas as $key => $m)
{
$newArray = array('master_report_id'=>$MASTERID,'i_time'=>$t,'spec_id'=>$key,'spec_value'=>$m);
$res = $this->quality_model->updateResinBatchCardChildTestData($newArray);
//print_r($newArray);
}
}
}
if(!empty($opstoinsert)){
foreach($opstoinsert as $opstins)
{
$tArray = array('master_id'=>$MASTERID,'EmpID'=>$opstins);
$this->db->insert('T_ResinBatchCard_Operators',$tArray);
//print_r($tArray);
}
}
if(!empty($opstodelete)){
foreach($opstodelete as $key => $opstdel)
{
//echo 'FROM CON'.'-'.$MASTERID.'-'.$opstdel[0];
$this->db->where('master_id',$MASTERID);
$this->db->where('EmpID',$opstdel[0]);
$this->db->delete('T_ResinBatchCard_Operators');
//print_r($tArray);
}
}
echo "Report Data Saved Successfully!";
}
function printReportPDF()
{
$type = '';
$html = '';
$filename = '';
if($this->input->post('type'))
{
$type = $this->input->post('type');
}
$reportid = $this->input->post('rid');
if($type != 'INWARD' or $type == ''){
$data['reportdata'] = $this->quality_model->getIndividualReportData($reportid);
$filename = 'PRE DESPATCH INSPECTION REPORT'.$reportid;
$html = $this->load->View("viewindreportpdf",$data,true);
}
else if($type == 'INWARD')
{
$data['reportdata'] = $this->quality_model->getIndividualInwardReportData($reportid);
$filename = 'INWARD MATERIAL INSPECTION REPORT'.$reportid;
$html = $this->load->View("viewindinwardreportpdf",$data,true);
}
require APPPATH . '/third_party/mpdf/mpdf.php';
$mpdf=new mPDF('utf-8','A4-P',7,10,10, 10, 10, 24, 4, 6);
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 1;
$mpdf->setAutoTopMargin = 'stretch';
$mpdf->setAutoBottomMargin = 'stretch';
$mpdf->WriteHTML($html);
$mpdf->Output($filename.'.pdf','I');
}
function uploadFile()
{
$pathinfo = pathinfo($_FILES['rfile']['name']);
$config['upload_path'] = 'uploads/QAD/';
$config['allowed_types'] = '*';
$filename = $_FILES['rfile']['name'];
$ext = end(explode('.',$filename));
$ext = strtolower($ext);
$fn = 'RESINBCARD' . date('Y-m-d') . time() . '.' . $ext;
//print_r($fn);die();
$config['file_name'] = $fn;
//echo $config['file_name'];
$this->load->library('upload',$config);
$this->upload->initialize($config);
if($this->upload->do_upload('rfile'))
{
$uploadData = $this->upload->data();
$uploadfilename = $uploadData['file_name'];
return $uploadfilename;
}
else
{
$error = array('error' => $this->upload->display_errors());
$uploadfilename = '';
print_r($error);
return null;
}
}
function viewIndReport()
{
$rbcid = $this->uri->segment(3);
//echo $rbcid;
$data['emplist'] = $this->quality_model->getEmplistforReport();
$data['records'] = $this->quality_model->getResinBatchCardDetails($rbcid);
//print_r($data['records']);
$data['machinelist'] = $this->quality_model->getMachineList();
$data['igrno'] = $this->quality_model->getIGRNos();
$data['igrlineitem'] = $this->quality_model->getIGRItemNos();
$data['trpbatchcardnos'] = $this->quality_model->getTRPBatchcardNos();
$data['operatorslist'] = $this->quality_model->getOperatorsListforReport();
$data['existoperatorslist'] = $this->quality_model->getExistOperatorsListforReport($rbcid);
//print_r($data['records']);die();
$this->global['pageTitle'] = 'Siddharth : Edit Resin Batch Card';
$this->loadViews("editresinbatchcard", $this->global, $data , NULL);
}
//this function used to edit resinbatch card pdf
function printResinBatchReport()
{
$rbcid = $this->uri->segment(3);
$data['records'] = $this->quality_model->getResinBatchCardDetails($rbcid);
//print_r( $data['records']);
$productid= $data['records']['masterdata'][0]->productid;
$customerid = $data['records']['masterdata'][0]->customerid;
$ttype = 'RESINBATCHCARD';
// echo $productid1;
// echo $customerid1;
$data['recordsheader'] = $this->quality_model->getSpecifications($productid,$customerid,$ttype);
//print_r($data['recordsheader']);
$data['existspec'] = $this->quality_model->getAllspec(); // values max 15 pdf include
$data['existoperatorslist'] = $this->quality_model->getExistOperatorsListforReport($rbcid);
// print_r( $data['existspec']);
// $filename = 'Siddharth :ResinBatchCard'.$rbcid;
$data['reportdata']['masterreport'] = $temparray;
$data['timearray'] = $time;
$data['emplist'] = $this->quality_model->getEmplistforReport();
$this->global['pageTitle'] = 'Siddharth :ResinBatchCardPDF';
$html = $this->load->View("viewresinbatchpdf",$data,true);
require APPPATH . '/third_party/mpdf/mpdf.php';
$mpdf=new mPDF('utf-8','A4-P',7,10,10, 10, 10, 24, 4, 6);
$mpdf->SetDisplayMode('fullpage');
$mpdf->SetTitle('Siddharth :ResinBatchCard'.$rbcid);
$mpdf->list_indent_first_level = 1;
$mpdf->setAutoTopMargin = 'stretch';
$mpdf->setAutoBottomMargin = 'stretch';
$mpdf->WriteHTML($html);
//$mpdf->SetJS('print();');
$mpdf->Output($filename.'.pdf','I');
}
}
?>