Let quick sale quantities be typed and specify quick sale production

Each line on the quick sale page gets a quantity field beside the
minus and plus buttons: the typed quantity is saved on change or
Enter, 0 removes the line and an invalid value keeps the old one
with an error.

The specification gets section 19.7 for phase 5: products with a
production process are sold as orders that go to a machine's work
list, are marked made at the machine (booking material and hours)
and are then paid in cash or by card.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-26 07:22:14 +02:00
co-authored by Claude Sonnet 5.5
parent 42b470d01c
commit 290936d8de
6 changed files with 123 additions and 20 deletions
@@ -33,7 +33,7 @@ new class extends Component
/**
* Quantities on the sale by product id, in the order added. Changed only
* by the add, decrease and remove actions.
* by the add, decrease, set and remove actions.
*
* @var array<int, int>
*/
@@ -148,6 +148,40 @@ new class extends Component
$this->changed($productId);
}
/**
* Sets a line's quantity typed in its field: 0 removes the line, and an
* invalid value keeps the old quantity with an error.
*/
public function setQuantity(int $productId, string $value): void
{
$this->authorize('sales.use');
if (! isset($this->quantities[$productId])) {
return;
}
$value = trim($value);
if (preg_match('/^\d{1,3}$/', $value) !== 1) {
$this->addError('quantities', __('sales.errors.quantity'));
$this->showQuantity($productId, $this->quantities[$productId]);
return;
}
$quantity = (int) $value;
if ($quantity === 0) {
$this->removeProduct($productId);
return;
}
$this->quantities[$productId] = min(QuickSaleLine::MAX_QUANTITY, $quantity);
$this->changed($productId);
$this->showQuantity($productId, $this->quantities[$productId]);
}
public function removeProduct(int $productId): void
{
$this->authorize('sales.use');
@@ -252,6 +286,15 @@ new class extends Component
]);
}
/**
* Puts the saved quantity back in the field, which is not bound to a
* property and so keeps what was typed (e.g. "03" or an invalid value).
*/
private function showQuantity(int $productId, int $quantity): void
{
$this->js("const field = document.getElementById('quantity-{$productId}'); if (field) { field.value = '{$quantity}'; }");
}
private function forgetLines(): void
{
unset($this->lines, $this->totalCents);
@@ -353,7 +396,20 @@ new class extends Component
</div>
<div class="flex items-center gap-1">
<x-button wire:click="decreaseProduct({{ $product->id }})" subtle color="black" sm icon="minus" :aria-label="__('sales.sell.decrease_named', ['product' => $product->name])" />
<span class="min-w-8 text-center font-medium" aria-hidden="true">{{ $line['quantity'] }}</span>
<label for="quantity-{{ $product->id }}" class="text-sm">{{ __('sales.sell.quantity') }}</label>
<input
id="quantity-{{ $product->id }}"
type="text"
inputmode="numeric"
pattern="[0-9]*"
maxlength="3"
autocomplete="off"
value="{{ $line['quantity'] }}"
wire:change="setQuantity({{ $product->id }}, $event.target.value)"
wire:keydown.enter.prevent="setQuantity({{ $product->id }}, $event.target.value)"
aria-label="{{ __('sales.sell.quantity_named', ['product' => $product->name]) }}"
class="h-9 w-14 rounded-md border border-zinc-500 bg-white px-2 text-center font-medium text-zinc-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:border-zinc-400 dark:bg-zinc-900 dark:text-zinc-100"
/>
<x-button wire:click="addProduct({{ $product->id }})" subtle color="black" sm icon="plus" :aria-label="__('sales.sell.increase_named', ['product' => $product->name])" />
<x-button wire:click="removeProduct({{ $product->id }})" subtle color="black" sm icon="trash" :aria-label="__('sales.sell.remove_named', ['product' => $product->name])" />
</div>