middleware('admin'); $this->bookingRepo = $bookingRepo; } public function index($step = false) { $data = [ //'bookings' => Booking::all()->sortByDesc("id"), 'step' => $step ]; return view('booking.index', $data); } public function detail($id) { if($id == "new") { $booking = new Booking(); $id = 'new'; }else{ $booking = Booking::findOrFail($id); $id = $booking->id; } $data = [ 'booking' => $booking, 'id' => $id, ]; return view('booking.detail', $data); } public function store($id) { // \Session()->flash('alert-save', '1'); $data = Request::all(); if($id == "new") { $booking = new Booking(); }else{ $booking = Booking::findOrFail($id); } $booking->merlin_order_number = $data['merlin_order_number']; $booking->save(); $i = 1; if($data['action'] == 'addItemUp'){ $travel_program_id = null; $request_date = null; $comfort = 0; if(count($booking->booking_draft_items)){ $first_booking_draft_item = $booking->booking_draft_items()->first(); $travel_program_id = $first_booking_draft_item->travel_program_id; $request_date = $first_booking_draft_item->request_date; $comfort = $first_booking_draft_item->comfort; } $booking->booking_draft_items()->create([ 'booking_id' => $booking->id, 'travel_program_id' => $travel_program_id, 'fewo_lodging_id' => null, 'travel_class_id' => null, 'draft_item_id' => null, 'draft_type_id' => null, 'request_date' => $request_date, 'days_start' => null, 'days_duration' => null, 'start_date' => null, 'end_date' => null, 'service' => '', 'price_adult' => null, 'adult' => null , 'price_children' => 0, 'children' => 0, 'price' => 0, 'pos' => $i, 'in_pdf' => true, 'comfort' => $comfort ]); $i++; } if(isset($data['draft_item'])){ foreach ($data['draft_item'] as $booking_draft_item_id => $draft_item){ $BookingDraftItem = BookingDraftItem::findOrFail($booking_draft_item_id); $draft_item['price_adult'] = isset($draft_item['price_adult']) ? $draft_item['price_adult'] : null; $draft_item['adult'] = isset($draft_item['adult']) ? $draft_item['adult'] : null; $draft_item['price_children'] = isset($draft_item['price_children']) ? $draft_item['price_children'] : null; $draft_item['children'] = isset($draft_item['children']) ? $draft_item['children'] : null; $draft_item['price'] = isset($draft_item['price']) ? $draft_item['price'] : null; $draft_item['pos'] = $i++; $draft_item['in_pdf'] = isset($draft_item['in_pdf']) ? true : false; $BookingDraftItem->fill($draft_item); $BookingDraftItem->save(); } } if($data['action'] == 'addItemDown'){ $travel_program_id = null; $request_date = null; $comfort = 0; if(count($booking->booking_draft_items)){ $first_booking_draft_item = $booking->booking_draft_items()->first(); $travel_program_id = $first_booking_draft_item->travel_program_id; $request_date = $first_booking_draft_item->request_date; $comfort = $first_booking_draft_item->comfort; } $booking->booking_draft_items()->create([ 'booking_id' => $booking->id, 'travel_program_id' => $travel_program_id, 'fewo_lodging_id' => null, 'travel_class_id' => null, 'draft_item_id' => null, 'draft_type_id' => null, 'request_date' => $request_date, 'days_start' => null, 'days_duration' => null, 'start_date' => null, 'end_date' => null, 'service' => '', 'price_adult' => null, 'adult' => null , 'price_children' => 0, 'children' => 0, 'price' => 0, 'pos' => $i, 'in_pdf' => true, 'comfort' => $comfort ]); } $booking->calculate_price_total(); if(strpos($data['action'], 'up_') !== false) { $reId = intval(str_replace('up_', '', $data['action'])); $d_from = BookingDraftItem::findOrFail($reId); $d_to = $booking->findBeforeDraftItemRelation($reId); if($d_to) { $t_pos = $d_from->pos; $d_from->pos = $d_to->pos; $d_to->pos = $t_pos; $d_from->save(); $d_to->save(); } } if(strpos($data['action'], 'down_') !== false) { $reId = intval(str_replace('down_', '', $data['action'])); $d_from = BookingDraftItem::findOrFail($reId); $d_to = $booking->findAfterDraftItemRelation($reId); if($d_to) { $t_pos = $d_from->pos; $d_from->pos = $d_to->pos; $d_to->pos = $t_pos; $d_from->save(); $d_to->save(); } } \Session()->flash('alert-save', '1'); return redirect(route('booking_detail', [$booking->id])); } public function draftItemDelete($id){ $boking_draft_item = BookingDraftItem::findOrFail($id); $booking = $boking_draft_item->booking; $boking_draft_item->delete(); $booking->calculate_price_total(); \Session()->flash('alert-success', __('Eintrag gelöscht')); return redirect(route('booking_detail', [$booking->id])); } }