Added panel box pallet count page and livewire pages #1575
68
app/Filament/Pages/PanelBoxPalletCount.php
Normal file
68
app/Filament/Pages/PanelBoxPalletCount.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
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\Facades\Filament;
|
||||
use App\Models\Plant;
|
||||
|
||||
class PanelBoxPalletCount extends Page
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static string $view = 'filament.pages.panel-box-pallet-count';
|
||||
|
||||
protected static ?string $navigationGroup = 'Panel Box Pallet';
|
||||
|
||||
public array $filters = [];
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->statePath('filters')
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
|
||||
Select::make('plant_id')
|
||||
->label('Plant')
|
||||
->relationship('plant', 'name')
|
||||
->reactive()
|
||||
// ->searchable()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, callable $get, $set) {
|
||||
$set('pallet_count', null);
|
||||
}),
|
||||
Select::make('pallet_count')
|
||||
->label('Select Pallet')
|
||||
->required()
|
||||
->columnSpan(1)
|
||||
->options(function (callable $get) {
|
||||
|
||||
if (!$get('plant_id')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return \App\Models\PanelPalletValidation::where('plant_id', $get('plant_id'))
|
||||
->pluck('pallet_number', 'pallet_number')
|
||||
->toArray();
|
||||
})
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $get, $set) {
|
||||
$plantId = $get('plant_id');
|
||||
$this->dispatch('loadData',$state, $plantId);
|
||||
}),
|
||||
|
||||
])
|
||||
->columns(2)
|
||||
]);
|
||||
}
|
||||
}
|
||||
53
app/Livewire/PanelPalletCountDataTable.php
Normal file
53
app/Livewire/PanelPalletCountDataTable.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\PanelPalletValidation;
|
||||
use Livewire\Component;
|
||||
|
||||
class PanelPalletCountDataTable extends Component
|
||||
{
|
||||
|
||||
public $plantId;
|
||||
|
||||
public $palletNumber;
|
||||
|
||||
public $snoCount = 0;
|
||||
|
||||
public $records = [];
|
||||
|
||||
protected $listeners = [
|
||||
//'removeSno' => 'requestRemoveSerialNumber',
|
||||
'loadData' => 'loadPalletData',
|
||||
];
|
||||
|
||||
|
||||
public function loadPalletData($palletNumber, $plantId)
|
||||
{
|
||||
$this->plantId = $plantId;
|
||||
$this->palletNumber = $palletNumber;
|
||||
$this->records = [];
|
||||
|
||||
$this->records = PanelPalletValidation::query()
|
||||
->where('plant_id', $plantId)
|
||||
->where('pallet_number', $palletNumber)
|
||||
->get()
|
||||
->groupBy(fn ($record) => trim($record->panel_box_code ?? ''))
|
||||
->map(function ($items, $code) {
|
||||
return [
|
||||
'panel_box_code' => $code,
|
||||
'count' => $items->pluck('panel_box_serial_number')
|
||||
->filter()
|
||||
->unique()
|
||||
->count(),
|
||||
];
|
||||
})
|
||||
->values()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.panel-pallet-count-data-table');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<x-filament-panels::page>
|
||||
|
||||
<div class="space-y-4">
|
||||
{{-- Render the Select form fields --}}
|
||||
<div class="space-y-4">
|
||||
{{ $this->form }}
|
||||
</div>
|
||||
|
||||
<div class="bg-white shadow rounded-xl p-4 mt-6">
|
||||
<livewire:panel-pallet-count-data-table />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</x-filament-panels::page>
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<div class="p-4">
|
||||
<h2 class="text-lg font-bold mb-4 text-gray-700 uppercase tracking-wider">
|
||||
PALLET COUNT DATA TABLE:
|
||||
</h2>
|
||||
|
||||
<div class="overflow-x-auto rounded-lg shadow">
|
||||
<table class="w-full divide-y divide-gray-200 text-sm text-center">
|
||||
<thead class="bg-gray-100 font-semibold uppercase text-gray-700">
|
||||
<tr>
|
||||
<th class="border px-4 py-2">No</th>
|
||||
<th class="border px-4 py-2">Panel Box Code</th>
|
||||
<th class="border px-4 py-2">Count</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@forelse ($records as $index => $record)
|
||||
<tr class="hover:bg-gray-50">
|
||||
<td class="border px-4 py-2">{{ $index + 1 }}</td>
|
||||
<td class="border px-4 py-2">
|
||||
{{ $record['panel_box_code'] }}
|
||||
</td>
|
||||
<td class="border px-4 py-2 font-semibold">
|
||||
{{ $record['count'] }}
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="3" class="px-4 py-4 text-center text-gray-500">
|
||||
No pallet records found.
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user