IMMREX7

aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/
File Up :
aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/OnlineRegistrationController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use Carbon\Carbon;
use Session;
use App\Http\SendSmsApi;
use PDF;

class OnlineRegistrationController extends Controller {

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index() {
        return view('onlinereg.regform');
    }

    public function mjForm() {
        header ("Content-type: image/jpg");
        $height=100; // Canvas Height
        $width=300;   //  Canvas Width 
        $text="plus2net";   // Text string to be written on Image. 
        $x=10;
        $y=70;
        $font_size=60; // size of the font to be written 
        $rotation=0; // angle of rotation of text 
        $font_f = 'arial.ttf'; // font family , set the path to arial.ttf file
        ///// Create the image ////////
        $im = @ImageCreate ($width,$height)
        or die ("Cannot Initialize new GD image stream");

        $background_color = ImageColorAllocate ($im, 204, 204, 204); 
        $text_color = ImageColorAllocate ($im, 51, 51, 255); 
        imagettftext($im, $font_size, $rotation, $x, $y, $text_color, realpath('path/to/you/font.ttf'), $text);
        ImageJpeg ($im); // image displayed
        imagedestroy($im); // Memory allocation for the image is removed. 
    }

    /**
     * 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) {
        $rules = [];
        if (!$request->hasFile('photo') && $request->photo != null) {
            flash('Photo not uploaded.');
            return redirect()->back();
        }
        /* $registered = \App\StudentRegistration::where('father_mobile','=',$request->father_mobile)->where('firstName','=',$request->firstName)->where('lastName','=',$request->lastName)->first();
          if(!empty($registered)){
          $rules+= [
          'stdregistered'=>'required'
          ];
          }
          $messages = [
          'stdregistered.required'=>'Student has already been registered with this contact no and name.'
          ]; */
        //$this->validate($request,$rules,$messages);
//        dd($request->all());
        $school = \App\School::where('idSchool', '=', $request->idSchool)->first();
        $student = new \App\StudentRegistration();
        $activities = "";
        if (isset($request->activities1))
            $activities = $activities . $request->activities1 . ',';
        if (isset($request->activities2))
            $activities = $activities . $request->activities2 . ',';
        if (isset($request->activities3))
            $activities = $activities . $request->activities3 . ',';
        $student->activities = $activities;
//        $student->idFinancialYear = $school->idFinancialYear;
//        $password = 123456;
        $sch = substr($school->schoolName, 0, 4);
        $student->fill($request->all());
        $student->idSchool = $school->idSchool;
        if(isset($request->about_school))
        $student->about_school = $request->about_school;

