clock->now(); return $this->transactions->run(function () use ($userId, $start, $approverId, $now): int { $approved = 0; $entries = $this->entries->forUserBetween($userId, $start, $start->modify('+6 days')); $missing = []; foreach ($entries as $entry) { if (! $entry->isApproved() && ! $entry->hasBillingNote()) { $missing[] = (int) $entry->id(); } } if ($missing !== []) { throw new BillingNotesMissing($missing); } foreach ($entries as $entry) { if ($entry->isApproved()) { continue; } $entry->approve($approverId, $now); $this->entries->save($entry); $approved++; } return $approved; }); } }