8fe42c1d9f
- Replace hardcoded database names (online_arrahn, master_krk, kaunterpkb) with configurable values across the codebase - Rename tennant_master.php to tennant_database.php for clearer naming - Update config keys: 'database' → 'master_db', add 'kaunter_db' - Update env variables: TENNANT_MASTER_DB and TENNANT_KAUNTER_DB - Modify Helper.php to use dynamic database references in getOnlineArrahnConnection(), getActiveCawanganDbConnection(), and getInactiveCawanganDbConnection() methods - Update database JOIN queries in CustomerController and MarhunController to use config values instead of hardcoded database names - Simplify migration logic by removing redundant hardcoded database checks - Update debug messages in CawanganDebugConnections to show actual configured database name - Update bootstrap/app.php to load tennant_database config This change improves multi-environment flexibility and eliminates environment-specific hardcoded values, making the application more configurable for different deployment scenarios (KRK, KGMK, etc).
113 lines
3.4 KiB
PHP
113 lines
3.4 KiB
PHP
<?php
|
|
namespace App;
|
|
|
|
use DateTime;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class Helper
|
|
{
|
|
|
|
public static function getOnlineArrahnConnection()
|
|
{
|
|
|
|
$online_arrahn_connection = array_filter(config('database.connections'), function ($connection) {
|
|
if ($connection['database'] === config('tennant_database.master_db')) {
|
|
return $connection;
|
|
}
|
|
});
|
|
|
|
return array_keys($online_arrahn_connection)[0];
|
|
}
|
|
public static function formatNumber($amount)
|
|
{
|
|
$formattedAmount = number_format($amount, 2, '.', ',');
|
|
|
|
return $formattedAmount;
|
|
}
|
|
|
|
public static function formatDate($date_string)
|
|
{
|
|
return (new DateTime($date_string))->format("d-m-Y");
|
|
}
|
|
|
|
public static function getActiveCawanganDbConnection()
|
|
{
|
|
$queryActiveCawanganDbConnection = function () {
|
|
$all_active_db_keys = array_filter(array_keys(config('database.connections')), function ($connection) {
|
|
try {
|
|
DB::connection($connection)->getPdo();
|
|
return true;
|
|
} catch (\Throwable $th) {
|
|
return false;
|
|
}
|
|
});
|
|
|
|
$non_cawangan_database = ['lelong', config('tennant_database.master_db'), config('tennant_database.kaunter_db')];
|
|
|
|
$all_cawangan_db = array_filter($all_active_db_keys, function ($db_key) use ($non_cawangan_database) {
|
|
$isNotCawangan = in_array(config('database.connections.' . $db_key . '.database'), $non_cawangan_database);
|
|
|
|
if ($isNotCawangan) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
return $all_cawangan_db;
|
|
|
|
};
|
|
|
|
return $queryActiveCawanganDbConnection();
|
|
}
|
|
|
|
public static function getInactiveCawanganDbConnection()
|
|
{
|
|
$queryInactiveCawanganDbConnection = function () {
|
|
$all_inactive_db_keys = array_filter(array_keys(config('database.connections')), function ($connection) {
|
|
try {
|
|
DB::connection($connection)->getPdo();
|
|
return false;
|
|
} catch (\Throwable $th) {
|
|
return true;
|
|
}
|
|
});
|
|
|
|
$non_cawangan_database = ['lelong', config('tennant_database.master_db'), config('tennant_database.kaunter_db')];
|
|
|
|
$all_cawangan_db = array_filter($all_inactive_db_keys, function ($db_key) use ($non_cawangan_database) {
|
|
$isNotCawangan = in_array(config('database.connections.' . $db_key . '.database'), $non_cawangan_database);
|
|
$isNotCawanganKey = in_array($db_key, $non_cawangan_database);
|
|
|
|
if ($isNotCawangan OR $isNotCawanganKey) {
|
|
return false;
|
|
}
|
|
|
|
|
|
return true;
|
|
});
|
|
|
|
return $all_cawangan_db;
|
|
|
|
};
|
|
|
|
$all_cawangan_db_connection = array_map(function ($db_connection) {
|
|
return [
|
|
'connection' => $db_connection,
|
|
'database' => config('database.connections.' . $db_connection . '.database'),
|
|
];
|
|
}, $queryInactiveCawanganDbConnection());
|
|
|
|
return $all_cawangan_db_connection;
|
|
|
|
}
|
|
|
|
public static function getActiveCawangan() {
|
|
|
|
return Cawangan::whereIn('mysql', helper::getactivecawangandbconnection())->get();
|
|
|
|
}
|
|
|
|
}
|