first commit

This commit is contained in:
2026-05-14 09:08:09 +08:00
commit 919b86c8ec
111 changed files with 14085 additions and 0 deletions

1
database/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.sqlite*

View File

@@ -0,0 +1,46 @@
<?php
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
/**
* @extends Factory<User>
*/
class UserFactory extends Factory
{
/**
* The current password being used by the factory.
*/
protected static ?string $password;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'no_telefon' => fake()->phoneNumber(),
'jawatan' => fake()->jobTitle(),
'status' => true,
'password' => static::$password ??= Hash::make('password'),
];
}
/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
}

View File

@@ -0,0 +1,54 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->foreignId('jabatan_id')->nullable()->index();
$table->string('name');
$table->string('email')->unique();
$table->string('no_telefon')->nullable();
$table->string('jawatan')->nullable();
$table->boolean('status')->default(true);
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->timestamp('last_login_at')->nullable();
$table->rememberToken();
$table->timestamps();
});
Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->longText('payload');
$table->integer('last_activity')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
Schema::dropIfExists('password_reset_tokens');
Schema::dropIfExists('sessions');
}
};

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
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('cache', function (Blueprint $table) {
$table->string('key')->primary();
$table->mediumText('value');
$table->integer('expiration')->index();
});
Schema::create('cache_locks', function (Blueprint $table) {
$table->string('key')->primary();
$table->string('owner');
$table->integer('expiration')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('cache');
Schema::dropIfExists('cache_locks');
}
};

View File

@@ -0,0 +1,57 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('jobs', function (Blueprint $table) {
$table->id();
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
Schema::create('job_batches', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->integer('total_jobs');
$table->integer('pending_jobs');
$table->integer('failed_jobs');
$table->longText('failed_job_ids');
$table->mediumText('options')->nullable();
$table->integer('cancelled_at')->nullable();
$table->integer('created_at');
$table->integer('finished_at')->nullable();
});
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('jobs');
Schema::dropIfExists('job_batches');
Schema::dropIfExists('failed_jobs');
}
};

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
{
Schema::create('jabatan', function (Blueprint $table) {
$table->id();
$table->string('nama');
$table->enum('peringkat', ['Jabatan', 'Bahagian', 'Seksyen', 'Unit', 'Sub Unit']);
$table->string('kod')->nullable()->unique();
$table->text('penerangan')->nullable();
$table->boolean('status')->default(true);
$table->softDeletes();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('jabatan');
}
};

View File

@@ -0,0 +1,22 @@
<?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('users', function (Blueprint $table) {
$table->foreign('jabatan_id')->references('id')->on('jabatan')->nullOnDelete();
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropForeign(['jabatan_id']);
});
}
};

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('vot', function (Blueprint $table) {
$table->id();
$table->foreignId('jabatan_id')->nullable()->constrained('jabatan')->nullOnDelete();
$table->string('kod')->unique();
$table->string('nama');
$table->text('penerangan')->nullable();
$table->boolean('status')->default(true);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('vot');
}
};

View File

