Files
Toiminnanohjaus/app/Modules/Customers/Presentation/Livewire/⚡show.blade.php
T
petriandClaude Opus 5.5 f4b58f6b1d Darken the dark canvas, add customer colours, the ongoing status and the board model
- Dark theme page background is #5a5e60; text on it is lifted to zinc-200 /
  primary-100 and TallStackUI's dark labels, hints and checkbox labels are
  lightened so everything stays at 4.5:1.
- Shared HexColor picks white or black text by the higher WCAG contrast; a
  native-dialog colour picker and a large work dialog component.
- Customers get a header colour (customers.header_color), set on the
  customer page.
- New job status Jatkuvat / Kausi (ongoing): open, never late, billed
  monthly like running jobs.
- Kanban model: board columns and views, urgent threshold, per-user board
  preferences (density, column colours and sort), card positions, tasks of
  continuing jobs pinned to the board, MoveBoardCard and board queries with
  logged hours from TimeTracking.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 06:11:49 +02:00

467 lines
19 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
use App\Modules\Customers\Application\Contracts\CustomerQueries;
use App\Modules\Customers\Application\DTOs\BillingUnitSummary;
use App\Modules\Customers\Application\DTOs\ContactSummary;
use App\Modules\Customers\Application\DTOs\CustomerSummary;
use App\Modules\Customers\Application\Services\CustomerRemoval;
use App\Modules\Customers\Application\UseCases\ChangeCustomerHeaderColor;
use App\Modules\Customers\Application\UseCases\RemoveBillingUnit;
use App\Modules\Customers\Application\UseCases\RemoveContact;
use App\Modules\Customers\Application\UseCases\RemoveCustomer;
use App\Modules\Customers\Domain\Exceptions\BillingUnitInUse;
use App\Modules\Customers\Domain\Exceptions\BillingUnitNotFound;
use App\Modules\Customers\Domain\Exceptions\ContactInUse;
use App\Modules\Customers\Domain\Exceptions\ContactNotFound;
use App\Modules\Customers\Domain\Exceptions\CustomerInUse;
use App\Modules\Customers\Domain\Exceptions\CustomerNotFound;
use App\Modules\Customers\Domain\Exceptions\InternalCustomerCannotBeRemoved;
use App\Modules\Customers\Domain\Enums\CustomerType;
use App\Modules\Shared\Domain\Exceptions\InvalidHexColor;
use Illuminate\Support\Facades\Gate;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Livewire\Component;
/**
* A customer's page: details, contacts and billing units. A customer with
* nothing linked to it can be removed here.
*/
new class extends Component
{
public const string REMOVE_DIALOG = 'remove-dialog';
#[Locked]
public int $customerId;
/**
* What the remove dialog asks about: 'customer', 'contact' or 'billing_unit'.
*/
#[Locked]
public ?string $removalType = null;
#[Locked]
public ?int $removalId = null;
#[Locked]
public string $removalName = '';
public string $statusMessage = '';
protected CustomerQueries $customerQueries;
protected CustomerRemoval $customerRemoval;
public function boot(CustomerQueries $customerQueries, CustomerRemoval $customerRemoval): void
{
$this->customerQueries = $customerQueries;
$this->customerRemoval = $customerRemoval;
}
public function mount(int $customer): void
{
$this->authorize('customers.use');
abort_if($this->customerQueries->findSummary($customer) === null, 404);
$this->customerId = $customer;
}
#[Computed]
public function customer(): CustomerSummary
{
return $this->customerQueries->findSummary($this->customerId) ?? abort(404);
}
/**
* The colour picker's "Use colour", or "Restore default colour" with null.
*/
public function setHeaderColor(?string $color, ChangeCustomerHeaderColor $changeColor): void
{
$this->authorize('customers.use');
try {
$changeColor->execute($this->customerId, $color);
} catch (InvalidHexColor) {
$this->statusMessage = __('customers.errors.invalid_header_color');
return;
} catch (CustomerNotFound) {
abort(404);
}
unset($this->customer);
$this->statusMessage = __('customers.header_color_saved');
}
/**
* The personal identity code as this user may see it: in full for admins
* and management, masked for others. Computed, so the full code is never
* kept in the component state sent to the browser.
*/
#[Computed]
public function personalIdentityCode(): ?string
{
if (Gate::allows('customers.view-personal-identity-code')) {
return $this->customerQueries->personalIdentityCodeOf($this->customerId);
}
return $this->customer->personalIdentityCodeMasked;
}
/**
* Whether nothing is linked to this customer, so the remove button is shown.
*/
#[Computed]
public function canBeRemoved(): bool
{
return $this->customerRemoval->canRemove($this->customerId);
}
/**
* @return list<ContactSummary>
*/
#[Computed]
public function contacts(): array
{
return $this->customerQueries->contactsOf($this->customerId);
}
/**
* @return list<BillingUnitSummary>
*/
#[Computed]
public function billingUnits(): array
{
return $this->customerQueries->billingUnitsOf($this->customerId);
}
/**
* Opens the remove dialog for this customer, or for one of its contacts
* or billing units.
*/
public function confirmRemoval(string $type, int $id): void
{
$this->authorize('customers.use');
$name = match ($type) {
'customer' => $id === $this->customerId ? $this->customerQueries->findSummary($id)?->name : null,
'contact' => $this->customerQueries->findContact($this->customerId, $id)?->name,
'billing_unit' => $this->customerQueries->findBillingUnit($this->customerId, $id)?->name,
default => null,
};
if ($name === null) {
$this->statusMessage = __('customers.removal.already_removed');
return;
}
$this->removalType = $type;
$this->removalId = $id;
$this->removalName = $name;
$this->statusMessage = '';
$this->js("document.getElementById('".self::REMOVE_DIALOG."').showModal()");
}
public function remove(RemoveContact $removeContact, RemoveBillingUnit $removeBillingUnit, RemoveCustomer $removeCustomer): void
{
$this->authorize('customers.use');
if ($this->removalType === null || $this->removalId === null) {
return;
}
if ($this->removalType === 'customer') {
$this->removeCustomer($removeCustomer);
return;
}
try {
match ($this->removalType) {
'contact' => $removeContact->execute($this->customerId, $this->removalId),
'billing_unit' => $removeBillingUnit->execute($this->customerId, $this->removalId),
};
$this->statusMessage = __('customers.removal.removed_'.$this->removalType, ['name' => $this->removalName]);
} catch (ContactNotFound|BillingUnitNotFound) {
$this->statusMessage = __('customers.removal.already_removed');
} catch (ContactInUse|BillingUnitInUse) {
$this->statusMessage = __('customers.removal.in_use_'.$this->removalType, ['name' => $this->removalName]);
}
// The removed row's button is gone, so focus moves to its section heading.
$heading = $this->removalType === 'contact' ? 'contacts-heading' : 'billing-units-heading';
$this->js("document.getElementById('".self::REMOVE_DIALOG."').close(); document.getElementById('{$heading}').focus()");
$this->reset('removalType', 'removalId', 'removalName');
}
/**
* Removes this customer and returns to the customer list, or tells why
* it was kept and moves focus back to the page heading.
*/
private function removeCustomer(RemoveCustomer $removeCustomer): void
{
try {
$removeCustomer->execute($this->customerId);
session()->flash('status', __('customers.removal.removed_customer', ['name' => $this->removalName]));
$this->redirectRoute('customers.index', navigate: true);
return;
} catch (CustomerNotFound) {
$this->statusMessage = __('customers.removal.already_removed');
} catch (InternalCustomerCannotBeRemoved) {
$this->statusMessage = __('customers.removal.internal_customer');
} catch (CustomerInUse) {
$this->statusMessage = __('customers.removal.in_use_customer', ['name' => $this->removalName]);
}
$this->js("document.getElementById('".self::REMOVE_DIALOG."').close(); document.getElementById('customer-heading').focus()");
$this->reset('removalType', 'removalId', 'removalName');
}
public function render(): mixed
{
return $this->view()->title($this->customer->name);
}
};
?>
<div class="mx-auto max-w-5xl space-y-8 p-4 sm:p-6">
<div class="space-y-4">
<a href="{{ route('customers.index') }}" wire:navigate class="inline-flex min-h-6 items-center gap-1 rounded-md text-sm font-medium text-primary-700 underline-offset-4 hover:underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 dark:text-primary-100 dark:focus-visible:outline-primary-300">
<x-icon name="arrow-left" class="size-4" aria-hidden="true" />{{ __('customers.title') }}
</a>
<div class="flex flex-wrap items-center justify-between gap-4">
<x-page-title icon="user-group" id="customer-heading" tabindex="-1" class="focus:outline-none">{{ $this->customer->name }}</x-page-title>
<div class="flex flex-wrap gap-2">
<x-button
:href="route('customers.edit', $customerId)"
wire:navigate
subtle
color="black"
icon="pencil"
:text="__('customers.edit_details')"
/>
<x-button
subtle
color="black"
icon="swatch"
:text="__('customers.fields.header_color')"
x-on:click="$dispatch('color-picker:open', {{ Js::from(['id' => 'colour-picker', 'title' => __('customers.header_color_title', ['name' => $this->customer->name]), 'color' => $this->customer->headerColor ?? '#23476a', 'method' => 'setHeaderColor', 'args' => [], 'resettable' => $this->customer->headerColor !== null]) }})"
/>
@if ($this->canBeRemoved)
<x-button
wire:click="confirmRemoval('customer', {{ $customerId }})"
subtle
color="black"
icon="trash"
:text="__('customers.remove_customer')"
/>
@endif
</div>
</div>
@if (session('status'))
<x-alert role="status" color="green" light icon="check-circle" :text="session('status')" />
@endif
<dl class="card grid gap-x-6 gap-y-2 text-sm sm:grid-cols-[max-content_1fr]">
<dt class="font-medium">{{ __('customers.fields.type') }}</dt>
<dd>
{{ __('customers.types.'.$this->customer->type->value) }}
@if ($this->customer->isInternal)
– {{ __('customers.internal') }}. {{ __('customers.internal_description') }}
@endif
</dd>
@if ($this->customer->businessId !== null)
<dt class="font-medium">{{ __('customers.fields.business_id') }}</dt>
<dd>{{ $this->customer->businessId }}</dd>
@endif
@if ($this->customer->type === CustomerType::Consumer)
<dt class="font-medium">{{ __('customers.fields.personal_identity_code') }}</dt>
<dd>
@if ($this->personalIdentityCode !== null)
{{ $this->personalIdentityCode }}
@else
<span class="inline-flex items-center gap-1">
<x-icon name="exclamation-triangle" class="size-4 shrink-0" aria-hidden="true" />
{{ __('customers.fields.personal_identity_code_missing') }}
</span>
@endif
</dd>
@endif
</dl>
<p role="status" aria-live="polite" class="text-sm">{{ $statusMessage }}</p>
</div>
<section aria-labelledby="contacts-heading" class="card space-y-4">
<div class="flex flex-wrap items-center justify-between gap-4">
<h2 id="contacts-heading" tabindex="-1" class="text-xl font-semibold focus:outline-none">
{{ __('customers.contacts.title') }}
</h2>
<x-button
:href="route('customers.contacts.create', $customerId)"
wire:navigate
icon="plus"
:text="__('customers.contacts.new')"
/>
</div>
@if ($this->contacts === [])
<x-empty-state icon="user-group">{{ __('customers.contacts.empty') }}</x-empty-state>
@else
<ul class="divide-y divide-zinc-200 rounded-lg border border-zinc-200 dark:divide-zinc-700 dark:border-zinc-700">
@foreach ($this->contacts as $contact)
<li wire:key="contact-{{ $contact->id }}" class="flex flex-wrap items-start justify-between gap-4 p-4">
<div class="min-w-0 space-y-1 text-sm">
<h3 class="text-base font-medium break-words">{{ $contact->name }}</h3>
@if ($contact->title !== null)
<p>{{ $contact->title }}</p>
@endif
@if ($contact->phone !== null)
<p>
<span class="sr-only">{{ __('customers.contacts.fields.phone') }}:</span>
<x-link :href="'tel:'.preg_replace('/[^\d+]/', '', $contact->phone)">{{ $contact->phone }}</x-link>
</p>
@endif
@if ($contact->email !== null)
<p class="break-all">
<span class="sr-only">{{ __('customers.contacts.fields.email') }}:</span>
<x-link :href="'mailto:'.$contact->email">{{ $contact->email }}</x-link>
</p>
@endif
@if ($contact->note !== null)
<p class="whitespace-pre-line text-zinc-600 dark:text-zinc-200">{{ $contact->note }}</p>
@endif
</div>
<div class="flex flex-wrap gap-2">
<x-button
:href="route('customers.contacts.edit', [$customerId, $contact->id])"
wire:navigate
subtle
color="black"
sm
icon="pencil"
:text="__('customers.edit')"
:aria-label="__('customers.contacts.edit_named', ['name' => $contact->name])"
/>
<x-button
wire:click="confirmRemoval('contact', {{ $contact->id }})"
subtle
color="black"
sm
icon="trash"
:text="__('customers.remove')"
:aria-label="__('customers.contacts.remove_named', ['name' => $contact->name])"
/>
</div>
</li>
@endforeach
</ul>
@endif
</section>
<section aria-labelledby="billing-units-heading" class="card space-y-4">
<div class="flex flex-wrap items-center justify-between gap-4">
<h2 id="billing-units-heading" tabindex="-1" class="text-xl font-semibold focus:outline-none">
{{ __('customers.billing_units.title') }}
</h2>
<x-button
:href="route('customers.billing-units.create', $customerId)"
wire:navigate
icon="plus"
:text="__('customers.billing_units.new')"
/>
</div>
@if ($this->billingUnits === [])
<x-empty-state icon="user-group">{{ __('customers.billing_units.empty') }}</x-empty-state>
@else
<ul class="divide-y divide-zinc-200 rounded-lg border border-zinc-200 dark:divide-zinc-700 dark:border-zinc-700">
@foreach ($this->billingUnits as $billingUnit)
<li wire:key="billing-unit-{{ $billingUnit->id }}" class="flex flex-wrap items-start justify-between gap-4 p-4">
<div class="min-w-0 space-y-1 text-sm">
<h3 class="text-base font-medium break-words">{{ $billingUnit->name }}</h3>
<dl class="grid gap-x-4 gap-y-1 sm:grid-cols-[max-content_1fr]">
@if ($billingUnit->billingAddress !== null)
<dt class="font-medium">{{ __('customers.billing_units.fields.billing_address') }}</dt>
<dd class="whitespace-pre-line">{{ $billingUnit->billingAddress }}</dd>
@endif
@if ($billingUnit->eInvoiceAddress !== null)
<dt class="font-medium">{{ __('customers.billing_units.fields.e_invoice_address') }}</dt>
<dd class="break-all">{{ $billingUnit->eInvoiceAddress }}</dd>
<dt class="font-medium">{{ __('customers.billing_units.fields.e_invoice_operator') }}</dt>
<dd class="break-all">{{ $billingUnit->eInvoiceOperator }}</dd>
@endif
@if ($billingUnit->reference !== null)
<dt class="font-medium">{{ __('customers.billing_units.fields.reference') }}</dt>
<dd class="break-words">{{ $billingUnit->reference }}</dd>
@endif
</dl>
</div>
<div class="flex flex-wrap gap-2">
<x-button
:href="route('customers.billing-units.edit', [$customerId, $billingUnit->id])"
wire:navigate
subtle
color="black"
sm
icon="pencil"
:text="__('customers.edit')"
:aria-label="__('customers.billing_units.edit_named', ['name' => $billingUnit->name])"
/>
<x-button
wire:click="confirmRemoval('billing_unit', {{ $billingUnit->id }})"
subtle
color="black"
sm
icon="trash"
:text="__('customers.remove')"
:aria-label="__('customers.billing_units.remove_named', ['name' => $billingUnit->name])"
/>
</div>
</li>
@endforeach
</ul>
@endif
</section>
<x-confirm-dialog id="remove-dialog" :title="__('customers.removal.title')">
<p>
@if ($removalType !== null)
{{ __('customers.removal.question_'.$removalType, ['name' => $removalName]) }}
@endif
</p>
<x-slot:actions>
<x-button wire:click="remove" color="red" icon="trash" :text="__('customers.remove')" />
</x-slot:actions>
</x-confirm-dialog>
<x-color-picker />
</div>