4 Commits

Author SHA1 Message Date
dhanabalan
da0c13b33a Enable or disable 'motor or pump or pumpset' 2025-04-11 23:38:47 +05:30
dhanabalan
3ded5ee112 Create function on enter key press and enable cancel action button only 2025-04-11 23:36:26 +05:30
dhanabalan
2ccad83e67 updated motor and pump scanning logic 2025-04-10 20:24:04 +05:30
dhanabalan
57c3a876bd added datagrid table 2025-04-10 13:05:52 +05:30
11 changed files with 837 additions and 251 deletions

View File

@@ -4,7 +4,10 @@ namespace App\Filament\Resources;
use App\Filament\Resources\InvoiceValidationResource\Pages;
use App\Models\InvoiceValidation;
use App\Models\StickerMaster;
use Filament\Actions\CreateAction;
use Filament\Forms;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Resources\Resource;
@@ -13,8 +16,11 @@ use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\View;
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
{
@@ -24,24 +30,21 @@ class InvoiceValidationResource extends Resource
protected static ?string $navigationGroup = 'Invoice';
public $enter_pressed = false;
public $invoiceNumber;
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Hidden::make('sticker_master_id')
//->relationship('stickerMaster', 'id')
->required(),
// Forms\Components\Hidden::make('sticker_master_id')
// //->relationship('stickerMaster', 'id')
// ->required(),
Section::make('')
Section::make('')
->schema([
// FileUpload::make('excel_file')
// ->label('Choose Excel File')
// ->disk('local')
// ->columnSpan(1),
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required(),
@@ -56,9 +59,13 @@ class InvoiceValidationResource extends Resource
'x-on:keydown.enter.prevent' => '$wire.processInvoice(value)',
]),
Forms\Components\TextInput::make('serial_number')
//->required()
->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')
@@ -70,17 +77,9 @@ class InvoiceValidationResource extends Resource
])
->columns(5),
// View::make('livewire.invoice-data-table')
// ->label('Invoice Details')
// ->viewData([
// 'invoiceData' => fn ($get) => $get('invoice_data') ?? [], // Changed from invoiceData to invoice_data
// ])
// ->columnSpan('full'),
]);
}
public static function table(Table $table): Table
{
return $table
@@ -98,35 +97,66 @@ class InvoiceValidationResource extends Resource
Tables\Columns\TextColumn::make('load_rate')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
Tables\Filters\TrashedFilter::make(),
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
]);
}
->headerActions([
Tables\Actions\Action::make('Import Serial Number')
->label('Import Serial Number')
->form([
FileUpload::make('invoice_serial_number')
->label('Invoice Serial Number')
->preserveFilenames() // <- this keeps the original filename
->storeFiles(false) // prevent auto-storing, we will store manually
->disk('local') //'local' refers to the local storage disk defined in config/filesystems.php, typically pointing to storage/app.
->directory('uploads/temp'), //storage/app/uploads/temp
])
->action(function (array $data) {
$uploadedFile = $data['invoice_serial_number'];
// Get original filename
$originalName = $uploadedFile->getClientOriginalName(); // e.g. 3RA0018732.xlsx
// Store manually using storeAs to keep original name
$path = $uploadedFile->storeAs('uploads/temp', $originalName, 'local'); // returns relative path
$fullPath = Storage::disk('local')->path($path);
// Save full file path to session
session(['uploaded_invoice_path' => $fullPath]);
// session()->flash('just_uploaded_invoice', true); // 👈 add this
Notification::make()
->title('File Uploaded. Continue in Create Page.')
->success()
->send();
}),
Tables\Actions\Action::make('Import Invoice Material')
->label('Import Invoice Material')
->form([
FileUpload::make('invoice_material')
->label('Invoice Material')
->required(),
])
]);
// ->filters([
// Tables\Filters\TrashedFilter::make(),
// ])
// ->actions([
// Tables\Actions\ViewAction::make(),
// Tables\Actions\EditAction::make(),
// ])
// ->bulkActions([
// Tables\Actions\BulkActionGroup::make([
// Tables\Actions\DeleteBulkAction::make(),
// Tables\Actions\ForceDeleteBulkAction::make(),
// Tables\Actions\RestoreBulkAction::make(),
// ]),
// ]);
}
public static function getRelations(): array
{

View File

@@ -3,10 +3,15 @@
namespace App\Filament\Resources\InvoiceValidationResource\Pages;
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;
use Maatwebsite\Excel\Facades\Excel;
use Livewire\Livewire;
class CreateInvoiceValidation extends CreateRecord
{
@@ -18,114 +23,240 @@ class CreateInvoiceValidation extends CreateRecord
public $invoice_data;
public $invoiceData = [];
public $scanned_quantity;
public $total_quantity;
public $invoiceNumber;
public bool $hasSearched = false;
public $excel_file;
public function getFormActions(): array
{
return parent::getFormActions();
}
public function processInvoice($invoiceNumber)
{
$user = Filament::auth()->user();
$this->invoice_number = $invoiceNumber;
$operatorName = $user->name;
// Check if the file is uploaded
if (!$this->excel_file) {
Notification::make()
->title('No File Uploaded')
->body("Please upload an Excel file to proceed with invoice: {$invoiceNumber}.")
->danger()
->persistent()
->send();
return;
}
$plantId = $this->form->getState()['plant_id'];
$localPath = $this->excel_file->getPath();
// Check if file exists
if (!file_exists($localPath)) {
Notification::make()
->title('File Not Found')
->body("No Excel file found for invoice: {$invoiceNumber}. Please ensure the file exists in your Downloads folder.")
->danger()
->persistent()
->send();
return;
}
try {
$rows = \Maatwebsite\Excel\Facades\Excel::toArray([], $localPath)[0] ?? [];
array_shift($rows);
if (empty($rows)) {
Notification::make()
->title('Empty File')
->body('The Excel file contains no data rows')
->danger()
->send();
return;
}
$validRecords = [];
$invalidMaterials = [];
foreach ($rows as $row) {
$materialCode = $row[0] ?? null;
$serialNumber = $row[1] ?? null;
if (!\App\Models\StickerMaster::where('item_id', $materialCode)->exists()) {
$invalidMaterials[] = $materialCode;
continue;
}
$validRecords[] = [
'material_code' => $materialCode,
'serial_number' => $serialNumber,
'invoice_number' => $invoiceNumber,
'created_at' => now(),
'updated_at' => now(),
];
}
if (!empty($invalidMaterials)) {
Notification::make()
->title('Invalid Materials')
->body('These codes not found: ' . implode(', ', array_unique($invalidMaterials)))
->danger()
->send();
return;
}
\DB::table('invoice_validations')->insert($validRecords);
$this->invoice_data = $validRecords;
$this->scanned_quantity = count($validRecords);
$this->total_quantity = count($validRecords);
$filePath = session('uploaded_invoice_path');
if (!file_exists($filePath))
{
Notification::make()
->title('Success')
->body(count($validRecords) . ' records inserted successfully')
->success()
->send();
} catch (\Exception $e) {
Notification::make()
->title('Error')
->body($e->getMessage())
->title('Excel File not found.')
->danger()
->send();
return;
}
// Extract filename without extension (e.g., "3RA0018732")
$uploadedFilename = pathinfo($filePath, PATHINFO_FILENAME);
// Compare with invoice number
if ($uploadedFilename !== $invoiceNumber) {
Notification::make()
->title("Uploaded file name does not match the invoice number.")
// ->body("Expected: {$invoiceNumber}.xlsx, but got: {$uploadedFilename}.xlsx")
->danger()
->send();
return;
}
if ($filePath && file_exists($filePath))
{
// Now you can read/process the file here
$rows = Excel::toArray(null, $filePath)[0]; //0 means excel first sheet
$materialCodes = [];
$serialNumbers = [];
foreach ($rows as $index => $row)
{
if ($index === 0) continue; // Skip header
$materialCode = trim($row[0]);
$serialNumber = trim($row[1]);
if (!empty($materialCode)) {
$materialCodes[] = $materialCode;
}
if (!empty($serialNumber)) {
$serialNumbers[] = $serialNumber;
}
}
$existingSerialNumbers = InvoiceValidation::whereIn('serial_number', $serialNumbers)->pluck('serial_number')->toArray();
// If there are duplicates, notify and stop the process
if (!empty($existingSerialNumbers)) {
Notification::make()
->title('Duplicate Serial Numbers Found')
->body('The following serial numbers already exist: ' . implode(', ', $existingSerialNumbers))
->danger()
->send();
return;
}
$uniqueCodes = array_unique($materialCodes);
$existingCodes = StickerMaster::with('item')
->get()
->pluck('item.code')
->toArray();
$missingCodes = array_diff($uniqueCodes, $existingCodes);
if (!empty($missingCodes)) {
Notification::make()
->title('Material codes do not exist in Sticker Master')
->body('Missing: ' . implode(', ', $missingCodes))
->danger()
->send();
return;
}
$inserted = 0;
foreach ($rows as $index => $row)
{
if ($index === 0) continue;
$materialCode = trim($row[0]);
$serialNumber = trim($row[1]);
if (in_array($serialNumber, $existingSerialNumbers)) {
continue; // here duplicate serial numbers are skipped and new serial numbers are inserted
}
$sticker = StickerMaster::whereHas('item', function ($query) use ($materialCode) {
$query->where('code', $materialCode); //Check if item.code matches Excel's materialCode
})->first();
if ($sticker) {
InvoiceValidation::create([
'sticker_master_id' => $sticker->id,
'serial_number' => $serialNumber,
'plant_id' => $plantId,
'invoice_number' => $invoiceNumber,
'operator_id'=> $operatorName,
]);
$inserted++;
}
}
if ($inserted > 0)
{
Notification::make()
->title("Import Successful")
->body("$inserted records were inserted.")
->success()
->send();
$this->dispatch('refreshInvoiceData', invoiceNumber: $invoiceNumber);
}
else
{
Notification::make()
->title("Import Failed")
->body("No new records were inserted.")
->danger()
->send();
return;
}
}
}
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';
}
// public function render(): View
// {
// return view('filament.resources.invoice-validation-resource.pages.create-invoice-validation');
// }
}

View File

@@ -4,6 +4,8 @@ namespace App\Filament\Resources\InvoiceValidationResource\Pages;
use App\Filament\Resources\InvoiceValidationResource;
use Filament\Actions;
use Filament\Actions\Action;
use Filament\Forms\Components\FileUpload;
use Filament\Resources\Pages\ListRecords;
class ListInvoiceValidations extends ListRecords
@@ -16,4 +18,12 @@ class ListInvoiceValidations extends ListRecords
Actions\CreateAction::make(),
];
}
//to hide the data from the table
protected function getTableQuery(): \Illuminate\Database\Eloquent\Builder
{
return static::getResource()::getEloquentQuery()->whereRaw('1 = 0');
}
}

