diff --git a/app/Filament/Resources/BlockResource.php b/app/Filament/Resources/BlockResource.php index b37030f78..a56c99780 100644 --- a/app/Filament/Resources/BlockResource.php +++ b/app/Filament/Resources/BlockResource.php @@ -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'; diff --git a/app/Filament/Resources/CompanyResource.php b/app/Filament/Resources/CompanyResource.php index 7830c2d7d..4593d5c5b 100644 --- a/app/Filament/Resources/CompanyResource.php +++ b/app/Filament/Resources/CompanyResource.php @@ -27,6 +27,7 @@ class CompanyResource extends Resource ->schema([ Forms\Components\TextInput::make('name') ->required() + //->citext('name') ->unique() ->columnSpanFull(), ]); diff --git a/app/Filament/Resources/ItemResource.php b/app/Filament/Resources/ItemResource.php index d55e80f2b..26d575bc3 100644 --- a/app/Filament/Resources/ItemResource.php +++ b/app/Filament/Resources/ItemResource.php @@ -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() diff --git a/app/Filament/Resources/PlantResource.php b/app/Filament/Resources/PlantResource.php index d226163f9..f83c6b926 100644 --- a/app/Filament/Resources/PlantResource.php +++ b/app/Filament/Resources/PlantResource.php @@ -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'; diff --git a/app/Filament/Resources/ProductionQuantityResource.php b/app/Filament/Resources/ProductionQuantityResource.php index b0a856e43..09ed47919 100644 --- a/app/Filament/Resources/ProductionQuantityResource.php +++ b/app/Filament/Resources/ProductionQuantityResource.php @@ -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'), diff --git a/app/Filament/Widgets/ItemOverview.php b/app/Filament/Widgets/ItemOverview.php index b6d88c0b9..fa264b6a7 100644 --- a/app/Filament/Widgets/ItemOverview.php +++ b/app/Filament/Widgets/ItemOverview.php @@ -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 diff --git a/app/Models/Item.php b/app/Models/Item.php index dba63d8e5..eb0f485be 100644 --- a/app/Models/Item.php +++ b/app/Models/Item.php @@ -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); + } } diff --git a/app/Models/ProductionQuantity.php b/app/Models/ProductionQuantity.php index 12e9c6995..6d5e7df24 100644 --- a/app/Models/ProductionQuantity.php +++ b/app/Models/ProductionQuantity.php @@ -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); + } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index e5970acd8..d82cd88df 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -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); + // } } } diff --git a/composer.json b/composer.json index 5832820e8..7db217490 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ "althinect/filament-spatie-roles-permissions": "^2.3", "filament/filament": "^3.3", "laravel/framework": "^11.31", - "laravel/tinker": "^2.9" + "laravel/tinker": "^2.9", + "tpetry/laravel-postgresql-enhanced": "^2.3" }, "require-dev": { "barryvdh/laravel-ide-helper": "^3.5", diff --git a/composer.lock b/composer.lock index f11b24d5e..a1993c395 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "292ea7e3ed35e47bcbea3972cfa9bb78", + "content-hash": "7b2a34f16f1fa4714c137023cb652961", "packages": [ { "name": "althinect/filament-spatie-roles-permissions", @@ -5031,6 +5031,69 @@ ], "time": "2025-02-28T20:29:57+00:00" }, + { + "name": "spatie/regex", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/spatie/regex.git", + "reference": "d543de2019a0068e7b80da0ba24f1c51c7469303" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/regex/zipball/d543de2019a0068e7b80da0ba24f1c51c7469303", + "reference": "d543de2019a0068e7b80da0ba24f1c51c7469303", + "shasum": "" + }, + "require": { + "php": "^8.0|^8.1" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\Regex\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Sebastian De Deyne", + "email": "sebastian@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "A sane interface for php's built in preg_* functions", + "homepage": "https://github.com/spatie/regex", + "keywords": [ + "expression", + "expressions", + "regex", + "regular", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/regex/issues", + "source": "https://github.com/spatie/regex/tree/3.1.1" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + }, + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2021-11-30T21:13:59+00:00" + }, { "name": "symfony/clock", "version": "v7.2.0", @@ -7383,6 +7446,80 @@ }, "time": "2024-12-21T16:25:41+00:00" }, + { + "name": "tpetry/laravel-postgresql-enhanced", + "version": "2.3.4", + "source": { + "type": "git", + "url": "https://github.com/tpetry/laravel-postgresql-enhanced.git", + "reference": "a242704496e1cff76193a552128940bfa59d1466" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tpetry/laravel-postgresql-enhanced/zipball/a242704496e1cff76193a552128940bfa59d1466", + "reference": "a242704496e1cff76193a552128940bfa59d1466", + "shasum": "" + }, + "require": { + "doctrine/dbal": "^2.6|^3.5|^4.0", + "illuminate/container": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", + "illuminate/database": "^6.0|^7.0|^8.79|^9.0|^10.0|^11.0|^12.0", + "illuminate/events": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", + "illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", + "php": "^8.0", + "spatie/regex": "^2.0|^3.0" + }, + "require-dev": { + "composer/semver": "^3.4", + "friendsofphp/php-cs-fixer": "^2.19.3|^3.5.0", + "larastan/larastan": "^1.0|^2.1|^3.0", + "nesbot/carbon": "^2.7|^3.3", + "orchestra/testbench": "^4.0|^5.0|^6.0|^7.0|^8.0|^9.0|^10.0", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.5|^2.0", + "phpunit/phpunit": "^8.5.23|^9.5.13|^10.5|^11.4", + "ramsey/uuid": "^3.9|^4.7" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Tpetry\\PostgresqlEnhanced\\PostgresqlEnhancedServiceProvider" + ] + }, + "phpstan": { + "includes": [ + "phpstan-extension.neon" + ] + } + }, + "autoload": { + "psr-4": { + "Tpetry\\PostgresqlEnhanced\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "tpetry", + "email": "tobias@tpetry.me" + } + ], + "description": "Support for many missing PostgreSQL specific features", + "homepage": "https://github.com/tpetry/laravel-postgresql-enhanced", + "keywords": [ + "laravel", + "postgresql" + ], + "support": { + "issues": "https://github.com/tpetry/laravel-postgresql-enhanced/issues", + "source": "https://github.com/tpetry/laravel-postgresql-enhanced/tree/2.3.4" + }, + "time": "2025-03-06T10:30:15+00:00" + }, { "name": "vlucas/phpdotenv", "version": "v5.6.1", diff --git a/database/migrations/2025_03_19_161954_create_companies_table.php b/database/migrations/2025_03_19_161954_create_companies_table.php index 749561aad..d4a0e15b4 100644 --- a/database/migrations/2025_03_19_161954_create_companies_table.php +++ b/database/migrations/2025_03_19_161954_create_companies_table.php @@ -13,7 +13,7 @@ return new class extends Migration $sql = <<<'SQL' CREATE TABLE companies ( id BIGINT GENERATED always AS IDENTITY PRIMARY KEY, - name CITEXT NOT NULL UNIQUE, + name TEXT NOT NULL UNIQUE, created_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW(), diff --git a/database/migrations/2025_03_19_171555_create_plants_table.php b/database/migrations/2025_03_19_171555_create_plants_table.php index 691620197..50bb04f5c 100644 --- a/database/migrations/2025_03_19_171555_create_plants_table.php +++ b/database/migrations/2025_03_19_171555_create_plants_table.php @@ -17,8 +17,8 @@ return new class extends Migration code INT NOT NULL CHECK (code >= 1000) UNIQUE, company_id BIGINT NOT NULL, - name CITEXT NOT NULL UNIQUE, -- CITEXT use extension - address CITEXT NOT NULL, + name TEXT NOT NULL UNIQUE, -- CITEXT use extension + address TEXT NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW(), diff --git a/database/migrations/2025_03_20_115918_create_blocks_table.php b/database/migrations/2025_03_20_115918_create_blocks_table.php index f16160901..f7bc9ef43 100644 --- a/database/migrations/2025_03_20_115918_create_blocks_table.php +++ b/database/migrations/2025_03_20_115918_create_blocks_table.php @@ -14,7 +14,7 @@ return new class extends Migration CREATE TABLE blocks ( id BIGINT GENERATED always AS IDENTITY PRIMARY KEY, - name CITEXT NOT NULL, + name TEXT NOT NULL, plant_id BIGINT NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT NOW(), diff --git a/database/migrations/2025_03_20_125247_create_shifts_table.php b/database/migrations/2025_03_20_125247_create_shifts_table.php index 32b8a8e6f..1ba0adef4 100644 --- a/database/migrations/2025_03_20_125247_create_shifts_table.php +++ b/database/migrations/2025_03_20_125247_create_shifts_table.php @@ -14,7 +14,7 @@ return new class extends Migration CREATE TABLE shifts ( id BIGINT GENERATED always AS IDENTITY PRIMARY KEY, - name CITEXT NOT NULL, + name TEXT NOT NULL, block_id BIGINT NOT NULL, plant_id BIGINT NOT NULL, diff --git a/database/migrations/2025_03_21_090348_create_items_table.php b/database/migrations/2025_03_21_090348_create_items_table.php index f6f0054c7..5db2ad43a 100644 --- a/database/migrations/2025_03_21_090348_create_items_table.php +++ b/database/migrations/2025_03_21_090348_create_items_table.php @@ -18,8 +18,8 @@ return new class extends Migration block_id BIGINT NOT NULL, plant_id BIGINT NOT NULL, - code CITEXT NOT NULL CHECK (LENGTH(code) >= 6), - description CITEXT NOT NULL, + code TEXT NOT NULL CHECK (LENGTH(code) >= 6), + description TEXT NOT NULL, hourly_quantity INT NOT NULL CHECK (hourly_quantity > 0), diff --git a/database/migrations/2025_03_22_184847_create_line_stops_table.php b/database/migrations/2025_03_22_184847_create_line_stops_table.php index ccbc3cc8a..01e53483c 100644 --- a/database/migrations/2025_03_22_184847_create_line_stops_table.php +++ b/database/migrations/2025_03_22_184847_create_line_stops_table.php @@ -19,8 +19,8 @@ return new class extends Migration block_id BIGINT NOT NULL, plant_id BIGINT NOT NULL, - code CITEXT NOT NULL, - reason CITEXT NOT NULL, + code TEXT NOT NULL, + reason TEXT NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW(), diff --git a/database/migrations/2025_03_22_190920_create_lines_table.php b/database/migrations/2025_03_22_190920_create_lines_table.php index 0b77ec608..9a058ee74 100644 --- a/database/migrations/2025_03_22_190920_create_lines_table.php +++ b/database/migrations/2025_03_22_190920_create_lines_table.php @@ -18,8 +18,8 @@ return new class extends Migration block_id BIGINT NOT NULL, plant_id BIGINT NOT NULL, - name CITEXT NOT NULL, - type CITEXT NOT NULL, + name TEXT NOT NULL, + type TEXT NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW(), diff --git a/database/migrations/2025_03_23_170155_create_production_quantities_table.php b/database/migrations/2025_03_23_170155_create_production_quantities_table.php index f24aaafe6..e174ce175 100644 --- a/database/migrations/2025_03_23_170155_create_production_quantities_table.php +++ b/database/migrations/2025_03_23_170155_create_production_quantities_table.php @@ -21,7 +21,7 @@ return new class extends Migration plant_id BIGINT NOT NULL, item_id BIGINT NOT NULL, - serial_number CITEXT NOT NULL UNIQUE, + serial_number TEXT NOT NULL UNIQUE, created_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW(), diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index c2fa2b4a5..ee039ddeb 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -20,14 +20,6 @@ class UserSeeder extends Seeder $user1->assignRole('Super Admin'); - $user2 = User::create([ - 'name' => 'Admin', - 'email' => 'admin@cripumps.com', - 'password' => bcrypt('admin'), - ]); - - $user2->assignRole('Super Admin'); - User::factory()->count(10)->create(); } }