1
0
forked from poc/pds

updated motor and pump scanning logic

This commit is contained in:
dhanabalan
2025-04-10 20:24:04 +05:30
parent 57c3a876bd
commit 2ccad83e67
6 changed files with 177 additions and 40 deletions

View File

@@ -20,6 +20,7 @@ use Filament\Notifications\Notification;
use Filament\Tables\Actions\Action; use Filament\Tables\Actions\Action;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Maatwebsite\Excel\Facades\Excel; use Maatwebsite\Excel\Facades\Excel;
use Livewire\Livewire; // Ensure this is imported
class InvoiceValidationResource extends Resource class InvoiceValidationResource extends Resource
{ {
@@ -29,6 +30,9 @@ class InvoiceValidationResource extends Resource
protected static ?string $navigationGroup = 'Invoice'; protected static ?string $navigationGroup = 'Invoice';
public $invoiceNumber;
public static function form(Form $form): Form public static function form(Form $form): Form
{ {
@@ -56,7 +60,12 @@ class InvoiceValidationResource extends Resource
]), ]),
Forms\Components\TextInput::make('serial_number') Forms\Components\TextInput::make('serial_number')
->reactive() ->extraAttributes([
'x-data' => '{ value: "" }',
'x-model' => 'value',
'wire:keydown.enter.prevent' => 'processSerialNumber(value)', // Using wire:keydown
])
->columnSpan(1), ->columnSpan(1),
Forms\Components\TextInput::make('total_quantity') Forms\Components\TextInput::make('total_quantity')
@@ -68,12 +77,9 @@ class InvoiceValidationResource extends Resource
]) ])
->columns(5), ->columns(5),
]); ]);
} }
public static function table(Table $table): Table public static function table(Table $table): Table
{ {
return $table return $table

View File

@@ -6,6 +6,7 @@ use App\Filament\Resources\InvoiceValidationResource;
use App\Livewire\InvoiceDataTable; use App\Livewire\InvoiceDataTable;
use App\Models\InvoiceValidation; use App\Models\InvoiceValidation;
use App\Models\StickerMaster; use App\Models\StickerMaster;
use Filament\Facades\Filament;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Filament\Resources\Pages\CreateRecord; use Filament\Resources\Pages\CreateRecord;
use Filament\Notifications\Notification; use Filament\Notifications\Notification;
@@ -28,7 +29,8 @@ class CreateInvoiceValidation extends CreateRecord
public $total_quantity; public $total_quantity;
public string $invoiceNumber; public $invoiceNumber;
public bool $hasSearched = false;
public $excel_file; public $excel_file;
@@ -40,7 +42,10 @@ class CreateInvoiceValidation extends CreateRecord
public function processInvoice($invoiceNumber) public function processInvoice($invoiceNumber)
{ {
// Get plant_id selected in the form $user = Filament::auth()->user();
$operatorName = $user->name;
$plantId = $this->form->getState()['plant_id']; $plantId = $this->form->getState()['plant_id'];
$filePath = session('uploaded_invoice_path'); $filePath = session('uploaded_invoice_path');
@@ -142,6 +147,7 @@ class CreateInvoiceValidation extends CreateRecord
'serial_number' => $serialNumber, 'serial_number' => $serialNumber,
'plant_id' => $plantId, 'plant_id' => $plantId,
'invoice_number' => $invoiceNumber, 'invoice_number' => $invoiceNumber,
'operator_id'=> $operatorName,
]); ]);
$inserted++; $inserted++;
} }
@@ -154,7 +160,7 @@ class CreateInvoiceValidation extends CreateRecord
->body("$inserted records were inserted.") ->body("$inserted records were inserted.")
->success() ->success()
->send(); ->send();
// Dispatch the event to refresh the Livewire component
$this->dispatch('refreshInvoiceData', invoiceNumber: $invoiceNumber); $this->dispatch('refreshInvoiceData', invoiceNumber: $invoiceNumber);
} }
@@ -170,6 +176,83 @@ class CreateInvoiceValidation extends CreateRecord
} }
} }
protected function refreshInvoiceTable()
{
if (empty($this->invoiceNumber)) {
$this->invoiceNumber = $this->form->getState()['invoice_number'] ?? '';
}
if (!empty($this->invoiceNumber)) {
$this->dispatch('refreshInvoiceData', invoiceNumber: $this->invoiceNumber);
}
}
public function processSerialNumber($serialNumber)
{
if (!preg_match('/^([a-zA-Z0-9]{6,})\|([a-zA-Z0-9]{8,})(?:\/[MmPpCc])?$/', $serialNumber, $matches)) {
Notification::make()
->danger()
->title('Invalid format')
->body('Please enter serial in correct format: ITEM123|123456789/M')
->send();
return;
}
if (preg_match('/^([a-zA-Z0-9]+)\|([a-zA-Z0-9]+(?:\/[MmPpCc]?)?)$/', $serialNumber, $matches))
{
$itemCode = $matches[1];
$serialNumber = $matches[2];
// Check if it ends with /M, /P, /C etc.
$isMarkM = preg_match('/\/[Mm]$/', $serialNumber);
$isMarkP = preg_match('/\/[Pp]$/', $serialNumber);
$serialNumber = preg_replace('/\/[MmPpCc]$/', '', $serialNumber);
$record = InvoiceValidation::where('serial_number', $serialNumber)
->whereHas('stickerMasterRelation.item', function ($query) use ($itemCode) {
$query->where('code', $itemCode);
})
->first();
if (!$record) {
Notification::make()
->danger()
->title('Serial not found')
->body("Item code '$itemCode' with serial '$serialNumber' not found.")
->send();
return;
}
if ($isMarkM) {
$record->motor_scanned_status = 1;
$record->save();
Notification::make()
->success()
->title('Updated')
->body("Motor scanned status marked as updated.")
->send();
$this->refreshInvoiceTable();
}
else if ($isMarkP) {
$record->pump_scanned_status = 1;
$record->save();
Notification::make()
->success()
->title('Updated')
->body("Pump scanned status marked as updated.")
->send();
$this->refreshInvoiceTable();
}
}
}
public function getHeading(): string public function getHeading(): string
{ {
return 'Scan Invoice Validation'; return 'Scan Invoice Validation';

View File

@@ -14,7 +14,8 @@ class InvoiceDataTable extends Component
public bool $hasSearched = false; public bool $hasSearched = false;
protected $listeners = ['refreshInvoiceData' => 'loadData']; protected $listeners = ['refreshInvoiceData' => 'loadData',];
public function loadData($invoiceNumber) public function loadData($invoiceNumber)
{ {
@@ -34,6 +35,8 @@ class InvoiceDataTable extends Component
'panel_box_supplier' => $record->panel_box_supplier, 'panel_box_supplier' => $record->panel_box_supplier,
'panel_box_serial_number' => $record->panel_box_serial_number, 'panel_box_serial_number' => $record->panel_box_serial_number,
'scanned_status' => $record->scanned_status, 'scanned_status' => $record->scanned_status,
'created_at' => $record->created_at,
'operator_id' => $record->operator_id,
]; ];
}) })
@@ -44,10 +47,12 @@ class InvoiceDataTable extends Component
$stickerMaster = \App\Models\StickerMaster::with('item')->find($row['sticker_master_id'] ?? null); $stickerMaster = \App\Models\StickerMaster::with('item')->find($row['sticker_master_id'] ?? null);
$row['code'] = $stickerMaster?->item?->code ?? 'N/A'; $row['code'] = $stickerMaster?->item?->code ?? 'N/A';
} }
} }
public function render() public function render()
{ {
return view('livewire.invoice-data-table'); return view('livewire.invoice-data-table');
} }
} }

