Email quick sale receipts and send them again from the sales list

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-26 16:00:15 +02:00
co-authored by Claude Sonnet 5.5
parent 3faa4cfbc6
commit d160854b79
29 changed files with 679 additions and 34 deletions
@@ -6,6 +6,7 @@ use App\Modules\Sales\Application\DTOs\QuickSaleSummary;
use App\Modules\Sales\Application\UseCases\CloseCashDay;
use App\Modules\Sales\Application\UseCases\CreditQuickSale;
use App\Modules\Sales\Application\UseCases\ReopenCashDay;
use App\Modules\Sales\Application\UseCases\ResendQuickSaleReceipt;
use App\Modules\Sales\Domain\Exceptions\CashDayClosed;
use App\Modules\Sales\Domain\Exceptions\CashDayInFuture;
use App\Modules\Sales\Domain\Exceptions\CashDayNotClosed;
@@ -13,6 +14,7 @@ use App\Modules\Sales\Domain\Exceptions\CreditCannotBeCredited;
use App\Modules\Sales\Domain\Exceptions\QuickSaleAlreadyCredited;
use App\Modules\Sales\Domain\Exceptions\QuickSaleNotFound;
use App\Modules\Sales\Presentation\Livewire\Concerns\FormatsSales;
use App\Modules\Shared\Domain\Exceptions\InvalidEmailAddress;
use App\Modules\Users\Application\Contracts\Clock;
use App\Modules\Users\Application\Contracts\UserAccountQueries;
use App\Modules\Users\Application\DTOs\UserOption;
@@ -27,7 +29,8 @@ use Livewire\Component;
* A day's quick sales and its cash day (kassapäivä). Sellers see their own
* sales, management everyone's. Anyone selling may close the day, which
* forms its balance; management may reopen it. Sales are credited, never
* deleted.
* deleted. An emailed receipt's state is shown on its row, and a receipt
* can be emailed again, to a corrected address if need be.
*/
new class extends Component
{
@@ -52,6 +55,11 @@ new class extends Component
#[Locked]
public string $statusMessage = '';
#[Locked]
public ?int $resendSaleId = null;
public string $resendEmail = '';
public function mount(Clock $clock): void
{
$this->authorize('sales.use');
@@ -155,6 +163,42 @@ new class extends Component
$this->js("document.getElementById('credit-dialog').close(); document.getElementById('sales-status').focus()");
}
public function confirmResend(int $saleId): void
{
$sale = app(QuickSaleQueries::class)->findSale($saleId) ?? abort(404);
$this->authorize('sales.view-sale', $sale->sellerId);
$this->resendSaleId = $saleId;
$this->resendEmail = $sale->receiptEmail ?? '';
$this->resetErrorBag('resendEmail');
$this->js("document.getElementById('resend-dialog').showModal()");
}
public function resend(ResendQuickSaleReceipt $resendQuickSaleReceipt): void
{
$sale = app(QuickSaleQueries::class)->findSale((int) $this->resendSaleId) ?? abort(404);
$this->authorize('sales.view-sale', $sale->sellerId);
$this->validate(
['resendEmail' => ['required', 'string', 'email', 'max:255']],
attributes: ['resendEmail' => __('sales.sell.receipt_email')],
);
try {
$resendQuickSaleReceipt->execute($sale->id, $this->resendEmail);
} catch (InvalidEmailAddress) {
$this->addError('resendEmail', __('sales.errors.receipt_email'));
return;
}
$this->statusMessage = __('sales.receipt_mail.resent', ['number' => $sale->id, 'email' => mb_strtolower(trim($this->resendEmail))]);
$this->resendSaleId = null;
$this->resendEmail = '';
unset($this->sales);
$this->js("document.getElementById('resend-dialog').close(); document.getElementById('sales-status').focus()");
}
public function confirmClose(): void
{
$this->authorize('sales.close-day');
@@ -425,6 +469,29 @@ new class extends Component
<x-icon name="document-text" class="size-4" aria-hidden="true" />
{{ __('sales.receipt_link') }}
</a>
@if ($sale->receiptStatus() !== null)
<span class="mr-2 inline-flex items-center gap-1 text-xs">
@if ($sale->receiptStatus() === 'failed')
<x-icon name="exclamation-triangle" class="size-4 text-red-700 dark:text-red-400" aria-hidden="true" />
@elseif ($sale->receiptStatus() === 'sent')
<x-icon name="envelope" class="size-4" aria-hidden="true" />
@else
<x-icon name="clock" class="size-4" aria-hidden="true" />
@endif
{{ __('sales.receipt_mail.status_'.$sale->receiptStatus()) }}
</span>
@endif
@can('sales.view-sale', $sale->sellerId)
<x-button
wire:click="confirmResend({{ $sale->id }})"
subtle
color="black"
sm
icon="envelope"
:text="__('sales.receipt_mail.send')"
:aria-label="__('sales.receipt_mail.send_named', ['number' => $sale->id])"
/>
@endcan
@if ($sale->canBeCredited())
@can('sales.credit', $sale->sellerId)
<x-button
@@ -454,6 +521,17 @@ new class extends Component
</x-slot:actions>
</x-confirm-dialog>
<x-confirm-dialog id="resend-dialog" :title="__('sales.receipt_mail.send_title')">
@if ($resendSaleId !== null)
<p class="mb-3">{{ __('sales.receipt_mail.send_text', ['number' => $resendSaleId]) }}</p>
@endif
<x-input id="resend-email" wire:model="resendEmail" type="email" inputmode="email" autocomplete="off" :label="__('sales.sell.receipt_email')" />
<x-slot:actions>
<x-button wire:click="resend" icon="envelope" :text="__('sales.receipt_mail.send_confirm')" />
</x-slot:actions>
</x-confirm-dialog>
<x-confirm-dialog id="close-dialog" :title="__('sales.cash_day.close_title')">
<p>{{ __('sales.cash_day.close_text') }}</p>
<p class="mt-2 font-medium">