Updated navigation order / label and Added export pdf func. and commented chart func.
This commit is contained in:
@@ -2,16 +2,19 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources;
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
|
use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction as ActionsFilamentExportBulkAction;
|
||||||
use App\Filament\Exports\ProductionQuantityExporter;
|
use App\Filament\Exports\ProductionQuantityExporter;
|
||||||
use App\Filament\Imports\ProductionQuantityImporter;
|
use App\Filament\Imports\ProductionQuantityImporter;
|
||||||
use App\Filament\Resources\ProductionQuantityResource\Pages;
|
use App\Filament\Resources\ProductionQuantityResource\Pages;
|
||||||
use App\Filament\Resources\ProductionQuantityResource\RelationManagers;
|
use App\Filament\Resources\ProductionQuantityResource\RelationManagers;
|
||||||
|
use App\Forms\Components\PlantSelect;
|
||||||
use App\Models\Item;
|
use App\Models\Item;
|
||||||
use App\Models\ProductionQuantity;
|
use App\Models\ProductionQuantity;
|
||||||
use App\Models\Shift;
|
use App\Models\Shift;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Components\Hidden;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Forms\Get;
|
use Filament\Forms\Get;
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
@@ -21,21 +24,30 @@ use Filament\Tables\Table;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
use Filament\Forms\Components\Section;
|
use Filament\Forms\Components\Section;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Forms\Concerns\InteractsWithForms;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Tables\Actions\ExportAction;
|
use Filament\Tables\Actions\ExportAction;
|
||||||
use Livewire\Livewire;
|
use Livewire\Livewire;
|
||||||
// use Filament\Forms\Components\View;
|
// use Filament\Forms\Components\View;
|
||||||
|
use Filament\Tables\Actions\FilamentExportBulkAction;
|
||||||
|
|
||||||
|
|
||||||
class ProductionQuantityResource extends Resource
|
class ProductionQuantityResource extends Resource
|
||||||
{
|
{
|
||||||
|
|
||||||
protected static ?string $model = ProductionQuantity::class;
|
protected static ?string $model = ProductionQuantity::class;
|
||||||
|
|
||||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||||
|
|
||||||
// protected static ?string $navigationParentItem = 'Display Transactions';
|
// protected static ?string $navigationParentItem = 'Display Transactions';
|
||||||
|
// protected static string $view = 'filament.pages.hourly-production';
|
||||||
|
|
||||||
protected static ?string $navigationGroup = 'Production';
|
protected static ?string $navigationGroup = 'Production';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 1;
|
||||||
|
|
||||||
|
|
||||||
// public $plant_id;
|
// public $plant_id;
|
||||||
public static function form(Form $form): Form
|
public static function form(Form $form): Form
|
||||||
{
|
{
|
||||||
@@ -48,6 +60,7 @@ class ProductionQuantityResource extends Resource
|
|||||||
->required()
|
->required()
|
||||||
// ->nullable()
|
// ->nullable()
|
||||||
->reactive()
|
->reactive()
|
||||||
|
// ->statePath('filters')
|
||||||
->columnSpan(2) //1
|
->columnSpan(2) //1
|
||||||
// ->default(fn () => optional(ProductionQuantity::latest()->first())->plant_id)
|
// ->default(fn () => optional(ProductionQuantity::latest()->first())->plant_id)
|
||||||
->default(function () {
|
->default(function () {
|
||||||
@@ -55,16 +68,9 @@ class ProductionQuantityResource extends Resource
|
|||||||
})
|
})
|
||||||
->disabled(fn (Get $get) => !empty($get('id')))
|
->disabled(fn (Get $get) => !empty($get('id')))
|
||||||
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
|
// ->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');
|
$plantId = $get('plant_id');
|
||||||
|
|
||||||
//...
|
|
||||||
|
|
||||||
session(['select_plant' => $state]);
|
|
||||||
session()->forget('select_line'); // Reset line filter
|
|
||||||
|
|
||||||
//...
|
|
||||||
|
|
||||||
$set('block_name', null);
|
$set('block_name', null);
|
||||||
if (!$plantId)
|
if (!$plantId)
|
||||||
{
|
{
|
||||||
@@ -78,13 +84,14 @@ class ProductionQuantityResource extends Resource
|
|||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
->extraAttributes([
|
// ->extraAttributes([
|
||||||
'x-on:change' => "
|
// 'x-on:change' => "
|
||||||
if (\$event.target.value) {
|
// if (\$event.target.value) {
|
||||||
\$wire.dispatch('filtersUpdated', { plantId: \$event.target.value });
|
// \$wire.dispatch('plant-updated', { plantId: \$event.target.value });
|
||||||
}
|
// }
|
||||||
",
|
// ",
|
||||||
])
|
// ])
|
||||||
|
|
||||||
|
|
||||||
// ->extraAttributes([
|
// ->extraAttributes([
|
||||||
// 'x-on:change' => "\$wire.dispatch('filtersUpdated', { plantId: \$event.target.value })"
|
// '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)"
|
// '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)
|
->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null)
|
||||||
->hintColor('danger'),
|
->hintColor('danger'),
|
||||||
|
|
||||||
Forms\Components\Select::make('block_name')
|
Forms\Components\Select::make('block_name')
|
||||||
->label('Block')
|
->label('Block')
|
||||||
->required()
|
->required()
|
||||||
@@ -133,8 +153,8 @@ class ProductionQuantityResource extends Resource
|
|||||||
$blockId = $get('block_name');
|
$blockId = $get('block_name');
|
||||||
$set('shift_id', null);
|
$set('shift_id', null);
|
||||||
|
|
||||||
session(['select_plant' => $get('plant_id')]);
|
// session(['select_plant' => $get('plant_id')]);
|
||||||
session()->forget('select_line');
|
// session()->forget('select_line');
|
||||||
|
|
||||||
if (!$blockId) {
|
if (!$blockId) {
|
||||||
$set('pqBlockError', 'Please select a block first.');
|
$set('pqBlockError', 'Please select a block first.');
|
||||||
@@ -185,9 +205,6 @@ class ProductionQuantityResource extends Resource
|
|||||||
$curShiftId = $get('shift_id');
|
$curShiftId = $get('shift_id');
|
||||||
$set('line_id', null);
|
$set('line_id', null);
|
||||||
|
|
||||||
session(['select_plant' => $get('plant_id')]);
|
|
||||||
session()->forget('select_line');
|
|
||||||
|
|
||||||
if (!$curShiftId) {
|
if (!$curShiftId) {
|
||||||
$set('pqShiftError', 'Please select a shift first.');
|
$set('pqShiftError', 'Please select a shift first.');
|
||||||
return;
|
return;
|
||||||
@@ -240,8 +257,8 @@ class ProductionQuantityResource extends Resource
|
|||||||
$lineId = $get('line_id');
|
$lineId = $get('line_id');
|
||||||
$set('item_code', null);
|
$set('item_code', null);
|
||||||
|
|
||||||
session(['select_plant' => $get('plant_id')]);
|
// session(['select_line' => $get('line_id')]);
|
||||||
session()->forget('select_line');
|
|
||||||
session(['select_line' => $state]);
|
session(['select_line' => $state]);
|
||||||
|
|
||||||
if (!$lineId) {
|
if (!$lineId) {
|
||||||
@@ -873,35 +890,6 @@ class ProductionQuantityResource extends Resource
|
|||||||
'x-data' => '{ value: "" }',
|
'x-data' => '{ value: "" }',
|
||||||
'x-model' => 'value',
|
'x-model' => 'value',
|
||||||
'wire:keydown.enter.prevent' => 'processAllValues(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')
|
Forms\Components\Hidden::make('serial_number')
|
||||||
->required(),
|
->required(),
|
||||||
@@ -940,8 +928,6 @@ class ProductionQuantityResource extends Resource
|
|||||||
->default(Filament::auth()->user()->name),
|
->default(Filament::auth()->user()->name),
|
||||||
])
|
])
|
||||||
->columns(12), //6
|
->columns(12), //6
|
||||||
|
|
||||||
//View::make('filament.pages.hourly-production'),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -996,6 +982,7 @@ class ProductionQuantityResource extends Resource
|
|||||||
Tables\Actions\DeleteBulkAction::make(),
|
Tables\Actions\DeleteBulkAction::make(),
|
||||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||||
Tables\Actions\RestoreBulkAction::make(),
|
Tables\Actions\RestoreBulkAction::make(),
|
||||||
|
ActionsFilamentExportBulkAction::make('export')
|
||||||
]),
|
]),
|
||||||
])
|
])
|
||||||
->headerActions([
|
->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
|
public static function getRelations(): array
|
||||||
{
|
{
|
||||||
return [
|
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
|
// public function mount(): void
|
||||||
// {
|
// {
|
||||||
// // Fetch the value from the database based on your conditions
|
// // Fetch the value from the database based on your conditions
|
||||||
|
|||||||
Reference in New Issue
Block a user