diff --git a/app/Http/Controllers/MaxPinjamanController.php b/app/Http/Controllers/MaxPinjamanController.php index 734d04b..540abe7 100644 --- a/app/Http/Controllers/MaxPinjamanController.php +++ b/app/Http/Controllers/MaxPinjamanController.php @@ -2,14 +2,117 @@ namespace App\Http\Controllers; +use App\MaxMutuEmas; use App\MaxPinjaman; use Illuminate\Http\Request; class MaxPinjamanController extends Controller { - public function getAllMaxPinjaman(){ - $pinjaman = MaxPinjaman::on('mysql7')->get(); + public function getAllMaxPinjaman(Request $request) + { + if (config('parameter.max_mutuemas')) { + $data = MaxMutuEmas::on('mysql7')->select('karat', 'teller', 'pc', 'operasi')->get(); + $calculateMargin = $this->calculateMaxPinjamanMutu($data, $request->mutu,$request->total_nilai_marhun); + + $pinjaman = [ + [ + "user_type" => "teller", + "max" => $calculateMargin['teller'] + ], + [ + "user_type" => "khazanah", + "max" => $calculateMargin['pc'] + ], + [ + "user_type" => "operasi", + "max" => $calculateMargin['operasi'] + ] + ]; + } else { + $pinjaman = MaxPinjaman::on('mysql7')->get(); + } return response()->json($pinjaman); } + + public function calculateMaxPinjamanMutu($data, $mutu,$totalMarhun) + { + $totalMaxPC = 0; + $totalMaxTeller = 0; + $totalMaxOperasi = 0; + + if($mutu == null || $totalMarhun == 0){ + return [ + "pc" => 0, + "teller" => 0, + "operasi" => 0 + ]; + } + $mutuKarat = array_map(function($item) { + return $item[0]; + }, $mutu); + $mutuNilai = array_map(function($item) { + return $item[1]; + }, $mutu); + + foreach($mutuKarat as $index => $karat){ + $margin = $data->where('karat', $karat)->first(); + if($margin){ + $nilai = $mutuNilai[$index]; + $totalMaxPC += ($margin->pc/100) * $nilai; + $totalMaxTeller += ($margin->teller/100) * $nilai; + $totalMaxOperasi += ($margin->operasi/100) * $nilai; + } + } + $totalMaxPC = $totalMarhun > 0 ? ($totalMaxPC / $totalMarhun) * 100 : 0; + $totalMaxTeller = $totalMarhun > 0 ? ($totalMaxTeller / $totalMarhun) * 100 : 0; + $totalMaxOperasi = $totalMarhun > 0 ? ($totalMaxOperasi / $totalMarhun) * 100 : 0; + + + return [ + "pc" => round($totalMaxPC,2), + "teller" => round($totalMaxTeller,2), + "operasi" => round($totalMaxOperasi,2) + ]; + } + + + public function getAllMaxMutuEmas(Request $request) + { + $maxmutuemas = MaxMutuEmas::on('mysql7')->get(); + return response()->json($maxmutuemas); + } + + public function updateMaxMutuEmas(Request $request) + { + $recno = $request->recno; + $karat = $request->karat; + $keterangan = $request->keterangan; + $teller = $request->teller; + $pc = $request->pc; + $operasi = $request->operasi; + + $maxmutuemas = MaxMutuEmas::on('mysql7')->where('recno', $recno)->first(); + + if ($maxmutuemas) { + $maxmutuemas->karat = $karat; + $maxmutuemas->keterangan = $keterangan; + $maxmutuemas->teller = $teller; + $maxmutuemas->pc = $pc; + $maxmutuemas->operasi = $operasi; + $maxmutuemas->tarikhupdate = \Carbon\Carbon::now(); + $maxmutuemas->save(); + + return response()->json([ + 'status' => 'success', + 'message' => 'Max Mutu Emas updated successfully', + 'data' => $maxmutuemas + ]); + } else { + return response()->json([ + 'status' => 'error', + 'message' => 'Record not found' + ], 404); + } + } } \ No newline at end of file diff --git a/app/MaxMutuEmas.php b/app/MaxMutuEmas.php new file mode 100644 index 0000000..4512185 --- /dev/null +++ b/app/MaxMutuEmas.php @@ -0,0 +1,40 @@ + 'decimal:2', + 'pc' => 'decimal:2', + 'operasi' => 'decimal:2', + 'tarikhupdate' => 'datetime', + ]; + + /** + * The attributes excluded from the model's JSON form. + * + * @var array + */ + // protected $hidden = []; +} \ No newline at end of file diff --git a/bootstrap/app.php b/bootstrap/app.php index 16b5e30..d358544 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -64,7 +64,7 @@ $app->configure('tinker'); $app->configure('tennant_database'); $app->configure('report'); $app->configure('app_parameter'); - +$app->configure('parameter'); /* |-------------------------------------------------------------------------- | Register Middleware diff --git a/config/parameter.php b/config/parameter.php new file mode 100644 index 0000000..8af8857 --- /dev/null +++ b/config/parameter.php @@ -0,0 +1,5 @@ + env('MAX_MUTUEMAS', true), +]; \ No newline at end of file diff --git a/database/migrations/2026_02_12_144445_create_max_mutuemas_table.php b/database/migrations/2026_02_12_144445_create_max_mutuemas_table.php new file mode 100644 index 0000000..718a8fb --- /dev/null +++ b/database/migrations/2026_02_12_144445_create_max_mutuemas_table.php @@ -0,0 +1,140 @@ +id('recno'); + $table->string('karat'); + $table->string('keterangan'); + $table->decimal('teller', 8, 2); + $table->decimal('pc', 8, 2); + $table->decimal('operasi', 8, 2); + $table->timestamp('tarikhupdate'); + }); + + // Insert data + DB::table('max_mutuemas')->insert([ + [ + 'recno' => 1, + 'karat' => '24.0Kgb', + 'keterangan' => '999 gb', + 'teller' => 75.00000, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 2, + 'karat' => '24.0K', + 'keterangan' => '999', + 'teller' => 75.00000, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 3, + 'karat' => '23.0K', + 'keterangan' => '950', + 'teller' => 74.00000, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 4, + 'karat' => '22.0K', + 'keterangan' => '916', + 'teller' => 73.66667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 5, + 'karat' => '21.0K', + 'keterangan' => '900', + 'teller' => 73.16667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 6, + 'karat' => '20.0K', + 'keterangan' => '835', + 'teller' => 72.66667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 7, + 'karat' => '18.0Kp', + 'keterangan' => '750', + 'teller' => 72.16667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 8, + 'karat' => '18.0K', + 'keterangan' => '750', + 'teller' => 71.66667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 21, + 'karat' => '14.0K', + 'keterangan' => '585', + 'teller' => 71.16667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 22, + 'karat' => '14.0Kp', + 'keterangan' => '585', + 'teller' => 70.66667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 23, + 'karat' => '9.0K', + 'keterangan' => '375', + 'teller' => 70.16667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + ]); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('max_mutuemas'); + } +} \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 2c3c1be..1faced3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -262,6 +262,8 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->get('maxpinjaman',['uses'=>'MaxPinjamanController@getAllMaxPinjaman']); + $router->get('maxmutuemas',['uses'=>'MaxPinjamanController@getAllMaxMutuEmas']); + $router->post('maxmutuemas/update',['uses'=>'MaxPinjamanController@updateMaxMutuEmas']); $router->get('transaksi_keuntungan/{norujukan}',['uses'=>'TransaksiKeuntunganController@getTransaksiKeuntunganByRujukan']); $router->get('transaksi_keuntungan_latest/{norujukan}',['uses'=>'TransaksiKeuntunganController@getTransaksiKeuntunganByRujukanLatest']);