diff --git a/app/Services/OnePercentServices.php b/app/Services/OnePercentServices.php index 71d39fd..6e8e834 100644 --- a/app/Services/OnePercentServices.php +++ b/app/Services/OnePercentServices.php @@ -21,7 +21,8 @@ class OnePercentServices $formula_margin = ($this->maks_margin - $margin) / $this->maks_margin; $ujrah_margin = $formula_margin * $kadarujrah; $rebate_ujrah = $nilaimarhun*($ujrah_margin/100); - $ujrah_sebenar = $ujrah; + // $ujrah_sebenar = $ujrah; + $ujrah_sebenar = $ujrah - $rebate_ujrah; return $ujrah_sebenar; } @@ -57,6 +58,9 @@ class OnePercentServices $onepercent = $this->kiraanOnePercent($pembiayaan); $ujrah_sebenar = $this->kiraanUjrahSebenar($nilaimarhun,$kadarujrah,$margin); + $onepercent = (!empty($onepercent)) ? $this->getRoundedMethod($onepercent) : 0; + $ujrah_sebenar = (!empty($ujrah_sebenar)) ? $this->getRoundedMethod($ujrah_sebenar) : 0; + $keuntungan = $onepercent + $ujrah_sebenar; return ['keuntungan' => $keuntungan,'onepercent' => $onepercent, 'ujrah' => $ujrah_sebenar]; @@ -67,6 +71,9 @@ class OnePercentServices $onepercent = $this->kiraanOnePercent($pembiayaan); $ujrah_sebenar = $this->kiraanUjrah($nilaimarhun,$kadarujrah,$margin); + $onepercent = (!empty($onepercent)) ? $this->getRoundedMethod($onepercent) : 0; + $ujrah_sebenar = (!empty($ujrah_sebenar)) ? $this->getRoundedMethod($ujrah_sebenar) : 0; + $keuntungan = $onepercent + $ujrah_sebenar; return ['keuntungan' => $keuntungan,'onepercent' => $onepercent, 'ujrah' => $ujrah_sebenar]; @@ -78,4 +85,26 @@ class OnePercentServices return isset($kadarujrah[0]) ? $kadarujrah[0]['kadarujrah'] : 0; } + + public function getRoundedMethod(float $number = 0.0) : Float{ + $number_string = number_format(floor($number * 100)/100,2); + + $rounded = substr($number_string, 0, -1); + $lastDigit = substr($number_string, -1); + + if ($lastDigit >= 0 && $lastDigit <= 2) { + if(strpos($rounded,',')){ + $rounded = str_replace(',','',$rounded); + } + return $rounded; + } elseif ($lastDigit >= 3 && $lastDigit <= 7) { + $rounded = $rounded . '5'; + if(strpos($rounded,',')){ + $rounded = str_replace(',','',$rounded); + } + return $rounded; + } else { + return round($number,PHP_ROUND_HALF_UP); + } + } }