model = $model; } public function update($data) { return $this->model; } public function updateNotice($id, $data){ $this->model = Booking::findOrFail($id); if($data['action'] === 'edit_notice' && isset($data['notice_id'])){ $BookingNotice = BookingNotice::findOrFail($data['notice_id']); $BookingNotice->message = isset($data['booking_notice']) ? $data['booking_notice'] : ""; $BookingNotice->edit_at = now(); $BookingNotice->save(); }else{ //save_notice BookingNotice::create([ 'booking_id' => $this->model->id, 'from_user_id' => Auth::user()->id, 'to_user_id' => isset($this->model->sf_guard_user->user_id) ? $this->model->sf_guard_user->user_id : null, 'message' => isset($data['booking_notice']) ? $data['booking_notice'] : "", ] ); } return $this->model; } public function updateLeadStatus($id, $data){ $this->model = Booking::findOrFail($id); if(isset($data['lead'])){ $lead = $this->model->lead; if($lead->id != $data['lead']['id']){ abort(500); } $lead->status_id = $data['lead']['status_id']; $lead->is_rebook = isset($data['lead']['is_rebook']) ? true : false; $lead->is_closed = isset($data['lead']['is_closed']) ? true : false; $lead->save(); } return $this->model; } public function updateBooking($id, $data){ $this->model = Booking::findOrFail($id); $fill = [ 'sf_guard_user_id' => $data['sf_guard_user_id'], 'booking_date' => $data['booking_date'] ? _reformat_date($data['booking_date']) : null, 'travel_number' => $data['travel_number'], 'travel_country_id' => $data['travel_country_id'] ? $data['travel_country_id'] : null, 'travelagenda_id' => $data['travelagenda_id'] ? $data['travelagenda_id'] : null, 'travel_category_id' => $data['travel_category_id'] ? $data['travel_category_id'] : null, 'start_date' => $data['start_date'] ? _reformat_date($data['start_date']) : null, 'end_date' => $data['end_date'] ? _reformat_date($data['end_date']) : null, 'title' => $data['title'], 'paying_out' => $data['paying_out'], 'paying_out_status' => $data['paying_out_status'], 'airline_id' => $data['airline_id'], 'refund' => $data['refund'], 'refund_date' => _reformat_date($data['refund_date']), 'lawyer_date' => _reformat_date($data['lawyer_date']), 'hold' => $data['hold'], 'xx_tkt' => $data['xx_tkt'], 'xx_tkt_date' => _reformat_date($data['xx_tkt_date']), 'filekey' => $data['filekey'], 'is_rail_fly' => isset($data['is_rail_fly']) ? true : false, 'notice' => $data['notice'], 'ev_number' => $data['ev_number'], 'merlin_order_number' => $data['merlin_order_number'], ]; $this->model->fill($fill); $this->model->save(); return $this->model; } public function updateBookingServices($id, $data){ $this->model = Booking::findOrFail($id); if(isset($data['country_service'])){ $this->updateCountryService($data['country_service']); } if(isset($data['provider_service'])){ $this->updateProviderService($data['provider_service']); } if(isset($data['company_service'])){ $this->updateCompanyService($data['company_service']); } return $this->model; } public function updateBookingNumber($id, $data){ $this->model = Booking::findOrFail($id); $fill = [ 'ev_number' => $data['ev_number'], 'merlin_order_number' => $data['merlin_order_number'], ]; $this->model->fill($fill); $this->model->save(); return $this->model; } public function updateBookingPrice($id, $data){ $this->model = Booking::findOrFail($id); $fill = [ 'deposit_total' => $data['deposit_total'] ? Util::_clean_float($data['deposit_total']) : 0, 'final_payment' => $data['final_payment'] ? Util::_clean_float($data['final_payment']) : 0, 'final_payment_date' => $data['final_payment_date'] ? _reformat_date($data['final_payment_date']) : null, ]; $this->model->fill($fill); $this->model->save(); return $this->model; } private function updateCountryService($country_services){ foreach ($country_services as $country_service_id=>$val){ $booking_country_service = BookingCountryService::where('travel_country_service_id', '=', $country_service_id) ->where('booking_id', '=', $this->model->id)->first(); if(!$booking_country_service){ BookingCountryService::create([ 'travel_country_service_id' => $country_service_id, 'booking_id' => $this->model->id, 'status' => $val ]); }else{ $booking_country_service->fill([ 'status' => $val ]); $booking_country_service->save(); } } } private function updateProviderService($provider_service){ foreach ($provider_service as $provider_service_id=>$val){ $booking_provider_service = BookingProviderService::where('service_provider_service_id', '=', $provider_service_id) ->where('booking_id', '=', $this->model->id)->first(); if(!$booking_provider_service){ BookingProviderService::create([ 'service_provider_service_id' => $provider_service_id, 'booking_id' => $this->model->id, 'status' => $val ]); }else{ $booking_provider_service->fill([ 'status' => $val ]); $booking_provider_service->save(); } } } private function updateCompanyService($company_service){ foreach ($company_service as $company_service_id=>$val){ $booking_company_service = BookingCompanyService::where('travel_company_service_id', '=', $company_service_id) ->where('booking_id', '=', $this->model->id)->first(); if(!$booking_company_service){ BookingCompanyService::create([ 'travel_company_service_id' => $company_service_id, 'booking_id' => $this->model->id, 'status' => $val ]); }else{ $booking_company_service->fill([ 'status' => $val ]); $booking_company_service->save(); } } } }