refactor(helpers, forms, livewire): Rename functions for clarity and consistency, update currency and date formatting across various components to improve maintainability and user experience.

This commit is contained in:
Yoga Pangestu 2025-12-14 15:49:53 +07:00
parent 6a16a306e9
commit a7427f145f
61 changed files with 263 additions and 300 deletions

View File

@ -8,6 +8,7 @@
enum Gender: int
{
use WithCommentEnum, WithValueEnum;
case MALE = 1;
case FEMALE = 2;

View File

@ -1,13 +1,13 @@
<?php
if (! function_exists('randomColors')) {
if (! function_exists('generateRandomRgbaColors')) {
/**
* Generate an array of random RGBA colors
*
* @param int $count Number of colors to generate
* @param float $alpha Alpha/transparency value (default: 0.2)
*/
function randomColors(int $count, float $alpha = 0.2): array
function generateRandomRgbaColors(int $count, float $alpha = 0.2): array
{
$colors = [];
for ($i = 0; $i < $count; $i++) {
@ -29,6 +29,6 @@ function randomColors(int $count, float $alpha = 0.2): array
*/
function randomBorderColors(int $count): array
{
return randomColors($count, 1.0);
return generateRandomRgbaColors($count, 1.0);
}
}

View File

@ -2,15 +2,15 @@
use Carbon\Carbon;
if (! function_exists('formatDate')) {
if (! function_exists('formatDateLocalized')) {
/**
* Format date/time with a configurable format using Carbon.
* Core formatting function used by formatTime() and formatDateTime().
* Core formatting function used by formatTime() and formatDateTimeLocalized().
*
* @param string $format Carbon format (default: 'l, d M Y')
* @param bool $translated Use translatedFormat for locale-aware output (default: true)
*/
function formatDate(?string $date = null, string $format = 'l, d M Y', bool $translated = true): string
function formatDateLocalized(?string $date = null, string $format = 'l, d M Y', bool $translated = true): string
{
if (! $date) {
return '-';
@ -24,34 +24,34 @@ function formatDate(?string $date = null, string $format = 'l, d M Y', bool $tra
if (! function_exists('formatTime')) {
/**
* Format time only (convenience wrapper for formatDate with time format).
* Format time only (convenience wrapper for formatDateLocalized with time format).
*
* @param string $format Carbon format (default: 'H:i')
*/
function formatTime(?string $time = null, string $format = 'H:i'): string
{
return formatDate($time, $format, false);
return formatDateLocalized($time, $format, false);
}
}
if (! function_exists('formatDateTime')) {
if (! function_exists('formatDateTimeLocalized')) {
/**
* Format date and time (convenience wrapper for formatDate with datetime format).
* Format date and time (convenience wrapper for formatDateLocalized with datetime format).
*
* @param string $format Carbon format (default: 'l, d M Y H:i:s')
*/
function formatDateTime(?string $dateTime = null, string $format = 'l, d M Y H:i:s'): string
function formatDateTimeLocalized(?string $dateTime = null, string $format = 'l, d M Y H:i:s'): string
{
return formatDate($dateTime, $format);
return formatDateLocalized($dateTime, $format);
}
}
if (! function_exists('getAge')) {
if (! function_exists('formatAgeYearsMonths')) {
/**
* Calculate age from birthdate using Carbon.
* Returns formatted string in Indonesian (e.g. "25 tahun 3 bulan").
*/
function getAge(?string $birthdate = null): string
function formatAgeYearsMonths(?string $birthdate = null): string
{
if (! $birthdate) {
return '-';
@ -65,12 +65,12 @@ function getAge(?string $birthdate = null): string
}
}
if (! function_exists('timeAgo')) {
if (! function_exists('formatRelativeTime')) {
/**
* Get relative time string using Carbon's diffForHumans().
* Returns localized relative time (e.g. "2 hours ago", "3 days ago").
*/
function timeAgo(?string $date = null): string
function tmeAgo(?string $date = null): string
{
if (! $date) {
return '-';

View File

@ -4,14 +4,14 @@
use Illuminate\Support\Number;
use Illuminate\Support\Str;
if (! function_exists('currency')) {
if (! function_exists('formatCurrencyNumber')) {
/**
* Format value as currency
*
* @param string|null $currency Currency prefix (default: null)
* @param string $locale Locale for formatting (default: 'id_ID')
*/
function currency(string|int|float|null $value = null, ?string $currency = null, string $locale = 'id_ID'): string
function formatCurrencyNumber(string|int|float|null $value = null, ?string $currency = null, string $locale = 'id_ID'): string
{
if ($value === null) {
return '';
@ -21,11 +21,11 @@ function currency(string|int|float|null $value = null, ?string $currency = null,
}
}
if (! function_exists('replaceCurrency')) {
if (! function_exists('parseRupiahToInt')) {
/**
* Strip currency format from string and return as integer
*/
function replaceCurrency(?string $value = null): ?int
function parseRupiahToInt(?string $value = null): ?int
{
if ($value === null) {
return null;
@ -41,7 +41,7 @@ function replaceCurrency(?string $value = null): ?int
}
}
if (! function_exists('percentage')) {
if (! function_exists('formatPercentage')) {
/**
* Format value as percentage
*
@ -49,7 +49,7 @@ function replaceCurrency(?string $value = null): ?int
* @param int $maxPrecision Max precision (default: 2)
* @param string $locale Locale for formatting (default: 'id_ID')
*/
function percentage(int|float $value, int $precision = 2, int $maxPrecision = 2, string $locale = 'id_ID'): string
function formatPercentage(int|float $value, int $precision = 2, int $maxPrecision = 2, string $locale = 'id_ID'): string
{
return Number::percentage($value, $precision, $maxPrecision, $locale);
}
@ -62,8 +62,8 @@ function percentage(int|float $value, int $precision = 2, int $maxPrecision = 2,
function formatDiscount(int|float $amount, VoucherType $type, string $currency = 'Rp'): string
{
return $type === VoucherType::PERCENTAGE
? percentage($amount)
: currency($amount, $currency);
? formatPercentage($amount)
: formatCurrencyNumber($amount, $currency);
}
}
@ -80,49 +80,8 @@ function generateReferralCode(string $username, int $unique): string
}
}
if (! function_exists('sanitizeIntegers')) {
/**
* Sanitize integer values in an array (convert empty string/null to 0)
*
* @param array $integerKeys Keys to sanitize (empty = all keys)
*/
function sanitizeIntegers(array $data, array $integerKeys = []): array
{
foreach ($data as $key => $value) {
if (empty($integerKeys) || in_array($key, $integerKeys)) {
if ($value === '' || $value === null) {
$data[$key] = 0;
}
}
}
return $data;
}
}
if (! function_exists('formatPhoneNumber')) {
/**
* Format Indonesian phone number with customizable country prefix
*
* @param string $prefix Country prefix (default: '+62')
* @param bool $useDash Use dashes for formatting (default: false)
*/
function formatPhoneNumber(string $number, string $prefix = '+62', bool $useDash = false): string
{
$clean = preg_replace('/\D+/', '', $number);
$clean = preg_replace('/^(0|62)/', '', $clean);
$formatted = $prefix.$clean;
if ($useDash) {
$formatted = preg_replace('/(\d{3})(\d{3,4})(\d{3,4})(\d+)?/', $prefix.'-$1-$2-$3$4', $formatted);
}
return $formatted;
}
}
if (! function_exists('terbilang')) {
function terbilang($angka)
if (! function_exists('convertNumberToIndonesianWords')) {
function convertNumberToIndonesianWords($angka)
{
$angka = (int) abs($angka);
$huruf = ['', 'satu', 'dua', 'tiga', 'empat', 'lima', 'enam', 'tujuh', 'delapan', 'sembilan', 'sepuluh', 'sebelas'];
@ -140,46 +99,46 @@ function terbilang($angka)
return $result;
} elseif ($angka < 200) {
return 'seratus '.terbilang($angka - 100);
return 'seratus '.convertNumberToIndonesianWords($angka - 100);
} elseif ($angka < 1000) {
$result = $huruf[$angka / 100].' ratus';
$sisa = $angka % 100;
if ($sisa > 0) {
$result .= ' '.terbilang($sisa);
$result .= ' '.convertNumberToIndonesianWords($sisa);
}
return $result;
} elseif ($angka < 2000) {
return 'seribu '.terbilang($angka - 1000);
return 'seribu '.convertNumberToIndonesianWords($angka - 1000);
} elseif ($angka < 1000000) {
$result = terbilang($angka / 1000).' ribu';
$result = convertNumberToIndonesianWords($angka / 1000).' ribu';
$sisa = $angka % 1000;
if ($sisa > 0) {
$result .= ' '.terbilang($sisa);
$result .= ' '.convertNumberToIndonesianWords($sisa);
}
return $result;
} elseif ($angka < 1000000000) {
$result = terbilang($angka / 1000000).' juta';
$result = convertNumberToIndonesianWords($angka / 1000000).' juta';
$sisa = $angka % 1000000;
if ($sisa > 0) {
$result .= ' '.terbilang($sisa);
$result .= ' '.convertNumberToIndonesianWords($sisa);
}
return $result;
} elseif ($angka < 1000000000000) {
$result = terbilang($angka / 1000000000).' milyar';
$result = convertNumberToIndonesianWords($angka / 1000000000).' milyar';
$sisa = $angka % 1000000000;
if ($sisa > 0) {
$result .= ' '.terbilang($sisa);
$result .= ' '.convertNumberToIndonesianWords($sisa);
}
return $result;
} elseif ($angka < 1000000000000000) {
$result = terbilang($angka / 1000000000000).' trilyun';
$result = convertNumberToIndonesianWords($angka / 1000000000000).' trilyun';
$sisa = $angka % 1000000000000;
if ($sisa > 0) {
$result .= ' '.terbilang($sisa);
$result .= ' '.convertNumberToIndonesianWords($sisa);
}
return $result;

View File

@ -37,8 +37,8 @@ public function mount(array $outlets)
// random colors
$count = count(OrderChannel::cases());
$this->backgroundColors = randomColors($count, 0.2);
$this->borderColors = randomColors($count, 1.0);
$this->backgroundColors = generateRandomRgbaColors($count, 0.2);
$this->borderColors = generateRandomRgbaColors($count, 1.0);
}
public function render()

View File

@ -39,8 +39,8 @@ public function mount(array $outlets)
// random colors
$count = count($this->outlets);
$this->backgroundColors = randomColors($count, 0.2);
$this->borderColors = randomColors($count, 1.0);
$this->backgroundColors = generateRandomRgbaColors($count, 0.2);
$this->borderColors = generateRandomRgbaColors($count, 1.0);
}
public function render()

View File

@ -29,8 +29,8 @@ public function mount(array $outlets)
// random colors
$count = count($this->outlets);
$this->backgroundColors = randomColors($count, 0.2);
$this->borderColors = randomColors($count, 1.0);
$this->backgroundColors = generateRandomRgbaColors($count, 0.2);
$this->borderColors = generateRandomRgbaColors($count, 1.0);
}
public function render()

View File

@ -50,10 +50,10 @@ public function columns(): array
Column::make('Harga Beli', 'cost_price')
->label(function ($row) use ($canSeePrice) {
if ($canSeePrice) {
return currency($row->cost_price, 'Rp');
return formatCurrencyNumber($row->cost_price, 'Rp');
}
$masked = Str::mask(currency($row->cost_price, 'Rp'), '*', 2);
$masked = Str::mask(formatCurrencyNumber($row->cost_price, 'Rp'), '*', 2);
return Blade::render('
<flux:modal.trigger name="show-price">
@ -69,7 +69,7 @@ public function columns(): array
->hideIf(! auth()->user()->hasRole(['Developer', 'Owner'])),
Column::make('Harga Jual', 'sale_price')
->label(fn ($row, $column) => currency($row->sale_price, 'Rp'))
->label(fn ($row, $column) => formatCurrencyNumber($row->sale_price, 'Rp'))
->searchable()
->sortable(),
@ -88,7 +88,7 @@ public function columns(): array
'id' => $outlet->hash,
'bottle_id' => $row->hash,
'name' => $outlet->name,
'stock' => currency($outlet->pivot->stock, ''),
'stock' => formatCurrencyNumber($outlet->pivot->stock, ''),
])->toArray()
)
->outputFormat(function ($index, $value) {

View File

@ -60,10 +60,10 @@ public function columns(): array
Column::make('Harga Beli', 'cost_price')
->label(function ($row) use ($canSeePrice) {
if ($canSeePrice) {
return currency($row->cost_price, 'Rp');
return formatCurrencyNumber($row->cost_price, 'Rp');
}
$masked = Str::mask(currency($row->cost_price, 'Rp'), '*', 2);
$masked = Str::mask(formatCurrencyNumber($row->cost_price, 'Rp'), '*', 2);
return Blade::render('
<flux:modal.trigger name="show-price">
@ -79,7 +79,7 @@ public function columns(): array
->hideIf(! auth()->user()->hasRole(['Developer', 'Owner'])),
Column::make('Harga Jual', 'sale_price')
->label(fn ($row, $column) => currency($row->sale_price, 'Rp'))
->label(fn ($row, $column) => formatCurrencyNumber($row->sale_price, 'Rp'))
->searchable()
->sortable(),
@ -91,7 +91,7 @@ public function columns(): array
'id' => $outlet->hash,
'perfume_id' => $row->hash,
'name' => $outlet->name,
'stock' => currency($outlet->pivot->stock, ''),
'stock' => formatCurrencyNumber($outlet->pivot->stock, ''),
])->toArray()
)
->outputFormat(function ($index, $value) {

View File

@ -49,10 +49,10 @@ public function columns(): array
Column::make('Harga Beli', 'cost_price')
->label(function ($row) use ($canSeePrice) {
if ($canSeePrice) {
return currency($row->cost_price, 'Rp');
return formatCurrencyNumber($row->cost_price, 'Rp');
}
$masked = Str::mask(currency($row->cost_price, 'Rp'), '*', 2);
$masked = Str::mask(formatCurrencyNumber($row->cost_price, 'Rp'), '*', 2);
return Blade::render('
<flux:modal.trigger name="show-price">
@ -68,7 +68,7 @@ public function columns(): array
->hideIf(! auth()->user()->hasRole(['Developer', 'Owner'])),
Column::make('Harga Jual', 'sale_price')
->label(fn ($row, $column) => currency($row->sale_price, 'Rp'))
->label(fn ($row, $column) => formatCurrencyNumber($row->sale_price, 'Rp'))
->searchable()
->sortable(),
@ -80,7 +80,7 @@ public function columns(): array
'id' => $outlet->hash,
'product_id' => $row->hash,
'name' => $outlet->name,
'stock' => currency($outlet->pivot->stock, ''),
'stock' => formatCurrencyNumber($outlet->pivot->stock, ''),
])->toArray()
)
->outputFormat(function ($index, $value) {

View File

@ -25,14 +25,14 @@ public function columns(): array
Column::make('Keterangan', 'description')->searchable(),
Column::make('Jumlah', 'amount')
->format(fn ($value) => currency($value, 'Rp'))
->format(fn ($value) => formatCurrencyNumber($value, 'Rp'))
->searchable(),
Column::make('Outlet', 'outlet.name')
->searchable(),
Column::make('Tanggal', 'created_at')
->format(fn ($value) => formatDateTime($value))
->format(fn ($value) => formatDateTimeLocalized($value))
->searchable(),
Column::make('Aksi')

View File

@ -25,23 +25,23 @@ public function columns(): array
Column::make('Pegawai', 'user.employee.full_name')->searchable(),
Column::make('Bulan', 'period_month')
->format(fn ($value) => formatDate($value, 'F Y'))
->format(fn ($value) => formatDateLocalized($value, 'F Y'))
->searchable(),
Column::make('Gaji Pokok', 'base_salary')
->format(fn ($value) => currency($value, 'Rp'))
->format(fn ($value) => formatCurrencyNumber($value, 'Rp'))
->searchable(),
Column::make('Bonus', 'bonus')
->format(fn ($value) => currency($value, 'Rp'))
->format(fn ($value) => formatCurrencyNumber($value, 'Rp'))
->searchable(),
Column::make('Potongan', 'deduction')
->format(fn ($value) => currency($value, 'Rp'))
->format(fn ($value) => formatCurrencyNumber($value, 'Rp'))
->searchable(),
Column::make('Total Gaji', 'total_salary')
->format(fn ($value) => currency($value, 'Rp'))
->format(fn ($value) => formatCurrencyNumber($value, 'Rp'))
->searchable(),
ArrayColumn::make('Rincian')
@ -50,7 +50,7 @@ public function columns(): array
->where('payroll_id', $row->id)
->map(fn ($item) => [
'color' => $item->type->value == SalaryAdjustmentType::DEDUCTION->value ? 'text-red-500' : 'text-green-500',
'amount' => currency($item->amount, 'Rp'),
'amount' => formatCurrencyNumber($item->amount, 'Rp'),
'description' => $item->description,
'id' => $item->id,
])->toArray()
@ -74,7 +74,7 @@ public function columns(): array
{{ $row->is_paid->label() }}
</flux:badge>
<span class="text-xs text-gray-400">
{{ $row->paid_at ? formatDateTime($row->paid_at) : "-" }}
{{ $row->paid_at ? formatDateTimeLocalized($row->paid_at) : "-" }}
</span>
</div>
', ['row' => $row]))

View File

@ -33,11 +33,11 @@ public function columns(): array
Column::make('Tanggal')
->label(function ($row) {
$startDate = formatDate($row->created_at);
$startAgo = timeAgo($row->created_at);
$startDate = formatDateLocalized($row->created_at);
$startAgo = formatRelativeTime($row->created_at);
$endDate = formatDate($row->finalized_at);
$endAgo = timeAgo($row->finalized_at);
$endDate = formatDateLocalized($row->finalized_at);
$endAgo = formatRelativeTime($row->finalized_at);
return <<<HTML
<div class="flex flex-col text-xs text-gray-700 dark:text-gray-300 gap-0.5">

View File

@ -47,12 +47,12 @@ public function columns(): array
CountColumn::make('Total Order')
->setDataSource('orders')
->label(fn ($value) => currency($value->orders_count))
->label(fn ($value) => formatCurrencyNumber($value->orders_count))
->sortable(),
SumColumn::make('Total Pembayaran')
->setDataSource('orders', 'total')
->label(fn ($value) => currency($value->orders_sum_total, 'Rp'))
->label(fn ($value) => formatCurrencyNumber($value->orders_sum_total, 'Rp'))
->sortable(),
Column::make('Terakhir Order')
@ -60,12 +60,12 @@ public function columns(): array
$latestOrder = $record->orders()->latest()->first();
return $latestOrder
? timeAgo($latestOrder->created_at)
? formatRelativeTime($latestOrder->created_at)
: '';
}),
Column::make('Terdaftar Sejak', 'created_at')
->format(fn ($value) => $value ? timeAgo($value) : '')
->format(fn ($value) => $value ? formatRelativeTime($value) : '')
->searchable()
->sortable(),

View File

@ -41,7 +41,7 @@ public function columns(): array
->sortable(),
Column::make('Min. Belanja', 'min_purchase')
->format(fn ($value) => currency($value, 'Rp'))
->format(fn ($value) => formatCurrencyNumber($value, 'Rp'))
->searchable()
->sortable(),
@ -51,17 +51,17 @@ public function columns(): array
->sortable(),
Column::make('Maks. Diskon')
->label(fn ($row, $column) => currency($row->max_discount, 'Rp'))
->label(fn ($row, $column) => formatCurrencyNumber($row->max_discount, 'Rp'))
->searchable()
->sortable(),
Column::make('Kuota', 'quota')
->format(fn ($value) => $value ? currency($value) : 'Tidak Terbatas')
->format(fn ($value) => $value ? formatCurrencyNumber($value) : 'Tidak Terbatas')
->searchable()
->sortable(),
Column::make('Sisa Voucher', 'available_count')
->format(fn ($value) => $value ? currency($value) : 'Tidak Terbatas')
->format(fn ($value) => $value ? formatCurrencyNumber($value) : 'Tidak Terbatas')
->searchable()
->sortable(),
@ -74,7 +74,7 @@ public function columns(): array
->data(
fn ($value, $row) => $row->outlets->map(fn ($outlet) => [
'name' => $outlet->name,
'stock' => currency($outlet->pivot->stock, ''),
'stock' => formatCurrencyNumber($outlet->pivot->stock, ''),
])->toArray()
)
->outputFormat(fn ($index, $value) => Blade::render('
@ -85,11 +85,11 @@ public function columns(): array
Column::make('Tanggal')
->label(function ($row) {
$startDate = formatDate($row->start_date);
$startAgo = timeAgo($row->start_date);
$startDate = formatDateLocalized($row->start_date);
$startAgo = formatRelativeTime($row->start_date);
$endDate = formatDate($row->end_date);
$endAgo = timeAgo($row->end_date);
$endDate = formatDateLocalized($row->end_date);
$endAgo = formatRelativeTime($row->end_date);
return <<<HTML
<div class="flex flex-col text-xs text-gray-700 dark:text-gray-300 gap-0.5">

View File

@ -32,11 +32,11 @@ public function columns(): array
->html(),
Column::make('Waktu Publish', 'published_at')
->format(fn ($value) => formatDateTime($value))
->format(fn ($value) => formatDateTimeLocalized($value))
->searchable(),
Column::make('Dilihat', 'views')
->format(fn ($value) => currency($value))
->format(fn ($value) => formatCurrencyNumber($value))
->searchable()
->sortable(),

View File

@ -43,20 +43,20 @@ public function columns(): array
->html(),
Column::make('Tanggal', 'ordered_at')
->format(fn ($value) => formatDate($value))
->format(fn ($value) => formatDateLocalized($value))
->searchable(),
Column::make('HPP', 'cogs')
->format(fn ($value) => currency($value, 'Rp'))
->format(fn ($value) => formatCurrencyNumber($value, 'Rp'))
->searchable(),
ArrayColumn::make('Item')
->data(
fn ($value, $row) => $row->items->map(fn ($item) => [
'name' => $item->orderable?->name,
'quantity' => currency($item->quantity, ''),
'unit_price' => currency($item->unit_price, 'Rp'),
'total_price' => currency($item->total_price, 'Rp'),
'quantity' => formatCurrencyNumber($item->quantity, ''),
'unit_price' => formatCurrencyNumber($item->unit_price, 'Rp'),
'total_price' => formatCurrencyNumber($item->total_price, 'Rp'),
])->toArray()
)
->outputFormat(
@ -71,11 +71,11 @@ public function columns(): array
Column::make('Ringkasan')
->label(function ($value) {
$subtotal = currency($value->subtotal, 'Rp');
$subtotal = formatCurrencyNumber($value->subtotal, 'Rp');
$discount = currency($value->discount, 'Rp');
$discount = formatCurrencyNumber($value->discount, 'Rp');
$total = currency($value->total, 'Rp');
$total = formatCurrencyNumber($value->total, 'Rp');
return Blade::render('
<div class="mt-2 text-start space-y-1">

View File

@ -30,12 +30,12 @@ public function columns(): array
Column::make('Nomor Invoice', 'invoice_number')->searchable(),
Column::make('Tanggal Belanja', 'purchase_date')
->format(fn ($value) => formatDate($value))
->format(fn ($value) => formatDateLocalized($value))
->searchable()
->sortable(),
Column::make('Total', 'total')
->format(fn ($value) => currency($value, 'Rp'))
->format(fn ($value) => formatCurrencyNumber($value, 'Rp'))
->searchable()
->sortable(),
@ -43,9 +43,9 @@ public function columns(): array
->data(
fn ($value, $row) => $row->items->map(fn ($item) => [
'name' => $item->purchasable?->name,
'quantity' => currency($item->quantity, ''),
'unit_price' => currency($item->unit_price, 'Rp'),
'total_price' => currency($item->total_price, 'Rp'),
'quantity' => formatCurrencyNumber($item->quantity, ''),
'unit_price' => formatCurrencyNumber($item->unit_price, 'Rp'),
'total_price' => formatCurrencyNumber($item->total_price, 'Rp'),
])->toArray()
)
->outputFormat(

View File

@ -23,7 +23,7 @@ public function columns(): array
Column::make('Outlet', 'outlet.name')->searchable(),
Column::make('Periode Bulan', 'period_month')
->format(fn ($row) => formatDate($row, 'F Y'))
->format(fn ($row) => formatDateLocalized($row, 'F Y'))
->searchable()
->sortable(),

View File

@ -102,8 +102,8 @@ private function prepareSavedData(): array
return [
'name' => $this->name,
'size' => $this->size,
'cost_price' => replaceCurrency($this->cost_price == '' ? '0' : $this->cost_price),
'sale_price' => replaceCurrency($this->sale_price),
'cost_price' => parseRupiahToInt($this->cost_price == '' ? '0' : $this->cost_price),
'sale_price' => parseRupiahToInt($this->sale_price),
'point_per_pcs' => round($this->sale_price / 100),
'description' => $this->description,
];

View File

@ -145,9 +145,9 @@ private function prepareSavedData(): array
return [
'name' => $this->name,
'sku' => $this->sku,
'cost_price' => replaceCurrency($this->cost_price == '' ? '0' : $this->cost_price),
'sale_price' => replaceCurrency($this->sale_price),
'point_per_ml' => round(replaceCurrency($this->sale_price) / 1000),
'cost_price' => parseRupiahToInt($this->cost_price == '' ? '0' : $this->cost_price),
'sale_price' => parseRupiahToInt($this->sale_price),
'point_per_ml' => round(parseRupiahToInt($this->sale_price) / 1000),
'base_notes' => $this->base_notes,
'middle_notes' => $this->middle_notes,
'top_notes' => $this->top_notes,

View File

@ -112,8 +112,8 @@ private function prepareSavedData(): array
return [
'name' => $this->name,
'sku' => $this->sku,
'cost_price' => replaceCurrency($this->cost_price == '' ? '0' : $this->cost_price),
'sale_price' => replaceCurrency($this->sale_price),
'cost_price' => parseRupiahToInt($this->cost_price == '' ? '0' : $this->cost_price),
'sale_price' => parseRupiahToInt($this->sale_price),
'point_per_pcs' => round($this->sale_price / 100),
'description' => $this->description,
'outlet_ids' => $this->outlet_ids,

View File

@ -48,7 +48,7 @@ public function setExpense(Expense $expense): void
$this->expense = $expense;
$this->description = $expense->description;
$this->amount = currency($expense->amount);
$this->amount = formatCurrencyNumber($expense->amount);
$this->outlet_id = $expense->outlet_id;
$this->image = $this->mapMediaCollection($expense->getMedia('image'));
@ -63,7 +63,7 @@ public function store(): void
'user_id' => auth()->id(),
'type' => ExpenseType::OPERATIONAL,
'description' => $this->description,
'amount' => replaceCurrency($this->amount),
'amount' => parseRupiahToInt($this->amount),
'outlet_id' => auth()->user()->outlets()->count() > 1 ? $this->outlet_id : auth()->user()->outlets()->first()->id,
]);
@ -78,7 +78,7 @@ public function update(): void
DB::transaction(function () {
$this->expense->update([
'description' => $this->description,
'amount' => replaceCurrency($this->amount),
'amount' => parseRupiahToInt($this->amount),
]);
$this->syncMedia($this->image, $this->expense, 'image');

View File

@ -47,7 +47,7 @@ public function store(): array
{
$this->validate();
$amount = (int) replaceCurrency($this->amount);
$amount = (int) parseRupiahToInt($this->amount);
DB::transaction(function () use ($amount, &$adjustment) {
foreach ($this->user_ids as $user_id) {
@ -83,12 +83,12 @@ public function store(): array
if ($adjustment->type->value == SalaryAdjustmentType::BONUS->value) {
return [
'userIds' => $this->user_ids,
'message' => '🎉 Horee! Anda mendapatkan bonus sebesar '.currency($amount, 'Rp').' untuk bulan ini. Lihat detailnya di menu Penggajian! 💰✨',
'message' => '🎉 Horee! Anda mendapatkan bonus sebesar '.formatCurrencyNumber($amount, 'Rp').' untuk bulan ini. Lihat detailnya di menu Penggajian! 💰✨',
];
} elseif ($adjustment->type->value == SalaryAdjustmentType::DEDUCTION->value) {
return [
'userIds' => $this->user_ids,
'message' => '⚠️ Yahh, gaji Anda dipotong sebesar '.currency($amount, 'Rp').' untuk bulan ini. Lihat detailnya di menu Penggajian. 📄',
'message' => '⚠️ Yahh, gaji Anda dipotong sebesar '.formatCurrencyNumber($amount, 'Rp').' untuk bulan ini. Lihat detailnya di menu Penggajian. 📄',
];
}
}

View File

@ -40,7 +40,7 @@ public function setRewards(TierReward $tierReward): void
$this->tier_id = $tierReward->tier_id;
$this->name = $tierReward->name;
$this->value = currency($tierReward->value);
$this->value = formatCurrencyNumber($tierReward->value);
}
public function store(): TierReward
@ -64,7 +64,7 @@ private function prepareSavedData(): array
return [
'tier_id' => $this->tier_id,
'name' => $this->name,
'value' => replaceCurrency($this->value),
'value' => parseRupiahToInt($this->value),
];
}
}

View File

@ -29,8 +29,8 @@ public function rules(): array
public function withValidator($validator): void
{
$validator->after(function ($validator) {
$minPoints = replaceCurrency($this->min_points);
$maxPoints = $this->max_points ? replaceCurrency($this->max_points) : null;
$minPoints = parseRupiahToInt($this->min_points);
$maxPoints = $this->max_points ? parseRupiahToInt($this->max_points) : null;
$ignoreId = $this->tier?->id;
$tierErrors = Tier::validateTierPoints($minPoints, $maxPoints, $ignoreId);
@ -83,8 +83,8 @@ private function prepareSavedData(): array
{
return [
'name' => $this->name,
'min_points' => replaceCurrency($this->min_points),
'max_points' => replaceCurrency($this->max_points),
'min_points' => parseRupiahToInt($this->min_points),
'max_points' => parseRupiahToInt($this->max_points),
];
}
}

View File

@ -107,9 +107,9 @@ public function setVoucher(Voucher $voucher): void
$this->code = $this->voucher->code;
$this->tags = $this->voucher->tags;
$this->type = $this->voucher->type->value;
$this->discount_amount = replaceCurrency($this->voucher->discount_amount);
$this->min_purchase = replaceCurrency($this->voucher->min_purchase);
$this->max_discount = replaceCurrency($this->voucher->max_discount);
$this->discount_amount = parseRupiahToInt($this->voucher->discount_amount);
$this->min_purchase = parseRupiahToInt($this->voucher->min_purchase);
$this->max_discount = parseRupiahToInt($this->voucher->max_discount);
$this->quota = $this->voucher->quota;
$this->limit_per_user = $this->voucher->limit_per_user;
$this->summary = $this->voucher->summary;
@ -159,9 +159,9 @@ private function prepareSavedData(): array
'code' => $this->code,
'tags' => $this->tags,
'type' => $this->type,
'discount_amount' => replaceCurrency($this->discount_amount),
'min_purchase' => replaceCurrency($this->min_purchase),
'max_discount' => $this->type == VoucherType::PERCENTAGE->value ? replaceCurrency($this->max_discount) : null,
'discount_amount' => parseRupiahToInt($this->discount_amount),
'min_purchase' => parseRupiahToInt($this->min_purchase),
'max_discount' => $this->type == VoucherType::PERCENTAGE->value ? parseRupiahToInt($this->max_discount) : null,
'quota' => $this->quota,
'available_count' => empty($this->quota) ? 0 : $this->quota,
'limit_per_user' => $this->limit_per_user,

View File

@ -94,7 +94,7 @@ public function store(): array
// Calculate subtotal before any global discount
$subtotal = $items->sum(fn ($item) => $item->unit_price * $item->quantity);
$manualDiscount = replaceCurrency($this->discount);
$manualDiscount = parseRupiahToInt($this->discount);
// Apply manual discount
$afterManual = $subtotal - $manualDiscount;

View File

@ -121,7 +121,7 @@ private function prepareSavedData(): array
'note' => $this->note,
'outlet_id' => $this->outlet_id,
'purchase_date' => $this->purchase_date,
'total' => replaceCurrency($this->total),
'total' => parseRupiahToInt($this->total),
];
}
}

View File

@ -40,7 +40,7 @@ public function setFormula(Formula $formula): void
$this->quality = $formula->quality;
$this->size = $formula->size;
$this->volume = replaceCurrency($formula->volume);
$this->volume = parseRupiahToInt($formula->volume);
}
public function store(): Formula
@ -68,7 +68,7 @@ private function prepareDataForSave(): array
return [
'quality' => $this->quality,
'size' => $this->size,
'volume' => replaceCurrency($this->volume),
'volume' => parseRupiahToInt($this->volume),
];
}
}

View File

@ -164,7 +164,7 @@ private function createEmployee(User $user, array $data): void
'full_name' => $data['full_name'],
'code' => Employee::generateEmployeeCode(),
'phone_number' => $data['phone_number'],
'base_salary' => replaceCurrency($data['base_salary']),
'base_salary' => parseRupiahToInt($data['base_salary']),
'birthdate' => $data['birthdate'],
'hire_date' => $data['hire_date'],
'resign_date' => $data['resign_date'],
@ -216,7 +216,7 @@ private function updateEmployee(array $data): void
$this->user->employee->update([
'full_name' => $data['full_name'],
'phone_number' => $data['phone_number'],
'base_salary' => replaceCurrency($data['base_salary']),
'base_salary' => parseRupiahToInt($data['base_salary']),
'birthdate' => $data['birthdate'],
'hire_date' => $data['hire_date'],
'resign_date' => $data['resign_date'],

View File

@ -43,7 +43,7 @@ public function setAccount(User $user): void
$this->username = $user->username;
$this->email = $user->email;
$this->status = $user->status->label();
$this->email_verified_at = $user->email_verified_at ? formatDateTime($user->email_verified_at) : '-';
$this->email_verified_at = $user->email_verified_at ? formatDateTimeLocalized($user->email_verified_at) : '-';
}
public function update(): void

View File

@ -60,7 +60,7 @@ public function setProfile(Employee $employee): void
$this->phone_number = $employee->phone_number;
$this->base_salary = $employee->base_salary;
$this->birthdate = $employee->birthdate;
$this->hire_date = formatDate($employee->hire_date);
$this->hire_date = formatDateLocalized($employee->hire_date);
$this->address = $employee->address;
$this->gender = $employee->gender->value;
$this->status = $employee->status->label();

View File

@ -66,8 +66,8 @@ public function render()
->latest()
->paginate(3)
->through(function (VoucherModel $voucher) {
$voucher->min_purchase_formatted = currency($voucher->min_purchase, 'Rp');
$voucher->end_date = formatDate($voucher->end_date);
$voucher->min_purchase_formatted = formatCurrencyNumber($voucher->min_purchase, 'Rp');
$voucher->end_date = formatDateLocalized($voucher->end_date);
return $voucher;
});

View File

@ -61,13 +61,13 @@ public function mount()
$this->stats = [
[
'title' => 'Poin Tier',
'value' => currency($this->membership->tier_points),
'description' => '+'.currency($monthlyTierAddition).' bulan ini',
'value' => formatCurrencyNumber($this->membership->tier_points),
'description' => '+'.formatCurrencyNumber($monthlyTierAddition).' bulan ini',
],
[
'title' => 'Tier Sekarang',
'value' => $this->membership->tier->name,
'description' => 'Terdaftar sejak '.formatDate($this->membership->created_at),
'description' => 'Terdaftar sejak '.formatDateLocalized($this->membership->created_at),
],
[
'title' => 'Tier Selanjutnya',
@ -76,7 +76,7 @@ public function mount()
],
[
'title' => 'Poin Hadiah',
'value' => currency($this->membership->reward_points),
'value' => formatCurrencyNumber($this->membership->reward_points),
'description' => 'Nikmati hadiah sekarang',
],
];
@ -86,7 +86,7 @@ public function mount()
->get()
->map(fn ($reward) => [
'name' => $reward->name,
'value' => currency($reward->value, 'Rp'),
'value' => formatCurrencyNumber($reward->value, 'Rp'),
])
->toArray();
@ -95,9 +95,9 @@ public function mount()
->limit(10)
->get()
->map(fn ($record) => [
'date' => formatDate($record->created_at),
'date' => formatDateLocalized($record->created_at),
'description' => $record->description,
'change' => currency($record->change),
'change' => formatCurrencyNumber($record->change),
'type' => $record->type->label(),
'is_addition' => $record->is_addition,
])

View File

@ -20,10 +20,10 @@ public function mount()
'name' => $voucher->name,
'code' => $voucher->code,
'is_percentage' => $voucher->type == VoucherType::PERCENTAGE,
'min_purchase' => $voucher->min_purchase ? currency($voucher->min_purchase, 'Rp') : 'No Min. Belanja',
'discount_amount' => $voucher->type == VoucherType::PERCENTAGE ? $voucher->discount_amount.'%' : currency($voucher->discount_amount, 'Rp'),
'max_discount' => currency($voucher->max_discount, 'Rp'),
'end_date' => $voucher->end_date ? timeAgo($voucher->end_date) : 'Tidak Ada Batas Waktu',
'min_purchase' => $voucher->min_purchase ? formatCurrencyNumber($voucher->min_purchase, 'Rp') : 'No Min. Belanja',
'discount_amount' => $voucher->type == VoucherType::PERCENTAGE ? $voucher->discount_amount.'%' : formatCurrencyNumber($voucher->discount_amount, 'Rp'),
'max_discount' => formatCurrencyNumber($voucher->max_discount, 'Rp'),
'end_date' => $voucher->end_date ? formatRelativeTime($voucher->end_date) : 'Tidak Ada Batas Waktu',
])->toArray();
}

View File

@ -171,7 +171,7 @@ protected function loadData()
$this->orders = array_filter([
[
'title' => 'Total Order',
'value' => currency(
'value' => formatCurrencyNumber(
Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
->when($dateQuery || ($startDate && $endDate), $filterDate)
->count()
@ -179,7 +179,7 @@ protected function loadData()
],
[
'title' => 'Pendapatan',
'value' => currency(
'value' => formatCurrencyNumber(
Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
->when($dateQuery || ($startDate && $endDate), $filterDate)
->sum('total'),
@ -189,7 +189,7 @@ protected function loadData()
auth()->user()->hasRole(['Developer', 'Owner']) ? [
'title' => 'HPP',
'value' => currency(
'value' => formatCurrencyNumber(
Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
->when($dateQuery || ($startDate && $endDate), $filterDate)
->sum('cogs'),
@ -199,7 +199,7 @@ protected function loadData()
[
'title' => 'Diskon',
'value' => currency(
'value' => formatCurrencyNumber(
Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
->when($dateQuery || ($startDate && $endDate), $filterDate)
->sum('discount'),
@ -208,7 +208,7 @@ protected function loadData()
],
[
'title' => 'Voucher Terpakai',
'value' => currency(
'value' => formatCurrencyNumber(
Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
->when($dateQuery || ($startDate && $endDate), $filterDate)
->whereNotNull('voucher_id')->count()
@ -216,7 +216,7 @@ protected function loadData()
],
[
'title' => 'Parfum Terjual',
'value' => currency(
'value' => formatCurrencyNumber(
OrderItem::where('orderable_type', Perfume::class)
->whereHas('order', fn ($q) => $q->when(! empty($outletIds), fn ($q2) => $q2->whereIn('outlet_id', $outletIds))->when($dateQuery || ($startDate && $endDate), $filterDate))
->sum('quantity')
@ -224,7 +224,7 @@ protected function loadData()
],
[
'title' => 'Produk Terjual',
'value' => currency(
'value' => formatCurrencyNumber(
OrderItem::where('orderable_type', Product::class)
->whereHas('order', fn ($q) => $q->when(! empty($outletIds), fn ($q2) => $q2->whereIn('outlet_id', $outletIds))->when($dateQuery || ($startDate && $endDate), $filterDate))
->sum('quantity')
@ -232,7 +232,7 @@ protected function loadData()
],
[
'title' => 'Botol Terjual',
'value' => currency(
'value' => formatCurrencyNumber(
OrderItem::where('orderable_type', Bottle::class)
->whereHas('order', fn ($q) => $q->when(! empty($outletIds), fn ($q2) => $q2->whereIn('outlet_id', $outletIds))->when($dateQuery || ($startDate && $endDate), $filterDate))
->sum('quantity')
@ -243,7 +243,7 @@ protected function loadData()
$this->expenses = array_filter([
[
'title' => 'Beban Toko',
'value' => currency(
'value' => formatCurrencyNumber(
Expense::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
->when($dateQuery || ($startDate && $endDate), $filterDate)
->sum('amount'),
@ -253,7 +253,7 @@ protected function loadData()
auth()->user()->hasRole(['Developer', 'Owner']) ? [
'title' => 'Belanja Barang',
'value' => currency(
'value' => formatCurrencyNumber(
Purchase::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
->when($dateQuery || ($startDate && $endDate), $filterDate)
->sum('total'),
@ -263,7 +263,7 @@ protected function loadData()
[
'title' => 'Penggajian',
'value' => currency(
'value' => formatCurrencyNumber(
Payroll::when(! empty($outletIds), fn ($q) => $q->whereHas('user.outlets', fn ($q2) => $q2->whereIn('outlets.id', $outletIds)))
->when($dateQuery || ($startDate && $endDate), $filterDate)
->paid()
@ -284,9 +284,9 @@ protected function loadData()
->get()
->map(fn ($perfume) => [
'name' => $perfume->name,
'sale_price' => currency($perfume->sale_price, 'Rp'),
'total_sold' => currency($perfume->items->sum('quantity')),
'total_sales' => currency($perfume->items->sum(fn ($item) => $item->order?->total ?? 0), 'Rp'),
'sale_price' => formatCurrencyNumber($perfume->sale_price, 'Rp'),
'total_sold' => formatCurrencyNumber($perfume->items->sum('quantity')),
'total_sales' => formatCurrencyNumber($perfume->items->sum(fn ($item) => $item->order?->total ?? 0), 'Rp'),
])
->sortByDesc('total_sales')
->filter(fn ($product) => $product['total_sold'] > 0)
@ -304,9 +304,9 @@ protected function loadData()
->get()
->map(fn ($product) => [
'name' => $product->name,
'sale_price' => currency($product->sale_price, 'Rp'),
'total_sold' => currency($product->items->sum('quantity')),
'total_sales' => currency($product->items->sum(fn ($item) => $item->order?->total ?? 0), 'Rp'),
'sale_price' => formatCurrencyNumber($product->sale_price, 'Rp'),
'total_sold' => formatCurrencyNumber($product->items->sum('quantity')),
'total_sales' => formatCurrencyNumber($product->items->sum(fn ($item) => $item->order?->total ?? 0), 'Rp'),
])
->sortByDesc('total_sales')
->filter(fn ($product) => $product['total_sold'] > 0)
@ -324,9 +324,9 @@ protected function loadData()
->get()
->map(fn ($bottle) => [
'name' => $bottle->name,
'sale_price' => currency($bottle->sale_price, 'Rp'),
'total_sold' => currency($bottle->items->sum('quantity')),
'total_sales' => currency($bottle->items->sum(fn ($item) => $item->order?->total ?? 0), 'Rp'),
'sale_price' => formatCurrencyNumber($bottle->sale_price, 'Rp'),
'total_sold' => formatCurrencyNumber($bottle->items->sum('quantity')),
'total_sales' => formatCurrencyNumber($bottle->items->sum(fn ($item) => $item->order?->total ?? 0), 'Rp'),
])
->sortByDesc('total_sales')
->filter(fn ($product) => $product['total_sold'] > 0)

View File

@ -153,35 +153,35 @@ protected function loadStats()
],
[
'title' => 'Pendapatan',
'value' => currency($todayIncome, 'Rp'),
'previous' => currency($yesterdayIncome, 'Rp'),
'value' => formatCurrencyNumber($todayIncome, 'Rp'),
'previous' => formatCurrencyNumber($yesterdayIncome, 'Rp'),
'trend' => $yesterdayIncome > 0
? round((($todayIncome - $yesterdayIncome) / $yesterdayIncome) * 100, 1).'%'
: '∞%',
'trendUp' => $todayIncome > $yesterdayIncome,
'formatted' => currency($todayIncome, 'Rp'),
'formatted' => formatCurrencyNumber($todayIncome, 'Rp'),
],
auth()->user()->hasRole(['Developer', 'Owner']) ? [
'title' => 'HPP',
'value' => currency($todayCogs, 'Rp'),
'previous' => currency($yesterdayCogs, 'Rp'),
'value' => formatCurrencyNumber($todayCogs, 'Rp'),
'previous' => formatCurrencyNumber($yesterdayCogs, 'Rp'),
'trend' => $yesterdayCogs > 0
? round((($todayCogs - $yesterdayCogs) / $yesterdayCogs) * 100, 1).'%'
: '∞%',
'trendUp' => $todayCogs > $yesterdayCogs,
'formatted' => currency($todayCogs, 'Rp'),
'formatted' => formatCurrencyNumber($todayCogs, 'Rp'),
] : null,
[
'title' => 'Diskon',
'value' => currency($todayDiscount, 'Rp'),
'previous' => currency($yesterdayDiscount, 'Rp'),
'value' => formatCurrencyNumber($todayDiscount, 'Rp'),
'previous' => formatCurrencyNumber($yesterdayDiscount, 'Rp'),
'trend' => $yesterdayDiscount > 0
? round((($todayDiscount - $yesterdayDiscount) / $yesterdayDiscount) * 100, 1).'%'
: '∞%',
'trendUp' => $todayDiscount > $yesterdayDiscount,
'formatted' => currency($todayDiscount, 'Rp'),
'formatted' => formatCurrencyNumber($todayDiscount, 'Rp'),
],
[
'title' => 'Voucher Terpakai',
@ -194,8 +194,8 @@ protected function loadStats()
],
[
'title' => 'Beban Toko',
'value' => currency($todayExpense, 'Rp'),
'previous' => currency($yesterdayExpense, 'Rp'),
'value' => formatCurrencyNumber($todayExpense, 'Rp'),
'previous' => formatCurrencyNumber($yesterdayExpense, 'Rp'),
'trend' => $yesterdayExpense > 0
? round((($todayExpense - $yesterdayExpense) / $yesterdayExpense) * 100, 1).'%'
: '∞%',
@ -204,8 +204,8 @@ protected function loadStats()
auth()->user()->hasRole(['Developer', 'Owner']) ? [
'title' => 'Belanja Barang',
'value' => currency($todayPurchase, 'Rp'),
'previous' => currency($yesterdayPurchase, 'Rp'),
'value' => formatCurrencyNumber($todayPurchase, 'Rp'),
'previous' => formatCurrencyNumber($yesterdayPurchase, 'Rp'),
'trend' => $yesterdayPurchase > 0
? round((($todayPurchase - $yesterdayPurchase) / $yesterdayPurchase) * 100, 1).'%'
: '∞%',
@ -214,8 +214,8 @@ protected function loadStats()
auth()->user()->hasRole(['Developer', 'Owner']) ? [
'title' => 'Laba Kotor',
'value' => currency($todayGrossProfit, 'Rp'),
'previous' => currency($yesterdayGrossProfit, 'Rp'),
'value' => formatCurrencyNumber($todayGrossProfit, 'Rp'),
'previous' => formatCurrencyNumber($yesterdayGrossProfit, 'Rp'),
'trend' => $yesterdayGrossProfit > 0
? round((($todayGrossProfit - $yesterdayGrossProfit) / $yesterdayGrossProfit) * 100, 1).'%'
: '∞%',
@ -224,8 +224,8 @@ protected function loadStats()
auth()->user()->hasRole(['Developer', 'Owner']) ? [
'title' => 'Laba Bersih',
'value' => currency($todayNetProfit, 'Rp'),
'previous' => currency($yesterdayNetProfit, 'Rp'),
'value' => formatCurrencyNumber($todayNetProfit, 'Rp'),
'previous' => formatCurrencyNumber($yesterdayNetProfit, 'Rp'),
'trend' => $yesterdayNetProfit > 0
? round((($todayNetProfit - $yesterdayNetProfit) / $yesterdayNetProfit) * 100, 1).'%'
: '∞%',

View File

@ -134,7 +134,7 @@ public function exportPdf(PayrollModel $payroll)
$fileName = 'Gaji '
.$payroll->user->employee->full_name
.' Bulan '
.formatDate($period, 'F Y')
.formatDateLocalized($period, 'F Y')
.'.pdf';
return response()->streamDownload(function () use ($pdf) {

View File

@ -49,9 +49,9 @@ public function loadTiers(): void
'id' => $tier->id,
'hash' => $tier->hash,
'name' => $tier->name,
'min_points' => currency($tier->min_points),
'max_points' => currency($tier->max_points),
'total_members' => currency($tier->memberships_count),
'min_points' => formatCurrencyNumber($tier->min_points),
'max_points' => formatCurrencyNumber($tier->max_points),
'total_members' => formatCurrencyNumber($tier->memberships_count),
'total_rewards' => $tier->rewards_count,
];
})
@ -90,17 +90,17 @@ public function getTopMemberStats($tierId): ?array
return [
'name' => $topMembership->user->customer->name,
'points' => currency($topMembership->tier_points),
'total_orders' => currency($totalOrders),
'points' => formatCurrencyNumber($topMembership->tier_points),
'total_orders' => formatCurrencyNumber($totalOrders),
'items' => [
'total_perfume' => currency($totalPerfume),
'total_product' => currency($totalProduct),
'total_bottle' => currency($totalBottle),
'total_perfume' => formatCurrencyNumber($totalPerfume),
'total_product' => formatCurrencyNumber($totalProduct),
'total_bottle' => formatCurrencyNumber($totalBottle),
],
'total' => [
'subtotal' => currency($subtotal, 'Rp'),
'discount' => currency($totalDiscount, 'Rp'),
'grand_total' => currency($grandTotal, 'Rp'),
'subtotal' => formatCurrencyNumber($subtotal, 'Rp'),
'discount' => formatCurrencyNumber($totalDiscount, 'Rp'),
'grand_total' => formatCurrencyNumber($grandTotal, 'Rp'),
],
];
}
@ -127,7 +127,7 @@ public function update(): void
$this->canOrAbort('update tier');
$oldMinPoints = $this->form->tier->min_points;
$newMinPoints = replaceCurrency($this->form->min_points);
$newMinPoints = parseRupiahToInt($this->form->min_points);
$this->form->update();

View File

@ -96,7 +96,7 @@ public function save(): void
PushNotification::whereIn('user_id', $userIds)->get(),
[
'title' => '🛒 Order Baru!',
'body' => 'Ada order baru masuk dengan nominal '.currency($result['data']['total'], 'Rp').' ✨',
'body' => 'Ada order baru masuk dengan nominal '.formatCurrencyNumber($result['data']['total'], 'Rp').' ✨',
'url' => route('studio.manage.order.index'),
],
);

View File

@ -26,11 +26,11 @@ public function mount(Order $order): void
'customer' => $order->customer?->name ?? 'Anonim',
'invoice_number' => $order->invoice_number,
'status' => $order->status->label(),
'date' => formatDateTime($order->created_at),
'date' => formatDateTimeLocalized($order->created_at),
'channel' => $order->channel->label(),
'subtotal' => currency($order->subtotal, 'Rp'),
'discount' => currency($order->discount, 'Rp'),
'total' => currency($order->total, 'Rp'),
'subtotal' => formatCurrencyNumber($order->subtotal, 'Rp'),
'discount' => formatCurrencyNumber($order->discount, 'Rp'),
'total' => formatCurrencyNumber($order->total, 'Rp'),
];
$this->items = $order->items
@ -38,8 +38,8 @@ public function mount(Order $order): void
'id' => $item->hash,
'name' => $item->orderable?->name,
'quantity' => $item->quantity,
'unit_price' => currency($item->unit_price, 'Rp'),
'total' => currency($item->quantity * $item->unit_price, 'Rp'),
'unit_price' => formatCurrencyNumber($item->unit_price, 'Rp'),
'total' => formatCurrencyNumber($item->quantity * $item->unit_price, 'Rp'),
])
->toArray();

View File

@ -46,7 +46,7 @@ protected function loadItems(): void
$stockOpname->total_item = $total;
$stockOpname->progress_filled = $filled;
$stockOpname->progress_percent = $percent;
$stockOpname->period_month = formatDate($stockOpname->period_month, 'F Y');
$stockOpname->period_month = formatDateLocalized($stockOpname->period_month, 'F Y');
return $stockOpname;
});

View File

@ -135,7 +135,7 @@ public function addProduct()
{
$product = Product::find($this->form->product_id);
$quantity = replaceCurrency($this->form->quantity_product);
$quantity = parseRupiahToInt($this->form->quantity_product);
if (! $product || $quantity <= 0) {
$this->toast('Produk atau kuantitas tidak valid', 'Gagal', 'danger');

View File

@ -11,6 +11,6 @@ public function getSubTotal()
public function getTotal()
{
return $this->items->sum(fn ($item) => $item->unit_price * $item->quantity - replaceCurrency($this->form->discount) - $this->voucherDiscount);
return $this->items->sum(fn ($item) => $item->unit_price * $item->quantity - parseRupiahToInt($this->form->discount) - $this->voucherDiscount);
}
}

View File

@ -24,7 +24,7 @@ public function calculateDiscount(int $subtotal, string $voucherId)
return [
'status' => false,
'message' => 'Minimal pembelian harus sebesar '.currency($voucher->min_purchase, 'Rp').' untuk menggunakan voucher ini.',
'message' => 'Minimal pembelian harus sebesar '.formatCurrencyNumber($voucher->min_purchase, 'Rp').' untuk menggunakan voucher ini.',
];
}

View File

@ -17,7 +17,7 @@ public function openModal(OrderItem $item)
$this->form->item_id = $item->id;
$this->form->quantity_edit = currency($item->quantity, '');
$this->form->quantity_edit = formatCurrencyNumber($item->quantity, '');
}
public function closeModal()
@ -35,7 +35,7 @@ public function updateItem()
return;
}
$item->update(['quantity' => replaceCurrency($this->form->quantity_edit)]);
$item->update(['quantity' => parseRupiahToInt($this->form->quantity_edit)]);
$item->refresh();

View File

@ -52,7 +52,7 @@ public function increaseOutletStock($outlet, $item)
'purchase_id' => $item->purchase_id ?? null,
])
->event('Menambah')
->log('Stok '.$item->orderable->name.' di '.$outlet->name.' bertambah '.currency($quantity));
->log('Stok '.$item->orderable->name.' di '.$outlet->name.' bertambah '.formatCurrencyNumber($quantity));
}
public function decreaseOutletStock($outlet, $item)
@ -108,6 +108,6 @@ public function decreaseOutletStock($outlet, $item)
'purchase_id' => $item->purchase_id ?? null,
])
->event('Mengurangi')
->log('Stok '.$item->orderable->name.' di '.$outlet->name.' berkurang '.currency($quantity));
->log('Stok '.$item->orderable->name.' di '.$outlet->name.' berkurang '.formatCurrencyNumber($quantity));
}
}

View File

@ -16,19 +16,19 @@ public function addItem(string $type)
case 'parfum':
$model = Perfume::class;
$id = $this->form->perfume_id;
$quantity = replaceCurrency($this->form->quantity_perfume);
$quantity = parseRupiahToInt($this->form->quantity_perfume);
break;
case 'produk':
$model = Product::class;
$id = $this->form->product_id;
$quantity = replaceCurrency($this->form->quantity_product);
$quantity = parseRupiahToInt($this->form->quantity_product);
break;
case 'botol':
$model = Bottle::class;
$id = $this->form->bottle_id;
$quantity = replaceCurrency($this->form->quantity_bottle);
$quantity = parseRupiahToInt($this->form->quantity_bottle);
break;
default:
@ -89,7 +89,7 @@ public function addItem(string $type)
$this->toast(Str::ucfirst($type).' ditambahkan ke keranjang.', 'Berhasil');
}
$this->form->total = currency($this->getTotal());
$this->form->total = formatCurrencyNumber($this->getTotal());
switch ($type) {
case 'parfum':

View File

@ -12,7 +12,7 @@ public function deleteItem(PurchaseItem $item)
$item->delete();
$this->form->total = currency($this->purchaseItems->sum('total_price'), '');
$this->form->total = formatCurrencyNumber($this->purchaseItems->sum('total_price'), '');
$this->toast('Item berhasil dihapus.');
}

View File

@ -17,7 +17,7 @@ public function openModal(PurchaseItem $item)
$this->form->item_id = $item->id;
$this->form->quantity_edit = currency($item->quantity);
$this->form->quantity_edit = formatCurrencyNumber($item->quantity);
}
public function closeModal()
@ -30,15 +30,15 @@ public function updateItem()
$item = PurchaseItem::find($this->form->item_id);
$item->update([
'quantity' => replaceCurrency($this->form->quantity_edit),
'total_price' => (int) $item->purchasable->cost_price * (int) replaceCurrency($this->form->quantity_edit),
'quantity' => parseRupiahToInt($this->form->quantity_edit),
'total_price' => (int) $item->purchasable->cost_price * (int) parseRupiahToInt($this->form->quantity_edit),
]);
$item->refresh();
$this->purchaseItems = $this->purchaseItems->map(fn ($i) => $i->id === $item->id ? $item : $i);
$this->form->total = currency($this->purchaseItems->sum('total_price'));
$this->form->total = formatCurrencyNumber($this->purchaseItems->sum('total_price'));
$this->toast('Item berhasil diperbarui.');

View File

@ -53,7 +53,7 @@ public function increaseOutletStock($outlet, $item)
'purchase_id' => $item->purchase_id ?? null,
])
->event('Menambah')
->log('Stok '.$item->purchasable->name.' di '.$outlet->name.' bertambah '.currency($quantity));
->log('Stok '.$item->purchasable->name.' di '.$outlet->name.' bertambah '.formatCurrencyNumber($quantity));
}
public function decreaseOutletStock($outlet, $item)

View File

@ -29,11 +29,11 @@ class="px-2 py-1 inline-flex text-xs font-semibold rounded-full
dark:border-gray-700" />
<div class="flex flex-wrap gap-4 text-sm ">
<div>Stok Sebelumnya: {{ currency($log->properties['previous_stock']) }}</div>
<div>Stok Sebelumnya: {{ formatCurrencyNumber($log->properties['previous_stock']) }}</div>
<flux:separator vertical class="dark:border-gray-700" />
<div>Perubahan: {{ currency($log->properties['quantity_change']) }}</div>
<div>Perubahan: {{ formatCurrencyNumber($log->properties['quantity_change']) }}</div>
<flux:separator vertical class="dark:border-gray-700" />
<div>Total Stok: {{ currency($log->properties['new_stock']) }}</div>
<div>Total Stok: {{ formatCurrencyNumber($log->properties['new_stock']) }}</div>
</div>
<flux:separator class="my-2 dark:border-gray-700" />

View File

@ -30,7 +30,7 @@
<div class="flex justify-between items-center mb-3">
<div>
<flux:heading>{{ $payroll->user->employee->full_name }}</flux:heading>
<flux:text>{{ formatDate($payroll->period_month, 'F Y') }}</flux:text>
<flux:text>{{ formatDateLocalized($payroll->period_month, 'F Y') }}</flux:text>
</div>
<div class="text-right">
<flux:badge color="{{ $payroll->is_paid->color() }}">
@ -42,15 +42,15 @@
<div class="grid grid-cols-1 gap-4 mb-2 text-sm">
<div>
<flux:text>Gaji Pokok</flux:text>
<div class="font-medium">{{ currency($payroll->base_salary, 'Rp') }}</div>
<div class="font-medium">{{ formatCurrencyNumber($payroll->base_salary, 'Rp') }}</div>
</div>
<div>
<flux:text>Bonus</flux:text>
<div class="font-medium text-green-600">{{ currency($payroll->bonus, 'Rp') }}</div>
<div class="font-medium text-green-600">{{ formatCurrencyNumber($payroll->bonus, 'Rp') }}</div>
</div>
<div>
<flux:text>Potongan</flux:text>
<div class="font-medium text-red-600">{{ currency($payroll->deduction, 'Rp') }}</div>
<div class="font-medium text-red-600">{{ formatCurrencyNumber($payroll->deduction, 'Rp') }}</div>
</div>
</div>
@ -62,7 +62,7 @@
<div>
<div
class="font-bold {{ $item->type->value == \App\Enums\SalaryAdjustmentType::DEDUCTION->value ? 'text-red-500' : 'text-green-500' }}">
{{ currency($item->amount, 'Rp') }}
{{ formatCurrencyNumber($item->amount, 'Rp') }}
</div>
<div class="text-gray-400 text-[12px]">{{ $item->description }}</div>
</div>
@ -78,7 +78,7 @@ class="font-bold {{ $item->type->value == \App\Enums\SalaryAdjustmentType::DEDUC
<div class="flex justify-between items-center mt-2">
<flux:text>Total Gaji</flux:text>
<FLux:heading>{{ currency($payroll->total_salary, 'Rp') }}</FLux:heading>
<FLux:heading>{{ formatCurrencyNumber($payroll->total_salary, 'Rp') }}</FLux:heading>
</div>
</flux:card>
@endforeach
@ -133,16 +133,16 @@ class="font-bold {{ $item->type->value == \App\Enums\SalaryAdjustmentType::DEDUC
</flux:label>
<flux:input.group>
<flux:input.group.prefix>Rp</flux:input.group.prefix>
<flux:input placeholder="1.500.000" x-mask:dynamic="$money($input, ',')"
wire:model="form.amount" autocomplete="off" autofocus />
<flux:input placeholder="1.500.000" x-mask:dynamic="$money($input, ',')" wire:model="form.amount"
autocomplete="off" autofocus />
</flux:input.group>
<flux:error name="form.amount" />
</flux:field>
<flux:field>
<flux:label>Keterangan <span class="text-red-500 ms-1">*</span></flux:label>
<flux:input placeholder="Gajian bulan xxx + bonus ya, semangat kerjanya"
wire:model="form.description" autocomplete="off" />
<flux:input placeholder="Gajian bulan xxx + bonus ya, semangat kerjanya" wire:model="form.description"
autocomplete="off" />
<flux:error name="form.description" />
</flux:field>

View File

@ -15,7 +15,7 @@
@foreach ($rewards as $reward)
<flux:table.row>
<flux:table.cell>{{ $reward['name'] }}</flux:table.cell>
<flux:table.cell>{{ currency($reward['value'], 'Rp') }}</flux:table.cell>
<flux:table.cell>{{ formatCurrencyNumber($reward['value'], 'Rp') }}</flux:table.cell>
<flux:table.cell>
<div class="flex gap-2 pt-2 border-gray-200 dark:border-gray-700">
@can('update tier reward')

View File

@ -222,14 +222,14 @@
<div>
<div>{{ $item->orderable->name }}</div>
<span
class="text-xs text-gray-400">{{ currency($item->quantity, '') }}
class="text-xs text-gray-400">{{ formatCurrencyNumber($item->quantity, '') }}
x
{{ currency($item->unit_price, 'Rp') }}</span>
{{ formatCurrencyNumber($item->unit_price, 'Rp') }}</span>
</div>
</flux:heading>
</flux:table.cell>
<flux:table.cell>
{{ currency($item->unit_price * $item->quantity, 'Rp') }}
{{ formatCurrencyNumber($item->unit_price * $item->quantity, 'Rp') }}
</flux:table.cell>
<flux:table.cell class="space-x-2">
<flux:modal.trigger name="form-modal">
@ -259,11 +259,11 @@ class="text-xs text-gray-400">{{ currency($item->quantity, '') }}
<div class="mt-2 text-end space-y-1">
<div>
<flux:text>{{ currency($subtotal, 'Rp') }}</flux:text>
<flux:text>{{ formatCurrencyNumber($subtotal, 'Rp') }}</flux:text>
</div>
<div>
<flux:text class="italic text-gray-500">Diskon Voucher</flux:text>
<flux:text>{{ currency($voucherDiscount, 'Rp') }}</flux:text>
<flux:text>{{ formatCurrencyNumber($voucherDiscount, 'Rp') }}</flux:text>
</div>
<div class="my-2">
<flux:field>
@ -279,7 +279,7 @@ class="text-xs text-gray-400">{{ currency($item->quantity, '') }}
</div>
<div class="text-lg font-bold">
<flux:heading>
{{ currency($total, 'Rp') }}
{{ formatCurrencyNumber($total, 'Rp') }}
</flux:heading>
</div>
</div>

View File

@ -149,14 +149,14 @@
<div>
<div>{{ $item->purchasable->name }}</div>
<span
class="text-xs text-gray-400">{{ currency($item->quantity, '') }}
class="text-xs text-gray-400">{{ formatCurrencyNumber($item->quantity, '') }}
x
{{ currency($item->purchasable->cost_price, 'Rp') }}</span>
{{ formatCurrencyNumber($item->purchasable->cost_price, 'Rp') }}</span>
</div>
</flux:heading>
</flux:table.cell>
<flux:table.cell>
{{ currency($item->total_price, 'Rp') }}
{{ formatCurrencyNumber($item->total_price, 'Rp') }}
</flux:table.cell>
<flux:table.cell class="space-x-2">
<flux:modal.trigger name="form-modal">

View File

@ -107,15 +107,16 @@ class="text-sm font-semibold text-gray-900 dark:text-white mb-2 flex items-cente
<div>
<span class="font-medium text-gray-900 dark:text-white">Tgl Buka:</span>
<span
class="text-gray-700 dark:text-gray-300">{{ formatDate($outlet->opened_date) }}</span>
<span class="text-gray-500">({{ timeAgo($outlet->opened_date) }})</span>
class="text-gray-700 dark:text-gray-300">{{ formatDateLocalized($outlet->opened_date) }}</span>
<span class="text-gray-500">({{ formatRelativeTime($outlet->opened_date) }})</span>
</div>
@if ($outlet->closed_date)
<div>
<span class="font-medium text-gray-900 dark:text-white">Tgl Tutup:</span>
<span
class="text-gray-700 dark:text-gray-300">{{ formatDate($outlet->closed_date) }}</span>
<span class="text-gray-500">({{ timeAgo($outlet->closed_date) }})</span>
class="text-gray-700 dark:text-gray-300">{{ formatDateLocalized($outlet->closed_date) }}</span>
<span
class="text-gray-500">({{ formatRelativeTime($outlet->closed_date) }})</span>
</div>
@endif
</div>

View File

@ -101,7 +101,7 @@ class="w-4 h-4 text-gray-500 dark:text-white flex-shrink-0 mt-0.5" />
<div>
<flux:heading class="uppercase font-semibold text-gray-500 dark:text-gray-400 ">Gaji
</flux:heading>
<flux:text>{{ currency($employee->base_salary, 'Rp') }}</flux:text>
<flux:text>{{ formatCurrencyNumber($employee->base_salary, 'Rp') }}</flux:text>
</div>
</div>
@ -155,24 +155,26 @@ class="text-xs text-gray-400 border border-gray-400 rounded px-2 py-1">
<div>
<span class="font-medium text-gray-900 dark:text-white">Tgl Lahir:</span>
<span
class="text-gray-700 dark:text-gray-300">{{ formatDate($employee->birthdate) }}</span>
<span class="text-gray-500">({{ getAge($employee->birthdate) }})</span>
class="text-gray-700 dark:text-gray-300">{{ formatDateLocalized($employee->birthdate) }}</span>
<span
class="text-gray-500">({{ formatAgeYearsMonths($employee->birthdate) }})</span>
</div>
<div>
<span class="font-medium text-gray-900 dark:text-white">Tgl
Bergabung:</span>
<span
class="text-gray-700 dark:text-gray-300">{{ formatDate($employee->hire_date) }}</span>
<span class="text-gray-500">({{ timeAgo($employee->hire_date) }})</span>
class="text-gray-700 dark:text-gray-300">{{ formatDateLocalized($employee->hire_date) }}</span>
<span
class="text-gray-500">({{ formatRelativeTime($employee->hire_date) }})</span>
</div>
@if ($employee->resign_date)
<div>
<span class="font-medium text-gray-900 dark:text-white">Tgl
Resign:</span>
<span
class="text-gray-700 dark:text-gray-300">{{ formatDate($employee->resign_date) }}</span>
class="text-gray-700 dark:text-gray-300">{{ formatDateLocalized($employee->resign_date) }}</span>
<span
class="text-gray-500">({{ timeAgo($employee->resign_date) }})</span>
class="text-gray-500">({{ formatRelativeTime($employee->resign_date) }})</span>
</div>
@endif
</div>

View File

@ -576,8 +576,8 @@ function mountTierComponent(User $user)
$component = mountTierComponent($this->user);
$loadedTier = $component->tiers->firstWhere('id', $tier->id);
expect(currency($loadedTier->min_points))->toContain('1.000');
expect(currency($loadedTier->max_points))->toContain('5.000');
expect(formatCurrencyNumber($loadedTier->min_points))->toContain('1.000');
expect(formatCurrencyNumber($loadedTier->max_points))->toContain('5.000');
});
it('handles currency formatting in form input', function () {
@ -610,7 +610,7 @@ function mountTierComponent(User $user)
$component = mountTierComponent($this->user);
$loadedTier = $component->tiers->firstWhere('id', $tier->id);
expect(currency($loadedTier->max_points))->not->toBeNull();
expect(formatCurrencyNumber($loadedTier->max_points))->not->toBeNull();
});
it('handles tier with zero min_points', function () {
@ -623,7 +623,7 @@ function mountTierComponent(User $user)
$component = mountTierComponent($this->user);
$loadedTier = $component->tiers->firstWhere('id', $tier->id);
expect(currency($loadedTier->min_points))->toContain('0');
expect(formatCurrencyNumber($loadedTier->min_points))->toContain('0');
});
it('handles empty tiers list', function () {
@ -648,6 +648,6 @@ function mountTierComponent(User $user)
$updatedTier = $component->tiers->firstWhere('hash', $tier->hash);
expect($updatedTier->name)->toBe('Gold');
expect(currency($updatedTier->min_points))->toContain('1.000');
expect(currency($updatedTier->max_points))->toContain('5.000');
expect(formatCurrencyNumber($updatedTier->min_points))->toContain('1.000');
expect(formatCurrencyNumber($updatedTier->max_points))->toContain('5.000');
});

View File

@ -109,7 +109,7 @@ function createTestOutlets(int $count = 3)
$component = mountEditComponent($this->user, $voucher);
// Note: replaceCurrency returns integer, so we check the raw value
// Note: parseRupiahToInt returns integer, so we check the raw value
// The form will display formatted currency in the view
expect($component->form->discount_amount)->toBe('50000');
expect($component->form->min_purchase)->toBe('200000');