14 Commits

Author SHA1 Message Date
dhanabalan
8980429b52 Added trigger function for refresh chart against plant and line 2025-04-19 12:53:18 +05:30
dhanabalan
f1f9a2c5da Added update invoice toggle button and import invoice validations 2025-04-19 12:51:59 +05:30
dhanabalan
978bff037d Displaying transaction grid 2025-04-19 12:49:27 +05:30
dhanabalan
56a74e5f11 Added chart on footer 2025-04-19 12:47:53 +05:30
dhanabalan
1232c7a549 Added refresh chart while update plant, line 2025-04-19 12:46:47 +05:30
dhanabalan
6813c53d9f Added data passing for completed, empty, serial, material invoices and capacitor form 2025-04-19 12:45:40 +05:30
dhanabalan
1dd5f3e103 Added line space between relation function 2025-04-19 12:43:31 +05:30
dhanabalan
af506b19fc Added read invoice import class 2025-04-19 12:41:19 +05:30
dhanabalan
f4fcc20a4f Added refresh chart while update plant, block, shift, line 2025-04-19 12:39:37 +05:30
dhanabalan
6dcb4f7460 Added completed, empty, serial, material invoice table and create invoice and load exist invoice 2025-04-19 12:16:29 +05:30
dhanabalan
5ccab502a4 Added panel box code, material type, bundle quantity validations 2025-04-19 12:13:13 +05:30
dhanabalan
0f5ab9e5ea Added transaction chart 2025-04-19 12:11:01 +05:30
dhanabalan
d1cffac58b Removed commented codes 2025-04-19 11:22:49 +05:30
dhanabalan
d9ba1d4330 Added completed and empty invoice html table design 2025-04-19 11:21:14 +05:30
13 changed files with 3144 additions and 406 deletions

View File

@@ -24,12 +24,11 @@ class Dashboard extends \Filament\Pages\Dashboard
->label('Select Plant') ->label('Select Plant')
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set) use ($selectedPlant) { ->afterStateUpdated(function ($state, callable $set) use ($selectedPlant) {
// Update only in memory and not in the URL session(['selected_plant' => $state]);
session(['selected_plant' => $state]); // Store in session session()->forget('selected_line');
session()->forget('selected_line'); // Reset line filter
$set('Plant', $state); $set('Plant', $state);
$set('Line', null); $set('Line', null);
$this->dispatch('filtersUpdated'); // Notify chart to refresh $this->triggerChartUpdate();
}), }),
// Line Filter // Line Filter
@@ -42,9 +41,16 @@ class Dashboard extends \Filament\Pages\Dashboard
->reactive() ->reactive()
->afterStateUpdated(function ($state) { ->afterStateUpdated(function ($state) {
session(['selected_line' => $state]); // Store in session session(['selected_line' => $state]); // Store in session
$this->dispatch('filtersUpdated'); // Notify chart to refresh $this->triggerChartUpdate(); // Notify chart to refresh
}), }),
]); ]);
} }
// Helper to check if both filters are set
public function triggerChartUpdate(): void
{
if (session()->has('selected_plant') && session()->has('selected_line')) {
$this->dispatch('filtersUpdated');
}
}
} }

View File

