From 0f5ab9e5ead58d444714f4c74f1a6f95ec9852cd Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 19 Apr 2025 12:11:01 +0530 Subject: [PATCH] Added transaction chart --- .../Resources/ProductionQuantityResource.php | 47 +++++++++++++++++-- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/app/Filament/Resources/ProductionQuantityResource.php b/app/Filament/Resources/ProductionQuantityResource.php index 7a4ef8724..65a1ae77e 100644 --- a/app/Filament/Resources/ProductionQuantityResource.php +++ b/app/Filament/Resources/ProductionQuantityResource.php @@ -22,7 +22,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope; use Filament\Forms\Components\Section; use Filament\Notifications\Notification; use Filament\Tables\Actions\ExportAction; -//use Livewire\Livewire; +use Livewire\Livewire; class ProductionQuantityResource extends Resource { @@ -33,6 +33,7 @@ class ProductionQuantityResource extends Resource // protected static ?string $navigationParentItem = 'Display Transactions'; protected static ?string $navigationGroup = 'Production'; + public $plant_id; public static function form(Form $form): Form @@ -45,7 +46,7 @@ class ProductionQuantityResource extends Resource ->relationship('plant', 'name') ->required() // ->nullable() - ->reactive() + ->reactive() // ->default(fn () => optional(ProductionQuantity::latest()->first())->plant_id) ->default(function () { return optional(ProductionQuantity::latest()->first())->plant_id; @@ -54,8 +55,19 @@ class ProductionQuantityResource extends Resource // ->afterStateUpdated(fn ($set) => $set('block_name', null)) ->afterStateUpdated(function ($state, callable $set, callable $get) { $plantId = $get('plant_id'); + + //... + + // $set('plantId', $state); + + session(['select_plant' => $state]); + session()->forget('select_line'); // Reset line filter + + //... + $set('block_name', null); - if (!$plantId) { + if (!$plantId) + { $set('pqPlantError', 'Please select a plant first.'); return; } @@ -64,7 +76,24 @@ class ProductionQuantityResource extends Resource $set('validationError', null); $set('pqPlantError', null); } + }) + ->extraAttributes([ + 'x-on:change' => " + if (\$event.target.value) { + \$wire.dispatch('filtersUpdated', { plantId: \$event.target.value }); + } + ", + ]) + + // ->extraAttributes([ + // 'x-on:change' => "\$wire.dispatch('filtersUpdated', { plantId: \$event.target.value })" + // ]) + // ->extraAttributes([ + // 'x-on:change' => "\$wire.set('plantId', \$event.target.value)" + // ]) + + ->extraAttributes(fn ($get) => [ 'class' => $get('pqPlantError') ? 'border-red-500' : '', ]) @@ -230,7 +259,16 @@ class ProductionQuantityResource extends Resource // $set('recent_qr', null); // } } + + //.. + session(['select_line' => $state]); }) + // ->extraAttributes([ + // 'x-on:change' => "\$wire.dispatch('filtersUpdated')", // Dispatch Livewire event from Alpine.js + // ]) + ->extraAttributes([ + 'x-on:change' => "\$wire.dispatch('filtersUpdated', { lineId: \$event.target.value })" + ]) ->extraAttributes(fn ($get) => [ 'class' => $get('pqLineError') ? 'border-red-500' : '', ]) @@ -335,7 +373,7 @@ class ProductionQuantityResource extends Resource [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0]; $hRs = (int) $hRs; - // $miNs = (int) $miNs;-*/ + //$miNs = (int) $miNs;-*/ $totalMinutes = $hRs * 60 + $miNs; @@ -793,6 +831,7 @@ class ProductionQuantityResource extends Resource ]); } + public static function table(Table $table): Table { return $table