diff --git a/app/Filament/Resources/ProductionLineStopResource.php b/app/Filament/Resources/ProductionLineStopResource.php
index 396aeb3..fa4010b 100644
--- a/app/Filament/Resources/ProductionLineStopResource.php
+++ b/app/Filament/Resources/ProductionLineStopResource.php
@@ -48,6 +48,9 @@ class ProductionLineStopResource extends Resource
->required()
// ->nullable()
->reactive()
+ ->default(function () {
+ return optional(ProductionLineStop::latest()->first())->plant_id;
+ })
->disabled(fn (Get $get) => !empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -82,23 +85,18 @@ class ProductionLineStopResource extends Resource
->toArray();
})
->reactive()
- // ->default(function (callable $get, callable $set) {
- // if ($get('id')) {
- // $getShift = ProductionLineStop::where('id', $get('id'))->first();
- // $getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first();
- // // dd($getBlock->block_id);
- // $set('block_name', $getBlock->block_id);
- // }
- // // return null; // Return null if no default value should be set
- // })
+ ->default(function () {
+ $latestShiftId = optional(ProductionLineStop::latest()->first())->shift_id;
+ return optional(Shift::where('id', $latestShiftId)->first())->block_id;
+ })
// ->afterStateUpdated(fn ($set) => $set('shift_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
$getShift = ProductionLineStop::where('id', $get('id'))->first();
- // $getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first();
- $getBlock = Shift::where('id', $getShift->shift_id)->first();
- if($getBlock->block_id)
+ // $getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first();
+ $getBlock = Shift::where('id', $getShift->shift_id)->first();
+ if($getBlock->block_id)
{
$set('block_name', $getBlock->block_id);
$set('plsBlockError', null);
@@ -137,6 +135,9 @@ class ProductionLineStopResource extends Resource
->toArray();
})
->reactive()
+ ->default(function () {
+ return optional(ProductionLineStop::latest()->first())->shift_id;
+ })
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
@@ -181,6 +182,9 @@ class ProductionLineStopResource extends Resource
->toArray();
})
->reactive()
+ ->default(function () {
+ return optional(ProductionLineStop::latest()->first())->line_id;
+ })
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
@@ -481,7 +485,8 @@ class ProductionLineStopResource extends Resource
])
->headerActions([
ImportAction::make()
- ->importer(ProductionLineStopImporter::class),
+ ->importer(ProductionLineStopImporter::class)
+ ->maxRows(100000),
]);
}
diff --git a/app/Filament/Resources/ProductionPlanResource.php b/app/Filament/Resources/ProductionPlanResource.php
index 7aaceb5..c51116e 100644
--- a/app/Filament/Resources/ProductionPlanResource.php
+++ b/app/Filament/Resources/ProductionPlanResource.php
@@ -6,6 +6,7 @@ use App\Filament\Imports\ProductionPlanImporter;
use App\Filament\Resources\ProductionPlanResource\Pages;
use App\Filament\Resources\ProductionPlanResource\RelationManagers;
use App\Models\ProductionPlan;
+use App\Models\Shift;
use Carbon\Carbon;
use Filament\Forms;
use Filament\Forms\Form;
@@ -40,6 +41,9 @@ class ProductionPlanResource extends Resource
->required()
// ->nullable()
->reactive()
+ ->default(function () {
+ return optional(ProductionPlan::latest()->first())->plant_id;
+ })
->disabled(fn (Get $get) => !empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -73,12 +77,16 @@ class ProductionPlanResource extends Resource
->toArray();
})
->reactive()
+ ->default(function () {
+ $latestShiftId = optional(ProductionPlan::latest()->first())->shift_id;
+ return optional(Shift::where('id', $latestShiftId)->first())->block_id;
+ })
//->afterStateUpdated(fn ($set) => $set('shift_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
$getShift = ProductionPlan::where('id', $get('id'))->first();
- $getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first();
+ $getBlock = Shift::where('id', $getShift->shift_id)->first();
if($getBlock->block_id)
{
$set('block_name', $getBlock->block_id);
@@ -113,12 +121,15 @@ class ProductionPlanResource extends Resource
return [];
}
- return \App\Models\Shift::where('plant_id', $get('plant_id'))
+ return Shift::where('plant_id', $get('plant_id'))
->where('block_id', $get('block_name'))
->pluck('name', 'id')
->toArray();
})
->reactive()
+ ->default(function () {
+ return optional(ProductionPlan::latest()->first())->shift_id;
+ })
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
@@ -167,6 +178,9 @@ class ProductionPlanResource extends Resource
->toArray();
})
->reactive()
+ // ->default(function () {
+ // return optional(ProductionPlan::latest()->first())->line_id;
+ // })
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
@@ -223,7 +237,7 @@ class ProductionPlanResource extends Resource
//$currentDate = date('Y-m-d');
$yesterday = date('Y-m-d', strtotime('-1 days'));
- $shiftId = \App\Models\Shift::where('id', $get('shift_id'))
+ $shiftId = Shift::where('id', $get('shift_id'))
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
@@ -251,7 +265,7 @@ class ProductionPlanResource extends Resource
{
$currentDate = date('Y-m-d');
- $shiftId = \App\Models\Shift::where('id', $get('shift_id'))
+ $shiftId = Shift::where('id', $get('shift_id'))
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
@@ -285,7 +299,7 @@ class ProductionPlanResource extends Resource
//$currentDate = date('Y-m-d');
$yesterday = date('Y-m-d', strtotime('-1 days'));
- $shiftId = \App\Models\Shift::where('id', $get('shift_id'))
+ $shiftId = Shift::where('id', $get('shift_id'))
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
@@ -316,7 +330,7 @@ class ProductionPlanResource extends Resource
{
$currentDate = date('Y-m-d');
- $shiftId = \App\Models\Shift::where('id', $get('shift_id'))
+ $shiftId = Shift::where('id', $get('shift_id'))
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
@@ -532,7 +546,8 @@ class ProductionPlanResource extends Resource
])
->headerActions([
ImportAction::make()
- ->importer(ProductionPlanImporter::class),
+ ->importer(ProductionPlanImporter::class)
+ ->maxRows(100000),
]);
}
diff --git a/app/Filament/Resources/ProductionQuantityResource.php b/app/Filament/Resources/ProductionQuantityResource.php
index 824d3e8..75ef646 100644
--- a/app/Filament/Resources/ProductionQuantityResource.php
+++ b/app/Filament/Resources/ProductionQuantityResource.php
@@ -5,7 +5,9 @@ namespace App\Filament\Resources;
use App\Filament\Imports\ProductionQuantityImporter;
use App\Filament\Resources\ProductionQuantityResource\Pages;
use App\Filament\Resources\ProductionQuantityResource\RelationManagers;
+use App\Models\Item;
use App\Models\ProductionQuantity;
+use App\Models\Shift;
use Carbon\Carbon;
use Filament\Forms;
use Filament\Forms\Form;
@@ -40,6 +42,9 @@ class ProductionQuantityResource extends Resource
->required()
// ->nullable()
->reactive()
+ ->default(function () {
+ return optional(ProductionQuantity::latest()->first())->plant_id;
+ })
->disabled(fn (Get $get) => !empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -73,12 +78,16 @@ class ProductionQuantityResource extends Resource
->toArray();
})
->reactive()
+ ->default(function () {
+ $latestShiftId = optional(ProductionQuantity::latest()->first())->shift_id;
+ return optional(Shift::where('id', $latestShiftId)->first())->block_id;
+ })
// ->afterStateUpdated(fn ($set) => $set('shift_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
$getShift = ProductionQuantity::where('id', $get('id'))->first();
- $getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first();
+ $getBlock = Shift::where('id', $getShift->shift_id)->first();
if($getBlock->block_id)
{
$set('block_name', $getBlock->block_id);
@@ -113,13 +122,16 @@ class ProductionQuantityResource extends Resource
return [];
}
- return \App\Models\Shift::where('plant_id', $get('plant_id'))
+ return Shift::where('plant_id', $get('plant_id'))
->where('block_id', $get('block_name'))
->pluck('name', 'id')
->toArray();
})
->reactive()
- ->afterStateUpdated(fn ($set) => $set('line_id', null))
+ ->default(function () {
+ return optional(ProductionQuantity::latest()->first())->shift_id;
+ })
+ //->afterStateUpdated(fn ($set) => $set('line_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
@@ -168,6 +180,9 @@ class ProductionQuantityResource extends Resource
->toArray();
})
->reactive()
+ ->default(function () {
+ return optional(ProductionQuantity::latest()->first())->line_id;
+ })
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
@@ -200,15 +215,15 @@ class ProductionQuantityResource extends Resource
->latest() // Orders by created_at DESC
->first();
- if($exists)
- {
- $existCode = \App\Models\Item::where('id', $exists->item_id)->first();
- $set('recent_qr', $existCode->code.'|'.$exists->serial_number);
- }
- else
- {
- $set('recent_qr', null);
- }
+ // if($exists)
+ // {
+ // $existCode = Item::where('id', $exists->item_id)->first();
+ // $set('recent_qr', $existCode->code.'|'.$exists->serial_number);
+ // }
+ // else
+ // {
+ // $set('recent_qr', null);
+ // }
}
})
->extraAttributes(fn ($get) => [
@@ -230,6 +245,8 @@ class ProductionQuantityResource extends Resource
// ->required()
->reactive()
->autofocus(true)
+ ->debounce(300)
+ // ->submitOnEnter()
->afterStateUpdated(function ($state, callable $get, callable $set) {
// **Check if input is empty before processing**
if (empty($state)) {
@@ -307,7 +324,7 @@ class ProductionQuantityResource extends Resource
{
$currentDate = date('Y-m-d');
- $shiftId = \App\Models\Shift::where('id', $get('shift_id'))
+ $shiftId = Shift::where('id', $get('shift_id'))
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
@@ -362,7 +379,7 @@ class ProductionQuantityResource extends Resource
//$currentDate = date('Y-m-d');
$yesterday = date('Y-m-d', strtotime('-1 days'));
- $shiftId = \App\Models\Shift::where('id', $get('shift_id'))
+ $shiftId = Shift::where('id', $get('shift_id'))
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
@@ -388,7 +405,7 @@ class ProductionQuantityResource extends Resource
{
$currentDate = date('Y-m-d');
- $shiftId = \App\Models\Shift::where('id', $get('shift_id'))
+ $shiftId = Shift::where('id', $get('shift_id'))
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
@@ -447,7 +464,7 @@ class ProductionQuantityResource extends Resource
//$currentDate = date('Y-m-d');
$yesterday = date('Y-m-d', strtotime('-1 days'));
- $shiftId = \App\Models\Shift::where('id', $get('shift_id'))
+ $shiftId = Shift::where('id', $get('shift_id'))
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
@@ -484,7 +501,7 @@ class ProductionQuantityResource extends Resource
{
$currentDate = date('Y-m-d');
- $shiftId = \App\Models\Shift::where('id', $get('shift_id'))
+ $shiftId = Shift::where('id', $get('shift_id'))
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
@@ -555,7 +572,7 @@ class ProductionQuantityResource extends Resource
Notification::make()
->title('Invalid QR')
- ->body("Scan the valid QR code. (Ex: Item_Code|Serial_Number )")
+ ->body("Scan the valid QR code.
(Ex: Item_Code|Serial_Number )")
->danger()
->send();
return;
@@ -623,7 +640,7 @@ class ProductionQuantityResource extends Resource
Notification::make()
->title('Invalid QR')
- ->body("Scan the valid QR code. (Ex: Item_Code|Serial_Number )")
+ ->body("Scan the valid QR code.
(Ex: Item_Code|Serial_Number )")
->danger()
->send();
return;
@@ -642,7 +659,7 @@ class ProductionQuantityResource extends Resource
$serialNumber = isset($parts[1]) ? trim($parts[1]) : null;
// Fetch item using item code and plant_id
- $item = \App\Models\Item::where('code', $itemCode)
+ $item = Item::where('code', $itemCode)
->where('plant_id', $get('plant_id'))
->first();
@@ -698,11 +715,27 @@ class ProductionQuantityResource extends Resource
->required()
->unique(ignoreRecord: true)
->readOnly(true)
- ->autocapitalize('serial_number'),
+ ->autocapitalize('characters'),
//->columnSpanFull(),
Forms\Components\TextInput::make('recent_qr') //item_description
->label('Last scanned QR')
->reactive()
+ ->default(function () {
+ // Get the latest 'item_id' foreign key from 'production_quantities' table
+ $latestProductionQuantity = ProductionQuantity::latest()->first();
+ if (!$latestProductionQuantity) {
+ return null; // Return null if no production quantities exist
+ }
+
+ // Get the corresponding 'code' from 'items' table where 'id' matches 'item_id'
+ $itemCode = optional(Item::find($latestProductionQuantity->item_id))->code;
+
+ // Get the latest 'serial_number' from 'production_quantities' table
+ $serialNumber = $latestProductionQuantity->serial_number;
+
+ // Combine 'code' and 'serial_number' into the desired format
+ return $itemCode && $serialNumber ? "{$itemCode} | {$serialNumber}" : null;
+ })
->readOnly(true),
Forms\Components\TextInput::make('id')
->hidden()
@@ -759,7 +792,8 @@ class ProductionQuantityResource extends Resource
])
->headerActions([
ImportAction::make()
- ->importer(ProductionQuantityImporter::class),
+ ->importer(ProductionQuantityImporter::class)
+ ->maxRows(100000),
]);
}