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:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Modules\Sales\Domain\Contracts;
|
||||
|
||||
use App\Modules\Sales\Domain\Entities\QuickSale;
|
||||
use App\Modules\Shared\Domain\ValueObjects\EmailAddress;
|
||||
use DateTimeImmutable;
|
||||
|
||||
interface QuickSaleRepository
|
||||
@@ -24,4 +25,14 @@ interface QuickSaleRepository
|
||||
* @return list<QuickSale>
|
||||
*/
|
||||
public function forDay(DateTimeImmutable $day): array;
|
||||
|
||||
/**
|
||||
* Sets the address the receipt is emailed to and clears the earlier
|
||||
* sending result, before the receipt is sent again.
|
||||
*/
|
||||
public function changeReceiptEmail(int $saleId, EmailAddress $email): void;
|
||||
|
||||
public function markReceiptSent(int $saleId, DateTimeImmutable $at): void;
|
||||
|
||||
public function markReceiptFailed(int $saleId, DateTimeImmutable $at): void;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Modules\Sales\Domain\Enums\PaymentMethod;
|
||||
use App\Modules\Sales\Domain\Exceptions\CreditCannotBeCredited;
|
||||
use App\Modules\Sales\Domain\Exceptions\QuickSaleEmpty;
|
||||
use App\Modules\Sales\Domain\ValueObjects\QuickSaleLine;
|
||||
use App\Modules\Shared\Domain\ValueObjects\EmailAddress;
|
||||
use DateTimeImmutable;
|
||||
|
||||
/**
|
||||
@@ -30,6 +31,7 @@ final class QuickSale
|
||||
private DateTimeImmutable $soldOn,
|
||||
private array $lines,
|
||||
private ?int $creditsSaleId,
|
||||
private ?EmailAddress $receiptEmail = null,
|
||||
) {
|
||||
if ($lines === []) {
|
||||
throw new QuickSaleEmpty;
|
||||
@@ -42,9 +44,9 @@ final class QuickSale
|
||||
*
|
||||
* @throws QuickSaleEmpty
|
||||
*/
|
||||
public static function sell(int $sellerId, ?int $customerId, PaymentMethod $paymentMethod, array $lines, DateTimeImmutable $soldAt, DateTimeImmutable $soldOn): self
|
||||
public static function sell(int $sellerId, ?int $customerId, PaymentMethod $paymentMethod, array $lines, DateTimeImmutable $soldAt, DateTimeImmutable $soldOn, ?EmailAddress $receiptEmail = null): self
|
||||
{
|
||||
return new self(null, $sellerId, $customerId, $paymentMethod, $soldAt, $soldOn, $lines, null);
|
||||
return new self(null, $sellerId, $customerId, $paymentMethod, $soldAt, $soldOn, $lines, null, $receiptEmail);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,15 +67,16 @@ final class QuickSale
|
||||
$soldOn,
|
||||
array_map(fn (QuickSaleLine $line): QuickSaleLine => $line->negated(), $original->lines),
|
||||
$original->id,
|
||||
$original->receiptEmail,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<QuickSaleLine> $lines
|
||||
*/
|
||||
public static function reconstitute(int $id, int $sellerId, ?int $customerId, PaymentMethod $paymentMethod, DateTimeImmutable $soldAt, DateTimeImmutable $soldOn, array $lines, ?int $creditsSaleId): self
|
||||
public static function reconstitute(int $id, int $sellerId, ?int $customerId, PaymentMethod $paymentMethod, DateTimeImmutable $soldAt, DateTimeImmutable $soldOn, array $lines, ?int $creditsSaleId, ?EmailAddress $receiptEmail = null): self
|
||||
{
|
||||
return new self($id, $sellerId, $customerId, $paymentMethod, $soldAt, $soldOn, $lines, $creditsSaleId);
|
||||
return new self($id, $sellerId, $customerId, $paymentMethod, $soldAt, $soldOn, $lines, $creditsSaleId, $receiptEmail);
|
||||
}
|
||||
|
||||
public function totalCents(): int
|
||||
@@ -128,4 +131,9 @@ final class QuickSale
|
||||
{
|
||||
return $this->creditsSaleId;
|
||||
}
|
||||
|
||||
public function receiptEmail(): ?EmailAddress
|
||||
{
|
||||
return $this->receiptEmail;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user