feat: enrich invoice summary with session payments, consumables and discount
Port the remaining gap of tauri /files/invoice-summary into the admin
invoice summary: GET /api/v1/billing/invoices/{uuid} now includes a
'session' key (full PatientSession payload) so InvoiceSummaryModal can
render the consumables table, the itemized payments table (method,
amount, date-time, recorder) and real discount/paid/remaining figures
instead of heuristics. Invoices without a source session keep the
previous behavior (session: null).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -139,7 +139,7 @@ class BillingController extends BaseController
|
||||
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'صورتحساب یافت نشد', 404);
|
||||
}
|
||||
|
||||
return $this->success(['data' => $invoice->toArray()]);
|
||||
return $this->success(['data' => $this->invoiceService->detailWithSession($invoice)]);
|
||||
}
|
||||
|
||||
#[Route('/api/v1/billing/invoices/{uuid}/finalize', methods: ['POST'])]
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Billing\ValueObject\Money;
|
||||
use App\ClinicService\Service\TariffService;
|
||||
use App\Insurance\Service\TenantInsuranceService;
|
||||
use App\Patient\Entity\PatientSession;
|
||||
use App\Patient\Repository\PatientSessionRepository;
|
||||
|
||||
class InvoiceService
|
||||
{
|
||||
@@ -17,6 +18,7 @@ class InvoiceService
|
||||
private readonly TariffService $tariffService,
|
||||
private readonly TenantInsuranceService $tenantInsuranceService,
|
||||
private readonly BillingCalculator $calculator,
|
||||
private readonly PatientSessionRepository $sessionRepo,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -75,6 +77,22 @@ class InvoiceService
|
||||
$this->invoiceRepo->save($invoice);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice detail enriched with its source encounter (`session` key):
|
||||
* payments, consumables, discount and paid totals for the invoice summary
|
||||
* view. `session` is null for invoices not created from a session.
|
||||
*/
|
||||
public function detailWithSession(Invoice $invoice): array
|
||||
{
|
||||
$data = $invoice->toArray();
|
||||
|
||||
$sessionId = $data['patient_session_id'];
|
||||
$session = $sessionId !== null ? $this->sessionRepo->find($sessionId) : null;
|
||||
$data['session'] = $session?->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paginated flat list of a tenant's recorded (finalized/paid) invoices for
|
||||
* the payments list (node 1). Rows arrive ready-shaped from the repository;
|
||||
|
||||
Reference in New Issue
Block a user