Added invoice finder pages and livewire pages
This commit is contained in:
215
app/Filament/Pages/InvoiceFinder.php
Normal file
215
app/Filament/Pages/InvoiceFinder.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\LocatorInvoiceValidation;
|
||||
use App\Models\PalletValidation;
|
||||
use App\Models\Plant;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
class InvoiceFinder extends Page implements HasForms
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static string $view = 'filament.pages.invoice-finder';
|
||||
|
||||
protected static ?string $navigationGroup = 'Export Dispatch';
|
||||
|
||||
//use InteractsWithForms;
|
||||
|
||||
public $pId, $invoiceNumber;
|
||||
|
||||
public array $invoiceOverviewData = [];
|
||||
|
||||
public array $filters = [];
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->statePath('filters')
|
||||
->schema([
|
||||
Section::make('') // You can give your section a title or leave it blank
|
||||
->schema([
|
||||
Select::make('plant_id')
|
||||
->options(Plant::pluck('name', 'id'))
|
||||
->label('Plant')
|
||||
->reactive()
|
||||
->required(),
|
||||
TextInput::make('scan_invoice')
|
||||
->label('Scan Invoice')
|
||||
->required()
|
||||
->reactive()
|
||||
->extraAttributes([
|
||||
'wire:keydown.enter' => 'processInvoiceNo($event.target.value)',
|
||||
]),
|
||||
TextInput::make('scan_quantity')
|
||||
->label('Scanned Quantity ')
|
||||
->readOnly()
|
||||
->reactive(),
|
||||
TextInput::make('pending_quantity')
|
||||
->label('Pending Quantity')
|
||||
->readOnly()
|
||||
->reactive(),
|
||||
TextInput::make('total_sno_quantity')
|
||||
->label('Total SNo. Quantity')
|
||||
->readOnly()
|
||||
->reactive(),
|
||||
|
||||
])
|
||||
->columns(5)
|
||||
]);
|
||||
}
|
||||
|
||||
public function processInvoiceNo($invoiceNo)
|
||||
{
|
||||
$plantId = $this->form->getState()['plant_id'];
|
||||
|
||||
if(!$invoiceNo)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Invoice number '$invoiceNo' can't be empty!")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', '', [], [], [], [], $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'scan_invoice' => $invoiceNo,
|
||||
'total_sno_quantity' => 0,
|
||||
'pending_quantity' => 0,
|
||||
'scan_quantity' => 0
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$invoiceExists = LocatorInvoiceValidation::where('plant_id', $plantId)
|
||||
->where('invoice_number', $invoiceNo)
|
||||
->first();
|
||||
|
||||
if(!$invoiceExists)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Invoice number '$invoiceNo' does not exist in locator invoice table!")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', '', [], [], [], [], $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'scan_invoice' => $invoiceNo,
|
||||
'total_sno_quantity' => 0,
|
||||
'pending_quantity' => 0,
|
||||
'scan_quantity' => 0
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$invoiceCompleted = LocatorInvoiceValidation::where('plant_id', $plantId)
|
||||
->where('invoice_number', $invoiceNo)
|
||||
->whereNull('scanned_status')
|
||||
->orWhere('scanned_status', '=','')
|
||||
->first();
|
||||
|
||||
if(!$invoiceCompleted)
|
||||
{
|
||||
$count = LocatorInvoiceValidation::where('invoice_number', $invoiceNo)
|
||||
->where('plant_id', $plantId)
|
||||
->count();
|
||||
Notification::make()
|
||||
->title("Invoice number '$invoiceNo' already completed the scanning process...")
|
||||
->success()
|
||||
->send();
|
||||
$this->dispatch('loadData', '', [], [], [], [], $plantId);
|
||||
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'scan_invoice' => $invoiceNo,
|
||||
'total_sno_quantity' => $count,
|
||||
'pending_quantity' => 0,
|
||||
'scan_quantity' => $count
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$serialNumbers = LocatorInvoiceValidation::where('plant_id', $plantId)
|
||||
->where('invoice_number', $invoiceNo)
|
||||
->pluck('serial_number');
|
||||
|
||||
$notFoundSerials = [];
|
||||
$incompleteSerials = [];
|
||||
$scannedSerials = [];
|
||||
$foundSerials = [];
|
||||
|
||||
foreach ($serialNumbers as $serial)
|
||||
{
|
||||
$locatorRecord = LocatorInvoiceValidation::where('serial_number', $serial)
|
||||
->where('plant_id', $plantId)
|
||||
->first();
|
||||
|
||||
//$scannedStatus = $locatorRecord->scanned_status ?? null;
|
||||
|
||||
if ($locatorRecord->scanned_status == 'Scanned')
|
||||
{
|
||||
$scannedSerials[] = $serial;
|
||||
continue;
|
||||
}
|
||||
|
||||
$palletRecord = palletValidation::where('serial_number', $serial)
|
||||
->where('plant_id', $plantId)
|
||||
->first();
|
||||
|
||||
if (!$palletRecord)
|
||||
{
|
||||
$notFoundSerials[] = $serial;
|
||||
continue;
|
||||
}
|
||||
|
||||
$palletStatus = $palletRecord->pallet_status ?? null;
|
||||
|
||||
if (strlen($palletRecord->pallet_number) > 1 && ($palletStatus == '' || $palletStatus == null))
|
||||
{
|
||||
$incompleteSerials[] = $serial;
|
||||
continue;
|
||||
}
|
||||
|
||||
$foundSerials[] = $serial;
|
||||
}
|
||||
|
||||
$count = LocatorInvoiceValidation::where('invoice_number', $invoiceNo)
|
||||
->where('plant_id', $plantId)
|
||||
->count();
|
||||
|
||||
$pendingCount = LocatorInvoiceValidation::where('invoice_number', $invoiceNo)
|
||||
->where('plant_id', $plantId)
|
||||
->whereNull('scanned_status')
|
||||
->orWhere('scanned_status', '=', '')
|
||||
->count();
|
||||
|
||||
$scannedCount = LocatorInvoiceValidation::where('invoice_number', $invoiceNo)
|
||||
->where('plant_id', $plantId)
|
||||
->where('scanned_status', '=', 'Scanned')
|
||||
->count();
|
||||
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'scan_invoice' => $invoiceNo,
|
||||
'total_sno_quantity' => $count,
|
||||
'pending_quantity' => $pendingCount,
|
||||
'scan_quantity' => $scannedCount,
|
||||
]);
|
||||
|
||||
$this->dispatch('loadData', $invoiceNo, $notFoundSerials, $incompleteSerials, $scannedSerials, $foundSerials, $plantId);
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return Auth::check() && Auth::user()->can('view invoice finder page');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user