예제 #1
0
 /**
  * Display a listing of the resource.
  * GET /reports
  *
  * @return Response
  */
 public function index()
 {
     $reports = Report::orderBy('id', 'DESC')->get();
     echo "<pre>";
     print_r($reports);
     echo "</pre>";
     exit;
     $hoje = Carbon::now()->today();
     $ontem = Carbon::now()->yesterday();
     $anteontem = Carbon::now()->subDays(2);
     $reports->hoje = Report::where('created_at', '>=', $hoje)->orderBy('id', 'DESC')->get();
     $reports->ontem = Report::where('created_at', '=', $ontem)->orderBy('id', 'DESC')->get();
     $reports->anteontem = Report::where('created_at', '=', $anteontem)->orderBy('id', 'DESC')->get();
     $reports->anteriores = Report::where('created_at', '<', Carbon::now()->subDays(2))->orderBy('id', 'DESC')->get();
     if ($reports->hoje) {
         foreach ($reports->hoje as $report) {
             // Get HOUR:MINUTE from CREATED_AT
             $date = Carbon::createFromFormat('Y-m-d H:i:s', $report->created_at);
             $report->date = $date->hour . ':' . $date->minute;
         }
     }
     if ($reports->ontem) {
         foreach ($reports->ontem as $report) {
             // Get HOUR:MINUTE from CREATED_AT
             $date = Carbon::createFromFormat('Y-m-d H:i:s', $report->created_at);
             $report->date = $date->hour . ':' . $date->minute;
         }
     }
     return View::make('reports.index', compact('reports'));
 }
예제 #2
0
 public function getHoursFromReports($departmentId, $userId, $week, $year)
 {
     $hoursWorked = 0;
     $report = Report::where('department_id', '=', $departmentId)->where('user_id', '=', $userId)->where('week', '=', $week)->where('year', '=', $year)->first();
     if ($report) {
         $hoursWorked = $report->hours;
     }
     return round($hoursWorked, 2);
 }
예제 #3
0
 public function listActivities()
 {
     $c_u_result = User::where(DB::raw('date(created_at)'), Carbon::today())->get();
     $u_u_result = User::where(DB::raw('date(updated_at)'), Carbon::today())->where(DB::raw('date(created_at)'), '<', DB::raw('date(updated_at)'))->get();
     $c_a_result = Agency::where(DB::raw('date(created_at)'), Carbon::today())->get();
     $u_a_result = Agency::where(DB::raw('date(updated_at)'), Carbon::today())->where(DB::raw('date(created_at)'), '<', DB::raw('date(updated_at)'))->get();
     //retrive report activities
     $c_r_result = Report::where(DB::raw('date(Reports.created_at)'), Carbon::today())->where('isDeleted', 0)->leftjoin('ReportStatusType', 'ReportStatusType.reportStatusTypeId', '=', 'Reports.status')->leftjoin('ReportType', 'ReportType.ReportTypeId', '=', 'Reports.ReportType')->lists('reportName', 'reportedBy', 'location', 'reportStatusTypeName', 'reportTypeName', 'Reports.created_at', 'Reports.updated_at');
     $u_r_result = Report::where(DB::raw('date(Reports.updated_at)'), Carbon::today())->where(DB::raw('date(Reports.created_at)'), '<', DB::raw('date(Reports.updated_at)'))->where('isDeleted', 0)->leftjoin('ReportStatusType', 'ReportStatusType.reportStatusTypeId', '=', 'Reports.status')->leftjoin('ReportType', 'ReportType.ReportTypeId', '=', 'Reports.ReportType')->lists('reportName', 'reportedBy', 'location', 'reportStatusTypeName', 'reportTypeName', 'Reports.created_at', 'Reports.updated_at');
     $d_r_result = Report::where(DB::raw('date(Reports.deleted_at)'), Carbon::today())->where('isDeleted', 1)->leftjoin('ReportStatusType', 'ReportStatusType.reportStatusTypeId', '=', 'Reports.status')->leftjoin('ReportType', 'ReportType.ReportTypeId', '=', 'Reports.ReportType')->lists('reportName', 'reportedBy', 'location', 'reportStatusTypeName', 'reportTypeName', 'Reports.created_at', 'Reports.updated_at');
     $result = array('users_created' => $c_u_result, 'users_updated' => $u_u_result, 'agencies_created' => $c_a_result, 'agencies_updated' => $u_a_result, 'reports_created' => $c_r_result, 'reports_updated' => $u_r_result, 'reports_deleted' => $d_r_result);
     return Response::json($result)->setCallback(Input::get('callback'));
 }