View File

@@ -26,6 +26,7 @@ class InvoiceValidation extends Model
'upload_status', 'upload_status',
'batch_number', 'batch_number',
'quantity', 'quantity',
'operator_id',
]; ];
public function plant(): BelongsTo public function plant(): BelongsTo
@@ -37,6 +38,10 @@ class InvoiceValidation extends Model
{ {
return $this->belongsTo(StickerMaster::class); return $this->belongsTo(StickerMaster::class);
} }
public function stickerMasterRelation()
{
return $this->belongsTo(StickerMaster::class, 'sticker_master_id');
}
} }

View File

@@ -0,0 +1,31 @@
<?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'
ALTER TABLE invoice_validations
ADD operator_id TEXT DEFAULT NULL;
SQL;
DB::statement($sql);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
}
};

View File

@@ -127,23 +127,26 @@
</div> </div>
</div> </div>
@if($hasSearched) @if($hasSearched)
<div class="overflow-x-auto overflow-y-visible"> <div class="overflow-x-auto overflow-y-visible">
<table class="min-w-[1500px] text-sm text-center border border-gray-300"> {{-- <table class="min-w-[1500px] text-sm text-center border border-gray-300"> --}}
{{-- <table class="table-fixed min-w-[1500px] text-sm text-center border border-gray-300"> --}}
<table class="min-w-full text-sm text-center border border-gray-300">
<thead class="bg-gray-100 font-bold"> <thead class="bg-gray-100 font-bold">
<tr> <tr>
<th class="border px-4 py-2 min-w-[100px]">No</th> <th class="border px-4 py-2">No</th>
<th class="border px-4 py-2 min-w-[200px]">Material Code</th> <th class="border px-4 py-2">Material Code</th>
<th class="border px-4 py-2 min-w-[250px]">Serial Number</th> <th class="border px-4 py-2">Serial Number</th>
<th class="border px-4 py-2 min-w-[200px]">Motor Scanned Status</th> <th class="border px-4 py-2">Motor Scanned Status</th>
<th class="border px-4 py-2 min-w-[200px]">Pump Scanned Status</th> <th class="border px-4 py-2">Pump Scanned Status</th>
<th class="border px-4 py-2 min-w-[250px]">Capacitor Scanned Status</th> <th class="border px-4 py-2">Capacitor Scanned Status</th>
<th class="border px-4 py-2 min-w-[200px]">Scanned Status Set</th> <th class="border px-4 py-2">Scanned Status Set</th>
<th class="border px-4 py-2 min-w-[250px]">Panel Box Supplier</th> <th class="border px-4 py-2">Scanned Status</th>
<th class="border px-4 py-2 min-w-[250px]">Panel Box Serial Number</th> <th class="border px-4 py-2 w-[300px] whitespace-nowrap">Time Stamp</th>
<th class="border px-4 py-2 min-w-[200px]">Scanned Status</th> <th class="border px-4 py-2">Operator ID</th>
<th class="border px-4 py-2">Panel Box Supplier</th>
<th class="border px-4 py-2">Panel Box Serial Number</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -156,9 +159,11 @@
<td class="border px-4 py-2">{{ $row['pump_scanned_status'] ?? 'N/A' }}</td> <td class="border px-4 py-2">{{ $row['pump_scanned_status'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['capacitor_scanned_status'] ?? 'N/A' }}</td> <td class="border px-4 py-2">{{ $row['capacitor_scanned_status'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['scanned_status_set'] ?? 'N/A' }}</td> <td class="border px-4 py-2">{{ $row['scanned_status_set'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['scanned_status'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['created_at'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['operator_id'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['panel_box_supplier'] ?? 'N/A' }}</td> <td class="border px-4 py-2">{{ $row['panel_box_supplier'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['panel_box_serial_number'] ?? 'N/A' }}</td> <td class="border px-4 py-2">{{ $row['panel_box_serial_number'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['scanned_status'] ?? 'N/A' }}</td>
</tr> </tr>
@empty @empty
<tr> <tr>
@@ -173,3 +178,5 @@
@endif @endif
</div> </div>