refactor: improve formatting consistency in various models and services

This commit is contained in:
Yoga Pangestu 2026-08-05 20:27:27 +07:00
parent b70a40af4d
commit 3f77a9436d
28 changed files with 61 additions and 67 deletions

View File

@ -39,7 +39,7 @@ public function create(): Response
public function store(EmployeeRequest $request): RedirectResponse
{
return $this->handleAction(
fn() => $this->service->create($request->validated()),
fn () => $this->service->create($request->validated()),
'Pegawai berhasil ditambahkan.',
'admin.hr.employees.index'
);
@ -58,7 +58,7 @@ public function edit(User $user): Response
public function update(EmployeeRequest $request, User $user): RedirectResponse
{
return $this->handleAction(
fn() => $this->service->update($user, $request->validated()),
fn () => $this->service->update($user, $request->validated()),
'Pegawai berhasil diperbarui.',
'admin.hr.employees.index'
);
@ -67,7 +67,7 @@ public function update(EmployeeRequest $request, User $user): RedirectResponse
public function destroy(User $user): RedirectResponse
{
return $this->handleAction(
fn() => $this->service->delete($user),
fn () => $this->service->delete($user),
'Pegawai berhasil dihapus.',
'admin.hr.employees.index'
);
@ -86,7 +86,7 @@ public function toggleActive(User $user): RedirectResponse
public function resetPassword(User $user): RedirectResponse
{
return $this->handleAction(
fn() => $this->service->resetPassword($user),
fn () => $this->service->resetPassword($user),
'Kata sandi pegawai berhasil direset ke kata sandi default.',
'admin.hr.employees.index'
);

View File

@ -27,7 +27,7 @@ protected function casts(): array
protected function formattedBalance(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->balance, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->balance, 0, ',', '.'),
);
}

View File

@ -36,14 +36,14 @@ protected function casts(): array
protected function formattedAmount(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->amount, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->amount, 0, ',', '.'),
);
}
protected function formattedBalanceAfter(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->balance_after, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->balance_after, 0, ',', '.'),
);
}

View File

@ -27,7 +27,7 @@ protected function formattedPhoneNumber(): Attribute
{
return Attribute::make(
get: fn () => $this->phone_number
? substr($this->phone_number, 0, 4) . ' ' . substr($this->phone_number, 4, 4) . ' ' . substr($this->phone_number, 8)
? substr($this->phone_number, 0, 4).' '.substr($this->phone_number, 4, 4).' '.substr($this->phone_number, 8)
: null,
set: fn (?string $value) => $value ? preg_replace('/\s/', '', $value) : null,
);

View File

@ -36,21 +36,21 @@ protected function casts(): array
protected function formattedCostPerUnit(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->cost_per_unit, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->cost_per_unit, 0, ',', '.'),
);
}
protected function formattedOtherCost(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->other_cost, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->other_cost, 0, ',', '.'),
);
}
protected function formattedSewingCost(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->sewing_cost, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->sewing_cost, 0, ',', '.'),
);
}
@ -64,7 +64,7 @@ protected function statusLabel(): Attribute
protected function formattedTotalMaterialCost(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->total_material_cost, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->total_material_cost, 0, ',', '.'),
);
}

View File

@ -33,7 +33,7 @@ protected function casts(): array
protected function formattedBaseSalary(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->base_salary, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->base_salary, 0, ',', '.'),
);
}

View File

@ -34,7 +34,7 @@ protected function casts(): array
protected function formattedAmount(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->amount, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->amount, 0, ',', '.'),
);
}
@ -55,7 +55,7 @@ protected function formattedDueDate(): Attribute
protected function formattedPaidAmount(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->paid_amount, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->paid_amount, 0, ',', '.'),
);
}

View File

@ -29,7 +29,7 @@ protected function casts(): array
protected function formattedAmount(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->amount, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->amount, 0, ',', '.'),
);
}

View File

