create nad update gadai table migration and add services class for one percent

This commit is contained in:
Hafifie PKB
2023-11-08 14:52:20 +08:00
parent 7921910c9a
commit c999d26886
5 changed files with 206 additions and 0 deletions
@@ -0,0 +1,64 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class AddOnepercentToGadaiTable 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('gadai', function (Blueprint $table) {
$table->decimal('kadarujrah', 5, 2);
$table->decimal('ujrah', 9, 2);
$table->decimal('onepercent', 9, 2);
$table->decimal('margin_semasa', 5, 2);
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$db_connection = $this->getActiveDB();
foreach($db_connection as $dbase){
Schema::connection($dbase)->table('gadai', function (Blueprint $table) {
// $table->dropColumn('votes');
$table->dropColumn(['kadarujrah', 'ujrah', 'onepercent','margin_semasa']);
});
}
}
}
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateHistoryOnepercentTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('history_onepercent', function (Blueprint $table) {
$table->id();
$table->decimal('tempoh', 10, 2);
$table->decimal('ujrah', 10, 2);
$table->decimal('onepercent', 10, 2);
$table->decimal('margin_semasa', 5, 2);
$table->decimal('bakipinjaman', 10, 2);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('history_onepercent');
}
}