IMMREX7

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

<?php

namespace App\Http\Controllers\School\Library;

use Illuminate\Http\Request;
use App\Http\Controllers\School\SchoolController;
use DB;
use Auth;
use Carbon\Carbon;
use PDF;

class ReportController extends SchoolController {

    public function defaulterReport(Request $request) {
        $type = $request->type;
        $defaulters = [];
        $fine = \App\LibraryFineMaster::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                ->first();
        if ($request->type == 'student') {
            $defaulters = DB::table('book_issue_return')
                    ->join('books', 'book_issue_return.idBook', '=', 'books.idBook')
                    ->join('students', 'book_issue_return.idMember', '=', 'students.idStudent')
                    ->join('classes', 'students.idClass', '=', 'classes.idClass')
                    ->join('sections', 'students.idSection', '=', 'sections.idSection')
                    ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                    ->where('book_issue_return.memberType', '=', 'student')
                    ->where('isReturn', '=', 'N')
                    ->whereDate('expectedReturnDate', '<', Carbon::now())
                    ->select('title', 'expectedReturnDate', 'rfid', 'accessionNo', 'issueDate', 'returnDate', 'ecNo', 'studentDob', 'idStudent', 'father_mobile', 'className', 'sectionName', 'father_fname', 'father_lname', 'firstName', 'middleName', 'lastName')
                    ->get();
        } elseif ($request->type == 'employee') {
            $defaulters = DB::table('book_issue_return')
                    ->join('books', 'book_issue_return.idBook', '=', 'books.idBook')
                    ->join('departments', 'employees.idDepartment', '=', 'departments.idDepartment')
                    ->join('designations', 'employees.idDesignation', '=', 'designations.idDesignation')
                    ->where('employees.idSchool', '=', Auth::guard('school')->user()->idSchool)
                    ->where('book_issue_return.memberType', '=', 'employee')
                    ->where('isReturn', '=', 'N')
                    ->whereDate('expectedReturnDate', '<', Carbon::now())
                    ->select('title', 'rfid', 'expectedReturnDate', 'accessionNo', 'issueDate', 'returnDate', 'ecNo', 'idEmployee', 'mobile', 'departmentName', 'designationName', 'firstName', 'middleName', 'lastName')
                    ->get();
        }
        return view('schools.library.defaulter_list', compact('defaulters', 'type', 'fine'));
    }

    public function collectionReport(Request $request) {
        $type = $request->type;
        $data = [];
        if ($request->type == 'student') {
            $data = DB::table('library_transaction')
                    ->join('books', 'library_transaction.idBook', '=', 'books.idBook')
                    ->join('students', 'library_transaction.idMember', '=', 'students.idStudent')
                    ->join('classes', 'students.idClass', '=', 'classes.idClass')
                    ->join('sections', 'students.idSection', '=', 'sections.idSection')
                    ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                    ->where('library_transaction.memberType', '=', 'student')
                    ->where(function($query) {
                        $query->whereNull('status');
                        $query->orWhere('status', '=', 'Cleared');
                        $query->orWhere('status', '=', 'In-Process');
                        $query->orWhere('status', '=', 'Success');
                    })
                    ->select('library_transaction.*', 'father_lname', 'father_fname', 'title', 'rfid', 'accessionNo', 'ecNo', 'studentDob', 'idStudent', 'father_mobile', 'className', 'sectionName', 'father_fname', 'father_lname', 'firstName', 'middleName', 'lastName')
                    ->get();
        } elseif ($request->type == 'employee') {
            $data = DB::table('library_transaction')
                    ->join('books', 'library_transaction.idBook', '=', 'books.idBook')
                    ->join('departments', 'employees.idDepartment', '=', 'departments.idDepartment')
                    ->join('designations', 'employees.idDesignation', '=', 'designations.idDesignation')
                    ->where('employees.idSchool', '=', Auth::guard('school')->user()->idSchool)
                    ->where('library_transaction.memberType', '=', 'employee')
                    ->where(function($query) {
                        $query->whereNull('status');
                        $query->orWhere('status', '=', 'Cleared');
                        $query->orWhere('status', '=', 'In-Process');
                        $query->orWhere('status', '=', 'Success');
                    })
                    ->select('title', 'rfid', 'father_lname', 'father_fname', 'accessionNo', 'ecNo', 'idEmployee', 'mobile', 'departmentName', 'designationName', 'firstName', 'middleName', 'lastName')
                    ->get();
        }
        return view('schools.library.collection_report', compact('data', 'type'));
    }

