public function loadEarnables($issue_id)
 {
     $issue = Issue::find($issue_id);
     $receivable = Receivable::with('installments_not_paid')->where('issue_id', '=', $issue_id)->first();
     $registrations = Registration::where('student_id', '=', $issue->student_id)->where('cost_is_paid', '=', 0)->get();
     $movements = Movement::where('issue_id', '=', $issue_id)->get();
     $punishments = Punishment::where('issue_id', '=', $issue_id)->where('paid', '=', 0)->get();
     $resigns = Resign::where('issue_id', '=', $issue_id)->where('is_earned', '=', 0)->get();
     $responses = array('receivable' => $receivable, 'registrations' => $registrations, 'movements' => $movements, 'punishments' => $punishments, 'resigns' => $resigns);
     return $responses;
 }
 public function create($issue_id)
 {
     $issue = Issue::find($issue_id);
     $receivable = Receivable::with('installments')->where('issue_id', '=', $issue_id)->first();
     $registration = Registration::where('student_id', '=', $issue->student_id)->where('cost_is_paid', '=', 0)->first();
     $movements = Movement::where('issue_id', '=', $issue_id)->where('paid', '=', 0)->get();
     $punishments = Punishment::where('issue_id', '=', $issue_id)->where('paid', '=', 0)->get();
     $resigns = Resign::where('issue_id', '=', $issue_id)->where('fines', '>', 0.0)->where('is_earned', '=', 0)->get();
     $employees = Employee::where('location_id', '=', Auth::user()->location_id)->get();
     $menu = 'finance';
     return View::make('earnings.create', compact('issue', 'receivable', 'registration', 'movements', 'punishments', 'resigns', 'employees', 'menu'));
 }
 public function showDashboard()
 {
     $menu = '';
     $_301 = Issue::where('generation_id', '=', 1)->where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->count();
     $_201 = Issue::where('generation_id', '=', 2)->where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->count();
     $_101 = Issue::where('generation_id', '=', 3)->where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->count();
     $_302 = Issue::where('generation_id', '=', 4)->where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->count();
     $_202 = Issue::where('generation_id', '=', 5)->where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->count();
     $_102 = Issue::where('generation_id', '=', 6)->where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->count();
     $_603 = Issue::where('generation_id', '=', 7)->where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->count();
     $_503 = Issue::where('generation_id', '=', 8)->where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->count();
     $_403 = Issue::where('generation_id', '=', 9)->where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->count();
     $last_month_registrations = Registration::where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->where(DB::raw('month(registration_date)'), '<>', date('m'))->where(DB::raw('year(registration_date)'), '=', date('Y'))->count();
     $curr_month_registrations = Registration::where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->where(DB::raw('month(registration_date)'), '=', date('m'))->where(DB::raw('year(registration_date)'), '=', date('Y'))->count();
     $movement_registrations = Registration::where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->where('classification_id', '=', 10)->count();
     $curr_active_students = Placement::where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->where('active', '=', 1)->count();
     $curr_do_students = Resign::where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->where('classification_id', '=', 13)->count();
     $curr_resign_students = Resign::where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->where('classification_id', '=', 14)->count();
     $curr_relocate_students = Resign::where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->where('classification_id', '=', 15)->count();
     $courses = Course::where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->get();
     return View::make('dashboard.home', compact('_301', '_201', '_101', '_302', '_202', '_102', '_603', '_503', '_403', 'last_month_registrations', 'curr_month_registrations', 'movement_registrations', 'curr_active_students', 'curr_do_students', 'curr_resign_students', 'curr_relocate_students', 'courses', 'menu'));
 }
 public function recapCirculationPeriodic()
 {
     $registrations = Classification::where('category', '=', 'Registration')->get();
     $resigns = Classification::where('category', '=', 'Resign')->get();
     $periods = DB::table('registrations')->select(DB::raw('month(registration_date) as months'), DB::raw('year(registration_date) as years'))->groupBy(DB::raw('month(registration_date)'))->get();
     $comes = array();
     $leaves = array();
     foreach ($registrations as $registration) {
         $statistics = array();
         foreach ($periods as $period) {
             $count = Registration::where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->where(DB::raw('month(registration_date)'), '=', $period->months)->where(DB::raw('year(registration_date)'), '=', $period->years)->where('classification_id', '=', $registration->id)->count();
             $statistics[] = array('count' => $count);
         }
         $comes[] = array('name' => $registration->name, 'statistics' => $statistics);
     }
     foreach ($resigns as $resign) {
         $statistics = array();
         foreach ($periods as $period) {
             $count = Resign::where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->where(DB::raw('month(resign_date)'), '=', $period->months)->where(DB::raw('year(resign_date)'), '=', $period->years)->where('classification_id', '=', $resign->id)->count();
             $statistics[] = array('count' => $count);
         }
         $leaves[] = array('name' => $resign->name, 'statistics' => $statistics);
     }
     $menu = 'report';
     return View::make('reports.recapcirculationperiodic', compact('comes', 'leaves', 'periods', 'menu'));
 }