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
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace App\Modules\Sales\Application\UseCases;
use App\Modules\Sales\Application\Contracts\ReceiptMailer;
use App\Modules\Sales\Domain\Contracts\QuickSaleRepository;
use App\Modules\Sales\Domain\Exceptions\QuickSaleNotFound;
use App\Modules\Shared\Application\Contracts\TransactionManager;
use App\Modules\Shared\Domain\Exceptions\InvalidEmailAddress;
use App\Modules\Shared\Domain\ValueObjects\EmailAddress;
/**
* Emails a sale's receipt again, to the stored address or a corrected one,
* which replaces it on the sale. Who may do this is checked by the caller.
*/
final class ResendQuickSaleReceipt
{
public function __construct(
private QuickSaleRepository $sales,
private ReceiptMailer $mailer,
private TransactionManager $transactions,
) {}
/**
* @throws QuickSaleNotFound
* @throws InvalidEmailAddress
*/
public function execute(int $saleId, string $email): void
{
$address = new EmailAddress($email);
$this->transactions->run(function () use ($saleId, $address): void {
$this->sales->findById($saleId) ?? throw new QuickSaleNotFound($saleId);
$this->sales->changeReceiptEmail($saleId, $address);
});
$this->mailer->send($saleId);
}
}