toBillable($this->jobs->billingInfoWithStatus(JobStatus::Done)); } public function find(array $jobIds): array { $result = []; foreach ($this->toBillable(array_values($this->jobs->billingInfoOf($jobIds))) as $job) { $result[$job->id] = $job; } return $result; } public function markInvoiced(int $jobId, int $actorUserId): void { $this->changeStatus->execute($jobId, JobStatus::Invoiced, $actorUserId); } /** * @param list $jobs * @return list */ private function toBillable(array $jobs): array { /** @var array $customers */ $customers = []; foreach ($jobs as $job) { if (! array_key_exists($job->customerId, $customers)) { $customers[$job->customerId] = $this->customers->findSummary($job->customerId); } } return array_map(function (JobBillingInfo $job) use ($customers): BillableJob { $customer = $customers[$job->customerId] ?? null; return new BillableJob( $job->id, $job->number, $job->name, $job->customerId, $job->customerName, $customer?->type === CustomerType::Consumer, $customer->isInternal ?? false, $customer?->hasPersonalIdentityCode() ?? false, $job->billingUnitId, $job->billingUnitName, $job->customerReference, match ($job->paymentBasis) { PaymentBasis::FixedQuote => BillingMode::FixedPrice, PaymentBasis::NotBillable, PaymentBasis::MonthlyFee => null, default => BillingMode::Hours, }, $job->quotedAmountCents, $job->status === JobStatus::Done, ); }, $jobs); } }