chore: update document approval workflow and bug fixes

This commit is contained in:
2026-05-25 13:05:20 +08:00
parent d573c02893
commit 39a8e1d4cd
910 changed files with 49994 additions and 1010 deletions

View File

@@ -0,0 +1,44 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('projects', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('code')->unique();
$table->text('description')->nullable();
$table->foreignId('customer_id')->nullable()->constrained('users')->nullOnDelete();
$table->string('location')->nullable();
$table->string('status')->default('under_bidding');
$table->decimal('contract_value', 15, 2)->default(0);
$table->decimal('total_capitalization', 15, 2)->default(0);
$table->date('start_date')->nullable();
$table->date('target_end_date')->nullable();
$table->date('actual_end_date')->nullable();
$table->decimal('completion_percentage', 5, 2)->default(0);
$table->timestamps();
$table->softDeletes();
});
Schema::create('project_user', function (Blueprint $table) {
$table->id();
$table->foreignId('project_id')->constrained()->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('role')->default('member'); // pm, engineer, laborer, member
$table->timestamps();
$table->unique(['project_id', 'user_id']);
});
}
public function down(): void
{
Schema::dropIfExists('project_user');
Schema::dropIfExists('projects');
}
};

View File

@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('tasks', function (Blueprint $table) {
$table->id();
$table->foreignId('project_id')->constrained()->cascadeOnDelete();
$table->foreignId('assigned_to')->nullable()->constrained('users')->nullOnDelete();
$table->string('name');
$table->text('description')->nullable();
$table->string('status')->default('pending');
$table->integer('sort_order')->default(0);
$table->decimal('labor_cost', 15, 2)->default(0);
$table->decimal('estimated_hours', 8, 2)->default(0);
$table->decimal('actual_hours', 8, 2)->default(0);
$table->date('start_date')->nullable();
$table->date('end_date')->nullable();
$table->date('actual_start_date')->nullable();
$table->date('actual_end_date')->nullable();
$table->decimal('completion_percentage', 5, 2)->default(0);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('tasks');
}
};

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('weekly_status_reports', function (Blueprint $table) {
$table->id();
$table->foreignId('project_id')->constrained()->cascadeOnDelete();
$table->date('period_start');
$table->date('period_end');
$table->string('status')->default('draft');
$table->text('narrative_status')->nullable();
$table->text('narrative_weather')->nullable();
$table->text('narrative_compliance')->nullable();
$table->foreignId('submitted_by')->nullable()->constrained('users')->nullOnDelete();
$table->foreignId('approved_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
$table->softDeletes();
$table->index(['project_id', 'period_end']);
$table->index(['project_id', 'status']);
});
}
public function down(): void
{
Schema::dropIfExists('weekly_status_reports');
}
};

View File

@@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('workforce_metrics', function (Blueprint $table) {
$table->id();
$table->foreignId('weekly_status_report_id')->constrained()->cascadeOnDelete();
$table->unsignedInteger('active_workforce')->default(0);
$table->decimal('period_man_hours', 12, 2)->default(0);
$table->decimal('cumulative_man_hours', 12, 2)->default(0);
$table->decimal('logistics_km', 10, 2)->default(0);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('workforce_metrics');
}
};

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('hse_records', function (Blueprint $table) {
$table->id();
$table->foreignId('weekly_status_report_id')->constrained()->cascadeOnDelete();
// Proactive safety
$table->unsignedInteger('toolbox_meetings')->default(0);
$table->unsignedInteger('safety_observations')->default(0);
// Reactive safety (zero targets)
$table->unsignedInteger('fatalities')->default(0);
$table->unsignedInteger('major_injuries')->default(0);
$table->unsignedInteger('first_aid_cases')->default(0);
$table->unsignedInteger('medical_cases')->default(0);
$table->unsignedInteger('near_misses')->default(0);
$table->unsignedInteger('environmental_damage')->default(0);
$table->unsignedInteger('property_damage')->default(0);
$table->decimal('fines', 12, 2)->default(0);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('hse_records');
}
};

View File

@@ -0,0 +1,23 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('projects', function (Blueprint $table) {
$table->foreignId('contractor_id')->nullable()->after('customer_id')
->constrained('contractors')->nullOnDelete();
});
}
public function down(): void
{
Schema::table('projects', function (Blueprint $table) {
$table->dropConstrainedForeignId('contractor_id');
});
}
};

View File

@@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('task_materials', function (Blueprint $table) {
$table->id();
$table->string('ulid', 26)->unique();
$table->foreignId('task_id')->constrained()->cascadeOnDelete();
$table->foreignId('material_id')->constrained()->cascadeOnDelete();
$table->decimal('planned_qty', 12, 2)->default(0);
$table->decimal('actual_qty', 12, 2)->default(0);
$table->decimal('unit_cost', 12, 2)->default(0);
$table->text('notes')->nullable();
$table->timestamps();
$table->unique(['task_id', 'material_id']);
});
if (!Schema::hasColumn('material_deployments', 'task_id')) {
Schema::table('material_deployments', function (Blueprint $table) {
$table->foreignId('task_id')->nullable()->after('project_id')
->constrained('tasks')->nullOnDelete();
});
}
}
public function down(): void
{
if (Schema::hasColumn('material_deployments', 'task_id')) {
Schema::table('material_deployments', function (Blueprint $table) {
$table->dropConstrainedForeignId('task_id');
});
}
Schema::dropIfExists('task_materials');
}
};

