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

@@ -6,6 +6,7 @@ use App\Filament\Resources\InvoiceValidationResource;
use App\Livewire\InvoiceDataTable;
use App\Models\InvoiceValidation;
use App\Models\StickerMaster;
use Filament\Facades\Filament;
use Illuminate\Contracts\View\View;
use Filament\Resources\Pages\CreateRecord;
use Filament\Notifications\Notification;
@@ -28,7 +29,8 @@ class CreateInvoiceValidation extends CreateRecord
public $total_quantity;
public string $invoiceNumber;
public $invoiceNumber;
public bool $hasSearched = false;
public $excel_file;
@@ -40,7 +42,10 @@ class CreateInvoiceValidation extends CreateRecord
public function processInvoice($invoiceNumber)
{
// Get plant_id selected in the form
$user = Filament::auth()->user();
$operatorName = $user->name;
$plantId = $this->form->getState()['plant_id'];
$filePath = session('uploaded_invoice_path');
@@ -142,6 +147,7 @@ class CreateInvoiceValidation extends CreateRecord
'serial_number' => $serialNumber,
'plant_id' => $plantId,
'invoice_number' => $invoiceNumber,
'operator_id'=> $operatorName,
]);
$inserted++;
}
@@ -154,7 +160,7 @@ class CreateInvoiceValidation extends CreateRecord
->body("$inserted records were inserted.")
->success()
->send();
// Dispatch the event to refresh the Livewire component
$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
{
return 'Scan Invoice Validation';