@ -52,21 +52,21 @@ protected function channelLabel(): Attribute
protected function formattedCogs(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->cogs, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->cogs, 0, ',', '.'),
);
}
protected function formattedDiscount(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->discount, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->discount, 0, ',', '.'),
);
}
protected function formattedNegoPrice(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->nego_price, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->nego_price, 0, ',', '.'),
);
}
@ -87,14 +87,14 @@ protected function statusLabel(): Attribute
protected function formattedSubtotal(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->subtotal, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->subtotal, 0, ',', '.'),
);
}
protected function formattedTotalAmount(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->total_amount, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->total_amount, 0, ',', '.'),
);
}

View File

@ -39,14 +39,14 @@ protected function stockQualityLabel(): Attribute
protected function formattedSubtotal(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->subtotal, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->subtotal, 0, ',', '.'),
);
}
protected function formattedUnitPrice(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->unit_price, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->unit_price, 0, ',', '.'),
);
}

View File

@ -35,28 +35,28 @@ protected function casts(): array
protected function formattedBaseSalary(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->base_salary, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->base_salary, 0, ',', '.'),
);
}
protected function formattedBonusAmount(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->bonus_amount, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->bonus_amount, 0, ',', '.'),
);
}
protected function formattedDeductionAmount(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->deduction_amount, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->deduction_amount, 0, ',', '.'),
);
}
protected function formattedAmount(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->attributes['total_amount'] ?? 0, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->attributes['total_amount'] ?? 0, 0, ',', '.'),
);
}
@ -70,7 +70,7 @@ protected function statusLabel(): Attribute
protected function formattedTotalAmount(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->total_amount, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->total_amount, 0, ',', '.'),
);
}

View File

@ -30,7 +30,7 @@ protected function casts(): array
protected function formattedAmount(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->amount, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->amount, 0, ',', '.'),
);
}

View File

@ -29,7 +29,7 @@ protected function casts(): array
protected function formattedPrice(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->price, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->price, 0, ',', '.'),
);
}

View File

@ -32,28 +32,28 @@ protected function casts(): array
protected function formattedDiscount(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->discount, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->discount, 0, ',', '.'),
);
}
protected function formattedShippingCost(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->shipping_cost, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->shipping_cost, 0, ',', '.'),
);
}
protected function formattedSubtotal(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->subtotal, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->subtotal, 0, ',', '.'),
);
}
protected function formattedTotal(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->total, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->total, 0, ',', '.'),
);
}

View File

@ -28,14 +28,14 @@ protected function casts(): array
protected function formattedSubtotal(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->subtotal, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->subtotal, 0, ',', '.'),
);
}
protected function formattedUnitPrice(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->unit_price, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->unit_price, 0, ',', '.'),
);
}

View File

@ -34,7 +34,7 @@ protected function casts(): array
protected function formattedPrice(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->price, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->price, 0, ',', '.'),
);
}

View File

@ -41,14 +41,14 @@ protected function stockTypeLabel(): Attribute
protected function formattedSubtotal(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->subtotal, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->subtotal, 0, ',', '.'),
);
}
protected function formattedTotal(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->total, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->total, 0, ',', '.'),
);
}

View File

@ -28,14 +28,14 @@ protected function casts(): array
protected function formattedSubtotal(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->subtotal, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->subtotal, 0, ',', '.'),
);
}
protected function formattedUnitPrice(): Attribute
{
return Attribute::make(
get: fn () => 'Rp ' . number_format($this->unit_price, 0, ',', '.'),
get: fn () => 'Rp '.number_format($this->unit_price, 0, ',', '.'),
);
}

View File

