Booking edit v3

This commit is contained in:
Kevin Adametz 2021-06-18 15:00:12 +02:00
parent 6706d28f51
commit 6880c7e989
20 changed files with 691 additions and 97 deletions

View file

@ -7,7 +7,10 @@ use Auth;
use App\Models\Lead;
use App\Services\Util;
use App\Models\Booking;
use App\Models\Participant;
use App\Models\BookingNotice;
use App\Models\BookingServiceItem;
use App\Models\ServiceProviderEntry;
use App\Models\BookingCompanyService;
use App\Models\BookingCountryService;
use App\Models\BookingProviderService;
@ -79,8 +82,12 @@ class BookingRepository extends BaseRepository {
'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' => $data['branch_id'],
'travel_company_id' => $data['travel_company_id'],
'airline_id' => $data['airline_id'],
'refund' => $data['refund'],
'refund_date' => _reformat_date($data['refund_date']),
@ -140,9 +147,77 @@ class BookingRepository extends BaseRepository {
$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();
}
}
}
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_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'] : 1;
$this->model->participant_name = isset($data['participant_name']) ? $data['participant_name'] : "";
$this->model->participant_firstname = isset($data['participant_firstname']) ? $data['participant_firstname'] : "";
$this->model->nationality_id = isset($data['nationality_id']) ? $data['nationality_id'] : 1;
$this->model->participant_birthdate = isset($data['participant_birthdate']) ? _reformat_date($data['participant_birthdate']) : 1;
$this->model->save();
return $this->model;
}
private function updateCountryService($country_services){
foreach ($country_services as $country_service_id=>$val){