Exemplo n.º 1
0
 protected function getView($id)
 {
     $ticket = Ticket::findOrFail($id);
     $notes = $ticket->notes()->orderBy('id', 'desc')->get();
     $allUsers = User::all();
     $assignedUsers = $ticket->users;
     foreach ($assignedUsers as $assignedUser) {
         $newAssignedUsers[$assignedUser->id] = ['name' => $assignedUser->name];
     }
     foreach ($allUsers as $user) {
         if (!empty($newAssignedUsers) && array_key_exists($user->id, $newAssignedUsers)) {
             $newAllUsers[$user->id] = ['name' => $user->name, 'selected' => true];
         } else {
             $newAllUsers[$user->id] = ['name' => $user->name, 'selected' => false];
         }
     }
     foreach ($ticket->progress as $progress) {
         $progressDatesArray[$progress->state_id] = ['date' => $progress->created_at->format('d-m-Y'), 'time' => $progress->created_at->format('H:i')];
     }
     return View('ticket.view', ['ticket' => Ticket::find($id), 'progressDates' => $progressDatesArray, 'allUsers' => $newAllUsers, 'notes' => $notes]);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(CancelledTicketRequest $request, $ticket_id)
 {
     $user_id = Auth::user()->id;
     $input = $request->all();
     if ($input['ticket_id'] != $ticket_id) {
         return redirect('salesman/devolutions');
     }
     $ticket = Ticket::findOrFail($input['ticket_id']);
     if ($ticket->cancelled == 1) {
         Session::flash('message', 'El ticket ya fue cancelado!');
         Session::flash('alert-class', 'alert-danger');
         return redirect('salesman/devolutions');
     }
     if ($ticket->presentation["cancelled"] == 0) {
         Session::flash('message', 'La presentation ' . $ticket->presentation_id . ' no fue cancelado, por lo tanto no se puede realizar devolución');
         Session::flash('alert-class', 'alert-danger');
         return redirect('/salesman/devolutions');
     }
     $module = Module::find(Auth::user()->module_id);
     if ($module->actual_cash < $ticket->total_price) {
         Session::flash('message', 'No tiene fondos en la caja para poder devolver');
         Session::flash('alert-class', 'alert-danger');
         return redirect('/salesman/devolutions');
     }
     $ticket->cancelled = 1;
     $ticket->save();
     $devolution = new Devolution();
     $devolution->ticket_id = $input['ticket_id'];
     $devolution->user_id = $user_id;
     $devolution->repayment = $ticket->total_price;
     if (isset($input['observation'])) {
         $devolution->observation = $input['observation'];
     }
     $devolution->save();
     Session::flash('message', 'Devolución realizado!');
     Session::flash('alert-class', 'alert-success');
     return redirect('/salesman/devolutions');
 }