Merge remote-tracking branch 'origin/prod-kopkb' into test/merge-prod-kopkb

This commit is contained in:
nurafrinaalimi16
2026-09-01 11:15:13 +08:00
66 changed files with 6674 additions and 327 deletions
@@ -0,0 +1,44 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateApprovalWithdrawal extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('approval_withdrawal', function (Blueprint $table) {
$table->id();
$table->char('kodcaw', 20);
$table->string('action', 50);
$table->string('pc_name', 100);
$table->string('operasi_name', 100)->nullable();
$table->decimal('amount', 10, 2)->default(0);
$table->string('approval_status',20);
$table->timestamp('approval_timestamp')->nullable();
$table->integer('gldetail_id_v3')->nullable()->default(0);
$table->integer('denopendser_id_v3')->nullable()->default(0);
$table->integer('gldetail_id_v2')->nullable()->default(0);
$table->integer('denopendser_id_v2')->nullable()->default(0);
$table->boolean('updated_serahan_v2')->default(false);
$table->boolean('updated_pendahuluan_v3')->default(false);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('approval_withdrawal');
}
}
@@ -0,0 +1,49 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
class AddTimestampToGldetailTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function getActiveDB(){
$config_db = array_keys(config("database.connections"));
$db_connection = array_filter($config_db,function($connection){
try{
if($connection == 'mysql7')
return false;
$db = DB::connection($connection)->getPdo();
return true;
} catch(\Exception $e){
return false;
}
});
return $db_connection;
}
public function up()
{
$db_connection = $this->getActiveDB();
foreach($db_connection as $dbase){
Schema::connection($dbase)->table('gldetail', function (Blueprint $table) use($dbase) {
$dateCreated = Schema::connection($dbase)->hasColumn('gldetail', 'date_created');
if (!$dateCreated) {
$table->timestamp('date_created');
}
});
}
}
}
@@ -0,0 +1,148 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class AddHapusAnsuranPropertiesToMohonidTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
protected $db_connection;
public function getActiveDB()
{
$connections = array_keys(config("database.connections"));
$excluded = config('database.excluded_connections', ['mysql7']);
$active = [];
foreach ($connections as $connection) {
if (in_array($connection, $excluded)) {
Log::debug("Skipping excluded connection: {$connection}");
continue;
}
try {
DB::connection($connection)->select('SELECT 1');
$active[] = $connection;
} catch (\Exception $e) {
continue;
}
}
return $active;
}
public function up()
{
$databases = $this->getActiveDB();
Log::info("Active databases: " . implode(', ', $databases));
foreach ($databases as $database) {
Log::info("Migrating database: {$database}");
$this->safeAddProperties($database, 'mohonid');
}
}
private function safeAddProperties($database, $table_name)
{
// Skip if table doesn't exist
if (!Schema::connection($database)->hasTable($table_name)) {
Log::warning("Table {$table_name} does not exist in database {$database}. Skipping migration.");
return;
}
try {
// Get existing columns once
$existing_columns = Schema::connection($database)->getColumnListing($table_name);
$columns_to_add = [
'tagoperasi' => 'boolean',
'ansuran' => 'decimal',
'masa' => 'time',
'operasi' => 'string',
'timestamp_approved_by_pc' => 'timestamp',
'timestamp_approved_by_operasi' => 'timestamp',
];
// Find missing columns (this was missing!)
$missing_columns = array_diff(array_keys($columns_to_add), $existing_columns);
// Add all missing columns in one schema call
if (!empty($missing_columns)) {
Schema::connection($database)->table($table_name, function (Blueprint $table) use ($existing_columns) {
// Add ansuran column - decimal with default 0
if( !in_array('tagoperasi', $existing_columns)) {
$table->boolean('tagoperasi')->default(0)->comment('Tag Operasi');
}
if (!in_array('ansuran', $existing_columns)) {
$table->decimal('ansuran', 10, 2)->default(0.00)->after('pinjaman')->comment('Ansuran Amount');
}
// Add masa column - TIME type
if (!in_array('masa', $existing_columns)) {
$table->time('masa')->nullable()->after('tarikh')->comment('Time period');
}
// Add operasi column - string
if (!in_array('operasi', $existing_columns)) {
$table->string('operasi')->nullable()->comment('Nama Operasi');
}
// Add approval timestamp columns (changed from boolean to timestamp)
if (!in_array('timestamp_approved_by_pc', $existing_columns)) {
$table->timestamp('timestamp_approved_by_pc')->nullable()->after('id')->comment('Time Approved by PC');
}
if (!in_array('timestamp_approved_by_operasi', $existing_columns)) {
$table->timestamp('timestamp_approved_by_operasi')->nullable()->comment('Time approved by Operasi');
}
});
}
} catch (\Exception $e) {
// Don't fail entire migration for one database
Log::error("Migration failed for database {$database}: " . $e->getMessage());
}
}
public function down()
{
$databases = $this->getActiveDB();
foreach ($databases as $database) {
if (Schema::connection($database)->hasTable('mohonid')) {
try {
Schema::connection($database)->table('mohonid', function (Blueprint $table) use ($database) {
// Check each column before dropping
if (Schema::connection($database)->hasColumn('mohonid', 'ansuran')) {
$table->dropColumn('ansuran');
}
if (Schema::connection($database)->hasColumn('mohonid', 'masa')) {
$table->dropColumn('masa');
}
if (Schema::connection($database)->hasColumn('mohonid', 'operasi')) {
$table->dropColumn('operasi');
}
if (Schema::connection($database)->hasColumn('mohonid', 'is_approved_by_pc')) {
$table->dropColumn('is_approved_by_pc');
}
if (Schema::connection($database)->hasColumn('mohonid', 'is_approved_by_operasi')) {
$table->dropColumn('is_approved_by_operasi');
}
});
} catch (\Exception $e) {
\Log::error("Rollback failed for database {$database}: " . $e->getMessage());
}
}
}
}
}
@@ -0,0 +1,122 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class AddNmJbgUntungPembiayaanColumnsToPalsuTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
private function getActiveDB() : array
{
$config_db = array_keys(config("database.connections"));
$db_connection = array_filter($config_db, function($connection) {
try {
if ($connection == 'mysql7') {
return false;
}
DB::connection($connection)->select('SELECT 1');
return true;
} catch (\Exception $e) {
return false;
}
});
return $db_connection ? array_values($db_connection) : [];
}
public function up()
{
$db_connection = $this->getActiveDB();
foreach ($db_connection as $dbase) {
Schema::connection($dbase)->table('palsu', function (Blueprint $table) use ($dbase) {
if (!Schema::connection($dbase)->hasColumn('palsu', 'pembiayaan')) {
$table->decimal('pembiayaan', 11, 2)->nullable()->comment('Pembiayaan amount');
}
if (!Schema::connection($dbase)->hasColumn('palsu', 'nilaimarhun')) {
$table->decimal('nilaimarhun', 11, 2)->nullable()->comment('Nilai marhun amount');
}
if (!Schema::connection($dbase)->hasColumn('palsu', 'jbg')) {
$table->float('jbg', 4, 2)->nullable()->comment('JBG value');
}
if (!Schema::connection($dbase)->hasColumn('palsu', 'untung')) {
$table->decimal('untung', 11, 2)->nullable()->comment('Untung amount');
}
if (!Schema::connection($dbase)->hasColumn('palsu', 'untungonepercent')) {
$table->decimal('untungonepercent', 11, 2)->nullable()->comment('Satu Persen amount');
}
if (!Schema::connection($dbase)->hasColumn('palsu', 'untungcajlain')) {
$table->decimal('untungcajlain', 11, 2)->nullable()->comment('Caj Lain-Lain amount');
}
// Add index and foreign key constraint to existing norujukan column
if (Schema::connection($dbase)->hasColumn('palsu', 'norujukan')) {
// Add index to norujukan column for better performance
$table->index('norujukan');
// Add foreign key constraint named 'norujukan'
$table->foreign('norujukan', 'norujukan')->references('norujukan')->on('gadai');
}
});
}
}
public function down()
{
$db_connection = $this->getActiveDB();
foreach ($db_connection as $dbase) {
Schema::connection($dbase)->table('palsu', function (Blueprint $table) use ($dbase) {
// Drop foreign key constraint and index from norujukan column
if (Schema::connection($dbase)->hasColumn('palsu', 'norujukan')) {
try {
$table->dropForeign('norujukan');
echo "Dropped foreign key 'norujukan' on connection '{$dbase}'\n";
} catch (\Exception $e) {
echo "Warning: Could not drop foreign key 'norujukan' on connection '{$dbase}': " . $e->getMessage() . "\n";
}
try {
$table->dropIndex(['norujukan']);
echo "Dropped index on 'norujukan' column on connection '{$dbase}'\n";
} catch (\Exception $e) {
echo "Warning: Could not drop index on 'norujukan' on connection '{$dbase}': " . $e->getMessage() . "\n";
}
}
// Drop other columns if they exist
$columnsToCheck = ['nilaimarhun', 'jbg', 'untung','untungonepercent','untungcajlain', 'pembiayaan'];
foreach ($columnsToCheck as $column) {
if (Schema::connection($dbase)->hasColumn('palsu', $column)) {
try {
$table->dropColumn($column);
echo "Dropped column '{$column}' on connection '{$dbase}'\n";
} catch (\Exception $e) {
echo "Warning: Could not drop column '{$column}' on connection '{$dbase}': " . $e->getMessage() . "\n";
}
}
}
});
}
}
}
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePenyelarasanTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('penyelarasan', function (Blueprint $table) {
$table->id();
$table->char('kodcaw', 20);
$table->decimal('rugilelong', 10, 2)->default(0);
$table->decimal('bakilelong', 10, 2)->default(0);
$table->decimal('lain-lain', 10, 2)->default(0);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('penyelarasan');
}
}
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddNotaArccToCustomerTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('customer', function (Blueprint $table) {
$table->string('nota_arcc')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('customer', function (Blueprint $table) {
$table->dropColumn('nota_arcc');
});
}
}
@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAnggotaTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('anggota', function (Blueprint $table) {
$table->id();
$table->string('no_anggota')->unique()->nullable(); // No keahlian
$table->string('nama');
$table->string('noic')->unique(); // IC wajib unik
$table->string('no_tel')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('anggota');
}
}
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddStatusToAnggotaTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('anggota', function (Blueprint $table) {
$table->tinyInteger('status')
->default(1)
->comment('1 = aktif, 0 = tidak aktif')
->after('no_tel');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('anggota', function (Blueprint $table) {
//
$table->dropColumn('status');
});
}
}
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddTagAnggotaToCustomerTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('customer', function (Blueprint $table) {
$table->boolean('tag_anggota')->default(0)->after('ahli');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('customer', function (Blueprint $table) {
$table->dropColumn('tag_anggota');
});
}
}
@@ -0,0 +1,64 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
class CreateMohonAnggotaTable extends Migration
{
// Dapatkan semua sambungan DB aktif (kecuali mysql7 pusat)
public function getActiveDB()
{
$config_db = array_keys(config("database.connections"));
$db_connection = array_filter($config_db, function($connection) {
try {
if ($connection == 'mysql7') return false; // skip pusat
DB::connection($connection)->getPdo();
return true;
} catch (\Exception $e) {
return false;
}
});
return $db_connection;
}
/**
* Jalankan migration
*/
public function up()
{
$db_connection = $this->getActiveDB();
foreach ($db_connection as $dbase) {
if (!Schema::connection($dbase)->hasTable('mohon_anggota')) {
Schema::connection($dbase)->create('mohon_anggota', function (Blueprint $table) {
$table->bigIncrements('id');
$table->date('tarikh')->nullable();
$table->string('nokp', 20)->nullable();
$table->string('nama', 100)->nullable();
$table->string('status', 50)->default('MENUNGGU OPERASI');
$table->text('komen')->nullable();
$table->string('teller', 100)->nullable();
$table->string('peloperasi', 100)->nullable();
$table->dateTime('datetime_pelulus')->nullable();
$table->timestamps();
});
}
}
}
/**
* Undur migration
*/
public function down()
{
$db_connection = $this->getActiveDB();
foreach ($db_connection as $dbase) {
Schema::connection($dbase)->dropIfExists('mohon_anggota');
}
}
}