예제 #4
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $reports = Report::where('user', $id)->get();
     return Response::json($reports, 200);
 }
 /**
  * Update the specified resource in storage.
  * PUT /reports/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     return $reports = Report::where('id', $id)->update(Input::all());
 }
 public function index()
 {
     $accidents = Report::where('type', 'Accident')->get();
     return Response::json($accidents, 200);
 }
예제 #7
0
 public function report()
 {
     $recordId = Input::get('record');
     $reason = Input::get('reason');
     if (!$reason) {
         Session::flash('error', 'Please enter a report reason!');
         return Redirect::back();
     }
     $count = Report::where('path_record_id', '=', $recordId)->count();
     if ($count > 0) {
         Session::flash('error', 'This path has already been reported');
         return Redirect::back();
     }
     // load record
     $record = PathRecord::findOrFail($recordId);
     if ($record->locked) {
         Session::flash('error', 'You cannot report this directory!');
         return Redirect::back();
     }
     $report = new Report();
     $report->path_record_id = $record->id;
     $report->path = $record->path;
     $report->reason = $reason;
     $user = Auth::user();
     if ($user) {
         $report->user_id = $user->id;
     }
     $report->save();
     Session::flash('success', 'Report submitted');
     return Redirect::back();
 }
예제 #8
0
 public function updateStatus()
 {
     $reportID = Input::get('reportID');
     $comment = Input::get('comment');
     $status = Input::get('status');
     $input = Input::all();
     $rules = array('Status' => 'numeric', 'comment' => 'max:255');
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         $error_messages = $validator->messages();
         $error_response = array('error' => array('message' => $error_messages->first(), 'type' => 'Exception', 'code' => 425));
         return Response::json($error_response, 425)->setCallback(Input::get('callback'));
     } else {
         $old_record = $this->getReportDetails($reportID)[0];
         Report::where('reportID', $reportID)->update(array('comment' => "{$comment}", 'status' => "{$status}"));
         $new_record = $this->getReportDetails($reportID)[0];
         $this->notify($old_record, $new_record);
         return "Report Updated.";
     }
 }
예제 #9
0
 public function reports()
 {
     return Report::where('tournaments.id', '=', $this->id)->join('games', 'games.id', '=', 'reports.game')->join('rounds', 'rounds.id', '=', 'games.round')->join('tournaments', 'tournaments.id', '=', 'rounds.tournament');
 }
예제 #10
0
 public function postShow($path)
 {
     $report = Report::where('path', $path)->first();
     $form_input = Input::all();
     $response = [];
     $cached_fields = [];
     $query = app($report->model);
     if (isset($form_input['grouping'])) {
         $grouping = ReportGrouping::findOrFail($form_input['grouping']);
         if (isset($form_input['sorting'])) {
             $column = ReportSorting::findOrFail($form_input['sorting']);
             $dir = 1;
             if (isset($form_input['sorting_dir'])) {
                 $dir = $form_input['sorting_dir'];
             }
             $query = $query->orderBy($column->name, $dir);
         }
         switch ($grouping->sql_function) {
             case 0:
                 $groups = $query->groupBy($grouping->name)->select($grouping->name)->get();
                 break;
             case 1:
                 $groups = $query->groupBy(DB::raw('year(' . $grouping->name . '), month(' . $grouping->name . ')'))->select(DB::raw('year(' . $grouping->name . ') as "year(' . $grouping->name . ')"'), DB::raw('month(' . $grouping->name . ') as "month(' . $grouping->name . ')"'))->get();
                 break;
             case 2:
                 $groups = $query->groupBy(DB::raw('year(' . $grouping->name . ')'))->select(DB::raw('year(' . $grouping->name . ') as "year(' . $grouping->name . ')"'))->get();
                 break;
         }
     } else {
         $groups = ['nogroup'];
     }
     foreach ($groups as $index => $wheres) {
         $query = app($report->model);
         $eagers = ReportEager::where('report_id', $report->id)->lists('name');
         foreach ($eagers as $eager) {
             $query = $query->with($eager);
         }
         if ($wheres !== 'nogroup') {
             foreach ($wheres->toArray() as $key => $value) {
                 $query = $query->where(DB::raw($key), $value);
             }
         }
         $update_query = function ($query, $field, $configs, $input) {
             switch ($field->type) {
                 case 1:
                     $query = $query->whereIn($configs[1], $input);
                     break;
                 case 2:
                     if ($configs[2] == 'from' && strlen($input) > 0) {
                         $query = $query->where($configs[1], '>=', $input);
                     }
                     if ($configs[2] == 'to' && strlen($input) > 0) {
                         $query = $query->where($configs[1], '<=', $input);
                     }
                     break;
                 case 4:
                 case 5:
                     $query = $query->where($configs[1], $input);
                     break;
                 case 6:
                     if (strlen($input) > 0) {
                         $query = $query->where($configs[1], 'like', '%' . $input . '%');
                     }
                     break;
             }
             return $query;
         };
         foreach ($form_input as $name => $value) {
             if (stristr($name, '|') !== false) {
                 $configs = explode('|', $name);
                 if (!isset($cached_fields[$configs[0]])) {
                     $cached_fields[$configs[0]] = ReportField::findOrFail($configs[0]);
                 }
                 $field = $cached_fields[$configs[0]];
                 if (stristr($field->name, '#') === false) {
                     $query = $update_query($query, $field, $configs, $value);
                 } else {
                     $tables_string = explode('#', $configs[1]);
                     $tables = array_reverse(explode('.', $tables_string[0]));
                     $configs[1] = $tables_string[1];
                     $str = '$table = $query->getModel()->getTable();' . "\r\n" . '$configs[1] = $table . "." . $configs[1];' . "\r\n" . '$update_query($query, $field, $configs, $value);';
                     foreach ($tables as $table) {
                         $str = '$query->whereHas("' . $table . '", function($query) use ($update_query, $field, $configs, $value) {' . "\r\n" . $str . "\r\n" . '});';
                     }
                     $query = eval('return ' . $str);
                 }
             }
         }
         if (isset($form_input['sorting'])) {
             $column = ReportSorting::findOrFail($form_input['sorting']);
             $dir = 1;
             if (isset($form_input['sorting_dir'])) {
                 $dir = $form_input['sorting_dir'];
             }
             $query = $query->orderBy($column->name, $dir);
         }
         if ($query->count() > 0) {
             if (isset($form_input['grouping'])) {
                 $grouping = ReportGrouping::findOrFail($form_input['grouping']);
                 switch ($grouping->sql_function) {
                     case 0:
                         $response[array_values($wheres->toArray())[0]] = $query->get();
                         break;
                     case 1:
                         $dates = array_reverse($wheres->toArray());
                         $response[implode(' - ', $dates)] = $query->get();
                         break;
                     case 2:
                         $year = array_values($wheres->toArray())[0] . ' ';
                         $response[$year] = $query->get();
                         break;
                 }
             } else {
                 $response[] = $query->get();
             }
         }
     }
     if (Request::ajax()) {
         return $response;
     }
     if ($form_input['operation'] === 'Download') {
         return Excel::create($report->name . '__' . date('Ymd-his'), function ($excel) use($response, $report) {
             foreach ($response as $index => $table) {
                 $sheet_name = 'default';
                 if (is_string($index)) {
                     $sheet_name = $index;
                 }
                 $excel->sheet($sheet_name, function ($sheet) use($table, $report, $response) {
                     $sheet->loadView('reports.table', ['table_columns' => $report->columns, 'table_data' => $table]);
                 });
             }
         })->download();
     }
     return View::make('reports.report', compact('report', 'response', 'form_input'));
 }
 public function postReport($workorderId)
 {
     $report = array_merge(Input::only('data', 'user_id'), ['workorder_id' => $workorderId]);
     if (Input::get('reportId', false)) {
         return Report::where('id', Input::get('reportId'))->update(Input::only('data'));
     }
     return Report::create($report);
 }