08 2024
This commit is contained in:
parent
c1c613a4b9
commit
881fc84207
384 changed files with 50679 additions and 990 deletions
396
app/Http/Controllers/Admin/ReportBookingController.php
Normal file
396
app/Http/Controllers/Admin/ReportBookingController.php
Normal file
|
|
@ -0,0 +1,396 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use Request;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Status;
|
||||
use App\Services\Util;
|
||||
use App\Models\Booking;
|
||||
use App\Models\TravelCompany;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Exports\ReportCollectionExport;
|
||||
|
||||
class ReportBookingController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware(['superadmin', '2fa']);
|
||||
}
|
||||
|
||||
public function bookings()
|
||||
{
|
||||
$data = [
|
||||
'filter_lead_status' => Status::get()->pluck('name', 'id')->toArray(),
|
||||
'filter_travel_companies' => TravelCompany::where('active', true)->get()->pluck('name', 'id')->toArray(),
|
||||
|
||||
];
|
||||
return view('admin.report.bookings', $data);
|
||||
}
|
||||
|
||||
public function checkBookings()
|
||||
{
|
||||
$data = [
|
||||
'filter_lead_status' => Status::get()->pluck('name', 'id')->toArray(),
|
||||
'filter_travel_companies' => TravelCompany::where('active', true)->get()->pluck('name', 'id')->toArray(),
|
||||
|
||||
];
|
||||
return view('admin.report.check_bookings', $data);
|
||||
}
|
||||
|
||||
//checkBookingsDatatable
|
||||
|
||||
private function prozessBookingSearch()
|
||||
{
|
||||
|
||||
$query = Booking::with( 'customer', 'lead', 'booking_strono','service_provider_entries', 'service_provider_entries.service_provider')->select('booking.*');
|
||||
|
||||
|
||||
if(Request::get('filter_db_lead_status_id') != ""){
|
||||
$query->whereHas('lead', function ($q) {
|
||||
$q->whereIn('status_id', Request::get('filter_db_lead_status_id'));
|
||||
|
||||
});
|
||||
}
|
||||
if(Request::get('filter_lead_status_id') != ""){
|
||||
$query->whereHas('lead', function ($q) {
|
||||
$q->whereIn('status_id', Request::get('filter_lead_status_id'));
|
||||
});
|
||||
}
|
||||
if(Request::get('filter_travel_company_id') != ""){
|
||||
$query->whereIn("travel_company_id", Request::get('filter_travel_company_id'));
|
||||
}
|
||||
|
||||
if(Request::get('filter_travel_date_from') != ""){
|
||||
$travel_date_from = Carbon::parse(Request::get('filter_travel_date_from'))->format("Y-m-d");
|
||||
$query->where("start_date", '>=', $travel_date_from);
|
||||
}
|
||||
if(Request::get('filter_travel_date_to') != ""){
|
||||
$travel_date_to = Carbon::parse(Request::get('filter_travel_date_to'))->format("Y-m-d");
|
||||
$query->where("start_date", '<=', $travel_date_to);
|
||||
}
|
||||
|
||||
if(Request::get('filter_booking_date_from') != ""){
|
||||
$filter_booking_date_from = Carbon::parse(Request::get('filter_booking_date_from'))->format("Y-m-d");
|
||||
$query->where("booking_date", '>=', $filter_booking_date_from);
|
||||
}
|
||||
if(Request::get('filter_booking_date_to') != ""){
|
||||
$filter_booking_date_from = Carbon::parse(Request::get('filter_booking_date_to'))->format("Y-m-d");
|
||||
$query->where("booking_date", '<=', $filter_booking_date_from);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function bookingsDatatable()
|
||||
{
|
||||
$query = $this->prozessBookingSearch();
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->with('price_total_sum', function() use ($query) {
|
||||
$price1 = with(clone $query)->whereNull('canceled')->sum('price');
|
||||
$price2 = with(clone $query)->whereNotNull('canceled')->sum('price_canceled');
|
||||
return Util::_number_format($price1+$price2);
|
||||
})
|
||||
->with('price_total_total_sum', function() use ($query) {
|
||||
return Util::_number_format($query->sum('price_total'));
|
||||
})
|
||||
->with('proceed_total_sum', function() use ($query) {
|
||||
if($query->count() > 200){
|
||||
return 'max 200 ';
|
||||
}
|
||||
$all = $query->get();
|
||||
$proceeds = 0;
|
||||
foreach ($all as $v){
|
||||
$proceeds += $v->proceeds(true);
|
||||
}
|
||||
return Util::_number_format($proceeds);
|
||||
})
|
||||
->addColumn('id', function (Booking $booking) {
|
||||
return '<a data-order="' . $booking->id . '" href="' . route('booking_detail', [$booking->id]) . '" data-id="' . $booking->id . '">' . $booking->id . '</a>';
|
||||
})
|
||||
->addColumn('customer.fullName', function (Booking $booking) {
|
||||
return $booking->customer->fullName();
|
||||
})
|
||||
->addColumn('price', function (Booking $booking) {
|
||||
return $booking->booking_strono ? $booking->price_canceled : $booking->price;
|
||||
})
|
||||
->addColumn('proceeds', function (Booking $booking) {
|
||||
return $booking->proceeds();
|
||||
})
|
||||
->addColumn('start_date', function (Booking $booking) {
|
||||
return $booking->getStartDateFormat();
|
||||
})
|
||||
->addColumn('end_date', function (Booking $booking) {
|
||||
return $booking->getEndDateFormat();
|
||||
})
|
||||
->addColumn('booking_date', function (Booking $booking) {
|
||||
return $booking->getBookingDateFormat();
|
||||
})
|
||||
->addColumn('booking_strono_date', function (Booking $booking) {
|
||||
return $booking->booking_strono ? $booking->booking_strono->storno_date->format("d.m.Y") : "";
|
||||
})
|
||||
->addColumn('service_provider.names', function (Booking $booking) {
|
||||
$ret = "";
|
||||
if($booking->service_provider_entries){
|
||||
foreach ($booking->service_provider_entries as $service_provider_entry){
|
||||
$ret .= '<span class="ui-stars">'.$service_provider_entry->service_provider->name." | ";
|
||||
$ret .= $service_provider_entry->getAmountFinalEur()." | ";
|
||||
$ret .= $service_provider_entry->is_cleared ? '<i class="fa fa-check text-success"></i>' : '<i class="fa fa-times text-danger"></i>';
|
||||
$ret .= "</span><br>";
|
||||
}
|
||||
}
|
||||
return $ret === "" ? "-" : $ret;
|
||||
})
|
||||
->addColumn('lead.status_id', function (Booking $booking) {
|
||||
if($booking->lead && $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>';
|
||||
})
|
||||
->filterColumn('customer.fullName', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereHas('customer', function ($q) use ($keyword) {
|
||||
$q->where("name", 'LIKE', '%' . $keyword . '%')
|
||||
->orWhere('firstname', 'LIKE', '%' . $keyword . '%');
|
||||
});
|
||||
}
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('start_date', 'start_date $1')
|
||||
->orderColumn('end_date', 'end_date $1')
|
||||
->orderColumn('price', 'price $1')
|
||||
->orderColumn('booking_date', 'booking_date $1')
|
||||
->orderColumn('customer.fullName', 'customer.firstname $1')
|
||||
->orderColumn('customer.firstname', 'customer.firstname $1')
|
||||
->orderColumn('customer.name', 'customer.name $1')
|
||||
//->orderColumn('lead.status_id', 'lead.status_id $1')
|
||||
//->orderColumn('is_cleared', 'is_cleared $1')
|
||||
->rawColumns(['id', 'lead.status_id', 'service_provider.names'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function bookingsExport(){
|
||||
|
||||
$query = $this->prozessBookingSearch();
|
||||
|
||||
$order = explode(",", Request::get('order'));
|
||||
$orderByNum = [
|
||||
0 => "id",
|
||||
2 => "merlin_order_number",
|
||||
3 => "price",
|
||||
4 => "price_total",
|
||||
7 => "start_date",
|
||||
8 => "end_date",
|
||||
9 => "booking_date",
|
||||
];
|
||||
if(isset($order[0])) {
|
||||
$column = isset($orderByNum[$order[0]]) ? $orderByNum[$order[0]] : "start_date";
|
||||
$direction = isset($order[1]) ? strtoupper($order[1]) : "ASC";
|
||||
$query->orderBy($column, $direction);
|
||||
}
|
||||
|
||||
$filename = "file-".date('Y-m-d-H-i-s');
|
||||
$exports = $query->get();
|
||||
$columns = [];
|
||||
|
||||
if(Request::get('export') === "export"){
|
||||
$filename = "Buchungen_".date('Y-m-d-H-i-s');
|
||||
|
||||
$headers = array(
|
||||
'BuchungsID',
|
||||
'Status',
|
||||
'Storno',
|
||||
'MyJack Nr.',
|
||||
'Organisation',
|
||||
'Reisepreis',
|
||||
'Erlös',
|
||||
'Kunde',
|
||||
'Reisedatum',
|
||||
'bis',
|
||||
'Buchungsdatum',
|
||||
'Reiseland',
|
||||
'Reiseprogramm',
|
||||
'Reiseteilnehmer',
|
||||
'Leistungsträger',
|
||||
'Zahlung',
|
||||
'Zahlungsdatum',
|
||||
'Rechnungsnummer',
|
||||
'abgeschlossen',
|
||||
);
|
||||
$total_price = 0;
|
||||
$total_price_total = 0;
|
||||
$total_proceeds = 0;
|
||||
$total_amount_final = 0;
|
||||
|
||||
foreach($exports as $export) {
|
||||
$storno_date = $export->booking_strono ? $export->booking_strono->storno_date->format("d.m.Y") : "";
|
||||
if($export->service_provider_entries->count()){
|
||||
$new = true;
|
||||
foreach ($export->service_provider_entries as $service_provider_entry){
|
||||
if($new){
|
||||
$total_price += $export->isCanceled() ? $export->getPriceCanceledRaw() : $export->getPriceRaw();
|
||||
$total_price_total += $export->getPriceTotalRaw();
|
||||
$total_proceeds += $export->proceeds(true);
|
||||
}
|
||||
$total_amount_final += $service_provider_entry->getAmountFinalEurRaw();
|
||||
$columns[] = array(
|
||||
'BuchungsID' => $new ? $export->id : "",
|
||||
'Status' => $new ? $export->lead->status->name : "",
|
||||
'Storno' => $new ? $storno_date : "",
|
||||
'MyJack Nr.' => $new ? $export->merlin_order_number : "",
|
||||
'Organisation' => $new ? ($export->isCanceled() ? $export->price_canceled : $export->price) : "",
|
||||
'Reisepreis' => $new ? $export->price_total : "",
|
||||
'Erlös' => $new ? $export->proceeds() : "",
|
||||
'Kunde' => $new ? $export->customer->fullName() : "",
|
||||
'Reisedatum' => $new ? $export->getStartDateFormat() : "",
|
||||
'bis' => $new ? $export->getEndDateFormat() : "",
|
||||
'Buchungsdatum' => $new ? $export->getBookingDateFormat() : "",
|
||||
'Reiseland' => $new && $export->travel_country ? $export->travel_country->name : "",
|
||||
'Reiseprogramm' => $new && $export->travel_agenda ? $export->travel_agenda->name : "",
|
||||
'Reiseteilnehmer' => $new ? $export->pax : "",
|
||||
'Leistungsträger' => $service_provider_entry->service_provider->name,
|
||||
'Zahlung' => $service_provider_entry->getAmountFinalEur(),
|
||||
'Zahlungsdatum' => $service_provider_entry->getPaymentDateFormat(),
|
||||
'Rechnungsnummer' => $service_provider_entry->invoice_number,
|
||||
'abgeschlossen' => $service_provider_entry->is_cleared ? 'J' : 'N',
|
||||
|
||||
);
|
||||
$new = false;
|
||||
}
|
||||
}else{
|
||||
|
||||
//$total_price += $export->booking->isCanceled() ? $export->booking->getPriceCanceledRaw() : $export->booking->getPriceRaw();
|
||||
$total_price += $export->isCanceled() ? $export->getPriceCanceledRaw() : $export->getPriceRaw();
|
||||
$columns[] = array(
|
||||
'BuchungsID' => $export->id,
|
||||
'Status' => $export->lead->status->name,
|
||||
'Storno' => $storno_date,
|
||||
'MyJack Nr.' => $export->merlin_order_number,
|
||||
'Organisation' => $export->price,
|
||||
'Organisation' => $export->isCanceled() ? $export->price_canceled : $export->price,
|
||||
'Reisepreis' => $export->price_total,
|
||||
'Erlös' => $export->proceeds(),
|
||||
'Kunde' => $export->customer->fullName(),
|
||||
'Reisedatum' => $export->getStartDateFormat(),
|
||||
'bis' => $export->getEndDateFormat(),
|
||||
'Buchungsdatum' => $export->getBookingDateFormat(),
|
||||
'Reiseland' => $export->travel_country ? $export->travel_country->name : "",
|
||||
'Reiseprogramm' => $export->travel_agenda ? $export->travel_agenda->name : "",
|
||||
'Reiseteilnehmer' => $export->pax,
|
||||
'Leistungsträger' => "",
|
||||
'Zahlung' => "",
|
||||
'Zahlungsdatum' => "",
|
||||
'Rechnungsnummer' => "",
|
||||
'abgeschlossen' => "",
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
$columns[] = array(
|
||||
'BuchungsID' => "Total",
|
||||
'Status' => "",
|
||||
'Storno' => "",
|
||||
'MyJack Nr.' => "",
|
||||
'Organisation' => Util::_number_format($total_price),
|
||||
'Reisepreis' => Util::_number_format($total_price_total),
|
||||
'Erlös' => Util::_number_format($total_proceeds),
|
||||
'Kunde' => "",
|
||||
'Reisedatum' => "",
|
||||
'bis' => "",
|
||||
'Buchungsdatum' => "",
|
||||
'Reiseland' => "",
|
||||
'Reiseprogramm' => "",
|
||||
'Reiseteilnehmer' => "",
|
||||
'Leistungsträger' => "",
|
||||
'Zahlung' => Util::_number_format($total_amount_final),
|
||||
'Zahlungsdatum' => "",
|
||||
'Rechnungsnummer' => "",
|
||||
'abgeschlossen' => "",
|
||||
);
|
||||
}
|
||||
return Excel::download(new ReportCollectionExport($columns, $headers), $filename.'.xls');
|
||||
}
|
||||
|
||||
public function checkBookingsDatatable()
|
||||
{
|
||||
$query = $this->prozessBookingSearch();
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (Booking $booking) {
|
||||
return '<a data-order="' . $booking->id . '" href="' . route('booking_detail', [$booking->id]) . '" data-id="' . $booking->id . '">' . $booking->id . '</a>';
|
||||
})
|
||||
->addColumn('old_crm', 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('id', function (Booking $booking) {
|
||||
return '<a data-order="' . $booking->id . '" href="' . route('booking_detail', [$booking->id]) . '" data-id="' . $booking->id . '">' . $booking->id . '</a>';
|
||||
})
|
||||
->addColumn('price', function (Booking $booking) {
|
||||
return $booking->price;
|
||||
})
|
||||
->addColumn('service_total', function (Booking $booking) {
|
||||
return $booking->getServiceTotal();
|
||||
})
|
||||
->addColumn('price_total', function (Booking $booking) {
|
||||
return $booking->price_total;
|
||||
})
|
||||
->addColumn('check_total', function (Booking $booking) {
|
||||
$check = $booking->getPriceRaw() + $booking->getServiceTotal(true);
|
||||
return ($booking->getPriceTotalRaw() != $check) ? '<span class="badge badge-danger">'.Util::_number_format($check).'</span>' : "";
|
||||
})
|
||||
->addColumn('price_canceled', function (Booking $booking) {
|
||||
return $booking->isCanceled() ? $booking->price_canceled : "";
|
||||
})
|
||||
|
||||
->addColumn('start_date', function (Booking $booking) {
|
||||
return $booking->getStartDateFormat();
|
||||
})
|
||||
->addColumn('end_date', function (Booking $booking) {
|
||||
return $booking->getEndDateFormat();
|
||||
})
|
||||
->addColumn('booking_date', function (Booking $booking) {
|
||||
return $booking->getBookingDateFormat();
|
||||
})
|
||||
|
||||
->addColumn('lead.status_id', function (Booking $booking) {
|
||||
if($booking->lead && $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>';
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('old_crm', 'old_crm $1')
|
||||
->orderColumn('start_date', 'start_date $1')
|
||||
->orderColumn('end_date', 'end_date $1')
|
||||
->orderColumn('price', 'price $1')
|
||||
->orderColumn('booking_date', 'booking_date $1')
|
||||
->orderColumn('customer.firstname', 'customer.firstname $1')
|
||||
->orderColumn('customer.name', 'customer.name $1')
|
||||
//->orderColumn('lead.status_id', 'lead.status_id $1')
|
||||
//->orderColumn('is_cleared', 'is_cleared $1')
|
||||
->rawColumns(['id', 'old_crm', 'check_total', 'lead.status_id'])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
205
app/Http/Controllers/Admin/ReportFewoController.php
Normal file
205
app/Http/Controllers/Admin/ReportFewoController.php
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use Request;
|
||||
use Response;
|
||||
|
||||
use HTMLHelper;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Status;
|
||||
use App\Services\Util;
|
||||
use App\Models\Booking;
|
||||
use App\Models\FewoLodging;
|
||||
use App\Models\TravelAgenda;
|
||||
use App\Models\TravelCompany;
|
||||
use App\Models\ServiceProvider;
|
||||
use Illuminate\Validation\Rules\In;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServiceProviderEntry;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Models\TravelUserBookingFewo;
|
||||
use App\Exports\ReportCollectionExport;
|
||||
|
||||
class ReportFewoController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware(['superadmin', '2fa']);
|
||||
}
|
||||
|
||||
public function fewo()
|
||||
{
|
||||
$data = [
|
||||
'filter_fewo_options' => FewoLodging::get()->pluck('name', 'id'),
|
||||
|
||||
];
|
||||
return view('admin.report.fewo', $data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//checkFewoDatatable
|
||||
|
||||
private function prozessFewoSearch()
|
||||
{
|
||||
|
||||
$query = TravelUserBookingFewo::with('travel_booking_fewo_channel')->with('fewo_lodging')
|
||||
->select('travel_user_booking_fewos.*')
|
||||
->where('deleted_at', '=', null);
|
||||
|
||||
if(Request::get('filter_option_fewo_id') != ""){
|
||||
$query->where('fewo_lodging_id', '=', Request::get('filter_option_fewo_id'));
|
||||
}
|
||||
|
||||
if(Request::get('filter_date_from') != ""){
|
||||
$date_from = Carbon::parse(Request::get('filter_date_from'))->format("Y-m-d");
|
||||
$query->where("from_date", '>=', $date_from);
|
||||
}
|
||||
if(Request::get('filter_date_to') != ""){
|
||||
$date_to = Carbon::parse(Request::get('filter_date_to'))->format("Y-m-d");
|
||||
$query->where("to_date", '<=', $date_to);
|
||||
}
|
||||
|
||||
if(Request::get('filter_booking_date_from') != ""){
|
||||
$booking_date_from = Carbon::parse(Request::get('filter_booking_date_from'))->format("Y-m-d");
|
||||
$query->where("booking_date", '>=', $booking_date_from);
|
||||
}
|
||||
if(Request::get('filter_booking_date_to') != ""){
|
||||
$booking_date_to = Carbon::parse(Request::get('filter_booking_date_to'))->format("Y-m-d");
|
||||
$query->where("booking_date", '<=', $booking_date_to);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function fewoDatatable()
|
||||
{
|
||||
$query = $this->prozessFewoSearch();
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->with('price_total_sum', function() use ($query) {
|
||||
if($query->count() > 2000){
|
||||
return 'max 2000 ';
|
||||
}
|
||||
$all = $query->get();
|
||||
$proceeds = 0;
|
||||
foreach ($all as $v){
|
||||
$proceeds += $v->getPriceTotalRaw();
|
||||
}
|
||||
return Util::_number_format($proceeds);
|
||||
})
|
||||
->addColumn('id', function (TravelUserBookingFewo $travel_user_booking_fewo) {
|
||||
return '<a data-order="'.$travel_user_booking_fewo->id.'" href="' . route('travel_user_booking_fewo_detail', [$travel_user_booking_fewo->id]) . '" class="">' . $travel_user_booking_fewo->id . '</a>';
|
||||
|
||||
// return '<a data-order="' . $travel_user_booking_fewo->id . '" href="' . route('booking_detail', [$travel_user_booking_fewo->id]) . '" data-id="' . $travel_user_booking_fewo->id . '">' . $travel_user_booking_fewo->id . '</a>';
|
||||
})
|
||||
->addColumn('travel_user', function (TravelUserBookingFewo $travel_user_booking_fewo) {
|
||||
return '<a href="' . route('travel_user_detail', [$travel_user_booking_fewo->travel_user_id]) . '">'.$travel_user_booking_fewo->travel_user->first_name.' '.$travel_user_booking_fewo->travel_user->last_name.'</a>';
|
||||
})
|
||||
|
||||
/* ->addColumn('start_date', function (TravelUserBookingFewo $travel_user_booking_fewo) {
|
||||
return $travel_user_booking_fewo->getStartDateFormat();
|
||||
})
|
||||
->addColumn('end_date', function (TravelUserBookingFewo $travel_user_booking_fewo) {
|
||||
return $travel_user_booking_fewo->getEndDateFormat();
|
||||
})
|
||||
/* ->addColumn('booking_date', function (TravelUserBookingFewo $travel_user_booking_fewo) {
|
||||
return $travel_user_booking_fewo->getBookingDateFormat();
|
||||
})
|
||||
*/
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('from_date', 'from_date $1')
|
||||
->orderColumn('to_date', 'to_date $1')
|
||||
->orderColumn('price_total', 'price_total $1')
|
||||
->orderColumn('booking_date', 'booking_date $1')
|
||||
->orderColumn('invoice_number', 'invoice_number $1')
|
||||
|
||||
|
||||
//->orderColumn('lead.status_id', 'lead.status_id $1')
|
||||
//->orderColumn('is_cleared', 'is_cleared $1')
|
||||
->rawColumns(['id', 'travel_user'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function fewoExport(){
|
||||
|
||||
$query = $this->prozessFewoSearch();
|
||||
$order = explode(",", Request::get('order'));
|
||||
$orderByNum = [
|
||||
0 => 'id',
|
||||
1 => 'fewo_lodging.name',
|
||||
2 => 'travel_user',
|
||||
3 => 'from_date',
|
||||
4 => 'to_date',
|
||||
5 => 'adults',
|
||||
6 => 'children',
|
||||
7 => 'persons',
|
||||
8 => 'price_total',
|
||||
9 => 'booking_date',
|
||||
10 => 'invoice_number',
|
||||
];
|
||||
if(isset($order[0])) {
|
||||
$column = isset($orderByNum[$order[0]]) ? $orderByNum[$order[0]] : "id";
|
||||
$direction = isset($order[1]) ? strtoupper($order[1]) : "ASC";
|
||||
$query->orderBy($column, $direction);
|
||||
}
|
||||
|
||||
$filename = "file-".date('Y-m-d-H-i-s');
|
||||
$exports = $query->get();
|
||||
$columns = [];
|
||||
|
||||
if(Request::get('export') === "export"){
|
||||
$filename = "Buchungen_Fewo_".date('Y-m-d-H-i-s');
|
||||
|
||||
$headers = array(
|
||||
'BuchungsID',
|
||||
'FeWo',
|
||||
'Kunde',
|
||||
'vom',
|
||||
'bis',
|
||||
'Erwachsene',
|
||||
'Kinder',
|
||||
'Gesamt',
|
||||
'Betrag',
|
||||
'Buchungsdatum',
|
||||
'R-Nr',
|
||||
);
|
||||
$total_price_total = 0;
|
||||
|
||||
foreach($exports as $export) {
|
||||
$total_price_total += $export->getPriceTotalRaw();
|
||||
$columns[] = array(
|
||||
'BuchungsID' => $export->id,
|
||||
'FeWo' => $export->fewo_lodging->name,
|
||||
'Kunde' => $export->travel_user_id ? $export->travel_user->first_name.' '.$export->travel_user->last_name : " ",
|
||||
'vom' => $export->from_date,
|
||||
'bis' => $export->to_date,
|
||||
'Erwachsene' => $export->adults,
|
||||
'Kinder' => $export->children,
|
||||
'Gesamt' => $export->persons,
|
||||
'Betrag' => $export->price_total,
|
||||
'Buchungsdatum' => $export->booking_date,
|
||||
'R-Nr' => $export->invoice_number,
|
||||
);
|
||||
}
|
||||
|
||||
$columns[] = array(
|
||||
|
||||
'BuchungsID' => "Total",
|
||||
'FeWo' => "",
|
||||
'Kunde' => "",
|
||||
'vom' => "",
|
||||
'bis' => "",
|
||||
'Erwachsene' => "",
|
||||
'Kinder' => "",
|
||||
'Gesamt' => Util::_number_format($total_price_total),
|
||||
'Betrag' => "",
|
||||
'Buchungsdatum' => "",
|
||||
'R-Nr' => "",
|
||||
);
|
||||
}
|
||||
return Excel::download(new ReportCollectionExport($columns, $headers), $filename.'.xls');
|
||||
}
|
||||
|
||||
}
|
||||
217
app/Http/Controllers/Admin/ReportLeadsController.php
Normal file
217
app/Http/Controllers/Admin/ReportLeadsController.php
Normal file
|
|
@ -0,0 +1,217 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use Request;
|
||||
use Response;
|
||||
|
||||
use HTMLHelper;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Lead;
|
||||
use App\Models\Status;
|
||||
use App\Services\Util;
|
||||
use App\Models\Booking;
|
||||
use App\Models\LeadMail;
|
||||
use App\Models\FewoLodging;
|
||||
use App\Models\TravelAgenda;
|
||||
use App\Models\TravelCompany;
|
||||
use App\Models\ServiceProvider;
|
||||
use Illuminate\Validation\Rules\In;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServiceProviderEntry;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Models\TravelUserBookingFewo;
|
||||
use App\Exports\ReportCollectionExport;
|
||||
|
||||
class ReportLeadsController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware(['superadmin', '2fa']);
|
||||
}
|
||||
|
||||
public function leads()
|
||||
{
|
||||
// $query = Lead::with('customer')->with('sf_guard_user')->with('status')->select('lead.*');
|
||||
|
||||
$data = [
|
||||
'filter_leads_options' => [], //need ??? FewoLodging::get()->pluck('name', 'id'),
|
||||
|
||||
];
|
||||
return view('admin.report.leads', $data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//checkLeadsDatatable
|
||||
|
||||
private function prozessLeadsSearch()
|
||||
{
|
||||
|
||||
$query = Lead::with('customer')->with('sf_guard_user')->with('status')
|
||||
->select('lead.*');
|
||||
//->where('deleted_at', '=', null);
|
||||
|
||||
/*
|
||||
if(Request::get('filter_option_leads_id') != ""){
|
||||
$query->where('...?', '=', Request::get('filter_option_leads_id'));
|
||||
}
|
||||
*/
|
||||
if(Request::get('filter_date_from') != ""){
|
||||
$date_from = Carbon::parse(Request::get('filter_date_from'))->format("Y-m-d");
|
||||
$query->where("request_date", '>=', $date_from);
|
||||
}
|
||||
if(Request::get('filter_date_to') != ""){
|
||||
$date_to = Carbon::parse(Request::get('filter_date_to'))->format("Y-m-d");
|
||||
$query->where("request_date", '<=', $date_to);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function leadsDatatable()
|
||||
{
|
||||
$query = $this->prozessLeadsSearch();
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('id', function (Lead $lead) {
|
||||
return '<a data-order="'.$lead->id.'" href="'.route('lead_detail', [$lead->id]).'" data-id="'.$lead->id.'">'.$lead->id.'</a>';
|
||||
})
|
||||
->addColumn('customer_id', function (Lead $lead) {
|
||||
return '<a data-order="'.$lead->customer_id.'" href="'.route('customer_detail', [$lead->customer_id]).'" data-id="'.$lead->customer_id.'">'.$lead->customer_id.'</a>';
|
||||
})
|
||||
->addColumn('request_date', function (Lead $lead) {
|
||||
return Carbon::parse($lead->request_date)->format(\Util::formatDateDB());
|
||||
})
|
||||
->addColumn('travel_country', function (Lead $lead) {
|
||||
return $lead->getTravelCountryDestco();
|
||||
})
|
||||
|
||||
->addColumn('status', function (Lead $lead) {
|
||||
return $lead->getStatusBadge();
|
||||
})
|
||||
->addColumn('lead_notice', function (Lead $lead) {
|
||||
return $lead->lead_notices->count() ? '<span data-order="1" class="badge badge-pill badge-success" data-lead_id="'.$lead->id.'" data-action="get_popover_lead_notice" data-placement="top" data-toggle="popover" title="letzte Notiz"><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('last_lead_email', function (Lead $lead) {
|
||||
|
||||
if($lead->lead_mails->count()){
|
||||
$lead_mail = $lead->lead_mails_sent_at->last();
|
||||
$badge = $lead_mail->is_answer ? 'badge-default' : 'badge-secondary';
|
||||
$badge = !$lead_mail->send ? $badge : 'badge-success';
|
||||
return '<a data-order="'.$lead_mail->getSentAtRaw().'" href="#" data-toggle="modal"
|
||||
data-target="#modals-load-content"
|
||||
data-id="show-mail"
|
||||
data-url="mail"
|
||||
data-preview="true"
|
||||
data-lead_id="'.$lead->id.'"
|
||||
data-lead_mail_id="'.$lead_mail->id.'"
|
||||
data-action="show-lead-mail"
|
||||
data-redirect="back"
|
||||
data-route="'.route('lead_mail_modal_load').'">
|
||||
<span class="badge '.$badge.'">'
|
||||
.($lead_mail->send ? '<i class="fa fa-check-circle"></i>' : '<i class="fa fa-times-circle"></i>').' '
|
||||
.$lead_mail->sent_at.'</span>
|
||||
</a>';
|
||||
}
|
||||
return '<span data-order="">-</span>';
|
||||
})
|
||||
->addColumn('action_delete', function (Lead $lead) {
|
||||
return '<a href="' . route('lead_delete', [$lead->id, 'lead']) . '" class="btn icon-btn btn-sm btn-danger" onclick="return confirm(\''.__('Really delete entry?').'\');"><span class="fa fa-trash"></span></a>';
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('customer_id', 'customer_id $1')
|
||||
->orderColumn('request_date', 'request_date $1')
|
||||
->orderColumn('status', 'status_id $1')
|
||||
|
||||
->orderColumn('last_lead_email', function ($query, $order) {
|
||||
|
||||
$query->whereHas('lead_mails',
|
||||
function ($q) use ($order) {
|
||||
// $q->select('sent_at')->where('sent_at', DB::raw("(select max('sent_at') customer_mails)")); //)
|
||||
})->orderBy(
|
||||
LeadMail::select('sent_at')
|
||||
->whereColumn('lead_id', 'lead.id')
|
||||
->orderBy('sent_at', 'DESC')
|
||||
->limit(1)
|
||||
, $order);
|
||||
})
|
||||
|
||||
->filterColumn('id', function($query, $keyword) {
|
||||
if($keyword != ""){
|
||||
$query->where('id', 'LIKE', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
->filterColumn('customer_id', function($query, $keyword) {
|
||||
if($keyword != ""){
|
||||
$query->where('customer_id', 'LIKE', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
->rawColumns(['action_edit', 'customer_id', 'sf_guard_user_id', 'id', 'status', 'last_lead_email', 'travel_country', 'lead_notice', 'action_delete'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function leadsExport(){
|
||||
|
||||
$query = $this->prozessLeadsSearch();
|
||||
$order = explode(",", Request::get('order'));
|
||||
|
||||
|
||||
$orderByNum = [
|
||||
0 => 'id',
|
||||
1 => 'customer_id',
|
||||
2 => 'customer.firstname',
|
||||
3 => 'customer.name',
|
||||
4 => 'customer.email',
|
||||
5 => 'request_date',
|
||||
6 => 'travel_country',
|
||||
7 => 'sf_guard_user.last_name',
|
||||
8 => 'status',
|
||||
9 => 'last_lead_email',
|
||||
];
|
||||
if(isset($order[0])) {
|
||||
$column = isset($orderByNum[$order[0]]) ? $orderByNum[$order[0]] : "id";
|
||||
$direction = isset($order[1]) ? strtoupper($order[1]) : "ASC";
|
||||
$query->orderBy($column, $direction);
|
||||
}
|
||||
|
||||
$filename = "file-".date('Y-m-d-H-i-s');
|
||||
$exports = $query->get();
|
||||
$columns = [];
|
||||
|
||||
if(Request::get('export') === "export"){
|
||||
$filename = "Buchungen_Anfragen_".date('Y-m-d-H-i-s');
|
||||
|
||||
$headers = array(
|
||||
'LeadID',
|
||||
'KundenID',
|
||||
'Vorname',
|
||||
'Nachname',
|
||||
'E-Mail',
|
||||
'Anfrage-Datum',
|
||||
'Reiseland',
|
||||
'Sachbearbeiter',
|
||||
'Status',
|
||||
'Letzte E-Mail',
|
||||
);
|
||||
|
||||
foreach($exports as $export) {
|
||||
$columns[] = array(
|
||||
'LeadID' => $export->id,
|
||||
'KundenID' => $export->customer_id,
|
||||
'Vorname' => $export->customer ? $export->customer->firstname : " ",
|
||||
'Nachname' => $export->customer ? $export->customer->name : " ",
|
||||
'E-Mail' => $export->customer ? $export->customer->email : " ",
|
||||
'Anfrage-Datum' => _format_date($export->request_date),
|
||||
'Reiseland' => $export->getTravelCountryDestco(false),
|
||||
'Sachbearbeiter' => $export->sf_guard_user->last_name,
|
||||
'Status' => $export->status->name,
|
||||
'Letzte E-Mail' => $export->lead_mails->count() ? $export->lead_mails_sent_at->last()->sent_at : " ",
|
||||
);
|
||||
}
|
||||
}
|
||||
return Excel::download(new ReportCollectionExport($columns, $headers), $filename.'.xls');
|
||||
}
|
||||
|
||||
}
|
||||
388
app/Http/Controllers/Admin/ReportProviderController.php
Normal file
388
app/Http/Controllers/Admin/ReportProviderController.php
Normal file
|
|
@ -0,0 +1,388 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use Request;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Status;
|
||||
use App\Services\Util;
|
||||
use App\Models\TravelCompany;
|
||||
use App\Models\ServiceProvider;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServiceProviderEntry;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Exports\ReportCollectionExport;
|
||||
|
||||
class ReportProviderController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware(['superadmin', '2fa']);
|
||||
}
|
||||
|
||||
public function providers()
|
||||
{
|
||||
$data = [
|
||||
'serviceProviders' => ServiceProvider::all(),
|
||||
'filter_lead_status' => Status::get()->pluck('name', 'id')->toArray(),
|
||||
'filter_travel_companies' => TravelCompany::where('active', true)->get()->pluck('name', 'id')->toArray(),
|
||||
|
||||
];
|
||||
return view('admin.report.service_providers', $data);
|
||||
}
|
||||
|
||||
private function prozessProvidersSearch(){
|
||||
|
||||
$query = ServiceProviderEntry::with('booking', 'service_provider', 'booking.customer', 'booking.lead')->select('service_provider_entry.*')
|
||||
->join('booking', 'service_provider_entry.booking_id', '=', 'booking.id' );
|
||||
|
||||
if(Request::get('filter_db_lead_status_id') != ""){
|
||||
$query->whereHas('booking', function ($qe) {
|
||||
$qe->whereHas('lead', function ($q) {
|
||||
$q->whereIn('status_id', Request::get('filter_db_lead_status_id'));
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
if(Request::get('filter_lead_status_id') != ""){
|
||||
$query->whereHas('booking', function ($qe) {
|
||||
$qe->whereHas('lead', function ($q) {
|
||||
$q->whereIn('status_id', Request::get('filter_lead_status_id'));
|
||||
});
|
||||
});
|
||||
}
|
||||
if(Request::get('filter_travel_company_id') != ""){
|
||||
$query->whereHas('booking', function ($q) {
|
||||
$q->whereIn("travel_company_id", Request::get('filter_travel_company_id'));
|
||||
});
|
||||
}
|
||||
if(Request::get('filter_is_cleared') != ""){
|
||||
$query->where('is_cleared', '=', Request::get('filter_is_cleared'));
|
||||
}
|
||||
if(Request::get('filter_service_provider_id') != ""){
|
||||
$query->where('service_provider_id', '=', Request::get('filter_service_provider_id'));
|
||||
}
|
||||
if(Request::get('filter_travel_date_from') != ""){
|
||||
$query->whereHas('booking', function ($q) {
|
||||
$travel_date_from = Carbon::parse(Request::get('filter_travel_date_from'))->format("Y-m-d");
|
||||
$q->where("start_date", '>=', $travel_date_from);
|
||||
});
|
||||
}
|
||||
if(Request::get('filter_travel_date_to') != ""){
|
||||
$query->whereHas('booking', function ($q) {
|
||||
$travel_date_to = Carbon::parse(Request::get('filter_travel_date_to'))->format("Y-m-d");
|
||||
$q->where("start_date", '<=', $travel_date_to);
|
||||
});
|
||||
}
|
||||
|
||||
if(Request::get('filter_booking_date_from') != ""){
|
||||
$query->whereHas('booking', function ($q) {
|
||||
$filter_booking_date_from = Carbon::parse(Request::get('filter_booking_date_from'))->format("Y-m-d");
|
||||
$q->where("booking_date", '>=', $filter_booking_date_from);
|
||||
});
|
||||
}
|
||||
if(Request::get('filter_booking_date_to') != ""){
|
||||
$query->whereHas('booking', function ($q) {
|
||||
$filter_booking_date_to = Carbon::parse(Request::get('filter_booking_date_to'))->format("Y-m-d");
|
||||
$q->where("booking_date", '<=', $filter_booking_date_to);
|
||||
});
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function providersDatatable()
|
||||
{
|
||||
$query = $this->prozessProvidersSearch();
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->with('price_total_sum', function() use ($query) {
|
||||
if($query->count() > 200){
|
||||
return 'max 200 ';
|
||||
}
|
||||
$all = $query->get();
|
||||
$price = 0;
|
||||
$isset = [];
|
||||
foreach ($all as $v){
|
||||
if(!in_array($v->booking->lead_id, $isset)){
|
||||
$price += $v->booking->isCanceled() ? $v->booking->getPriceCanceledRaw() : $v->booking->getPriceRaw();
|
||||
}
|
||||
$isset[] = $v->booking->lead_id;
|
||||
|
||||
}
|
||||
return Util::_number_format($price);
|
||||
})
|
||||
->with('price_total_total_sum', function() use ($query) {
|
||||
if($query->count() > 200){
|
||||
return 'max 200 ';
|
||||
}
|
||||
$all = $query->get();
|
||||
$price = 0;
|
||||
$isset = [];
|
||||
foreach ($all as $v){
|
||||
$price += in_array($v->booking->lead_id, $isset) ? 0 : $v->booking->getPriceTotalRaw();
|
||||
$isset[] = $v->booking->lead_id;
|
||||
}
|
||||
return Util::_number_format($price);
|
||||
})
|
||||
->with('proceed_total_sum', function() use ($query) {
|
||||
if($query->count() > 200){
|
||||
return 'max 200 ';
|
||||
}
|
||||
$all = $query->get();
|
||||
$proceeds = 0;
|
||||
$isset = [];
|
||||
foreach ($all as $v){
|
||||
$proceeds += in_array($v->booking->lead_id, $isset) ? 0 : $v->booking->proceeds(true);
|
||||
$isset[] = $v->booking->lead_id;
|
||||
}
|
||||
return Util::_number_format($proceeds);
|
||||
/*$all = $query->get();
|
||||
$proceeds = 0;
|
||||
foreach ($all as $v){
|
||||
$proceeds += $v->proceeds(true);
|
||||
}
|
||||
return Util::_number_format($proceeds);*/
|
||||
})
|
||||
->addColumn('booking.id', function (ServiceProviderEntry $serviceProviderEntry) {
|
||||
return '<a data-order="' . $serviceProviderEntry->booking->id . '" href="' . route('booking_detail', [$serviceProviderEntry->booking->id]) . '" data-id="' . $serviceProviderEntry->booking->id . '">' . $serviceProviderEntry->booking->id . '</a>';
|
||||
})
|
||||
->addColumn('booking.customer.fullName', function (ServiceProviderEntry $serviceProviderEntry) {
|
||||
return $serviceProviderEntry->booking->customer->fullName();
|
||||
})
|
||||
->addColumn('booking.price', function (ServiceProviderEntry $serviceProviderEntry) {
|
||||
return $serviceProviderEntry->booking->booking_strono ? $serviceProviderEntry->booking->price_canceled : $serviceProviderEntry->booking->price;
|
||||
})
|
||||
->addColumn('booking.proceeds', function (ServiceProviderEntry $serviceProviderEntry) {
|
||||
return $serviceProviderEntry->booking->proceeds();
|
||||
})
|
||||
->addColumn('booking.start_date', function (ServiceProviderEntry $serviceProviderEntry) {
|
||||
return $serviceProviderEntry->booking->getStartDateFormat();
|
||||
})
|
||||
->addColumn('booking.end_date', function (ServiceProviderEntry $serviceProviderEntry) {
|
||||
return $serviceProviderEntry->booking->getEndDateFormat();
|
||||
})
|
||||
->addColumn('booking.booking_date', function (ServiceProviderEntry $serviceProviderEntry) {
|
||||
return $serviceProviderEntry->booking->getBookingDateFormat();
|
||||
})
|
||||
->addColumn('is_cleared', function (ServiceProviderEntry $serviceProviderEntry) {
|
||||
return $serviceProviderEntry->is_cleared ? ' <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('booking.lead.status_id', function (ServiceProviderEntry $serviceProviderEntry) {
|
||||
if($serviceProviderEntry->booking->lead && $serviceProviderEntry->booking->lead->status_id){
|
||||
$color = $serviceProviderEntry->booking->lead->status->color;
|
||||
$icon = "";
|
||||
if($serviceProviderEntry->booking->lead->status_id == 14 && $serviceProviderEntry->booking->lead->is_rebook){
|
||||
$color = '#94ae59';
|
||||
$icon = '<i class="fa fa-check-circle"></i> ';
|
||||
}
|
||||
if($serviceProviderEntry->booking->lead->status_id == 14 && !$serviceProviderEntry->booking->lead->is_rebook){
|
||||
$icon = '<i class="fa fa-times-circle"></i> ';
|
||||
}
|
||||
return '<span data-order="'.$serviceProviderEntry->booking->lead->status_id.'"><span class="badge badge-dark" style="background-color: '.$color.'">'.$icon.$serviceProviderEntry->booking->lead->status->name.'</span></span>';
|
||||
}
|
||||
return '<span data-order="0">-</span>';
|
||||
})
|
||||
->filterColumn('booking.customer.fullName', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereHas('booking', function ($q) use ($keyword) {
|
||||
$q->whereHas('customer', function ($q) use ($keyword) {
|
||||
$q->where("name", 'LIKE', '%' . $keyword . '%')
|
||||
->orWhere('firstname', 'LIKE', '%' . $keyword . '%');
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
->orderColumn('booking.id', 'booking.id $1')
|
||||
->orderColumn('booking.price', 'booking.price $1')
|
||||
->orderColumn('booking.start_date', 'booking.start_date $1')
|
||||
->orderColumn('booking.end_date', 'booking.end_date $1')
|
||||
->orderColumn('booking.booking_date', 'booking.booking_date $1')
|
||||
->orderColumn('booking.customer.firstname', 'booking.customer.firstname $1')
|
||||
->orderColumn('booking.customer.name', 'booking.customer.name $1')
|
||||
->orderColumn('is_cleared', 'is_cleared $1')
|
||||
->rawColumns(['is_cleared', 'booking.id', 'booking.lead.status_id'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function providersExport()
|
||||
{
|
||||
$query = $this->prozessProvidersSearch();
|
||||
|
||||
$order = explode(",", Request::get('order'));
|
||||
$orderByNum = [
|
||||
0 => "id",
|
||||
1 => "booking.id", //booking
|
||||
4 => "booking.merlin_order_number",//booking
|
||||
5 => "booking.price",//booking
|
||||
6 => "booking.price_total",//booking
|
||||
9 => "booking.start_date",//booking
|
||||
10 => "booking.end_date",//booking
|
||||
11 => "booking.booking_date",//booking
|
||||
12 => "is_cleared",
|
||||
];
|
||||
|
||||
if(isset($order[0])){
|
||||
$column = isset($orderByNum[$order[0]]) ? $orderByNum[$order[0]] : "start_date";
|
||||
$direction = isset($order[1]) ? strtoupper($order[1]) : "ASC";
|
||||
$query->orderBy($column, $direction);;
|
||||
}
|
||||
|
||||
$filename = "file-".date('Y-m-d-H-i-s');
|
||||
$exports = $query->get();
|
||||
$ctemps = [];
|
||||
$columns = [];
|
||||
|
||||
if(Request::get('export') === "export"){
|
||||
$filename = "Export_".date('Y-m-d-H-i-s');
|
||||
|
||||
$headers = array(
|
||||
'Zähler',
|
||||
'MyJack Nr.',
|
||||
'CRM Nr',
|
||||
'Kunde',
|
||||
'Reisedatum',
|
||||
'bis',
|
||||
'Buchungsdatum',
|
||||
'Organisation',
|
||||
'Gesamtreisepreis',
|
||||
'Reiseland',
|
||||
'Reiseprogramm',
|
||||
'Reiseteilnehmer',
|
||||
'Leistungsträger',
|
||||
'Rechnungsnummer',
|
||||
'Zahlung',
|
||||
'Zahlungsdatum',
|
||||
'Erlös',
|
||||
'Konto',
|
||||
);
|
||||
$isset = [];
|
||||
$total_price = 0;
|
||||
$total_price_total = 0;
|
||||
$total_amount_final = 0;
|
||||
$total_proceeds = 0;
|
||||
foreach($exports as $export) {
|
||||
$new = in_array($export->booking->id, $isset) ? false : true;
|
||||
if($new){
|
||||
$total_price += $export->booking->isCanceled() ? $export->booking->getPriceCanceledRaw() : $export->booking->getPriceRaw();
|
||||
$total_price_total += $export->booking->getPriceTotalRaw();
|
||||
$total_proceeds += $export->booking->proceeds(true);
|
||||
}
|
||||
$total_amount_final += $export->getAmountFinalEurRaw();
|
||||
$ctemps[$export->booking->id][] = array(
|
||||
'Zähler' => $new ? $export->getCounter() : "",
|
||||
'MyJack Nr.' => $new ? $export->booking->merlin_order_number : "",
|
||||
'CRM Nr' => $new ? $export->booking->lead_id : "",
|
||||
'Kunde' => $new ? $export->booking->customer->name : "",
|
||||
'Reisedatum' => $new ? $export->booking->getStartDateFormat() : "",
|
||||
'bis' => $new ? $export->booking->getEndDateFormat() : "",
|
||||
'Buchungsdatum' => $export->booking->getBookingDateFormat(),
|
||||
'Organisation' => $new ? ($export->booking->isCanceled() ? $export->booking->price_canceled : $export->booking->price) : "",
|
||||
'Gesamtreisepreis' => $new ? $export->booking->price_total : "",
|
||||
'Reiseland' => $new && $export->booking->travel_country ? $export->booking->travel_country->name : "",
|
||||
'Reiseprogramm' => $new && $export->booking->travel_agenda ? $export->booking->travel_agenda->name : "",
|
||||
'Reiseteilnehmer' => $new ? $export->booking->pax : "",
|
||||
'Leistungsträger' => $export->service_provider->name,
|
||||
'Rechnungsnummer' => $export->invoice_number,
|
||||
'Zahlung' => $export->getAmountFinalEur(),
|
||||
'Zahlungsdatum' => $export->getPaymentDateFormat(),
|
||||
'Erlös' => $new ? $export->booking->proceeds() : "",
|
||||
'Konto' => $export->booking->getKontoNumber()
|
||||
);
|
||||
$isset[] = $export->booking->id;
|
||||
}
|
||||
foreach($ctemps as $bid => $value){
|
||||
$columns = array_merge($columns, $value);
|
||||
}
|
||||
$columns[] = array(
|
||||
'Zähler' => "Total",
|
||||
'MyJack Nr.' => "",
|
||||
'CRM Nr' => "",
|
||||
'Kunde' =>"",
|
||||
'Reisedatum' => "",
|
||||
'bis' => "",
|
||||
'Buchungsdatum' => "",
|
||||
'Organisation' => Util::_number_format($total_price),
|
||||
'Gesamtreisepreis' => Util::_number_format($total_price_total),
|
||||
'Reiseland' => "",
|
||||
'Reiseprogramm' => "",
|
||||
'Reiseteilnehmer' => "",
|
||||
'Leistungsträger' => "",
|
||||
'Rechnungsnummer' => "",
|
||||
'Zahlung' => Util::_number_format($total_amount_final),
|
||||
'Zahlungsdatum' => "",
|
||||
'Erlös' => Util::_number_format($total_proceeds),
|
||||
'Konto' => ""
|
||||
);
|
||||
}
|
||||
if(Request::get('export') === "export_lt"){
|
||||
$filename = "Export_LT_".date('Y-m-d-H-i-s');
|
||||
|
||||
$headers = array(
|
||||
'Zähler',
|
||||
'MyJack Nr.',
|
||||
'CRM Nr',
|
||||
'Kunde',
|
||||
'Reisedatum',
|
||||
'bis',
|
||||
'Buchungsdatum',
|
||||
'Reiseland',
|
||||
'Reiseprogramm',
|
||||
'Reiseteilnehmer',
|
||||
'Leistungsträger',
|
||||
'Rechnungsnummer',
|
||||
'Zahlung',
|
||||
'ZahlungVorgang',
|
||||
);
|
||||
$isset = [];
|
||||
$total_amount_final = 0;
|
||||
$payments_total = 0;
|
||||
foreach($exports as $export) {
|
||||
$new = in_array($export->booking->id, $isset) ? false : true;
|
||||
if($new) {
|
||||
$payments_total += $export->booking->getServiceProviderPaymentsTotal(true);
|
||||
}
|
||||
$total_amount_final += $export->getAmountFinalEurRaw();
|
||||
$ctemps[$export->booking->id][] = array(
|
||||
'Zähler' => $new ? $export->getCounter() : "",
|
||||
'MyJack Nr.' => $new ? $export->booking->merlin_order_number : "",
|
||||
'CRM Nr' => $new ? $export->booking->lead_id : "",
|
||||
'Kunde' => $new ? $export->booking->customer->name : "",
|
||||
'Reisedatum' => $new ? $export->booking->getStartDateFormat() : "",
|
||||
'bis' => $new ? $export->booking->getEndDateFormat() : "",
|
||||
'Buchungsdatum' => $new ? $export->booking->getBookingDateFormat() : "",
|
||||
'Reiseland' => $new && $export->booking->travel_country ? $export->booking->travel_country->name : "",
|
||||
'Reiseprogramm' => $new && $export->booking->travel_agenda ? $export->booking->travel_agenda->name : "",
|
||||
'Reiseteilnehmer' => $new ? $export->booking->pax : "",
|
||||
'Leistungsträger' => $export->service_provider->name,
|
||||
'Rechnungsnummer' => $export->invoice_number,
|
||||
'Zahlung' => $export->getAmountFinalEur(),
|
||||
'ZahlungVorgang' => $export->booking->getServiceProviderPaymentsTotal(),
|
||||
);
|
||||
$isset[] = $export->booking->id;
|
||||
}
|
||||
foreach($ctemps as $bid => $value){
|
||||
$columns = array_merge($columns, $value);
|
||||
}
|
||||
$columns[] = array(
|
||||
'Zähler' => "Total",
|
||||
'MyJack Nr.' => "",
|
||||
'CRM Nr' => "",
|
||||
'Kunde' => "",
|
||||
'Reisedatum' => "",
|
||||
'bis',
|
||||
'Buchungsdatum' => "",
|
||||
'Reiseland' => "",
|
||||
'Reiseprogramm' => "",
|
||||
'Reiseteilnehmer' => "",
|
||||
'Leistungsträger' => "",
|
||||
'Rechnungsnummer' => "",
|
||||
'Zahlung' => Util::_number_format($total_amount_final),
|
||||
'ZahlungVorgang' => Util::_number_format($payments_total),
|
||||
);
|
||||
}
|
||||
return Excel::download(new ReportCollectionExport($columns, $headers), $filename.'.xls');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue