1
0
forked from poc/pds

Updated navigation order / label and Added export pdf func. and commented chart func.

This commit is contained in:
dhanabalan
2025-04-28 00:28:42 +05:30
parent 4633066b13
commit f014d9fd42

View File

@@ -2,16 +2,19 @@
namespace App\Filament\Resources;
use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction as ActionsFilamentExportBulkAction;
use App\Filament\Exports\ProductionQuantityExporter;
use App\Filament\Imports\ProductionQuantityImporter;
use App\Filament\Resources\ProductionQuantityResource\Pages;
use App\Filament\Resources\ProductionQuantityResource\RelationManagers;
use App\Forms\Components\PlantSelect;
use App\Models\Item;
use App\Models\ProductionQuantity;
use App\Models\Shift;
use Carbon\Carbon;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
@@ -21,21 +24,30 @@ use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Notifications\Notification;
use Filament\Tables\Actions\ExportAction;
use Livewire\Livewire;
// use Filament\Forms\Components\View;
use Filament\Tables\Actions\FilamentExportBulkAction;
class ProductionQuantityResource extends Resource
{
protected static ?string $model = ProductionQuantity::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
// protected static ?string $navigationParentItem = 'Display Transactions';
// protected static string $view = 'filament.pages.hourly-production';
protected static ?string $navigationGroup = 'Production';
protected static ?int $navigationSort = 1;
// public $plant_id;
public static function form(Form $form): Form
{
@@ -48,6 +60,7 @@ class ProductionQuantityResource extends Resource
->required()
// ->nullable()
->reactive()
// ->statePath('filters')
->columnSpan(2) //1
// ->default(fn () => optional(ProductionQuantity::latest()->first())->plant_id)
->default(function () {
@@ -55,16 +68,9 @@ class ProductionQuantityResource extends Resource
})
->disabled(fn (Get $get) => !empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
->afterStateUpdated(function ($state, $set, callable $get,$livewire) {
$plantId = $get('plant_id');
//...
session(['select_plant' => $state]);
session()->forget('select_line'); // Reset line filter
//...
$set('block_name', null);
if (!$plantId)
{
@@ -78,13 +84,14 @@ class ProductionQuantityResource extends Resource
}
})
->extraAttributes([
'x-on:change' => "
if (\$event.target.value) {
\$wire.dispatch('filtersUpdated', { plantId: \$event.target.value });
}
",
])
// ->extraAttributes([
// 'x-on:change' => "
// if (\$event.target.value) {
// \$wire.dispatch('plant-updated', { plantId: \$event.target.value });
// }
// ",
// ])
// ->extraAttributes([
// 'x-on:change' => "\$wire.dispatch('filtersUpdated', { plantId: \$event.target.value })"
@@ -93,12 +100,25 @@ class ProductionQuantityResource extends Resource
// 'x-on:change' => "\$wire.set('plantId', \$event.target.value)"
// ])
// ->extraAttributes([
// 'x-on:change' => '$dispatch("plant-updated", { plantId: $event.target.value })',
// // Dispatch Alpine event
// ])
// ->extraAttributes([
// 'x-on:change' => '$dispatch("plant-updated", { plantId: $event.target.value }); console.log("Plant updated:", $event.target.value);',
// ])
->extraAttributes(fn ($get) => [
'class' => $get('pqPlantError') ? 'border-red-500' : '',
])
// ->extraAttributes([
// 'x-data' => '{ value: "" }',
// 'x-model' => 'value',
// 'wire:keydown.enter.prevent' => 'processSelectedPlant(value)', // Call Livewire method
// ])
->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null)
->hintColor('danger'),
Forms\Components\Select::make('block_name')
->label('Block')
->required()
@@ -133,8 +153,8 @@ class ProductionQuantityResource extends Resource
$blockId = $get('block_name');
$set('shift_id', null);
session(['select_plant' => $get('plant_id')]);
session()->forget('select_line');
// session(['select_plant' => $get('plant_id')]);
// session()->forget('select_line');
if (!$blockId) {
$set('pqBlockError', 'Please select a block first.');
@@ -185,9 +205,6 @@ class ProductionQuantityResource extends Resource
$curShiftId = $get('shift_id');
$set('line_id', null);
session(['select_plant' => $get('plant_id')]);
session()->forget('select_line');
if (!$curShiftId) {
$set('pqShiftError', 'Please select a shift first.');
return;
@@ -240,8 +257,8 @@ class ProductionQuantityResource extends Resource
$lineId = $get('line_id');
$set('item_code', null);
session(['select_plant' => $get('plant_id')]);
session()->forget('select_line');
// session(['select_line' => $get('line_id')]);
session(['select_line' => $state]);
if (!$lineId) {
@@ -873,35 +890,6 @@ class ProductionQuantityResource extends Resource
'x-data' => '{ value: "" }',
'x-model' => 'value',
'wire:keydown.enter.prevent' => 'processAllValues(value)',
// 'x-data' => '{ value: "" }',
// 'x-model' => 'value',
// 'x-on:keydown.enter.prevent' => '$wire.processQr(value)',
//'wire:keydown.enter.prevent' => 'processQr(value)',
//working fine on text enter
// 'x-data' => '{}',
// 'x-on:keydown.enter.prevent' => '
// const formData = new FormData($event.target.form);
// const data = Object.fromEntries(formData.entries());
// $wire.processAllValues(data)
// ',
// 'x-data' => '{}',
// 'x-on:change' => '
// const formData = new FormData($event.target.form);
// const data = Object.fromEntries(formData.entries());
// $wire.processAllValues(data)
// ',
// 'x-data' => '{}',
// 'x-on:keydown.enter.prevent' => '
// $event.target.blur(); // Ensures value is updated
// setTimeout(() => {
// const formData = new FormData($event.target.form);
// const data = Object.fromEntries(formData.entries());
// $wire.processAllValues(data)
// }, 10); // Small delay to allow value update
// ',
]),
Forms\Components\Hidden::make('serial_number')
->required(),
@@ -940,8 +928,6 @@ class ProductionQuantityResource extends Resource
->default(Filament::auth()->user()->name),
])
->columns(12), //6
//View::make('filament.pages.hourly-production'),
]);
}
@@ -996,6 +982,7 @@ class ProductionQuantityResource extends Resource
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
ActionsFilamentExportBulkAction::make('export')
]),
])
->headerActions([
@@ -1014,6 +1001,12 @@ class ProductionQuantityResource extends Resource
]);
}
// public function updatedDataPlantId($value)
// {
// session(['select_plant' => $value]);
// $this->dispatch('filtersUpdated', $value);
// }
public static function getRelations(): array
{
return [
@@ -1039,6 +1032,26 @@ class ProductionQuantityResource extends Resource
]);
}
public static function getNavigationLabel(): string
{
return 'Production Reports';
}
// public function triggerChartUpdate(): void
// {
// if (session()->has('select_plant') && session()->has('select_line')) {
// $this->dispatch('filtersUpdated');
// }
// }
// public function updatedDataPlantId($newPlantId)
// {
// session(['select_plant' => $newPlantId]);
// $this->emit('filtersUpdated', $newPlantId);
// }
// public function mount(): void
// {
// // Fetch the value from the database based on your conditions