Merge pull request 'ranjith-dev' (#552) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

Reviewed-on: #552
This commit was merged in pull request #552.
This commit is contained in:
2026-04-29 12:50:01 +00:00
9 changed files with 411 additions and 222 deletions

View File

@@ -25,15 +25,15 @@ class WorkGroupMasterExporter extends Exporter
ExportColumn::make('plant.code') ExportColumn::make('plant.code')
->label('PLANT CODE'), ->label('PLANT CODE'),
ExportColumn::make('name') ExportColumn::make('name')
->label('WORK GROUP NAME'), ->label('GROUP WORK CENTER'),
ExportColumn::make('description') ExportColumn::make('description')
->label('WORK GROUP DESCRIPTION'), ->label('DESCRIPTION'),
ExportColumn::make('operation_number') ExportColumn::make('operation_number')
->label('OPERATION NUMBER'), ->label('OPERATION NUMBER'),
ExportColumn::make('created_by')
->label('CREATED BY'),
ExportColumn::make('created_at') ExportColumn::make('created_at')
->label('CREATED AT'), ->label('CREATED AT'),
ExportColumn::make('created_by')
->label('CREATED BY'),
ExportColumn::make('updated_at') ExportColumn::make('updated_at')
->label('UPDATED AT'), ->label('UPDATED AT'),
ExportColumn::make('deleted_at') ExportColumn::make('deleted_at')

View File

@@ -27,15 +27,15 @@ class WorkGroupMasterImporter extends Importer
->rules(['required']), ->rules(['required']),
ImportColumn::make('name') ImportColumn::make('name')
->requiredMapping() ->requiredMapping()
->exampleHeader('Work Group Name') ->exampleHeader('Group Work Center')
->example('RMGCEABC') ->example('RMGCEABC')
->label('Work Group Name') ->label('Group Work Center')
->rules(['required']), ->rules(['required']),
ImportColumn::make('description') ImportColumn::make('description')
->requiredMapping() ->requiredMapping()
->exampleHeader('Work Group Description') ->exampleHeader('Description')
->example('Testing Model 1') ->example('Testing Model 1')
->label('Work Group Description') ->label('Description')
->rules(['required']), ->rules(['required']),
ImportColumn::make('operation_number') ImportColumn::make('operation_number')
->requiredMapping() ->requiredMapping()
@@ -60,85 +60,92 @@ class WorkGroupMasterImporter extends Importer
// ]); // ]);
$warnMsg = []; $warnMsg = [];
$plantCod = $this->data['plant']; $plantCod = $this->data['plant'];
$createdBy = $this->data['created_by'];
$groupWorkCenter = $this->data['name'];
$desc = trim($this->data['description']);
$opNo = $this->data['operation_number'];
$plantId = null; $plantId = null;
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) { if (! $plantCod || $plantCod == null || $plantCod == '') {
$warnMsg[] = 'Invalid plant code found'; $warnMsg[] = "Plant code can't be empty!";
} elseif (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = "Invalid plant code '{$plantCod}' found!";
} else { } else {
$plant = Plant::where('code', $plantCod)->first(); $plant = Plant::where('code', $plantCod)->first();
if (! $plant) { if (! $plant) {
$warnMsg[] = 'Plant not found'; $warnMsg[] = "Plant code '{$plantCod}' not found!";
} else { } else {
$plantId = $plant->id; $plantId = $plant->id;
} }
} }
if (Str::length($this->data['name']) <= 0) { // || !ctype_alnum($this->data['description']) if (Str::length($groupWorkCenter) <= 0) { // || !ctype_alnum($desc)
$warnMsg[] = 'Invalid work group name found'; $warnMsg[] = 'Invalid group work center found!';
} }
if (Str::length(trim($this->data['description'])) <= 0) { if (Str::length(trim($desc)) <= 0) {
$warnMsg[] = 'Invalid work group description found'; $warnMsg[] = 'Invalid description found!';
} }
$desc = trim($this->data['description']);
if (Str::length($desc) > 44) { if (Str::length($desc) > 44) {
$warnMsg[] = ' work group description should be less than 44 digits.'; $warnMsg[] = 'Description should be less than 44 digits.';
} }
if (Str::length($this->data['operation_number']) <= 0) { if (Str::length($opNo) <= 0) {
$warnMsg[] = 'Invalid operation number found'; $warnMsg[] = 'Invalid operation number found!';
} }
if (! is_numeric($this->data['operation_number'])) { if (! is_numeric($opNo)) {
$warnMsg[] = 'Invalid operation number found must be numeric'; $warnMsg[] = 'Operation number must be numeric values only.';
} }
$user = User::where('name', $this->data['created_by'])->first(); $user = User::where('name', $createdBy)->first();
if (! $user) { if (! $user) {
$warnMsg[] = 'Operator ID not found'; $warnMsg[] = "Operator ID '{$createdBy}' not found!";
} }
if (! empty($warnMsg)) { if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg)); throw new RowImportFailedException(implode(', ', $warnMsg));
} else { } else {
// Check (plant_id, name) // Check (plant_id, name)
$existingByName = WorkGroupMaster::where('plant_id', $plantId) // $existingByName = WorkGroupMaster::where('plant_id', $plantId)
->where('name', $this->data['name']) // ->where('name', $groupWorkCenter)
->first(); // ->first();
if ($existingByName) { // if ($existingByName) {
throw new RowImportFailedException('Work group name already exists for this plant!'); // throw new RowImportFailedException('Group work center already exists for this plant!');
} // }
// Check (plant_id, operation_number) // Check (plant_id, operation_number)
$existingByOpNum = WorkGroupMaster::where('plant_id', $plantId) // $existingByOpNum = WorkGroupMaster::where('plant_id', $plantId)
->where('operation_number', $this->data['operation_number']) // ->where('operation_number', $opNo)
->where('name', $this->data['name']) // ->where('name', $groupWorkCenter)
->first(); // ->first();
if ($existingByOpNum) { // if ($existingByOpNum) {
throw new RowImportFailedException('Operation number already exists for this plant!'); // throw new RowImportFailedException('Operation number already exists for this plant!');
} // }
// Check (plant_id) // Check (plant_id)
$existingByOperator = WorkGroupMaster::where('plant_id', $plantId) $existingByOperator = WorkGroupMaster::whereNot('plant_id', $plantId)
->where('name', $this->data['name']) ->where('name', $groupWorkCenter)
->first(); ->first();
if ($existingByOperator) { if ($existingByOperator) {
throw new RowImportFailedException('Already work group name assigned to another plant!'); throw new RowImportFailedException('Already group work center assigned to another plant!');
} }
} }
WorkGroupMaster::updateOrCreate([ WorkGroupMaster::updateOrCreate([
'plant_id' => $plantId, 'plant_id' => $plantId,
'name' => $this->data['name'], 'name' => $groupWorkCenter,
'description' => $this->data['description'], ],
'operation_number' => $this->data['operation_number'], [
'created_by' => $this->data['created_by'], 'description' => $desc,
]); 'operation_number' => $opNo,
'created_by' => $createdBy,
]
);
return null; return null;

