Added production non planned report page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
This commit is contained in:
194
app/Filament/Pages/ProductionNonPlannedReport.php
Normal file
194
app/Filament/Pages/ProductionNonPlannedReport.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Item;
|
||||
use App\Models\ProductionPlan;
|
||||
use App\Models\QualityValidation;
|
||||
use App\Models\StickerMaster;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Filament\Forms\Form;
|
||||
use App\Models\Plant;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
|
||||
class ProductionNonPlannedReport extends Page implements HasForms
|
||||
{
|
||||
use InteractsWithForms;
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static string $view = 'filament.pages.production-non-planned-report';
|
||||
|
||||
protected static ?string $navigationGroup = 'Production';
|
||||
|
||||
public array $filters = [];
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->form->fill([
|
||||
'date' => null,
|
||||
'plant_id' => null,
|
||||
'line_id' => null,
|
||||
'category' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->statePath('filters')
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
|
||||
DateTimePicker::make('date')
|
||||
->label('Choose Date')
|
||||
->native(false)
|
||||
->displayFormat('d-m-Y')
|
||||
->reactive(),
|
||||
|
||||
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) {
|
||||
// dd($state);
|
||||
$set('line_id', null);
|
||||
$set('category', null);
|
||||
$this->dispatch('loadData',$state, '', '', '', '');
|
||||
}),
|
||||
Select::make('line_id')
|
||||
->label('Line')
|
||||
->required()
|
||||
// ->relationship('line', 'name')
|
||||
// ->searchable()
|
||||
->columnSpan(1)
|
||||
->options(function (callable $get) {
|
||||
if (!$get('plant_id')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return \App\Models\Line::where('plant_id', $get('plant_id'))
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $get, $set) {
|
||||
$plantId = $get('plant_id');
|
||||
$lineId = $state;
|
||||
$month = $get('month');
|
||||
$year = $get('year');
|
||||
$date = $get('date');
|
||||
|
||||
$month = (int) $get('month');
|
||||
$this->dispatch('loadData',$year, $month, $plantId, $lineId, $date);
|
||||
}),
|
||||
|
||||
// Select::make('item_id')
|
||||
// ->label('Item Code')
|
||||
// ->placeholder('Select Item Code')
|
||||
// ->options(function (callable $get) {
|
||||
// $plantId = $get('plant_id');
|
||||
// $lineId = $get('line_id');
|
||||
// $date = $get('date');
|
||||
|
||||
// if (!$plantId || !$lineId || !$date) {
|
||||
// return [];
|
||||
// }
|
||||
|
||||
// $selectedDate = Carbon::parse($date)->startOfDay();
|
||||
// $startDate = $selectedDate->copy()->setTime(8, 0, 0);
|
||||
// $endDate = $startDate->copy()->addDay();
|
||||
|
||||
// $month = $selectedDate->month;
|
||||
// $year = $selectedDate->year;
|
||||
|
||||
// $plannedItemIds = ProductionPlan::query()
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->where('line_id', $lineId)
|
||||
// ->whereMonth('production_plans.created_at', $month)
|
||||
// ->whereYear('production_plans.created_at', $year)
|
||||
// ->whereNotNull('item_id')
|
||||
// ->distinct()
|
||||
// ->pluck('item_id');
|
||||
|
||||
// $stickerMasterIds = QualityValidation::query()
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->where('line_id', $lineId)
|
||||
// ->where('created_at', '>=', $startDate)
|
||||
// ->where('created_at', '<', $endDate)
|
||||
// ->whereNotNull('sticker_master_id')
|
||||
// ->distinct()
|
||||
// ->pluck('sticker_master_id');
|
||||
|
||||
// $producedItemIds = StickerMaster::query()
|
||||
// ->whereIn('id', $stickerMasterIds)
|
||||
// ->whereNotNull('item_id')
|
||||
// ->distinct()
|
||||
// ->pluck('item_id');
|
||||
|
||||
// return Item::query()
|
||||
// ->whereIn('id', $producedItemIds)
|
||||
// ->whereNotIn('id', $plannedItemIds)
|
||||
// ->orderBy('code')
|
||||
// ->pluck('code', 'id')
|
||||
// ->toArray();
|
||||
// })
|
||||
// ->searchable()
|
||||
// ->reactive()
|
||||
// ->required(),
|
||||
|
||||
TextInput::make('category')
|
||||
->label('Category')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $get, $set) {
|
||||
$plantId = $get('plant_id');
|
||||
$lineId = $get('line_id');
|
||||
// $month = $get('month');
|
||||
$year = $get('year');
|
||||
|
||||
$month = (int) $get('month');
|
||||
$category = $get('category');
|
||||
|
||||
}),
|
||||
|
||||
])
|
||||
->columns(4)
|
||||
]);
|
||||
}
|
||||
|
||||
public function generateNonPlan(){
|
||||
$plantId = $this->filters['plant_id'] ?? null;
|
||||
$lineId = $this->filters['line_id'] ?? null;
|
||||
$date = $this->filters['date'] ?? null;
|
||||
$category = $this->filters['category'] ?? null;
|
||||
if($category == '' || $category == null){
|
||||
$this->dispatch('loadData', $date, $plantId, $lineId);
|
||||
}
|
||||
else{
|
||||
$this->dispatch('loadDataCategory',$date, $plantId, $lineId, $category);
|
||||
}
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return Auth::check() && Auth::user()->can('view production non planned page');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<x-filament-panels::page>
|
||||
<div class="space-y-4">
|
||||
|
||||
{{-- Render the Select form fields --}}
|
||||
<div class="space-y-4">
|
||||
{{ $this->form }}
|
||||
</div>
|
||||
<x-filament::button
|
||||
wire:click="generateNonPlan"
|
||||
color="primary"
|
||||
class="mt-4"
|
||||
>
|
||||
Generate
|
||||
</x-filament::button>
|
||||
|
||||
<div class="bg-white shadow rounded-xl p-4 mt-6">
|
||||
<livewire:production-non-planned />
|
||||
</div>
|
||||
</div>
|
||||
</x-filament-panels::page>
|
||||
Reference in New Issue
Block a user