app/Http/Controllers/Admin/StudentReportsController.php
/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
Display a listing of the resource.
@return \Illuminate\Http\Response
Display a listing of the resource . @return \ Illuminate \ Http \ Response
public function index()
    {
        $students = Role::find(config('global.STUDENT_ROLE_ID'))->users()->get();
        $student_reports = Array();
        foreach($students as $student)
        {
            $invoices = Invoice::where('user_id', $student->id);
            $total_hours = array_sum($invoices->get('total_hours')->pluck('total_hours')->toArray());
            $total_amount = array_sum($invoices->get('total_amount')->pluck('total_amount')->toArray());
            $orders = Order::where('user_id', $student->id)
             -> where('package_id', '!=', 0)
             -> where('status_id', 5);
            $total_hours += array_sum($orders->get('total_hours')->pluck('total_hours')->toArray());
            $total_amount += array_sum($orders->get('total')->pluck('total')->toArray());
            $sessions = Session::whereHas('assignments', function($assignment) use ($student){
                return $assignment->where('student_id', $student->id);
            })->get();
            $total_revenues = $this->stuff($sessions);
            $student_reports[] = array("Id" => $student['id']
            , "Student Name" => $student['fname'] . ' ' . $student['lname']
            , 'Email' => $student['email'], 'City' => $student['city']
            , 'Total Hours' => $total_hours, 'Total Revenues' =>$total_amount
            , 'Total Profits' => $total_amount - $total_revenues);
        }
        return view('admin.studentreports.index')->with('reports', $student_reports);
    }
public function index ( ) { $ students = Role :: find ( config ( 'global.STUDENT_ROLE_ID' ) ) -> users ( ) -> get ( ) ; $ student_reports = Array ( ) ; foreach ( $ students as $ student ) { $ invoices = Invoice :: where ( 'user_id' , $ student -> id ) ; $ total_hours = array_sum ( $ invoices -> get ( 'total_hours' ) -> pluck ( 'total_hours' ) -> toArray ( ) ) ; $ total_amount = array_sum ( $ invoices -> get ( 'total_amount' ) -> pluck ( 'total_amount' ) -> toArray ( ) ) ; $ orders = Order :: where ( 'user_id' , $ student -> id ) -> where ( 'package_id' , '!=' , 0 ) -> where ( 'status_id' , 5 ) ; $ total_hours += array_sum ( $ orders -> get ( 'total_hours' ) -> pluck ( 'total_hours' ) -> toArray ( ) ) ; $ total_amount += array_sum ( $ orders -> get ( 'total' ) -> pluck ( 'total' ) -> toArray ( ) ) ; $ sessions = Session :: whereHas ( 'assignments' , function ( $ assignment ) use ( $ student ) { return $ assignment -> where ( 'student_id' , $ student -> id ) ; } ) -> get ( ) ; $ total_revenues = $ this -> stuff ( $ sessions ) ; $ student_reports [ ] = array ( " Id " => $ student [ 'id' ] , " Student Name " => $ student [ 'fname' ] . ' ' . $ student [ 'lname' ] , 'Email' => $ student [ 'email' ] , 'City' => $ student [ 'city' ] , 'Total Hours' => $ total_hours , 'Total Revenues' => $ total_amount , 'Total Profits' => $ total_amount - $ total_revenues ) ; } return view ( 'admin.studentreports.index' ) -> with ( 'reports' , $ student_reports ) ; }
Display a listing of the resource.
Display a listing of the resource .
//dd($students); //Get Total Hours and Total Amount of Invoices //Get Total Hours and Total Amount of Orders //Get Total Revenuses