diff --git a/app/Filament/Imports/ProductionPlanImporter.php b/app/Filament/Imports/ProductionPlanImporter.php
index 54d27c9..10e6b06 100644
--- a/app/Filament/Imports/ProductionPlanImporter.php
+++ b/app/Filament/Imports/ProductionPlanImporter.php
@@ -3,6 +3,7 @@
namespace App\Filament\Imports;
use App\Models\Block;
+use App\Models\Item;
use App\Models\Line;
use App\Models\Plant;
use App\Models\ProductionPlan;
@@ -23,11 +24,33 @@ class ProductionPlanImporter extends Importer
public static function getColumns(): array
{
return [
- ImportColumn::make('created_at')
+ // ImportColumn::make('created_at')
+ // ->requiredMapping()
+ // ->exampleHeader('Created DateTime')
+ // ->example(['01-01-2025 08:00:00', '01-01-2025 19:30:00'])
+ // ->label('Created DateTime')
+ // ->rules(['required']),
+
+ ImportColumn::make('plant')
->requiredMapping()
- ->exampleHeader('Created DateTime')
- ->example(['01-01-2025 08:00:00', '01-01-2025 19:30:00'])
- ->label('Created DateTime')
+ ->exampleHeader('Plant Code')
+ ->example(['1000', '1000'])
+ ->label('Plant Code')
+ ->relationship(resolveUsing: 'code')
+ ->rules(['required']),
+ ImportColumn::make('line')
+ ->requiredMapping()
+ ->exampleHeader('Line Name')
+ ->example(['4 inch pump line', '4 inch pump line'])
+ ->label('Line Name')
+ ->relationship(resolveUsing: 'name')
+ ->rules(['required']),
+ ImportColumn::make('item')
+ ->requiredMapping()
+ ->exampleHeader('Item Code')
+ ->example(['123456', '210987'])
+ ->label('Item Code')
+ ->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('plan_quantity')
->requiredMapping()
@@ -36,52 +59,40 @@ class ProductionPlanImporter extends Importer
->label('Plan Quantity')
->numeric()
->rules(['required', 'integer']),
- ImportColumn::make('production_quantity')
- ->requiredMapping()
- ->exampleHeader('Production Quantity')
- ->example(['0', '0'])
- ->label('Production Quantity')
- ->numeric()
- ->rules(['required', 'integer']),
- ImportColumn::make('line')
- ->requiredMapping()
- ->exampleHeader('Line Name')
- ->example(['4 inch pump line', '4 inch pump line'])
- ->label('Line Name')
- ->relationship(resolveUsing: 'name')
- ->rules(['required']),
- ImportColumn::make('block_reference')
- ->requiredMapping() // Or optionalMapping() if not always present
- ->exampleHeader('Block Name')
- ->example(['Block A', 'Block A'])
- ->label('Block Name')
- ->rules(['required']), // Or remove if not required
- ImportColumn::make('shift')
- ->requiredMapping()
- ->exampleHeader('Shift Name') // ID
- ->example(['Day', 'Night']) // '2', '7'
- ->label('Shift Name') // ID
- ->relationship(resolveUsing: 'name')
- ->rules(['required']),
- ImportColumn::make('plant')
- ->requiredMapping()
- ->exampleHeader('Plant Code')
- ->example(['1000', '1000'])
- ->label('Plant Code')
- ->relationship(resolveUsing: 'code')
- ->rules(['required']),
- ImportColumn::make('updated_at')
- ->requiredMapping()
- ->exampleHeader('Updated DateTime')
- ->example(['01-01-2025 08:00:00', '01-01-2025 19:30:00'])
- ->label('Updated DateTime')
- ->rules(['required']),
- ImportColumn::make('operator_id')
- ->requiredMapping()
- ->exampleHeader('Operator ID')
- ->example([Filament::auth()->user()->name, Filament::auth()->user()->name])
- ->label('Operator ID')
- ->rules(['required']),
+ // ImportColumn::make('production_quantity')
+ // ->requiredMapping()
+ // ->exampleHeader('Production Quantity')
+ // ->example(['0', '0'])
+ // ->label('Production Quantity')
+ // ->numeric()
+ // ->rules(['required', 'integer']),
+
+ // ImportColumn::make('block_reference')
+ // ->requiredMapping() // Or optionalMapping() if not always present
+ // ->exampleHeader('Block Name')
+ // ->example(['Block A', 'Block A'])
+ // ->label('Block Name')
+ // ->rules(['required']), // Or remove if not required
+ // ImportColumn::make('shift')
+ // ->requiredMapping()
+ // ->exampleHeader('Shift Name') // ID
+ // ->example(['Day', 'Night']) // '2', '7'
+ // ->label('Shift Name') // ID
+ // ->relationship(resolveUsing: 'name')
+ // ->rules(['required']),
+
+ // ImportColumn::make('updated_at')
+ // ->requiredMapping()
+ // ->exampleHeader('Updated DateTime')
+ // ->example(['01-01-2025 08:00:00', '01-01-2025 19:30:00'])
+ // ->label('Updated DateTime')
+ // ->rules(['required']),
+ // ImportColumn::make('operator_id')
+ // ->requiredMapping()
+ // ->exampleHeader('Operator ID')
+ // ->example([Filament::auth()->user()->name, Filament::auth()->user()->name])
+ // ->label('Operator ID')
+ // ->rules(['required']),
];
}
@@ -89,6 +100,7 @@ class ProductionPlanImporter extends Importer
{
$warnMsg = [];
$plantCod = $this->data['plant'];
+ $itemCod = $this->data['item'];
$plant = null;
$line = null;
$block = null;
@@ -103,113 +115,52 @@ class ProductionPlanImporter extends Importer
$warnMsg[] = 'Plant not found';
} else {
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
- // block_reference
- $block = Block::where('name', $this->data['block_reference'])->where('plant_id', $plant->id)->first();
}
if (! $line) {
$warnMsg[] = 'Line not found';
}
- $shift = null;
- if (! $block) {
- $warnMsg[] = 'Block not found';
- } elseif ($plant) {
- $shift = Shift::where('name', $this->data['shift'])->where('plant_id', $plant->id)->where('block_id', $block->id)->first();
+ if (Str::length($itemCod) < 6 || ! is_numeric($itemCod)) {
+ $warnMsg[] = 'Invalid item code found';
+ } else {
+ $item = Item::where('code', $itemCod)->first();
}
- // $shift = Shift::where('id', $this->data['shift'])->where('plant_id', $plant->id)->first();
- if (! $shift) {
- $warnMsg[] = 'Shift not found';
+ if (! $item) {
+ $warnMsg[] = 'Item not found';
}
+
+ $plantId = $plant->id;
+
+ $itemAgaPlant = Item::where('plant_id', $plantId)->where('code', $itemCod)->first();
+
+ if(!$itemAgaPlant){
+ $warnMsg[] = 'Item not found against plant code';
+ }
+
+ $user = Filament::auth()->user();
+
+ $operatorName = $user->name;
+
if (Str::length($this->data['plan_quantity']) < 0 || ! is_numeric($this->data['plan_quantity']) || $this->data['plan_quantity'] <= 0) {
$warnMsg[] = 'Invalid plan quantity found';
}
- if (Str::length($this->data['production_quantity']) < 0 || ! is_numeric($this->data['production_quantity']) || $this->data['production_quantity'] < 0) {
- $warnMsg[] = 'Invalid production quantity found';
- }
-
- $fromDate = $this->data['created_at'];
- $toDate = $this->data['updated_at'];
-
- $formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
-
- $fdateTime = null;
- $tdateTime = null;
- // Try parsing with multiple formats
- foreach ($formats as $format) {
- try {
- $fdateTime = Carbon::createFromFormat($format, $fromDate);
- break;
- } catch (\Exception $e) {
- // Optionally collect warning messages
- // $warnMsg[] = "Date format mismatch with format: $format";
- }
- }
-
- foreach ($formats as $format) {
- try {
- $tdateTime = Carbon::createFromFormat($format, $toDate);
- break;
- } catch (\Exception $e) {
- // Optionally collect warning messages
- // $warnMsg[] = "Date format mismatch with format: $format";
- }
- }
-
- $fDateOnly = '';
- if (! isset($fdateTime)) {
- // throw new \Exception('Invalid date time format');
- $warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
- } else {
- $fDateOnly = $fdateTime->toDateString();
- }
- if (! isset($tdateTime)) {
- $warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
- }
-
- if (isset($fdateTime) && isset($tdateTime)) {
- if ($fdateTime->greaterThan($tdateTime)) {
- $warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'.";
- }
- }
-
- // if (!$fromDate) {
- // $warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
- // }
- // else if (!$toDate) {
- // $warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
- // }
-
- $user = User::where('name', $this->data['operator_id'])->first();
- if (! $user) {
- $warnMsg[] = 'Operator ID not found';
- }
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
- } else { // if (empty($warnMsg))
+ } else {
$productionPlan = ProductionPlan::where('plant_id', $plant->id)
- ->where('shift_id', $shift->id)
->where('line_id', $line->id)
- ->whereDate('created_at', $fDateOnly)
- // ->where('plan_quantity', $productionQuantity->plan_quantity)
+ ->where('item_id', $itemAgaPlant->id)
->latest()
->first();
if ($productionPlan) {
- // if($productionPlan->production_quantity)
- // {
- // throw new RowImportFailedException("{$productionPlan->created_at}, {$productionPlan->production_quantity}");
- // }
- // $warnMsg[] = "Production plan already exist on '{$fDateOnly}'!";
$productionPlan->update([
'plan_quantity' => $this->data['plan_quantity'],
- // 'production_quantity' => $productionPlan->production_quantity,
- // 'created_at' => $productionPlan->created_at,//$fdateTime->format('Y-m-d H:i:s'),
- // 'updated_at' => $tdateTime->format('Y-m-d H:i:s'),
- 'operator_id' => $this->data['operator_id'],
+ 'operator_id' => $operatorName,
]);
$productionPlan->save();
@@ -220,21 +171,15 @@ class ProductionPlanImporter extends Importer
ProductionPlan::updateOrCreate([
'plant_id' => $plant->id,
'line_id' => $line->id,
- 'shift_id' => $shift->id,
+ 'item_id' => $itemAgaPlant->id,
+ // 'shift_id' => $shift->id,
'plan_quantity' => $this->data['plan_quantity'],
- 'production_quantity' => $this->data['production_quantity'],
- 'created_at' => $fdateTime->format('Y-m-d H:i:s'), // $this->data['created_at'],
- 'updated_at' => $tdateTime->format('Y-m-d H:i:s'), // $this->data['updated_at'],
- 'operator_id' => $this->data['operator_id'],
+ 'created_at' =>now(),
+ 'updated_at' => now(),
+ 'operator_id' => $operatorName,
]);
return null;
- // return ProductionPlan::firstOrNew([
- // // Update existing records, matching them by `$this->data['column_name']`
- // 'email' => $this->data['email'],
- // ]);
-
- // return new ProductionPlan();
}
public static function getCompletedNotificationBody(Import $import): string
diff --git a/app/Filament/Pages/ProductionQuantityPage.php b/app/Filament/Pages/ProductionQuantityPage.php
index 29a8411..1386d3f 100644
--- a/app/Filament/Pages/ProductionQuantityPage.php
+++ b/app/Filament/Pages/ProductionQuantityPage.php
@@ -3,7 +3,10 @@
namespace App\Filament\Pages;
use App\Models\Item;
+use App\Models\Line;
+use App\Models\Machine;
use App\Models\Plant;
+use App\Models\ProductionPlan;
use App\Models\ProductionQuantity;
use App\Models\Shift;
use Carbon\Carbon;
@@ -14,19 +17,18 @@ use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
+use Filament\Notifications\Notification;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
use Filament\Pages\Page;
-use Route;
-use Illuminate\Support\Facades\Request;
-use Filament\Notifications\Notification;
use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Request;
use Livewire\Attributes\On;
-
+use Route;
class ProductionQuantityPage extends Page implements HasForms
{
-
use InteractsWithForms;
+
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.pages.production-quantity';
@@ -37,10 +39,43 @@ class ProductionQuantityPage extends Page implements HasForms
protected static ?string $navigationGroup = 'Production';
- public $qrData, $pId, $bId, $sId, $lId, $iId, $succId, $sNoId, $succStat, $recQr, $prodOrder;
+ public $qrData;
- // public $recent_qr, $clear_qr;
+ public $pId;
+ public $mId;
+
+ public $mNam;
+
+ public $bId;
+
+ public $bNam;
+
+ public $sId;
+
+ public $sNam;
+
+ public $lId;
+
+ public $lNam;
+
+ public $iId;
+
+ public $succId;
+
+ public $sNoId;
+
+ public $succStat;
+
+ public $recQr;
+
+ public $prodOrder;
+
+ public $workCenter;
+
+ public $recent_qr;
+
+ // public $recent_qr, $clear_qr;
use HasFiltersForm;
@@ -53,6 +88,7 @@ class ProductionQuantityPage extends Page implements HasForms
'line' => null,
]);
}
+
public function boot(): void
{
Filament::registerRenderHook(
@@ -60,7 +96,7 @@ class ProductionQuantityPage extends Page implements HasForms
function () {
// Check if the current route matches '/admin/production-quantity'
if (Request::is('admin/production-quantity*')) {
- echo <<
/* Hide sidebar and topbar */
.fi-sidebar,
@@ -137,19 +173,38 @@ class ProductionQuantityPage extends Page implements HasForms
->default(function () {
return optional(ProductionQuantity::latest()->first())->plant_id;
})
- ->afterStateUpdated(function ($state, $set, callable $get,$livewire) {
+ ->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
$plantId = $get('plant_id');
$set('block_name', null);
+ $now = Carbon::now()->format('H:i:s');
+ $shiftType = ($now >= '08:00:00' && $now <= '19:29:59')
+ ? 'Day'
+ : 'Night';
+
+ $set('shift_id', $shiftType);
+
session(['select_plant' => $state]);
- if (!$plantId)
- {
+ if (! $plantId) {
$set('pqPlantError', 'Please select a plant first.');
+ $this->form->fill([
+ 'plant_id' => $this->pId,
+ 'block_name' => null,
+ 'shift_id' => null,
+ 'line_id' => null,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => null,
+ 'sap_msg_status' => null,
+ 'sap_msg_description' => null,
+ // 'operator_id'=> $operatorName,
+ 'recent_qr' => $this->recQr,
+ ]);
+
return;
- }
- else
- {
+ } else {
$this->pId = $plantId;
$set('validationError', null);
$set('pqPlantError', null);
@@ -159,263 +214,299 @@ class ProductionQuantityPage extends Page implements HasForms
->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null)
->hintColor('danger'),
- // Block Filter
- Select::make('block_name')
+ // Select::make('line_id')
+ // ->relationship('line', 'name')
+ // ->required()
+ // ->columnSpan(1)
+ // ->options(function (callable $get) {
+ // if (!$get('plant_id')) {
+ // return [];
+ // }
+
+ // return \App\Models\Line::where('plant_id', $get('plant_id'))
+ // ->pluck('name', 'id')
+ // ->toArray();
+ // })
+ // ->reactive()
+ // ->default(function () {
+ // return optional(ProductionQuantity::latest()->first())->line_id;
+ // })
+ // ->afterStateUpdated(function ($state, callable $set, callable $get) {
+ // if($get('id'))
+ // {
+ // $getShift = ProductionQuantity::where('id', $get('id'))->first();
+ // if($getShift->line_id)
+ // {
+ // $set('line_id', $getShift->line_id);
+ // $set('pqLineError', null);
+ // }
+ // }
+
+ // $lineId = $get('line_id');
+ // $set('item_code', null);
+
+ // $now = Carbon::now()->format('H:i:s');
+ // $shiftType = ($now >= '08:00:00' && $now <= '19:29:59')
+ // ? 'Day'
+ // : 'Night';
+
+ // $set('shift', $shiftType);
+
+ // session(['select_line' => $state]);
+ // // dd(session('select_line'));
+
+ // $this->triggerChartUpdate();
+
+ // if (!$lineId) {
+ // $set('pqLineError', 'Please select a line first.');
+ // return;
+ // }
+ // else
+ // {
+ // $this->lId = $lineId;
+ // $set('validationError', null);
+ // $set('pqLineError', null);
+ // $set('item_id', null);
+ // // $set('item_description', null);
+ // $set('serial_number', null);
+ // }
+ // })
+ // ->extraAttributes(fn ($get) => [
+ // 'class' => $get('pqLineError') ? 'border-red-500' : '',
+ // ])
+ // ->hint(fn ($get) => $get('pqLineError') ? $get('pqLineError') : null)
+ // ->hintColor('danger'),
+
+ TextInput::make('machine_id')
+ ->label('Machine')
+ ->required()
+ ->columnSpan(1)
+ ->reactive()
+ ->afterStateUpdated(function ($state, callable $set, callable $get) {
+ $plantId = $get('plant_id');
+ $machineId = $get('machine_id');
+
+ $this->mNam = $machineId;
+
+ })
+ ->extraAttributes(fn ($get) => [
+ // 'class' => $get('pqLineError') ? 'border-red-500' : '',
+ 'wire:keydown.enter' => 'processMachine($event.target.value)',
+ ]),
+ // ->hint(fn ($get) => $get('pqLineError') ? $get('pqLineError') : null)
+ // ->hintColor('danger'),
+
+ TextInput::make('line_id')
+ ->label('Line')
+ ->reactive()
+ ->readOnly()
+ ->required()
+ ->afterStateUpdated(fn ($state) => $this->lNam = $state),
+
+ TextInput::make('block_name')
->label('Block')
- ->required()
- // ->nullable()
->reactive()
- ->columnSpan(1)
- ->options(function (callable $get) {
- if (!$get('plant_id')) {
- return [];
- }
-
- return \App\Models\Block::where('plant_id', $get('plant_id'))
- ->pluck('name', 'id')
- ->toArray();
- })
- ->default(function () {
- $latestShiftId = optional(ProductionQuantity::latest()->first())->shift_id;
- return optional(Shift::where('id', $latestShiftId)->first())->block_id;
- })
- ->afterStateUpdated(function ($state, callable $set, callable $get) {
- if($get('id'))
- {
- $getShift = ProductionQuantity::where('id', $get('id'))->first();
- $getBlock = Shift::where('id', $getShift->shift_id)->first();
- if($getBlock->block_id)
- {
- $set('block_name', $getBlock->block_id);
- $set('pqBlockError', null);
- }
- }
-
- $blockId = $get('block_name');
- $set('shift_id', null);
-
- if (!$blockId) {
- $set('pqBlockError', 'Please select a block first.');
- return;
- }
- else
- {
- $this->bId = $blockId;
- $set('validationError', null);
- $set('pqBlockError', null);
- }
- })
- ->extraAttributes(fn ($get) => [
- 'class' => $get('pqBlockError') ? 'border-red-500' : '',
- ])
- ->hint(fn ($get) => $get('pqBlockError') ? $get('pqBlockError') : null)
- ->hintColor('danger'),
-
- Select::make('shift_id')
- ->relationship('shift', 'name')
+ ->readOnly()
->required()
- ->columnSpan(1)
- // ->nullable()
- ->options(function (callable $get) {
- if (!$get('plant_id') || !$get('block_name')) {
- return [];
- }
+ ->afterStateUpdated(fn ($state) => $this->bNam = $state),
- return Shift::where('plant_id', $get('plant_id'))
- ->where('block_id', $get('block_name'))
- ->pluck('name', 'id')
- ->toArray();
- })
+ TextInput::make('shift_id')
+ ->label('Shift')
->reactive()
- ->default(function () {
- return optional(ProductionQuantity::latest()->first())->shift_id;
- })
- ->afterStateUpdated(function ($state, callable $set, callable $get) {
- if($get('id'))
- {
- $getShift = ProductionQuantity::where('id', $get('id'))->first();
- if($getShift->shift_id)
- {
- $set('shift_id', $getShift->shift_id);
- $set('pqShiftError', null);
- }
- }
-
- $curShiftId = $get('shift_id');
-
- $set('line_id', null);
-
- if (!$curShiftId) {
- $set('pqShiftError', 'Please select a shift first.');
- return;
- }
- else
- {
- $this->sId = $curShiftId;
- $set('validationError', null);
- $set('pqShiftError', null);
- }
- })
- ->extraAttributes(fn ($get) => [
- 'class' => $get('pqShiftError') ? 'border-red-500' : '',
- ])
- ->hint(fn ($get) => $get('pqShiftError') ? $get('pqShiftError') : null)
- ->hintColor('danger'),
-
- Select::make('line_id')
- ->relationship('line', 'name')
+ ->readOnly()
->required()
- ->columnSpan(1)
- ->options(function (callable $get) {
- if (!$get('plant_id') || !$get('block_name') || !$get('shift_id')) {
- return [];
- }
-
- return \App\Models\Line::where('plant_id', $get('plant_id'))
- ->pluck('name', 'id')
- ->toArray();
- })
+ ->afterStateUpdated(fn ($state) => $this->sNam = $state),
+ TextInput::make('production_order')
+ ->label('Production Order')
->reactive()
- ->default(function () {
- return optional(ProductionQuantity::latest()->first())->line_id;
- })
- ->afterStateUpdated(function ($state, callable $set, callable $get) {
- if($get('id'))
- {
- $getShift = ProductionQuantity::where('id', $get('id'))->first();
- if($getShift->line_id)
- {
- $set('line_id', $getShift->line_id);
- $set('pqLineError', null);
- }
- }
-
- $lineId = $get('line_id');
- $set('item_code', null);
-
-
- session(['select_line' => $state]);
- // dd(session('select_line'));
-
- $this->triggerChartUpdate();
-
- if (!$lineId) {
- $set('pqLineError', 'Please select a line first.');
- return;
- }
- else
- {
- $this->lId = $lineId;
- $set('validationError', null);
- $set('pqLineError', null);
+ ->required()
+ ->minLength(7)
+ ->maxLength(14)
+ // ->columnSpan(1)
+ ->columnSpan(['default' => 1, 'sm' => 1])
+ ->afterStateUpdated(function ($state, callable $get, callable $set): void {
+ if (! is_numeric($get('production_order')) || ! preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order'))) {
+ $set('productionError', 'Must be a numeric value with 7 to 14 digits.');
+ $set('production_order', null);
+ $set('item_code', null);
$set('item_id', null);
// $set('item_description', null);
$set('serial_number', null);
+ $set('validationError', null);
+ $this->prodOrder = null;
+ } else {
+ $set('productionError', null);
+ $set('production_order', $state);
+ $set('item_code', null);
+ $set('item_id', null);
+ // $set('item_description', null);
+ $set('serial_number', null);
+ $set('validationError', null);
+ $this->prodOrder = $state;
+ // if (empty($state)) {
+ // }
}
})
->extraAttributes(fn ($get) => [
- 'class' => $get('pqLineError') ? 'border-red-500' : '',
+ 'id' => 'scan_locator_no',
+ 'class' => $get('productionError') ? 'border-red-500' : '',
])
- ->hint(fn ($get) => $get('pqLineError') ? $get('pqLineError') : null)
+ ->hint(fn ($get) => $get('productionError') ? $get('productionError') : null)
->hintColor('danger'),
- TextInput::make('production_order')
- ->label('Production Order')
- ->reactive()
- ->required()
- ->minLength(7)
- ->maxLength(14)
- //->columnSpan(1)
- ->columnSpan(['default' => 1, 'sm' => 1])
- ->afterStateUpdated(function ($state, callable $get, callable $set): void {
- if(!is_numeric($get('production_order')) || !preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order')))
- {
- $set('productionError', "Must be a numeric value with 7 to 14 digits.");
- $set('production_order', null);
- $set('item_code', null);
- $set('item_id', null);
- // $set('item_description', null);
- $set('serial_number', null);
- $set('validationError', null);
- $this->prodOrder = null;
- }
- else
- {
- $set('productionError', null);
- $set('production_order', $state);
- $set('item_code', null);
- $set('item_id', null);
- // $set('item_description', null);
- $set('serial_number', null);
- $set('validationError', null);
- $this->prodOrder = $state;
- // if (empty($state)) {
- // }
- }
- })
- ->extraAttributes(fn ($get) => [
- 'class' => $get('productionError') ? 'border-red-500' : '',
- ])
- ->hint(fn ($get) => $get('productionError') ? $get('productionError') : null)
- ->hintColor('danger'),
-
- // TextInput::make('item_code')
- // ->label('Item Code')
- // ->columnSpan(1)
- // ->autofocus(true)
- // //->reactive()
- // ->live(onBlur: true) // avoids per-keystroke triggering
- // ->default(fn () => $this->clear_qr)
- // ->extraAttributes([
- // 'wire:keydown.enter' => 'processAllValues($event.target.value)',
- // ]),
-
- Hidden::make('serial_number')
+ Hidden::make('serial_number')
->required(),
- Hidden::make('success_msg')
+ Hidden::make('success_msg')
->required(),
- Hidden::make('item_id')
+ Hidden::make('item_id')
->required(),
- Hidden::make('sap_msg_status'),
- Hidden::make('sap_msg_description'),
+ Hidden::make('sap_msg_status'),
+ Hidden::make('sap_msg_description'),
- TextInput::make('recent_qr')
+ TextInput::make('recent_qr')
->label('Last scanned QR')
->reactive()
->columnSpan(['default' => 1, 'sm' => 2])
- //->columnSpan(2)
- // ->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
- // }
+ // ->columnSpan(2)
+ // ->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 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;
+ // // 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;
+ // // Combine 'code' and 'serial_number' into the desired format
+ // // return $itemCode && $serialNumber ? "{$itemCode} | {$serialNumber}" : null;
- // $this->recQr = $itemCode && $serialNumber ? "{$itemCode} | {$serialNumber}" : null;
+ // $this->recQr = $itemCode && $serialNumber ? "{$itemCode} | {$serialNumber}" : null;
- // })
+ // })
->default(fn () => $this->recQr)
->readOnly(true),
- TextInput::make('id')
+ TextInput::make('id')
->hidden()
->readOnly(),
- Hidden::make('operator_id')
+ Hidden::make('operator_id')
->default(Filament::auth()->user()->name),
])
// ->columns(6);
- ->columns(['default' => 1, 'sm' => 7]);
+ ->columns(['default' => 1, 'sm' => 8]);
}
+ public function processMachine($value)
+ {
+ $plantId = $this->pId;
+ $plantCode = Plant::find($plantId);
+
+ $PlaCo = $plantCode->code;
+ $this->mNam = $value;
+
+ $now = Carbon::now()->format('H:i:s');
+ $this->sNam = ($now >= '08:00:00' && $now <= '19:29:59')
+ ? 'Day'
+ : 'Night';
+
+ $machine = Machine::where('plant_id', $plantId)->where('work_center', $this->mNam)->with('line.block')->first();
+
+ $machinenotAgaPlant = Machine::where('work_center', $this->mNam)->first();
+
+ $machineAgaPlant = Machine::where('plant_id', $plantId)->where('work_center', $this->mNam)->first();
+
+ if (!$machinenotAgaPlant) {
+ Notification::make()
+ ->title('Unknown WorkCenter')
+ ->body("Work Center not found")
+ ->danger()
+ ->send();
+ $this->form->fill([
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
+ 'sap_msg_status' => null,
+ 'sap_msg_description' => null,
+ // 'operator_id'=> $operatorName,
+ 'recent_qr' => $this->recQr,
+ ]);
+ return;
+ }
+ else if (!$machineAgaPlant) {
+ Notification::make()
+ ->title('Unknown WorkCenter')
+ ->body("Work Center not found against plant code $PlaCo")
+ ->danger()
+ ->send();
+
+ $this->form->fill([
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
+ 'sap_msg_status' => null,
+ 'sap_msg_description' => null,
+ // 'operator_id'=> $operatorName,
+ 'recent_qr' => $this->recQr,
+ ]);
+ return;
+ }
+
+ $rec = ProductionQuantity::where('plant_id', $plantId)->where('machine_id', $machineAgaPlant->id)->latest()->first();
+
+ if($rec)
+ {
+
+ $item = Item::where('id', $rec->item_id)->where('plant_id', $plantId)->first();
+
+ $itemCode = $item?->code ?? '';
+ $serialNo = $rec->serial_number ?? '';
+
+ $this->recQr = $itemCode . ' | ' . $serialNo;
+
+ }
+
+ if ($machine) {
+ $this->lNam = Line::where('id', $machine->line_id)->value('name');
+ $this->bNam = $machine->line->block->name ?? null;
+
+ // dd($lineName, $blockName);
+
+ session(['select_line' => $machine->line_id]);
+
+ $this->form->fill([
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
+ 'sap_msg_status' => null,
+ 'sap_msg_description' => null,
+ // 'operator_id'=> $operatorName,
+ 'recent_qr' => $this->recQr,
+ ]);
+ $this->triggerChartUpdate();
+ }
+ }
// Method to process the value when Enter is pressed
@@ -428,21 +519,21 @@ class ProductionQuantityPage extends Page implements HasForms
public function processAllValues($formQRData)
{
- //dd($formQRData);
- //$formValues = [];
+ // dd($formQRData);
+ // $formValues = [];
// This will get all form data from the request
- //$this->clear_qr = null;
+ // $this->clear_qr = null;
$this->qrData = null;
$this->iId = null;
$this->succId = null;
$this->sNoId = null;
$this->succStat = null;
- $this->validateAndProcessForm( $formQRData); // Process the form values
+ $this->validateAndProcessForm($formQRData); // Process the form values
}
public function validateAndProcessForm($formQRData)
{
- $user = Filament::auth()->user(); //->name
+ $user = Filament::auth()->user(); // ->name
$operatorName = $user->name;
$this->qrData = $formQRData;
@@ -456,687 +547,724 @@ class ProductionQuantityPage extends Page implements HasForms
if (empty($formQRData)) {
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
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;
- }
- else
- {
- if (!$this->pId) {
+ } else {
+ if (! $this->pId) {
$this->form->fill([
- 'plant_id'=> null,
- 'block_name'=> null,
- 'shift_id'=> null,
- 'line_id'=> null,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> null,
+ 'plant_id' => null,
+ 'machine_id' => null,
+ 'block_name' => null,
+ 'shift_id' => null,
+ 'line_id' => null,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => null,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
Notification::make()
->title('Choose Plant')
- ->body("Please select a plant first.")
+ ->body('Please select a plant first.')
->danger()
->send();
+
return;
- }
- else if (!$this->bId) {
+ } elseif (! $this->mNam) {
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> null,
- 'shift_id'=> null,
- 'line_id'=> null,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> null,
+ 'plant_id' => $this->pId,
+ 'machine_id' => null,
+ 'block_name' => null,
+ 'shift_id' => null,
+ 'line_id' => null,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => null,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
Notification::make()
- ->title('Choose Block')
- ->body("Please select a block first.")
+ ->title('Unknown Machine')
+ ->body("Machine can't be empty!")
->danger()
->send();
+
return;
- }
- else if (!$this->sId) {
+ } elseif (! $this->lNam) {
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> null,
- 'line_id'=> null,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> null,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => null,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => null,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
- 'recent_qr' => $this->recQr,
- ]);
- Notification::make()
- ->title('Choose Shift')
- ->body("Please select a shift first.")
- ->danger()
- ->send();
- return;
- }
- else if (!$this->lId) {
- $this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> null,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> null,
- 'sap_msg_status' => null,
- 'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
Notification::make()
->title('Choose Line')
- ->body("Please select a line first.")
+ ->body('Please select a line first.')
->danger()
->send();
+
return;
- }
- else if (!$this->prodOrder) {
+ } elseif (! $this->bNam) {
+
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> null,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => null,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
+ 'recent_qr' => $this->recQr,
+ ]);
+ Notification::make()
+ ->title('Choose Line')
+ ->body('Please select a Block first.')
+ ->danger()
+ ->send();
+
+ return;
+ } elseif (! $this->sNam) {
+ $this->form->fill([
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => null,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => null,
+ 'sap_msg_status' => null,
+ 'sap_msg_description' => null,
+ 'operator_id' => $operatorName,
+ 'recent_qr' => $this->recQr,
+ ]);
+ Notification::make()
+ ->title('Choose Shift')
+ ->body('Please select a shift first.')
+ ->danger()
+ ->send();
+
+ return;
+ } elseif (! $this->prodOrder) {
+ $this->form->fill([
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => null,
+ 'sap_msg_status' => null,
+ 'sap_msg_description' => null,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
Notification::make()
->title('Please scan the production order first.')
->danger()
->send();
+
return;
}
- if(!is_numeric($this->prodOrder))
- {
+ if (! is_numeric($this->prodOrder)) {
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> null,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => null,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
Notification::make()
->title('Invalid Production Order')
- ->body("Must contain numeric values only.")
+ ->body('Must contain numeric values only.')
->danger()
->send();
+
return;
- }
- else if (!preg_match('/^[1-9][0-9]{6,13}$/', $this->prodOrder))
- {
+ } elseif (! preg_match('/^[1-9][0-9]{6,13}$/', $this->prodOrder)) {
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> null,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => null,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
Notification::make()
->title('Invalid Production Order')
- ->body("Must be a numeric value with 7 to 14 digits.
Must start with a non-zero digit.")
+ ->body('Must be a numeric value with 7 to 14 digits.
Must start with a non-zero digit.')
->danger()
->send();
+
return;
}
- // ********************************
+ // $exists = \App\Models\ProductionPlan::where('plant_id', $this->pId)
+ // ->where('shift_id', $this->sId)
+ // ->where('line_id', $this->lId)
+ // ->whereDate('created_at', today())
+ // ->latest()
+ // ->exists();
- $exists = \App\Models\ProductionPlan::where('plant_id', $this->pId)
- ->where('shift_id', $this->sId)
- ->where('line_id', $this->lId)
- ->whereDate('created_at', today())
- ->latest()
- ->exists();
+ // if ($exists)
+ // {
+ // $currentDate = date('Y-m-d');
- if ($exists)
- {
- $currentDate = date('Y-m-d');
+ // $shiftId = Shift::where('id', $this->sId)
+ // ->first();
- $shiftId = Shift::where('id', $this->sId)
- ->first();
+ // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
+ // $hRs = (int) $hRs;
+ // //$miNs = (int) $miNs;-*/
- [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
- $hRs = (int) $hRs;
- //$miNs = (int) $miNs;-*/
+ // $totalMinutes = $hRs * 60 + $miNs;
- $totalMinutes = $hRs * 60 + $miNs;
+ // $from_dt = $currentDate . ' ' . $shiftId->start_time;
- $from_dt = $currentDate . ' ' . $shiftId->start_time;
+ // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
- $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
+ // $currentDateTime = date('Y-m-d H:i:s');
- $currentDateTime = date('Y-m-d H:i:s');
+ // // Check if current date time is within the range
+ // if (!($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
+ // //echo "Choosed a valid shift...";
+ // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
- // Check if current date time is within the range
- if (!($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
- //echo "Choosed a valid shift...";
- // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
+ // $this->form->fill([
+ // 'plant_id'=> $this->pId,
+ // 'block_name'=> $this->bId,
+ // 'shift_id'=> $this->sId,
+ // 'line_id'=> $this->lId,
+ // 'item_id'=> null,
+ // 'serial_number'=> null,
+ // 'success_msg'=> null,
+ // 'production_order'=> $this->prodOrder,
+ // 'sap_msg_status' => null,
+ // 'sap_msg_description' => null,
+ // 'operator_id'=> $operatorName,
+ // 'recent_qr' => $this->recQr,
+ // ]);
+ // Notification::make()
+ // ->title('Invalid Shift')
+ // ->body("Please select a valid shift.")
+ // ->danger()
+ // ->send();
+ // //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')');
+ // return;
+ // }
+ // else
+ // {
+ // $this->form->fill([
+ // 'plant_id'=> $this->pId,
+ // 'block_name'=> $this->bId,
+ // 'shift_id'=> $this->sId,
+ // 'line_id'=> $this->lId,
+ // 'item_id'=> null,
+ // 'serial_number'=> null,
+ // 'success_msg'=> null,
+ // 'production_order'=> $this->prodOrder,
+ // 'sap_msg_status' => null,
+ // 'sap_msg_description' => null,
+ // 'operator_id'=> $operatorName,
+ // 'recent_qr' => $this->recQr,
+ // ]);
+ // }
+ // }
+ // else
+ // {
+ // $existShifts = \App\Models\ProductionPlan::where('plant_id', $this->pId)
+ // ->where('shift_id', $this->sId)
+ // ->where('line_id', $this->lId)
+ // ->whereDate('created_at', Carbon::yesterday())
+ // ->latest()
+ // ->exists();
- $this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
- 'sap_msg_status' => null,
- 'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
- 'recent_qr' => $this->recQr,
- ]);
- Notification::make()
- ->title('Invalid Shift')
- ->body("Please select a valid shift.")
- ->danger()
- ->send();
- //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')');
- return;
- }
- else
- {
- $this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
- 'sap_msg_status' => null,
- 'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
- 'recent_qr' => $this->recQr,
- ]);
- }
- }
- else
- {
- $existShifts = \App\Models\ProductionPlan::where('plant_id', $this->pId)
- ->where('shift_id', $this->sId)
- ->where('line_id', $this->lId)
- ->whereDate('created_at', Carbon::yesterday())
- ->latest()
- ->exists();
+ // if ($existShifts) //if ($existShifts->count() > 0)
+ // { // record exist on yesterday
+ // //$currentDate = date('Y-m-d');
+ // $yesterday = date('Y-m-d', strtotime('-1 days'));
- if ($existShifts) //if ($existShifts->count() > 0)
- { // record exist on yesterday
- //$currentDate = date('Y-m-d');
- $yesterday = date('Y-m-d', strtotime('-1 days'));
+ // $shiftId = Shift::where('id', $this->sId)
+ // ->first();
- $shiftId = Shift::where('id', $this->sId)
- ->first();
+ // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
+ // $hRs = (int) $hRs;
+ // // $miNs = (int) $miNs;-*/
- [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
- $hRs = (int) $hRs;
- // $miNs = (int) $miNs;-*/
+ // $totalMinutes = $hRs * 60 + $miNs;
- $totalMinutes = $hRs * 60 + $miNs;
+ // $from_dt = $yesterday . ' ' . $shiftId->start_time;
- $from_dt = $yesterday . ' ' . $shiftId->start_time;
+ // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
- $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
+ // $currentDateTime = date('Y-m-d H:i:s');
- $currentDateTime = date('Y-m-d H:i:s');
+ // // Check if current date time is within the range
+ // if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
+ // $this->form->fill([
+ // 'plant_id'=> $this->pId,
+ // 'block_name'=> $this->bId,
+ // 'shift_id'=> $this->sId,
+ // 'line_id'=> $this->lId,
+ // 'item_id'=> null,
+ // 'serial_number'=> null,
+ // 'success_msg'=> null,
+ // 'production_order'=> $this->prodOrder,
+ // 'sap_msg_status' => null,
+ // 'sap_msg_description' => null,
+ // 'operator_id'=> $operatorName,
+ // 'recent_qr' => $this->recQr,
+ // ]);
+ // }
+ // else
+ // {
+ // $currentDate = date('Y-m-d');
- // Check if current date time is within the range
- if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
- $this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
- 'sap_msg_status' => null,
- 'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
- 'recent_qr' => $this->recQr,
- ]);
- }
- else
- {
- $currentDate = date('Y-m-d');
+ // $shiftId = Shift::where('id', $this->sId)
+ // ->first();
- $shiftId = Shift::where('id', $this->sId)
- ->first();
+ // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
+ // $hRs = (int) $hRs;
+ // // $miNs = (int) $miNs;-*/
- [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
- $hRs = (int) $hRs;
- // $miNs = (int) $miNs;-*/
+ // $totalMinutes = $hRs * 60 + $miNs;
- $totalMinutes = $hRs * 60 + $miNs;
+ // $from_dt = $currentDate . ' ' . $shiftId->start_time;
- $from_dt = $currentDate . ' ' . $shiftId->start_time;
+ // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
- $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
+ // $currentDateTime = date('Y-m-d H:i:s');
- $currentDateTime = date('Y-m-d H:i:s');
+ // // Check if current date time is within the range
+ // if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
+ // //echo "Choosed a valid shift...";
+ // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
- // Check if current date time is within the range
- if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
- //echo "Choosed a valid shift...";
- // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
+ // $this->form->fill([
+ // 'plant_id'=> $this->pId,
+ // 'block_name'=> $this->bId,
+ // 'shift_id'=> $this->sId,
+ // 'line_id'=> $this->lId,
+ // 'item_id'=> null,
+ // 'serial_number'=> null,
+ // 'success_msg'=> null,
+ // 'production_order'=> $this->prodOrder,
+ // 'sap_msg_status' => null,
+ // 'sap_msg_description' => null,
+ // 'operator_id'=> $operatorName,
+ // 'recent_qr' => $this->recQr,
+ // ]);
+ // Notification::make()
+ // ->title('Plan Not Found')
+ // ->body("Please set production plan first.")
+ // ->danger()
+ // ->send();
+ // //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')');
+ // return;
+ // }
+ // else
+ // {
+ // //echo "Choosed a valid shift...";
+ // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
- $this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
- 'sap_msg_status' => null,
- 'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
- 'recent_qr' => $this->recQr,
- ]);
- Notification::make()
- ->title('Plan Not Found')
- ->body("Please set production plan first.")
- ->danger()
- ->send();
- //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')');
- return;
- }
- else
- {
- //echo "Choosed a valid shift...";
- // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
+ // $this->form->fill([
+ // 'plant_id'=> $this->pId,
+ // 'block_name'=> $this->bId,
+ // 'shift_id'=> $this->sId,
+ // 'line_id'=> $this->lId,
+ // 'item_id'=> null,
+ // 'serial_number'=> null,
+ // 'success_msg'=> null,
+ // 'production_order'=> $this->prodOrder,
+ // 'sap_msg_status' => null,
+ // 'sap_msg_description' => null,
+ // 'operator_id'=> $operatorName,
+ // 'recent_qr' => $this->recQr,
+ // ]);
+ // Notification::make()
+ // ->title('Invalid Shift')
+ // ->body("Please select a valid shift.")
+ // ->danger()
+ // ->send();
+ // //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')');
+ // return;
+ // }
+ // }
+ // }
+ // else
+ // { // record not exist on yesterday
- $this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
- 'sap_msg_status' => null,
- 'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
- 'recent_qr' => $this->recQr,
- ]);
- Notification::make()
- ->title('Invalid Shift')
- ->body("Please select a valid shift.")
- ->danger()
- ->send();
- //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')');
- return;
- }
- }
- }
- else
- { // record not exist on yesterday
+ // //$currentDate = date('Y-m-d');
+ // $yesterday = date('Y-m-d', strtotime('-1 days'));
- //$currentDate = date('Y-m-d');
- $yesterday = date('Y-m-d', strtotime('-1 days'));
+ // $shiftId = Shift::where('id', $this->sId)
+ // ->first();
- $shiftId = Shift::where('id', $this->sId)
- ->first();
+ // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
+ // $hRs = (int) $hRs;
+ // // $miNs = (int) $miNs;-*/
- [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
- $hRs = (int) $hRs;
- // $miNs = (int) $miNs;-*/
+ // $totalMinutes = $hRs * 60 + $miNs;
- $totalMinutes = $hRs * 60 + $miNs;
+ // $from_dt = $yesterday . ' ' . $shiftId->start_time;
- $from_dt = $yesterday . ' ' . $shiftId->start_time;
+ // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
- $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
+ // $currentDateTime = date('Y-m-d H:i:s');
- $currentDateTime = date('Y-m-d H:i:s');
+ // // Check if current date time is within the range
+ // if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
+ // //echo "Choosed a valid shift...";
+ // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
- // Check if current date time is within the range
- if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
- //echo "Choosed a valid shift...";
- // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
+ // $this->form->fill([
+ // 'plant_id'=> $this->pId,
+ // 'block_name'=> $this->bId,
+ // 'shift_id'=> $this->sId,
+ // 'line_id'=> $this->lId,
+ // 'item_id'=> null,
+ // 'serial_number'=> null,
+ // 'success_msg'=> null,
+ // 'production_order'=> $this->prodOrder,
+ // 'sap_msg_status' => null,
+ // 'sap_msg_description' => null,
+ // 'operator_id'=> $operatorName,
+ // 'recent_qr' => $this->recQr,
+ // ]);
+ // Notification::make()
+ // ->title('Plan Not Found')
+ // ->body("Please set production plan first.")
+ // ->danger()
+ // ->send();
+ // //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')');
+ // return;
+ // }
+ // else
+ // {
+ // $currentDate = date('Y-m-d');
- $this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
- 'sap_msg_status' => null,
- 'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
- 'recent_qr' => $this->recQr,
- ]);
- Notification::make()
- ->title('Plan Not Found')
- ->body("Please set production plan first.")
- ->danger()
- ->send();
- //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')');
- return;
- }
- else
- {
- $currentDate = date('Y-m-d');
+ // $shiftId = Shift::where('id', $this->sId)
+ // ->first();
- $shiftId = Shift::where('id', $this->sId)
- ->first();
+ // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
+ // $hRs = (int) $hRs;
+ // // $miNs = (int) $miNs;-*/
- [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
- $hRs = (int) $hRs;
- // $miNs = (int) $miNs;-*/
+ // $totalMinutes = $hRs * 60 + $miNs;
- $totalMinutes = $hRs * 60 + $miNs;
+ // $from_dt = $currentDate . ' ' . $shiftId->start_time;
- $from_dt = $currentDate . ' ' . $shiftId->start_time;
+ // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
- $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
+ // $currentDateTime = date('Y-m-d H:i:s');
- $currentDateTime = date('Y-m-d H:i:s');
+ // // Check if current date time is within the range
+ // if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
+ // //echo "Choosed a valid shift...";
+ // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
- // Check if current date time is within the range
- if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
- //echo "Choosed a valid shift...";
- // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
+ // $this->form->fill([
+ // 'plant_id'=> $this->pId,
+ // 'block_name'=> $this->bId,
+ // 'shift_id'=> $this->sId,
+ // 'line_id'=> $this->lId,
+ // 'item_id'=> null,
+ // 'serial_number'=> null,
+ // 'success_msg'=> null,
+ // 'production_order'=> $this->prodOrder,
+ // 'sap_msg_status' => null,
+ // 'sap_msg_description' => null,
+ // 'operator_id'=> $operatorName,
+ // 'recent_qr' => $this->recQr,
+ // ]);
+ // Notification::make()
+ // ->title('Plan Not Found')
+ // ->body("Please set production plan first.")
+ // ->danger()
+ // ->send();
+ // //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')');
+ // return;
+ // }
+ // else
+ // {
+ // //echo "Choosed a valid shift...";
+ // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
- $this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
- 'sap_msg_status' => null,
- 'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
- 'recent_qr' => $this->recQr,
- ]);
- Notification::make()
- ->title('Plan Not Found')
- ->body("Please set production plan first.")
- ->danger()
- ->send();
- //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')');
- return;
- }
- else
- {
- //echo "Choosed a valid shift...";
- // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
+ // $this->form->fill([
+ // 'plant_id'=> $this->pId,
+ // 'block_name'=> $this->bId,
+ // 'shift_id'=> $this->sId,
+ // 'line_id'=> $this->lId,
+ // 'item_id'=> null,
+ // 'serial_number'=> null,
+ // 'success_msg'=> null,
+ // 'production_order'=> $this->prodOrder,
+ // 'sap_msg_status' => null,
+ // 'sap_msg_description' => null,
+ // 'operator_id'=> $operatorName,
+ // 'recent_qr' => $this->recQr,
+ // ]);
+ // Notification::make()
+ // ->title('Invalid Shift')
+ // ->body("Please select a valid shift.")
+ // ->danger()
+ // ->send();
+ // //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')');
+ // return;
+ // }
+ // }
+ // }
+ // }
- $this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
- 'sap_msg_status' => null,
- 'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
- 'recent_qr' => $this->recQr,
- ]);
- Notification::make()
- ->title('Invalid Shift')
- ->body("Please select a valid shift.")
- ->danger()
- ->send();
- //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')');
- return;
- }
- }
- }
- }
+ // $this->form->fill([
+ // 'plant_id'=> $this->pId,
+ // 'block_name'=> $this->bId,
+ // 'shift_id'=> $this->sId,
+ // 'line_id'=> $this->lId,
+ // 'item_id'=> null,
+ // 'serial_number'=> null,
+ // 'success_msg'=> null,
+ // 'production_order'=> $this->prodOrder,
+ // 'sap_msg_status' => null,
+ // 'sap_msg_description' => null,
+ // 'operator_id'=> $operatorName,
+ // 'recent_qr' => $this->recQr,
+ // ]);
- // ********************************
-
- $this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
- 'sap_msg_status' => null,
- 'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
- 'recent_qr' => $this->recQr,
- ]);
}
- if (!preg_match('/^[a-zA-Z0-9]{6,}+\|[1-9][a-zA-Z0-9]{8,}+(\|)?$/', $formQRData)) {
- if (strpos($formQRData, '|') === false) {
+ if (! preg_match('/^[a-zA-Z0-9]{6,}+\|[1-9][a-zA-Z0-9]{8,}+(\|)?$/', $formQRData)) {
+
+ if (strpos($formQRData, '|') == false) {
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
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;
- }
- else
- {
+ } else {
$splits = explode('|', $formQRData);
$iCode = trim($splits[0]);
$sNumber = isset($splits[1]) ? trim($splits[1]) : null;
- if (!ctype_alnum($iCode)) {
+
+ if (! ctype_alnum($iCode)) {
+
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
Notification::make()
->title('Invalid Item Code')
- ->body("Item code must contain alpha-numeric values only.")
+ ->body('Item code must contain alpha-numeric values only.')
->danger()
->send();
+
return;
- }
- else if (strlen($iCode) < 6) {
+ } elseif (strlen($iCode) < 6) {
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
Notification::make()
->title('Invalid Item Code')
- ->body("Item code must be at least 6 digits.")
+ ->body('Item code must be at least 6 digits.')
->danger()
->send();
+
return;
- }
- else if (!ctype_alnum($sNumber)) {
+ } elseif (! ctype_alnum($sNumber)) {
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
Notification::make()
->title('Invalid Serial Number')
- ->body("Serial Number must contain alpha-numeric values only.")
+ ->body('Serial Number must contain alpha-numeric values only.')
->danger()
->duration(800)
->send();
+
return;
- }
- else if (strlen($sNumber) < 9) {
+ } elseif (strlen($sNumber) < 9) {
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
Notification::make()
->title('Invalid Serial Number')
- ->body("Serial Number must be at least 9 digits.")
+ ->body('Serial Number must be at least 9 digits.')
->danger()
->duration(800)
->send();
+
return;
}
}
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
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;
- }
- else
- {
+ } else {
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
}
@@ -1148,27 +1276,28 @@ class ProductionQuantityPage extends Page implements HasForms
// Fetch item using item code and plant_id
$masItem = Item::where('code', $itemCode)->first();
- if (!$masItem)
- {
+ if (! $masItem) {
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
Notification::make()
->title('Unknown Item Code')
- ->body("Item code does not exist in master data.")
+ ->body('Item code does not exist in master data.')
->danger()
->send();
+
return;
}
@@ -1176,142 +1305,224 @@ class ProductionQuantityPage extends Page implements HasForms
->where('plant_id', $this->pId)
->first();
- if ($item)
- {
+ if ($item) {
$sNo = ProductionQuantity::where('serial_number', $serialNumber)->where('plant_id', $this->pId)->exists();
- if (!$sNo)
- {
+ if (! $sNo) {
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> $item->id,
- 'serial_number'=> null,
- 'success_msg'=> 'Y',
- 'production_order'=> $this->prodOrder,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => $item->id,
+ 'serial_number' => null,
+ 'success_msg' => 'Y',
+ 'production_order' => $this->prodOrder,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
$this->succId = 'Y';
$this->iId = $item->id;
- }
- else
- {
+ } else {
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
Notification::make()
->title('Duplicate Serial Number')
- ->body("Serial number already exist in database for choosed plant.")
+ ->body('Serial number already exist in database for choosed plant.')
->danger()
->send();
+
return;
}
- }
- else
- {
+ } else {
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
Notification::make()
->title('Unknown Item Code')
- ->body("Item code does not exist in master data for choosed plant.")
+ ->body('Item code does not exist in master data for choosed plant.')
->danger()
->send();
+
return;
}
- if ($this->succId === null) {
+ if ($this->succId == null) {
$this->form->fill([
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $this->recQr,
]);
Notification::make()
- ->title("Invalid QR Found") // {$operatorName}
- ->body("Please, scan the valid QR code.")
- ->danger()
- // ->persistent()
- ->send();
+ ->title('Invalid QR Found') // {$operatorName}
+ ->body('Please, scan the valid QR code.')
+ ->danger()
+ ->send();
+
return;
- }
- else
- {
- // // Perform any additional processing or database operations
- // $this->saveFormData($formValues);
+ } else {
$parts = explode('|', $this->qrData);
$itemCode = trim($parts[0]);
$this->sNoId = isset($parts[1]) ? trim($parts[1]) : null;
+ $machine = Machine::where('work_center', $this->mNam)->where('plant_id', $this->pId)->first();
+
+ if (! $machine) {
+ Notification::make()
+ ->title('Unknown Machine')
+ ->body("Work center {$this->mNam} not found for this plant.")
+ ->danger()
+ ->send();
+
+ return;
+ }
+
+ $this->mId = $machine->id;
+
+ $this->lId = $machine->line_id;
+
+ $line = Line::find($this->lId);
+ if (! $line) {
+ Notification::make()
+ ->title('Invalid Line')
+ ->body('Line associated with the machine not found.')
+ ->danger()
+ ->send();
+
+ return;
+ }
+
+ $this->bId = $line->block_id;
+
+ $shift = Shift::where('block_id', $this->bId)->first();
+ if (! $shift) {
+ Notification::make()
+ ->title('No Shift Found')
+ ->body('No shift associated with this block.')
+ ->danger()
+ ->send();
+
+ return;
+ }
+
+ $this->sId = $shift->id;
+
+ $currentMonth = Carbon::now()->month;
+ $currentYear = Carbon::now()->year;
+
+ // $line = Line::with('block')->find($this->lId);
+
+ // $this->lNam = $line?->name;
+ // $this->bNam = $line?->block?->name;
+ // $this->sNam = $shift?->name;
+
+ $hasPlan = ProductionPlan::where('plant_id', $this->pId)
+ ->where('line_id', $this->lId)
+ ->where('item_id', $this->iId)
+ ->whereMonth('created_at', $currentMonth)
+ ->whereYear('created_at', $currentYear)
+ ->where('plan_quantity', '>', 0)
+ ->exists();
+
+ if (! $hasPlan) {
+ Notification::make()
+ ->title('No Production Plan')
+ ->body('Scanned Item Code has no plan quantity for current month/year.')
+ ->danger()
+ ->send();
+
+ $this->form->fill([
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
+ 'sap_msg_status' => null,
+ 'sap_msg_description' => null,
+ 'operator_id' => $operatorName,
+ 'recent_qr' => $this->recQr,
+ ]);
+
+ return;
+ }
+
ProductionQuantity::create([
- 'plant_id'=> $this->pId,
- 'shift_id'=> $this->sId,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mId,
+ 'shift_id' => $this->sId,
'line_id' => $this->lId,
- 'item_id'=> $this->iId,
+ 'item_id' => $this->iId,
'serial_number' => $this->sNoId,
- 'production_order'=> $this->prodOrder,
- 'operator_id'=> $operatorName,
+ 'production_order' => $this->prodOrder,
+ 'operator_id' => $operatorName,
]);
$this->iId = null;
+ // $this->recent_qr = $itemCode.' | '.$this->sNoId;
// after success insertion
$this->form->fill([
-
- 'plant_id'=> $this->pId,
- 'block_name'=> $this->bId,
- 'shift_id'=> $this->sId,
- 'line_id'=> $this->lId,
- 'item_id'=> null,
- //'item_code'=> null,
- 'serial_number'=> null,
- 'success_msg'=> null,
- 'production_order'=> $this->prodOrder,
+ 'plant_id' => $this->pId,
+ 'machine_id' => $this->mNam,
+ 'block_name' => $this->bNam,
+ 'shift_id' => $this->sNam,
+ 'line_id' => $this->lNam,
+ 'item_id' => null,
+ 'serial_number' => null,
+ 'success_msg' => null,
+ 'production_order' => $this->prodOrder,
'sap_msg_status' => null,
'sap_msg_description' => null,
- 'operator_id'=> $operatorName,
+ 'operator_id' => $operatorName,
'recent_qr' => $itemCode.' | '.$this->sNoId,
]);
Notification::make()
- ->title("Valid QR Found") // {$operatorName}
+ ->title('Valid QR Found') // {$operatorName}
->body("Valid QR code scanned: {$this->qrData}.")
->success()
->duration(200)
@@ -1332,6 +1543,7 @@ class ProductionQuantityPage extends Page implements HasForms
// // Optionally, you can emit an event or perform a redirect after saving
// $this->emit('formSaved', $model->id);
}
+
public function triggerChartUpdate(): void
{
if (session()->has('select_plant') && session()->has('select_line')) {
@@ -1354,5 +1566,4 @@ class ProductionQuantityPage extends Page implements HasForms
{
return Auth::check() && Auth::user()->can('create ProductionQuantities');
}
-
}
diff --git a/app/Filament/Resources/LineResource.php b/app/Filament/Resources/LineResource.php
index 7b690b4..ad2e088 100644
--- a/app/Filament/Resources/LineResource.php
+++ b/app/Filament/Resources/LineResource.php
@@ -5,6 +5,7 @@ namespace App\Filament\Resources;
use App\Filament\Exports\LineExporter;
use App\Filament\Imports\LineImporter;
use App\Filament\Resources\LineResource\Pages;
+use App\Models\Block;
use App\Models\Line;
use App\Models\Plant;
use App\Models\WorkGroupMaster;
@@ -71,6 +72,38 @@ class LineResource extends Resource
])
->hint(fn ($get) => $get('lPlantError') ? $get('lPlantError') : null)
->hintColor('danger'),
+ Forms\Components\Select::make('block_id')
+ ->label('Block')
+ ->relationship('block', 'name')
+ // ->required()
+ // ->nullable(),
+ ->reactive()
+ ->options(function (callable $get) {
+ if (! $get('plant_id')) {
+ return [];
+ }
+
+ return Block::where('plant_id', $get('plant_id'))
+ ->pluck('name', 'id')
+ ->toArray();
+ })
+ ->default(function () {
+ return optional(Block::latest()->first())->plant_id;
+ })
+ ->afterStateUpdated(function ($state, callable $set, callable $get) {
+ $blockId = $get('block_id');
+ if (! $blockId) {
+ $set('lblockError', 'Please select a Block first.');
+ return;
+ } else {
+ $set('lblockError', null);
+ }
+ })
+ ->extraAttributes(fn ($get) => [
+ 'class' => $get('lblockError') ? 'border-red-500' : '',
+ ])
+ ->hint(fn ($get) => $get('lblockError') ? $get('lblockError') : null)
+ ->hintColor('danger'),
Forms\Components\TextInput::make('name')
->required()
->placeholder('Scan the valid name')
@@ -1012,6 +1045,11 @@ class LineResource extends Resource
->alignCenter()
->sortable()
->searchable(),
+ Tables\Columns\TextColumn::make('block.name')
+ ->label('Block')
+ ->alignCenter()
+ ->sortable()
+ ->searchable(),
Tables\Columns\TextColumn::make('name')
->label('Line')
->alignCenter()
diff --git a/app/Filament/Resources/ProductionPlanResource.php b/app/Filament/Resources/ProductionPlanResource.php
index d255a59..f2a1b4e 100644
--- a/app/Filament/Resources/ProductionPlanResource.php
+++ b/app/Filament/Resources/ProductionPlanResource.php
@@ -7,6 +7,7 @@ use App\Filament\Exports\ProductionPlanExporter;
use App\Filament\Imports\ProductionPlanImporter;
use App\Filament\Resources\ProductionPlanResource\Pages;
use App\Models\Block;
+use App\Models\Item;
use App\Models\Line;
use App\Models\Plant;
use App\Models\ProductionPlan;
@@ -77,97 +78,6 @@ class ProductionPlanResource extends Resource
])
->hint(fn ($get) => $get('ppPlantError') ? $get('ppPlantError') : null)
->hintColor('danger'),
- Forms\Components\Select::make('block_name')
- ->required()
- // ->nullable()
- ->label('Block')
- ->options(function (callable $get) {
- if (! $get('plant_id')) {
- return [];
- }
-
- return Block::where('plant_id', $get('plant_id'))
- ->pluck('name', 'id')
- ->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 = Shift::where('id', $getShift->shift_id)->first();
- if ($getBlock->block_id) {
- $set('block_name', $getBlock->block_id);
- $set('ppBlockError', null);
- }
- }
-
- $blockId = $get('block_name');
- $set('shift_id', null);
-
- if (! $blockId) {
- $set('ppBlockError', 'Please select a block first.');
-
- return;
- } else {
- $set('ppBlockError', null);
- }
- })
- ->extraAttributes(fn ($get) => [
- 'class' => $get('ppBlockError') ? 'border-red-500' : '',
- ])
- ->hint(fn ($get) => $get('ppBlockError') ? $get('ppBlockError') : null)
- ->hintColor('danger'),
- Forms\Components\Select::make('shift_id')
- ->relationship('shift', 'name')
- ->required()
- // ->nullable()
- ->autofocus(true)
- ->options(function (callable $get) {
- if (! $get('plant_id') || ! $get('block_name')) {
- return [];
- }
-
- 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')) {
- $getShift = ProductionPlan::where('id', $get('id'))->first();
- if ($getShift->shift_id) {
- $set('shift_id', $getShift->shift_id);
- $set('ppShiftError', null);
- }
- }
-
- $curShiftId = $get('shift_id');
- $set('line_id', null);
-
- if (! $curShiftId) {
- $set('ppShiftError', 'Please select a shift first.');
-
- return;
- } else {
- $set('ppShiftError', null);
- }
- })
- ->extraAttributes(fn ($get) => [
- 'class' => $get('ppShiftError') ? 'border-red-500' : '',
- ])
- ->hint(fn ($get) => $get('ppShiftError') ? $get('ppShiftError') : null)
- ->hintColor('danger'),
Forms\Components\Select::make('line_id')
->relationship('line', 'name')
->required()
@@ -178,7 +88,7 @@ class ProductionPlanResource extends Resource
// ->toArray() // Convert collection to array
// )
->options(function (callable $get) {
- if (! $get('plant_id') || ! $get('block_name') || ! $get('shift_id')) {
+ if (! $get('plant_id')) {
return [];
}
@@ -190,239 +100,257 @@ class ProductionPlanResource extends Resource
// ->default(function () {
// return optional(ProductionPlan::latest()->first())->line_id;
// })
+ // ->afterStateUpdated(function ($state, callable $set, callable $get) {
+ // if ($get('id')) {
+ // $getShift = ProductionPlan::where('id', $get('id'))->first();
+ // if ($getShift->line_id) {
+ // $set('line_id', $getShift->line_id);
+ // $set('ppLineError', null);
+ // }
+ // } else {
+ // $currentDT = Carbon::now()->toDateTimeString();
+ // $set('created_at', $currentDT);
+ // $set('update_date', null);
+ // }
+
+ // $lineId = $get('line_id');
+ // // $set('plan_quantity', null);
+
+ // if (! $lineId) {
+ // $set('ppLineError', 'Please select a line first.');
+
+ // return;
+ // } else {
+ // $isUpdate = ! empty($get('id'));
+ // if (! $isUpdate) {
+ // $exists = ProductionPlan::where('plant_id', $get('plant_id'))
+ // ->where('shift_id', $get('shift_id'))
+ // ->where('line_id', $get('line_id'))
+ // ->whereDate('created_at', today())
+ // ->latest()
+ // ->exists();
+
+ // if ($exists) {
+ // $set('line_id', null);
+ // $set('ppLineError', 'Production plan already updated.');
+
+ // return;
+ // } else {
+ // $existShifts = ProductionPlan::where('plant_id', $get('plant_id'))
+ // ->where('shift_id', $get('shift_id'))
+ // ->where('line_id', $get('line_id'))
+ // ->whereDate('created_at', Carbon::yesterday())
+ // ->latest()
+ // ->exists();
+
+ // if ($existShifts) { // if ($existShifts->count() > 0)
+ // // $currentDate = date('Y-m-d');
+ // $yesterday = date('Y-m-d', strtotime('-1 days'));
+
+ // $shiftId = Shift::where('id', $get('shift_id'))
+ // ->first();
+
+ // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
+ // $hRs = (int) $hRs;
+ // // $miNs = (int) $miNs;-*/
+
+ // $totalMinutes = $hRs * 60 + $miNs;
+
+ // $from_dt = $yesterday.' '.$shiftId->start_time;
+
+ // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
+
+ // $currentDateTime = date('Y-m-d H:i:s');
+
+ // // Check if current date time is within the range
+ // if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
+ // // echo "Choosed a valid shift...";
+
+ // $set('line_id', null);
+ // $set('ppLineError', 'Production plan already updated.');
+
+ // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
+ // return;
+ // } else {
+ // $currentDate = date('Y-m-d');
+
+ // $shiftId = Shift::where('id', $get('shift_id'))
+ // ->first();
+
+ // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
+ // $hRs = (int) $hRs;
+ // // $miNs = (int) $miNs;-*/
+
+ // $totalMinutes = $hRs * 60 + $miNs;
+
+ // $from_dt = $currentDate.' '.$shiftId->start_time;
+
+ // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
+
+ // $currentDateTime = date('Y-m-d H:i:s');
+
+ // // Check if current date time is within the range
+ // if (! ($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
+ // // echo "Choosed a valid shift...";
+
+ // $set('line_id', null);
+ // $set('ppLineError', 'Choosed a invalid shift.');
+
+ // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
+ // return;
+ // }
+ // }
+
+ // $set('ppLineError', null);
+
+ // return;
+ // } else {
+ // // $currentDate = date('Y-m-d');
+ // $yesterday = date('Y-m-d', strtotime('-1 days'));
+
+ // $shiftId = Shift::where('id', $get('shift_id'))
+ // ->first();
+
+ // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
+ // $hRs = (int) $hRs;
+ // // $miNs = (int) $miNs;-*/
+
+ // $totalMinutes = $hRs * 60 + $miNs;
+
+ // $from_dt = $yesterday.' '.$shiftId->start_time;
+
+ // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
+
+ // $currentDateTime = date('Y-m-d H:i:s');
+
+ // // Check if current date time is within the range
+ // if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
+ // // echo "Choosed a valid shift...";
+
+ // // here i'm updating created as yesterday
+ // $set('created_at', $from_dt);
+ // $set('update_date', '1');
+
+ // $set('ppLineError', null);
+
+ // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
+ // return;
+ // } else {
+ // $currentDate = date('Y-m-d');
+
+ // $shiftId = Shift::where('id', $get('shift_id'))
+ // ->first();
+
+ // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
+ // $hRs = (int) $hRs;
+ // // $miNs = (int) $miNs;-*/
+
+ // $totalMinutes = $hRs * 60 + $miNs;
+
+ // $from_dt = $currentDate.' '.$shiftId->start_time;
+
+ // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
+
+ // $currentDateTime = date('Y-m-d H:i:s');
+
+ // // Check if current date time is within the range
+ // if (! ($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
+ // // echo "Choosed a valid shift...";
+
+ // $set('line_id', null);
+ // $set('ppLineError', 'Choosed a invalid shift.');
+
+ // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
+ // return;
+ // }
+ // }
+
+ // $set('ppLineError', null);
+
+ // return;
+ // }
+
+ // // $exists = ProductionPlan::where('plant_id', $get('plant_id'))
+ // // //->where('shift_id', $get('shift_id'))
+ // // ->where('line_id', $get('line_id'))
+ // // ->whereDate('created_at', today())
+ // // ->latest() // Orders by created_at DESC
+ // // ->first();
+
+ // // if ($exists)
+ // // {
+ // // $existingShifts = ProductionPlan::where('plant_id', $get('plant_id'))
+ // // //->where('shift_id', $get('shift_id'))
+ // // ->where('line_id', $get('line_id'))
+ // // // ->whereDate('created_at', today())
+ // // ->whereDate('created_at', today())
+ // // ->get();
+
+ // // foreach ($existingShifts as $shift) {
+ // // $curShiftId = $shift->shift_id;
+
+ // // $currentDate = date('Y-m-d');
+
+ // // $shiftId = \App\Models\Shift::where('id', $curShiftId)
+ // // ->first();
+
+ // // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
+ // // $hRs = (int) $hRs;
+ // // // $miNs = (int) $miNs;-*/
+
+ // // $totalMinutes = $hRs * 60 + $miNs;
+
+ // // $from_dt = $currentDate . ' ' . $shiftId->start_time;
+
+ // // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
+
+ // // $currentDateTime = date('Y-m-d H:i:s');
+
+ // // // Check if current date time is within the range
+ // // if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
+ // // //echo "Choosed a valid shift...";
+ // // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
+
+ // // $set('line_id', null);
+ // // $set('ppLineError', 'Production plan already updated.');
+ // // return;
+ // // }
+ // // // else {
+ // // // $set('ppLineError', 'Choosed a invalid shift...');
+ // // // return;
+ // // // }
+ // // }
+ // // $set('ppLineError', null);
+ // // return;
+ // // }
+ // }
+ // }
+ // $set('ppLineError', null);
+ // }
+ // })
->afterStateUpdated(function ($state, callable $set, callable $get) {
- if ($get('id')) {
- $getShift = ProductionPlan::where('id', $get('id'))->first();
- if ($getShift->line_id) {
- $set('line_id', $getShift->line_id);
- $set('ppLineError', null);
- }
- } else {
- $currentDT = Carbon::now()->toDateTimeString();
- $set('created_at', $currentDT);
- $set('update_date', null);
- }
-
- $lineId = $get('line_id');
- // $set('plan_quantity', null);
-
- if (! $lineId) {
- $set('ppLineError', 'Please select a line first.');
-
- return;
- } else {
- $isUpdate = ! empty($get('id'));
- if (! $isUpdate) {
- $exists = ProductionPlan::where('plant_id', $get('plant_id'))
- ->where('shift_id', $get('shift_id'))
- ->where('line_id', $get('line_id'))
- ->whereDate('created_at', today())
- ->latest()
- ->exists();
-
- if ($exists) {
- $set('line_id', null);
- $set('ppLineError', 'Production plan already updated.');
-
- return;
- } else {
- $existShifts = ProductionPlan::where('plant_id', $get('plant_id'))
- ->where('shift_id', $get('shift_id'))
- ->where('line_id', $get('line_id'))
- ->whereDate('created_at', Carbon::yesterday())
- ->latest()
- ->exists();
-
- if ($existShifts) { // if ($existShifts->count() > 0)
- // $currentDate = date('Y-m-d');
- $yesterday = date('Y-m-d', strtotime('-1 days'));
-
- $shiftId = Shift::where('id', $get('shift_id'))
- ->first();
-
- [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
- $hRs = (int) $hRs;
- // $miNs = (int) $miNs;-*/
-
- $totalMinutes = $hRs * 60 + $miNs;
-
- $from_dt = $yesterday.' '.$shiftId->start_time;
-
- $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
-
- $currentDateTime = date('Y-m-d H:i:s');
-
- // Check if current date time is within the range
- if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
- // echo "Choosed a valid shift...";
-
- $set('line_id', null);
- $set('ppLineError', 'Production plan already updated.');
-
- // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
- return;
- } else {
- $currentDate = date('Y-m-d');
-
- $shiftId = Shift::where('id', $get('shift_id'))
- ->first();
-
- [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
- $hRs = (int) $hRs;
- // $miNs = (int) $miNs;-*/
-
- $totalMinutes = $hRs * 60 + $miNs;
-
- $from_dt = $currentDate.' '.$shiftId->start_time;
-
- $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
-
- $currentDateTime = date('Y-m-d H:i:s');
-
- // Check if current date time is within the range
- if (! ($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
- // echo "Choosed a valid shift...";
-
- $set('line_id', null);
- $set('ppLineError', 'Choosed a invalid shift.');
-
- // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
- return;
- }
- }
-
- $set('ppLineError', null);
-
- return;
- } else {
- // $currentDate = date('Y-m-d');
- $yesterday = date('Y-m-d', strtotime('-1 days'));
-
- $shiftId = Shift::where('id', $get('shift_id'))
- ->first();
-
- [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
- $hRs = (int) $hRs;
- // $miNs = (int) $miNs;-*/
-
- $totalMinutes = $hRs * 60 + $miNs;
-
- $from_dt = $yesterday.' '.$shiftId->start_time;
-
- $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
-
- $currentDateTime = date('Y-m-d H:i:s');
-
- // Check if current date time is within the range
- if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
- // echo "Choosed a valid shift...";
-
- // here i'm updating created as yesterday
- $set('created_at', $from_dt);
- $set('update_date', '1');
-
- $set('ppLineError', null);
-
- // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
- return;
- } else {
- $currentDate = date('Y-m-d');
-
- $shiftId = Shift::where('id', $get('shift_id'))
- ->first();
-
- [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
- $hRs = (int) $hRs;
- // $miNs = (int) $miNs;-*/
-
- $totalMinutes = $hRs * 60 + $miNs;
-
- $from_dt = $currentDate.' '.$shiftId->start_time;
-
- $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
-
- $currentDateTime = date('Y-m-d H:i:s');
-
- // Check if current date time is within the range
- if (! ($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
- // echo "Choosed a valid shift...";
-
- $set('line_id', null);
- $set('ppLineError', 'Choosed a invalid shift.');
-
- // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
- return;
- }
- }
-
- $set('ppLineError', null);
-
- return;
- }
-
- // $exists = ProductionPlan::where('plant_id', $get('plant_id'))
- // //->where('shift_id', $get('shift_id'))
- // ->where('line_id', $get('line_id'))
- // ->whereDate('created_at', today())
- // ->latest() // Orders by created_at DESC
- // ->first();
-
- // if ($exists)
- // {
- // $existingShifts = ProductionPlan::where('plant_id', $get('plant_id'))
- // //->where('shift_id', $get('shift_id'))
- // ->where('line_id', $get('line_id'))
- // // ->whereDate('created_at', today())
- // ->whereDate('created_at', today())
- // ->get();
-
- // foreach ($existingShifts as $shift) {
- // $curShiftId = $shift->shift_id;
-
- // $currentDate = date('Y-m-d');
-
- // $shiftId = \App\Models\Shift::where('id', $curShiftId)
- // ->first();
-
- // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
- // $hRs = (int) $hRs;
- // // $miNs = (int) $miNs;-*/
-
- // $totalMinutes = $hRs * 60 + $miNs;
-
- // $from_dt = $currentDate . ' ' . $shiftId->start_time;
-
- // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
-
- // $currentDateTime = date('Y-m-d H:i:s');
-
- // // Check if current date time is within the range
- // if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
- // //echo "Choosed a valid shift...";
- // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
-
- // $set('line_id', null);
- // $set('ppLineError', 'Production plan already updated.');
- // return;
- // }
- // // else {
- // // $set('ppLineError', 'Choosed a invalid shift...');
- // // return;
- // // }
- // }
- // $set('ppLineError', null);
- // return;
- // }
- }
- }
- $set('ppLineError', null);
- }
+ $set('item_id', null);
+ $set('plan_quantity', null);
})
->extraAttributes(fn ($get) => [
'class' => $get('ppLineError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('ppLineError') ? $get('ppLineError') : null)
->hintColor('danger'),
+ Forms\Components\Select::make('item_id')
+ ->label('Item')
+ ->reactive()
+ ->searchable()
+ ->required()
+ ->options(function (callable $get) {
+ if (! $get('plant_id')) {
+ return [];
+ }
+
+ return Item::where('plant_id', $get('plant_id'))
+ ->pluck('code', 'id')
+ ->toArray();
+ }),
Forms\Components\TextInput::make('plan_quantity')
->required()
->integer()
@@ -453,29 +381,19 @@ class ProductionPlanResource extends Resource
])
->hint(fn ($get) => $get('ppPlanQuanError') ? $get('ppPlanQuanError') : null)
->hintColor('danger'),
- Forms\Components\TextInput::make('production_quantity')
- ->required()
- ->integer()
- ->label('Production Quantity')
- ->readOnly(fn (callable $get) => ! $get('id'))
- ->default(0),
+ // Forms\Components\TextInput::make('production_quantity')
+ // ->required()
+ // ->integer()
+ // ->label('Production Quantity')
+ // ->readOnly(fn (callable $get) => ! $get('id'))
+ // ->default(0),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
- Forms\Components\TextInput::make('update_date')
- ->hidden()
- ->reactive()
- ->readOnly(),
- Forms\Components\DateTimePicker::make('created_at')
- ->label('Created DateTime')
- ->hidden()
- ->reactive()
- ->required()
- ->readOnly(),
Forms\Components\Hidden::make('operator_id')
->default(Filament::auth()->user()->name),
])
- ->columns(2),
+ ->columns(4),
]);
}
@@ -513,32 +431,52 @@ class ProductionPlanResource extends Resource
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
+ Tables\Columns\TextColumn::make('plant.name')
+ ->label('Plant')
+ ->alignCenter()
+ ->sortable()
+ ->searchable(),
+ Tables\Columns\TextColumn::make('line.name')
+ ->label('Plant')
+ ->alignCenter()
+ ->sortable()
+ ->searchable(),
+ Tables\Columns\TextColumn::make('item.code')
+ ->label('Item')
+ ->alignCenter()
+ ->sortable()
+ ->searchable(),
Tables\Columns\TextColumn::make('plan_quantity')
->label('Plan Quantity')
->alignCenter()
->numeric()
- ->sortable(),
+ ->sortable()
+ ->searchable(),
+ Tables\Columns\TextColumn::make('working_days')
+ ->label('Working Days')
+ ->alignCenter()
+ ->numeric()
+ ->sortable()
+ ->searchable(),
Tables\Columns\TextColumn::make('production_quantity')
->label('Production Quantity')
->alignCenter()
->numeric()
- ->sortable(),
- Tables\Columns\TextColumn::make('line.name')
- ->label('Line')
- ->alignCenter()
- ->sortable(), // ->searchable(),
- Tables\Columns\TextColumn::make('shift.block.name')
- ->label('Block')
- ->alignCenter()
- ->sortable(),
- Tables\Columns\TextColumn::make('shift.name')
- ->label('Shift')
- ->alignCenter()
- ->sortable(), // ->searchable(),
- Tables\Columns\TextColumn::make('plant.name')
- ->label('Plant')
- ->alignCenter()
- ->sortable(), // ->searchable(),
+ ->sortable()
+ ->searchable(),
+ // Tables\Columns\TextColumn::make('line.name')
+ // ->label('Line')
+ // ->alignCenter()
+ // ->sortable(), // ->searchable(),
+ // Tables\Columns\TextColumn::make('shift.block.name')
+ // ->label('Block')
+ // ->alignCenter()
+ // ->sortable(),
+ // Tables\Columns\TextColumn::make('shift.name')
+ // ->label('Shift')
+ // ->alignCenter()
+ // ->sortable(), // ->searchable(),
+
Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->dateTime()
diff --git a/resources/views/filament/pages/production-quantity.blade.php b/resources/views/filament/pages/production-quantity.blade.php
index dfa7832..0ddf762 100644
--- a/resources/views/filament/pages/production-quantity.blade.php
+++ b/resources/views/filament/pages/production-quantity.blade.php
@@ -7,6 +7,8 @@
{{ $this->form }}
+ {{--