mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
added function to export company details to excel
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use App\Models\Company;
|
||||
use Carbon\Carbon;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
|
||||
class ExportsCustomers implements FromQuery, WithHeadingRow, WithMapping
|
||||
{
|
||||
|
||||
use Exportable;
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Marking',
|
||||
'Name',
|
||||
'Number of bookings',
|
||||
'Bookings total',
|
||||
'Registration Date',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
return Company::where('business_type', '=', 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Company $company
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function map($company): array
|
||||
{
|
||||
return [
|
||||
$company->reference,
|
||||
$company->name,
|
||||
count($company->bookings),
|
||||
$company->bookings()->sum('fix_amount'),
|
||||
Carbon::parse($company->created_at)->format('d-m-Y')
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Exports;
|
||||
|
||||
|
||||
use App\Classes\Modules\Exports\Services\ExportsCustomers;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Maatwebsite\Excel\Excel;
|
||||
|
||||
class ExportCustomersToExcelController
|
||||
{
|
||||
|
||||
public function export(ExportsCustomers $exportsCustomers, Request $request){
|
||||
$token = Auth::fromUser(User::find(1));
|
||||
$request->headers->set('Authorization', 'Bearer '.$token);
|
||||
return $exportsCustomers->download('customers.csv', Excel::CSV, ['Content-Type' => 'text/csv']);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
"intervention/image": "^2.5",
|
||||
"laravel/framework": "^7.0",
|
||||
"laravel/tinker": "^2.0",
|
||||
"maatwebsite/excel": "^3.1",
|
||||
"rinvex/countries": "^6.1",
|
||||
"spatie/laravel-activitylog": "^3.14",
|
||||
"spatie/laravel-permission": "^3.17",
|
||||
|
||||
@@ -68,3 +68,5 @@ Route::get('/transfer/merge/{marking}', function ($marking) {
|
||||
Route::get('/mail', function () {
|
||||
echo route('login');
|
||||
});
|
||||
|
||||
Route::get('/export/customers/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@export');
|
||||
|
||||
Reference in New Issue
Block a user