View File

@@ -380,6 +380,7 @@ class InvoiceValidationResource extends Resource
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->searchable()
->label('Select Plant') ->label('Select Plant')
->required() ->required()
->default(function () { ->default(function () {
@@ -730,6 +731,7 @@ class InvoiceValidationResource extends Resource
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->searchable()
->label('Select Plant') ->label('Select Plant')
->required() ->required()
->default(function () { ->default(function () {

View File

@@ -13,6 +13,7 @@ use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\DateTimePicker; use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select; use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput; use Filament\Forms\Components\TextInput;
use Filament\Forms\Form; use Filament\Forms\Form;
@@ -42,41 +43,83 @@ class WeightValidationResource extends Resource
{ {
return $form return $form
->schema([ ->schema([
Forms\Components\Select::make('plant_id') Section::make('')
->relationship('plant', 'name') ->schema([
->options(function (callable $get) { Forms\Components\Select::make('plant_id')
$userHas = Filament::auth()->user()->plant_id; ->label('Plant Name')
->relationship('plant', 'name')
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->required(), ->columnSpan(1)
Forms\Components\Select::make('item_id') ->required(),
->relationship('item', 'code') Forms\Components\Select::make('item_id')
->label('Item Code') ->relationship('item', 'code')
->searchable() ->label('Item Code')
->required(), ->searchable()
Forms\Components\TextInput::make('obd_number') ->columnSpan(1)
->label('OBD Number') ->required(),
->required(), Forms\Components\TextInput::make('obd_number')
Forms\Components\TextInput::make('line_number') ->label('OBD Number')
->label('Line Number') ->minLength(8)
->required(), ->placeholder('Scan the valid OBD Number')
Forms\Components\TextInput::make('batch_number') ->columnSpan(1)
->label('Batch Number') ->required(),
->required(), Forms\Components\TextInput::make('line_number')
Forms\Components\TextInput::make('obd_weight') ->label('Line Number')
->label('Actual Weight') ->minLength(1)
->required(), ->integer()
Forms\Components\TextInput::make('vehicle_number') ->columnSpan(1)
->label('Vehicle Number'), ->placeholder('Scan the valid Line Number')
Forms\Components\TextInput::make('heat_number') ->required(),
->label('Heat Number'), Forms\Components\TextInput::make('batch_number')
Forms\Components\TextInput::make('bundle_number') ->label('Batch Number')
->label('Bundle Number'), ->minLength(8)
Forms\Components\TextInput::make('picked_weight') ->numeric()
->label('Picked Weight'), ->columnSpan(1)
Forms\Components\TextInput::make('scanned_by') ->placeholder('Scan the valid Batch Number')
->label('Scanned By'), ->required(),
Forms\Components\TextInput::make('obd_weight')
->label('Actual Weight')
->minLength(1)
->numeric()
->columnSpan(1)
->placeholder('Scan the valid Actual Weight')
->required(),
Forms\Components\TextInput::make('vehicle_number')
->label('Vehicle Number')
->minLength(10)
->columnSpan(1)
->placeholder('Scan the valid Vehicle Number'),
Forms\Components\TextInput::make('heat_number')
->label('Heat Number')
->minLength(4)
->columnSpan(1)
->placeholder('Scan the valid Heat Number'),
Forms\Components\TextInput::make('bundle_number')
->label('Bundle Number')
->minLength(1)
->numeric()
->columnSpan(1)
->placeholder('Scan the valid Bundle Number'),
Forms\Components\TextInput::make('picked_weight')
->label('Picked Weight')
->minLength(1)
->numeric()
->columnSpan(1)
->placeholder('Scan the valid Picked Weight'),
Forms\Components\TextInput::make('scanned_by')
->label('Scanned By')
->minLength(3)
->columnSpan(1)
->placeholder('Scan the valid Scanned By'),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
->columns(['default' => 1, 'sm' => 2]),
]); ]);
} }
@@ -98,7 +141,7 @@ class WeightValidationResource extends Resource
return ($currentPage - 1) * $perPage + $rowLoop->iteration; return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}), }),
Tables\Columns\TextColumn::make('plant.name') Tables\Columns\TextColumn::make('plant.name')
->label('Plant') ->label('Plant Name')
->alignCenter() ->alignCenter()
->sortable() ->sortable()
->searchable(), ->searchable(),
@@ -160,7 +203,7 @@ class WeightValidationResource extends Resource
->label('Advanced Filters') ->label('Advanced Filters')
->form([ ->form([
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Search by Plant Name')
->nullable() ->nullable()
// ->options(function () { // ->options(function () {
// return Plant::pluck('name', 'id'); // return Plant::pluck('name', 'id');
@@ -168,25 +211,24 @@ class WeightValidationResource extends Resource
->options(function (callable $get) { ->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id; $userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); // return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
if ($userHas && strlen($userHas) > 0) {
return Plant::where('id', $userHas)->pluck('name', 'id')->toArray();
} else {
return Plant::whereHas('weightValidations', function ($query) {
$query->whereNotNull('id');
})->orderBy('code')->pluck('name', 'id')->toArray();
}
}) })
->reactive(), ->searchable()
// ->afterStateUpdated(function ($state, callable $set, callable $get) { ->reactive()
// $set('sticker_master_id', null); ->afterStateUpdated(function ($state, callable $set, callable $get): void {
// $set('sap_msg_status', null); $set('Item Code', null);
// }), }),
Select::make('Item Code') Select::make('Item Code')
->label('Search by Item Code') ->label('Search by Item Code')
->nullable() ->nullable()
// ->options(function (callable $get) {
// $plantId = $get('Plant');
// if (! $plantId) {
// return [];
// }
// return Item::where('plant_id', $plantId)->pluck('code', 'id');
// })
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
if (! $plantId) { if (! $plantId) {
@@ -207,16 +249,23 @@ class WeightValidationResource extends Resource
->placeholder('Enter OBD Number'), ->placeholder('Enter OBD Number'),
Select::make('Line') Select::make('Line')
->label('Line') ->label('Line Number')
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
$itemCode = $get('Item Code');
if (! $plantId) { if (! $plantId) {
return []; return [];
} elseif (! $itemCode) {
return WeightValidation::where('plant_id', $plantId)
->distinct()
->orderBy('line_number')
->pluck('line_number', 'line_number')
->toArray();
} }
// Get unique line_numbers for the selected plant_id // Get unique line_numbers for the selected plant_id
return WeightValidation::where('plant_id', $plantId) return WeightValidation::where('plant_id', $plantId)
->where('item_id', $itemCode)
->distinct() ->distinct()
->orderBy('line_number') ->orderBy('line_number')
->pluck('line_number', 'line_number') ->pluck('line_number', 'line_number')
@@ -285,31 +334,31 @@ class WeightValidationResource extends Resource
} }
if (! empty($data['Obd Number'])) { if (! empty($data['Obd Number'])) {
$query->where('obd_number', $data['Obd Number']); $query->where('obd_number', 'like', '%'.$data['Obd Number'].'%');
} }
if (! empty($data['Batch'])) { if (! empty($data['Batch'])) {
$query->where('batch_number', $data['Batch']); $query->where('batch_number', 'like', '%'.$data['Batch'].'%');
} }
if (! empty($data['Actual Weight'])) { if (! empty($data['Actual Weight'])) {
$query->where('actual_weight', $data['Actual Weight']); $query->where('actual_weight', 'like', '%'.$data['Actual Weight'].'%');
} }
if (! empty($data['Vehicle Number'])) { if (! empty($data['Vehicle Number'])) {
$query->where('vehicle_number', $data['Vehicle Number']); $query->where('vehicle_number', 'like', '%'.$data['Vehicle Number'].'%');
} }
if (! empty($data['Heat Number'])) { if (! empty($data['Heat Number'])) {
$query->where('heat_number', $data['Heat Number']); $query->where('heat_number', 'like', '%'.$data['Heat Number'].'%');
} }
if (! empty($data['Bundle Number'])) { if (! empty($data['Bundle Number'])) {
$query->where('bundle_number', $data['Bundle Number']); $query->where('bundle_number', 'like', '%'.$data['Bundle Number'].'%');
} }
if (! empty($data['Scanned By'])) { if (! empty($data['Scanned By'])) {
$query->where('scanned_by', $data['Scanned By']); $query->where('scanned_by', 'like', '%'.$data['Scanned By'].'%');
} }
if (! empty($data['created_from'])) { if (! empty($data['created_from'])) {
@@ -324,7 +373,7 @@ class WeightValidationResource extends Resource
$indicators = []; $indicators = [];
if (! empty($data['Plant'])) { if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name'); $indicators[] = 'Plant Name : '.Plant::where('id', $data['Plant'])->value('name');
} else { } else {
$userHas = Filament::auth()->user()->plant_id; $userHas = Filament::auth()->user()->plant_id;
@@ -334,19 +383,19 @@ class WeightValidationResource extends Resource
} }
if (! empty($data['Item Code'])) { if (! empty($data['Item Code'])) {
$indicators[] = 'Item Code: '.Item::where('id', $data['Item Code'])->value('code'); $indicators[] = 'Item Code : '.Item::where('id', $data['Item Code'])->value('code');
} }
if (! empty($data['Line'])) { if (! empty($data['Line'])) {
$indicators[] = 'Line: '.$data['Line']; $indicators[] = 'Line : '.$data['Line'];
} }
if (! empty($data['Obd Number'])) { if (! empty($data['Obd Number'])) {
$indicators[] = 'OBD Number: '.$data['Obd Number']; $indicators[] = 'OBD Number : '.$data['Obd Number'];
} }
if (! empty($data['Batch'])) { if (! empty($data['Batch'])) {
$indicators[] = 'Batch Number: '.$data['Batch']; $indicators[] = 'Batch Number : '.$data['Batch'];
} }
if (! empty($data['Actual Weight'])) { if (! empty($data['Actual Weight'])) {
@@ -354,32 +403,32 @@ class WeightValidationResource extends Resource
} }
if (! empty($data['Vehicle Number'])) { if (! empty($data['Vehicle Number'])) {
$indicators[] = 'Vehicle Number: '.$data['Vehicle Number']; $indicators[] = 'Vehicle Number : '.$data['Vehicle Number'];
} }
if (! empty($data['Heat Number'])) { if (! empty($data['Heat Number'])) {
$indicators[] = 'Heat Number: '.$data['Heat Number']; $indicators[] = 'Heat Number : '.$data['Heat Number'];
} }
if (! empty($data['Bundle Number'])) { if (! empty($data['Bundle Number'])) {
$indicators[] = 'Bundle Number: '.$data['Bundle Number']; $indicators[] = 'Bundle Number : '.$data['Bundle Number'];
} }
if (! empty($data['Scanned By'])) { if (! empty($data['Scanned By'])) {
$indicators[] = 'Scanned By: '.$data['Scanned By']; $indicators[] = 'Scanned By : '.$data['Scanned By'];
} }
if (! empty($data['created_from'])) { if (! empty($data['created_from'])) {
$indicators[] = 'From: '.$data['created_from']; $indicators[] = 'From : '.$data['created_from'];
} }
if (! empty($data['created_to'])) { if (! empty($data['created_to'])) {
$indicators[] = 'To: '.$data['created_to']; $indicators[] = 'To : '.$data['created_to'];
} }
if (! empty($data['sticker_master_id'])) { if (! empty($data['sticker_master_id'])) {
$itemCode = Item::find($data['sticker_master_id'])->code ?? 'Unknown'; $itemCode = Item::find($data['sticker_master_id'])->code ?? 'Unknown';
$indicators[] = 'Item Codes: '.$itemCode; $indicators[] = 'Item Codes : '.$itemCode;
} }
return $indicators; return $indicators;
@@ -409,6 +458,7 @@ class WeightValidationResource extends Resource
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->label('Select Plant') ->label('Select Plant')
->searchable()
->required() ->required()
->default(function () { ->default(function () {
return optional(WeightValidation::latest()->first())->plant_id; return optional(WeightValidation::latest()->first())->plant_id;

View File

@@ -11,6 +11,7 @@ use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Section; use Filament\Forms\Components\Section;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction; use Filament\Tables\Actions\ExportAction;
@@ -37,7 +38,7 @@ class WorkGroupMasterResource extends Resource
Section::make('') Section::make('')
->schema([ ->schema([
Forms\Components\Select::make('plant_id') Forms\Components\Select::make('plant_id')
->label('Plant') ->label('Plant Name')
->relationship('plant', 'name') ->relationship('plant', 'name')
->reactive() ->reactive()
->columnSpan(1) ->columnSpan(1)
@@ -47,6 +48,10 @@ class WorkGroupMasterResource extends Resource
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->default(function () {
return optional(WorkGroupMaster::latest()->first())->plant_id;
})
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, $set, callable $get) { ->afterStateUpdated(function ($state, $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
@@ -68,7 +73,7 @@ class WorkGroupMasterResource extends Resource
->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null) ->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null)
->hintColor('danger'), ->hintColor('danger'),
Forms\Components\TextInput::make('name') Forms\Components\TextInput::make('name')
->label('Name') ->label('Group Work Center')
->required() ->required()
->minLength(6) ->minLength(6)
->columnSpan(1) ->columnSpan(1)
@@ -119,12 +124,12 @@ class WorkGroupMasterResource extends Resource
return ($currentPage - 1) * $perPage + $rowLoop->iteration; return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}), }),
Tables\Columns\TextColumn::make('plant.name') Tables\Columns\TextColumn::make('plant.name')
->label('Plant') ->label('Plant Name')
->alignCenter() ->alignCenter()
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('name') Tables\Columns\TextColumn::make('name')
->label('Name') ->label('Group Work Center')
->alignCenter() ->alignCenter()
->searchable() ->searchable()
->sortable(), ->sortable(),
@@ -138,23 +143,21 @@ class WorkGroupMasterResource extends Resource
->alignCenter() ->alignCenter()
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->alignCenter()
->dateTime()
->sortable(),
Tables\Columns\TextColumn::make('created_by') Tables\Columns\TextColumn::make('created_by')
->label('Created By') ->label('Created By')
->alignCenter() ->alignCenter()
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->alignCenter()
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at') Tables\Columns\TextColumn::make('updated_at')
->label('Updated At') ->label('Updated At')
->alignCenter() ->alignCenter()
->dateTime() ->dateTime()
->sortable() ->sortable(),
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at') Tables\Columns\TextColumn::make('deleted_at')
->label('Deleted At') ->label('Deleted At')
->alignCenter() ->alignCenter()

View File

@@ -19,7 +19,7 @@ class ObdController extends Controller
/** /**
* Store a newly created resource in storage. * Store a newly created resource in storage.
*/ */
public function store(Request $request) public function store_obd(Request $request)
{ {
$expectedUser = env('API_AUTH_USER'); $expectedUser = env('API_AUTH_USER');
$expectedPw = env('API_AUTH_PW'); $expectedPw = env('API_AUTH_PW');
@@ -42,51 +42,62 @@ class ObdController extends Controller
try { try {
$data = $request->all(); $data = $request->all();
$plantCode = $data['plant_code'] ?? '';
$obdNumber = $data['obd_number'] ?? '';
Log::info('OBD POST API >>', ['Post-Data' => $data]); Log::info('OBD POST API >>', ['Post-Data' => $data]);
// Validate required fields // Validate required fields
$missing = []; if (! $plantCode || $plantCode == null || $plantCode == '') {
if (empty($data['plant_name'])) { return response()->json([
$missing[] = 'plant_name'; 'status_code' => 'ERROR',
} 'status_description' => "Plant code can't be empty!",
if (empty($data['obd_number'])) { ], 404);
$missing[] = 'obd_number'; } elseif (! is_numeric($plantCode) || Str::length($plantCode) < 4 || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) { // !ctype_digit($data['plant_code'])
} return response()->json([
if (empty($data['line_numbers'])) { 'status_code' => 'ERROR',
$missing[] = 'line_numbers'; 'status_description' => "Invalid plant code '{$plantCode}' found!",
} ], 404);
} elseif (! $obdNumber || $obdNumber == null || $obdNumber == '') {
if (! empty($missing)) { // return response("ERROR: OBD Number can't be empty", 400)
$message = 'Missing required field(s): '.implode(', ', $missing); // ->header('Content-Type', 'text/plain');
return response()->json([
'status_code' => 'ERROR',
'status_description' => "OBD number can't be empty!",
], 400);
} elseif (Str::length($obdNumber) < 8) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "OBD number '{$obdNumber}' should contain minimum 8 digits!",
], 404);
} elseif (! ctype_alnum($obdNumber)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "OBD number '{$obdNumber}' should contain only alpha-numeric values!",
], 404);
} elseif (! preg_match('/^[a-zA-Z1-9][a-zA-Z0-9]{8,}$/', $obdNumber)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "OBD number '{$obdNumber}' should not begin with '0'!",
], 404);
} elseif (empty($data['line_numbers'])) {
// return response($message, 400)->header('Content-Type', 'text/plain'); // return response($message, 400)->header('Content-Type', 'text/plain');
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => $message, 'status_description' => 'Missing required field(s): line_numbers',
], 400); ], 400);
} }
// OBD Number validation // Lookup plant_id by plant code
$obdNumber = $data['obd_number']; $plant = Plant::where('code', $plantCode)->first();
if (Str::length($obdNumber) < 8 || ! ctype_alnum($obdNumber)) { if (! $plant) {
// return response("ERROR: OBD Number should contain minimum 8 digits", 400)
// ->header('Content-Type', 'text/plain');
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'OBD number should contain minimum 8 digit alpha-numeric values only!', 'status_description' => "Plant code '{$plantCode}' not found!",
], 400);
}
// Lookup plant_id by plant_name
$plantId = Plant::where('name', $data['plant_name'])->value('id');
if (! $plantId) {
// return response("ERROR: Plant '{$data['plant_name']}' not found", 404)
// ->header('Content-Type', 'text/plain');
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Plant '{$data['plant_name']}' not found!",
], 404); ], 404);
} }
$plantId = $plant?->id ?? null;
$plantName = $plant?->name ?? null;
// Check if OBD number exists for that plant // Check if OBD number exists for that plant
$obdRecords = WeightValidation::where('plant_id', $plantId) $obdRecords = WeightValidation::where('plant_id', $plantId)
@@ -94,10 +105,10 @@ class ObdController extends Controller
->exists(); ->exists();
if (! $obdRecords) { if (! $obdRecords) {
// return response( "ERROR: OBD Number '$obdNumber' not found for plant '{$data['plant_name']}'",404)->header('Content-Type', 'text/plain'); // return response( "ERROR: OBD Number '$obdNumber' not found for plant '{$plantCode}'",404)->header('Content-Type', 'text/plain');
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "OBD Number '$obdNumber' not found for plant '{$data['plant_name']}'!", 'status_description' => "OBD Number '{$obdNumber}' not found for the plant '{$plantName}'!",
], 404); ], 404);
} }
@@ -105,22 +116,23 @@ class ObdController extends Controller
$alreadyUpdatedLines = []; $alreadyUpdatedLines = [];
foreach ($data['line_numbers'] as $line) { foreach ($data['line_numbers'] as $line) {
if ($line['line_number'] == '' || $line['line_number'] == null) { $lineNumber = $line['line_number'] ?? null;
if ($lineNumber == '' || $lineNumber == null) {
// return response("ERROR: Line Number can't be empty", 400) // return response("ERROR: Line Number can't be empty", 400)
// ->header('Content-Type', 'text/plain'); // ->header('Content-Type', 'text/plain');
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Line Number can't be empty!", 'status_description' => "Line number can't be empty!",
], 404); ], 404);
} }
$record = WeightValidation::where('plant_id', $plantId) $record = WeightValidation::where('plant_id', $plantId)
->where('obd_number', $data['obd_number']) ->where('obd_number', $obdNumber)
->where('line_number', $line['line_number']) ->where('line_number', $lineNumber)
->first(); ->first();
if (! $record) { if (! $record) {
$missingLines[] = $line['line_number']; $missingLines[] = $lineNumber;
continue; continue;
} }
@@ -142,23 +154,19 @@ class ObdController extends Controller
$fieldsString = implode(', ', $missingFields).' and '.$lastField; $fieldsString = implode(', ', $missingFields).' and '.$lastField;
} }
$message = $fieldsString." can't be empty for line_number {$line['line_number']}!";
// return response($message, 400)->header('Content-Type', 'text/plain'); // return response($message, 400)->header('Content-Type', 'text/plain');
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => $message, 'status_description' => $fieldsString." can't be empty for line_number {$lineNumber}!",
], 400); ], 400);
} }
} }
if (! empty($missingLines)) { if (! empty($missingLines)) {
$message = 'Line(s) '.implode(', ', $missingLines)." not found for Plant '{$data['plant_name']}' and OBD Number: '{$data['obd_number']}'!";
// return response($message, 404)->header('Content-Type', 'text/plain'); // return response($message, 404)->header('Content-Type', 'text/plain');
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => $message, 'status_description' => 'Line(s) '.implode(', ', $missingLines)." not found for the plant '{$plantName}' and OBD number: '{$obdNumber}'!",
], 404); ], 404);
} }
@@ -168,8 +176,8 @@ class ObdController extends Controller
// Check for duplicates within the request // Check for duplicates within the request
foreach ($data['line_numbers'] as $line) { foreach ($data['line_numbers'] as $line) {
$lineNumber = $line['line_number']; $lineNumber = $line['line_number'] ?? null;
$bundleNumber = trim((string) $line['bundle_number']); $bundleNumber = trim((string) $line['bundle_number'] ?? '');
$pairKey = $lineNumber.'|'.$bundleNumber; $pairKey = $lineNumber.'|'.$bundleNumber;
if (isset($seenPairs[$pairKey])) { if (isset($seenPairs[$pairKey])) {
@@ -228,11 +236,9 @@ class ObdController extends Controller
// 400 // 400
// )->header('Content-Type', 'text/plain'); // )->header('Content-Type', 'text/plain');
$retRes = implode(', and ', $allDuplicates);
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => $retRes, 'status_description' => implode(', and ', $allDuplicates),
], 400); ], 400);
} }
@@ -244,7 +250,7 @@ class ObdController extends Controller
$lineTracker = []; $lineTracker = [];
foreach ($data['line_numbers'] as $line) { foreach ($data['line_numbers'] as $line) {
$lineNumber = $line['line_number']; $lineNumber = $line['line_number'] ?? null;
$existing = WeightValidation::where('plant_id', $plantId) $existing = WeightValidation::where('plant_id', $plantId)
->where('obd_number', $obdNumber) ->where('obd_number', $obdNumber)
->where('line_number', $lineNumber) ->where('line_number', $lineNumber)
@@ -267,11 +273,12 @@ class ObdController extends Controller
$updatedLines[] = $lineNumber; $updatedLines[] = $lineNumber;
$lineTracker[$lineNumber] = 1; $lineTracker[$lineNumber] = 1;
} else { } else {
$original = WeightValidation::where([ $original = WeightValidation::where('plant_id', $plantId)
'plant_id' => $plantId, ->where('obd_number', $obdNumber)
'obd_number' => $obdNumber, ->where('line_number', $lineNumber)
'line_number' => $lineNumber, ->orderBy('id')
])->orderBy('id')->first(); ->first();
// where(['plant_id' => $plantId, 'obd_number' => $obdNumber, 'line_number' => $lineNumber])
WeightValidation::create([ WeightValidation::create([
'plant_id' => $plantId, 'plant_id' => $plantId,
@@ -302,7 +309,7 @@ class ObdController extends Controller
} }
if ($inserted > 0) { if ($inserted > 0) {
$responseMessage .= 'Inserted successfully. Line Numbers: {'.implode(', ', $insertedLines).'}'; $responseMessage .= ' inserted successfully. Line Numbers: {'.implode(', ', $insertedLines).'}';
} }
// return response($responseMessage, 200) // return response($responseMessage, 200)
@@ -321,7 +328,6 @@ class ObdController extends Controller
} }
} }
// Route::get('obd/get-test-datas', [ObdController::class, 'get_test']);
public function get_test(Request $request) public function get_test(Request $request)
{ {
$expectedUser = env('API_AUTH_USER'); $expectedUser = env('API_AUTH_USER');
@@ -373,7 +379,7 @@ class ObdController extends Controller
} elseif (Str::length($productionOrder) < 7 || ! is_numeric($productionOrder)) { } elseif (Str::length($productionOrder) < 7 || ! is_numeric($productionOrder)) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Production order should contain minimum 7 digits numeric values only!', 'status_description' => "Production order '{$productionOrder}' should contain minimum 7 digits numeric values only!",
], 400); ], 400);
} }
@@ -382,7 +388,7 @@ class ObdController extends Controller
if (! $prodOrderExist) { if (! $prodOrderExist) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Production order not found!', 'status_description' => "Production order '{$productionOrder}' not found!",
], 400); ], 400);
} }
@@ -423,46 +429,56 @@ class ObdController extends Controller
], 403); ], 403);
} }
$plantName = $request->header('plant-name'); $plantCode = $request->header('plant-code');
$obdNumber = $request->header('obd-number'); $obdNumber = $request->header('obd-number');
Log::info('OBD GET API >>', ['plant-name' => $plantName, 'obd-number' => $obdNumber]); Log::info('OBD GET API >>', ['plant-code' => $plantCode, 'obd-number' => $obdNumber]);
if (empty($plantName)) { if (! $plantCode || $plantCode == null || $plantCode == '') {
// return response("ERROR: Plant Name can't be empty", 400)
// ->header('Content-Type', 'text/plain');
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Plant Name can't be empty!", 'status_description' => "Plant code can't be empty!",
], 400); ], 404);
} elseif (empty($obdNumber)) { } elseif (! is_numeric($plantCode) || Str::length($plantCode) < 4 || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) { // !ctype_digit($data['plant_code'])
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Invalid plant code '{$plantCode}' found!",
], 404);
} elseif (! $obdNumber || $obdNumber == null || $obdNumber == '') {
// return response("ERROR: OBD Number can't be empty", 400) // return response("ERROR: OBD Number can't be empty", 400)
// ->header('Content-Type', 'text/plain'); // ->header('Content-Type', 'text/plain');
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "OBD Number can't be empty!", 'status_description' => "OBD number can't be empty!",
], 400); ], 400);
} elseif (Str::length($obdNumber) < 8 || ! ctype_alnum($obdNumber)) { } elseif (Str::length($obdNumber) < 8) {
// return response("ERROR: OBD Number should contain minimum 8 digits: '$obdNumber'", 400)
// ->header('Content-Type', 'text/plain');
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'OBD number should contain minimum 8 digit alpha-numeric values only!', 'status_description' => "OBD number '{$obdNumber}' should contain minimum 8 digits!",
], 400); ], 404);
} } elseif (! ctype_alnum($obdNumber)) {
// Fetch the plant id by name
$plantId = Plant::where('name', $plantName)->value('id');
if (! $plantId) {
// return response("ERROR: Plant not found", 400)
// ->header('Content-Type', 'text/plain');
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Plant not found!', 'status_description' => "OBD number '{$obdNumber}' should contain only alpha-numeric values!",
], 400); ], 404);
} elseif (! preg_match('/^[a-zA-Z1-9][a-zA-Z0-9]{8,}$/', $obdNumber)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "OBD number '{$obdNumber}' should not begin with '0'!",
], 404);
} }
// Fetch the plant id by code
$plant = Plant::where('code', $plantCode)->first();
if (! $plant) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Plant code '{$plantCode}' not found!",
], 404);
}
$plantId = $plant?->id ?? null;
$plantName = $plant?->name ?? null;
// $records = WeightValidation::where('plant_id', $plantId) // $records = WeightValidation::where('plant_id', $plantId)
// ->where('obd_number', $obdNumber) // ->where('obd_number', $obdNumber)
// ->get(); // ->get();
@@ -473,11 +489,11 @@ class ObdController extends Controller
->exists(); ->exists();
if (! $exists) { if (! $exists) {
// return response("ERROR: OBD number $obdNumber does not exist for plant '$plantName'", 404) // return response("ERROR: OBD number $obdNumber does not exist for plant '$plantCode'", 404)
// ->header('Content-Type', 'text/plain'); // ->header('Content-Type', 'text/plain');
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "OBD number $obdNumber does not exist for plant '$plantName'!", 'status_description' => "OBD number '{$obdNumber}' does not exist for plant '{$plantName}'!",
], 400); ], 400);
} }
@@ -492,7 +508,7 @@ class ObdController extends Controller
// return response("SUCCESS: Already scanning process completed for the OBD Number", 200)->header('Content-Type', values: 'text/plain'); // return response("SUCCESS: Already scanning process completed for the OBD Number", 200)->header('Content-Type', values: 'text/plain');
return response()->json([ return response()->json([
'status_code' => 'SUCCESS', 'status_code' => 'SUCCESS',
'status_description' => 'Already weight validation completed for the OBD Number!', 'status_description' => "Already weight validation completed for the OBD Number '{$obdNumber}'!",
], 200); ], 200);
} }

