From 42bc78b366d88b340662e9ce6e9420126905e41d Mon Sep 17 00:00:00 2001 From: Hafifie PKB Date: Wed, 8 Nov 2023 14:52:20 +0800 Subject: [PATCH] create nad update gadai table migration and add services class for one percent --- app/Console/Commands/TestOnePercent.php | 54 ++++++++++++++++ app/Console/Kernel.php | 2 + app/Services/OnePercentServices.php | 50 +++++++++++++++ ...8_115215_add_onepercent_to_gadai_table.php | 64 +++++++++++++++++++ ...143916_create_history_onepercent_table.php | 36 +++++++++++ 5 files changed, 206 insertions(+) create mode 100644 app/Console/Commands/TestOnePercent.php create mode 100644 app/Services/OnePercentServices.php create mode 100644 database/migrations/2023_11_08_115215_add_onepercent_to_gadai_table.php create mode 100644 database/migrations/2023_11_08_143916_create_history_onepercent_table.php diff --git a/app/Console/Commands/TestOnePercent.php b/app/Console/Commands/TestOnePercent.php new file mode 100644 index 0000000..5d8af0a --- /dev/null +++ b/app/Console/Commands/TestOnePercent.php @@ -0,0 +1,54 @@ +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; + } +} \ No newline at end of file diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index d5b505a..e18917f 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -18,6 +18,8 @@ class Kernel extends ConsoleKernel */ protected $commands = [ Commands\DailyGadai::class, + Commands\TestOnePercent::class, + ]; /** diff --git a/app/Services/OnePercentServices.php b/app/Services/OnePercentServices.php new file mode 100644 index 0000000..271d316 --- /dev/null +++ b/app/Services/OnePercentServices.php @@ -0,0 +1,50 @@ += 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]; + } +} diff --git a/database/migrations/2023_11_08_115215_add_onepercent_to_gadai_table.php b/database/migrations/2023_11_08_115215_add_onepercent_to_gadai_table.php new file mode 100644 index 0000000..0a346ee --- /dev/null +++ b/database/migrations/2023_11_08_115215_add_onepercent_to_gadai_table.php @@ -0,0 +1,64 @@ +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']); + }); + } + } +} diff --git a/database/migrations/2023_11_08_143916_create_history_onepercent_table.php b/database/migrations/2023_11_08_143916_create_history_onepercent_table.php new file mode 100644 index 0000000..9854de5 --- /dev/null +++ b/database/migrations/2023_11_08_143916_create_history_onepercent_table.php @@ -0,0 +1,36 @@ +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'); + } +}