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 enum Gender: int
{ {
use WithCommentEnum, WithValueEnum; use WithCommentEnum, WithValueEnum;
case MALE = 1; case MALE = 1;
case FEMALE = 2; case FEMALE = 2;

View File

@ -1,13 +1,13 @@
<?php <?php
if (! function_exists('randomColors')) { if (! function_exists('generateRandomRgbaColors')) {
/** /**
* Generate an array of random RGBA colors * Generate an array of random RGBA colors
* *
* @param int $count Number of colors to generate * @param int $count Number of colors to generate
* @param float $alpha Alpha/transparency value (default: 0.2) * @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 = []; $colors = [];
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
@ -29,6 +29,6 @@ function randomColors(int $count, float $alpha = 0.2): array
*/ */
function randomBorderColors(int $count): 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; use Carbon\Carbon;
if (! function_exists('formatDate')) { if (! function_exists('formatDateLocalized')) {
/** /**
* Format date/time with a configurable format using Carbon. * 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 string $format Carbon format (default: 'l, d M Y')
* @param bool $translated Use translatedFormat for locale-aware output (default: true) * @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) { if (! $date) {
return '-'; return '-';
@ -24,34 +24,34 @@ function formatDate(?string $date = null, string $format = 'l, d M Y', bool $tra
if (! function_exists('formatTime')) { 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') * @param string $format Carbon format (default: 'H:i')
*/ */
function formatTime(?string $time = null, string $format = 'H:i'): string 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') * @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. * Calculate age from birthdate using Carbon.
* Returns formatted string in Indonesian (e.g. "25 tahun 3 bulan"). * 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) { if (! $birthdate) {
return '-'; 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(). * Get relative time string using Carbon's diffForHumans().
* Returns localized relative time (e.g. "2 hours ago", "3 days ago"). * 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) { if (! $date) {
return '-'; return '-';

View File

@ -4,14 +4,14 @@
use Illuminate\Support\Number; use Illuminate\Support\Number;
use Illuminate\Support\Str; use Illuminate\Support\Str;
if (! function_exists('currency')) { if (! function_exists('formatCurrencyNumber')) {
/** /**
* Format value as currency * Format value as currency
* *
* @param string|null $currency Currency prefix (default: null) * @param string|null $currency Currency prefix (default: null)
* @param string $locale Locale for formatting (default: 'id_ID') * @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) { if ($value === null) {
return ''; 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 * Strip currency format from string and return as integer
*/ */
function replaceCurrency(?string $value = null): ?int function parseRupiahToInt(?string $value = null): ?int
{ {
if ($value === null) { if ($value === null) {
return 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 * Format value as percentage
* *
@ -49,7 +49,7 @@ function replaceCurrency(?string $value = null): ?int
* @param int $maxPrecision Max precision (default: 2) * @param int $maxPrecision Max precision (default: 2)
* @param string $locale Locale for formatting (default: 'id_ID') * @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); 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 function formatDiscount(int|float $amount, VoucherType $type, string $currency = 'Rp'): string
{ {
return $type === VoucherType::PERCENTAGE return $type === VoucherType::PERCENTAGE
? percentage($amount) ? formatPercentage($amount)
: currency($amount, $currency); : formatCurrencyNumber($amount, $currency);
} }
} }
@ -80,49 +80,8 @@ function generateReferralCode(string $username, int $unique): string
} }
} }
if (! function_exists('sanitizeIntegers')) { if (! function_exists('convertNumberToIndonesianWords')) {
/** function convertNumberToIndonesianWords($angka)
* 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)
{ {
$angka = (int) abs($angka); $angka = (int) abs($angka);
$huruf = ['', 'satu', 'dua', 'tiga', 'empat', 'lima', 'enam', 'tujuh', 'delapan', 'sembilan', 'sepuluh', 'sebelas']; $huruf = ['', 'satu', 'dua', 'tiga', 'empat', 'lima', 'enam', 'tujuh', 'delapan', 'sembilan', 'sepuluh', 'sebelas'];
@ -140,46 +99,46 @@ function terbilang($angka)
return $result; return $result;
} elseif ($angka < 200) { } elseif ($angka < 200) {
return 'seratus '.terbilang($angka - 100); return 'seratus '.convertNumberToIndonesianWords($angka - 100);
} elseif ($angka < 1000) { } elseif ($angka < 1000) {
$result = $huruf[$angka / 100].' ratus'; $result = $huruf[$angka / 100].' ratus';
$sisa = $angka % 100; $sisa = $angka % 100;
if ($sisa > 0) { if ($sisa > 0) {
$result .= ' '.terbilang($sisa); $result .= ' '.convertNumberToIndonesianWords($sisa);
} }
return $result; return $result;
} elseif ($angka < 2000) { } elseif ($angka < 2000) {
return 'seribu '.terbilang($angka - 1000); return 'seribu '.convertNumberToIndonesianWords($angka - 1000);
} elseif ($angka < 1000000) { } elseif ($angka < 1000000) {
$result = terbilang($angka / 1000).' ribu'; $result = convertNumberToIndonesianWords($angka / 1000).' ribu';
$sisa = $angka % 1000; $sisa = $angka % 1000;
if ($sisa > 0) { if ($sisa > 0) {
$result .= ' '.terbilang($sisa); $result .= ' '.convertNumberToIndonesianWords($sisa);
} }
return $result; return $result;
} elseif ($angka < 1000000000) { } elseif ($angka < 1000000000) {
$result = terbilang($angka / 1000000).' juta'; $result = convertNumberToIndonesianWords($angka / 1000000).' juta';
$sisa = $angka % 1000000; $sisa = $angka % 1000000;
if ($sisa > 0) { if ($sisa > 0) {
$result .= ' '.terbilang($sisa); $result .= ' '.convertNumberToIndonesianWords($sisa);
} }
return $result; return $result;
} elseif ($angka < 1000000000000) { } elseif ($angka < 1000000000000) {
$result = terbilang($angka / 1000000000).' milyar'; $result = convertNumberToIndonesianWords($angka / 1000000000).' milyar';
$sisa = $angka % 1000000000; $sisa = $angka % 1000000000;
if ($sisa > 0) { if ($sisa > 0) {
$result .= ' '.terbilang($sisa); $result .= ' '.convertNumberToIndonesianWords($sisa);
} }
return $result; return $result;
} elseif ($angka < 1000000000000000) { } elseif ($angka < 1000000000000000) {
$result = terbilang($angka / 1000000000000).' trilyun'; $result = convertNumberToIndonesianWords($angka / 1000000000000).' trilyun';
$sisa = $angka % 1000000000000; $sisa = $angka % 1000000000000;
if ($sisa > 0) { if ($sisa > 0) {
$result .= ' '.terbilang($sisa); $result .= ' '.convertNumberToIndonesianWords($sisa);
} }
return $result; return $result;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -33,11 +33,11 @@ public function columns(): array
Column::make('Tanggal') Column::make('Tanggal')
->label(function ($row) { ->label(function ($row) {
$startDate = formatDate($row->created_at); $startDate = formatDateLocalized($row->created_at);
$startAgo = timeAgo($row->created_at); $startAgo = formatRelativeTime($row->created_at);
$endDate = formatDate($row->finalized_at); $endDate = formatDateLocalized($row->finalized_at);
$endAgo = timeAgo($row->finalized_at); $endAgo = formatRelativeTime($row->finalized_at);
return <<<HTML return <<<HTML
<div class="flex flex-col text-xs text-gray-700 dark:text-gray-300 gap-0.5"> <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') CountColumn::make('Total Order')
->setDataSource('orders') ->setDataSource('orders')
->label(fn ($value) => currency($value->orders_count)) ->label(fn ($value) => formatCurrencyNumber($value->orders_count))
->sortable(), ->sortable(),
SumColumn::make('Total Pembayaran') SumColumn::make('Total Pembayaran')
->setDataSource('orders', 'total') ->setDataSource('orders', 'total')
->label(fn ($value) => currency($value->orders_sum_total, 'Rp')) ->label(fn ($value) => formatCurrencyNumber($value->orders_sum_total, 'Rp'))
->sortable(), ->sortable(),
Column::make('Terakhir Order') Column::make('Terakhir Order')
@ -60,12 +60,12 @@ public function columns(): array
$latestOrder = $record->orders()->latest()->first(); $latestOrder = $record->orders()->latest()->first();
return $latestOrder return $latestOrder
? timeAgo($latestOrder->created_at) ? formatRelativeTime($latestOrder->created_at)
: ''; : '';
}), }),
Column::make('Terdaftar Sejak', 'created_at') Column::make('Terdaftar Sejak', 'created_at')
->format(fn ($value) => $value ? timeAgo($value) : '') ->format(fn ($value) => $value ? formatRelativeTime($value) : '')
->searchable() ->searchable()
->sortable(), ->sortable(),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -48,7 +48,7 @@ public function setExpense(Expense $expense): void
$this->expense = $expense; $this->expense = $expense;
$this->description = $expense->description; $this->description = $expense->description;
$this->amount = currency($expense->amount); $this->amount = formatCurrencyNumber($expense->amount);
$this->outlet_id = $expense->outlet_id; $this->outlet_id = $expense->outlet_id;
$this->image = $this->mapMediaCollection($expense->getMedia('image')); $this->image = $this->mapMediaCollection($expense->getMedia('image'));
@ -63,7 +63,7 @@ public function store(): void
'user_id' => auth()->id(), 'user_id' => auth()->id(),
'type' => ExpenseType::OPERATIONAL, 'type' => ExpenseType::OPERATIONAL,
'description' => $this->description, '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, '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 () { DB::transaction(function () {
$this->expense->update([ $this->expense->update([
'description' => $this->description, 'description' => $this->description,
'amount' => replaceCurrency($this->amount), 'amount' => parseRupiahToInt($this->amount),
]); ]);
$this->syncMedia($this->image, $this->expense, 'image'); $this->syncMedia($this->image, $this->expense, 'image');

View File

@ -47,7 +47,7 @@ public function store(): array
{ {
$this->validate(); $this->validate();
$amount = (int) replaceCurrency($this->amount); $amount = (int) parseRupiahToInt($this->amount);
DB::transaction(function () use ($amount, &$adjustment) { DB::transaction(function () use ($amount, &$adjustment) {
foreach ($this->user_ids as $user_id) { foreach ($this->user_ids as $user_id) {
@ -83,12 +83,12 @@ public function store(): array
if ($adjustment->type->value == SalaryAdjustmentType::BONUS->value) { if ($adjustment->type->value == SalaryAdjustmentType::BONUS->value) {
return [ return [
'userIds' => $this->user_ids, '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) { } elseif ($adjustment->type->value == SalaryAdjustmentType::DEDUCTION->value) {
return [ return [
'userIds' => $this->user_ids, '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->tier_id = $tierReward->tier_id;
$this->name = $tierReward->name; $this->name = $tierReward->name;
$this->value = currency($tierReward->value); $this->value = formatCurrencyNumber($tierReward->value);
} }
public function store(): TierReward public function store(): TierReward
@ -64,7 +64,7 @@ private function prepareSavedData(): array
return [ return [
'tier_id' => $this->tier_id, 'tier_id' => $this->tier_id,
'name' => $this->name, '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 public function withValidator($validator): void
{ {
$validator->after(function ($validator) { $validator->after(function ($validator) {
$minPoints = replaceCurrency($this->min_points); $minPoints = parseRupiahToInt($this->min_points);
$maxPoints = $this->max_points ? replaceCurrency($this->max_points) : null; $maxPoints = $this->max_points ? parseRupiahToInt($this->max_points) : null;
$ignoreId = $this->tier?->id; $ignoreId = $this->tier?->id;
$tierErrors = Tier::validateTierPoints($minPoints, $maxPoints, $ignoreId); $tierErrors = Tier::validateTierPoints($minPoints, $maxPoints, $ignoreId);
@ -83,8 +83,8 @@ private function prepareSavedData(): array
{ {
return [ return [
'name' => $this->name, 'name' => $this->name,
'min_points' => replaceCurrency($this->min_points), 'min_points' => parseRupiahToInt($this->min_points),
'max_points' => replaceCurrency($this->max_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->code = $this->voucher->code;
$this->tags = $this->voucher->tags; $this->tags = $this->voucher->tags;
$this->type = $this->voucher->type->value; $this->type = $this->voucher->type->value;
$this->discount_amount = replaceCurrency($this->voucher->discount_amount); $this->discount_amount = parseRupiahToInt($this->voucher->discount_amount);
$this->min_purchase = replaceCurrency($this->voucher->min_purchase); $this->min_purchase = parseRupiahToInt($this->voucher->min_purchase);
$this->max_discount = replaceCurrency($this->voucher->max_discount); $this->max_discount = parseRupiahToInt($this->voucher->max_discount);
$this->quota = $this->voucher->quota; $this->quota = $this->voucher->quota;
$this->limit_per_user = $this->voucher->limit_per_user; $this->limit_per_user = $this->voucher->limit_per_user;
$this->summary = $this->voucher->summary; $this->summary = $this->voucher->summary;
@ -159,9 +159,9 @@ private function prepareSavedData(): array
'code' => $this->code, 'code' => $this->code,
'tags' => $this->tags, 'tags' => $this->tags,
'type' => $this->type, 'type' => $this->type,
'discount_amount' => replaceCurrency($this->discount_amount), 'discount_amount' => parseRupiahToInt($this->discount_amount),
'min_purchase' => replaceCurrency($this->min_purchase), 'min_purchase' => parseRupiahToInt($this->min_purchase),
'max_discount' => $this->type == VoucherType::PERCENTAGE->value ? replaceCurrency($this->max_discount) : null, 'max_discount' => $this->type == VoucherType::PERCENTAGE->value ? parseRupiahToInt($this->max_discount) : null,
'quota' => $this->quota, 'quota' => $this->quota,
'available_count' => empty($this->quota) ? 0 : $this->quota, 'available_count' => empty($this->quota) ? 0 : $this->quota,
'limit_per_user' => $this->limit_per_user, 'limit_per_user' => $this->limit_per_user,

View File

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

View File

@ -121,7 +121,7 @@ private function prepareSavedData(): array
'note' => $this->note, 'note' => $this->note,
'outlet_id' => $this->outlet_id, 'outlet_id' => $this->outlet_id,
'purchase_date' => $this->purchase_date, '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->quality = $formula->quality;
$this->size = $formula->size; $this->size = $formula->size;
$this->volume = replaceCurrency($formula->volume); $this->volume = parseRupiahToInt($formula->volume);
} }
public function store(): Formula public function store(): Formula
@ -68,7 +68,7 @@ private function prepareDataForSave(): array
return [ return [
'quality' => $this->quality, 'quality' => $this->quality,
'size' => $this->size, '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'], 'full_name' => $data['full_name'],
'code' => Employee::generateEmployeeCode(), 'code' => Employee::generateEmployeeCode(),
'phone_number' => $data['phone_number'], 'phone_number' => $data['phone_number'],
'base_salary' => replaceCurrency($data['base_salary']), 'base_salary' => parseRupiahToInt($data['base_salary']),
'birthdate' => $data['birthdate'], 'birthdate' => $data['birthdate'],
'hire_date' => $data['hire_date'], 'hire_date' => $data['hire_date'],
'resign_date' => $data['resign_date'], 'resign_date' => $data['resign_date'],
@ -216,7 +216,7 @@ private function updateEmployee(array $data): void
$this->user->employee->update([ $this->user->employee->update([
'full_name' => $data['full_name'], 'full_name' => $data['full_name'],
'phone_number' => $data['phone_number'], 'phone_number' => $data['phone_number'],
'base_salary' => replaceCurrency($data['base_salary']), 'base_salary' => parseRupiahToInt($data['base_salary']),
'birthdate' => $data['birthdate'], 'birthdate' => $data['birthdate'],
'hire_date' => $data['hire_date'], 'hire_date' => $data['hire_date'],
'resign_date' => $data['resign_date'], 'resign_date' => $data['resign_date'],

View File

@ -43,7 +43,7 @@ public function setAccount(User $user): void
$this->username = $user->username; $this->username = $user->username;
$this->email = $user->email; $this->email = $user->email;
$this->status = $user->status->label(); $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 public function update(): void

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -96,7 +96,7 @@ public function save(): void
PushNotification::whereIn('user_id', $userIds)->get(), PushNotification::whereIn('user_id', $userIds)->get(),
[ [
'title' => '🛒 Order Baru!', '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'), 'url' => route('studio.manage.order.index'),
], ],
); );

View File

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

View File

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

View File

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

View File

@ -11,6 +11,6 @@ public function getSubTotal()
public function getTotal() 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 [ return [
'status' => false, '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->item_id = $item->id;
$this->form->quantity_edit = currency($item->quantity, ''); $this->form->quantity_edit = formatCurrencyNumber($item->quantity, '');
} }
public function closeModal() public function closeModal()
@ -35,7 +35,7 @@ public function updateItem()
return; return;
} }
$item->update(['quantity' => replaceCurrency($this->form->quantity_edit)]); $item->update(['quantity' => parseRupiahToInt($this->form->quantity_edit)]);
$item->refresh(); $item->refresh();

View File

@ -52,7 +52,7 @@ public function increaseOutletStock($outlet, $item)
'purchase_id' => $item->purchase_id ?? null, 'purchase_id' => $item->purchase_id ?? null,
]) ])
->event('Menambah') ->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) public function decreaseOutletStock($outlet, $item)
@ -108,6 +108,6 @@ public function decreaseOutletStock($outlet, $item)
'purchase_id' => $item->purchase_id ?? null, 'purchase_id' => $item->purchase_id ?? null,
]) ])
->event('Mengurangi') ->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': case 'parfum':
$model = Perfume::class; $model = Perfume::class;
$id = $this->form->perfume_id; $id = $this->form->perfume_id;
$quantity = replaceCurrency($this->form->quantity_perfume); $quantity = parseRupiahToInt($this->form->quantity_perfume);
break; break;
case 'produk': case 'produk':
$model = Product::class; $model = Product::class;
$id = $this->form->product_id; $id = $this->form->product_id;
$quantity = replaceCurrency($this->form->quantity_product); $quantity = parseRupiahToInt($this->form->quantity_product);
break; break;
case 'botol': case 'botol':
$model = Bottle::class; $model = Bottle::class;
$id = $this->form->bottle_id; $id = $this->form->bottle_id;
$quantity = replaceCurrency($this->form->quantity_bottle); $quantity = parseRupiahToInt($this->form->quantity_bottle);
break; break;
default: default:
@ -89,7 +89,7 @@ public function addItem(string $type)
$this->toast(Str::ucfirst($type).' ditambahkan ke keranjang.', 'Berhasil'); $this->toast(Str::ucfirst($type).' ditambahkan ke keranjang.', 'Berhasil');
} }
$this->form->total = currency($this->getTotal()); $this->form->total = formatCurrencyNumber($this->getTotal());
switch ($type) { switch ($type) {
case 'parfum': case 'parfum':

View File

@ -12,7 +12,7 @@ public function deleteItem(PurchaseItem $item)
$item->delete(); $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.'); $this->toast('Item berhasil dihapus.');
} }

View File

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

View File

@ -53,7 +53,7 @@ public function increaseOutletStock($outlet, $item)
'purchase_id' => $item->purchase_id ?? null, 'purchase_id' => $item->purchase_id ?? null,
]) ])
->event('Menambah') ->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) 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" /> dark:border-gray-700" />
<div class="flex flex-wrap gap-4 text-sm "> <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" /> <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" /> <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> </div>
<flux:separator class="my-2 dark:border-gray-700" /> <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 class="flex justify-between items-center mb-3">
<div> <div>
<flux:heading>{{ $payroll->user->employee->full_name }}</flux:heading> <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>
<div class="text-right"> <div class="text-right">
<flux:badge color="{{ $payroll->is_paid->color() }}"> <flux:badge color="{{ $payroll->is_paid->color() }}">
@ -42,15 +42,15 @@
<div class="grid grid-cols-1 gap-4 mb-2 text-sm"> <div class="grid grid-cols-1 gap-4 mb-2 text-sm">
<div> <div>
<flux:text>Gaji Pokok</flux:text> <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>
<div> <div>
<flux:text>Bonus</flux:text> <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>
<div> <div>
<flux:text>Potongan</flux:text> <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>
</div> </div>
@ -62,7 +62,7 @@
<div> <div>
<div <div
class="font-bold {{ $item->type->value == \App\Enums\SalaryAdjustmentType::DEDUCTION->value ? 'text-red-500' : 'text-green-500' }}"> 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>
<div class="text-gray-400 text-[12px]">{{ $item->description }}</div> <div class="text-gray-400 text-[12px]">{{ $item->description }}</div>
</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"> <div class="flex justify-between items-center mt-2">
<flux:text>Total Gaji</flux:text> <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> </div>
</flux:card> </flux:card>
@endforeach @endforeach
@ -133,16 +133,16 @@ class="font-bold {{ $item->type->value == \App\Enums\SalaryAdjustmentType::DEDUC
</flux:label> </flux:label>
<flux:input.group> <flux:input.group>
<flux:input.group.prefix>Rp</flux:input.group.prefix> <flux:input.group.prefix>Rp</flux:input.group.prefix>
<flux:input placeholder="1.500.000" x-mask:dynamic="$money($input, ',')" <flux:input placeholder="1.500.000" x-mask:dynamic="$money($input, ',')" wire:model="form.amount"
wire:model="form.amount" autocomplete="off" autofocus /> autocomplete="off" autofocus />
</flux:input.group> </flux:input.group>
<flux:error name="form.amount" /> <flux:error name="form.amount" />
</flux:field> </flux:field>
<flux:field> <flux:field>
<flux:label>Keterangan <span class="text-red-500 ms-1">*</span></flux:label> <flux:label>Keterangan <span class="text-red-500 ms-1">*</span></flux:label>
<flux:input placeholder="Gajian bulan xxx + bonus ya, semangat kerjanya" <flux:input placeholder="Gajian bulan xxx + bonus ya, semangat kerjanya" wire:model="form.description"
wire:model="form.description" autocomplete="off" /> autocomplete="off" />
<flux:error name="form.description" /> <flux:error name="form.description" />
</flux:field> </flux:field>

View File

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

View File

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

View File

@ -149,14 +149,14 @@
<div> <div>
<div>{{ $item->purchasable->name }}</div> <div>{{ $item->purchasable->name }}</div>
<span <span
class="text-xs text-gray-400">{{ currency($item->quantity, '') }} class="text-xs text-gray-400">{{ formatCurrencyNumber($item->quantity, '') }}
x x
{{ currency($item->purchasable->cost_price, 'Rp') }}</span> {{ formatCurrencyNumber($item->purchasable->cost_price, 'Rp') }}</span>
</div> </div>
</flux:heading> </flux:heading>
</flux:table.cell> </flux:table.cell>
<flux:table.cell> <flux:table.cell>
{{ currency($item->total_price, 'Rp') }} {{ formatCurrencyNumber($item->total_price, 'Rp') }}
</flux:table.cell> </flux:table.cell>
<flux:table.cell class="space-x-2"> <flux:table.cell class="space-x-2">
<flux:modal.trigger name="form-modal"> <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> <div>
<span class="font-medium text-gray-900 dark:text-white">Tgl Buka:</span> <span class="font-medium text-gray-900 dark:text-white">Tgl Buka:</span>
<span <span
class="text-gray-700 dark:text-gray-300">{{ formatDate($outlet->opened_date) }}</span> class="text-gray-700 dark:text-gray-300">{{ formatDateLocalized($outlet->opened_date) }}</span>
<span class="text-gray-500">({{ timeAgo($outlet->opened_date) }})</span> <span class="text-gray-500">({{ formatRelativeTime($outlet->opened_date) }})</span>
</div> </div>
@if ($outlet->closed_date) @if ($outlet->closed_date)
<div> <div>
<span class="font-medium text-gray-900 dark:text-white">Tgl Tutup:</span> <span class="font-medium text-gray-900 dark:text-white">Tgl Tutup:</span>
<span <span
class="text-gray-700 dark:text-gray-300">{{ formatDate($outlet->closed_date) }}</span> class="text-gray-700 dark:text-gray-300">{{ formatDateLocalized($outlet->closed_date) }}</span>
<span class="text-gray-500">({{ timeAgo($outlet->closed_date) }})</span> <span
class="text-gray-500">({{ formatRelativeTime($outlet->closed_date) }})</span>
</div> </div>
@endif @endif
</div> </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> <div>
<flux:heading class="uppercase font-semibold text-gray-500 dark:text-gray-400 ">Gaji <flux:heading class="uppercase font-semibold text-gray-500 dark:text-gray-400 ">Gaji
</flux:heading> </flux:heading>
<flux:text>{{ currency($employee->base_salary, 'Rp') }}</flux:text> <flux:text>{{ formatCurrencyNumber($employee->base_salary, 'Rp') }}</flux:text>
</div> </div>
</div> </div>
@ -155,24 +155,26 @@ class="text-xs text-gray-400 border border-gray-400 rounded px-2 py-1">
<div> <div>
<span class="font-medium text-gray-900 dark:text-white">Tgl Lahir:</span> <span class="font-medium text-gray-900 dark:text-white">Tgl Lahir:</span>
<span <span
class="text-gray-700 dark:text-gray-300">{{ formatDate($employee->birthdate) }}</span> class="text-gray-700 dark:text-gray-300">{{ formatDateLocalized($employee->birthdate) }}</span>
<span class="text-gray-500">({{ getAge($employee->birthdate) }})</span> <span
class="text-gray-500">({{ formatAgeYearsMonths($employee->birthdate) }})</span>
</div> </div>
<div> <div>
<span class="font-medium text-gray-900 dark:text-white">Tgl <span class="font-medium text-gray-900 dark:text-white">Tgl
Bergabung:</span> Bergabung:</span>
<span <span
class="text-gray-700 dark:text-gray-300">{{ formatDate($employee->hire_date) }}</span> class="text-gray-700 dark:text-gray-300">{{ formatDateLocalized($employee->hire_date) }}</span>
<span class="text-gray-500">({{ timeAgo($employee->hire_date) }})</span> <span
class="text-gray-500">({{ formatRelativeTime($employee->hire_date) }})</span>
</div> </div>
@if ($employee->resign_date) @if ($employee->resign_date)
<div> <div>
<span class="font-medium text-gray-900 dark:text-white">Tgl <span class="font-medium text-gray-900 dark:text-white">Tgl
Resign:</span> Resign:</span>
<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 <span
class="text-gray-500">({{ timeAgo($employee->resign_date) }})</span> class="text-gray-500">({{ formatRelativeTime($employee->resign_date) }})</span>
</div> </div>
@endif @endif
</div> </div>

View File

@ -576,8 +576,8 @@ function mountTierComponent(User $user)
$component = mountTierComponent($this->user); $component = mountTierComponent($this->user);
$loadedTier = $component->tiers->firstWhere('id', $tier->id); $loadedTier = $component->tiers->firstWhere('id', $tier->id);
expect(currency($loadedTier->min_points))->toContain('1.000'); expect(formatCurrencyNumber($loadedTier->min_points))->toContain('1.000');
expect(currency($loadedTier->max_points))->toContain('5.000'); expect(formatCurrencyNumber($loadedTier->max_points))->toContain('5.000');
}); });
it('handles currency formatting in form input', function () { it('handles currency formatting in form input', function () {
@ -610,7 +610,7 @@ function mountTierComponent(User $user)
$component = mountTierComponent($this->user); $component = mountTierComponent($this->user);
$loadedTier = $component->tiers->firstWhere('id', $tier->id); $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 () { it('handles tier with zero min_points', function () {
@ -623,7 +623,7 @@ function mountTierComponent(User $user)
$component = mountTierComponent($this->user); $component = mountTierComponent($this->user);
$loadedTier = $component->tiers->firstWhere('id', $tier->id); $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 () { it('handles empty tiers list', function () {
@ -648,6 +648,6 @@ function mountTierComponent(User $user)
$updatedTier = $component->tiers->firstWhere('hash', $tier->hash); $updatedTier = $component->tiers->firstWhere('hash', $tier->hash);
expect($updatedTier->name)->toBe('Gold'); expect($updatedTier->name)->toBe('Gold');
expect(currency($updatedTier->min_points))->toContain('1.000'); expect(formatCurrencyNumber($updatedTier->min_points))->toContain('1.000');
expect(currency($updatedTier->max_points))->toContain('5.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); $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 // The form will display formatted currency in the view
expect($component->form->discount_amount)->toBe('50000'); expect($component->form->discount_amount)->toBe('50000');
expect($component->form->min_purchase)->toBe('200000'); expect($component->form->min_purchase)->toBe('200000');