View File

@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
if (!Schema::hasColumn('task_materials', 'purchase_order_id')) {
Schema::table('task_materials', function (Blueprint $table) {
$table->foreignId('purchase_order_id')->nullable()->after('material_id')
->constrained('purchase_orders')->nullOnDelete();
});
}
}
public function down(): void
{
if (Schema::hasColumn('task_materials', 'purchase_order_id')) {
Schema::table('task_materials', function (Blueprint $table) {
$table->dropConstrainedForeignId('purchase_order_id');
});
}
}
};

View File

@@ -0,0 +1,23 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('projects', function (Blueprint $table) {
$table->string('client_name')->nullable()->after('customer_id');
$table->integer('contract_duration')->nullable()->after('target_end_date');
});
}
public function down(): void
{
Schema::table('projects', function (Blueprint $table) {
$table->dropColumn(['client_name', 'contract_duration']);
});
}
};

View File

@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('project_milestones', function (Blueprint $table) {
$table->id();
$table->string('ulid', 26)->unique();
$table->foreignId('project_id')->constrained()->cascadeOnDelete();
$table->string('name');
$table->text('description')->nullable();
$table->date('planned_date')->nullable();
$table->date('actual_date')->nullable();
$table->integer('sort_order')->default(0);
$table->decimal('weight_percentage', 5, 2)->default(0);
$table->boolean('is_default')->default(false);
$table->boolean('weather_impacted')->default(false);
$table->string('weather_condition')->nullable();
$table->integer('weather_delay_days')->default(0);
$table->text('weather_notes')->nullable();
$table->timestamps();
$table->index(['project_id', 'sort_order']);
});
}
public function down(): void
{
Schema::dropIfExists('project_milestones');
}
};

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('task_delays', function (Blueprint $table) {
$table->id();
$table->string('ulid', 26)->unique();
$table->foreignId('task_id')->constrained()->cascadeOnDelete();
$table->string('reason_type');
$table->string('weather_condition')->nullable();
$table->date('delay_date');
$table->decimal('lost_hours', 8, 2)->default(0);
$table->text('notes')->nullable();
$table->foreignId('reported_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
$table->index(['task_id', 'delay_date']);
$table->index(['task_id', 'reason_type']);
});
}
public function down(): void
{
Schema::dropIfExists('task_delays');
}
};

View File

@@ -0,0 +1,23 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('weekly_status_reports', function (Blueprint $table) {
$table->integer('weather_work_days_lost')->default(0)->after('narrative_compliance');
$table->json('weather_conditions')->nullable()->after('weather_work_days_lost');
});
}
public function down(): void
{
Schema::table('weekly_status_reports', function (Blueprint $table) {
$table->dropColumn(['weather_work_days_lost', 'weather_conditions']);
});
}
};

View File

@@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('task_user', function (Blueprint $table) {
$table->id();
$table->foreignId('task_id')->constrained()->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->timestamps();
});
Schema::table('tasks', function (Blueprint $table) {
$table->dropForeign(['assigned_to']);
$table->dropColumn('assigned_to');
});
Schema::table('task_materials', function (Blueprint $table) {
$table->dropForeign(['purchase_order_id']);
$table->dropColumn('purchase_order_id');
});
}
public function down(): void
{
Schema::table('task_materials', function (Blueprint $table) {
$table->foreignId('purchase_order_id')->nullable()->constrained('purchase_orders')->nullOnDelete();
});
Schema::table('tasks', function (Blueprint $table) {
$table->foreignId('assigned_to')->nullable()->constrained('users')->nullOnDelete();
});
Schema::dropIfExists('task_user');
}
};

View File

@@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('task_activities', function (Blueprint $table) {
$table->id();
$table->ulid('ulid')->unique();
$table->foreignId('task_id')->constrained('tasks')->cascadeOnDelete();
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
$table->string('description');
$table->string('type')->default('assignment');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('task_activities');
}
};

View File

@@ -0,0 +1,31 @@
<?php
namespace Modules\ProjectManagement\Database\Seeders;
use App\Models\User;
use Illuminate\Database\Seeder;
use Modules\ProjectManagement\Models\Project;
class ProjectManagementDatabaseSeeder extends Seeder
{
public function run(): void
{
// Create a sample project
$project = Project::create([
'name' => 'GSB Tower Construction',
'code' => 'PRJ-2026-001',
'description' => 'Main tower construction project for GSB headquarters.',
'location' => 'Manila, Philippines',
'status' => 'planning',
'contract_value' => 50000000.00,
'start_date' => '2026-04-01',
'target_end_date' => '2027-12-31',
]);
// Assign admin as PM
$admin = User::where('email', 'admin@gsb-cons.com')->first();
if ($admin) {
$project->personnel()->attach($admin->id, ['role' => 'pm']);
}
}
}