@@ -0,0 +1,39 @@
<?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('permohonan', function (Blueprint $table) {
$table->id();
$table->string('no_rujukan')->unique();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->foreignId('jabatan_id')->nullable()->constrained('jabatan')->nullOnDelete();
$table->foreignId('vot_id')->nullable()->constrained('vot')->nullOnDelete();
$table->string('kategori');
$table->text('tujuan');
$table->decimal('jumlah_keseluruhan', 14, 2)->default(0);
$table->enum('status', ['Draft', 'Submitted', 'Under Review', 'Accepted', 'Rejected', 'Approved'])->default('Draft');
$table->text('catatan')->nullable();
$table->string('gambar_1')->nullable();
$table->string('gambar_2')->nullable();
$table->enum('status_semakan', ['Belum Disemak', 'Sedang Disemak', 'Selesai'])->default('Belum Disemak');
$table->text('catatan_semakan')->nullable();
$table->foreignId('reviewed_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamp('reviewed_at')->nullable();
$table->foreignId('approved_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamp('approved_at')->nullable();
$table->timestamp('submitted_at')->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('permohonan');
}
};

View File

@@ -0,0 +1,28 @@
<?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('permohonan_items', function (Blueprint $table) {
$table->id();
$table->foreignId('permohonan_id')->constrained('permohonan')->cascadeOnDelete();
$table->string('item');
$table->integer('kuantiti');
$table->decimal('harga_anggaran', 14, 2);
$table->decimal('jumlah', 14, 2);
$table->enum('status_item', ['Pending', 'Accepted', 'Rejected', 'Partial Accept'])->default('Pending');
$table->text('catatan_pelaksana')->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('permohonan_items');
}
};

View File

@@ -0,0 +1,27 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateActivityLogTable extends Migration
{
public function up()
{
Schema::connection(config('activitylog.database_connection'))->create(config('activitylog.table_name'), function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('log_name')->nullable();
$table->text('description');
$table->nullableMorphs('subject', 'subject');
$table->nullableMorphs('causer', 'causer');
$table->json('properties')->nullable();
$table->timestamps();
$table->index('log_name');
});
}
public function down()
{
Schema::connection(config('activitylog.database_connection'))->dropIfExists(config('activitylog.table_name'));
}
}

View File

@@ -0,0 +1,137 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
$teams = config('permission.teams');
$tableNames = config('permission.table_names');
$columnNames = config('permission.column_names');
$pivotRole = $columnNames['role_pivot_key'] ?? 'role_id';
$pivotPermission = $columnNames['permission_pivot_key'] ?? 'permission_id';
throw_if(empty($tableNames), 'Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
throw_if($teams && empty($columnNames['team_foreign_key'] ?? null), 'Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.');
/**
* See `docs/prerequisites.md` for suggested lengths on 'name' and 'guard_name' if "1071 Specified key was too long" errors are encountered.
*/
Schema::create($tableNames['permissions'], static function (Blueprint $table) {
$table->id(); // permission id
$table->string('name');
$table->string('guard_name');
$table->timestamps();
$table->unique(['name', 'guard_name']);
});
/**
* See `docs/prerequisites.md` for suggested lengths on 'name' and 'guard_name' if "1071 Specified key was too long" errors are encountered.
*/
Schema::create($tableNames['roles'], static function (Blueprint $table) use ($teams, $columnNames) {
$table->id(); // role id
if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing
$table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable();
$table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index');
}
$table->string('name');
$table->string('guard_name');
$table->timestamps();
if ($teams || config('permission.testing')) {
$table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']);
} else {
$table->unique(['name', 'guard_name']);
}
});
Schema::create($tableNames['model_has_permissions'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) {
$table->unsignedBigInteger($pivotPermission);
$table->string('model_type');
$table->unsignedBigInteger($columnNames['model_morph_key']);
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index');
$table->foreign($pivotPermission)
->references('id') // permission id
->on($tableNames['permissions'])
->cascadeOnDelete();
if ($teams) {
$table->unsignedBigInteger($columnNames['team_foreign_key']);
$table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index');
$table->primary([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'],
'model_has_permissions_permission_model_type_primary');
} else {
$table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
'model_has_permissions_permission_model_type_primary');
}
});
Schema::create($tableNames['model_has_roles'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) {
$table->unsignedBigInteger($pivotRole);
$table->string('model_type');
$table->unsignedBigInteger($columnNames['model_morph_key']);
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index');
$table->foreign($pivotRole)
->references('id') // role id
->on($tableNames['roles'])
->cascadeOnDelete();
if ($teams) {
$table->unsignedBigInteger($columnNames['team_foreign_key']);
$table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index');
$table->primary([$columnNames['team_foreign_key'], $pivotRole, $columnNames['model_morph_key'], 'model_type'],
'model_has_roles_role_model_type_primary');
} else {
$table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type'],
'model_has_roles_role_model_type_primary');
}
});
Schema::create($tableNames['role_has_permissions'], static function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) {
$table->unsignedBigInteger($pivotPermission);
$table->unsignedBigInteger($pivotRole);
$table->foreign($pivotPermission)
->references('id') // permission id
->on($tableNames['permissions'])
->cascadeOnDelete();
$table->foreign($pivotRole)
->references('id') // role id
->on($tableNames['roles'])
->cascadeOnDelete();
$table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary');
});
app('cache')
->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
->forget(config('permission.cache.key'));
}
/**
* Reverse the migrations.
*/
public function down(): void
{
$tableNames = config('permission.table_names');
throw_if(empty($tableNames), 'Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
Schema::dropIfExists($tableNames['role_has_permissions']);
Schema::dropIfExists($tableNames['model_has_roles']);
Schema::dropIfExists($tableNames['model_has_permissions']);
Schema::dropIfExists($tableNames['roles']);
Schema::dropIfExists($tableNames['permissions']);
}
};

View File

@@ -0,0 +1,22 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddEventColumnToActivityLogTable extends Migration
{
public function up()
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->string('event')->nullable()->after('subject_type');
});
}
public function down()
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->dropColumn('event');
});
}
}

View File