View File

@@ -48,6 +48,11 @@ class Plant extends Model
return $this->hasMany(StickerMaster::class, 'plant_id', 'id'); return $this->hasMany(StickerMaster::class, 'plant_id', 'id');
} }
public function weightValidations(): HasMany
{
return $this->hasMany(WeightValidation::class, 'plant_id', 'id');
}
public function invoiceValidations() public function invoiceValidations()
{ {
return $this->hasMany(InvoiceValidation::class, 'plant_id', 'id'); return $this->hasMany(InvoiceValidation::class, 'plant_id', 'id');

View File

@@ -0,0 +1,106 @@
<?php
namespace App\Policies;
use Illuminate\Auth\Access\Response;
use App\Models\ProductionTemp;
use App\Models\User;
class ProductionTempPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->checkPermissionTo('view-any ProductionTemp');
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, ProductionTemp $productiontemp): bool
{
return $user->checkPermissionTo('view ProductionTemp');
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->checkPermissionTo('create ProductionTemp');
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, ProductionTemp $productiontemp): bool
{
return $user->checkPermissionTo('update ProductionTemp');
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, ProductionTemp $productiontemp): bool
{
return $user->checkPermissionTo('delete ProductionTemp');
}
/**
* Determine whether the user can delete any models.
*/
public function deleteAny(User $user): bool
{
return $user->checkPermissionTo('delete-any ProductionTemp');
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, ProductionTemp $productiontemp): bool
{
return $user->checkPermissionTo('restore ProductionTemp');
}
/**
* Determine whether the user can restore any models.
*/
public function restoreAny(User $user): bool
{
return $user->checkPermissionTo('restore-any ProductionTemp');
}
/**
* Determine whether the user can replicate the model.
*/
public function replicate(User $user, ProductionTemp $productiontemp): bool
{
return $user->checkPermissionTo('replicate ProductionTemp');
}
/**
* Determine whether the user can reorder the models.
*/
public function reorder(User $user): bool
{
return $user->checkPermissionTo('reorder ProductionTemp');
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, ProductionTemp $productiontemp): bool
{
return $user->checkPermissionTo('force-delete ProductionTemp');
}
/**
* Determine whether the user can permanently delete any models.
*/
public function forceDeleteAny(User $user): bool
{
return $user->checkPermissionTo('force-delete-any ProductionTemp');
}
}