        DB::beginTransaction();
        $student->save();
        if ($request->hasFile('photo')) {
            $photo = 'photo_' . $student->idRegistration . '.' . $request->file('photo')->getClientOriginalExtension();
            $request->file('photo')->storeAs('public/schools/' . $request->idSchool . '/onlinereg/', $photo);
            $student->photo = $photo;
        }
        if ($request->hasFile('fphoto')) {
            $photo = 'fphoto_' . $student->idRegistration . '.' . $request->file('fphoto')->getClientOriginalExtension();
            $request->file('fphoto')->storeAs('public/schools/' . $request->idSchool . '/onlinereg/', $photo);
            $student->father_photo = $photo;
        }
        if ($request->hasFile('mphoto')) {
            $photo = 'mphoto_' . $student->idRegistration . '.' . $request->file('mphoto')->getClientOriginalExtension();
            $request->file('mphoto')->storeAs('public/schools/' . $request->idSchool . '/onlinereg/', $photo);
            $student->mother_photo = $photo;
        }
        $reg_no = 'REG' . $sch . '000' . $student->idRegistration;
        Session::put('registrationNo', $reg_no);
        $student->registrationNo = $reg_no;
        $student->update();
        if (is_array($request->siblings)) {
            if (count($request->siblings) > 0) {
                foreach ($request->siblings as $key => $value) {
                    if ($value['fName'] != null) {
                        $sibling = new \App\StudentRegSibling();
                        $sibling->fill($request->all());
                        $sibling->idRegistration = $student->idRegistration;
                        $sibling->fName = $value['fName'];
                        $sibling->lName = $value['lName'];
                        $sibling->age = $value['age'];
                        $sibling->education = $value['education'];
                        $sibling->schoolName = $value['schoolName'];
                        $sibling->save();
                    }
                }
            }
        }
        DB::commit();
        if ($school->idSchool == 135 || $school->idSchool == 140) {
            $message = 'Dear Parents, Thanks for the online registration with us. You will receive a message with user iD and password when the Admission is confirmed by the school Admin. It takes a few minutes to a few hours please keep patience, Regards JIJAU ENTP.';
            $phone_number = $student->father_mobile;
            $tempid = '1707165133782518188';
            \App\Http\SendSmsApi::getUserNumber($phone_number, $message, $school, $tempid);
        } else {
            $message = 'Dear Parents, your admission is now confirmed. The User ID for App and Web is ' . $student->father_mobile . ' and the default password is 123456 Regards JIJAU ENTP.';
            $phone_number = $student->father_mobile;
            $tempid = '1707165133782518188';
            \App\Http\SendSmsApi::getUserNumber($phone_number, $message, $school, $tempid);
        }
        flash('Student has been Registered successfully !!');
        if ($school->idSchool == 25) {
            return redirect('onlinereg/success/' . $school->schoolName . '/' . strtoupper($reg_no));
        } else
            return redirect('onlinereg/' . $student->registrationNo . '/upload-documents');
//        return redirect('onlinereg/success/' . $school->schoolName);
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id) {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id) {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id) {
        //
        $student = \App\StudentRegistration::where('idRegistration', '=', $id)->first();
        $school = \App\School::where('idSchool', '=', $request->idSchool)->first();
        $activities = "";
        if (isset($request->activities1))
            $activities = $activities . $request->activities1 . ',';
        if (isset($request->activities2))
            $activities = $activities . $request->activities2 . ',';
        if (isset($request->activities3))
            $activities = $activities . $request->activities3 . ',';
        $student->activities = $activities;
        if(isset($request->about_school))
        $student->about_school = $request->about_school;
//        $student->idFinancialYear = $school->idFinancialYear;
//        $password = 123456;
        // $sch = substr($school->schoolName, 0, 4);
        $student->fill($request->all());
        $student->idSchool = $school->idSchool;
        $registration = \App\StudentRegistration::where('idRegistration', '=', $student->idRegistration)->first();
        DB::beginTransaction();
        if ($request->hasFile('photo')) {
            $photo = 'photo_' . $student->idRegistration . '.' . $request->file('photo')->getClientOriginalExtension();
            $request->file('photo')->storeAs('public/schools/' . $request->idSchool . '/onlinereg/', $photo);
            $student->photo = $photo;
        }
        if ($school->idSchool == 25) {
            $documentMaster = \App\DocumentType::where('idSchool', '=', $school->idSchool)->where('type', 'Student')->orderBy('idDocType', 'ASC')->get()->pluck('documentType', 'idDocType')->toArray();
            $error = null;
            foreach ($documentMaster as $key => $value) {
                $regdocument = \App\StdRegistrationMaster::where('idRegistration', '=', $student->idRegistration)->where('documentName', '=', $value)->first();
                if ($regdocument == null) {
                    $regdoc = new \App\StdRegistrationMaster();
                    $regdoc->idRegistration = $student->idRegistration;
                    $regdoc->documentName = $value;
                    $keyValue = str_replace(' ', '_', strtolower($value));
                    if ($request->hasFile($keyValue)) {
                        $document = $keyValue . '_' . $student->registrationNo . '.' . $request->file($keyValue)->getClientOriginalExtension();
                        $request->file($keyValue)->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $document);
                        $regdoc->path = $document;
                        $regdoc->save();
                    } else {
                        $error = $value . ' not uploaded!';
                    }
                } else {
                    $keyValue = str_replace(' ', '_', strtolower($value));
                    if ($request->hasFile($keyValue)) {
                        $document = $keyValue . '_' . $registration->registrationNo . '.' . $request->file($keyValue)->getClientOriginalExtension();
                        $request->file($keyValue)->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $document);
                        $regdocument->path = $document;
                        $regdocument->update();
                    }
                }
            }
        } else {
            $regdoc = \App\StdRegistrationDocumnet::where('idRegistration', $student->idRegistration)->first();
            //store photo
            if ($regdoc != null) {
                if ($request->hasFile('photo')) {
                    $photo = 'photo_' . $registration->registrationNo . '.' . $request->file('photo')->getClientOriginalExtension();
                    $request->file('photo')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $photo);
                    $regdoc->photo = $photo;
                }

                if ($request->hasFile('casteCopy')) {
                    $aadhaar = 'caste_' . $registration->registrationNo . '.' . $request->file('casteCopy')->getClientOriginalExtension();
                    $request->file('casteCopy')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $aadhaar);
                    $regdoc->casteCopy = $aadhaar;
                }

                if ($request->hasFile('birthCopy')) {
                    $aadhaar = 'birth' . $registration->registrationNo . '.' . $request->file('birthCopy')->getClientOriginalExtension();
                    $request->file('birthCopy')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $aadhaar);
                    $regdoc->birthCopy = $aadhaar;
                }

                //store aadhhar
                if ($request->hasFile('aadharCopy')) {
                    $aadhaar = 'aadhaar_' . $registration->registrationNo . '.' . $request->file('aadharCopy')->getClientOriginalExtension();
                    $request->file('aadharCopy')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $aadhaar);
                    $regdoc->aadharCopy = $aadhaar;
                }

                //store marksheet
                if ($request->hasFile('marksheet')) {
                    $marksheet = 'marksheet_' . $registration->registrationNo . '.' . $request->file('marksheet')->getClientOriginalExtension();
                    $request->file('marksheet')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $marksheet);
                    $regdoc->marksheet = $marksheet;
                }

                //store migration certificate
                if ($request->hasFile('migrationCertificate')) {
                    $mc = 'migration-certificate_' . $registration->registrationNo . '.' . $request->file('migrationCertificate')->getClientOriginalExtension();
                    $request->file('migrationCertificate')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $mc);
                    $regdoc->migrationCertificate = $mc;
                }



                //store slc
                if ($request->hasFile('slc')) {
                    $slc = 'slc_' . $registration->registrationNo . '.' . $request->file('slc')->getClientOriginalExtension();
                    $request->file('slc')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $slc);
                    $regdoc->slc = $slc;
                }

                //store otherdoc
                if ($request->hasFile('otherdoc')) {
                    $od = 'otherdoc_' . $registration->registrationNo . '.' . $request->file('otherdoc')->getClientOriginalExtension();
                    $request->file('otherdoc')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $od);
                    $regdoc->otherdoc = $od;
                }
                $regdoc->update();
            } else {
                $regdoc = new \App\StdRegistrationDocumnet();
                $regdoc->idRegistration = $registration->idRegistration;
                if ($request->hasFile('photo')) {
                    $photo = 'photo_' . $registration->registrationNo . '.' . $request->file('photo')->getClientOriginalExtension();
                    $request->file('photo')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $photo);
                    $regdoc->photo = $photo;
                }

                //store aadhhar
                if ($request->hasFile('casteCopy')) {
                    $aadhaar = 'caste_' . $registration->registrationNo . '.' . $request->file('casteCopy')->getClientOriginalExtension();
                    $request->file('casteCopy')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $aadhaar);
                    $regdoc->casteCopy = $aadhaar;
                }

                if ($request->hasFile('birthCopy')) {
                    $aadhaar = 'birth' . $registration->registrationNo . '.' . $request->file('birthCopy')->getClientOriginalExtension();
                    $request->file('birthCopy')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $aadhaar);
                    $regdoc->birthCopy = $aadhaar;
                }

                //store aadhhar
                if ($request->hasFile('aadharCopy')) {
                    $aadhaar = 'aadhaar_' . $registration->registrationNo . '.' . $request->file('aadharCopy')->getClientOriginalExtension();
                    $request->file('aadharCopy')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $aadhaar);
                    $regdoc->aadharCopy = $aadhaar;
                }

                //store marksheet
                if ($request->hasFile('marksheet')) {
                    $marksheet = 'marksheet_' . $registration->registrationNo . '.' . $request->file('marksheet')->getClientOriginalExtension();
                    $request->file('marksheet')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $marksheet);
                    $regdoc->marksheet = $marksheet;
                }

                //store migration certificate
                if ($request->hasFile('migrationCertificate')) {
                    $mc = 'migration-certificate_' . $registration->registrationNo . '.' . $request->file('migrationCertificate')->getClientOriginalExtension();
                    $request->file('migrationCertificate')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $mc);
                    $regdoc->migrationCertificate = $mc;
                }



                //store slc
                if ($request->hasFile('slc')) {
                    $slc = 'slc_' . $registration->registrationNo . '.' . $request->file('slc')->getClientOriginalExtension();
                    $request->file('slc')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $slc);
                    $regdoc->slc = $slc;
                }

                //store otherdoc
                if ($request->hasFile('otherdoc')) {
                    $od = 'otherdoc_' . $registration->registrationNo . '.' . $request->file('otherdoc')->getClientOriginalExtension();
                    $request->file('otherdoc')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $od);
                    $regdoc->otherdoc = $od;
                }
                if ($regdoc->otherdoc != null || $regdoc->photo != null || $regdoc->aadharCopy != null || $regdoc->marksheet != null || $regdoc->migrationCertificate != null || $regdoc->slc != null) {
                    $regdoc->save();
                }
            }
        }
        $student->update();
        if (is_array($request->siblings)) {
            if (count($request->siblings) > 0) {
                foreach ($request->siblings as $key => $value) {
                    if ($value['fName'] != null) {
                        if (isset($value['id'])) {
                            $updtsibling = \App\StudentRegSibling::find($value['id']);
                            if ($updtsibling != null) {
                                $updtsibling->idRegistration = $student->idRegistration;
                                $updtsibling->fName = $value['fName'];
                                $updtsibling->lName = $value['lName'];
                                $updtsibling->age = $value['age'];
                                $updtsibling->education = $value['education'];
                                $updtsibling->schoolName = $value['schoolName'];
                                $updtsibling->update();
                            }
                        } else {
                            $sibling = new \App\StudentRegSibling();
                            $sibling->fill($request->all());
                            $sibling->idRegistration = $student->idRegistration;
                            $sibling->fName = $value['fName'];
                            $sibling->lName = $value['lName'];
                            $sibling->age = $value['age'];
                            $sibling->education = $value['education'];
                            $sibling->schoolName = $value['schoolName'];
                            $sibling->save();
                        }
                    }
                }
            }
        }
        DB::commit();
        flash('Student has been updated successfully !!');
        return redirect('school/registered-students');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id) {
        //
    }

    public function onlineRegForm($schname) {
        $school = \App\School::where('schoolName', '=', $schname)
                ->where('onlineregFormActive', '=', 'Y')
                ->first();
        if($school == null){
            $school = \App\School::where('short_code_online', '=', $schname)
                ->where('onlineregFormActive', '=', 'Y')
                ->first();
        }

        if (!empty($school)) {
            $studentCategory = \App\StudentCategoryModel::where('idSchool', '=', $school->idSchool)->get()->pluck('categoryName', 'categoryName')->toArray();
            $classes = ['' => '---Select---'] + \App\ClassM::where('idSchool', '=', $school->idSchool)->get()->pluck('className', 'idClass')->toArray();
            $sessions = \App\FinancialYear::where('idSchool', '=', $school->idSchool)->orderBy('startDate', 'DESC')->get()->pluck('financialYearName', 'idFinancialYear')->toArray();
            if ($school->idSchool == 25) {
                return view('onlinereg.regform_royal', compact('school', 'classes', 'studentCategory', 'sessions'));
            } else if ($school->idSchool == 135 || $school->idSchool == 140 || $school->idSchool == 159 || $school->idSchool == 160) {
                return view('onlinereg.regform_mhws', compact('school', 'classes', 'studentCategory', 'sessions'));
            } else {
                return view('onlinereg.regform', compact('school', 'classes', 'studentCategory', 'sessions'));
            }
        } else {
            return view('errors.404');
        }
    }

    public function enquiryForm($schname) {
        $school = \App\School::where('schoolName', '=', $schname)
                ->where('onlineregFormActive', '=', 'Y')
                ->first();
        if (!empty($school)) {
            $studentCategory = \App\StudentCategoryModel::where('idSchool', '=', $school->idSchool)->get()->pluck('categoryName', 'categoryName')->toArray();
            $fy = ['' => '---Select---'] + \App\FinancialYear::where('idSchool', '=', $school->idSchool)->orderBy('startDate', 'DESC')->get()->pluck('financialYearName', 'idFinancialYear')->toArray();
            $classes = ['' => '---Select---'] + \App\ClassM::where('idSchool', '=', $school->idSchool)->get()->pluck('className', 'idClass')->toArray();
            if ($school->idSchool == 25) {
                return view('onlinereg.enquiry_royal', compact('school', 'classes', 'studentCategory','fy'));
            } else
                return view('onlinereg.enquiry_global', compact('school', 'classes', 'studentCategory','fy'));
        } else {
            return view('errors.404');
        }
    }

    public function registrationSuccessPage($schname) {
        $school = \App\School::where('schoolName', '=', $schname)->first();
        $regNo = Session::get('registrationNo');
        $regno = Session::get('registrationNo');
        return view('onlinereg.registration-success', compact('school', 'regNo','regno'));
    }

    public function successPage($schname, $regno) {
        $school = \App\School::where('schoolName', '=', $schname)->first();
        if ($school->idSchool == 25) {
            $registration = \App\StudentRegistration::where('registrationNo', '=', $regno)->first();
            $uploaded = \App\StdRegistrationMaster::where('idRegistration', '=', $registration->idRegistration)->get()->pluck('documentName')->toArray();
            $documentMaster = \App\DocumentType::where('idSchool', '=', $school->idSchool)->where('type', 'Student')->orderBy('idDocType', 'ASC')->get()->pluck('documentType', 'idDocType')->toArray();
            return view('onlinereg.royal-success', compact('school', 'regno', 'registration', 'documentMaster', 'uploaded'));
        } else
            return view('onlinereg.registration-success', compact('school', 'regno'));
    }

    public function uploadDocumentForm($regno) {
        $registration = \App\StudentRegistration::where('registrationNo', '=', $regno)->first();
        $school = \App\School::where('idSchool', '=', $registration->idSchool)->first();
        $documentMaster = \App\DocumentType::where('idSchool', '=', $school->idSchool)->where('type', 'Student')->orderBy('idDocType', 'ASC')->get()->pluck('documentType')->toArray();     
        return view('onlinereg.upload-documents', compact('registration', 'school','documentMaster'));
    }

    public function uploadDocument(Request $request) {
        $registration = \App\StudentRegistration::where('registrationNo', '=', $request->registrationNo)->first();
        Session::put('registrationNo', $request->registrationNo);
        $school = \App\School::where('idSchool', '=', $registration->idSchool)->first();

        if ($school->idSchool == 25) {
            $documentMaster = \App\DocumentType::where('idSchool', '=', $school->idSchool)->where('type', 'Student')->orderBy('idDocType', 'ASC')->get()->pluck('documentType', 'idDocType')->toArray();
            $error = null;
            foreach ($documentMaster as $key => $value) {
                $regdocument = \App\StdRegistrationMaster::where('idRegistration', '=', $registration->idRegistration)->where('documentName', '=', $value)->first();
                if ($regdocument == null) {
                    $regdoc = new \App\StdRegistrationMaster();
                    $regdoc->idRegistration = $registration->idRegistration;
                    $regdoc->documentName = $value;
                    $keyValue = str_replace(' ', '_', strtolower($value));
                    if ($request->hasFile($keyValue)) {
                        $document = $keyValue . '_' . $registration->registrationNo . '.' . $request->file($keyValue)->getClientOriginalExtension();
                        $request->file($keyValue)->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $document);
                        $regdoc->path = $document;
                        $regdoc->save();
                    } else {
                        $error = $value . ' not uploaded!';
                    }
                } else {
                    $keyValue = str_replace(' ', '_', strtolower($value));
                    if ($request->hasFile($keyValue)) {
                        $document = $keyValue . '_' . $registration->registrationNo . '.' . $request->file($keyValue)->getClientOriginalExtension();
                        $request->file($keyValue)->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $document);
                        $regdocument->path = $document;
                        $regdocument->update();
                    }
                }
            }
            //if($error != null)
            //return redirect()->back()->with('error', $error);
        } else {
            $regdoc = new \App\StdRegistrationDocumnet();
            $regdoc->idRegistration = $registration->idRegistration;
            //store photo
            if ($request->hasFile('photo')) {
                $photo = 'photo_' . $registration->registrationNo . '.' . $request->file('photo')->getClientOriginalExtension();
                $request->file('photo')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $photo);
                $regdoc->photo = $photo;
            } else {
                return redirect()->back()->with('error', 'Photo not uploaded!');
            }

            //store aadhhar
            if ($request->hasFile('aadharCopy')) {
                $aadhaar = 'aadhaar_' . $registration->registrationNo . '.' . $request->file('aadharCopy')->getClientOriginalExtension();
                $request->file('aadharCopy')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $aadhaar);
                $regdoc->aadharCopy = $aadhaar;
            }

            //store marksheet
            if ($request->hasFile('marksheet')) {
                $marksheet = 'marksheet_' . $registration->registrationNo . '.' . $request->file('marksheet')->getClientOriginalExtension();
                $request->file('marksheet')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $marksheet);
                $regdoc->marksheet = $marksheet;
            }

            //store migration certificate
            if ($request->hasFile('migrationCertificate')) {
                $mc = 'migration-certificate_' . $registration->registrationNo . '.' . $request->file('migrationCertificate')->getClientOriginalExtension();
                $request->file('migrationCertificate')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $mc);
                $regdoc->migrationCertificate = $mc;
            }

            if ($request->hasFile('casteCopy')) {
                $aadhaar = 'caste_' . $registration->registrationNo . '.' . $request->file('casteCopy')->getClientOriginalExtension();
                $request->file('casteCopy')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $aadhaar);
                $regdoc->casteCopy = $aadhaar;
            }

            if ($request->hasFile('birthCopy')) {
                $aadhaar = 'birth' . $registration->registrationNo . '.' . $request->file('birthCopy')->getClientOriginalExtension();
                $request->file('birthCopy')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $aadhaar);
                $regdoc->birthCopy = $aadhaar;
            }

            //store slc
            if ($request->hasFile('slc')) {
                $slc = 'slc_' . $registration->registrationNo . '.' . $request->file('slc')->getClientOriginalExtension();
                $request->file('slc')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $slc);
                $regdoc->slc = $slc;
            }

            //store otherdoc
            if ($request->hasFile('otherdoc')) {
                $od = 'otherdoc_' . $registration->registrationNo . '.' . $request->file('otherdoc')->getClientOriginalExtension();
                $request->file('otherdoc')->storeAs('public/schools/' . $school->idSchool . '/onlinereg/', $od);
                $regdoc->otherdoc = $od;
            }
            $regdoc->save();
        }

        if ($school->regPaymentLink != null) {
            return redirect()->away($school->regPaymentLink);
        } else {
            return redirect('onlinereg/success/' . $school->schoolName);
        }
