Skip to content

Commit

Permalink
✨ feat: enforce-stock-quantity-limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Hertzogjr committed May 3, 2024
1 parent 4bc3769 commit 2cab760
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/Filament/Resources/OrderResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
use Illuminate\Contracts\Database\Eloquent\Builder;
use Livewire\Attributes\On;


class OrderResource extends Resource
{
protected static ?string $model = Order::class;
Expand Down Expand Up @@ -337,7 +336,13 @@ public static function getItemsRepeater(): Repeater
return !is_null($stock) ? "{$stock} em estoque" : null;
})
->afterStateUpdated(function ($state, $set, $get) {
$stock = Product::find($get('product_id'))?->in_stock;

if($state > $stock) {
$state = $stock;
$set('quantity', $stock);
}

$unit_price = $get('unit_price');

$sub_total = number_format((float)$state * $unit_price, 2, '.', '');
Expand Down

0 comments on commit 2cab760

Please sign in to comment.