@@ -0,0 +1,22 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddBatchUuidColumnToActivityLogTable extends Migration
{
public function up()
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->uuid('batch_uuid')->nullable()->after('properties');
});
}
public function down()
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->dropColumn('batch_uuid');
});
}
}

View File

@@ -0,0 +1,94 @@
<?php
namespace Database\Seeders;
use App\Models\Jabatan;
use App\Models\Permohonan;
use App\Models\User;
use App\Models\Vot;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
class DatabaseSeeder extends Seeder
{
public function run(): void
{
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
$permissions = [
'manage configuration', 'manage users', 'manage roles', 'create permohonan',
'review permohonan', 'approve permohonan', 'view reports', 'export reports',
];
foreach ($permissions as $permission) {
Permission::firstOrCreate(['name' => $permission, 'guard_name' => 'web']);
}
$adminRole = Role::firstOrCreate(['name' => 'Admin', 'guard_name' => 'web']);
$pelaksanaRole = Role::firstOrCreate(['name' => 'Pelaksana', 'guard_name' => 'web']);
$pemohonRole = Role::firstOrCreate(['name' => 'Pemohon', 'guard_name' => 'web']);
$adminRole->syncPermissions($permissions);
$pelaksanaRole->syncPermissions(['review permohonan', 'view reports']);
$pemohonRole->syncPermissions(['create permohonan']);
$jabatan = collect([
['kod' => 'KEW', 'nama' => 'Jabatan Kewangan', 'peringkat' => 'Jabatan', 'penerangan' => 'Pengurusan kewangan dan bajet MBIP'],
['kod' => 'ICT', 'nama' => 'Bahagian Teknologi Maklumat', 'peringkat' => 'Bahagian', 'penerangan' => 'Perkhidmatan digital dan infrastruktur ICT'],
['kod' => 'KORP', 'nama' => 'Jabatan Korporat', 'peringkat' => 'Jabatan', 'penerangan' => 'Komunikasi korporat dan pentadbiran'],
])->map(fn ($row) => Jabatan::firstOrCreate(['kod' => $row['kod']], $row));
$vot = collect([
['kod' => '21000', 'nama' => 'Bekalan Pejabat', 'jabatan_id' => $jabatan[0]->id],
['kod' => '24000', 'nama' => 'Penyelenggaraan Sistem', 'jabatan_id' => $jabatan[1]->id],
['kod' => '27000', 'nama' => 'Program Korporat', 'jabatan_id' => $jabatan[2]->id],
])->map(fn ($row) => Vot::firstOrCreate(['kod' => $row['kod']], $row + ['status' => true]));
$admin = User::firstOrCreate(['email' => 'admin@mbip.gov.my'], [
'name' => 'Admin Kewangan',
'password' => Hash::make('password'),
'jabatan_id' => $jabatan[0]->id,
'jawatan' => 'Akauntan',
'no_telefon' => '07-5550001',
'status' => true,
]);
$admin->syncRoles('Admin');
$pelaksana = User::firstOrCreate(['email' => 'pelaksana@mbip.gov.my'], [
'name' => 'Pegawai Pelaksana',
'password' => Hash::make('password'),
'jabatan_id' => $jabatan[1]->id,
'jawatan' => 'Pegawai Penyemak Bajet',
'no_telefon' => '07-5550002',
'status' => true,
]);
$pelaksana->syncRoles('Pelaksana');
$pemohon = User::firstOrCreate(['email' => 'pemohon@mbip.gov.my'], [
'name' => 'Pegawai Pemohon',
'password' => Hash::make('password'),
'jabatan_id' => $jabatan[1]->id,
'jawatan' => 'Penolong Pegawai Teknologi Maklumat',
'no_telefon' => '07-5550003',
'status' => true,
]);
$pemohon->syncRoles('Pemohon');
$permohonan = Permohonan::firstOrCreate(['no_rujukan' => 'MBIP/BJT/DEMO/001'], [
'user_id' => $pemohon->id,
'jabatan_id' => $jabatan[1]->id,
'vot_id' => $vot[1]->id,
'kategori' => 'Penyelenggaraan',
'tujuan' => 'Penyelenggaraan lesen dan sokongan sistem dalaman.',
'status' => 'Submitted',
'submitted_at' => now(),
'jumlah_keseluruhan' => 12500,
]);
if ($permohonan->items()->count() === 0) {
$permohonan->items()->createMany([
['item' => 'Lesen sistem helpdesk', 'kuantiti' => 10, 'harga_anggaran' => 850, 'jumlah' => 8500],
['item' => 'Sokongan teknikal tahunan', 'kuantiti' => 1, 'harga_anggaran' => 4000, 'jumlah' => 4000],
]);
}
}
}