1
0
forked from poc/pds

After change datatype from citext to text

This commit is contained in:
dhanabalan
2025-03-25 15:02:25 +05:30
parent 8612cc08b1
commit 70a42a6651
20 changed files with 234 additions and 87 deletions

View File

@@ -16,7 +16,7 @@ class BlockResource extends Resource
{ {
protected static ?string $model = Block::class; 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'; protected static ?string $navigationGroup = 'Master Entries';

View File

@@ -27,6 +27,7 @@ class CompanyResource extends Resource
->schema([ ->schema([
Forms\Components\TextInput::make('name') Forms\Components\TextInput::make('name')
->required() ->required()
//->citext('name')
->unique() ->unique()
->columnSpanFull(), ->columnSpanFull(),
]); ]);

View File

@@ -40,6 +40,15 @@ class ItemResource extends Resource
Forms\Components\Textarea::make('description') Forms\Components\Textarea::make('description')
->required() ->required()
->columnSpanFull(), ->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(), ->sortable(),
Tables\Columns\TextColumn::make('description') Tables\Columns\TextColumn::make('description')
->sortable(), ->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') Tables\Columns\TextColumn::make('created_at')
->dateTime() ->dateTime()
->sortable() ->sortable()

View File

@@ -17,7 +17,7 @@ class PlantResource extends Resource
{ {
protected static ?string $model = Plant::class; 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'; protected static ?string $navigationGroup = 'Master Entries';

View File

@@ -27,16 +27,13 @@ class ProductionQuantityResource extends Resource
{ {
return $form return $form
->schema([ ->schema([
Forms\Components\TextInput::make('plan_quantity') Forms\Components\Select::make('item_id')
->required() ->relationship('item', 'code')
->numeric(), ->required(),
Forms\Components\TextInput::make('hourly_quantity') // Forms\Components\TextInput::make('item_code')
->required() // ->required()
->numeric(), // ->autocapitalize('item_code'),
Forms\Components\TextInput::make('item_code') // //->columnSpanFull(),
->required()
->autocapitalize('item_code'),
//->columnSpanFull(),
Forms\Components\TextInput::make('serial_number') Forms\Components\TextInput::make('serial_number')
->required() ->required()
->autocapitalize('serial_number'), ->autocapitalize('serial_number'),

View File

@@ -14,15 +14,30 @@ class ItemOverview extends ChartWidget
protected function getData(): array protected function getData(): array
{ {
$activeFilter = $this->filter; $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') $query = \DB::table('production_quantities')
->selectRaw('EXTRACT(HOUR FROM created_at) AS hour, SUM(hourly_quantity) AS total_quantity') ->selectRaw('EXTRACT(HOUR FROM created_at) AS hour, COUNT(*) AS total_quantity')
->whereBetween('created_at', [now()->startOfDay(), now()->endOfDay()]) ->whereBetween('created_at', [now()->startOfDay(), now()->endOfDay()]);
->groupByRaw('EXTRACT(HOUR FROM created_at)')
// 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)') ->orderByRaw('EXTRACT(HOUR FROM created_at)')
->pluck('total_quantity', 'hour') ->pluck('total_quantity', 'hour')
->toArray(); ->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) $data = array_fill(8, 12, 0);
// Populate actual values // Populate actual values
// foreach ($query as $record) { // foreach ($query as $record) {
@@ -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)), '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 protected function getType(): string

View File

@@ -4,14 +4,33 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Item extends Model class Item extends Model
{ {
use SoftDeletes; use SoftDeletes;
protected $fillable = [ protected $fillable = [
"plant_id",
"block_id",
"line_id",
'code', 'code',
'description', 'description',
'hourly_quantity', '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);
}
} }

View File

@@ -15,9 +15,7 @@ class ProductionQuantity extends Model
"block_id", "block_id",
"shift_id", "shift_id",
"line_id", "line_id",
"plan_quantity", "item_id",
"hourly_quantity",
"item_code",
"serial_number", "serial_number",
]; ];
@@ -40,4 +38,9 @@ class ProductionQuantity extends Model
{ {
return $this->belongsTo(Line::class); return $this->belongsTo(Line::class);
} }
public function item(): BelongsTo
{
return $this->belongsTo(Item::class);
}
} }

View File

@@ -4,6 +4,7 @@ namespace App\Providers;
use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
// use Doctrine\DBAL\Types\Type;
class AppServiceProvider extends ServiceProvider class AppServiceProvider extends ServiceProvider
{ {
@@ -23,5 +24,9 @@ class AppServiceProvider extends ServiceProvider
Gate::before(function ($user, $ability) { Gate::before(function ($user, $ability) {
return $user->hasRole('Super Admin') ? true : null; return $user->hasRole('Super Admin') ? true : null;
}); });
// if (!Type::hasType('citext')) {
// Type::addType('citext', \Doctrine\DBAL\Platforms\PostgreSqlPlatform::class);
// }
} }
} }

View File

@@ -10,7 +10,8 @@
"althinect/filament-spatie-roles-permissions": "^2.3", "althinect/filament-spatie-roles-permissions": "^2.3",
"filament/filament": "^3.3", "filament/filament": "^3.3",
"laravel/framework": "^11.31", "laravel/framework": "^11.31",
"laravel/tinker": "^2.9" "laravel/tinker": "^2.9",
"tpetry/laravel-postgresql-enhanced": "^2.3"
}, },
"require-dev": { "require-dev": {
"barryvdh/laravel-ide-helper": "^3.5", "barryvdh/laravel-ide-helper": "^3.5",

139
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "292ea7e3ed35e47bcbea3972cfa9bb78", "content-hash": "7b2a34f16f1fa4714c137023cb652961",
"packages": [ "packages": [
{ {
"name": "althinect/filament-spatie-roles-permissions", "name": "althinect/filament-spatie-roles-permissions",
@@ -5031,6 +5031,69 @@
], ],
"time": "2025-02-28T20:29:57+00:00" "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", "name": "symfony/clock",
"version": "v7.2.0", "version": "v7.2.0",
@@ -7383,6 +7446,80 @@
}, },
"time": "2024-12-21T16:25:41+00:00" "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", "name": "vlucas/phpdotenv",
"version": "v5.6.1", "version": "v5.6.1",

View File

@@ -13,7 +13,7 @@ return new class extends Migration
$sql = <<<'SQL' $sql = <<<'SQL'
CREATE TABLE companies ( CREATE TABLE companies (
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY, 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(), created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW(),

View File

@@ -17,8 +17,8 @@ return new class extends Migration
code INT NOT NULL CHECK (code >= 1000) UNIQUE, code INT NOT NULL CHECK (code >= 1000) UNIQUE,
company_id BIGINT NOT NULL, company_id BIGINT NOT NULL,
name CITEXT NOT NULL UNIQUE, -- CITEXT use extension name TEXT NOT NULL UNIQUE, -- CITEXT use extension
address CITEXT NOT NULL, address TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(), created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW(),

View File

@@ -14,7 +14,7 @@ return new class extends Migration
CREATE TABLE blocks ( CREATE TABLE blocks (
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY, id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
name CITEXT NOT NULL, name TEXT NOT NULL,
plant_id BIGINT NOT NULL, plant_id BIGINT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(), created_at TIMESTAMP NOT NULL DEFAULT NOW(),

View File

@@ -14,7 +14,7 @@ return new class extends Migration
CREATE TABLE shifts ( CREATE TABLE shifts (
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY, id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
name CITEXT NOT NULL, name TEXT NOT NULL,
block_id BIGINT NOT NULL, block_id BIGINT NOT NULL,
plant_id BIGINT NOT NULL, plant_id BIGINT NOT NULL,

View File

@@ -18,8 +18,8 @@ return new class extends Migration
block_id BIGINT NOT NULL, block_id BIGINT NOT NULL,
plant_id BIGINT NOT NULL, plant_id BIGINT NOT NULL,
code CITEXT NOT NULL CHECK (LENGTH(code) >= 6), code TEXT NOT NULL CHECK (LENGTH(code) >= 6),
description CITEXT NOT NULL, description TEXT NOT NULL,
hourly_quantity INT NOT NULL CHECK (hourly_quantity > 0), hourly_quantity INT NOT NULL CHECK (hourly_quantity > 0),

View File

@@ -19,8 +19,8 @@ return new class extends Migration
block_id BIGINT NOT NULL, block_id BIGINT NOT NULL,
plant_id BIGINT NOT NULL, plant_id BIGINT NOT NULL,
code CITEXT NOT NULL, code TEXT NOT NULL,
reason CITEXT NOT NULL, reason TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(), created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW(),

View File

@@ -18,8 +18,8 @@ return new class extends Migration
block_id BIGINT NOT NULL, block_id BIGINT NOT NULL,
plant_id BIGINT NOT NULL, plant_id BIGINT NOT NULL,
name CITEXT NOT NULL, name TEXT NOT NULL,
type CITEXT NOT NULL, type TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(), created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW(),

View File

@@ -21,7 +21,7 @@ return new class extends Migration
plant_id BIGINT NOT NULL, plant_id BIGINT NOT NULL,
item_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(), created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW(),

View File

@@ -20,14 +20,6 @@ class UserSeeder extends Seeder
$user1->assignRole('Super Admin'); $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(); User::factory()->count(10)->create();
} }
} }