ranjith-dev #289

Merged
jothi merged 4 commits from ranjith-dev into master 2026-01-31 07:23:18 +00:00
Showing only changes of commit 02c9059cf3 - Show all commits

View File

@@ -8,6 +8,7 @@ use App\Models\CharacteristicApproverMaster;
use App\Models\Item;
use App\Models\Machine;
use App\Models\RequestCharacteristic;
use Closure;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Section;
@@ -21,6 +22,7 @@ use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Facades\Schema;
use Illuminate\Validation\Rule;
class RequestCharacteristicResource extends Resource
@@ -236,7 +238,7 @@ class RequestCharacteristicResource extends Resource
})
->required(),
// ->disabled(fn ($get) => self::isFieldDisabled($get))
Section::make('Request Characteristic')
Section::make('Request Characteristic Field')
// ->columnSpan(['default' => 2, 'sm' => 4])
->reactive()
->schema([
@@ -244,24 +246,82 @@ class RequestCharacteristicResource extends Resource
->label('Characteristic Name')
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('characteristic_name', strtoupper($state));
$set('updated_by', Filament::auth()->user()?->name);
})
->required()
->disabled(fn ($get) => self::isFieldDisabled($get)),
->rules([
// function (callable $get) {
// return Rule::unique('request_characteristics', 'characteristic_name')
// ->where('plant_id', $get('plant_id'))
// ->where('machine_id', $get('machine_id'))
// ->where('machine_name', $get('machine_name'))
// ->ignore($get('id'));
// },
function (callable $get): Closure {
return function (string $attribute, $value, Closure $fail) use ($get) {
$charVal = strtolower($value);
$columns = Schema::getColumnListing('class_characteristics');
if (! in_array($charVal, $columns, true)) {
$fail('Unknown characteristic field found.'); // .implode(', ', $columns).
} else {
$plantId = $get('plant_id');
$jobNo = $get('aufnr');
$updId = $get('id');
$pendingExists = RequestCharacteristic::where('plant_id', $plantId)->where('aufnr', $jobNo)->where('characteristic_name', $value)->latest()->first();
if ($pendingExists) {
if ($updId && $pendingExists->id == $updId) {
return;
}
$app1 = $pendingExists->approver_status1 ?? null;
$app2 = $pendingExists->approver_status2 ?? null;
$app3 = $pendingExists->approver_status3 ?? null;
if ($app1 != 'Rejected' && $app2 != 'Rejected' && $app3 != 'Rejected' && $app1 != 'Approved' && $app2 != 'Approved' && $app3 != 'Approved') {
$fail('Approval is already pending.');
}
}
}
};
},
])
->readOnly(fn ($get) => self::isFieldDisabled($get)), // disabled
Forms\Components\TextInput::make('current_value')
->label('Current Value')
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name);
})
->disabled(fn ($get) => self::isFieldDisabled(get: $get)),
->required(function (callable $get) {
$updateVal = $get('update_value');
if ($updateVal == null || $updateVal == '') {
return true;
}
return false;
})
->readOnly(fn ($get) => self::isFieldDisabled($get)),
Forms\Components\TextInput::make('update_value')
->label('Update Value')
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name);
})
->disabled(fn ($get) => self::isFieldDisabled($get)),
->rules([
function (callable $get): Closure {
return function (string $attribute, $value, Closure $fail) use ($get) {
$currVal = $get('current_value');
if ($value == $currVal) {
$fail('Update value must be different from current value.');
}
};
},
])
->readOnly(fn ($get) => self::isFieldDisabled($get)),
])
->collapsible()
->columns(['default' => 1, 'sm' => 3]),
@@ -798,6 +858,19 @@ class RequestCharacteristicResource extends Resource
->dateTime()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('mail_status')
->label('Mail Status')
->alignCenter()
->searchable()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('trigger_at')
->label('Trigger At')
->dateTime()
->alignCenter()
->searchable()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->dateTime()