commit
4890b393a9
|
|
@ -14,5 +14,6 @@ use BenSampo\Enum\Enum;
|
||||||
final class ContractType extends Enum
|
final class ContractType extends Enum
|
||||||
{
|
{
|
||||||
const BuyContract = '0';
|
const BuyContract = '0';
|
||||||
|
|
||||||
const SellContract = '1';
|
const SellContract = '1';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,14 @@ use BenSampo\Enum\Enum;
|
||||||
final class InsuranceType extends Enum
|
final class InsuranceType extends Enum
|
||||||
{
|
{
|
||||||
const Keine = '0';
|
const Keine = '0';
|
||||||
|
|
||||||
const QBase = '1';
|
const QBase = '1';
|
||||||
|
|
||||||
const OneStar = '2';
|
const OneStar = '2';
|
||||||
|
|
||||||
const ThreeStar = '3';
|
const ThreeStar = '3';
|
||||||
|
|
||||||
const FiveStar = '4';
|
const FiveStar = '4';
|
||||||
|
|
||||||
const FiveStarPlus = '5';
|
const FiveStarPlus = '5';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ use BenSampo\Enum\Enum;
|
||||||
final class PaymentType extends Enum
|
final class PaymentType extends Enum
|
||||||
{
|
{
|
||||||
const Transaction = '0';
|
const Transaction = '0';
|
||||||
|
|
||||||
const Cash = '1';
|
const Cash = '1';
|
||||||
|
|
||||||
const Cembra = '2';
|
const Cembra = '2';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,15 @@
|
||||||
|
|
||||||
namespace App\Exports;
|
namespace App\Exports;
|
||||||
|
|
||||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
|
||||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
||||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||||
|
|
||||||
class Export implements FromCollection, WithHeadings, WithStyles
|
class Export implements FromCollection, WithHeadings, WithStyles
|
||||||
{
|
{
|
||||||
protected $model;
|
protected $model;
|
||||||
|
|
||||||
protected $headings;
|
protected $headings;
|
||||||
|
|
||||||
public function __construct($model, $headings)
|
public function __construct($model, $headings)
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,21 @@
|
||||||
|
|
||||||
namespace App\Exports;
|
namespace App\Exports;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use App\Models\Car;
|
use App\Models\Car;
|
||||||
use App\Models\Contract;
|
use App\Models\Contract;
|
||||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
use Carbon\Carbon;
|
||||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
|
||||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
|
||||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
|
||||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
|
||||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
||||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||||
|
|
||||||
class Report implements FromCollection ,WithTitle, WithHeadings, WithStyles, WithColumnFormatting, ShouldAutoSize
|
class Report implements FromCollection, WithTitle, WithHeadings, WithStyles, WithColumnFormatting, ShouldAutoSize
|
||||||
{
|
{
|
||||||
protected $year;
|
protected $year;
|
||||||
|
|
||||||
|
|
@ -46,7 +46,7 @@ class Report implements FromCollection ,WithTitle, WithHeadings, WithStyles, Wit
|
||||||
$cars = $cars->merge(Car::unsoldOnly()->get())->unique()->map(function ($car) {
|
$cars = $cars->merge(Car::unsoldOnly()->get())->unique()->map(function ($car) {
|
||||||
$bcontract = $car->latestBuyContract();
|
$bcontract = $car->latestBuyContract();
|
||||||
$scontract = $car->latestSellContract();
|
$scontract = $car->latestSellContract();
|
||||||
if (!$car->isSold()) {
|
if (! $car->isSold()) {
|
||||||
$scontract = null;
|
$scontract = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,9 +57,9 @@ class Report implements FromCollection ,WithTitle, WithHeadings, WithStyles, Wit
|
||||||
'buy_price' => $bcontract ? $bcontract->price_for_excel : null,
|
'buy_price' => $bcontract ? $bcontract->price_for_excel : null,
|
||||||
'seller' => $bcontract ? $bcontract->contact->full_title_with_address : null,
|
'seller' => $bcontract ? $bcontract->contact->full_title_with_address : null,
|
||||||
'sell_date' => $scontract ? Date::dateTimeToExcel(Carbon::parse($scontract->date)) : null,
|
'sell_date' => $scontract ? Date::dateTimeToExcel(Carbon::parse($scontract->date)) : null,
|
||||||
'sell_price' => $scontract ? $scontract->price_for_excel : null,
|
'sell_price' => $scontract ? $scontract->price_for_excel : null,
|
||||||
'buyer' => $scontract ? $scontract->contact->full_title_with_address : null,
|
'buyer' => $scontract ? $scontract->contact->full_title_with_address : null,
|
||||||
'lager' => !$scontract && $bcontract ? $bcontract->price_for_excel : null,
|
'lager' => ! $scontract && $bcontract ? $bcontract->price_for_excel : null,
|
||||||
];
|
];
|
||||||
})->sortBy('buy_date');
|
})->sortBy('buy_date');
|
||||||
|
|
||||||
|
|
@ -86,6 +86,6 @@ class Report implements FromCollection ,WithTitle, WithHeadings, WithStyles, Wit
|
||||||
|
|
||||||
public function title(): string
|
public function title(): string
|
||||||
{
|
{
|
||||||
return 'Wagenhandelbuch ' . $this->year;
|
return 'Wagenhandelbuch '.$this->year;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,16 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use App\Models\Car;
|
|
||||||
use Inertia\Inertia;
|
|
||||||
use App\Models\Brand;
|
|
||||||
use App\Exports\Export;
|
use App\Exports\Export;
|
||||||
|
use App\Models\Brand;
|
||||||
|
use App\Models\Car;
|
||||||
use App\Models\Contract;
|
use App\Models\Contract;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
|
||||||
use Illuminate\Support\Facades\Redirect;
|
use Illuminate\Support\Facades\Redirect;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
|
||||||
class CarController extends Controller
|
class CarController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -27,7 +27,6 @@ class CarController extends Controller
|
||||||
|
|
||||||
public function sold(Request $request)
|
public function sold(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
return $this->renderCarsList($request, Car::soldOnly(), 'Cars/Sold', 'sell_contract.date');
|
return $this->renderCarsList($request, Car::soldOnly(), 'Cars/Sold', 'sell_contract.date');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,6 +59,7 @@ class CarController extends Controller
|
||||||
->map(function ($car) {
|
->map(function ($car) {
|
||||||
$bcontract = $car->latestBuyContract();
|
$bcontract = $car->latestBuyContract();
|
||||||
$scontract = $car->latestSellContract();
|
$scontract = $car->latestSellContract();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'brand' => $car->brand->name,
|
'brand' => $car->brand->name,
|
||||||
'model' => $car->carModel->name,
|
'model' => $car->carModel->name,
|
||||||
|
|
@ -79,8 +79,8 @@ class CarController extends Controller
|
||||||
'sell_price' => $scontract ? $scontract->price : null,
|
'sell_price' => $scontract ? $scontract->price : null,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
return Excel::download(new Export($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)
|
public function unsoldPrint(Request $request)
|
||||||
|
|
@ -108,6 +108,7 @@ class CarController extends Controller
|
||||||
->get()
|
->get()
|
||||||
->map(function ($car) {
|
->map(function ($car) {
|
||||||
$contract = $car->latestBuyContract();
|
$contract = $car->latestBuyContract();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'brand' => $car->brand->name,
|
'brand' => $car->brand->name,
|
||||||
'model' => $car->carModel->name,
|
'model' => $car->carModel->name,
|
||||||
|
|
@ -124,8 +125,8 @@ class CarController extends Controller
|
||||||
'price' => $contract ? $contract->price : null,
|
'price' => $contract ? $contract->price : null,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
return Excel::download(new Export($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)
|
public function soldPrint(Request $request)
|
||||||
|
|
@ -157,6 +158,7 @@ class CarController extends Controller
|
||||||
->map(function ($car) {
|
->map(function ($car) {
|
||||||
$bcontract = $car->latestBuyContract();
|
$bcontract = $car->latestBuyContract();
|
||||||
$scontract = $car->latestSellContract();
|
$scontract = $car->latestSellContract();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'brand' => $car->brand->name,
|
'brand' => $car->brand->name,
|
||||||
'model' => $car->carModel->name,
|
'model' => $car->carModel->name,
|
||||||
|
|
@ -176,11 +178,12 @@ class CarController extends Controller
|
||||||
'sell_price' => $scontract ? $scontract->price : null,
|
'sell_price' => $scontract ? $scontract->price : null,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
return Excel::download(new Export($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') {
|
private function renderCarsList(Request $request, $cars, string $renderPage, string $defaultSort = 'buy_contract.date')
|
||||||
|
{
|
||||||
$direction = $this->getDirection($request, 'desc');
|
$direction = $this->getDirection($request, 'desc');
|
||||||
$sortBy = $this->getSortBy($request, $defaultSort);
|
$sortBy = $this->getSortBy($request, $defaultSort);
|
||||||
$cars = $this->getWithCustomSort($cars, $sortBy, $direction);
|
$cars = $this->getWithCustomSort($cars, $sortBy, $direction);
|
||||||
|
|
@ -208,11 +211,13 @@ class CarController extends Controller
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getContractFields(?Contract $contract) {
|
private function getContractFields(?Contract $contract)
|
||||||
if (!$contract) {
|
{
|
||||||
|
if (! $contract) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$contact = $contract->contact;
|
$contact = $contract->contact;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $contract->id,
|
'id' => $contract->id,
|
||||||
'date' => $contract->date_formatted,
|
'date' => $contract->date_formatted,
|
||||||
|
|
@ -224,48 +229,41 @@ class CarController extends Controller
|
||||||
|
|
||||||
private function getWithCustomSort($cars, string $sortBy, string $direction)
|
private function getWithCustomSort($cars, string $sortBy, string $direction)
|
||||||
{
|
{
|
||||||
switch($sortBy) {
|
return match ($sortBy) {
|
||||||
case 'name':
|
'name' => $cars
|
||||||
return $cars
|
->leftJoin('car_models', 'cars.car_model_id', '=', 'car_models.id')
|
||||||
->leftJoin('car_models', 'cars.car_model_id', '=', 'car_models.id')
|
->leftJoin('brands', 'car_models.brand_id', '=', 'brands.id')
|
||||||
->leftJoin('brands', 'car_models.brand_id', '=', 'brands.id')
|
->orderBy('brands.name', $direction)
|
||||||
->orderBy('brands.name', $direction)
|
->orderBy('car_models.name', $direction),
|
||||||
->orderBy('car_models.name', $direction);
|
'initial_date' => $cars->orderBy('initial_date', $direction),
|
||||||
case 'initial_date':
|
'stammnummer' => $cars->orderBy('stammnummer', $direction),
|
||||||
return $cars->orderBy('initial_date', $direction);
|
'buy_contract.date' => $cars
|
||||||
case 'stammnummer':
|
->leftJoin('contracts', function ($join) {
|
||||||
return $cars->orderBy('stammnummer', $direction);
|
$join->on('contracts.car_id', '=', 'cars.id')
|
||||||
case 'buy_contract.date':
|
->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '0' order by date desc limit 1)"));
|
||||||
return $cars
|
})
|
||||||
->leftJoin('contracts', function($join) {
|
->orderBy('contracts.date', $direction),
|
||||||
$join->on('contracts.car_id', '=', 'cars.id')
|
'buy_contract.price' => $cars
|
||||||
->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '0' order by date desc limit 1)"));
|
->leftJoin('contracts', function ($join) {
|
||||||
})
|
$join->on('contracts.car_id', '=', 'cars.id')
|
||||||
->orderBy('contracts.date', $direction);
|
->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '0' order by date desc limit 1)"));
|
||||||
case 'buy_contract.price':
|
})
|
||||||
return $cars
|
->orderBy('contracts.price', $direction),
|
||||||
->leftJoin('contracts', function($join) {
|
'sell_contract.date' => $cars
|
||||||
$join->on('contracts.car_id', '=', 'cars.id')
|
->leftJoin('contracts', function ($join) {
|
||||||
->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '0' order by date desc limit 1)"));
|
$join->on('contracts.car_id', '=', 'cars.id')
|
||||||
})
|
->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '1' order by date desc limit 1)"));
|
||||||
->orderBy('contracts.price', $direction);
|
})
|
||||||
case 'sell_contract.date':
|
->orderBy('contracts.date', $direction),
|
||||||
return $cars
|
'sell_contract.price' => $cars
|
||||||
->leftJoin('contracts', function($join) {
|
->leftJoin('contracts', function ($join) {
|
||||||
$join->on('contracts.car_id', '=', 'cars.id')
|
$join->on('contracts.car_id', '=', 'cars.id')
|
||||||
->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '1' order by date desc limit 1)"));
|
->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '1' order by date desc limit 1)"));
|
||||||
})
|
}
|
||||||
->orderBy('contracts.date', $direction);
|
)
|
||||||
case 'sell_contract.price':
|
->orderBy('contracts.price', $direction),
|
||||||
return $cars
|
default => $cars->orderBy('initial_date', $direction),
|
||||||
->leftJoin('contracts', function($join) {
|
};
|
||||||
$join->on('contracts.car_id', '=', 'cars.id')
|
|
||||||
->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '1' order by date desc limit 1)"));
|
|
||||||
})
|
|
||||||
->orderBy('contracts.price', $direction);
|
|
||||||
default:
|
|
||||||
return $cars->orderBy('initial_date', $direction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getSortBy(Request $request, $defaultSort)
|
private function getSortBy(Request $request, $defaultSort)
|
||||||
|
|
@ -304,8 +302,9 @@ class CarController extends Controller
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$car = $this->createCar($request);
|
$car = $this->createCar($request);
|
||||||
|
|
||||||
session()->flash('flash.banner', 'Auto erstellt.');
|
session()->flash('flash.banner', 'Auto erstellt.');
|
||||||
|
|
||||||
return Redirect::route('cars.show', $car);
|
return Redirect::route('cars.show', $car);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,7 +315,7 @@ class CarController extends Controller
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$request->validate($this->getValidationRules());
|
$request->validate($this->getValidationRules());
|
||||||
|
|
||||||
if ($request->get('initial_date')) {
|
if ($request->get('initial_date')) {
|
||||||
$request->merge(['initial_date' => Carbon::parse($request->get('initial_date'))->format('Y-m-d')]);
|
$request->merge(['initial_date' => Carbon::parse($request->get('initial_date'))->format('Y-m-d')]);
|
||||||
}
|
}
|
||||||
|
|
@ -337,7 +336,7 @@ class CarController extends Controller
|
||||||
'stammnummer' => $car->stammnummer,
|
'stammnummer' => $car->stammnummer,
|
||||||
'vin' => $car->vin,
|
'vin' => $car->vin,
|
||||||
'name' => $car->name,
|
'name' => $car->name,
|
||||||
'label' => $car->name . ' (' . $car->stammnummer . ')',
|
'label' => $car->name.' ('.$car->stammnummer.')',
|
||||||
'colour' => $car->colour,
|
'colour' => $car->colour,
|
||||||
'last_check_date' => $car->last_check_date_formatted,
|
'last_check_date' => $car->last_check_date_formatted,
|
||||||
'kilometers' => $car->kilometers,
|
'kilometers' => $car->kilometers,
|
||||||
|
|
@ -392,12 +391,16 @@ class CarController extends Controller
|
||||||
->orderBy('date', 'desc')
|
->orderBy('date', 'desc')
|
||||||
->with('contact')
|
->with('contact')
|
||||||
->get()
|
->get()
|
||||||
->map(function ($contract) { return $this->getContractFields($contract); }),
|
->map(function ($contract) {
|
||||||
|
return $this->getContractFields($contract);
|
||||||
|
}),
|
||||||
'sell_contracts' => $car->sellContracts()
|
'sell_contracts' => $car->sellContracts()
|
||||||
->orderBy('date', 'desc')
|
->orderBy('date', 'desc')
|
||||||
->with('contact')
|
->with('contact')
|
||||||
->get()
|
->get()
|
||||||
->map(function ($contract) { return $this->getContractFields($contract); }),
|
->map(function ($contract) {
|
||||||
|
return $this->getContractFields($contract);
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
@ -440,6 +443,7 @@ class CarController extends Controller
|
||||||
{
|
{
|
||||||
$this->updateCar($request, $car);
|
$this->updateCar($request, $car);
|
||||||
session()->flash('flash.banner', 'Auto geändert.');
|
session()->flash('flash.banner', 'Auto geändert.');
|
||||||
|
|
||||||
return Redirect::route('cars.show', $car);
|
return Redirect::route('cars.show', $car);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -450,8 +454,8 @@ class CarController extends Controller
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'stammnummer' => ['required', 'unique:cars,stammnummer,' . $car->id . ',id,deleted_at,NULL', 'string', 'size:11', 'regex:/[0-9]{3}[.][0-9]{3}[.][0-9]{3}/i'],
|
'stammnummer' => ['required', 'unique:cars,stammnummer,'.$car->id.',id,deleted_at,NULL', 'string', 'size:11', 'regex:/[0-9]{3}[.][0-9]{3}[.][0-9]{3}/i'],
|
||||||
'vin' => ['required', 'unique:cars,vin,' . $car->id . ',id,deleted_at,NULL', 'string', 'size:17'],
|
'vin' => ['required', 'unique:cars,vin,'.$car->id.',id,deleted_at,NULL', 'string', 'size:17'],
|
||||||
'initial_date' => ['required', 'date_format:"d.m.Y"'],
|
'initial_date' => ['required', 'date_format:"d.m.Y"'],
|
||||||
'last_check_date' => ['nullable', 'date_format:"d.m.Y"'],
|
'last_check_date' => ['nullable', 'date_format:"d.m.Y"'],
|
||||||
'colour' => ['nullable', 'max:75'],
|
'colour' => ['nullable', 'max:75'],
|
||||||
|
|
@ -476,6 +480,7 @@ class CarController extends Controller
|
||||||
{
|
{
|
||||||
$car->delete();
|
$car->delete();
|
||||||
session()->flash('flash.banner', 'Auto gelöscht.');
|
session()->flash('flash.banner', 'Auto gelöscht.');
|
||||||
|
|
||||||
return Redirect::route('cars.show', $car);
|
return Redirect::route('cars.show', $car);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -483,6 +488,7 @@ class CarController extends Controller
|
||||||
{
|
{
|
||||||
$car->restore();
|
$car->restore();
|
||||||
session()->flash('flash.banner', 'Auto wiederhergestellt.');
|
session()->flash('flash.banner', 'Auto wiederhergestellt.');
|
||||||
|
|
||||||
return Redirect::route('cars.show', $car);
|
return Redirect::route('cars.show', $car);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Inertia\Inertia;
|
|
||||||
use App\Exports\Export;
|
use App\Exports\Export;
|
||||||
use App\Models\Contact;
|
use App\Models\Contact;
|
||||||
use App\Models\Contract;
|
use App\Models\Contract;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
|
||||||
use Illuminate\Support\Facades\Redirect;
|
use Illuminate\Support\Facades\Redirect;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
|
||||||
class ContactController extends Controller
|
class ContactController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -27,7 +27,8 @@ class ContactController extends Controller
|
||||||
return $this->renderContactsList($request, Contact::has('sellContracts'), 'Contacts/Buyers');
|
return $this->renderContactsList($request, Contact::has('sellContracts'), 'Contacts/Buyers');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderContactsList(Request $request, $contacts, string $renderPage) {
|
private function renderContactsList(Request $request, $contacts, string $renderPage)
|
||||||
|
{
|
||||||
$direction = $this->getDirection($request);
|
$direction = $this->getDirection($request);
|
||||||
$sortBy = $this->getSortBy($request);
|
$sortBy = $this->getSortBy($request);
|
||||||
$contacts = $this->getWithCustomSort($contacts, $sortBy, $direction);
|
$contacts = $this->getWithCustomSort($contacts, $sortBy, $direction);
|
||||||
|
|
@ -56,9 +57,9 @@ class ContactController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
public function letter(Contact $contact)
|
public function letter(Contact $contact)
|
||||||
{
|
{
|
||||||
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor(resource_path() . '/docx/letter.docx');
|
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor(resource_path().'/docx/letter.docx');
|
||||||
$templateProcessor->setValue('date', date("d.m.Y"));
|
$templateProcessor->setValue('date', date('d.m.Y'));
|
||||||
$templateProcessor->setValue('company', $contact->company);
|
$templateProcessor->setValue('company', $contact->company);
|
||||||
$templateProcessor->setValue('name', $contact->name);
|
$templateProcessor->setValue('name', $contact->name);
|
||||||
$templateProcessor->setValue('address', $contact->address);
|
$templateProcessor->setValue('address', $contact->address);
|
||||||
|
|
@ -66,28 +67,28 @@ class ContactController extends Controller
|
||||||
$templateProcessor->setValue('country', $contact->country !== 'CH' ? $contact->country : '');
|
$templateProcessor->setValue('country', $contact->country !== 'CH' ? $contact->country : '');
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$templateProcessor->saveAs("php://output");
|
$templateProcessor->saveAs('php://output');
|
||||||
$contents = ob_get_contents();
|
$contents = ob_get_contents();
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
|
|
||||||
return response()->streamDownload(function () use ($contents) {
|
return response()->streamDownload(function () use ($contents) {
|
||||||
echo $contents;
|
echo $contents;
|
||||||
}, 'Briefvorlage ' . $contact->title . '.docx');
|
}, 'Briefvorlage '.$contact->title.'.docx');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function print(Request $request)
|
public function print(Request $request)
|
||||||
{
|
{
|
||||||
return $this->printList($request, Contact::query(), date('Y-m-d') . '-Alle-Kontakte.xlsx');
|
return $this->printList($request, Contact::query(), date('Y-m-d').'-Alle-Kontakte.xlsx');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buyersPrint(Request $request)
|
public function buyersPrint(Request $request)
|
||||||
{
|
{
|
||||||
return $this->printList($request, Contact::has('buyContracts'), date('Y-m-d') . '-Verkäufer.xlsx');
|
return $this->printList($request, Contact::has('buyContracts'), date('Y-m-d').'-Verkäufer.xlsx');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sellersPrint(Request $request)
|
public function sellersPrint(Request $request)
|
||||||
{
|
{
|
||||||
return $this->printList($request, Contact::has('sellContracts'), date('Y-m-d') . '-Käufer.xlsx');
|
return $this->printList($request, Contact::has('sellContracts'), date('Y-m-d').'-Käufer.xlsx');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function printList(Request $request, $contacts, $title)
|
private function printList(Request $request, $contacts, $title)
|
||||||
|
|
@ -130,18 +131,13 @@ class ContactController extends Controller
|
||||||
|
|
||||||
private function getWithCustomSort($contacts, string $sortBy, string $direction)
|
private function getWithCustomSort($contacts, string $sortBy, string $direction)
|
||||||
{
|
{
|
||||||
switch($sortBy) {
|
return match ($sortBy) {
|
||||||
case 'company':
|
'company' => $contacts->orderBy('company', $direction),
|
||||||
return $contacts->orderBy('company', $direction);
|
'fullCity' => $contacts->orderBy('city', $direction),
|
||||||
case 'fullCity':
|
'email' => $contacts->orderBy('email', $direction),
|
||||||
return $contacts->orderBy('city', $direction);
|
'address' => $contacts->orderBy('address', $direction),
|
||||||
case 'email':
|
default => $contacts->orderByName($direction),
|
||||||
return $contacts->orderBy('email', $direction);
|
};
|
||||||
case 'address':
|
|
||||||
return $contacts->orderBy('address', $direction);
|
|
||||||
default:
|
|
||||||
return $contacts->orderByName($direction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getSortBy(Request $request)
|
private function getSortBy(Request $request)
|
||||||
|
|
@ -165,6 +161,7 @@ class ContactController extends Controller
|
||||||
);
|
);
|
||||||
|
|
||||||
session()->flash('flash.banner', 'Kontakt erstellt.');
|
session()->flash('flash.banner', 'Kontakt erstellt.');
|
||||||
|
|
||||||
return Redirect::route('contacts.show', $contact);
|
return Redirect::route('contacts.show', $contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,7 +204,7 @@ class ContactController extends Controller
|
||||||
'city' => $contact->city,
|
'city' => $contact->city,
|
||||||
'country' => $contact->country,
|
'country' => $contact->country,
|
||||||
'deleted_at' => $contact->deleted_at,
|
'deleted_at' => $contact->deleted_at,
|
||||||
]
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -244,21 +241,27 @@ class ContactController extends Controller
|
||||||
->orderBy('date', 'desc')
|
->orderBy('date', 'desc')
|
||||||
->with('car')
|
->with('car')
|
||||||
->get()
|
->get()
|
||||||
->map(function ($contract) { return $this->getContractFields($contract); }),
|
->map(function ($contract) {
|
||||||
|
return $this->getContractFields($contract);
|
||||||
|
}),
|
||||||
'sell_contracts' => $contact->sellContracts()
|
'sell_contracts' => $contact->sellContracts()
|
||||||
->orderBy('date', 'desc')
|
->orderBy('date', 'desc')
|
||||||
->with('car')
|
->with('car')
|
||||||
->get()
|
->get()
|
||||||
->map(function ($contract) { return $this->getContractFields($contract); }),
|
->map(function ($contract) {
|
||||||
]
|
return $this->getContractFields($contract);
|
||||||
|
}),
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getContractFields(?Contract $contract) {
|
private function getContractFields(?Contract $contract)
|
||||||
if (!$contract) {
|
{
|
||||||
|
if (! $contract) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$car = $contract->car;
|
$car = $contract->car;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $contract->id,
|
'id' => $contract->id,
|
||||||
'date' => $contract->date_formatted,
|
'date' => $contract->date_formatted,
|
||||||
|
|
@ -275,6 +278,7 @@ class ContactController extends Controller
|
||||||
);
|
);
|
||||||
|
|
||||||
session()->flash('flash.banner', 'Kontakt geändert.');
|
session()->flash('flash.banner', 'Kontakt geändert.');
|
||||||
|
|
||||||
return Redirect::route('contacts.show', $contact);
|
return Redirect::route('contacts.show', $contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -298,6 +302,7 @@ class ContactController extends Controller
|
||||||
{
|
{
|
||||||
$contact->delete();
|
$contact->delete();
|
||||||
session()->flash('flash.banner', 'Kontakt gelöscht.');
|
session()->flash('flash.banner', 'Kontakt gelöscht.');
|
||||||
|
|
||||||
return Redirect::back();
|
return Redirect::back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -305,6 +310,7 @@ class ContactController extends Controller
|
||||||
{
|
{
|
||||||
$contact->restore();
|
$contact->restore();
|
||||||
session()->flash('flash.banner', 'Kontakt wiederhergestellt.');
|
session()->flash('flash.banner', 'Kontakt wiederhergestellt.');
|
||||||
|
|
||||||
return Redirect::back();
|
return Redirect::back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,23 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use App\Models\Car;
|
|
||||||
use Inertia\Inertia;
|
|
||||||
use App\Models\Brand;
|
|
||||||
use App\Models\Contact;
|
|
||||||
use App\Models\Payment;
|
|
||||||
use App\Models\Contract;
|
|
||||||
use App\Enums\PaymentType;
|
|
||||||
use App\Enums\ContractType;
|
use App\Enums\ContractType;
|
||||||
use App\Enums\InsuranceType;
|
use App\Enums\InsuranceType;
|
||||||
use Illuminate\Http\Request;
|
use App\Enums\PaymentType;
|
||||||
use Illuminate\Validation\Rule;
|
use App\Models\Brand;
|
||||||
|
use App\Models\Car;
|
||||||
|
use App\Models\Contact;
|
||||||
|
use App\Models\Contract;
|
||||||
|
use App\Models\Payment;
|
||||||
use Barryvdh\DomPDF\Facade as PDF;
|
use Barryvdh\DomPDF\Facade as PDF;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Redirect;
|
use Illuminate\Support\Facades\Redirect;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
|
||||||
class ContractController extends Controller
|
class ContractController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
public function dashboard()
|
public function dashboard()
|
||||||
{
|
{
|
||||||
return Inertia::render('Dashboard', [
|
return Inertia::render('Dashboard', [
|
||||||
|
|
@ -55,7 +54,7 @@ class ContractController extends Controller
|
||||||
|
|
||||||
public function create(Request $request)
|
public function create(Request $request)
|
||||||
{
|
{
|
||||||
$type = (string)($request->get('type') ?? '1');
|
$type = (string) ($request->get('type') ?? '1');
|
||||||
$car = Car::find($request->get('car'));
|
$car = Car::find($request->get('car'));
|
||||||
$contact = Contact::find($request->get('contact'));
|
$contact = Contact::find($request->get('contact'));
|
||||||
|
|
||||||
|
|
@ -80,8 +79,9 @@ class ContractController extends Controller
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCarFields(?Car $car) {
|
private function getCarFields(?Car $car)
|
||||||
if (!$car) {
|
{
|
||||||
|
if (! $car) {
|
||||||
return [
|
return [
|
||||||
'name' => null,
|
'name' => null,
|
||||||
'label' => null,
|
'label' => null,
|
||||||
|
|
@ -93,11 +93,12 @@ class ContractController extends Controller
|
||||||
'initial_date' => null,
|
'initial_date' => null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'name' => $car->name,
|
'name' => $car->name,
|
||||||
'label' => $car->name . ' (' . $car->stammnummer . ')',
|
'label' => $car->name.' ('.$car->stammnummer.')',
|
||||||
'id' => $car->id,
|
'id' => $car->id,
|
||||||
'stammnummer' => $car->stammnummer,
|
'stammnummer' => $car->stammnummer,
|
||||||
'vin' => $car->vin,
|
'vin' => $car->vin,
|
||||||
'name' => $car->name,
|
'name' => $car->name,
|
||||||
'colour' => $car->colour,
|
'colour' => $car->colour,
|
||||||
|
|
@ -105,8 +106,9 @@ class ContractController extends Controller
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getContactFields(?Contact $contact) {
|
private function getContactFields(?Contact $contact)
|
||||||
if (!$contact) {
|
{
|
||||||
|
if (! $contact) {
|
||||||
return [
|
return [
|
||||||
'id' => null,
|
'id' => null,
|
||||||
'title' => null,
|
'title' => null,
|
||||||
|
|
@ -122,6 +124,7 @@ class ContractController extends Controller
|
||||||
'email' => null,
|
'email' => null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $contact->id,
|
'id' => $contact->id,
|
||||||
'title' => $contact->full_title,
|
'title' => $contact->full_title,
|
||||||
|
|
@ -141,9 +144,9 @@ class ContractController extends Controller
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$request->merge([
|
$request->merge([
|
||||||
'type' => (string)$request->get('type'),
|
'type' => (string) $request->get('type'),
|
||||||
'payment_type' => (string)$request->get('payment_type'),
|
'payment_type' => (string) $request->get('payment_type'),
|
||||||
'insurance_type' => (string)$request->get('insurance_type'),
|
'insurance_type' => (string) $request->get('insurance_type'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
|
|
@ -165,7 +168,7 @@ class ContractController extends Controller
|
||||||
$contract = Contract::create($request->all());
|
$contract = Contract::create($request->all());
|
||||||
|
|
||||||
$request->merge([
|
$request->merge([
|
||||||
'type' => (string)$request->get('payment_type'),
|
'type' => (string) $request->get('payment_type'),
|
||||||
'contract_id' => $contract->id,
|
'contract_id' => $contract->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
@ -181,8 +184,8 @@ class ContractController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
session()->flash('flash.banner', 'Vertrag erstellt.');
|
session()->flash('flash.banner', 'Vertrag erstellt.');
|
||||||
return Redirect::route('contracts.show', $contract);
|
|
||||||
|
|
||||||
|
return Redirect::route('contracts.show', $contract);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit(Contract $contract)
|
public function edit(Contract $contract)
|
||||||
|
|
@ -197,8 +200,8 @@ class ContractController extends Controller
|
||||||
'type' => $contract->type,
|
'type' => $contract->type,
|
||||||
'type_formatted' => $contract->type_formatted,
|
'type_formatted' => $contract->type_formatted,
|
||||||
'notes' => $contract->notes,
|
'notes' => $contract->notes,
|
||||||
'price' => (int)$contract->price->getAmount(),
|
'price' => (int) $contract->price->getAmount(),
|
||||||
'insurance_type' => (string)$contract->insurance_type,
|
'insurance_type' => (string) $contract->insurance_type,
|
||||||
'car' => [
|
'car' => [
|
||||||
'id' => $contract->car->id,
|
'id' => $contract->car->id,
|
||||||
'name' => $contract->car->name,
|
'name' => $contract->car->name,
|
||||||
|
|
@ -211,7 +214,7 @@ class ContractController extends Controller
|
||||||
public function update(Request $request, Contract $contract)
|
public function update(Request $request, Contract $contract)
|
||||||
{
|
{
|
||||||
$request->merge([
|
$request->merge([
|
||||||
'insurance_type' => (string)$request->get('insurance_type'),
|
'insurance_type' => (string) $request->get('insurance_type'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
|
|
@ -230,73 +233,75 @@ class ContractController extends Controller
|
||||||
$contract->update($request->all());
|
$contract->update($request->all());
|
||||||
|
|
||||||
session()->flash('flash.banner', 'Vertrag geändert.');
|
session()->flash('flash.banner', 'Vertrag geändert.');
|
||||||
|
|
||||||
return Redirect::route('contracts.show', $contract);
|
return Redirect::route('contracts.show', $contract);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show(Contract $contract)
|
public function show(Contract $contract)
|
||||||
{
|
{
|
||||||
return Inertia::render('Contracts/Show', [
|
return Inertia::render('Contracts/Show', [
|
||||||
'contract' => [
|
'contract' => [
|
||||||
'id' => $contract->id,
|
'id' => $contract->id,
|
||||||
'date' => $contract->date_formatted,
|
'date' => $contract->date_formatted,
|
||||||
'delivery_date' => $contract->delivery_date_formatted,
|
'delivery_date' => $contract->delivery_date_formatted,
|
||||||
'price' => $contract->price->format(),
|
'price' => $contract->price->format(),
|
||||||
'type' => $contract->type,
|
'type' => $contract->type,
|
||||||
'type_formatted' => $contract->type_formatted,
|
'type_formatted' => $contract->type_formatted,
|
||||||
'notes' => $contract->notes,
|
'notes' => $contract->notes,
|
||||||
'paid' => $contract->paid->format(),
|
'paid' => $contract->paid->format(),
|
||||||
'left_to_pay' => $contract->left_to_pay->format(),
|
'left_to_pay' => $contract->left_to_pay->format(),
|
||||||
'left_to_pay_raw' => (int)$contract->left_to_pay->getAmount(),
|
'left_to_pay_raw' => (int) $contract->left_to_pay->getAmount(),
|
||||||
'is_sell_contract' => $contract->isSellContract(),
|
'is_sell_contract' => $contract->isSellContract(),
|
||||||
'documents' => $contract->documents()->orderBy('created_at', 'asc')->get()
|
'documents' => $contract->documents()->orderBy('created_at', 'asc')->get()
|
||||||
->map(function ($document) {
|
->map(function ($document) {
|
||||||
return [
|
return [
|
||||||
'id' => $document->id,
|
'id' => $document->id,
|
||||||
'name' => $document->name,
|
'name' => $document->name,
|
||||||
'size' => $document->size,
|
'size' => $document->size,
|
||||||
'extension' => $document->extension,
|
'extension' => $document->extension,
|
||||||
'link' => $document->link,
|
'link' => $document->link,
|
||||||
'created_at' => $document->created_at,
|
'created_at' => $document->created_at,
|
||||||
];
|
];
|
||||||
}),
|
}),
|
||||||
'payments' => $contract->payments()->orderBy('date', 'asc')->get()
|
'payments' => $contract->payments()->orderBy('date', 'asc')->get()
|
||||||
->map(function ($payment) {
|
->map(function ($payment) {
|
||||||
return [
|
return [
|
||||||
'id' => $payment->id,
|
'id' => $payment->id,
|
||||||
'date' => $payment->date,
|
'date' => $payment->date,
|
||||||
'amount' => $payment->amount->format(),
|
'amount' => $payment->amount->format(),
|
||||||
'type' => $payment->type,
|
'type' => $payment->type,
|
||||||
'print_link' => $payment->print_link,
|
'print_link' => $payment->print_link,
|
||||||
'delete_link' => $payment->delete_link,
|
'delete_link' => $payment->delete_link,
|
||||||
];
|
];
|
||||||
}),
|
}),
|
||||||
'insurance_type' => $contract->insurance_type ? InsuranceType::fromValue($contract->insurance_type)->key : null,
|
'insurance_type' => $contract->insurance_type ? InsuranceType::fromValue($contract->insurance_type)->key : null,
|
||||||
'deleted_at' => $contract->deleted_at,
|
'deleted_at' => $contract->deleted_at,
|
||||||
'contact' => $contract->contact->only(['id', 'full_title', 'link']),
|
'contact' => $contract->contact->only(['id', 'full_title', 'link']),
|
||||||
'car' => $contract->car->only(['id', 'name_with_year', 'link']),
|
'car' => $contract->car->only(['id', 'name_with_year', 'link']),
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function print(Contract $contract)
|
public function print(Contract $contract)
|
||||||
{
|
{
|
||||||
$contxt = stream_context_create([
|
$contxt = stream_context_create([
|
||||||
'ssl' => [
|
'ssl' => [
|
||||||
'verify_peer' => FALSE,
|
'verify_peer' => false,
|
||||||
'verify_peer_name' => FALSE,
|
'verify_peer_name' => false,
|
||||||
'allow_self_signed'=> TRUE
|
'allow_self_signed'=> true,
|
||||||
]
|
],
|
||||||
]);
|
]);
|
||||||
$pdf = PDF::setOptions(['isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true])->loadView('contract', compact('contract'));
|
$pdf = PDF::setOptions(['isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true])->loadView('contract', compact('contract'));
|
||||||
$pdf->getDomPDF()->setHttpContext($contxt);
|
$pdf->getDomPDF()->setHttpContext($contxt);
|
||||||
return $pdf->stream($contract->date . '_' . $contract->type_formatted . '.pdf');
|
|
||||||
|
return $pdf->stream($contract->date.'_'.$contract->type_formatted.'.pdf');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy(Contract $contract)
|
public function destroy(Contract $contract)
|
||||||
{
|
{
|
||||||
$contract->delete();
|
$contract->delete();
|
||||||
session()->flash('flash.banner', 'Vertrag gelöscht.');
|
session()->flash('flash.banner', 'Vertrag gelöscht.');
|
||||||
|
|
||||||
return Redirect::route('contracts.show', $contract);
|
return Redirect::route('contracts.show', $contract);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -304,6 +309,7 @@ class ContractController extends Controller
|
||||||
{
|
{
|
||||||
$contract->restore();
|
$contract->restore();
|
||||||
session()->flash('flash.banner', 'Vertrag wiederhergestellt.');
|
session()->flash('flash.banner', 'Vertrag wiederhergestellt.');
|
||||||
|
|
||||||
return Redirect::route('contracts.show', $contract);
|
return Redirect::route('contracts.show', $contract);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
|
||||||
use Illuminate\Routing\Controller as BaseController;
|
|
||||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
|
||||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||||
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||||
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Routing\Controller as BaseController;
|
||||||
|
|
||||||
class Controller extends BaseController
|
class Controller extends BaseController
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ class DocumentController extends Controller
|
||||||
public function show(Document $document)
|
public function show(Document $document)
|
||||||
{
|
{
|
||||||
if (file_exists($document->path)) {
|
if (file_exists($document->path)) {
|
||||||
header('Content-Disposition: filename="' . $document->name . '"');
|
header('Content-Disposition: filename="'.$document->name.'"');
|
||||||
|
|
||||||
return response()->file($document->path);
|
return response()->file($document->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,12 +23,12 @@ class DocumentController extends Controller
|
||||||
{
|
{
|
||||||
$class = $request->get('documentable_type');
|
$class = $request->get('documentable_type');
|
||||||
$id = $request->get('documentable_id');
|
$id = $request->get('documentable_id');
|
||||||
if (!in_array($class, ['contracts', 'cars', 'contacts'])) {
|
if (! in_array($class, ['contracts', 'cars', 'contacts'])) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = $request->file()['document'];
|
$file = $request->file()['document'];
|
||||||
$internalName = date('Y-m-d-H-i-s') . '.' . $file->extension();
|
$internalName = date('Y-m-d-H-i-s').'.'.$file->extension();
|
||||||
$document = Document::create([
|
$document = Document::create([
|
||||||
'name' => $file->getClientOriginalName(),
|
'name' => $file->getClientOriginalName(),
|
||||||
'internal_name' => $internalName,
|
'internal_name' => $internalName,
|
||||||
|
|
@ -50,10 +51,11 @@ class DocumentController extends Controller
|
||||||
|
|
||||||
public function destroy(Request $request)
|
public function destroy(Request $request)
|
||||||
{
|
{
|
||||||
$document = Document::find((int)$request->get('id'));
|
$document = Document::find((int) $request->get('id'));
|
||||||
|
|
||||||
if (!$document) {
|
if (! $document) {
|
||||||
session()->flash('flash.banner', 'Fehler beim Löschen, Dokument nicht gefunden.');
|
session()->flash('flash.banner', 'Fehler beim Löschen, Dokument nicht gefunden.');
|
||||||
|
|
||||||
return Redirect::back();
|
return Redirect::back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,6 +65,7 @@ class DocumentController extends Controller
|
||||||
|
|
||||||
$document->delete();
|
$document->delete();
|
||||||
session()->flash('flash.banner', 'Dokument gelöscht.');
|
session()->flash('flash.banner', 'Dokument gelöscht.');
|
||||||
|
|
||||||
return Redirect::back();
|
return Redirect::back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Inertia\Inertia;
|
|
||||||
use App\Models\Payment;
|
|
||||||
use App\Models\Contract;
|
|
||||||
use Barryvdh\DomPDF\Facade as PDF;
|
|
||||||
use App\Enums\PaymentType;
|
use App\Enums\PaymentType;
|
||||||
|
use App\Models\Contract;
|
||||||
|
use App\Models\Payment;
|
||||||
|
use Barryvdh\DomPDF\Facade as PDF;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
use Illuminate\Support\Facades\Redirect;
|
use Illuminate\Support\Facades\Redirect;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
|
||||||
class PaymentController extends Controller
|
class PaymentController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -22,7 +22,7 @@ class PaymentController extends Controller
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$request->merge([
|
$request->merge([
|
||||||
'type' => (string)$request->get('type'),
|
'type' => (string) $request->get('type'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
|
|
@ -39,6 +39,7 @@ class PaymentController extends Controller
|
||||||
$payment = Payment::create($request->all());
|
$payment = Payment::create($request->all());
|
||||||
|
|
||||||
session()->flash('flash.banner', 'Einzahlung gespeichert.');
|
session()->flash('flash.banner', 'Einzahlung gespeichert.');
|
||||||
|
|
||||||
return Redirect::route('contracts.show', $payment->contract);
|
return Redirect::route('contracts.show', $payment->contract);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,24 +47,25 @@ class PaymentController extends Controller
|
||||||
{
|
{
|
||||||
$contxt = stream_context_create([
|
$contxt = stream_context_create([
|
||||||
'ssl' => [
|
'ssl' => [
|
||||||
'verify_peer' => FALSE,
|
'verify_peer' => false,
|
||||||
'verify_peer_name' => FALSE,
|
'verify_peer_name' => false,
|
||||||
'allow_self_signed'=> TRUE
|
'allow_self_signed'=> true,
|
||||||
]
|
],
|
||||||
]);
|
]);
|
||||||
$pdf = PDF::setOptions(['isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true])->loadView('receipt', compact('contract', 'payment'));
|
$pdf = PDF::setOptions(['isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true])->loadView('receipt', compact('contract', 'payment'));
|
||||||
$pdf->getDomPDF()->setHttpContext($contxt);
|
$pdf->getDomPDF()->setHttpContext($contxt);
|
||||||
return $pdf->stream($payment->date . '_quittung.pdf');
|
|
||||||
|
return $pdf->stream($payment->date.'_quittung.pdf');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy(Request $request, Contract $contract)
|
public function destroy(Request $request, Contract $contract)
|
||||||
{
|
{
|
||||||
if (Payment::destroy((int)$request->get('id'))) {
|
if (Payment::destroy((int) $request->get('id'))) {
|
||||||
session()->flash('flash.banner', 'Einzahlung gelöscht.');
|
session()->flash('flash.banner', 'Einzahlung gelöscht.');
|
||||||
} else {
|
} else {
|
||||||
session()->flash('flash.banner', 'Fehler beim Löschen, Einzahlung nicht gefunden.');
|
session()->flash('flash.banner', 'Fehler beim Löschen, Einzahlung nicht gefunden.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return Redirect::back();
|
return Redirect::back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,22 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Inertia\Inertia;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Exports\Report;
|
use App\Exports\Report;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Inertia\Inertia;
|
||||||
use Maatwebsite\Excel\Facades\Excel as Excel;
|
use Maatwebsite\Excel\Facades\Excel as Excel;
|
||||||
|
|
||||||
class ReportController extends Controller
|
class ReportController extends Controller
|
||||||
{
|
{
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
return Inertia::render('Reports/Index', ['year' => (int)date('Y'), 'years' => array_reverse(range((int)date('Y') - 20, (int)date('Y')))]);
|
return Inertia::render('Reports/Index', ['year' => (int) date('Y'), 'years' => array_reverse(range((int) date('Y') - 20, (int) date('Y')))]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function print(Request $request)
|
public function print(Request $request)
|
||||||
{
|
{
|
||||||
$year = (int)$request->get('year');
|
$year = (int) $request->get('year');
|
||||||
return Excel::download(new Report($year), 'Wagenhandelbuch-' . $year .'.xlsx');
|
|
||||||
|
return Excel::download(new Report($year), 'Wagenhandelbuch-'.$year.'.xlsx');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use App\Enums\ContractType;
|
use App\Enums\ContractType;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
|
|
||||||
class Car extends Model
|
class Car extends Model
|
||||||
{
|
{
|
||||||
|
|
@ -31,18 +31,18 @@ class Car extends Model
|
||||||
|
|
||||||
public function getNameAttribute()
|
public function getNameAttribute()
|
||||||
{
|
{
|
||||||
if (!$this->carModel) {
|
if (! $this->carModel) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$out = $this->brand->name . ' ' . $this->carModel->name;
|
$out = $this->brand->name.' '.$this->carModel->name;
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNameWithYearAttribute()
|
public function getNameWithYearAttribute()
|
||||||
{
|
{
|
||||||
return $this->name . ' (' . $this->year . ')';
|
return $this->name.' ('.$this->year.')';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getYearAttribute()
|
public function getYearAttribute()
|
||||||
|
|
@ -74,7 +74,7 @@ class Car extends Model
|
||||||
if ($deleted_at) {
|
if ($deleted_at) {
|
||||||
return Carbon::parse($deleted_at)->format('d.m.Y');
|
return Carbon::parse($deleted_at)->format('d.m.Y');
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,10 +127,10 @@ class Car extends Model
|
||||||
{
|
{
|
||||||
return $query->withCount([
|
return $query->withCount([
|
||||||
'contracts AS buy_contracts_count' => function ($query) {
|
'contracts AS buy_contracts_count' => function ($query) {
|
||||||
$query->where('type', (string)ContractType::BuyContract);
|
$query->where('type', (string) ContractType::BuyContract);
|
||||||
},
|
},
|
||||||
'contracts AS sell_contracts_count' => function ($query) {
|
'contracts AS sell_contracts_count' => function ($query) {
|
||||||
$query->where('type', (string)ContractType::SellContract);
|
$query->where('type', (string) ContractType::SellContract);
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
@ -151,9 +151,9 @@ class Car extends Model
|
||||||
$parts = explode(' ', $search);
|
$parts = explode(' ', $search);
|
||||||
foreach ($parts as $part) {
|
foreach ($parts as $part) {
|
||||||
$query->where(function ($query) use ($part) {
|
$query->where(function ($query) use ($part) {
|
||||||
$query->orWhere('colour', 'like', $part . '%')
|
$query->orWhere('colour', 'like', $part.'%')
|
||||||
->orWhere('stammnummer', 'like', $part . '%')
|
->orWhere('stammnummer', 'like', $part.'%')
|
||||||
->orWhere('vin', 'like', $part . '%')
|
->orWhere('vin', 'like', $part.'%')
|
||||||
->orWhereHas('carModel', function ($query) use ($part) {
|
->orWhereHas('carModel', function ($query) use ($part) {
|
||||||
$query->where('name', 'like', $part.'%')
|
$query->where('name', 'like', $part.'%')
|
||||||
->orWhereHas('brand', function ($query) use ($part) {
|
->orWhereHas('brand', function ($query) use ($part) {
|
||||||
|
|
@ -169,10 +169,8 @@ class Car extends Model
|
||||||
$query->onlyTrashed();
|
$query->onlyTrashed();
|
||||||
}
|
}
|
||||||
})->when($filters['brand'] ?? null, function ($query, $brand) {
|
})->when($filters['brand'] ?? null, function ($query, $brand) {
|
||||||
$query->whereHas('carModel', function($q) use ($brand)
|
$query->whereHas('carModel', function ($q) use ($brand) {
|
||||||
{
|
|
||||||
$q->where('brand_id', '=', $brand);
|
$q->where('brand_id', '=', $brand);
|
||||||
|
|
||||||
})->get();
|
})->get();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use App\Enums\ContractType;
|
use App\Enums\ContractType;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
|
|
||||||
class Contact extends Model
|
class Contact extends Model
|
||||||
{
|
{
|
||||||
|
|
@ -49,7 +49,7 @@ class Contact extends Model
|
||||||
if ($deleted_at) {
|
if ($deleted_at) {
|
||||||
return Carbon::parse($deleted_at)->format('d.m.Y');
|
return Carbon::parse($deleted_at)->format('d.m.Y');
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,7 +63,6 @@ class Contact extends Model
|
||||||
return implode(', ', array_filter([$this->company, $this->name]));
|
return implode(', ', array_filter([$this->company, $this->name]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getFullTitleWithAddressAttribute()
|
public function getFullTitleWithAddressAttribute()
|
||||||
{
|
{
|
||||||
return implode(', ', array_filter([$this->full_title, $this->address, $this->full_city]));
|
return implode(', ', array_filter([$this->full_title, $this->address, $this->full_city]));
|
||||||
|
|
@ -71,7 +70,7 @@ class Contact extends Model
|
||||||
|
|
||||||
public function getFullCityAttribute()
|
public function getFullCityAttribute()
|
||||||
{
|
{
|
||||||
return $this->zip . ' ' . $this->city;
|
return $this->zip.' '.$this->city;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLinkAttribute()
|
public function getLinkAttribute()
|
||||||
|
|
@ -105,17 +104,16 @@ class Contact extends Model
|
||||||
$parts = explode(' ', $search);
|
$parts = explode(' ', $search);
|
||||||
foreach ($parts as $part) {
|
foreach ($parts as $part) {
|
||||||
$query->where(function ($query) use ($part) {
|
$query->where(function ($query) use ($part) {
|
||||||
$query->where('firstname', 'like', '%' . $part . '%')
|
$query->where('firstname', 'like', '%'.$part.'%')
|
||||||
->orWhere('lastname', 'like', '%' . $part . '%')
|
->orWhere('lastname', 'like', '%'.$part.'%')
|
||||||
->orWhere('company', 'like', '%' . $part . '%')
|
->orWhere('company', 'like', '%'.$part.'%')
|
||||||
->orWhere('email', 'like', '%' . $part . '%')
|
->orWhere('email', 'like', '%'.$part.'%')
|
||||||
->orWhere('zip', 'like', $part . '%')
|
->orWhere('zip', 'like', $part.'%')
|
||||||
->orWhere('city', 'like', '%' . $part . '%')
|
->orWhere('city', 'like', '%'.$part.'%')
|
||||||
->orWhere('address', 'like', '%' . $part . '%')
|
->orWhere('address', 'like', '%'.$part.'%')
|
||||||
->orWhere('phone', 'like', '%' . $part . '%');
|
->orWhere('phone', 'like', '%'.$part.'%');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
})->when($filters['trashed'] ?? null, function ($query, $trashed) {
|
})->when($filters['trashed'] ?? null, function ($query, $trashed) {
|
||||||
if ($trashed === 'with') {
|
if ($trashed === 'with') {
|
||||||
$query->withTrashed();
|
$query->withTrashed();
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Cknow\Money\Money;
|
|
||||||
use App\Enums\ContractType;
|
use App\Enums\ContractType;
|
||||||
use App\Enums\InsuranceType;
|
use App\Enums\InsuranceType;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Cknow\Money\Money;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
|
|
||||||
class Contract extends Model
|
class Contract extends Model
|
||||||
{
|
{
|
||||||
|
|
@ -47,50 +47,39 @@ class Contract extends Model
|
||||||
|
|
||||||
public function getPaidAttribute()
|
public function getPaidAttribute()
|
||||||
{
|
{
|
||||||
|
|
||||||
return Money::CHF($this->payments()->sum('amount'));
|
return Money::CHF($this->payments()->sum('amount'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPaidInCashAttribute()
|
public function getPaidInCashAttribute()
|
||||||
{
|
{
|
||||||
|
|
||||||
return Money::CHF($this->payments()->cashOnly()->sum('amount'));
|
return Money::CHF($this->payments()->cashOnly()->sum('amount'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPaidInTransactionAttribute()
|
public function getPaidInTransactionAttribute()
|
||||||
{
|
{
|
||||||
|
|
||||||
return Money::CHF($this->payments()->transactionOnly()->sum('amount'));
|
return Money::CHF($this->payments()->transactionOnly()->sum('amount'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPaidInCembraAttribute()
|
public function getPaidInCembraAttribute()
|
||||||
{
|
{
|
||||||
|
|
||||||
return Money::CHF($this->payments()->cembraOnly()->sum('amount'));
|
return Money::CHF($this->payments()->cembraOnly()->sum('amount'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLeftToPayAttribute()
|
public function getLeftToPayAttribute()
|
||||||
{
|
{
|
||||||
|
|
||||||
return $this->price->subtract($this->paid);
|
return $this->price->subtract($this->paid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInsuranceTypeFormattedAttribute()
|
public function getInsuranceTypeFormattedAttribute()
|
||||||
{
|
{
|
||||||
switch ($this->insurance_type) {
|
return match ($this->insurance_type) {
|
||||||
case InsuranceType::QBase:
|
InsuranceType::QBase => 'Q Basis',
|
||||||
return 'Q Basis';
|
InsuranceType::OneStar => '1 Stern',
|
||||||
case InsuranceType::OneStar:
|
InsuranceType::ThreeStar => '3 Stern',
|
||||||
return '1 Stern';
|
InsuranceType::FiveStar => '5 Stern',
|
||||||
case InsuranceType::ThreeStar:
|
InsuranceType::FiveStarPlus => '5 Stern+',
|
||||||
return '3 Stern';
|
default => 'Nein',
|
||||||
case InsuranceType::FiveStar:
|
};
|
||||||
return '5 Stern';
|
|
||||||
case InsuranceType::FiveStarPlus:
|
|
||||||
return '5 Stern+';
|
|
||||||
default:
|
|
||||||
return 'Nein';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDeletedAtAttribute($deleted_at)
|
public function getDeletedAtAttribute($deleted_at)
|
||||||
|
|
@ -98,18 +87,18 @@ class Contract extends Model
|
||||||
if ($deleted_at) {
|
if ($deleted_at) {
|
||||||
return Carbon::parse($deleted_at)->format('d.m.Y');
|
return Carbon::parse($deleted_at)->format('d.m.Y');
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isBuyContract()
|
public function isBuyContract()
|
||||||
{
|
{
|
||||||
return $this->type === (string)ContractType::BuyContract;
|
return $this->type === (string) ContractType::BuyContract;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isSellContract()
|
public function isSellContract()
|
||||||
{
|
{
|
||||||
return $this->type === (string)ContractType::SellContract;
|
return $this->type === (string) ContractType::SellContract;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTypeFormattedAttribute()
|
public function getTypeFormattedAttribute()
|
||||||
|
|
@ -164,11 +153,11 @@ class Contract extends Model
|
||||||
|
|
||||||
public function scopeBuyContracts($query)
|
public function scopeBuyContracts($query)
|
||||||
{
|
{
|
||||||
$query->where('type', (string)ContractType::BuyContract);
|
$query->where('type', (string) ContractType::BuyContract);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeSellContracts($query)
|
public function scopeSellContracts($query)
|
||||||
{
|
{
|
||||||
$query->where('type', (string)ContractType::SellContract);
|
$query->where('type', (string) ContractType::SellContract);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Document extends Model
|
class Document extends Model
|
||||||
{
|
{
|
||||||
|
|
@ -37,14 +37,14 @@ class Document extends Model
|
||||||
public function getSizeAttribute($size)
|
public function getSizeAttribute($size)
|
||||||
{
|
{
|
||||||
if ($size / 1024 < 1) {
|
if ($size / 1024 < 1) {
|
||||||
return $size . " B";
|
return $size.' B';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($size / 1024 / 1024 < 1) {
|
if ($size / 1024 / 1024 < 1) {
|
||||||
return floor($size / 1024) . " KB";
|
return floor($size / 1024).' KB';
|
||||||
}
|
}
|
||||||
|
|
||||||
return floor($size / 1024 / 1024) . " MB";
|
return floor($size / 1024 / 1024).' MB';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLinkAttribute()
|
public function getLinkAttribute()
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\PaymentType;
|
||||||
|
use App\Models\Contract;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Cknow\Money\Money;
|
use Cknow\Money\Money;
|
||||||
use App\Models\Contract;
|
|
||||||
use App\Enums\PaymentType;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Payment extends Model
|
class Payment extends Model
|
||||||
{
|
{
|
||||||
|
|
@ -42,27 +42,20 @@ class Payment extends Model
|
||||||
|
|
||||||
public function getTypeAttribute($type)
|
public function getTypeAttribute($type)
|
||||||
{
|
{
|
||||||
|
return match ($type) {
|
||||||
switch ($type) {
|
PaymentType::Transaction() => 'Banküberweisung',
|
||||||
case PaymentType::Transaction():
|
PaymentType::Cash() => 'Barzahlung',
|
||||||
return 'Banküberweisung';
|
default => 'Überweisung via Cembra',
|
||||||
case PaymentType::Cash():
|
};
|
||||||
return 'Barzahlung';
|
|
||||||
default:
|
|
||||||
return 'Überweisung via Cembra';
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTypeTextAttribute()
|
public function getTypeTextAttribute()
|
||||||
{
|
{
|
||||||
switch ($this->type) {
|
return match ($this->type) {
|
||||||
case 'Banküberweisung':
|
'Banküberweisung' => 'via Banküberweisung erhalten',
|
||||||
return 'via Banküberweisung erhalten';
|
'Barzahlung' => 'in bar erhalten',
|
||||||
case 'Barzahlung':
|
default => 'via Cembra-Überweisung erhalten',
|
||||||
return 'in bar erhalten';
|
};
|
||||||
default:
|
|
||||||
return 'via Cembra-Überweisung erhalten';
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPrintLinkAttribute()
|
public function getPrintLinkAttribute()
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,33 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
use Illuminate\Support\ServiceProvider;
|
|
||||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
class MorphServiceProvider extends ServiceProvider
|
class MorphServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Bootstrap services.
|
* Bootstrap services.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
Relation::morphMap([
|
Relation::morphMap([
|
||||||
'contracts' => 'App\Models\Contract',
|
'contracts' => \App\Models\Contract::class,
|
||||||
'cars' => 'App\Models\Car',
|
'cars' => \App\Models\Car::class,
|
||||||
'contacts' => 'App\Models\Contact',
|
'contacts' => \App\Models\Contact::class,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register services.
|
* Register services.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@ namespace App\Providers;
|
||||||
|
|
||||||
use App\Models\Car;
|
use App\Models\Car;
|
||||||
use App\Models\Contact;
|
use App\Models\Contact;
|
||||||
use App\Models\Payment;
|
|
||||||
use App\Models\Contract;
|
use App\Models\Contract;
|
||||||
use Illuminate\Http\Request;
|
use App\Models\Payment;
|
||||||
use Illuminate\Support\Facades\Route;
|
|
||||||
use Illuminate\Cache\RateLimiting\Limit;
|
use Illuminate\Cache\RateLimiting\Limit;
|
||||||
use Illuminate\Support\Facades\RateLimiter;
|
|
||||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\RateLimiter;
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
class RouteServiceProvider extends ServiceProvider
|
class RouteServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
|
@ -46,6 +46,7 @@ class RouteServiceProvider extends ServiceProvider
|
||||||
if (in_array(Route::currentRouteName(), ['cars.show', 'cars.restore'])) {
|
if (in_array(Route::currentRouteName(), ['cars.show', 'cars.restore'])) {
|
||||||
return Car::withTrashed()->find($value);
|
return Car::withTrashed()->find($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Car::find($value);
|
return Car::find($value);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -53,6 +54,7 @@ class RouteServiceProvider extends ServiceProvider
|
||||||
if (in_array(Route::currentRouteName(), ['contacts.show', 'contacts.restore'])) {
|
if (in_array(Route::currentRouteName(), ['contacts.show', 'contacts.restore'])) {
|
||||||
return Contact::withTrashed()->find($value);
|
return Contact::withTrashed()->find($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Contact::find($value);
|
return Contact::find($value);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -60,6 +62,7 @@ class RouteServiceProvider extends ServiceProvider
|
||||||
if (in_array(Route::currentRouteName(), ['contracts.show', 'contracts.restore', 'payments.destroy', 'payments.print'])) {
|
if (in_array(Route::currentRouteName(), ['contracts.show', 'contracts.restore', 'payments.destroy', 'payments.print'])) {
|
||||||
return Contract::withTrashed()->find($value);
|
return Contract::withTrashed()->find($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Contract::find($value);
|
return Contract::find($value);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -230,7 +230,7 @@ return [
|
||||||
'URL' => Illuminate\Support\Facades\URL::class,
|
'URL' => Illuminate\Support\Facades\URL::class,
|
||||||
'Validator' => Illuminate\Support\Facades\Validator::class,
|
'Validator' => Illuminate\Support\Facades\Validator::class,
|
||||||
'View' => Illuminate\Support\Facades\View::class,
|
'View' => Illuminate\Support\Facades\View::class,
|
||||||
'PDF' => Barryvdh\DomPDF\Facade::class,
|
'PDF' => Barryvdh\DomPDF\Facade::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,6 @@ return [
|
||||||
'custom' => [
|
'custom' => [
|
||||||
// 'MY1' => 2,
|
// 'MY1' => 2,
|
||||||
// 'MY2' => 3
|
// 'MY2' => 3
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ class CarFactory extends Factory
|
||||||
public function definition()
|
public function definition()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'stammnummer' => $this->faker->randomNumber(3, true) . '.' . $this->faker->randomNumber(3, true) . '.' . $this->faker->randomNumber(3, true),
|
'stammnummer' => $this->faker->randomNumber(3, true).'.'.$this->faker->randomNumber(3, true).'.'.$this->faker->randomNumber(3, true),
|
||||||
'vin' => $this->faker->regexify('[A-Z]{3}ZZZ[A-Z0-9]{3}[A-Z1-9]{1}[A-Z]{1}[0-9]{6}'),
|
'vin' => $this->faker->regexify('[A-Z]{3}ZZZ[A-Z0-9]{3}[A-Z1-9]{1}[A-Z]{1}[0-9]{6}'),
|
||||||
'colour' => $this->faker->safeColorName(),
|
'colour' => $this->faker->safeColorName(),
|
||||||
'notes' => $this->faker->paragraph(),
|
'notes' => $this->faker->paragraph(),
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Brand;
|
||||||
use App\Models\CarModel;
|
use App\Models\CarModel;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
use App\Models\Brand;
|
|
||||||
|
|
||||||
class CarModelFactory extends Factory
|
class CarModelFactory extends Factory
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
use App\Models\Contact;
|
use App\Models\Contact;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
||||||
use Faker\Provider\de_CH\PhoneNumber;
|
use Faker\Provider\de_CH\PhoneNumber;
|
||||||
use Faker\Provider\en_US\Person;
|
|
||||||
use Faker\Provider\en_US\Address;
|
use Faker\Provider\en_US\Address;
|
||||||
use Faker\Provider\en_US\Company;
|
use Faker\Provider\en_US\Company;
|
||||||
|
use Faker\Provider\en_US\Person;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
class ContactFactory extends Factory
|
class ContactFactory extends Factory
|
||||||
{
|
{
|
||||||
|
|
@ -30,7 +30,7 @@ class ContactFactory extends Factory
|
||||||
'lastname' => $this->faker->lastName(),
|
'lastname' => $this->faker->lastName(),
|
||||||
'phone' => $this->faker->PhoneNumber(),
|
'phone' => $this->faker->PhoneNumber(),
|
||||||
'email' => $this->faker->email(),
|
'email' => $this->faker->email(),
|
||||||
'address' => $this->faker->streetName() . ' ' . $this->faker->buildingNumber(),
|
'address' => $this->faker->streetName().' '.$this->faker->buildingNumber(),
|
||||||
'zip' => $this->faker->randomNumber(4, true),
|
'zip' => $this->faker->randomNumber(4, true),
|
||||||
'city' => $this->faker->city(),
|
'city' => $this->faker->city(),
|
||||||
'country' => 'CH',
|
'country' => 'CH',
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
use App\Models\Contract;
|
use App\Enums\ContractType;
|
||||||
|
use App\Enums\InsuranceType;
|
||||||
use App\Models\Car;
|
use App\Models\Car;
|
||||||
use App\Models\Contact;
|
use App\Models\Contact;
|
||||||
|
use App\Models\Contract;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
use App\Enums\InsuranceType;
|
|
||||||
use App\Enums\ContractType;
|
|
||||||
|
|
||||||
class ContractFactory extends Factory
|
class ContractFactory extends Factory
|
||||||
{
|
{
|
||||||
|
|
@ -32,8 +32,8 @@ class ContractFactory extends Factory
|
||||||
'price' => $this->faker->numberBetween(150000, 3500000),
|
'price' => $this->faker->numberBetween(150000, 3500000),
|
||||||
'contact_id' => $this->faker->numberBetween(1, Contact::count()),
|
'contact_id' => $this->faker->numberBetween(1, Contact::count()),
|
||||||
'car_id' => $this->faker->numberBetween(1, Car::count()),
|
'car_id' => $this->faker->numberBetween(1, Car::count()),
|
||||||
'insurance_type' => (string)InsuranceType::getRandomValue(),
|
'insurance_type' => (string) InsuranceType::getRandomValue(),
|
||||||
'type' => (string)ContractType::getRandomValue(),
|
'type' => (string) ContractType::getRandomValue(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,10 @@
|
||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
use App\Models\Document;
|
|
||||||
use App\Models\Contract;
|
use App\Models\Contract;
|
||||||
|
use App\Models\Document;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
|
||||||
class DocumentFactory extends Factory
|
class DocumentFactory extends Factory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
use App\Models\Payment;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
||||||
use App\Enums\PaymentType;
|
use App\Enums\PaymentType;
|
||||||
use App\Models\Contract;
|
use App\Models\Contract;
|
||||||
|
use App\Models\Payment;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
class PaymentFactory extends Factory
|
class PaymentFactory extends Factory
|
||||||
{
|
{
|
||||||
|
|
@ -26,7 +26,7 @@ class PaymentFactory extends Factory
|
||||||
return [
|
return [
|
||||||
'amount' => $this->faker->numberBetween(1000, 10000),
|
'amount' => $this->faker->numberBetween(1000, 10000),
|
||||||
'date' => $this->faker->date(),
|
'date' => $this->faker->date(),
|
||||||
'type' => (string)PaymentType::getRandomValue(),
|
'type' => (string) PaymentType::getRandomValue(),
|
||||||
'contract_id' => $this->faker->numberBetween(1, Contract::count()),
|
'contract_id' => $this->faker->numberBetween(1, Contract::count()),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Enums\ContractType;
|
||||||
|
use App\Enums\InsuranceType;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use App\Enums\InsuranceType;
|
|
||||||
use App\Enums\ContractType;
|
|
||||||
|
|
||||||
class CreateContractsTable extends Migration
|
class CreateContractsTable extends Migration
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Enums\PaymentType;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use App\Enums\PaymentType;
|
|
||||||
|
|
||||||
class CreatePaymentsTable extends Migration
|
class CreatePaymentsTable extends Migration
|
||||||
{
|
{
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,13 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Http\Controllers\ContactController;
|
|
||||||
use App\Http\Controllers\CarController;
|
|
||||||
use App\Http\Controllers\BrandController;
|
use App\Http\Controllers\BrandController;
|
||||||
use App\Http\Controllers\ReportController;
|
use App\Http\Controllers\CarController;
|
||||||
use App\Http\Controllers\CarModelController;
|
use App\Http\Controllers\CarModelController;
|
||||||
use App\Http\Controllers\PaymentController;
|
use App\Http\Controllers\ContactController;
|
||||||
use App\Http\Controllers\ContractController;
|
use App\Http\Controllers\ContractController;
|
||||||
use App\Http\Controllers\DocumentController;
|
use App\Http\Controllers\DocumentController;
|
||||||
|
use App\Http\Controllers\PaymentController;
|
||||||
|
use App\Http\Controllers\ReportController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::middleware(['auth:sanctum', 'verified'])->group(function () {
|
Route::middleware(['auth:sanctum', 'verified'])->group(function () {
|
||||||
|
|
@ -69,17 +69,16 @@ Route::middleware(['auth:sanctum', 'verified'])->group(function () {
|
||||||
Route::get('restore', [ContractController::class, 'restore'])->name('contracts.restore');
|
Route::get('restore', [ContractController::class, 'restore'])->name('contracts.restore');
|
||||||
Route::get('print', [ContractController::class, 'print'])->name('contracts.print');
|
Route::get('print', [ContractController::class, 'print'])->name('contracts.print');
|
||||||
|
|
||||||
Route::prefix('payments')->group(function () {
|
Route::prefix('payments')->group(function () {
|
||||||
Route::get('create', [PaymentController::class, 'create'])->name('payments.create');
|
Route::get('create', [PaymentController::class, 'create'])->name('payments.create');
|
||||||
Route::delete('delete', [PaymentController::class, 'destroy'])->name('payments.destroy');
|
Route::delete('delete', [PaymentController::class, 'destroy'])->name('payments.destroy');
|
||||||
Route::post('/', [PaymentController::class, 'store'])->name('payments.store');
|
Route::post('/', [PaymentController::class, 'store'])->name('payments.store');
|
||||||
Route::get('{payment}/print', [PaymentController::class, 'print'])->name('payments.print');
|
Route::get('{payment}/print', [PaymentController::class, 'print'])->name('payments.print');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::prefix('documents')->group(function () {
|
Route::prefix('documents')->group(function () {
|
||||||
Route::get('{document}', [DocumentController::class, 'show'])->name('documents.show');
|
Route::get('{document}', [DocumentController::class, 'show'])->name('documents.show');
|
||||||
Route::delete('delete', [DocumentController::class, 'destroy'])->name('documents.destroy');
|
Route::delete('delete', [DocumentController::class, 'destroy'])->name('documents.destroy');
|
||||||
Route::post('upload', [DocumentController::class, 'store'])->name('documents.store');
|
Route::post('upload', [DocumentController::class, 'store'])->name('documents.store');
|
||||||
|
|
@ -87,4 +86,4 @@ Route::middleware(['auth:sanctum', 'verified'])->group(function () {
|
||||||
|
|
||||||
Route::post('brands', [BrandController::class, 'store'])->name('brands.store');
|
Route::post('brands', [BrandController::class, 'store'])->name('brands.store');
|
||||||
Route::post('models', [CarModelController::class, 'store'])->name('models.store');
|
Route::post('models', [CarModelController::class, 'store'])->name('models.store');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue