IMMREX7
<?php
namespace App\Http\Controllers\School\Exam;
use Illuminate\Http\Request;
use App\Http\Controllers\School\SchoolController;
use DB;
use Auth;
use PDF;
use Storage;
use Session;
use \Milon\Barcode\DNS1D;
class ExamGenerateController extends SchoolController {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$template = ['' => '--Select--'] +\App\ExamTemplate::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idTemplate')->get()->pluck('templateName','idTemplate' )->toArray();
$excel = ['' => '--Select--'] +\App\ExcelTemplate::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idExcel')->get()->pluck( 'fileName','idExcel')->toArray();
return view('schools.exams.exam_generate', compact('template','excel'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create() {
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request) {
$data=json_decode($request->getContent(),true);
$school = \App\School::where('idSchool','=',Auth::guard('school')->user()->idSchool)->first();
$html = $data['image'];
$values = $data['data'];
$template = \App\ExamTemplate::findOrfail($data['idTemplate']);
$exam = \App\ExamType::findOrfail($template->idExamType);
$size = $template->size;
if(isset($html)){
$pdf = PDF::loadView('schools.exams.print_exam', compact('html','size'));
$content = $pdf->output();
$path = ('public/schools/' . $school->idSchool . '/results/'.$exam->typeName.'/'.$values['ec_no'].'.pdf');
Storage::put($path, $content);
}
$pdfFile = \App\ExamResult::where('idSchool','=',Auth::guard('school')->user()->idSchool)
->where('idExamType','=',$exam->idExamType)
->where('ecNo','=',$values['ec_no'])
->first();
if( isset($pdfFile->idResult)){
$pdfFile->delete();
}
$results = new \App\ExamResult();
$results->idSchool = Auth::guard('school')->user()->idSchool;
$studentID = DB::table('students')->where('idSchool', Auth::guard('school')->user()->idSchool)->where('ecNo',$values['ec_no'])
->first();
if($studentID != null){
$results->idStudent = $studentID->idStudent;
}
$results->idExamType = $exam->idExamType;
$results->idFinancialYear = Session::get('idFinancialYear');
$results->nameClass = $values['class'];
$results->nameSection = $values['section'];
$results->mobileNumber = $values['contact_number'];
$results->fullName = $values['full_name'];
$results->ecNo = $values['ec_no'];
$results->fatherName = $values['fathers_name'];
DB::beginTransaction();
$results->save();
DB::commit();
if ($request->ajax()) {
return response()->json(['success' => "SUCCESS",'count' => $data['position'] ], 200, ['app-status' => 'success']);
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id) {
//
}
public function getExcelData(Request $request){
$data=json_decode($request->getContent(),true);
$excel = \App\ExcelTemplate::findOrfail($data['excel_id']);
$reader = \Excel::load('storage/app/public/schools/' . Auth::guard('school')->user()->idSchool . '/excels/'.$excel->imageFile)->get();
foreach ($reader as $key => $value) {
$student = \App\AdmEntry::where('ecNo', '=', $value['ec_no'])
->where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->first();
$barcode = (new DNS1D)->getBarcodePNG($value['ec_no'], "C39+", 1, 50);
if($student != null)
$reader[$key]['image'] = $student->photo;
$reader[$key]['barcode'] = $barcode;
}
return json_encode($reader);
}
public function createDocument(Request $request){
$template = \App\ExamTemplate::findOrfail($request->idTemplate);
$excel = \App\ExcelTemplate::findOrfail($request->idExcel);
$pageWidth = "0px";
$pageHeight = "0px";
switch ($template->size) {
case 'A4':
$pageWidth = "21.0cm";
$pageHeight = "29.7cm";
break;
case 'A3':
$pageWidth = "29.7cm";
$pageHeight = "42.0cm";
break;
case 'A2':
$pageWidth = "42.0cm";
$pageHeight = "59.4cm";
break;
case 'A5':
$pageWidth = "14.8cm";
$pageHeight = "21.0cm";
break;
default:
$pageWidth = "0px";
$pageHeight = "0px";
break;
}
$background = Auth::guard('school')->user()->idSchool.'/templates/'.$template->imageFile;
$reader = \Excel::load('storage/app/public/schools/' . Auth::guard('school')->user()->idSchool . '/excels/'.$excel->imageFile)->get();
$headerRow = $reader->first()->keys()->toArray();
$firstValue = [] ;
foreach ($reader as $key => $value) {
$student = \App\AdmEntry::where('ecNo', '=', $value['ec_no'])
->where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->first();
$barcode = (new DNS1D)->getBarcodePNG($value['ec_no'], "C39+", 1, 50);
$firstValue = $value;
if($student != null)
$firstValue['image'] = $student->photo;
else $firstValue['image'] = '';
$firstValue['barcode'] = $barcode;
break;
}
$total = $reader->count() ;
return view('schools.exams.exam_program',compact('pageWidth','pageHeight','headerRow','total','firstValue','background','template','excel'));
}
/*
//$excel = \App\ExcelTemplate::findOrfail($data['excel_id']);
//$reader = \Excel::load('storage/app/public/schools/' . Auth::guard('school')->user()->idSchool . '/excels/'.$excel->imageFile)->get();
$headerRow = $reader->first()->keys()->toArray();
$pageWidth = "0px";
$pageHeight = "0px";
switch ($template->size) {
case 'A4':
$pageWidth = "21.0cm";
$pageHeight = "29.7cm";
break;
case 'A3':
$pageWidth = "29.7cm";
$pageHeight = "42.0cm";
break;
case 'A2':
$pageWidth = "42.0cm";
$pageHeight = "59.4cm";
break;
case 'A5':
$pageWidth = "14.8cm";
$pageHeight = "21.0cm";
break;
default:
$pageWidth = "0px";
$pageHeight = "0px";
break;
}
$firstValue = [] ;
foreach ($reader as $key => $value) {
$firstValue = $value;
$html =$htmlData;
foreach ($headerRow as $var) {
if (strpos($html,$var) !== false) {
$html = str_replace("[".$var."]", $firstValue[$var],$html);
}
}
$barcode = DNS1D::getBarcodePNG($firstValue['ec_no'], "C39+", 1, 50);
echo view('schools.exams.print_exam',compact('html','firstValue','barcode','pageWidth','pageHeight'));
$pdf = PDF::loadView('schools.exams.print_exam', compact('html','firstValue','barcode','pageWidth','pageHeight'));
$content = $pdf->output();
}
$path = ('public/schools/' . $school->idSchool . '/results/barcode.pdf');
Storage::put($path, $content);*/
}
Copyright © 2021 -