01 2020
This commit is contained in:
parent
bed91c4f4a
commit
c8948338bb
122 changed files with 7911 additions and 1639 deletions
216
app/Http/Controllers/Admin/ReportController.php
Executable file
216
app/Http/Controllers/Admin/ReportController.php
Executable file
|
|
@ -0,0 +1,216 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Exports\ReportCollectionExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Models\Booking;
|
||||
use App\Models\ServiceProvider;
|
||||
use App\Models\ServiceProviderEntry;
|
||||
use App\Models\TravelAgenda;
|
||||
use App\Services\Util;
|
||||
use Carbon\Carbon;
|
||||
use HTMLHelper;
|
||||
use Illuminate\Validation\Rules\In;
|
||||
use Input;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Request;
|
||||
use Response;
|
||||
|
||||
class ReportController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('superadmin');
|
||||
}
|
||||
|
||||
|
||||
public function bookings()
|
||||
{
|
||||
$data = [
|
||||
'text' => "Umsetzung folgt",
|
||||
];
|
||||
return view('_empty', $data);
|
||||
}
|
||||
|
||||
public function providers()
|
||||
{
|
||||
$data = [
|
||||
'serviceProviders' => ServiceProvider::all(),
|
||||
];
|
||||
return view('admin.report.index', $data);
|
||||
}
|
||||
|
||||
public function providersExport(){
|
||||
|
||||
$query = ServiceProviderEntry::with('booking', 'service_provider', 'booking.customer');
|
||||
if(Input::get('filter_is_cleared') != ""){
|
||||
$query->where('is_cleared', '=', Input::get('filter_is_cleared'));
|
||||
}
|
||||
if(Input::get('filter_service_provider_id') != ""){
|
||||
$query->where('service_provider_id', '=', Input::get('filter_service_provider_id'));
|
||||
}
|
||||
if(Input::get('filter_travel_date_from') != ""){
|
||||
$query->whereHas('booking', function ($q) {
|
||||
$travel_date_from = Carbon::parse(Input::get('filter_travel_date_from'))->format("Y-m-d");
|
||||
$q->where("start_date", '>=', $travel_date_from);
|
||||
});
|
||||
}
|
||||
if(Input::get('filter_travel_date_to') != ""){
|
||||
$query->whereHas('booking', function ($q) {
|
||||
$travel_date_to = Carbon::parse(Input::get('filter_travel_date_to'))->format("Y-m-d");
|
||||
$q->where("start_date", '<=', $travel_date_to);
|
||||
});
|
||||
}
|
||||
|
||||
$query->whereHas('booking', function ($q) {
|
||||
$q->orderBy("lead_id", 'ASC');
|
||||
});
|
||||
|
||||
$filename = "file-".date('Y-m-d-H-i-s');
|
||||
$exports = $query->get();
|
||||
$columns = [];
|
||||
if(Input::get('export') === "export"){
|
||||
$filename = "Export_".date('Y-m-d-H-i-s');
|
||||
|
||||
$headers = array(
|
||||
'Zähler',
|
||||
'MyJack Nr.',
|
||||
'CRM Nr',
|
||||
'Kunde',
|
||||
'Reisedatum',
|
||||
'Gesamtreisepreis',
|
||||
'Reiseland',
|
||||
'Reiseprogramm',
|
||||
'Reiseteilnehmer',
|
||||
'Leistungsträger',
|
||||
'Rechnungsnummer',
|
||||
'Zahlung',
|
||||
'Zahlungsdatum',
|
||||
'Erlös',
|
||||
'Konto',
|
||||
);
|
||||
$isset = [];
|
||||
foreach($exports as $export) {
|
||||
$new = in_array($export->booking->lead_id, $isset) ? false : true;
|
||||
$columns[] = 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() : "",
|
||||
'Gesamtreisepreis' => $new ? $export->booking->price : "",
|
||||
'Reiseland' => $new ? $export->booking->travel_country->name : "",
|
||||
'Reiseprogramm' => $new ? $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->lead_id;
|
||||
}
|
||||
}
|
||||
if(Input::get('export') === "export_lt"){
|
||||
$filename = "Export_LT_".date('Y-m-d-H-i-s');
|
||||
|
||||
$headers = array(
|
||||
'Zähler',
|
||||
'MyJack Nr.',
|
||||
'CRM Nr',
|
||||
'Kunde',
|
||||
'Reisedatum',
|
||||
'Reiseland',
|
||||
'Reiseprogramm',
|
||||
'Reiseteilnehmer',
|
||||
'Leistungsträger',
|
||||
'Rechnungsnummer',
|
||||
'Zahlung',
|
||||
'ZahlungVorgang',
|
||||
);
|
||||
$isset = [];
|
||||
foreach($exports as $export) {
|
||||
$new = in_array($export->booking->lead_id, $isset) ? false : true;
|
||||
$columns[] = 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() : "",
|
||||
'Reiseland' => $new ? $export->booking->travel_country->name : "",
|
||||
'Reiseprogramm' => $new ? $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->lead_id;
|
||||
}
|
||||
}
|
||||
return Excel::download(new ReportCollectionExport($columns, $headers), $filename.'.xls');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function providersDatatable()
|
||||
{
|
||||
|
||||
$query = ServiceProviderEntry::with('booking', 'service_provider', 'booking.customer');
|
||||
|
||||
if(Input::get('filter_is_cleared') != ""){
|
||||
$query->where('is_cleared', '=', Input::get('filter_is_cleared'));
|
||||
}
|
||||
if(Input::get('filter_service_provider_id') != ""){
|
||||
$query->where('service_provider_id', '=', Input::get('filter_service_provider_id'));
|
||||
}
|
||||
if(Input::get('filter_travel_date_from') != ""){
|
||||
$query->whereHas('booking', function ($q) {
|
||||
$travel_date_from = Carbon::parse(Input::get('filter_travel_date_from'))->format("Y-m-d");
|
||||
$q->where("start_date", '>=', $travel_date_from);
|
||||
});
|
||||
}
|
||||
if(Input::get('filter_travel_date_to') != ""){
|
||||
$query->whereHas('booking', function ($q) {
|
||||
$travel_date_to = Carbon::parse(Input::get('filter_travel_date_to'))->format("Y-m-d");
|
||||
$q->where("start_date", '<=', $travel_date_to);
|
||||
});
|
||||
}
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('booking.customer.fullName', function (ServiceProviderEntry $serviceProviderEntry) {
|
||||
return $serviceProviderEntry->booking->customer->fullName();
|
||||
})
|
||||
->addColumn('booking.proceeds', function (ServiceProviderEntry $serviceProviderEntry) {
|
||||
return $serviceProviderEntry->booking->proceeds();
|
||||
})
|
||||
->addColumn('booking.start_date', function (ServiceProviderEntry $serviceProviderEntry) {
|
||||
return $serviceProviderEntry->booking->getStartDateFormat();
|
||||
})
|
||||
->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>';
|
||||
})
|
||||
->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.start_date', 'booking.start_date $1')
|
||||
->orderColumn('is_cleared', 'is_cleared $1')
|
||||
->rawColumns(['is_cleared'])
|
||||
->make(true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue