add more exports

shift-build-2464
Nadim Salloum 2021-06-16 18:14:41 +03:00
parent 3d446c601d
commit 5785cdf1c5
16 changed files with 1270 additions and 181 deletions

View File

@ -3,8 +3,6 @@
namespace App\Exports;
use App\Models\Contract;
use App\Enums\ContractType;
use PhpOffice\PhpSpreadsheet\Shared\Date;
class BuyContractsSheet extends ContractsSheet
{

View File

@ -1,51 +0,0 @@
<?php
namespace App\Exports;
use App\Models\Car;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\FromCollection;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class CarsExport implements FromCollection, WithHeadings, WithStyles
{
protected $car;
protected $headings;
public function __construct($car, $headings)
{
$this->car = $car;
$this->headings = $headings;
}
public function headings(): array
{
return $this->headings;
}
// public function map($car): array
// {
// $contract = $car->latestBuyContract();
// return [
// $car->name,
// $car->stammnummer,
// $car->initial_date_formatted,
// $contract ? $contract->date_formatted : null,
// $contract ? $contract->price : null,
// ];
// }
public function collection()
{
return $this->car;
}
public function styles(Worksheet $sheet)
{
return [
1 => ['font' => ['bold' => true]],
];
}
}

View File

@ -2,7 +2,6 @@
namespace App\Exports;
use App\Models\Contract;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
class ContractsExport implements WithMultipleSheets

View File

@ -5,7 +5,6 @@ namespace App\Exports;
use App\Models\Contract;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithTitle;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\WithMapping;

37
app/Exports/Export.php Normal file
View File

@ -0,0 +1,37 @@
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\FromCollection;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class Export implements FromCollection, WithHeadings, WithStyles
{
protected $model;
protected $headings;
public function __construct($model, $headings)
{
$this->model = $model;
$this->headings = $headings;
}
public function headings(): array
{
return $this->headings;
}
public function collection()
{
return $this->model;
}
public function styles(Worksheet $sheet)
{
return [
1 => ['font' => ['bold' => true]],
];
}
}

View File

@ -3,9 +3,7 @@
namespace App\Exports;
use App\Models\Contract;
use App\Enums\ContractType;
use Maatwebsite\Excel\Events\AfterSheet;
use PhpOffice\PhpSpreadsheet\Shared\Date;
class SellContractsSheet extends ContractsSheet
{

View File

@ -1,32 +0,0 @@
<?php
namespace App\Exports;
use App\Exports\CarsExport;
class UnsoldCarsExport extends CarsExport
{
public function headings(): array
{
return [
'Name',
'Stammnummer',
'Inverkehrssetzung',
'Einkaufsdatum',
'Einkaufspreis',
];
}
public function map($car): array
{
$contract = $car->latestBuyContract();
return [
$car->name,
$car->stammnummer,
$car->initial_date_formatted,
$contract ? $contract->date_formatted : null,
$contract ? $contract->price : null,
];
}
}

View File

@ -6,12 +6,10 @@ use Carbon\Carbon;
use App\Models\Car;
use Inertia\Inertia;
use App\Models\Brand;
use App\Exports\Export;
use App\Models\Contract;
use App\Enums\ContractType;
use App\Exports\CarsExport;
use App\Enums\InsuranceType;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Facades\Excel;
use Illuminate\Support\Facades\Redirect;
@ -37,10 +35,20 @@ class CarController extends Controller
public function print(Request $request)
{
$headings = [
'Name',
'Marke',
'Modell',
'Stammnummer',
'Chassisnummer',
'Farbe',
'Inverkehrssetzung',
'Letzte Überprüfung',
'Kilometerstand',
'Bemerkungen',
'Bekannter Schaden',
'Verkäufer',
'Einkaufsdatum',
'Einkaufspreis',
'Käufer',
'Verkaufsdatum',
'Verkaufspreis',
'Profit',
@ -55,25 +63,43 @@ class CarController extends Controller
$bcontract = $car->latestBuyContract();
$scontract = $car->latestSellContract();
return [
'name' => $car->name,
'brand' => $car->brand->name,
'model' => $car->carModel->name,
'stammnummer' => $car->stammnummer,
'vin' => $car->vin,
'colour' => $car->colour,
'initial_date' => $car->initial_date_formatted,
'last_check_date' => $car->last_check_date_formatted,
'kilometers' => $car->kilometers_formatted,
'notes' => $car->notes,
'known_damage' => $car->known_damage,
'seller' => $bcontract ? $bcontract->contact->full_title : null,
'buy_date' => $bcontract ? $bcontract->date_formatted : null,
'buy_price' => $bcontract ? $bcontract->price : null,
'price' => $bcontract ? $bcontract->price : null,
'buyer' => $scontract ? $scontract->contact->full_title : null,
'sell_date' => $scontract ? $scontract->date_formatted : null,
'sell_price' => $scontract ? $scontract->price : null,
'profit' => $car->latestProfit(),
];
});
return Excel::download(new CarsExport($cars, $headings), date('Y-m-d') . '-Alle-Autos.xlsx');
return Excel::download(new Export($cars, $headings), date('Y-m-d') . '-Alle-Autos.xlsx');
}
public function unsoldPrint(Request $request)
{
$headings = [
'Name',
'Marke',
'Modell',
'Stammnummer',
'Chassisnummer',
'Farbe',
'Inverkehrssetzung',
'Letzte Überprüfung',
'Kilometerstand',
'Bemerkungen',
'Bekannter Schaden',
'Verkäufer',
'Einkaufsdatum',
'Einkaufspreis',
];
@ -86,24 +112,42 @@ class CarController extends Controller
->map(function ($car) {
$contract = $car->latestBuyContract();
return [
'name' => $car->name,
'brand' => $car->brand->name,
'model' => $car->carModel->name,
'stammnummer' => $car->stammnummer,
'vin' => $car->vin,
'colour' => $car->colour,
'initial_date' => $car->initial_date_formatted,
'last_check_date' => $car->last_check_date_formatted,
'kilometers' => $car->kilometers_formatted,
'notes' => $car->notes,
'known_damage' => $car->known_damage,
'seller' => $contract ? $contract->contact->full_title : null,
'buy_date' => $contract ? $contract->date_formatted : null,
'price' => $contract ? $contract->price : null,
];
});
return Excel::download(new CarsExport($cars, $headings), date('Y-m-d') . '-Meine-Autos.xlsx');
return Excel::download(new Export($cars, $headings), date('Y-m-d') . '-Meine-Autos.xlsx');
}
public function soldPrint(Request $request)
{
$headings = [
'Name',
'Marke',
'Modell',
'Stammnummer',
'Chassisnummer',
'Farbe',
'Inverkehrssetzung',
'Letzte Überprüfung',
'Kilometerstand',
'Bemerkungen',
'Bekannter Schaden',
'Verkäufer',
'Einkaufsdatum',
'Einkaufspreis',
'Käufer',
'Verkaufsdatum',
'Verkaufspreis',
'Profit',
@ -118,17 +162,27 @@ class CarController extends Controller
$bcontract = $car->latestBuyContract();
$scontract = $car->latestSellContract();
return [
'name' => $car->name,
'brand' => $car->brand->name,
'model' => $car->carModel->name,
'stammnummer' => $car->stammnummer,
'vin' => $car->vin,
'colour' => $car->colour,
'initial_date' => $car->initial_date_formatted,
'last_check_date' => $car->last_check_date_formatted,
'kilometers' => $car->kilometers_formatted,
'notes' => $car->notes,
'known_damage' => $car->known_damage,
'seller' => $bcontract ? $bcontract->contact->full_title : null,
'buy_date' => $bcontract ? $bcontract->date_formatted : null,
'buy_price' => $bcontract ? $bcontract->price : null,
'price' => $bcontract ? $bcontract->price : null,
'buyer' => $scontract ? $scontract->contact->full_title : null,
'sell_date' => $scontract ? $scontract->date_formatted : null,
'sell_price' => $scontract ? $scontract->price : null,
'profit' => $car->latestProfit(),
];
});
return Excel::download(new CarsExport($cars, $headings), date('Y-m-d') . '-Verkaufte-Autos.xlsx');
return Excel::download(new Export($cars, $headings), date('Y-m-d') . '-Verkaufte-Autos.xlsx');
}
private function renderCarsList(Request $request, $cars, string $renderPage, string $defaultSort = 'buy_contract.date') {

View File

@ -4,11 +4,13 @@ namespace App\Http\Controllers;
use App\Models\Car;
use Inertia\Inertia;
use App\Exports\Export;
use App\Models\Contact;
use App\Models\Contract;
use App\Enums\InsuranceType;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Maatwebsite\Excel\Facades\Excel;
use Illuminate\Support\Facades\Redirect;
class ContactController extends Controller
@ -56,6 +58,59 @@ class ContactController extends Controller
]);
}
public function print(Request $request)
{
return $this->printList($request, Contact::query(), date('Y-m-d') . '-Alle-Kontakte.xlsx');
}
public function buyersPrint(Request $request)
{
return $this->printList($request, Contact::has('buyContracts'), date('Y-m-d') . '-Verkäufer.xlsx');
}
public function sellersPrint(Request $request)
{
return $this->printList($request, Contact::has('sellContracts'), date('Y-m-d') . '-Käufer.xlsx');
}
private function printList(Request $request, $contacts, $title)
{
$headings = [
'Nachname',
'Vorname',
'Firma',
'Adresse',
'PLZ',
'Ort',
'Land',
'Email',
'Telefon',
'Bemerkungen',
];
$direction = $this->getDirection($request);
$sortBy = $this->getSortBy($request);
$contacts = $this->getWithCustomSort($contacts, $sortBy, $direction)
->filter($request->only('search', 'trashed'))
->get()
->map(function ($contact) {
return [
'lastname' => $contact->lastname,
'firstname' => $contact->firstname,
'company' => $contact->company,
'address' => $contact->address,
'zip' => $contact->zip,
'city' => $contact->city,
'country' => $contact->country,
'email' => $contact->email,
'phone' => $contact->phone,
'notes' => $contact->notes,
];
});
return Excel::download(new Export($contacts, $headings), $title);
}
private function getWithCustomSort($contacts, string $sortBy, string $direction)
{
switch($sortBy) {

View File

@ -28,7 +28,7 @@ class ContractFactory extends Factory
return [
'date' => $this->faker->date(),
'delivery_date' => $this->faker->date(),
'notes' => $this->faker->paragraph(),
'notes' => $this->faker->word(),
'price' => $this->faker->numberBetween(150000, 3500000),
'contact_id' => $this->faker->numberBetween(1, Contact::count()),
'car_id' => $this->faker->numberBetween(1, Car::count()),

File diff suppressed because it is too large Load Diff

9
public/js/app.js vendored
View File

@ -28495,7 +28495,8 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
columns: $data.columns,
defaultSort: $props.sort,
filters: $props.filters,
currentRoute: $data.currentRoute
currentRoute: $data.currentRoute,
print: true
}, null, 8
/* PROPS */
, ["title", "data", "columns", "defaultSort", "filters", "currentRoute"])])];
@ -29043,7 +29044,8 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
columns: $data.columns,
defaultSort: $props.sort,
filters: $props.filters,
currentRoute: $data.currentRoute
currentRoute: $data.currentRoute,
print: true
}, null, 8
/* PROPS */
, ["title", "data", "columns", "defaultSort", "filters", "currentRoute"])])];
@ -29101,7 +29103,8 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
columns: $data.columns,
defaultSort: $props.sort,
filters: $props.filters,
currentRoute: $data.currentRoute
currentRoute: $data.currentRoute,
print: true
}, null, 8
/* PROPS */
, ["title", "data", "columns", "defaultSort", "filters", "currentRoute"])])];

View File

@ -7,7 +7,7 @@
</h2>
</template>
<div class="w-full mx-auto">
<simple-table :title="contacts.total + ' Käufer'" :data="contacts" :columns="columns" :defaultSort="sort" :filters="filters" :currentRoute="currentRoute" />
<simple-table :title="contacts.total + ' Käufer'" :data="contacts" :columns="columns" :defaultSort="sort" :filters="filters" :currentRoute="currentRoute" :print="true" />
</div>
</layout>
</template>

View File

@ -7,7 +7,7 @@
</h2>
</template>
<div class="w-full mx-auto">
<simple-table :title="contacts.total + ' ' + (contacts.total === 1 ? 'Kontakt' : 'Kontakte')" :data="contacts" :columns="columns" :defaultSort="sort" :filters="filters" :currentRoute="currentRoute" />
<simple-table :title="contacts.total + ' ' + (contacts.total === 1 ? 'Kontakt' : 'Kontakte')" :data="contacts" :columns="columns" :defaultSort="sort" :filters="filters" :currentRoute="currentRoute" :print="true" />
</div>
</layout>
</template>

View File

@ -7,7 +7,7 @@
</h2>
</template>
<div class="w-full mx-auto">
<simple-table :title="contacts.total + ' Verkäufer'" :data="contacts" :columns="columns" :defaultSort="sort" :filters="filters" :currentRoute="currentRoute" />
<simple-table :title="contacts.total + ' Verkäufer'" :data="contacts" :columns="columns" :defaultSort="sort" :filters="filters" :currentRoute="currentRoute" :print="true" />
</div>
</layout>
</template>

View File

@ -19,8 +19,11 @@ Route::middleware(['auth:sanctum', 'verified'])->group(function () {
Route::prefix('contacts')->group(function () {
Route::get('/', [ContactController::class, 'index'])->name('contacts');
Route::get('/print', [ContactController::class, 'print'])->name('contacts.print');
Route::get('buyers', [ContactController::class, 'buyers'])->name('contacts.buyers');
Route::get('buyers/print', [ContactController::class, 'buyersPrint'])->name('contacts.buyers.print');
Route::get('sellers', [ContactController::class, 'sellers'])->name('contacts.sellers');
Route::get('sellers/print', [ContactController::class, 'sellersPrint'])->name('contacts.sellers.print');
Route::get('create', [ContactController::class, 'create'])->name('contacts.create');
Route::post('/', [ContactController::class, 'store'])->name('contacts.store');
Route::post('store_for_contract', [ContactController::class, 'storeForContract'])->name('contacts.store_for_contract');