Issue cashier booth tickets when financial gates block service.
Deploy Ladill Care / deploy (push) Successful in 41s

Pay-before-service holds now create a billing queue ticket (via an open bill) so cashiers can Call next / Serve; clearance completes the ticket and releases the clinical line as before.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-18 19:29:29 +00:00
co-authored by Cursor
parent c3219a1bf1
commit 131ccd6edb
9 changed files with 405 additions and 23 deletions
@@ -506,4 +506,158 @@ class CareFinancialWorkflowRuntimeTest extends TestCase
'status' => FinancialObligation::STATUS_PENDING,
]);
}
public function test_awaiting_payment_issues_a_billing_cashier_ticket(): void
{
Http::fake();
$visit = $this->checkIn();
$obligation = FinancialObligation::query()
->where('visit_id', $visit->id)
->where('stage_code', 'registration')
->firstOrFail();
$this->assertNotNull($obligation->bill_id);
$bill = $obligation->bill()->first();
$this->assertNotNull($bill);
$this->assertNotNull($bill->queue_ticket_uuid);
$this->assertSame('waiting', $bill->queue_ticket_status);
$this->assertStringStartsWith('B', (string) $bill->queue_ticket_number);
$this->assertDatabaseHas('care_queue_tickets', [
'uuid' => $bill->queue_ticket_uuid,
'ticket_number' => $bill->queue_ticket_number,
'status' => 'waiting',
'care_entity' => 'bill',
'care_entity_id' => $bill->id,
]);
$this->assertDatabaseHas('care_service_queues', [
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'context' => CareQueueContexts::BILLING,
]);
$this->assertTrue(app(WorkflowQueueGate::class)->canRelease(
$this->organization,
$visit,
CareQueueContexts::BILLING,
));
$this->assertFalse(app(WorkflowQueueGate::class)->canRelease(
$this->organization,
$visit,
CareQueueContexts::CONSULTATION,
));
Http::assertNothingSent();
}
public function test_queue_off_keeps_financial_gate_without_cashier_ticket(): void
{
$settings = $this->organization->settings;
$settings['queue_integration_enabled'] = false;
$this->organization->update(['settings' => $settings]);
$visit = $this->checkIn();
$obligation = FinancialObligation::query()
->where('visit_id', $visit->id)
->where('stage_code', 'registration')
->firstOrFail();
$this->assertSame(FinancialObligation::STATUS_PENDING, $obligation->status);
$this->assertNull($obligation->bill_id);
$this->assertSame(0, Bill::query()->where('visit_id', $visit->id)->count());
$this->assertSame(VisitStageAdvance::STATUS_BLOCKED, app(WorkflowEngine::class)->currentAdvance($visit)->status);
}
public function test_clearing_gate_completes_cashier_ticket_and_releases_clinical_queue(): void
{
Http::fake();
$visit = $this->checkIn();
$consultation = $this->reachConsultation($visit);
$consultation->refresh();
$this->assertNotNull($consultation->bill_id);
$bill = $consultation->bill()->firstOrFail();
$this->assertNotNull($bill->queue_ticket_uuid);
$ticketUuid = $bill->queue_ticket_uuid;
$appointment = Appointment::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'patient_id' => $this->patient->id,
'visit_id' => $visit->id,
'type' => Appointment::TYPE_WALK_IN,
'status' => Appointment::STATUS_WAITING,
'scheduled_at' => now(),
'checked_in_at' => now(),
'waiting_at' => now(),
'queue_position' => 1,
]);
$this->actingAs($this->owner)
->post(route('care.obligations.clear', $consultation), [
'method' => 'payment',
'payment_mode' => 'internal_cashier',
'payment_method' => 'cash',
'reference' => 'CASH-QUEUE-1',
])
->assertRedirect()
->assertSessionHas('success');
$bill->refresh();
$this->assertSame('completed', $bill->queue_ticket_status);
$this->assertDatabaseHas('care_queue_tickets', [
'uuid' => $ticketUuid,
'status' => 'completed',
]);
$this->assertSame(VisitStageAdvance::STATUS_ACTIVE, app(WorkflowEngine::class)->currentAdvance($visit)->status);
$this->assertTrue(app(WorkflowQueueGate::class)->canRelease(
$this->organization,
$visit,
CareQueueContexts::CONSULTATION,
));
$appointment->refresh();
$this->assertNotNull($appointment->queue_ticket_uuid);
$this->assertSame('waiting', $appointment->queue_ticket_status);
$this->assertStringStartsWith('C', (string) $appointment->queue_ticket_number);
}
public function test_cashier_can_call_next_and_serve_billing_ticket(): void
{
Http::fake();
Member::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'user_ref' => 'cashier-queue-user',
'role' => 'cashier',
'branch_id' => $this->branch->id,
]);
$cashier = User::create([
'public_id' => 'cashier-queue-user',
'name' => 'Cashier',
'email' => 'cashier-queue@example.com',
]);
$visit = $this->checkIn();
$obligation = FinancialObligation::query()
->where('visit_id', $visit->id)
->where('stage_code', 'registration')
->firstOrFail();
$bill = $obligation->bill()->firstOrFail();
$this->assertNotNull($bill->queue_ticket_uuid);
$this->actingAs($cashier)
->post(route('care.bills.call-next'), ['branch_id' => $this->branch->id])
->assertRedirect()
->assertSessionHas('success');
$bill->refresh();
$this->assertSame('called', $bill->queue_ticket_status);
$this->actingAs($cashier)
->post(route('care.bills.serve', $bill))
->assertRedirect()
->assertSessionHas('success');
$this->assertSame('serving', $bill->fresh()->queue_ticket_status);
}
}