Menambahkan function formatTanggalIndonesia dan formatRupiah di Helper di Module LPJ

This commit is contained in:
2024-10-16 08:55:58 +07:00
parent 03c96af9c5
commit 8cfe31cb8b
2 changed files with 42 additions and 41 deletions

View File

@@ -1,10 +1,41 @@
<?php <?php
function formatAlamat($alamat) { use Carbon\Carbon;
return
($alamat->address ? $alamat->address . ', ' : '') . function formatTanggalIndonesia($date)
(isset($alamat->village) ? $alamat->village->name.', ' : '') . {
(isset($alamat->city) ? $alamat->city->name.', ' : '') . $carbonDate = Carbon::parse($date);
(isset($alamat->province) ? $alamat->province->name.', ' : '') . $indonesianMonths = [
($alamat->postal_code ?? ''); 'Januari',
} 'Februari',
'Maret',
'April',
'Mei',
'Juni',
'Juli',
'Agustus',
'September',
'Oktober',
'November',
'Desember',
];
$month = $indonesianMonths[$carbonDate->month - 1];
return $carbonDate->format('d') . ' ' . $month . ' ' . $carbonDate->format('Y');
}
function formatRupiah($number)
{
$number = (float) $number;
return 'Rp ' . number_format($number, 2, ',', '.');
}
function formatAlamat($alamat)
{
return ($alamat->address ? $alamat->address . ', ' : '') .
(isset($alamat->village) ? $alamat->village->name . ', ' : '') .
(isset($alamat->city) ? $alamat->city->name . ', ' : '') .
(isset($alamat->province) ? $alamat->province->name . ', ' : '') .
($alamat->postal_code ?? '');
}

View File

@@ -1,35 +1,3 @@
@php
function formatTanggalIndonesia($date)
{
$carbonDate = \Carbon\Carbon::parse($date);
$indonesianMonths = [
'Januari',
'Februari',
'Maret',
'April',
'Mei',
'Juni',
'Juli',
'Agustus',
'September',
'Oktober',
'November',
'Desember',
];
$month = $indonesianMonths[$carbonDate->month - 1];
return $carbonDate->format('d') . ' ' . $month . ' ' . $carbonDate->format('Y');
}
function formatRupiah($number)
{
// Convert to float if the input is a string
$number = (float) $number;
return 'Rp ' . number_format($number, 2, ',', '.');
}
@endphp
@extends('layouts.main') @extends('layouts.main')
@section('breadcrumbs') @section('breadcrumbs')
@@ -199,4 +167,6 @@
</div> </div>
</div> </div>
</div> </div>
@endsection </div>
</div>
@endsection