After change datatype from citext to text
This commit is contained in:
@@ -16,7 +16,7 @@ class BlockResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Block::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'codeat3/blade-clarity-icons';
|
||||
protected static ?string $navigationIcon = 'heroicon-c-building-library';
|
||||
|
||||
protected static ?string $navigationGroup = 'Master Entries';
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ class CompanyResource extends Resource
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required()
|
||||
//->citext('name')
|
||||
->unique()
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
|
||||
@@ -40,6 +40,15 @@ class ItemResource extends Resource
|
||||
Forms\Components\Textarea::make('description')
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->relationship('plant', 'name')
|
||||
->required(),
|
||||
Forms\Components\Select::make('block_id')
|
||||
->relationship('block', 'name')
|
||||
->required(),
|
||||
Forms\Components\Select::make('line_id')
|
||||
->relationship('line', 'name')
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -58,6 +67,12 @@ class ItemResource extends Resource
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('description')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('line.name')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('block.name')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
|
||||
@@ -17,7 +17,7 @@ class PlantResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Plant::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
protected static ?string $navigationIcon = 'heroicon-s-building-office-2';
|
||||
|
||||
protected static ?string $navigationGroup = 'Master Entries';
|
||||
|
||||
|
||||
@@ -27,16 +27,13 @@ class ProductionQuantityResource extends Resource
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('plan_quantity')
|
||||
->required()
|
||||
->numeric(),
|
||||
Forms\Components\TextInput::make('hourly_quantity')
|
||||
->required()
|
||||
->numeric(),
|
||||
Forms\Components\TextInput::make('item_code')
|
||||
->required()
|
||||
->autocapitalize('item_code'),
|
||||
//->columnSpanFull(),
|
||||
Forms\Components\Select::make('item_id')
|
||||
->relationship('item', 'code')
|
||||
->required(),
|
||||
// Forms\Components\TextInput::make('item_code')
|
||||
// ->required()
|
||||
// ->autocapitalize('item_code'),
|
||||
// //->columnSpanFull(),
|
||||
Forms\Components\TextInput::make('serial_number')
|
||||
->required()
|
||||
->autocapitalize('serial_number'),
|
||||
|
||||
@@ -14,23 +14,38 @@ class ItemOverview extends ChartWidget
|
||||
protected function getData(): array
|
||||
{
|
||||
$activeFilter = $this->filter;
|
||||
|
||||
// Get selected values from the plant and line filter form inputs
|
||||
$selectedPlant = request()->input('plant'); // Assuming form input name is 'plant'
|
||||
$selectedLine = request()->input('line'); // Assuming form input name is 'line'
|
||||
|
||||
$query = \DB::table('production_quantities')
|
||||
->selectRaw('EXTRACT(HOUR FROM created_at) AS hour, SUM(hourly_quantity) AS total_quantity')
|
||||
->whereBetween('created_at', [now()->startOfDay(), now()->endOfDay()])
|
||||
->groupByRaw('EXTRACT(HOUR FROM created_at)')
|
||||
->selectRaw('EXTRACT(HOUR FROM created_at) AS hour, COUNT(*) AS total_quantity')
|
||||
->whereBetween('created_at', [now()->startOfDay(), now()->endOfDay()]);
|
||||
|
||||
// Apply filters only if values are selected
|
||||
if (!empty($selectedPlant)) {
|
||||
$query->where('plant', $selectedPlant);
|
||||
}
|
||||
|
||||
if (!empty($selectedLine)) {
|
||||
$query->where('line', $selectedLine);
|
||||
}
|
||||
|
||||
$query = $query->groupByRaw('EXTRACT(HOUR FROM created_at)')
|
||||
->orderByRaw('EXTRACT(HOUR FROM created_at)')
|
||||
->pluck('total_quantity', 'hour')
|
||||
->toArray();
|
||||
// Initialize data for each hour interval (8 AM - 7 PM)
|
||||
$data = array_fill(8, 12, 0); // 8 AM to 7 PM (indexes 8 to 19)
|
||||
|
||||
// Populate actual values
|
||||
// foreach ($query as $record) {
|
||||
// $hour = (int) $record->hour;
|
||||
// if ($hour >= 8 && $hour <= 19) {
|
||||
// $data[$hour] = $record->total_quantity; // Assign only the hourly production
|
||||
// }
|
||||
// }
|
||||
$data = array_fill(8, 12, 0);
|
||||
|
||||
// Populate actual values
|
||||
// foreach ($query as $record) {
|
||||
// $hour = (int) $record->hour;
|
||||
// if ($hour >= 8 && $hour <= 19) {
|
||||
// $data[$hour] = $record->total_quantity; // Assign only the hourly production
|
||||
// }
|
||||
// }
|
||||
|
||||
// Convert data to chart format
|
||||
return [
|
||||
@@ -47,44 +62,6 @@ class ItemOverview extends ChartWidget
|
||||
'labels' => array_map(fn($h) => ($h <= 11 ? "$h AM" : ($h == 12 ? "12 PM" : ($h - 12) . " PM")), array_keys($data)),
|
||||
];
|
||||
|
||||
// // Initialize data for each hour interval (8 AM - 7 PM)
|
||||
// $data = [
|
||||
// '8 AM - 9 AM' => 0, '9 AM - 10 AM' => 0, '10 AM - 11 AM' => 0, '11 AM - 12 PM' => 0,
|
||||
// '12 PM - 1 PM' => 0, '1 PM - 2 PM' => 0, '2 PM - 3 PM' => 0, '3 PM - 4 PM' => 0,
|
||||
// '4 PM - 5 PM' => 0, '5 PM - 6 PM' => 0, '6 PM - 7 PM' => 0, '7 PM - 8 PM' => 0,
|
||||
// ];
|
||||
|
||||
|
||||
// // Populate actual values
|
||||
// foreach ($query as $record) {
|
||||
// $hour = (int) $record->hour;
|
||||
// if ($hour >= 8 && $hour <= 19) {
|
||||
// $index = ($hour - 8); // Match hour to array index
|
||||
// $labels = array_keys($data); // Get labels
|
||||
|
||||
// // Store only the production for that specific hour
|
||||
// $data[$labels[$index]] = $record->total_quantity;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// // Debugging: Check if data exists
|
||||
// if (empty($query) || array_sum($data) === 0) {
|
||||
// \Log::info('No production data found for today.');
|
||||
// }
|
||||
|
||||
// return [
|
||||
// 'datasets' => [
|
||||
// [
|
||||
// 'label' => 'Production Quantities',
|
||||
// 'data' => array_values($data),
|
||||
// 'borderColor' => 'rgba(75, 192, 192, 1)',
|
||||
// 'backgroundColor' => 'rgba(75, 192, 192, 0.2)',
|
||||
// 'fill' => true,
|
||||
// ],
|
||||
// ],
|
||||
// 'labels' => array_keys($data),
|
||||
// ];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
|
||||
@@ -4,14 +4,33 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Item extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
"plant_id",
|
||||
"block_id",
|
||||
"line_id",
|
||||
'code',
|
||||
'description',
|
||||
'hourly_quantity',
|
||||
];
|
||||
|
||||
public function plant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Plant::class);
|
||||
}
|
||||
|
||||
public function block(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Block::class);
|
||||
}
|
||||
|
||||
public function line(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Line::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,7 @@ class ProductionQuantity extends Model
|
||||
"block_id",
|
||||
"shift_id",
|
||||
"line_id",
|
||||
"plan_quantity",
|
||||
"hourly_quantity",
|
||||
"item_code",
|
||||
"item_id",
|
||||
"serial_number",
|
||||
];
|
||||
|
||||
@@ -40,4 +38,9 @@ class ProductionQuantity extends Model
|
||||
{
|
||||
return $this->belongsTo(Line::class);
|
||||
}
|
||||
|
||||
public function item(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Item::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
// use Doctrine\DBAL\Types\Type;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -23,5 +24,9 @@ class AppServiceProvider extends ServiceProvider
|
||||
Gate::before(function ($user, $ability) {
|
||||
return $user->hasRole('Super Admin') ? true : null;
|
||||
});
|
||||
|
||||
// if (!Type::hasType('citext')) {
|
||||
// Type::addType('citext', \Doctrine\DBAL\Platforms\PostgreSqlPlatform::class);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user