- New Expenses module: purchases (materials, other) with a description and cost, and mileage priced with the price list's mileage rate. - Who paid and whether the expense is billed are separate: an employee's own payments are reimbursed elsewhere. A billed expense has a markup and a billed amount, cost plus markup unless given. - A job's expenses page lists, adds, edits and removes them; amounts of others' expenses need the expenses permission, own ones always show. Done jobs lock their expenses. - The Kulut menu shows the user's own expenses by month. Management records subcontractors' expenses, which they see but cannot change. - The price list gets a default markup for new purchases. - Number fields that update a calculation now use wire:model.live.blur: in Livewire 4 plain .blur no longer sends the value to the server, which also fixes the product form's VAT calculation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
63 lines
2.0 KiB
PHP
63 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Expenses\Presentation\Livewire\Concerns;
|
|
|
|
use App\Modules\Expenses\Application\DTOs\ExpenseSummary;
|
|
use App\Modules\Expenses\Domain\Enums\ExpenseCategory;
|
|
use App\Modules\Expenses\Domain\ValueObjects\Kilometers;
|
|
use App\Modules\Shared\Domain\ValueObjects\Money;
|
|
use Carbon\CarbonImmutable;
|
|
|
|
/**
|
|
* Formatting shared by the expense lists: labels, dates and amounts, which
|
|
* are shown only to those who may see them.
|
|
*/
|
|
trait ShowsExpenses
|
|
{
|
|
public function canSeeAmount(ExpenseSummary $expense): bool
|
|
{
|
|
return auth()->user()?->can('expenses.see-amount', [$expense->userId, $expense->recordedBy]) ?? false;
|
|
}
|
|
|
|
public function canChange(ExpenseSummary $expense): bool
|
|
{
|
|
return ! $expense->job->isLocked
|
|
&& (auth()->user()?->can('expenses.change', [$expense->userId, $expense->recordedBy]) ?? false);
|
|
}
|
|
|
|
public function amount(ExpenseSummary $expense, ?int $cents): string
|
|
{
|
|
if (! $this->canSeeAmount($expense)) {
|
|
return __('expenses.hidden_amount');
|
|
}
|
|
|
|
return $cents === null ? __('expenses.not_billed') : Money::fromCents($cents)->format();
|
|
}
|
|
|
|
public function money(int $cents): string
|
|
{
|
|
return Money::fromCents($cents)->format();
|
|
}
|
|
|
|
/**
|
|
* What the expense is: the description, or for kilometres "40 km, Tampere (Asiakastapaaminen)".
|
|
*/
|
|
public function summaryText(ExpenseSummary $expense): string
|
|
{
|
|
if ($expense->category !== ExpenseCategory::Mileage || $expense->kilometerTenths === null) {
|
|
return (string) $expense->description;
|
|
}
|
|
|
|
return __('expenses.mileage_summary', [
|
|
'km' => (new Kilometers($expense->kilometerTenths))->format(),
|
|
'destination' => $expense->destination,
|
|
'purpose' => $expense->purpose,
|
|
]);
|
|
}
|
|
|
|
public function dayLabel(string $day): string
|
|
{
|
|
return CarbonImmutable::parse($day)->format('j.n.Y');
|
|
}
|
|
}
|