View File

@@ -22,6 +22,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Notifications\Notification;
use Filament\Tables\Actions\ExportAction;
//use Livewire\Livewire;
class ProductionQuantityResource extends Resource
{
@@ -33,6 +34,7 @@ class ProductionQuantityResource extends Resource
protected static ?string $navigationGroup = 'Production';
public static function form(Form $form): Form
{
return $form
@@ -44,6 +46,7 @@ class ProductionQuantityResource extends Resource
->required()
// ->nullable()
->reactive()
// ->default(fn () => optional(ProductionQuantity::latest()->first())->plant_id)
->default(function () {
return optional(ProductionQuantity::latest()->first())->plant_id;
})
@@ -247,10 +250,11 @@ class ProductionQuantityResource extends Resource
// ->required()
->reactive()
->autofocus(true)
->debounce(1000)
->debounce(100)
// ->submitOnEnter()
->afterStateUpdated(function ($state, callable $get, callable $set) {
// **Check if input is empty before processing**
$set('success_msg', null);
if (empty($state)) {
$set('item_id', null);
// $set('item_description', null);
@@ -567,10 +571,11 @@ class ProductionQuantityResource extends Resource
if (!preg_match('/^[a-zA-Z0-9]{6,}+\|[1-9][a-zA-Z0-9]{8,}+(\|)?$/', $state)) {
if (strpos($state, '|') === false) {
$set('validationError', 'Scan valid QR code. (Ex: Item_Code|Serial_Number )');
$set('item_code', null);
$set('item_id', null);
// $set('item_description', null);
$set('serial_number', null);
$set('validationError', 'Scan valid QR code. (Ex: Item_Code|Serial_Number )');
Notification::make()
->title('Invalid QR')
@@ -586,10 +591,12 @@ class ProductionQuantityResource extends Resource
$sNumber = isset($splits[1]) ? trim($splits[1]) : null;
if (!ctype_alnum($iCode)) {
$set('validationError', 'Item code must contain alpha-numeric values.');
$set('item_code', null);
$set('item_id', null);
// $set('item_description', null);
$set('serial_number', null);
$set('validationError', 'Item code must contain alpha-numeric values.');
Notification::make()
->title('Invalid Item Code')
->body("Item code must contain alpha-numeric values only.")
@@ -598,10 +605,12 @@ class ProductionQuantityResource extends Resource
return;
}
else if (strlen($iCode) < 6) {
$set('validationError', 'Item code must be at least 6 digits.');
$set('item_code', null);
$set('item_id', null);
// $set('item_description', null);
$set('serial_number', null);
$set('validationError', 'Item code must be at least 6 digits.');
Notification::make()
->title('Invalid Item Code')
->body("Item code must be at least 6 digits.")
@@ -610,10 +619,12 @@ class ProductionQuantityResource extends Resource
return;
}
else if (!ctype_alnum($sNumber)) {
$set('validationError', 'Serial Number must contain alpha-numeric values.');
$set('item_code', null);
$set('item_id', null);
// $set('item_description', null);
$set('serial_number', null);
$set('validationError', 'Serial Number must contain alpha-numeric values.');
Notification::make()
->title('Invalid Serial Number')
->body("Serial Number must contain alpha-numeric values only.")
@@ -622,10 +633,12 @@ class ProductionQuantityResource extends Resource
return;
}
else if (strlen($sNumber) < 9) {
$set('validationError', 'Serial Number must be at least 9 digits.');
// $set('item_code', null);
$set('item_id', null);
// $set('item_description', null);
$set('serial_number', null);
$set('validationError', 'Serial Number must be at least 9 digits.');
Notification::make()
->title('Invalid Serial Number')
->body("Serial Number must be at least 9 digits.")
@@ -635,10 +648,10 @@ class ProductionQuantityResource extends Resource
}
}
$set('validationError', 'Scan valid QR code. (Ex: Item_Code|Serial_Number )');
$set('item_id', null);
// $set('item_description', null);
$set('serial_number', null);
$set('validationError', 'Scan valid QR code. (Ex: Item_Code|Serial_Number )');
Notification::make()
->title('Invalid QR')
@@ -672,14 +685,33 @@ class ProductionQuantityResource extends Resource
->exists();
if (!$sNo)
{
$set('serial_number', $serialNumber);
$set('item_id', $item->id);
$set('item_code', $itemCode);
// $set('item_description', $item->description);
$set('success_msg', 'Y');
// if (preg_match('/\n/', $state)) {
// dd($state.': Enter key pressed');
//$set('serial_number', $serialNumber);
$set('item_id', $item->id);
//$set('item_code', $itemCode);
// }
// if (str_ends_with($state, "\n")) {
// // Enter key was pressed (newline character detected)
// //$state = trim($state); // Remove the newline
// dd($state.': Enter key pressed');
// // Perform your custom logic here
// // For example, you could trigger a form submission:
// // $this->submit();
// $set('serial_number', $serialNumber);
// $set('item_id', $item->id);
// $set('item_code', $itemCode);
// // $set('item_description', $item->description);
// }
}
else
{
$set('validationError', 'Serial number already exist in database.');
////$set('item_code', null); //246118|651616516155667
$set('item_id', null);
// $set('item_description', null);
$set('serial_number', null);
@@ -693,10 +725,11 @@ class ProductionQuantityResource extends Resource
}
else
{
$set('validationError', 'Item code does not exist in master data.');
$set('item_code', null);
$set('item_id', null);
// $set('item_description', null);
$set('serial_number', null);
$set('validationError', 'Item code does not exist in master data.');
Notification::make()
->title('Unknown Item Code')
@@ -710,20 +743,28 @@ class ProductionQuantityResource extends Resource
'class' => $get('validationError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('validationError') ? $get('validationError') : null)
->hintColor('danger'),
// ->extraAttributes([
// 'x-data' => '{ value: "" }',
// 'x-model' => 'value',
// 'x-on:keydown.enter.prevent' => '$wire.processQr(value)',
// ]),
->hintColor('danger')
->extraAttributes([
'x-data' => '{}',
// 'x-data' => '{ value: "" }',
// 'x-model' => 'value',
// 'x-on:keydown.enter.prevent' => '$wire.processQr(value)',
//'wire:keydown.enter.prevent' => 'processQr(value)',
'x-on:keydown.enter.prevent' => '
const formData = new FormData($event.target.form);
const data = Object.fromEntries(formData.entries());
$wire.processAllValues(data)
',
]),
Forms\Components\Hidden::make('item_id')
->required(),
Forms\Components\TextInput::make('serial_number')
->required()
->unique(ignoreRecord: true)
->readOnly(true)
->autocapitalize('characters'),
//->columnSpanFull(),
Forms\Components\Hidden::make('success_msg')
->required(),
Forms\Components\Hidden::make('serial_number')
->required(),
//->unique(ignoreRecord: true),
// ->autocapitalize('characters'),
// ->columnSpanFull(),
Forms\Components\TextInput::make('recent_qr') //item_description
->label('Last scanned QR')
->reactive()

View File

@@ -3,9 +3,13 @@
namespace App\Filament\Resources\ProductionQuantityResource\Pages;
use App\Filament\Resources\ProductionQuantityResource;
use App\Models\ProductionQuantity;
use App\Models\Shift;
use Filament\Actions;
use Filament\Facades\Filament;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\CreateRecord;
use Livewire\Livewire;
class CreateProductionQuantity extends CreateRecord
{
@@ -16,29 +20,118 @@ class CreateProductionQuantity extends CreateRecord
return $this->getResource()::getUrl('create'); // Stay on Create Page after saving
}
// public $qr_data;
public $qrData, $pId, $bId, $sId, $lId, $iId, $succId, $sNoId, $succStat, $recQr;
// public function processQr($itemCode)
// {
// $this->qr_data = $itemCode;
// protected static bool $canCreateAnother = false;
// // Check if the file is uploaded
// if (!$this->qr_data) {
// Notification::make()
// ->title('No QR Found')
// ->body("Please, scan the QR code.")
// ->danger()
// // ->persistent()
// ->send();
// return;
// }
// else {
// Notification::make()
// ->title('QR Found')
// ->body("Valid QR code scanned: {$this->qr_data}.")
// ->success()
// // ->persistent()
// ->send();
// }
// }
public function getFormActions(): array
{
// return parent::getFormActions(); //return [];
return [
$this->getCancelFormAction(),
];
}
public function processAllValues($formData)
{
//$formValues = [];
$formValues = request()->all(); // This will get all form data from the request
//dd($formValues);
$this->validateAndProcessForm($formValues); // Process the form values
}
public function validateAndProcessForm($formValues)
{
$user = Filament::auth()->user();
$operatorName = $user->name;
// $this->validate();
try {
// Access the nested form data
$componentData = json_decode($formValues['components'][0]['snapshot'], true);
$formData = $componentData['data']['data'][0]; // Access first item in data array
// Extract specific values
$this->qrData = $formData['item_code'] ?? null;
$this->pId = $formData['plant_id'] ?? null;
$this->bId = $formData['block_name'] ?? null;
$this->sId = $formData['shift_id'] ?? null;
$this->lId = $formData['line_id'] ?? null;
$this->iId = $formData['item_id'] ?? null;
$this->succId = $formData['success_msg'] ?? null;
// $this->sNoId = $formData['serial_number'] ?? null;
$this->recQr = $formData['recent_qr'] ?? null;
} catch (\Exception $e) {
dd('Error parsing form data:', $e->getMessage(), $formValues);
}
if ($this->succId === null) {
$this->form->fill([
'plant_id'=> $this->pId,
'block_name'=> $this->bId,
'shift_id'=> $this->sId,
'line_id'=> $this->lId,
'item_id'=> null,
'serial_number'=> null,
'success_msg'=> null,
'recent_qr' => $this->recQr,
]);
Notification::make()
->title("Invalid QR Found") // {$operatorName}
->body("Please, scan the valid QR code.")
->danger()
// ->persistent()
->send();
return;
}
else
{
// // Perform any additional processing or database operations
// $this->saveFormData($formValues);
$parts = explode('|', $this->qrData);
$itemCode = trim($parts[0]);
$this->sNoId = isset($parts[1]) ? trim($parts[1]) : null;
ProductionQuantity::create([
'plant_id'=> $this->pId,
'shift_id'=> $this->sId,
'line_id' => $this->lId,
'item_id'=> $this->iId,
'serial_number' => $this->sNoId,
// 'operator_id'=> $operatorName,
]);
// after success insertion
$this->form->fill([
'plant_id'=> $this->pId,
'block_name'=> $this->bId,
'shift_id'=> $this->sId,
'line_id'=> $this->lId,
'item_id'=> null,
'serial_number'=> null,
'success_msg'=> null,
'recent_qr' => $itemCode.' | '.$this->sNoId,
]);
Notification::make()
->title("Valid QR Found") // {$operatorName}
->body("Valid QR code scanned: {$this->qrData}.")
->success()
// ->persistent()
->send();
}
}
protected function saveFormData($formValues)
{
// Save the form data to the database or perform other operations
// For example:
$model = ProductionQuantity::create($formValues);
// // Optionally, you can emit an event or perform a redirect after saving
// $this->emit('formSaved', $model->id);
}
}

View File

@@ -8,6 +8,7 @@ use App\Filament\Imports\StickerMasterImporter;
use App\Filament\Resources\StickerMasterResource\Pages;
use App\Filament\Resources\StickerMasterResource\RelationManagers;
use App\Models\StickerMaster;
use Closure;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
@@ -183,51 +184,111 @@ class StickerMasterResource extends Resource
Forms\Components\Checkbox::make('serial_number_motor')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
->reactive()
->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('serial_number_pumpset'))
{
$set('serial_number_motor', false);
}
})
->dehydrateStateUsing(fn ($state): mixed => $state ? $state : null),
Forms\Components\Checkbox::make('serial_number_pump')
->nullable()
->reactive()
->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('serial_number_pumpset'))
{
$set('serial_number_pump', false);
}
})
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('serial_number_pumpset')
->nullable()
->disabled(function ($get) {
return $get('serial_number_motor') || $get('serial_number_pump');
})
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('pack_slip_motor')
->nullable()
->reactive()
->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('pack_slip_pumpset'))
{
$set('pack_slip_motor', false);
}
})
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('pack_slip_pump')
->nullable()
->reactive()
->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('pack_slip_pumpset'))
{
$set('pack_slip_pump', false);
}
})
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('pack_slip_pumpset')
->nullable()
->reactive()
->disabled(function ($get) {
return $get('pack_slip_motor') || $get('pack_slip_pump');
})
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('name_plate_motor')
->nullable()
->reactive()
->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('name_plate_pumpset'))
{
$set('name_plate_motor', false);
}
})
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('name_plate_pump')
->nullable()
->reactive()
->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('name_plate_pumpset'))
{
$set('name_plate_pump', false);
}
})
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('name_plate_pumpset')
->nullable()
->reactive()
->disabled(function ($get) {
return $get('name_plate_motor') || $get('name_plate_pump');
})
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('tube_sticker_motor')
->nullable()
->reactive()
->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('tube_sticker_pumpset'))
{
$set('tube_sticker_motor', false);
}
})
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('tube_sticker_pump')
->nullable()
->reactive()
->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('tube_sticker_pumpset'))
{
$set('tube_sticker_pump', false);
}
})
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('tube_sticker_pumpset')
->nullable()
->reactive()
->disabled(function ($get) {
return $get('tube_sticker_motor') || $get('tube_sticker_pump');
})
->dehydrateStateUsing(fn ($state) => $state ? $state : null), //to pass null value
Forms\Components\Checkbox::make('warranty_card')

