385 lines
18 KiB
PHP
Executable file
385 lines
18 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Airline;
|
|
use App\Models\Booking;
|
|
use App\Models\CustomerMail;
|
|
use App\Models\Status;
|
|
use App\Models\Sym\TravelCountry;
|
|
use App\Models\TravelAgenda;
|
|
use App\Repositories\CustomerMailRepository;
|
|
use Carbon\Carbon;
|
|
use Request;
|
|
use DataTables;
|
|
|
|
class RequestController extends Controller
|
|
{
|
|
|
|
|
|
public function __construct()
|
|
{
|
|
$this->middleware('admin');
|
|
}
|
|
|
|
public function index($step = false)
|
|
{
|
|
|
|
$travel_countries = Booking::join('travel_country', 'travel_country_id', '=', 'travel_country.id')->get()->pluck('name', 'travel_country_id')->unique()->toArray();
|
|
|
|
$filter_lead_status = Status::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_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_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,
|
|
];
|
|
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_mails')->where('lead_id', '!=', NULL);
|
|
|
|
if(Request::get('full_firstname_search') != ""){
|
|
$query->where('participant_firstname', 'LIKE', '%'.Request::get('full_firstname_search').'%');
|
|
}
|
|
|
|
if(Request::get('full_lastname_search') != ""){
|
|
$query->where('participant_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_lead_status_id') != ""){
|
|
$query->whereHas('lead', function ($q) {
|
|
$q->where('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_id', '=', Request::get('travel_option_airline_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(){
|
|
|
|
$query = $this->getSearchRequests();
|
|
$ret = $query->get()->pluck('travelagenda_id', 'id')->unique()->toArray();
|
|
return TravelAgenda::whereIn('id', $ret)->get()->pluck('name', 'id');
|
|
}
|
|
|
|
public function loadModal(){
|
|
$data = Request::all();
|
|
$ret = "";
|
|
if(Request::ajax()){
|
|
$data['customers'] = [];
|
|
$query = $this->getSearchRequests();
|
|
$bookings = $query->orderBy('id', 'DESC')->limit(50)->get();
|
|
foreach ($bookings as $booking){
|
|
$tmp = [];
|
|
$tmp['email'] = $booking->customer ? $booking->customer->email : "";
|
|
$tmp['name'] = $booking->customer ? $booking->customer->firstname." ".$booking->customer->name." | " : "- | ";
|
|
$tmp['name'] .= $booking->travel_country_id ? $booking->travel_country->name." | " : "- | ";
|
|
$tmp['name'] .= $booking->travelagenda_id ? $booking->travel_agenda->name."" : "-";
|
|
$data['customers'][$booking->id] = $tmp;
|
|
}
|
|
$ret = CustomerMailRepository::loadModal($data);
|
|
}
|
|
return response()->json(['response' => $data, 'html'=>$ret]);
|
|
}
|
|
|
|
public function getRequests()
|
|
{
|
|
|
|
$query = $this->getSearchRequests();
|
|
|
|
return DataTables::eloquent($query)
|
|
->addColumn('action_lead_edit', function (Booking $booking) {
|
|
return '<a href="' . route('booking_detail', [$booking->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
|
})
|
|
->addColumn('lead_id', function (Booking $booking) {
|
|
return '<a data-order="'.$booking->lead_id.'" href="'.make_old_url('leads/'.$booking->lead_id.'/edit').'" data-id="'.$booking->lead_id.'">'.$booking->lead_id.'</a>';
|
|
})
|
|
->addColumn('participant_firstname', function (Booking $booking) {
|
|
return '<a data-order="'.$booking->participant_firstname.'" href="'.make_old_url('customer/'.$booking->customer_id.'/edit').'" data-id="'.$booking->customer_id.'">'.$booking->participant_firstname.'</a>';
|
|
})
|
|
->addColumn('participant_name', function (Booking $booking) {
|
|
return '<a data-order="'.$booking->participant_name.'" href="'.make_old_url('customer/'.$booking->customer_id.'/edit').'" data-id="'.$booking->customer_id.'">'.$booking->participant_name.'</a>';
|
|
})
|
|
->addColumn('id', function (Booking $booking) {
|
|
return '<a data-order="'.$booking->id.'" href="'.make_old_url('booking/'.$booking->id.'/edit').'" data-id="'.$booking->id.'">'.$booking->id.'</a>';
|
|
})
|
|
->addColumn('action_booking_edit', function (Booking $booking) {
|
|
return '<a href="' . route('booking_detail', [$booking->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
|
})
|
|
->addColumn('travel_country_id', function (Booking $booking) {
|
|
return '<span data-order="'.($booking->travel_country_id ? $booking->travel_country_id : 0).'">'.($booking->travel_country_id ? $booking->travel_country->name : "-").'</span>';
|
|
})
|
|
->addColumn('travelagenda_id', function (Booking $booking) {
|
|
return '<span data-order="'.($booking->travelagenda_id ? $booking->travelagenda_id : 0).'">'.($booking->travelagenda_id ? $booking->travel_agenda->name : "-").'</span>';
|
|
})
|
|
->addColumn('start_date', function (Booking $booking) {
|
|
return $booking->getStartDateFormat();
|
|
})
|
|
->addColumn('end_date', function (Booking $booking) {
|
|
return $booking->getEndDateFormat();
|
|
})
|
|
->addColumn('travel_documents', function (Booking $booking) {
|
|
return $booking->travel_documents ? ' <span data-order="1" class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : '<span data-order="0" class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
|
|
})
|
|
->addColumn('sf_guard_user_id', function (Booking $booking) {
|
|
return '<span data-order="'.($booking->sf_guard_user_id ? $booking->sf_guard_user_id : 0).'">'.($booking->sf_guard_user_id? $booking->sf_guard_user->first_name." ".$booking->sf_guard_user->last_name : "-").'</span>';
|
|
})
|
|
->addColumn('lead.status_id', function (Booking $booking) {
|
|
//umbuchen
|
|
if($booking->lead->status_id){
|
|
$color = $booking->lead->status->color;
|
|
$icon = "";
|
|
if($booking->lead->status_id == 14 && $booking->lead->is_rebook){
|
|
$color = '#94ae59';
|
|
$icon = '<i class="fa fa-check-circle"></i> ';
|
|
}
|
|
if($booking->lead->status_id == 14 && !$booking->lead->is_rebook){
|
|
$icon = '<i class="fa fa-times-circle"></i> ';
|
|
}
|
|
return '<span data-order="'.$booking->lead->status_id.'"><span class="badge badge-dark" style="background-color: '.$color.'">'.$icon.$booking->lead->status->name.'</span></span>';
|
|
}
|
|
return '<span data-order="0">-</span>';
|
|
})
|
|
->addColumn('last_customer_email', function (Booking $booking) {
|
|
//umbuchen
|
|
if($booking->customer_mails->count()){
|
|
$customer_mail = $booking->customer_mails_sent_at->last();
|
|
return '<a data-order="'.$customer_mail->getSentAtRaw().'" href="'.route('booking_detail', [$booking->id]).'#collapseBookingMails" data-order="'.$customer_mail->sent_at.'"><span class="badge '.($customer_mail->is_answer ? 'badge-default' : 'badge-secondary').'">'.$customer_mail->sent_at.'</span></a>';
|
|
}
|
|
return '<span data-order="">-</span>';
|
|
})
|
|
->addColumn('paying_out', function (Booking $booking) {
|
|
$icon = "";
|
|
$badge = $booking->getPayingOutColor();
|
|
if($booking->paying_out_status == 1){ //offen
|
|
$icon = '<i class="fa fa-times-circle"></i> ';
|
|
}
|
|
if($booking->paying_out_status == 2){ //erledigt
|
|
$badge = 'success';
|
|
$icon = '<i class="fa fa-check-circle"></i> ';
|
|
}
|
|
return '<span data-order="'.$booking->paying_out.'"><span class="badge badge-'.$booking->getPayingOutColor().'">'.$icon.$booking->getPayingOutType().'</span></span>';
|
|
})
|
|
->addColumn('paying_out_status', function (Booking $booking) {
|
|
return '<span data-order="'.$booking->paying_out_status.'"><span class="badge badge-'.$booking->getPayingOutStatusColor().'">'.$booking->getPayingOutStatusType().'</span></span>';
|
|
})
|
|
->addColumn('airline_id', function (Booking $booking) {
|
|
return $booking->airline ? '<span data-order="'.$booking->airline_id.'">'.$booking->airline->name.'</span>' : '-';
|
|
})
|
|
->addColumn('refund', function (Booking $booking) {
|
|
return '<span data-order="'.$booking->refund_date.'"><span class="badge badge-'.$booking->getRefundColor().'">'.$booking->getRefundTypeList().'</span></span>';
|
|
})
|
|
->addColumn('hold', function (Booking $booking) {
|
|
return $booking->hold ? ' <span data-order="1" class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : '<span data-order="0" class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
|
|
})
|
|
->addColumn('xx_tkt', function (Booking $booking) {
|
|
return '<span data-order="'.$booking->xx_tkt_date.'"><span class="badge badge-'.$booking->getXxTktColor().'">'.$booking->getXxTktTypeList().'</span></span>';
|
|
})
|
|
|
|
->orderColumn('last_customer_email', function ($query, $order) {
|
|
|
|
$query->whereHas('customer_mails',
|
|
function ($q) use ($order) {
|
|
// $q->select('sent_at')->where('sent_at', DB::raw("(select max('sent_at') customer_mails)")); //)
|
|
})->orderBy(
|
|
CustomerMail::select('sent_at')
|
|
->whereColumn('booking_id', 'booking.id')
|
|
->orderBy('sent_at', 'DESC')
|
|
->limit(1)
|
|
, $order);
|
|
})
|
|
|
|
/*
|
|
->filterColumn('travelagenda_id', function($query, $keyword) {
|
|
if($keyword != ""){
|
|
$query->whereRaw("travelagenda_id = ?", $keyword);
|
|
|
|
}
|
|
})
|
|
*/
|
|
->orderColumn('lead_id', 'lead_id $1')
|
|
->orderColumn('participant_firstname', 'participant_firstname $1')
|
|
->orderColumn('participant_name', 'participant_name $1')
|
|
->orderColumn('id', 'id $1')
|
|
->orderColumn('travel_country_id', 'travel_country_id $1')
|
|
->orderColumn('travelagenda_id', 'travelagenda_id $1')
|
|
->orderColumn('sf_guard_user_id', 'sf_guard_user_id $1')
|
|
->orderColumn('start_date', 'start_date $1')
|
|
->orderColumn('end_date', 'end_date $1')
|
|
->orderColumn('paying_out', 'paying_out $1')
|
|
->orderColumn('paying_out_status', 'paying_out_status $1')
|
|
->orderColumn('refund', 'refund_date $1')
|
|
->orderColumn('airline_id', 'airline_id $1')
|
|
->orderColumn('hold', 'hold $1')
|
|
->orderColumn('xx_tkt', 'xx_tkt_date $1')
|
|
->orderColumn('travel_documents', 'travel_documents $1')
|
|
->rawColumns(['action_lead_edit', 'lead_id', 'participant_firstname', 'participant_name', 'action_booking_edit', 'travel_country_id', 'travelagenda_id', 'sf_guard_user_id', 'lead.status_id', 'last_customer_email', 'id', 'travel_documents', 'paying_out', 'paying_out_status', 'airline_id', 'refund', 'hold', 'xx_tkt'])
|
|
->make(true);
|
|
}
|
|
}
|
|
|
|
|