Add the quoted amount and completion time to customer jobs
- Jobs get a budget / quoted amount (cents, VAT 0). Only users who may see quotes see and edit it on the job form and page, and only they see its changes in the history. Others' saves keep the stored amount: the server decides whether the amount is set, not the browser. - Jobs record when they were done: set when a job first reaches a status that locks its hours, kept through the billing statuses, cleared when management opens the lock. The billing export will use it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -40,5 +40,7 @@ final readonly class CustomerJobData
|
|||||||
public array $memberUserIds = [],
|
public array $memberUserIds = [],
|
||||||
public array $tags = [],
|
public array $tags = [],
|
||||||
public array $links = [],
|
public array $links = [],
|
||||||
|
public ?string $quotedAmount = null,
|
||||||
|
public bool $setsQuotedAmount = false,
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ final readonly class CustomerJobDetails
|
|||||||
public array $links,
|
public array $links,
|
||||||
public string $createdAt,
|
public string $createdAt,
|
||||||
public string $createdByName,
|
public string $createdByName,
|
||||||
|
public ?int $quotedAmountCents = null,
|
||||||
|
public ?string $completedAt = null,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ use App\Modules\Jobs\Domain\ValueObjects\JobDetails;
|
|||||||
use App\Modules\Jobs\Domain\ValueObjects\JobLink;
|
use App\Modules\Jobs\Domain\ValueObjects\JobLink;
|
||||||
use App\Modules\Jobs\Domain\ValueObjects\JobName;
|
use App\Modules\Jobs\Domain\ValueObjects\JobName;
|
||||||
use App\Modules\Jobs\Domain\ValueObjects\Tag;
|
use App\Modules\Jobs\Domain\ValueObjects\Tag;
|
||||||
|
use App\Modules\Shared\Domain\Exceptions\InvalidMoneyAmount;
|
||||||
|
use App\Modules\Shared\Domain\ValueObjects\Money;
|
||||||
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||||
use App\Modules\Users\Domain\Enums\Role;
|
use App\Modules\Users\Domain\Enums\Role;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
@@ -36,7 +38,11 @@ final class JobDetailsFactory
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The quoted amount changes only when the caller may set it
|
||||||
|
* ($data->setsQuotedAmount); otherwise the job keeps its amount.
|
||||||
|
*
|
||||||
* @throws InvalidJobReference
|
* @throws InvalidJobReference
|
||||||
|
* @throws InvalidMoneyAmount
|
||||||
*/
|
*/
|
||||||
public function build(CustomerJobData $data, ?JobDetails $current = null): JobDetails
|
public function build(CustomerJobData $data, ?JobDetails $current = null): JobDetails
|
||||||
{
|
{
|
||||||
@@ -66,6 +72,7 @@ final class JobDetailsFactory
|
|||||||
memberUserIds: $data->memberUserIds,
|
memberUserIds: $data->memberUserIds,
|
||||||
tags: array_map(fn (string $tag): Tag => new Tag($tag), $data->tags),
|
tags: array_map(fn (string $tag): Tag => new Tag($tag), $data->tags),
|
||||||
links: array_map(fn (array $link): JobLink => new JobLink($link['title'], $link['url']), $data->links),
|
links: array_map(fn (array $link): JobLink => new JobLink($link['title'], $link['url']), $data->links),
|
||||||
|
quotedAmount: $data->setsQuotedAmount ? Money::parse((string) $data->quotedAmount) : $current?->quotedAmount,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use App\Modules\Jobs\Domain\Contracts\CustomerJobRepository;
|
|||||||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||||
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
|
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
|
||||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||||
|
use App\Modules\Users\Application\Contracts\Clock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves a job to another status (e.g. on the Kanban board) and records it.
|
* Moves a job to another status (e.g. on the Kanban board) and records it.
|
||||||
@@ -17,6 +18,7 @@ final class ChangeJobStatus
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private CustomerJobRepository $jobs,
|
private CustomerJobRepository $jobs,
|
||||||
private TransactionManager $transactions,
|
private TransactionManager $transactions,
|
||||||
|
private Clock $clock,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,6 +29,7 @@ final class ChangeJobStatus
|
|||||||
$this->transactions->run(function () use ($jobId, $status, $actorUserId): void {
|
$this->transactions->run(function () use ($jobId, $status, $actorUserId): void {
|
||||||
$job = $this->jobs->findById($jobId) ?? throw new CustomerJobNotFound($jobId);
|
$job = $this->jobs->findById($jobId) ?? throw new CustomerJobNotFound($jobId);
|
||||||
$changes = $job->changeStatus($status);
|
$changes = $job->changeStatus($status);
|
||||||
|
$job->recordCompletion($this->clock->now());
|
||||||
|
|
||||||
if ($changes === []) {
|
if ($changes === []) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ final class CreateCustomerJob
|
|||||||
|
|
||||||
return $this->transactions->run(function () use ($details, $year, $actorUserId): int {
|
return $this->transactions->run(function () use ($details, $year, $actorUserId): int {
|
||||||
$job = CustomerJob::open($this->numbers->next($year), $details, $actorUserId);
|
$job = CustomerJob::open($this->numbers->next($year), $details, $actorUserId);
|
||||||
|
$job->recordCompletion($this->clock->now());
|
||||||
$jobId = (int) $this->jobs->save($job)->id();
|
$jobId = (int) $this->jobs->save($job)->id();
|
||||||
|
|
||||||
$this->jobs->recordChanges($jobId, $actorUserId, [new FieldChange('created', null, $job->number()->format())]);
|
$this->jobs->recordChanges($jobId, $actorUserId, [new FieldChange('created', null, $job->number()->format())]);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use App\Modules\Jobs\Domain\Contracts\CustomerJobRepository;
|
|||||||
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
|
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
|
||||||
use App\Modules\Jobs\Domain\Exceptions\InvalidJobReference;
|
use App\Modules\Jobs\Domain\Exceptions\InvalidJobReference;
|
||||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||||
|
use App\Modules\Users\Application\Contracts\Clock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes a customer job and records each changed field in its history.
|
* Changes a customer job and records each changed field in its history.
|
||||||
@@ -21,6 +22,7 @@ final class UpdateCustomerJob
|
|||||||
private CustomerJobRepository $jobs,
|
private CustomerJobRepository $jobs,
|
||||||
private JobDetailsFactory $detailsFactory,
|
private JobDetailsFactory $detailsFactory,
|
||||||
private TransactionManager $transactions,
|
private TransactionManager $transactions,
|
||||||
|
private Clock $clock,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,6 +35,7 @@ final class UpdateCustomerJob
|
|||||||
$job = $this->jobs->findById($jobId) ?? throw new CustomerJobNotFound($jobId);
|
$job = $this->jobs->findById($jobId) ?? throw new CustomerJobNotFound($jobId);
|
||||||
|
|
||||||
$changes = $job->changeDetails($this->detailsFactory->build($data, $job->details()));
|
$changes = $job->changeDetails($this->detailsFactory->build($data, $job->details()));
|
||||||
|
$job->recordCompletion($this->clock->now());
|
||||||
|
|
||||||
if ($changes === []) {
|
if ($changes === []) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -8,10 +8,13 @@ use App\Modules\Jobs\Domain\Enums\JobStatus;
|
|||||||
use App\Modules\Jobs\Domain\ValueObjects\FieldChange;
|
use App\Modules\Jobs\Domain\ValueObjects\FieldChange;
|
||||||
use App\Modules\Jobs\Domain\ValueObjects\JobDetails;
|
use App\Modules\Jobs\Domain\ValueObjects\JobDetails;
|
||||||
use App\Modules\Jobs\Domain\ValueObjects\JobNumber;
|
use App\Modules\Jobs\Domain\ValueObjects\JobNumber;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A customer job (asiakastyö): the work done for a customer, which tasks,
|
* A customer job (asiakastyö): the work done for a customer, which tasks,
|
||||||
* time entries and invoices are attached to.
|
* time entries and invoices are attached to. It knows when it was done:
|
||||||
|
* reaching a status that locks hours sets the time, and opening the lock
|
||||||
|
* clears it.
|
||||||
*/
|
*/
|
||||||
final class CustomerJob
|
final class CustomerJob
|
||||||
{
|
{
|
||||||
@@ -20,6 +23,7 @@ final class CustomerJob
|
|||||||
private JobNumber $number,
|
private JobNumber $number,
|
||||||
private JobDetails $details,
|
private JobDetails $details,
|
||||||
private int $createdBy,
|
private int $createdBy,
|
||||||
|
private ?DateTimeImmutable $completedAt = null,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public static function open(JobNumber $number, JobDetails $details, int $createdBy): self
|
public static function open(JobNumber $number, JobDetails $details, int $createdBy): self
|
||||||
@@ -27,9 +31,30 @@ final class CustomerJob
|
|||||||
return new self(null, $number, $details, $createdBy);
|
return new self(null, $number, $details, $createdBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function reconstitute(int $id, JobNumber $number, JobDetails $details, int $createdBy): self
|
public static function reconstitute(int $id, JobNumber $number, JobDetails $details, int $createdBy, ?DateTimeImmutable $completedAt = null): self
|
||||||
{
|
{
|
||||||
return new self($id, $number, $details, $createdBy);
|
return new self($id, $number, $details, $createdBy, $completedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keeps the completion time in step with the status: set when the job
|
||||||
|
* first reaches a locking status, kept while it stays locked, cleared
|
||||||
|
* when the lock is opened.
|
||||||
|
*/
|
||||||
|
public function recordCompletion(DateTimeImmutable $now): void
|
||||||
|
{
|
||||||
|
if (! $this->details->status->locksTime()) {
|
||||||
|
$this->completedAt = null;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->completedAt ??= $now;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function completedAt(): ?DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->completedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use App\Modules\Jobs\Domain\Enums\Priority;
|
|||||||
use App\Modules\Jobs\Domain\Exceptions\DueBeforeStart;
|
use App\Modules\Jobs\Domain\Exceptions\DueBeforeStart;
|
||||||
use App\Modules\Jobs\Domain\Exceptions\PlanEndsBeforeStart;
|
use App\Modules\Jobs\Domain\Exceptions\PlanEndsBeforeStart;
|
||||||
use App\Modules\Jobs\Domain\Exceptions\ServiceUnitRequired;
|
use App\Modules\Jobs\Domain\Exceptions\ServiceUnitRequired;
|
||||||
|
use App\Modules\Shared\Domain\ValueObjects\Money;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,6 +59,7 @@ final readonly class JobDetails
|
|||||||
array $memberUserIds,
|
array $memberUserIds,
|
||||||
array $tags,
|
array $tags,
|
||||||
public array $links,
|
public array $links,
|
||||||
|
public ?Money $quotedAmount = null,
|
||||||
) {
|
) {
|
||||||
$serviceUnitIds = array_values(array_unique($serviceUnitIds));
|
$serviceUnitIds = array_values(array_unique($serviceUnitIds));
|
||||||
|
|
||||||
@@ -95,7 +97,7 @@ final readonly class JobDetails
|
|||||||
$this->kind, $status, $this->priority, $this->paymentBasis, $this->estimatedHours,
|
$this->kind, $status, $this->priority, $this->paymentBasis, $this->estimatedHours,
|
||||||
$this->customerReference, $this->instructions, $this->responsibleUserId, $this->contactUserId,
|
$this->customerReference, $this->instructions, $this->responsibleUserId, $this->contactUserId,
|
||||||
$this->customerContactId, $this->billerUserId, $this->billingUnitId, $this->memberUserIds,
|
$this->customerContactId, $this->billerUserId, $this->billingUnitId, $this->memberUserIds,
|
||||||
$this->tags, $this->links,
|
$this->tags, $this->links, $this->quotedAmount,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,6 +139,7 @@ final readonly class JobDetails
|
|||||||
'priority' => $this->priority->value,
|
'priority' => $this->priority->value,
|
||||||
'payment_basis' => $this->paymentBasis?->value,
|
'payment_basis' => $this->paymentBasis?->value,
|
||||||
'estimated_hours' => $this->estimatedHours?->format(),
|
'estimated_hours' => $this->estimatedHours?->format(),
|
||||||
|
'quoted_amount' => $this->quotedAmount === null ? null : (string) $this->quotedAmount->cents,
|
||||||
'customer_reference' => $this->customerReference,
|
'customer_reference' => $this->customerReference,
|
||||||
'instructions' => $this->instructions,
|
'instructions' => $this->instructions,
|
||||||
'responsible_user' => (string) $this->responsibleUserId,
|
'responsible_user' => (string) $this->responsibleUserId,
|
||||||
|
|||||||
@@ -41,13 +41,15 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
* @property int|null $biller_user_id
|
* @property int|null $biller_user_id
|
||||||
* @property int|null $billing_unit_id
|
* @property int|null $billing_unit_id
|
||||||
* @property int $created_by
|
* @property int $created_by
|
||||||
|
* @property int|null $quoted_amount_cents
|
||||||
|
* @property CarbonImmutable|null $completed_at
|
||||||
* @property CarbonImmutable $created_at
|
* @property CarbonImmutable $created_at
|
||||||
*/
|
*/
|
||||||
#[Table('customer_jobs')]
|
#[Table('customer_jobs')]
|
||||||
#[Fillable([
|
#[Fillable([
|
||||||
'number', 'name', 'description', 'customer_id', 'starts_on', 'due_on', 'planned_from', 'planned_to',
|
'number', 'name', 'description', 'customer_id', 'starts_on', 'due_on', 'planned_from', 'planned_to',
|
||||||
'kind', 'status', 'priority', 'payment_basis', 'estimated_hours', 'customer_reference', 'instructions',
|
'kind', 'status', 'priority', 'payment_basis', 'estimated_hours', 'quoted_amount_cents', 'customer_reference', 'instructions',
|
||||||
'responsible_user_id', 'contact_user_id', 'customer_contact_id', 'biller_user_id', 'billing_unit_id', 'created_by',
|
'responsible_user_id', 'contact_user_id', 'customer_contact_id', 'biller_user_id', 'billing_unit_id', 'created_by', 'completed_at',
|
||||||
])]
|
])]
|
||||||
#[UseFactory(CustomerJobFactory::class)]
|
#[UseFactory(CustomerJobFactory::class)]
|
||||||
class CustomerJobModel extends Model
|
class CustomerJobModel extends Model
|
||||||
@@ -62,6 +64,8 @@ class CustomerJobModel extends Model
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'customer_id' => 'integer',
|
'customer_id' => 'integer',
|
||||||
|
'quoted_amount_cents' => 'integer',
|
||||||
|
'completed_at' => 'immutable_datetime',
|
||||||
'starts_on' => 'immutable_date',
|
'starts_on' => 'immutable_date',
|
||||||
'due_on' => 'immutable_date',
|
'due_on' => 'immutable_date',
|
||||||
'planned_from' => 'immutable_date',
|
'planned_from' => 'immutable_date',
|
||||||
|
|||||||
+2
@@ -179,6 +179,8 @@ class EloquentCustomerJobQueries implements CustomerJobQueries
|
|||||||
->all(),
|
->all(),
|
||||||
createdAt: $model->created_at->format('Y-m-d H:i'),
|
createdAt: $model->created_at->format('Y-m-d H:i'),
|
||||||
createdByName: $userNames[$model->created_by] ?? '',
|
createdByName: $userNames[$model->created_by] ?? '',
|
||||||
|
quotedAmountCents: $model->quoted_amount_cents,
|
||||||
|
completedAt: $model->completed_at?->setTimezone((string) config('app.business_timezone'))->format('Y-m-d H:i'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-1
@@ -11,6 +11,7 @@ use App\Modules\Jobs\Domain\ValueObjects\JobName;
|
|||||||
use App\Modules\Jobs\Domain\ValueObjects\JobNumber;
|
use App\Modules\Jobs\Domain\ValueObjects\JobNumber;
|
||||||
use App\Modules\Jobs\Domain\ValueObjects\Tag;
|
use App\Modules\Jobs\Domain\ValueObjects\Tag;
|
||||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||||
|
use App\Modules\Shared\Domain\ValueObjects\Money;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
@@ -42,6 +43,8 @@ class EloquentCustomerJobRepository implements CustomerJobRepository
|
|||||||
'priority' => $details->priority,
|
'priority' => $details->priority,
|
||||||
'payment_basis' => $details->paymentBasis,
|
'payment_basis' => $details->paymentBasis,
|
||||||
'estimated_hours' => $details->estimatedHours?->value,
|
'estimated_hours' => $details->estimatedHours?->value,
|
||||||
|
'quoted_amount_cents' => $details->quotedAmount?->cents,
|
||||||
|
'completed_at' => $job->completedAt()?->format('Y-m-d H:i:s'),
|
||||||
'customer_reference' => $details->customerReference,
|
'customer_reference' => $details->customerReference,
|
||||||
'instructions' => $details->instructions,
|
'instructions' => $details->instructions,
|
||||||
'responsible_user_id' => $details->responsibleUserId,
|
'responsible_user_id' => $details->responsibleUserId,
|
||||||
@@ -147,8 +150,15 @@ class EloquentCustomerJobRepository implements CustomerJobRepository
|
|||||||
->get()
|
->get()
|
||||||
->map(fn ($row): JobLink => new JobLink((string) $row->title, (string) $row->url))
|
->map(fn ($row): JobLink => new JobLink((string) $row->title, (string) $row->url))
|
||||||
->all(),
|
->all(),
|
||||||
|
quotedAmount: $model->quoted_amount_cents === null ? null : Money::fromCents($model->quoted_amount_cents),
|
||||||
);
|
);
|
||||||
|
|
||||||
return CustomerJob::reconstitute($model->id, JobNumber::fromString($model->number), $details, $model->created_by);
|
return CustomerJob::reconstitute(
|
||||||
|
$model->id,
|
||||||
|
JobNumber::fromString($model->number),
|
||||||
|
$details,
|
||||||
|
$model->created_by,
|
||||||
|
$model->completed_at === null ? null : DateTimeImmutable::createFromInterface($model->completed_at),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ use App\Modules\Jobs\Domain\Exceptions\InvalidTag;
|
|||||||
use App\Modules\Jobs\Domain\Exceptions\PlanEndsBeforeStart;
|
use App\Modules\Jobs\Domain\Exceptions\PlanEndsBeforeStart;
|
||||||
use App\Modules\Jobs\Domain\Exceptions\ServiceUnitRequired;
|
use App\Modules\Jobs\Domain\Exceptions\ServiceUnitRequired;
|
||||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||||
|
use App\Modules\Shared\Domain\Exceptions\InvalidMoneyAmount;
|
||||||
|
use App\Modules\Shared\Domain\ValueObjects\Money;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Livewire\Form;
|
use Livewire\Form;
|
||||||
|
|
||||||
@@ -54,6 +57,11 @@ class JobForm extends Form
|
|||||||
|
|
||||||
public string $estimated_hours = '';
|
public string $estimated_hours = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only for users who may see quoted amounts; filled and sent only for them.
|
||||||
|
*/
|
||||||
|
public string $quoted_amount = '';
|
||||||
|
|
||||||
public string $customer_reference = '';
|
public string $customer_reference = '';
|
||||||
|
|
||||||
public string $instructions = '';
|
public string $instructions = '';
|
||||||
@@ -92,6 +100,7 @@ class JobForm extends Form
|
|||||||
$this->priority = $job->priority->value;
|
$this->priority = $job->priority->value;
|
||||||
$this->payment_basis = $job->paymentBasis->value ?? '';
|
$this->payment_basis = $job->paymentBasis->value ?? '';
|
||||||
$this->estimated_hours = $job->estimatedHours ?? '';
|
$this->estimated_hours = $job->estimatedHours ?? '';
|
||||||
|
$this->quoted_amount = $job->quotedAmountCents === null || ! Gate::allows('money.quotes') ? '' : Money::fromCents($job->quotedAmountCents)->inputValue();
|
||||||
$this->customer_reference = $job->customerReference ?? '';
|
$this->customer_reference = $job->customerReference ?? '';
|
||||||
$this->instructions = $job->instructions ?? '';
|
$this->instructions = $job->instructions ?? '';
|
||||||
$this->responsible_user_id = (string) $job->responsible->id;
|
$this->responsible_user_id = (string) $job->responsible->id;
|
||||||
@@ -135,6 +144,8 @@ class JobForm extends Form
|
|||||||
memberUserIds: array_map('intval', $this->member_user_ids),
|
memberUserIds: array_map('intval', $this->member_user_ids),
|
||||||
tags: $this->tags,
|
tags: $this->tags,
|
||||||
links: array_values(array_filter($this->links, fn (array $link): bool => trim($link['title']) !== '' || trim($link['url']) !== '')),
|
links: array_values(array_filter($this->links, fn (array $link): bool => trim($link['title']) !== '' || trim($link['url']) !== '')),
|
||||||
|
quotedAmount: $text($this->quoted_amount),
|
||||||
|
setsQuotedAmount: Gate::allows('money.quotes'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +160,7 @@ class JobForm extends Form
|
|||||||
$exception instanceof DueBeforeStart => ['due_on', 'jobs.errors.due_before_start'],
|
$exception instanceof DueBeforeStart => ['due_on', 'jobs.errors.due_before_start'],
|
||||||
$exception instanceof PlanEndsBeforeStart => ['planned_to', 'jobs.errors.plan_ends_before_start'],
|
$exception instanceof PlanEndsBeforeStart => ['planned_to', 'jobs.errors.plan_ends_before_start'],
|
||||||
$exception instanceof InvalidEstimatedHours => ['estimated_hours', 'jobs.errors.invalid_hours'],
|
$exception instanceof InvalidEstimatedHours => ['estimated_hours', 'jobs.errors.invalid_hours'],
|
||||||
|
$exception instanceof InvalidMoneyAmount => ['quoted_amount', 'jobs.errors.invalid_amount'],
|
||||||
$exception instanceof InvalidTag => ['tags', 'jobs.errors.invalid_tag'],
|
$exception instanceof InvalidTag => ['tags', 'jobs.errors.invalid_tag'],
|
||||||
$exception instanceof InvalidJobLink => ['links', 'jobs.errors.invalid_link'],
|
$exception instanceof InvalidJobLink => ['links', 'jobs.errors.invalid_link'],
|
||||||
$exception instanceof InvalidJobReference => [self::referenceField($exception->field), 'jobs.errors.invalid_reference'],
|
$exception instanceof InvalidJobReference => [self::referenceField($exception->field), 'jobs.errors.invalid_reference'],
|
||||||
@@ -188,6 +200,7 @@ class JobForm extends Form
|
|||||||
'priority' => ['required', Rule::enum(Priority::class)],
|
'priority' => ['required', Rule::enum(Priority::class)],
|
||||||
'payment_basis' => ['nullable', Rule::enum(PaymentBasis::class)],
|
'payment_basis' => ['nullable', Rule::enum(PaymentBasis::class)],
|
||||||
'estimated_hours' => ['nullable', 'numeric', 'min:0', 'max:99999'],
|
'estimated_hours' => ['nullable', 'numeric', 'min:0', 'max:99999'],
|
||||||
|
'quoted_amount' => ['nullable', 'string', 'max:20'],
|
||||||
'customer_reference' => ['nullable', 'string', 'max:255'],
|
'customer_reference' => ['nullable', 'string', 'max:255'],
|
||||||
'instructions' => ['nullable', 'string', 'max:10000'],
|
'instructions' => ['nullable', 'string', 'max:10000'],
|
||||||
'responsible_user_id' => ['required', 'integer'],
|
'responsible_user_id' => ['required', 'integer'],
|
||||||
@@ -226,6 +239,7 @@ class JobForm extends Form
|
|||||||
'estimated_hours.numeric' => __('jobs.errors.invalid_hours'),
|
'estimated_hours.numeric' => __('jobs.errors.invalid_hours'),
|
||||||
'estimated_hours.min' => __('jobs.errors.invalid_hours'),
|
'estimated_hours.min' => __('jobs.errors.invalid_hours'),
|
||||||
'estimated_hours.max' => __('jobs.errors.invalid_hours'),
|
'estimated_hours.max' => __('jobs.errors.invalid_hours'),
|
||||||
|
'quoted_amount.max' => __('jobs.errors.invalid_amount'),
|
||||||
'customer_reference.max' => __('jobs.errors.too_long', ['max' => 255]),
|
'customer_reference.max' => __('jobs.errors.too_long', ['max' => 255]),
|
||||||
'instructions.max' => __('jobs.errors.too_long', ['max' => 10000]),
|
'instructions.max' => __('jobs.errors.too_long', ['max' => 10000]),
|
||||||
'responsible_user_id.required' => __('jobs.errors.responsible_required'),
|
'responsible_user_id.required' => __('jobs.errors.responsible_required'),
|
||||||
|
|||||||
@@ -358,6 +358,16 @@ new class extends Component
|
|||||||
:label="__('jobs.fields.estimated_hours')"
|
:label="__('jobs.fields.estimated_hours')"
|
||||||
:hint="__('jobs.fields.estimated_hours_description')"
|
:hint="__('jobs.fields.estimated_hours_description')"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@can('money.quotes')
|
||||||
|
<x-input
|
||||||
|
wire:model="form.quoted_amount"
|
||||||
|
inputmode="decimal"
|
||||||
|
autocomplete="off"
|
||||||
|
:label="__('jobs.fields.quoted_amount_input')"
|
||||||
|
:hint="__('jobs.fields.quoted_amount_description')"
|
||||||
|
/>
|
||||||
|
@endcan
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
|||||||
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
use App\Modules\Shared\Domain\ValueObjects\Money;
|
||||||
use Livewire\Attributes\Computed;
|
use Livewire\Attributes\Computed;
|
||||||
use Livewire\Attributes\Locked;
|
use Livewire\Attributes\Locked;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
@@ -61,7 +62,12 @@ new class extends Component
|
|||||||
#[Computed]
|
#[Computed]
|
||||||
public function changes(): array
|
public function changes(): array
|
||||||
{
|
{
|
||||||
return app(CustomerJobQueries::class)->changes($this->jobId);
|
$changes = app(CustomerJobQueries::class)->changes($this->jobId);
|
||||||
|
|
||||||
|
// Changes of the quoted amount are shown only to those who may see quotes (spec 5.7).
|
||||||
|
return Gate::allows('money.quotes')
|
||||||
|
? $changes
|
||||||
|
: array_values(array_filter($changes, fn (JobChangeEntry $change): bool => $change->field !== 'quoted_amount'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -165,6 +171,7 @@ new class extends Component
|
|||||||
|
|
||||||
return match ($field) {
|
return match ($field) {
|
||||||
'starts_on', 'due_on', 'planned_from', 'planned_to' => $this->formatDate($value),
|
'starts_on', 'due_on', 'planned_from', 'planned_to' => $this->formatDate($value),
|
||||||
|
'quoted_amount' => Money::fromCents((int) $value)->format(),
|
||||||
'kind' => __('jobs.kinds.'.$value),
|
'kind' => __('jobs.kinds.'.$value),
|
||||||
'status' => __('jobs.statuses.'.$value),
|
'status' => __('jobs.statuses.'.$value),
|
||||||
'priority' => __('jobs.priorities.'.$value),
|
'priority' => __('jobs.priorities.'.$value),
|
||||||
@@ -235,12 +242,22 @@ new class extends Component
|
|||||||
<dt class="font-medium">{{ __('jobs.fields.estimated_hours') }}</dt>
|
<dt class="font-medium">{{ __('jobs.fields.estimated_hours') }}</dt>
|
||||||
<dd>{{ $job->estimatedHours === null ? __('jobs.not_set') : str_replace('.', ',', $job->estimatedHours).' h' }}</dd>
|
<dd>{{ $job->estimatedHours === null ? __('jobs.not_set') : str_replace('.', ',', $job->estimatedHours).' h' }}</dd>
|
||||||
|
|
||||||
|
@can('money.quotes')
|
||||||
|
<dt class="font-medium">{{ __('jobs.fields.quoted_amount') }}</dt>
|
||||||
|
<dd>{{ $job->quotedAmountCents === null ? __('jobs.not_set') : Money::fromCents($job->quotedAmountCents)->format().' '.__('jobs.vat_excluded') }}</dd>
|
||||||
|
@endcan
|
||||||
|
|
||||||
<dt class="font-medium">{{ __('jobs.fields.customer_reference') }}</dt>
|
<dt class="font-medium">{{ __('jobs.fields.customer_reference') }}</dt>
|
||||||
<dd class="break-words">{{ $job->customerReference ?? __('jobs.not_set') }}</dd>
|
<dd class="break-words">{{ $job->customerReference ?? __('jobs.not_set') }}</dd>
|
||||||
|
|
||||||
<dt class="font-medium">{{ __('jobs.fields.tags') }}</dt>
|
<dt class="font-medium">{{ __('jobs.fields.tags') }}</dt>
|
||||||
<dd>{{ $job->tags === [] ? __('jobs.tags.none') : implode(', ', $job->tags) }}</dd>
|
<dd>{{ $job->tags === [] ? __('jobs.tags.none') : implode(', ', $job->tags) }}</dd>
|
||||||
|
|
||||||
|
@if ($job->completedAt !== null)
|
||||||
|
<dt class="font-medium">{{ __('jobs.fields.completed_at') }}</dt>
|
||||||
|
<dd>{{ CarbonImmutable::parse($job->completedAt)->format('j.n.Y H.i') }}</dd>
|
||||||
|
@endif
|
||||||
|
|
||||||
<dt class="font-medium">{{ __('jobs.fields.created_at') }}</dt>
|
<dt class="font-medium">{{ __('jobs.fields.created_at') }}</dt>
|
||||||
<dd>{{ CarbonImmutable::parse($job->createdAt)->format('j.n.Y H.i') }}, {{ $job->createdByName }}</dd>
|
<dd>{{ CarbonImmutable::parse($job->createdAt)->format('j.n.Y H.i') }}, {{ $job->createdByName }}</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ class CustomerJobFactory extends Factory
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function quoted(int $cents): static
|
||||||
|
{
|
||||||
|
return $this->state(fn (): array => ['quoted_amount_cents' => $cents]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param list<int> $userIds
|
* @param list<int> $userIds
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The budget or quoted amount of a job (cents, VAT 0), seen only with the
|
||||||
|
* quotes permission, and when the job was done, for billing.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('customer_jobs', function (Blueprint $table) {
|
||||||
|
$table->unsignedInteger('quoted_amount_cents')->nullable()->after('estimated_hours');
|
||||||
|
$table->timestamp('completed_at')->nullable()->after('created_by');
|
||||||
|
|
||||||
|
$table->index('completed_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('customer_jobs', function (Blueprint $table) {
|
||||||
|
$table->dropIndex(['completed_at']);
|
||||||
|
$table->dropColumn(['quoted_amount_cents', 'completed_at']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
+7
-3
@@ -119,7 +119,7 @@ Nimi, sähköposti, rooli (yksi per käyttäjä, *K13*), aktiivinen, harjoitteli
|
|||||||
| Prioriteetti | `priority` | ks. 5.4 |
|
| Prioriteetti | `priority` | ks. 5.4 |
|
||||||
| Maksuperuste | `payment_basis` | ks. 5.5 |
|
| Maksuperuste | `payment_basis` | ks. 5.5 |
|
||||||
| Arvioidut tunnit | `estimated_hours` | *(K24)* |
|
| Arvioidut tunnit | `estimated_hours` | *(K24)* |
|
||||||
| Budjetti / tarjoussumma | `quoted_amount` | Rahamäärä (2.3) *(K24)* |
|
| Budjetti / tarjoussumma | `quoted_amount_cents` | Rahamäärä ALV 0; näkyy ja muokattavissa vain Tarjoukset-oikeudella (2.3), muiden tallennus säilyttää sen *(K24, valmis)* |
|
||||||
| Asiakkaan viite (PO) | `customer_reference` | *(K24)* |
|
| Asiakkaan viite (PO) | `customer_reference` | *(K24)* |
|
||||||
| Tagit | `tags` | Haku listasta tai uuden lisäys, joka tallentuu listaan *(K25)* |
|
| Tagit | `tags` | Haku listasta tai uuden lisäys, joka tallentuu listaan *(K25)* |
|
||||||
| Linkit | `links` | Linkit tiedostoihin (Drive, Dropbox ym.), otsikko + URL *(K26)* |
|
| Linkit | `links` | Linkit tiedostoihin (Drive, Dropbox ym.), otsikko + URL *(K26)* |
|
||||||
@@ -199,7 +199,7 @@ Käyttäjän "omat työt" ovat työt, joissa hän on vastuuhenkilö, kontaktihen
|
|||||||
|
|
||||||
### 5.7 Muutoshistoria *(K27)*
|
### 5.7 Muutoshistoria *(K27)*
|
||||||
|
|
||||||
Asiakastyön kenttien muutokset tallennetaan: kuka, milloin, mikä kenttä, vanha ja uusi arvo. Historia näkyy työn sivulla. Rahakenttien muutokset näkyvät vain niille, joilla on oikeus rahamääriin.
|
Asiakastyön kenttien muutokset tallennetaan: kuka, milloin, mikä kenttä, vanha ja uusi arvo. Historia näkyy työn sivulla. Rahakenttien muutokset näkyvät vain niille, joilla on oikeus rahamääriin (tarjoussumma: Tarjoukset-oikeus) *(valmis)*.
|
||||||
|
|
||||||
## 6. Uuden työn vastaanotto *(K46, K47)*
|
## 6. Uuden työn vastaanotto *(K46, K47)*
|
||||||
|
|
||||||
@@ -341,7 +341,7 @@ Taulut ja tärkeimmät sarakkeet. Kaikissa tauluissa on `id` ja `created_at`/`up
|
|||||||
- `settings` *(V2, olemassa)*: `key` (uniikki, omistajamoduulin etuliite, esim. `catalog.mileage_rate_cents`), `value` (esim. km-hinta, työajanseuranta päällä)
|
- `settings` *(V2, olemassa)*: `key` (uniikki, omistajamoduulin etuliite, esim. `catalog.mileage_rate_cents`), `value` (esim. km-hinta, työajanseuranta päällä)
|
||||||
|
|
||||||
**Jobs** (asiakastyöt)
|
**Jobs** (asiakastyöt)
|
||||||
- `customer_jobs`: `number`, `name`, `description`, `customer_id`, `starts_on`, `due_on`, `planned_from`, `planned_to`, `kind`, `status`, `priority`, `payment_basis`, `estimated_hours`, `customer_reference`, `instructions`, `responsible_user_id`, `contact_user_id`, `customer_contact_id`, `biller_user_id`, `billing_unit_id`, `created_by` *(olemassa)*; `quoted_amount_cents`, `completed_at` *(V2)*
|
- `customer_jobs`: `number`, `name`, `description`, `customer_id`, `starts_on`, `due_on`, `planned_from`, `planned_to`, `kind`, `status`, `priority`, `payment_basis`, `estimated_hours`, `customer_reference`, `instructions`, `responsible_user_id`, `contact_user_id`, `customer_contact_id`, `biller_user_id`, `billing_unit_id`, `created_by` *(olemassa)*; `quoted_amount_cents`, `completed_at` (asetetaan, kun työ saavuttaa lukitsevan tilan; tyhjennetään, kun lukitus avataan) *(V2, olemassa)*
|
||||||
- `job_number_sequences`: `year`, `last_number`
|
- `job_number_sequences`: `year`, `last_number`
|
||||||
- `customer_job_service_unit`: `customer_job_id`, `service_unit_id`
|
- `customer_job_service_unit`: `customer_job_id`, `service_unit_id`
|
||||||
- `customer_job_members`: `customer_job_id`, `user_id`
|
- `customer_job_members`: `customer_job_id`, `user_id`
|
||||||
@@ -465,6 +465,10 @@ Jokainen sivu täyttää saavutettavuusvaatimukset ja saa selaintestin (vaalea/t
|
|||||||
- Johdon Tuntien hyväksyntä -sivu (`/time/approvals`, valikossa "Hyväksyntä") ja toisen käyttäjän viikkonäkymä lukutilassa (`/time?kayttaja=ID`), jossa hyväksyntä ja sen peruminen (vahvistus dialogissa).
|
- Johdon Tuntien hyväksyntä -sivu (`/time/approvals`, valikossa "Hyväksyntä") ja toisen käyttäjän viikkonäkymä lukutilassa (`/time?kayttaja=ID`), jossa hyväksyntä ja sen peruminen (vahvistus dialogissa).
|
||||||
- Valmiin työn siirto takaisin aiempaan tilaan vain johdolle (Kanban ja työn lomake).
|
- Valmiin työn siirto takaisin aiempaan tilaan vain johdolle (Kanban ja työn lomake).
|
||||||
|
|
||||||
|
### 17.5 Asiakastyön rahakentät *(valmis)*
|
||||||
|
- Työn lomakkeella "Budjetti / tarjoussumma (€, ALV 0)" ja työn sivulla sen arvo vain Tarjoukset-oikeudella; muutoshistorian tarjoussummarivit näytetään vain heille.
|
||||||
|
- Työn sivulla "Valmistunut", kun työ on siirretty Valmis-tilaan (tai myöhempään); aika säilyy laskutustiloissa ja tyhjenee, kun johto avaa lukituksen.
|
||||||
|
|
||||||
## 18. Avoimet kysymykset
|
## 18. Avoimet kysymykset
|
||||||
|
|
||||||
1. ~~**Lukitus**~~: ratkaistu – vain johto avaa valmiin työn lukituksen siirtämällä työn aiempaan tilaan, ja avaus näkyy muutoshistoriassa (5.3).
|
1. ~~**Lukitus**~~: ratkaistu – vain johto avaa valmiin työn lukituksen siirtämällä työn aiempaan tilaan, ja avaus näkyy muutoshistoriassa (5.3).
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
'vat_excluded' => '(ALV 0)',
|
||||||
'title' => 'Asiakastyöt',
|
'title' => 'Asiakastyöt',
|
||||||
'new' => 'Uusi asiakastyö',
|
'new' => 'Uusi asiakastyö',
|
||||||
'create_title' => 'Uusi asiakastyö',
|
'create_title' => 'Uusi asiakastyö',
|
||||||
@@ -125,6 +126,10 @@ return [
|
|||||||
'payment_basis' => 'Maksuperuste',
|
'payment_basis' => 'Maksuperuste',
|
||||||
'estimated_hours' => 'Arvioidut tunnit',
|
'estimated_hours' => 'Arvioidut tunnit',
|
||||||
'estimated_hours_description' => 'Tunteina, esimerkiksi 7,5.',
|
'estimated_hours_description' => 'Tunteina, esimerkiksi 7,5.',
|
||||||
|
'quoted_amount' => 'Budjetti / tarjoussumma',
|
||||||
|
'quoted_amount_input' => 'Budjetti / tarjoussumma (€, ALV 0)',
|
||||||
|
'quoted_amount_description' => 'Veroton summa, esim. 4500. Näkyy vain niille, joilla on oikeus tarjouksiin.',
|
||||||
|
'completed_at' => 'Valmistunut',
|
||||||
'customer_reference' => 'Asiakkaan viite (PO)',
|
'customer_reference' => 'Asiakkaan viite (PO)',
|
||||||
'instructions' => 'Ohjeistus',
|
'instructions' => 'Ohjeistus',
|
||||||
'instructions_description' => 'Työhön liittyvät asiat ja huomiot tekijöille.',
|
'instructions_description' => 'Työhön liittyvät asiat ja huomiot tekijöille.',
|
||||||
@@ -232,6 +237,7 @@ return [
|
|||||||
'due_before_start' => 'Määräaika ei voi olla ennen alkamispäivää.',
|
'due_before_start' => 'Määräaika ei voi olla ennen alkamispäivää.',
|
||||||
'plan_ends_before_start' => 'Suunniteltu loppu ei voi olla ennen suunniteltua alkua.',
|
'plan_ends_before_start' => 'Suunniteltu loppu ei voi olla ennen suunniteltua alkua.',
|
||||||
'invalid_hours' => 'Anna tunnit nollana tai suurempana, vartin tarkkuudella (esim. 7,25).',
|
'invalid_hours' => 'Anna tunnit nollana tai suurempana, vartin tarkkuudella (esim. 7,25).',
|
||||||
|
'invalid_amount' => 'Anna summa euroina, esim. 4500 tai 4500,50 (enintään kaksi desimaalia).',
|
||||||
'invalid_tag' => 'Tagin pituus on 1–50 merkkiä.',
|
'invalid_tag' => 'Tagin pituus on 1–50 merkkiä.',
|
||||||
'invalid_link' => 'Anna linkille otsikko ja osoite, joka alkaa http:// tai https://.',
|
'invalid_link' => 'Anna linkille otsikko ja osoite, joka alkaa http:// tai https://.',
|
||||||
'invalid_reference' => 'Valinta ei ole enää käytettävissä. Valitse uudelleen.',
|
'invalid_reference' => 'Valinta ei ole enää käytettävissä. Valitse uudelleen.',
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ beforeEach(function () {
|
|||||||
'priority' => 'immediate',
|
'priority' => 'immediate',
|
||||||
'due_on' => now()->subDay()->toDateString(),
|
'due_on' => now()->subDay()->toDateString(),
|
||||||
'instructions' => 'Kuvaus klo 9.',
|
'instructions' => 'Kuvaus klo 9.',
|
||||||
|
'quoted_amount_cents' => 450000,
|
||||||
]);
|
]);
|
||||||
DB::table('customer_job_links')->insert(['customer_job_id' => $this->job->id, 'title' => 'Briiffi', 'url' => 'https://drive.example.test/b', 'sort_order' => 1]);
|
DB::table('customer_job_links')->insert(['customer_job_id' => $this->job->id, 'title' => 'Briiffi', 'url' => 'https://drive.example.test/b', 'sort_order' => 1]);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class InMemoryCustomerJobRepository implements CustomerJobRepository, JobNumberS
|
|||||||
public function save(CustomerJob $job): CustomerJob
|
public function save(CustomerJob $job): CustomerJob
|
||||||
{
|
{
|
||||||
$id = $job->id() ?? $this->nextId++;
|
$id = $job->id() ?? $this->nextId++;
|
||||||
$this->jobs[$id] = CustomerJob::reconstitute($id, $job->number(), $job->details(), $job->createdBy());
|
$this->jobs[$id] = CustomerJob::reconstitute($id, $job->number(), $job->details(), $job->createdBy(), $job->completedAt());
|
||||||
|
|
||||||
return clone $this->jobs[$id];
|
return clone $this->jobs[$id];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||||
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||||
|
use App\Modules\Users\Domain\Enums\MoneyPermission;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
uses(RefreshDatabase::class);
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
$this->job = CustomerJobModel::factory()->quoted(450000)->create(['name' => 'Messuvideo', 'status' => JobStatus::Order]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('lets management set the quoted amount and see it with its history', function () {
|
||||||
|
$this->actingAs(User::factory()->management()->create());
|
||||||
|
|
||||||
|
Livewire::test('jobs::form', ['job' => $this->job->id])
|
||||||
|
->assertSet('form.quoted_amount', '4500,00')
|
||||||
|
->set('form.quoted_amount', '5200,50')
|
||||||
|
->call('save')
|
||||||
|
->assertHasNoErrors();
|
||||||
|
|
||||||
|
expect($this->job->refresh()->quoted_amount_cents)->toBe(520050);
|
||||||
|
|
||||||
|
$this->get(route('jobs.show', $this->job->id))
|
||||||
|
->assertSee('Budjetti / tarjoussumma')
|
||||||
|
->assertSee("5\u{00A0}200,50\u{00A0}€", false)
|
||||||
|
->assertSee("4\u{00A0}500,00\u{00A0}€", false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects an invalid quoted amount with a Finnish field error', function () {
|
||||||
|
$this->actingAs(User::factory()->management()->create());
|
||||||
|
|
||||||
|
Livewire::test('jobs::form', ['job' => $this->job->id])
|
||||||
|
->set('form.quoted_amount', '12,345')
|
||||||
|
->call('save')
|
||||||
|
->assertHasErrors(['form.quoted_amount' => [__('jobs.errors.invalid_amount')]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('hides the quoted amount from employees without the quotes permission and keeps it when they save', function () {
|
||||||
|
$this->actingAs(User::factory()->management()->create());
|
||||||
|
Livewire::test('jobs::form', ['job' => $this->job->id])->set('form.quoted_amount', '5000')->call('save');
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->employee()->create());
|
||||||
|
|
||||||
|
$this->get(route('jobs.show', $this->job->id))
|
||||||
|
->assertOk()
|
||||||
|
->assertDontSee('Budjetti / tarjoussumma')
|
||||||
|
->assertDontSee("5\u{00A0}000,00\u{00A0}€", false);
|
||||||
|
|
||||||
|
Livewire::test('jobs::form', ['job' => $this->job->id])
|
||||||
|
->assertSet('form.quoted_amount', '')
|
||||||
|
->assertDontSee('Budjetti / tarjoussumma')
|
||||||
|
->set('form.quoted_amount', '1')
|
||||||
|
->set('form.name', 'Messuvideo 2')
|
||||||
|
->call('save')
|
||||||
|
->assertHasNoErrors();
|
||||||
|
|
||||||
|
expect($this->job->refresh()->quoted_amount_cents)->toBe(500000)
|
||||||
|
->and($this->job->name)->toBe('Messuvideo 2');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows the quoted amount to an employee with the quotes permission', function () {
|
||||||
|
$this->actingAs(User::factory()->employee()->withMoneyPermissions(MoneyPermission::Quotes)->create());
|
||||||
|
|
||||||
|
$this->get(route('jobs.show', $this->job->id))->assertSee("4\u{00A0}500,00\u{00A0}€", false);
|
||||||
|
|
||||||
|
Livewire::test('jobs::form', ['job' => $this->job->id])
|
||||||
|
->set('form.quoted_amount', '')
|
||||||
|
->call('save')
|
||||||
|
->assertHasNoErrors();
|
||||||
|
|
||||||
|
expect($this->job->refresh()->quoted_amount_cents)->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('records when a job is done and clears it when management opens the lock', function () {
|
||||||
|
$this->actingAs(User::factory()->management()->create());
|
||||||
|
|
||||||
|
Livewire::test('jobs::board')->set('mine', false)->call('moveJob', $this->job->id, 'done');
|
||||||
|
$completedAt = $this->job->refresh()->completed_at;
|
||||||
|
|
||||||
|
expect($completedAt)->not->toBeNull();
|
||||||
|
|
||||||
|
Livewire::test('jobs::board')->set('mine', false)->call('moveJob', $this->job->id, 'invoiced');
|
||||||
|
expect($this->job->refresh()->completed_at?->equalTo($completedAt))->toBeTrue();
|
||||||
|
|
||||||
|
$this->get(route('jobs.show', $this->job->id))->assertSee('Valmistunut');
|
||||||
|
|
||||||
|
Livewire::test('jobs::board')->set('mine', false)->call('moveJob', $this->job->id, 'in_production');
|
||||||
|
expect($this->job->refresh()->completed_at)->toBeNull();
|
||||||
|
});
|
||||||
@@ -34,8 +34,8 @@ beforeEach(function () {
|
|||||||
|
|
||||||
$factory = new JobDetailsFactory($this->customers, $this->catalog, $this->users);
|
$factory = new JobDetailsFactory($this->customers, $this->catalog, $this->users);
|
||||||
$this->create = new CreateCustomerJob($this->jobs, $this->jobs, $factory, $transactions, $this->clock);
|
$this->create = new CreateCustomerJob($this->jobs, $this->jobs, $factory, $transactions, $this->clock);
|
||||||
$this->update = new UpdateCustomerJob($this->jobs, $factory, $transactions);
|
$this->update = new UpdateCustomerJob($this->jobs, $factory, $transactions, $this->clock);
|
||||||
$this->changeStatus = new ChangeJobStatus($this->jobs, $transactions);
|
$this->changeStatus = new ChangeJobStatus($this->jobs, $transactions, new FakeClock(new DateTimeImmutable('2026-05-01')));
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ beforeEach(function () {
|
|||||||
$this->changeTaskStatus = new ChangeTaskStatus($this->tasks, $transactions);
|
$this->changeTaskStatus = new ChangeTaskStatus($this->tasks, $transactions);
|
||||||
$this->usage = new FakeTaskUsage;
|
$this->usage = new FakeTaskUsage;
|
||||||
$this->removeTask = new RemoveTask($this->tasks, $this->usage, $transactions);
|
$this->removeTask = new RemoveTask($this->tasks, $this->usage, $transactions);
|
||||||
$this->changeJobStatus = new ChangeJobStatus($this->jobs, $transactions);
|
$this->changeJobStatus = new ChangeJobStatus($this->jobs, $transactions, new FakeClock(new DateTimeImmutable('2026-05-01')));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows tasks from a quote request on, not before and not when archived', function () {
|
it('allows tasks from a quote request on, not before and not when archived', function () {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use App\Modules\Jobs\Domain\ValueObjects\JobLink;
|
|||||||
use App\Modules\Jobs\Domain\ValueObjects\JobName;
|
use App\Modules\Jobs\Domain\ValueObjects\JobName;
|
||||||
use App\Modules\Jobs\Domain\ValueObjects\JobNumber;
|
use App\Modules\Jobs\Domain\ValueObjects\JobNumber;
|
||||||
use App\Modules\Jobs\Domain\ValueObjects\Tag;
|
use App\Modules\Jobs\Domain\ValueObjects\Tag;
|
||||||
|
use App\Modules\Shared\Domain\ValueObjects\Money;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string, mixed> $overrides
|
* @param array<string, mixed> $overrides
|
||||||
@@ -97,3 +98,29 @@ it('returns only the fields that changed', function () {
|
|||||||
->and($job->changeStatus(JobStatus::Tentative))->toBe([])
|
->and($job->changeStatus(JobStatus::Tentative))->toBe([])
|
||||||
->and(JobStatus::kanbanStatuses())->not->toContain(JobStatus::Archived);
|
->and(JobStatus::kanbanStatuses())->not->toContain(JobStatus::Archived);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('compares the quoted amount for the history', function () {
|
||||||
|
$job = CustomerJob::open(new JobNumber(2026, 1), jobDetails(), 10);
|
||||||
|
|
||||||
|
$changes = $job->changeDetails(jobDetails(['quotedAmount' => Money::fromCents(450000)]));
|
||||||
|
|
||||||
|
expect(array_map(fn ($change) => [$change->field, $change->oldValue, $change->newValue], $changes))->toBe([['quoted_amount', null, '450000']]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('records the completion time while the job is locked and clears it when opened', function () {
|
||||||
|
$job = CustomerJob::open(new JobNumber(2026, 1), jobDetails(), 10);
|
||||||
|
$done = new DateTimeImmutable('2026-11-20 10:00');
|
||||||
|
|
||||||
|
$job->recordCompletion($done);
|
||||||
|
expect($job->completedAt())->toBeNull();
|
||||||
|
|
||||||
|
$job->changeStatus(JobStatus::Done);
|
||||||
|
$job->recordCompletion($done);
|
||||||
|
$job->changeStatus(JobStatus::Billed);
|
||||||
|
$job->recordCompletion(new DateTimeImmutable('2026-12-01'));
|
||||||
|
expect($job->completedAt())->toEqual($done);
|
||||||
|
|
||||||
|
$job->changeStatus(JobStatus::InProduction);
|
||||||
|
$job->recordCompletion(new DateTimeImmutable('2026-12-02'));
|
||||||
|
expect($job->completedAt())->toBeNull();
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user