Ejemplo n.º 1
0
function price_format($a, $status = true)
{
    // masuk 500000 ,, keluar jadi Rp. 500.000
    $pengaturan = Pengaturan::where('akunId', '=', Session::get('akunid'))->remember(1)->first();
    if ($pengaturan->checkoutType != 2) {
        $string = $a . "";
        $tempKoma = "";
        if (strpos($string, ".") != false) {
            $posKoma = strpos($string, ".");
            $tempKoma = substr($string, $posKoma);
            $tempKoma = str_replace(".", ",", $tempKoma);
            $tempKoma = substr($tempKoma, 0, 3);
            $string = substr($string, 0, strpos($string, "."));
        }
        $jumDot = intval(strlen($string) / 3);
        if (strlen($string) % 3 == 0) {
            $jumDot = $jumDot - 1;
        }
        $aha = 0;
        for ($i = 0; $i < $jumDot; $i++) {
            $part[$i] = substr($string, strlen($string) - 3);
            $string = substr($string, 0, strlen($string) - 3);
            $aha++;
        }
        $temp = $string;
        $string = "";
        for ($i = 0; $i < $jumDot; $i++) {
            $string = "." . $part[$i] . $string;
        }
        $currencies = Currencies::remember(1)->find($pengaturan->mataUang);
        $string = ucfirst($currencies->symbol) . ' ' . $temp . $string;
        if ($status == true) {
            if ($string != ucfirst($currencies->symbol) . " 0") {
                return $string;
            } else {
                $string = ucfirst($currencies->symbol) . ' 0';
                return $string;
            }
        } else {
            if ($status == false) {
                return '';
            }
        }
    } else {
        return '';
    }
}