    public function bookReport(Request $request) {
        $type = $request->type;
        $data = [];
        $fine = \App\LibraryFineMaster::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                ->first();
        if ($request->type == 'student') {
            $data = DB::table('book_issue_return')
                    ->join('books', 'book_issue_return.idBook', '=', 'books.idBook')
                    ->join('students', 'book_issue_return.idMember', '=', 'students.idStudent')
                    ->join('classes', 'students.idClass', '=', 'classes.idClass')
                    ->join('sections', 'students.idSection', '=', 'sections.idSection')
                    ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                    ->where('book_issue_return.memberType', '=', 'student')
                    ->select('title', 'rfid', 'accessionNo', 'issueDate', 'returnDate', 'ecNo', 'studentDob', 'idStudent', 'father_mobile', 'className', 'sectionName', 'father_fname', 'father_lname', 'firstName', 'middleName', 'lastName')
                    ->get();
        } elseif ($request->type == 'employee') {
            $data = DB::table('book_issue_return')
                    ->join('books', 'book_issue_return.idBook', '=', 'books.idBook')
                    ->join('departments', 'employees.idDepartment', '=', 'departments.idDepartment')
                    ->join('designations', 'employees.idDesignation', '=', 'designations.idDesignation')
                    ->where('employees.idSchool', '=', Auth::guard('school')->user()->idSchool)
                    ->where('book_issue_return.memberType', '=', 'employee')
                    ->select('title', 'rfid', 'accessionNo', 'issueDate', 'returnDate', 'ecNo', 'idEmployee', 'mobile', 'departmentName', 'designationName', 'firstName', 'middleName', 'lastName')
                    ->get();
        }
        return view('schools.library.issue_return_report', compact('data', 'type', 'fine'));
    }

    public function defaulterSMS(Request $request) {
        $rules = [];
        if ($request->has('members') && $request->members != null) {
            $rules += ['message' => 'required'];
        } else {
            $rules += ['member' => 'required'];
        }
        $messages = ['member.required' => 'Atleast One Member must be selected'];
        $this->validate($request, $rules, $messages);

        $school = \App\School::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->first();
        $message = $request->message;
        if ($request->type == 'student') {
            foreach ($request->members 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
            if($school->notificationmode == "auto"){
                $reg_ids = DB::table('students')
                                ->join('parents', 'students.father_mobile', '=', 'parents.mobile')
                                ->select('parents.idFirebase')
                                ->where('students.idStudent', $value)
                                ->get()->pluck('idFirebase')->toArray();
                SendNotificationApi::sendSingleNotification($reg_ids, $message);
                $reg_ids = DB::table('students')
                                        ->join('parents', 'students.mother_mobile', '=', 'parents.mobile')
                                        ->select('parents.idFirebase')
                                        ->where('students.idStudent', $value)
                                        ->get()->pluck('idFirebase')->toArray();
                SendNotificationApi::sendSingleNotification($reg_ids, $message);
            } 
            flash('Notification has been sent successfully');
            return redirect('school/defauters');
        } else {
            foreach ($request->members as $value) {
                $emp = \App\Employee::where('idEmployee', '=', $value)->first();
                $sms = new \App\SMSModel();
                $sms->fill($request->all());
                $sms->idTeacher = $value;
                $sms->cardholder = 'employee';
                $sms->idSchool = $school->idSchool;
                //   $sms->save();
                //get all number to which msg to be sent
                $cn[] = $emp->mobile;
            }
            // SMS API Integration Statrt
            $phone_number = implode(',', $cn);
            //SendSmsApi::getUserNumber($phone_number, $message, $school);
            //     SMS API Integration end
            flash('Notification has been sent successfully');
            return redirect('school/defauters');
        }
    }

    public function printReceipt($type, $id) {
        $school = \App\School::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->first();
        if ($type == 'student') {
            $transaction = \App\LibraryTransaction::where('idLibraryTransaction', '=', $id)->first();
            $student = \App\AdmEntry::where('idStudent','=',$transaction->idMember)->first();
            $pdf = PDF::loadView('schools.library.print_receipt', ['margin_top' => 20], compact('student','transaction',  'school'));
            return $pdf->stream('invoice.pdf');
        } else {
            $transaction = \App\LibraryTransaction::where('idLibraryTransaction', '=', $id)->first();
            $student = \App\Employee::where('idEmployee','=',$transaction->idMember)->first();
            $pdf = PDF::loadView('schools.library.print_receipt', ['margin_top' => 20], compact('student','transaction', 'school'));
            return $pdf->stream('invoice.pdf');
        }
    }

    public function cancelReceipt($id) {
        $pay = \App\LibraryTransaction::where('idLibraryTransaction', '=', $id)->first();
        $pay->status = 'Cancelled';
        $pay->update();
        return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
    }

}

Copyright © 2021 - 2025 IMMREX7