IMMREX7

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

<?php

namespace App\Http\Controllers\School;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
use Auth;
use Carbon\Carbon;
use App\Http\SendSmsApi;
use PDF;

class CreditNoteController extends SchoolController {

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request) {
        $creditnotes = \App\CreditNote::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->orderBy('idNotes', 'desc')->get();
        return view('schools.reports.creditnotes', compact('creditnotes'));
    }

    /**
     * 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->has('students') && $request->students != null) {
            if ($request->has('credit')) {
                $rules += ['creditNote' => 'required'];
            } else {
                $rules += ['message' => 'required'];
            }
        }else{
            $rules += ['student' => 'required'];
        }
        $messages = ['creditNote.required'=>'Credit Note Message is mandatory','student.required'=>'Atleast One student must be selected'];
        $this->validate($request, $rules,$messages);
        if ($request->has('credit')) {
            foreach ($request->students as $var) {
                //    dd($var);
                $creditnote = new \App\CreditNote();
                $creditnote->fill($request->all());
                $creditnote->idSchool = Auth::guard('school')->user()->idSchool;
                $creditnote->idStudent = $var;
                $creditnote->save();
            }
            return redirect('school/creditnotes');
        } else {
            $school = \App\School::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->first();
            $message = $request->message;
            foreach ($request->students as $value) {
                $std = \App\AdmEntry::where('idStudent', '=', $value)->first();
                $sms = new \App\SMSModel();
                $sms->fill($request->all());
                $sms->idStudent = $value;
                $sms->idSection = $std->idSection;
                $sms->idSchool = $school->idSchool;
                //   $sms->save();
                //get all number to which msg to be sent
                $cn[] = $std->father_mobile;
            }
            // SMS API Integration Statrt
            $phone_number = implode(',', $cn);
            SendSmsApi::getUserNumber($phone_number, $message, $school);
            //     SMS API Integration end
            flash('Sms has been sent successfully');
            return redirect('school/stdduedata');
        }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id) {
        $cnote = \App\CreditNote::where('idNotes', '=', $id)->first();
        $school = \App\School::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->first();
        $student = \App\AdmEntry::where('idStudent', '=', $cnote->idStudent)->first();
        $class_feeheads = \DB::table('feeheads')->where('idClass', '=', $student->idClass)
                ->where('idSection', '=', $student->idSection)
                ->where('studentCategory', '=', $student->studentType)
                ->whereNull('idStudent');
        //   ->get();
        $allcat_feeheads = \DB::table('feeheads')->where('idClass', '=', $student->idClass)
                ->where('idSection', '=', $student->idSection)
                ->where('studentCategory', '=', 'All')
                ->whereNull('idStudent');
        //   ->get();
        $feeheads = \DB::table('feeheads')->where('idStudent', '=', $student->idStudent)
                ->union($class_feeheads)
                ->union($allcat_feeheads)
                ->orderBy('toDate')
                ->get();
        $feetotal = $feeheads->sum('amount');
        $transaction = \App\StudentTransaction::where('idStudent', '=', $student->idStudent)
                ->select(DB::raw('SUM(excessAmount) as excessAmount'), DB::raw('SUM(totalPaid) as totalPaid'), DB::raw('SUM(discount) as discount'), DB::raw('SUM(fine) as fine'), DB::raw('SUM(penaltyAmount) as penaltyAmount'))
                ->first();
        $balance = $feetotal + $transaction->fine + $transaction->penaltyAmount - $transaction->discount - $transaction->totalPaid;
        $pdf = PDF::loadView('schools.reports.print_creditnotes', ['margin_top' => 40], compact('balance', 'cnote', 'student', 'school'));
        return $pdf->stream('creditnotes.pdf');
    }

    /**
     * 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) {
        //
    }

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

    public function StudentDues(Request $request) {
        $today_date = Carbon::today()->format('Y-m-d');
        if ($request->has('fromDate') && $request->fromDate != null) {
            $from_date = Carbon::createFromFormat('d-m-Y', $request->fromDate);
        }
        if ($request->has('toDate') && $request->toDate != null) {
            $to_date = Carbon::createFromFormat('d-m-Y', $request->toDate);
        }
        $classes = \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
        $school = \App\School::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->first();

        $students = \App\AdmEntry::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                ->where('isActive','Y')
                ->orderBy('idStudent');
        if ($request->has('sections') && count($request->sections) > 0) {
            $students = $students->whereIn('idSection', $request->sections)->get();
        } else if ($request->has('classes') && count($request->classes) > 0) {
            $students = $students->whereIn('idClass', $request->classes)->get();
        } else {
            $students = $students->get();
        }
        return view('schools.reports.pending_fee_creditnote', compact('classes', 'students','school'));
    }
    
    public function printCreditNote(Request $request) {
        $rules = [];
        if (!$request->has('notes')) {
            $rules += ['student' => 'required'];
        }
        $messages = ['student.required'=>'Atleast One Note must be selected for Printing'];
        $this->validate($request, $rules,$messages);
        
        $cnotes = \App\CreditNote::whereIn('idNotes', $request->notes)->get();
        $school = \App\School::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->first();
        
        $pdf = PDF::loadView('schools.reports.print_creditnotes', ['margin_top' => 40], compact('cnotes','school'));
        return $pdf->stream('creditnotes.pdf');
    }

}

Copyright © 2021 - 2025 IMMREX7