File Controller, Booking Organisation, import Draft, old arrangements
This commit is contained in:
parent
4eb83def39
commit
8fd1f4d451
289 changed files with 36649 additions and 10877 deletions
|
|
@ -3,19 +3,21 @@
|
|||
namespace App\Repositories;
|
||||
|
||||
|
||||
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\BookingDraftItem;
|
||||
use App\Models\BookingNotice;
|
||||
use App\Models\BookingProviderService;
|
||||
use App\Models\BookingServiceItem;
|
||||
use App\Models\Lead;
|
||||
use App\Models\Participant;
|
||||
use App\Models\ServiceProviderEntry;
|
||||
use App\Services\Util;
|
||||
use Auth;
|
||||
|
||||
class BookingRepository extends BaseRepository {
|
||||
class BookingRepository extends BaseRepository
|
||||
{
|
||||
|
||||
|
||||
public function __construct(Booking $model)
|
||||
|
|
@ -29,35 +31,38 @@ class BookingRepository extends BaseRepository {
|
|||
}
|
||||
|
||||
|
||||
public function updateNotice($id, $data){
|
||||
public function updateNotice($id, $data)
|
||||
{
|
||||
|
||||
$this->model = Booking::findOrFail($id);
|
||||
if($data['action'] === 'edit_notice' && isset($data['notice_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{
|
||||
} 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'] : "",
|
||||
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){
|
||||
public function updateLeadStatus($id, $data)
|
||||
{
|
||||
|
||||
$this->model = Booking::findOrFail($id);
|
||||
|
||||
if(isset($data['lead'])){
|
||||
if (isset($data['lead'])) {
|
||||
$lead = $this->model->lead;
|
||||
if($lead->id != $data['lead']['id']){
|
||||
if ($lead->id != $data['lead']['id']) {
|
||||
abort(500);
|
||||
}
|
||||
$lead->status_id = $data['lead']['status_id'];
|
||||
|
|
@ -68,7 +73,8 @@ class BookingRepository extends BaseRepository {
|
|||
return $this->model;
|
||||
}
|
||||
|
||||
public function updateBooking($id, $data){
|
||||
public function updateBooking($id, $data)
|
||||
{
|
||||
|
||||
$this->model = Booking::findOrFail($id);
|
||||
|
||||
|
|
@ -88,7 +94,7 @@ class BookingRepository extends BaseRepository {
|
|||
'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,
|
||||
'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,
|
||||
|
|
@ -107,8 +113,8 @@ class BookingRepository extends BaseRepository {
|
|||
$this->model->fill($fill);
|
||||
$this->model->save();
|
||||
|
||||
if($this->model->booking_draft_items){
|
||||
foreach($this->model->booking_draft_items as $booking_draft_item){
|
||||
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();
|
||||
}
|
||||
|
|
@ -116,24 +122,26 @@ class BookingRepository extends BaseRepository {
|
|||
return $this->model;
|
||||
}
|
||||
|
||||
public function updateBookingServices($id, $data){
|
||||
public function updateBookingServices($id, $data)
|
||||
{
|
||||
|
||||
$this->model = Booking::findOrFail($id);
|
||||
if(isset($data['country_service'])){
|
||||
if (isset($data['country_service'])) {
|
||||
$this->updateCountryService($data['country_service']);
|
||||
}
|
||||
|
||||
if(isset($data['provider_service'])){
|
||||
if (isset($data['provider_service'])) {
|
||||
$this->updateProviderService($data['provider_service']);
|
||||
}
|
||||
|
||||
if(isset($data['company_service'])){
|
||||
if (isset($data['company_service'])) {
|
||||
$this->updateCompanyService($data['company_service']);
|
||||
}
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
public function updateBookingNumber($id, $data){
|
||||
public function updateBookingNumber($id, $data)
|
||||
{
|
||||
|
||||
$this->model = Booking::findOrFail($id);
|
||||
$fill = [
|
||||
|
|
@ -145,7 +153,8 @@ class BookingRepository extends BaseRepository {
|
|||
return $this->model;
|
||||
}
|
||||
|
||||
public function updateBookingPrice($id, $data){
|
||||
public function updateBookingPrice($id, $data)
|
||||
{
|
||||
|
||||
$this->model = Booking::findOrFail($id);
|
||||
$fill = [
|
||||
|
|
@ -158,46 +167,48 @@ class BookingRepository extends BaseRepository {
|
|||
$this->model->save();
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
public function updateServiceProviderEntry($id, $data){
|
||||
|
||||
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){
|
||||
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();
|
||||
}
|
||||
}
|
||||
$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){
|
||||
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){
|
||||
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();
|
||||
}
|
||||
$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){
|
||||
if ($fill['is_commission_locked'] === true) {
|
||||
$service_price_refund = 0;
|
||||
if($BookingServiceItem->getServicePriceRaw() > 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();
|
||||
|
|
@ -205,21 +216,22 @@ class BookingRepository extends BaseRepository {
|
|||
return $this->model;
|
||||
}
|
||||
|
||||
public function updateBookingParticipant($id, $data){
|
||||
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){
|
||||
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();
|
||||
}
|
||||
}
|
||||
$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;
|
||||
|
|
@ -229,29 +241,30 @@ class BookingRepository extends BaseRepository {
|
|||
$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){
|
||||
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){
|
||||
|
||||
|
||||
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){
|
||||
if (!$booking_country_service) {
|
||||
BookingCountryService::create([
|
||||
'travel_country_service_id' => $country_service_id,
|
||||
'booking_id' => $this->model->id,
|
||||
'status' => $val
|
||||
]);
|
||||
}else{
|
||||
} else {
|
||||
$booking_country_service->fill([
|
||||
'status' => $val
|
||||
]);
|
||||
|
|
@ -260,18 +273,19 @@ class BookingRepository extends BaseRepository {
|
|||
}
|
||||
}
|
||||
|
||||
private function updateProviderService($provider_service){
|
||||
foreach ($provider_service as $provider_service_id=>$val){
|
||||
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){
|
||||
if (!$booking_provider_service) {
|
||||
BookingProviderService::create([
|
||||
'service_provider_service_id' => $provider_service_id,
|
||||
'booking_id' => $this->model->id,
|
||||
'status' => $val
|
||||
]);
|
||||
}else{
|
||||
} else {
|
||||
$booking_provider_service->fill([
|
||||
'status' => $val
|
||||
]);
|
||||
|
|
@ -280,18 +294,19 @@ class BookingRepository extends BaseRepository {
|
|||
}
|
||||
}
|
||||
|
||||
private function updateCompanyService($company_service){
|
||||
foreach ($company_service as $company_service_id=>$val){
|
||||
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();
|
||||
->where('booking_id', '=', $this->model->id)->first();
|
||||
|
||||
if(!$booking_company_service){
|
||||
if (!$booking_company_service) {
|
||||
BookingCompanyService::create([
|
||||
'travel_company_service_id' => $company_service_id,
|
||||
'booking_id' => $this->model->id,
|
||||
'status' => $val
|
||||
]);
|
||||
}else{
|
||||
} else {
|
||||
$booking_company_service->fill([
|
||||
'status' => $val
|
||||
]);
|
||||
|
|
@ -300,4 +315,135 @@ class BookingRepository extends BaseRepository {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
public function convertArrangementsToDrafts(Booking $booking)
|
||||
{
|
||||
if (!$booking->arrangements || $booking->arrangements->count() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$nextPos = 1;
|
||||
if ($booking->booking_draft_items && $booking->booking_draft_items->count() > 0) {
|
||||
$nextPos = $booking->booking_draft_items->max('pos') + 1;
|
||||
}
|
||||
|
||||
foreach ($booking->arrangements->sortByDesc('view_position') as $arrangement) {
|
||||
|
||||
$data = $arrangement->getDataAsMap();
|
||||
|
||||
|
||||
// Erstelle neues BookingDraftItem aus Arrangement
|
||||
$draftItem = new BookingDraftItem();
|
||||
|
||||
// Mappe die grundlegenden Daten
|
||||
$draftItem->booking_id = $booking->id;
|
||||
$draftItem->pos = $nextPos++;
|
||||
|
||||
// Daten von Arrangement übertragen
|
||||
if ($arrangement->begin) {
|
||||
$draftItem->start_date = $arrangement->begin->format('Y-m-d');
|
||||
}
|
||||
if ($arrangement->end) {
|
||||
$draftItem->end_date = $arrangement->end->format('Y-m-d');
|
||||
}
|
||||
|
||||
// Service/Beschreibung aus data_s generieren
|
||||
$serviceText = $arrangement->getDataS();
|
||||
$draftItem->service = $serviceText;
|
||||
|
||||
$draftItem->adult = $data['Teilnehmer'] ?? $booking->pax;
|
||||
$draftItem->price_adult = $data['Preis'] ?? 0;
|
||||
|
||||
// PDF-Einstellung übernehmen
|
||||
$draftItem->in_pdf = $arrangement->in_pdf ? 1 : 0;
|
||||
|
||||
// Versuche DraftType zu finden basierend auf ArrangementType
|
||||
if ($arrangement->arrangement_type && isset($arrangement->arrangement_type->name)) {
|
||||
$draftType = \App\Models\DraftType::where('name', 'like', '%' . $arrangement->arrangement_type->name . '%')->first();
|
||||
if ($draftType) {
|
||||
$draftItem->draft_type_id = $draftType->id;
|
||||
}
|
||||
} else {
|
||||
// Fallback: Suche nach einem passenden DraftType basierend auf dem Namen
|
||||
$draftType = \App\Models\DraftType::where('name', 'like', '%' . $arrangement->type_s . '%')->first();
|
||||
if ($draftType) {
|
||||
$draftItem->draft_type_id = $draftType->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Standardwerte für neue Felder setzen
|
||||
$draftItem->comfort = 0;
|
||||
$draftItem->price = 0;
|
||||
$draftItem->adult = 0;
|
||||
$draftItem->price_children = 0;
|
||||
$draftItem->children = 0;
|
||||
|
||||
$draftItem->save();
|
||||
|
||||
// Arrangement als konvertiert markieren oder löschen
|
||||
// Hier löschen wir das Arrangement nach erfolgreicher Konvertierung
|
||||
$arrangement->delete();
|
||||
}
|
||||
|
||||
// Stelle sicher, dass new_drafts aktiviert ist
|
||||
if (!$booking->new_drafts) {
|
||||
$booking->new_drafts = true;
|
||||
$booking->save();
|
||||
}
|
||||
|
||||
// Preise neu berechnen
|
||||
$booking->calculate_price_total();
|
||||
}
|
||||
|
||||
public function loadDraftToBooking($bookingId, $draftId)
|
||||
{
|
||||
$booking = Booking::findOrFail($bookingId);
|
||||
$draft = \App\Models\Draft::findOrFail($draftId);
|
||||
|
||||
if (!$booking->new_drafts) {
|
||||
$booking->new_drafts = true;
|
||||
$booking->save();
|
||||
}
|
||||
|
||||
// Lösche bestehende Draft Items falls gewünscht
|
||||
if ($booking->booking_draft_items && $booking->booking_draft_items->count() > 0) {
|
||||
foreach ($booking->booking_draft_items as $existingItem) {
|
||||
$existingItem->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$pos = 1;
|
||||
foreach ($draft->draft_items as $draftItem) {
|
||||
$bookingDraftItem = new \App\Models\BookingDraftItem();
|
||||
|
||||
// Kopiere alle Daten aus der Draft Vorlage
|
||||
$bookingDraftItem->booking_id = $booking->id;
|
||||
$bookingDraftItem->draft_type_id = $draftItem->draft_type_id;
|
||||
$bookingDraftItem->travel_program_id = null; // Wird später gesetzt wenn nötig
|
||||
$bookingDraftItem->fewo_lodging_id = null;
|
||||
$bookingDraftItem->travel_class_id = null;
|
||||
$bookingDraftItem->draft_item_id = $draftItem->id;
|
||||
$bookingDraftItem->request_date = null;
|
||||
$bookingDraftItem->days_start = $draftItem->days_start;
|
||||
$bookingDraftItem->days_duration = $draftItem->days_duration;
|
||||
$bookingDraftItem->start_date = null; // Wird später basierend auf Reisebeginn gesetzt
|
||||
$bookingDraftItem->end_date = null; // Wird später basierend auf Reiseende gesetzt
|
||||
$bookingDraftItem->service = $draftItem->service;
|
||||
$bookingDraftItem->price_adult = $draftItem->price_adult;
|
||||
$bookingDraftItem->adult = $draftItem->adult;
|
||||
$bookingDraftItem->price_children = $draftItem->price_children;
|
||||
$bookingDraftItem->children = $draftItem->children;
|
||||
$bookingDraftItem->price = 0; // Wird später berechnet
|
||||
$bookingDraftItem->pos = $pos++;
|
||||
$bookingDraftItem->in_pdf = $draftItem->in_pdf;
|
||||
$bookingDraftItem->comfort = 0;
|
||||
$bookingDraftItem->status = 1;
|
||||
|
||||
$bookingDraftItem->save();
|
||||
}
|
||||
|
||||
// Preise neu berechnen
|
||||
$booking->calculate_price_total();
|
||||
|
||||
return $booking;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue