From 6d80afed8f441cc824a6a9c4220591cdd4f953b1 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Wed, 17 Sep 2025 12:38:51 +0800 Subject: [PATCH] Continue dev on pampasan module --- app/Http/Controllers/BarangkesController.php | 2 +- app/Http/Controllers/PampasanController.php | 5 + app/Palsu.php | 7 + ...092001_add_jenis_column_to_palsu_table.php | 68 +++++++++ ...jenis_to_pampasan_for_semporna_records.php | 78 +++++++++++ ...on_semporna_records_jenis_to_hapuskira.php | 130 ++++++++++++++++++ 6 files changed, 289 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2025_09_17_092001_add_jenis_column_to_palsu_table.php create mode 100644 database/migrations/2025_09_17_093116_update_jenis_to_pampasan_for_semporna_records.php create mode 100644 database/migrations/2025_09_17_093117_update_non_semporna_records_jenis_to_hapuskira.php diff --git a/app/Http/Controllers/BarangkesController.php b/app/Http/Controllers/BarangkesController.php index 603efb4..fed34b7 100644 --- a/app/Http/Controllers/BarangkesController.php +++ b/app/Http/Controllers/BarangkesController.php @@ -6,9 +6,9 @@ use App\Audit; use App\Polis; use App\Cawangan; use App\LookupAlasan; +use App\Gadai; use App\Pampasan; use App\Palsu; -use App\Gadai; use Illuminate\Http\Request; use Carbon\Carbon; diff --git a/app/Http/Controllers/PampasanController.php b/app/Http/Controllers/PampasanController.php index cdbeb86..1972c2a 100644 --- a/app/Http/Controllers/PampasanController.php +++ b/app/Http/Controllers/PampasanController.php @@ -70,6 +70,11 @@ class PampasanController extends Controller Palsu::on($cawangan['mysql']) ->where('norujukan', $norujukan) ->update(['status' => 1]); +<<<<<<< HEAD +======= + + // dd($pampasan); +>>>>>>> 83d619ac (Continue dev on pampasan module) return $this->successResponse('Status Pampasan berjaya dituntut.', $pampasan, 201); } diff --git a/app/Palsu.php b/app/Palsu.php index 00ce962..7defa11 100644 --- a/app/Palsu.php +++ b/app/Palsu.php @@ -32,6 +32,10 @@ class Palsu extends Model 'untungonepercent', 'untungcajlain', 'pembiayaan', +<<<<<<< HEAD +======= + 'jenis', +>>>>>>> 83d619ac (Continue dev on pampasan module) 'status', ]; @@ -95,9 +99,12 @@ class Palsu extends Model { return $this->hasOne(Tebus::class, 'norujukan', 'norujukan'); } +<<<<<<< HEAD public function gadai(): HasOne { return $this->hasOne(Gadai::class, 'norujukan', 'norujukan'); } +======= +>>>>>>> 83d619ac (Continue dev on pampasan module) } diff --git a/database/migrations/2025_09_17_092001_add_jenis_column_to_palsu_table.php b/database/migrations/2025_09_17_092001_add_jenis_column_to_palsu_table.php new file mode 100644 index 0000000..a9de2a2 --- /dev/null +++ b/database/migrations/2025_09_17_092001_add_jenis_column_to_palsu_table.php @@ -0,0 +1,68 @@ +select('SELECT 1'); + return true; + } catch (\Exception $e) { + return false; + } + }); + + return $db_connection ? array_values($db_connection) : []; + } + + /** + * Run the migrations. + * + * @return void + */ + 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', 'jenis')) { + $table->string('jenis', 50)->nullable()->comment('Jenis/Type classification'); + } + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + $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', 'jenis')) { + $table->dropColumn('jenis'); + } + }); + } + } +} diff --git a/database/migrations/2025_09_17_093116_update_jenis_to_pampasan_for_semporna_records.php b/database/migrations/2025_09_17_093116_update_jenis_to_pampasan_for_semporna_records.php new file mode 100644 index 0000000..424a87b --- /dev/null +++ b/database/migrations/2025_09_17_093116_update_jenis_to_pampasan_for_semporna_records.php @@ -0,0 +1,78 @@ +getSempornaRecords(); + + // Update jenis to 'pampasan' for Semporna records in mysql34 (Semporna branch) + try { + $updated = DB::connection('mysql34')->table('palsu') + ->whereIn('norujukan', $semporna_records) + ->update(['jenis' => 'pampasan']); + + echo "Updated {$updated} Semporna records with jenis = 'pampasan'\n"; + } catch (\Exception $e) { + echo "Error updating Semporna records: " . $e->getMessage() . "\n"; + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + $semporna_records = $this->getSempornaRecords(); + + // Revert jenis to null for Semporna records + try { + $reverted = DB::connection('mysql34')->table('palsu') + ->whereIn('norujukan', $semporna_records) + ->update(['jenis' => null]); + + echo "Reverted {$reverted} Semporna records jenis to null\n"; + } catch (\Exception $e) { + echo "Error reverting Semporna records: " . $e->getMessage() . "\n"; + } + } +} diff --git a/database/migrations/2025_09_17_093117_update_non_semporna_records_jenis_to_hapuskira.php b/database/migrations/2025_09_17_093117_update_non_semporna_records_jenis_to_hapuskira.php new file mode 100644 index 0000000..44594a3 --- /dev/null +++ b/database/migrations/2025_09_17_093117_update_non_semporna_records_jenis_to_hapuskira.php @@ -0,0 +1,130 @@ +select('SELECT 1'); + return true; + } catch (\Exception $e) { + return false; + } + }); + + return $db_connection ? array_values($db_connection) : []; + } + + /** + * Semporna norujukan records to exclude + */ + private function getSempornaRecords(): array + { + return [ + '011237240808-0003', + '011237240719-0015', + '011237240806-0011', + '011237240828-0001', + '011237240904-0007', + '011237240904-0008', + '011237240904-0009', + '011237240719-0023', + '011237240719-0024', + '011237240719-0025', + '011237240618-0026', + '011237240719-0027', + '011237240719-0028', + '011237240618-0020', + '011237240719-0030', + '011237240618-0029', + '011237240731-0026', + '011237240912-0009' + ]; + } + + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + $db_connection = $this->getActiveDB(); + $semporna_records = $this->getSempornaRecords(); + + foreach ($db_connection as $dbase) { + try { + if ($dbase == 'mysql34') { + // For Semporna (mysql34), update only non-Semporna records to 'hapuskira' + $updated = DB::connection($dbase)->table('palsu') + ->whereNotIn('norujukan', $semporna_records) + ->update(['jenis' => 'hapuskira']); + + if ($updated > 0) { + echo "Updated {$updated} non-Semporna records in {$dbase} to jenis = 'hapuskira'\n"; + } + } else { + // For all other databases, update all records to 'hapuskira' + $updated = DB::connection($dbase)->table('palsu') + ->update(['jenis' => 'hapuskira']); + + if ($updated > 0) { + echo "Updated {$updated} records in {$dbase} to jenis = 'hapuskira'\n"; + } + } + } catch (\Exception $e) { + echo "Error updating {$dbase}: " . $e->getMessage() . "\n"; + } + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + $db_connection = $this->getActiveDB(); + + foreach ($db_connection as $dbase) { + try { + // Revert all jenis values to null except Semporna records which should remain 'pampasan' + if ($dbase == 'mysql34') { + $semporna_records = $this->getSempornaRecords(); + $reverted = DB::connection($dbase)->table('palsu') + ->whereNotIn('norujukan', $semporna_records) + ->update(['jenis' => null]); + + if ($reverted > 0) { + echo "Reverted {$reverted} non-Semporna records in {$dbase} jenis to null\n"; + } + } else { + $reverted = DB::connection($dbase)->table('palsu') + ->update(['jenis' => null]); + + if ($reverted > 0) { + echo "Reverted {$reverted} records in {$dbase} jenis to null\n"; + } + } + } catch (\Exception $e) { + echo "Error reverting {$dbase}: " . $e->getMessage() . "\n"; + } + } + } +}