Change a quick sale order before making starts
An unpaid order whose lines have no completed step can be reopened in the cart from the open orders list; saving replaces its lines with current prices and processes, moves the machine work list rows and keeps the pickup number. Keyboard browser tests cover changing and cancelling an order and moving production steps. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -7,6 +7,7 @@ namespace App\Modules\Sales\Domain\Entities;
|
||||
use App\Modules\Sales\Domain\Enums\OrderStatus;
|
||||
use App\Modules\Sales\Domain\Exceptions\QuickSaleEmpty;
|
||||
use App\Modules\Sales\Domain\Exceptions\QuickSaleOrderClosed;
|
||||
use App\Modules\Sales\Domain\Exceptions\QuickSaleOrderInProduction;
|
||||
use App\Modules\Sales\Domain\Exceptions\QuickSaleOrderPaid;
|
||||
use DateTimeImmutable;
|
||||
|
||||
@@ -121,6 +122,54 @@ final class QuickSaleOrder
|
||||
$this->cancelledBy = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether no step has been completed on any line yet.
|
||||
*/
|
||||
public function canBeChanged(): bool
|
||||
{
|
||||
if ($this->paidAt !== null || $this->cancelledAt !== null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this->lines as $line) {
|
||||
if ($line->hasStarted()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the products and the customer before making has started; the
|
||||
* pickup number stays.
|
||||
*
|
||||
* @param list<OrderLine> $lines
|
||||
*
|
||||
* @throws QuickSaleOrderClosed
|
||||
* @throws QuickSaleOrderInProduction
|
||||
* @throws QuickSaleEmpty
|
||||
*/
|
||||
public function change(?int $customerId, ?string $customerName, array $lines): void
|
||||
{
|
||||
if ($this->paidAt !== null || $this->cancelledAt !== null) {
|
||||
throw new QuickSaleOrderClosed;
|
||||
}
|
||||
|
||||
if (! $this->canBeChanged()) {
|
||||
throw new QuickSaleOrderInProduction;
|
||||
}
|
||||
|
||||
if ($lines === []) {
|
||||
throw new QuickSaleEmpty;
|
||||
}
|
||||
|
||||
$customerName = $customerName === null ? null : mb_substr(trim($customerName), 0, 150);
|
||||
$this->customerId = $customerId;
|
||||
$this->customerName = $customerName === '' ? null : $customerName;
|
||||
$this->lines = $lines;
|
||||
}
|
||||
|
||||
public function lineById(int $lineId): ?OrderLine
|
||||
{
|
||||
foreach ($this->lines as $line) {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Sales\Domain\Exceptions;
|
||||
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
|
||||
final class QuickSaleOrderInProduction extends DomainException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('Making the order has already started, so it cannot be changed.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user