commit
4890b393a9
|
|
@ -14,5 +14,6 @@ use BenSampo\Enum\Enum;
|
|||
final class ContractType extends Enum
|
||||
{
|
||||
const BuyContract = '0';
|
||||
|
||||
const SellContract = '1';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,14 @@ use BenSampo\Enum\Enum;
|
|||
final class InsuranceType extends Enum
|
||||
{
|
||||
const Keine = '0';
|
||||
|
||||
const QBase = '1';
|
||||
|
||||
const OneStar = '2';
|
||||
|
||||
const ThreeStar = '3';
|
||||
|
||||
const FiveStar = '4';
|
||||
|
||||
const FiveStarPlus = '5';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ use BenSampo\Enum\Enum;
|
|||
final class PaymentType extends Enum
|
||||
{
|
||||
const Transaction = '0';
|
||||
|
||||
const Cash = '1';
|
||||
|
||||
const Cembra = '2';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,15 @@
|
|||
|
||||
namespace App\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
class Export implements FromCollection, WithHeadings, WithStyles
|
||||
{
|
||||
protected $model;
|
||||
|
||||
protected $headings;
|
||||
|
||||
public function __construct($model, $headings)
|
||||
|
|
|
|||
|
|
@ -2,18 +2,18 @@
|
|||
|
||||
namespace App\Exports;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Car;
|
||||
use App\Models\Contract;
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
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 Carbon\Carbon;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
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;
|
||||
|
||||
class Report implements FromCollection, WithTitle, WithHeadings, WithStyles, WithColumnFormatting, ShouldAutoSize
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Car;
|
||||
use Inertia\Inertia;
|
||||
use App\Models\Brand;
|
||||
use App\Exports\Export;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Car;
|
||||
use App\Models\Contract;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Inertia\Inertia;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class CarController extends Controller
|
||||
{
|
||||
|
|
@ -27,7 +27,6 @@ class CarController extends Controller
|
|||
|
||||
public function sold(Request $request)
|
||||
{
|
||||
|
||||
return $this->renderCarsList($request, Car::soldOnly(), 'Cars/Sold', 'sell_contract.date');
|
||||
}
|
||||
|
||||
|
|
@ -60,6 +59,7 @@ class CarController extends Controller
|
|||
->map(function ($car) {
|
||||
$bcontract = $car->latestBuyContract();
|
||||
$scontract = $car->latestSellContract();
|
||||
|
||||
return [
|
||||
'brand' => $car->brand->name,
|
||||
'model' => $car->carModel->name,
|
||||
|
|
@ -108,6 +108,7 @@ class CarController extends Controller
|
|||
->get()
|
||||
->map(function ($car) {
|
||||
$contract = $car->latestBuyContract();
|
||||
|
||||
return [
|
||||
'brand' => $car->brand->name,
|
||||
'model' => $car->carModel->name,
|
||||
|
|
@ -157,6 +158,7 @@ class CarController extends Controller
|
|||
->map(function ($car) {
|
||||
$bcontract = $car->latestBuyContract();
|
||||
$scontract = $car->latestSellContract();
|
||||
|
||||
return [
|
||||
'brand' => $car->brand->name,
|
||||
'model' => $car->carModel->name,
|
||||
|
|
@ -180,7 +182,8 @@ class CarController extends Controller
|
|||
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');
|
||||
$sortBy = $this->getSortBy($request, $defaultSort);
|
||||
$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) {
|
||||
return null;
|
||||
}
|
||||
$contact = $contract->contact;
|
||||
|
||||
return [
|
||||
'id' => $contract->id,
|
||||
'date' => $contract->date_formatted,
|
||||
|
|
@ -224,48 +229,41 @@ class CarController extends Controller
|
|||
|
||||
private function getWithCustomSort($cars, string $sortBy, string $direction)
|
||||
{
|
||||
switch($sortBy) {
|
||||
case 'name':
|
||||
return $cars
|
||||
return match ($sortBy) {
|
||||
'name' => $cars
|
||||
->leftJoin('car_models', 'cars.car_model_id', '=', 'car_models.id')
|
||||
->leftJoin('brands', 'car_models.brand_id', '=', 'brands.id')
|
||||
->orderBy('brands.name', $direction)
|
||||
->orderBy('car_models.name', $direction);
|
||||
case 'initial_date':
|
||||
return $cars->orderBy('initial_date', $direction);
|
||||
case 'stammnummer':
|
||||
return $cars->orderBy('stammnummer', $direction);
|
||||
case 'buy_contract.date':
|
||||
return $cars
|
||||
->orderBy('car_models.name', $direction),
|
||||
'initial_date' => $cars->orderBy('initial_date', $direction),
|
||||
'stammnummer' => $cars->orderBy('stammnummer', $direction),
|
||||
'buy_contract.date' => $cars
|
||||
->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 = '0' order by date desc limit 1)"));
|
||||
})
|
||||
->orderBy('contracts.date', $direction);
|
||||
case 'buy_contract.price':
|
||||
return $cars
|
||||
->orderBy('contracts.date', $direction),
|
||||
'buy_contract.price' => $cars
|
||||
->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 = '0' order by date desc limit 1)"));
|
||||
})
|
||||
->orderBy('contracts.price', $direction);
|
||||
case 'sell_contract.date':
|
||||
return $cars
|
||||
->orderBy('contracts.price', $direction),
|
||||
'sell_contract.date' => $cars
|
||||
->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.date', $direction);
|
||||
case 'sell_contract.price':
|
||||
return $cars
|
||||
->orderBy('contracts.date', $direction),
|
||||
'sell_contract.price' => $cars
|
||||
->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);
|
||||
}
|
||||
)
|
||||
->orderBy('contracts.price', $direction),
|
||||
default => $cars->orderBy('initial_date', $direction),
|
||||
};
|
||||
}
|
||||
|
||||
private function getSortBy(Request $request, $defaultSort)
|
||||
|
|
@ -306,6 +304,7 @@ class CarController extends Controller
|
|||
$car = $this->createCar($request);
|
||||
|
||||
session()->flash('flash.banner', 'Auto erstellt.');
|
||||
|
||||
return Redirect::route('cars.show', $car);
|
||||
}
|
||||
|
||||
|
|
@ -392,12 +391,16 @@ class CarController extends Controller
|
|||
->orderBy('date', 'desc')
|
||||
->with('contact')
|
||||
->get()
|
||||
->map(function ($contract) { return $this->getContractFields($contract); }),
|
||||
->map(function ($contract) {
|
||||
return $this->getContractFields($contract);
|
||||
}),
|
||||
'sell_contracts' => $car->sellContracts()
|
||||
->orderBy('date', 'desc')
|
||||
->with('contact')
|
||||
->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);
|
||||
session()->flash('flash.banner', 'Auto geändert.');
|
||||
|
||||
return Redirect::route('cars.show', $car);
|
||||
}
|
||||
|
||||
|
|
@ -476,6 +480,7 @@ class CarController extends Controller
|
|||
{
|
||||
$car->delete();
|
||||
session()->flash('flash.banner', 'Auto gelöscht.');
|
||||
|
||||
return Redirect::route('cars.show', $car);
|
||||
}
|
||||
|
||||
|
|
@ -483,6 +488,7 @@ class CarController extends Controller
|
|||
{
|
||||
$car->restore();
|
||||
session()->flash('flash.banner', 'Auto wiederhergestellt.');
|
||||
|
||||
return Redirect::route('cars.show', $car);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Inertia\Inertia;
|
||||
use App\Exports\Export;
|
||||
use App\Models\Contact;
|
||||
use App\Models\Contract;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Inertia\Inertia;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class ContactController extends Controller
|
||||
{
|
||||
|
|
@ -27,7 +27,8 @@ class ContactController extends Controller
|
|||
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);
|
||||
$sortBy = $this->getSortBy($request);
|
||||
$contacts = $this->getWithCustomSort($contacts, $sortBy, $direction);
|
||||
|
|
@ -58,7 +59,7 @@ class ContactController extends Controller
|
|||
public function letter(Contact $contact)
|
||||
{
|
||||
$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('name', $contact->name);
|
||||
$templateProcessor->setValue('address', $contact->address);
|
||||
|
|
@ -66,7 +67,7 @@ class ContactController extends Controller
|
|||
$templateProcessor->setValue('country', $contact->country !== 'CH' ? $contact->country : '');
|
||||
|
||||
ob_start();
|
||||
$templateProcessor->saveAs("php://output");
|
||||
$templateProcessor->saveAs('php://output');
|
||||
$contents = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
|
|
@ -130,18 +131,13 @@ class ContactController extends Controller
|
|||
|
||||
private function getWithCustomSort($contacts, string $sortBy, string $direction)
|
||||
{
|
||||
switch($sortBy) {
|
||||
case 'company':
|
||||
return $contacts->orderBy('company', $direction);
|
||||
case 'fullCity':
|
||||
return $contacts->orderBy('city', $direction);
|
||||
case 'email':
|
||||
return $contacts->orderBy('email', $direction);
|
||||
case 'address':
|
||||
return $contacts->orderBy('address', $direction);
|
||||
default:
|
||||
return $contacts->orderByName($direction);
|
||||
}
|
||||
return match ($sortBy) {
|
||||
'company' => $contacts->orderBy('company', $direction),
|
||||
'fullCity' => $contacts->orderBy('city', $direction),
|
||||
'email' => $contacts->orderBy('email', $direction),
|
||||
'address' => $contacts->orderBy('address', $direction),
|
||||
default => $contacts->orderByName($direction),
|
||||
};
|
||||
}
|
||||
|
||||
private function getSortBy(Request $request)
|
||||
|
|
@ -165,6 +161,7 @@ class ContactController extends Controller
|
|||
);
|
||||
|
||||
session()->flash('flash.banner', 'Kontakt erstellt.');
|
||||
|
||||
return Redirect::route('contacts.show', $contact);
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +204,7 @@ class ContactController extends Controller
|
|||
'city' => $contact->city,
|
||||
'country' => $contact->country,
|
||||
'deleted_at' => $contact->deleted_at,
|
||||
]
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -244,21 +241,27 @@ class ContactController extends Controller
|
|||
->orderBy('date', 'desc')
|
||||
->with('car')
|
||||
->get()
|
||||
->map(function ($contract) { return $this->getContractFields($contract); }),
|
||||
->map(function ($contract) {
|
||||
return $this->getContractFields($contract);
|
||||
}),
|
||||
'sell_contracts' => $contact->sellContracts()
|
||||
->orderBy('date', 'desc')
|
||||
->with('car')
|
||||
->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) {
|
||||
return null;
|
||||
}
|
||||
$car = $contract->car;
|
||||
|
||||
return [
|
||||
'id' => $contract->id,
|
||||
'date' => $contract->date_formatted,
|
||||
|
|
@ -275,6 +278,7 @@ class ContactController extends Controller
|
|||
);
|
||||
|
||||
session()->flash('flash.banner', 'Kontakt geändert.');
|
||||
|
||||
return Redirect::route('contacts.show', $contact);
|
||||
}
|
||||
|
||||
|
|
@ -298,6 +302,7 @@ class ContactController extends Controller
|
|||
{
|
||||
$contact->delete();
|
||||
session()->flash('flash.banner', 'Kontakt gelöscht.');
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
|
|
@ -305,6 +310,7 @@ class ContactController extends Controller
|
|||
{
|
||||
$contact->restore();
|
||||
session()->flash('flash.banner', 'Kontakt wiederhergestellt.');
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,24 +2,23 @@
|
|||
|
||||
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\InsuranceType;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Enums\PaymentType;
|
||||
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 Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class ContractController extends Controller
|
||||
{
|
||||
|
||||
public function dashboard()
|
||||
{
|
||||
return Inertia::render('Dashboard', [
|
||||
|
|
@ -80,7 +79,8 @@ class ContractController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
private function getCarFields(?Car $car) {
|
||||
private function getCarFields(?Car $car)
|
||||
{
|
||||
if (! $car) {
|
||||
return [
|
||||
'name' => null,
|
||||
|
|
@ -93,6 +93,7 @@ class ContractController extends Controller
|
|||
'initial_date' => null,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'name' => $car->name,
|
||||
'label' => $car->name.' ('.$car->stammnummer.')',
|
||||
|
|
@ -105,7 +106,8 @@ class ContractController extends Controller
|
|||
];
|
||||
}
|
||||
|
||||
private function getContactFields(?Contact $contact) {
|
||||
private function getContactFields(?Contact $contact)
|
||||
{
|
||||
if (! $contact) {
|
||||
return [
|
||||
'id' => null,
|
||||
|
|
@ -122,6 +124,7 @@ class ContractController extends Controller
|
|||
'email' => null,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $contact->id,
|
||||
'title' => $contact->full_title,
|
||||
|
|
@ -181,8 +184,8 @@ class ContractController extends Controller
|
|||
}
|
||||
|
||||
session()->flash('flash.banner', 'Vertrag erstellt.');
|
||||
return Redirect::route('contracts.show', $contract);
|
||||
|
||||
return Redirect::route('contracts.show', $contract);
|
||||
}
|
||||
|
||||
public function edit(Contract $contract)
|
||||
|
|
@ -230,8 +233,8 @@ class ContractController extends Controller
|
|||
$contract->update($request->all());
|
||||
|
||||
session()->flash('flash.banner', 'Vertrag geändert.');
|
||||
return Redirect::route('contracts.show', $contract);
|
||||
|
||||
return Redirect::route('contracts.show', $contract);
|
||||
}
|
||||
|
||||
public function show(Contract $contract)
|
||||
|
|
@ -283,13 +286,14 @@ class ContractController extends Controller
|
|||
{
|
||||
$contxt = stream_context_create([
|
||||
'ssl' => [
|
||||
'verify_peer' => FALSE,
|
||||
'verify_peer_name' => FALSE,
|
||||
'allow_self_signed'=> TRUE
|
||||
]
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
'allow_self_signed'=> true,
|
||||
],
|
||||
]);
|
||||
$pdf = PDF::setOptions(['isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true])->loadView('contract', compact('contract'));
|
||||
$pdf->getDomPDF()->setHttpContext($contxt);
|
||||
|
||||
return $pdf->stream($contract->date.'_'.$contract->type_formatted.'.pdf');
|
||||
}
|
||||
|
||||
|
|
@ -297,6 +301,7 @@ class ContractController extends Controller
|
|||
{
|
||||
$contract->delete();
|
||||
session()->flash('flash.banner', 'Vertrag gelöscht.');
|
||||
|
||||
return Redirect::route('contracts.show', $contract);
|
||||
}
|
||||
|
||||
|
|
@ -304,6 +309,7 @@ class ContractController extends Controller
|
|||
{
|
||||
$contract->restore();
|
||||
session()->flash('flash.banner', 'Vertrag wiederhergestellt.');
|
||||
|
||||
return Redirect::route('contracts.show', $contract);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
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\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ class DocumentController extends Controller
|
|||
{
|
||||
if (file_exists($document->path)) {
|
||||
header('Content-Disposition: filename="'.$document->name.'"');
|
||||
|
||||
return response()->file($document->path);
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +55,7 @@ class DocumentController extends Controller
|
|||
|
||||
if (! $document) {
|
||||
session()->flash('flash.banner', 'Fehler beim Löschen, Dokument nicht gefunden.');
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
|
|
@ -63,6 +65,7 @@ class DocumentController extends Controller
|
|||
|
||||
$document->delete();
|
||||
session()->flash('flash.banner', 'Dokument gelöscht.');
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
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\Models\Contract;
|
||||
use App\Models\Payment;
|
||||
use Barryvdh\DomPDF\Facade as PDF;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
|
|
@ -39,6 +39,7 @@ class PaymentController extends Controller
|
|||
$payment = Payment::create($request->all());
|
||||
|
||||
session()->flash('flash.banner', 'Einzahlung gespeichert.');
|
||||
|
||||
return Redirect::route('contracts.show', $payment->contract);
|
||||
}
|
||||
|
||||
|
|
@ -46,13 +47,14 @@ class PaymentController extends Controller
|
|||
{
|
||||
$contxt = stream_context_create([
|
||||
'ssl' => [
|
||||
'verify_peer' => FALSE,
|
||||
'verify_peer_name' => FALSE,
|
||||
'allow_self_signed'=> TRUE
|
||||
]
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
'allow_self_signed'=> true,
|
||||
],
|
||||
]);
|
||||
$pdf = PDF::setOptions(['isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true])->loadView('receipt', compact('contract', 'payment'));
|
||||
$pdf->getDomPDF()->setHttpContext($contxt);
|
||||
|
||||
return $pdf->stream($payment->date.'_quittung.pdf');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Exports\Report;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Maatwebsite\Excel\Facades\Excel as Excel;
|
||||
|
||||
class ReportController extends Controller
|
||||
|
|
@ -17,6 +17,7 @@ class ReportController extends Controller
|
|||
public function print(Request $request)
|
||||
{
|
||||
$year = (int) $request->get('year');
|
||||
|
||||
return Excel::download(new Report($year), 'Wagenhandelbuch-'.$year.'.xlsx');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Enums\ContractType;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Car extends Model
|
||||
{
|
||||
|
|
@ -169,10 +169,8 @@ class Car extends Model
|
|||
$query->onlyTrashed();
|
||||
}
|
||||
})->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);
|
||||
|
||||
})->get();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Enums\ContractType;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Contact extends Model
|
||||
{
|
||||
|
|
@ -63,7 +63,6 @@ class Contact extends Model
|
|||
return implode(', ', array_filter([$this->company, $this->name]));
|
||||
}
|
||||
|
||||
|
||||
public function getFullTitleWithAddressAttribute()
|
||||
{
|
||||
return implode(', ', array_filter([$this->full_title, $this->address, $this->full_city]));
|
||||
|
|
@ -115,7 +114,6 @@ class Contact extends Model
|
|||
->orWhere('phone', 'like', '%'.$part.'%');
|
||||
});
|
||||
}
|
||||
|
||||
})->when($filters['trashed'] ?? null, function ($query, $trashed) {
|
||||
if ($trashed === 'with') {
|
||||
$query->withTrashed();
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Cknow\Money\Money;
|
||||
use App\Enums\ContractType;
|
||||
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\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Contract extends Model
|
||||
{
|
||||
|
|
@ -47,50 +47,39 @@ class Contract extends Model
|
|||
|
||||
public function getPaidAttribute()
|
||||
{
|
||||
|
||||
return Money::CHF($this->payments()->sum('amount'));
|
||||
}
|
||||
|
||||
public function getPaidInCashAttribute()
|
||||
{
|
||||
|
||||
return Money::CHF($this->payments()->cashOnly()->sum('amount'));
|
||||
}
|
||||
|
||||
public function getPaidInTransactionAttribute()
|
||||
{
|
||||
|
||||
return Money::CHF($this->payments()->transactionOnly()->sum('amount'));
|
||||
}
|
||||
|
||||
public function getPaidInCembraAttribute()
|
||||
{
|
||||
|
||||
return Money::CHF($this->payments()->cembraOnly()->sum('amount'));
|
||||
}
|
||||
|
||||
public function getLeftToPayAttribute()
|
||||
{
|
||||
|
||||
return $this->price->subtract($this->paid);
|
||||
}
|
||||
|
||||
public function getInsuranceTypeFormattedAttribute()
|
||||
{
|
||||
switch ($this->insurance_type) {
|
||||
case InsuranceType::QBase:
|
||||
return 'Q Basis';
|
||||
case InsuranceType::OneStar:
|
||||
return '1 Stern';
|
||||
case InsuranceType::ThreeStar:
|
||||
return '3 Stern';
|
||||
case InsuranceType::FiveStar:
|
||||
return '5 Stern';
|
||||
case InsuranceType::FiveStarPlus:
|
||||
return '5 Stern+';
|
||||
default:
|
||||
return 'Nein';
|
||||
}
|
||||
return match ($this->insurance_type) {
|
||||
InsuranceType::QBase => 'Q Basis',
|
||||
InsuranceType::OneStar => '1 Stern',
|
||||
InsuranceType::ThreeStar => '3 Stern',
|
||||
InsuranceType::FiveStar => '5 Stern',
|
||||
InsuranceType::FiveStarPlus => '5 Stern+',
|
||||
default => 'Nein',
|
||||
};
|
||||
}
|
||||
|
||||
public function getDeletedAtAttribute($deleted_at)
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Document extends Model
|
||||
{
|
||||
|
|
@ -37,14 +37,14 @@ class Document extends Model
|
|||
public function getSizeAttribute($size)
|
||||
{
|
||||
if ($size / 1024 < 1) {
|
||||
return $size . " B";
|
||||
return $size.' B';
|
||||
}
|
||||
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\PaymentType;
|
||||
use App\Models\Contract;
|
||||
use Carbon\Carbon;
|
||||
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\Model;
|
||||
|
||||
class Payment extends Model
|
||||
{
|
||||
|
|
@ -42,26 +42,19 @@ class Payment extends Model
|
|||
|
||||
public function getTypeAttribute($type)
|
||||
{
|
||||
|
||||
switch ($type) {
|
||||
case PaymentType::Transaction():
|
||||
return 'Banküberweisung';
|
||||
case PaymentType::Cash():
|
||||
return 'Barzahlung';
|
||||
default:
|
||||
return 'Überweisung via Cembra';
|
||||
return match ($type) {
|
||||
PaymentType::Transaction() => 'Banküberweisung',
|
||||
PaymentType::Cash() => 'Barzahlung',
|
||||
default => 'Überweisung via Cembra',
|
||||
};
|
||||
}
|
||||
|
||||
public function getTypeTextAttribute()
|
||||
{
|
||||
switch ($this->type) {
|
||||
case 'Banküberweisung':
|
||||
return 'via Banküberweisung erhalten';
|
||||
case 'Barzahlung':
|
||||
return 'in bar erhalten';
|
||||
default:
|
||||
return 'via Cembra-Überweisung erhalten';
|
||||
return match ($this->type) {
|
||||
'Banküberweisung' => 'via Banküberweisung erhalten',
|
||||
'Barzahlung' => 'in bar erhalten',
|
||||
default => 'via Cembra-Überweisung erhalten',
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class MorphServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
|
@ -14,9 +15,9 @@ class MorphServiceProvider extends ServiceProvider
|
|||
public function boot()
|
||||
{
|
||||
Relation::morphMap([
|
||||
'contracts' => 'App\Models\Contract',
|
||||
'cars' => 'App\Models\Car',
|
||||
'contacts' => 'App\Models\Contact',
|
||||
'contracts' => \App\Models\Contract::class,
|
||||
'cars' => \App\Models\Car::class,
|
||||
'contacts' => \App\Models\Contact::class,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ namespace App\Providers;
|
|||
|
||||
use App\Models\Car;
|
||||
use App\Models\Contact;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Contract;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Models\Payment;
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
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
|
||||
{
|
||||
|
|
@ -46,6 +46,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||
if (in_array(Route::currentRouteName(), ['cars.show', 'cars.restore'])) {
|
||||
return Car::withTrashed()->find($value);
|
||||
}
|
||||
|
||||
return Car::find($value);
|
||||
});
|
||||
|
||||
|
|
@ -53,6 +54,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||
if (in_array(Route::currentRouteName(), ['contacts.show', 'contacts.restore'])) {
|
||||
return Contact::withTrashed()->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'])) {
|
||||
return Contract::withTrashed()->find($value);
|
||||
}
|
||||
|
||||
return Contract::find($value);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,6 @@ return [
|
|||
'custom' => [
|
||||
// 'MY1' => 2,
|
||||
// 'MY2' => 3
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Brand;
|
||||
use App\Models\CarModel;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use App\Models\Brand;
|
||||
|
||||
class CarModelFactory extends Factory
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@
|
|||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Contact;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Faker\Provider\de_CH\PhoneNumber;
|
||||
use Faker\Provider\en_US\Person;
|
||||
use Faker\Provider\en_US\Address;
|
||||
use Faker\Provider\en_US\Company;
|
||||
use Faker\Provider\en_US\Person;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ContactFactory extends Factory
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Contract;
|
||||
use App\Enums\ContractType;
|
||||
use App\Enums\InsuranceType;
|
||||
use App\Models\Car;
|
||||
use App\Models\Contact;
|
||||
use App\Models\Contract;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use App\Enums\InsuranceType;
|
||||
use App\Enums\ContractType;
|
||||
|
||||
class ContractFactory extends Factory
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@
|
|||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Document;
|
||||
use App\Models\Contract;
|
||||
use App\Models\Document;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
|
||||
class DocumentFactory extends Factory
|
||||
{
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Payment;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use App\Enums\PaymentType;
|
||||
use App\Models\Contract;
|
||||
use App\Models\Payment;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class PaymentFactory extends Factory
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\ContractType;
|
||||
use App\Enums\InsuranceType;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use App\Enums\InsuranceType;
|
||||
use App\Enums\ContractType;
|
||||
|
||||
class CreateContractsTable extends Migration
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\PaymentType;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use App\Enums\PaymentType;
|
||||
|
||||
class CreatePaymentsTable extends Migration
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\User;
|
||||
use App\Models\Team;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Car;
|
||||
use App\Models\CarModel;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Contract;
|
||||
use App\Models\Contact;
|
||||
use App\Models\Contract;
|
||||
use App\Models\Document;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
|
|
@ -1173,5 +1173,4 @@ class DatabaseSeeder extends Seeder
|
|||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\ContactController;
|
||||
use App\Http\Controllers\CarController;
|
||||
use App\Http\Controllers\BrandController;
|
||||
use App\Http\Controllers\ReportController;
|
||||
use App\Http\Controllers\CarController;
|
||||
use App\Http\Controllers\CarModelController;
|
||||
use App\Http\Controllers\PaymentController;
|
||||
use App\Http\Controllers\ContactController;
|
||||
use App\Http\Controllers\ContractController;
|
||||
use App\Http\Controllers\DocumentController;
|
||||
use App\Http\Controllers\PaymentController;
|
||||
use App\Http\Controllers\ReportController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::middleware(['auth:sanctum', 'verified'])->group(function () {
|
||||
|
|
@ -75,7 +75,6 @@ Route::middleware(['auth:sanctum', 'verified'])->group(function () {
|
|||
Route::post('/', [PaymentController::class, 'store'])->name('payments.store');
|
||||
Route::get('{payment}/print', [PaymentController::class, 'print'])->name('payments.print');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue