diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php new file mode 100644 index 0000000..55f780f --- /dev/null +++ b/app/Http/Controllers/AjaxController.php @@ -0,0 +1,32 @@ +middleware('auth'); + } + + public function load(){ + $data = Request::all(); + $ret = ""; + $status = false; + if(Request::ajax()){ + + if($data['action'] === 'load_travelagenda_by_country' && isset($data['travel_country_id'])){ + $ret = Model::getTravelAgendaArray(true, $data['travel_country_id']); + $status = true; + } + } + return response()->json(['response' => $data, 'html'=>$ret, 'status'=>$status]); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/BookingController.php b/app/Http/Controllers/BookingController.php index 7a03a21..f425340 100755 --- a/app/Http/Controllers/BookingController.php +++ b/app/Http/Controllers/BookingController.php @@ -7,7 +7,12 @@ use App\Models\Booking; use App\Models\Customer; use App\Models\BookingFile; use App\Models\BookingNotice; +use App\Models\ServiceProvider; use App\Models\BookingDraftItem; +use App\Models\BookingServiceItem; +use App\Models\Participant; +use App\Models\ServiceProviderEntry; +use App\Models\TravelCompany; use App\Repositories\DraftRepository; use App\Repositories\BookingRepository; use App\Repositories\BookingFileRepository; @@ -100,6 +105,27 @@ class BookingController extends Controller return redirect(route('booking_detail', [$booking->id])."#collapseBookingPrice"); } + if($data['action'] === 'update_service_provider_entry'){ + $booking = $this->bookingRepo->updateServiceProviderEntry($id, $data); + \Session()->flash('alert-save', '1'); + return redirect(route('booking_detail', [$booking->id])."#collapseBookingProvider"); + } + + if($data['action'] === 'update_booking_service_item'){ + $booking = $this->bookingRepo->updateBookingServiceItem($id, $data); + \Session()->flash('alert-save', '1'); + return redirect(route('booking_detail', [$booking->id])."#collapseBookingProvider"); + } + + + if($data['action'] === 'update_booking_participant'){ + $booking = $this->bookingRepo->updateBookingParticipant($id, $data); + \Session()->flash('alert-save', '1'); + return redirect(route('booking_detail', [$booking->id])."#collapseBookingParticipant"); + } + + + @@ -230,7 +256,6 @@ class BookingController extends Controller return redirect(route('booking_detail', [$booking->id])); } - public function loadModal(){ $data = Request::all(); $ret = ""; @@ -283,16 +308,63 @@ class BookingController extends Controller public function action($action, $id=false){ + if(!$booking = Booking::find($id)){ + abort(404); + } + if($action === 'change_travel_dates'){ - if($booking = Booking::find($id)){ $draftRepo = new DraftRepository($booking); $draftRepo->change_dates_drafts_from_booking(Request::get('change_travel_start_date')); \Session()->flash('alert-success', __('Datum der Reise wurde geändert')); - return redirect(route('booking_detail', [$booking->id])); - } + return redirect(route('booking_detail', [$booking->id])."#collapseBookingOrganisation"); } - } + if($action === 'service_provider_entry_add_discount'){ + $ServiceProvider = ServiceProvider::where('type', 'discount')->where('active',true)->first(); + ServiceProviderEntry::create([ + 'booking_id' => $booking->id, + 'service_provider_id' => $ServiceProvider->id, + 'type' => 'discount', + ]); + \Session()->flash('alert-success', __('Leistungsträger neuer Rabatt hinzugefügt')); + return redirect(route('booking_detail', [$booking->id])."#collapseBookingProvider"); + } + + if($action === 'service_provider_entry_add_payment'){ + $ServiceProvider = ServiceProvider::where('type', 'payment')->where('active',true)->first(); + ServiceProviderEntry::create([ + 'booking_id' => $booking->id, + 'service_provider_id' => $ServiceProvider->id, + 'type' => 'payment', + ]); + \Session()->flash('alert-success', __('Leistungsträger neue Zahlung hinzugefügt')); + return redirect(route('booking_detail', [$booking->id])."#collapseBookingProvider"); + } + + if($action === 'booking_service_item_add'){ + $TravelCompany = TravelCompany::where('active',true)->first(); + BookingServiceItem::create([ + 'booking_id' => $booking->id, + 'travel_company_id' => $TravelCompany->id, + 'travel_date' => now(), + ]); + \Session()->flash('alert-success', __('Reiseveranstalter neue Leistung hinzugefügt')); + return redirect(route('booking_detail', [$booking->id])."#collapseBookingCompany"); + } + + if($action === 'booking_participant_add'){ + Participant::create([ + 'booking_id' => $booking->id, + 'nationality_id' => 1, + 'participant_salutation_id' => 1, + + ]); + \Session()->flash('alert-success', __('Neuen Teilnehmer hinzugefügt')); + return redirect(route('booking_detail', [$booking->id])."#collapseBookingParticipant"); + } + + + } public function delete($id, $del="booking"){ @@ -309,22 +381,50 @@ class BookingController extends Controller $fileRepo->delete(); $booking_file->delete(); \Session()->flash('alert-success', 'Datei gelöscht'); - return redirect(route('booking_detail', [$booking->id])); + return redirect(route('booking_detail', [$booking->id])."#collapseBookingFiles"); } if($del === 'booking_notice'){ $booking_notice = BookingNotice::findOrFail($id); $booking = $booking_notice->booking; $booking_notice->delete(); \Session()->flash('alert-success', 'Notiz gelöscht'); - return redirect(route('booking_detail', [$booking->id])); + return redirect(route('booking_detail', [$booking->id])."#collapseBookingNotice"); + } if($del === 'passolution_file'){ $booking = Booking::findOrFail($id); $booking->resyncPassolutionPDF(); \Session()->flash('alert-success', 'Passolution erneuert'); - return redirect(route('booking_detail', [$booking->id])); + return redirect(route('booking_detail', [$booking->id])."#collapseBookingFiles"); + } + + if($del === 'service_provider_entry'){ + $ServiceProviderEntry = ServiceProviderEntry::findOrFail($id); + $booking = $ServiceProviderEntry->booking; + $ServiceProviderEntry->delete(); + \Session()->flash('alert-success', 'Leistungsträger gelöscht'); + return redirect(route('booking_detail', [$booking->id])."#collapseBookingProvider"); + + } + + if($del === 'booking_service_item'){ + $BookingServiceItem = BookingServiceItem::findOrFail($id); + $booking = $BookingServiceItem->booking; + $BookingServiceItem->delete(); + \Session()->flash('alert-success', 'Reiseveranstalter gelöscht'); + return redirect(route('booking_detail', [$booking->id])."#collapseBookingCompany"); + } + + if($del === 'participant'){ + $Participant = Participant::findOrFail($id); + $booking = $Participant->booking; + $Participant->delete(); + \Session()->flash('alert-success', 'Teilnehmer gelöscht'); + return redirect(route('booking_detail', [$booking->id])."#collapseBookingParticipant"); + } + return redirect(route('requests')); } diff --git a/app/Models/Booking.php b/app/Models/Booking.php index 2b6227f..dbb1068 100644 --- a/app/Models/Booking.php +++ b/app/Models/Booking.php @@ -590,8 +590,7 @@ class Booking extends Model if(empty($nats)){ $nats['de'] = 'de'; - } - + } foreach ($nats as $nat){ $data = [ 'nat' => $nat, @@ -778,7 +777,7 @@ class Booking extends Model { $total = 0; foreach ($this->service_provider_entries as $entry){ - $total += $entry->getAmountRaw() / $entry->factor; + $total += $entry->getAmountRaw() / $entry->getFactortRaw(); } return $raw ? $total : Util::_number_format($total); } diff --git a/app/Models/BookingServiceItem.php b/app/Models/BookingServiceItem.php index c6aab4d..5972329 100644 --- a/app/Models/BookingServiceItem.php +++ b/app/Models/BookingServiceItem.php @@ -83,7 +83,10 @@ class BookingServiceItem extends Model return $this->belongsTo(TravelCompany::class); } - + public function setServicePriceAttribute($value) + { + $this->attributes['service_price'] = Util::_clean_float($value); + } public function getServicePriceAttribute() { return Util::_number_format($this->attributes['service_price']); @@ -92,4 +95,35 @@ class BookingServiceItem extends Model { return $this->attributes['service_price']; } + + public function setCommissionAttribute($value) + { + $this->attributes['commission'] = Util::_clean_float($value); + } + public function getCommissionAttribute() + { + return Util::_number_format($this->attributes['commission']); + } + public function getCommissionRaw() + { + return $this->attributes['commission']; + } + + public function setServicePriceRefundAttribute($value) + { + $this->attributes['service_price_refund'] = Util::_clean_float($value); + } + public function getServicePriceRefundAttribute() + { + return Util::_number_format($this->attributes['service_price_refund']); + } + public function getServicePriceRefundRaw() + { + return $this->attributes['service_price_refund']; + } + + public function setServicePriceRefundRaw($value) + { + return $this->attributes['service_price_refund'] = $value; + } } diff --git a/app/Models/Branch.php b/app/Models/Branch.php new file mode 100644 index 0000000..d1f0406 --- /dev/null +++ b/app/Models/Branch.php @@ -0,0 +1,41 @@ +hasMany(Booking::class); + } + + public function sf_guard_users() + { + return $this->hasMany(SfGuardUser::class); + } +} diff --git a/app/Models/ServiceProviderEntry.php b/app/Models/ServiceProviderEntry.php index 56550a0..07ee5a2 100644 --- a/app/Models/ServiceProviderEntry.php +++ b/app/Models/ServiceProviderEntry.php @@ -97,6 +97,23 @@ class ServiceProviderEntry extends Model } } + public function setFactorAttribute($value) + { + $this->attributes['factor'] = floatval(preg_replace("/[^0-9.-]/", "", str_replace(',', '.', $value))); + } + public function getFactorAttribute() + { + return Util::_number_format($this->attributes['factor'], 4); + } + public function getFactortRaw() + { + return $this->attributes['factor']; + } + + public function setAmountAttribute($value) + { + $this->attributes['amount'] = Util::_clean_float($value); + } public function getAmountAttribute() { return Util::_number_format($this->attributes['amount']); @@ -105,7 +122,10 @@ class ServiceProviderEntry extends Model { return $this->attributes['amount']; } - + public function setAmountEurAttribute($value) + { + $this->attributes['amount_eur'] = Util::_clean_float($value); + } public function getAmountEurAttribute() { return Util::_number_format($this->attributes['amount_eur']); @@ -135,4 +155,5 @@ class ServiceProviderEntry extends Model if(!$this->attributes['payment_date']){ return ""; } return Carbon::parse($this->attributes['payment_date'])->format(\Util::formatDateDB()); } + } diff --git a/app/Repositories/BookingRepository.php b/app/Repositories/BookingRepository.php index 4b33f3b..853d80b 100644 --- a/app/Repositories/BookingRepository.php +++ b/app/Repositories/BookingRepository.php @@ -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){ diff --git a/app/Services/Model.php b/app/Services/Model.php index 78a7efe..cc973a1 100644 --- a/app/Services/Model.php +++ b/app/Services/Model.php @@ -1,12 +1,17 @@ get()->pluck('name', 'id'); + public static function getTravelAgendaArray($emtpy = false, $travelcountry_id = false){ + if($travelcountry_id){ + $TravelAgenda = TravelAgenda::where('travelcountry_id', $travelcountry_id)->where('active', true)->orderBy('name')->get()->pluck('name', 'id'); + }else{ + $TravelAgenda = TravelAgenda::orderBy('name')->get()->pluck('name', 'id'); + } return $emtpy ? $TravelAgenda->prepend('-', 0) : $TravelAgenda; } public static function getSymTravelCountryArray($emtpy = false){ - $TravelAgenda = SymTravelCountry::orderBy('name')->get()->pluck('name', 'id'); - return $emtpy ? $TravelAgenda->prepend('-', 0) : $TravelAgenda; + $SymTravelCountry = SymTravelCountry::orderBy('name')->get()->pluck('name', 'id'); + return $emtpy ? $SymTravelCountry->prepend('-', 0) : $SymTravelCountry; } public static function getStatusArray($emtpy = false){ @@ -42,5 +51,33 @@ class Model return $emtpy ? $Status->prepend('-', 0) : $Status; } + public static function getTravelCompanyArray($emtpy = false){ + $TravelCompany = TravelCompany::where('active', true)->orderBy('name')->get()->pluck('name', 'id'); + return $emtpy ? $TravelCompany->prepend('-', 0) : $TravelCompany; + } + + public static function getBranchArray($emtpy = false){ + $Branch = Branch::orderBy('name')->get()->pluck('name', 'id'); + return $emtpy ? $Branch->prepend('-', 0) : $Branch; + } + + public static function getServiceProviderArray($emtpy = false, $type='payment'){ + $ServiceProvider = ServiceProvider::where('type', $type)->orderBy('name')->get()->pluck('name', 'id'); + return $emtpy ? $ServiceProvider->prepend('-', 0) : $ServiceProvider; + } + + public static function getSalutationArray($emtpy = false){ + $Salutation = Salutation::orderBy('name')->get()->pluck('name', 'id'); + return $emtpy ? $Salutation->prepend('-', 0) : $Salutation; + } + + public static function getTravelNationalityArray($emtpy = false){ + $TravelNationality = TravelNationality::where('active', true)->orderBy('name')->get()->pluck('name', 'id'); + return $emtpy ? $TravelNationality->prepend('-', 0) : $TravelNationality; + } + + + + } \ No newline at end of file diff --git a/app/Services/Passolution.php b/app/Services/Passolution.php index fccb632..008d5b6 100644 --- a/app/Services/Passolution.php +++ b/app/Services/Passolution.php @@ -95,7 +95,6 @@ class Passolution $client = new Client(); $res = $client->get($url, [ ]); - if($res->getStatusCode() == 200){ $body = $res->getBody(); $body = json_decode($body); diff --git a/app/Services/Util.php b/app/Services/Util.php index 4ba4fb9..4e2245d 100644 --- a/app/Services/Util.php +++ b/app/Services/Util.php @@ -45,8 +45,8 @@ class Util } - public static function _number_format($value){ - return number_format(($value), 2, ',', '.'); + public static function _number_format($value, $dec=2){ + return number_format(($value), $dec, ',', '.'); } diff --git a/database/migrations/2021_06_09_114811_create_branch_table.php b/database/migrations/2021_06_09_114811_create_branch_table.php new file mode 100644 index 0000000..7b30d8e --- /dev/null +++ b/database/migrations/2021_06_09_114811_create_branch_table.php @@ -0,0 +1,32 @@ +bigIncrements('id'); + $table->string('name', 255); + $table->primary('id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('branch'); + } +} diff --git a/public/js/custom.js b/public/js/custom.js index d19e512..2668aee 100644 --- a/public/js/custom.js +++ b/public/js/custom.js @@ -7,6 +7,20 @@ $('.iq-save-bar').closest('form').find(':input, select, textarea').keydown(funct showIqSaveBar($(this).closest('form')); }); +function _floatNumber(n) { + 'use strict'; + n = n.replace(/\./g, '').replace(',', '.'); + return parseFloat(n); +} + +function _formatNumber(n) { + n = parseFloat(n).toFixed(2); + if(isNaN(n)){ + return 0; + } + return n.replace(".", ","); +} + CookiesAddJSONValue = function(name, value) { var elements = []; if(Cookies.get(name)){ @@ -193,7 +207,9 @@ $(function () { }); function ajax_object_action(event, object, callback) { - event.preventDefault(); + if(event){ + event.preventDefault(); + } var data = {}; $.each(object.data(), function(index, value){ if(typeof value !== 'object'){ diff --git a/resources/views/booking/_detail_booking.blade.php b/resources/views/booking/_detail_booking.blade.php index 4b17a48..25bb44f 100755 --- a/resources/views/booking/_detail_booking.blade.php +++ b/resources/views/booking/_detail_booking.blade.php @@ -30,7 +30,7 @@
Kunde: {{ $customer_mail->customer->getSalutation() }} {{ $customer_mail->customer->title }} {{ $customer_mail->customer->firstname }} {{ $customer_mail->customer->name }} - @if($customer_mail->booking) - ({{$customer_mail->booking->id}}) + @if($customer_mail->customer) + ({{$customer_mail->customer->id}}) @endif
@endif @if($customer_mail->booking)Buchung: - @if($value->booking->fewo_lodging_id) {{ $value->booking->fewo_lodging->name." | " }} @endif - ({{ $value->booking->id }}) + @if($customer_mail->booking->fewo_lodging_id) {{ $customer_mail->booking->fewo_lodging->name." | " }} @endif + ({{ $customer_mail->booking->id }})
@endif @@ -58,6 +58,7 @@ Mail gesendetDatum: {{$customer_mail->sent_at}}
@endif + @if($customer_mail->fail) Mail Fehler{{$customer_mail->error }}
diff --git a/routes/web.php b/routes/web.php index bf1f965..d73d532 100755 --- a/routes/web.php +++ b/routes/web.php @@ -93,6 +93,9 @@ Route::group(['middleware' => ['admin']], function() Route::post('/modal/load', 'ModalController@load')->name('modal_load'); Route::post('/iq/content/modal/load', 'IQ\ContentModalController@load')->name('iq_content_modal_load'); + + Route::post('customer_mail/ajax', 'CustomerMailController@ajax')->name('customer_mail_ajax'); + //trees Route::get('/iq/content/tree/index', 'IQ\ContentTreeController@index')->name('iq_content_tree_index'); Route::get('/iq/content/tree/detail/{id}/{node_id?}/{area_section_id?}', 'IQ\ContentTreeController@detail')->name('iq_content_tree_detail'); @@ -109,7 +112,7 @@ Route::group(['middleware' => ['admin']], function() Route::get('/customer_mail/data/table', 'CustomerMailController@getRequests')->name('customer_mail_data_table'); Route::get('/email_template/data/table', 'CustomerMailController@getEmailTemplates')->name('email_template_data_table'); Route::get('/customer_mail/delete/{id}', 'CustomerMailController@delete')->name('customer_mail_delete'); - Route::post('customer_mail/ajax', 'CustomerMailController@ajax')->name('customer_mail_ajax'); + Route::post('/ajax/load/data', 'AjaxController@load')->name('ajax_load_data'); Route::get('/customer_mail/delete/{id}', 'CustomerMailController@delete')->name('customer_mail_delete'); Route::get('/customer_mail/detail/{id}', 'CustomerMailController@detail')->name('customer_mail_detail'); @@ -191,6 +194,7 @@ Route::group(['middleware' => ['admin']], function() Route::post('/booking/detail/{id}', 'BookingController@store')->name('booking_detail'); Route::get('/booking/draft_item/delete/{id}', 'BookingController@draftItemDelete')->name('booking_draft_item_delete'); Route::post('/booking/modal/load', 'BookingController@loadModal')->name('booking_modal_load'); + Route::get('/booking/action/{action}/{id?}', 'BookingController@action')->name('booking_action'); Route::post('/booking/action/{action}/{id?}', 'BookingController@action')->name('booking_action'); Route::get('/booking/delete/{id}/{del?}', 'BookingController@delete')->name('booking_delete');