08 2024
This commit is contained in:
parent
c1c613a4b9
commit
881fc84207
384 changed files with 50679 additions and 990 deletions
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');
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue