Compare commits
9 Commits
4cc0366fba
...
3d744e8183
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d744e8183 | ||
|
|
6c119778c6 | ||
|
|
5425970fc2 | ||
|
|
2fa637bfab | ||
|
|
4b1a25ccbd | ||
|
|
88349309cd | ||
|
|
80d09b1780 | ||
|
|
d210bfebf9 | ||
|
|
3ac8c3c613 |
@@ -18,11 +18,11 @@ class Dashboard extends \Filament\Pages\Dashboard
|
||||
|
||||
protected static ?string $navigationGroup = 'Production DashBoard';
|
||||
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
session()->forget(['selected_plant']);
|
||||
$this->filtersForm->fill([
|
||||
'plant' => Plant::first()?->id // Default to first plant
|
||||
'plant' => null
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,13 @@ class HourlyProduction extends Page
|
||||
|
||||
use HasFiltersForm;
|
||||
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
session()->forget(['selected_plant', 'selected_line']);
|
||||
$this->filtersForm->fill([
|
||||
'plant' => Plant::first()?->id // Default to first plant
|
||||
//'plant' => Plant::first()?->id // Default to first plant
|
||||
'plant' => null,
|
||||
'line' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,10 @@ class InvoiceDashboard extends Page
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
session()->forget(['selec_plant', 'select_invoice']);
|
||||
$this->filtersForm->fill([
|
||||
'plant' => Plant::first()?->id // Default to first plant
|
||||
'plant' => null,
|
||||
'invoice' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
87
app/Filament/Pages/ProductionOrderCount.php
Normal file
87
app/Filament/Pages/ProductionOrderCount.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Plant;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Tables\Concerns\HasFilters;
|
||||
|
||||
class ProductionOrderCount extends Page
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static string $view = 'filament.pages.production-order-count';
|
||||
|
||||
protected static ?string $navigationGroup = 'Production DashBoard';
|
||||
|
||||
use HasFiltersForm;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
session()->forget(['selected_plant', 'selected_line', 'production_order']);
|
||||
$this->filtersForm->fill([
|
||||
'plant' => null,
|
||||
'line' => null,
|
||||
'production_order' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function filtersForm(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->statePath('filters') // Explicitly set where to store form data
|
||||
->schema([
|
||||
Select::make('plant')
|
||||
->options(Plant::pluck('name', 'id'))
|
||||
->label('Select Plant')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state) {
|
||||
session(['selected_plant' => $state]);
|
||||
$this->triggerChartUpdate();
|
||||
}),
|
||||
// Line Filter
|
||||
Select::make('line')
|
||||
->options(function ($get) {
|
||||
$plantId = $get('plant');
|
||||
return $plantId ? Plant::find($plantId)->getLineNames()->pluck('name', 'id') : [];
|
||||
})
|
||||
->label('Select Line')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state) {
|
||||
session(['selected_line' => $state]); // Store in session
|
||||
$this->triggerChartUpdate();
|
||||
}),
|
||||
|
||||
// Production Order Text Input
|
||||
TextInput::make('production_order')
|
||||
->label('Production Order')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state) {
|
||||
session(['production_order' => $state]);
|
||||
$this->triggerChartUpdate();
|
||||
}),
|
||||
])
|
||||
->columns(3);
|
||||
}
|
||||
|
||||
// public function triggerChartUpdate(): void
|
||||
// {
|
||||
// if (session()->has('selected_plant') && session()->has('selected_line') && session()->has('production_order')) {
|
||||
// $this->dispatch('productionOrderChart');
|
||||
// }
|
||||
// }
|
||||
|
||||
public function triggerChartUpdate(): void
|
||||
{
|
||||
$filters = $this->filtersForm->getState();
|
||||
|
||||
if (!empty($filters['plant']) && !empty($filters['line']) && !empty($filters['production_order'])) {
|
||||
$this->dispatch('productionOrderChart', filters: $filters);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,10 @@ use App\Filament\Resources\InvoiceValidationResource\Pages;
|
||||
use App\Models\InvoiceValidation;
|
||||
use App\Models\Plant;
|
||||
use App\Models\StickerMaster;
|
||||
use Auth;
|
||||
use Filament\Actions\Action as FilamentActionsAction;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Actions\Action as ActionsAction;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
@@ -299,7 +301,6 @@ class InvoiceValidationResource extends Resource
|
||||
->visible(fn (Get $get) => !empty($get('plant_id')))
|
||||
->directory('uploads/temp'),
|
||||
])
|
||||
|
||||
->action(function (array $data) {
|
||||
$uploadedFile = $data['invoice_serial_number'];
|
||||
|
||||
@@ -546,6 +547,9 @@ class InvoiceValidationResource extends Resource
|
||||
->send();
|
||||
}
|
||||
}
|
||||
})
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view import serial invoice');
|
||||
}),
|
||||
|
||||
Tables\Actions\Action::make('Import Invoice Material')
|
||||
@@ -556,14 +560,13 @@ class InvoiceValidationResource extends Resource
|
||||
->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);
|
||||
}),
|
||||
|
||||
})
|
||||
->reactive(),
|
||||
|
||||
FileUpload::make('invoice_material')
|
||||
->label('Invoice Material')
|
||||
@@ -573,8 +576,7 @@ class InvoiceValidationResource extends Resource
|
||||
->storeFiles(false) // prevent auto-storing
|
||||
->disk('local')
|
||||
->visible(fn (Get $get) => !empty($get('plant_id')))
|
||||
->directory('uploads/temp')
|
||||
|
||||
->directory('uploads/temp'),
|
||||
])
|
||||
|
||||
->action(function (array $data) {
|
||||
@@ -877,6 +879,9 @@ class InvoiceValidationResource extends Resource
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view import material invoice');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->label('Export Invoices')
|
||||
|
||||
@@ -480,7 +480,6 @@ class ProductionPlanResource extends Resource
|
||||
->readOnly(),
|
||||
Forms\Components\Hidden::make('operator_id')
|
||||
->default(Filament::auth()->user()->name),
|
||||
|
||||
])
|
||||
->columns(2),
|
||||
]);
|
||||
|
||||
@@ -24,6 +24,7 @@ use Filament\Forms\Components\Section;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Livewire\Livewire;
|
||||
// use Filament\Forms\Components\View;
|
||||
|
||||
class ProductionQuantityResource extends Resource
|
||||
{
|
||||
@@ -857,9 +858,10 @@ class ProductionQuantityResource extends Resource
|
||||
->readOnly(),
|
||||
Forms\Components\Hidden::make('operator_id')
|
||||
->default(Filament::auth()->user()->name),
|
||||
|
||||
])
|
||||
->columns(12), //6
|
||||
|
||||
//View::make('filament.pages.hourly-production'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ class CreateProductionQuantity extends CreateRecord
|
||||
return $this->getResource()::getUrl('create'); // Stay on Create Page after saving
|
||||
}
|
||||
|
||||
public $qrData, $pId, $bId, $sId, $lId, $iId, $succId, $sNoId, $succStat, $recQr;
|
||||
public $qrData, $pId, $bId, $sId, $lId, $iId, $succId, $sNoId, $succStat, $recQr, $prodOrder;
|
||||
|
||||
// protected static bool $canCreateAnother = false;
|
||||
|
||||
@@ -121,7 +121,7 @@ class CreateProductionQuantity extends CreateRecord
|
||||
|
||||
public function validateAndProcessForm($formValues)
|
||||
{
|
||||
$user = Filament::auth()->user();
|
||||
$user = Filament::auth()->user(); //->name
|
||||
$operatorName = $user->name;
|
||||
// $this->validate();
|
||||
|
||||
@@ -139,10 +139,18 @@ class CreateProductionQuantity extends CreateRecord
|
||||
$this->iId = $formData['item_id'] ?? null;
|
||||
$this->succId = $formData['success_msg'] ?? null;
|
||||
// $this->sNoId = $formData['serial_number'] ?? null;
|
||||
$this->prodOrder = $formData['production_order'] ?? null;
|
||||
$this->recQr = $formData['recent_qr'] ?? null;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
dd('Error parsing form data:', $e->getMessage(), $formValues);
|
||||
//dd('Error parsing form data:', $e->getMessage(), $formValues);
|
||||
Notification::make()
|
||||
->title("Error Parsing Form Data") // {$operatorName}
|
||||
->body($e->getMessage())
|
||||
->danger()
|
||||
// ->persistent()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->succId === null) {
|
||||
@@ -154,6 +162,8 @@ class CreateProductionQuantity extends CreateRecord
|
||||
'item_id'=> null,
|
||||
'serial_number'=> null,
|
||||
'success_msg'=> null,
|
||||
'production_order'=> null,
|
||||
'operator_id'=> $operatorName,
|
||||
'recent_qr' => $this->recQr,
|
||||
]);
|
||||
|
||||
@@ -180,7 +190,8 @@ class CreateProductionQuantity extends CreateRecord
|
||||
'line_id' => $this->lId,
|
||||
'item_id'=> $this->iId,
|
||||
'serial_number' => $this->sNoId,
|
||||
// 'operator_id'=> $operatorName,
|
||||
'production_order'=> $this->prodOrder,
|
||||
'operator_id'=> $operatorName,
|
||||
]);
|
||||
|
||||
// after success insertion
|
||||
@@ -192,6 +203,8 @@ class CreateProductionQuantity extends CreateRecord
|
||||
'item_id'=> null,
|
||||
'serial_number'=> null,
|
||||
'success_msg'=> null,
|
||||
'production_order'=> $this->prodOrder,
|
||||
'operator_id'=> $operatorName,
|
||||
'recent_qr' => $itemCode.' | '.$this->sNoId,
|
||||
]);
|
||||
|
||||
|
||||
@@ -11,11 +11,13 @@ class CumulativeChart extends ChartWidget
|
||||
|
||||
protected $listeners = ['cumulativeChart'];
|
||||
|
||||
protected static ?string $maxHeight = '350px';
|
||||
|
||||
|
||||
protected int|string|array $columnSpan = 12;
|
||||
protected function getData(): array
|
||||
{
|
||||
$selectedPlant = session('selected_plant') ?? session('select_plant');
|
||||
$selectedPlant = session('selected_plant');
|
||||
$activeFilter = $this->filter;
|
||||
|
||||
// Define date range based on filter
|
||||
|
||||
@@ -15,7 +15,6 @@ class InvoiceChart extends ChartWidget
|
||||
|
||||
protected $listeners = ['invoiceChart'];
|
||||
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$selectedPlant =session('selec_plant');
|
||||
@@ -33,13 +32,17 @@ class InvoiceChart extends ChartWidget
|
||||
}
|
||||
|
||||
if ($activeFilter === 'yesterday') {
|
||||
$startDate = now()->subDay()->startOfDay();
|
||||
$endDate = now()->subDay()->endOfDay();
|
||||
$startDate = now()->subDay()->setTime(8, 0, 0); // yesterday 8:00 AM
|
||||
$endDate = now()->setTime(8, 0, 0); // today 8:00 AM
|
||||
$groupBy = 'EXTRACT(HOUR FROM invoice_validations.created_at)';
|
||||
}
|
||||
else if ($activeFilter === 'this_week') {
|
||||
$startDate = now()->startOfWeek(); // Monday 12:00 AM
|
||||
$endDate = now()->endOfWeek(); // Sunday 11:59 PM
|
||||
// Monday 8:00 AM of the current week
|
||||
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
|
||||
// Next Monday 8:00 AM (end of Sunday + 8 hrs)
|
||||
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
|
||||
$groupBy = 'EXTRACT(DOW FROM invoice_validations.created_at)'; // Group by day of week
|
||||
}
|
||||
else if ($activeFilter === 'this_month') {
|
||||
@@ -49,17 +52,48 @@ class InvoiceChart extends ChartWidget
|
||||
}
|
||||
else
|
||||
{
|
||||
$startDate = now()->startOfDay();
|
||||
$endDate = now()->endOfDay();
|
||||
$startDate = now()->setTime(8, 0, 0); // today at 8:00 AM
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0); // tomorrow at 8:00 AM
|
||||
$groupBy = 'EXTRACT(HOUR FROM invoice_validations.created_at)';
|
||||
}
|
||||
|
||||
$fullyScannedInvoiceNumbers = \DB::table('invoice_validations')
|
||||
->select('invoice_number')
|
||||
->where('plant_id', $selectedPlant)
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw("SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END) = COUNT(*)")
|
||||
->pluck('invoice_number');
|
||||
// $fullyScannedInvoiceNumbers = \DB::table('invoice_validations')
|
||||
// ->select('invoice_number')
|
||||
// ->where('plant_id', $selectedPlant)
|
||||
// ->groupBy('invoice_number')
|
||||
// ->havingRaw("SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END) = COUNT(*)")
|
||||
// ->pluck('invoice_number');
|
||||
|
||||
if ($selectedInvoice === 'individual_material')
|
||||
{
|
||||
$fullyScannedInvoiceNumbers = \DB::table('invoice_validations')
|
||||
->select('invoice_number')
|
||||
->where('plant_id', $selectedPlant)
|
||||
->havingRaw('MIN(quantity) = 1 AND MAX(quantity) = 1') // All rows must have quantity = 1
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw("SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END) = COUNT(*)")
|
||||
->pluck('invoice_number');
|
||||
}
|
||||
else if ($selectedInvoice === 'bundle_material')
|
||||
{
|
||||
$fullyScannedInvoiceNumbers = \DB::table('invoice_validations')
|
||||
->select('invoice_number')
|
||||
->where('plant_id', $selectedPlant)
|
||||
->havingRaw('MIN(quantity) > 1')
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw("SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END) = COUNT(*)")
|
||||
->pluck('invoice_number');
|
||||
}
|
||||
else
|
||||
{
|
||||
$fullyScannedInvoiceNumbers = \DB::table('invoice_validations')
|
||||
->select('invoice_number')
|
||||
->where('plant_id', $selectedPlant)
|
||||
->groupBy('invoice_number')
|
||||
->havingRaw("SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END) = COUNT(*)")
|
||||
->pluck('invoice_number');
|
||||
}
|
||||
|
||||
|
||||
//query data
|
||||
$query = \DB::table('invoice_validations')
|
||||
@@ -173,7 +207,6 @@ class InvoiceChart extends ChartWidget
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ class ItemOverview extends ChartWidget
|
||||
// Monday 8:00 AM of the current week
|
||||
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
|
||||
// Next Monday 8:00 AM (end of Sunday + 8 hrs)
|
||||
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
|
||||
$groupBy = 'EXTRACT(DOW FROM production_quantities.created_at)'; // Group by day of week
|
||||
@@ -178,6 +177,9 @@ class ItemOverview extends ChartWidget
|
||||
public static function canView(): bool
|
||||
{
|
||||
// Only show on HourlyProduction page
|
||||
return request()->routeIs('filament.pages.hourly-production');
|
||||
return request()->routeIs([
|
||||
'filament.pages.hourly-production',
|
||||
'filament.admin.resources.production-quantities.create',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
177
app/Filament/Widgets/ProductionOrderChart.php
Normal file
177
app/Filament/Widgets/ProductionOrderChart.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Widgets\ChartWidget;
|
||||
|
||||
class ProductionOrderChart extends ChartWidget
|
||||
{
|
||||
protected static ?string $heading = 'ProductionOrderCount';
|
||||
|
||||
protected int|string|array $columnSpan = 12;
|
||||
|
||||
protected $listeners = ['productionOrderChart'];
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$activeFilter = $this->filter;
|
||||
|
||||
$selectedPlant = session('selected_plant');
|
||||
$selectedLine = session('selected_line');
|
||||
$productionOrder = session('production_order');
|
||||
|
||||
if (!$selectedPlant || !$selectedLine || !$productionOrder)
|
||||
{
|
||||
return [
|
||||
'datasets' => [],
|
||||
'labels' => [],
|
||||
];
|
||||
}
|
||||
|
||||
if ($activeFilter === 'yesterday') {
|
||||
$startDate = now()->subDay()->setTime(8, 0, 0); // yesterday 8:00 AM
|
||||
$endDate = now()->setTime(8, 0, 0); // today 8:00 AM
|
||||
$groupBy = 'EXTRACT(HOUR FROM production_quantities.created_at)';
|
||||
}
|
||||
else if ($activeFilter === 'this_week') {
|
||||
// Monday 8:00 AM of the current week
|
||||
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
|
||||
// Next Monday 8:00 AM (end of Sunday + 8 hrs)
|
||||
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
|
||||
$groupBy = 'EXTRACT(DOW FROM production_quantities.created_at)'; // Group by day of week
|
||||
}
|
||||
|
||||
else if ($activeFilter === 'this_month') {
|
||||
$startDate = now()->startOfMonth();
|
||||
$endDate = now()->endOfMonth();
|
||||
$groupBy = "FLOOR((EXTRACT(DAY FROM production_quantities.created_at) - 1) / 7) + 1";
|
||||
}
|
||||
else
|
||||
{
|
||||
$startDate = now()->setTime(8, 0, 0); // today at 8:00 AM
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0); // tomorrow at 8:00 AM
|
||||
$groupBy = 'EXTRACT(HOUR FROM production_quantities.created_at)';
|
||||
}
|
||||
|
||||
|
||||
$query = \DB::table('production_quantities')
|
||||
->join('plants', 'production_quantities.plant_id', '=', 'plants.id')
|
||||
->join('lines', 'production_quantities.line_id', '=', 'lines.id')
|
||||
->selectRaw("$groupBy AS time_unit, count(*) AS total_quantity")
|
||||
->whereBetween('production_quantities.created_at', [$startDate, $endDate])
|
||||
->where('plants.id', $selectedPlant)
|
||||
->where('lines.id', $selectedLine)
|
||||
->when($productionOrder, fn($q) => $q->where('production_quantities.production_order', $productionOrder))
|
||||
->groupByRaw($groupBy)
|
||||
->orderByRaw($groupBy)
|
||||
->pluck('total_quantity', 'time_unit')
|
||||
->toArray();
|
||||
if ($activeFilter === 'this_month') {
|
||||
$weeksCount = ceil($endDate->day / 7); // Calculate total weeks dynamically
|
||||
$allWeeks = array_fill(1, $weeksCount, 0); // Initialize all weeks with 0
|
||||
$data = array_replace($allWeeks, $query); // Fill missing weeks with 0
|
||||
|
||||
// Generate dynamic week labels
|
||||
$labels = [];
|
||||
for ($i = 1; $i <= $weeksCount; $i++) {
|
||||
$weekStart = $startDate->copy()->addDays(($i - 1) * 7)->format('d M');
|
||||
$weekEnd = $startDate->copy()->addDays($i * 7 - 1)->min($endDate)->format('d M');
|
||||
$labels[] = "Week $i ($weekStart - $weekEnd)";
|
||||
}
|
||||
|
||||
$orderedData = array_values($data);
|
||||
}
|
||||
else if ($activeFilter === 'this_week') {
|
||||
// Correct week labels: ['Mon', 'Tue', ..., 'Sun']
|
||||
$labels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||
|
||||
// Initialize default data for all 7 days
|
||||
$data = array_fill(0, 7, 0);
|
||||
|
||||
// Fill in data from query results
|
||||
foreach ($query as $dow => $count) {
|
||||
$data[$dow] = $count;
|
||||
}
|
||||
|
||||
// Ensure days are ordered from Monday to Sunday
|
||||
$orderedData = [
|
||||
$data[1] ?? 0, // Monday
|
||||
$data[2] ?? 0, // Tuesday
|
||||
$data[3] ?? 0, // Wednesday
|
||||
$data[4] ?? 0, // Thursday
|
||||
$data[5] ?? 0, // Friday
|
||||
$data[6] ?? 0, // Saturday
|
||||
$data[0] ?? 0, // Sunday (move to last)
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hourly data (same as before)
|
||||
$allHours = array_fill(0, 24, 0);
|
||||
$data = array_replace($allHours, $query);
|
||||
|
||||
// Shift hours for proper display (8 AM to 7 AM)
|
||||
$shiftedKeys = array_merge(range(8, 23), range(0, 8));
|
||||
$orderedData = array_map(fn($hour) => $data[$hour], $shiftedKeys);
|
||||
|
||||
// Labels: ["8 AM", "9 AM", ..., "7 AM"]
|
||||
$labels = array_map(fn ($hour) => date("g A", strtotime("$hour:00")), $shiftedKeys);
|
||||
}
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => match ($activeFilter) {
|
||||
'this_week' => "Daily Production Order Count This Week",
|
||||
'this_month' => "Weekly Production Order Count This Month", // Updated Label
|
||||
'yesterday' => "Yesterday's Hourly Order Count Production",
|
||||
default => "Today's Hourly Production Order Count",
|
||||
},
|
||||
'data' => $orderedData,
|
||||
'borderColor' => 'rgba(75, 192, 192, 1)',
|
||||
'backgroundColor' => 'rgba(75, 192, 192, 0.2)',
|
||||
'fill' => false,
|
||||
'tension' => 0.3,
|
||||
],
|
||||
],
|
||||
'labels' => $labels,
|
||||
];
|
||||
}
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'bar';
|
||||
}
|
||||
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
|
||||
'scales' => [
|
||||
'y' => [
|
||||
'beginAtZero' => true,
|
||||
'ticks' => [
|
||||
'stepSize' => 0.5,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getFilters(): ?array
|
||||
{
|
||||
return [
|
||||
'today' => 'Today',
|
||||
'yesterday' => 'Yesterday',
|
||||
'this_week'=> 'This Week',
|
||||
'this_month'=> 'This Month',
|
||||
];
|
||||
}
|
||||
|
||||
public static function canView(): bool
|
||||
{
|
||||
// Only show on HourlyProduction page
|
||||
return request()->routeIs('filament.pages.production-order-count');
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ class ProductionLineStop extends Model
|
||||
"to_datetime",
|
||||
"stop_hour",
|
||||
"stop_min",
|
||||
"operator_id",
|
||||
];
|
||||
|
||||
public function plant(): BelongsTo
|
||||
|
||||
@@ -17,6 +17,7 @@ class ProductionPlan extends Model
|
||||
"line_id",
|
||||
"plan_quantity",
|
||||
"production_quantity",
|
||||
"operator_id",
|
||||
];
|
||||
|
||||
public function plant(): BelongsTo
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -20,6 +21,7 @@ class ProductionQuantity extends Model
|
||||
"item_id",
|
||||
"serial_number",
|
||||
"production_order",
|
||||
"operator_id",
|
||||
];
|
||||
|
||||
public function plant(): BelongsTo
|
||||
@@ -69,10 +71,13 @@ class ProductionQuantity extends Model
|
||||
->first();
|
||||
}
|
||||
|
||||
$operatorName = Filament::auth()->user()->name;
|
||||
|
||||
if ($productionPlan) {
|
||||
$productionPlan->update([
|
||||
'production_quantity' => $productionPlan->production_quantity + 1,
|
||||
'updated_at' => now(),
|
||||
'operator_id'=> $operatorName,
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -33,6 +33,8 @@ class PermissionSeeder extends Seeder
|
||||
Permission::updateOrCreate(['name' => $permission]); //firstOrCreate
|
||||
}
|
||||
|
||||
Permission::updateOrCreate(['name' => 'view import serial invoice']);
|
||||
Permission::updateOrCreate(['name' => 'view import material invoice']);
|
||||
Permission::updateOrCreate(['name' => 'view production dashboard']);
|
||||
Permission::updateOrCreate(['name' => 'view invoice dashboard']);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<x-filament-panels::page>
|
||||
<div class="space-y-4">
|
||||
{{-- Render the Select form fields --}}
|
||||
<div class="space-y-4">
|
||||
{{ $this->filtersForm($this->form) }}
|
||||
</div>
|
||||
|
||||
{{-- Render the chart widget below the form --}}
|
||||
<div class="mt-6">
|
||||
@livewire(\App\Filament\Widgets\ProductionOrderChart::class)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</x-filament-panels::page>
|
||||
Reference in New Issue
Block a user