@@ -3,13 +3,21 @@
namespace App\Filament\Resources; namespace App\Filament\Resources;
use App\Filament\Resources\InvoiceValidationResource\Pages; use App\Filament\Resources\InvoiceValidationResource\Pages;
use App\Imports\ExcelImport;
use App\Models\InvoiceValidation; use App\Models\InvoiceValidation;
use App\Models\Plant;
use App\Models\StickerMaster; use App\Models\StickerMaster;
use Filament\Actions\Action as FilamentActionsAction;
use Filament\Actions\CreateAction; use Filament\Actions\CreateAction;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Actions\Action as ActionsAction;
use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Section; use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\ToggleButtons;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Table; use Filament\Tables\Table;
@@ -20,7 +28,11 @@ 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 use Livewire\Livewire;
use Str;
class InvoiceValidationResource extends Resource class InvoiceValidationResource extends Resource
{ {
@@ -45,117 +57,842 @@ class InvoiceValidationResource extends Resource
Section::make('') Section::make('')
->schema([ ->schema([
Forms\Components\Select::make('plant_id') Forms\Components\Select::make('plant_id')
->relationship('plant', 'name') ->relationship('plant', 'name')
->required(),
Forms\Components\TextInput::make('invoice_number')
->required() ->required()
->label('Invoice Number') // ->preload()
// ->nullable(),
->reactive()
->columnSpan(1) ->columnSpan(1)
->default(function () {
return optional(InvoiceValidation::latest()->first())->plant_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
$set('update_invoice', null);
// Ensure `linestop_id` is not cleared
if (!$plantId) {
$set('ivPlantError', 'Please select a plant first.');
return;
}
else
{
$set('ivPlantError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('ivPlantError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('ivPlantError') ? $get('ivPlantError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('invoice_number')
->label('Invoice Number')
->required()
->reactive()
->columnSpan(1)
->readOnly(fn (callable $get) => !empty($get('serial_number')))
//->disabled(fn (Get $get) => !empty($get('serial_number')))
->extraAttributes([ ->extraAttributes([
'x-data' => '{ value: "" }', 'x-data' => '{ value: "" }',
'x-model' => 'value', 'x-model' => 'value',
'x-on:keydown.enter.prevent' => '$wire.processInvoice(value)', 'x-on:keydown.enter.prevent' => '$wire.processInvoice(value)',
]), ])
// ->afterStateHydrated(function (TextInput $component, string $state) {
// $component->state(ucwords($state));
// })
->afterStateUpdated(function ($state, callable $set, callable $get) {
$invNo = $get('invoice_number');
$set('serial_number', null);
$set('update_invoice', null);
// if (!$invNo) { return; } else { }
}),
Forms\Components\TextInput::make('serial_number') Forms\Components\TextInput::make('serial_number')
->label('Serial Number')
->reactive()
->readOnly(fn (callable $get) => empty($get('invoice_number')))
//->disabled(fn (Get $get) => empty($get('invoice_number')))
->extraAttributes([ ->extraAttributes([
'x-data' => '{ value: "" }', 'x-data' => '{ value: "" }',
'x-model' => 'value', 'x-model' => 'value',
'wire:keydown.enter.prevent' => 'processSerialNumber(value)', // Using wire:keydown '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')
->label('Total Quantity') ->label('Total Quantity')
->readOnly(true)
->columnSpan(1), ->columnSpan(1),
Forms\Components\TextInput::make('scanned_quantity') Forms\Components\TextInput::make('scanned_quantity')
->label('Scanned Quantity') ->label('Scanned Quantity')
->readOnly(true)
->columnSpan(1), ->columnSpan(1),
ToggleButtons::make('update_invoice')
->label('Update Invoice?')
->boolean()
->grouped()
->reactive()
->hidden(fn (callable $get) => ($get('invoice_number') == null || $get('update_invoice') === '0') || !empty($get('serial_number')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if(!$get('plant_id'))
{
$set('update_invoice', null);
return;
}
if($get('update_invoice') === "1")
{
$totQuan = InvoiceValidation::where('invoice_number', $get('invoice_number'))->where('plant_id', $get('plant_id'))->count();
if($totQuan <= 0)
{
$set('update_invoice', null);
return;
}
$totMQuan = InvoiceValidation::where('invoice_number', $get('invoice_number'))->whereNotNull('quantity')->where('plant_id', $get('plant_id'))->count();
$scanMQuan = InvoiceValidation::where('invoice_number', $get('invoice_number'))->whereNotNull('serial_number')->where('serial_number', '!=', '')->where('plant_id', $get('plant_id'))->count();
$scanSQuan = InvoiceValidation::where('invoice_number', $get('invoice_number'))->where('scanned_status', 'Scanned')->where('plant_id', $get('plant_id'))->count();
if($totMQuan > 0)
{
if ($totQuan === $scanMQuan)
{
$set('update_invoice', null);
return;
}
}
else
{
if ($totQuan === $scanSQuan)
{
$set('update_invoice', null);
return;
}
}
}
})
->disabled(fn (Get $get) => empty($get('invoice_number'))),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(true),
]) ])
->columns(5), ->columns(5),
]); ]);
} }
public static function table(Table $table): Table public static function table(Table $table): Table
{ {
return $table return $table
->columns([ ->columns([
Tables\Columns\TextColumn::make('id') Tables\Columns\TextColumn::make('id')
->label('ID') ->label('ID')
->numeric() ->numeric()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('stickerMaster.id') Tables\Columns\TextColumn::make('invoice_number')
->numeric() ->label('Invoice Number')
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('plant.name') Tables\Columns\TextColumn::make('stickerMaster.item.code')
->numeric() ->label('Material Code')
->sortable(),
Tables\Columns\TextColumn::make('serial_number')
->label('Serial Number')
->sortable(),
Tables\Columns\TextColumn::make('motor_scanned_status')
->label('Motor Scanned Status')
->sortable(),
Tables\Columns\TextColumn::make('pump_scanned_status')
->label('Pump Scanned Status')
->sortable(),
Tables\Columns\TextColumn::make('scanned_status_set')
->label('Pump Set Scanned Status')
->sortable(),
Tables\Columns\TextColumn::make('capacitor_scanned_status')
->label('Capacitor Scanned Status')
->sortable(),
Tables\Columns\TextColumn::make('scanned_status')
->label('Scanned Status')
->sortable(),
Tables\Columns\TextColumn::make('panel_box_supplier')
->label('Panel Box Supplier')
->sortable(),
Tables\Columns\TextColumn::make('panel_box_serial_number')
->label('Panel Box Serial Number')
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('load_rate') Tables\Columns\TextColumn::make('load_rate')
->label('Load Rate')
->numeric() ->numeric()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('upload_status')
->label('Upload Status')
->sortable(),
Tables\Columns\TextColumn::make('batch_number')
->label('Batch Number')
->sortable(),
Tables\Columns\TextColumn::make('quantity')
->label('Quantity')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('operator_id')
->label('Operator ID')
->sortable(),
Tables\Columns\TextColumn::make('plant.name')
->label('Plant')
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->dateTime()
->sortable(),
Tables\Columns\TextColumn::make('updated_at')
->label('Updated At')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at')
->label('Deleted At')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
]) ])
->headerActions([ ->headerActions([
// Action::make('plant_id')
// ->label('Select Plant')
// ->form([
// Select::make('plant_id')
// ->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs
// ->label('Select Plant')
// ->required()
// ->reactive()
// ]),
Tables\Actions\Action::make('Import Serial Number') Tables\Actions\Action::make('Import Serial Number')
->label('Import Serial Number') ->label('Import Serial Invoice')
->form([ ->form([
Select::make('plant_id')
->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs
->label('Select Plant')
->required()
->default(function () {
return optional(InvoiceValidation::latest()->first())->plant_id;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('invoice_serial_number', null);
})
->reactive(),
FileUpload::make('invoice_serial_number') FileUpload::make('invoice_serial_number')
->label('Invoice Serial Number') ->label('Invoice Serial Number')
// ->required()
->preserveFilenames() // <- this keeps the original filename ->preserveFilenames() // <- this keeps the original filename
->storeFiles(false) // prevent auto-storing, we will store manually ->storeFiles(false) // prevent auto-storing, we will store manually
->reactive()
->required()
->disk('local') //'local' refers to the local storage disk defined in config/filesystems.php, typically pointing to storage/app. ->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 ->visible(fn (Get $get) => !empty($get('plant_id')))
->directory('uploads/temp'),
]) ])
->action(function (array $data) { ->action(function (array $data) {
$uploadedFile = $data['invoice_serial_number']; $uploadedFile = $data['invoice_serial_number'];
$disk = Storage::disk('local');
$plantId = $data['plant_id'];
// Get original filename // Get original filename
$originalName = $uploadedFile->getClientOriginalName(); // e.g. 3RA0018732.xlsx $originalName = $uploadedFile->getClientOriginalName(); // e.g. 3RA0018732.xlsx
// Store manually using storeAs to keep original name // Store manually using storeAs to keep original name
$path = $uploadedFile->storeAs('uploads/temp', $originalName, 'local'); // returns relative path $path = $uploadedFile->storeAs('uploads/temp', $originalName, 'local'); // returns relative path
// uploads/temp/3RA0018735.xlsx
$fullPath = Storage::disk('local')->path($path);
// /home/iot-dev/projects/pds/storage/app/private/uploads/temp/3RA0018735.xlsx
$totQuan = InvoiceValidation::where('invoice_number', $originalName)->where('plant_id', $plantId)->count();
$scanSQuan = InvoiceValidation::where('invoice_number', $originalName)->where('scanned_status', 'Scanned')->where('plant_id', $plantId)->count();
if($totQuan == $scanSQuan && $totQuan > 0)
{
Notification::make()
->title('Serial invoice already completed the scanning process for selected plant.')
->danger()
->send();
if ($disk->exists($path))
{
$disk->delete($path);
}
return;
}
if ($fullPath && file_exists($fullPath))
{
$rows = Excel::toArray(null, $fullPath)[0];
if((count($rows) - 1) <= 0)
{
Notification::make()
->title('Records Not Found')
->body("Import the valid 'Serial Invoice' file to proceed..!")
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$invalidMatCodes = [];
$invalidSerialCodes=[];
$materialCodes = [];
$missingSerials = [];
$duplicateSerials = [];
$seenSerialNumbers = [];
$validRowsFound = false;
foreach ($rows as $index => $row)
{
if ($index === 0) continue; // Skip header
$materialCode = trim($row[0]);
$serialNumber = trim($row[1]);
if (empty($materialCode) && empty($serialNumber)) {
continue;
}
if (!empty($materialCode))
{
if(Str::length($materialCode) < 6 || !ctype_alnum($materialCode))
{
$invalidMatCodes[] = $materialCode;
}
else
{
if (empty($serialNumber)) {
$missingSerials[] = $materialCode;
}
else if(Str::length($serialNumber) < 9 || !ctype_alnum($serialNumber))
{
$invalidSerialCodes[] = $serialNumber;
}
else
{
if (in_array($serialNumber, $seenSerialNumbers)) {
$duplicateSerials[] = $serialNumber;
} else {
$seenSerialNumbers[] = $serialNumber;
$materialCodes[] = $materialCode;
$validRowsFound = true;
}
}
}
}
else
{
continue;
}
}
$uniqueInvalidCodes = array_unique($invalidMatCodes);
$uniqueMissingSerials = array_unique($missingSerials);
$uniqueSerialCodes = array_unique($invalidSerialCodes);
$duplicateSerialCodes = array_unique($duplicateSerials);
if (!empty($uniqueInvalidCodes)) {
Notification::make()
->title('Invalid Item Codes')
->body('The following item codes should contain minimum 6 digit alpha numeric values:<br>' . implode(', ', $uniqueInvalidCodes))
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
else if (!empty($uniqueMissingSerials)) {
Notification::make()
->title('Missing Serial Numbers')
->body("The following item codes doesn't have valid serial number:<br>" . implode(', ', $uniqueMissingSerials))
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
else if (!empty($uniqueSerialCodes)) {
Notification::make()
->title('Invalid Serial Number')
->body('The following serial numbers should contain minimum 9 digit alpha numeric values:<br>' . implode(', ', $uniqueSerialCodes))
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
else if (!empty($duplicateSerialCodes)) {
Notification::make()
->title('Duplicate Serial Numbers')
->body('The following serial numbers are already exist in database:<br>' . implode(', ', $duplicateSerialCodes))
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
if (!$validRowsFound) {
Notification::make()
->title('Invalid Serial Invoice')
->danger() // This makes the notification red to indicate an error
->body('Uploaded Excel sheet is empty or<br>contains no valid data.')
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$uniqueCodes = array_unique($materialCodes);
$matchedItems = StickerMaster::with('item')
->whereHas('item', function ($query) use ($uniqueCodes) {
$query->whereIn('code', $uniqueCodes);
})
->get();
$matchedCodes = $matchedItems->pluck('item.code')->toArray();
$missingCodes = array_diff($uniqueCodes, $matchedCodes);
if (!empty($missingCodes))
{
$missingCount = count($missingCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database." : 'The following item codes are not found in database:<br>' . implode(', ', $missingCodes);
Notification::make()
->title('Unknown Item Codes')
->body($message)
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
// Check which codes have a material_type set (not null)
$invalidCodes = $matchedItems
->filter(fn ($sticker) => !empty($sticker->material_type)) //filter invalid
->pluck('item.code')
->toArray();
if (count($invalidCodes) > 10)
{
Notification::make()
->title('Invalid item codes found')
->body('' . count($invalidCodes) . 'item codes found have material type.')
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
else if(count($invalidCodes) > 0)
{
Notification::make()
->title('Invalid item codes found')
->body('Material invoice Item Codes found : ' . implode(', ', $invalidCodes))
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
else
{
// Save full file path to session
session(['uploaded_invoice_path' => $fullPath]);
Notification::make()
->title('Serial invoice imported successfully.')
->success()
->send();
}
}
}),
Tables\Actions\Action::make('Import Invoice Material')
->label('Import Material Invoice')
->form([
Select::make('plant_id')
->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs
->label('Select Plant')
->required()
->reactive()
->default(function () {
return optional(InvoiceValidation::latest()->first())->plant_id;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('invoice_material', null);
}),
FileUpload::make('invoice_material')
->label('Invoice Material')
->required()
->preserveFilenames()
->reactive() // <- this keeps the original filename
->storeFiles(false) // prevent auto-storing
->disk('local')
->visible(fn (Get $get) => !empty($get('plant_id')))
->directory('uploads/temp')
])
->action(function (array $data) {
$uploadedFile = $data['invoice_material'];
$plantId = $data['plant_id']; // Access the selected plant_id
$disk = Storage::disk('local');
// Get original filename
$originalName = $uploadedFile->getClientOriginalName();
$path = $uploadedFile->storeAs('uploads/temp', $originalName, 'local');
$fullPath = Storage::disk('local')->path($path); $fullPath = Storage::disk('local')->path($path);
// Save full file path to session $totQuan = InvoiceValidation::where('invoice_number', $originalName)->where('plant_id', $plantId)->count();
session(['uploaded_invoice_path' => $fullPath]); $scanMQuan = InvoiceValidation::where('invoice_number', $originalName)->whereNotNull('serial_number')->where('serial_number', '!=', '')->where('plant_id', $plantId)->count();
// session()->flash('just_uploaded_invoice', true); // 👈 add this if($totQuan == $scanMQuan && $totQuan > 0)
{
Notification::make()
->title('Material invoice already completed the scanning process for selected plant.')
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
Notification::make() if ($fullPath && file_exists($fullPath))
->title('File Uploaded. Continue in Create Page.') {
->success() $rows = Excel::toArray(null, $fullPath)[0];
->send();
if((count($rows) - 1) <= 0)
{
Notification::make()
->title('Records Not Found')
->body("Import the valid 'Material Invoice' file to proceed..!")
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$invalidMatCodes = [];
$materialCodes = [];
$missingQuantities = [];
$invalidMatQuan = [];
$invalidMaterialQuan = [];
$validRowsFound = false;
foreach ($rows as $index => $row)
{
if ($index === 0) continue; // Skip header
$materialCode = trim($row[0]);
$materialQuantity = trim($row[1]);
if (empty($materialCode) && empty($materialQuantity)) {
continue;
}
if (!empty($materialCode)) {
if(Str::length($materialCode) < 6 || !ctype_alnum($materialCode))
{
$invalidMatCodes[] = $materialCode;
}
else
{
if($materialQuantity == 0)
{
$invalidMaterialQuan[] = $materialCode;
}
else if (empty($materialQuantity))
{
$missingQuantities[] = $materialCode;
}
else if(!is_numeric($materialQuantity))
{
$invalidMatQuan[] = $materialCode;
}
else
{
$materialCodes[] = $materialCode;
$validRowsFound = true;
}
}
}
else
{
continue;
}
}
$uniqueInvalidCodes = array_unique($invalidMatCodes);
$uniqueaplhaMat = array_unique($invalidMatQuan);
$uniqueZeroMat = array_unique($invalidMaterialQuan);
$uniqueEmptyMat = array_unique($missingQuantities);
if (!empty($uniqueInvalidCodes)) {
Notification::make()
->title('Invalid Item Codes')
->body('The following item codes should contain minimum 6 digit alpha numeric values:<br>' . implode(', ', $uniqueInvalidCodes))
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
if (!empty($uniqueaplhaMat)) {
Notification::make()
->title('Invalid Material Quantity')
->body("The following item codes material quantity must be a numeric values :<br>" . implode(', ', $uniqueaplhaMat))
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
if (!empty($uniqueZeroMat)) {
Notification::make()
->title('Invalid Material Quantity')
->body("The following item codes material quantity should be greater than 0:<br>" . implode(', ', $uniqueZeroMat))
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
if (!empty($uniqueEmptyMat)) {
Notification::make()
->title('Missing Material Quantity')
->body("The following item codes doesn't have valid material quantity:<br>" . implode(', ', $uniqueEmptyMat))
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
if (!$validRowsFound) {
Notification::make()
->title('Invalid Material Invoice')
->danger() // This makes the notification red to indicate an error
->body('Uploaded Excel sheet is empty or<br>contains no valid data.')
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$uniqueCodes = array_unique($materialCodes);
$matchedItems = StickerMaster::with('item')
->whereHas('item', function ($query) use ($uniqueCodes) {
$query->whereIn('code', $uniqueCodes);
})
->get();
$matchedCodes = $matchedItems->pluck('item.code')->toArray();
$missingCodes = array_diff($uniqueCodes, $matchedCodes);
if (!empty($missingCodes))
{
$missingCount = count($missingCodes);
$message = $missingCount > 10
? "'$missingCount' Item Codes are not found in sticker master."
: 'Item Codes are not found in sticker master:<br>' . implode(', ', $missingCodes);
Notification::make()
->title('Unknown Item Codes')
->body($message)
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$invalidCodes = $matchedItems
->filter(fn ($sticker) => empty($sticker->material_type)) //filter invalid
->pluck('item.code')
->toArray();
if (count($invalidCodes) > 10)
{
Notification::make()
->title('Invalid item codes found')
->body('' . count($invalidCodes) . 'invalid item codes found have serial number.')
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
else if(count($invalidCodes) > 0)
{
Notification::make()
->title('Invalid item codes found')
->body('Serial invoice Item Codes found : ' . implode(', ', $invalidCodes))
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$nonNumericQtyCodes = [];
$zeroQtyCodes = [];
$notDivisibleCodes = [];
foreach ($matchedItems as $sticker)
{
$code = $sticker->item->code;
$materialType = $sticker->material_type;
if ($materialType == 2)
{
$bundleQty = $sticker->bundle_quantity ?? 0;
$totalExcelQty = 0;
foreach ($rows as $index => $row)
{
if ($index === 0) continue; // Skip header
$excelCode = trim($row[0]);
$excelMatQty = trim($row[1]);
if ($excelCode === $code && is_numeric($excelMatQty)) {
$totalExcelQty += $excelMatQty; // Sum up the quantities
}
}
if ($totalExcelQty === 0) {
$zeroQtyCodes[] = $code;
} elseif (!is_numeric($totalExcelQty)) {
$nonNumericQtyCodes[] = $code; // Here you may want to check divisibility condition too
} elseif ($bundleQty != 0 && $totalExcelQty % $bundleQty !== 0) {
$notDivisibleCodes[] = $code;
}
}
}
$showValidationNotification = function(array $codes, string $message) {
if (count($codes) === 0) return;
$uniqueCodes = array_unique($codes);
$codeList = implode(', ', $uniqueCodes);
Notification::make()
->title('Invalid Bundle Quantity')
->body("$message <br>$codeList")
->danger()
->send();
};
$showValidationNotification($nonNumericQtyCodes, "The following item codes contains invalid bundle quantity:");
$showValidationNotification($zeroQtyCodes, "The following item codes quantity should be greater than '0':");
$showValidationNotification($notDivisibleCodes, "The following item codes quantity is not divisible by bundle quantity.");
if ($nonNumericQtyCodes || $zeroQtyCodes || $notDivisibleCodes) {
if ($disk->exists($path))
{
$disk->delete($path);
}
return;
}
else
{
// Save full file path to session
session(['uploaded_material_invoice' => $fullPath]);
Notification::make()
->title('Material invoice imported successfully.')
->success()
->send();
}
}
}), }),
])
Tables\Actions\Action::make('Import Invoice Material') ->filters([
->label('Import Invoice Material') Tables\Filters\TrashedFilter::make(),
->form([ ])
FileUpload::make('invoice_material') ->actions([
->label('Invoice Material') Tables\Actions\ViewAction::make(),
->required(), Tables\Actions\EditAction::make(),
]) ])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
]); ]);
// ->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 public static function getRelations(): array

View File

@@ -19,11 +19,11 @@ class ListInvoiceValidations extends ListRecords
]; ];
} }
//to hide the data from the table // //to hide the data from the table
protected function getTableQuery(): \Illuminate\Database\Eloquent\Builder // protected function getTableQuery(): \Illuminate\Database\Eloquent\Builder
{ // {
return static::getResource()::getEloquentQuery()->whereRaw('1 = 0'); // return static::getResource()::getEloquentQuery()->whereRaw('1 = 0');
} // }
} }

View File

@@ -22,7 +22,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section; use Filament\Forms\Components\Section;
use Filament\Notifications\Notification; use Filament\Notifications\Notification;
use Filament\Tables\Actions\ExportAction; use Filament\Tables\Actions\ExportAction;
//use Livewire\Livewire; use Livewire\Livewire;
class ProductionQuantityResource extends Resource class ProductionQuantityResource extends Resource
{ {
@@ -34,7 +34,7 @@ class ProductionQuantityResource extends Resource
protected static ?string $navigationGroup = 'Production'; protected static ?string $navigationGroup = 'Production';
// public $plant_id;
public static function form(Form $form): Form public static function form(Form $form): Form
{ {
return $form return $form
@@ -45,7 +45,7 @@ class ProductionQuantityResource extends Resource
->relationship('plant', 'name') ->relationship('plant', 'name')
->required() ->required()
// ->nullable() // ->nullable()
->reactive() ->reactive()
// ->default(fn () => optional(ProductionQuantity::latest()->first())->plant_id) // ->default(fn () => optional(ProductionQuantity::latest()->first())->plant_id)
->default(function () { ->default(function () {
return optional(ProductionQuantity::latest()->first())->plant_id; return optional(ProductionQuantity::latest()->first())->plant_id;
@@ -54,8 +54,17 @@ class ProductionQuantityResource extends Resource
// ->afterStateUpdated(fn ($set) => $set('block_name', null)) // ->afterStateUpdated(fn ($set) => $set('block_name', null))
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
//...
session(['select_plant' => $state]);
session()->forget('select_line'); // Reset line filter
//...
$set('block_name', null); $set('block_name', null);
if (!$plantId) { if (!$plantId)
{
$set('pqPlantError', 'Please select a plant first.'); $set('pqPlantError', 'Please select a plant first.');
return; return;
} }
@@ -64,7 +73,24 @@ class ProductionQuantityResource extends Resource
$set('validationError', null); $set('validationError', null);
$set('pqPlantError', null); $set('pqPlantError', null);
} }
}) })
->extraAttributes([
'x-on:change' => "
if (\$event.target.value) {
\$wire.dispatch('filtersUpdated', { plantId: \$event.target.value });
}
",
])
// ->extraAttributes([
// 'x-on:change' => "\$wire.dispatch('filtersUpdated', { plantId: \$event.target.value })"
// ])
// ->extraAttributes([
// 'x-on:change' => "\$wire.set('plantId', \$event.target.value)"
// ])
->extraAttributes(fn ($get) => [ ->extraAttributes(fn ($get) => [
'class' => $get('pqPlantError') ? 'border-red-500' : '', 'class' => $get('pqPlantError') ? 'border-red-500' : '',
]) ])
@@ -87,7 +113,6 @@ class ProductionQuantityResource extends Resource
$latestShiftId = optional(ProductionQuantity::latest()->first())->shift_id; $latestShiftId = optional(ProductionQuantity::latest()->first())->shift_id;
return optional(Shift::where('id', $latestShiftId)->first())->block_id; return optional(Shift::where('id', $latestShiftId)->first())->block_id;
}) })
// ->afterStateUpdated(fn ($set) => $set('shift_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id')) if($get('id'))
{ {
@@ -103,6 +128,9 @@ class ProductionQuantityResource extends Resource
$blockId = $get('block_name'); $blockId = $get('block_name');
$set('shift_id', null); $set('shift_id', null);
session(['select_plant' => $get('plant_id')]);
session()->forget('select_line');
if (!$blockId) { if (!$blockId) {
$set('pqBlockError', 'Please select a block first.'); $set('pqBlockError', 'Please select a block first.');
return; return;
@@ -151,6 +179,9 @@ class ProductionQuantityResource extends Resource
$curShiftId = $get('shift_id'); $curShiftId = $get('shift_id');
$set('line_id', null); $set('line_id', null);
session(['select_plant' => $get('plant_id')]);
session()->forget('select_line');
if (!$curShiftId) { if (!$curShiftId) {
$set('pqShiftError', 'Please select a shift first.'); $set('pqShiftError', 'Please select a shift first.');
return; return;
@@ -200,8 +231,12 @@ class ProductionQuantityResource extends Resource
} }
$lineId = $get('line_id'); $lineId = $get('line_id');
$set('item_code', null); $set('item_code', null);
session(['select_plant' => $get('plant_id')]);
session()->forget('select_line');
session(['select_line' => $state]);
if (!$lineId) { if (!$lineId) {
$set('pqLineError', 'Please select a line first.'); $set('pqLineError', 'Please select a line first.');
return; return;
@@ -231,6 +266,12 @@ class ProductionQuantityResource extends Resource
// } // }
} }
}) })
// ->extraAttributes([
// 'x-on:change' => "\$wire.dispatch('filtersUpdated')", // Dispatch Livewire event from Alpine.js
// ])
->extraAttributes([
'x-on:change' => "\$wire.dispatch('filtersUpdated', { lineId: \$event.target.value })"
])
->extraAttributes(fn ($get) => [ ->extraAttributes(fn ($get) => [
'class' => $get('pqLineError') ? 'border-red-500' : '', 'class' => $get('pqLineError') ? 'border-red-500' : '',
]) ])
@@ -335,7 +376,7 @@ class ProductionQuantityResource extends Resource
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0]; [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
$hRs = (int) $hRs; $hRs = (int) $hRs;
// $miNs = (int) $miNs;-*/ //$miNs = (int) $miNs;-*/
$totalMinutes = $hRs * 60 + $miNs; $totalMinutes = $hRs * 60 + $miNs;
@@ -793,6 +834,7 @@ class ProductionQuantityResource extends Resource
]); ]);
} }
public static function table(Table $table): Table public static function table(Table $table): Table
{ {
return $table return $table

View File

@@ -3,6 +3,7 @@
namespace App\Filament\Resources\ProductionQuantityResource\Pages; namespace App\Filament\Resources\ProductionQuantityResource\Pages;
use App\Filament\Resources\ProductionQuantityResource; use App\Filament\Resources\ProductionQuantityResource;
use App\Filament\Widgets\ItemOverview;
use App\Models\ProductionQuantity; use App\Models\ProductionQuantity;
use App\Models\Shift; use App\Models\Shift;
use Filament\Actions; use Filament\Actions;
@@ -15,6 +16,13 @@ class CreateProductionQuantity extends CreateRecord
{ {
protected static string $resource = ProductionQuantityResource::class; protected static string $resource = ProductionQuantityResource::class;
protected function getFooterWidgets(): array
{
return [
ItemOverview::make(),
];
}
protected function getRedirectUrl(): string protected function getRedirectUrl(): string
{ {
return $this->getResource()::getUrl('create'); // Stay on Create Page after saving return $this->getResource()::getUrl('create'); // Stay on Create Page after saving

View File

@@ -161,11 +161,15 @@ class StickerMasterResource extends Resource
Forms\Components\TextInput::make('panel_box_code') Forms\Components\TextInput::make('panel_box_code')
->label('Panel Box Code') ->label('Panel Box Code')
->readOnly(fn (callable $get) => $get('material_type'))
->nullable(), ->nullable(),
Forms\Components\TextInput::make('load_rate') Forms\Components\TextInput::make('load_rate')
->label('Load Rate') ->label('Load Rate')
->default(0) ->default(0)
->disabled(function ($get) {
return $get('material_type');
})
->integer() ->integer()
->nullable(), ->nullable(),
@@ -173,28 +177,55 @@ class StickerMasterResource extends Resource
Forms\Components\Select::make('material_type') Forms\Components\Select::make('material_type')
->label('Material Type') ->label('Material Type')
->options([ ->options([
'individual' => '1', '1' => 'Individual',
'bundle' => '2', '2' => 'Bundle',
]), ])
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
Forms\Components\TextInput::make('bundle_quantity') if ($state)
{
$set('panel_box_code', null);
$set('load_rate', 0);
}
if ($state !== "2")
{
$set('bundle_quantity', null);
}
else
{
$set('bundle_quantity', 1);
}
//$plantId = $get('plant_id');
})
->nullable(),
Forms\Components\TextInput::make('bundle_quantity')
->label('Bundle Quantity') ->label('Bundle Quantity')
->integer() ->integer()
->readOnly(fn (callable $get) => $get('material_type') !== "2")
->nullable(), ->nullable(),
Forms\Components\Checkbox::make('serial_number_motor') Forms\Components\Checkbox::make('serial_number_motor')
->reactive() ->reactive()
->disabled(function ($get) {
return $get('serial_number_pumpset');
})
->afterStateUpdated(function ($state, callable $set,callable $get) { ->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('serial_number_pumpset')) if ($get('serial_number_pumpset'))
{ {
$set('serial_number_motor', false); $set('serial_number_motor', false);
} }
}) })
->dehydrateStateUsing(fn ($state): mixed => $state ? $state : null), ->dehydrateStateUsing(fn ($state): mixed => $state ? $state : null),
Forms\Components\Checkbox::make('serial_number_pump') Forms\Components\Checkbox::make('serial_number_pump')
->reactive() ->reactive()
->disabled(function ($get) {
return $get('serial_number_pumpset');
})
->afterStateUpdated(function ($state, callable $set,callable $get) { ->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('serial_number_pumpset')) if ($get('serial_number_pumpset'))
{ {
@@ -204,13 +235,24 @@ class StickerMasterResource extends Resource
->dehydrateStateUsing(fn ($state) => $state ? $state : null), ->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('serial_number_pumpset') Forms\Components\Checkbox::make('serial_number_pumpset')
->disabled(function ($get) { ->reactive()
return $get('serial_number_motor') || $get('serial_number_pump'); ->disabled(function ($get) {
}) return $get('serial_number_motor') || $get('serial_number_pump');
->dehydrateStateUsing(fn ($state) => $state ? $state : null), })
->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('serial_number_pumpset'))
{
$set('serial_number_motor', false);
$set('serial_number_pump', false);
}
})
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('pack_slip_motor') Forms\Components\Checkbox::make('pack_slip_motor')
->reactive() ->reactive()
->disabled(function ($get) {
return $get('pack_slip_pumpset');
})
->afterStateUpdated(function ($state, callable $set,callable $get) { ->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('pack_slip_pumpset')) if ($get('pack_slip_pumpset'))
{ {
@@ -221,6 +263,9 @@ class StickerMasterResource extends Resource
Forms\Components\Checkbox::make('pack_slip_pump') Forms\Components\Checkbox::make('pack_slip_pump')
->reactive() ->reactive()
->disabled(function ($get) {
return $get('pack_slip_pumpset');
})
->afterStateUpdated(function ($state, callable $set,callable $get) { ->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('pack_slip_pumpset')) if ($get('pack_slip_pumpset'))
{ {
@@ -234,10 +279,20 @@ class StickerMasterResource extends Resource
->disabled(function ($get) { ->disabled(function ($get) {
return $get('pack_slip_motor') || $get('pack_slip_pump'); return $get('pack_slip_motor') || $get('pack_slip_pump');
}) })
->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('pack_slip_pumpset'))
{
$set('pack_slip_motor', false);
$set('pack_slip_pump', false);
}
})
->dehydrateStateUsing(fn ($state) => $state ? $state : null), ->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('name_plate_motor') Forms\Components\Checkbox::make('name_plate_motor')
->reactive() ->reactive()
->disabled(function ($get) {
return $get('name_plate_pumpset');
})
->afterStateUpdated(function ($state, callable $set,callable $get) { ->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('name_plate_pumpset')) if ($get('name_plate_pumpset'))
{ {
@@ -248,6 +303,9 @@ class StickerMasterResource extends Resource
Forms\Components\Checkbox::make('name_plate_pump') Forms\Components\Checkbox::make('name_plate_pump')
->reactive() ->reactive()
->disabled(function ($get) {
return $get('name_plate_pumpset');
})
->afterStateUpdated(function ($state, callable $set,callable $get) { ->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('name_plate_pumpset')) if ($get('name_plate_pumpset'))
{ {
@@ -260,11 +318,21 @@ class StickerMasterResource extends Resource
->reactive() ->reactive()
->disabled(function ($get) { ->disabled(function ($get) {
return $get('name_plate_motor') || $get('name_plate_pump'); return $get('name_plate_motor') || $get('name_plate_pump');
})
->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('name_plate_pumpset'))
{
$set('name_plate_motor', false);
$set('name_plate_pump', false);
}
}) })
->dehydrateStateUsing(fn ($state) => $state ? $state : null), ->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('tube_sticker_motor') Forms\Components\Checkbox::make('tube_sticker_motor')
->reactive() ->reactive()
->disabled(function ($get) {
return $get('tube_sticker_pumpset');
})
->afterStateUpdated(function ($state, callable $set,callable $get) { ->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('tube_sticker_pumpset')) if ($get('tube_sticker_pumpset'))
{ {
@@ -275,6 +343,9 @@ class StickerMasterResource extends Resource
Forms\Components\Checkbox::make('tube_sticker_pump') Forms\Components\Checkbox::make('tube_sticker_pump')
->reactive() ->reactive()
->disabled(function ($get) {
return $get('tube_sticker_pumpset');
})
->afterStateUpdated(function ($state, callable $set,callable $get) { ->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('tube_sticker_pumpset')) if ($get('tube_sticker_pumpset'))
{ {
@@ -288,6 +359,13 @@ class StickerMasterResource extends Resource
->reactive() ->reactive()
->disabled(function ($get) { ->disabled(function ($get) {
return $get('tube_sticker_motor') || $get('tube_sticker_pump'); return $get('tube_sticker_motor') || $get('tube_sticker_pump');
})
->afterStateUpdated(function ($state, callable $set,callable $get) {
if ($get('tube_sticker_pumpset'))
{
$set('tube_sticker_motor', false);
$set('tube_sticker_pump', false);
}
}) })
->dehydrateStateUsing(fn ($state) => $state ? $state : null), //to pass null value ->dehydrateStateUsing(fn ($state) => $state ? $state : null), //to pass null value

View File

@@ -10,60 +10,29 @@ class ItemOverview extends ChartWidget
protected int|string|array $columnSpan = 'full'; protected int|string|array $columnSpan = 'full';
//protected $listeners = ['filtersUpdated' => '$refresh']; // Listen for filter updates protected $listeners = ['filtersUpdated' => '$refresh'];
// public $plantId;
// public $lineId;
// protected function getData(): array
// {
// $activeFilter = $this->filter;
// // Get filter values from session
// $selectedPlant = session('selected_plant');
// $selectedLine = session('selected_line');
// $query = \DB::table('production_quantities')
// ->join('plants', 'production_quantities.plant_id', '=', 'plants.id') // Join plants table
// ->join('lines', 'production_quantities.line_id', '=', 'lines.id') // Join lines table
// ->selectRaw('EXTRACT(HOUR FROM production_quantities.created_at) AS hour, count(*) AS total_quantity')
// ->whereBetween('production_quantities.created_at', [now()->startOfDay(), now()->endOfDay()])
// ->when($selectedPlant, function ($q) use ($selectedPlant) {
// return $q->where('plants.id', $selectedPlant);
// })
// ->when($selectedLine, function ($q) use ($selectedLine) {
// return $q->where('lines.id', $selectedLine);
// })
// ->groupByRaw('EXTRACT(HOUR FROM production_quantities.created_at)')
// ->orderByRaw('EXTRACT(HOUR FROM production_quantities.created_at)')
// ->pluck('total_quantity', 'hour')
// ->toArray();
// $allHours = array_fill(0, 24, 0);
// $data = array_replace($allHours, $query);
// $shiftedKeys = range(8, 23); // 8 AM to 11 PM
// $shiftedKeys = array_merge($shiftedKeys, range(0, 8));
// $orderedData = array_map(fn($hour) => $data[$hour], $shiftedKeys);
// return [
// 'datasets' => [
// [
// 'label' => 'Hourly Production',
// 'data' => array_values($orderedData),
// 'borderColor' => 'rgba(75, 192, 192, 1)',
// 'backgroundColor' => 'rgba(75, 192, 192, 0.2)',
// 'fill' => false,
// 'tension' => 0.3,
// ],
// ],
// // Correct label sequence from 8 AM to 7 AM
// 'labels' => array_map(fn ($hour) => date("g A", strtotime("$hour:00")), $shiftedKeys),
// ];
// }
protected function getData(): array protected function getData(): array
{ {
$activeFilter = $this->filter; $activeFilter = $this->filter;
$selectedPlant = session('selected_plant'); // $selectPlant = session('select_plant');
$selectedLine = session('selected_line'); // $selectLine = session('select_line');
// $selectedPlant = session('selected_plant');
// $selectedLine = session('selected_line');
$selectedPlant = session('selected_plant') ?? session('select_plant');
$selectedLine = session('selected_line') ?? session('select_line');
if (!$selectedPlant || !$selectedLine) {
return [
'datasets' => [],
'labels' => [],
];
}
if ($activeFilter === 'yesterday') { if ($activeFilter === 'yesterday') {
$startDate = now()->subDay()->startOfDay(); $startDate = now()->subDay()->startOfDay();
@@ -90,7 +59,7 @@ class ItemOverview extends ChartWidget
} }
$query = \DB::table('production_quantities') $query = \DB::table('production_quantities')
->join('plants', 'production_quantities.plant_id', '=', 'plants.id') ->join('plants', 'production_quantities.plant_id', '=', 'plants.id') //inner join
->join('lines', 'production_quantities.line_id', '=', 'lines.id') ->join('lines', 'production_quantities.line_id', '=', 'lines.id')
->selectRaw("$groupBy AS time_unit, count(*) AS total_quantity") ->selectRaw("$groupBy AS time_unit, count(*) AS total_quantity")
->whereBetween('production_quantities.created_at', [$startDate, $endDate]) ->whereBetween('production_quantities.created_at', [$startDate, $endDate])
@@ -205,4 +174,6 @@ class ItemOverview extends ChartWidget
]; ];
} }
} }

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Imports;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
class ExcelImport implements ToCollection
{
public $rows = [];
/**
* @param Collection $collection
*/
public function collection(Collection $collection)
{
foreach($collection as $item) {
self::$rows[] = $item->toArray();
}
}
public function getRows()
{
return self::$rows;
}
}

View File

@@ -2,57 +2,334 @@
namespace App\Livewire; namespace App\Livewire;
use App\Filament\Resources\InvoiceValidationResource\Pages\CreateInvoiceValidation;
use App\Models\InvoiceValidation; use App\Models\InvoiceValidation;
use App\Models\StickerMaster;
use Filament\Notifications\Notification;
use Livewire\Component; use Livewire\Component;
class InvoiceDataTable extends Component class InvoiceDataTable extends Component
{ {
public $invoiceData = []; public $invoiceData = [];
public $plantId = 0;
public string $invoiceNumber = ''; public string $invoiceNumber = '';
public bool $completedInvoice = false;
public bool $emptyInvoice = false;
public bool $hasSearched = false; public bool $hasSearched = false;
protected $listeners = ['refreshInvoiceData' => 'loadData',]; public bool $materialInvoice = false;
public bool $showCapacitorInput = false;
public function loadData($invoiceNumber) // protected $listeners = ['refreshInvoiceData' => 'loadData',];
protected $listeners = [
'refreshCompletedInvoice' => 'loadCompletedData',
'refreshEmptyInvoice' => 'loadEmptyData',
'refreshInvoiceData' => 'loadData',
'refreshMaterialInvoiceData' => 'loadMaterialData',
'openCapacitorModal' => 'showCapacitorInputBox',
];
public $capacitorInput = '';
public $panel_box_supplier;
public $panel_box_item_code;
public $panel_box_serial_number;
public string $currentItemCode = '';
public string $currentSerialNumber = '';
public function loadCompletedData($invoiceNumber, $plantId)
{ {
$this->plantId = $plantId;
$this->invoiceNumber = $invoiceNumber;
$this->completedInvoice = true;
$this->emptyInvoice = false;
$this->hasSearched = false;
$this->materialInvoice = false;
// $this->showCapacitorInput = false;
}
public function loadEmptyData($invoiceNumber, $plantId)
{
$this->plantId = $plantId;
$this->invoiceNumber = $invoiceNumber;
$this->emptyInvoice = true;
$this->completedInvoice = false;
$this->hasSearched = false;
$this->materialInvoice = false;
// $this->showCapacitorInput = false;
}
public function loadData($invoiceNumber, $plantId)
{
$this->plantId = $plantId;
$this->invoiceNumber = $invoiceNumber; $this->invoiceNumber = $invoiceNumber;
$this->hasSearched = true; $this->hasSearched = true;
$this->emptyInvoice = false;
$this->completedInvoice = false;
$this->materialInvoice = false;
// $this->showCapacitorInput = false;
//->where('serial_number', '!=', '')
$this->invoiceData = InvoiceValidation::where('invoice_number', $this->invoiceNumber) $this->invoiceData = InvoiceValidation::where('invoice_number', $this->invoiceNumber)
->where('plant_id', $plantId)->where('scanned_status', null)
->get() ->get()
->map(function ($record) { ->map(function ($record) {
return [ return [
'sticker_master_id' => $record->sticker_master_id, 'sticker_master_id' => $record->sticker_master_id,
'serial_number' => $record->serial_number, 'serial_number' => $record->serial_number,
'motor_scanned_status' => $record->motor_scanned_status, 'motor_scanned_status' => $record->motor_scanned_status ?? '',
'pump_scanned_status' => $record->pump_scanned_status, 'pump_scanned_status' => $record->pump_scanned_status ?? '',
'capacitor_scanned_status' => $record->capacitor_scanned_status, 'capacitor_scanned_status' => $record->capacitor_scanned_status ?? '',
'scanned_status_set' => $record->scanned_status_set, 'scanned_status_set' => $record->scanned_status_set ?? '',
'panel_box_supplier' => $record->panel_box_supplier, 'scanned_status' => $record->scanned_status ?? '',
'panel_box_serial_number' => $record->panel_box_serial_number, 'panel_box_supplier' => $record->panel_box_supplier ?? '',
'scanned_status' => $record->scanned_status, 'panel_box_serial_number' => $record->panel_box_serial_number ?? '',
'created_at' => $record->created_at, 'created_at' => $record->created_at,
'operator_id' => $record->operator_id, 'operator_id' => $record->operator_id,
]; ];
}) })
->toArray(); ->toArray();
//Loop through and replace 'code' using related StickerMaster > Item > code //Loop through and replace 'code' using related StickerMaster > Item > code
foreach ($this->invoiceData as &$row) { foreach ($this->invoiceData as &$row) {
$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::with('item')->find($row['sticker_master_id'] ?? null)?->item?->code ?? 'N/A';
}
}
public function loadMaterialData($invoiceNumber, $plantId)
{
$this->plantId = $plantId;
$this->invoiceNumber = $invoiceNumber;
$this->materialInvoice = true;
$this->emptyInvoice = false;
$this->completedInvoice = false;
$this->hasSearched = false;
// $this->showCapacitorInput = false;
//->where('serial_number', '!=', '')
$this->invoiceData = InvoiceValidation::where('invoice_number', $this->invoiceNumber)->where('plant_id', $plantId)->where('serial_number', null)
->get()
->map(function ($record) {
return [
'sticker_master_id' => $record->sticker_master_id,
// 'material_type' => StickerMaster::where('id', $record->sticker_master_id)->first()->material_type ?? '',
'quantity' => $record->quantity ?? '',
'serial_number' => $record->serial_number ?? '',
'batch_number' => $record->batch_number ?? '',
'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::with('item')->find($row['sticker_master_id'] ?? null)?->item?->code ?? 'N/A';
$matType = StickerMaster::where('id', $row['sticker_master_id'] ?? null)->first()->material_type ?? '';
if($matType === 1)
{
$row['material_type'] = 'Individual';
}
else if($matType === 2)
{
$row['material_type'] = 'Bundle';
}
else
{
$row['material_type'] = 'N/A';
}
}
}
// public function showCapacitorInputBox()
// {
// $this->showCapacitorInput = true;
// }
public function showCapacitorInputBox($itemCode, $serialNumber, $plantId)
{
$this->plantId = $plantId;
$this->currentItemCode = $itemCode;
$this->currentSerialNumber = $serialNumber;
$this->showCapacitorInput = true;
// $this->capacitorInput = '';
$this->emptyInvoice = false;
$this->completedInvoice = false;
$this->hasSearched = false;
$this->materialInvoice = false;
}
public function cancelCapacitorInput()
{
$this->showCapacitorInput = false;
}
public function processCapacitorInput()
{
if (!$this->capacitorInput) {
return;
} }
if (!preg_match('/^[^\/]+\/[^\/]+\/.+$/', $this->capacitorInput)) {
Notification::make()
->title('Invalid Panel Box QR Format:')
->body('Scan the valid panel box QR code to proceed!')
->danger()
->duration(3000)
->send();
return;
}
$parts = explode('/', $this->capacitorInput);
$supplier = $parts[0];
$itemCode = $parts[1];
$serialNumber = implode('/', array_slice($parts, 2)); // Keep rest of the string
$existsInStickerMaster = StickerMaster::where('panel_box_code', $itemCode)->where('plant_id', $this->plantId)->whereHas('item', function ($query) {
$query->where('code', $this->currentItemCode);
})
->exists();
if (!$existsInStickerMaster) {
Notification::make()
->title('Unknown: Panel Box Code')
->body("Unknown panel box code: $itemCode found for item code: $this->currentItemCode")
->danger()
->duration(4000)
->send();
$this->capacitorInput = '';
return;
}
foreach ($this->invoiceData as &$row) {
if (
($row['code'] ?? '') === $this->currentItemCode &&
($row['serial_number'] ?? '') === $this->currentSerialNumber
) {
$row['panel_box_supplier'] = $supplier;
$row['panel_box_item_code'] = $itemCode;
$row['panel_box_serial_number'] = $serialNumber;
$row['capacitor_scanned_status'] = 1;
// $row['scanned_status_set'] = true;
$matchingValidation = InvoiceValidation::with('stickerMaster.item')
->where('serial_number', $this->currentSerialNumber)
->where('plant_id', $this->plantId)
->get()
->first(function ($validation) {
return $validation->stickerMaster?->item?->code === $this->currentItemCode;
});
if ($matchingValidation) {
$hasMotorQr = $matchingValidation->stickerMasterRelation->tube_sticker_motor ?? null;
$hasPumpQr = $matchingValidation->stickerMasterRelation->tube_sticker_pump ?? null;
$hasPumpSetQr = $matchingValidation->stickerMasterRelation->tube_sticker_pumpset ?? null;
// $hasCapacitorQr = $matchingValidation->stickerMasterRelation->panel_box_code ?? null;
$hadMotorQr = $matchingValidation->motor_scanned_status ?? null;
$hadPumpQr = $matchingValidation->pump_scanned_status ?? null;
$hadPumpSetQr = $matchingValidation->scanned_status_set ?? null;
// $hadCapacitorQr = $matchingValidation->capacitor_scanned_status ?? null;
$packCnt = 1;
$scanCnt = 1;
// if($hadMotorQr === $hasMotorQr && $hadPumpQr === $hasPumpQr && $hadPumpSetQr === $hasPumpSetQr)
if($hasMotorQr || $hasPumpQr || $hasPumpSetQr)
{
$packCnt = $hasMotorQr ? $packCnt + 1 : $packCnt;
$packCnt = $hasPumpQr ? $packCnt + 1 : $packCnt;
$packCnt = $hasPumpSetQr ? $packCnt + 1 : $packCnt;
$scanCnt = $hadMotorQr ? $scanCnt + 1: $scanCnt;
$scanCnt = $hadPumpQr ? $scanCnt + 1: $scanCnt;
$scanCnt = $hadPumpSetQr ? $scanCnt + 1: $scanCnt;
if($packCnt === $scanCnt)
{
$matchingValidation->update([
'panel_box_supplier' => $supplier,
'panel_box_item_code' => $itemCode,
'panel_box_serial_number' => $serialNumber,
'capacitor_scanned_status' => 1,
'scanned_status' => 'Scanned',
]);
}
else
{
$matchingValidation->update([
'panel_box_supplier' => $supplier,
'panel_box_item_code' => $itemCode,
'panel_box_serial_number' => $serialNumber,
'capacitor_scanned_status' => 1,
]);
}
}
else
{
$matchingValidation->update([
'panel_box_supplier' => $supplier,
'panel_box_item_code' => $itemCode,
'panel_box_serial_number' => $serialNumber,
'capacitor_scanned_status' => 1,
'scanned_status' => 'Scanned',
]);
}
Notification::make()
->title('Success: Capacitor QR')
// ->title("Panel box code scanned: $itemCode")
->body("'Capacitor' QR scanned status updated, Scan next QR.")
->success()
->duration(3000)
->send();
$totalQuantity = InvoiceValidation::where('invoice_number', $matchingValidation->invoice_number)->where('plant_id', $this->plantId)->count();
$scannedQuantity = InvoiceValidation::where('invoice_number', $matchingValidation->invoice_number)->where('plant_id', $this->plantId)->where('scanned_status', 'Scanned')->count();
// $this->form->fill([
// 'plant_id' => $matchingValidation->plant_id,
// 'invoice_number' => $matchingValidation->invoice_number,
// 'serial_number' => null,
// 'total_quantity' => $totalQuantity,
// 'scanned_quantity'=> $scannedQuantity,
// ]);
if($totalQuantity === $scannedQuantity)
{
Notification::make()
->title('Completed: Serial Invoice')
->body("Serial invoice '$matchingValidation->invoice_number' completed the scanning process.<br>Scan the next 'Serial Invoice' to proceed!")
->success()
->send();
$this->loadCompletedData($matchingValidation->invoice_number, $matchingValidation->plant_id);
}
else
{
$this->loadData($matchingValidation->invoice_number, $matchingValidation->plant_id);
}
}
break;
}
}
$this->showCapacitorInput = false;
$this->capacitorInput = '';
} }
public function render() public function render()
{ {
return view('livewire.invoice-data-table'); return view('livewire.invoice-data-table');
} }
} }

View File

@@ -38,6 +38,7 @@ class InvoiceValidation extends Model
{ {
return $this->belongsTo(StickerMaster::class); return $this->belongsTo(StickerMaster::class);
} }
public function stickerMasterRelation() public function stickerMasterRelation()
{ {
return $this->belongsTo(StickerMaster::class, 'sticker_master_id'); return $this->belongsTo(StickerMaster::class, 'sticker_master_id');

View File

@@ -1,17 +1,4 @@
{{-- <x-filament::page>
<form wire:submit.prevent="create">
{{ $this->form }}
<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> <x-filament::page>
<form wire:submit.prevent="create" class="space-y-6"> <form wire:submit.prevent="create" class="space-y-6">
{{-- Form Section --}} {{-- Form Section --}}

View File

@@ -1,123 +1,3 @@
{{-- <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>
<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 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>
<div class="mb-4"> <div class="mb-4">
@@ -127,9 +7,23 @@
</div> </div>
</div> </div>
@if($hasSearched) {{-- Modal for completed invoice--}}
@if ($completedInvoice)
<div class="text-center text-red-500">
<p>Completed the scanning process for invoice number <strong>{{ $invoiceNumber }}</strong>.</p>
</div>
@endif
<div class="overflow-x-auto overflow-y-visible"> {{-- Modal for empty invoice--}}
@if ($emptyInvoice)
<div class="text-center text-red-500">
<p>No data found for invoice number <strong>{{ $invoiceNumber }}</strong>.</p>
</div>
@endif
{{-- Modal for serial invoice--}}
@if ($hasSearched)
<div class="overflow-x-auto overflow-y-visible" style="height: 385px;">
{{-- <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="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"> <table class="min-w-full text-sm text-center border border-gray-300">
@@ -155,15 +49,95 @@
<td class="border px-4 py-2">{{ $index + 1 }}</td> <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['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['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['motor_scanned_status'] ?? '' }}</td>
<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'] ?? '' }}</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'] ?? '' }}</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'] ?? '' }}</td>
<td class="border px-4 py-2">{{ $row['scanned_status'] ?? 'N/A' }}</td> <td class="border px-4 py-2">{{ $row['scanned_status'] ?? '' }}</td>
<td class="border px-4 py-2">{{ $row['created_at'] ?? '' }}</td>
<td class="border px-4 py-2">{{ $row['operator_id'] ?? '' }}</td>
<td class="border px-4 py-2">{{ $row['panel_box_supplier'] ?? '' }}</td>
<td class="border px-4 py-2">{{ $row['panel_box_serial_number'] ?? '' }}</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
{{-- Modal for Capacitor Input --}}
<div>
<button wire:click="$set('showCapacitorInput', true)"></button>
@if($showCapacitorInput)
<div class="fixed inset-0 z-[9999] bg-black bg-opacity-50 flex items-center justify-center">
<div style="background:white; border:4px solid orange;" class="p-6 rounded-xl shadow-2xl w-[450px]">
<h3 class="text-xl font-semibold text-orange-700 mb-4">
Scan the Panel Box Supplier/Item Code/Serial Number
</h3>
<input
type="text"
id="capacitorInput"
autocomplete="off"
wire:model.defer="capacitorInput"
wire:keydown.enter.prevent="processCapacitorInput"
class="w-full border border-orange-300 rounded px-3 py-2 focus:outline-none focus:ring-0 focus:border-orange-300"
placeholder="Scan the panel box QR code"
{{-- autofocus --}}
onload="this.focus(); this.select();"
{{-- onfocus="this.select();" --}}
/>
<div class="flex justify-end gap-2 mt-4">
<button type="button" wire:click="cancelCapacitorInput"
class="mt-6 ml-10 bg-gray-300 hover:bg-gray-400 px-4 py-2 rounded transition">
Cancel
</button>
</div>
</div>
</div>
{{-- Add this script to focus on the input --}}
<script>
document.getElementById('capacitorInput').focus();
</script>
@endif
</div>
{{-- Modal for material invoice--}}
@if($materialInvoice)
<div class="overflow-x-auto overflow-y-visible" style="height: 385px;">
{{-- <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">Material Type</th>
<th class="border px-4 py-2">Material Quantity</th>
<th class="border px-4 py-2">Serial Number</th>
<th class="border px-4 py-2">Batch Number</th>
<th class="border px-4 py-2">TimeStamp</th>
<th class="border px-4 py-2">Operator ID</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['material_type'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['quantity'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['serial_number'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['batch_number'] ?? 'N/A' }}</td>
<td class="border px-4 py-2">{{ $row['created_at'] ?? '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['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> </tr>
@empty @empty
<tr> <tr>
@@ -177,6 +151,11 @@
</div> </div>
@endif @endif
</div> </div>
{{-- <script>
// Clear input and set focus on form load
document.addEventListener('DOMContentLoaded', function () {
const input = document.getElementById('capacitorInput');
input.value = ''; // Clear the input field
input.focus(); // Set focus to the input field
});
</script> --}}