Added panel check list livewire file
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 15s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 17s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 20s
Laravel Pint / pint (pull_request) Successful in 3m23s
Laravel Larastan / larastan (pull_request) Failing after 3m44s

This commit is contained in:
dhanabalan
2026-06-18 12:20:23 +05:30
parent 66a35d2796
commit 18cd1938a5
2 changed files with 351 additions and 0 deletions

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,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>