middleware(['admin', '2fa']);
}
public function index($step = false)
{
// Get distinct travel_country_ids from bookings that are not null
$usedCountryIds = Booking::whereNotNull('travel_country_id')
->distinct()
->pluck('travel_country_id');
// Fetch the corresponding TravelCountry models and create an associative array [id => name]
$travel_countries = TravelCountry::whereIn('id', $usedCountryIds)
->pluck('name', 'id') // Use country id as key
->toArray();
//dd($travel_countries); // Keep this for debugging if needed
$filter_lead_status = Status::get()->pluck('name', 'id')->toArray();
$filter_travel_company = TravelCompany::get()->pluck('name', 'id')->toArray();
$filter_airports = Airport::get()->pluck('name', 'id')->toArray();
$filter_paying_out = Booking::$paying_out_types;
$filter_paying_out_status = Booking::$paying_out_status_types;
$filter_refund = Booking::$refund_types;
$filter_xx_tkt = Booking::$xx_tkt_types;
$filter_sf_guard_user = SfGuardUser::where('is_active', 1)->where('user_id', '!=', NULL)
->whereHas('user', function ($q) {
$q->where('active', 1);
})->get()->pluck('username', 'id')->toArray();
$filter_airlines = Airline::get()->pluck('name', 'id')->toArray();
unset($filter_paying_out[0]);
unset($filter_refund[0]);
unset($filter_xx_tkt[0]);
$data = [
'step' => $step,
'travel_countries' => $travel_countries,
'filter_travel_company' => $filter_travel_company,
'filter_lead_status' => $filter_lead_status,
'filter_paying_out' => $filter_paying_out,
'filter_paying_out_status' => $filter_paying_out_status,
'filter_refund' => $filter_refund,
'filter_xx_tkt' => $filter_xx_tkt,
'filter_airlines' => $filter_airlines,
'filter_sf_guard_user' => $filter_sf_guard_user,
'filter_airports' => $filter_airports,
];
return view('request.index', $data);
}
public function detail($id)
{
$travel_countries = Booking::join('travel_country', 'travel_country_id', '=', 'travel_country.id')->get()->pluck('name', 'travel_country_id')->unique()->toArray();
$data = [
'travel_countries' => $travel_countries,
];
return view('request.index', $data);
}
/*
wirte old where has state to new has travel_documents
$bs = Booking::whereHas('arrangements', function($q){
$q->where('state', '!=', NULL);
})->where('lead_id', '!=', NULL)->where('new_drafts', 0)->get();
foreach ($bs as $b){
$b->travel_documents = true;
$b->save();
var_dump($b->travel_documents);
}
die();
*/
private function getSearchRequests()
{
$query = Booking::with('lead')->with('customer')->with('customer_mails')->with('customer_mails')->select('booking.*')->where('lead_id', '!=', NULL);
if (Request::get('full_firstname_search') != "") {
$query->whereHas('customer', function ($q) {
$q->where('firstname', 'LIKE', '%' . Request::get('full_firstname_search') . '%');
});
}
if (Request::get('full_lastname_search') != "") {
$query->whereHas('customer', function ($q) {
$q->where('name', 'LIKE', '%' . Request::get('full_lastname_search') . '%');
});
}
if (Request::get('travel_option_country_id') != "") {
$country_ids = TravelCountry::where('contact_lands', 'LIKE', '%"' . Request::get('travel_option_country_id') . '"%')->get()->pluck('id');
$country_ids[] = Request::get('travel_option_country_id');
$query->whereIn('travel_country_id', $country_ids);
}
if (Request::get('travel_option_agenda_id') != "") {
$query->where('travelagenda_id', '=', Request::get('travel_option_agenda_id'));
}
if (Request::get('travel_option_company_id') != "") {
$query->where('travel_company_id', '=', Request::get('travel_option_company_id'));
}
if (Request::get('travel_option_lead_status_id') != "") {
$query->whereHas('lead', function ($q) {
$q->whereIn('status_id', Request::get('travel_option_lead_status_id'));
});
}
if (Request::get('travel_option_paying_out') != "") {
$query->where('paying_out', '=', Request::get('travel_option_paying_out'));
}
if (Request::get('travel_option_paying_out_status') != "") {
$query->where('paying_out_status', '=', Request::get('travel_option_paying_out_status'));
}
if (Request::get('travel_option_refund') != "") {
$query->where('refund', '=', Request::get('travel_option_refund'));
}
if (Request::get('travel_option_xx_tkt') != "") {
$query->where('xx_tkt', '=', Request::get('travel_option_xx_tkt'));
}
if (Request::get('travel_option_airline_id') != "") {
$query->where('airline_ids', 'LIKE', '%' . Request::get('travel_option_airline_id') . '%');
}
if (Request::get('travel_option_airport_id') != "") {
$query->where('airport_id', '=', Request::get('travel_option_airport_id'));
}
// $query->where('end_date', '<=', $now);
if (Request::get('travel_option_search')) {
$now = Carbon::now();
switch (Request::get('travel_option_search')) {
case 'before_2':
$query->whereBetween('start_date', [Carbon::now()->modify('-2 month'), $now]);
break;
case 'brefore_1':
$query->whereBetween('start_date', [Carbon::now()->modify('-1 month'), $now]);
break;
case 'on_site':
$query->where('start_date', '<=', $now);
$query->where('end_date', '>=', $now);
break;
case 'after_1':
$query->whereBetween('start_date', [$now, Carbon::now()->modify('+1 month')]);
break;
case 'after_2':
$query->whereBetween('start_date', [$now, Carbon::now()->modify('+2 month')]);
break;
}
} else {
$start = null;
$end = null;
if (Request::get('arrival_start_date') != "") {
$arrStart = explode(".", Request::get('arrival_start_date'));
if (count($arrStart) == 3) {
$start = Carbon::create($arrStart[2], $arrStart[1], $arrStart[0], 0, 0, 0);
}
}
if (Request::get('arrival_end_date') != "") {
$arrEnd = explode(".", Request::get('arrival_end_date'));
if (count($arrEnd) == 3) {
$end = Carbon::create($arrEnd[2], $arrEnd[1], $arrEnd[0], 23, 59, 59);
}
}
if ($start && $end) {
$query->whereBetween('start_date', [$start, $end]);
}
if ($start && !$end) {
$query->where('start_date', '>=', $start);
}
if (!$start && $end) {
$query->where('start_date', '<=', $end);
}
$start = null;
$end = null;
if (Request::get('departure_start_date') != "") {
$arrStart = explode(".", Request::get('departure_start_date'));
if (count($arrStart) == 3) {
$start = Carbon::create($arrStart[2], $arrStart[1], $arrStart[0], 0, 0, 0);
}
}
if (Request::get('departure_end_date') != "") {
$arrEnd = explode(".", Request::get('departure_end_date'));
if (count($arrEnd) == 3) {
$end = Carbon::create($arrEnd[2], $arrEnd[1], $arrEnd[0], 23, 59, 59);
}
}
if ($start && $end) {
$query->whereBetween('end_date', [$start, $end]);
}
if ($start && !$end) {
$query->where('end_date', '>=', $start);
}
if (!$start && $end) {
$query->where('end_date', '<=', $end);
}
}
if (Request::get('sort_travel_country_id') != "") {
$query->where('travel_country_id', '=', Request::get('sort_travel_country_id'));
}
if (Request::get('sort_travelagenda_id') != "") {
$query->where('travelagenda_id', '=', Request::get('sort_travelagenda_id'));
}
if (Request::get('sort_sf_guard_user_id') != "") {
$query->where('sf_guard_user_id', '=', Request::get('sort_sf_guard_user_id'));
}
if (Request::get('sort_travel_documents') != "") {
$query->where('travel_documents', '=', Request::get('sort_travel_documents'));
}
if (Request::get('full_lead_id_search') != "") {
$query->where('lead_id', 'LIKE', '%' . Request::get('full_lead_id_search') . '%');
}
if (Request::get('full_booking_id_search') != "") {
$query->where('id', 'LIKE', '%' . Request::get('full_booking_id_search') . '%');
}
return $query;
}
public function getAjaxRequests()
{
$data = Request::all();
if (Request::ajax()) {
if (isset($data['action']) && $data['action'] === "get_popover_booking_services") {
$booking = Booking::findOrFail($data['booking_id']);
$ret = "";
$count = false;
foreach ($booking->travel_country->getContactLandsModels() as $TravelCountry) {
if ($TravelCountry->stern_travel_country) {
$hl = $TravelCountry->stern_travel_country->name . "
";
$tmp = "";
foreach ($TravelCountry->stern_travel_country->travel_country_services as $travel_country_service) {
$tmp .= \App\Models\BookingCountryService::getStatus($travel_country_service->id, $booking->id) ?
' ' . $travel_country_service->name . '' :
' ' . $travel_country_service->name . '';
$tmp .= '
';
}
if ($tmp !== "") {
$ret .= $hl . $tmp;
}
}
}
if ($booking->service_provider_entries->count()) {
foreach ($booking->service_provider_entries as $service_provider_entry) {
if ($service_provider_entry->service_provider->service_provider_services->count()) {
$hl = $service_provider_entry->service_provider->name . "
";
$tmp = "";
foreach ($service_provider_entry->service_provider->service_provider_services as $service_provider_service) {
$tmp .= \App\Models\BookingProviderService::getStatus($service_provider_service->id, $booking->id) ?
' ' . $service_provider_service->name . '' :
' ' . $service_provider_service->name . '';
$tmp .= '
';
}
if ($tmp !== "") {
$ret .= $hl . $tmp;
}
}
}
}
if ($booking->booking_service_items->count()) {
foreach ($booking->booking_service_items as $booking_service_item) {
if ($booking_service_item->travel_company->travel_company_services->count()) {
$hl = $booking_service_item->travel_company->name . "
";
$tmp = "";
foreach ($booking_service_item->travel_company->travel_company_services as $travel_company_service) {
$tmp .= \App\Models\BookingCompanyService::getStatus($travel_company_service->id, $booking->id) ?
' ' . $travel_company_service->name . '' :
' ' . $travel_company_service->name . '';
$tmp .= '
';
}
if ($tmp !== "") {
$ret .= $hl . $tmp;
}
}
}
}
return $ret === "" ? 'keine Leistungen definiert' : $ret;
}
if (isset($data['action']) && $data['action'] === "get_popover_booking_notice") {
$booking = Booking::findOrFail($data['booking_id']);
$ret = "";
if ($booking->booking_notices->count()) {
$booking_notice = $booking->booking_notices->first();
return $booking_notice->getSmallerMessage(500);
}
return $ret === "" ? 'keine E-Notiz' : $ret;
}
if (isset($data['action']) && $data['action'] === "get_popover_booking_last_email") {
$booking = Booking::findOrFail($data['booking_id']);
$ret = "";
if ($booking->customer_mails->count()) {
$customer_mail = $booking->customer_mails_sent_at->last();
return "