where('id', $billId)->value('settlement_period_id'); if ($this->periodCompletion->isPeriodReadOnly($periodId)) { throw ValidationException::withMessages([ 'period' => ['completed'], ]); } } public function assertNetAmountMutable(int $billId): void { $bill = DB::table('settlement_bills')->where('id', $billId)->first(); if ($bill === null) { return; } if (in_array((string) $bill->status, self::LOCKED_STATUSES, true) || $bill->locked_at !== null) { throw ValidationException::withMessages([ 'bill' => ['locked'], ]); } } public function assertPayable(int $billId): void { $bill = DB::table('settlement_bills')->where('id', $billId)->first(); if ($bill === null) { throw new \InvalidArgumentException('bill_not_found'); } if (! in_array((string) $bill->status, self::PAYABLE_STATUSES, true)) { throw ValidationException::withMessages([ 'bill' => ['not_payable'], ]); } } public function markConfirmed(int $billId): void { $this->assertPeriodMutable($billId); $bill = DB::table('settlement_bills')->where('id', $billId)->first(); if ($bill === null) { throw new \InvalidArgumentException('bill_not_found'); } if ((string) $bill->status === 'confirmed') { return; } if ((string) $bill->status !== 'pending_confirm') { throw ValidationException::withMessages([ 'bill' => ['not_confirmable'], ]); } DB::table('settlement_bills')->where('id', $billId)->update([ 'status' => 'confirmed', 'locked_at' => now(), 'confirmed_at' => now(), 'updated_at' => now(), ]); } }