added migration, model, resource , grid table
This commit is contained in:
155
app/Filament/Resources/InvoiceValidationResource.php
Normal file
155
app/Filament/Resources/InvoiceValidationResource.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\InvoiceValidationResource\Pages;
|
||||
use App\Models\InvoiceValidation;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\View;
|
||||
|
||||
|
||||
|
||||
class InvoiceValidationResource extends Resource
|
||||
{
|
||||
protected static ?string $model = InvoiceValidation::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Invoice';
|
||||
|
||||
public $enter_pressed = false;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Hidden::make('sticker_master_id')
|
||||
//->relationship('stickerMaster', 'id')
|
||||
->required(),
|
||||
|
||||
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(),
|
||||
|
||||
Forms\Components\TextInput::make('invoice_number')
|
||||
->required()
|
||||
->label('Invoice Number')
|
||||
->columnSpan(1)
|
||||
->extraAttributes([
|
||||
'x-data' => '{ value: "" }',
|
||||
'x-model' => 'value',
|
||||
'x-on:keydown.enter.prevent' => '$wire.processInvoice(value)',
|
||||
]),
|
||||
|
||||
Forms\Components\TextInput::make('serial_number')
|
||||
//->required()
|
||||
->reactive()
|
||||
->columnSpan(1),
|
||||
|
||||
Forms\Components\TextInput::make('total_quantity')
|
||||
->label('Total Quantity')
|
||||
->columnSpan(1),
|
||||
Forms\Components\TextInput::make('scanned_quantity')
|
||||
->label('Scanned Quantity')
|
||||
->columnSpan(1),
|
||||
|
||||
])
|
||||
->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
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('stickerMaster.id')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
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(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListInvoiceValidations::route('/'),
|
||||
'create' => Pages\CreateInvoiceValidation::route('/create'),
|
||||
'view' => Pages\ViewInvoiceValidation::route('/{record}'),
|
||||
'edit' => Pages\EditInvoiceValidation::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\InvoiceValidationResource\Pages;
|
||||
|
||||
use App\Filament\Resources\InvoiceValidationResource;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
|
||||
class CreateInvoiceValidation extends CreateRecord
|
||||
{
|
||||
protected static string $resource = InvoiceValidationResource::class;
|
||||
|
||||
protected static string $view = 'filament.resources.invoice-validation-resource.pages.create-invoice-validation';
|
||||
|
||||
public $invoice_number;
|
||||
|
||||
public $invoice_data;
|
||||
|
||||
public $scanned_quantity;
|
||||
|
||||
public $total_quantity;
|
||||
|
||||
|
||||
public $excel_file;
|
||||
|
||||
public function processInvoice($invoiceNumber)
|
||||
{
|
||||
|
||||
$this->invoice_number = $invoiceNumber;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
$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);
|
||||
|
||||
Notification::make()
|
||||
->title('Success')
|
||||
->body(count($validRecords) . ' records inserted successfully')
|
||||
->success()
|
||||
->send();
|
||||
} catch (\Exception $e) {
|
||||
Notification::make()
|
||||
->title('Error')
|
||||
->body($e->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
|
||||
public function getHeading(): string
|
||||
{
|
||||
return 'Scan Invoice Validation';
|
||||
}
|
||||
|
||||
// public function render(): View
|
||||
// {
|
||||
// return view('filament.resources.invoice-validation-resource.pages.create-invoice-validation');
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\InvoiceValidationResource\Pages;
|
||||
|
||||
use App\Filament\Resources\InvoiceValidationResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditInvoiceValidation extends EditRecord
|
||||
{
|
||||
protected static string $resource = InvoiceValidationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\ForceDeleteAction::make(),
|
||||
Actions\RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\InvoiceValidationResource\Pages;
|
||||
|
||||
use App\Filament\Resources\InvoiceValidationResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListInvoiceValidations extends ListRecords
|
||||
{
|
||||
protected static string $resource = InvoiceValidationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\InvoiceValidationResource\Pages;
|
||||
|
||||
use App\Filament\Resources\InvoiceValidationResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewInvoiceValidation extends ViewRecord
|
||||
{
|
||||
protected static string $resource = InvoiceValidationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
40
app/Livewire/InvoiceDataTable.php
Normal file
40
app/Livewire/InvoiceDataTable.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\InvoiceValidation;
|
||||
use Livewire\Component;
|
||||
|
||||
class InvoiceDataTable extends Component
|
||||
{
|
||||
|
||||
public $invoiceData = [];
|
||||
|
||||
protected $listeners = ['refreshInvoiceData' => 'loadData'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadData();
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
// ]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
42
app/Models/InvoiceValidation.php
Normal file
42
app/Models/InvoiceValidation.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class InvoiceValidation extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'sticker_master_id',
|
||||
'plant_id',
|
||||
'invoice_number',
|
||||
'serial_number',
|
||||
'motor_scanned_status',
|
||||
'pump_scanned_status',
|
||||
'capacitor_scanned_status',
|
||||
'scanned_status_set',
|
||||
'scanned_status',
|
||||
'panel_box_supplier',
|
||||
'panel_box_serial_number',
|
||||
'load_rate',
|
||||
'upload_status',
|
||||
'batch_number',
|
||||
'quantity',
|
||||
];
|
||||
|
||||
public function plant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Plant::class);
|
||||
}
|
||||
|
||||
public function stickerMaster(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(StickerMaster::class);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?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'
|
||||
CREATE TABLE invoice_validations (
|
||||
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
|
||||
|
||||
sticker_master_id BIGINT NOT NULL,
|
||||
plant_id BIGINT NOT NULL,
|
||||
|
||||
invoice_number TEXT NOT NULL,
|
||||
serial_number TEXT UNIQUE,
|
||||
|
||||
motor_scanned_status TEXT DEFAULT NULL,
|
||||
pump_scanned_status TEXT DEFAULT NULL,
|
||||
capacitor_scanned_status TEXT DEFAULT NULL,
|
||||
scanned_status_set TEXT DEFAULT NULL,
|
||||
scanned_status TEXT DEFAULT NULL,
|
||||
|
||||
panel_box_supplier TEXT DEFAULT NULL,
|
||||
panel_box_serial_number TEXT DEFAULT NULL,
|
||||
|
||||
load_rate INT NOT NULL DEFAULT (0),
|
||||
upload_status TEXT NOT NULL DEFAULT 'N',
|
||||
|
||||
|
||||
batch_number TEXT DEFAULT NULL,
|
||||
quantity INT DEFAULT NULL,
|
||||
|
||||
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
deleted_at TIMESTAMP,
|
||||
|
||||
FOREIGN KEY (sticker_master_id) REFERENCES sticker_masters (id),
|
||||
FOREIGN KEY (plant_id) REFERENCES plants (id)
|
||||
);
|
||||
SQL;
|
||||
|
||||
DB::statement($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('invoice_validations');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
<x-filament::page>
|
||||
{{ $this->form }}
|
||||
|
||||
{{-- @livewire('invoice-data-table') --}}
|
||||
<livewire:invoice-data-table :invoice-data="$invoice_data" />
|
||||
|
||||
</x-filament::page>
|
||||
45
resources/views/livewire/invoice-data-table.blade.php
Normal file
45
resources/views/livewire/invoice-data-table.blade.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<div wire:poll.5s>
|
||||
<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>
|
||||
|
||||
<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
|
||||
<tr>
|
||||
<td colspan="10" class="text-center py-4 text-gray-500">No data available.</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
Reference in New Issue
Block a user