diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index c40b56a..79fcaa9 100644 --- a/app/Http/Controllers/CustomerController.php +++ b/app/Http/Controllers/CustomerController.php @@ -23,6 +23,14 @@ class CustomerController extends Controller return view('customer.create'); } + /** + * Display the specified resource. + */ + public function show(Customer $customer): View + { + return view('customer.show', ['customer' => $customer->load(['addresses', 'invoices'])]); + } + /** * Show the form for editing the specified resource. diff --git a/app/Models/Customer.php b/app/Models/Customer.php index eb26fb1..4b2815f 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -92,4 +92,12 @@ class Customer extends Model { return $this->hasMany(Address::class); } + + /** + * Get all customer's invoices. + */ + public function invoices(): HasMany + { + return $this->hasMany(Invoice::class); + } } diff --git a/resources/views/customer/index.blade.php b/resources/views/customer/index.blade.php index 8417001..09215c4 100644 --- a/resources/views/customer/index.blade.php +++ b/resources/views/customer/index.blade.php @@ -7,6 +7,7 @@
+
@@ -14,11 +15,9 @@

{{ __('customer.Add new customer') }}

-

{{ __("customer.Add new customer by clicking add") }}

- {{ __('form.Add') }}
@@ -35,50 +34,22 @@ - +
{{ __('common.Name') }}
{{ __('common.Email') }}
{{ __('common.Created at') }}
-
+
+
diff --git a/resources/views/customer/show.blade.php b/resources/views/customer/show.blade.php new file mode 100644 index 0000000..59da3d1 --- /dev/null +++ b/resources/views/customer/show.blade.php @@ -0,0 +1,99 @@ + + +

+ {{ __('customer.Customer') }}: {{ $customer->name }} +

+
+ +
+
+ + + +
+
+
+
+

+ {{ __('customer.Existing addresses') }} +

+
+ +
+ @if($customer->address) +
+
{{ __('customer.Invoice Address') }}
+
{{ $customer->address->name }}
+
{{ $customer->address->address }}
+
{{ $customer->address->zip }} {{ $customer->address->city }}
+
{{ $customer->address->phone }}
+
{{ $customer->address->email }}
+
+ @endif + @if($customer->delivery) +
+
{{ __('customer.Delivery Address') }}
+
{{ $customer->delivery->name }}
+
{{ $customer->delivery->address }}
+
{{ $customer->delivery->zip }} {{ $customer->delivery->city }}
+
{{ $customer->delivery->phone }}
+
{{ $customer->delivery->email }}
+
+ @endif +
+
+
+
+ +
+
+
+
+

+ {{ __('invoice.Invoices') }} +

+
+ + +
{{ __('invoice.Invoice Number') }}
+
{{ __('common.Name') }}
+
{{ __('invoice.State') }}
+
{{ __('invoice.Sum') }}
+
{{ __('common.Created at') }}
+
+ + @php + $sum = 0; + @endphp + @foreach($customer->invoices as $invoice) + @php($sum += $invoice->sum) +
+ +
{{ $invoice->number }}
+
{{ $invoice->address->name }}
+
{{ $invoice->localized_state }}
+
{{ \Illuminate\Support\Number::currency($invoice->sum) }}
+
{{ $invoice->created }}
+
+
+ @endforeach + +
+
+
{{ __('invoice.Sum') }}
+
{{ \Illuminate\Support\Number::currency($sum) }}
+
+
+ +
+
+
+
+
+
diff --git a/routes/web.php b/routes/web.php index 428bc25..2c7dcaa 100644 --- a/routes/web.php +++ b/routes/web.php @@ -25,7 +25,7 @@ Route::middleware('auth')->group(function () { Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update'); Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy'); - Route::resource('/customer', CustomerController::class)->only(['index', 'create', 'edit']); + Route::resource('/customer', CustomerController::class)->only(['index', 'create', 'show', 'edit']); Route::get('/address/{id}/edit', [AddressController::class, 'edit'])->name('address.edit'); Route::resource('/taxrate', TaxrateController::class)->only(['index', 'create', 'edit']); Route::get('/option', [OptionController::class, 'index'])->name('option.index');