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, 'comfort' => isset($data['travel_comfort']) ? true : false, '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'], 'pax' => $data['pax'], 'travel_documents' => $data['travel_documents'], 'paying_out' => $data['paying_out'], 'paying_out_status' => $data['paying_out_status'], 'branch_id' => isset($data['branch_id']) ? $data['branch_id'] : 4, 'airport_id' => (isset($data['airport_id']) && $data['airport_id']>0) ? $data['airport_id'] : null, 'travel_company_id' => $data['travel_company_id'], //'airline_id' => $data['airline_id'], 'airline_ids' => isset($data['airline_ids']) ? $data['airline_ids'] : null, '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(); if($this->model->booking_draft_items){ foreach($this->model->booking_draft_items as $booking_draft_item){ $booking_draft_item->comfort = isset($data['travel_comfort']) ? true : false; $booking_draft_item->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, 'price_total' => ($this->model->getPriceRaw() + $this->model->getServiceTotal(true)), ]; $this->model->fill($fill); $this->model->save(); return $this->model; } public function updateServiceProviderEntry($id, $data){ $this->model = Booking::findOrFail($id); if(isset($data['service_provider_entry'])){ foreach($data['service_provider_entry'] as $spe_id => $fill){ $ServiceProviderEntry = ServiceProviderEntry::findOrFail($spe_id); if($ServiceProviderEntry->booking_id !== $this->model->id){ abort(500); } $fill['is_cleared'] = isset($fill['is_cleared']) ? true : false; $fill['payment_date'] = isset($fill['payment_date']) ? _reformat_date($fill['payment_date']) : null; $ServiceProviderEntry->fill($fill); $ServiceProviderEntry->save(); } } return $this->model; } public function updateBookingServiceItem($id, $data){ $this->model = Booking::findOrFail($id); if(isset($data['booking_service_item'])){ foreach($data['booking_service_item'] as $bsi_id => $fill){ $BookingServiceItem = BookingServiceItem::findOrFail($bsi_id); if($BookingServiceItem->booking_id !== $this->model->id){ abort(500); } $fill['is_commission_locked'] = isset($fill['is_commission_locked']) ? true : false; $fill['travel_date'] = isset($fill['travel_date']) ? _reformat_date($fill['travel_date']) : now(); $BookingServiceItem->fill($fill); $BookingServiceItem->save(); if($fill['is_commission_locked'] === true){ $service_price_refund = 0; if($BookingServiceItem->getServicePriceRaw() > 0){ $service_price_refund = $BookingServiceItem->getServicePriceRaw() / 100 * $BookingServiceItem->travel_company->getPercentageRaw(); } $BookingServiceItem->setServicePriceRefundRaw($service_price_refund); $BookingServiceItem->save(); } } } $this->model->price_total = ($this->model->getPriceRaw() + $this->model->getServiceTotal(true)); $this->model->save(); return $this->model; } public function updateBookingParticipant($id, $data){ $this->model = Booking::findOrFail($id); if(isset($data['participant'])){ foreach($data['participant'] as $p_id => $fill){ $Participant = Participant::findOrFail($p_id); if($Participant->booking_id !== $this->model->id){ abort(500); } $fill['participant_pass'] = isset($fill['participant_pass']) ? true : false; $fill['participant_storno'] = isset($fill['participant_storno']) ? true : false; $fill['participant_child'] = isset($fill['participant_child']) ? true : false; $fill['participant_birthdate'] = isset($fill['participant_birthdate']) ? _reformat_date($fill['participant_birthdate']) : null; $Participant->fill($fill); $Participant->save(); } } //main $this->model->participant_salutation_id = isset($data['participant_salutation_id']) ? $data['participant_salutation_id'] : null; $this->model->participant_name = isset($data['participant_name']) ? $data['participant_name'] : null; $this->model->participant_firstname = isset($data['participant_firstname']) ? $data['participant_firstname'] : null; $this->model->nationality_id = isset($data['nationality_id']) ? $data['nationality_id'] : null; $this->model->participant_birthdate = isset($data['participant_birthdate']) ? _reformat_date($data['participant_birthdate']) : null; $this->model->participant_pass = isset($data['participant_pass']) ? true : false; //update pax if($this->model->participants->count() > 0){ $this->model->pax = $this->model->participants->where('participant_storno', false)->count(); } $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(); } } } }