updated motor and pump scanning logic
This commit is contained in:
@@ -20,6 +20,7 @@ use Filament\Notifications\Notification;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Livewire\Livewire; // Ensure this is imported
|
||||
|
||||
class InvoiceValidationResource extends Resource
|
||||
{
|
||||
@@ -29,6 +30,9 @@ class InvoiceValidationResource extends Resource
|
||||
|
||||
protected static ?string $navigationGroup = 'Invoice';
|
||||
|
||||
public $invoiceNumber;
|
||||
|
||||
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
@@ -55,8 +59,13 @@ class InvoiceValidationResource extends Resource
|
||||
'x-on:keydown.enter.prevent' => '$wire.processInvoice(value)',
|
||||
]),
|
||||
|
||||
Forms\Components\TextInput::make('serial_number')
|
||||
->reactive()
|
||||
Forms\Components\TextInput::make('serial_number')
|
||||
->extraAttributes([
|
||||
'x-data' => '{ value: "" }',
|
||||
'x-model' => 'value',
|
||||
'wire:keydown.enter.prevent' => 'processSerialNumber(value)', // Using wire:keydown
|
||||
])
|
||||
|
||||
->columnSpan(1),
|
||||
|
||||
Forms\Components\TextInput::make('total_quantity')
|
||||
@@ -68,12 +77,9 @@ class InvoiceValidationResource extends Resource
|
||||
|
||||
])
|
||||
->columns(5),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user