@ -27,7 +27,7 @@ protected function formattedPhoneNumber(): Attribute
{
return Attribute::make(
get: fn () => $this->phone_number
? substr($this->phone_number, 0, 4) . ' ' . substr($this->phone_number, 4, 4) . ' ' . substr($this->phone_number, 8)
? substr($this->phone_number, 0, 4).' '.substr($this->phone_number, 4, 4).' '.substr($this->phone_number, 8)
: null,
set: fn (?string $value) => $value ? preg_replace('/\s/', '', $value) : null,
);

View File

@ -45,7 +45,7 @@ protected function formattedPhoneNumber(): Attribute
{
return Attribute::make(
get: fn () => $this->phone_number
? substr($this->phone_number, 0, 4) . ' ' . substr($this->phone_number, 4, 4) . ' ' . substr($this->phone_number, 8)
? substr($this->phone_number, 0, 4).' '.substr($this->phone_number, 4, 4).' '.substr($this->phone_number, 8)
: null,
set: fn (?string $value) => $value ? preg_replace('/\s/', '', $value) : null,
);

View File

@ -2,10 +2,8 @@
namespace App\Services\Admin\Finance;
use App\Enums\CashTransactionType;
use App\Enums\EmployeeAdvanceStatus;
use App\Models\CashAccount;
use App\Models\CashTransaction;
use App\Models\EmployeeAdvance;
use App\Services\Concerns\HandlesCashTransactions;
use App\Services\NotificationService;
@ -17,6 +15,7 @@
class EmployeeAdvanceService
{
use HandlesCashTransactions;
public function getAll(array $filters = []): Collection
{
return EmployeeAdvance::select('id', 'employee_id', 'amount', 'paid_amount', 'description', 'due_date', 'status', 'created_at')

View File

@ -2,9 +2,7 @@
namespace App\Services\Admin\Finance;
use App\Enums\CashTransactionType;
use App\Models\CashAccount;
use App\Models\CashTransaction;
use App\Models\Expense;
use App\Services\Concerns\HandlesCashTransactions;
use App\Services\Concerns\RegistersMedia;

View File

@ -2,11 +2,8 @@
namespace App\Services\Admin\Finance;
use App\Enums\CashTransactionType;
use App\Enums\PayrollPeriodStatus;
use App\Enums\PayrollStatus;
use App\Models\CashAccount;
use App\Models\CashTransaction;
use App\Models\Payroll;
use App\Models\PayrollPeriod;
use App\Services\Concerns\HandlesCashTransactions;
@ -19,6 +16,7 @@
class PayrollPeriodService
{
use HandlesCashTransactions;
public function getAll(array $filters = []): Collection
{
return PayrollPeriod::select('id', 'year', 'month', 'status', 'closed_at', 'created_at')

View File

@ -14,13 +14,13 @@ public function getAll(array $filters = []): Collection
return User::select(['id', 'email', 'username', 'is_active'])
->where(fn ($q) => $q->whereHas('employee')->orWhereHas('roles', fn ($rq) => $rq->where('name', 'Owner')))
->with([
'userProfile' => fn($q) => $q->select('id', 'user_id', 'full_name', 'phone_number', 'gender'),
'employee' => fn($q) => $q->select('id', 'user_id', 'join_date', 'employment_status', 'base_salary'),
'roles' => fn($q) => $q->select('id', 'name'),
'userProfile' => fn ($q) => $q->select('id', 'user_id', 'full_name', 'phone_number', 'gender'),
'employee' => fn ($q) => $q->select('id', 'user_id', 'join_date', 'employment_status', 'base_salary'),
'roles' => fn ($q) => $q->select('id', 'name'),
])
->when($filters['employment_status'] ?? null, fn($q, $status) => $q->whereHas('employee', fn($eq) => $eq->where('employment_status', $status)))
->when(isset($filters['is_active']) && $filters['is_active'] !== '', fn($q) => $q->where('is_active', filter_var($filters['is_active'], FILTER_VALIDATE_BOOLEAN)))
->when($filters['gender'] ?? null, fn($q, $gender) => $q->whereHas('userProfile', fn($uq) => $uq->where('gender', $gender)))
->when($filters['employment_status'] ?? null, fn ($q, $status) => $q->whereHas('employee', fn ($eq) => $eq->where('employment_status', $status)))
->when(isset($filters['is_active']) && $filters['is_active'] !== '', fn ($q) => $q->where('is_active', filter_var($filters['is_active'], FILTER_VALIDATE_BOOLEAN)))
->when($filters['gender'] ?? null, fn ($q, $gender) => $q->whereHas('userProfile', fn ($uq) => $uq->where('gender', $gender)))
->latest()
->get();
}
@ -31,14 +31,14 @@ public function paginated(int $perPage = 25, string $search = '', string $sort =
->select(['id', 'email', 'username', 'is_active'])
->where(fn ($q) => $q->whereHas('employee')->orWhereHas('roles', fn ($rq) => $rq->where('name', 'Owner')))
->with([
'userProfile' => fn($q) => $q->select('id', 'user_id', 'full_name', 'phone_number', 'gender'),
'employee' => fn($q) => $q->select('id', 'user_id', 'join_date', 'employment_status', 'base_salary'),
'roles' => fn($q) => $q->select('id', 'name'),
'userProfile' => fn ($q) => $q->select('id', 'user_id', 'full_name', 'phone_number', 'gender'),
'employee' => fn ($q) => $q->select('id', 'user_id', 'join_date', 'employment_status', 'base_salary'),
'roles' => fn ($q) => $q->select('id', 'name'),
])
->when($search, fn($q) => $q->whereHas('userProfile', fn($uq) => $uq->where('full_name', 'like', "%{$search}%")))
->when($filters['employment_status'] ?? null, fn($q, $status) => $q->whereHas('employee', fn($eq) => $eq->where('employment_status', $status)))
->when(isset($filters['is_active']) && $filters['is_active'] !== '', fn($q) => $q->where('is_active', filter_var($filters['is_active'], FILTER_VALIDATE_BOOLEAN)))
->when($filters['gender'] ?? null, fn($q, $gender) => $q->whereHas('userProfile', fn($uq) => $uq->where('gender', $gender)))
->when($search, fn ($q) => $q->whereHas('userProfile', fn ($uq) => $uq->where('full_name', 'like', "%{$search}%")))
->when($filters['employment_status'] ?? null, fn ($q, $status) => $q->whereHas('employee', fn ($eq) => $eq->where('employment_status', $status)))
->when(isset($filters['is_active']) && $filters['is_active'] !== '', fn ($q) => $q->where('is_active', filter_var($filters['is_active'], FILTER_VALIDATE_BOOLEAN)))
->when($filters['gender'] ?? null, fn ($q, $gender) => $q->whereHas('userProfile', fn ($uq) => $uq->where('gender', $gender)))
->orderBy($sort, $direction)
->paginate($perPage);
}

View File

@ -241,5 +241,4 @@ private function buildItemRows(array $items, string $stockType, $now, int &$subt
];
})->toArray();
}
}

View File

@ -5,7 +5,6 @@
use App\Enums\CashTransactionType;
use App\Models\CashAccount;
use App\Models\CashTransaction;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\ValidationException;
trait HandlesCashTransactions

View File

@ -3,6 +3,7 @@
namespace App\Services\Concerns;
use App\Enums\ProductStockQuality;
use App\Models\ProductVariant;
use Illuminate\Database\Eloquent\Model;
trait HasStockAdjustment
@ -26,7 +27,7 @@ private function adjustVariantStock(int $variantId, int $quantity, int $sign, st
$field = self::QUALITY_STOCK_MAP[$stockType] ?? 'stock';
$this->adjustStock(
model: app(\App\Models\ProductVariant::class)->newQuery()->findOrFail($variantId),
model: app(ProductVariant::class)->newQuery()->findOrFail($variantId),
field: $field,
quantity: $quantity,
sign: $sign,

View File

@ -60,7 +60,7 @@ public function run(): void
$developerOwnerPerms = array_values(array_filter(
$allPermissions,
fn($p) => ! in_array($p, $excludedFromDeveloperOwner, true)
fn ($p) => ! in_array($p, $excludedFromDeveloperOwner, true)
));
$rolePermissions = [