View File

@@ -1,6 +1,5 @@
<?php <?php
use App\Http\Controllers\CharacteristicApprovalController;
use App\Http\Controllers\CharacteristicsController; use App\Http\Controllers\CharacteristicsController;
use App\Http\Controllers\EquipmentMasterController; use App\Http\Controllers\EquipmentMasterController;
use App\Http\Controllers\InvoiceValidationController; use App\Http\Controllers\InvoiceValidationController;
@@ -63,12 +62,11 @@ use Illuminate\Support\Facades\Route;
// 'data' => $request->all() // 'data' => $request->all()
// ]); // ]);
// }); // });
Route::post('obd/store-data', [ObdController::class, 'store']);
Route::get('obd/get-test-datas', [ObdController::class, 'get_test']); Route::get('obd/get-test-datas', [ObdController::class, 'get_test']);
Route::get('obd/store-data/get', [ObdController::class, 'get_obd']); Route::get('obd/get-data', [ObdController::class, 'get_obd']);
Route::post('obd/store-data', [ObdController::class, 'store_obd']);
Route::get('plant/get-all-data', [PlantController::class, 'get_all_data']); Route::get('plant/get-all-data', [PlantController::class, 'get_all_data']);
@@ -154,7 +152,7 @@ Route::get('testing/equipment/get-master-data', [EquipmentMasterController::clas
Route::post('testing/reading/store-data', [TestingPanelController::class, 'store']); Route::post('testing/reading/store-data', [TestingPanelController::class, 'store']);
Route::get('get-pdf', [PdfController::class, 'getPdf']); Route::get('get-pdf', [PdfController::class, 'getPdf']); // processorder/get-pdf
// ..Part Validation - Characteristics // ..Part Validation - Characteristics
@@ -168,6 +166,8 @@ Route::post('laser/route/data', [CharacteristicsController::class, 'test']); //
Route::get('laser/characteristics/get', [CharacteristicsController::class, 'getClassChar']); Route::get('laser/characteristics/get', [CharacteristicsController::class, 'getClassChar']);
// ..Job or Serial - Status
Route::get('laser/characteristics/check', [CharacteristicsController::class, 'checkClassChar']); Route::get('laser/characteristics/check', [CharacteristicsController::class, 'checkClassChar']);
// ..Job or Master - Characteristics // ..Job or Master - Characteristics