//        
    }



    public function openVirtualCard($id, Request $request){
        $data = [];
        $data['url'] = $id;
        $virutal = \App\CardMaster::where('link_id', '=', $id)->first();
        if($virutal == null)
        {
            $data['result'] = 0;
            $data['error'] = "No data found";
        }
        else {
            $data['result'] = 1;
            $data['startDate'] = $virutal->start_date;
            $data['endDate'] = $virutal->end_date;
            $data['id'] = $virutal->id;
            $data['idSchool'] = $virutal->idSchool;
            $data['idFinancialYear'] = $virutal->idFinancialYear;
            if(Carbon::parse($virutal->start_date)->gte(Carbon::now())){
                $data['start_count'] = $virutal->start_date;
                $data['is_started'] = 0;
                return view('schools.virtualcard.coming_soon',compact('data'));
            }

            if(Carbon::parse($virutal->end_date)->gte(Carbon::now())){
                $data['start_count'] = $virutal->end_date;
                $data['is_started'] = 1;
                if($request->get('edit') == "Y"){
                    return view('schools.virtualcard.virtual-card',compact('data'));
                }else
                return view('schools.virtualcard.coming_soon',compact('data'));
            }

            if(Carbon::parse($virutal->end_date)->lte(Carbon::now())){
                $data['result'] = 0;
                $data['error'] = "No data found";
                return view('schools.virtualcard.virtual-card',compact('data'));
            }

        } 
        return view('schools.virtualcard.virtual-card',compact('data'));
    }

    public function saveVirtualCard(Request $request){
        $school = \App\School::where('idSchool', '=', $request->idSchool)->first();
        if($school->isActive == 'Y'){
            $card = new \App\CardView();
            $classes = \App\ClassM::where('idClass', '=', $request->idClass)->first();
            $card->className = $classes->className;
            $card->idClass = $classes->idClass;
            $card->idSchool = $request->idSchool;
            $card->idFinancialYear = $request->idFinancialYear;
            $card->sectionName = "";
            $fatherName = '';
            if(isset($request->father_fname)){
                $fatherName = $fatherName.trim($request->father_fname).' ';
            }
            if(isset($request->father_lname)){
                $fatherName = $fatherName.trim($request->father_lname).' ';
            }

            $motherName = '';
            if(isset($request->mother_fname)){
                $motherName = $motherName.trim($request->mother_fname).' ';
            }
            if(isset($request->mother_lname)){
                $motherName = $motherName.trim($request->mother_lname).' ';
            }

            $studentName = '';
            if(isset($request->firstName)){
                $studentName = $studentName.trim($request->firstName).' ';
            }
            if(isset($request->middleName)){
                $studentName = $studentName.trim($request->middleName).' ';
            }
            if(isset($request->lastName)){
                $studentName = $studentName.trim($request->lastName).' ';
            }

            $state = \App\State::where('idState',$request->resState)->first()->stateName;
            $card->parentName = $fatherName;
            $card->isVerified = 'Y';
            $card->parentDate = Carbon::today()->format('Y-m-d');
            $card->studentName = $studentName;
            $card->address = $request->resAddress.' '.$request->resCity.' '.$state.' '.$request->resPincode;
            $card->student_dob = $request->studentDob;
            $card->gender = $request->gender;
            $card->city = $request->resCity;
            $card->pincode = $request->resPincode;
            $card->blood_group = $request->blood_group;
            $card->motherName = $motherName;
            $card->state = $state;
            $card->contact_alternative = $request->mother_mobile;
            $card->contactNo = $request->father_mobile;
            $card->save();

            if ($request->hasFile('photo')) {
                $photo = 'virtualcard_' . $card->id. '.' . $request->file('photo')->getClientOriginalExtension();
                $request->file('photo')->storeAs('public/schools/' . $school->idSchool . '/students/', $photo);
                $card->photo = $photo;
                $card->update();
            }

            return redirect('/id-card-confirmation/created?id='.$card->id);

        }else{
            return redirect('/id-card-confirmation/error');
        }
    }

    public function confirmCard($id, Request $request){
        $data = [];
        if($id == "created" && $request->get('id') != ""){
            $card = \App\CardView::where('id',$request->get('id'))->first();
            $school = \App\School::where('idSchool', '=', $card->idSchool)->first();
            return view('schools.virtualcard.confirm',compact('card','school'));
        }else{
            $data['result'] = 0;
            $data['error'] = "No data found";
            return view('schools.virtualcard.virtual-card',compact('data'));
        }
    }
}

Copyright © 2021 - 2025 IMMREX7