View File

@@ -10,31 +10,49 @@ class InvoiceDataTable extends Component
public $invoiceData = [];
protected $listeners = ['refreshInvoiceData' => 'loadData'];
public string $invoiceNumber = '';
public function mount()
public bool $hasSearched = false;
protected $listeners = ['refreshInvoiceData' => 'loadData',];
public function loadData($invoiceNumber)
{
$this->loadData();
$this->invoiceNumber = $invoiceNumber;
$this->hasSearched = true;
}
$this->invoiceData = InvoiceValidation::where('invoice_number', $this->invoiceNumber)
->get()
->map(function ($record) {
return [
'sticker_master_id' => $record->sticker_master_id,
'serial_number' => $record->serial_number,
'motor_scanned_status' => $record->motor_scanned_status,
'pump_scanned_status' => $record->pump_scanned_status,
'capacitor_scanned_status' => $record->capacitor_scanned_status,
'scanned_status_set' => $record->scanned_status_set,
'panel_box_supplier' => $record->panel_box_supplier,
'panel_box_serial_number' => $record->panel_box_serial_number,
'scanned_status' => $record->scanned_status,
'created_at' => $record->created_at,
'operator_id' => $record->operator_id,
];
})
->toArray();
//Loop through and replace 'code' using related StickerMaster > Item > code
foreach ($this->invoiceData as &$row) {
$stickerMaster = \App\Models\StickerMaster::with('item')->find($row['sticker_master_id'] ?? null);
$row['code'] = $stickerMaster?->item?->code ?? 'N/A';
}
public function loadData()
{
$this->invoiceData = InvoiceValidation::all()->toArray();
}
public function render()
{
// Always fetch fresh data when Livewire re-renders (like via polling)
$invoiceData = InvoiceValidation::latest()->get();
return view('livewire.invoice-data-table', [
'invoiceData' => $invoiceData,
]);
// return view('livewire.invoice-data-table', [
// 'invoiceData' => $this->invoiceData, // <--- this is important
// ]);
return view('livewire.invoice-data-table');
}
}

