public function eventsForDate(Request $request) { $input = $request->all(); $date_at = strtotime($input['date_at']); $presentations = Presentation::where("cancelled", "0")->whereBetween("starts_at", [$date_at, $date_at + 86400])->get(); $eventsDate = Event::where("cancelled", "0")->where("selling_date", '<=', $date_at)->get(); $eventInformation = []; foreach ($eventsDate as $eventDate) { $presentationsDate = Presentation::where("cancelled", "0")->whereBetween("starts_at", [$date_at, $date_at + 86400])->where("event_id", $eventDate->id)->get(); $presentationInformation = []; if (count($presentationsDate) != 0) { foreach ($presentationsDate as $pre) { array_push($presentationInformation, array($pre->starts_at)); } array_push($eventInformation, array($eventDate->image, $eventDate->id, $eventDate->name, $eventDate->place->name, $eventDate->place->address, $eventDate->category->name, $presentationInformation)); } } $events = Event::where(["publication_date" => $date_at, "cancelled" => "0"])->get(); return view('external.calendar', ["events" => $events, "date_at" => $date_at, "presentations" => $presentations], compact('eventInformation')); }
public function cancelStorage(StorePresentationRequest $request, $presentation_id) { $user_id = Auth::user()->id; $input = $request->all(); $presentation = Presentation::findOrFail($presentation_id); $presentation->cancelled = "1"; $presentation->save(); $event = Event::find($presentation->event_id); if ($event->presentations->isEmpty()) { $event->cancelled = true; $event->save(); } $cancel = new CancelPresentation(); $cancel->presentation_id = $presentation_id; $cancel->user_id = $user_id; $cancel->reason = $input['reason']; $cancel->duration = $input['duration']; $cancel->authorized = $input['authorized']; $cancel->date_refund = $input['date_refund']; $cancel->save(); Session::flash('message', 'La presentación se ha cancelado!'); Session::flash('alert-class', 'alert-success'); return redirect('/promoter/presentation/cancelled'); }
public function unpublished() { $presentations = Presentation::latest()->unpublished()->get(); return view('presentations.index', ['presentations' => $presentations]); }
public function store(StoreBookingRequest $request) { $event = Event::find($request['event_id']); $zone = Zone::find($request['zone_id']); $nTickets = $request['quantity']; $codigo_reserva = uniqid(); $seats_array = array(); if ($event->place->rows != null) { //Es numerado $seats = $request['seats']; $seats = $this->getSelectedSlots($seats, $zone->id); foreach ($seats as $seat_id) { $slot = DB::table('slot_presentation')->where('slot_id', $seat_id)->where('presentation_id', $request['presentation_id'])->first(); array_push($seats_array, Slot::where('id', $seat_id)->get()->first()); if ($slot->status != config('constants.seat_available')) { return back()->withInput($request->except('seats'))->withErrors(['El asiento ' . $seat_id . ' no esta libre']); } } } else { //No es numerado $zoneXpres = DB::table('zone_presentation')->where('zone_id', $request['zone_id'])->where('presentation_id', $request['presentation_id'])->first(); if ($zoneXpres->slots_availables - $nTickets < 0) { //Deberia ser zona x presentacion return back()->withInput($request->except('seats'))->withErrors(['La zona esta llena']); } } DB::beginTransaction(); try { $tickets = array(); for ($i = 0; $i < $nTickets; $i++) { if ($event->place->rows != null) { //Cambiar estado de asiento $seat = DB::table('slot_presentation')->where('slot_id', $seats[$i])->where('presentation_id', $request['presentation_id'])->sharedLock(); //Revisa de nuevo $seat = DB::table('slot_presentation')->where('slot_id', $seats[$i])->where('presentation_id', $request['presentation_id'])->first(); if ($seat->status != config('constants.seat_available')) { return back()->withInput($request->except('seats'))->withErrors(['El asiento ' . $seat_id . ' no esta libre']); } DB::table('slot_presentation')->where('slot_id', $seats[$i])->where('presentation_id', $request['presentation_id'])->update(['status' => config('constants.seat_reserved')]); } else { //Disminuir capacidad en la zona de esa presentacion DB::table('zone_presentation')->where('zone_id', $request['zone_id'])->where('presentation_id', $request['presentation_id'])->sharedLock(); $zoneXpres = DB::table('zone_presentation')->where('zone_id', $request['zone_id'])->where('presentation_id', $request['presentation_id'])->first(); if ($zoneXpres->slots_availables - $nTickets < 0) { return back()->withInput($request->except('seats'))->withErrors(['La zona esta llena']); } DB::table('zone_presentation')->where('zone_id', $request['zone_id'])->where('presentation_id', $request['presentation_id'])->decrement('slots_availables'); } } //Crear ticket $id = DB::table('tickets')->insertGetId(['payment_date' => null, 'reserve' => $codigo_reserva, 'cancelled' => 0, 'owner_id' => \Auth::user()->id, 'event_id' => $request['event_id'], 'price' => $zone->price, 'presentation_id' => $request['presentation_id'], 'zone_id' => $request['zone_id'], 'promo_id' => null, 'quantity' => $nTickets, 'salesman_id' => null, 'picked_up' => false, 'discount' => null, 'designee' => \Auth::user()->di, 'total_price' => $zone->price * $nTickets, 'created_at' => new Carbon(), 'updated_at' => new Carbon()]); if ($request['dni_recojo'] != null) { DB::table('tickets')->where('id', $id)->update(['designee' => $request['dni_recojo']]); } if ($event->place->rows != null) { //Asignar id en caso sea numerado for ($i = 0; $i < $nTickets; $i++) { DB::table('slot_presentation')->where('slot_id', $seats[$i])->where('presentation_id', $request['presentation_id'])->update(['sale_id' => $id]); } } array_push($tickets, $id); DB::commit(); } catch (\Exception $e) { //dd('rollback'); DB::rollback(); return back()->withInput($request->except('seats'))->withErrors(['Por favor intentelo nuevamente']); } $presentation = Presentation::find($request->input('presentation_id')); session(['tickets' => $tickets]); $array = ['event' => $event, 'zone' => $zone, 'cant' => $nTickets, 'eventDate' => date("d-m-Y h:i:s a", $presentation->starts_at), 'codigo' => $codigo_reserva, 'seats' => '']; if ($event->place->rows != null) { $array['seats'] = $seats_array; } return view('external.booking.results', $array); //return $array['seats'][0]->row ; }
/** * Show the form for creating a new resource. * * @param int $id * @return \Illuminate\Http\Response */ public function createSalesman($id) { $userId = Auth::user()->id; $moduleUser = ModuleAssigment::where(["salesman_id" => $userId, "status" => 1])->first(); if (!is_object($moduleUser)) { return back()->withErrors(['Usted no tiene modulo asignado, por lo tanto no puede vender']); } else { if (Auth::user()->role_id == config('constants.salesman') && Auth::user()->module && Auth::user()->module->openModule == 0) { return back()->withErrors(['Usted no ha abierto su caja, por lo tanto no puede vender']); } } //Buscar y enviar info de evento con $id $event = Event::find($id); $presentations = Presentation::where('event_id', $id)->where('cancelled', 0)->where('starts_at', '>', strtotime(Carbon::now()))->get(); $slots_array = array(); foreach ($presentations as $pres) { $slots = DB::table('slot_presentation')->where('presentation_id', $pres->id)->where('status', config('constants.seat_available'))->lists('slot_id', 'slot_id'); $slots_array[$pres->id] = $slots; } $presentations = $presentations->lists('starts_at', 'id'); foreach ($presentations as $key => $pres) { $presentations[$key] = date("Y-m-d H:i", $pres); } $presentations = $presentations->toArray(); $zones = Zone::where('event_id', $id)->lists('name', 'id'); $exchangeRate = ExchangeRate::where('status', config('constants.active'))->first(); return view('internal.salesman.buy', compact('event', 'presentations', 'zones', 'slots_array', 'exchangeRate')); }
/** * Display the specified resource. * * @return \Illuminate\Http\Response */ public function showSales() { $events = Event::all(); $tickets = Ticket::all(); $eventInformation = []; foreach ($events as $event) { // pueden ser muchos eventos. Necesito información para llenar la tabla $eventsDate = Presentation::where('event_id', '=', $event->id)->where('cancelled', '=', 0)->get(); foreach ($eventsDate as $eventDate) { $tickets = Ticket::where('presentation_id', '=', $eventDate->id)->get(); $onlineTickets = 0; $presentialTicket = 0; $subTotalOnline = 0; $subTotalPresential = 0; foreach ($tickets as $ticket) { if ($ticket->cancelled != 1) { if (empty($ticket->salesman_id)) { $onlineTickets = $onlineTickets + $ticket->quantity; $subTotalPresential = $subTotalPresential + $ticket->total_price; } else { $presentialTicket = $presentialTicket + $ticket->quantity; $subTotalOnline = $subTotalOnline + $ticket->total_price; } } } array_push($eventInformation, array($event->name, $eventDate->id, date("d/m/Y", $eventDate->starts_at), $onlineTickets, $subTotalPresential, $presentialTicket, $subTotalOnline, $subTotalPresential + $subTotalOnline)); } } // //return $eventInformation; return view('internal.admin.reports.sales', compact('eventInformation')); }