Extend customers' information.

This commit is contained in:
2025-02-03 14:41:53 +01:00
parent 2c32b51058
commit ade1bfb863
5 changed files with 123 additions and 37 deletions

View File

@@ -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.

View File

@@ -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);
}
}

View File

@@ -7,6 +7,7 @@
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
<div class="p-4 sm:p-8 bg-white dark:bg-gray-800 shadow sm:rounded-lg">
<div class="max-w-xl">
<section>
@@ -14,11 +15,9 @@
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
{{ __('customer.Add new customer') }}
</h2>
<p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
{{ __("customer.Add new customer by clicking add") }}
</p>
</header>
<a class="mt-6 inline-block" href="{{ route('customer.create') }}"><x-primary-button>{{ __('form.Add') }}</x-primary-button></a>
</section>
@@ -35,50 +34,22 @@
</h2>
</header>
<summary class="cursor-pointer grid grid-cols-3 mt-4">
<div class="cursor-pointer grid grid-cols-3 mt-4">
<div class="font-bold border-b-2">{{ __('common.Name') }}</div>
<div class="font-bold border-b-2">{{ __('common.Email') }}</div>
<div class="font-bold border-b-2">{{ __('common.Created at') }}</div>
</summary>
</div>
<template x-for="customer in customers">
<details class="even:bg-gray-100 odd:bg-white">
<summary class="cursor-pointer grid grid-cols-3">
<div class="even:bg-gray-100 odd:bg-white hover:bg-gray-400">
<div class="cursor-pointer grid grid-cols-3" x-on:click="window.location.href='/customer/' + customer.id;">
<div x-text="customer.name"></div>
<div x-text="customer.email"></div>
<div x-text="customer.created"></div>
</summary>
<div class="flex flex-row">
<template x-if="customer.address">
<div class="flex flex-col p-8 w-1/3">
<div class="text-lg font-medium text-gray-900 dark:text-gray-100">{{ __('customer.Invoice Address') }}</div>
<div x-text="customer.address.name"></div>
<div x-text="customer.address.address"></div>
<div x-text="customer.address.zip +' ' + customer.address.city"></div>
<div x-text="customer.address.phone"></div>
<div x-text="customer.address.email"></div>
</div>
</template>
<template x-if="customer.delivery">
<div class="flex flex-col p-8 w-1/3">
<div class="text-lg font-medium text-gray-900 dark:text-gray-100">{{ __('customer.Delivery Address') }}</div>
<div x-text="customer.delivery.name"></div>
<div x-text="customer.delivery.address"></div>
<div x-text="customer.delivery.zip +' ' + customer.delivery.city"></div>
<div x-text="customer.delivery.phone"></div>
<div x-text="customer.delivery.email"></div>
</div>
</template>
</div>
<div>
<a class="ml-8 mb-8 inline-block" x-bind:href="'/customer/' + customer.id + '/edit'"><x-primary-button class="pl-2+
"><x-edit-icon class="h-6 mr-2"/>{{ __('form.Edit') }}</x-primary-button></a>
</div>
</details>
</div>
</template>
</section>
</div>
</div>

View File

@@ -0,0 +1,99 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
{{ __('customer.Customer') }}: {{ $customer->name }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
<div class="p-4 sm:p-8 bg-white dark:bg-gray-800 shadow sm:rounded-lg">
<div class="max-w">
<a class="inline-block" href="{{ route('customer.edit', $customer->id) }}">
<x-primary-button>{{ __('form.Edit') }}</x-primary-button>
</a>
</div>
</div>
<div class="p-4 sm:p-8 bg-white dark:bg-gray-800 shadow sm:rounded-lg">
<div class="max-w">
<section>
<header>
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
{{ __('customer.Existing addresses') }}
</h2>
</header>
<div class="flex flex-row">
@if($customer->address)
<div class="flex flex-col p-8 w-1/2">
<div class="text-lg font-medium text-gray-900 dark:text-gray-100">{{ __('customer.Invoice Address') }}</div>
<div>{{ $customer->address->name }}</div>
<div>{{ $customer->address->address }}</div>
<div>{{ $customer->address->zip }} {{ $customer->address->city }}</div>
<div>{{ $customer->address->phone }}</div>
<div>{{ $customer->address->email }}</div>
</div>
@endif
@if($customer->delivery)
<div class="flex flex-col p-8 w-1/2">
<div class="text-lg font-medium text-gray-900 dark:text-gray-100">{{ __('customer.Delivery Address') }}</div>
<div x-text="customer.delivery.name">{{ $customer->delivery->name }}</div>
<div x-text="customer.delivery.address">{{ $customer->delivery->address }}</div>
<div x-text="customer.delivery.zip +' ' + customer.delivery.city">{{ $customer->delivery->zip }} {{ $customer->delivery->city }}</div>
<div x-text="customer.delivery.phone">{{ $customer->delivery->phone }}</div>
<div x-text="customer.delivery.email">{{ $customer->delivery->email }}</div>
</div>
@endif
</div>
</section>
</div>
</div>
<div class="p-4 sm:p-8 bg-white dark:bg-gray-800 shadow sm:rounded-lg">
<div class="max-w">
<section>
<header>
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
{{ __('invoice.Invoices') }}
</h2>
</header>
<summary class="cursor-pointer flex flex-row w-full mt-4">
<div class="w-1/6 font-bold border-b-2">{{ __('invoice.Invoice Number') }}</div>
<div class="w-1/3 font-bold border-b-2">{{ __('common.Name') }}</div>
<div class="w-1/6 font-bold border-b-2">{{ __('invoice.State') }}</div>
<div class="w-1/6 font-bold border-b-2 text-right">{{ __('invoice.Sum') }}</div>
<div class="w-1/6 font-bold border-b-2 text-right">{{ __('common.Created at') }}</div>
</summary>
@php
$sum = 0;
@endphp
@foreach($customer->invoices as $invoice)
@php($sum += $invoice->sum)
<details class="even:bg-gray-100 odd:bg-white hover:bg-gray-400">
<summary class="cursor-pointer flex flex-row w-full" onclick="window.location.href='/invoice/{{ $invoice->id }}'">
<div class="w-1/6">{{ $invoice->number }}</div>
<div class="w-1/3">{{ $invoice->address->name }}</div>
<div class="w-1/6">{{ $invoice->localized_state }}</div>
<div class="w-1/6 text-right">{{ \Illuminate\Support\Number::currency($invoice->sum) }}</div>
<div class="w-1/6 text-right">{{ $invoice->created }}</div>
</summary>
</details>
@endforeach
<div class="flex flex-row font-bold border-t-2">
<div class="w-1/6"></div>
<div class="w-1/3">{{ __('invoice.Sum') }}</div>
<div class="w-1/3 text-right" x-text="invoice.sum + ' €'">{{ \Illuminate\Support\Number::currency($sum) }}</div>
<div class="w-1/6 text-right" x-text="invoice.created"></div>
</div>
</section>
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@@ -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');