1. added page for edit mutu
2. change from max pinjaman with a static 75% and 80% to manipulate value
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MaxMutuEmas extends Model
|
||||
{
|
||||
protected $table = 'max_mutuemas';
|
||||
protected $primaryKey = 'recno';
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'recno', 'karat', 'keterangan', 'teller', 'pc', 'operasi', 'tarikhupdate'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'teller' => 'decimal:2',
|
||||
'pc' => 'decimal:2',
|
||||
'operasi' => 'decimal:2',
|
||||
'tarikhupdate' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
// protected $hidden = [];
|
||||
}
|
||||
Reference in New Issue
Block a user