View File

@@ -26,6 +26,7 @@ class InvoiceValidation extends Model
'upload_status',
'batch_number',
'quantity',
'operator_id',
];
public function plant(): BelongsTo
@@ -37,6 +38,10 @@ class InvoiceValidation extends Model
{
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

@@ -1,7 +1,36 @@
<x-filament::page>
{{-- <x-filament::page>
<form wire:submit.prevent="create">
{{ $this->form }}
{{-- @livewire('invoice-data-table') --}}
<livewire:invoice-data-table :invoice-data="$invoice_data" />
<livewire:invoice-data-table :invoice-data="$invoice_data" />
<x-filament::actions class="mt-4">
@foreach ($this->getFormActions() as $action)
{{ $action }}
@endforeach
</x-filament::actions>
</x-filament::page> --}}
<x-filament::page>
<form wire:submit.prevent="create" class="space-y-6">
{{-- Form Section --}}
<div class="filament-form space-y-6">
{{ $this->form }}
</div>
{{-- Livewire Component (Invoice Table) --}}
<div class="bg-white shadow rounded-xl p-4">
<livewire:invoice-data-table :invoice-data="$invoice_data" />
</div>
{{-- Actions --}}
<div class="filament-actions mt-6">
<x-filament::actions>
@foreach ($this->getFormActions() as $action)
{{ $action }}
@endforeach
</x-filament::actions>
</div>
</form>
</x-filament::page>

View File

@@ -1,4 +1,4 @@
<div wire:poll.5s>
{{-- <div>
<div class="mb-4">
<h2 class="text-lg font-bold text-gray-800">INVOICE DATA TABLE</h2>
<div class="mt-2">
@@ -6,40 +6,177 @@
</div>
</div>
<table class="min-w-full text-sm text-center border border-gray-300">
<thead class="bg-gray-100 font-bold">
<tr>
<th class="border px-4 py-2 min-w-[100px]">No</th>
<th class="border px-4 py-2 min-w-[200px]">Material Code</th>
<th class="border px-4 py-2 min-w-[250px]">Serial Number</th>
<th class="border px-4 py-2 min-w-[200px]">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 min-w-[250px]">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 min-w-[250px]">Panel Box Supplier</th>
<th class="border px-4 py-2 min-w-[250px]">Panel Box Serial Number</th>
<th class="border px-4 py-2 min-w-[200px]">Scanned Status</th>
</tr>
</thead>
<tbody>
@forelse ($invoiceData as $index => $row)
<tr class="border-t">
<td class="border px-4 py-2">{{ $index + 1 }}</td>
<td class="border px-4 py-2">{{ $row['material_code'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['serial_number'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['motor_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['scanned_status_set'] ?? '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['scanned_status'] ?? 'N/A' }}</td>
</tr>
@empty
<div class="overflow-x-auto overflow-y-visible">
<table class="min-w-[1500px] text-sm text-center border border-gray-300">
<thead class="bg-gray-100 font-bold">
<tr>
<td colspan="10" class="text-center py-4 text-gray-500">No data available.</td>
<th class="border px-4 py-2 min-w-[100px]">No</th>
<th class="border px-4 py-2 min-w-[200px]">Material Code</th>
<th class="border px-4 py-2 min-w-[250px]">Serial Number</th>
<th class="border px-4 py-2 min-w-[200px]">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 min-w-[250px]">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 min-w-[250px]">Panel Box Supplier</th>
<th class="border px-4 py-2 min-w-[250px]">Panel Box Serial Number</th>
<th class="border px-4 py-2 min-w-[200px]">Scanned Status</th>
</tr>
@endforelse
</tbody>
</table>
</thead>
<tbody>
@forelse ($invoiceData as $index => $row)
<tr class="border-t">
<td class="border px-4 py-2">{{ $index + 1 }}</td>
<td class="border px-4 py-2">{{ $row['code'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['serial_number'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['motor_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['scanned_status_set'] ?? '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['scanned_status'] ?? 'N/A' }}</td>
</tr>
@empty
<tr>
<td colspan="10" class="text-center py-4 text-gray-500">No data available.</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
<script>
window.addEventListener('load-data', event => {
Livewire.emit('loadData', event.detail.invoiceNumber);
});
</script> --}}
{{-- this is code for input box inisde the data grid --}}
{{-- <div>
<div class="mb-4">
<h2 class="text-lg font-bold text-gray-800">INVOICE DATA TABLE</h2>
<div class="mt-2">
<hr class="border-t-2 border-gray-300">
</div>
</div>
<input
type="text"
wire:model.defer="invoiceNumber"
wire:keydown.enter="loadData"
placeholder="Enter invoice number and press Enter"
class="border rounded px-3 py-2 mb-4"
/>
@if($hasSearched)
<div class="overflow-x-auto overflow-y-visible">
<table class="min-w-[1500px] text-sm text-center border border-gray-300">
<thead class="bg-gray-100 font-bold">
<tr>
<th class="border px-4 py-2 min-w-[100px]">No</th>
<th class="border px-4 py-2 min-w-[200px]">Material Code</th>
<th class="border px-4 py-2 min-w-[250px]">Serial Number</th>
<th class="border px-4 py-2 min-w-[200px]">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 min-w-[250px]">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 min-w-[250px]">Panel Box Supplier</th>
<th class="border px-4 py-2 min-w-[250px]">Panel Box Serial Number</th>
<th class="border px-4 py-2 min-w-[200px]">Scanned Status</th>
</tr>
</thead>
<tbody>
@forelse ($invoiceData as $index => $row)
<tr class="border-t">
<td class="border px-4 py-2">{{ $index + 1 }}</td>
<td class="border px-4 py-2">{{ $row['code'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['serial_number'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['motor_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['scanned_status_set'] ?? '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['scanned_status'] ?? 'N/A' }}</td>
</tr>
@empty
<tr>
<td colspan="10" class="text-center py-4 text-gray-500">
No data found for invoice number <strong>{{ $invoiceNumber }}</strong>.
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
@endif
</div> --}}
<div>
<div class="mb-4">
<h2 class="text-lg font-bold text-gray-800">INVOICE DATA TABLE</h2>
<div class="mt-2">
<hr class="border-t-2 border-gray-300">
</div>
</div>
@if($hasSearched)
<div class="overflow-x-auto overflow-y-visible">
{{-- <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">
<tr>
<th class="border px-4 py-2">No</th>
<th class="border px-4 py-2">Material Code</th>
<th class="border px-4 py-2">Serial Number</th>
<th class="border px-4 py-2">Motor Scanned Status</th>
<th class="border px-4 py-2">Pump Scanned Status</th>
<th class="border px-4 py-2">Capacitor Scanned Status</th>
<th class="border px-4 py-2">Scanned Status Set</th>
<th class="border px-4 py-2">Scanned Status</th>
<th class="border px-4 py-2 w-[300px] whitespace-nowrap">Time Stamp</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>
</thead>
<tbody>
@forelse ($invoiceData as $index => $row)
<tr class="border-t">
<td class="border px-4 py-2">{{ $index + 1 }}</td>
<td class="border px-4 py-2">{{ $row['code'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['serial_number'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['motor_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['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_serial_number'] ?? 'N/A' }}</td>
</tr>
@empty
<tr>
<td colspan="10" class="text-center py-4 text-gray-500">
No data found for invoice number <strong>{{ $invoiceNumber }}</strong>.
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
@endif
</div>