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 fa0d1e1467
commit 42bc78b366
5 changed files with 206 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Services\OnePercentServices;
class TestOnePercent extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'onepercent:test';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update JBG for every active gadai';
/**
* Create a new command instance.
*
* @return void
*/
protected $onepercentserv;
public function __construct(OnePercentServices $onepercentserv)
{
$this->onepercentserv = $onepercentserv;
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$pemb = $this->ask('Pembiayaan?');
$nm = $this->ask('Nilaimarhun?');
$ku = $this->ask('Kadarujrah?');
$marg = $this->ask('Margin?');
$test = $this->onepercentserv->kiraanKeuntunganSebenar($pemb,$nm,$ku,$marg);
dd($test);
return $test;
}
}
+2
View File
@@ -18,6 +18,8 @@ class Kernel extends ConsoleKernel
*/
protected $commands = [
Commands\DailyGadai::class,
Commands\TestOnePercent::class,
];
/**
+50
View File
@@ -0,0 +1,50 @@
<?php
namespace App\Services;
class OnePercentServices
{
protected $maks_margin = 80;
protected $one_percent = 1;
private function kiraanUjrah(float $nilaimarhun = 0.0,float $kadarujrah = 0.0,float $margin = 0.0){
//periksa adakah kadar ujrah ini diberi percentage
if($kadarujrah >= 1){
return;
}
$ujrah = ($kadarujrah/100) * $nilaimarhun;
$formula_margin = ($this->maks_margin - $margin) / $this->maks_margin;
$ujrah_margin = $formula_margin * $kadarujrah;
$rebate_ujrah = $nilaimarhun*($ujrah_margin/100);
$ujrah_sebenar = $ujrah - $rebate_ujrah;
return $ujrah_sebenar;
}
private function kiraanOnePercent(float $pembiayaan = 0.0){
//periksa adakah pembiayaan adalah null atau kosong.
if($pembiayaan == 0 || $pembiayaan == null)
return;
$onepercent = ($this->one_percent/100) * $pembiayaan;
return $onepercent;
}
public function kiraanKeuntunganSebenar(float $pembiayaan = 0.0,float $nilaimarhun = 0.0,float $kadarujrah = 0.0,float $margin = 0.0){
$onepercent = $this->kiraanOnePercent($pembiayaan);
$ujrah_sebenar = $this->kiraanUjrah($nilaimarhun,$kadarujrah,$margin);
$keuntungan = $onepercent + $ujrah_sebenar;
return ['keuntungan' => $keuntungan,'onepercent' => $onepercent, 'ujrah' => $ujrah_sebenar];
}
}
@@ -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');
}
}