Merge pull request 'ranjith-dev' (#765) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 18s

Reviewed-on: #765
This commit was merged in pull request #765.
This commit is contained in:
2026-06-18 06:51:04 +00:00
11 changed files with 2115 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,269 @@
<?php
namespace App\Filament\Resources\PanelBoxValidationResource\Pages;
use App\Filament\Resources\PanelBoxValidationResource;
use App\Models\ProductCharacteristicsMaster;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Validation\ValidationException;
class CreatePanelBoxValidation extends CreateRecord {
protected static string $resource = PanelBoxValidationResource::class;
public $showChecklist = false;
public $checklist;
public $skipChecklistValidation = false;
public bool $shouldSkipChecklist = false;
public $existingRecords = [];
protected $listeners = [
'checklistUpdated' => 'setChecklist',
'checklist-cancelled' => 'handleChecklistCancel',
'checklist-saved' => 'checkListSaved',
];
public function setChecklist($checklist)
{
$this->data['checklist'] = $checklist;
}
public function doCreate()
{
$this->create();
}
public function mount(): void
{
parent::mount();
session()->forget([
'last_selected_plant_id',
'last_selected_line',
'last_selected_production',
]);
}
public function handleChecklistCancel()
{
$this->skipChecklistValidation = true;
$this->showChecklist = false;
}
protected function mutateFormDataBeforeCreate(array $data): array
{
// if ($this->shouldSkipChecklist) {
// return $data;
// }
if ($this->checkIfHasCharacteristics($data)) {
$this->showChecklist = true;
$this->halt();
}
return $data;
}
protected function checkIfHasCharacteristics(array $data)
{
$plantId = $data['plant_id'] ?? null;
$itemCode = $data['item_id'] ?? null;
$lineId = $data['line_id'] ?? null;
if (!$plantId || !$itemCode || !$lineId) {
return false;
}
$item = \App\Models\Item::where('code', $itemCode)
->where('plant_id', $plantId)
->first();
$categoryName = trim($item->category) ?? null;
if (!$item) {
$this->existingRecords = collect();
return false;
}
$this->existingRecords = ProductCharacteristicsMaster::where('plant_id', $plantId)
->where('category', $categoryName)
->where('line_id', $lineId)
->get();
return $this->existingRecords->isNotEmpty();
}
public function checkListSaved()
{
$this->showChecklist = false;
$plantId = $this->data['plant_id'] ?? null;
$lineId = $this->data['line_id'] ?? null;
$productionOrder = $this->data['production_order'] ?? null;
return redirect()->to(
static::getResource()::getUrl('create', [
'plant_id' => $this->data['plant_id'] ?? null,
'line_id' => $this->data['line_id'] ?? null,
'production_order' => $this->data['production_order'] ?? null,
])
);
}
protected function beforeCreate(): void
{
$errors = [];
if (!empty($this->data['validationError'])) {
$errors['validationError'] = ['Fix the errors before submitting.'];
}
if (!empty($this->data['serialPanelError'])) {
$errors['serialPanelError'] = ['Fix the errors before submitting.'];
}
if (!empty($this->data['packSlipPanelError'])) {
$errors['packSlipPanelError'] = ['Fix the errors before submitting.'];
}
if (!empty($this->data['namePlatePanelError'])) {
$errors['namePlatePanelError'] = ['Fix the errors before submitting.'];
}
//..name plate
if (!empty($this->data['tubeStickerPanelError'])) {
$errors['tubeStickerPanelError'] = ['Fix the errors before submitting.'];
}
if (!empty($this->data['warrantyCardPanelError'])) {
$errors['warrantyCardPanelError'] = ['Fix the errors before submitting.'];
}
//..part validations
if (!empty($this->data['part_validation1_error'])) {
$errors['part_validation1_error'] = ['Fix the errors before submitting.'];
}
if (!empty($this->data['part_validation2_error'])) {
$errors['part_validation2_error'] = ['Fix the errors before submitting.'];
}
if (!empty($this->data['part_validation3_error'])) {
$errors['part_validation3_error'] = ['Fix the errors before submitting.'];
}
if (!empty($this->data['part_validation4_error'])) {
$errors['part_validation4_error'] = ['Fix the errors before submitting.'];
}
if (!empty($this->data['part_validation5_error'])) {
$errors['part_validation5_error'] = ['Fix the errors before submitting.'];
}
if (!empty($errors)) {
throw ValidationException::withMessages($errors);
}
$this->checkExisting();
$checklist = $this->data['data']['checklist'] ?? [];
if (count($this->existingRecords) > 0){
$this->showChecklist = true;
$this->halt();
}
else{
$this->showChecklist = false;
}
}
public function checkExisting()
{
$plant_id = $this->data['plant_id'] ?? null;
$item_code = $this->data['item_id'] ?? null;
$line_id = $this->data['line_id'] ?? null;
$item = \App\Models\Item::where('code', $item_code)->where('plant_id', $plant_id)->first();
if (!$item) {
$this->existingRecords = collect();
return;
}
// $item_id = $item->id;
$categoryName = trim($item->category) ?? null;
$this->existingRecords = ProductCharacteristicsMaster::where('plant_id', $plant_id)
->where('category', $categoryName)
->where('line_id', $line_id)
->get();
}
protected function afterCreate(): void
{
// Get the value from the hidden field 'plant'
$plant = $this->form->getState()['plant'] ?? null;
$line = $this->form->getState()['line'] ?? null;
$production = $this->form->getState()['production'] ?? null;
// $this->skipChecklistValidation = false;
// $this->showChecklist = false;
// $this->checklist = [];
// $this->form->fill();
// reset checklist
$this->checklist = [];
$this->skipChecklistValidation = false;
$this->showChecklist = false;
$this->form->fill([]);
$this->data = [];
$this->resetValidation();
$this->resetErrorBag();
$this->form->fill([
'plant_id' => null,
'line_id' => null,
'production_order' => null,
]);
// $this->dispatch('focus-item-id');
session()->flash('focus_item_id_after_redirect', true);
logger('Focus flag set in session');
if ($plant) {
session(['last_selected_plant_id' => $plant]);
}
if ($line) {
session(['last_selected_line' => $line]);
}
if ($production) {
session(['last_selected_production' => $production]);
}
}
protected function getRedirectUrl(): string
{
//return $this->getResource()::getUrl('create'); // Stay on Create Page after savin
return $this->getResource()::getUrl('create', [
'plant_id' => $this->data['plant_id'] ?? null,
'line_id' => $this->data['line_id'] ?? null,
'production_order' => $this->data['production_order'] ?? null,
]);
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Filament\Resources\PanelBoxValidationResource\Pages;
use App\Filament\Resources\PanelBoxValidationResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditPanelBoxValidation extends EditRecord
{
protected static string $resource = PanelBoxValidationResource::class;
protected function getHeaderActions(): array
{
return [
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
Actions\ForceDeleteAction::make(),
Actions\RestoreAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\PanelBoxValidationResource\Pages;
use App\Filament\Resources\PanelBoxValidationResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListPanelBoxValidations extends ListRecords
{
protected static string $resource = PanelBoxValidationResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\PanelBoxValidationResource\Pages;
use App\Filament\Resources\PanelBoxValidationResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;
class ViewPanelBoxValidation extends ViewRecord
{
protected static string $resource = PanelBoxValidationResource::class;
protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
];
}
}

View File

@@ -0,0 +1,260 @@
<?php
namespace App\Livewire;
use App\Models\AlertMailRule;
use App\Models\Item;
use App\Models\Line;
use App\Models\PanelBoxValidation;
use App\Models\Plant;
use App\Models\ProductCharacteristicsMaster;
use App\Models\ProductionCharacteristic;
use Filament\Facades\Filament;
use Livewire\Component;
use Filament\Notifications\Notification;
use Illuminate\Support\Facades\Mail;
use App\Mail\InvalidQualityMail;
class PanelCheckList extends Component
{
public $records = [];
public $existingRecords = [];
// public bool $shouldSkipChecklist = false;
public array $checklist = [];
public $showChecklist = false;
// public $skipChecklistValidation = false;
// protected $listeners = ['focus-item-id' => 'handleFocus', 'trigger-create' => 'doCreate',];
public $data =
[
'item_id' => '',
'plant_id' => '',
];
public $data1 = [
'checklist' => [],
];
// public function doCreate()
// {
// $this->create();
// $this->shouldSkipChecklist = false;
// }
public function mount($records = [])
{
// $this->records = collect($records);
$this->records = $records;
// foreach ($records as $record) {
// $this->checklist[$record['id']] = 'ok';
// }
}
public function cancel()
{
$this->dispatch('checklist-cancelled');
}
public function saveChecklist()
{
if (empty($this->checklist) || count($this->checklist) != count($this->records)) {
Notification::make()
->title('Incomplete Checklist')
->body('Please complete all checklist fields before submitting.')
->danger()
->send();
return;
}
$item = Item::where('code', $this->data['item_id'])->first();
if (! $item) {
Notification::make()
->title('Invalid Item Code')
->body('Item not found for given code.')
->danger()
->send();
return;
}
$itemAgaPlant = Item::where('code', $this->data['item_id'])->where('plant_id', $this->data['plant_id'])->first();
$plant = Plant::find($this->data['plant_id']);
if (! $itemAgaPlant) {
Notification::make()
->title('Invalid Item Code')
->body("Item code '$this->data['item_id']' not found for given plant code '{$plant?->code}'.")
->danger()
->send();
return;
}
$itemId = $itemAgaPlant->id;
$exists = PanelBoxValidation::where('plant_id', $this->data['plant_id'] ?? null)
->where('serial_number', $this->data['serial_number'] ?? null)
->first();
$plan = Plant::find($this->data['plant_id']);
if ($exists) {
Notification::make()
->title('Duplicate Serial Number')
->body("serial number {$this->data['serial_number']} already exists for the selected plant $plan->code.")
->danger()
->send();
return;
}
$qualityValidation = PanelBoxValidation::create([
'plant_id' => $this->data['plant_id'] ?? null,
'line_id' => $this->data['line_id'] ?? null,
'sticker_master_id' => $this->data['sticker_master_id'] ?? null,
'production_order' => $this->data['production_order'] ?? null,
'serial_number' => $this->data['serial_number'] ?? null,
'serial_number_panel' => $this->data['serial_number_panel'] ?? null,
'pack_slip_panel' => $this->data['pack_slip_panel'] ?? null,
'name_plate_panel' => $this->data['name_plate_panel'] ?? null,
'tube_sticker_panel' => $this->data['tube_sticker_panel'] ?? null,
'warranty_card_panel' => $this->data['warranty_card_panel'] ?? null,
'part_validation1' => $this->data['part_validation1'] ?? null,
'part_validation2' => $this->data['part_validation2'] ?? null,
'part_validation3' => $this->data['part_validation3'] ?? null,
'part_validation4' => $this->data['part_validation4'] ?? null,
'part_validation5' => $this->data['part_validation5'] ?? null,
]);
if (! $qualityValidation || ! $qualityValidation->exists) {
Notification::make()
->title('Failed to save Panel Box Validation')
->body('Something went wrong while inserting data.')
->danger()
->send();
return;
}
foreach ($this->checklist as $characteristicId => $value) {
$status = 'Ok';
$characteristic = ProductCharacteristicsMaster::find($characteristicId);
if (
$characteristic &&
is_numeric($value) &&
$value >= $characteristic->lower &&
$value <= $characteristic->upper
) {
$status = 'Ok';
} else {
$status = 'NotOk';
}
ProductionCharacteristic::create([
'plant_id' => $this->data['plant_id'] ?? null,
'item_id' => $itemId ?? null,
'line_id' => $this->data['line_id'] ?? null,
'machine_id' => $characteristic?->machine_id ?? null,
'production_order' => $this->data['production_order'] ?? null,
'serial_number' => $this->data['serial_number'] ?? null,
'characteristic_name' => $characteristic?->name ?? null,
'observed_value' => $value ?? null,
'status' => $status,
'inspection_status' => $finalInspectionStatus ?? null,
'created_by' => $this->data['operator_id'] ?? null,
]);
}
$this->showChecklist = false;
$this->dispatch('checklist-saved');
}
public function canSaveChecklist(): bool
{
if (empty($this->checklist) || count($this->checklist) != count($this->records)) {
return false;
}
foreach ($this->checklist as $characteristicId => $value) {
if ($value == null || $value == '') {
return false;
}
$characteristic = ProductCharacteristicsMaster::find($characteristicId);
if (! $characteristic || ! is_numeric($value) || $value <= $characteristic->lower || $value >= $characteristic->upper){
return false;
}
}
return true;
}
public function getCharacteristicStatus($characteristicId): ?string
{
$value = $this->checklist[$characteristicId] ?? null;
if ($value == null || $value == '') {
return null;
}
$characteristic = ProductCharacteristicsMaster::find($characteristicId);
if (! $characteristic || ! is_numeric($value)) {
return 'Not Ok';
}
return ($value > $characteristic->lower && $value < $characteristic->upper) ? 'Ok' : 'Not Ok';
}
// public static function getMailData($plantId)
// {
// $globalEmails = AlertMailRule::where('plant', 0)
// ->where('module', 'QualityValidation')
// ->where('rule_name', 'QualityMail')
// ->where(fn ($q) => $q->whereNull('schedule_type')->orWhere('schedule_type', ''))
// ->pluck('email')
// ->toArray();
// if (! empty($globalEmails)) {
// return [
// 'plant_id' => 0,
// 'plant_name' => 'All Plants',
// 'emails' => $globalEmails,
// ];
// }
// $mPlantName = Plant::where('id', $plantId)->value('name');
// $emails = AlertMailRule::where('plant', $plantId)
// ->where('module', 'QualityValidation')
// ->where('rule_name', 'QualityMail')
// ->where(fn ($q) => $q->whereNull('schedule_type')->orWhere('schedule_type', ''))
// ->pluck('email')
// ->toArray();
// return [
// 'plant_id' => $plantId,
// 'plant_name' => $mPlantName,
// 'emails' => $emails,
// ];
// }
public function render()
{
return view('livewire.panel-check-list');
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class PanelBoxValidation extends Model
{
use SoftDeletes;
protected $fillable = [
'plant_id',
'line_id',
'sticker_master_id',
'production_order',
'serial_number',
'serial_number_panel',
'pack_slip_panel',
'name_plate_panel',
'tube_sticker_panel',
'warranty_card_panel',
'part_validation1',
'part_validation2',
'part_validation3',
'part_validation4',
'part_validation5',
'created_by',
'updated_by'
];
public function plant(): BelongsTo
{
return $this->belongsTo(Plant::class);
}
public function line(): BelongsTo
{
return $this->belongsTo(Line::class);
}
public function stickerMaster(): BelongsTo
{
return $this->belongsTo(StickerMaster::class);
}
}

View File

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

View File

@@ -0,0 +1,56 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
$sql = <<<'SQL'
CREATE TABLE panel_box_validations (
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
plant_id BIGINT NOT NULL,
line_id BIGINT NOT NULL,
sticker_master_id BIGINT NOT NULL,
production_order TEXT DEFAULT NULL,
serial_number TEXT DEFAULT NULL,
serial_number_panel TEXT DEFAULT NULL,
pack_slip_panel TEXT DEFAULT NULL,
name_plate_panel TEXT DEFAULT NULL,
tube_sticker_panel TEXT DEFAULT NULL,
warranty_card_panel TEXT DEFAULT NULL,
part_validation1 TEXT DEFAULT NULL,
part_validation2 TEXT DEFAULT NULL,
part_validation3 TEXT DEFAULT NULL,
part_validation4 TEXT DEFAULT NULL,
part_validation5 TEXT DEFAULT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP,
created_by TEXT DEFAULT NULL,
updated_by TEXT DEFAULT NULL,
deleted_at TIMESTAMP,
UNIQUE (plant_id, serial_number),
FOREIGN KEY (plant_id) REFERENCES plants (id),
FOREIGN KEY (line_id) REFERENCES lines (id),
FOREIGN KEY (sticker_master_id) REFERENCES sticker_masters (id)
);
SQL;
DB::statement($sql);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('panel_box_validations');
}
};

View File

@@ -0,0 +1,6 @@
<div>
@livewire('panel-check-list', [
'records' => $existingRecords,
'data' => $data
])
</div>

View File

@@ -0,0 +1,91 @@
<div class="fixed inset-0 flex items-center justify-center z-50">
{{-- <div class="bg-white max-h-[80vh] overflow-hidden p-6 rounded-lg shadow-lg pointer-events-auto"
style="width:30vw !important; max-width:none !important;"> --}}
<div
class="bg-white rounded-lg shadow-lg pointer-events-auto
w-full max-w-2xl max-h-[90vh] flex flex-col">
{{-- @if($records && $records->count()) --}}
@if(!empty($records) && count($records))
<div style="max-height:250px; overflow-y:auto; border:1px solid #ccc;">
{{-- <table class="min-w-full border"> --}}
<table class="w-full table-fixed border text-sm">
<thead>
<tr class="bg-gray-100">
<th class="border px-2 py-1 w-2/3">Characteristics</th>
<th class="border px-2 py-1 w-1/3">Value</th>
</tr>
</thead>
<tbody>
@foreach($records as $record)
<tr>
<td class="border p-2">
{{ $record['name'] }}
</td>
{{-- <td class="border p-2">
<input
type="text"
wire:model.defer="checklist.{{ $record['id'] }}"
wire:model.live="checklist.{{ $record['id'] }}"
class="w-full border rounded px-2 py-1"
placeholder="Enter value"
>
</td> --}}
<td class="border p-2">
@php
$status = $this->getCharacteristicStatus($record['id']);
@endphp
<input
type="text"
wire:model.live="checklist.{{ $record['id'] }}"
class="w-full rounded px-2 py-1 border-2 transition-all duration-200"
style="
@if($status === 'Ok')
border-color: #22c55e;
box-shadow: 0 0 8px rgba(34, 197, 94, 0.8);
@elseif($status === 'Not Ok')
border-color: #ef4444;
box-shadow: 0 0 8px rgba(239, 68, 68, 0.8);
@else
border-color: #d1d5db;
@endif
"
placeholder="Enter value"
>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@else
<p>No records found.</p>
@endif
<div class="border-t mt-6 pt-4 flex justify-end gap-3">
<button
type="button"
wire:click="cancel"
style="background-color:#dc2626; color:white;"
class="px-6 py-2 rounded-lg shadow-md"
>
Cancel
</button>
<button
type="button"
wire:click="saveChecklist"
style="background-color:#16a34a; color:white;"
@disabled(!$this->canSaveChecklist())
class="px-6 py-2 rounded-lg shadow-md disabled:opacity-50 disabled:cursor-not-allowed"
>
Save
</button>
</div>
</div>
</div>