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:
@@ -226,6 +226,13 @@ new class extends Component
|
||||
$this->js("document.getElementById('orders-status')?.focus()");
|
||||
}
|
||||
|
||||
public function edit(int $orderId): void
|
||||
{
|
||||
$this->authorize('sales.use');
|
||||
|
||||
$this->dispatch('edit-quick-sale-order', orderId: $this->order($orderId)->id);
|
||||
}
|
||||
|
||||
public function confirmCancel(int $orderId): void
|
||||
{
|
||||
$this->authorize('sales.use');
|
||||
@@ -408,6 +415,9 @@ new class extends Component
|
||||
@else
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<x-button wire:click="startPay({{ $order->id }})" sm icon="banknotes" :text="__('sales.orders.pay')" :aria-label="__('sales.orders.pay_named', ['number' => $order->pickupNumber])" />
|
||||
@if ($order->canBeChanged)
|
||||
<x-button wire:click="edit({{ $order->id }})" subtle color="black" sm icon="pencil" :text="__('sales.orders.change')" :aria-label="__('sales.orders.change_named', ['number' => $order->pickupNumber])" />
|
||||
@endif
|
||||
<x-button wire:click="confirmCancel({{ $order->id }})" subtle color="black" sm icon="x-mark" :text="__('sales.orders.cancel')" :aria-label="__('sales.orders.cancel_named', ['number' => $order->pickupNumber])" />
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@@ -4,6 +4,10 @@ use App\Modules\Customers\Application\Contracts\CustomerQueries;
|
||||
use App\Modules\Customers\Application\DTOs\CustomerSummary;
|
||||
use App\Modules\Sales\Application\Contracts\QuickSaleProducts;
|
||||
use App\Modules\Sales\Application\Contracts\ProductionProcesses;
|
||||
use App\Modules\Sales\Application\Contracts\QuickSaleOrderQueries;
|
||||
use App\Modules\Sales\Domain\Exceptions\QuickSaleOrderClosed;
|
||||
use App\Modules\Sales\Domain\Exceptions\QuickSaleOrderInProduction;
|
||||
use App\Modules\Sales\Domain\Exceptions\QuickSaleOrderNotFound;
|
||||
use App\Modules\Sales\Application\DTOs\OrderData;
|
||||
use App\Modules\Sales\Application\DTOs\SaleData;
|
||||
use App\Modules\Sales\Application\UseCases\QuickSaleOrders;
|
||||
@@ -22,6 +26,7 @@ use App\Modules\Shared\Domain\Exceptions\InvalidEmailAddress;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
@@ -74,6 +79,57 @@ new class extends Component
|
||||
|
||||
public string $orderCustomerName = '';
|
||||
|
||||
/**
|
||||
* The open order being changed on this form, if any (spec 19.7).
|
||||
*/
|
||||
#[Locked]
|
||||
public ?int $editingOrderId = null;
|
||||
|
||||
#[Locked]
|
||||
public ?int $editingPickupNumber = null;
|
||||
|
||||
/**
|
||||
* Loads an order whose making has not started into the form to change
|
||||
* its products and customer.
|
||||
*/
|
||||
#[On('edit-quick-sale-order')]
|
||||
public function editOrder(int $orderId): void
|
||||
{
|
||||
$this->authorize('sales.use');
|
||||
|
||||
$order = app(QuickSaleOrderQueries::class)->findOrder($orderId) ?? abort(404);
|
||||
|
||||
if (! $order->canBeChanged) {
|
||||
$this->addError('sale', __('sales.orders.errors.started'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->reset('quantities', 'cartMessage', 'savedMessage', 'hoursMessage', 'savedSaleId', 'savedPickupNumber');
|
||||
|
||||
foreach ($order->lines as $line) {
|
||||
$this->quantities[$line->productId] = $line->quantity;
|
||||
}
|
||||
|
||||
$this->editingOrderId = $order->id;
|
||||
$this->editingPickupNumber = $order->pickupNumber;
|
||||
$this->customerId = $order->customerId;
|
||||
$this->customerName = $order->customerId === null ? '' : (string) $order->customerName;
|
||||
$this->orderCustomerName = $order->customerId === null ? (string) $order->customerName : '';
|
||||
$this->resetErrorBag();
|
||||
$this->forgetLines();
|
||||
$this->cartMessage = __('sales.orders.editing', ['number' => $order->pickupNumber]);
|
||||
$this->js("document.getElementById('cart-heading')?.focus()");
|
||||
}
|
||||
|
||||
public function stopEditing(): void
|
||||
{
|
||||
$this->reset('quantities', 'customerSearch', 'customerId', 'customerName', 'orderCustomerName', 'editingOrderId', 'editingPickupNumber');
|
||||
$this->forgetLines();
|
||||
$this->cartMessage = __('sales.orders.editing_stopped');
|
||||
$this->js("document.getElementById('cart-heading')?.focus()");
|
||||
}
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->authorize('sales.use');
|
||||
@@ -257,7 +313,7 @@ new class extends Component
|
||||
$this->savedSaleId = null;
|
||||
$this->savedPickupNumber = null;
|
||||
|
||||
if ($this->isOrder()) {
|
||||
if ($this->isOrder() || $this->editingOrderId !== null) {
|
||||
$this->sendOrder($orders);
|
||||
|
||||
return;
|
||||
@@ -334,11 +390,24 @@ new class extends Component
|
||||
{
|
||||
$this->validate(['orderCustomerName' => ['nullable', 'string', 'max:150']]);
|
||||
|
||||
$data = new OrderData($this->quantities, $this->customerId, $this->orderCustomerName);
|
||||
|
||||
try {
|
||||
$result = $orders->send((int) auth()->id(), new OrderData($this->quantities, $this->customerId, $this->orderCustomerName));
|
||||
} catch (QuickSaleEmpty|InvalidQuantity|OrderHasNoProduction) {
|
||||
$result = $this->editingOrderId === null
|
||||
? $orders->send((int) auth()->id(), $data)
|
||||
: $orders->change($this->editingOrderId, $data);
|
||||
} catch (QuickSaleEmpty|InvalidQuantity) {
|
||||
$this->addError('quantities', __('sales.errors.empty'));
|
||||
|
||||
return;
|
||||
} catch (OrderHasNoProduction) {
|
||||
$this->addError('quantities', __($this->editingOrderId === null ? 'sales.errors.empty' : 'sales.orders.errors.no_production'));
|
||||
|
||||
return;
|
||||
} catch (QuickSaleOrderInProduction|QuickSaleOrderClosed|QuickSaleOrderNotFound) {
|
||||
$this->addError('sale', __('sales.orders.errors.started'));
|
||||
$this->stopEditing();
|
||||
|
||||
return;
|
||||
} catch (ProductNotSellable $exception) {
|
||||
unset($this->quantities[$exception->id], $this->products);
|
||||
@@ -354,9 +423,9 @@ new class extends Component
|
||||
}
|
||||
|
||||
$this->savedPickupNumber = $result->pickupNumber;
|
||||
$this->savedMessage = __('sales.orders.sent', ['number' => $result->pickupNumber, 'total' => $this->money($result->totalCents)]);
|
||||
$this->savedMessage = __($this->editingOrderId === null ? 'sales.orders.sent' : 'sales.orders.changed', ['number' => $result->pickupNumber, 'total' => $this->money($result->totalCents)]);
|
||||
|
||||
$this->reset('quantities', 'paymentMethod', 'customerSearch', 'customerId', 'customerName', 'cartMessage', 'receiptEmail', 'orderCustomerName');
|
||||
$this->reset('quantities', 'paymentMethod', 'customerSearch', 'customerId', 'customerName', 'cartMessage', 'receiptEmail', 'orderCustomerName', 'editingOrderId', 'editingPickupNumber');
|
||||
$this->forgetLines();
|
||||
$this->dispatch('quick-sale-orders-changed');
|
||||
|
||||
@@ -536,9 +605,16 @@ new class extends Component
|
||||
</p>
|
||||
</section>
|
||||
|
||||
@php($isOrder = $this->isOrder())
|
||||
@php($isOrder = $this->isOrder() || $editingOrderId !== null)
|
||||
|
||||
<form wire:submit="save" class="space-y-6" novalidate>
|
||||
@if ($editingOrderId !== null)
|
||||
<div class="flex flex-wrap items-center gap-3 rounded-lg border border-zinc-400 p-3 text-sm dark:border-zinc-500">
|
||||
<x-icon name="pencil" class="size-5 shrink-0" aria-hidden="true" />
|
||||
<p class="grow">{{ __('sales.orders.editing_notice', ['number' => $editingPickupNumber]) }}</p>
|
||||
<x-button id="stop-editing" wire:click="stopEditing" subtle color="black" sm :text="__('sales.orders.stop_editing')" />
|
||||
</div>
|
||||
@endif
|
||||
@if ($isOrder)
|
||||
<p class="flex items-start gap-2 rounded-lg border border-zinc-400 p-3 text-sm dark:border-zinc-500">
|
||||
<x-icon name="printer" class="size-5 shrink-0" aria-hidden="true" />
|
||||
@@ -616,7 +692,7 @@ new class extends Component
|
||||
/>
|
||||
@endunless
|
||||
|
||||
<x-button submit lg class="w-full" :text="$isOrder ? __('sales.orders.send') : __('sales.sell.save')" />
|
||||
<x-button submit lg class="w-full" :text="$editingOrderId !== null ? __('sales.orders.save_change') : ($isOrder ? __('sales.orders.send') : __('sales.sell.save'))" />
|
||||
</form>
|
||||
@endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user